data-structure-typed 1.39.1 → 1.39.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  3. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  4. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +11 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.js +38 -0
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  10. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  11. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  12. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  13. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  14. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  15. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  16. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  17. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  18. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  19. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -28
  20. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +59 -49
  21. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  22. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +75 -7
  23. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +110 -9
  24. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  25. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  26. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  27. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  28. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  29. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  30. package/dist/cjs/data-structures/queue/deque.d.ts +20 -20
  31. package/dist/cjs/data-structures/queue/deque.js +22 -22
  32. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  33. package/dist/cjs/data-structures/queue/queue.d.ts +3 -3
  34. package/dist/cjs/data-structures/queue/queue.js +3 -3
  35. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  36. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +11 -1
  37. package/dist/mjs/data-structures/binary-tree/binary-tree.js +38 -0
  38. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -28
  39. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +59 -49
  40. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +75 -7
  41. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +110 -9
  42. package/dist/mjs/data-structures/queue/deque.d.ts +20 -20
  43. package/dist/mjs/data-structures/queue/deque.js +22 -22
  44. package/dist/mjs/data-structures/queue/queue.d.ts +3 -3
  45. package/dist/mjs/data-structures/queue/queue.js +3 -3
  46. package/dist/umd/data-structure-typed.min.js +1 -1
  47. package/dist/umd/data-structure-typed.min.js.map +1 -1
  48. package/package.json +5 -5
  49. package/src/data-structures/binary-tree/avl-tree.ts +2 -3
  50. package/src/data-structures/binary-tree/binary-indexed-tree.ts +1 -1
  51. package/src/data-structures/binary-tree/binary-tree.ts +47 -5
  52. package/src/data-structures/binary-tree/bst.ts +1 -2
  53. package/src/data-structures/binary-tree/rb-tree.ts +1 -2
  54. package/src/data-structures/binary-tree/tree-multiset.ts +1 -2
  55. package/src/data-structures/graph/abstract-graph.ts +10 -11
  56. package/src/data-structures/graph/directed-graph.ts +1 -2
  57. package/src/data-structures/graph/undirected-graph.ts +4 -5
  58. package/src/data-structures/hash/hash-map.ts +1 -1
  59. package/src/data-structures/hash/tree-map.ts +2 -1
  60. package/src/data-structures/hash/tree-set.ts +2 -1
  61. package/src/data-structures/heap/heap.ts +2 -2
  62. package/src/data-structures/heap/max-heap.ts +1 -1
  63. package/src/data-structures/heap/min-heap.ts +1 -1
  64. package/src/data-structures/linked-list/doubly-linked-list.ts +62 -56
  65. package/src/data-structures/linked-list/singly-linked-list.ts +119 -14
  66. package/src/data-structures/matrix/matrix.ts +1 -1
  67. package/src/data-structures/matrix/vector2d.ts +2 -1
  68. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  69. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  70. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  71. package/src/data-structures/queue/deque.ts +27 -26
  72. package/src/data-structures/queue/queue.ts +4 -4
  73. package/src/types/data-structures/matrix/navigator.ts +1 -1
  74. package/src/types/utils/utils.ts +1 -1
  75. package/src/types/utils/validate-type.ts +2 -2
  76. package/test/integration/bst.test.ts +1 -1
  77. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +1 -1
  78. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +23 -3
  79. package/test/unit/data-structures/binary-tree/bst.test.ts +6 -6
  80. package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
  81. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -2
  82. package/test/unit/data-structures/hash/coordinate-map.test.ts +20 -0
  83. package/test/unit/data-structures/hash/coordinate-set.test.ts +25 -0
  84. package/test/unit/data-structures/hash/hash-table.test.ts +3 -1
  85. package/test/unit/data-structures/heap/heap.test.ts +2 -2
  86. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +70 -7
  87. package/test/unit/data-structures/linked-list/linked-list.test.ts +2 -2
  88. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +60 -13
  89. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +2 -2
  90. package/test/unit/data-structures/queue/deque.test.ts +43 -43
  91. package/test/unit/data-structures/queue/queue.test.ts +7 -7
  92. package/test/utils/big-o.ts +1 -1
@@ -37,25 +37,25 @@ export declare class ObjectDeque<E = number> {
37
37
  */
38
38
  addLast(value: E): void;
39
39
  /**
40
- * The function `pollFirst()` removes and returns the first element in a data structure.
40
+ * The function `popFirst()` removes and returns the first element in a data structure.
41
41
  * @returns The value of the first element in the data structure.
42
42
  */
43
- pollFirst(): E | undefined;
43
+ popFirst(): E | undefined;
44
44
  /**
45
- * The `peekFirst` function returns the first element in an array-like data structure if it exists.
45
+ * The `getFirst` function returns the first element in an array-like data structure if it exists.
46
46
  * @returns The element at the first position of the `_nodes` array.
47
47
  */
48
- peekFirst(): E | undefined;
48
+ getFirst(): E | undefined;
49
49
  /**
50
- * The `pollLast()` function removes and returns the last element in a data structure.
50
+ * The `popLast()` function removes and returns the last element in a data structure.
51
51
  * @returns The value that was removed from the data structure.
52
52
  */
53
- pollLast(): E | undefined;
53
+ popLast(): E | undefined;
54
54
  /**
55
- * The `peekLast()` function returns the last element in an array-like data structure.
55
+ * The `getLast()` function returns the last element in an array-like data structure.
56
56
  * @returns The last element in the array "_nodes" is being returned.
57
57
  */
58
- peekLast(): E | undefined;
58
+ getLast(): E | undefined;
59
59
  /**
60
60
  * The get function returns the element at the specified index in an array-like data structure.
61
61
  * @param {number} index - The index parameter is a number that represents the position of the element you want to
@@ -87,16 +87,16 @@ export declare class ArrayDeque<E> {
87
87
  */
88
88
  addLast(value: E): number;
89
89
  /**
90
- * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
91
- * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
90
+ * The function "popLast" returns and removes the last element from an array, or returns null if the array is empty.
91
+ * @returns The method `popLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
92
92
  */
93
- pollLast(): E | null;
93
+ popLast(): E | null;
94
94
  /**
95
- * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
96
- * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
95
+ * The `popFirst` function removes and returns the first element from an array, or returns null if the array is empty.
96
+ * @returns The `popFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
97
97
  * empty.
98
98
  */
99
- pollFirst(): E | null;
99
+ popFirst(): E | null;
100
100
  /**
101
101
  * O(n) time complexity of adding at the beginning and the end
102
102
  */
@@ -108,16 +108,16 @@ export declare class ArrayDeque<E> {
108
108
  */
109
109
  addFirst(value: E): number;
110
110
  /**
111
- * The `peekFirst` function returns the first element of an array or null if the array is empty.
112
- * @returns The function `peekFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
111
+ * The `getFirst` function returns the first element of an array or null if the array is empty.
112
+ * @returns The function `getFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
113
113
  * empty, it will return `null`.
114
114
  */
115
- peekFirst(): E | null;
115
+ getFirst(): E | null;
116
116
  /**
117
- * The `peekLast` function returns the last element of an array or null if the array is empty.
118
- * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
117
+ * The `getLast` function returns the last element of an array or null if the array is empty.
118
+ * @returns The method `getLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
119
119
  */
120
- peekLast(): E | null;
120
+ getLast(): E | null;
121
121
  /**
122
122
  * O(1) time complexity of obtaining the value
123
123
  */
@@ -85,44 +85,44 @@ class ObjectDeque {
85
85
  this._size++;
86
86
  }
87
87
  /**
88
- * The function `pollFirst()` removes and returns the first element in a data structure.
88
+ * The function `popFirst()` removes and returns the first element in a data structure.
89
89
  * @returns The value of the first element in the data structure.
90
90
  */
91
- pollFirst() {
91
+ popFirst() {
92
92
  if (!this._size)
93
93
  return;
94
- const value = this.peekFirst();
94
+ const value = this.getFirst();
95
95
  delete this._nodes[this._first];
96
96
  this._first++;
97
97
  this._size--;
98
98
  return value;
99
99
  }
100
100
  /**
101
- * The `peekFirst` function returns the first element in an array-like data structure if it exists.
101
+ * The `getFirst` function returns the first element in an array-like data structure if it exists.
102
102
  * @returns The element at the first position of the `_nodes` array.
103
103
  */
104
- peekFirst() {
104
+ getFirst() {
105
105
  if (this._size)
106
106
  return this._nodes[this._first];
107
107
  }
108
108
  /**
109
- * The `pollLast()` function removes and returns the last element in a data structure.
109
+ * The `popLast()` function removes and returns the last element in a data structure.
110
110
  * @returns The value that was removed from the data structure.
111
111
  */
112
- pollLast() {
112
+ popLast() {
113
113
  if (!this._size)
114
114
  return;
115
- const value = this.peekLast();
115
+ const value = this.getLast();
116
116
  delete this._nodes[this._last];
117
117
  this._last--;
118
118
  this._size--;
119
119
  return value;
120
120
  }
121
121
  /**
122
- * The `peekLast()` function returns the last element in an array-like data structure.
122
+ * The `getLast()` function returns the last element in an array-like data structure.
123
123
  * @returns The last element in the array "_nodes" is being returned.
124
124
  */
125
- peekLast() {
125
+ getLast() {
126
126
  if (this._size)
127
127
  return this._nodes[this._last];
128
128
  }
@@ -170,18 +170,18 @@ class ArrayDeque {
170
170
  return this._nodes.push(value);
171
171
  }
172
172
  /**
173
- * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
174
- * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
173
+ * The function "popLast" returns and removes the last element from an array, or returns null if the array is empty.
174
+ * @returns The method `popLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
175
175
  */
176
- pollLast() {
176
+ popLast() {
177
177
  return this._nodes.pop() ?? null;
178
178
  }
179
179
  /**
180
- * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
181
- * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
180
+ * The `popFirst` function removes and returns the first element from an array, or returns null if the array is empty.
181
+ * @returns The `popFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
182
182
  * empty.
183
183
  */
184
- pollFirst() {
184
+ popFirst() {
185
185
  return this._nodes.shift() ?? null;
186
186
  }
187
187
  /**
@@ -197,18 +197,18 @@ class ArrayDeque {
197
197
  return this._nodes.unshift(value);
198
198
  }
199
199
  /**
200
- * The `peekFirst` function returns the first element of an array or null if the array is empty.
201
- * @returns The function `peekFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
200
+ * The `getFirst` function returns the first element of an array or null if the array is empty.
201
+ * @returns The function `getFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
202
202
  * empty, it will return `null`.
203
203
  */
204
- peekFirst() {
204
+ getFirst() {
205
205
  return this._nodes[0] ?? null;
206
206
  }
207
207
  /**
208
- * The `peekLast` function returns the last element of an array or null if the array is empty.
209
- * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
208
+ * The `getLast` function returns the last element of an array or null if the array is empty.
209
+ * @returns The method `getLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
210
210
  */
211
- peekLast() {
211
+ getLast() {
212
212
  return this._nodes[this._nodes.length - 1] ?? null;
213
213
  }
214
214
  /**
@@ -68,11 +68,11 @@ export declare class Queue<E = any> {
68
68
  */
69
69
  peek(): E | undefined;
70
70
  /**
71
- * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
72
- * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
71
+ * The `getLast` function returns the last element in an array-like data structure, or null if the structure is empty.
72
+ * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
73
73
  * array is empty, it returns `null`.
74
74
  */
75
- peekLast(): E | undefined;
75
+ getLast(): E | undefined;
76
76
  /**
77
77
  * The enqueue function adds a value to the end of a queue.
78
78
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -110,11 +110,11 @@ class Queue {
110
110
  return this.size > 0 ? this.nodes[this.offset] : undefined;
111
111
  }
112
112
  /**
113
- * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
114
- * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
113
+ * The `getLast` function returns the last element in an array-like data structure, or null if the structure is empty.
114
+ * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
115
115
  * array is empty, it returns `null`.
116
116
  */
117
- peekLast() {
117
+ getLast() {
118
118
  return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
119
119
  }
120
120
  /**
@@ -1,4 +1,4 @@
1
- "use strict";var dataStructureTyped=(()=>{var ae=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var We=Object.prototype.hasOwnProperty;var Xe=(a,e)=>{for(var t in e)ae(a,t,{get:e[t],enumerable:!0})},Ye=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ge(e))!We.call(a,n)&&n!==t&&ae(a,n,{get:()=>e[n],enumerable:!(r=Ue(e,n))||r.enumerable});return a};var Qe=a=>Ye(ae({},"__esModule",{value:!0}),a);var Ze={};Xe(Ze,{AVLTree:()=>Q,AVLTreeNode:()=>H,AbstractEdge:()=>R,AbstractGraph:()=>L,AbstractVertex:()=>N,ArrayDeque:()=>xe,BST:()=>I,BSTNode:()=>C,BinaryIndexedTree:()=>Le,BinaryTree:()=>Y,BinaryTreeNode:()=>k,CP:()=>se,Character:()=>le,CoordinateMap:()=>ue,CoordinateSet:()=>de,Deque:()=>_e,DirectedEdge:()=>z,DirectedGraph:()=>W,DirectedVertex:()=>D,DoublyLinkedList:()=>U,DoublyLinkedListNode:()=>K,FamilyPosition:()=>ie,FibonacciHeap:()=>we,FibonacciHeapNode:()=>$,HashMap:()=>pe,HashTable:()=>he,HashTableNode:()=>q,Heap:()=>M,IterationType:()=>X,LinkedListQueue:()=>ye,MapEdge:()=>ne,MapGraph:()=>Se,MapVertex:()=>re,Matrix2D:()=>He,MatrixNTI2D:()=>Oe,MaxHeap:()=>ke,MaxPriorityQueue:()=>Ce,MinHeap:()=>Be,MinPriorityQueue:()=>Ke,Navigator:()=>Ae,ObjectDeque:()=>be,PriorityQueue:()=>S,Queue:()=>T,RBColor:()=>Re,RBTree:()=>Ie,RBTreeNode:()=>oe,SegmentTree:()=>De,SegmentTreeNode:()=>O,SinglyLinkedList:()=>j,SinglyLinkedListNode:()=>B,SkipList:()=>me,SkipListNode:()=>G,Stack:()=>ge,THUNK_SYMBOL:()=>Ee,TopologicalProperty:()=>je,TreeMap:()=>fe,TreeMultiset:()=>Fe,TreeMultisetNode:()=>A,TreeNode:()=>ze,TreeSet:()=>ce,Trie:()=>Pe,TrieNode:()=>J,UndirectedEdge:()=>te,UndirectedGraph:()=>Me,UndirectedVertex:()=>ee,Vector2D:()=>P,arrayRemove:()=>w,getMSB:()=>ve,isThunk:()=>Ne,toThunk:()=>Te,trampoline:()=>Z,trampolineAsync:()=>Je,uuidV4:()=>Ve});var q=class{key;val;next;constructor(e,t){this.key=e,this.val=t,this.next=null}},he=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}set capacity(e){this._capacity=e}_size;get size(){return this._size}_buckets;get buckets(){return this._buckets}set buckets(e){this._buckets=e}_hashFn;get hashFn(){return this._hashFn}set hashFn(e){this._hashFn=e}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.val=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.val;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 q(n.key,n.val);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 ue=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))}_setJoint(e){this._joint=e}};var de=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))}_setJoint(e){this._joint=e}};var fe=class{};var ce=class{};var pe=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}set initialCapacity(e){this._initialCapacity=e}_loadFactor;get loadFactor(){return this._loadFactor}set loadFactor(e){this._loadFactor=e}_capacityMultiplier;get capacityMultiplier(){return this._capacityMultiplier}set capacityMultiplier(e){this._capacityMultiplier=e}_size;get size(){return this._size}set size(e){this._size=e}_table;get table(){return this._table}set table(e){this._table=e}_hashFn;get hashFn(){return this._hashFn}set hashFn(e){this._hashFn=e}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 B=class{constructor(e){this._val=e,this._next=null}_val;get val(){return this._val}set val(e){this._val=e}_next;get next(){return this._next}set next(e){this._next=e}},j=class a{constructor(){this._head=null,this._tail=null,this._length=0}_head;get head(){return this._head}set head(e){this._head=e}_tail;get tail(){return this._tail}set tail(e){this._tail=e}_length;get length(){return this._length}static fromArray(e){let t=new a;for(let r of e)t.push(r);return t}getLength(){return this._length}push(e){let t=new B(e);this.head?(this.tail.next=t,this.tail=t):(this.head=t,this.tail=t),this._length++}pop(){if(!this.head)return;if(this.head===this.tail){let r=this.head.val;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.val;return e.next=null,this.tail=e,this._length--,t}shift(){if(!this.head)return;let e=this.head;return this.head=this.head.next,this._length--,e.val}unshift(e){let t=new B(e);this.head?(t.next=this.head,this.head=t):(this.head=t,this.tail=t),this._length++}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.val}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.val}delete(e){if(!e)return!1;let t;e instanceof B?t=e.val:t=e;let r=this.head,n=null;for(;r;){if(r.val===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 B(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.val),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.val))return t.val;t=t.next}return null}indexOf(e){let t=0,r=this.head;for(;r;){if(r.val===e)return t;t++,r=r.next}return-1}findNode(e){let t=this.head;for(;t;){if(t.val===e)return t;t=t.next}return null}insertBefore(e,t){if(!this.head)return!1;let r;if(e instanceof B?r=e.val:r=e,this.head.val===r)return this.unshift(t),!0;let n=this.head;for(;n.next;){if(n.next.val===r){let i=new B(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 B?r=e:r=this.findNode(e),r){let n=new B(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.val===e&&t++,r=r.next;return t}*[Symbol.iterator](){let e=this.head;for(;e;)yield e.val,e=e.next}};var K=class{constructor(e){this._val=e,this._next=null,this._prev=null}_val;get val(){return this._val}set val(e){this._val=e}_next;get next(){return this._next}set next(e){this._next=e}_prev;get prev(){return this._prev}set prev(e){this._prev=e}},U=class a{constructor(){this._head=null,this._tail=null,this._length=0}_head;get head(){return this._head}set head(e){this._head=e}_tail;get tail(){return this._tail}set tail(e){this._tail=e}_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 K(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.val}pollLast(){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.val}pollFirst(){return this.shift()}unshift(e){let t=new K(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)}peekFirst(){return this.head?.val}peekLast(){return this.tail?.val}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.val}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}findNode(e){let t=this.head;for(;t;){if(t.val===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 K(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}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.val}delete(e){let t;if(e instanceof K?t=e:t=this.findNode(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.val),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.val))return t.val;t=t.next}return null}indexOf(e){let t=0,r=this.head;for(;r;){if(r.val===e)return t;t++,r=r.next}return-1}findLast(e){let t=this.tail;for(;t;){if(e(t.val))return t.val;t=t.prev}return null}toArrayReverse(){let e=[],t=this.tail;for(;t;)e.push(t.val),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.val,r),t=t.next,r++}map(e){let t=new a,r=this.head;for(;r;)t.push(e(r.val)),r=r.next;return t}filter(e){let t=new a,r=this.head;for(;r;)e(r.val)&&t.push(r.val),r=r.next;return t}reduce(e,t){let r=t,n=this.head;for(;n;)r=e(r,n.val),n=n.next;return r}insertAfter(e,t){let r;if(e instanceof K?r=e:r=this.findNode(e),r){let n=new K(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}insertBefore(e,t){let r;if(e instanceof K?r=e:r=this.findNode(e),r){let n=new K(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}};var G=class{key;value;forward;constructor(e,t,r){this.key=e,this.value=t,this.forward=new Array(r)}},me=class{constructor(e=16,t=.5){this._head=new G(null,null,e),this._level=0,this._maxLevel=e,this._probability=t}_head;get head(){return this._head}set head(e){this._head=e}_level;get level(){return this._level}set level(e){this._level=e}_maxLevel;get maxLevel(){return this._maxLevel}set maxLevel(e){this._maxLevel=e}_probability;get probability(){return this._probability}set probability(e){this._probability=e}add(e,t){let r=new G(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}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}randomLevel(){let e=1;for(;Math.random()<this.probability&&e<this.maxLevel;)e++;return e}};var ge=class a{_elements;constructor(e){this._elements=Array.isArray(e)?e:[]}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 ye=class extends j{enqueue(e){this.push(e)}dequeue(){return this.shift()}peek(){return this.head?.val}},T=class a{constructor(e){this._nodes=e||[],this._offset=0}_nodes;get nodes(){return this._nodes}set nodes(e){this._nodes=e}_offset;get offset(){return this._offset}set offset(e){this._offset=e}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.peek();return this.offset+=1,this.offset*2<this.nodes.length||(this.nodes=this.nodes.slice(this.offset),this.offset=0),e}peek(){return this.size>0?this.nodes[this.offset]:void 0}peekLast(){return this.size>0?this.nodes[this.nodes.length-1]:void 0}enqueue(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 U{},be=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}set capacity(e){this._capacity=e}_first=-1;get first(){return this._first}set first(e){this._first=e}_last=-1;get last(){return this._last}set last(e){this._last=e}_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++}pollFirst(){if(!this._size)return;let e=this.peekFirst();return delete this._nodes[this._first],this._first++,this._size--,e}peekFirst(){if(this._size)return this._nodes[this._first]}pollLast(){if(!this._size)return;let e=this.peekLast();return delete this._nodes[this._last],this._last--,this._size--,e}peekLast(){if(this._size)return this._nodes[this._last]}get(e){return this._nodes[this._first+e]||null}isEmpty(){return this._size<=0}_seNodes(e){this._nodes=e}_setSize(e){this._size=e}},xe=class{_nodes=[];get size(){return this._nodes.length}addLast(e){return this._nodes.push(e)}pollLast(){return this._nodes.pop()??null}pollFirst(){return this._nodes.shift()??null}addFirst(e){return this._nodes.unshift(e)}peekFirst(){return this._nodes[0]??null}peekLast(){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)})},w=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},Ee=Symbol("thunk"),Ne=a=>typeof a=="function"&&a.__THUNK__===Ee,Te=a=>{let e=()=>a();return e.__THUNK__=Ee,e},Z=a=>Object.assign((...t)=>{let r=a(...t);for(;Ne(r)&&typeof r=="function";)r=r();return r},{cont:(...t)=>Te(()=>a(...t))}),Je=a=>Object.assign(async(...t)=>{let r=await a(...t);for(;Ne(r)&&typeof r=="function";)r=await r();return r},{cont:(...t)=>Te(()=>a(...t))}),ve=a=>a<=0?0:1<<31-Math.clz32(a);var M=class a{nodes=[];comparator;constructor(e){this.comparator=e.comparator,e.nodes&&e.nodes.length>0&&(this.nodes=e.nodes,this.fix())}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)}},$=class{element;degree;left;right;child;parent;marked;constructor(e,t=0){this.element=e,this.degree=t,this.marked=!1}},we=class{root;size=0;min;comparator;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.")}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 $(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 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 Be=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 S=class extends M{constructor(e){super(e)}};var Ke=class extends S{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 Ce=class extends S{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 N=class{constructor(e,t){this._key=e,this._val=t}_key;get key(){return this._key}set key(e){this._key=e}_val;get val(){return this._val}set val(e){this._val=e}},R=class{constructor(e,t){this._weight=e!==void 0?e:1,this._val=t,this._hashCode=Ve()}_val;get val(){return this._val}set val(e){this._val=e}_weight;get weight(){return this._weight}set weight(e){this._weight=e}_hashCode;get hashCode(){return this._hashCode}_setHashCode(e){this._hashCode=e}},L=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 N)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 R)return this._addEdgeOnly(e);if(t instanceof N||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof N&&(e=e.key),t instanceof N&&(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){let r=[],n=this._getVertex(e),i=this._getVertex(t);if(!(n&&i))return[];let s=(o,l,h,d)=>{h.set(o,!0),o===l&&r.push([n,...d]);let c=this.getNeighbors(o);for(let m of c)h.get(m)||(d.push(m),s(m,l,h,d),w(d,x=>x===m));h.set(o,!1)};return s(n,i,new Map,[]),r}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 T([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 c=this.getNeighbors(d);for(let m of c)s.has(m)||(s.set(m,!0),o.push(m))}}l++}return null}}getMinPathBetween(e,t,r){if(r===void 0&&(r=!1),r){let n=this.getAllPathsBetween(e,t),i=1/0,s=-1,o=0;for(let l of n){let h=this.getPathSumWeight(l);h<i&&(i=h,s=o),o++}return n[s]||null}else{let n=[],i=this._getVertex(e),s=this._getVertex(t);if(!(i&&s))return[];let o=(l,h,d,c)=>{if(d.set(l,!0),l===h){n=[i,...c];return}let m=this.getNeighbors(l);for(let x of m)d.get(x)||(c.push(x),o(x,h,d,c),w(c,E=>E===x));d.set(l,!1)};return o(i,s,new Map,[]),n}}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,c=new Set,m=new Map,x=this._getVertex(e),E=t?this._getVertex(t):null;if(!x)return null;for(let u of h){let f=u[1];f instanceof N&&d.set(f,1/0)}d.set(x,0),m.set(x,null);let y=()=>{let u=1/0,f=null;for(let[g,_]of d)c.has(g)||_<u&&(u=_,f=g);return f},b=u=>{for(let f of h){let g=f[1];if(g instanceof N){let _=[g],p=m.get(g);for(;p;)_.push(p),p=m.get(p);let V=_.reverse();f[1]===u&&(o=V),l.push(V)}}};for(let u=1;u<h.size;u++){let f=y();if(f){if(c.add(f),E&&E===f)return r&&(i=d.get(E)||1/0),n&&b(E),{distMap:d,preMap:m,seen:c,paths:l,minDist:i,minPath:o};let g=this.getNeighbors(f);for(let _ of g)if(!c.has(_)){let p=this.getEdge(f,_);if(p){let V=d.get(f),v=d.get(_);V!==void 0&&v!==void 0&&p.weight+V<v&&(d.set(_,p.weight+V),m.set(_,f))}}}}return r&&d.forEach((u,f)=>{f!==x&&u<i&&(i=u,n&&(s=f))}),n&&b(s),{distMap:d,preMap:m,seen:c,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,c=new Set,m=new Map,x=this._getVertex(e),E=t?this._getVertex(t):null;if(!x)return null;for(let u of h){let f=u[1];f instanceof N&&d.set(f,1/0)}let y=new S({comparator:(u,f)=>u.key-f.key});y.add({key:0,val:x}),d.set(x,0),m.set(x,null);let b=u=>{for(let f of h){let g=f[1];if(g instanceof N){let _=[g],p=m.get(g);for(;p;)_.push(p),p=m.get(p);let V=_.reverse();f[1]===u&&(o=V),l.push(V)}}};for(;y.size>0;){let u=y.poll(),f=u?.key,g=u?.val;if(f!==void 0&&g){if(c.add(g),E&&E===g)return r&&(i=d.get(E)||1/0),n&&b(E),{distMap:d,preMap:m,seen:c,paths:l,minDist:i,minPath:o};let _=this.getNeighbors(g);for(let p of _)if(!c.has(p)){let V=this.getEdge(g,p)?.weight;if(typeof V=="number"){let v=d.get(p);v&&f+V<v&&(y.add({key:f+V,val:p}),m.set(p,g),d.set(p,f+V))}}}}return r&&d.forEach((u,f)=>{f!==x&&u<i&&(i=u,n&&(s=f))}),n&&b(s),{distMap:d,preMap:m,seen:c,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=[],c;if(t&&(c=!1),!i)return{hasNegativeCycle:c,distMap:o,preMap:l,paths:s,min:h,minPath:d};let m=this._vertices,x=m.size,E=this.edgeSet(),y=E.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<y;++f){let g=this.getEndsOfEdge(E[f]);if(g){let[_,p]=g,V=E[f].weight,v=o.get(_),F=o.get(p);v!==void 0&&F!==void 0&&o.get(_)!==1/0&&v+V<F&&(o.set(p,v+V),n&&l.set(p,_))}}let b=null;if(r&&o.forEach((u,f)=>{f!==i&&u<h&&(h=u,n&&(b=f))}),n)for(let u of m){let f=u[1];if(f instanceof N){let g=[f],_=l.get(f);for(;_!==void 0;)g.push(_),_=l.get(_);let p=g.reverse();u[1]===b&&(d=p),s.push(p)}}for(let u=0;u<y;++u){let f=this.getEndsOfEdge(E[u]);if(f){let[g]=f,_=E[u].weight,p=o.get(g);p&&p!==1/0&&p+_<p&&(c=!0)}}return{hasNegativeCycle:c,distMap:o,preMap:l,paths:s,min:h,minPath:d}}floyd(){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,t,r,n){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=[],c=[],m=0,x=(u,f)=>{m++,s.set(u,m),o.set(u,m);let g=this.getNeighbors(u),_=0;for(let p of g)if(p!==f){s.get(p)===-1&&(_++,x(p,u));let V=o.get(p),v=o.get(u);v!==void 0&&V!==void 0&&o.set(u,Math.min(v,V));let F=s.get(u);if(V!==void 0&&F!==void 0&&(e&&(u===h&&_>=2||u!==h&&V>=F)&&d.push(u),t&&V>F)){let qe=this.getEdge(u,p);qe&&c.push(qe)}}};x(h,null);let E=new Map,y=()=>{let u=new Map;return o.forEach((f,g)=>{u.has(f)?u.get(f)?.push(g):u.set(f,[g])}),u};r&&(E=y());let b=new Map;if(n){let u=new Map;u.size<1&&(u=y()),u.forEach((f,g)=>{f.length>1&&b.set(g,f)})}return{dfnMap:s,lowMap:o,bridges:c,articulationPoints:d,SCCs:E,cycles:b}}_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 N?e.key:e}_setVertices(e){this._vertices=e}};var D=class extends N{constructor(e,t){super(e,t)}},z=class extends R{constructor(e,t,r,n){super(r,n),this._src=e,this._dest=t}_src;get src(){return this._src}set src(e){this._src=e}_dest;get dest(){return this._dest}set dest(e){this._dest=e}},W=class extends L{constructor(){super()}_outEdgeMap=new Map;get outEdgeMap(){return this._outEdgeMap}_inEdgeMap=new Map;get inEdgeMap(){return this._inEdgeMap}createVertex(e,t){return new D(e,t??e)}createEdge(e,t,r,n){return new z(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&&w(s,l=>l.dest===n.key);let o=this._inEdgeMap.get(n);return o&&(i=w(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&&w(i,o=>o.src===r.key);let s=this._inEdgeMap.get(n);s&&s.length>0&&(t=w(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 D?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}_setOutEdgeMap(e){this._outEdgeMap=e}_setInEdgeMap(e){this._inEdgeMap=e}};var ee=class extends N{constructor(e,t){super(e,t)}},te=class extends R{constructor(e,t,r,n){super(r,n),this._vertices=[e,t]}_vertices;get vertices(){return this._vertices}set vertices(e){this._vertices=e}},Me=class extends L{constructor(){super(),this._edges=new Map}_edges;get edges(){return this._edges}createVertex(e,t){return new ee(e,t??e)}createEdge(e,t,r,n){return new te(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=w(i,l=>l.vertices.includes(n.key))[0]||null);let o=this._edges.get(n);return o&&w(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}_setEdges(e){this._edges=e}};var re=class extends D{constructor(e,t,r,n){super(e,n),this._lat=t,this._long=r}_lat;get lat(){return this._lat}set lat(e){this._lat=e}_long;get long(){return this._long}set long(e){this._long=e}},ne=class extends z{constructor(e,t,r,n){super(e,t,r,n)}},Se=class extends W{constructor(e,t){super(),this._origin=e,this._bottomRight=t}_origin=[0,0];get origin(){return this._origin}set origin(e){this._origin=e}_bottomRight;get bottomRight(){return this._bottomRight}set bottomRight(e){this._bottomRight=e}createVertex(e,t=this.origin[0],r=this.origin[1],n){return new re(e,t,r,n)}createEdge(e,t,r,n){return new ne(e,t,r,n)}};var X=(t=>(t.ITERATIVE="ITERATIVE",t.RECURSIVE="RECURSIVE",t))(X||{}),ie=(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))(ie||{});var Re=(t=>(t.RED="RED",t.BLACK="BLACK",t))(Re||{});var je=(r=>(r.VAL="VAL",r.NODE="NODE",r.ID="ID",r))(je||{});var se=(r=>(r.lt="lt",r.eq="eq",r.gt="gt",r))(se||{});var k=class{key;val;parent;constructor(e,t){this.key=e,this.val=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{constructor(e){if(e!==void 0){let{iterationType:t="ITERATIVE"}=e;this._iterationType=t}}_iterationType="ITERATIVE";get iterationType(){return this._iterationType}set iterationType(e){this._iterationType=e}_root=null;get root(){return this._root}_size=0;get size(){return this._size}createNode(e,t){return new k(e,t)}clear(){this._root=null,this._size=0}isEmpty(){return this.size===0}add(e,t){let r=(l,h)=>{let d=new T([l]);for(;d.size>0;){let c=d.shift();if(c){if(h&&c.key===h.key)return;let m=this._addTo(h,c);if(m!==void 0)return m;c.left&&d.push(c.left),c.right&&d.push(c.right)}else return}},n,i;if(e===null)i=null;else if(typeof e=="number")i=this.createNode(e,t);else if(e instanceof k)i=e;else return;let s=typeof e=="number"?e:e?e.key:void 0,o=s!==void 0?this.get(s,this._defaultCallbackByKey):void 0;return this.root?o?(o.val=t,n=o):n=r(this.root,i):(this._setRoot(i),i!==null?this._setSize(1):this._setSize(0),n=this.root),n}addMany(e,t){return e.map((r,n)=>{if(r instanceof k)return this.add(r.key,r.val);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._defaultCallbackByKey){let r=[];if(!this.root)return r;e instanceof k&&(t=l=>l);let n=this.get(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._setSize(this.size-1),r.push({deleted:o,needBalanced:s}),r}getDepth(e,t=this.root){typeof e=="number"&&(e=this.get(e)),typeof t=="number"&&(t=this.get(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.get(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._defaultCallbackByKey,r=!1,n=this.root,i=this.iterationType){if(!n)return[];e instanceof k&&(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 T([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._defaultCallbackByKey,r=this.root,n=this.iterationType){return e instanceof k&&(t=i=>i),this.getNodes(e,t,!0,r,n).length>0}get(e,t=this._defaultCallbackByKey,r=this.root,n=this.iterationType){return e instanceof k&&(t=i=>i),this.getNodes(e,t,!0,r,n)[0]??null}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.get(e)),!e)return e;if(t==="RECURSIVE"){let r=n=>n.left?r(n.left):n;return r(e)}else{let r=Z(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=Z(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._defaultCallbackByKey,t=this.root,r=this.iterationType){typeof t=="number"&&(t=this.get(t));let n=[];if(!t)return n;if(r==="RECURSIVE"){let i=s=>{n.push(e(s)),s.left&&i(s.left),s.right&&i(s.right)};i(t)}else{let i=[t];for(;i.length>0;){let s=i.pop();n.push(e(s)),s.right&&i.push(s.right),s.left&&i.push(s.left)}}return n}dfs(e=this._defaultCallbackByKey,t="in",r=this.root,n="ITERATIVE"){if(!r)return[];let i=[];if(n==="RECURSIVE"){let s=o=>{switch(t){case"in":o.left&&s(o.left),i.push(e(o)),o.right&&s(o.right);break;case"pre":i.push(e(o)),o.left&&s(o.left),o.right&&s(o.right);break;case"post":o.left&&s(o.left),o.right&&s(o.right),i.push(e(o));break}};s(r)}else{let s=[{opt:0,node:r}];for(;s.length>0;){let o=s.pop();if(!(!o||!o.node))if(o.opt===1)i.push(e(o.node));else switch(t){case"in":s.push({opt:0,node:o.node.right}),s.push({opt:1,node:o.node}),s.push({opt:0,node:o.node.left});break;case"pre":s.push({opt:0,node:o.node.right}),s.push({opt:0,node:o.node.left}),s.push({opt:1,node:o.node});break;case"post":s.push({opt:1,node:o.node}),s.push({opt:0,node:o.node.right}),s.push({opt:0,node:o.node.left});break;default:s.push({opt:0,node:o.node.right}),s.push({opt:1,node:o.node}),s.push({opt:0,node:o.node.left});break}}}return i}bfs(e=this._defaultCallbackByKey,t=this.root,r=this.iterationType){if(!t)return[];let n=[];if(r==="RECURSIVE"){let o=function(l){if(s.size===0)return;let h=s.shift();n.push(e(h)),h.left&&s.push(h.left),h.right&&s.push(h.right),o(l+1)};var i=o;let s=new T([t]);o(0)}else{let s=new T([t]);for(;s.size>0;){let o=s.size;for(let l=0;l<o;l++){let h=s.shift();n.push(e(h)),h.left&&s.push(h.left),h.right&&s.push(h.right)}}}return n}listLevels(e=this._defaultCallbackByKey,t=this.root,r=this.iterationType){if(!t)return[];let n=[];if(r==="RECURSIVE"){let i=(s,o)=>{n[o]||(n[o]=[]),n[o].push(e(s)),s.left&&i(s.left,o+1),s.right&&i(s.right,o+1)};i(t,0)}else{let i=[[t,0]];for(;i.length>0;){let s=i.pop(),[o,l]=s;n[l]||(n[l]=[]),n[l].push(e(o)),o.right&&i.push([o.right,l+1]),o.left&&i.push([o.left,l+1])}}return n}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}morris(e=this._defaultCallbackByKey,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}_swap(e,t){let{key:r,val:n}=t,i=this.createNode(r,n);return i&&(t.key=e.key,t.val=e.val,e.key=i.key,e.val=i.val),t}_defaultCallbackByKey=e=>e.key;_addTo(e,t){if(t)return t.left===void 0?(t.left=e,e&&this._setSize(this.size+1),t.left):t.right===void 0?(t.right=e,e&&this._setSize(this.size+1),t.right):void 0}_setRoot(e){e&&(e.parent=void 0),this._root=e}_setSize(e){this._size=e}};var C=class extends k{constructor(e,t){super(e,t)}},I=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 C(e,t)}add(e,t){let r=null,n=null;if(e instanceof C?n=e:typeof e=="number"?n=this.createNode(e,t):e===null&&(n=null),this.root===null)this._setRoot(n),this._setSize(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.val=n.val),s=!1,r=i):this._compare(i.key,n.key)==="gt"?i.left===void 0?(n&&(n.parent=i),i.left=n,this._setSize(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._setSize(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(null)===-1}if(!r||!i(e))return super.addMany(e,t);let s=[],o=e.map((y,b)=>[y,t?.[b]]),l=[];function h(y){for(let[b]of y)if(b instanceof C)return!0;return!1}function d(y){for(let[b]of y)if(typeof b=="number")return!0;return!1}let c=[],m=[];if(h(o))l=o.sort((y,b)=>y[0].key-b[0].key);else if(d(o))l=o.sort((y,b)=>y[0]-b[0]);else throw new Error("Invalid input keysOrNodes");c=l.map(([y])=>y),m=l.map(([,y])=>y);let x=(y,b)=>{if(y.length===0)return;let u=Math.floor((y.length-1)/2),f=this.add(y[u],b?.[u]);s.push(f),x(y.slice(0,u),b?.slice(0,u)),x(y.slice(u+1),b?.slice(u+1))},E=()=>{let b=[[0,l.length-1]];for(;b.length>0;){let u=b.pop();if(u){let[f,g]=u;if(f<=g){let _=f+Math.floor((g-f)/2),p=this.add(c[_],m?.[_]);s.push(p),b.push([_+1,g]),b.push([f,_-1])}}}};return n==="RECURSIVE"?x(c,m):E(),s}get(e,t=this._defaultCallbackByKey,r=this.root,n=this.iterationType){return this.getNodes(e,t,!0,r,n)[0]??null}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._defaultCallbackByKey,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._defaultCallbackByKey?(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 T([n]);for(;o.size>0;){let l=o.shift();if(l){if(t(l)===e&&(s.push(l),r))return s;t===this._defaultCallbackByKey?(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._defaultCallbackByKey,t="lt",r=this.root,n=this.iterationType){typeof r=="number"&&(r=this.get(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 T([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.val),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.val),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 Le=class{_freq;_max;constructor({frequency:e=0,max:t}){this._freq=e,this._max=t,this._freqMap={0:0},this._msb=ve(t),this._negativeCount=e<0?t:0}_freqMap;get freqMap(){return this._freqMap}set freqMap(e){this._freqMap=e}_msb;get msb(){return this._msb}set msb(e){this._msb=e}_negativeCount;get negativeCount(){return this._negativeCount}set negativeCount(e){this._negativeCount=e}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 O=class{constructor(e,t,r,n){this._start=e,this._end=t,this._sum=r,this._val=n||null}_start=0;get start(){return this._start}set start(e){this._start=e}_end=0;get end(){return this._end}set end(e){this._end=e}_val=null;get val(){return this._val}set val(e){this._val=e}_sum=0;get sum(){return this._sum}set sum(e){this._sum=e}_left=null;get left(){return this._left}set left(e){this._left=e}_right=null;get right(){return this._right}set right(e){this._right=e}},De=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 O(e,t,0);if(e===t)return new O(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 O(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.val=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)}_setValues(e){this._values=e}_setStart(e){this._start=e}_setEnd(e){this._end=e}_setRoot(e){this._root=e}};var H=class extends C{height;constructor(e,t){super(e,t),this.height=0}},Q=class extends I{constructor(e){super(e)}createNode(e,t){return new H(e,t)}add(e,t){let r=super.add(e,t);return r&&this._balancePath(r),r}delete(e,t=this._defaultCallbackByKey){let r=super.delete(e,t);for(let{needBalanced:n}of r)n&&this._balancePath(n);return r}_swap(e,t){let{key:r,val:n,height:i}=t,s=this.createNode(r,n);return s&&(s.height=i,t.key=e.key,t.val=e.val,t.height=e.height,e.key=s.key,e.val=s.val,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 oe=class extends C{constructor(e,t){super(e,t),this._color="RED"}_color;get color(){return this._color}set color(e){this._color=e}},Ie=class extends I{constructor(e){super(e)}createNode(e,t){return new oe(e,t)}};var A=class extends H{count;constructor(e,t,r=1){super(e,t),this.count=r}},Fe=class extends Q{constructor(e){super(e)}_count=0;get count(){return this._count}createNode(e,t,r){return new A(e,t,r)}add(e,t,r=1){let n,i;if(e instanceof A?i=this.createNode(e.key,e.val,e.count):e===null?i=null:i=this.createNode(e,t,r),!this.root)this._setRoot(i),this._setSize(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.val=i.val,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._setSize(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._setSize(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._setSize(this.size+1),this._setCount(this.count+e.count)),t.left):t.right===void 0?(t.right=e,e!==null&&(this._setSize(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 A){r.push(this.add(i.key,i.val,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.val,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.val,h.count),n.push([l+1,o]),n.push([s,l-1])}}}return!0}}delete(e,t=this._defaultCallbackByKey,r=!1){let n=[];if(!this.root)return n;let i=this.get(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._setSize(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,val:n,count:i,height:s}=t,o=this.createNode(r,n,i);return o&&(o.height=s,t.key=e.key,t.val=e.val,t.count=e.count,t.height=e.height,e.key=o.key,e.val=o.val,e.count=o.count,e.height=o.height),t}_setCount(e){this._count=e}};var ze=class a{constructor(e,t,r){this._key=e,this._value=t||void 0,this._children=r||[]}_key;get key(){return this._key}set key(e){this._key=e}_value;get value(){return this._value}set value(e){this._value=e}_children;get children(){return this._children}set children(e){this._children=e}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 Oe=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 P=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 He=class a{_matrix;constructor(e){typeof e>"u"?this._matrix=a.identity:e instanceof P?(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 P(this._matrix[0][0],this._matrix[1][0])}};var le=class a{direction;turn;constructor(e,t){this.direction=e,this.turn=()=>new a(t[e],t)}},Ae=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 le(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 J=class{constructor(e){this._key=e,this._isEnd=!1,this._children=new Map}_key;get key(){return this._key}set key(e){this._key=e}_children;get children(){return this._children}set children(e){this._children=e}_isEnd;get isEnd(){return this._isEnd}set isEnd(e){this._isEnd=e}},Pe=class{_caseSensitive;constructor(e,t=!0){if(this._root=new J(""),this._caseSensitive=t,e)for(let r of e)this.add(r)}_root;get root(){return this._root}set root(e){this._root=e}add(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);n||(n=new J(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 c=l.children.get(d);c!==void 0&&s(c,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 Qe(Ze);})();
1
+ "use strict";var dataStructureTyped=(()=>{var ae=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var We=Object.prototype.hasOwnProperty;var Xe=(a,e)=>{for(var t in e)ae(a,t,{get:e[t],enumerable:!0})},Ye=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ge(e))!We.call(a,n)&&n!==t&&ae(a,n,{get:()=>e[n],enumerable:!(r=je(e,n))||r.enumerable});return a};var Qe=a=>Ye(ae({},"__esModule",{value:!0}),a);var Ze={};Xe(Ze,{AVLTree:()=>Q,AVLTreeNode:()=>O,AbstractEdge:()=>R,AbstractGraph:()=>L,AbstractVertex:()=>N,ArrayDeque:()=>xe,BST:()=>I,BSTNode:()=>C,BinaryIndexedTree:()=>Le,BinaryTree:()=>Y,BinaryTreeNode:()=>k,CP:()=>se,Character:()=>le,CoordinateMap:()=>ue,CoordinateSet:()=>de,Deque:()=>_e,DirectedEdge:()=>z,DirectedGraph:()=>W,DirectedVertex:()=>D,DoublyLinkedList:()=>j,DoublyLinkedListNode:()=>K,FamilyPosition:()=>ie,FibonacciHeap:()=>we,FibonacciHeapNode:()=>$,HashMap:()=>pe,HashTable:()=>he,HashTableNode:()=>U,Heap:()=>M,IterationType:()=>X,LinkedListQueue:()=>ye,MapEdge:()=>ne,MapGraph:()=>Se,MapVertex:()=>re,Matrix2D:()=>Oe,MatrixNTI2D:()=>He,MaxHeap:()=>ke,MaxPriorityQueue:()=>Ce,MinHeap:()=>Be,MinPriorityQueue:()=>Ke,Navigator:()=>Ae,ObjectDeque:()=>be,PriorityQueue:()=>S,Queue:()=>T,RBColor:()=>Re,RBTree:()=>Ie,RBTreeNode:()=>oe,SegmentTree:()=>De,SegmentTreeNode:()=>H,SinglyLinkedList:()=>q,SinglyLinkedListNode:()=>B,SkipList:()=>me,SkipListNode:()=>G,Stack:()=>ge,THUNK_SYMBOL:()=>Ee,TopologicalProperty:()=>qe,TreeMap:()=>fe,TreeMultiset:()=>Fe,TreeMultisetNode:()=>A,TreeNode:()=>ze,TreeSet:()=>ce,Trie:()=>Pe,TrieNode:()=>J,UndirectedEdge:()=>te,UndirectedGraph:()=>Me,UndirectedVertex:()=>ee,Vector2D:()=>P,arrayRemove:()=>w,getMSB:()=>ve,isThunk:()=>Ne,toThunk:()=>Te,trampoline:()=>Z,trampolineAsync:()=>Je,uuidV4:()=>Ve});var U=class{key;val;next;constructor(e,t){this.key=e,this.val=t,this.next=null}},he=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}set capacity(e){this._capacity=e}_size;get size(){return this._size}_buckets;get buckets(){return this._buckets}set buckets(e){this._buckets=e}_hashFn;get hashFn(){return this._hashFn}set hashFn(e){this._hashFn=e}set(e,t){let r=this._hash(e),n=new U(e,t);if(!this._buckets[r])this._buckets[r]=n;else{let i=this._buckets[r];for(;i;){if(i.key===e){i.val=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.val;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 U(n.key,n.val);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 ue=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))}_setJoint(e){this._joint=e}};var de=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))}_setJoint(e){this._joint=e}};var fe=class{};var ce=class{};var pe=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}set initialCapacity(e){this._initialCapacity=e}_loadFactor;get loadFactor(){return this._loadFactor}set loadFactor(e){this._loadFactor=e}_capacityMultiplier;get capacityMultiplier(){return this._capacityMultiplier}set capacityMultiplier(e){this._capacityMultiplier=e}_size;get size(){return this._size}set size(e){this._size=e}_table;get table(){return this._table}set table(e){this._table=e}_hashFn;get hashFn(){return this._hashFn}set hashFn(e){this._hashFn=e}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 B=class{constructor(e){this._val=e,this._next=null}_val;get val(){return this._val}set val(e){this._val=e}_next;get next(){return this._next}set next(e){this._next=e}},q=class a{constructor(){this._head=null,this._tail=null,this._length=0}_head;get head(){return this._head}set head(e){this._head=e}_tail;get tail(){return this._tail}set tail(e){this._tail=e}_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 B(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.val;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.val;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.val}popFirst(){return this.shift()}unshift(e){let t=new B(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.val}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.val}delete(e){if(!e)return!1;let t;e instanceof B?t=e.val:t=e;let r=this.head,n=null;for(;r;){if(r.val===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 B(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.val),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.val))return t.val;t=t.next}return null}indexOf(e){let t=0,r=this.head;for(;r;){if(r.val===e)return t;t++,r=r.next}return-1}getNode(e){let t=this.head;for(;t;){if(t.val===e)return t;t=t.next}return null}insertBefore(e,t){if(!this.head)return!1;let r;if(e instanceof B?r=e.val:r=e,this.head.val===r)return this.unshift(t),!0;let n=this.head;for(;n.next;){if(n.next.val===r){let i=new B(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 B?r=e:r=this.getNode(e),r){let n=new B(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.val===e&&t++,r=r.next;return t}forEach(e){let t=this.head,r=0;for(;t;)e(t.val,r),t=t.next,r++}map(e){let t=new a,r=this.head;for(;r;)t.push(e(r.val)),r=r.next;return t}filter(e){let t=new a,r=this.head;for(;r;)e(r.val)&&t.push(r.val),r=r.next;return t}reduce(e,t){let r=t,n=this.head;for(;n;)r=e(r,n.val),n=n.next;return r}*[Symbol.iterator](){let e=this.head;for(;e;)yield e.val,e=e.next}};var K=class{constructor(e){this._val=e,this._next=null,this._prev=null}_val;get val(){return this._val}set val(e){this._val=e}_next;get next(){return this._next}set next(e){this._next=e}_prev;get prev(){return this._prev}set prev(e){this._prev=e}},j=class a{constructor(){this._head=null,this._tail=null,this._length=0}_head;get head(){return this._head}set head(e){this._head=e}_tail;get tail(){return this._tail}set tail(e){this._tail=e}_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 K(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.val}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.val}popFirst(){return this.shift()}unshift(e){let t=new K(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?.val}getLast(){return this.tail?.val}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.val}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.val===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 K(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 K?r=e:r=this.getNode(e),r){let n=new K(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.val}delete(e){let t;if(e instanceof K?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.val),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.val))return t.val;t=t.next}return null}indexOf(e){let t=0,r=this.head;for(;r;){if(r.val===e)return t;t++,r=r.next}return-1}findBackward(e){let t=this.tail;for(;t;){if(e(t.val))return t.val;t=t.prev}return null}toArrayBackward(){let e=[],t=this.tail;for(;t;)e.push(t.val),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.val,r),t=t.next,r++}map(e){let t=new a,r=this.head;for(;r;)t.push(e(r.val)),r=r.next;return t}filter(e){let t=new a,r=this.head;for(;r;)e(r.val)&&t.push(r.val),r=r.next;return t}reduce(e,t){let r=t,n=this.head;for(;n;)r=e(r,n.val),n=n.next;return r}insertAfter(e,t){let r;if(e instanceof K?r=e:r=this.getNode(e),r){let n=new K(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.val,e=e.next}};var G=class{key;value;forward;constructor(e,t,r){this.key=e,this.value=t,this.forward=new Array(r)}},me=class{constructor(e=16,t=.5){this._head=new G(null,null,e),this._level=0,this._maxLevel=e,this._probability=t}_head;get head(){return this._head}set head(e){this._head=e}_level;get level(){return this._level}set level(e){this._level=e}_maxLevel;get maxLevel(){return this._maxLevel}set maxLevel(e){this._maxLevel=e}_probability;get probability(){return this._probability}set probability(e){this._probability=e}add(e,t){let r=new G(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}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}randomLevel(){let e=1;for(;Math.random()<this.probability&&e<this.maxLevel;)e++;return e}};var ge=class a{_elements;constructor(e){this._elements=Array.isArray(e)?e:[]}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 ye=class extends q{enqueue(e){this.push(e)}dequeue(){return this.shift()}peek(){return this.head?.val}},T=class a{constructor(e){this._nodes=e||[],this._offset=0}_nodes;get nodes(){return this._nodes}set nodes(e){this._nodes=e}_offset;get offset(){return this._offset}set offset(e){this._offset=e}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.peek();return this.offset+=1,this.offset*2<this.nodes.length||(this.nodes=this.nodes.slice(this.offset),this.offset=0),e}peek(){return this.size>0?this.nodes[this.offset]:void 0}getLast(){return this.size>0?this.nodes[this.nodes.length-1]:void 0}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 j{},be=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}set capacity(e){this._capacity=e}_first=-1;get first(){return this._first}set first(e){this._first=e}_last=-1;get last(){return this._last}set last(e){this._last=e}_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}_seNodes(e){this._nodes=e}_setSize(e){this._size=e}},xe=class{_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)})},w=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},Ee=Symbol("thunk"),Ne=a=>typeof a=="function"&&a.__THUNK__===Ee,Te=a=>{let e=()=>a();return e.__THUNK__=Ee,e},Z=a=>Object.assign((...t)=>{let r=a(...t);for(;Ne(r)&&typeof r=="function";)r=r();return r},{cont:(...t)=>Te(()=>a(...t))}),Je=a=>Object.assign(async(...t)=>{let r=await a(...t);for(;Ne(r)&&typeof r=="function";)r=await r();return r},{cont:(...t)=>Te(()=>a(...t))}),ve=a=>a<=0?0:1<<31-Math.clz32(a);var M=class a{nodes=[];comparator;constructor(e){this.comparator=e.comparator,e.nodes&&e.nodes.length>0&&(this.nodes=e.nodes,this.fix())}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)}},$=class{element;degree;left;right;child;parent;marked;constructor(e,t=0){this.element=e,this.degree=t,this.marked=!1}},we=class{root;size=0;min;comparator;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.")}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 $(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 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 Be=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 S=class extends M{constructor(e){super(e)}};var Ke=class extends S{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 Ce=class extends S{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 N=class{constructor(e,t){this._key=e,this._val=t}_key;get key(){return this._key}set key(e){this._key=e}_val;get val(){return this._val}set val(e){this._val=e}},R=class{constructor(e,t){this._weight=e!==void 0?e:1,this._val=t,this._hashCode=Ve()}_val;get val(){return this._val}set val(e){this._val=e}_weight;get weight(){return this._weight}set weight(e){this._weight=e}_hashCode;get hashCode(){return this._hashCode}_setHashCode(e){this._hashCode=e}},L=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 N)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 R)return this._addEdgeOnly(e);if(t instanceof N||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof N&&(e=e.key),t instanceof N&&(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){let r=[],n=this._getVertex(e),i=this._getVertex(t);if(!(n&&i))return[];let s=(o,l,h,d)=>{h.set(o,!0),o===l&&r.push([n,...d]);let c=this.getNeighbors(o);for(let m of c)h.get(m)||(d.push(m),s(m,l,h,d),w(d,x=>x===m));h.set(o,!1)};return s(n,i,new Map,[]),r}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 T([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 c=this.getNeighbors(d);for(let m of c)s.has(m)||(s.set(m,!0),o.push(m))}}l++}return null}}getMinPathBetween(e,t,r){if(r===void 0&&(r=!1),r){let n=this.getAllPathsBetween(e,t),i=1/0,s=-1,o=0;for(let l of n){let h=this.getPathSumWeight(l);h<i&&(i=h,s=o),o++}return n[s]||null}else{let n=[],i=this._getVertex(e),s=this._getVertex(t);if(!(i&&s))return[];let o=(l,h,d,c)=>{if(d.set(l,!0),l===h){n=[i,...c];return}let m=this.getNeighbors(l);for(let x of m)d.get(x)||(c.push(x),o(x,h,d,c),w(c,E=>E===x));d.set(l,!1)};return o(i,s,new Map,[]),n}}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,c=new Set,m=new Map,x=this._getVertex(e),E=t?this._getVertex(t):null;if(!x)return null;for(let u of h){let f=u[1];f instanceof N&&d.set(f,1/0)}d.set(x,0),m.set(x,null);let y=()=>{let u=1/0,f=null;for(let[g,_]of d)c.has(g)||_<u&&(u=_,f=g);return f},b=u=>{for(let f of h){let g=f[1];if(g instanceof N){let _=[g],p=m.get(g);for(;p;)_.push(p),p=m.get(p);let V=_.reverse();f[1]===u&&(o=V),l.push(V)}}};for(let u=1;u<h.size;u++){let f=y();if(f){if(c.add(f),E&&E===f)return r&&(i=d.get(E)||1/0),n&&b(E),{distMap:d,preMap:m,seen:c,paths:l,minDist:i,minPath:o};let g=this.getNeighbors(f);for(let _ of g)if(!c.has(_)){let p=this.getEdge(f,_);if(p){let V=d.get(f),v=d.get(_);V!==void 0&&v!==void 0&&p.weight+V<v&&(d.set(_,p.weight+V),m.set(_,f))}}}}return r&&d.forEach((u,f)=>{f!==x&&u<i&&(i=u,n&&(s=f))}),n&&b(s),{distMap:d,preMap:m,seen:c,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,c=new Set,m=new Map,x=this._getVertex(e),E=t?this._getVertex(t):null;if(!x)return null;for(let u of h){let f=u[1];f instanceof N&&d.set(f,1/0)}let y=new S({comparator:(u,f)=>u.key-f.key});y.add({key:0,val:x}),d.set(x,0),m.set(x,null);let b=u=>{for(let f of h){let g=f[1];if(g instanceof N){let _=[g],p=m.get(g);for(;p;)_.push(p),p=m.get(p);let V=_.reverse();f[1]===u&&(o=V),l.push(V)}}};for(;y.size>0;){let u=y.poll(),f=u?.key,g=u?.val;if(f!==void 0&&g){if(c.add(g),E&&E===g)return r&&(i=d.get(E)||1/0),n&&b(E),{distMap:d,preMap:m,seen:c,paths:l,minDist:i,minPath:o};let _=this.getNeighbors(g);for(let p of _)if(!c.has(p)){let V=this.getEdge(g,p)?.weight;if(typeof V=="number"){let v=d.get(p);v&&f+V<v&&(y.add({key:f+V,val:p}),m.set(p,g),d.set(p,f+V))}}}}return r&&d.forEach((u,f)=>{f!==x&&u<i&&(i=u,n&&(s=f))}),n&&b(s),{distMap:d,preMap:m,seen:c,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=[],c;if(t&&(c=!1),!i)return{hasNegativeCycle:c,distMap:o,preMap:l,paths:s,min:h,minPath:d};let m=this._vertices,x=m.size,E=this.edgeSet(),y=E.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<y;++f){let g=this.getEndsOfEdge(E[f]);if(g){let[_,p]=g,V=E[f].weight,v=o.get(_),F=o.get(p);v!==void 0&&F!==void 0&&o.get(_)!==1/0&&v+V<F&&(o.set(p,v+V),n&&l.set(p,_))}}let b=null;if(r&&o.forEach((u,f)=>{f!==i&&u<h&&(h=u,n&&(b=f))}),n)for(let u of m){let f=u[1];if(f instanceof N){let g=[f],_=l.get(f);for(;_!==void 0;)g.push(_),_=l.get(_);let p=g.reverse();u[1]===b&&(d=p),s.push(p)}}for(let u=0;u<y;++u){let f=this.getEndsOfEdge(E[u]);if(f){let[g]=f,_=E[u].weight,p=o.get(g);p&&p!==1/0&&p+_<p&&(c=!0)}}return{hasNegativeCycle:c,distMap:o,preMap:l,paths:s,min:h,minPath:d}}floyd(){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,t,r,n){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=[],c=[],m=0,x=(u,f)=>{m++,s.set(u,m),o.set(u,m);let g=this.getNeighbors(u),_=0;for(let p of g)if(p!==f){s.get(p)===-1&&(_++,x(p,u));let V=o.get(p),v=o.get(u);v!==void 0&&V!==void 0&&o.set(u,Math.min(v,V));let F=s.get(u);if(V!==void 0&&F!==void 0&&(e&&(u===h&&_>=2||u!==h&&V>=F)&&d.push(u),t&&V>F)){let Ue=this.getEdge(u,p);Ue&&c.push(Ue)}}};x(h,null);let E=new Map,y=()=>{let u=new Map;return o.forEach((f,g)=>{u.has(f)?u.get(f)?.push(g):u.set(f,[g])}),u};r&&(E=y());let b=new Map;if(n){let u=new Map;u.size<1&&(u=y()),u.forEach((f,g)=>{f.length>1&&b.set(g,f)})}return{dfnMap:s,lowMap:o,bridges:c,articulationPoints:d,SCCs:E,cycles:b}}_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 N?e.key:e}_setVertices(e){this._vertices=e}};var D=class extends N{constructor(e,t){super(e,t)}},z=class extends R{constructor(e,t,r,n){super(r,n),this._src=e,this._dest=t}_src;get src(){return this._src}set src(e){this._src=e}_dest;get dest(){return this._dest}set dest(e){this._dest=e}},W=class extends L{constructor(){super()}_outEdgeMap=new Map;get outEdgeMap(){return this._outEdgeMap}_inEdgeMap=new Map;get inEdgeMap(){return this._inEdgeMap}createVertex(e,t){return new D(e,t??e)}createEdge(e,t,r,n){return new z(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&&w(s,l=>l.dest===n.key);let o=this._inEdgeMap.get(n);return o&&(i=w(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&&w(i,o=>o.src===r.key);let s=this._inEdgeMap.get(n);s&&s.length>0&&(t=w(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 D?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}_setOutEdgeMap(e){this._outEdgeMap=e}_setInEdgeMap(e){this._inEdgeMap=e}};var ee=class extends N{constructor(e,t){super(e,t)}},te=class extends R{constructor(e,t,r,n){super(r,n),this._vertices=[e,t]}_vertices;get vertices(){return this._vertices}set vertices(e){this._vertices=e}},Me=class extends L{constructor(){super(),this._edges=new Map}_edges;get edges(){return this._edges}createVertex(e,t){return new ee(e,t??e)}createEdge(e,t,r,n){return new te(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=w(i,l=>l.vertices.includes(n.key))[0]||null);let o=this._edges.get(n);return o&&w(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}_setEdges(e){this._edges=e}};var re=class extends D{constructor(e,t,r,n){super(e,n),this._lat=t,this._long=r}_lat;get lat(){return this._lat}set lat(e){this._lat=e}_long;get long(){return this._long}set long(e){this._long=e}},ne=class extends z{constructor(e,t,r,n){super(e,t,r,n)}},Se=class extends W{constructor(e,t){super(),this._origin=e,this._bottomRight=t}_origin=[0,0];get origin(){return this._origin}set origin(e){this._origin=e}_bottomRight;get bottomRight(){return this._bottomRight}set bottomRight(e){this._bottomRight=e}createVertex(e,t=this.origin[0],r=this.origin[1],n){return new re(e,t,r,n)}createEdge(e,t,r,n){return new ne(e,t,r,n)}};var X=(t=>(t.ITERATIVE="ITERATIVE",t.RECURSIVE="RECURSIVE",t))(X||{}),ie=(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))(ie||{});var Re=(t=>(t.RED="RED",t.BLACK="BLACK",t))(Re||{});var qe=(r=>(r.VAL="VAL",r.NODE="NODE",r.ID="ID",r))(qe||{});var se=(r=>(r.lt="lt",r.eq="eq",r.gt="gt",r))(se||{});var k=class{key;val;parent;constructor(e,t){this.key=e,this.val=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{constructor(e){if(e!==void 0){let{iterationType:t="ITERATIVE"}=e;this._iterationType=t}}_iterationType="ITERATIVE";get iterationType(){return this._iterationType}set iterationType(e){this._iterationType=e}_root=null;get root(){return this._root}_size=0;get size(){return this._size}createNode(e,t){return new k(e,t)}clear(){this._root=null,this._size=0}isEmpty(){return this.size===0}add(e,t){let r=(l,h)=>{let d=new T([l]);for(;d.size>0;){let c=d.shift();if(c){if(h&&c.key===h.key)return;let m=this._addTo(h,c);if(m!==void 0)return m;c.left&&d.push(c.left),c.right&&d.push(c.right)}else return}},n,i;if(e===null)i=null;else if(typeof e=="number")i=this.createNode(e,t);else if(e instanceof k)i=e;else return;let s=typeof e=="number"?e:e?e.key:void 0,o=s!==void 0?this.get(s,this._defaultCallbackByKey):void 0;return this.root?o?(o.val=t,n=o):n=r(this.root,i):(this._setRoot(i),i!==null?this._setSize(1):this._setSize(0),n=this.root),n}addMany(e,t){return e.map((r,n)=>{if(r instanceof k)return this.add(r.key,r.val);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._defaultCallbackByKey){let r=[];if(!this.root)return r;e instanceof k&&(t=l=>l);let n=this.get(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._setSize(this.size-1),r.push({deleted:o,needBalanced:s}),r}getDepth(e,t=this.root){typeof e=="number"&&(e=this.get(e)),typeof t=="number"&&(t=this.get(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.get(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._defaultCallbackByKey,r=!1,n=this.root,i=this.iterationType){if(!n)return[];e instanceof k&&(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 T([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._defaultCallbackByKey,r=this.root,n=this.iterationType){return e instanceof k&&(t=i=>i),this.getNodes(e,t,!0,r,n).length>0}get(e,t=this._defaultCallbackByKey,r=this.root,n=this.iterationType){return e instanceof k&&(t=i=>i),this.getNodes(e,t,!0,r,n)[0]??null}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.get(e)),!e)return e;if(t==="RECURSIVE"){let r=n=>n.left?r(n.left):n;return r(e)}else{let r=Z(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=Z(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._defaultCallbackByKey,t=this.root,r=this.iterationType){typeof t=="number"&&(t=this.get(t));let n=[];if(!t)return n;if(r==="RECURSIVE"){let i=s=>{n.push(e(s)),s.left&&i(s.left),s.right&&i(s.right)};i(t)}else{let i=[t];for(;i.length>0;){let s=i.pop();n.push(e(s)),s.right&&i.push(s.right),s.left&&i.push(s.left)}}return n}dfs(e=this._defaultCallbackByKey,t="in",r=this.root,n="ITERATIVE"){if(!r)return[];let i=[];if(n==="RECURSIVE"){let s=o=>{switch(t){case"in":o.left&&s(o.left),i.push(e(o)),o.right&&s(o.right);break;case"pre":i.push(e(o)),o.left&&s(o.left),o.right&&s(o.right);break;case"post":o.left&&s(o.left),o.right&&s(o.right),i.push(e(o));break}};s(r)}else{let s=[{opt:0,node:r}];for(;s.length>0;){let o=s.pop();if(!(!o||!o.node))if(o.opt===1)i.push(e(o.node));else switch(t){case"in":s.push({opt:0,node:o.node.right}),s.push({opt:1,node:o.node}),s.push({opt:0,node:o.node.left});break;case"pre":s.push({opt:0,node:o.node.right}),s.push({opt:0,node:o.node.left}),s.push({opt:1,node:o.node});break;case"post":s.push({opt:1,node:o.node}),s.push({opt:0,node:o.node.right}),s.push({opt:0,node:o.node.left});break;default:s.push({opt:0,node:o.node.right}),s.push({opt:1,node:o.node}),s.push({opt:0,node:o.node.left});break}}}return i}bfs(e=this._defaultCallbackByKey,t=this.root,r=this.iterationType){if(!t)return[];let n=[];if(r==="RECURSIVE"){let o=function(l){if(s.size===0)return;let h=s.shift();n.push(e(h)),h.left&&s.push(h.left),h.right&&s.push(h.right),o(l+1)};var i=o;let s=new T([t]);o(0)}else{let s=new T([t]);for(;s.size>0;){let o=s.size;for(let l=0;l<o;l++){let h=s.shift();n.push(e(h)),h.left&&s.push(h.left),h.right&&s.push(h.right)}}}return n}listLevels(e=this._defaultCallbackByKey,t=this.root,r=this.iterationType){if(!t)return[];let n=[];if(r==="RECURSIVE"){let i=(s,o)=>{n[o]||(n[o]=[]),n[o].push(e(s)),s.left&&i(s.left,o+1),s.right&&i(s.right,o+1)};i(t,0)}else{let i=[[t,0]];for(;i.length>0;){let s=i.pop(),[o,l]=s;n[l]||(n[l]=[]),n[l].push(e(o)),o.right&&i.push([o.right,l+1]),o.left&&i.push([o.left,l+1])}}return n}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}morris(e=this._defaultCallbackByKey,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))}_swap(e,t){let{key:r,val:n}=t,i=this.createNode(r,n);return i&&(t.key=e.key,t.val=e.val,e.key=i.key,e.val=i.val),t}_defaultCallbackByKey=e=>e.key;_addTo(e,t){if(t)return t.left===void 0?(t.left=e,e&&this._setSize(this.size+1),t.left):t.right===void 0?(t.right=e,e&&this._setSize(this.size+1),t.right):void 0}_setRoot(e){e&&(e.parent=void 0),this._root=e}_setSize(e){this._size=e}};var C=class extends k{constructor(e,t){super(e,t)}},I=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 C(e,t)}add(e,t){let r=null,n=null;if(e instanceof C?n=e:typeof e=="number"?n=this.createNode(e,t):e===null&&(n=null),this.root===null)this._setRoot(n),this._setSize(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.val=n.val),s=!1,r=i):this._compare(i.key,n.key)==="gt"?i.left===void 0?(n&&(n.parent=i),i.left=n,this._setSize(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._setSize(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(null)===-1}if(!r||!i(e))return super.addMany(e,t);let s=[],o=e.map((y,b)=>[y,t?.[b]]),l=[];function h(y){for(let[b]of y)if(b instanceof C)return!0;return!1}function d(y){for(let[b]of y)if(typeof b=="number")return!0;return!1}let c=[],m=[];if(h(o))l=o.sort((y,b)=>y[0].key-b[0].key);else if(d(o))l=o.sort((y,b)=>y[0]-b[0]);else throw new Error("Invalid input keysOrNodes");c=l.map(([y])=>y),m=l.map(([,y])=>y);let x=(y,b)=>{if(y.length===0)return;let u=Math.floor((y.length-1)/2),f=this.add(y[u],b?.[u]);s.push(f),x(y.slice(0,u),b?.slice(0,u)),x(y.slice(u+1),b?.slice(u+1))},E=()=>{let b=[[0,l.length-1]];for(;b.length>0;){let u=b.pop();if(u){let[f,g]=u;if(f<=g){let _=f+Math.floor((g-f)/2),p=this.add(c[_],m?.[_]);s.push(p),b.push([_+1,g]),b.push([f,_-1])}}}};return n==="RECURSIVE"?x(c,m):E(),s}get(e,t=this._defaultCallbackByKey,r=this.root,n=this.iterationType){return this.getNodes(e,t,!0,r,n)[0]??null}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._defaultCallbackByKey,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._defaultCallbackByKey?(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 T([n]);for(;o.size>0;){let l=o.shift();if(l){if(t(l)===e&&(s.push(l),r))return s;t===this._defaultCallbackByKey?(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._defaultCallbackByKey,t="lt",r=this.root,n=this.iterationType){typeof r=="number"&&(r=this.get(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 T([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.val),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.val),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 Le=class{_freq;_max;constructor({frequency:e=0,max:t}){this._freq=e,this._max=t,this._freqMap={0:0},this._msb=ve(t),this._negativeCount=e<0?t:0}_freqMap;get freqMap(){return this._freqMap}set freqMap(e){this._freqMap=e}_msb;get msb(){return this._msb}set msb(e){this._msb=e}_negativeCount;get negativeCount(){return this._negativeCount}set negativeCount(e){this._negativeCount=e}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{constructor(e,t,r,n){this._start=e,this._end=t,this._sum=r,this._val=n||null}_start=0;get start(){return this._start}set start(e){this._start=e}_end=0;get end(){return this._end}set end(e){this._end=e}_val=null;get val(){return this._val}set val(e){this._val=e}_sum=0;get sum(){return this._sum}set sum(e){this._sum=e}_left=null;get left(){return this._left}set left(e){this._left=e}_right=null;get right(){return this._right}set right(e){this._right=e}},De=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.val=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)}_setValues(e){this._values=e}_setStart(e){this._start=e}_setEnd(e){this._end=e}_setRoot(e){this._root=e}};var O=class extends C{height;constructor(e,t){super(e,t),this.height=0}},Q=class extends I{constructor(e){super(e)}createNode(e,t){return new O(e,t)}add(e,t){let r=super.add(e,t);return r&&this._balancePath(r),r}delete(e,t=this._defaultCallbackByKey){let r=super.delete(e,t);for(let{needBalanced:n}of r)n&&this._balancePath(n);return r}_swap(e,t){let{key:r,val:n,height:i}=t,s=this.createNode(r,n);return s&&(s.height=i,t.key=e.key,t.val=e.val,t.height=e.height,e.key=s.key,e.val=s.val,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 oe=class extends C{constructor(e,t){super(e,t),this._color="RED"}_color;get color(){return this._color}set color(e){this._color=e}},Ie=class extends I{constructor(e){super(e)}createNode(e,t){return new oe(e,t)}};var A=class extends O{count;constructor(e,t,r=1){super(e,t),this.count=r}},Fe=class extends Q{constructor(e){super(e)}_count=0;get count(){return this._count}createNode(e,t,r){return new A(e,t,r)}add(e,t,r=1){let n,i;if(e instanceof A?i=this.createNode(e.key,e.val,e.count):e===null?i=null:i=this.createNode(e,t,r),!this.root)this._setRoot(i),this._setSize(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.val=i.val,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._setSize(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._setSize(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._setSize(this.size+1),this._setCount(this.count+e.count)),t.left):t.right===void 0?(t.right=e,e!==null&&(this._setSize(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 A){r.push(this.add(i.key,i.val,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.val,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.val,h.count),n.push([l+1,o]),n.push([s,l-1])}}}return!0}}delete(e,t=this._defaultCallbackByKey,r=!1){let n=[];if(!this.root)return n;let i=this.get(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._setSize(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,val:n,count:i,height:s}=t,o=this.createNode(r,n,i);return o&&(o.height=s,t.key=e.key,t.val=e.val,t.count=e.count,t.height=e.height,e.key=o.key,e.val=o.val,e.count=o.count,e.height=o.height),t}_setCount(e){this._count=e}};var ze=class a{constructor(e,t,r){this._key=e,this._value=t||void 0,this._children=r||[]}_key;get key(){return this._key}set key(e){this._key=e}_value;get value(){return this._value}set value(e){this._value=e}_children;get children(){return this._children}set children(e){this._children=e}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 He=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 P=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 Oe=class a{_matrix;constructor(e){typeof e>"u"?this._matrix=a.identity:e instanceof P?(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 P(this._matrix[0][0],this._matrix[1][0])}};var le=class a{direction;turn;constructor(e,t){this.direction=e,this.turn=()=>new a(t[e],t)}},Ae=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 le(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 J=class{constructor(e){this._key=e,this._isEnd=!1,this._children=new Map}_key;get key(){return this._key}set key(e){this._key=e}_children;get children(){return this._children}set children(e){this._children=e}_isEnd;get isEnd(){return this._isEnd}set isEnd(e){this._isEnd=e}},Pe=class{_caseSensitive;constructor(e,t=!0){if(this._root=new J(""),this._caseSensitive=t,e)for(let r of e)this.add(r)}_root;get root(){return this._root}set root(e){this._root=e}add(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let n=t.children.get(r);n||(n=new J(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 c=l.children.get(d);c!==void 0&&s(c,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 Qe(Ze);})();
2
2
  /**
3
3
  * data-structure-typed
4
4
  *