data-structure-typed 1.42.3 → 1.42.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/src/data-structures/binary-tree/avl-tree.d.ts +2 -2
  3. package/dist/cjs/src/data-structures/binary-tree/avl-tree.js +5 -3
  4. package/dist/cjs/src/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/cjs/src/data-structures/binary-tree/binary-tree.d.ts +56 -52
  6. package/dist/cjs/src/data-structures/binary-tree/binary-tree.js +115 -53
  7. package/dist/cjs/src/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/cjs/src/data-structures/binary-tree/bst.d.ts +42 -15
  9. package/dist/cjs/src/data-structures/binary-tree/bst.js +77 -21
  10. package/dist/cjs/src/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/src/data-structures/binary-tree/rb-tree.d.ts +28 -51
  12. package/dist/cjs/src/data-structures/binary-tree/rb-tree.js +148 -180
  13. package/dist/cjs/src/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/cjs/src/data-structures/binary-tree/tree-multiset.d.ts +10 -10
  15. package/dist/cjs/src/data-structures/binary-tree/tree-multiset.js +20 -17
  16. package/dist/cjs/src/data-structures/binary-tree/tree-multiset.js.map +1 -1
  17. package/dist/cjs/src/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  18. package/dist/cjs/src/types/data-structures/binary-tree/rb-tree.d.ts +4 -0
  19. package/dist/cjs/src/types/data-structures/binary-tree/rb-tree.js +0 -5
  20. package/dist/cjs/src/types/data-structures/binary-tree/rb-tree.js.map +1 -1
  21. package/dist/mjs/src/data-structures/binary-tree/avl-tree.d.ts +2 -2
  22. package/dist/mjs/src/data-structures/binary-tree/avl-tree.js +5 -3
  23. package/dist/mjs/src/data-structures/binary-tree/binary-tree.d.ts +56 -52
  24. package/dist/mjs/src/data-structures/binary-tree/binary-tree.js +115 -53
  25. package/dist/mjs/src/data-structures/binary-tree/bst.d.ts +42 -15
  26. package/dist/mjs/src/data-structures/binary-tree/bst.js +79 -21
  27. package/dist/mjs/src/data-structures/binary-tree/rb-tree.d.ts +28 -51
  28. package/dist/mjs/src/data-structures/binary-tree/rb-tree.js +148 -184
  29. package/dist/mjs/src/data-structures/binary-tree/tree-multiset.d.ts +10 -10
  30. package/dist/mjs/src/data-structures/binary-tree/tree-multiset.js +19 -17
  31. package/dist/mjs/src/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  32. package/dist/mjs/src/types/data-structures/binary-tree/rb-tree.d.ts +4 -0
  33. package/dist/mjs/src/types/data-structures/binary-tree/rb-tree.js +0 -5
  34. package/dist/umd/data-structure-typed.min.js +1 -1
  35. package/dist/umd/data-structure-typed.min.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/data-structures/binary-tree/avl-tree.ts +5 -4
  38. package/src/data-structures/binary-tree/binary-tree.ts +201 -131
  39. package/src/data-structures/binary-tree/bst.ts +100 -34
  40. package/src/data-structures/binary-tree/rb-tree.ts +227 -236
  41. package/src/data-structures/binary-tree/tree-multiset.ts +24 -23
  42. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  43. package/src/types/data-structures/binary-tree/rb-tree.ts +5 -5
  44. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +20 -1
  45. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +12 -31
  46. package/test/unit/data-structures/binary-tree/bst.test.ts +3 -3
  47. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +205 -159
@@ -53,23 +53,25 @@ class TreeMultiset extends avl_tree_1.AVLTree {
53
53
  /**
54
54
  * The `add` function adds a new node to a binary search tree, updating the count if the key already
55
55
  * exists, and balancing the tree if necessary.
56
- * @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
56
+ * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can be either a
57
57
  * `BTNKey` (which represents the key of the node to be added), a `N` (which represents a
58
- * node to be added), or `null` (which represents a null node).
58
+ * node to be added), or `undefined` (which represents a undefined node).
59
59
  * @param [value] - The `value` parameter represents the value associated with the key that is being
60
60
  * added to the binary tree.
61
61
  * @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
62
62
  * pair that will be added to the binary tree. It has a default value of 1, which means that if no
63
63
  * count is specified, the default count will be 1.
64
- * @returns The function `add` returns a value of type `N | null | undefined`.
64
+ * @returns The function `add` returns a value of type `N | undefined | undefined`.
65
65
  */
66
66
  add(keyOrNode, value, count = 1) {
67
+ if (keyOrNode === null)
68
+ return undefined;
67
69
  let inserted = undefined, newNode;
68
70
  if (keyOrNode instanceof TreeMultisetNode) {
69
71
  newNode = this.createNode(keyOrNode.key, keyOrNode.value, keyOrNode.count);
70
72
  }
71
- else if (keyOrNode === null) {
72
- newNode = null;
73
+ else if (keyOrNode === undefined) {
74
+ newNode = undefined;
73
75
  }
74
76
  else {
75
77
  newNode = this.createNode(keyOrNode, value, count);
@@ -127,7 +129,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
127
129
  }
128
130
  }
129
131
  else {
130
- // TODO may need to support null inserted
132
+ // TODO may need to support undefined inserted
131
133
  }
132
134
  }
133
135
  else {
@@ -141,8 +143,8 @@ class TreeMultiset extends avl_tree_1.AVLTree {
141
143
  }
142
144
  /**
143
145
  * The function adds a new node to a binary tree if there is an available slot in the parent node.
144
- * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to
145
- * the tree. It can be either a node object (`N`) or `null`.
146
+ * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be added to
147
+ * the tree. It can be either a node object (`N`) or `undefined`.
146
148
  * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
147
149
  * be added as a child.
148
150
  * @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
@@ -151,7 +153,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
151
153
  if (parent) {
152
154
  if (parent.left === undefined) {
153
155
  parent.left = newNode;
154
- if (newNode !== null) {
156
+ if (newNode !== undefined) {
155
157
  this._size = this.size + 1;
156
158
  this._setCount(this.count + newNode.count);
157
159
  }
@@ -159,7 +161,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
159
161
  }
160
162
  else if (parent.right === undefined) {
161
163
  parent.right = newNode;
162
- if (newNode !== null) {
164
+ if (newNode !== undefined) {
163
165
  this._size = this.size + 1;
164
166
  this._setCount(this.count + newNode.count);
165
167
  }
@@ -176,12 +178,12 @@ class TreeMultiset extends avl_tree_1.AVLTree {
176
178
  /**
177
179
  * The `addMany` function adds multiple keys or nodes to a TreeMultiset and returns an array of the
178
180
  * inserted nodes.
179
- * @param {(BTNKey | null)[] | (N | null)[]} keysOrNodes - An array of keys or nodes to be
181
+ * @param {(BTNKey | undefined)[] | (N | undefined)[]} keysOrNodes - An array of keys or nodes to be
180
182
  * added to the multiset. Each element can be either a BTNKey or a TreeMultisetNode.
181
183
  * @param {V[]} [data] - The `data` parameter is an optional array of values that correspond
182
184
  * to the keys or nodes being added to the multiset. It is used to associate additional data with
183
185
  * each key or node.
184
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
186
+ * @returns The function `addMany` returns an array of `N`, `undefined`, or `undefined` values.
185
187
  */
186
188
  addMany(keysOrNodes, data) {
187
189
  const inserted = [];
@@ -191,7 +193,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
191
193
  inserted.push(this.add(keyOrNode.key, keyOrNode.value, keyOrNode.count));
192
194
  continue;
193
195
  }
194
- if (keyOrNode === null) {
196
+ if (keyOrNode === undefined) {
195
197
  inserted.push(this.add(NaN, undefined, 0));
196
198
  continue;
197
199
  }
@@ -263,11 +265,11 @@ class TreeMultiset extends avl_tree_1.AVLTree {
263
265
  const bstDeletedResult = [];
264
266
  if (!this.root)
265
267
  return bstDeletedResult;
266
- const curr = this.getNode(identifier, callback);
268
+ const curr = this.getNode(identifier, callback) ?? undefined;
267
269
  if (!curr)
268
270
  return bstDeletedResult;
269
- const parent = curr?.parent ? curr.parent : null;
270
- let needBalanced = null, orgCurrent = curr;
271
+ const parent = curr?.parent ? curr.parent : undefined;
272
+ let needBalanced = undefined, orgCurrent = curr;
271
273
  if (curr.count > 1 && !ignoreCount) {
272
274
  curr.count--;
273
275
  this._setCount(this.count - 1);
@@ -290,7 +292,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
290
292
  }
291
293
  }
292
294
  else {
293
- const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
295
+ const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : undefined;
294
296
  if (leftSubTreeRightMost) {
295
297
  const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
296
298
  orgCurrent = this._swap(curr, leftSubTreeRightMost);
@@ -21,7 +21,7 @@ export declare enum FamilyPosition {
21
21
  export type BTNKey = number;
22
22
  export type BinaryTreeDeletedResult<N> = {
23
23
  deleted: N | null | undefined;
24
- needBalanced: N | null;
24
+ needBalanced: N | null | undefined;
25
25
  };
26
26
  export type BinaryTreeNodeNested<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
27
27
  export type BinaryTreeOptions = {
@@ -1,4 +1,8 @@
1
+ import { RBTreeNode } from '../../../data-structures';
2
+ import { BSTOptions } from "./bst";
1
3
  export declare enum RBTNColor {
2
4
  RED = 1,
3
5
  BLACK = 0
4
6
  }
7
+ export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
8
+ export type RBTreeOptions = BSTOptions & {};
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- // import {BinaryTreeOptions} from './binary-tree';
3
- // import {RBTreeNode} from '../../../data-structures';
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
3
  exports.RBTNColor = void 0;
6
4
  var RBTNColor;
@@ -8,6 +6,3 @@ var RBTNColor;
8
6
  RBTNColor[RBTNColor["RED"] = 1] = "RED";
9
7
  RBTNColor[RBTNColor["BLACK"] = 0] = "BLACK";
10
8
  })(RBTNColor || (exports.RBTNColor = RBTNColor = {}));
11
- // export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
12
- //
13
- // export type RBTreeOptions = BinaryTreeOptions & {}
@@ -1,4 +1,4 @@
1
- "use strict";var dataStructureTyped=(()=>{var de=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Ye=Object.prototype.hasOwnProperty;var $e=(a,e)=>{for(var t in e)de(a,t,{get:e[t],enumerable:!0})},Je=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Xe(e))!Ye.call(a,n)&&n!==t&&de(a,n,{get:()=>e[n],enumerable:!(r=Qe(e,n))||r.enumerable});return a};var Ze=a=>Je(de({},"__esModule",{value:!0}),a);var tt={};$e(tt,{AVLTree:()=>J,AVLTreeNode:()=>F,AbstractEdge:()=>L,AbstractGraph:()=>D,AbstractVertex:()=>v,ArrayDeque:()=>Te,BST:()=>$,BSTNode:()=>S,BinaryIndexedTree:()=>Fe,BinaryTree:()=>Y,BinaryTreeNode:()=>O,CP:()=>ae,Character:()=>he,CoordinateMap:()=>pe,CoordinateSet:()=>ge,Deque:()=>xe,DirectedEdge:()=>A,DirectedGraph:()=>Q,DirectedVertex:()=>I,DoublyLinkedList:()=>G,DoublyLinkedListNode:()=>B,FamilyPosition:()=>le,FibonacciHeap:()=>ke,FibonacciHeapNode:()=>re,HashMap:()=>be,HashTable:()=>ce,HashTableNode:()=>j,Heap:()=>R,IterationType:()=>X,LinkedListQueue:()=>Ee,MapEdge:()=>oe,MapGraph:()=>De,MapVertex:()=>se,Matrix2D:()=>je,MatrixNTI2D:()=>Ue,MaxHeap:()=>Ke,MaxPriorityQueue:()=>Le,MinHeap:()=>Re,MinPriorityQueue:()=>Me,NIL:()=>T,Navigator:()=>qe,ObjectDeque:()=>Ve,PriorityQueue:()=>M,Queue:()=>C,RBTNColor:()=>Ie,RBTreeNode:()=>Z,RedBlackTree:()=>Ae,SegmentTree:()=>ze,SegmentTreeNode:()=>H,SinglyLinkedList:()=>q,SinglyLinkedListNode:()=>w,SkipList:()=>Ne,SkipListNode:()=>W,Stack:()=>_e,THUNK_SYMBOL:()=>Ce,TopologicalProperty:()=>We,TreeMap:()=>me,TreeMultiset:()=>He,TreeMultisetNode:()=>P,TreeNode:()=>Pe,TreeSet:()=>ye,Trie:()=>Ge,TrieNode:()=>ee,UndirectedEdge:()=>ie,UndirectedGraph:()=>Se,UndirectedVertex:()=>ne,Vector2D:()=>U,arrayRemove:()=>K,getMSB:()=>Be,isThunk:()=>Oe,toThunk:()=>we,trampoline:()=>te,trampolineAsync:()=>et,uuidV4:()=>ve});var j=class{key;value;next;constructor(e,t){this.key=e,this.value=t,this.next=null}},ce=class a{static DEFAULT_CAPACITY=16;static LOAD_FACTOR=.75;constructor(e=a.DEFAULT_CAPACITY,t){this._hashFn=t||this._defaultHashFn,this._capacity=Math.max(e,a.DEFAULT_CAPACITY),this._size=0,this._buckets=new Array(this._capacity).fill(null)}_capacity;get capacity(){return this._capacity}_size;get size(){return this._size}_buckets;get buckets(){return this._buckets}_hashFn;get hashFn(){return this._hashFn}set(e,t){let r=this._hash(e),n=new j(e,t);if(!this._buckets[r])this._buckets[r]=n;else{let i=this._buckets[r];for(;i;){if(i.key===e){i.value=t;return}if(!i.next)break;i=i.next}i.next=n}this._size++,this._size/this._capacity>=a.LOAD_FACTOR&&this._expand()}get(e){let t=this._hash(e),r=this._buckets[t];for(;r;){if(r.key===e)return r.value;r=r.next}}delete(e){let t=this._hash(e),r=this._buckets[t],n=null;for(;r;){if(r.key===e){n?n.next=r.next:this._buckets[t]=r.next,this._size--,r.next=null;return}n=r,r=r.next}}_defaultHashFn(e){return(typeof e=="string"?this._murmurStringHashFn(e):this._objectHash(e))%this._capacity}_multiplicativeStringHashFn(e){let t=String(e),r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n),s=.618033988749895,o=1<<30;r=(r*s+i)%o}return Math.abs(r)}_murmurStringHashFn(e){let t=String(e),n=0;for(let i=0;i<t.length;i++){let s=t.charCodeAt(i);n=(n^s)*1540483477,n=(n^n>>>15)*668265261,n=n^n>>>15}return Math.abs(n)}_hash(e){return this.hashFn(e)}_stringHash(e){let t=0;for(let r=0;r<e.length;r++)t=t*31+e.charCodeAt(r)&4294967295;return t}_objectHash(e){return this._stringHash(JSON.stringify(e))}_expand(){let e=this._capacity*2,t=new Array(e).fill(null);for(let r of this._buckets){let n=r;for(;n;){let i=this._hash(n.key),s=new j(n.key,n.value);if(!t[i])t[i]=s;else{let o=t[i];for(;o.next;)o=o.next;o.next=s}n=n.next}}this._buckets=t,this._capacity=e}};var pe=class extends Map{constructor(e){super(),e!==void 0&&(this._joint=e)}_joint="_";get joint(){return this._joint}has(e){return super.has(e.join(this._joint))}set(e,t){return super.set(e.join(this._joint),t)}get(e){return super.get(e.join(this._joint))}delete(e){return super.delete(e.join(this._joint))}};var ge=class extends Set{constructor(e){super(),e!==void 0&&(this._joint=e)}_joint="_";get joint(){return this._joint}has(e){return super.has(e.join(this._joint))}add(e){return super.add(e.join(this._joint))}delete(e){return super.delete(e.join(this._joint))}};var me=class{};var ye=class{};var be=class{constructor(e=16,t=.75,r){this._initialCapacity=e,this._loadFactor=t,this._capacityMultiplier=2,this._size=0,this._table=new Array(e),this._hashFn=r||(n=>{let i=String(n),s=0;for(let o=0;o<i.length;o++)s+=i.charCodeAt(o);return s%this.table.length})}_initialCapacity;get initialCapacity(){return this._initialCapacity}_loadFactor;get loadFactor(){return this._loadFactor}_capacityMultiplier;get capacityMultiplier(){return this._capacityMultiplier}_size;get size(){return this._size}_table;get table(){return this._table}_hashFn;get hashFn(){return this._hashFn}set(e,t){this.size/this.table.length>=this.loadFactor&&this.resizeTable(this.table.length*this.capacityMultiplier);let n=this._hash(e);this.table[n]||(this.table[n]=[]);for(let i=0;i<this.table[n].length;i++)if(this.table[n][i][0]===e){this.table[n][i][1]=t;return}this.table[n].push([e,t]),this._size++}get(e){let t=this._hash(e);if(this.table[t]){for(let[r,n]of this.table[t])if(r===e)return n}}delete(e){let t=this._hash(e);if(this.table[t]){for(let r=0;r<this.table[t].length;r++)if(this.table[t][r][0]===e){this.table[t].splice(r,1),this._size--,this.size/this.table.length<this.loadFactor/this.capacityMultiplier&&this.resizeTable(this.table.length/this.capacityMultiplier);return}}}*entries(){for(let e of this.table)if(e)for(let[t,r]of e)yield[t,r]}[Symbol.iterator](){return this.entries()}clear(){this._size=0,this._table=new Array(this.initialCapacity)}isEmpty(){return this.size===0}_hash(e){return this._hashFn(e)}resizeTable(e){let t=new Array(e);for(let r of this._table)if(r)for(let[n,i]of r){let s=this._hash(n)%e;t[s]||(t[s]=[]),t[s].push([n,i])}this._table=t}};var w=class{value;next;constructor(e){this.value=e,this.next=null}},q=class a{constructor(){this._head=null,this._tail=null,this._length=0}_head;get head(){return this._head}_tail;get tail(){return this._tail}_length;get length(){return this._length}static fromArray(e){let t=new a;for(let r of e)t.push(r);return t}push(e){let t=new w(e);this.head?(this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++}addLast(e){this.push(e)}pop(){if(!this.head)return;if(this.head===this.tail){let r=this.head.value;return this._head=null,this._tail=null,this._length--,r}let e=this.head;for(;e.next!==this.tail;)e=e.next;let t=this.tail.value;return e.next=null,this._tail=e,this._length--,t}popLast(){return this.pop()}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._length--,e.value}popFirst(){return this.shift()}unshift(e){let t=new w(e);this.head?(t.next=this.head,this._head=t):(this._head=t,this._tail=t),this._length++}addFirst(e){this.unshift(e)}getAt(e){if(e<0||e>=this.length)return;let t=this.head;for(let r=0;r<e;r++)t=t.next;return t.value}getNodeAt(e){let t=this.head;for(let r=0;r<e;r++)t=t.next;return t}deleteAt(e){if(e<0||e>=this.length)return;if(e===0)return this.shift();if(e===this.length-1)return this.pop();let t=this.getNodeAt(e-1),r=t.next;return t.next=r.next,this._length--,r.value}delete(e){if(!e)return!1;let t;e instanceof w?t=e.value:t=e;let r=this.head,n=null;for(;r;){if(r.value===t)return n===null?(this._head=r.next,r===this.tail&&(this._tail=null)):(n.next=r.next,r===this.tail&&(this._tail=n)),this._length--,!0;n=r,r=r.next}return!1}insertAt(e,t){if(e<0||e>this.length)return!1;if(e===0)return this.unshift(t),!0;if(e===this.length)return this.push(t),!0;let r=new w(t),n=this.getNodeAt(e-1);return r.next=n.next,n.next=r,this._length++,!0}isEmpty(){return this.length===0}clear(){this._head=null,this._tail=null,this._length=0}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}reverse(){if(!this.head||this.head===this.tail)return;let e=null,t=this.head,r=null;for(;t;)r=t.next,t.next=e,e=t,t=r;[this._head,this._tail]=[this.tail,this.head]}find(e){let t=this.head;for(;t;){if(e(t.value))return t.value;t=t.next}return null}indexOf(e){let t=0,r=this.head;for(;r;){if(r.value===e)return t;t++,r=r.next}return-1}getNode(e){let t=this.head;for(;t;){if(t.value===e)return t;t=t.next}return null}insertBefore(e,t){if(!this.head)return!1;let r;if(e instanceof w?r=e.value:r=e,this.head.value===r)return this.unshift(t),!0;let n=this.head;for(;n.next;){if(n.next.value===r){let i=new w(t);return i.next=n.next,n.next=i,this._length++,!0}n=n.next}return!1}insertAfter(e,t){let r;if(e instanceof w?r=e:r=this.getNode(e),r){let n=new w(t);return n.next=r.next,r.next=n,r===this.tail&&(this._tail=n),this._length++,!0}return!1}countOccurrences(e){let t=0,r=this.head;for(;r;)r.value===e&&t++,r=r.next;return t}forEach(e){let t=this.head,r=0;for(;t;)e(t.value,r),t=t.next,r++}map(e){let t=new a,r=this.head;for(;r;)t.push(e(r.value)),r=r.next;return t}filter(e){let t=new a,r=this.head;for(;r;)e(r.value)&&t.push(r.value),r=r.next;return t}reduce(e,t){let r=t,n=this.head;for(;n;)r=e(r,n.value),n=n.next;return r}*[Symbol.iterator](){let e=this.head;for(;e;)yield e.value,e=e.next}};var B=class{value;next;prev;constructor(e){this.value=e,this.next=null,this.prev=null}},G=class a{constructor(){this._head=null,this._tail=null,this._length=0}_head;get head(){return this._head}_tail;get tail(){return this._tail}_length;get length(){return this._length}get size(){return this.length}static fromArray(e){let t=new a;for(let r of e)t.push(r);return t}push(e){let t=new B(e);this.head?(t.prev=this.tail,this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++}addLast(e){this.push(e)}pop(){if(!this.tail)return;let e=this.tail;return this.head===this.tail?(this._head=null,this._tail=null):(this._tail=e.prev,this.tail.next=null),this._length--,e.value}popLast(){return this.pop()}shift(){if(!this.head)return;let e=this.head;return this.head===this.tail?(this._head=null,this._tail=null):(this._head=e.next,this.head.prev=null),this._length--,e.value}popFirst(){return this.shift()}unshift(e){let t=new B(e);this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._length++}addFirst(e){this.unshift(e)}getFirst(){return this.head?.value}getLast(){return this.tail?.value}getAt(e){if(e<0||e>=this.length)return;let t=this.head;for(let r=0;r<e;r++)t=t.next;return t.value}getNodeAt(e){if(e<0||e>=this.length)return null;let t=this.head;for(let r=0;r<e;r++)t=t.next;return t}getNode(e){let t=this.head;for(;t;){if(t.value===e)return t;t=t.next}return null}insertAt(e,t){if(e<0||e>this.length)return!1;if(e===0)return this.unshift(t),!0;if(e===this.length)return this.push(t),!0;let r=new B(t),n=this.getNodeAt(e-1),i=n.next;return r.prev=n,r.next=i,n.next=r,i.prev=r,this._length++,!0}insertBefore(e,t){let r;if(e instanceof B?r=e:r=this.getNode(e),r){let n=new B(t);return n.prev=r.prev,r.prev&&(r.prev.next=n),n.next=r,r.prev=n,r===this.head&&(this._head=n),this._length++,!0}return!1}deleteAt(e){if(e<0||e>=this.length)return;if(e===0)return this.shift();if(e===this.length-1)return this.pop();let t=this.getNodeAt(e),r=t.prev,n=t.next;return r.next=n,n.prev=r,this._length--,t.value}delete(e){let t;if(e instanceof B?t=e:t=this.getNode(e),t){if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let r=t.prev,n=t.next;r.next=n,n.prev=r,this._length--}return!0}return!1}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}isEmpty(){return this.length===0}clear(){this._head=null,this._tail=null,this._length=0}find(e){let t=this.head;for(;t;){if(e(t.value))return t.value;t=t.next}return null}indexOf(e){let t=0,r=this.head;for(;r;){if(r.value===e)return t;t++,r=r.next}return-1}findBackward(e){let t=this.tail;for(;t;){if(e(t.value))return t.value;t=t.prev}return null}toArrayBackward(){let e=[],t=this.tail;for(;t;)e.push(t.value),t=t.prev;return e}reverse(){let e=this.head;for([this._head,this._tail]=[this.tail,this.head];e;){let t=e.next;[e.prev,e.next]=[e.next,e.prev],e=t}}forEach(e){let t=this.head,r=0;for(;t;)e(t.value,r),t=t.next,r++}map(e){let t=new a,r=this.head;for(;r;)t.push(e(r.value)),r=r.next;return t}filter(e){let t=new a,r=this.head;for(;r;)e(r.value)&&t.push(r.value),r=r.next;return t}reduce(e,t){let r=t,n=this.head;for(;n;)r=e(r,n.value),n=n.next;return r}insertAfter(e,t){let r;if(e instanceof B?r=e:r=this.getNode(e),r){let n=new B(t);return n.next=r.next,r.next&&(r.next.prev=n),n.prev=r,r.next=n,r===this.tail&&(this._tail=n),this._length++,!0}return!1}*[Symbol.iterator](){let e=this.head;for(;e;)yield e.value,e=e.next}};var W=class{key;value;forward;constructor(e,t,r){this.key=e,this.value=t,this.forward=new Array(r)}},Ne=class{constructor(e=16,t=.5){this._head=new W(null,null,e),this._level=0,this._maxLevel=e,this._probability=t}_head;get head(){return this._head}_level;get level(){return this._level}_maxLevel;get maxLevel(){return this._maxLevel}_probability;get probability(){return this._probability}add(e,t){let r=new W(e,t,this._randomLevel()),n=new Array(this.maxLevel).fill(this.head),i=this.head;for(let s=this.level-1;s>=0;s--){for(;i.forward[s]&&i.forward[s].key<e;)i=i.forward[s];n[s]=i}for(let s=0;s<r.forward.length;s++)r.forward[s]=n[s].forward[s],n[s].forward[s]=r;r.forward[0]!==null&&(this._level=Math.max(this.level,r.forward.length))}get(e){let t=this.head;for(let r=this.level-1;r>=0;r--)for(;t.forward[r]&&t.forward[r].key<e;)t=t.forward[r];if(t=t.forward[0],t&&t.key===e)return t.value}has(e){return this.get(e)!==void 0}delete(e){let t=new Array(this.maxLevel).fill(this.head),r=this.head;for(let n=this.level-1;n>=0;n--){for(;r.forward[n]&&r.forward[n].key<e;)r=r.forward[n];t[n]=r}if(r=r.forward[0],r&&r.key===e){for(let n=0;n<this.level&&t[n].forward[n]===r;n++)t[n].forward[n]=r.forward[n];for(;this.level>0&&this.head.forward[this.level-1]===null;)this._level--;return!0}return!1}getFirst(){let e=this.head.forward[0];return e?e.value:void 0}getLast(){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t];)e=e.forward[t];return e.value}higher(e){let t=this.head;for(let n=this.level-1;n>=0;n--)for(;t.forward[n]&&t.forward[n].key<=e;)t=t.forward[n];let r=t.forward[0];return r?r.value:void 0}lower(e){let t=this.head,r=null;for(let n=this.level-1;n>=0;n--){for(;t.forward[n]&&t.forward[n].key<e;)t=t.forward[n];t.key<e&&(r=t)}return r?r.value:void 0}_randomLevel(){let e=1;for(;Math.random()<this.probability&&e<this.maxLevel;)e++;return e}};var _e=class a{constructor(e){this._elements=Array.isArray(e)?e:[]}_elements;get elements(){return this._elements}static fromArray(e){return new a(e)}isEmpty(){return this.elements.length===0}size(){return this.elements.length}peek(){return this.isEmpty()?null:this.elements[this.elements.length-1]}push(e){return this.elements.push(e),this}pop(){return this.isEmpty()?null:this.elements.pop()||null}toArray(){return this.elements.slice()}clear(){this._elements=[]}clone(){return new a(this.elements.slice())}};var Ee=class extends q{enqueue(e){this.push(e)}dequeue(){return this.shift()}getFirst(){return this.head?.value}peek(){return this.getFirst()}},C=class a{constructor(e){this._nodes=e||[],this._offset=0}_nodes;get nodes(){return this._nodes}_offset;get offset(){return this._offset}get size(){return this.nodes.length-this.offset}static fromArray(e){return new a(e)}push(e){return this.nodes.push(e),this}shift(){if(this.size===0)return;let e=this.getFirst();return this._offset+=1,this.offset*2<this.nodes.length||(this._nodes=this.nodes.slice(this.offset),this._offset=0),e}getFirst(){return this.size>0?this.nodes[this.offset]:void 0}peek(){return this.getFirst()}getLast(){return this.size>0?this.nodes[this.nodes.length-1]:void 0}peekLast(){return this.getLast()}enqueue(e){this.push(e)}dequeue(){return this.shift()}getAt(e){return this.nodes[e]}isEmpty(){return this.size===0}toArray(){return this.nodes.slice(this.offset)}clear(){this._nodes=[],this._offset=0}clone(){return new a(this.nodes.slice(this.offset))}*[Symbol.iterator](){for(let e of this.nodes)yield e}};var xe=class extends G{},Ve=class{constructor(e){e!==void 0&&(this._capacity=e)}_nodes={};get nodes(){return this._nodes}_capacity=Number.MAX_SAFE_INTEGER;get capacity(){return this._capacity}_first=-1;get first(){return this._first}_last=-1;get last(){return this._last}_size=0;get size(){return this._size}addFirst(e){if(this.size===0){let t=Math.floor(this.capacity/2);this._first=t,this._last=t}else this._first--;this.nodes[this.first]=e,this._size++}addLast(e){if(this.size===0){let t=Math.floor(this.capacity/2);this._first=t,this._last=t}else this._last++;this.nodes[this.last]=e,this._size++}popFirst(){if(!this.size)return;let e=this.getFirst();return delete this.nodes[this.first],this._first++,this._size--,e}getFirst(){if(this.size)return this.nodes[this.first]}popLast(){if(!this.size)return;let e=this.getLast();return delete this.nodes[this.last],this._last--,this._size--,e}getLast(){if(this.size)return this.nodes[this.last]}get(e){return this.nodes[this.first+e]||null}isEmpty(){return this.size<=0}},Te=class{_nodes=[];get nodes(){return this._nodes}get size(){return this.nodes.length}addLast(e){return this.nodes.push(e)}popLast(){return this.nodes.pop()??null}popFirst(){return this.nodes.shift()??null}addFirst(e){return this.nodes.unshift(e)}getFirst(){return this.nodes[0]??null}getLast(){return this.nodes[this.nodes.length-1]??null}get(e){return this.nodes[e]??null}set(e,t){return this.nodes[e]=t}insert(e,t){return this.nodes.splice(e,0,t)}delete(e){return this.nodes.splice(e,1)}isEmpty(){return this.nodes.length===0}};var ve=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(a){let e=Math.random()*16|0;return(a=="x"?e:e&3|8).toString(16)})},K=function(a,e){let t=-1,r=a?a.length:0,n=[];for(;++t<r;){let i=a[t];e(i,t,a)&&(n.push(i),Array.prototype.splice.call(a,t--,1),r--)}return n},Ce=Symbol("thunk"),Oe=a=>typeof a=="function"&&a.__THUNK__===Ce,we=a=>{let e=()=>a();return e.__THUNK__=Ce,e},te=a=>Object.assign((...t)=>{let r=a(...t);for(;Oe(r)&&typeof r=="function";)r=r();return r},{cont:(...t)=>we(()=>a(...t))}),et=a=>Object.assign(async(...t)=>{let r=await a(...t);for(;Oe(r)&&typeof r=="function";)r=await r();return r},{cont:(...t)=>we(()=>a(...t))}),Be=a=>a<=0?0:1<<31-Math.clz32(a);var R=class a{constructor(e){this._comparator=e.comparator,e.nodes&&e.nodes.length>0&&(this._nodes=e.nodes,this.fix())}_nodes=[];get nodes(){return this._nodes}_comparator;get comparator(){return this._comparator}get size(){return this.nodes.length}get leaf(){return this.nodes[this.size-1]??void 0}static heapify(e){return new a(e)}add(e){return this.push(e)}push(e){return this.nodes.push(e),this.bubbleUp(this.nodes.length-1),this}poll(){if(this.nodes.length===0)return;if(this.nodes.length===1)return this.nodes.pop();let e=this.nodes[0];return this.nodes[0]=this.nodes.pop(),this.sinkDown(0),e}pop(){return this.poll()}peek(){if(this.nodes.length!==0)return this.nodes[0]}isEmpty(){return this.size===0}clear(){this._nodes=[]}refill(e){this._nodes=e,this.fix()}has(e){return this.nodes.includes(e)}dfs(e){let t=[],r=n=>{n<this.size&&(e==="in"?(r(2*n+1),t.push(this.nodes[n]),r(2*n+2)):e==="pre"?(t.push(this.nodes[n]),r(2*n+1),r(2*n+2)):e==="post"&&(r(2*n+1),r(2*n+2),t.push(this.nodes[n])))};return r(0),t}toArray(){return[...this.nodes]}getNodes(){return this.nodes}clone(){let e=new a({comparator:this.comparator});return e._nodes=[...this.nodes],e}sort(){let e=[],t=this.clone();for(;t.size!==0;){let r=t.poll();r&&e.push(r)}return e}bubbleUp(e){let t=this.nodes[e];for(;e>0;){let r=Math.floor((e-1)/2),n=this.nodes[r];if(this.comparator(t,n)<0)this.nodes[e]=n,this.nodes[r]=t,e=r;else break}}sinkDown(e){let t=2*e+1,r=2*e+2,n=this.nodes.length,i=e;if(t<n&&this.comparator(this.nodes[t],this.nodes[i])<0&&(i=t),r<n&&this.comparator(this.nodes[r],this.nodes[i])<0&&(i=r),i!==e){let s=this.nodes[e];this.nodes[e]=this.nodes[i],this.nodes[i]=s,this.sinkDown(i)}}fix(){for(let e=Math.floor(this.size/2);e>=0;e--)this.sinkDown(e)}},re=class{element;degree;left;right;child;parent;marked;constructor(e,t=0){this.element=e,this.degree=t,this.marked=!1}},ke=class{constructor(e){if(this.clear(),this._comparator=e||this.defaultComparator,typeof this.comparator!="function")throw new Error("FibonacciHeap constructor: given comparator should be a function.")}_root;get root(){return this._root}_size=0;get size(){return this._size}_min;get min(){return this._min}_comparator;get comparator(){return this._comparator}clear(){this._root=void 0,this._min=void 0,this._size=0}add(e){return this.push(e)}push(e){let t=this.createNode(e);return t.left=t,t.right=t,this.mergeWithRoot(t),(!this.min||this.comparator(t.element,this.min.element)<=0)&&(this._min=t),this._size++,this}peek(){return this.min?this.min.element:void 0}consumeLinkedList(e){let t=[];if(!e)return t;let r=e,n=!1;for(;!(r===e&&n);)r===e&&(n=!0),r&&(t.push(r),r=r.right);return t}mergeWithChild(e,t){e.child?(t.right=e.child.right,t.left=e.child,e.child.right.left=t,e.child.right=t):e.child=t}poll(){return this.pop()}pop(){if(this.size===0)return;let e=this.min;if(e.child){let t=this.consumeLinkedList(e.child);for(let r of t)this.mergeWithRoot(r),r.parent=void 0}return this.removeFromRoot(e),e===e.right?(this._min=void 0,this._root=void 0):(this._min=e.right,this.consolidate()),this._size--,e.element}merge(e){if(e.size!==0){if(this.root&&e.root){let t=this.root,r=e.root,n=t.right,i=r.left;t.right=r,r.left=t,n.left=i,i.right=n}(!this.min||e.min&&this.comparator(e.min.element,this.min.element)<0)&&(this._min=e.min),this._size+=e.size,e.clear()}}defaultComparator(e,t){return e<t?-1:e>t?1:0}createNode(e){return new re(e)}mergeWithRoot(e){this.root?(e.right=this.root.right,e.left=this.root,this.root.right.left=e,this.root.right=e):this._root=e}removeFromRoot(e){this.root===e&&(this._root=e.right),e.left&&(e.left.right=e.right),e.right&&(e.right.left=e.left)}link(e,t){this.removeFromRoot(e),e.left=e,e.right=e,this.mergeWithChild(t,e),t.degree++,e.parent=t}consolidate(){let e=new Array(this.size),t=this.consumeLinkedList(this.root),r,n,i,s;for(let o of t){for(r=o,i=r.degree;e[i];)n=e[i],this.comparator(r.element,n.element)>0&&(s=r,r=n,n=s),this.link(n,r),e[i]=void 0,i++;e[i]=r}for(let o=0;o<this.size;o++)e[o]&&this.comparator(e[o].element,this.min.element)<=0&&(this._min=e[o])}};var Ke=class extends R{constructor(e={comparator:(t,r)=>{if(typeof t=="number"&&typeof r=="number")return r-t;throw new Error("The a, b params of compare function must be number")}}){super(e)}};var Re=class extends R{constructor(e={comparator:(t,r)=>{if(typeof t=="number"&&typeof r=="number")return t-r;throw new Error("The a, b params of compare function must be number")}}){super(e)}};var M=class extends R{constructor(e){super(e)}};var Me=class extends M{constructor(e={comparator:(t,r)=>{if(typeof t=="number"&&typeof r=="number")return t-r;throw new Error("The a, b params of compare function must be number")}}){super(e)}};var Le=class extends M{constructor(e={comparator:(t,r)=>{if(typeof t=="number"&&typeof r=="number")return r-t;throw new Error("The a, b params of compare function must be number")}}){super(e)}};var v=class{key;value;constructor(e,t){this.key=e,this.value=t}},L=class{value;weight;constructor(e,t){this.weight=e!==void 0?e:1,this.value=t,this._hashCode=ve()}_hashCode;get hashCode(){return this._hashCode}},D=class{_vertices=new Map;get vertices(){return this._vertices}getVertex(e){return this._vertices.get(e)||null}hasVertex(e){return this._vertices.has(this._getVertexKey(e))}addVertex(e,t){if(e instanceof v)return this._addVertexOnly(e);{let r=this.createVertex(e,t);return this._addVertexOnly(r)}}deleteVertex(e){let t=this._getVertexKey(e);return this._vertices.delete(t)}removeManyVertices(e){let t=[];for(let r of e)t.push(this.deleteVertex(r));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,r,n){if(e instanceof L)return this._addEdgeOnly(e);if(t instanceof v||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof v&&(e=e.key),t instanceof v&&(t=t.key);let i=this.createEdge(e,t,r,n);return this._addEdgeOnly(i)}else throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(e,t,r){let n=this.getEdge(e,t);return n?(n.weight=r,!0):!1}getAllPathsBetween(e,t,r=1e3){let n=[],i=this._getVertex(e),s=this._getVertex(t);if(!(i&&s))return[];let o=[];for(o.push({vertex:i,path:[i]});o.length>0;){let{vertex:l,path:h}=o.pop();if(l===s&&(n.push(h),n.length>=r))return n;let d=this.getNeighbors(l);for(let g of d)if(!h.includes(g)){let y=[...h,g];o.push({vertex:g,path:y})}}return n}getPathSumWeight(e){let t=0;for(let r=0;r<e.length;r++)t+=this.getEdge(e[r],e[r+1])?.weight||0;return t}getMinCostBetween(e,t,r){if(r===void 0&&(r=!1),r){let n=this.getAllPathsBetween(e,t),i=1/0;for(let s of n)i=Math.min(this.getPathSumWeight(s),i);return i}else{let n=this._getVertex(t),i=this._getVertex(e);if(!(i&&n))return null;let s=new Map,o=new C([i]);s.set(i,!0);let l=0;for(;o.size>0;){for(let h=0;h<o.size;h++){let d=o.shift();if(d===n)return l;if(d!==void 0){let g=this.getNeighbors(d);for(let y of g)s.has(y)||(s.set(y,!0),o.push(y))}}l++}return null}}getMinPathBetween(e,t,r,n=!1){if(r===void 0&&(r=!1),r)if(n){let i=this.getAllPathsBetween(e,t,1e4),s=1/0,o=-1,l=0;for(let h of i){let d=this.getPathSumWeight(h);d<s&&(s=d,o=l),l++}return i[o]||null}else return this.dijkstra(e,t,!0,!0)?.minPath??[];else{let i=[],s=this._getVertex(e),o=this._getVertex(t);if(!(s&&o))return[];let l=(h,d,g,y)=>{if(g.add(h),h===d){i=[s,...y];return}let x=this.getNeighbors(h);for(let _ of x)g.has(_)||(y.push(_),l(_,d,g,y),y.pop());g.delete(h)};return l(s,o,new Set,[]),i}}dijkstraWithoutHeap(e,t,r,n){r===void 0&&(r=!1),n===void 0&&(n=!1),t===void 0&&(t=null);let i=1/0,s=null,o=[],l=[],h=this._vertices,d=new Map,g=new Set,y=new Map,x=this._getVertex(e),_=t?this._getVertex(t):null;if(!x)return null;for(let u of h){let f=u[1];f instanceof v&&d.set(f,1/0)}d.set(x,0),y.set(x,null);let b=()=>{let u=1/0,f=null;for(let[c,m]of d)g.has(c)||m<u&&(u=m,f=c);return f},N=u=>{for(let f of h){let c=f[1];if(c instanceof v){let m=[c],p=y.get(c);for(;p;)m.push(p),p=y.get(p);let E=m.reverse();f[1]===u&&(o=E),l.push(E)}}};for(let u=1;u<h.size;u++){let f=b();if(f){if(g.add(f),_&&_===f)return r&&(i=d.get(_)||1/0),n&&N(_),{distMap:d,preMap:y,seen:g,paths:l,minDist:i,minPath:o};let c=this.getNeighbors(f);for(let m of c)if(!g.has(m)){let p=this.getEdge(f,m);if(p){let E=d.get(f),V=d.get(m);E!==void 0&&V!==void 0&&p.weight+E<V&&(d.set(m,p.weight+E),y.set(m,f))}}}}return r&&d.forEach((u,f)=>{f!==x&&u<i&&(i=u,n&&(s=f))}),n&&N(s),{distMap:d,preMap:y,seen:g,paths:l,minDist:i,minPath:o}}dijkstra(e,t,r,n){r===void 0&&(r=!1),n===void 0&&(n=!1),t===void 0&&(t=null);let i=1/0,s=null,o=[],l=[],h=this._vertices,d=new Map,g=new Set,y=new Map,x=this._getVertex(e),_=t?this._getVertex(t):null;if(!x)return null;for(let u of h){let f=u[1];f instanceof v&&d.set(f,1/0)}let b=new M({comparator:(u,f)=>u.key-f.key});b.add({key:0,value:x}),d.set(x,0),y.set(x,null);let N=u=>{for(let f of h){let c=f[1];if(c instanceof v){let m=[c],p=y.get(c);for(;p;)m.push(p),p=y.get(p);let E=m.reverse();f[1]===u&&(o=E),l.push(E)}}};for(;b.size>0;){let u=b.poll(),f=u?.key,c=u?.value;if(f!==void 0&&c){if(g.add(c),_&&_===c)return r&&(i=d.get(_)||1/0),n&&N(_),{distMap:d,preMap:y,seen:g,paths:l,minDist:i,minPath:o};let m=this.getNeighbors(c);for(let p of m)if(!g.has(p)){let E=this.getEdge(c,p)?.weight;if(typeof E=="number"){let V=d.get(p);V&&f+E<V&&(b.add({key:f+E,value:p}),y.set(p,c),d.set(p,f+E))}}}}return r&&d.forEach((u,f)=>{f!==x&&u<i&&(i=u,n&&(s=f))}),n&&N(s),{distMap:d,preMap:y,seen:g,paths:l,minDist:i,minPath:o}}bellmanFord(e,t,r,n){r===void 0&&(r=!1),n===void 0&&(n=!1);let i=this._getVertex(e),s=[],o=new Map,l=new Map,h=1/0,d=[],g;if(t&&(g=!1),!i)return{hasNegativeCycle:g,distMap:o,preMap:l,paths:s,min:h,minPath:d};let y=this._vertices,x=y.size,_=this.edgeSet(),b=_.length;this._vertices.forEach(u=>{o.set(u,1/0)}),o.set(i,0);for(let u=1;u<x;++u)for(let f=0;f<b;++f){let c=this.getEndsOfEdge(_[f]);if(c){let[m,p]=c,E=_[f].weight,V=o.get(m),k=o.get(p);V!==void 0&&k!==void 0&&o.get(m)!==1/0&&V+E<k&&(o.set(p,V+E),n&&l.set(p,m))}}let N=null;if(r&&o.forEach((u,f)=>{f!==i&&u<h&&(h=u,n&&(N=f))}),n)for(let u of y){let f=u[1];if(f instanceof v){let c=[f],m=l.get(f);for(;m!==void 0;)c.push(m),m=l.get(m);let p=c.reverse();u[1]===N&&(d=p),s.push(p)}}for(let u=0;u<b;++u){let f=this.getEndsOfEdge(_[u]);if(f){let[c]=f,m=_[u].weight,p=o.get(c);p&&p!==1/0&&p+m<p&&(g=!0)}}return{hasNegativeCycle:g,distMap:o,preMap:l,paths:s,min:h,minPath:d}}floydWarshall(){let e=[...this._vertices],t=e.length,r=[],n=[];for(let i=0;i<t;i++){r[i]=[],n[i]=[];for(let s=0;s<t;s++)n[i][s]=null}for(let i=0;i<t;i++)for(let s=0;s<t;s++)r[i][s]=this.getEdge(e[i][1],e[s][1])?.weight||1/0;for(let i=0;i<t;i++)for(let s=0;s<t;s++)for(let o=0;o<t;o++)r[s][o]>r[s][i]+r[i][o]&&(r[s][o]=r[s][i]+r[i][o],n[s][o]=e[i][1]);return{costs:r,predecessor:n}}tarjan(e=!1,t=!1,r=!0,n=!1){e===void 0&&(e=!1),t===void 0&&(t=!1),r===void 0&&(r=!1),n===void 0&&(n=!1);let s=new Map,o=new Map,l=this._vertices;l.forEach(u=>{s.set(u,-1),o.set(u,1/0)});let[h]=l.values(),d=[],g=[],y=0,x=(u,f)=>{y++,s.set(u,y),o.set(u,y);let c=this.getNeighbors(u),m=0;for(let p of c)if(p!==f){s.get(p)===-1&&(m++,x(p,u));let E=o.get(p),V=o.get(u);V!==void 0&&E!==void 0&&o.set(u,Math.min(V,E));let k=s.get(u);if(E!==void 0&&k!==void 0&&(e&&(u===h&&m>=2||u!==h&&E>=k)&&d.push(u),t&&E>k)){let z=this.getEdge(u,p);z&&g.push(z)}}};x(h,null);let _=new Map,b=()=>{let u=new Map;return o.forEach((f,c)=>{u.has(f)?u.get(f)?.push(c):u.set(f,[c])}),u};r&&(_=b());let N=new Map;if(n){let u=new Map;u.size<1&&(u=b()),u.forEach((f,c)=>{f.length>1&&N.set(c,f)})}return{dfnMap:s,lowMap:o,bridges:g,cutVertexes:d,SCCs:_,cycles:N}}getDFNMap(){return this.tarjan(!1,!1,!1,!1).dfnMap}getLowMap(){return this.tarjan(!1,!1,!1,!1).lowMap}getCycles(){return this.tarjan(!1,!1,!1,!0).cycles}getCutVertexes(){return this.tarjan(!0,!1,!1,!1).cutVertexes}getSCCs(){return this.tarjan(!1,!1,!0,!1).SCCs}getBridges(){return this.tarjan(!1,!0,!1,!1).bridges}_addVertexOnly(e){return this.hasVertex(e)?!1:(this._vertices.set(e.key,e),!0)}_getVertex(e){let t=this._getVertexKey(e);return this._vertices.get(t)||null}_getVertexKey(e){return e instanceof v?e.key:e}};var I=class extends v{constructor(e,t){super(e,t)}},A=class extends L{src;dest;constructor(e,t,r,n){super(r,n),this.src=e,this.dest=t}},Q=class extends D{constructor(){super()}_outEdgeMap=new Map;get outEdgeMap(){return this._outEdgeMap}_inEdgeMap=new Map;get inEdgeMap(){return this._inEdgeMap}createVertex(e,t){return new I(e,t??e)}createEdge(e,t,r,n){return new A(e,t,r??1,n)}getEdge(e,t){let r=[];if(e!==null&&t!==null){let n=this._getVertex(e),i=this._getVertex(t);if(n&&i){let s=this._outEdgeMap.get(n);s&&(r=s.filter(o=>o.dest===i.key))}}return r[0]||null}deleteEdgeSrcToDest(e,t){let r=this._getVertex(e),n=this._getVertex(t),i=null;if(!r||!n)return null;let s=this._outEdgeMap.get(r);s&&K(s,l=>l.dest===n.key);let o=this._inEdgeMap.get(n);return o&&(i=K(o,l=>l.src===r.key)[0]||null),i}deleteEdge(e){let t=null,r=this._getVertex(e.src),n=this._getVertex(e.dest);if(r&&n){let i=this._outEdgeMap.get(r);i&&i.length>0&&K(i,o=>o.src===r.key);let s=this._inEdgeMap.get(n);s&&s.length>0&&(t=K(s,o=>o.dest===n.key)[0])}return t}deleteEdgesBetween(e,t){let r=[];if(e&&t){let n=this.deleteEdgeSrcToDest(e,t),i=this.deleteEdgeSrcToDest(t,e);n&&r.push(n),i&&r.push(i)}return r}incomingEdgesOf(e){let t=this._getVertex(e);return t?this.inEdgeMap.get(t)||[]:[]}outgoingEdgesOf(e){let t=this._getVertex(e);return t?this._outEdgeMap.get(t)||[]:[]}degreeOf(e){return this.outDegreeOf(e)+this.inDegreeOf(e)}inDegreeOf(e){return this.incomingEdgesOf(e).length}outDegreeOf(e){return this.outgoingEdgesOf(e).length}edgesOf(e){return[...this.outgoingEdgesOf(e),...this.incomingEdgesOf(e)]}getEdgeSrc(e){return this._getVertex(e.src)}getEdgeDest(e){return this._getVertex(e.dest)}getDestinations(e){if(e===null)return[];let t=[],r=this.outgoingEdgesOf(e);for(let n of r){let i=this.getEdgeDest(n);i&&t.push(i)}return t}topologicalSort(e){e=e??"key";let t=new Map;for(let s of this.vertices)t.set(s[1],0);let r=[],n=!1,i=s=>{t.set(s,1);let o=this.getDestinations(s);for(let l of o){let h=t.get(l);h===0?i(l):h===1&&(n=!0)}t.set(s,2),r.push(s)};for(let s of this.vertices)t.get(s[1])===0&&i(s[1]);return n?null:(e==="key"&&(r=r.map(s=>s instanceof I?s.key:s)),r.reverse())}edgeSet(){let e=[];return this._outEdgeMap.forEach(t=>{e=[...e,...t]}),e}getNeighbors(e){let t=[],r=this._getVertex(e);if(r){let n=this.outgoingEdgesOf(r);for(let i of n){let s=this._getVertex(i.dest);s&&t.push(s)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.src,e.dest))return null;let t=this._getVertex(e.src),r=this._getVertex(e.dest);return t&&r?[t,r]:null}_addEdgeOnly(e){if(!(this.hasVertex(e.src)&&this.hasVertex(e.dest)))return!1;let t=this._getVertex(e.src),r=this._getVertex(e.dest);if(t&&r){let n=this._outEdgeMap.get(t);n?n.push(e):this._outEdgeMap.set(t,[e]);let i=this._inEdgeMap.get(r);return i?i.push(e):this._inEdgeMap.set(r,[e]),!0}else return!1}};var ne=class extends v{constructor(e,t){super(e,t)}},ie=class extends L{vertices;constructor(e,t,r,n){super(r,n),this.vertices=[e,t]}},Se=class extends D{constructor(){super(),this._edges=new Map}_edges;get edges(){return this._edges}createVertex(e,t){return new ne(e,t??e)}createEdge(e,t,r,n){return new ie(e,t,r??1,n)}getEdge(e,t){let r=[];if(e!==null&&t!==null){let n=this._getVertex(e),i=this._getVertex(t);n&&i&&(r=this._edges.get(n)?.filter(s=>s.vertices.includes(i.key)))}return r&&r[0]||null}deleteEdgeBetween(e,t){let r=this._getVertex(e),n=this._getVertex(t);if(!r||!n)return null;let i=this._edges.get(r),s=null;i&&(s=K(i,l=>l.vertices.includes(n.key))[0]||null);let o=this._edges.get(n);return o&&K(o,l=>l.vertices.includes(r.key)),s}deleteEdge(e){return this.deleteEdgeBetween(e.vertices[0],e.vertices[1])}degreeOf(e){let t=this._getVertex(e);return t&&this._edges.get(t)?.length||0}edgesOf(e){let t=this._getVertex(e);return t?this._edges.get(t)||[]:[]}edgeSet(){let e=new Set;return this._edges.forEach(t=>{t.forEach(r=>{e.add(r)})}),[...e]}getNeighbors(e){let t=[],r=this._getVertex(e);if(r){let n=this.edgesOf(r);for(let i of n){let s=this._getVertex(i.vertices.filter(o=>o!==r.key)[0]);s&&t.push(s)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.vertices[0],e.vertices[1]))return null;let t=this._getVertex(e.vertices[0]),r=this._getVertex(e.vertices[1]);return t&&r?[t,r]:null}_addEdgeOnly(e){for(let t of e.vertices){let r=this._getVertex(t);if(r===null)return!1;if(r){let n=this._edges.get(r);n?n.push(e):this._edges.set(r,[e])}}return!0}};var se=class extends I{lat;long;constructor(e,t,r,n){super(e,t),this.lat=r,this.long=n}},oe=class extends A{constructor(e,t,r,n){super(e,t,r,n)}},De=class extends Q{constructor(e,t){super(),this._origin=e,this._bottomRight=t}_origin=[0,0];get origin(){return this._origin}_bottomRight;get bottomRight(){return this._bottomRight}createVertex(e,t,r=this.origin[0],n=this.origin[1]){return new se(e,t,r,n)}createEdge(e,t,r,n){return new oe(e,t,r,n)}};var X=(t=>(t.ITERATIVE="ITERATIVE",t.RECURSIVE="RECURSIVE",t))(X||{}),le=(o=>(o.ROOT="ROOT",o.LEFT="LEFT",o.RIGHT="RIGHT",o.ROOT_LEFT="ROOT_LEFT",o.ROOT_RIGHT="ROOT_RIGHT",o.ISOLATED="ISOLATED",o.MAL_NODE="MAL_NODE",o))(le||{});var Ie=(t=>(t[t.RED=1]="RED",t[t.BLACK=0]="BLACK",t))(Ie||{});var We=(r=>(r.VAL="VAL",r.NODE="NODE",r.ID="ID",r))(We||{});var ae=(r=>(r.lt="lt",r.eq="eq",r.gt="gt",r))(ae||{});var O=class{key;value;parent;constructor(e,t){this.key=e,this.value=t}_left;get left(){return this._left}set left(e){e&&(e.parent=this),this._left=e}_right;get right(){return this._right}set right(e){e&&(e.parent=this),this._right=e}get familyPosition(){let e=this;return this.parent?this.parent.left===e?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===e?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}},Y=class{iterationType="ITERATIVE";constructor(e){if(e!==void 0){let{iterationType:t="ITERATIVE"}=e;this.iterationType=t}}_root=null;get root(){return this._root}_size=0;get size(){return this._size}createNode(e,t){return new O(e,t)}clear(){this._setRoot(null),this._size=0}isEmpty(){return this.size===0}add(e,t){let r=(s,o)=>{let l=new C([s]);for(;l.size>0;){let h=l.shift();if(h){if(o&&h.key===o.key){h.value=o.value;return}let d=this._addTo(o,h);if(d!==void 0)return d;h.left&&l.push(h.left),h.right&&l.push(h.right)}else return}},n,i;if(e===null)i=null;else if(typeof e=="number")i=this.createNode(e,t);else if(e instanceof O)i=e;else return;return this.root?n=r(this.root,i):(this._setRoot(i),i!==null?this._size=1:this._size=0,n=this.root),n}addMany(e,t){return e.map((r,n)=>{if(r instanceof O)return this.add(r.key,r.value);if(r===null)return this.add(null);let i=t?.[n];return this.add(r,i)})}refill(e,t){return this.clear(),e.length===this.addMany(e,t).length}delete(e,t=this.defaultOneParamCallback){let r=[];if(!this.root)return r;e instanceof O&&(t=l=>l);let n=this.getNode(e,t);if(!n)return r;let i=n?.parent?n.parent:null,s=null,o=n;if(n.left){let l=n.left?this.getRightMost(n.left):null;if(l){let h=l.parent;o=this._swap(n,l),h&&(h.right===l?h.right=l.left:h.left=l.left,s=h)}}else if(!i)this._setRoot(null);else{let{familyPosition:l}=n;l==="LEFT"||l==="ROOT_LEFT"?i.left=n.right:(l==="RIGHT"||l==="ROOT_RIGHT")&&(i.right=n.right),s=i}return this._size=this.size-1,r.push({deleted:o,needBalanced:s}),r}getDepth(e,t=this.root){typeof e=="number"&&(e=this.getNode(e)),typeof t=="number"&&(t=this.getNode(t));let r=0;for(;e?.parent;){if(e===t)return r;r++,e=e.parent}return r}getHeight(e=this.root,t=this.iterationType){if(typeof e=="number"&&(e=this.getNode(e)),!e)return-1;if(t==="RECURSIVE"){let r=n=>{if(!n)return-1;let i=r(n.left),s=r(n.right);return Math.max(i,s)+1};return r(e)}else{if(!e)return-1;let r=[{node:e,depth:0}],n=0;for(;r.length>0;){let{node:i,depth:s}=r.pop();i.left&&r.push({node:i.left,depth:s+1}),i.right&&r.push({node:i.right,depth:s+1}),n=Math.max(n,s)}return n}}getMinHeight(e=this.root,t=this.iterationType){if(!e)return-1;if(t==="RECURSIVE"){let r=n=>{if(!n||!n.left&&!n.right)return 0;let i=r(n.left),s=r(n.right);return Math.min(i,s)+1};return r(e)}else{let r=[],n=e,i=null,s=new Map;for(;r.length>0||n;)if(n)r.push(n),n=n.left;else if(n=r[r.length-1],!n.right||i===n.right){if(n=r.pop(),n){let o=n.left?s.get(n.left)??-1:-1,l=n.right?s.get(n.right)??-1:-1;s.set(n,1+Math.min(o,l)),i=n,n=null}}else n=n.right;return s.get(e)??-1}}isPerfectlyBalanced(e=this.root){return this.getMinHeight(e)+1>=this.getHeight(e)}getNodes(e,t=this.defaultOneParamCallback,r=!1,n=this.root,i=this.iterationType){if(!n)return[];e instanceof O&&(t=o=>o);let s=[];if(i==="RECURSIVE"){let o=l=>{t(l)===e&&(s.push(l),r)||!l.left&&!l.right||(l.left&&o(l.left),l.right&&o(l.right))};o(n)}else{let o=new C([n]);for(;o.size>0;){let l=o.shift();if(l){if(t(l)===e&&(s.push(l),r))return s;l.left&&o.push(l.left),l.right&&o.push(l.right)}}}return s}has(e,t=this.defaultOneParamCallback,r=this.root,n=this.iterationType){return e instanceof O&&(t=i=>i),this.getNodes(e,t,!0,r,n).length>0}getNode(e,t=this.defaultOneParamCallback,r=this.root,n=this.iterationType){return e instanceof O&&(t=i=>i),this.getNodes(e,t,!0,r,n)[0]??null}get(e,t=this.defaultOneParamCallback,r=this.root,n=this.iterationType){return e instanceof O&&(t=i=>i),this.getNode(e,t,r,n)?.value??void 0}getPathToRoot(e,t=!0){let r=[];for(;e.parent;)r.push(e),e=e.parent;return r.push(e),t?r.reverse():r}getLeftMost(e=this.root,t=this.iterationType){if(typeof e=="number"&&(e=this.getNode(e)),!e)return e;if(t==="RECURSIVE"){let r=n=>n.left?r(n.left):n;return r(e)}else{let r=te(n=>n.left?r.cont(n.left):n);return r(e)}}getRightMost(e=this.root,t=this.iterationType){if(!e)return e;if(t==="RECURSIVE"){let r=n=>n.right?r(n.right):n;return r(e)}else{let r=te(n=>n.right?r.cont(n.right):n);return r(e)}}isSubtreeBST(e,t=this.iterationType){if(!e)return!0;if(t==="RECURSIVE"){let r=(n,i,s)=>n?n.key<=i||n.key>=s?!1:r(n.left,i,n.key)&&r(n.right,n.key,s):!0;return r(e,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER)}else{let r=[],n=Number.MIN_SAFE_INTEGER,i=e;for(;i||r.length>0;){for(;i;)r.push(i),i=i.left;if(i=r.pop(),!i||n>=i.key)return!1;n=i.key,i=i.right}return!0}}isBST(e=this.iterationType){return this.root===null?!0:this.isSubtreeBST(this.root,e)}subTreeTraverse(e=this.defaultOneParamCallback,t=this.root,r=this.iterationType,n=!1){typeof t=="number"&&(t=this.getNode(t));let i=[];if(!t)return i;if(r==="RECURSIVE"){let s=o=>{o!==void 0&&(i.push(e(o)),n?(o!==null&&o.left!==void 0&&s(o.left),o!==null&&o.right!==void 0&&s(o.right)):(o!==null&&o.left&&s(o.left),o!==null&&o.right&&s(o.right)))};s(t)}else{let s=[t];for(;s.length>0;){let o=s.pop();o!==void 0&&(i.push(e(o)),n?(o!==null&&o.right!==void 0&&s.push(o.right),o!==null&&o.left!==void 0&&s.push(o.left)):(o!==null&&o.right&&s.push(o.right),o!==null&&o.left&&s.push(o.left)))}}return i}dfs(e=this.defaultOneParamCallback,t="in",r=this.root,n="ITERATIVE",i=!1){if(!r)return[];let s=[];if(n==="RECURSIVE"){let o=l=>{switch(t){case"in":i?(l!==null&&l.left!==void 0&&o(l.left),s.push(e(l)),l!==null&&l.right!==void 0&&o(l.right)):(l!==null&&l.left&&o(l.left),s.push(e(l)),l!==null&&l.right&&o(l.right));break;case"pre":i?(s.push(e(l)),l!==null&&l.left!==void 0&&o(l.left),l!==null&&l.right!==void 0&&o(l.right)):(s.push(e(l)),l!==null&&l.left&&o(l.left),l!==null&&l.right&&o(l.right));break;case"post":i?(l!==null&&l.left!==void 0&&o(l.left),l!==null&&l.right!==void 0&&o(l.right),s.push(e(l))):(l!==null&&l.left&&o(l.left),l!==null&&l.right&&o(l.right),s.push(e(l)));break}};o(r)}else{let o=[{opt:0,node:r}];for(;o.length>0;){let l=o.pop();if(l!==void 0){if(i){if(l.node===void 0)continue}else if(l.node===null||l.node===void 0)continue;if(l.opt===1)s.push(e(l.node));else switch(t){case"in":l.node&&o.push({opt:0,node:l.node.right}),o.push({opt:1,node:l.node}),l.node&&o.push({opt:0,node:l.node.left});break;case"pre":l.node&&o.push({opt:0,node:l.node.right}),l.node&&o.push({opt:0,node:l.node.left}),o.push({opt:1,node:l.node});break;case"post":o.push({opt:1,node:l.node}),l.node&&o.push({opt:0,node:l.node.right}),l.node&&o.push({opt:0,node:l.node.left});break;default:l.node&&o.push({opt:0,node:l.node.right}),o.push({opt:1,node:l.node}),l.node&&o.push({opt:0,node:l.node.left});break}}}}return s}bfs(e=this.defaultOneParamCallback,t=this.root,r=this.iterationType,n=!1){if(!t)return[];let i=[];if(r==="RECURSIVE"){let s=new C([t]),o=l=>{if(s.size===0)return;let h=s.shift();i.push(e(h)),n?(h&&h.left!==void 0&&s.push(h.left),h&&h.right!==void 0&&s.push(h.right)):(h.left&&s.push(h.left),h.right&&s.push(h.right)),o(l+1)};o(0)}else{let s=new C([t]);for(;s.size>0;){let o=s.size;for(let l=0;l<o;l++){let h=s.shift();i.push(e(h)),n?(h!==null&&h.left!==void 0&&s.push(h.left),h!==null&&h.right!==void 0&&s.push(h.right)):(h.left&&s.push(h.left),h.right&&s.push(h.right))}}}return i}listLevels(e=this.defaultOneParamCallback,t=this.root,r=this.iterationType,n=!1){if(!t)return[];let i=[];if(r==="RECURSIVE"){let s=(o,l)=>{i[l]||(i[l]=[]),i[l].push(e(o)),n?(o&&o.left!==void 0&&s(o.left,l+1),o&&o.right!==void 0&&s(o.right,l+1)):(o&&o.left&&s(o.left,l+1),o&&o.right&&s(o.right,l+1))};s(t,0)}else{let s=[[t,0]];for(;s.length>0;){let o=s.pop(),[l,h]=o;i[h]||(i[h]=[]),i[h].push(e(l)),n?(l&&l.right!==void 0&&s.push([l.right,h+1]),l&&l.left!==void 0&&s.push([l.left,h+1])):(l&&l.right&&s.push([l.right,h+1]),l&&l.left&&s.push([l.left,h+1]))}}return i}getPredecessor(e){if(e.left){let t=e.left;for(;!t||t.right&&t.right!==e;)t&&(t=t.right);return t}else return e}getSuccessor(e){if(e.right)return this.getLeftMost(e.right);let t=e.parent;for(;t&&t&&e===t.right;)e=t,t=t.parent;return t}morris(e=this.defaultOneParamCallback,t="in",r=this.root){if(r===null)return[];let n=[],i=r,s=l=>{let h=null,d=null;for(;l;)d=l.right,l.right=h,h=l,l=d;return h},o=l=>{let h=s(l),d=h;for(;d;)n.push(e(d)),d=d.right;s(h)};switch(t){case"in":for(;i;){if(i.left){let l=this.getPredecessor(i);if(l.right)l.right=null;else{l.right=i,i=i.left;continue}}n.push(e(i)),i=i.right}break;case"pre":for(;i;){if(i.left){let l=this.getPredecessor(i);if(l.right)l.right=null;else{l.right=i,n.push(e(i)),i=i.left;continue}}else n.push(e(i));i=i.right}break;case"post":for(;i;){if(i.left){let l=this.getPredecessor(i);if(l.right===null){l.right=i,i=i.left;continue}else l.right=null,o(i.left)}i=i.right}o(r);break}return n}*[Symbol.iterator](e=this.root){if(e)if(this.iterationType==="ITERATIVE"){let t=[],r=e;for(;r||t.length>0;){for(;r;)t.push(r),r=r.left;r=t.pop(),r&&(yield r.key),r&&(r=r.right)}}else e.left&&(yield*this[Symbol.iterator](e.left)),yield e.key,e.right&&(yield*this[Symbol.iterator](e.right))}defaultOneParamCallback=e=>e.key;_swap(e,t){let{key:r,value:n}=t,i=this.createNode(r,n);return i&&(t.key=e.key,t.value=e.value,e.key=i.key,e.value=i.value),t}_addTo(e,t){if(t)return t.left===void 0?(t.left=e,e&&(this._size=this.size+1),t.left):t.right===void 0?(t.right=e,e&&(this._size=this.size+1),t.right):void 0}_setRoot(e){e&&(e.parent=void 0),this._root=e}};var S=class extends O{constructor(e,t){super(e,t)}},$=class extends Y{constructor(e){if(super(e),e!==void 0){let{comparator:t}=e;t!==void 0&&(this._comparator=t)}}createNode(e,t){return new S(e,t)}add(e,t){let r=null,n=null;if(e instanceof S?n=e:typeof e=="number"?n=this.createNode(e,t):e===null&&(n=null),this.root===null)this._setRoot(n),this._size=this.size+1,r=this.root;else{let i=this.root,s=!0;for(;s;)i!==null&&n!==null?this._compare(i.key,n.key)==="eq"?(n&&(i.value=n.value),s=!1,r=i):this._compare(i.key,n.key)==="gt"?i.left===void 0?(n&&(n.parent=i),i.left=n,this._size=this.size+1,s=!1,r=i.left):i.left&&(i=i.left):this._compare(i.key,n.key)==="lt"&&(i.right===void 0?(n&&(n.parent=i),i.right=n,this._size=this.size+1,s=!1,r=i.right):i.right&&(i=i.right)):s=!1}return r}addMany(e,t,r=!0,n=this.iterationType){function i(b){return b.indexOf(null)===-1}if(!r||!i(e))return super.addMany(e,t);let s=[],o=e.map((b,N)=>[b,t?.[N]]),l=[];function h(b){for(let[N]of b)if(N instanceof S)return!0;return!1}function d(b){for(let[N]of b)if(typeof N=="number")return!0;return!1}let g=[],y=[];if(h(o))l=o.sort((b,N)=>b[0].key-N[0].key);else if(d(o))l=o.sort((b,N)=>b[0]-N[0]);else throw new Error("Invalid input keysOrNodes");g=l.map(([b])=>b),y=l.map(([,b])=>b);let x=(b,N)=>{if(b.length===0)return;let u=Math.floor((b.length-1)/2),f=this.add(b[u],N?.[u]);s.push(f),x(b.slice(0,u),N?.slice(0,u)),x(b.slice(u+1),N?.slice(u+1))},_=()=>{let N=[[0,l.length-1]];for(;N.length>0;){let u=N.pop();if(u){let[f,c]=u;if(f<=c){let m=f+Math.floor((c-f)/2),p=this.add(g[m],y?.[m]);s.push(p),N.push([m+1,c]),N.push([f,m-1])}}}};return n==="RECURSIVE"?x(g,y):_(),s}lastKey(e=this.root,t=this.iterationType){return this._compare(0,1)==="lt"?this.getRightMost(e,t)?.key??0:this._compare(0,1)==="gt"?this.getLeftMost(e,t)?.key??0:this.getRightMost(e,t)?.key??0}getNodes(e,t=this.defaultOneParamCallback,r=!1,n=this.root,i=this.iterationType){if(!n)return[];let s=[];if(i==="RECURSIVE"){let o=l=>{t(l)===e&&(s.push(l),r)||!l.left&&!l.right||(t===this.defaultOneParamCallback?(this._compare(l.key,e)==="gt"&&l.left&&o(l.left),this._compare(l.key,e)==="lt"&&l.right&&o(l.right)):(l.left&&o(l.left),l.right&&o(l.right)))};o(n)}else{let o=new C([n]);for(;o.size>0;){let l=o.shift();if(l){if(t(l)===e&&(s.push(l),r))return s;t===this.defaultOneParamCallback?(this._compare(l.key,e)==="gt"&&l.left&&o.push(l.left),this._compare(l.key,e)==="lt"&&l.right&&o.push(l.right)):(l.left&&o.push(l.left),l.right&&o.push(l.right))}}}return s}lesserOrGreaterTraverse(e=this.defaultOneParamCallback,t="lt",r=this.root,n=this.iterationType){typeof r=="number"&&(r=this.getNode(r));let i=[];if(!r)return i;let s=r.key;if(!this.root)return i;if(n==="RECURSIVE"){let o=l=>{this._compare(l.key,s)===t&&i.push(e(l)),!(!l.left&&!l.right)&&(l.left&&this._compare(l.left.key,s)===t&&o(l.left),l.right&&this._compare(l.right.key,s)===t&&o(l.right))};return o(this.root),i}else{let o=new C([this.root]);for(;o.size>0;){let l=o.shift();l&&(this._compare(l.key,s)===t&&i.push(e(l)),l.left&&this._compare(l.left.key,s)===t&&o.push(l.left),l.right&&this._compare(l.right.key,s)===t&&o.push(l.right))}return i}}perfectlyBalance(e=this.iterationType){let t=this.dfs(n=>n,"in"),r=t.length;if(this.clear(),t.length<1)return!1;if(e==="RECURSIVE"){let n=(i,s)=>{if(i>s)return;let o=i+Math.floor((s-i)/2),l=t[o];this.add(l.key,l.value),n(i,o-1),n(o+1,s)};return n(0,r-1),!0}else{let n=[[0,r-1]];for(;n.length>0;){let i=n.pop();if(i){let[s,o]=i;if(s<=o){let l=s+Math.floor((o-s)/2),h=t[l];this.add(h.key,h.value),n.push([l+1,o]),n.push([s,l-1])}}}return!0}}isAVLBalanced(e=this.iterationType){if(!this.root)return!0;let t=!0;if(e==="RECURSIVE"){let r=n=>{if(!n)return 0;let i=r(n.left),s=r(n.right);return Math.abs(i-s)>1&&(t=!1),Math.max(i,s)+1};r(this.root)}else{let r=[],n=this.root,i=null,s=new Map;for(;r.length>0||n;)if(n)r.push(n),n=n.left;else if(n=r[r.length-1],!n.right||i===n.right){if(n=r.pop(),n){let o=n.left?s.get(n.left)??-1:-1,l=n.right?s.get(n.right)??-1:-1;if(Math.abs(o-l)>1)return!1;s.set(n,1+Math.max(o,l)),i=n,n=null}}else n=n.right}return t}_comparator=(e,t)=>e-t;_compare(e,t){let r=this._comparator(e,t);return r>0?"gt":r<0?"lt":"eq"}};var Fe=class{_freq;_max;constructor({frequency:e=0,max:t}){this._freq=e,this._max=t,this._freqMap={0:0},this._msb=Be(t),this._negativeCount=e<0?t:0}_freqMap;get freqMap(){return this._freqMap}_msb;get msb(){return this._msb}_negativeCount;get negativeCount(){return this._negativeCount}get freq(){return this._freq}get max(){return this._max}readSingle(e){return this._checkIndex(e),this._readSingle(e)}update(e,t){this._checkIndex(e);let r=this._readSingle(e);this._update(e,t),this._updateNegativeCount(r,r+t)}writeSingle(e,t){this._checkIndex(e),this._writeSingle(e,t)}read(e){if(!Number.isInteger(e))throw new Error("Invalid count");return this._read(Math.max(Math.min(e,this.max),0))}lowerBound(e){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(e,(t,r)=>t<r)}upperBound(e){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(e,(t,r)=>t<=r)}getPrefixSum(e){this._checkIndex(e),e++;let t=0;for(;e>0;)t+=this._getFrequency(e),e-=e&-e;return t}_getFrequency(e){return e in this.freqMap?this.freqMap[e]:this.freq*(e&-e)}_updateFrequency(e,t){this.freqMap[e]=this._getFrequency(e)+t}_checkIndex(e){if(!Number.isInteger(e))throw new Error("Invalid index: Index must be an integer.");if(e<0||e>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(e){e=e+1;let t=this._getFrequency(e),r=e-(e&-e);for(e--;e!==r;)t-=this._getFrequency(e),e-=e&-e;return t}_updateNegativeCount(e,t){e<0&&t>=0?this._negativeCount--:e>=0&&t<0&&this._negativeCount++}_update(e,t){for(e=e+1;e<=this.max;)this._updateFrequency(e,t),e+=e&-e}_writeSingle(e,t){let r=this._readSingle(e);this._update(e,t-r),this._updateNegativeCount(r,t)}_read(e){let t=e,r=0;for(;t;)r+=this._getFrequency(t),t-=t&-t;return r}_binarySearch(e,t){let r=0,n=this.msb<<1,i=e;for(;n>r+1;){let s=r+n>>1,o=this._getFrequency(s);s<=this.max&&t(o,i)?(i-=o,r=s):n=s}return r}};var H=class{start=0;end=0;value=null;sum=0;left=null;right=null;constructor(e,t,r,n){this.start=e,this.end=t,this.sum=r,this.value=n||null}},ze=class{constructor(e,t,r){t=t||0,r=r||e.length-1,this._values=e,this._start=t,this._end=r,e.length>0?this._root=this.build(t,r):(this._root=null,this._values=[])}_values=[];get values(){return this._values}_start=0;get start(){return this._start}_end;get end(){return this._end}_root;get root(){return this._root}build(e,t){if(e>t)return new H(e,t,0);if(e===t)return new H(e,t,this._values[e]);let r=e+Math.floor((t-e)/2),n=this.build(e,r),i=this.build(r+1,t),s=new H(e,t,n.sum+i.sum);return s.left=n,s.right=i,s}updateNode(e,t,r){let n=this.root||null;if(!n)return;let i=(s,o,l,h)=>{if(s.start===s.end&&s.start===o){s.sum=l,h!==void 0&&(s.value=h);return}let d=s.start+Math.floor((s.end-s.start)/2);o<=d?s.left&&i(s.left,o,l,h):s.right&&i(s.right,o,l,h),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};i(n,e,t,r)}querySumByRange(e,t){let r=this.root||null;if(!r)return 0;if(e<0||t>=this.values.length||e>t)return NaN;let n=(i,s,o)=>{if(s<=i.start&&o>=i.end)return i.sum;let l=i.start+Math.floor((i.end-i.start)/2);if(o<=l)return i.left?n(i.left,s,o):NaN;if(s>l)return i.right?n(i.right,s,o):NaN;{let h=0,d=0;return i.left&&(h=n(i.left,s,l)),i.right&&(d=n(i.right,l+1,o)),h+d}};return n(r,e,t)}};var F=class extends S{height;constructor(e,t){super(e,t),this.height=0}},J=class extends ${constructor(e){super(e)}createNode(e,t){return new F(e,t)}add(e,t){let r=super.add(e,t);return r&&this._balancePath(r),r}delete(e,t=this.defaultOneParamCallback){e instanceof F&&(t=n=>n);let r=super.delete(e,t);for(let{needBalanced:n}of r)n&&this._balancePath(n);return r}_swap(e,t){let{key:r,value:n,height:i}=t,s=this.createNode(r,n);return s&&(s.height=i,t.key=e.key,t.value=e.value,t.height=e.height,e.key=s.key,e.value=s.value,e.height=s.height),t}_balanceFactor(e){return e.right?e.left?e.right.height-e.left.height:+e.height:-e.height}_updateHeight(e){if(!e.left&&!e.right)e.height=0;else if(e.left)e.right?e.height=1+Math.max(e.right.height,e.left.height):e.height=1+e.left.height;else{let t=e.right?e.right.height:0;e.height=1+t}}_balancePath(e){let t=this.getPathToRoot(e,!1);for(let r=0;r<t.length;r++){let n=t[r];switch(this._updateHeight(n),this._balanceFactor(n)){case-2:n&&n.left&&(this._balanceFactor(n.left)<=0?this._balanceLL(n):this._balanceLR(n));break;case 2:n&&n.right&&(this._balanceFactor(n.right)>=0?this._balanceRR(n):this._balanceRL(n))}}}_balanceLL(e){let t=e.parent,r=e.left;e.parent=r,r&&r.right&&(r.right.parent=e),r&&(r.parent=t),e===this.root?r&&this._setRoot(r):t?.left===e?t.left=r:t&&(t.right=r),r&&(e.left=r.right,r.right=e),this._updateHeight(e),r&&this._updateHeight(r)}_balanceLR(e){let t=e.parent,r=e.left,n=null;r&&(n=r.right),e&&(e.parent=n),r&&(r.parent=n),n&&(n.left&&(n.left.parent=r),n.right&&(n.right.parent=e),n.parent=t),e===this.root?n&&this._setRoot(n):t&&(t.left===e?t.left=n:t.right=n),n&&(e.left=n.right,r&&(r.right=n.left),n.left=r,n.right=e),this._updateHeight(e),r&&this._updateHeight(r),n&&this._updateHeight(n)}_balanceRR(e){let t=e.parent,r=e.right;e.parent=r,r&&(r.left&&(r.left.parent=e),r.parent=t),e===this.root?r&&this._setRoot(r):t&&(t.left===e?t.left=r:t.right=r),r&&(e.right=r.left,r.left=e),this._updateHeight(e),r&&this._updateHeight(r)}_balanceRL(e){let t=e.parent,r=e.right,n=null;r&&(n=r.left),e.parent=n,r&&(r.parent=n),n&&(n.left&&(n.left.parent=e),n.right&&(n.right.parent=r),n.parent=t),e===this.root?n&&this._setRoot(n):t&&(t.left===e?t.left=n:t.right=n),n&&(e.right=n.left),r&&n&&(r.left=n.right),n&&(n.left=e),n&&(n.right=r),this._updateHeight(e),r&&this._updateHeight(r),n&&this._updateHeight(n)}};var Z=class{key;parent;left;right;color=0;constructor(e,t=0){this.key=e,this.color=t,this.parent=null,this.left=null,this.right=null}},T=new Z(0),Ae=class{constructor(){this._root=T}_root;get root(){return this._root}_size=0;get size(){return this._size}add(e){let t=new Z(e,1);t.left=T,t.right=T;let r=null,n=this.root;for(;n!==T;)r=n,t.key<n.key?n=n.left:n=n.right;if(t.parent=r,r===null?this._root=t:t.key<r.key?r.left=t:r.right=t,t.parent===null){t.color=0,this._size++;return}if(t.parent.parent===null){this._size++;return}this._fixInsert(t),this._size++}delete(e){(r=>{let n=T,i,s;for(;r!==T;)r.key===e&&(n=r),r.key<=e?r=r.right:r=r.left;if(n===T){this._size--;return}s=n;let o=s.color;n.left===T?(i=n.right,this._rbTransplant(n,n.right)):n.right===T?(i=n.left,this._rbTransplant(n,n.left)):(s=this.getLeftMost(n.right),o=s.color,i=s.right,s.parent===n?i.parent=s:(this._rbTransplant(s,s.right),s.right=n.right,s.right.parent=s),this._rbTransplant(n,s),s.left=n.left,s.left.parent=s,s.color=n.color),o===0&&this._fixDelete(i),this._size--})(this.root)}isRealNode(e){return e!==T&&e!==null}getNode(e,t=this.root){let r=n=>this.isRealNode(n)?e===n.key?n:e<n.key?r(n.left):r(n.right):null;return r(t)}getLeftMost(e=this.root){for(;e.left!==null&&e.left!==T;)e=e.left;return e}getRightMost(e){for(;e.right!==null&&e.right!==T;)e=e.right;return e}getSuccessor(e){if(e.right!==T)return this.getLeftMost(e.right);let t=e.parent;for(;t!==T&&t!==null&&e===t.right;)e=t,t=t.parent;return t}getPredecessor(e){if(e.left!==T)return this.getRightMost(e.left);let t=e.parent;for(;t!==T&&e===t.left;)e=t,t=t.parent;return t}clear(){this._root=T,this._size=0}print(e=this.root){let t=n=>{let[i,,,]=r(n);for(let s of i)console.log(s)},r=n=>{if(n===null)return[[],0,0,0];if(n.right===null&&n.left===null){let f=`${n.key}`,c=f.length,m=1,p=Math.floor(c/2);return[[f],c,m,p]}if(n.right===null){let[f,c,m,p]=r(n.left),E=`${n.key}`,V=E.length,k=" ".repeat(p+1)+"_".repeat(c-p-1)+E,z=" ".repeat(p)+"/"+" ".repeat(c-p-1+V),ue=f.map(fe=>fe+" ".repeat(V));return[[k,z,...ue],c+V,m+2,c+Math.floor(V/2)]}if(n.left===null){let[f,c,m,p]=r(n.right),E=`${n.key}`,V=E.length,k=E+"_".repeat(V)+" ".repeat(c-V),z=" ".repeat(p+V)+"\\"+" ".repeat(c-V-1),ue=f.map(fe=>" ".repeat(p)+fe);return[[k,z,...ue],c+V,m+2,Math.floor(p/2)]}let[i,s,o,l]=r(n.left),[h,d,g,y]=r(n.right),x=`${n.key}`,_=x.length,b=" ".repeat(l+1)+"_".repeat(s-l-1)+x+"_".repeat(y)+" ".repeat(d-y),N=" ".repeat(l)+"/"+" ".repeat(s-l-1+_+y)+"\\"+" ".repeat(d-y-1);o<g?i.push(...new Array(g-o).fill(" ".repeat(s))):g<o&&h.push(...new Array(o-g).fill(" ".repeat(d)));let u=i.map((f,c)=>f+" ".repeat(_)+h[c]);return[[b,N,...u],s+d+_,Math.max(o,g)+2,s+Math.floor(_/2)]};t(e)}_leftRotate(e){let t=e.right;e.right=t.left,t.left!==T&&(t.left.parent=e),t.parent=e.parent,e.parent===null?this._root=t:e===e.parent.left?e.parent.left=t:e.parent.right=t,t.left=e,e.parent=t}_rightRotate(e){let t=e.left;e.left=t.right,t.right!==T&&(t.right.parent=e),t.parent=e.parent,e.parent===null?this._root=t:e===e.parent.right?e.parent.right=t:e.parent.left=t,t.right=e,e.parent=t}_fixDelete(e){let t;for(;e!==this.root&&e.color===0;)e===e.parent.left?(t=e.parent.right,t.color===1&&(t.color=0,e.parent.color=1,this._leftRotate(e.parent),t=e.parent.right),t.left!==null&&t.left.color===0&&t.right.color===0?(t.color=1,e=e.parent):(t.right.color===0&&(t.left.color=0,t.color=1,this._rightRotate(t),t=e.parent.right),t.color=e.parent.color,e.parent.color=0,t.right.color=0,this._leftRotate(e.parent),e=this.root)):(t=e.parent.left,t.color===1&&(t.color=0,e.parent.color=1,this._rightRotate(e.parent),t=e.parent.left),t.right.color===0&&t.right.color===0?(t.color=1,e=e.parent):(t.left.color===0&&(t.right.color=0,t.color=1,this._leftRotate(t),t=e.parent.left),t.color=e.parent.color,e.parent.color=0,t.left.color=0,this._rightRotate(e.parent),e=this.root));e.color=0}_rbTransplant(e,t){e.parent===null?this._root=t:e===e.parent.left?e.parent.left=t:e.parent.right=t,t.parent=e.parent}_fixInsert(e){let t;for(;e.parent.color===1&&(e.parent===e.parent.parent.right?(t=e.parent.parent.left,t.color===1?(t.color=0,e.parent.color=0,e.parent.parent.color=1,e=e.parent.parent):(e===e.parent.left&&(e=e.parent,this._rightRotate(e)),e.parent.color=0,e.parent.parent.color=1,this._leftRotate(e.parent.parent))):(t=e.parent.parent.right,t.color===1?(t.color=0,e.parent.color=0,e.parent.parent.color=1,e=e.parent.parent):(e===e.parent.right&&(e=e.parent,this._leftRotate(e)),e.parent.color=0,e.parent.parent.color=1,this._rightRotate(e.parent.parent))),e!==this.root););this.root.color=0}};var P=class extends F{count;constructor(e,t,r=1){super(e,t),this.count=r}},He=class extends J{constructor(e){super(e)}_count=0;get count(){return this._count}createNode(e,t,r){return new P(e,t,r)}add(e,t,r=1){let n,i;if(e instanceof P?i=this.createNode(e.key,e.value,e.count):e===null?i=null:i=this.createNode(e,t,r),!this.root)this._setRoot(i),this._size=this.size+1,i&&this._setCount(this.count+i.count),n=this.root;else{let s=this.root,o=!0;for(;o;)s?i&&(this._compare(s.key,i.key)==="eq"?(s.value=i.value,s.count+=i.count,this._setCount(this.count+i.count),o=!1,n=s):this._compare(s.key,i.key)==="gt"?s.left===void 0?(s.left=i,this._size=this.size+1,this._setCount(this.count+i.count),o=!1,n=s.left):s.left&&(s=s.left):this._compare(s.key,i.key)==="lt"&&(s.right===void 0?(s.right=i,this._size=this.size+1,this._setCount(this.count+i.count),o=!1,n=s.right):s.right&&(s=s.right))):o=!1}return n&&this._balancePath(n),n}_addTo(e,t){if(t)return t.left===void 0?(t.left=e,e!==null&&(this._size=this.size+1,this._setCount(this.count+e.count)),t.left):t.right===void 0?(t.right=e,e!==null&&(this._size=this.size+1,this._setCount(this.count+e.count)),t.right):void 0}addMany(e,t){let r=[];for(let n=0;n<e.length;n++){let i=e[n];if(i instanceof P){r.push(this.add(i.key,i.value,i.count));continue}if(i===null){r.push(this.add(NaN,void 0,0));continue}r.push(this.add(i,t?.[n],1))}return r}perfectlyBalance(e=this.iterationType){let t=this.dfs(n=>n,"in"),r=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let n=(i,s)=>{if(i>s)return;let o=i+Math.floor((s-i)/2),l=t[o];this.add(l.key,l.value,l.count),n(i,o-1),n(o+1,s)};return n(0,r-1),!0}else{let n=[[0,r-1]];for(;n.length>0;){let i=n.pop();if(i){let[s,o]=i;if(s<=o){let l=s+Math.floor((o-s)/2),h=t[l];this.add(h.key,h.value,h.count),n.push([l+1,o]),n.push([s,l-1])}}}return!0}}delete(e,t=this.defaultOneParamCallback,r=!1){let n=[];if(!this.root)return n;let i=this.getNode(e,t);if(!i)return n;let s=i?.parent?i.parent:null,o=null,l=i;if(i.count>1&&!r)i.count--,this._setCount(this.count-1);else{if(i.left){let h=i.left?this.getRightMost(i.left):null;if(h){let d=h.parent;l=this._swap(i,h),d&&(d.right===h?d.right=h.left:d.left=h.left,o=d)}}else if(!s)i.right!==void 0&&this._setRoot(i.right);else{let{familyPosition:h}=i;h==="LEFT"||h==="ROOT_LEFT"?s.left=i.right:(h==="RIGHT"||h==="ROOT_RIGHT")&&(s.right=i.right),o=s}this._size=this.size-1,this._setCount(this.count-l.count)}return n.push({deleted:l,needBalanced:o}),o&&this._balancePath(o),n}clear(){super.clear(),this._setCount(0)}_swap(e,t){let{key:r,value:n,count:i,height:s}=t,o=this.createNode(r,n,i);return o&&(o.height=s,t.key=e.key,t.value=e.value,t.count=e.count,t.height=e.height,e.key=o.key,e.value=o.value,e.count=o.count,e.height=o.height),t}_setCount(e){this._count=e}};var Pe=class a{key;value;children;constructor(e,t,r){this.key=e,this.value=t||void 0,this.children=r||[]}addChildren(e){this.children||(this.children=[]),e instanceof a?this.children.push(e):this.children=this.children.concat(e)}getHeight(){let e=0;if(this){let t=(r,n)=>{n>e&&(e=n);let{children:i}=r;if(i)for(let s=0,o=i.length;s<o;s++)t(i[s],n+1)};t(this,0)}return e}};var Ue=class{_matrix;constructor(e){let{row:t,col:r,initialVal:n}=e;this._matrix=new Array(t).fill(void 0).map(()=>new Array(r).fill(n||0))}toArray(){return this._matrix}};var U=class a{constructor(e=0,t=0,r=1){this.x=e;this.y=t;this.w=r}get isZero(){return this.x===0&&this.y===0}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 a(Math.round(this.x),Math.round(this.y))}static add(e,t){return new a(e.x+t.x,e.y+t.y)}static subtract(e,t){return new a(e.x-t.x,e.y-t.y)}static subtractValue(e,t){return new a(e.x-t,e.y-t)}static multiply(e,t){return new a(e.x*t,e.y*t)}static divide(e,t){return new a(e.x/t,e.y/t)}static equals(e,t){return e.x===t.x&&e.y===t.y}static equalsRounded(e,t,r=12){let n=a.abs(a.subtract(e,t));return n.x<r&&n.y<r}static normalize(e){let t=e.length;return t>2220446049250313e-31?a.divide(e,t):e}static truncate(e,t){return e.length>t?a.multiply(a.normalize(e),t):e}static perp(e){return new a(-e.y,e.x)}static reverse(e){return new a(-e.x,-e.y)}static abs(e){return new a(Math.abs(e.x),Math.abs(e.y))}static dot(e,t){return e.x*t.x+e.y*t.y}static distance(e,t){let r=t.y-e.y,n=t.x-e.x;return Math.sqrt(r*r+n*n)}static distanceSq(e,t){let r=t.y-e.y,n=t.x-e.x;return r*r+n*n}static sign(e,t){return e.y*t.x>e.x*t.y?-1:1}static angle(e){let t=new a(0,-1),r=Math.acos(a.dot(e,t)/(e.length*t.length));return a.sign(e,t)===1?Math.PI*2-r:r}static random(e,t){let r=Math.floor(Math.random()*e-e/2),n=Math.floor(Math.random()*t-t/2);return new a(r,n)}zero(){this.x=0,this.y=0}};var je=class a{_matrix;constructor(e){typeof e>"u"?this._matrix=a.identity:e instanceof U?(this._matrix=a.identity,this._matrix[0][0]=e.x,this._matrix[1][0]=e.y,this._matrix[2][0]=e.w):this._matrix=e}static get empty(){return[[],[],[]]}static get identity(){return[[1,0,0],[0,1,0],[0,0,1]]}get m(){return this._matrix}static add(e,t){let r=a.empty;for(let n=0;n<3;n++)for(let i=0;i<3;i++)r[n][i]=e.m[n][i]+t.m[n][i];return new a(r)}static subtract(e,t){let r=a.empty;for(let n=0;n<3;n++)for(let i=0;i<3;i++)r[n][i]=e.m[n][i]-t.m[n][i];return new a(r)}static multiply(e,t){let r=a.empty;for(let n=0;n<3;n++)for(let i=0;i<3;i++){r[n][i]=0;for(let s=0;s<3;s++)r[n][i]+=e.m[n][s]*t.m[s][i]}return new a(r)}static multiplyByValue(e,t){let r=a.empty;for(let n=0;n<3;n++)for(let i=0;i<3;i++)r[n][i]=e.m[n][i]*t;return new a(r)}static multiplyByVector(e,t){return a.multiply(e,new a(t)).toVector()}static view(e,t){let n=e/2,i=t/2,s=Math.cos(Math.PI);return new a([[1,0,n],[0,s*1,i],[0,0,1]])}static scale(e){return a.multiplyByValue(new a,e)}static rotate(e){let t=Math.cos(e),r=Math.sin(e);return new a([[t,-r,0],[r,t,0],[0,0,1]])}static translate(e){return new a([[1,0,e.x],[0,1,e.y],[0,0,e.w]])}toVector(){return new U(this._matrix[0][0],this._matrix[1][0])}};var he=class a{direction;turn;constructor(e,t){this.direction=e,this.turn=()=>new a(t[e],t)}},qe=class{onMove;_matrix;_cur;_character;_VISITED;constructor({matrix:e,turning:t,onMove:r,init:{cur:n,charDir:i,VISITED:s}}){this._matrix=e,this._cur=n,this._character=new he(i,t),this.onMove=r,this.onMove&&this.onMove(this._cur),this._VISITED=s,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){let{direction:e}=this._character;this.check(e)?this.move(e):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(e){let t,r,n=this._matrix,[i,s]=this._cur;switch(e){case"up":if(r=n[i-1],!r)return!1;t=r[s];break;case"right":t=n[i][s+1];break;case"down":if(r=n[i+1],!r)return!1;t=r[s];break;case"left":t=n[i][s-1];break}return t!==void 0&&t!==this._VISITED}move(e){switch(e){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--;break}let[t,r]=this._cur;this._matrix[t][r]=this._VISITED,this.onMove&&this.onMove(this._cur)}};var ee=class{key;children;isEnd;constructor(e){this.key=e,this.isEnd=!1,this.children=new Map}},Ge=class{constructor(e,t=!0){if(this._root=new ee(""),this._caseSensitive=t,e)for(let r of e)this.add(r)}_caseSensitive;get caseSensitive(){return this._caseSensitive}_root;get root(){return this._root}add(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);n||(n=new ee(r),t.children.set(r,n)),t=n}return t.isEnd=!0,!0}has(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);if(!n)return!1;t=n}return t.isEnd}delete(e){e=this._caseProcess(e);let t=!1,r=(n,i)=>{let s=e[i],o=n.children.get(s);return o?i===e.length-1?o.isEnd?(o.children.size>0?o.isEnd=!1:n.children.delete(s),t=!0,!0):!1:r(o,i+1)&&!n.isEnd&&o.children.size===0?(n.children.delete(s),!0):!1:!1};return r(this.root,0),t}getHeight(){let e=this.root,t=0;if(e){let r=(n,i)=>{i>t&&(t=i);let{children:s}=n;if(s)for(let o of s.entries())r(o[1],i+1)};r(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);if(!n)return!1;t=n}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);if(!n)return!1;t=n}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",r=n=>{if(t+=n.key,t!==e&&!n.isEnd)if(n&&n.children&&n.children.size===1)r(Array.from(n.children.values())[0]);else return};return r(this.root),t===e}getLongestCommonPrefix(){let e="",t=r=>{if(e+=r.key,!r.isEnd)if(r&&r.children&&r.children.size===1)t(Array.from(r.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,r=!1){e=this._caseProcess(e);let n=[],i=0;function s(l,h){for(let d of l.children.keys()){let g=l.children.get(d);g!==void 0&&s(g,h.concat(d))}if(l.isEnd){if(i>t-1)return;n.push(h),i++}}let o=this.root;if(e)for(let l of e){let h=o.children.get(l);h&&(o=h)}return(r||o!==this.root)&&s(o,e),n}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};return Ze(tt);})();
1
+ "use strict";var dataStructureTyped=(()=>{var de=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var Xe=Object.prototype.hasOwnProperty;var Ye=(a,e)=>{for(var t in e)de(a,t,{get:e[t],enumerable:!0})},$e=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Qe(e))!Xe.call(a,n)&&n!==t&&de(a,n,{get:()=>e[n],enumerable:!(r=We(e,n))||r.enumerable});return a};var Je=a=>$e(de({},"__esModule",{value:!0}),a);var et={};Ye(et,{AVLTree:()=>J,AVLTreeNode:()=>F,AbstractEdge:()=>L,AbstractGraph:()=>S,AbstractVertex:()=>V,ArrayDeque:()=>Ee,BST:()=>D,BSTNode:()=>k,BinaryIndexedTree:()=>De,BinaryTree:()=>$,BinaryTreeNode:()=>C,CP:()=>le,Character:()=>ae,CoordinateMap:()=>ce,CoordinateSet:()=>pe,Deque:()=>_e,DirectedEdge:()=>A,DirectedGraph:()=>X,DirectedVertex:()=>I,DoublyLinkedList:()=>W,DoublyLinkedListNode:()=>B,FamilyPosition:()=>oe,FibonacciHeap:()=>we,FibonacciHeapNode:()=>te,HashMap:()=>Ne,HashTable:()=>fe,HashTableNode:()=>q,Heap:()=>K,IterationType:()=>Y,LinkedListQueue:()=>Te,MapEdge:()=>se,MapGraph:()=>Se,MapVertex:()=>ie,Matrix2D:()=>Ue,MatrixNTI2D:()=>Pe,MaxHeap:()=>ke,MaxPriorityQueue:()=>Me,MinHeap:()=>Re,MinPriorityQueue:()=>Ke,Navigator:()=>je,ObjectDeque:()=>xe,PriorityQueue:()=>M,Queue:()=>O,RBTNColor:()=>Ie,RBTreeNode:()=>P,RedBlackTree:()=>ze,SegmentTree:()=>Fe,SegmentTreeNode:()=>H,SinglyLinkedList:()=>G,SinglyLinkedListNode:()=>v,SkipList:()=>ye,SkipListNode:()=>Q,Stack:()=>be,THUNK_SYMBOL:()=>Ce,TopologicalProperty:()=>Ge,TreeMap:()=>ge,TreeMultiset:()=>Ae,TreeMultisetNode:()=>U,TreeNode:()=>He,TreeSet:()=>me,Trie:()=>qe,TrieNode:()=>Z,UndirectedEdge:()=>ne,UndirectedGraph:()=>Le,UndirectedVertex:()=>re,Vector2D:()=>j,arrayRemove:()=>R,getMSB:()=>Be,isThunk:()=>Oe,toThunk:()=>ve,trampoline:()=>ee,trampolineAsync:()=>Ze,uuidV4:()=>Ve});var q=class{key;value;next;constructor(e,t){this.key=e,this.value=t,this.next=null}},fe=class a{static DEFAULT_CAPACITY=16;static LOAD_FACTOR=.75;constructor(e=a.DEFAULT_CAPACITY,t){this._hashFn=t||this._defaultHashFn,this._capacity=Math.max(e,a.DEFAULT_CAPACITY),this._size=0,this._buckets=new Array(this._capacity).fill(null)}_capacity;get capacity(){return this._capacity}_size;get size(){return this._size}_buckets;get buckets(){return this._buckets}_hashFn;get hashFn(){return this._hashFn}set(e,t){let r=this._hash(e),n=new q(e,t);if(!this._buckets[r])this._buckets[r]=n;else{let i=this._buckets[r];for(;i;){if(i.key===e){i.value=t;return}if(!i.next)break;i=i.next}i.next=n}this._size++,this._size/this._capacity>=a.LOAD_FACTOR&&this._expand()}get(e){let t=this._hash(e),r=this._buckets[t];for(;r;){if(r.key===e)return r.value;r=r.next}}delete(e){let t=this._hash(e),r=this._buckets[t],n=null;for(;r;){if(r.key===e){n?n.next=r.next:this._buckets[t]=r.next,this._size--,r.next=null;return}n=r,r=r.next}}_defaultHashFn(e){return(typeof e=="string"?this._murmurStringHashFn(e):this._objectHash(e))%this._capacity}_multiplicativeStringHashFn(e){let t=String(e),r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n),s=.618033988749895,l=1<<30;r=(r*s+i)%l}return Math.abs(r)}_murmurStringHashFn(e){let t=String(e),n=0;for(let i=0;i<t.length;i++){let s=t.charCodeAt(i);n=(n^s)*1540483477,n=(n^n>>>15)*668265261,n=n^n>>>15}return Math.abs(n)}_hash(e){return this.hashFn(e)}_stringHash(e){let t=0;for(let r=0;r<e.length;r++)t=t*31+e.charCodeAt(r)&4294967295;return t}_objectHash(e){return this._stringHash(JSON.stringify(e))}_expand(){let e=this._capacity*2,t=new Array(e).fill(null);for(let r of this._buckets){let n=r;for(;n;){let i=this._hash(n.key),s=new q(n.key,n.value);if(!t[i])t[i]=s;else{let l=t[i];for(;l.next;)l=l.next;l.next=s}n=n.next}}this._buckets=t,this._capacity=e}};var ce=class extends Map{constructor(e){super(),e!==void 0&&(this._joint=e)}_joint="_";get joint(){return this._joint}has(e){return super.has(e.join(this._joint))}set(e,t){return super.set(e.join(this._joint),t)}get(e){return super.get(e.join(this._joint))}delete(e){return super.delete(e.join(this._joint))}};var pe=class extends Set{constructor(e){super(),e!==void 0&&(this._joint=e)}_joint="_";get joint(){return this._joint}has(e){return super.has(e.join(this._joint))}add(e){return super.add(e.join(this._joint))}delete(e){return super.delete(e.join(this._joint))}};var ge=class{};var me=class{};var Ne=class{constructor(e=16,t=.75,r){this._initialCapacity=e,this._loadFactor=t,this._capacityMultiplier=2,this._size=0,this._table=new Array(e),this._hashFn=r||(n=>{let i=String(n),s=0;for(let l=0;l<i.length;l++)s+=i.charCodeAt(l);return s%this.table.length})}_initialCapacity;get initialCapacity(){return this._initialCapacity}_loadFactor;get loadFactor(){return this._loadFactor}_capacityMultiplier;get capacityMultiplier(){return this._capacityMultiplier}_size;get size(){return this._size}_table;get table(){return this._table}_hashFn;get hashFn(){return this._hashFn}set(e,t){this.size/this.table.length>=this.loadFactor&&this.resizeTable(this.table.length*this.capacityMultiplier);let n=this._hash(e);this.table[n]||(this.table[n]=[]);for(let i=0;i<this.table[n].length;i++)if(this.table[n][i][0]===e){this.table[n][i][1]=t;return}this.table[n].push([e,t]),this._size++}get(e){let t=this._hash(e);if(this.table[t]){for(let[r,n]of this.table[t])if(r===e)return n}}delete(e){let t=this._hash(e);if(this.table[t]){for(let r=0;r<this.table[t].length;r++)if(this.table[t][r][0]===e){this.table[t].splice(r,1),this._size--,this.size/this.table.length<this.loadFactor/this.capacityMultiplier&&this.resizeTable(this.table.length/this.capacityMultiplier);return}}}*entries(){for(let e of this.table)if(e)for(let[t,r]of e)yield[t,r]}[Symbol.iterator](){return this.entries()}clear(){this._size=0,this._table=new Array(this.initialCapacity)}isEmpty(){return this.size===0}_hash(e){return this._hashFn(e)}resizeTable(e){let t=new Array(e);for(let r of this._table)if(r)for(let[n,i]of r){let s=this._hash(n)%e;t[s]||(t[s]=[]),t[s].push([n,i])}this._table=t}};var v=class{value;next;constructor(e){this.value=e,this.next=null}},G=class a{constructor(){this._head=null,this._tail=null,this._length=0}_head;get head(){return this._head}_tail;get tail(){return this._tail}_length;get length(){return this._length}static fromArray(e){let t=new a;for(let r of e)t.push(r);return t}push(e){let t=new v(e);this.head?(this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++}addLast(e){this.push(e)}pop(){if(!this.head)return;if(this.head===this.tail){let r=this.head.value;return this._head=null,this._tail=null,this._length--,r}let e=this.head;for(;e.next!==this.tail;)e=e.next;let t=this.tail.value;return e.next=null,this._tail=e,this._length--,t}popLast(){return this.pop()}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._length--,e.value}popFirst(){return this.shift()}unshift(e){let t=new v(e);this.head?(t.next=this.head,this._head=t):(this._head=t,this._tail=t),this._length++}addFirst(e){this.unshift(e)}getAt(e){if(e<0||e>=this.length)return;let t=this.head;for(let r=0;r<e;r++)t=t.next;return t.value}getNodeAt(e){let t=this.head;for(let r=0;r<e;r++)t=t.next;return t}deleteAt(e){if(e<0||e>=this.length)return;if(e===0)return this.shift();if(e===this.length-1)return this.pop();let t=this.getNodeAt(e-1),r=t.next;return t.next=r.next,this._length--,r.value}delete(e){if(!e)return!1;let t;e instanceof v?t=e.value:t=e;let r=this.head,n=null;for(;r;){if(r.value===t)return n===null?(this._head=r.next,r===this.tail&&(this._tail=null)):(n.next=r.next,r===this.tail&&(this._tail=n)),this._length--,!0;n=r,r=r.next}return!1}insertAt(e,t){if(e<0||e>this.length)return!1;if(e===0)return this.unshift(t),!0;if(e===this.length)return this.push(t),!0;let r=new v(t),n=this.getNodeAt(e-1);return r.next=n.next,n.next=r,this._length++,!0}isEmpty(){return this.length===0}clear(){this._head=null,this._tail=null,this._length=0}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}reverse(){if(!this.head||this.head===this.tail)return;let e=null,t=this.head,r=null;for(;t;)r=t.next,t.next=e,e=t,t=r;[this._head,this._tail]=[this.tail,this.head]}find(e){let t=this.head;for(;t;){if(e(t.value))return t.value;t=t.next}return null}indexOf(e){let t=0,r=this.head;for(;r;){if(r.value===e)return t;t++,r=r.next}return-1}getNode(e){let t=this.head;for(;t;){if(t.value===e)return t;t=t.next}return null}insertBefore(e,t){if(!this.head)return!1;let r;if(e instanceof v?r=e.value:r=e,this.head.value===r)return this.unshift(t),!0;let n=this.head;for(;n.next;){if(n.next.value===r){let i=new v(t);return i.next=n.next,n.next=i,this._length++,!0}n=n.next}return!1}insertAfter(e,t){let r;if(e instanceof v?r=e:r=this.getNode(e),r){let n=new v(t);return n.next=r.next,r.next=n,r===this.tail&&(this._tail=n),this._length++,!0}return!1}countOccurrences(e){let t=0,r=this.head;for(;r;)r.value===e&&t++,r=r.next;return t}forEach(e){let t=this.head,r=0;for(;t;)e(t.value,r),t=t.next,r++}map(e){let t=new a,r=this.head;for(;r;)t.push(e(r.value)),r=r.next;return t}filter(e){let t=new a,r=this.head;for(;r;)e(r.value)&&t.push(r.value),r=r.next;return t}reduce(e,t){let r=t,n=this.head;for(;n;)r=e(r,n.value),n=n.next;return r}*[Symbol.iterator](){let e=this.head;for(;e;)yield e.value,e=e.next}};var B=class{value;next;prev;constructor(e){this.value=e,this.next=null,this.prev=null}},W=class a{constructor(){this._head=null,this._tail=null,this._length=0}_head;get head(){return this._head}_tail;get tail(){return this._tail}_length;get length(){return this._length}get size(){return this.length}static fromArray(e){let t=new a;for(let r of e)t.push(r);return t}push(e){let t=new B(e);this.head?(t.prev=this.tail,this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++}addLast(e){this.push(e)}pop(){if(!this.tail)return;let e=this.tail;return this.head===this.tail?(this._head=null,this._tail=null):(this._tail=e.prev,this.tail.next=null),this._length--,e.value}popLast(){return this.pop()}shift(){if(!this.head)return;let e=this.head;return this.head===this.tail?(this._head=null,this._tail=null):(this._head=e.next,this.head.prev=null),this._length--,e.value}popFirst(){return this.shift()}unshift(e){let t=new B(e);this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._length++}addFirst(e){this.unshift(e)}getFirst(){return this.head?.value}getLast(){return this.tail?.value}getAt(e){if(e<0||e>=this.length)return;let t=this.head;for(let r=0;r<e;r++)t=t.next;return t.value}getNodeAt(e){if(e<0||e>=this.length)return null;let t=this.head;for(let r=0;r<e;r++)t=t.next;return t}getNode(e){let t=this.head;for(;t;){if(t.value===e)return t;t=t.next}return null}insertAt(e,t){if(e<0||e>this.length)return!1;if(e===0)return this.unshift(t),!0;if(e===this.length)return this.push(t),!0;let r=new B(t),n=this.getNodeAt(e-1),i=n.next;return r.prev=n,r.next=i,n.next=r,i.prev=r,this._length++,!0}insertBefore(e,t){let r;if(e instanceof B?r=e:r=this.getNode(e),r){let n=new B(t);return n.prev=r.prev,r.prev&&(r.prev.next=n),n.next=r,r.prev=n,r===this.head&&(this._head=n),this._length++,!0}return!1}deleteAt(e){if(e<0||e>=this.length)return;if(e===0)return this.shift();if(e===this.length-1)return this.pop();let t=this.getNodeAt(e),r=t.prev,n=t.next;return r.next=n,n.prev=r,this._length--,t.value}delete(e){let t;if(e instanceof B?t=e:t=this.getNode(e),t){if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let r=t.prev,n=t.next;r.next=n,n.prev=r,this._length--}return!0}return!1}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}isEmpty(){return this.length===0}clear(){this._head=null,this._tail=null,this._length=0}find(e){let t=this.head;for(;t;){if(e(t.value))return t.value;t=t.next}return null}indexOf(e){let t=0,r=this.head;for(;r;){if(r.value===e)return t;t++,r=r.next}return-1}findBackward(e){let t=this.tail;for(;t;){if(e(t.value))return t.value;t=t.prev}return null}toArrayBackward(){let e=[],t=this.tail;for(;t;)e.push(t.value),t=t.prev;return e}reverse(){let e=this.head;for([this._head,this._tail]=[this.tail,this.head];e;){let t=e.next;[e.prev,e.next]=[e.next,e.prev],e=t}}forEach(e){let t=this.head,r=0;for(;t;)e(t.value,r),t=t.next,r++}map(e){let t=new a,r=this.head;for(;r;)t.push(e(r.value)),r=r.next;return t}filter(e){let t=new a,r=this.head;for(;r;)e(r.value)&&t.push(r.value),r=r.next;return t}reduce(e,t){let r=t,n=this.head;for(;n;)r=e(r,n.value),n=n.next;return r}insertAfter(e,t){let r;if(e instanceof B?r=e:r=this.getNode(e),r){let n=new B(t);return n.next=r.next,r.next&&(r.next.prev=n),n.prev=r,r.next=n,r===this.tail&&(this._tail=n),this._length++,!0}return!1}*[Symbol.iterator](){let e=this.head;for(;e;)yield e.value,e=e.next}};var Q=class{key;value;forward;constructor(e,t,r){this.key=e,this.value=t,this.forward=new Array(r)}},ye=class{constructor(e=16,t=.5){this._head=new Q(null,null,e),this._level=0,this._maxLevel=e,this._probability=t}_head;get head(){return this._head}_level;get level(){return this._level}_maxLevel;get maxLevel(){return this._maxLevel}_probability;get probability(){return this._probability}add(e,t){let r=new Q(e,t,this._randomLevel()),n=new Array(this.maxLevel).fill(this.head),i=this.head;for(let s=this.level-1;s>=0;s--){for(;i.forward[s]&&i.forward[s].key<e;)i=i.forward[s];n[s]=i}for(let s=0;s<r.forward.length;s++)r.forward[s]=n[s].forward[s],n[s].forward[s]=r;r.forward[0]!==null&&(this._level=Math.max(this.level,r.forward.length))}get(e){let t=this.head;for(let r=this.level-1;r>=0;r--)for(;t.forward[r]&&t.forward[r].key<e;)t=t.forward[r];if(t=t.forward[0],t&&t.key===e)return t.value}has(e){return this.get(e)!==void 0}delete(e){let t=new Array(this.maxLevel).fill(this.head),r=this.head;for(let n=this.level-1;n>=0;n--){for(;r.forward[n]&&r.forward[n].key<e;)r=r.forward[n];t[n]=r}if(r=r.forward[0],r&&r.key===e){for(let n=0;n<this.level&&t[n].forward[n]===r;n++)t[n].forward[n]=r.forward[n];for(;this.level>0&&this.head.forward[this.level-1]===null;)this._level--;return!0}return!1}getFirst(){let e=this.head.forward[0];return e?e.value:void 0}getLast(){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t];)e=e.forward[t];return e.value}higher(e){let t=this.head;for(let n=this.level-1;n>=0;n--)for(;t.forward[n]&&t.forward[n].key<=e;)t=t.forward[n];let r=t.forward[0];return r?r.value:void 0}lower(e){let t=this.head,r=null;for(let n=this.level-1;n>=0;n--){for(;t.forward[n]&&t.forward[n].key<e;)t=t.forward[n];t.key<e&&(r=t)}return r?r.value:void 0}_randomLevel(){let e=1;for(;Math.random()<this.probability&&e<this.maxLevel;)e++;return e}};var be=class a{constructor(e){this._elements=Array.isArray(e)?e:[]}_elements;get elements(){return this._elements}static fromArray(e){return new a(e)}isEmpty(){return this.elements.length===0}size(){return this.elements.length}peek(){return this.isEmpty()?null:this.elements[this.elements.length-1]}push(e){return this.elements.push(e),this}pop(){return this.isEmpty()?null:this.elements.pop()||null}toArray(){return this.elements.slice()}clear(){this._elements=[]}clone(){return new a(this.elements.slice())}};var Te=class extends G{enqueue(e){this.push(e)}dequeue(){return this.shift()}getFirst(){return this.head?.value}peek(){return this.getFirst()}},O=class a{constructor(e){this._nodes=e||[],this._offset=0}_nodes;get nodes(){return this._nodes}_offset;get offset(){return this._offset}get size(){return this.nodes.length-this.offset}static fromArray(e){return new a(e)}push(e){return this.nodes.push(e),this}shift(){if(this.size===0)return;let e=this.getFirst();return this._offset+=1,this.offset*2<this.nodes.length||(this._nodes=this.nodes.slice(this.offset),this._offset=0),e}getFirst(){return this.size>0?this.nodes[this.offset]:void 0}peek(){return this.getFirst()}getLast(){return this.size>0?this.nodes[this.nodes.length-1]:void 0}peekLast(){return this.getLast()}enqueue(e){this.push(e)}dequeue(){return this.shift()}getAt(e){return this.nodes[e]}isEmpty(){return this.size===0}toArray(){return this.nodes.slice(this.offset)}clear(){this._nodes=[],this._offset=0}clone(){return new a(this.nodes.slice(this.offset))}*[Symbol.iterator](){for(let e of this.nodes)yield e}};var _e=class extends W{},xe=class{constructor(e){e!==void 0&&(this._capacity=e)}_nodes={};get nodes(){return this._nodes}_capacity=Number.MAX_SAFE_INTEGER;get capacity(){return this._capacity}_first=-1;get first(){return this._first}_last=-1;get last(){return this._last}_size=0;get size(){return this._size}addFirst(e){if(this.size===0){let t=Math.floor(this.capacity/2);this._first=t,this._last=t}else this._first--;this.nodes[this.first]=e,this._size++}addLast(e){if(this.size===0){let t=Math.floor(this.capacity/2);this._first=t,this._last=t}else this._last++;this.nodes[this.last]=e,this._size++}popFirst(){if(!this.size)return;let e=this.getFirst();return delete this.nodes[this.first],this._first++,this._size--,e}getFirst(){if(this.size)return this.nodes[this.first]}popLast(){if(!this.size)return;let e=this.getLast();return delete this.nodes[this.last],this._last--,this._size--,e}getLast(){if(this.size)return this.nodes[this.last]}get(e){return this.nodes[this.first+e]||null}isEmpty(){return this.size<=0}},Ee=class{_nodes=[];get nodes(){return this._nodes}get size(){return this.nodes.length}addLast(e){return this.nodes.push(e)}popLast(){return this.nodes.pop()??null}popFirst(){return this.nodes.shift()??null}addFirst(e){return this.nodes.unshift(e)}getFirst(){return this.nodes[0]??null}getLast(){return this.nodes[this.nodes.length-1]??null}get(e){return this.nodes[e]??null}set(e,t){return this.nodes[e]=t}insert(e,t){return this.nodes.splice(e,0,t)}delete(e){return this.nodes.splice(e,1)}isEmpty(){return this.nodes.length===0}};var Ve=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(a){let e=Math.random()*16|0;return(a=="x"?e:e&3|8).toString(16)})},R=function(a,e){let t=-1,r=a?a.length:0,n=[];for(;++t<r;){let i=a[t];e(i,t,a)&&(n.push(i),Array.prototype.splice.call(a,t--,1),r--)}return n},Ce=Symbol("thunk"),Oe=a=>typeof a=="function"&&a.__THUNK__===Ce,ve=a=>{let e=()=>a();return e.__THUNK__=Ce,e},ee=a=>Object.assign((...t)=>{let r=a(...t);for(;Oe(r)&&typeof r=="function";)r=r();return r},{cont:(...t)=>ve(()=>a(...t))}),Ze=a=>Object.assign(async(...t)=>{let r=await a(...t);for(;Oe(r)&&typeof r=="function";)r=await r();return r},{cont:(...t)=>ve(()=>a(...t))}),Be=a=>a<=0?0:1<<31-Math.clz32(a);var K=class a{constructor(e){this._comparator=e.comparator,e.nodes&&e.nodes.length>0&&(this._nodes=e.nodes,this.fix())}_nodes=[];get nodes(){return this._nodes}_comparator;get comparator(){return this._comparator}get size(){return this.nodes.length}get leaf(){return this.nodes[this.size-1]??void 0}static heapify(e){return new a(e)}add(e){return this.push(e)}push(e){return this.nodes.push(e),this.bubbleUp(this.nodes.length-1),this}poll(){if(this.nodes.length===0)return;if(this.nodes.length===1)return this.nodes.pop();let e=this.nodes[0];return this.nodes[0]=this.nodes.pop(),this.sinkDown(0),e}pop(){return this.poll()}peek(){if(this.nodes.length!==0)return this.nodes[0]}isEmpty(){return this.size===0}clear(){this._nodes=[]}refill(e){this._nodes=e,this.fix()}has(e){return this.nodes.includes(e)}dfs(e){let t=[],r=n=>{n<this.size&&(e==="in"?(r(2*n+1),t.push(this.nodes[n]),r(2*n+2)):e==="pre"?(t.push(this.nodes[n]),r(2*n+1),r(2*n+2)):e==="post"&&(r(2*n+1),r(2*n+2),t.push(this.nodes[n])))};return r(0),t}toArray(){return[...this.nodes]}getNodes(){return this.nodes}clone(){let e=new a({comparator:this.comparator});return e._nodes=[...this.nodes],e}sort(){let e=[],t=this.clone();for(;t.size!==0;){let r=t.poll();r&&e.push(r)}return e}bubbleUp(e){let t=this.nodes[e];for(;e>0;){let r=Math.floor((e-1)/2),n=this.nodes[r];if(this.comparator(t,n)<0)this.nodes[e]=n,this.nodes[r]=t,e=r;else break}}sinkDown(e){let t=2*e+1,r=2*e+2,n=this.nodes.length,i=e;if(t<n&&this.comparator(this.nodes[t],this.nodes[i])<0&&(i=t),r<n&&this.comparator(this.nodes[r],this.nodes[i])<0&&(i=r),i!==e){let s=this.nodes[e];this.nodes[e]=this.nodes[i],this.nodes[i]=s,this.sinkDown(i)}}fix(){for(let e=Math.floor(this.size/2);e>=0;e--)this.sinkDown(e)}},te=class{element;degree;left;right;child;parent;marked;constructor(e,t=0){this.element=e,this.degree=t,this.marked=!1}},we=class{constructor(e){if(this.clear(),this._comparator=e||this.defaultComparator,typeof this.comparator!="function")throw new Error("FibonacciHeap constructor: given comparator should be a function.")}_root;get root(){return this._root}_size=0;get size(){return this._size}_min;get min(){return this._min}_comparator;get comparator(){return this._comparator}clear(){this._root=void 0,this._min=void 0,this._size=0}add(e){return this.push(e)}push(e){let t=this.createNode(e);return t.left=t,t.right=t,this.mergeWithRoot(t),(!this.min||this.comparator(t.element,this.min.element)<=0)&&(this._min=t),this._size++,this}peek(){return this.min?this.min.element:void 0}consumeLinkedList(e){let t=[];if(!e)return t;let r=e,n=!1;for(;!(r===e&&n);)r===e&&(n=!0),r&&(t.push(r),r=r.right);return t}mergeWithChild(e,t){e.child?(t.right=e.child.right,t.left=e.child,e.child.right.left=t,e.child.right=t):e.child=t}poll(){return this.pop()}pop(){if(this.size===0)return;let e=this.min;if(e.child){let t=this.consumeLinkedList(e.child);for(let r of t)this.mergeWithRoot(r),r.parent=void 0}return this.removeFromRoot(e),e===e.right?(this._min=void 0,this._root=void 0):(this._min=e.right,this.consolidate()),this._size--,e.element}merge(e){if(e.size!==0){if(this.root&&e.root){let t=this.root,r=e.root,n=t.right,i=r.left;t.right=r,r.left=t,n.left=i,i.right=n}(!this.min||e.min&&this.comparator(e.min.element,this.min.element)<0)&&(this._min=e.min),this._size+=e.size,e.clear()}}defaultComparator(e,t){return e<t?-1:e>t?1:0}createNode(e){return new te(e)}mergeWithRoot(e){this.root?(e.right=this.root.right,e.left=this.root,this.root.right.left=e,this.root.right=e):this._root=e}removeFromRoot(e){this.root===e&&(this._root=e.right),e.left&&(e.left.right=e.right),e.right&&(e.right.left=e.left)}link(e,t){this.removeFromRoot(e),e.left=e,e.right=e,this.mergeWithChild(t,e),t.degree++,e.parent=t}consolidate(){let e=new Array(this.size),t=this.consumeLinkedList(this.root),r,n,i,s;for(let l of t){for(r=l,i=r.degree;e[i];)n=e[i],this.comparator(r.element,n.element)>0&&(s=r,r=n,n=s),this.link(n,r),e[i]=void 0,i++;e[i]=r}for(let l=0;l<this.size;l++)e[l]&&this.comparator(e[l].element,this.min.element)<=0&&(this._min=e[l])}};var ke=class extends K{constructor(e={comparator:(t,r)=>{if(typeof t=="number"&&typeof r=="number")return r-t;throw new Error("The a, b params of compare function must be number")}}){super(e)}};var Re=class extends K{constructor(e={comparator:(t,r)=>{if(typeof t=="number"&&typeof r=="number")return t-r;throw new Error("The a, b params of compare function must be number")}}){super(e)}};var M=class extends K{constructor(e){super(e)}};var Ke=class extends M{constructor(e={comparator:(t,r)=>{if(typeof t=="number"&&typeof r=="number")return t-r;throw new Error("The a, b params of compare function must be number")}}){super(e)}};var Me=class extends M{constructor(e={comparator:(t,r)=>{if(typeof t=="number"&&typeof r=="number")return r-t;throw new Error("The a, b params of compare function must be number")}}){super(e)}};var V=class{key;value;constructor(e,t){this.key=e,this.value=t}},L=class{value;weight;constructor(e,t){this.weight=e!==void 0?e:1,this.value=t,this._hashCode=Ve()}_hashCode;get hashCode(){return this._hashCode}},S=class{_vertices=new Map;get vertices(){return this._vertices}getVertex(e){return this._vertices.get(e)||null}hasVertex(e){return this._vertices.has(this._getVertexKey(e))}addVertex(e,t){if(e instanceof V)return this._addVertexOnly(e);{let r=this.createVertex(e,t);return this._addVertexOnly(r)}}deleteVertex(e){let t=this._getVertexKey(e);return this._vertices.delete(t)}removeManyVertices(e){let t=[];for(let r of e)t.push(this.deleteVertex(r));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,r,n){if(e instanceof L)return this._addEdgeOnly(e);if(t instanceof V||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof V&&(e=e.key),t instanceof V&&(t=t.key);let i=this.createEdge(e,t,r,n);return this._addEdgeOnly(i)}else throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(e,t,r){let n=this.getEdge(e,t);return n?(n.weight=r,!0):!1}getAllPathsBetween(e,t,r=1e3){let n=[],i=this._getVertex(e),s=this._getVertex(t);if(!(i&&s))return[];let l=[];for(l.push({vertex:i,path:[i]});l.length>0;){let{vertex:o,path:u}=l.pop();if(o===s&&(n.push(u),n.length>=r))return n;let f=this.getNeighbors(o);for(let g of f)if(!u.includes(g)){let N=[...u,g];l.push({vertex:g,path:N})}}return n}getPathSumWeight(e){let t=0;for(let r=0;r<e.length;r++)t+=this.getEdge(e[r],e[r+1])?.weight||0;return t}getMinCostBetween(e,t,r){if(r===void 0&&(r=!1),r){let n=this.getAllPathsBetween(e,t),i=1/0;for(let s of n)i=Math.min(this.getPathSumWeight(s),i);return i}else{let n=this._getVertex(t),i=this._getVertex(e);if(!(i&&n))return null;let s=new Map,l=new O([i]);s.set(i,!0);let o=0;for(;l.size>0;){for(let u=0;u<l.size;u++){let f=l.shift();if(f===n)return o;if(f!==void 0){let g=this.getNeighbors(f);for(let N of g)s.has(N)||(s.set(N,!0),l.push(N))}}o++}return null}}getMinPathBetween(e,t,r,n=!1){if(r===void 0&&(r=!1),r)if(n){let i=this.getAllPathsBetween(e,t,1e4),s=1/0,l=-1,o=0;for(let u of i){let f=this.getPathSumWeight(u);f<s&&(s=f,l=o),o++}return i[l]||null}else return this.dijkstra(e,t,!0,!0)?.minPath??[];else{let i=[],s=this._getVertex(e),l=this._getVertex(t);if(!(s&&l))return[];let o=(u,f,g,N)=>{if(g.add(u),u===f){i=[s,...N];return}let x=this.getNeighbors(u);for(let T of x)g.has(T)||(N.push(T),o(T,f,g,N),N.pop());g.delete(u)};return o(s,l,new Set,[]),i}}dijkstraWithoutHeap(e,t,r,n){r===void 0&&(r=!1),n===void 0&&(n=!1),t===void 0&&(t=null);let i=1/0,s=null,l=[],o=[],u=this._vertices,f=new Map,g=new Set,N=new Map,x=this._getVertex(e),T=t?this._getVertex(t):null;if(!x)return null;for(let h of u){let d=h[1];d instanceof V&&f.set(d,1/0)}f.set(x,0),N.set(x,null);let y=()=>{let h=1/0,d=null;for(let[c,m]of f)g.has(c)||m<h&&(h=m,d=c);return d},b=h=>{for(let d of u){let c=d[1];if(c instanceof V){let m=[c],p=N.get(c);for(;p;)m.push(p),p=N.get(p);let _=m.reverse();d[1]===h&&(l=_),o.push(_)}}};for(let h=1;h<u.size;h++){let d=y();if(d){if(g.add(d),T&&T===d)return r&&(i=f.get(T)||1/0),n&&b(T),{distMap:f,preMap:N,seen:g,paths:o,minDist:i,minPath:l};let c=this.getNeighbors(d);for(let m of c)if(!g.has(m)){let p=this.getEdge(d,m);if(p){let _=f.get(d),E=f.get(m);_!==void 0&&E!==void 0&&p.weight+_<E&&(f.set(m,p.weight+_),N.set(m,d))}}}}return r&&f.forEach((h,d)=>{d!==x&&h<i&&(i=h,n&&(s=d))}),n&&b(s),{distMap:f,preMap:N,seen:g,paths:o,minDist:i,minPath:l}}dijkstra(e,t,r,n){r===void 0&&(r=!1),n===void 0&&(n=!1),t===void 0&&(t=null);let i=1/0,s=null,l=[],o=[],u=this._vertices,f=new Map,g=new Set,N=new Map,x=this._getVertex(e),T=t?this._getVertex(t):null;if(!x)return null;for(let h of u){let d=h[1];d instanceof V&&f.set(d,1/0)}let y=new M({comparator:(h,d)=>h.key-d.key});y.add({key:0,value:x}),f.set(x,0),N.set(x,null);let b=h=>{for(let d of u){let c=d[1];if(c instanceof V){let m=[c],p=N.get(c);for(;p;)m.push(p),p=N.get(p);let _=m.reverse();d[1]===h&&(l=_),o.push(_)}}};for(;y.size>0;){let h=y.poll(),d=h?.key,c=h?.value;if(d!==void 0&&c){if(g.add(c),T&&T===c)return r&&(i=f.get(T)||1/0),n&&b(T),{distMap:f,preMap:N,seen:g,paths:o,minDist:i,minPath:l};let m=this.getNeighbors(c);for(let p of m)if(!g.has(p)){let _=this.getEdge(c,p)?.weight;if(typeof _=="number"){let E=f.get(p);E&&d+_<E&&(y.add({key:d+_,value:p}),N.set(p,c),f.set(p,d+_))}}}}return r&&f.forEach((h,d)=>{d!==x&&h<i&&(i=h,n&&(s=d))}),n&&b(s),{distMap:f,preMap:N,seen:g,paths:o,minDist:i,minPath:l}}bellmanFord(e,t,r,n){r===void 0&&(r=!1),n===void 0&&(n=!1);let i=this._getVertex(e),s=[],l=new Map,o=new Map,u=1/0,f=[],g;if(t&&(g=!1),!i)return{hasNegativeCycle:g,distMap:l,preMap:o,paths:s,min:u,minPath:f};let N=this._vertices,x=N.size,T=this.edgeSet(),y=T.length;this._vertices.forEach(h=>{l.set(h,1/0)}),l.set(i,0);for(let h=1;h<x;++h)for(let d=0;d<y;++d){let c=this.getEndsOfEdge(T[d]);if(c){let[m,p]=c,_=T[d].weight,E=l.get(m),w=l.get(p);E!==void 0&&w!==void 0&&l.get(m)!==1/0&&E+_<w&&(l.set(p,E+_),n&&o.set(p,m))}}let b=null;if(r&&l.forEach((h,d)=>{d!==i&&h<u&&(u=h,n&&(b=d))}),n)for(let h of N){let d=h[1];if(d instanceof V){let c=[d],m=o.get(d);for(;m!==void 0;)c.push(m),m=o.get(m);let p=c.reverse();h[1]===b&&(f=p),s.push(p)}}for(let h=0;h<y;++h){let d=this.getEndsOfEdge(T[h]);if(d){let[c]=d,m=T[h].weight,p=l.get(c);p&&p!==1/0&&p+m<p&&(g=!0)}}return{hasNegativeCycle:g,distMap:l,preMap:o,paths:s,min:u,minPath:f}}floydWarshall(){let e=[...this._vertices],t=e.length,r=[],n=[];for(let i=0;i<t;i++){r[i]=[],n[i]=[];for(let s=0;s<t;s++)n[i][s]=null}for(let i=0;i<t;i++)for(let s=0;s<t;s++)r[i][s]=this.getEdge(e[i][1],e[s][1])?.weight||1/0;for(let i=0;i<t;i++)for(let s=0;s<t;s++)for(let l=0;l<t;l++)r[s][l]>r[s][i]+r[i][l]&&(r[s][l]=r[s][i]+r[i][l],n[s][l]=e[i][1]);return{costs:r,predecessor:n}}tarjan(e=!1,t=!1,r=!0,n=!1){e===void 0&&(e=!1),t===void 0&&(t=!1),r===void 0&&(r=!1),n===void 0&&(n=!1);let s=new Map,l=new Map,o=this._vertices;o.forEach(h=>{s.set(h,-1),l.set(h,1/0)});let[u]=o.values(),f=[],g=[],N=0,x=(h,d)=>{N++,s.set(h,N),l.set(h,N);let c=this.getNeighbors(h),m=0;for(let p of c)if(p!==d){s.get(p)===-1&&(m++,x(p,h));let _=l.get(p),E=l.get(h);E!==void 0&&_!==void 0&&l.set(h,Math.min(E,_));let w=s.get(h);if(_!==void 0&&w!==void 0&&(e&&(h===u&&m>=2||h!==u&&_>=w)&&f.push(h),t&&_>w)){let z=this.getEdge(h,p);z&&g.push(z)}}};x(u,null);let T=new Map,y=()=>{let h=new Map;return l.forEach((d,c)=>{h.has(d)?h.get(d)?.push(c):h.set(d,[c])}),h};r&&(T=y());let b=new Map;if(n){let h=new Map;h.size<1&&(h=y()),h.forEach((d,c)=>{d.length>1&&b.set(c,d)})}return{dfnMap:s,lowMap:l,bridges:g,cutVertexes:f,SCCs:T,cycles:b}}getDFNMap(){return this.tarjan(!1,!1,!1,!1).dfnMap}getLowMap(){return this.tarjan(!1,!1,!1,!1).lowMap}getCycles(){return this.tarjan(!1,!1,!1,!0).cycles}getCutVertexes(){return this.tarjan(!0,!1,!1,!1).cutVertexes}getSCCs(){return this.tarjan(!1,!1,!0,!1).SCCs}getBridges(){return this.tarjan(!1,!0,!1,!1).bridges}_addVertexOnly(e){return this.hasVertex(e)?!1:(this._vertices.set(e.key,e),!0)}_getVertex(e){let t=this._getVertexKey(e);return this._vertices.get(t)||null}_getVertexKey(e){return e instanceof V?e.key:e}};var I=class extends V{constructor(e,t){super(e,t)}},A=class extends L{src;dest;constructor(e,t,r,n){super(r,n),this.src=e,this.dest=t}},X=class extends S{constructor(){super()}_outEdgeMap=new Map;get outEdgeMap(){return this._outEdgeMap}_inEdgeMap=new Map;get inEdgeMap(){return this._inEdgeMap}createVertex(e,t){return new I(e,t??e)}createEdge(e,t,r,n){return new A(e,t,r??1,n)}getEdge(e,t){let r=[];if(e!==null&&t!==null){let n=this._getVertex(e),i=this._getVertex(t);if(n&&i){let s=this._outEdgeMap.get(n);s&&(r=s.filter(l=>l.dest===i.key))}}return r[0]||null}deleteEdgeSrcToDest(e,t){let r=this._getVertex(e),n=this._getVertex(t),i=null;if(!r||!n)return null;let s=this._outEdgeMap.get(r);s&&R(s,o=>o.dest===n.key);let l=this._inEdgeMap.get(n);return l&&(i=R(l,o=>o.src===r.key)[0]||null),i}deleteEdge(e){let t=null,r=this._getVertex(e.src),n=this._getVertex(e.dest);if(r&&n){let i=this._outEdgeMap.get(r);i&&i.length>0&&R(i,l=>l.src===r.key);let s=this._inEdgeMap.get(n);s&&s.length>0&&(t=R(s,l=>l.dest===n.key)[0])}return t}deleteEdgesBetween(e,t){let r=[];if(e&&t){let n=this.deleteEdgeSrcToDest(e,t),i=this.deleteEdgeSrcToDest(t,e);n&&r.push(n),i&&r.push(i)}return r}incomingEdgesOf(e){let t=this._getVertex(e);return t?this.inEdgeMap.get(t)||[]:[]}outgoingEdgesOf(e){let t=this._getVertex(e);return t?this._outEdgeMap.get(t)||[]:[]}degreeOf(e){return this.outDegreeOf(e)+this.inDegreeOf(e)}inDegreeOf(e){return this.incomingEdgesOf(e).length}outDegreeOf(e){return this.outgoingEdgesOf(e).length}edgesOf(e){return[...this.outgoingEdgesOf(e),...this.incomingEdgesOf(e)]}getEdgeSrc(e){return this._getVertex(e.src)}getEdgeDest(e){return this._getVertex(e.dest)}getDestinations(e){if(e===null)return[];let t=[],r=this.outgoingEdgesOf(e);for(let n of r){let i=this.getEdgeDest(n);i&&t.push(i)}return t}topologicalSort(e){e=e??"key";let t=new Map;for(let s of this.vertices)t.set(s[1],0);let r=[],n=!1,i=s=>{t.set(s,1);let l=this.getDestinations(s);for(let o of l){let u=t.get(o);u===0?i(o):u===1&&(n=!0)}t.set(s,2),r.push(s)};for(let s of this.vertices)t.get(s[1])===0&&i(s[1]);return n?null:(e==="key"&&(r=r.map(s=>s instanceof I?s.key:s)),r.reverse())}edgeSet(){let e=[];return this._outEdgeMap.forEach(t=>{e=[...e,...t]}),e}getNeighbors(e){let t=[],r=this._getVertex(e);if(r){let n=this.outgoingEdgesOf(r);for(let i of n){let s=this._getVertex(i.dest);s&&t.push(s)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.src,e.dest))return null;let t=this._getVertex(e.src),r=this._getVertex(e.dest);return t&&r?[t,r]:null}_addEdgeOnly(e){if(!(this.hasVertex(e.src)&&this.hasVertex(e.dest)))return!1;let t=this._getVertex(e.src),r=this._getVertex(e.dest);if(t&&r){let n=this._outEdgeMap.get(t);n?n.push(e):this._outEdgeMap.set(t,[e]);let i=this._inEdgeMap.get(r);return i?i.push(e):this._inEdgeMap.set(r,[e]),!0}else return!1}};var re=class extends V{constructor(e,t){super(e,t)}},ne=class extends L{vertices;constructor(e,t,r,n){super(r,n),this.vertices=[e,t]}},Le=class extends S{constructor(){super(),this._edges=new Map}_edges;get edges(){return this._edges}createVertex(e,t){return new re(e,t??e)}createEdge(e,t,r,n){return new ne(e,t,r??1,n)}getEdge(e,t){let r=[];if(e!==null&&t!==null){let n=this._getVertex(e),i=this._getVertex(t);n&&i&&(r=this._edges.get(n)?.filter(s=>s.vertices.includes(i.key)))}return r&&r[0]||null}deleteEdgeBetween(e,t){let r=this._getVertex(e),n=this._getVertex(t);if(!r||!n)return null;let i=this._edges.get(r),s=null;i&&(s=R(i,o=>o.vertices.includes(n.key))[0]||null);let l=this._edges.get(n);return l&&R(l,o=>o.vertices.includes(r.key)),s}deleteEdge(e){return this.deleteEdgeBetween(e.vertices[0],e.vertices[1])}degreeOf(e){let t=this._getVertex(e);return t&&this._edges.get(t)?.length||0}edgesOf(e){let t=this._getVertex(e);return t?this._edges.get(t)||[]:[]}edgeSet(){let e=new Set;return this._edges.forEach(t=>{t.forEach(r=>{e.add(r)})}),[...e]}getNeighbors(e){let t=[],r=this._getVertex(e);if(r){let n=this.edgesOf(r);for(let i of n){let s=this._getVertex(i.vertices.filter(l=>l!==r.key)[0]);s&&t.push(s)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.vertices[0],e.vertices[1]))return null;let t=this._getVertex(e.vertices[0]),r=this._getVertex(e.vertices[1]);return t&&r?[t,r]:null}_addEdgeOnly(e){for(let t of e.vertices){let r=this._getVertex(t);if(r===null)return!1;if(r){let n=this._edges.get(r);n?n.push(e):this._edges.set(r,[e])}}return!0}};var ie=class extends I{lat;long;constructor(e,t,r,n){super(e,t),this.lat=r,this.long=n}},se=class extends A{constructor(e,t,r,n){super(e,t,r,n)}},Se=class extends X{constructor(e,t){super(),this._origin=e,this._bottomRight=t}_origin=[0,0];get origin(){return this._origin}_bottomRight;get bottomRight(){return this._bottomRight}createVertex(e,t,r=this.origin[0],n=this.origin[1]){return new ie(e,t,r,n)}createEdge(e,t,r,n){return new se(e,t,r,n)}};var Y=(t=>(t.ITERATIVE="ITERATIVE",t.RECURSIVE="RECURSIVE",t))(Y||{}),oe=(l=>(l.ROOT="ROOT",l.LEFT="LEFT",l.RIGHT="RIGHT",l.ROOT_LEFT="ROOT_LEFT",l.ROOT_RIGHT="ROOT_RIGHT",l.ISOLATED="ISOLATED",l.MAL_NODE="MAL_NODE",l))(oe||{});var Ie=(t=>(t[t.RED=1]="RED",t[t.BLACK=0]="BLACK",t))(Ie||{});var Ge=(r=>(r.VAL="VAL",r.NODE="NODE",r.ID="ID",r))(Ge||{});var le=(r=>(r.lt="lt",r.eq="eq",r.gt="gt",r))(le||{});var C=class{key;value;parent;constructor(e,t){this.key=e,this.value=t}_left;get left(){return this._left}set left(e){e&&(e.parent=this),this._left=e}_right;get right(){return this._right}set right(e){e&&(e.parent=this),this._right=e}get familyPosition(){let e=this;return this.parent?this.parent.left===e?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===e?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}},$=class{iterationType="ITERATIVE";constructor(e){if(e!==void 0){let{iterationType:t="ITERATIVE"}=e;this.iterationType=t}}_root=void 0;get root(){return this._root}_size=0;get size(){return this._size}createNode(e,t){return new C(e,t)}clear(){this._setRoot(void 0),this._size=0}isEmpty(){return this.size===0}add(e,t){let r=(s,l)=>{let o=new O([s]);for(;o.size>0;){let u=o.shift();if(u){if(l&&u.key===l.key){u.value=l.value;return}let f=this._addTo(l,u);if(f!==void 0)return f;u.left&&o.push(u.left),u.right&&o.push(u.right)}else return}},n,i;if(e===null)i=null;else if(typeof e=="number")i=this.createNode(e,t);else if(e instanceof C)i=e;else return;return this.root?n=r(this.root,i):(this._setRoot(i),i!==null?this._size=1:this._size=0,n=this.root),n}addMany(e,t){return e.map((r,n)=>{if(r instanceof C)return this.add(r.key,r.value);if(r===null)return this.add(null);let i=t?.[n];return this.add(r,i)})}refill(e,t){return this.clear(),e.length===this.addMany(e,t).length}delete(e,t=this.defaultOneParamCallback){let r=[];if(!this.root)return r;e instanceof C&&(t=o=>o);let n=this.getNode(e,t);if(!n)return r;let i=n?.parent?n.parent:null,s=null,l=n;if(n.left){let o=n.left?this.getRightMost(n.left):null;if(o){let u=o.parent;l=this._swap(n,o),u&&(u.right===o?u.right=o.left:u.left=o.left,s=u)}}else if(!i)this._setRoot(null);else{let{familyPosition:o}=n;o==="LEFT"||o==="ROOT_LEFT"?i.left=n.right:(o==="RIGHT"||o==="ROOT_RIGHT")&&(i.right=n.right),s=i}return this._size=this.size-1,r.push({deleted:l,needBalanced:s}),r}getDepth(e,t=this.root){typeof e=="number"&&(e=this.getNode(e)),typeof t=="number"&&(t=this.getNode(t));let r=0;for(;e?.parent;){if(e===t)return r;r++,e=e.parent}return r}getHeight(e=this.root,t=this.iterationType){if(typeof e=="number"&&(e=this.getNode(e)),!e)return-1;if(t==="RECURSIVE"){let r=n=>{if(!n)return-1;let i=r(n.left),s=r(n.right);return Math.max(i,s)+1};return r(e)}else{if(!e)return-1;let r=[{node:e,depth:0}],n=0;for(;r.length>0;){let{node:i,depth:s}=r.pop();i.left&&r.push({node:i.left,depth:s+1}),i.right&&r.push({node:i.right,depth:s+1}),n=Math.max(n,s)}return n}}getMinHeight(e=this.root,t=this.iterationType){if(!e)return-1;if(t==="RECURSIVE"){let r=n=>{if(!n||!n.left&&!n.right)return 0;let i=r(n.left),s=r(n.right);return Math.min(i,s)+1};return r(e)}else{let r=[],n=e,i=null,s=new Map;for(;r.length>0||n;)if(n)r.push(n),n=n.left;else if(n=r[r.length-1],!n.right||i===n.right){if(n=r.pop(),n){let l=n.left?s.get(n.left)??-1:-1,o=n.right?s.get(n.right)??-1:-1;s.set(n,1+Math.min(l,o)),i=n,n=null}}else n=n.right;return s.get(e)??-1}}isPerfectlyBalanced(e=this.root){return this.getMinHeight(e)+1>=this.getHeight(e)}getNodes(e,t=this.defaultOneParamCallback,r=!1,n=this.root,i=this.iterationType){if(!n)return[];e instanceof C&&(t=l=>l);let s=[];if(i==="RECURSIVE"){let l=o=>{t(o)===e&&(s.push(o),r)||!o.left&&!o.right||(o.left&&l(o.left),o.right&&l(o.right))};l(n)}else{let l=new O([n]);for(;l.size>0;){let o=l.shift();if(o){if(t(o)===e&&(s.push(o),r))return s;o.left&&l.push(o.left),o.right&&l.push(o.right)}}}return s}has(e,t=this.defaultOneParamCallback,r=this.root,n=this.iterationType){return e instanceof C&&(t=i=>i),this.getNodes(e,t,!0,r,n).length>0}getNode(e,t=this.defaultOneParamCallback,r=this.root,n=this.iterationType){return e instanceof C&&(t=i=>i),this.getNodes(e,t,!0,r,n)[0]??null}get(e,t=this.defaultOneParamCallback,r=this.root,n=this.iterationType){return e instanceof C&&(t=i=>i),this.getNode(e,t,r,n)?.value??void 0}getPathToRoot(e,t=!0){let r=[];for(;e.parent;)r.push(e),e=e.parent;return r.push(e),t?r.reverse():r}getLeftMost(e=this.root,t=this.iterationType){if(typeof e=="number"&&(e=this.getNode(e)),!e)return e;if(t==="RECURSIVE"){let r=n=>n.left?r(n.left):n;return r(e)}else{let r=ee(n=>n.left?r.cont(n.left):n);return r(e)}}getRightMost(e=this.root,t=this.iterationType){if(!e)return e;if(t==="RECURSIVE"){let r=n=>n.right?r(n.right):n;return r(e)}else{let r=ee(n=>n.right?r.cont(n.right):n);return r(e)}}isSubtreeBST(e,t=this.iterationType){if(!e)return!0;if(t==="RECURSIVE"){let r=(n,i,s)=>n?n.key<=i||n.key>=s?!1:r(n.left,i,n.key)&&r(n.right,n.key,s):!0;return r(e,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER)}else{let r=[],n=Number.MIN_SAFE_INTEGER,i=e;for(;i||r.length>0;){for(;i;)r.push(i),i=i.left;if(i=r.pop(),!i||n>=i.key)return!1;n=i.key,i=i.right}return!0}}isBST(e=this.iterationType){return this.root===null?!0:this.isSubtreeBST(this.root,e)}subTreeTraverse(e=this.defaultOneParamCallback,t=this.root,r=this.iterationType,n=!1){typeof t=="number"&&(t=this.getNode(t));let i=[];if(!t)return i;if(r==="RECURSIVE"){let s=l=>{l!==void 0&&(i.push(e(l)),n?(l&&this.isNodeOrNull(l.left)&&s(l.left),l&&this.isNodeOrNull(l.right)&&s(l.right)):(l&&l.left&&s(l.left),l&&l.right&&s(l.right)))};s(t)}else{let s=[t];for(;s.length>0;){let l=s.pop();l!==void 0&&(i.push(e(l)),n?(l&&this.isNodeOrNull(l.right)&&s.push(l.right),l&&this.isNodeOrNull(l.left)&&s.push(l.left)):(l&&l.right&&s.push(l.right),l&&l.left&&s.push(l.left)))}}return i}isNode(e){return e instanceof C&&e.key.toString()!=="NaN"}isNIL(e){return e instanceof C&&e.key.toString()==="NaN"}isNodeOrNull(e){return this.isNode(e)||e===null}dfs(e=this.defaultOneParamCallback,t="in",r=this.root,n="ITERATIVE",i=!1){if(!r)return[];let s=[];if(n==="RECURSIVE"){let l=o=>{switch(t){case"in":i?(o&&this.isNodeOrNull(o.left)&&l(o.left),this.isNodeOrNull(o)&&s.push(e(o)),o&&this.isNodeOrNull(o.right)&&l(o.right)):(o&&o.left&&l(o.left),this.isNode(o)&&s.push(e(o)),o&&o.right&&l(o.right));break;case"pre":i?(this.isNodeOrNull(o)&&s.push(e(o)),o&&this.isNodeOrNull(o.left)&&l(o.left),o&&this.isNodeOrNull(o.right)&&l(o.right)):(this.isNode(o)&&s.push(e(o)),o&&o.left&&l(o.left),o&&o.right&&l(o.right));break;case"post":i?(o&&this.isNodeOrNull(o.left)&&l(o.left),o&&this.isNodeOrNull(o.right)&&l(o.right),this.isNodeOrNull(o)&&s.push(e(o))):(o&&o.left&&l(o.left),o&&o.right&&l(o.right),this.isNode(o)&&s.push(e(o)));break}};l(r)}else{let l=[{opt:0,node:r}];for(;l.length>0;){let o=l.pop();if(!(o===void 0||this.isNIL(o.node))){if(i){if(o.node===void 0)continue}else if(o.node===null||o.node===void 0)continue;if(o.opt===1)s.push(e(o.node));else switch(t){case"in":o.node&&l.push({opt:0,node:o.node.right}),l.push({opt:1,node:o.node}),o.node&&l.push({opt:0,node:o.node.left});break;case"pre":o.node&&l.push({opt:0,node:o.node.right}),o.node&&l.push({opt:0,node:o.node.left}),l.push({opt:1,node:o.node});break;case"post":l.push({opt:1,node:o.node}),o.node&&l.push({opt:0,node:o.node.right}),o.node&&l.push({opt:0,node:o.node.left});break;default:o.node&&l.push({opt:0,node:o.node.right}),l.push({opt:1,node:o.node}),o.node&&l.push({opt:0,node:o.node.left});break}}}}return s}bfs(e=this.defaultOneParamCallback,t=this.root,r=this.iterationType,n=!1){if(!t)return[];let i=[];if(r==="RECURSIVE"){let s=new O([t]),l=o=>{if(s.size===0)return;let u=s.shift();i.push(e(u)),n?(u&&this.isNodeOrNull(u.left)&&s.push(u.left),u&&this.isNodeOrNull(u.right)&&s.push(u.right)):(u.left&&s.push(u.left),u.right&&s.push(u.right)),l(o+1)};l(0)}else{let s=new O([t]);for(;s.size>0;){let l=s.size;for(let o=0;o<l;o++){let u=s.shift();i.push(e(u)),n?(u&&this.isNodeOrNull(u.left)&&s.push(u.left),u&&this.isNodeOrNull(u.right)&&s.push(u.right)):(u.left&&s.push(u.left),u.right&&s.push(u.right))}}}return i}listLevels(e=this.defaultOneParamCallback,t=this.root,r=this.iterationType,n=!1){if(!t)return[];let i=[];if(r==="RECURSIVE"){let s=(l,o)=>{i[o]||(i[o]=[]),i[o].push(e(l)),n?(l&&this.isNodeOrNull(l.left)&&s(l.left,o+1),l&&this.isNodeOrNull(l.right)&&s(l.right,o+1)):(l&&l.left&&s(l.left,o+1),l&&l.right&&s(l.right,o+1))};s(t,0)}else{let s=[[t,0]];for(;s.length>0;){let l=s.pop(),[o,u]=l;i[u]||(i[u]=[]),i[u].push(e(o)),n?(o&&this.isNodeOrNull(o.right)&&s.push([o.right,u+1]),o&&this.isNodeOrNull(o.left)&&s.push([o.left,u+1])):(o&&o.right&&s.push([o.right,u+1]),o&&o.left&&s.push([o.left,u+1]))}}return i}getPredecessor(e){if(e.left){let t=e.left;for(;!t||t.right&&t.right!==e;)t&&(t=t.right);return t}else return e}getSuccessor(e){if(e.right)return this.getLeftMost(e.right);let t=e.parent;for(;t&&t&&e===t.right;)e=t,t=t.parent;return t}morris(e=this.defaultOneParamCallback,t="in",r=this.root){if(r===null)return[];let n=[],i=r,s=o=>{let u=null,f=null;for(;o;)f=o.right,o.right=u,u=o,o=f;return u},l=o=>{let u=s(o),f=u;for(;f;)n.push(e(f)),f=f.right;s(u)};switch(t){case"in":for(;i;){if(i.left){let o=this.getPredecessor(i);if(o.right)o.right=null;else{o.right=i,i=i.left;continue}}n.push(e(i)),i=i.right}break;case"pre":for(;i;){if(i.left){let o=this.getPredecessor(i);if(o.right)o.right=null;else{o.right=i,n.push(e(i)),i=i.left;continue}}else n.push(e(i));i=i.right}break;case"post":for(;i;){if(i.left){let o=this.getPredecessor(i);if(o.right===null){o.right=i,i=i.left;continue}else o.right=null,l(i.left)}i=i.right}l(r);break}return n}*[Symbol.iterator](e=this.root){if(e)if(this.iterationType==="ITERATIVE"){let t=[],r=e;for(;r||t.length>0;){for(;r;)t.push(r),r=r.left;r=t.pop(),r&&(yield r.key),r&&(r=r.right)}}else e.left&&(yield*this[Symbol.iterator](e.left)),yield e.key,e.right&&(yield*this[Symbol.iterator](e.right))}defaultOneParamCallback=e=>e.key;_swap(e,t){let{key:r,value:n}=t,i=this.createNode(r,n);return i&&(t.key=e.key,t.value=e.value,e.key=i.key,e.value=i.value),t}_addTo(e,t){if(t)return t.left===void 0?(t.left=e,e&&(this._size=this.size+1),t.left):t.right===void 0?(t.right=e,e&&(this._size=this.size+1),t.right):void 0}_setRoot(e){e&&(e.parent=void 0),this._root=e}print(e=this.root){let t=n=>{let[i,,,]=r(n);for(let s of i)console.log(s)},r=n=>{if(n==null)return[[],0,0,0];if(n&&n.right===void 0&&n.left===void 0){let d=`${n.key}`,c=d.length,m=1,p=Math.floor(c/2);return[[d],c,m,p]}if(n&&n.right===void 0){let[d,c,m,p]=r(n.left),_=`${n.key}`,E=_.length,w=" ".repeat(p+1)+"_".repeat(c-p-1)+_,z=" ".repeat(p)+"/"+" ".repeat(c-p-1+E),ue=d.map(he=>he+" ".repeat(E));return[[w,z,...ue],c+E,m+2,c+Math.floor(E/2)]}if(n&&n.left===void 0){let[d,c,m,p]=r(n.right),_=`${n.key}`,E=_.length,w=_+"_".repeat(E)+" ".repeat(c-E),z=" ".repeat(p+E)+"\\"+" ".repeat(c-E-1),ue=d.map(he=>" ".repeat(p)+he);return[[w,z,...ue],c+E,m+2,Math.floor(p/2)]}let[i,s,l,o]=r(n.left),[u,f,g,N]=r(n.right),x=`${n.key}`,T=x.length,y=" ".repeat(o+1)+"_".repeat(s-o-1)+x+"_".repeat(N)+" ".repeat(f-N),b=" ".repeat(o)+"/"+" ".repeat(s-o-1+T+N)+"\\"+" ".repeat(f-N-1);l<g?i.push(...new Array(g-l).fill(" ".repeat(s))):g<l&&u.push(...new Array(l-g).fill(" ".repeat(f)));let h=i.map((d,c)=>d+" ".repeat(T)+u[c]);return[[y,b,...h],s+f+T,Math.max(l,g)+2,s+Math.floor(T/2)]};t(e)}};var k=class extends C{parent;constructor(e,t){super(e,t),this.parent=void 0,this._left=void 0,this._right=void 0}_left;get left(){return this._left}set left(e){e&&(e.parent=this),this._left=e}_right;get right(){return this._right}set right(e){e&&(e.parent=this),this._right=e}},D=class extends ${constructor(e){if(super(e),this._root=void 0,e!==void 0){let{comparator:t}=e;t!==void 0&&(this._comparator=t)}}_root=void 0;get root(){return this._root}createNode(e,t){return new k(e,t)}add(e,t){if(e===8)debugger;if(e===null)return;let r,n;if(e instanceof k?n=e:typeof e=="number"?n=this.createNode(e,t):n=void 0,this.root===void 0)this._setRoot(n),this._size=this.size+1,r=this.root;else{let i=this.root,s=!0;for(;s;)i!==void 0&&n!==void 0?this._compare(i.key,n.key)==="eq"?(n&&(i.value=n.value),s=!1,r=i):this._compare(i.key,n.key)==="gt"?i.left===void 0?(n&&(n.parent=i),i.left=n,this._size=this.size+1,s=!1,r=i.left):i.left&&(i=i.left):this._compare(i.key,n.key)==="lt"&&(i.right===void 0?(n&&(n.parent=i),i.right=n,this._size=this.size+1,s=!1,r=i.right):i.right&&(i=i.right)):s=!1}return r}addMany(e,t,r=!0,n=this.iterationType){function i(y){return y.indexOf(void 0)===-1}if(!r||!i(e))return super.addMany(e,t).map(y=>y??void 0);let s=[],l=e.map((y,b)=>[y,t?.[b]]),o=[];function u(y){for(let[b]of y)if(b instanceof k)return!0;return!1}function f(y){for(let[b]of y)if(typeof b=="number")return!0;return!1}let g=[],N=[];if(u(l))o=l.sort((y,b)=>y[0].key-b[0].key);else if(f(l))o=l.sort((y,b)=>y[0]-b[0]);else throw new Error("Invalid input keysOrNodes");g=o.map(([y])=>y),N=o.map(([,y])=>y);let x=(y,b)=>{if(y.length===0)return;let h=Math.floor((y.length-1)/2),d=this.add(y[h],b?.[h]);s.push(d),x(y.slice(0,h),b?.slice(0,h)),x(y.slice(h+1),b?.slice(h+1))},T=()=>{let b=[[0,o.length-1]];for(;b.length>0;){let h=b.pop();if(h){let[d,c]=h;if(d<=c){let m=d+Math.floor((c-d)/2),p=this.add(g[m],N?.[m]);s.push(p),b.push([m+1,c]),b.push([d,m-1])}}}};return n==="RECURSIVE"?x(g,N):T(),s}lastKey(e=this.root,t=this.iterationType){return this._compare(0,1)==="lt"?this.getRightMost(e,t)?.key??0:this._compare(0,1)==="gt"?this.getLeftMost(e,t)?.key??0:this.getRightMost(e,t)?.key??0}getNodes(e,t=this.defaultOneParamCallback,r=!1,n=this.root,i=this.iterationType){if(!n)return[];let s=[];if(i==="RECURSIVE"){let l=o=>{t(o)===e&&(s.push(o),r)||!o.left&&!o.right||(t===this.defaultOneParamCallback?(this._compare(o.key,e)==="gt"&&o.left&&l(o.left),this._compare(o.key,e)==="lt"&&o.right&&l(o.right)):(o.left&&l(o.left),o.right&&l(o.right)))};l(n)}else{let l=new O([n]);for(;l.size>0;){let o=l.shift();if(o){if(t(o)===e&&(s.push(o),r))return s;t===this.defaultOneParamCallback?(this._compare(o.key,e)==="gt"&&o.left&&l.push(o.left),this._compare(o.key,e)==="lt"&&o.right&&l.push(o.right)):(o.left&&l.push(o.left),o.right&&l.push(o.right))}}}return s}lesserOrGreaterTraverse(e=this.defaultOneParamCallback,t="lt",r=this.root,n=this.iterationType){typeof r=="number"&&(r=this.getNode(r)??void 0);let i=[];if(!r)return i;let s=r.key;if(!this.root)return i;if(n==="RECURSIVE"){let l=o=>{this._compare(o.key,s)===t&&i.push(e(o)),!(!o.left&&!o.right)&&(o.left&&this._compare(o.left.key,s)===t&&l(o.left),o.right&&this._compare(o.right.key,s)===t&&l(o.right))};return l(this.root),i}else{let l=new O([this.root]);for(;l.size>0;){let o=l.shift();o&&(this._compare(o.key,s)===t&&i.push(e(o)),o.left&&this._compare(o.left.key,s)===t&&l.push(o.left),o.right&&this._compare(o.right.key,s)===t&&l.push(o.right))}return i}}perfectlyBalance(e=this.iterationType){let t=this.dfs(n=>n,"in"),r=t.length;if(this.clear(),t.length<1)return!1;if(e==="RECURSIVE"){let n=(i,s)=>{if(i>s)return;let l=i+Math.floor((s-i)/2),o=t[l];this.add(o.key,o.value),n(i,l-1),n(l+1,s)};return n(0,r-1),!0}else{let n=[[0,r-1]];for(;n.length>0;){let i=n.pop();if(i){let[s,l]=i;if(s<=l){let o=s+Math.floor((l-s)/2),u=t[o];debugger;this.add(u.key,u.value),n.push([o+1,l]),n.push([s,o-1])}}}return!0}}isAVLBalanced(e=this.iterationType){if(!this.root)return!0;let t=!0;if(e==="RECURSIVE"){let r=n=>{if(!n)return 0;let i=r(n.left),s=r(n.right);return Math.abs(i-s)>1&&(t=!1),Math.max(i,s)+1};r(this.root)}else{let r=[],n=this.root,i,s=new Map;for(;r.length>0||n;)if(n)r.push(n),n=n.left;else if(n=r[r.length-1],!n.right||i===n.right){if(n=r.pop(),n){let l=n.left?s.get(n.left)??-1:-1,o=n.right?s.get(n.right)??-1:-1;if(Math.abs(l-o)>1)return!1;s.set(n,1+Math.max(l,o)),i=n,n=void 0}}else n=n.right}return t}_comparator=(e,t)=>e-t;_setRoot(e){e&&(e.parent=void 0),this._root=e}_compare(e,t){let r=this._comparator(e,t);return r>0?"gt":r<0?"lt":"eq"}};var De=class{_freq;_max;constructor({frequency:e=0,max:t}){this._freq=e,this._max=t,this._freqMap={0:0},this._msb=Be(t),this._negativeCount=e<0?t:0}_freqMap;get freqMap(){return this._freqMap}_msb;get msb(){return this._msb}_negativeCount;get negativeCount(){return this._negativeCount}get freq(){return this._freq}get max(){return this._max}readSingle(e){return this._checkIndex(e),this._readSingle(e)}update(e,t){this._checkIndex(e);let r=this._readSingle(e);this._update(e,t),this._updateNegativeCount(r,r+t)}writeSingle(e,t){this._checkIndex(e),this._writeSingle(e,t)}read(e){if(!Number.isInteger(e))throw new Error("Invalid count");return this._read(Math.max(Math.min(e,this.max),0))}lowerBound(e){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(e,(t,r)=>t<r)}upperBound(e){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(e,(t,r)=>t<=r)}getPrefixSum(e){this._checkIndex(e),e++;let t=0;for(;e>0;)t+=this._getFrequency(e),e-=e&-e;return t}_getFrequency(e){return e in this.freqMap?this.freqMap[e]:this.freq*(e&-e)}_updateFrequency(e,t){this.freqMap[e]=this._getFrequency(e)+t}_checkIndex(e){if(!Number.isInteger(e))throw new Error("Invalid index: Index must be an integer.");if(e<0||e>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(e){e=e+1;let t=this._getFrequency(e),r=e-(e&-e);for(e--;e!==r;)t-=this._getFrequency(e),e-=e&-e;return t}_updateNegativeCount(e,t){e<0&&t>=0?this._negativeCount--:e>=0&&t<0&&this._negativeCount++}_update(e,t){for(e=e+1;e<=this.max;)this._updateFrequency(e,t),e+=e&-e}_writeSingle(e,t){let r=this._readSingle(e);this._update(e,t-r),this._updateNegativeCount(r,t)}_read(e){let t=e,r=0;for(;t;)r+=this._getFrequency(t),t-=t&-t;return r}_binarySearch(e,t){let r=0,n=this.msb<<1,i=e;for(;n>r+1;){let s=r+n>>1,l=this._getFrequency(s);s<=this.max&&t(l,i)?(i-=l,r=s):n=s}return r}};var H=class{start=0;end=0;value=null;sum=0;left=null;right=null;constructor(e,t,r,n){this.start=e,this.end=t,this.sum=r,this.value=n||null}},Fe=class{constructor(e,t,r){t=t||0,r=r||e.length-1,this._values=e,this._start=t,this._end=r,e.length>0?this._root=this.build(t,r):(this._root=null,this._values=[])}_values=[];get values(){return this._values}_start=0;get start(){return this._start}_end;get end(){return this._end}_root;get root(){return this._root}build(e,t){if(e>t)return new H(e,t,0);if(e===t)return new H(e,t,this._values[e]);let r=e+Math.floor((t-e)/2),n=this.build(e,r),i=this.build(r+1,t),s=new H(e,t,n.sum+i.sum);return s.left=n,s.right=i,s}updateNode(e,t,r){let n=this.root||null;if(!n)return;let i=(s,l,o,u)=>{if(s.start===s.end&&s.start===l){s.sum=o,u!==void 0&&(s.value=u);return}let f=s.start+Math.floor((s.end-s.start)/2);l<=f?s.left&&i(s.left,l,o,u):s.right&&i(s.right,l,o,u),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};i(n,e,t,r)}querySumByRange(e,t){let r=this.root||null;if(!r)return 0;if(e<0||t>=this.values.length||e>t)return NaN;let n=(i,s,l)=>{if(s<=i.start&&l>=i.end)return i.sum;let o=i.start+Math.floor((i.end-i.start)/2);if(l<=o)return i.left?n(i.left,s,l):NaN;if(s>o)return i.right?n(i.right,s,l):NaN;{let u=0,f=0;return i.left&&(u=n(i.left,s,o)),i.right&&(f=n(i.right,o+1,l)),u+f}};return n(r,e,t)}};var F=class extends k{height;constructor(e,t){super(e,t),this.height=0}},J=class extends D{constructor(e){super(e)}createNode(e,t){return new F(e,t)}add(e,t){if(e===null)return;let r=super.add(e,t);return r&&this._balancePath(r),r}delete(e,t=this.defaultOneParamCallback){e instanceof F&&(t=n=>n);let r=super.delete(e,t);for(let{needBalanced:n}of r)n&&this._balancePath(n);return r}_swap(e,t){let{key:r,value:n,height:i}=t,s=this.createNode(r,n);return s&&(s.height=i,t.key=e.key,t.value=e.value,t.height=e.height,e.key=s.key,e.value=s.value,e.height=s.height),t}_balanceFactor(e){return e.right?e.left?e.right.height-e.left.height:+e.height:-e.height}_updateHeight(e){if(!e.left&&!e.right)e.height=0;else if(e.left)e.right?e.height=1+Math.max(e.right.height,e.left.height):e.height=1+e.left.height;else{let t=e.right?e.right.height:0;e.height=1+t}}_balancePath(e){let t=this.getPathToRoot(e,!1);for(let r=0;r<t.length;r++){let n=t[r];switch(this._updateHeight(n),this._balanceFactor(n)){case-2:n&&n.left&&(this._balanceFactor(n.left)<=0?this._balanceLL(n):this._balanceLR(n));break;case 2:n&&n.right&&(this._balanceFactor(n.right)>=0?this._balanceRR(n):this._balanceRL(n))}}}_balanceLL(e){let t=e.parent,r=e.left;e.parent=r,r&&r.right&&(r.right.parent=e),r&&(r.parent=t),e===this.root?r&&this._setRoot(r):t?.left===e?t.left=r:t&&(t.right=r),r&&(e.left=r.right,r.right=e),this._updateHeight(e),r&&this._updateHeight(r)}_balanceLR(e){let t=e.parent,r=e.left,n;r&&(n=r.right),e&&(e.parent=n),r&&(r.parent=n),n&&(n.left&&(n.left.parent=r),n.right&&(n.right.parent=e),n.parent=t),e===this.root?n&&this._setRoot(n):t&&(t.left===e?t.left=n:t.right=n),n&&(e.left=n.right,r&&(r.right=n.left),n.left=r,n.right=e),this._updateHeight(e),r&&this._updateHeight(r),n&&this._updateHeight(n)}_balanceRR(e){let t=e.parent,r=e.right;e.parent=r,r&&(r.left&&(r.left.parent=e),r.parent=t),e===this.root?r&&this._setRoot(r):t&&(t.left===e?t.left=r:t.right=r),r&&(e.right=r.left,r.left=e),this._updateHeight(e),r&&this._updateHeight(r)}_balanceRL(e){let t=e.parent,r=e.right,n;r&&(n=r.left),e.parent=n,r&&(r.parent=n),n&&(n.left&&(n.left.parent=e),n.right&&(n.right.parent=r),n.parent=t),e===this.root?n&&this._setRoot(n):t&&(t.left===e?t.left=n:t.right=n),n&&(e.right=n.left),r&&n&&(r.left=n.right),n&&(n.left=e),n&&(n.right=r),this._updateHeight(e),r&&this._updateHeight(r),n&&this._updateHeight(n)}};var P=class extends k{color;constructor(e,t,r=0){super(e,t),this.color=r}},ze=class extends D{constructor(e){super(e),this._root=this.NIL}_root;get root(){return this._root}_size=0;get size(){return this._size}NIL=new P(NaN);add(e,t){let r;if(typeof e=="number")r=this.createNode(e,t,1);else if(e instanceof P)r=e;else return void 0;r.left=this.NIL,r.right=this.NIL;let n,i=this.root;for(;i!==this.NIL;)n=i,i&&r.key<i.key?i=i.left:i=i?.right;if(r.parent=n,n===void 0?this._setRoot(r):r.key<n.key?n.left=r:n.right=r,r.parent===void 0){r.color=0,this._size++;return}if(r.parent.parent===void 0){this._size++;return}this._fixInsert(r),this._size++}createNode(e,t,r=0){return new P(e,t,r)}delete(e,t=this.defaultOneParamCallback){let r=[];return e===null||(i=>{let s=this.NIL,l,o;for(;i!==this.NIL;)i&&t(i)===e&&(s=i),i&&e&&t(i)<=e?i=i.right:i=i?.left;if(s===this.NIL){this._size--;return}o=s;let u=o.color;s.left===this.NIL?(l=s.right,this._rbTransplant(s,s.right)):s.right===this.NIL?(l=s.left,this._rbTransplant(s,s.left)):(o=this.getLeftMost(s.right),u=o.color,l=o.right,o.parent===s?l.parent=o:(this._rbTransplant(o,o.right),o.right=s.right,o.right.parent=o),this._rbTransplant(s,o),o.left=s.left,o.left.parent=o,o.color=s.color),u===0&&this._fixDelete(l),this._size--})(this.root),r}isNode(e){return e!==this.NIL&&e!==void 0}getNode(e,t=this.defaultOneParamCallback,r=this.root,n=this.iterationType){return e instanceof C&&(t=i=>i),this.getNodes(e,t,!0,r,n)[0]??void 0}getLeftMost(e=this.root){for(;e.left!==void 0&&e.left!==this.NIL;)e=e.left;return e}getRightMost(e){for(;e.right!==void 0&&e.right!==this.NIL;)e=e.right;return e}getSuccessor(e){if(e.right!==this.NIL)return this.getLeftMost(e.right);let t=e.parent;for(;t!==this.NIL&&t!==void 0&&e===t.right;)e=t,t=t.parent;return t}getPredecessor(e){if(e.left!==this.NIL)return this.getRightMost(e.left);let t=e.parent;for(;t!==this.NIL&&e===t.left;)e=t,t=t.parent;return t}clear(){this._root=this.NIL,this._size=0}_setRoot(e){e&&(e.parent=void 0),this._root=e}_leftRotate(e){if(e.right){let t=e.right;e.right=t.left,t.left!==this.NIL&&t.left&&(t.left.parent=e),t.parent=e.parent,e.parent===void 0?this._setRoot(t):e===e.parent.left?e.parent.left=t:e.parent.right=t,t.left=e,e.parent=t}}_rightRotate(e){if(e.left){let t=e.left;e.left=t.right,t.right!==this.NIL&&t.right&&(t.right.parent=e),t.parent=e.parent,e.parent===void 0?this._setRoot(t):e===e.parent.right?e.parent.right=t:e.parent.left=t,t.right=e,e.parent=t}}_fixDelete(e){let t;for(;e!==this.root&&e.color===0;)e.parent&&e===e.parent.left?(t=e.parent.right,t.color===1&&(t.color=0,e.parent.color=1,this._leftRotate(e.parent),t=e.parent.right),t.left!==void 0&&t.left.color===0&&t.right&&t.right.color===0?(t.color=1,e=e.parent):(t.right&&t.right.color===0&&(t.left&&(t.left.color=0),t.color=1,this._rightRotate(t),t=e.parent.right),t&&(t.color=e.parent.color),e.parent.color=0,t&&t.right&&(t.right.color=0),this._leftRotate(e.parent),e=this.root)):(t=e.parent.left,t.color===1&&(t.color=0,e.parent.color=1,this._rightRotate(e.parent),t=e.parent.left),t&&t.right&&t.right.color===0&&t.right.color===0?(t.color=1,e=e.parent):(t&&t.left&&t.left.color===0&&(t.right&&(t.right.color=0),t.color=1,this._leftRotate(t),t=e.parent.left),t&&(t.color=e.parent.color),e.parent.color=0,t&&t.left&&(t.left.color=0),this._rightRotate(e.parent),e=this.root));e.color=0}_rbTransplant(e,t){e.parent===void 0?this._setRoot(t):e===e.parent.left?e.parent.left=t:e.parent.right=t,t.parent=e.parent}_fixInsert(e){let t;for(;e.parent&&e.parent.color===1&&(e.parent.parent&&e.parent===e.parent.parent.right?(t=e.parent.parent.left,t&&t.color===1?(t.color=0,e.parent.color=0,e.parent.parent.color=1,e=e.parent.parent):(e===e.parent.left&&(e=e.parent,this._rightRotate(e)),e.parent.color=0,e.parent.parent.color=1,this._leftRotate(e.parent.parent))):(t=e.parent.parent.right,t&&t.color===1?(t.color=0,e.parent.color=0,e.parent.parent.color=1,e=e.parent.parent):(e===e.parent.right&&(e=e.parent,this._leftRotate(e)),e.parent.color=0,e.parent.parent.color=1,this._rightRotate(e.parent.parent))),e!==this.root););this.root.color=0}};var U=class extends F{count;constructor(e,t,r=1){super(e,t),this.count=r}},Ae=class extends J{constructor(e){super(e)}_count=0;get count(){return this._count}createNode(e,t,r){return new U(e,t,r)}add(e,t,r=1){if(e===null)return;let n,i;if(e instanceof U?i=this.createNode(e.key,e.value,e.count):e===void 0?i=void 0:i=this.createNode(e,t,r),!this.root)this._setRoot(i),this._size=this.size+1,i&&this._setCount(this.count+i.count),n=this.root;else{let s=this.root,l=!0;for(;l;)s?i&&(this._compare(s.key,i.key)==="eq"?(s.value=i.value,s.count+=i.count,this._setCount(this.count+i.count),l=!1,n=s):this._compare(s.key,i.key)==="gt"?s.left===void 0?(s.left=i,this._size=this.size+1,this._setCount(this.count+i.count),l=!1,n=s.left):s.left&&(s=s.left):this._compare(s.key,i.key)==="lt"&&(s.right===void 0?(s.right=i,this._size=this.size+1,this._setCount(this.count+i.count),l=!1,n=s.right):s.right&&(s=s.right))):l=!1}return n&&this._balancePath(n),n}_addTo(e,t){if(t)return t.left===void 0?(t.left=e,e!==void 0&&(this._size=this.size+1,this._setCount(this.count+e.count)),t.left):t.right===void 0?(t.right=e,e!==void 0&&(this._size=this.size+1,this._setCount(this.count+e.count)),t.right):void 0}addMany(e,t){let r=[];for(let n=0;n<e.length;n++){let i=e[n];if(i instanceof U){r.push(this.add(i.key,i.value,i.count));continue}if(i===void 0){r.push(this.add(NaN,void 0,0));continue}r.push(this.add(i,t?.[n],1))}return r}perfectlyBalance(e=this.iterationType){let t=this.dfs(n=>n,"in"),r=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let n=(i,s)=>{if(i>s)return;let l=i+Math.floor((s-i)/2),o=t[l];this.add(o.key,o.value,o.count),n(i,l-1),n(l+1,s)};return n(0,r-1),!0}else{let n=[[0,r-1]];for(;n.length>0;){let i=n.pop();if(i){let[s,l]=i;if(s<=l){let o=s+Math.floor((l-s)/2),u=t[o];this.add(u.key,u.value,u.count),n.push([o+1,l]),n.push([s,o-1])}}}return!0}}delete(e,t=this.defaultOneParamCallback,r=!1){let n=[];if(!this.root)return n;let i=this.getNode(e,t)??void 0;if(!i)return n;let s=i?.parent?i.parent:void 0,l,o=i;if(i.count>1&&!r)i.count--,this._setCount(this.count-1);else{if(i.left){let u=i.left?this.getRightMost(i.left):void 0;if(u){let f=u.parent;o=this._swap(i,u),f&&(f.right===u?f.right=u.left:f.left=u.left,l=f)}}else if(!s)i.right!==void 0&&this._setRoot(i.right);else{let{familyPosition:u}=i;u==="LEFT"||u==="ROOT_LEFT"?s.left=i.right:(u==="RIGHT"||u==="ROOT_RIGHT")&&(s.right=i.right),l=s}this._size=this.size-1,this._setCount(this.count-o.count)}return n.push({deleted:o,needBalanced:l}),l&&this._balancePath(l),n}clear(){super.clear(),this._setCount(0)}_swap(e,t){let{key:r,value:n,count:i,height:s}=t,l=this.createNode(r,n,i);return l&&(l.height=s,t.key=e.key,t.value=e.value,t.count=e.count,t.height=e.height,e.key=l.key,e.value=l.value,e.count=l.count,e.height=l.height),t}_setCount(e){this._count=e}};var He=class a{key;value;children;constructor(e,t,r){this.key=e,this.value=t||void 0,this.children=r||[]}addChildren(e){this.children||(this.children=[]),e instanceof a?this.children.push(e):this.children=this.children.concat(e)}getHeight(){let e=0;if(this){let t=(r,n)=>{n>e&&(e=n);let{children:i}=r;if(i)for(let s=0,l=i.length;s<l;s++)t(i[s],n+1)};t(this,0)}return e}};var Pe=class{_matrix;constructor(e){let{row:t,col:r,initialVal:n}=e;this._matrix=new Array(t).fill(void 0).map(()=>new Array(r).fill(n||0))}toArray(){return this._matrix}};var j=class a{constructor(e=0,t=0,r=1){this.x=e;this.y=t;this.w=r}get isZero(){return this.x===0&&this.y===0}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 a(Math.round(this.x),Math.round(this.y))}static add(e,t){return new a(e.x+t.x,e.y+t.y)}static subtract(e,t){return new a(e.x-t.x,e.y-t.y)}static subtractValue(e,t){return new a(e.x-t,e.y-t)}static multiply(e,t){return new a(e.x*t,e.y*t)}static divide(e,t){return new a(e.x/t,e.y/t)}static equals(e,t){return e.x===t.x&&e.y===t.y}static equalsRounded(e,t,r=12){let n=a.abs(a.subtract(e,t));return n.x<r&&n.y<r}static normalize(e){let t=e.length;return t>2220446049250313e-31?a.divide(e,t):e}static truncate(e,t){return e.length>t?a.multiply(a.normalize(e),t):e}static perp(e){return new a(-e.y,e.x)}static reverse(e){return new a(-e.x,-e.y)}static abs(e){return new a(Math.abs(e.x),Math.abs(e.y))}static dot(e,t){return e.x*t.x+e.y*t.y}static distance(e,t){let r=t.y-e.y,n=t.x-e.x;return Math.sqrt(r*r+n*n)}static distanceSq(e,t){let r=t.y-e.y,n=t.x-e.x;return r*r+n*n}static sign(e,t){return e.y*t.x>e.x*t.y?-1:1}static angle(e){let t=new a(0,-1),r=Math.acos(a.dot(e,t)/(e.length*t.length));return a.sign(e,t)===1?Math.PI*2-r:r}static random(e,t){let r=Math.floor(Math.random()*e-e/2),n=Math.floor(Math.random()*t-t/2);return new a(r,n)}zero(){this.x=0,this.y=0}};var Ue=class a{_matrix;constructor(e){typeof e>"u"?this._matrix=a.identity:e instanceof j?(this._matrix=a.identity,this._matrix[0][0]=e.x,this._matrix[1][0]=e.y,this._matrix[2][0]=e.w):this._matrix=e}static get empty(){return[[],[],[]]}static get identity(){return[[1,0,0],[0,1,0],[0,0,1]]}get m(){return this._matrix}static add(e,t){let r=a.empty;for(let n=0;n<3;n++)for(let i=0;i<3;i++)r[n][i]=e.m[n][i]+t.m[n][i];return new a(r)}static subtract(e,t){let r=a.empty;for(let n=0;n<3;n++)for(let i=0;i<3;i++)r[n][i]=e.m[n][i]-t.m[n][i];return new a(r)}static multiply(e,t){let r=a.empty;for(let n=0;n<3;n++)for(let i=0;i<3;i++){r[n][i]=0;for(let s=0;s<3;s++)r[n][i]+=e.m[n][s]*t.m[s][i]}return new a(r)}static multiplyByValue(e,t){let r=a.empty;for(let n=0;n<3;n++)for(let i=0;i<3;i++)r[n][i]=e.m[n][i]*t;return new a(r)}static multiplyByVector(e,t){return a.multiply(e,new a(t)).toVector()}static view(e,t){let n=e/2,i=t/2,s=Math.cos(Math.PI);return new a([[1,0,n],[0,s*1,i],[0,0,1]])}static scale(e){return a.multiplyByValue(new a,e)}static rotate(e){let t=Math.cos(e),r=Math.sin(e);return new a([[t,-r,0],[r,t,0],[0,0,1]])}static translate(e){return new a([[1,0,e.x],[0,1,e.y],[0,0,e.w]])}toVector(){return new j(this._matrix[0][0],this._matrix[1][0])}};var ae=class a{direction;turn;constructor(e,t){this.direction=e,this.turn=()=>new a(t[e],t)}},je=class{onMove;_matrix;_cur;_character;_VISITED;constructor({matrix:e,turning:t,onMove:r,init:{cur:n,charDir:i,VISITED:s}}){this._matrix=e,this._cur=n,this._character=new ae(i,t),this.onMove=r,this.onMove&&this.onMove(this._cur),this._VISITED=s,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){let{direction:e}=this._character;this.check(e)?this.move(e):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(e){let t,r,n=this._matrix,[i,s]=this._cur;switch(e){case"up":if(r=n[i-1],!r)return!1;t=r[s];break;case"right":t=n[i][s+1];break;case"down":if(r=n[i+1],!r)return!1;t=r[s];break;case"left":t=n[i][s-1];break}return t!==void 0&&t!==this._VISITED}move(e){switch(e){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--;break}let[t,r]=this._cur;this._matrix[t][r]=this._VISITED,this.onMove&&this.onMove(this._cur)}};var Z=class{key;children;isEnd;constructor(e){this.key=e,this.isEnd=!1,this.children=new Map}},qe=class{constructor(e,t=!0){if(this._root=new Z(""),this._caseSensitive=t,e)for(let r of e)this.add(r)}_caseSensitive;get caseSensitive(){return this._caseSensitive}_root;get root(){return this._root}add(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);n||(n=new Z(r),t.children.set(r,n)),t=n}return t.isEnd=!0,!0}has(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);if(!n)return!1;t=n}return t.isEnd}delete(e){e=this._caseProcess(e);let t=!1,r=(n,i)=>{let s=e[i],l=n.children.get(s);return l?i===e.length-1?l.isEnd?(l.children.size>0?l.isEnd=!1:n.children.delete(s),t=!0,!0):!1:r(l,i+1)&&!n.isEnd&&l.children.size===0?(n.children.delete(s),!0):!1:!1};return r(this.root,0),t}getHeight(){let e=this.root,t=0;if(e){let r=(n,i)=>{i>t&&(t=i);let{children:s}=n;if(s)for(let l of s.entries())r(l[1],i+1)};r(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);if(!n)return!1;t=n}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);if(!n)return!1;t=n}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",r=n=>{if(t+=n.key,t!==e&&!n.isEnd)if(n&&n.children&&n.children.size===1)r(Array.from(n.children.values())[0]);else return};return r(this.root),t===e}getLongestCommonPrefix(){let e="",t=r=>{if(e+=r.key,!r.isEnd)if(r&&r.children&&r.children.size===1)t(Array.from(r.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,r=!1){e=this._caseProcess(e);let n=[],i=0;function s(o,u){for(let f of o.children.keys()){let g=o.children.get(f);g!==void 0&&s(g,u.concat(f))}if(o.isEnd){if(i>t-1)return;n.push(u),i++}}let l=this.root;if(e)for(let o of e){let u=l.children.get(o);u&&(l=u)}return(r||l!==this.root)&&s(l,e),n}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};return Je(et);})();
2
2
  /**
3
3
  * data-structure-typed
4
4
  *