data-structure-typed 1.37.1 → 1.37.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.
- package/dist/data-structures/binary-tree/binary-tree.d.ts +36 -200
- package/dist/data-structures/binary-tree/binary-tree.js +79 -231
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +9 -8
- package/dist/data-structures/binary-tree/bst.js +37 -25
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -35
- package/dist/data-structures/binary-tree/tree-multiset.js +1 -79
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/heap/heap.d.ts +1 -1
- package/dist/data-structures/heap/heap.js +1 -1
- package/dist/types/data-structures/binary-tree.d.ts +2 -0
- package/dist/types/data-structures/index.d.ts +2 -0
- package/lib/data-structures/binary-tree/binary-tree.d.ts +36 -200
- package/lib/data-structures/binary-tree/binary-tree.js +79 -231
- package/lib/data-structures/binary-tree/bst.d.ts +9 -8
- package/lib/data-structures/binary-tree/bst.js +37 -25
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +1 -35
- package/lib/data-structures/binary-tree/tree-multiset.js +1 -79
- package/lib/data-structures/heap/heap.d.ts +1 -1
- package/lib/data-structures/heap/heap.js +1 -1
- package/lib/types/data-structures/binary-tree.d.ts +2 -0
- package/lib/types/data-structures/index.d.ts +2 -0
- package/package.json +5 -5
- package/test/integration/avl-tree.test.ts +19 -16
- package/test/integration/bst.test.ts +37 -33
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {BST, BSTNode} from
|
|
1
|
+
import {BST, BSTNode, CP} from "data-structure-typed";
|
|
2
2
|
|
|
3
3
|
describe('Individual package BST operations test', () => {
|
|
4
4
|
it('should perform various operations on a Binary Search Tree with numeric values', () => {
|
|
@@ -33,10 +33,12 @@ describe('Individual package BST operations test', () => {
|
|
|
33
33
|
const minNodeBySpecificNode = node15 && bst.getLeftMost(node15);
|
|
34
34
|
expect(minNodeBySpecificNode?.key).toBe(12);
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
let subTreeSum = 0;
|
|
37
|
+
node15 && bst.subTreeForeach(15, node => subTreeSum += node.key);
|
|
37
38
|
expect(subTreeSum).toBe(70);
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
let lesserSum = 0;
|
|
41
|
+
bst.lesserOrGreaterForeach(10, CP.lt, node => lesserSum += node.key);
|
|
40
42
|
expect(lesserSum).toBe(45);
|
|
41
43
|
|
|
42
44
|
expect(node15).toBeInstanceOf(BSTNode);
|
|
@@ -55,7 +57,7 @@ describe('Individual package BST operations test', () => {
|
|
|
55
57
|
expect(bfsNodesAfterBalanced[0].key).toBe(8);
|
|
56
58
|
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
|
|
57
59
|
|
|
58
|
-
const removed11 = bst.
|
|
60
|
+
const removed11 = bst.delete(11);
|
|
59
61
|
expect(removed11).toBeInstanceOf(Array);
|
|
60
62
|
expect(removed11[0]).toBeDefined();
|
|
61
63
|
expect(removed11[0].deleted).toBeDefined();
|
|
@@ -66,7 +68,7 @@ describe('Individual package BST operations test', () => {
|
|
|
66
68
|
|
|
67
69
|
expect(bst.getHeight(15)).toBe(1);
|
|
68
70
|
|
|
69
|
-
const removed1 = bst.
|
|
71
|
+
const removed1 = bst.delete(1);
|
|
70
72
|
expect(removed1).toBeInstanceOf(Array);
|
|
71
73
|
expect(removed1[0]).toBeDefined();
|
|
72
74
|
expect(removed1[0].deleted).toBeDefined();
|
|
@@ -76,7 +78,7 @@ describe('Individual package BST operations test', () => {
|
|
|
76
78
|
|
|
77
79
|
expect(bst.getHeight()).toBe(4);
|
|
78
80
|
|
|
79
|
-
const removed4 = bst.
|
|
81
|
+
const removed4 = bst.delete(4);
|
|
80
82
|
expect(removed4).toBeInstanceOf(Array);
|
|
81
83
|
expect(removed4[0]).toBeDefined();
|
|
82
84
|
expect(removed4[0].deleted).toBeDefined();
|
|
@@ -84,7 +86,7 @@ describe('Individual package BST operations test', () => {
|
|
|
84
86
|
expect(bst.isAVLBalanced()).toBe(true);
|
|
85
87
|
expect(bst.getHeight()).toBe(4);
|
|
86
88
|
|
|
87
|
-
const removed10 = bst.
|
|
89
|
+
const removed10 = bst.delete(10);
|
|
88
90
|
expect(removed10).toBeInstanceOf(Array);
|
|
89
91
|
expect(removed10[0]).toBeDefined();
|
|
90
92
|
expect(removed10[0].deleted).toBeDefined();
|
|
@@ -92,7 +94,7 @@ describe('Individual package BST operations test', () => {
|
|
|
92
94
|
expect(bst.isAVLBalanced()).toBe(false);
|
|
93
95
|
expect(bst.getHeight()).toBe(4);
|
|
94
96
|
|
|
95
|
-
const removed15 = bst.
|
|
97
|
+
const removed15 = bst.delete(15);
|
|
96
98
|
expect(removed15).toBeInstanceOf(Array);
|
|
97
99
|
expect(removed15[0]).toBeDefined();
|
|
98
100
|
expect(removed15[0].deleted).toBeDefined();
|
|
@@ -101,7 +103,7 @@ describe('Individual package BST operations test', () => {
|
|
|
101
103
|
expect(bst.isAVLBalanced()).toBe(true);
|
|
102
104
|
expect(bst.getHeight()).toBe(3);
|
|
103
105
|
|
|
104
|
-
const removed5 = bst.
|
|
106
|
+
const removed5 = bst.delete(5);
|
|
105
107
|
expect(removed5).toBeInstanceOf(Array);
|
|
106
108
|
expect(removed5[0]).toBeDefined();
|
|
107
109
|
expect(removed5[0].deleted).toBeDefined();
|
|
@@ -110,7 +112,7 @@ describe('Individual package BST operations test', () => {
|
|
|
110
112
|
expect(bst.isAVLBalanced()).toBe(true);
|
|
111
113
|
expect(bst.getHeight()).toBe(3);
|
|
112
114
|
|
|
113
|
-
const removed13 = bst.
|
|
115
|
+
const removed13 = bst.delete(13);
|
|
114
116
|
expect(removed13).toBeInstanceOf(Array);
|
|
115
117
|
expect(removed13[0]).toBeDefined();
|
|
116
118
|
expect(removed13[0].deleted).toBeDefined();
|
|
@@ -118,7 +120,7 @@ describe('Individual package BST operations test', () => {
|
|
|
118
120
|
expect(bst.isAVLBalanced()).toBe(true);
|
|
119
121
|
expect(bst.getHeight()).toBe(3);
|
|
120
122
|
|
|
121
|
-
const removed3 = bst.
|
|
123
|
+
const removed3 = bst.delete(3);
|
|
122
124
|
expect(removed3).toBeInstanceOf(Array);
|
|
123
125
|
expect(removed3[0]).toBeDefined();
|
|
124
126
|
expect(removed3[0].deleted).toBeDefined();
|
|
@@ -126,7 +128,7 @@ describe('Individual package BST operations test', () => {
|
|
|
126
128
|
expect(bst.isAVLBalanced()).toBe(false);
|
|
127
129
|
expect(bst.getHeight()).toBe(3);
|
|
128
130
|
|
|
129
|
-
const removed8 = bst.
|
|
131
|
+
const removed8 = bst.delete(8);
|
|
130
132
|
expect(removed8).toBeInstanceOf(Array);
|
|
131
133
|
expect(removed8[0]).toBeDefined();
|
|
132
134
|
expect(removed8[0].deleted).toBeDefined();
|
|
@@ -134,16 +136,16 @@ describe('Individual package BST operations test', () => {
|
|
|
134
136
|
expect(bst.isAVLBalanced()).toBe(true);
|
|
135
137
|
expect(bst.getHeight()).toBe(3);
|
|
136
138
|
|
|
137
|
-
const removed6 = bst.
|
|
139
|
+
const removed6 = bst.delete(6);
|
|
138
140
|
expect(removed6).toBeInstanceOf(Array);
|
|
139
141
|
expect(removed6[0]).toBeDefined();
|
|
140
142
|
expect(removed6[0].deleted).toBeDefined();
|
|
141
143
|
if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
|
|
142
|
-
expect(bst.
|
|
144
|
+
expect(bst.delete(6).length).toBe(0);
|
|
143
145
|
expect(bst.isAVLBalanced()).toBe(false);
|
|
144
146
|
expect(bst.getHeight()).toBe(3);
|
|
145
147
|
|
|
146
|
-
const removed7 = bst.
|
|
148
|
+
const removed7 = bst.delete(7);
|
|
147
149
|
expect(removed7).toBeInstanceOf(Array);
|
|
148
150
|
expect(removed7[0]).toBeDefined();
|
|
149
151
|
expect(removed7[0].deleted).toBeDefined();
|
|
@@ -151,7 +153,7 @@ describe('Individual package BST operations test', () => {
|
|
|
151
153
|
expect(bst.isAVLBalanced()).toBe(false);
|
|
152
154
|
expect(bst.getHeight()).toBe(3);
|
|
153
155
|
|
|
154
|
-
const removed9 = bst.
|
|
156
|
+
const removed9 = bst.delete(9);
|
|
155
157
|
expect(removed9).toBeInstanceOf(Array);
|
|
156
158
|
expect(removed9[0]).toBeDefined();
|
|
157
159
|
expect(removed9[0].deleted).toBeDefined();
|
|
@@ -159,7 +161,7 @@ describe('Individual package BST operations test', () => {
|
|
|
159
161
|
expect(bst.isAVLBalanced()).toBe(false);
|
|
160
162
|
expect(bst.getHeight()).toBe(3);
|
|
161
163
|
|
|
162
|
-
const removed14 = bst.
|
|
164
|
+
const removed14 = bst.delete(14);
|
|
163
165
|
expect(removed14).toBeInstanceOf(Array);
|
|
164
166
|
expect(removed14[0]).toBeDefined();
|
|
165
167
|
expect(removed14[0].deleted).toBeDefined();
|
|
@@ -231,10 +233,12 @@ describe('Individual package BST operations test', () => {
|
|
|
231
233
|
const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15);
|
|
232
234
|
expect(minNodeBySpecificNode?.key).toBe(12);
|
|
233
235
|
|
|
234
|
-
|
|
236
|
+
let subTreeSum = 0;
|
|
237
|
+
node15 && objBST.subTreeForeach(node15, node => subTreeSum += node.key);
|
|
235
238
|
expect(subTreeSum).toBe(70);
|
|
236
239
|
|
|
237
|
-
|
|
240
|
+
let lesserSum = 0;
|
|
241
|
+
objBST.lesserOrGreaterForeach(10, CP.lt, node => lesserSum += node.key);
|
|
238
242
|
expect(lesserSum).toBe(45);
|
|
239
243
|
|
|
240
244
|
expect(node15).toBeInstanceOf(BSTNode);
|
|
@@ -253,7 +257,7 @@ describe('Individual package BST operations test', () => {
|
|
|
253
257
|
expect(bfsNodesAfterBalanced[0].key).toBe(8);
|
|
254
258
|
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
|
|
255
259
|
|
|
256
|
-
const removed11 = objBST.
|
|
260
|
+
const removed11 = objBST.delete(11);
|
|
257
261
|
expect(removed11).toBeInstanceOf(Array);
|
|
258
262
|
expect(removed11[0]).toBeDefined();
|
|
259
263
|
expect(removed11[0].deleted).toBeDefined();
|
|
@@ -264,7 +268,7 @@ describe('Individual package BST operations test', () => {
|
|
|
264
268
|
|
|
265
269
|
expect(node15 && objBST.getHeight(node15)).toBe(2);
|
|
266
270
|
|
|
267
|
-
const removed1 = objBST.
|
|
271
|
+
const removed1 = objBST.delete(1);
|
|
268
272
|
expect(removed1).toBeInstanceOf(Array);
|
|
269
273
|
expect(removed1[0]).toBeDefined();
|
|
270
274
|
expect(removed1[0].deleted).toBeDefined();
|
|
@@ -274,7 +278,7 @@ describe('Individual package BST operations test', () => {
|
|
|
274
278
|
|
|
275
279
|
expect(objBST.getHeight()).toBe(4);
|
|
276
280
|
|
|
277
|
-
const removed4 = objBST.
|
|
281
|
+
const removed4 = objBST.delete(4);
|
|
278
282
|
expect(removed4).toBeInstanceOf(Array);
|
|
279
283
|
expect(removed4[0]).toBeDefined();
|
|
280
284
|
expect(removed4[0].deleted).toBeDefined();
|
|
@@ -282,7 +286,7 @@ describe('Individual package BST operations test', () => {
|
|
|
282
286
|
expect(objBST.isAVLBalanced()).toBe(true);
|
|
283
287
|
expect(objBST.getHeight()).toBe(4);
|
|
284
288
|
|
|
285
|
-
const removed10 = objBST.
|
|
289
|
+
const removed10 = objBST.delete(10);
|
|
286
290
|
expect(removed10).toBeInstanceOf(Array);
|
|
287
291
|
expect(removed10[0]).toBeDefined();
|
|
288
292
|
expect(removed10[0].deleted).toBeDefined();
|
|
@@ -290,7 +294,7 @@ describe('Individual package BST operations test', () => {
|
|
|
290
294
|
expect(objBST.isAVLBalanced()).toBe(false);
|
|
291
295
|
expect(objBST.getHeight()).toBe(4);
|
|
292
296
|
|
|
293
|
-
const removed15 = objBST.
|
|
297
|
+
const removed15 = objBST.delete(15);
|
|
294
298
|
expect(removed15).toBeInstanceOf(Array);
|
|
295
299
|
expect(removed15[0]).toBeDefined();
|
|
296
300
|
expect(removed15[0].deleted).toBeDefined();
|
|
@@ -299,7 +303,7 @@ describe('Individual package BST operations test', () => {
|
|
|
299
303
|
expect(objBST.isAVLBalanced()).toBe(true);
|
|
300
304
|
expect(objBST.getHeight()).toBe(3);
|
|
301
305
|
|
|
302
|
-
const removed5 = objBST.
|
|
306
|
+
const removed5 = objBST.delete(5);
|
|
303
307
|
expect(removed5).toBeInstanceOf(Array);
|
|
304
308
|
expect(removed5[0]).toBeDefined();
|
|
305
309
|
expect(removed5[0].deleted).toBeDefined();
|
|
@@ -308,7 +312,7 @@ describe('Individual package BST operations test', () => {
|
|
|
308
312
|
expect(objBST.isAVLBalanced()).toBe(true);
|
|
309
313
|
expect(objBST.getHeight()).toBe(3);
|
|
310
314
|
|
|
311
|
-
const removed13 = objBST.
|
|
315
|
+
const removed13 = objBST.delete(13);
|
|
312
316
|
expect(removed13).toBeInstanceOf(Array);
|
|
313
317
|
expect(removed13[0]).toBeDefined();
|
|
314
318
|
expect(removed13[0].deleted).toBeDefined();
|
|
@@ -316,7 +320,7 @@ describe('Individual package BST operations test', () => {
|
|
|
316
320
|
expect(objBST.isAVLBalanced()).toBe(true);
|
|
317
321
|
expect(objBST.getHeight()).toBe(3);
|
|
318
322
|
|
|
319
|
-
const removed3 = objBST.
|
|
323
|
+
const removed3 = objBST.delete(3);
|
|
320
324
|
expect(removed3).toBeInstanceOf(Array);
|
|
321
325
|
expect(removed3[0]).toBeDefined();
|
|
322
326
|
expect(removed3[0].deleted).toBeDefined();
|
|
@@ -324,7 +328,7 @@ describe('Individual package BST operations test', () => {
|
|
|
324
328
|
expect(objBST.isAVLBalanced()).toBe(false);
|
|
325
329
|
expect(objBST.getHeight()).toBe(3);
|
|
326
330
|
|
|
327
|
-
const removed8 = objBST.
|
|
331
|
+
const removed8 = objBST.delete(8);
|
|
328
332
|
expect(removed8).toBeInstanceOf(Array);
|
|
329
333
|
expect(removed8[0]).toBeDefined();
|
|
330
334
|
expect(removed8[0].deleted).toBeDefined();
|
|
@@ -332,16 +336,16 @@ describe('Individual package BST operations test', () => {
|
|
|
332
336
|
expect(objBST.isAVLBalanced()).toBe(true);
|
|
333
337
|
expect(objBST.getHeight()).toBe(3);
|
|
334
338
|
|
|
335
|
-
const removed6 = objBST.
|
|
339
|
+
const removed6 = objBST.delete(6);
|
|
336
340
|
expect(removed6).toBeInstanceOf(Array);
|
|
337
341
|
expect(removed6[0]).toBeDefined();
|
|
338
342
|
expect(removed6[0].deleted).toBeDefined();
|
|
339
343
|
if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
|
|
340
|
-
expect(objBST.
|
|
344
|
+
expect(objBST.delete(6).length).toBe(0);
|
|
341
345
|
expect(objBST.isAVLBalanced()).toBe(false);
|
|
342
346
|
expect(objBST.getHeight()).toBe(3);
|
|
343
347
|
|
|
344
|
-
const removed7 = objBST.
|
|
348
|
+
const removed7 = objBST.delete(7);
|
|
345
349
|
expect(removed7).toBeInstanceOf(Array);
|
|
346
350
|
expect(removed7[0]).toBeDefined();
|
|
347
351
|
expect(removed7[0].deleted).toBeDefined();
|
|
@@ -349,7 +353,7 @@ describe('Individual package BST operations test', () => {
|
|
|
349
353
|
expect(objBST.isAVLBalanced()).toBe(false);
|
|
350
354
|
expect(objBST.getHeight()).toBe(3);
|
|
351
355
|
|
|
352
|
-
const removed9 = objBST.
|
|
356
|
+
const removed9 = objBST.delete(9);
|
|
353
357
|
expect(removed9).toBeInstanceOf(Array);
|
|
354
358
|
expect(removed9[0]).toBeDefined();
|
|
355
359
|
expect(removed9[0].deleted).toBeDefined();
|
|
@@ -357,7 +361,7 @@ describe('Individual package BST operations test', () => {
|
|
|
357
361
|
expect(objBST.isAVLBalanced()).toBe(false);
|
|
358
362
|
expect(objBST.getHeight()).toBe(3);
|
|
359
363
|
|
|
360
|
-
const removed14 = objBST.
|
|
364
|
+
const removed14 = objBST.delete(14);
|
|
361
365
|
expect(removed14).toBeInstanceOf(Array);
|
|
362
366
|
expect(removed14[0]).toBeDefined();
|
|
363
367
|
expect(removed14[0].deleted).toBeDefined();
|
package/umd/bundle.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see bundle.min.js.LICENSE.txt */
|
|
2
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.dataStructureTyped=e():t.dataStructureTyped=e()}(self,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{AVLTree:()=>it,AVLTreeNode:()=>st,AbstractEdge:()=>O,AbstractGraph:()=>L,AbstractVertex:()=>A,ArrayDeque:()=>x,BST:()=>Z,BSTNode:()=>X,BinaryIndexedTree:()=>$,BinaryTree:()=>J,BinaryTreeNode:()=>Y,CP:()=>K,Character:()=>yt,CoordinateMap:()=>r,CoordinateSet:()=>n,Deque:()=>v,DirectedEdge:()=>C,DirectedGraph:()=>I,DirectedVertex:()=>P,DoublyLinkedList:()=>d,DoublyLinkedListNode:()=>c,FamilyPosition:()=>q,FibonacciHeap:()=>V,FibonacciHeapNode:()=>S,HashMap:()=>l,HashTable:()=>i,HashTableNode:()=>s,Heap:()=>N,LinkedListQueue:()=>_,LoopType:()=>G,MapEdge:()=>j,MapGraph:()=>U,MapVertex:()=>H,Matrix2D:()=>_t,MatrixNTI2D:()=>ft,MaxHeap:()=>at,MaxPriorityQueue:()=>dt,MinHeap:()=>ut,MinPriorityQueue:()=>ct,Navigator:()=>vt,ObjectDeque:()=>m,PriorityQueue:()=>z,Queue:()=>y,RBColor:()=>W,RBTree:()=>nt,RBTreeNode:()=>rt,SegmentTree:()=>et,SegmentTreeNode:()=>tt,SinglyLinkedList:()=>u,SinglyLinkedListNode:()=>a,SkipList:()=>g,SkipListNode:()=>f,Stack:()=>p,THUNK_SYMBOL:()=>b,TopologicalProperty:()=>Q,TreeMap:()=>h,TreeMultiset:()=>ot,TreeMultisetNode:()=>ht,TreeNode:()=>lt,TreeSet:()=>o,Trie:()=>xt,TrieNode:()=>mt,UndirectedEdge:()=>B,UndirectedGraph:()=>D,UndirectedVertex:()=>F,Vector2D:()=>gt,arrayRemove:()=>E,isThunk:()=>w,toThunk:()=>M,trampoline:()=>T,trampolineAsync:()=>R,uuidV4:()=>k});class s{constructor(t,e){this.key=t,this.val=e,this.next=null}}class i{get hashFn(){return this._hashFn}set hashFn(t){this._hashFn=t}get buckets(){return this._buckets}set buckets(t){this._buckets=t}get capacity(){return this._capacity}set capacity(t){this._capacity=t}constructor(t=i.DEFAULT_CAPACITY,e){this._hashFn=e||this._defaultHashFn,this._capacity=Math.max(t,i.DEFAULT_CAPACITY),this._size=0,this._buckets=new Array(this._capacity).fill(null)}_defaultHashFn(t){return("string"==typeof t?this._murmurStringHashFn(t):this._objectHash(t))%this._capacity}_multiplicativeStringHashFn(t){const e=String(t);let s=0;for(let t=0;t<e.length;t++)s=(.618033988749895*s+e.charCodeAt(t))%(1<<30);return Math.abs(s)}_murmurStringHashFn(t){const e=String(t);let s=0;for(let t=0;t<e.length;t++)s=1540483477*(s^e.charCodeAt(t)),s=668265261*(s^s>>>15),s^=s>>>15;return Math.abs(s)}_hash(t){return this.hashFn(t)}_stringHash(t){let e=0;for(let s=0;s<t.length;s++)e=31*e+t.charCodeAt(s)&4294967295;return e}_objectHash(t){return this._stringHash(JSON.stringify(t))}set(t,e){const r=this._hash(t),n=new s(t,e);if(this._buckets[r]){let s=this._buckets[r];for(;s;){if(s.key===t)return void(s.val=e);if(!s.next)break;s=s.next}s.next=n}else this._buckets[r]=n;this._size++,this._size/this._capacity>=i.LOAD_FACTOR&&this._expand()}get(t){const e=this._hash(t);let s=this._buckets[e];for(;s;){if(s.key===t)return s.val;s=s.next}}delete(t){const e=this._hash(t);let s=this._buckets[e],i=null;for(;s;){if(s.key===t)return i?i.next=s.next:this._buckets[e]=s.next,this._size--,void(s.next=null);i=s,s=s.next}}_expand(){const t=2*this._capacity,e=new Array(t).fill(null);for(const t of this._buckets){let i=t;for(;i;){const t=this._hash(i.key),r=new s(i.key,i.val);if(e[t]){let s=e[t];for(;s.next;)s=s.next;s.next=r}else e[t]=r;i=i.next}}this._buckets=e,this._capacity=t}get size(){return this._size}}i.DEFAULT_CAPACITY=16,i.LOAD_FACTOR=.75;class r extends Map{constructor(t){super(),this._joint="_",void 0!==t&&(this._joint=t)}get joint(){return this._joint}has(t){return super.has(t.join(this._joint))}set(t,e){return super.set(t.join(this._joint),e)}get(t){return super.get(t.join(this._joint))}delete(t){return super.delete(t.join(this._joint))}_setJoint(t){this._joint=t}}class n extends Set{constructor(t){super(),this._joint="_",void 0!==t&&(this._joint=t)}get joint(){return this._joint}has(t){return super.has(t.join(this._joint))}add(t){return super.add(t.join(this._joint))}delete(t){return super.delete(t.join(this._joint))}_setJoint(t){this._joint=t}}class h{}class o{}class l{get hashFn(){return this._hashFn}set hashFn(t){this._hashFn=t}get table(){return this._table}set table(t){this._table=t}get capacityMultiplier(){return this._capacityMultiplier}set capacityMultiplier(t){this._capacityMultiplier=t}get loadFactor(){return this._loadFactor}set loadFactor(t){this._loadFactor=t}get initialCapacity(){return this._initialCapacity}set initialCapacity(t){this._initialCapacity=t}get size(){return this._size}set size(t){this._size=t}constructor(t=16,e=.75,s){this._initialCapacity=t,this._loadFactor=e,this._capacityMultiplier=2,this._size=0,this._table=new Array(t),this._hashFn=s||(t=>{const e=String(t);let s=0;for(let t=0;t<e.length;t++)s+=e.charCodeAt(t);return s%this.table.length})}_hash(t){return this._hashFn(t)}resizeTable(t){const e=new Array(t);for(const s of this._table)if(s)for(const[i,r]of s){const s=this._hash(i)%t;e[s]||(e[s]=[]),e[s].push([i,r])}this._table=e}set(t,e){this.size/this.table.length>=this.loadFactor&&this.resizeTable(this.table.length*this.capacityMultiplier);const s=this._hash(t);this.table[s]||(this.table[s]=[]);for(let i=0;i<this.table[s].length;i++)if(this.table[s][i][0]===t)return void(this.table[s][i][1]=e);this.table[s].push([t,e]),this.size++}get(t){const e=this._hash(t);if(this.table[e])for(const[s,i]of this.table[e])if(s===t)return i}delete(t){const e=this._hash(t);if(this.table[e])for(let s=0;s<this.table[e].length;s++)if(this.table[e][s][0]===t)return this.table[e].splice(s,1),this.size--,void(this.size/this.table.length<this.loadFactor/this.capacityMultiplier&&this.resizeTable(this.table.length/this.capacityMultiplier))}*entries(){for(const t of this.table)if(t)for(const[e,s]of t)yield[e,s]}[Symbol.iterator](){return this.entries()}clear(){this.size=0,this.table=new Array(this.initialCapacity)}isEmpty(){return 0===this.size}}class a{constructor(t){this._val=t,this._next=null}get val(){return this._val}set val(t){this._val=t}get next(){return this._next}set next(t){this._next=t}}class u{constructor(){this._head=null,this._tail=null,this._length=0}get head(){return this._head}set head(t){this._head=t}get tail(){return this._tail}set tail(t){this._tail=t}get length(){return this._length}static fromArray(t){const e=new u;for(const s of t)e.push(s);return e}getLength(){return this._length}push(t){const e=new a(t);this.head?(this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}pop(){if(!this.head)return;if(this.head===this.tail){const t=this.head.val;return this.head=null,this.tail=null,this._length--,t}let t=this.head;for(;t.next!==this.tail;)t=t.next;const e=this.tail.val;return t.next=null,this.tail=t,this._length--,e}shift(){if(!this.head)return;const t=this.head;return this.head=this.head.next,this._length--,t.val}unshift(t){const e=new a(t);this.head?(e.next=this.head,this.head=e):(this.head=e,this.tail=e),this._length++}getAt(t){if(t<0||t>=this.length)return;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e.val}getNodeAt(t){let e=this.head;for(let s=0;s<t;s++)e=e.next;return e}deleteAt(t){if(t<0||t>=this.length)return;if(0===t)return this.shift();if(t===this.length-1)return this.pop();const e=this.getNodeAt(t-1),s=e.next;return e.next=s.next,this._length--,s.val}delete(t){let e;e=t instanceof a?t.val:t;let s=this.head,i=null;for(;s;){if(s.val===e)return null===i?(this.head=s.next,s===this.tail&&(this.tail=null)):(i.next=s.next,s===this.tail&&(this.tail=i)),this._length--,!0;i=s,s=s.next}return!1}insertAt(t,e){if(t<0||t>this.length)return!1;if(0===t)return this.unshift(e),!0;if(t===this.length)return this.push(e),!0;const s=new a(e),i=this.getNodeAt(t-1);return s.next=i.next,i.next=s,this._length++,!0}isEmpty(){return 0===this.length}clear(){this._head=null,this._tail=null,this._length=0}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.val),e=e.next;return t}reverse(){if(!this.head||this.head===this.tail)return;let t=null,e=this.head,s=null;for(;e;)s=e.next,e.next=t,t=e,e=s;[this.head,this.tail]=[this.tail,this.head]}find(t){let e=this.head;for(;e;){if(t(e.val))return e.val;e=e.next}return null}indexOf(t){let e=0,s=this.head;for(;s;){if(s.val===t)return e;e++,s=s.next}return-1}findNode(t){let e=this.head;for(;e;){if(e.val===t)return e;e=e.next}return null}insertBefore(t,e){if(!this.head)return!1;let s;if(s=t instanceof a?t.val:t,this.head.val===s)return this.unshift(e),!0;let i=this.head;for(;i.next;){if(i.next.val===s){const t=new a(e);return t.next=i.next,i.next=t,this._length++,!0}i=i.next}return!1}insertAfter(t,e){let s;if(s=t instanceof a?t:this.findNode(t),s){const t=new a(e);return t.next=s.next,s.next=t,s===this.tail&&(this.tail=t),this._length++,!0}return!1}countOccurrences(t){let e=0,s=this.head;for(;s;)s.val===t&&e++,s=s.next;return e}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.val,t=t.next}}class c{constructor(t){this._val=t,this._next=null,this._prev=null}get val(){return this._val}set val(t){this._val=t}get next(){return this._next}set next(t){this._next=t}get prev(){return this._prev}set prev(t){this._prev=t}}class d{constructor(){this._head=null,this._tail=null,this._length=0}get head(){return this._head}set head(t){this._head=t}get tail(){return this._tail}set tail(t){this._tail=t}get length(){return this._length}static fromArray(t){const e=new d;for(const s of t)e.push(s);return e}push(t){const e=new c(t);this.head?(e.prev=this.tail,this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}addLast(t){this.push(t)}pop(){if(!this.tail)return;const t=this.tail;return this.head===this.tail?(this.head=null,this.tail=null):(this.tail=t.prev,this.tail.next=null),this._length--,t.val}pollLast(){return this.pop()}shift(){if(!this.head)return;const t=this.head;return this.head===this.tail?(this.head=null,this.tail=null):(this.head=t.next,this.head.prev=null),this._length--,t.val}pollFirst(){return this.shift()}unshift(t){const e=new c(t);this.head?(e.next=this.head,this.head.prev=e,this.head=e):(this.head=e,this.tail=e),this._length++}addFirst(t){this.unshift(t)}peekFirst(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}peekLast(){var t;return null===(t=this.tail)||void 0===t?void 0:t.val}get size(){return this.length}getAt(t){if(t<0||t>=this.length)return;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e.val}getNodeAt(t){if(t<0||t>=this.length)return null;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e}findNode(t){let e=this.head;for(;e;){if(e.val===t)return e;e=e.next}return null}insertAt(t,e){if(t<0||t>this.length)return!1;if(0===t)return this.unshift(e),!0;if(t===this.length)return this.push(e),!0;const s=new c(e),i=this.getNodeAt(t-1),r=i.next;return s.prev=i,s.next=r,i.next=s,r.prev=s,this._length++,!0}deleteAt(t){if(t<0||t>=this.length)return;if(0===t)return this.shift();if(t===this.length-1)return this.pop();const e=this.getNodeAt(t),s=e.prev,i=e.next;return s.next=i,i.prev=s,this._length--,e.val}delete(t){let e;if(e=t instanceof c?t:this.findNode(t),e){if(e===this.head)this.shift();else if(e===this.tail)this.pop();else{const t=e.prev,s=e.next;t.next=s,s.prev=t,this._length--}return!0}return!1}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.val),e=e.next;return t}isEmpty(){return 0===this.length}clear(){this._head=null,this._tail=null,this._length=0}find(t){let e=this.head;for(;e;){if(t(e.val))return e.val;e=e.next}return null}indexOf(t){let e=0,s=this.head;for(;s;){if(s.val===t)return e;e++,s=s.next}return-1}findLast(t){let e=this.tail;for(;e;){if(t(e.val))return e.val;e=e.prev}return null}toArrayReverse(){const t=[];let e=this.tail;for(;e;)t.push(e.val),e=e.prev;return t}reverse(){let t=this.head;for([this.head,this.tail]=[this.tail,this.head];t;){const e=t.next;[t.prev,t.next]=[t.next,t.prev],t=e}}forEach(t){let e=this.head,s=0;for(;e;)t(e.val,s),e=e.next,s++}map(t){const e=new d;let s=this.head;for(;s;)e.push(t(s.val)),s=s.next;return e}filter(t){const e=new d;let s=this.head;for(;s;)t(s.val)&&e.push(s.val),s=s.next;return e}reduce(t,e){let s=e,i=this.head;for(;i;)s=t(s,i.val),i=i.next;return s}insertAfter(t,e){let s;if(s=t instanceof c?t:this.findNode(t),s){const t=new c(e);return t.next=s.next,s.next&&(s.next.prev=t),t.prev=s,s.next=t,s===this.tail&&(this.tail=t),this._length++,!0}return!1}insertBefore(t,e){let s;if(s=t instanceof c?t:this.findNode(t),s){const t=new c(e);return t.prev=s.prev,s.prev&&(s.prev.next=t),t.next=s,s.prev=t,s===this.head&&(this.head=t),this._length++,!0}return!1}}class f{constructor(t,e,s){this.key=t,this.value=e,this.forward=new Array(s)}}class g{get probability(){return this._probability}set probability(t){this._probability=t}get maxLevel(){return this._maxLevel}set maxLevel(t){this._maxLevel=t}get level(){return this._level}set level(t){this._level=t}get head(){return this._head}set head(t){this._head=t}constructor(t=16,e=.5){this._head=new f(null,null,t),this._level=0,this._maxLevel=t,this._probability=e}randomLevel(){let t=1;for(;Math.random()<this.probability&&t<this.maxLevel;)t++;return t}add(t,e){const s=new f(t,e,this.randomLevel()),i=new Array(this.maxLevel).fill(this.head);let r=this.head;for(let e=this.level-1;e>=0;e--){for(;r.forward[e]&&r.forward[e].key<t;)r=r.forward[e];i[e]=r}for(let t=0;t<s.forward.length;t++)s.forward[t]=i[t].forward[t],i[t].forward[t]=s;null!==s.forward[0]&&(this.level=Math.max(this.level,s.forward.length))}get(t){let e=this.head;for(let s=this.level-1;s>=0;s--)for(;e.forward[s]&&e.forward[s].key<t;)e=e.forward[s];if(e=e.forward[0],e&&e.key===t)return e.value}delete(t){const e=new Array(this.maxLevel).fill(this.head);let s=this.head;for(let i=this.level-1;i>=0;i--){for(;s.forward[i]&&s.forward[i].key<t;)s=s.forward[i];e[i]=s}if(s=s.forward[0],s&&s.key===t){for(let t=0;t<this.level&&e[t].forward[t]===s;t++)e[t].forward[t]=s.forward[t];for(;this.level>0&&null===this.head.forward[this.level-1];)this.level--;return!0}return!1}}class p{constructor(t){this._elements=Array.isArray(t)?t:[]}static fromArray(t){return new p(t)}isEmpty(){return 0===this._elements.length}size(){return this._elements.length}peek(){return this.isEmpty()?null:this._elements[this._elements.length-1]}push(t){return this._elements.push(t),this}pop(){return this.isEmpty()?null:this._elements.pop()||null}toArray(){return this._elements.slice()}clear(){this._elements=[]}clone(){return new p(this._elements.slice())}}class _ extends u{enqueue(t){this.push(t)}dequeue(){return this.shift()}peek(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}}class y{constructor(t){this._nodes=t||[],this._offset=0}get nodes(){return this._nodes}set nodes(t){this._nodes=t}get offset(){return this._offset}set offset(t){this._offset=t}get size(){return this.nodes.length-this.offset}static fromArray(t){return new y(t)}push(t){return this.nodes.push(t),this}shift(){if(0===this.size)return;const t=this.peek();return this.offset+=1,2*this.offset<this.nodes.length||(this.nodes=this.nodes.slice(this.offset),this.offset=0),t}peek(){return this.size>0?this.nodes[this.offset]:void 0}peekLast(){return this.size>0?this.nodes[this.nodes.length-1]:void 0}enqueue(t){this.push(t)}dequeue(){return this.shift()}getAt(t){return this.nodes[t]}isEmpty(){return 0===this.size}toArray(){return this.nodes.slice(this.offset)}clear(){this.nodes=[],this.offset=0}clone(){return new y(this.nodes.slice(this.offset))}*[Symbol.iterator](){for(const t of this.nodes)yield t}}class v extends d{}class m{constructor(t){this._nodes={},this._capacity=Number.MAX_SAFE_INTEGER,this._first=-1,this._last=-1,this._size=0,void 0!==t&&(this._capacity=t)}get nodes(){return this._nodes}get capacity(){return this._capacity}set capacity(t){this._capacity=t}get first(){return this._first}set first(t){this._first=t}get last(){return this._last}set last(t){this._last=t}get size(){return this._size}addFirst(t){if(0===this._size){const t=Math.floor(this._capacity/2);this._first=t,this._last=t}else this._first--;this._nodes[this._first]=t,this._size++}addLast(t){if(0===this._size){const t=Math.floor(this._capacity/2);this._first=t,this._last=t}else this._last++;this._nodes[this._last]=t,this._size++}pollFirst(){if(!this._size)return;const t=this.peekFirst();return delete this._nodes[this._first],this._first++,this._size--,t}peekFirst(){if(this._size)return this._nodes[this._first]}pollLast(){if(!this._size)return;const t=this.peekLast();return delete this._nodes[this._last],this._last--,this._size--,t}peekLast(){if(this._size)return this._nodes[this._last]}get(t){return this._nodes[this._first+t]||null}isEmpty(){return this._size<=0}_seNodes(t){this._nodes=t}_setSize(t){this._size=t}}class x{constructor(){this._nodes=[]}get size(){return this._nodes.length}addLast(t){return this._nodes.push(t)}pollLast(){var t;return null!==(t=this._nodes.pop())&&void 0!==t?t:null}pollFirst(){var t;return null!==(t=this._nodes.shift())&&void 0!==t?t:null}addFirst(t){return this._nodes.unshift(t)}peekFirst(){var t;return null!==(t=this._nodes[0])&&void 0!==t?t:null}peekLast(){var t;return null!==(t=this._nodes[this._nodes.length-1])&&void 0!==t?t:null}get(t){var e;return null!==(e=this._nodes[t])&&void 0!==e?e:null}set(t,e){return this._nodes[t]=e}insert(t,e){return this._nodes.splice(t,0,e)}delete(t){return this._nodes.splice(t,1)}isEmpty(){return 0===this._nodes.length}}const k=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,(function(t){const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))},E=function(t,e){let s=-1,i=t?t.length:0;const r=[];for(;++s<i;){const n=t[s];e(n,s,t)&&(r.push(n),Array.prototype.splice.call(t,s--,1),i--)}return r},b=Symbol("thunk"),w=t=>"function"==typeof t&&t.__THUNK__===b,M=t=>{const e=()=>t();return e.__THUNK__=b,e},T=t=>Object.assign(((...e)=>{let s=t(...e);for(;w(s)&&"function"==typeof s;)s=s();return s}),{cont:(...e)=>M((()=>t(...e)))}),R=t=>Object.assign(((...e)=>{return s=void 0,i=void 0,n=function*(){let s=yield t(...e);for(;w(s)&&"function"==typeof s;)s=yield s();return s},new((r=void 0)||(r=Promise))((function(t,e){function h(t){try{l(n.next(t))}catch(t){e(t)}}function o(t){try{l(n.throw(t))}catch(t){e(t)}}function l(e){var s;e.done?t(e.value):(s=e.value,s instanceof r?s:new r((function(t){t(s)}))).then(h,o)}l((n=n.apply(s,i||[])).next())}));var s,i,r,n}),{cont:(...e)=>M((()=>t(...e)))});class N{constructor(t){this.nodes=[],this.comparator=t}add(t){return this.push(t)}push(t){return this.nodes.push(t),this.bubbleUp(this.nodes.length-1),this}poll(){if(0===this.nodes.length)return;if(1===this.nodes.length)return this.nodes.pop();const t=this.nodes[0];return this.nodes[0]=this.nodes.pop(),this.sinkDown(0),t}pop(){return this.poll()}bubbleUp(t){const e=this.nodes[t];for(;t>0;){const s=Math.floor((t-1)/2),i=this.nodes[s];if(!(this.comparator(e,i)<0))break;this.nodes[t]=i,this.nodes[s]=e,t=s}}sinkDown(t){const e=2*t+1,s=2*t+2,i=this.nodes.length;let r=t;if(e<i&&this.comparator(this.nodes[e],this.nodes[r])<0&&(r=e),s<i&&this.comparator(this.nodes[s],this.nodes[r])<0&&(r=s),r!==t){const e=this.nodes[t];this.nodes[t]=this.nodes[r],this.nodes[r]=e,this.sinkDown(r)}}fix(){for(let t=Math.floor(this.size/2);t>=0;t--)this.sinkDown(t)}peek(){if(0!==this.nodes.length)return this.nodes[0]}get size(){return this.nodes.length}get leaf(){var t;return null!==(t=this.nodes[this.size-1])&&void 0!==t?t:void 0}isEmpty(){return 0===this.size}clear(){this.nodes=[]}refill(t){this.nodes=t,this.fix()}has(t){return this.nodes.includes(t)}dfs(t){const e=[],s=i=>{i<this.size&&("in"===t?(s(2*i+1),e.push(this.nodes[i]),s(2*i+2)):"pre"===t?(e.push(this.nodes[i]),s(2*i+1),s(2*i+2)):"post"===t&&(s(2*i+1),s(2*i+2),e.push(this.nodes[i])))};return s(0),e}toArray(){return[...this.nodes]}getNodes(){return this.nodes}clone(){const t=new N(this.comparator);return t.nodes=[...this.nodes],t}sort(){const t=[],e=this.clone();for(;0!==e.size;){const s=e.poll();s&&t.push(s)}return t}static heapify(t,e){const s=new N(e);return s.nodes=[...t],s.fix(),s}}class S{constructor(t,e=0){this.element=t,this.degree=e,this.marked=!1}}class V{constructor(t){if(this.size=0,this.clear(),this.comparator=t||this.defaultComparator,"function"!=typeof this.comparator)throw new Error("FibonacciHeap constructor: given comparator should be a function.")}defaultComparator(t,e){return t<e?-1:t>e?1:0}clear(){this.root=void 0,this.min=void 0,this.size=0}createNode(t){return new S(t)}mergeWithRoot(t){this.root?(t.right=this.root.right,t.left=this.root,this.root.right.left=t,this.root.right=t):this.root=t}add(t){return this.push(t)}push(t){const e=this.createNode(t);return e.left=e,e.right=e,this.mergeWithRoot(e),(!this.min||this.comparator(e.element,this.min.element)<=0)&&(this.min=e),this.size++,this}peek(){return this.min?this.min.element:void 0}consumeLinkedList(t){const e=[];if(!t)return e;let s=t,i=!1;for(;s!==t||!i;)s===t&&(i=!0),s&&(e.push(s),s=s.right);return e}removeFromRoot(t){this.root===t&&(this.root=t.right),t.left&&(t.left.right=t.right),t.right&&(t.right.left=t.left)}mergeWithChild(t,e){t.child?(e.right=t.child.right,e.left=t.child,t.child.right.left=e,t.child.right=e):t.child=e}link(t,e){this.removeFromRoot(t),t.left=t,t.right=t,this.mergeWithChild(e,t),e.degree++,t.parent=e}consolidate(){const t=new Array(this.size),e=this.consumeLinkedList(this.root);let s,i,r,n;for(const h of e){for(s=h,r=s.degree;t[r];)i=t[r],this.comparator(s.element,i.element)>0&&(n=s,s=i,i=n),this.link(i,s),t[r]=void 0,r++;t[r]=s}for(let e=0;e<this.size;e++)t[e]&&this.comparator(t[e].element,this.min.element)<=0&&(this.min=t[e])}poll(){return this.pop()}pop(){if(0===this.size)return;const t=this.min;if(t.child){const e=this.consumeLinkedList(t.child);for(const t of e)this.mergeWithRoot(t),t.parent=void 0}return this.removeFromRoot(t),t===t.right?(this.min=void 0,this.root=void 0):(this.min=t.right,this.consolidate()),this.size--,t.element}merge(t){if(0!==t.size){if(this.root&&t.root){const e=this.root,s=t.root,i=e.right,r=s.left;e.right=s,s.left=e,i.left=r,r.right=i}(!this.min||t.min&&this.comparator(t.min.element,this.min.element)<0)&&(this.min=t.min),this.size+=t.size,t.clear()}}}class z extends N{constructor(t){super(t)}}class A{constructor(t,e){this._key=t,this._val=e}get key(){return this._key}set key(t){this._key=t}get val(){return this._val}set val(t){this._val=t}}class O{constructor(t,e){this._weight=void 0!==t?t:1,this._val=e,this._hashCode=k()}get val(){return this._val}set val(t){this._val=t}get weight(){return this._weight}set weight(t){this._weight=t}get hashCode(){return this._hashCode}_setHashCode(t){this._hashCode=t}}class L{constructor(){this._vertices=new Map}get vertices(){return this._vertices}getVertex(t){return this._vertices.get(t)||null}hasVertex(t){return this._vertices.has(this._getVertexKey(t))}addVertex(t,e){if(t instanceof A)return this._addVertexOnly(t);{const s=this.createVertex(t,e);return this._addVertexOnly(s)}}removeVertex(t){const e=this._getVertexKey(t);return this._vertices.delete(e)}removeAllVertices(t){const e=[];for(const s of t)e.push(this.removeVertex(s));return e.length>0}hasEdge(t,e){return!!this.getEdge(t,e)}addEdge(t,e,s,i){if(t instanceof O)return this._addEdgeOnly(t);if(e instanceof A||"string"==typeof e||"number"==typeof e){if(!this.hasVertex(t)||!this.hasVertex(e))return!1;t instanceof A&&(t=t.key),e instanceof A&&(e=e.key);const r=this.createEdge(t,e,s,i);return this._addEdgeOnly(r)}throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(t,e,s){const i=this.getEdge(t,e);return!!i&&(i.weight=s,!0)}getAllPathsBetween(t,e){const s=[],i=this._getVertex(t),r=this._getVertex(e);if(!i||!r)return[];const n=(t,e,r,h)=>{r.set(t,!0),t===e&&s.push([i,...h]);const o=this.getNeighbors(t);for(const t of o)r.get(t)||(h.push(t),n(t,e,r,h),E(h,(e=>e===t)));r.set(t,!1)};return n(i,r,new Map,[]),s}getPathSumWeight(t){var e;let s=0;for(let i=0;i<t.length;i++)s+=(null===(e=this.getEdge(t[i],t[i+1]))||void 0===e?void 0:e.weight)||0;return s}getMinCostBetween(t,e,s){if(void 0===s&&(s=!1),s){const s=this.getAllPathsBetween(t,e);let i=1/0;for(const t of s)i=Math.min(this.getPathSumWeight(t),i);return i}{const s=this._getVertex(e),i=this._getVertex(t);if(!i||!s)return null;const r=new Map,n=new y([i]);r.set(i,!0);let h=0;for(;n.size>0;){for(let t=0;t<n.size;t++){const t=n.shift();if(t===s)return h;if(void 0!==t){const e=this.getNeighbors(t);for(const t of e)r.has(t)||(r.set(t,!0),n.push(t))}}h++}return null}}getMinPathBetween(t,e,s){if(void 0===s&&(s=!1),s){const s=this.getAllPathsBetween(t,e);let i=1/0,r=-1,n=0;for(const t of s){const e=this.getPathSumWeight(t);e<i&&(i=e,r=n),n++}return s[r]||null}{let s=[];const i=this._getVertex(t),r=this._getVertex(e);if(!i||!r)return[];const n=(t,e,r,h)=>{if(r.set(t,!0),t===e)return void(s=[i,...h]);const o=this.getNeighbors(t);for(const t of o)r.get(t)||(h.push(t),n(t,e,r,h),E(h,(e=>e===t)));r.set(t,!1)};return n(i,r,new Map,[]),s}}dijkstraWithoutHeap(t,e,s,i){void 0===s&&(s=!1),void 0===i&&(i=!1),void 0===e&&(e=null);let r=1/0,n=null,h=[];const o=[],l=this._vertices,a=new Map,u=new Set,c=new Map,d=this._getVertex(t),f=e?this._getVertex(e):null;if(!d)return null;for(const t of l){const e=t[1];e instanceof A&&a.set(e,1/0)}a.set(d,0),c.set(d,null);const g=()=>{let t=1/0,e=null;for(const[s,i]of a)u.has(s)||i<t&&(t=i,e=s);return e},p=t=>{for(const e of l){const s=e[1];if(s instanceof A){const i=[s];let r=c.get(s);for(;r;)i.push(r),r=c.get(r);const n=i.reverse();e[1]===t&&(h=n),o.push(n)}}};for(let t=1;t<l.size;t++){const t=g();if(t){if(u.add(t),f&&f===t)return s&&(r=a.get(f)||1/0),i&&p(f),{distMap:a,preMap:c,seen:u,paths:o,minDist:r,minPath:h};const e=this.getNeighbors(t);for(const s of e)if(!u.has(s)){const e=this.getEdge(t,s);if(e){const i=a.get(t),r=a.get(s);void 0!==i&&void 0!==r&&e.weight+i<r&&(a.set(s,e.weight+i),c.set(s,t))}}}}return s&&a.forEach(((t,e)=>{e!==d&&t<r&&(r=t,i&&(n=e))})),i&&p(n),{distMap:a,preMap:c,seen:u,paths:o,minDist:r,minPath:h}}dijkstra(t,e,s,i){var r;void 0===s&&(s=!1),void 0===i&&(i=!1),void 0===e&&(e=null);let n=1/0,h=null,o=[];const l=[],a=this._vertices,u=new Map,c=new Set,d=new Map,f=this._getVertex(t),g=e?this._getVertex(e):null;if(!f)return null;for(const t of a){const e=t[1];e instanceof A&&u.set(e,1/0)}const p=new z(((t,e)=>t.key-e.key));p.add({key:0,val:f}),u.set(f,0),d.set(f,null);const _=t=>{for(const e of a){const s=e[1];if(s instanceof A){const i=[s];let r=d.get(s);for(;r;)i.push(r),r=d.get(r);const n=i.reverse();e[1]===t&&(o=n),l.push(n)}}};for(;p.size>0;){const t=p.poll(),e=null==t?void 0:t.key,h=null==t?void 0:t.val;if(void 0!==e&&h){if(c.add(h),g&&g===h)return s&&(n=u.get(g)||1/0),i&&_(g),{distMap:u,preMap:d,seen:c,paths:l,minDist:n,minPath:o};const t=this.getNeighbors(h);for(const s of t)if(!c.has(s)){const t=null===(r=this.getEdge(h,s))||void 0===r?void 0:r.weight;if("number"==typeof t){const i=u.get(s);i&&e+t<i&&(p.add({key:e+t,val:s}),d.set(s,h),u.set(s,e+t))}}}}return s&&u.forEach(((t,e)=>{e!==f&&t<n&&(n=t,i&&(h=e))})),i&&_(h),{distMap:u,preMap:d,seen:c,paths:l,minDist:n,minPath:o}}bellmanFord(t,e,s,i){void 0===s&&(s=!1),void 0===i&&(i=!1);const r=this._getVertex(t),n=[],h=new Map,o=new Map;let l,a=1/0,u=[];if(e&&(l=!1),!r)return{hasNegativeCycle:l,distMap:h,preMap:o,paths:n,min:a,minPath:u};const c=this._vertices,d=c.size,f=this.edgeSet(),g=f.length;this._vertices.forEach((t=>{h.set(t,1/0)})),h.set(r,0);for(let t=1;t<d;++t)for(let t=0;t<g;++t){const e=this.getEndsOfEdge(f[t]);if(e){const[s,r]=e,n=f[t].weight,l=h.get(s),a=h.get(r);void 0!==l&&void 0!==a&&h.get(s)!==1/0&&l+n<a&&(h.set(r,l+n),i&&o.set(r,s))}}let p=null;if(s&&h.forEach(((t,e)=>{e!==r&&t<a&&(a=t,i&&(p=e))})),i)for(const t of c){const e=t[1];if(e instanceof A){const s=[e];let i=o.get(e);for(;void 0!==i;)s.push(i),i=o.get(i);const r=s.reverse();t[1]===p&&(u=r),n.push(r)}}for(let t=0;t<g;++t){const e=this.getEndsOfEdge(f[t]);if(e){const[s]=e,i=f[t].weight,r=h.get(s);r&&r!==1/0&&r+i<r&&(l=!0)}}return{hasNegativeCycle:l,distMap:h,preMap:o,paths:n,min:a,minPath:u}}floyd(){var t;const e=[...this._vertices],s=e.length,i=[],r=[];for(let t=0;t<s;t++){i[t]=[],r[t]=[];for(let e=0;e<s;e++)r[t][e]=null}for(let r=0;r<s;r++)for(let n=0;n<s;n++)i[r][n]=(null===(t=this.getEdge(e[r][1],e[n][1]))||void 0===t?void 0:t.weight)||1/0;for(let t=0;t<s;t++)for(let n=0;n<s;n++)for(let h=0;h<s;h++)i[n][h]>i[n][t]+i[t][h]&&(i[n][h]=i[n][t]+i[t][h],r[n][h]=e[t][1]);return{costs:i,predecessor:r}}tarjan(t,e,s,i){const r=!1;void 0===t&&(t=r),void 0===e&&(e=r),void 0===s&&(s=r),void 0===i&&(i=r);const n=new Map,h=new Map,o=this._vertices;o.forEach((t=>{n.set(t,-1),h.set(t,1/0)}));const[l]=o.values(),a=[],u=[];let c=0;const d=(s,i)=>{c++,n.set(s,c),h.set(s,c);const r=this.getNeighbors(s);let o=0;for(const c of r)if(c!==i){-1===n.get(c)&&(o++,d(c,s));const i=h.get(c),r=h.get(s);void 0!==r&&void 0!==i&&h.set(s,Math.min(r,i));const f=n.get(s);if(void 0!==i&&void 0!==f&&(t&&(s===l&&o>=2||s!==l&&i>=f)&&a.push(s),e&&i>f)){const t=this.getEdge(s,c);t&&u.push(t)}}};d(l,null);let f=new Map;const g=()=>{const t=new Map;return h.forEach(((e,s)=>{var i;t.has(e)?null===(i=t.get(e))||void 0===i||i.push(s):t.set(e,[s])})),t};s&&(f=g());const p=new Map;if(i){let t=new Map;t.size<1&&(t=g()),t.forEach(((t,e)=>{t.length>1&&p.set(e,t)}))}return{dfnMap:n,lowMap:h,bridges:u,articulationPoints:a,SCCs:f,cycles:p}}_addVertexOnly(t){return!this.hasVertex(t)&&(this._vertices.set(t.key,t),!0)}_getVertex(t){const e=this._getVertexKey(t);return this._vertices.get(e)||null}_getVertexKey(t){return t instanceof A?t.key:t}_setVertices(t){this._vertices=t}}class P extends A{constructor(t,e){super(t,e)}}class C extends O{constructor(t,e,s,i){super(s,i),this._src=t,this._dest=e}get src(){return this._src}set src(t){this._src=t}get dest(){return this._dest}set dest(t){this._dest=t}}class I extends L{constructor(){super(),this._outEdgeMap=new Map,this._inEdgeMap=new Map}get outEdgeMap(){return this._outEdgeMap}get inEdgeMap(){return this._inEdgeMap}createVertex(t,e){return new P(t,null!=e?e:t)}createEdge(t,e,s,i){return new C(t,e,null!=s?s:1,i)}getEdge(t,e){let s=[];if(null!==t&&null!==e){const i=this._getVertex(t),r=this._getVertex(e);if(i&&r){const t=this._outEdgeMap.get(i);t&&(s=t.filter((t=>t.dest===r.key)))}}return s[0]||null}removeEdgeSrcToDest(t,e){const s=this._getVertex(t),i=this._getVertex(e);let r=null;if(!s||!i)return null;const n=this._outEdgeMap.get(s);n&&E(n,(t=>t.dest===i.key));const h=this._inEdgeMap.get(i);return h&&(r=E(h,(t=>t.src===s.key))[0]||null),r}removeEdge(t){let e=null;const s=this._getVertex(t.src),i=this._getVertex(t.dest);if(s&&i){const t=this._outEdgeMap.get(s);t&&t.length>0&&E(t,(t=>t.src===s.key));const r=this._inEdgeMap.get(i);r&&r.length>0&&(e=E(r,(t=>t.dest===i.key))[0])}return e}removeEdgesBetween(t,e){const s=[];if(t&&e){const i=this.removeEdgeSrcToDest(t,e),r=this.removeEdgeSrcToDest(e,t);i&&s.push(i),r&&s.push(r)}return s}incomingEdgesOf(t){const e=this._getVertex(t);return e&&this.inEdgeMap.get(e)||[]}outgoingEdgesOf(t){const e=this._getVertex(t);return e&&this._outEdgeMap.get(e)||[]}degreeOf(t){return this.outDegreeOf(t)+this.inDegreeOf(t)}inDegreeOf(t){return this.incomingEdgesOf(t).length}outDegreeOf(t){return this.outgoingEdgesOf(t).length}edgesOf(t){return[...this.outgoingEdgesOf(t),...this.incomingEdgesOf(t)]}getEdgeSrc(t){return this._getVertex(t.src)}getEdgeDest(t){return this._getVertex(t.dest)}getDestinations(t){if(null===t)return[];const e=[],s=this.outgoingEdgesOf(t);for(const t of s){const s=this.getEdgeDest(t);s&&e.push(s)}return e}topologicalSort(t){t=null!=t?t:"key";const e=new Map;for(const t of this.vertices)e.set(t[1],0);let s=[],i=!1;const r=t=>{e.set(t,1);const n=this.getDestinations(t);for(const t of n){const s=e.get(t);0===s?r(t):1===s&&(i=!0)}e.set(t,2),s.push(t)};for(const t of this.vertices)0===e.get(t[1])&&r(t[1]);return i?null:("key"===t&&(s=s.map((t=>t instanceof P?t.key:t))),s.reverse())}edgeSet(){let t=[];return this._outEdgeMap.forEach((e=>{t=[...t,...e]})),t}getNeighbors(t){const e=[],s=this._getVertex(t);if(s){const t=this.outgoingEdgesOf(s);for(const s of t){const t=this._getVertex(s.dest);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.src,t.dest))return null;const e=this._getVertex(t.src),s=this._getVertex(t.dest);return e&&s?[e,s]:null}_addEdgeOnly(t){if(!this.hasVertex(t.src)||!this.hasVertex(t.dest))return!1;const e=this._getVertex(t.src),s=this._getVertex(t.dest);if(e&&s){const i=this._outEdgeMap.get(e);i?i.push(t):this._outEdgeMap.set(e,[t]);const r=this._inEdgeMap.get(s);return r?r.push(t):this._inEdgeMap.set(s,[t]),!0}return!1}_setOutEdgeMap(t){this._outEdgeMap=t}_setInEdgeMap(t){this._inEdgeMap=t}}class F extends A{constructor(t,e){super(t,e)}}class B extends O{constructor(t,e,s,i){super(s,i),this._vertices=[t,e]}get vertices(){return this._vertices}set vertices(t){this._vertices=t}}class D extends L{constructor(){super(),this._edges=new Map}get edges(){return this._edges}createVertex(t,e){return new F(t,null!=e?e:t)}createEdge(t,e,s,i){return new B(t,e,null!=s?s:1,i)}getEdge(t,e){var s;let i=[];if(null!==t&&null!==e){const r=this._getVertex(t),n=this._getVertex(e);r&&n&&(i=null===(s=this._edges.get(r))||void 0===s?void 0:s.filter((t=>t.vertices.includes(n.key))))}return i&&i[0]||null}removeEdgeBetween(t,e){const s=this._getVertex(t),i=this._getVertex(e);if(!s||!i)return null;const r=this._edges.get(s);let n=null;r&&(n=E(r,(t=>t.vertices.includes(i.key)))[0]||null);const h=this._edges.get(i);return h&&E(h,(t=>t.vertices.includes(s.key))),n}removeEdge(t){return this.removeEdgeBetween(t.vertices[0],t.vertices[1])}degreeOf(t){var e;const s=this._getVertex(t);return s&&(null===(e=this._edges.get(s))||void 0===e?void 0:e.length)||0}edgesOf(t){const e=this._getVertex(t);return e&&this._edges.get(e)||[]}edgeSet(){const t=new Set;return this._edges.forEach((e=>{e.forEach((e=>{t.add(e)}))})),[...t]}getNeighbors(t){const e=[],s=this._getVertex(t);if(s){const t=this.edgesOf(s);for(const i of t){const t=this._getVertex(i.vertices.filter((t=>t!==s.key))[0]);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.vertices[0],t.vertices[1]))return null;const e=this._getVertex(t.vertices[0]),s=this._getVertex(t.vertices[1]);return e&&s?[e,s]:null}_addEdgeOnly(t){for(const e of t.vertices){const s=this._getVertex(e);if(null===s)return!1;if(s){const e=this._edges.get(s);e?e.push(t):this._edges.set(s,[t])}}return!0}_setEdges(t){this._edges=t}}class H extends P{constructor(t,e,s,i){super(t,i),this._lat=e,this._long=s}get lat(){return this._lat}set lat(t){this._lat=t}get long(){return this._long}set long(t){this._long=t}}class j extends C{constructor(t,e,s,i){super(t,e,s,i)}}class U extends I{constructor(t,e){super(),this._origin=[0,0],this._origin=t,this._bottomRight=e}get origin(){return this._origin}set origin(t){this._origin=t}get bottomRight(){return this._bottomRight}set bottomRight(t){this._bottomRight=t}createVertex(t,e,s=this.origin[0],i=this.origin[1]){return new H(t,s,i,e)}createEdge(t,e,s,i){return new j(t,e,s,i)}}var G,q,K,W,Q;!function(t){t.ITERATIVE="ITERATIVE",t.RECURSIVE="RECURSIVE"}(G||(G={})),function(t){t.ROOT="ROOT",t.LEFT="LEFT",t.RIGHT="RIGHT",t.ROOT_LEFT="ROOT_LEFT",t.ROOT_RIGHT="ROOT_RIGHT",t.ISOLATED="ISOLATED",t.MAL_NODE="MAL_NODE"}(q||(q={})),function(t){t.lt="lt",t.eq="eq",t.gt="gt"}(K||(K={})),function(t){t.RED="RED",t.BLACK="BLACK"}(W||(W={})),function(t){t.VAL="VAL",t.NODE="NODE",t.ID="ID"}(Q||(Q={}));class Y{constructor(t,e){this.key=t,this.val=e}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get familyPosition(){const t=this;return t.parent?t.parent.left===t?t.left||t.right?q.ROOT_LEFT:q.LEFT:t.parent.right===t?t.left||t.right?q.ROOT_RIGHT:q.RIGHT:q.MAL_NODE:t.left||t.right?q.ROOT:q.ISOLATED}}class J{constructor(t){if(this._root=null,this._size=0,this._loopType=G.ITERATIVE,this.visitedKey=[],this.visitedVal=[],this.visitedNode=[],void 0!==t){const{loopType:e=G.ITERATIVE}=t;this._loopType=e}}createNode(t,e){return new Y(t,e)}get root(){return this._root}get size(){return this._size}get loopType(){return this._loopType}set loopType(t){this._loopType=t}_swap(t,e){const{key:s,val:i}=e,r=this.createNode(s,i);return r&&(e.key=t.key,e.val=t.val,t.key=r.key,t.val=r.val),e}clear(){this._root=null,this._size=0,this._clearResults()}isEmpty(){return 0===this.size}add(t,e){let s,i;if(null===t)i=null;else if("number"==typeof t)i=this.createNode(t,e);else{if(!(t instanceof Y))return;i=t}const r=t?this.get(t,"key"):void 0;return this.root?r?(r.val=e,s=r):s=((t,e)=>{const s=new y([t]);for(;s.size>0;){const t=s.shift();if(!t)return;{if(e&&t.key===e.key)return;const i=this._addTo(e,t);if(void 0!==i)return i;t.left&&s.push(t.left),t.right&&s.push(t.right)}}})(this.root,i):(this._setRoot(i),null!==i?this._setSize(1):this._setSize(0),s=this.root),s}addMany(t,e){const s=[];for(let i=0;i<t.length;i++){const r=t[i];if(r instanceof Y){s.push(this.add(r.key,r.val));continue}if(null===r){s.push(this.add(null));continue}const n=null==e?void 0:e[i];s.push(this.add(r,n))}return s}refill(t,e){return this.clear(),t.length===this.addMany(t,e).length}delete(t){const e=[];if(!this.root)return e;const s="number"==typeof t?this.get(t):t;if(!s)return e;const i=(null==s?void 0:s.parent)?s.parent:null;let r=null,n=s;if(s.left){const t=s.left?this.getRightMost(s.left):null;if(t){const e=t.parent;n=this._swap(s,t),e&&(e.right===t?e.right=t.left:e.left=t.left,r=e)}}else if(i){const{familyPosition:t}=s;t===q.LEFT||t===q.ROOT_LEFT?i.left=s.right:t!==q.RIGHT&&t!==q.ROOT_RIGHT||(i.right=s.right),r=i}else void 0!==s.right&&this._setRoot(s.right);return this._setSize(this.size-1),e.push({deleted:n,needBalanced:r}),e}getDepth(t,e=this.root){"number"==typeof t&&(t=this.get(t,"key")),"number"==typeof e&&(e=this.get(e,"key"));let s=0;for(;null==t?void 0:t.parent;){if(t===e)return s;s++,t=t.parent}return s}getHeight(t=this.root){if("number"==typeof t&&(t=this.get(t,"key")),!t)return-1;if(this._loopType===G.RECURSIVE){const e=t=>{if(!t)return-1;const s=e(t.left),i=e(t.right);return Math.max(s,i)+1};return e(t)}{if(!t)return-1;const e=[{node:t,depth:0}];let s=0;for(;e.length>0;){const{node:t,depth:i}=e.pop();t.left&&e.push({node:t.left,depth:i+1}),t.right&&e.push({node:t.right,depth:i+1}),s=Math.max(s,i)}return s}}getMinHeight(t=this.root){var e,s,i;if(!t)return-1;if(this._loopType===G.RECURSIVE){const e=t=>{if(!t)return 0;if(!t.left&&!t.right)return 0;const s=e(t.left),i=e(t.right);return Math.min(s,i)+1};return e(t)}{const r=[];let n=t,h=null;const o=new Map;for(;r.length>0||n;)if(n)r.push(n),n=n.left;else if(n=r[r.length-1],n.right&&h!==n.right)n=n.right;else if(n=r.pop(),n){const t=n.left&&null!==(e=o.get(n.left))&&void 0!==e?e:-1,i=n.right&&null!==(s=o.get(n.right))&&void 0!==s?s:-1;o.set(n,1+Math.min(t,i)),h=n,n=null}return null!==(i=o.get(t))&&void 0!==i?i:-1}}isPerfectlyBalanced(t=this.root){return this.getMinHeight(t)+1>=this.getHeight(t)}getNodes(t,e="key",s=!1){if(!this.root)return[];const i=[];if(this.loopType===G.RECURSIVE){const r=n=>{this._pushByPropertyNameStopOrNot(n,i,t,e,s)||(n.left||n.right)&&(n.left&&r(n.left),n.right&&r(n.right))};r(this.root)}else{const r=new y([this.root]);for(;r.size>0;){const n=r.shift();if(n){if(this._pushByPropertyNameStopOrNot(n,i,t,e,s))return i;n.left&&r.push(n.left),n.right&&r.push(n.right)}}}return i}has(t,e="key"){return this.getNodes(t,e).length>0}get(t,e="key"){var s;return null!==(s=this.getNodes(t,e,!0)[0])&&void 0!==s?s:null}getPathToRoot(t,e=!0){const s=[];for(;t.parent;)s.push(t),t=t.parent;return s.push(t),e?s.reverse():s}getLeftMost(t=this.root){if("number"==typeof t&&(t=this.get(t,"key")),!t)return t;if(this._loopType===G.RECURSIVE){const e=t=>t.left?e(t.left):t;return e(t)}{const e=T((t=>t.left?e.cont(t.left):t));return e(t)}}getRightMost(t=this.root){if(!t)return t;if(this._loopType===G.RECURSIVE){const e=t=>t.right?e(t.right):t;return e(t)}{const e=T((t=>t.right?e.cont(t.right):t));return e(t)}}isSubtreeBST(t){if(!t)return!0;if(this._loopType===G.RECURSIVE){const e=(t,s,i)=>!t||!(t.key<=s||t.key>=i)&&e(t.left,s,t.key)&&e(t.right,t.key,i);return e(t,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER)}{const e=[];let s=Number.MIN_SAFE_INTEGER,i=t;for(;i||e.length>0;){for(;i;)e.push(i),i=i.left;if(i=e.pop(),!i||s>=i.key)return!1;s=i.key,i=i.right}return!0}}isBST(){return this.isSubtreeBST(this.root)}getSubTreeSize(t){let e=0;if(!t)return e;if(this._loopType===G.RECURSIVE){const s=t=>{e++,t.left&&s(t.left),t.right&&s(t.right)};return s(t),e}{const s=[t];for(;s.length>0;){const t=s.pop();e++,t.right&&s.push(t.right),t.left&&s.push(t.left)}return e}}subTreeForeach(t,e){if("number"==typeof t&&(t=this.get(t,"key")),!t)return!1;if(this._loopType===G.RECURSIVE){const s=t=>{e(t),t.left&&s(t.left),t.right&&s(t.right)};s(t)}else{const s=[t];for(;s.length>0;){const t=s.pop();e(t),t.right&&s.push(t.right),t.left&&s.push(t.left)}}return!0}bfs(t="key"){this._clearResults();const e=new y([this.root]);for(;0!==e.size;){const s=e.shift();s&&(this._accumulatedByPropertyName(s,t),null!==(null==s?void 0:s.left)&&e.push(s.left),null!==(null==s?void 0:s.right)&&e.push(s.right))}return this._getResultByPropertyName(t)}dfs(t="in",e="key",s=G.ITERATIVE){if(this._clearResults(),s===G.RECURSIVE){const s=i=>{switch(t){case"in":i.left&&s(i.left),this._accumulatedByPropertyName(i,e),i.right&&s(i.right);break;case"pre":this._accumulatedByPropertyName(i,e),i.left&&s(i.left),i.right&&s(i.right);break;case"post":i.left&&s(i.left),i.right&&s(i.right),this._accumulatedByPropertyName(i,e)}};this.root&&s(this.root)}else{if(!this.root)return this._getResultByPropertyName(e);const s=[{opt:0,node:this.root}];for(;s.length>0;){const i=s.pop();if(i&&i.node)if(1===i.opt)this._accumulatedByPropertyName(i.node,e);else switch(t){case"in":default:s.push({opt:0,node:i.node.right}),s.push({opt:1,node:i.node}),s.push({opt:0,node:i.node.left});break;case"pre":s.push({opt:0,node:i.node.right}),s.push({opt:0,node:i.node.left}),s.push({opt:1,node:i.node});break;case"post":s.push({opt:1,node:i.node}),s.push({opt:0,node:i.node.right}),s.push({opt:0,node:i.node.left})}}}return this._getResultByPropertyName(e)}listLevels(t=this.root,e="key"){if(!t)return[];const s=[],i=(t,i)=>{switch(e){case"key":default:s[i].push(t.key);break;case"val":s[i].push(t.val);break;case"node":s[i].push(t)}};if(this.loopType===G.RECURSIVE){const e=(t,r)=>{s[r]||(s[r]=[]),i(t,r),t.left&&e(t.left,r+1),t.right&&e(t.right,r+1)};e(t,0)}else{const e=[[t,0]];for(;e.length>0;){const t=e.pop(),[r,n]=t;s[n]||(s[n]=[]),i(r,n),r.right&&e.push([r.right,n+1]),r.left&&e.push([r.left,n+1])}}return s}getPredecessor(t){if(t.left){let e=t.left;for(;!e||e.right&&e.right!==t;)e&&(e=e.right);return e}return t}morris(t="in",e="key"){if(null===this.root)return[];this._clearResults();let s=this.root;const i=t=>{let e=null,s=null;for(;t;)s=t.right,t.right=e,e=t,t=s;return e},r=t=>{const s=i(t);let r=s;for(;r;)this._accumulatedByPropertyName(r,e),r=r.right;i(s)};switch(t){case"in":for(;s;){if(s.left){const t=this.getPredecessor(s);if(!t.right){t.right=s,s=s.left;continue}t.right=null}this._accumulatedByPropertyName(s,e),s=s.right}break;case"pre":for(;s;){if(s.left){const t=this.getPredecessor(s);if(!t.right){t.right=s,this._accumulatedByPropertyName(s,e),s=s.left;continue}t.right=null}else this._accumulatedByPropertyName(s,e);s=s.right}break;case"post":for(;s;){if(s.left){const t=this.getPredecessor(s);if(null===t.right){t.right=s,s=s.left;continue}t.right=null,r(s.left)}s=s.right}r(this.root)}return this._getResultByPropertyName(e)}_addTo(t,e){return e?void 0===e.left?(e.left=t,t&&this._setSize(this.size+1),e.left):void 0===e.right?(e.right=t,t&&this._setSize(this.size+1),e.right):void 0:void 0}_setRoot(t){t&&(t.parent=void 0),this._root=t}_setSize(t){this._size=t}_clearResults(){this.visitedKey=[],this.visitedVal=[],this.visitedNode=[]}_pushByPropertyNameStopOrNot(t,e,s,i="key",r=!1){switch(i){case"key":default:if(t.key===s)return e.push(t),r;break;case"val":if(t.val===s)return e.push(t),r}}_accumulatedByPropertyName(t,e="key"){switch(e){case"key":default:this.visitedKey.push(t.key);break;case"val":this.visitedVal.push(t.val);break;case"node":this.visitedNode.push(t)}}_getResultByPropertyName(t="key"){switch(t){case"key":default:return this.visitedKey;case"val":return this.visitedVal;case"node":return this.visitedNode}}}class X extends Y{constructor(t,e){super(t,e)}}class Z extends J{constructor(t){if(super(t),this._comparator=(t,e)=>t-e,void 0!==t){const{comparator:e}=t;void 0!==e&&(this._comparator=e)}}createNode(t,e){return new X(t,e)}add(t,e){let s=null,i=null;if(t instanceof X?i=t:"number"==typeof t?i=this.createNode(t,e):null===t&&(i=null),null===this.root)this._setRoot(i),this._setSize(this.size+1),s=this.root;else{let t=this.root,e=!0;for(;e;)null!==t&&null!==i?this._compare(t.key,i.key)===K.eq?(i&&(t.val=i.val),e=!1,s=t):this._compare(t.key,i.key)===K.gt?void 0===t.left?(i&&(i.parent=t),t.left=i,this._setSize(this.size+1),e=!1,s=t.left):t.left&&(t=t.left):this._compare(t.key,i.key)===K.lt&&(void 0===t.right?(i&&(i.parent=t),t.right=i,this._setSize(this.size+1),e=!1,s=t.right):t.right&&(t=t.right)):e=!1}return s}addMany(t,e,s=!0){if(!s||-1!==t.indexOf(null))return super.addMany(t,e);const i=[],r=t.map(((t,s)=>[t,null==e?void 0:e[s]]));let n=[],h=[],o=[];if(function(t){for(const[e]of t)if(e instanceof X)return!0;return!1}(r))n=r.sort(((t,e)=>t[0].key-e[0].key));else{if(!function(t){for(const[e]of t)if("number"==typeof e)return!0;return!1}(r))throw new Error("Invalid input keysOrNodes");n=r.sort(((t,e)=>t[0]-e[0]))}h=n.map((([t])=>t)),o=n.map((([,t])=>t));const l=(t,e)=>{if(0===t.length)return;const s=Math.floor((t.length-1)/2),r=this.add(t[s],null==e?void 0:e[s]);i.push(r),l(t.slice(0,s),null==e?void 0:e.slice(0,s)),l(t.slice(s+1),null==e?void 0:e.slice(s+1))};return this.loopType===G.RECURSIVE?l(h,o):(()=>{const t=[[0,n.length-1]];for(;t.length>0;){const e=t.pop();if(e){const[s,r]=e;if(s<=r){const e=s+Math.floor((r-s)/2),n=this.add(h[e],null==o?void 0:o[e]);i.push(n),t.push([e+1,r]),t.push([s,e-1])}}}})(),i}get(t,e="key"){var s;return null!==(s=this.getNodes(t,e,!0)[0])&&void 0!==s?s:null}lastKey(){var t,e,s,i,r,n;return this._compare(0,1)===K.lt?null!==(e=null===(t=this.getRightMost())||void 0===t?void 0:t.key)&&void 0!==e?e:0:this._compare(0,1)===K.gt?null!==(i=null===(s=this.getLeftMost())||void 0===s?void 0:s.key)&&void 0!==i?i:0:null!==(n=null===(r=this.getRightMost())||void 0===r?void 0:r.key)&&void 0!==n?n:0}getNodes(t,e="key",s=!1){if(!this.root)return[];const i=[];if(this.loopType===G.RECURSIVE){const r=n=>{this._pushByPropertyNameStopOrNot(n,i,t,e,s)||(n.left||n.right)&&("key"===e?(this._compare(n.key,t)===K.gt&&n.left&&r(n.left),this._compare(n.key,t)===K.lt&&n.right&&r(n.right)):(n.left&&r(n.left),n.right&&r(n.right)))};r(this.root)}else{const r=new y([this.root]);for(;r.size>0;){const n=r.shift();if(n){if(this._pushByPropertyNameStopOrNot(n,i,t,e,s))return i;"key"===e?(this._compare(n.key,t)===K.gt&&n.left&&r.push(n.left),this._compare(n.key,t)===K.lt&&n.right&&r.push(n.right)):(n.left&&r.push(n.left),n.right&&r.push(n.right))}}}return i}lesserOrGreaterForeach(t,e=K.lt,s){if("number"==typeof t&&(t=this.get(t,"key")),!t)return!1;const i=t.key;if(!this.root)return!1;if(this.loopType===G.RECURSIVE){const t=r=>{this._compare(r.key,i)===e&&s(r),(r.left||r.right)&&(r.left&&this._compare(r.left.key,i)===e&&t(r.left),r.right&&this._compare(r.right.key,i)===e&&t(r.right))};return t(this.root),!0}{const t=new y([this.root]);for(;t.size>0;){const r=t.shift();r&&(this._compare(r.key,i)===e&&s(r),r.left&&this._compare(r.left.key,i)===e&&t.push(r.left),r.right&&this._compare(r.right.key,i)===e&&t.push(r.right))}return!0}}perfectlyBalance(){const t=this.dfs("in","node"),e=t.length;if(this.clear(),t.length<1)return!1;if(this.loopType===G.RECURSIVE){const s=(e,i)=>{if(e>i)return;const r=e+Math.floor((i-e)/2),n=t[r];this.add(n.key,n.val),s(e,r-1),s(r+1,i)};return s(0,e-1),!0}{const s=[[0,e-1]];for(;s.length>0;){const e=s.pop();if(e){const[i,r]=e;if(i<=r){const e=i+Math.floor((r-i)/2),n=t[e];this.add(n.key,n.val),s.push([e+1,r]),s.push([i,e-1])}}}return!0}}isAVLBalanced(){var t,e;if(!this.root)return!0;let s=!0;if(this.loopType===G.RECURSIVE){const t=e=>{if(!e)return 0;const i=t(e.left),r=t(e.right);return Math.abs(i-r)>1&&(s=!1),Math.max(i,r)+1};t(this.root)}else{const s=[];let i=this.root,r=null;const n=new Map;for(;s.length>0||i;)if(i)s.push(i),i=i.left;else if(i=s[s.length-1],i.right&&r!==i.right)i=i.right;else if(i=s.pop(),i){const s=i.left&&null!==(t=n.get(i.left))&&void 0!==t?t:-1,h=i.right&&null!==(e=n.get(i.right))&&void 0!==e?e:-1;if(Math.abs(s-h)>1)return!1;n.set(i,1+Math.max(s,h)),r=i,i=null}}return s}_compare(t,e){const s=this._comparator(t,e);return s>0?K.gt:s<0?K.lt:K.eq}}class ${constructor(t){this._sumTree=new Array(t+1).fill(0)}get sumTree(){return this._sumTree}static lowBit(t){return t&-t}update(t,e){for(;t<this._sumTree.length;)this._sumTree[t]+=e,t+=$.lowBit(t)}getPrefixSum(t){let e=0;for(;t>0;)e+=this._sumTree[t],t-=$.lowBit(t);return e}getRangeSum(t,e){if(!(0<=t&&t<=e&&e<=this._sumTree.length))throw"Index out of bounds";return this.getPrefixSum(e)-this.getPrefixSum(t)}_setSumTree(t){this._sumTree=t}}class tt{constructor(t,e,s,i){this._start=0,this._end=0,this._val=null,this._sum=0,this._left=null,this._right=null,this._start=t,this._end=e,this._sum=s,this._val=i||null}get start(){return this._start}set start(t){this._start=t}get end(){return this._end}set end(t){this._end=t}get val(){return this._val}set val(t){this._val=t}get sum(){return this._sum}set sum(t){this._sum=t}get left(){return this._left}set left(t){this._left=t}get right(){return this._right}set right(t){this._right=t}}class et{constructor(t,e,s){this._values=[],this._start=0,e=e||0,s=s||t.length-1,this._values=t,this._start=e,this._end=s,t.length>0?this._root=this.build(e,s):(this._root=null,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(t,e){if(t>e)return new tt(t,e,0);if(t===e)return new tt(t,e,this._values[t]);const s=t+Math.floor((e-t)/2),i=this.build(t,s),r=this.build(s+1,e),n=new tt(t,e,i.sum+r.sum);return n.left=i,n.right=r,n}updateNode(t,e,s){const i=this.root||null;if(!i)return;const r=(t,e,s,i)=>{if(t.start===t.end&&t.start===e)return t.sum=s,void(void 0!==i&&(t.val=i));e<=t.start+Math.floor((t.end-t.start)/2)?t.left&&r(t.left,e,s,i):t.right&&r(t.right,e,s,i),t.left&&t.right&&(t.sum=t.left.sum+t.right.sum)};r(i,t,e,s)}querySumByRange(t,e){const s=this.root||null;if(!s)return 0;if(t<0||e>=this.values.length||t>e)return NaN;const i=(t,e,s)=>{if(e<=t.start&&s>=t.end)return t.sum;const r=t.start+Math.floor((t.end-t.start)/2);if(s<=r)return t.left?i(t.left,e,s):NaN;if(e>r)return t.right?i(t.right,e,s):NaN;{let n=0,h=0;return t.left&&(n=i(t.left,e,r)),t.right&&(h=i(t.right,r+1,s)),n+h}};return i(s,t,e)}_setValues(t){this._values=t}_setStart(t){this._start=t}_setEnd(t){this._end=t}_setRoot(t){this._root=t}}class st extends X{constructor(t,e){super(t,e),this.height=0}}class it extends Z{constructor(t){super(t)}_swap(t,e){const{key:s,val:i,height:r}=e,n=this.createNode(s,i);return n&&(n.height=r,e.key=t.key,e.val=t.val,e.height=t.height,t.key=n.key,t.val=n.val,t.height=n.height),e}createNode(t,e){return new st(t,e)}add(t,e){const s=super.add(t,e);return s&&this._balancePath(s),s}delete(t){const e=super.delete(t);for(const{needBalanced:t}of e)t&&this._balancePath(t);return e}_balanceFactor(t){return t.right?t.left?t.right.height-t.left.height:+t.height:-t.height}_updateHeight(t){if(t.left||t.right)if(t.left)t.right?t.height=1+Math.max(t.right.height,t.left.height):t.height=1+t.left.height;else{const e=t.right?t.right.height:0;t.height=1+e}else t.height=0}_balancePath(t){const e=this.getPathToRoot(t,!1);for(let t=0;t<e.length;t++){const s=e[t];switch(this._updateHeight(s),this._balanceFactor(s)){case-2:s&&s.left&&(this._balanceFactor(s.left)<=0?this._balanceLL(s):this._balanceLR(s));break;case 2:s&&s.right&&(this._balanceFactor(s.right)>=0?this._balanceRR(s):this._balanceRL(s))}}}_balanceLL(t){const e=t.parent,s=t.left;t.parent=s,s&&s.right&&(s.right.parent=t),s&&(s.parent=e),t===this.root?s&&this._setRoot(s):(null==e?void 0:e.left)===t?e.left=s:e&&(e.right=s),s&&(t.left=s.right,s.right=t),this._updateHeight(t),s&&this._updateHeight(s)}_balanceLR(t){const e=t.parent,s=t.left;let i=null;s&&(i=s.right),t&&(t.parent=i),s&&(s.parent=i),i&&(i.left&&(i.left.parent=s),i.right&&(i.right.parent=t),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.left=i.right,s&&(s.right=i.left),i.left=s,i.right=t),this._updateHeight(t),s&&this._updateHeight(s),i&&this._updateHeight(i)}_balanceRR(t){const e=t.parent,s=t.right;t.parent=s,s&&(s.left&&(s.left.parent=t),s.parent=e),t===this.root?s&&this._setRoot(s):e&&(e.left===t?e.left=s:e.right=s),s&&(t.right=s.left,s.left=t),this._updateHeight(t),s&&this._updateHeight(s)}_balanceRL(t){const e=t.parent,s=t.right;let i=null;s&&(i=s.left),t.parent=i,s&&(s.parent=i),i&&(i.left&&(i.left.parent=t),i.right&&(i.right.parent=s),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.right=i.left),s&&i&&(s.left=i.right),i&&(i.left=t),i&&(i.right=s),this._updateHeight(t),s&&this._updateHeight(s),i&&this._updateHeight(i)}}class rt extends X{constructor(t,e){super(t,e),this._color=W.RED}get color(){return this._color}set color(t){this._color=t}}class nt extends Z{constructor(t){super(t)}createNode(t,e){return new rt(t,e)}}class ht extends st{constructor(t,e,s=1){super(t,e),this.count=s}}class ot extends it{constructor(t){super(t),this._count=0}get count(){return this._count}createNode(t,e,s){return new ht(t,e,s)}_swap(t,e){const{key:s,val:i,count:r,height:n}=e,h=this.createNode(s,i,r);return h&&(h.height=n,e.key=t.key,e.val=t.val,e.count=t.count,e.height=t.height,t.key=h.key,t.val=h.val,t.count=h.count,t.height=h.height),e}add(t,e,s=1){let i,r;if(r=t instanceof ht?this.createNode(t.key,t.val,t.count):null===t?null:this.createNode(t,e,s),this.root){let t=this.root,e=!0;for(;e;)t?r&&(this._compare(t.key,r.key)===K.eq?(t.val=r.val,t.count+=r.count,this._setCount(this.count+r.count),e=!1,i=t):this._compare(t.key,r.key)===K.gt?void 0===t.left?(t.left=r,this._setSize(this.size+1),this._setCount(this.count+r.count),e=!1,i=t.left):t.left&&(t=t.left):this._compare(t.key,r.key)===K.lt&&(void 0===t.right?(t.right=r,this._setSize(this.size+1),this._setCount(this.count+r.count),e=!1,i=t.right):t.right&&(t=t.right))):e=!1}else this._setRoot(r),this._setSize(this.size+1),r&&this._setCount(this.count+r.count),i=this.root;return i&&this._balancePath(i),i}_addTo(t,e){return e?void 0===e.left?(e.left=t,null!==t&&(this._setSize(this.size+1),this._setCount(this.count+t.count)),e.left):void 0===e.right?(e.right=t,null!==t&&(this._setSize(this.size+1),this._setCount(this.count+t.count)),e.right):void 0:void 0}addMany(t,e){const s=[];for(let i=0;i<t.length;i++){const r=t[i];r instanceof ht?s.push(this.add(r.key,r.val,r.count)):null!==r?s.push(this.add(r,null==e?void 0:e[i],1)):s.push(this.add(NaN,null,0))}return s}perfectlyBalance(){const t=this.dfs("in","node"),e=t.length;if(t.length<1)return!1;if(this.clear(),this.loopType===G.RECURSIVE){const s=(e,i)=>{if(e>i)return;const r=e+Math.floor((i-e)/2),n=t[r];this.add(n.key,n.val,n.count),s(e,r-1),s(r+1,i)};return s(0,e-1),!0}{const s=[[0,e-1]];for(;s.length>0;){const e=s.pop();if(e){const[i,r]=e;if(i<=r){const e=i+Math.floor((r-i)/2),n=t[e];this.add(n.key,n.val,n.count),s.push([e+1,r]),s.push([i,e-1])}}}return!0}}delete(t,e=!1){const s=[];if(!this.root)return s;const i=this.get(t);if(!i)return s;const r=(null==i?void 0:i.parent)?i.parent:null;let n=null,h=i;if(i.count>1&&!e)i.count--,this._setCount(this.count-1);else{if(i.left){const t=i.left?this.getRightMost(i.left):null;if(t){const e=t.parent;h=this._swap(i,t),e&&(e.right===t?e.right=t.left:e.left=t.left,n=e)}}else if(r){const{familyPosition:t}=i;t===q.LEFT||t===q.ROOT_LEFT?r.left=i.right:t!==q.RIGHT&&t!==q.ROOT_RIGHT||(r.right=i.right),n=r}else void 0!==i.right&&this._setRoot(i.right);this._setSize(this.size-1),this._setCount(this.count-h.count)}return s.push({deleted:h,needBalanced:n}),n&&this._balancePath(n),s}getNodesByCount(t,e=!1){if(!this.root)return[];const s=[];if(this.loopType===G.RECURSIVE){const i=r=>{r.count===t&&(s.push(r),e)||(r.left||r.right)&&(r.left&&i(r.left),r.right&&i(r.right))};i(this.root)}else{const i=new y([this.root]);for(;i.size>0;){const r=i.shift();if(r){if(r.count===t&&(s.push(r),e))return s;r.left&&i.push(r.left),r.right&&i.push(r.right)}}}return s}bfsCount(){return super.bfs("node").map((t=>t.count))}listLevelsCount(t){return super.listLevels(t,"node").map((t=>t.map((t=>t.count))))}morrisCount(t="in"){return super.morris(t,"node").map((t=>t.count))}clear(){super.clear(),this._setCount(0)}_setCount(t){this._count=t}}class lt{constructor(t,e,s){this._key=t,this._value=e||void 0,this._children=s||[]}get key(){return this._key}set key(t){this._key=t}get value(){return this._value}set value(t){this._value=t}get children(){return this._children}set children(t){this._children=t}addChildren(t){this.children||(this.children=[]),t instanceof lt?this.children.push(t):this.children=this.children.concat(t)}getHeight(){let t=0;if(this){const e=(s,i)=>{i>t&&(t=i);const{children:r}=s;if(r)for(let t=0,s=r.length;t<s;t++)e(r[t],i+1)};e(this,0)}return t}}class at extends N{constructor(t=((t,e)=>{if("number"!=typeof t||"number"!=typeof e)throw new Error("The a, b params of compare function must be number");return e-t})){super(t)}}class ut extends N{constructor(t=((t,e)=>{if("number"!=typeof t||"number"!=typeof e)throw new Error("The a, b params of compare function must be number");return t-e})){super(t)}}class ct extends z{constructor(t=((t,e)=>{if("number"!=typeof t||"number"!=typeof e)throw new Error("The a, b params of compare function must be number");return t-e})){super(t)}}class dt extends z{constructor(t=((t,e)=>{if("number"!=typeof t||"number"!=typeof e)throw new Error("The a, b params of compare function must be number");return e-t})){super(t)}}class ft{constructor(t){const{row:e,col:s,initialVal:i}=t;this._matrix=new Array(e).fill(void 0).map((()=>new Array(s).fill(i||0)))}toArray(){return this._matrix}}class gt{constructor(t=0,e=0,s=1){this.x=t,this.y=e,this.w=s}get isZero(){return 0===this.x&&0===this.y}get length(){return Math.sqrt(this.x*this.x+this.y*this.y)}get lengthSq(){return this.x*this.x+this.y*this.y}get rounded(){return new gt(Math.round(this.x),Math.round(this.y))}static add(t,e){return new gt(t.x+e.x,t.y+e.y)}static subtract(t,e){return new gt(t.x-e.x,t.y-e.y)}static subtractValue(t,e){return new gt(t.x-e,t.y-e)}static multiply(t,e){return new gt(t.x*e,t.y*e)}static divide(t,e){return new gt(t.x/e,t.y/e)}static equals(t,e){return t.x===e.x&&t.y===e.y}static equalsRounded(t,e,s=12){const i=gt.abs(gt.subtract(t,e));return i.x<s&&i.y<s}static normalize(t){const e=t.length;return e>2220446049250313e-31?gt.divide(t,e):t}static truncate(t,e){return t.length>e?gt.multiply(gt.normalize(t),e):t}static perp(t){return new gt(-t.y,t.x)}static reverse(t){return new gt(-t.x,-t.y)}static abs(t){return new gt(Math.abs(t.x),Math.abs(t.y))}static dot(t,e){return t.x*e.x+t.y*e.y}static distance(t,e){const s=e.y-t.y,i=e.x-t.x;return Math.sqrt(s*s+i*i)}static distanceSq(t,e){const s=e.y-t.y,i=e.x-t.x;return s*s+i*i}static sign(t,e){return t.y*e.x>t.x*e.y?-1:1}static angle(t){const e=new gt(0,-1),s=Math.acos(gt.dot(t,e)/(t.length*e.length));return 1===gt.sign(t,e)?2*Math.PI-s:s}static random(t,e){const s=Math.floor(Math.random()*t-t/2),i=Math.floor(Math.random()*e-e/2);return new gt(s,i)}zero(){this.x=0,this.y=0}}const pt=gt;class _t{constructor(t){void 0===t?this._matrix=_t.identity:t instanceof pt?(this._matrix=_t.identity,this._matrix[0][0]=t.x,this._matrix[1][0]=t.y,this._matrix[2][0]=t.w):this._matrix=t}static get empty(){return[[],[],[]]}static get identity(){return[[1,0,0],[0,1,0],[0,0,1]]}get m(){return this._matrix}toVector(){return new pt(this._matrix[0][0],this._matrix[1][0])}static add(t,e){const s=_t.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]+e.m[i][r];return new _t(s)}static subtract(t,e){const s=_t.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]-e.m[i][r];return new _t(s)}static multiply(t,e){const s=_t.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++){s[i][r]=0;for(let n=0;n<3;n++)s[i][r]+=t.m[i][n]*e.m[n][r]}return new _t(s)}static multiplyByValue(t,e){const s=_t.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]*e;return new _t(s)}static multiplyByVector(t,e){return _t.multiply(t,new _t(e)).toVector()}static view(t,e){const s=t/2,i=e/2,r=Math.cos(Math.PI);return new _t([[1,0,s],[0,1*r,i],[0,0,1]])}static scale(t){return _t.multiplyByValue(new _t,t)}static rotate(t){const e=Math.cos(t),s=Math.sin(t);return new _t([[e,-s,0],[s,e,0],[0,0,1]])}static translate(t){return new _t([[1,0,t.x],[0,1,t.y],[0,0,t.w]])}}class yt{constructor(t,e){this.direction=t,this.turn=()=>new yt(e[t],e)}}class vt{constructor({matrix:t,turning:e,onMove:s,init:{cur:i,charDir:r,VISITED:n}}){this._matrix=t,this._cur=i,this._character=new yt(r,e),this.onMove=s,this.onMove&&this.onMove(this._cur),this._VISITED=n,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){const{direction:t}=this._character;this.check(t)?this.move(t):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(t){let e,s;const i=this._matrix,[r,n]=this._cur;switch(t){case"up":if(s=i[r-1],!s)return!1;e=s[n];break;case"right":e=i[r][n+1];break;case"down":if(s=i[r+1],!s)return!1;e=s[n];break;case"left":e=i[r][n-1]}return void 0!==e&&e!==this._VISITED}move(t){switch(t){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--}const[e,s]=this._cur;this._matrix[e][s]=this._VISITED,this.onMove&&this.onMove(this._cur)}}class mt{constructor(t){this._key=t,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(t){this._key=t}get children(){return this._children}set children(t){this._children=t}get isEnd(){return this._isEnd}set isEnd(t){this._isEnd=t}}class xt{constructor(t,e=!0){if(this._root=new mt(""),this._caseSensitive=e,t)for(const e of t)this.add(e)}get root(){return this._root}set root(t){this._root=t}add(t){t=this._caseProcess(t);let e=this.root;for(const s of t){let t=e.children.get(s);t||(t=new mt(s),e.children.set(s,t)),e=t}return e.isEnd=!0,!0}has(t){t=this._caseProcess(t);let e=this.root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return e.isEnd}_caseProcess(t){return this._caseSensitive||(t=t.toLowerCase()),t}delete(t){t=this._caseProcess(t);let e=!1;const s=(i,r)=>{const n=t[r],h=i.children.get(n);return!!h&&(r===t.length-1?!!h.isEnd&&(h.children.size>0?h.isEnd=!1:i.children.delete(n),e=!0,!0):!(!s(h,r+1)||i.isEnd||0!==h.children.size||(i.children.delete(n),0)))};return s(this.root,0),e}getHeight(){const t=this.root;let e=0;if(t){const s=(t,i)=>{i>e&&(e=i);const{children:r}=t;if(r)for(const t of r.entries())s(t[1],i+1)};s(t,0)}return e}hasPurePrefix(t){t=this._caseProcess(t);let e=this.root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return!e.isEnd}hasPrefix(t){t=this._caseProcess(t);let e=this.root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return!0}hasCommonPrefix(t){t=this._caseProcess(t);let e="";const s=i=>{e+=i.key,e!==t&&(i.isEnd||i&&i.children&&1===i.children.size&&s(Array.from(i.children.values())[0]))};return s(this.root),e===t}getLongestCommonPrefix(){let t="";const e=s=>{t+=s.key,s.isEnd||s&&s.children&&1===s.children.size&&e(Array.from(s.children.values())[0])};return e(this.root),t}getWords(t="",e=Number.MAX_SAFE_INTEGER){t=this._caseProcess(t);const s=[];let i=0,r=this.root;if(t)for(const e of t){const t=r.children.get(e);t&&(r=t)}return r!==this.root&&function t(r,n){for(const e of r.children.keys()){const s=r.children.get(e);void 0!==s&&t(s,n.concat(e))}if(r.isEnd){if(i>e-1)return;s.push(n),i++}}(r,t),s}}return e})()));
|
|
2
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.dataStructureTyped=e():t.dataStructureTyped=e()}(self,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{AVLTree:()=>it,AVLTreeNode:()=>st,AbstractEdge:()=>C,AbstractGraph:()=>O,AbstractVertex:()=>N,ArrayDeque:()=>x,BST:()=>Z,BSTNode:()=>X,BinaryIndexedTree:()=>$,BinaryTree:()=>J,BinaryTreeNode:()=>Y,CP:()=>q,Character:()=>vt,CoordinateMap:()=>r,CoordinateSet:()=>n,Deque:()=>y,DirectedEdge:()=>I,DirectedGraph:()=>F,DirectedVertex:()=>L,DoublyLinkedList:()=>d,DoublyLinkedListNode:()=>c,FamilyPosition:()=>G,FibonacciHeap:()=>V,FibonacciHeapNode:()=>S,HashMap:()=>l,HashTable:()=>i,HashTableNode:()=>s,Heap:()=>z,LinkedListQueue:()=>p,LoopType:()=>K,MapEdge:()=>j,MapGraph:()=>U,MapVertex:()=>H,Matrix2D:()=>pt,MatrixNTI2D:()=>ft,MaxHeap:()=>at,MaxPriorityQueue:()=>dt,MinHeap:()=>ut,MinPriorityQueue:()=>ct,Navigator:()=>yt,ObjectDeque:()=>m,PriorityQueue:()=>A,Queue:()=>v,RBColor:()=>W,RBTree:()=>nt,RBTreeNode:()=>rt,SegmentTree:()=>et,SegmentTreeNode:()=>tt,SinglyLinkedList:()=>u,SinglyLinkedListNode:()=>a,SkipList:()=>g,SkipListNode:()=>f,Stack:()=>_,THUNK_SYMBOL:()=>k,TopologicalProperty:()=>Q,TreeMap:()=>h,TreeMultiset:()=>ot,TreeMultisetNode:()=>ht,TreeNode:()=>lt,TreeSet:()=>o,Trie:()=>xt,TrieNode:()=>mt,UndirectedEdge:()=>D,UndirectedGraph:()=>B,UndirectedVertex:()=>P,Vector2D:()=>gt,arrayRemove:()=>E,isThunk:()=>w,toThunk:()=>M,trampoline:()=>T,trampolineAsync:()=>R,uuidV4:()=>b});class s{constructor(t,e){this.key=t,this.val=e,this.next=null}}class i{get hashFn(){return this._hashFn}set hashFn(t){this._hashFn=t}get buckets(){return this._buckets}set buckets(t){this._buckets=t}get capacity(){return this._capacity}set capacity(t){this._capacity=t}constructor(t=i.DEFAULT_CAPACITY,e){this._hashFn=e||this._defaultHashFn,this._capacity=Math.max(t,i.DEFAULT_CAPACITY),this._size=0,this._buckets=new Array(this._capacity).fill(null)}_defaultHashFn(t){return("string"==typeof t?this._murmurStringHashFn(t):this._objectHash(t))%this._capacity}_multiplicativeStringHashFn(t){const e=String(t);let s=0;for(let t=0;t<e.length;t++)s=(.618033988749895*s+e.charCodeAt(t))%(1<<30);return Math.abs(s)}_murmurStringHashFn(t){const e=String(t);let s=0;for(let t=0;t<e.length;t++)s=1540483477*(s^e.charCodeAt(t)),s=668265261*(s^s>>>15),s^=s>>>15;return Math.abs(s)}_hash(t){return this.hashFn(t)}_stringHash(t){let e=0;for(let s=0;s<t.length;s++)e=31*e+t.charCodeAt(s)&4294967295;return e}_objectHash(t){return this._stringHash(JSON.stringify(t))}set(t,e){const r=this._hash(t),n=new s(t,e);if(this._buckets[r]){let s=this._buckets[r];for(;s;){if(s.key===t)return void(s.val=e);if(!s.next)break;s=s.next}s.next=n}else this._buckets[r]=n;this._size++,this._size/this._capacity>=i.LOAD_FACTOR&&this._expand()}get(t){const e=this._hash(t);let s=this._buckets[e];for(;s;){if(s.key===t)return s.val;s=s.next}}delete(t){const e=this._hash(t);let s=this._buckets[e],i=null;for(;s;){if(s.key===t)return i?i.next=s.next:this._buckets[e]=s.next,this._size--,void(s.next=null);i=s,s=s.next}}_expand(){const t=2*this._capacity,e=new Array(t).fill(null);for(const t of this._buckets){let i=t;for(;i;){const t=this._hash(i.key),r=new s(i.key,i.val);if(e[t]){let s=e[t];for(;s.next;)s=s.next;s.next=r}else e[t]=r;i=i.next}}this._buckets=e,this._capacity=t}get size(){return this._size}}i.DEFAULT_CAPACITY=16,i.LOAD_FACTOR=.75;class r extends Map{constructor(t){super(),this._joint="_",void 0!==t&&(this._joint=t)}get joint(){return this._joint}has(t){return super.has(t.join(this._joint))}set(t,e){return super.set(t.join(this._joint),e)}get(t){return super.get(t.join(this._joint))}delete(t){return super.delete(t.join(this._joint))}_setJoint(t){this._joint=t}}class n extends Set{constructor(t){super(),this._joint="_",void 0!==t&&(this._joint=t)}get joint(){return this._joint}has(t){return super.has(t.join(this._joint))}add(t){return super.add(t.join(this._joint))}delete(t){return super.delete(t.join(this._joint))}_setJoint(t){this._joint=t}}class h{}class o{}class l{get hashFn(){return this._hashFn}set hashFn(t){this._hashFn=t}get table(){return this._table}set table(t){this._table=t}get capacityMultiplier(){return this._capacityMultiplier}set capacityMultiplier(t){this._capacityMultiplier=t}get loadFactor(){return this._loadFactor}set loadFactor(t){this._loadFactor=t}get initialCapacity(){return this._initialCapacity}set initialCapacity(t){this._initialCapacity=t}get size(){return this._size}set size(t){this._size=t}constructor(t=16,e=.75,s){this._initialCapacity=t,this._loadFactor=e,this._capacityMultiplier=2,this._size=0,this._table=new Array(t),this._hashFn=s||(t=>{const e=String(t);let s=0;for(let t=0;t<e.length;t++)s+=e.charCodeAt(t);return s%this.table.length})}_hash(t){return this._hashFn(t)}resizeTable(t){const e=new Array(t);for(const s of this._table)if(s)for(const[i,r]of s){const s=this._hash(i)%t;e[s]||(e[s]=[]),e[s].push([i,r])}this._table=e}set(t,e){this.size/this.table.length>=this.loadFactor&&this.resizeTable(this.table.length*this.capacityMultiplier);const s=this._hash(t);this.table[s]||(this.table[s]=[]);for(let i=0;i<this.table[s].length;i++)if(this.table[s][i][0]===t)return void(this.table[s][i][1]=e);this.table[s].push([t,e]),this.size++}get(t){const e=this._hash(t);if(this.table[e])for(const[s,i]of this.table[e])if(s===t)return i}delete(t){const e=this._hash(t);if(this.table[e])for(let s=0;s<this.table[e].length;s++)if(this.table[e][s][0]===t)return this.table[e].splice(s,1),this.size--,void(this.size/this.table.length<this.loadFactor/this.capacityMultiplier&&this.resizeTable(this.table.length/this.capacityMultiplier))}*entries(){for(const t of this.table)if(t)for(const[e,s]of t)yield[e,s]}[Symbol.iterator](){return this.entries()}clear(){this.size=0,this.table=new Array(this.initialCapacity)}isEmpty(){return 0===this.size}}class a{constructor(t){this._val=t,this._next=null}get val(){return this._val}set val(t){this._val=t}get next(){return this._next}set next(t){this._next=t}}class u{constructor(){this._head=null,this._tail=null,this._length=0}get head(){return this._head}set head(t){this._head=t}get tail(){return this._tail}set tail(t){this._tail=t}get length(){return this._length}static fromArray(t){const e=new u;for(const s of t)e.push(s);return e}getLength(){return this._length}push(t){const e=new a(t);this.head?(this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}pop(){if(!this.head)return;if(this.head===this.tail){const t=this.head.val;return this.head=null,this.tail=null,this._length--,t}let t=this.head;for(;t.next!==this.tail;)t=t.next;const e=this.tail.val;return t.next=null,this.tail=t,this._length--,e}shift(){if(!this.head)return;const t=this.head;return this.head=this.head.next,this._length--,t.val}unshift(t){const e=new a(t);this.head?(e.next=this.head,this.head=e):(this.head=e,this.tail=e),this._length++}getAt(t){if(t<0||t>=this.length)return;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e.val}getNodeAt(t){let e=this.head;for(let s=0;s<t;s++)e=e.next;return e}deleteAt(t){if(t<0||t>=this.length)return;if(0===t)return this.shift();if(t===this.length-1)return this.pop();const e=this.getNodeAt(t-1),s=e.next;return e.next=s.next,this._length--,s.val}delete(t){let e;e=t instanceof a?t.val:t;let s=this.head,i=null;for(;s;){if(s.val===e)return null===i?(this.head=s.next,s===this.tail&&(this.tail=null)):(i.next=s.next,s===this.tail&&(this.tail=i)),this._length--,!0;i=s,s=s.next}return!1}insertAt(t,e){if(t<0||t>this.length)return!1;if(0===t)return this.unshift(e),!0;if(t===this.length)return this.push(e),!0;const s=new a(e),i=this.getNodeAt(t-1);return s.next=i.next,i.next=s,this._length++,!0}isEmpty(){return 0===this.length}clear(){this._head=null,this._tail=null,this._length=0}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.val),e=e.next;return t}reverse(){if(!this.head||this.head===this.tail)return;let t=null,e=this.head,s=null;for(;e;)s=e.next,e.next=t,t=e,e=s;[this.head,this.tail]=[this.tail,this.head]}find(t){let e=this.head;for(;e;){if(t(e.val))return e.val;e=e.next}return null}indexOf(t){let e=0,s=this.head;for(;s;){if(s.val===t)return e;e++,s=s.next}return-1}findNode(t){let e=this.head;for(;e;){if(e.val===t)return e;e=e.next}return null}insertBefore(t,e){if(!this.head)return!1;let s;if(s=t instanceof a?t.val:t,this.head.val===s)return this.unshift(e),!0;let i=this.head;for(;i.next;){if(i.next.val===s){const t=new a(e);return t.next=i.next,i.next=t,this._length++,!0}i=i.next}return!1}insertAfter(t,e){let s;if(s=t instanceof a?t:this.findNode(t),s){const t=new a(e);return t.next=s.next,s.next=t,s===this.tail&&(this.tail=t),this._length++,!0}return!1}countOccurrences(t){let e=0,s=this.head;for(;s;)s.val===t&&e++,s=s.next;return e}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.val,t=t.next}}class c{constructor(t){this._val=t,this._next=null,this._prev=null}get val(){return this._val}set val(t){this._val=t}get next(){return this._next}set next(t){this._next=t}get prev(){return this._prev}set prev(t){this._prev=t}}class d{constructor(){this._head=null,this._tail=null,this._length=0}get head(){return this._head}set head(t){this._head=t}get tail(){return this._tail}set tail(t){this._tail=t}get length(){return this._length}static fromArray(t){const e=new d;for(const s of t)e.push(s);return e}push(t){const e=new c(t);this.head?(e.prev=this.tail,this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}addLast(t){this.push(t)}pop(){if(!this.tail)return;const t=this.tail;return this.head===this.tail?(this.head=null,this.tail=null):(this.tail=t.prev,this.tail.next=null),this._length--,t.val}pollLast(){return this.pop()}shift(){if(!this.head)return;const t=this.head;return this.head===this.tail?(this.head=null,this.tail=null):(this.head=t.next,this.head.prev=null),this._length--,t.val}pollFirst(){return this.shift()}unshift(t){const e=new c(t);this.head?(e.next=this.head,this.head.prev=e,this.head=e):(this.head=e,this.tail=e),this._length++}addFirst(t){this.unshift(t)}peekFirst(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}peekLast(){var t;return null===(t=this.tail)||void 0===t?void 0:t.val}get size(){return this.length}getAt(t){if(t<0||t>=this.length)return;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e.val}getNodeAt(t){if(t<0||t>=this.length)return null;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e}findNode(t){let e=this.head;for(;e;){if(e.val===t)return e;e=e.next}return null}insertAt(t,e){if(t<0||t>this.length)return!1;if(0===t)return this.unshift(e),!0;if(t===this.length)return this.push(e),!0;const s=new c(e),i=this.getNodeAt(t-1),r=i.next;return s.prev=i,s.next=r,i.next=s,r.prev=s,this._length++,!0}deleteAt(t){if(t<0||t>=this.length)return;if(0===t)return this.shift();if(t===this.length-1)return this.pop();const e=this.getNodeAt(t),s=e.prev,i=e.next;return s.next=i,i.prev=s,this._length--,e.val}delete(t){let e;if(e=t instanceof c?t:this.findNode(t),e){if(e===this.head)this.shift();else if(e===this.tail)this.pop();else{const t=e.prev,s=e.next;t.next=s,s.prev=t,this._length--}return!0}return!1}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.val),e=e.next;return t}isEmpty(){return 0===this.length}clear(){this._head=null,this._tail=null,this._length=0}find(t){let e=this.head;for(;e;){if(t(e.val))return e.val;e=e.next}return null}indexOf(t){let e=0,s=this.head;for(;s;){if(s.val===t)return e;e++,s=s.next}return-1}findLast(t){let e=this.tail;for(;e;){if(t(e.val))return e.val;e=e.prev}return null}toArrayReverse(){const t=[];let e=this.tail;for(;e;)t.push(e.val),e=e.prev;return t}reverse(){let t=this.head;for([this.head,this.tail]=[this.tail,this.head];t;){const e=t.next;[t.prev,t.next]=[t.next,t.prev],t=e}}forEach(t){let e=this.head,s=0;for(;e;)t(e.val,s),e=e.next,s++}map(t){const e=new d;let s=this.head;for(;s;)e.push(t(s.val)),s=s.next;return e}filter(t){const e=new d;let s=this.head;for(;s;)t(s.val)&&e.push(s.val),s=s.next;return e}reduce(t,e){let s=e,i=this.head;for(;i;)s=t(s,i.val),i=i.next;return s}insertAfter(t,e){let s;if(s=t instanceof c?t:this.findNode(t),s){const t=new c(e);return t.next=s.next,s.next&&(s.next.prev=t),t.prev=s,s.next=t,s===this.tail&&(this.tail=t),this._length++,!0}return!1}insertBefore(t,e){let s;if(s=t instanceof c?t:this.findNode(t),s){const t=new c(e);return t.prev=s.prev,s.prev&&(s.prev.next=t),t.next=s,s.prev=t,s===this.head&&(this.head=t),this._length++,!0}return!1}}class f{constructor(t,e,s){this.key=t,this.value=e,this.forward=new Array(s)}}class g{get probability(){return this._probability}set probability(t){this._probability=t}get maxLevel(){return this._maxLevel}set maxLevel(t){this._maxLevel=t}get level(){return this._level}set level(t){this._level=t}get head(){return this._head}set head(t){this._head=t}constructor(t=16,e=.5){this._head=new f(null,null,t),this._level=0,this._maxLevel=t,this._probability=e}randomLevel(){let t=1;for(;Math.random()<this.probability&&t<this.maxLevel;)t++;return t}add(t,e){const s=new f(t,e,this.randomLevel()),i=new Array(this.maxLevel).fill(this.head);let r=this.head;for(let e=this.level-1;e>=0;e--){for(;r.forward[e]&&r.forward[e].key<t;)r=r.forward[e];i[e]=r}for(let t=0;t<s.forward.length;t++)s.forward[t]=i[t].forward[t],i[t].forward[t]=s;null!==s.forward[0]&&(this.level=Math.max(this.level,s.forward.length))}get(t){let e=this.head;for(let s=this.level-1;s>=0;s--)for(;e.forward[s]&&e.forward[s].key<t;)e=e.forward[s];if(e=e.forward[0],e&&e.key===t)return e.value}delete(t){const e=new Array(this.maxLevel).fill(this.head);let s=this.head;for(let i=this.level-1;i>=0;i--){for(;s.forward[i]&&s.forward[i].key<t;)s=s.forward[i];e[i]=s}if(s=s.forward[0],s&&s.key===t){for(let t=0;t<this.level&&e[t].forward[t]===s;t++)e[t].forward[t]=s.forward[t];for(;this.level>0&&null===this.head.forward[this.level-1];)this.level--;return!0}return!1}}class _{constructor(t){this._elements=Array.isArray(t)?t:[]}static fromArray(t){return new _(t)}isEmpty(){return 0===this._elements.length}size(){return this._elements.length}peek(){return this.isEmpty()?null:this._elements[this._elements.length-1]}push(t){return this._elements.push(t),this}pop(){return this.isEmpty()?null:this._elements.pop()||null}toArray(){return this._elements.slice()}clear(){this._elements=[]}clone(){return new _(this._elements.slice())}}class p extends u{enqueue(t){this.push(t)}dequeue(){return this.shift()}peek(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}}class v{constructor(t){this._nodes=t||[],this._offset=0}get nodes(){return this._nodes}set nodes(t){this._nodes=t}get offset(){return this._offset}set offset(t){this._offset=t}get size(){return this.nodes.length-this.offset}static fromArray(t){return new v(t)}push(t){return this.nodes.push(t),this}shift(){if(0===this.size)return;const t=this.peek();return this.offset+=1,2*this.offset<this.nodes.length||(this.nodes=this.nodes.slice(this.offset),this.offset=0),t}peek(){return this.size>0?this.nodes[this.offset]:void 0}peekLast(){return this.size>0?this.nodes[this.nodes.length-1]:void 0}enqueue(t){this.push(t)}dequeue(){return this.shift()}getAt(t){return this.nodes[t]}isEmpty(){return 0===this.size}toArray(){return this.nodes.slice(this.offset)}clear(){this.nodes=[],this.offset=0}clone(){return new v(this.nodes.slice(this.offset))}*[Symbol.iterator](){for(const t of this.nodes)yield t}}class y extends d{}class m{constructor(t){this._nodes={},this._capacity=Number.MAX_SAFE_INTEGER,this._first=-1,this._last=-1,this._size=0,void 0!==t&&(this._capacity=t)}get nodes(){return this._nodes}get capacity(){return this._capacity}set capacity(t){this._capacity=t}get first(){return this._first}set first(t){this._first=t}get last(){return this._last}set last(t){this._last=t}get size(){return this._size}addFirst(t){if(0===this._size){const t=Math.floor(this._capacity/2);this._first=t,this._last=t}else this._first--;this._nodes[this._first]=t,this._size++}addLast(t){if(0===this._size){const t=Math.floor(this._capacity/2);this._first=t,this._last=t}else this._last++;this._nodes[this._last]=t,this._size++}pollFirst(){if(!this._size)return;const t=this.peekFirst();return delete this._nodes[this._first],this._first++,this._size--,t}peekFirst(){if(this._size)return this._nodes[this._first]}pollLast(){if(!this._size)return;const t=this.peekLast();return delete this._nodes[this._last],this._last--,this._size--,t}peekLast(){if(this._size)return this._nodes[this._last]}get(t){return this._nodes[this._first+t]||null}isEmpty(){return this._size<=0}_seNodes(t){this._nodes=t}_setSize(t){this._size=t}}class x{constructor(){this._nodes=[]}get size(){return this._nodes.length}addLast(t){return this._nodes.push(t)}pollLast(){var t;return null!==(t=this._nodes.pop())&&void 0!==t?t:null}pollFirst(){var t;return null!==(t=this._nodes.shift())&&void 0!==t?t:null}addFirst(t){return this._nodes.unshift(t)}peekFirst(){var t;return null!==(t=this._nodes[0])&&void 0!==t?t:null}peekLast(){var t;return null!==(t=this._nodes[this._nodes.length-1])&&void 0!==t?t:null}get(t){var e;return null!==(e=this._nodes[t])&&void 0!==e?e:null}set(t,e){return this._nodes[t]=e}insert(t,e){return this._nodes.splice(t,0,e)}delete(t){return this._nodes.splice(t,1)}isEmpty(){return 0===this._nodes.length}}const b=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,(function(t){const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))},E=function(t,e){let s=-1,i=t?t.length:0;const r=[];for(;++s<i;){const n=t[s];e(n,s,t)&&(r.push(n),Array.prototype.splice.call(t,s--,1),i--)}return r},k=Symbol("thunk"),w=t=>"function"==typeof t&&t.__THUNK__===k,M=t=>{const e=()=>t();return e.__THUNK__=k,e},T=t=>Object.assign(((...e)=>{let s=t(...e);for(;w(s)&&"function"==typeof s;)s=s();return s}),{cont:(...e)=>M((()=>t(...e)))}),R=t=>Object.assign(((...e)=>{return s=void 0,i=void 0,n=function*(){let s=yield t(...e);for(;w(s)&&"function"==typeof s;)s=yield s();return s},new((r=void 0)||(r=Promise))((function(t,e){function h(t){try{l(n.next(t))}catch(t){e(t)}}function o(t){try{l(n.throw(t))}catch(t){e(t)}}function l(e){var s;e.done?t(e.value):(s=e.value,s instanceof r?s:new r((function(t){t(s)}))).then(h,o)}l((n=n.apply(s,i||[])).next())}));var s,i,r,n}),{cont:(...e)=>M((()=>t(...e)))});class z{constructor(t){this.nodes=[],this.comparator=t}add(t){return this.push(t)}push(t){return this.nodes.push(t),this.bubbleUp(this.nodes.length-1),this}poll(){if(0===this.nodes.length)return;if(1===this.nodes.length)return this.nodes.pop();const t=this.nodes[0];return this.nodes[0]=this.nodes.pop(),this.sinkDown(0),t}pop(){return this.poll()}bubbleUp(t){const e=this.nodes[t];for(;t>0;){const s=Math.floor((t-1)/2),i=this.nodes[s];if(!(this.comparator(e,i)<0))break;this.nodes[t]=i,this.nodes[s]=e,t=s}}sinkDown(t){const e=2*t+1,s=2*t+2,i=this.nodes.length;let r=t;if(e<i&&this.comparator(this.nodes[e],this.nodes[r])<0&&(r=e),s<i&&this.comparator(this.nodes[s],this.nodes[r])<0&&(r=s),r!==t){const e=this.nodes[t];this.nodes[t]=this.nodes[r],this.nodes[r]=e,this.sinkDown(r)}}fix(){for(let t=Math.floor(this.size/2);t>=0;t--)this.sinkDown(t)}peek(){if(0!==this.nodes.length)return this.nodes[0]}get size(){return this.nodes.length}get leaf(){var t;return null!==(t=this.nodes[this.size-1])&&void 0!==t?t:void 0}isEmpty(){return 0===this.size}clear(){this.nodes=[]}refill(t){this.nodes=t,this.fix()}has(t){return this.nodes.includes(t)}dfs(t){const e=[],s=i=>{i<this.size&&("in"===t?(s(2*i+1),e.push(this.nodes[i]),s(2*i+2)):"pre"===t?(e.push(this.nodes[i]),s(2*i+1),s(2*i+2)):"post"===t&&(s(2*i+1),s(2*i+2),e.push(this.nodes[i])))};return s(0),e}toArray(){return[...this.nodes]}getNodes(){return this.nodes}clone(){const t=new z(this.comparator);return t.nodes=[...this.nodes],t}sort(){const t=[],e=this.clone();for(;0!==e.size;){const s=e.poll();s&&t.push(s)}return t}static heapify(t,e){const s=new z(e);return s.nodes=[...t],s.fix(),s}}class S{constructor(t,e=0){this.element=t,this.degree=e,this.marked=!1}}class V{constructor(t){if(this.size=0,this.clear(),this.comparator=t||this.defaultComparator,"function"!=typeof this.comparator)throw new Error("FibonacciHeap constructor: given comparator should be a function.")}defaultComparator(t,e){return t<e?-1:t>e?1:0}clear(){this.root=void 0,this.min=void 0,this.size=0}createNode(t){return new S(t)}mergeWithRoot(t){this.root?(t.right=this.root.right,t.left=this.root,this.root.right.left=t,this.root.right=t):this.root=t}add(t){return this.push(t)}push(t){const e=this.createNode(t);return e.left=e,e.right=e,this.mergeWithRoot(e),(!this.min||this.comparator(e.element,this.min.element)<=0)&&(this.min=e),this.size++,this}peek(){return this.min?this.min.element:void 0}consumeLinkedList(t){const e=[];if(!t)return e;let s=t,i=!1;for(;s!==t||!i;)s===t&&(i=!0),s&&(e.push(s),s=s.right);return e}removeFromRoot(t){this.root===t&&(this.root=t.right),t.left&&(t.left.right=t.right),t.right&&(t.right.left=t.left)}mergeWithChild(t,e){t.child?(e.right=t.child.right,e.left=t.child,t.child.right.left=e,t.child.right=e):t.child=e}link(t,e){this.removeFromRoot(t),t.left=t,t.right=t,this.mergeWithChild(e,t),e.degree++,t.parent=e}consolidate(){const t=new Array(this.size),e=this.consumeLinkedList(this.root);let s,i,r,n;for(const h of e){for(s=h,r=s.degree;t[r];)i=t[r],this.comparator(s.element,i.element)>0&&(n=s,s=i,i=n),this.link(i,s),t[r]=void 0,r++;t[r]=s}for(let e=0;e<this.size;e++)t[e]&&this.comparator(t[e].element,this.min.element)<=0&&(this.min=t[e])}poll(){return this.pop()}pop(){if(0===this.size)return;const t=this.min;if(t.child){const e=this.consumeLinkedList(t.child);for(const t of e)this.mergeWithRoot(t),t.parent=void 0}return this.removeFromRoot(t),t===t.right?(this.min=void 0,this.root=void 0):(this.min=t.right,this.consolidate()),this.size--,t.element}merge(t){if(0!==t.size){if(this.root&&t.root){const e=this.root,s=t.root,i=e.right,r=s.left;e.right=s,s.left=e,i.left=r,r.right=i}(!this.min||t.min&&this.comparator(t.min.element,this.min.element)<0)&&(this.min=t.min),this.size+=t.size,t.clear()}}}class A extends z{constructor(t){super(t)}}class N{constructor(t,e){this._key=t,this._val=e}get key(){return this._key}set key(t){this._key=t}get val(){return this._val}set val(t){this._val=t}}class C{constructor(t,e){this._weight=void 0!==t?t:1,this._val=e,this._hashCode=b()}get val(){return this._val}set val(t){this._val=t}get weight(){return this._weight}set weight(t){this._weight=t}get hashCode(){return this._hashCode}_setHashCode(t){this._hashCode=t}}class O{constructor(){this._vertices=new Map}get vertices(){return this._vertices}getVertex(t){return this._vertices.get(t)||null}hasVertex(t){return this._vertices.has(this._getVertexKey(t))}addVertex(t,e){if(t instanceof N)return this._addVertexOnly(t);{const s=this.createVertex(t,e);return this._addVertexOnly(s)}}removeVertex(t){const e=this._getVertexKey(t);return this._vertices.delete(e)}removeAllVertices(t){const e=[];for(const s of t)e.push(this.removeVertex(s));return e.length>0}hasEdge(t,e){return!!this.getEdge(t,e)}addEdge(t,e,s,i){if(t instanceof C)return this._addEdgeOnly(t);if(e instanceof N||"string"==typeof e||"number"==typeof e){if(!this.hasVertex(t)||!this.hasVertex(e))return!1;t instanceof N&&(t=t.key),e instanceof N&&(e=e.key);const r=this.createEdge(t,e,s,i);return this._addEdgeOnly(r)}throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(t,e,s){const i=this.getEdge(t,e);return!!i&&(i.weight=s,!0)}getAllPathsBetween(t,e){const s=[],i=this._getVertex(t),r=this._getVertex(e);if(!i||!r)return[];const n=(t,e,r,h)=>{r.set(t,!0),t===e&&s.push([i,...h]);const o=this.getNeighbors(t);for(const t of o)r.get(t)||(h.push(t),n(t,e,r,h),E(h,(e=>e===t)));r.set(t,!1)};return n(i,r,new Map,[]),s}getPathSumWeight(t){var e;let s=0;for(let i=0;i<t.length;i++)s+=(null===(e=this.getEdge(t[i],t[i+1]))||void 0===e?void 0:e.weight)||0;return s}getMinCostBetween(t,e,s){if(void 0===s&&(s=!1),s){const s=this.getAllPathsBetween(t,e);let i=1/0;for(const t of s)i=Math.min(this.getPathSumWeight(t),i);return i}{const s=this._getVertex(e),i=this._getVertex(t);if(!i||!s)return null;const r=new Map,n=new v([i]);r.set(i,!0);let h=0;for(;n.size>0;){for(let t=0;t<n.size;t++){const t=n.shift();if(t===s)return h;if(void 0!==t){const e=this.getNeighbors(t);for(const t of e)r.has(t)||(r.set(t,!0),n.push(t))}}h++}return null}}getMinPathBetween(t,e,s){if(void 0===s&&(s=!1),s){const s=this.getAllPathsBetween(t,e);let i=1/0,r=-1,n=0;for(const t of s){const e=this.getPathSumWeight(t);e<i&&(i=e,r=n),n++}return s[r]||null}{let s=[];const i=this._getVertex(t),r=this._getVertex(e);if(!i||!r)return[];const n=(t,e,r,h)=>{if(r.set(t,!0),t===e)return void(s=[i,...h]);const o=this.getNeighbors(t);for(const t of o)r.get(t)||(h.push(t),n(t,e,r,h),E(h,(e=>e===t)));r.set(t,!1)};return n(i,r,new Map,[]),s}}dijkstraWithoutHeap(t,e,s,i){void 0===s&&(s=!1),void 0===i&&(i=!1),void 0===e&&(e=null);let r=1/0,n=null,h=[];const o=[],l=this._vertices,a=new Map,u=new Set,c=new Map,d=this._getVertex(t),f=e?this._getVertex(e):null;if(!d)return null;for(const t of l){const e=t[1];e instanceof N&&a.set(e,1/0)}a.set(d,0),c.set(d,null);const g=()=>{let t=1/0,e=null;for(const[s,i]of a)u.has(s)||i<t&&(t=i,e=s);return e},_=t=>{for(const e of l){const s=e[1];if(s instanceof N){const i=[s];let r=c.get(s);for(;r;)i.push(r),r=c.get(r);const n=i.reverse();e[1]===t&&(h=n),o.push(n)}}};for(let t=1;t<l.size;t++){const t=g();if(t){if(u.add(t),f&&f===t)return s&&(r=a.get(f)||1/0),i&&_(f),{distMap:a,preMap:c,seen:u,paths:o,minDist:r,minPath:h};const e=this.getNeighbors(t);for(const s of e)if(!u.has(s)){const e=this.getEdge(t,s);if(e){const i=a.get(t),r=a.get(s);void 0!==i&&void 0!==r&&e.weight+i<r&&(a.set(s,e.weight+i),c.set(s,t))}}}}return s&&a.forEach(((t,e)=>{e!==d&&t<r&&(r=t,i&&(n=e))})),i&&_(n),{distMap:a,preMap:c,seen:u,paths:o,minDist:r,minPath:h}}dijkstra(t,e,s,i){var r;void 0===s&&(s=!1),void 0===i&&(i=!1),void 0===e&&(e=null);let n=1/0,h=null,o=[];const l=[],a=this._vertices,u=new Map,c=new Set,d=new Map,f=this._getVertex(t),g=e?this._getVertex(e):null;if(!f)return null;for(const t of a){const e=t[1];e instanceof N&&u.set(e,1/0)}const _=new A(((t,e)=>t.key-e.key));_.add({key:0,val:f}),u.set(f,0),d.set(f,null);const p=t=>{for(const e of a){const s=e[1];if(s instanceof N){const i=[s];let r=d.get(s);for(;r;)i.push(r),r=d.get(r);const n=i.reverse();e[1]===t&&(o=n),l.push(n)}}};for(;_.size>0;){const t=_.poll(),e=null==t?void 0:t.key,h=null==t?void 0:t.val;if(void 0!==e&&h){if(c.add(h),g&&g===h)return s&&(n=u.get(g)||1/0),i&&p(g),{distMap:u,preMap:d,seen:c,paths:l,minDist:n,minPath:o};const t=this.getNeighbors(h);for(const s of t)if(!c.has(s)){const t=null===(r=this.getEdge(h,s))||void 0===r?void 0:r.weight;if("number"==typeof t){const i=u.get(s);i&&e+t<i&&(_.add({key:e+t,val:s}),d.set(s,h),u.set(s,e+t))}}}}return s&&u.forEach(((t,e)=>{e!==f&&t<n&&(n=t,i&&(h=e))})),i&&p(h),{distMap:u,preMap:d,seen:c,paths:l,minDist:n,minPath:o}}bellmanFord(t,e,s,i){void 0===s&&(s=!1),void 0===i&&(i=!1);const r=this._getVertex(t),n=[],h=new Map,o=new Map;let l,a=1/0,u=[];if(e&&(l=!1),!r)return{hasNegativeCycle:l,distMap:h,preMap:o,paths:n,min:a,minPath:u};const c=this._vertices,d=c.size,f=this.edgeSet(),g=f.length;this._vertices.forEach((t=>{h.set(t,1/0)})),h.set(r,0);for(let t=1;t<d;++t)for(let t=0;t<g;++t){const e=this.getEndsOfEdge(f[t]);if(e){const[s,r]=e,n=f[t].weight,l=h.get(s),a=h.get(r);void 0!==l&&void 0!==a&&h.get(s)!==1/0&&l+n<a&&(h.set(r,l+n),i&&o.set(r,s))}}let _=null;if(s&&h.forEach(((t,e)=>{e!==r&&t<a&&(a=t,i&&(_=e))})),i)for(const t of c){const e=t[1];if(e instanceof N){const s=[e];let i=o.get(e);for(;void 0!==i;)s.push(i),i=o.get(i);const r=s.reverse();t[1]===_&&(u=r),n.push(r)}}for(let t=0;t<g;++t){const e=this.getEndsOfEdge(f[t]);if(e){const[s]=e,i=f[t].weight,r=h.get(s);r&&r!==1/0&&r+i<r&&(l=!0)}}return{hasNegativeCycle:l,distMap:h,preMap:o,paths:n,min:a,minPath:u}}floyd(){var t;const e=[...this._vertices],s=e.length,i=[],r=[];for(let t=0;t<s;t++){i[t]=[],r[t]=[];for(let e=0;e<s;e++)r[t][e]=null}for(let r=0;r<s;r++)for(let n=0;n<s;n++)i[r][n]=(null===(t=this.getEdge(e[r][1],e[n][1]))||void 0===t?void 0:t.weight)||1/0;for(let t=0;t<s;t++)for(let n=0;n<s;n++)for(let h=0;h<s;h++)i[n][h]>i[n][t]+i[t][h]&&(i[n][h]=i[n][t]+i[t][h],r[n][h]=e[t][1]);return{costs:i,predecessor:r}}tarjan(t,e,s,i){const r=!1;void 0===t&&(t=r),void 0===e&&(e=r),void 0===s&&(s=r),void 0===i&&(i=r);const n=new Map,h=new Map,o=this._vertices;o.forEach((t=>{n.set(t,-1),h.set(t,1/0)}));const[l]=o.values(),a=[],u=[];let c=0;const d=(s,i)=>{c++,n.set(s,c),h.set(s,c);const r=this.getNeighbors(s);let o=0;for(const c of r)if(c!==i){-1===n.get(c)&&(o++,d(c,s));const i=h.get(c),r=h.get(s);void 0!==r&&void 0!==i&&h.set(s,Math.min(r,i));const f=n.get(s);if(void 0!==i&&void 0!==f&&(t&&(s===l&&o>=2||s!==l&&i>=f)&&a.push(s),e&&i>f)){const t=this.getEdge(s,c);t&&u.push(t)}}};d(l,null);let f=new Map;const g=()=>{const t=new Map;return h.forEach(((e,s)=>{var i;t.has(e)?null===(i=t.get(e))||void 0===i||i.push(s):t.set(e,[s])})),t};s&&(f=g());const _=new Map;if(i){let t=new Map;t.size<1&&(t=g()),t.forEach(((t,e)=>{t.length>1&&_.set(e,t)}))}return{dfnMap:n,lowMap:h,bridges:u,articulationPoints:a,SCCs:f,cycles:_}}_addVertexOnly(t){return!this.hasVertex(t)&&(this._vertices.set(t.key,t),!0)}_getVertex(t){const e=this._getVertexKey(t);return this._vertices.get(e)||null}_getVertexKey(t){return t instanceof N?t.key:t}_setVertices(t){this._vertices=t}}class L extends N{constructor(t,e){super(t,e)}}class I extends C{constructor(t,e,s,i){super(s,i),this._src=t,this._dest=e}get src(){return this._src}set src(t){this._src=t}get dest(){return this._dest}set dest(t){this._dest=t}}class F extends O{constructor(){super(),this._outEdgeMap=new Map,this._inEdgeMap=new Map}get outEdgeMap(){return this._outEdgeMap}get inEdgeMap(){return this._inEdgeMap}createVertex(t,e){return new L(t,null!=e?e:t)}createEdge(t,e,s,i){return new I(t,e,null!=s?s:1,i)}getEdge(t,e){let s=[];if(null!==t&&null!==e){const i=this._getVertex(t),r=this._getVertex(e);if(i&&r){const t=this._outEdgeMap.get(i);t&&(s=t.filter((t=>t.dest===r.key)))}}return s[0]||null}removeEdgeSrcToDest(t,e){const s=this._getVertex(t),i=this._getVertex(e);let r=null;if(!s||!i)return null;const n=this._outEdgeMap.get(s);n&&E(n,(t=>t.dest===i.key));const h=this._inEdgeMap.get(i);return h&&(r=E(h,(t=>t.src===s.key))[0]||null),r}removeEdge(t){let e=null;const s=this._getVertex(t.src),i=this._getVertex(t.dest);if(s&&i){const t=this._outEdgeMap.get(s);t&&t.length>0&&E(t,(t=>t.src===s.key));const r=this._inEdgeMap.get(i);r&&r.length>0&&(e=E(r,(t=>t.dest===i.key))[0])}return e}removeEdgesBetween(t,e){const s=[];if(t&&e){const i=this.removeEdgeSrcToDest(t,e),r=this.removeEdgeSrcToDest(e,t);i&&s.push(i),r&&s.push(r)}return s}incomingEdgesOf(t){const e=this._getVertex(t);return e&&this.inEdgeMap.get(e)||[]}outgoingEdgesOf(t){const e=this._getVertex(t);return e&&this._outEdgeMap.get(e)||[]}degreeOf(t){return this.outDegreeOf(t)+this.inDegreeOf(t)}inDegreeOf(t){return this.incomingEdgesOf(t).length}outDegreeOf(t){return this.outgoingEdgesOf(t).length}edgesOf(t){return[...this.outgoingEdgesOf(t),...this.incomingEdgesOf(t)]}getEdgeSrc(t){return this._getVertex(t.src)}getEdgeDest(t){return this._getVertex(t.dest)}getDestinations(t){if(null===t)return[];const e=[],s=this.outgoingEdgesOf(t);for(const t of s){const s=this.getEdgeDest(t);s&&e.push(s)}return e}topologicalSort(t){t=null!=t?t:"key";const e=new Map;for(const t of this.vertices)e.set(t[1],0);let s=[],i=!1;const r=t=>{e.set(t,1);const n=this.getDestinations(t);for(const t of n){const s=e.get(t);0===s?r(t):1===s&&(i=!0)}e.set(t,2),s.push(t)};for(const t of this.vertices)0===e.get(t[1])&&r(t[1]);return i?null:("key"===t&&(s=s.map((t=>t instanceof L?t.key:t))),s.reverse())}edgeSet(){let t=[];return this._outEdgeMap.forEach((e=>{t=[...t,...e]})),t}getNeighbors(t){const e=[],s=this._getVertex(t);if(s){const t=this.outgoingEdgesOf(s);for(const s of t){const t=this._getVertex(s.dest);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.src,t.dest))return null;const e=this._getVertex(t.src),s=this._getVertex(t.dest);return e&&s?[e,s]:null}_addEdgeOnly(t){if(!this.hasVertex(t.src)||!this.hasVertex(t.dest))return!1;const e=this._getVertex(t.src),s=this._getVertex(t.dest);if(e&&s){const i=this._outEdgeMap.get(e);i?i.push(t):this._outEdgeMap.set(e,[t]);const r=this._inEdgeMap.get(s);return r?r.push(t):this._inEdgeMap.set(s,[t]),!0}return!1}_setOutEdgeMap(t){this._outEdgeMap=t}_setInEdgeMap(t){this._inEdgeMap=t}}class P extends N{constructor(t,e){super(t,e)}}class D extends C{constructor(t,e,s,i){super(s,i),this._vertices=[t,e]}get vertices(){return this._vertices}set vertices(t){this._vertices=t}}class B extends O{constructor(){super(),this._edges=new Map}get edges(){return this._edges}createVertex(t,e){return new P(t,null!=e?e:t)}createEdge(t,e,s,i){return new D(t,e,null!=s?s:1,i)}getEdge(t,e){var s;let i=[];if(null!==t&&null!==e){const r=this._getVertex(t),n=this._getVertex(e);r&&n&&(i=null===(s=this._edges.get(r))||void 0===s?void 0:s.filter((t=>t.vertices.includes(n.key))))}return i&&i[0]||null}removeEdgeBetween(t,e){const s=this._getVertex(t),i=this._getVertex(e);if(!s||!i)return null;const r=this._edges.get(s);let n=null;r&&(n=E(r,(t=>t.vertices.includes(i.key)))[0]||null);const h=this._edges.get(i);return h&&E(h,(t=>t.vertices.includes(s.key))),n}removeEdge(t){return this.removeEdgeBetween(t.vertices[0],t.vertices[1])}degreeOf(t){var e;const s=this._getVertex(t);return s&&(null===(e=this._edges.get(s))||void 0===e?void 0:e.length)||0}edgesOf(t){const e=this._getVertex(t);return e&&this._edges.get(e)||[]}edgeSet(){const t=new Set;return this._edges.forEach((e=>{e.forEach((e=>{t.add(e)}))})),[...t]}getNeighbors(t){const e=[],s=this._getVertex(t);if(s){const t=this.edgesOf(s);for(const i of t){const t=this._getVertex(i.vertices.filter((t=>t!==s.key))[0]);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.vertices[0],t.vertices[1]))return null;const e=this._getVertex(t.vertices[0]),s=this._getVertex(t.vertices[1]);return e&&s?[e,s]:null}_addEdgeOnly(t){for(const e of t.vertices){const s=this._getVertex(e);if(null===s)return!1;if(s){const e=this._edges.get(s);e?e.push(t):this._edges.set(s,[t])}}return!0}_setEdges(t){this._edges=t}}class H extends L{constructor(t,e,s,i){super(t,i),this._lat=e,this._long=s}get lat(){return this._lat}set lat(t){this._lat=t}get long(){return this._long}set long(t){this._long=t}}class j extends I{constructor(t,e,s,i){super(t,e,s,i)}}class U extends F{constructor(t,e){super(),this._origin=[0,0],this._origin=t,this._bottomRight=e}get origin(){return this._origin}set origin(t){this._origin=t}get bottomRight(){return this._bottomRight}set bottomRight(t){this._bottomRight=t}createVertex(t,e,s=this.origin[0],i=this.origin[1]){return new H(t,s,i,e)}createEdge(t,e,s,i){return new j(t,e,s,i)}}var K,G,q,W,Q;!function(t){t.ITERATIVE="ITERATIVE",t.RECURSIVE="RECURSIVE"}(K||(K={})),function(t){t.ROOT="ROOT",t.LEFT="LEFT",t.RIGHT="RIGHT",t.ROOT_LEFT="ROOT_LEFT",t.ROOT_RIGHT="ROOT_RIGHT",t.ISOLATED="ISOLATED",t.MAL_NODE="MAL_NODE"}(G||(G={})),function(t){t.lt="lt",t.eq="eq",t.gt="gt"}(q||(q={})),function(t){t.RED="RED",t.BLACK="BLACK"}(W||(W={})),function(t){t.VAL="VAL",t.NODE="NODE",t.ID="ID"}(Q||(Q={}));class Y{constructor(t,e){this.key=t,this.val=e}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get familyPosition(){const t=this;return t.parent?t.parent.left===t?t.left||t.right?G.ROOT_LEFT:G.LEFT:t.parent.right===t?t.left||t.right?G.ROOT_RIGHT:G.RIGHT:G.MAL_NODE:t.left||t.right?G.ROOT:G.ISOLATED}}class J{constructor(t){if(this._root=null,this._size=0,this._loopType=K.ITERATIVE,this._defaultCallbackByKey=t=>t.key,void 0!==t){const{loopType:e=K.ITERATIVE}=t;this._loopType=e}}createNode(t,e){return new Y(t,e)}get root(){return this._root}get size(){return this._size}get loopType(){return this._loopType}set loopType(t){this._loopType=t}_swap(t,e){const{key:s,val:i}=e,r=this.createNode(s,i);return r&&(e.key=t.key,e.val=t.val,t.key=r.key,t.val=r.val),e}clear(){this._root=null,this._size=0}isEmpty(){return 0===this.size}add(t,e){let s,i;if(null===t)i=null;else if("number"==typeof t)i=this.createNode(t,e);else{if(!(t instanceof Y))return;i=t}const r=t?this.get(t,this._defaultCallbackByKey):void 0;return this.root?r?(r.val=e,s=r):s=((t,e)=>{const s=new v([t]);for(;s.size>0;){const t=s.shift();if(!t)return;{if(e&&t.key===e.key)return;const i=this._addTo(e,t);if(void 0!==i)return i;t.left&&s.push(t.left),t.right&&s.push(t.right)}}})(this.root,i):(this._setRoot(i),null!==i?this._setSize(1):this._setSize(0),s=this.root),s}addMany(t,e){const s=[];for(let i=0;i<t.length;i++){const r=t[i];if(r instanceof Y){s.push(this.add(r.key,r.val));continue}if(null===r){s.push(this.add(null));continue}const n=null==e?void 0:e[i];s.push(this.add(r,n))}return s}refill(t,e){return this.clear(),t.length===this.addMany(t,e).length}delete(t){const e=[];if(!this.root)return e;const s="number"==typeof t?this.get(t):t;if(!s)return e;const i=(null==s?void 0:s.parent)?s.parent:null;let r=null,n=s;if(s.left){const t=s.left?this.getRightMost(s.left):null;if(t){const e=t.parent;n=this._swap(s,t),e&&(e.right===t?e.right=t.left:e.left=t.left,r=e)}}else if(i){const{familyPosition:t}=s;t===G.LEFT||t===G.ROOT_LEFT?i.left=s.right:t!==G.RIGHT&&t!==G.ROOT_RIGHT||(i.right=s.right),r=i}else void 0!==s.right&&this._setRoot(s.right);return this._setSize(this.size-1),e.push({deleted:n,needBalanced:r}),e}getDepth(t,e=this.root){"number"==typeof t&&(t=this.get(t)),"number"==typeof e&&(e=this.get(e));let s=0;for(;null==t?void 0:t.parent;){if(t===e)return s;s++,t=t.parent}return s}getHeight(t=this.root){if("number"==typeof t&&(t=this.get(t)),!t)return-1;if(this._loopType===K.RECURSIVE){const e=t=>{if(!t)return-1;const s=e(t.left),i=e(t.right);return Math.max(s,i)+1};return e(t)}{if(!t)return-1;const e=[{node:t,depth:0}];let s=0;for(;e.length>0;){const{node:t,depth:i}=e.pop();t.left&&e.push({node:t.left,depth:i+1}),t.right&&e.push({node:t.right,depth:i+1}),s=Math.max(s,i)}return s}}getMinHeight(t=this.root){var e,s,i;if(!t)return-1;if(this._loopType===K.RECURSIVE){const e=t=>{if(!t)return 0;if(!t.left&&!t.right)return 0;const s=e(t.left),i=e(t.right);return Math.min(s,i)+1};return e(t)}{const r=[];let n=t,h=null;const o=new Map;for(;r.length>0||n;)if(n)r.push(n),n=n.left;else if(n=r[r.length-1],n.right&&h!==n.right)n=n.right;else if(n=r.pop(),n){const t=n.left&&null!==(e=o.get(n.left))&&void 0!==e?e:-1,i=n.right&&null!==(s=o.get(n.right))&&void 0!==s?s:-1;o.set(n,1+Math.min(t,i)),h=n,n=null}return null!==(i=o.get(t))&&void 0!==i?i:-1}}isPerfectlyBalanced(t=this.root){return this.getMinHeight(t)+1>=this.getHeight(t)}getNodes(t,e=this._defaultCallbackByKey,s=!1,i=this.root){if(!i)return[];const r=[];if(this.loopType===K.RECURSIVE){const n=i=>{e(i)===t&&(r.push(i),s)||(i.left||i.right)&&(i.left&&n(i.left),i.right&&n(i.right))};n(i)}else{const n=new v([i]);for(;n.size>0;){const i=n.shift();if(i){if(e(i)===t&&(r.push(i),s))return r;i.left&&n.push(i.left),i.right&&n.push(i.right)}}}return r}has(t,e=this._defaultCallbackByKey){return this.getNodes(t,e,!0).length>0}get(t,e=this._defaultCallbackByKey){var s;return null!==(s=this.getNodes(t,e,!0)[0])&&void 0!==s?s:null}getPathToRoot(t,e=!0){const s=[];for(;t.parent;)s.push(t),t=t.parent;return s.push(t),e?s.reverse():s}getLeftMost(t=this.root){if("number"==typeof t&&(t=this.get(t)),!t)return t;if(this._loopType===K.RECURSIVE){const e=t=>t.left?e(t.left):t;return e(t)}{const e=T((t=>t.left?e.cont(t.left):t));return e(t)}}getRightMost(t=this.root){if(!t)return t;if(this._loopType===K.RECURSIVE){const e=t=>t.right?e(t.right):t;return e(t)}{const e=T((t=>t.right?e.cont(t.right):t));return e(t)}}isSubtreeBST(t){if(!t)return!0;if(this._loopType===K.RECURSIVE){const e=(t,s,i)=>!t||!(t.key<=s||t.key>=i)&&e(t.left,s,t.key)&&e(t.right,t.key,i);return e(t,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER)}{const e=[];let s=Number.MIN_SAFE_INTEGER,i=t;for(;i||e.length>0;){for(;i;)e.push(i),i=i.left;if(i=e.pop(),!i||s>=i.key)return!1;s=i.key,i=i.right}return!0}}isBST(){return this.isSubtreeBST(this.root)}subTreeTraverse(t=this._defaultCallbackByKey,e=this.root){"number"==typeof e&&(e=this.get(e));const s=[];if(!e)return s;if(this._loopType===K.RECURSIVE){const i=e=>{s.push(t(e)),e.left&&i(e.left),e.right&&i(e.right)};i(e)}else{const i=[e];for(;i.length>0;){const e=i.pop();s.push(t(e)),e.right&&i.push(e.right),e.left&&i.push(e.left)}}return s}dfs(t=this._defaultCallbackByKey,e="in",s=this.root,i=K.ITERATIVE){if(!s)return[];const r=[];if(i===K.RECURSIVE){const i=s=>{switch(e){case"in":s.left&&i(s.left),r.push(t(s)),s.right&&i(s.right);break;case"pre":r.push(t(s)),s.left&&i(s.left),s.right&&i(s.right);break;case"post":s.left&&i(s.left),s.right&&i(s.right),r.push(t(s))}};i(s)}else{const i=[{opt:0,node:s}];for(;i.length>0;){const s=i.pop();if(s&&s.node)if(1===s.opt)r.push(t(s.node));else switch(e){case"in":default:i.push({opt:0,node:s.node.right}),i.push({opt:1,node:s.node}),i.push({opt:0,node:s.node.left});break;case"pre":i.push({opt:0,node:s.node.right}),i.push({opt:0,node:s.node.left}),i.push({opt:1,node:s.node});break;case"post":i.push({opt:1,node:s.node}),i.push({opt:0,node:s.node.right}),i.push({opt:0,node:s.node.left})}}}return r}bfs(t=this._defaultCallbackByKey,e=!1,s){if(s||(s=this.root),!s)return[];const i=[];if(this.loopType===K.RECURSIVE){const r=(s,n)=>{t&&i.push(t(s,e?n:void 0)),s.left&&r(s.left,n+1),s.right&&r(s.right,n+1)};r(s,0)}else{const r=[[s,0]];for(;r.length>0;){const s=r.pop(),[n,h]=s;t&&i.push(t(n,e?h:void 0)),n.right&&r.push([n.right,h+1]),n.left&&r.push([n.left,h+1])}}return i}getPredecessor(t){if(t.left){let e=t.left;for(;!e||e.right&&e.right!==t;)e&&(e=e.right);return e}return t}morris(t=this._defaultCallbackByKey,e="in"){if(null===this.root)return[];const s=[];let i=this.root;const r=t=>{let e=null,s=null;for(;t;)s=t.right,t.right=e,e=t,t=s;return e},n=e=>{const i=r(e);let n=i;for(;n;)s.push(t(n)),n=n.right;r(i)};switch(e){case"in":for(;i;){if(i.left){const t=this.getPredecessor(i);if(!t.right){t.right=i,i=i.left;continue}t.right=null}s.push(t(i)),i=i.right}break;case"pre":for(;i;){if(i.left){const e=this.getPredecessor(i);if(!e.right){e.right=i,s.push(t(i)),i=i.left;continue}e.right=null}else s.push(t(i));i=i.right}break;case"post":for(;i;){if(i.left){const t=this.getPredecessor(i);if(null===t.right){t.right=i,i=i.left;continue}t.right=null,n(i.left)}i=i.right}n(this.root)}return s}_addTo(t,e){return e?void 0===e.left?(e.left=t,t&&this._setSize(this.size+1),e.left):void 0===e.right?(e.right=t,t&&this._setSize(this.size+1),e.right):void 0:void 0}_setRoot(t){t&&(t.parent=void 0),this._root=t}_setSize(t){this._size=t}}class X extends Y{constructor(t,e){super(t,e)}}class Z extends J{constructor(t){if(super(t),this._comparator=(t,e)=>t-e,void 0!==t){const{comparator:e}=t;void 0!==e&&(this._comparator=e)}}createNode(t,e){return new X(t,e)}add(t,e){let s=null,i=null;if(t instanceof X?i=t:"number"==typeof t?i=this.createNode(t,e):null===t&&(i=null),null===this.root)this._setRoot(i),this._setSize(this.size+1),s=this.root;else{let t=this.root,e=!0;for(;e;)null!==t&&null!==i?this._compare(t.key,i.key)===q.eq?(i&&(t.val=i.val),e=!1,s=t):this._compare(t.key,i.key)===q.gt?void 0===t.left?(i&&(i.parent=t),t.left=i,this._setSize(this.size+1),e=!1,s=t.left):t.left&&(t=t.left):this._compare(t.key,i.key)===q.lt&&(void 0===t.right?(i&&(i.parent=t),t.right=i,this._setSize(this.size+1),e=!1,s=t.right):t.right&&(t=t.right)):e=!1}return s}addMany(t,e,s=!0){if(!s||-1!==t.indexOf(null))return super.addMany(t,e);const i=[],r=t.map(((t,s)=>[t,null==e?void 0:e[s]]));let n=[],h=[],o=[];if(function(t){for(const[e]of t)if(e instanceof X)return!0;return!1}(r))n=r.sort(((t,e)=>t[0].key-e[0].key));else{if(!function(t){for(const[e]of t)if("number"==typeof e)return!0;return!1}(r))throw new Error("Invalid input keysOrNodes");n=r.sort(((t,e)=>t[0]-e[0]))}h=n.map((([t])=>t)),o=n.map((([,t])=>t));const l=(t,e)=>{if(0===t.length)return;const s=Math.floor((t.length-1)/2),r=this.add(t[s],null==e?void 0:e[s]);i.push(r),l(t.slice(0,s),null==e?void 0:e.slice(0,s)),l(t.slice(s+1),null==e?void 0:e.slice(s+1))};return this.loopType===K.RECURSIVE?l(h,o):(()=>{const t=[[0,n.length-1]];for(;t.length>0;){const e=t.pop();if(e){const[s,r]=e;if(s<=r){const e=s+Math.floor((r-s)/2),n=this.add(h[e],null==o?void 0:o[e]);i.push(n),t.push([e+1,r]),t.push([s,e-1])}}}})(),i}get(t,e=this._defaultCallbackByKey){var s;return null!==(s=this.getNodes(t,e,!0)[0])&&void 0!==s?s:null}lastKey(){var t,e,s,i,r,n;return this._compare(0,1)===q.lt?null!==(e=null===(t=this.getRightMost())||void 0===t?void 0:t.key)&&void 0!==e?e:0:this._compare(0,1)===q.gt?null!==(i=null===(s=this.getLeftMost())||void 0===s?void 0:s.key)&&void 0!==i?i:0:null!==(n=null===(r=this.getRightMost())||void 0===r?void 0:r.key)&&void 0!==n?n:0}getNodes(t,e=this._defaultCallbackByKey,s=!1,i=this.root){if(!i)return[];const r=[];if(this.loopType===K.RECURSIVE){const n=i=>{e(i)===t&&(r.push(i),s)||(i.left||i.right)&&(e===this._defaultCallbackByKey?(this._compare(i.key,t)===q.gt&&i.left&&n(i.left),this._compare(i.key,t)===q.lt&&i.right&&n(i.right)):(i.left&&n(i.left),i.right&&n(i.right)))};n(i)}else{const n=new v([i]);for(;n.size>0;){const i=n.shift();if(i){if(e(i)===t&&(r.push(i),s))return r;e===this._defaultCallbackByKey?(this._compare(i.key,t)===q.gt&&i.left&&n.push(i.left),this._compare(i.key,t)===q.lt&&i.right&&n.push(i.right)):(i.left&&n.push(i.left),i.right&&n.push(i.right))}}}return r}lesserOrGreaterTraverse(t=this._defaultCallbackByKey,e=q.lt,s){"number"==typeof s&&(s=this.get(s));const i=[];if(!s)return[];const r=s.key;if(!this.root)return!1;if(this.loopType===K.RECURSIVE){const s=n=>{this._compare(n.key,r)===e&&i.push(t(n)),(n.left||n.right)&&(n.left&&this._compare(n.left.key,r)===e&&s(n.left),n.right&&this._compare(n.right.key,r)===e&&s(n.right))};return s(this.root),!0}{const s=new v([this.root]);for(;s.size>0;){const n=s.shift();n&&(this._compare(n.key,r)===e&&i.push(t(n)),n.left&&this._compare(n.left.key,r)===e&&s.push(n.left),n.right&&this._compare(n.right.key,r)===e&&s.push(n.right))}return i}}perfectlyBalance(){const t=this.dfs((t=>t),"in"),e=t.length;if(this.clear(),t.length<1)return!1;if(this.loopType===K.RECURSIVE){const s=(e,i)=>{if(e>i)return;const r=e+Math.floor((i-e)/2),n=t[r];this.add(n.key,n.val),s(e,r-1),s(r+1,i)};return s(0,e-1),!0}{const s=[[0,e-1]];for(;s.length>0;){const e=s.pop();if(e){const[i,r]=e;if(i<=r){const e=i+Math.floor((r-i)/2),n=t[e];this.add(n.key,n.val),s.push([e+1,r]),s.push([i,e-1])}}}return!0}}isAVLBalanced(){var t,e;if(!this.root)return!0;let s=!0;if(this.loopType===K.RECURSIVE){const t=e=>{if(!e)return 0;const i=t(e.left),r=t(e.right);return Math.abs(i-r)>1&&(s=!1),Math.max(i,r)+1};t(this.root)}else{const s=[];let i=this.root,r=null;const n=new Map;for(;s.length>0||i;)if(i)s.push(i),i=i.left;else if(i=s[s.length-1],i.right&&r!==i.right)i=i.right;else if(i=s.pop(),i){const s=i.left&&null!==(t=n.get(i.left))&&void 0!==t?t:-1,h=i.right&&null!==(e=n.get(i.right))&&void 0!==e?e:-1;if(Math.abs(s-h)>1)return!1;n.set(i,1+Math.max(s,h)),r=i,i=null}}return s}_compare(t,e){const s=this._comparator(t,e);return s>0?q.gt:s<0?q.lt:q.eq}}class ${constructor(t){this._sumTree=new Array(t+1).fill(0)}get sumTree(){return this._sumTree}static lowBit(t){return t&-t}update(t,e){for(;t<this._sumTree.length;)this._sumTree[t]+=e,t+=$.lowBit(t)}getPrefixSum(t){let e=0;for(;t>0;)e+=this._sumTree[t],t-=$.lowBit(t);return e}getRangeSum(t,e){if(!(0<=t&&t<=e&&e<=this._sumTree.length))throw"Index out of bounds";return this.getPrefixSum(e)-this.getPrefixSum(t)}_setSumTree(t){this._sumTree=t}}class tt{constructor(t,e,s,i){this._start=0,this._end=0,this._val=null,this._sum=0,this._left=null,this._right=null,this._start=t,this._end=e,this._sum=s,this._val=i||null}get start(){return this._start}set start(t){this._start=t}get end(){return this._end}set end(t){this._end=t}get val(){return this._val}set val(t){this._val=t}get sum(){return this._sum}set sum(t){this._sum=t}get left(){return this._left}set left(t){this._left=t}get right(){return this._right}set right(t){this._right=t}}class et{constructor(t,e,s){this._values=[],this._start=0,e=e||0,s=s||t.length-1,this._values=t,this._start=e,this._end=s,t.length>0?this._root=this.build(e,s):(this._root=null,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(t,e){if(t>e)return new tt(t,e,0);if(t===e)return new tt(t,e,this._values[t]);const s=t+Math.floor((e-t)/2),i=this.build(t,s),r=this.build(s+1,e),n=new tt(t,e,i.sum+r.sum);return n.left=i,n.right=r,n}updateNode(t,e,s){const i=this.root||null;if(!i)return;const r=(t,e,s,i)=>{if(t.start===t.end&&t.start===e)return t.sum=s,void(void 0!==i&&(t.val=i));e<=t.start+Math.floor((t.end-t.start)/2)?t.left&&r(t.left,e,s,i):t.right&&r(t.right,e,s,i),t.left&&t.right&&(t.sum=t.left.sum+t.right.sum)};r(i,t,e,s)}querySumByRange(t,e){const s=this.root||null;if(!s)return 0;if(t<0||e>=this.values.length||t>e)return NaN;const i=(t,e,s)=>{if(e<=t.start&&s>=t.end)return t.sum;const r=t.start+Math.floor((t.end-t.start)/2);if(s<=r)return t.left?i(t.left,e,s):NaN;if(e>r)return t.right?i(t.right,e,s):NaN;{let n=0,h=0;return t.left&&(n=i(t.left,e,r)),t.right&&(h=i(t.right,r+1,s)),n+h}};return i(s,t,e)}_setValues(t){this._values=t}_setStart(t){this._start=t}_setEnd(t){this._end=t}_setRoot(t){this._root=t}}class st extends X{constructor(t,e){super(t,e),this.height=0}}class it extends Z{constructor(t){super(t)}_swap(t,e){const{key:s,val:i,height:r}=e,n=this.createNode(s,i);return n&&(n.height=r,e.key=t.key,e.val=t.val,e.height=t.height,t.key=n.key,t.val=n.val,t.height=n.height),e}createNode(t,e){return new st(t,e)}add(t,e){const s=super.add(t,e);return s&&this._balancePath(s),s}delete(t){const e=super.delete(t);for(const{needBalanced:t}of e)t&&this._balancePath(t);return e}_balanceFactor(t){return t.right?t.left?t.right.height-t.left.height:+t.height:-t.height}_updateHeight(t){if(t.left||t.right)if(t.left)t.right?t.height=1+Math.max(t.right.height,t.left.height):t.height=1+t.left.height;else{const e=t.right?t.right.height:0;t.height=1+e}else t.height=0}_balancePath(t){const e=this.getPathToRoot(t,!1);for(let t=0;t<e.length;t++){const s=e[t];switch(this._updateHeight(s),this._balanceFactor(s)){case-2:s&&s.left&&(this._balanceFactor(s.left)<=0?this._balanceLL(s):this._balanceLR(s));break;case 2:s&&s.right&&(this._balanceFactor(s.right)>=0?this._balanceRR(s):this._balanceRL(s))}}}_balanceLL(t){const e=t.parent,s=t.left;t.parent=s,s&&s.right&&(s.right.parent=t),s&&(s.parent=e),t===this.root?s&&this._setRoot(s):(null==e?void 0:e.left)===t?e.left=s:e&&(e.right=s),s&&(t.left=s.right,s.right=t),this._updateHeight(t),s&&this._updateHeight(s)}_balanceLR(t){const e=t.parent,s=t.left;let i=null;s&&(i=s.right),t&&(t.parent=i),s&&(s.parent=i),i&&(i.left&&(i.left.parent=s),i.right&&(i.right.parent=t),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.left=i.right,s&&(s.right=i.left),i.left=s,i.right=t),this._updateHeight(t),s&&this._updateHeight(s),i&&this._updateHeight(i)}_balanceRR(t){const e=t.parent,s=t.right;t.parent=s,s&&(s.left&&(s.left.parent=t),s.parent=e),t===this.root?s&&this._setRoot(s):e&&(e.left===t?e.left=s:e.right=s),s&&(t.right=s.left,s.left=t),this._updateHeight(t),s&&this._updateHeight(s)}_balanceRL(t){const e=t.parent,s=t.right;let i=null;s&&(i=s.left),t.parent=i,s&&(s.parent=i),i&&(i.left&&(i.left.parent=t),i.right&&(i.right.parent=s),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.right=i.left),s&&i&&(s.left=i.right),i&&(i.left=t),i&&(i.right=s),this._updateHeight(t),s&&this._updateHeight(s),i&&this._updateHeight(i)}}class rt extends X{constructor(t,e){super(t,e),this._color=W.RED}get color(){return this._color}set color(t){this._color=t}}class nt extends Z{constructor(t){super(t)}createNode(t,e){return new rt(t,e)}}class ht extends st{constructor(t,e,s=1){super(t,e),this.count=s}}class ot extends it{constructor(t){super(t),this._count=0}get count(){return this._count}createNode(t,e,s){return new ht(t,e,s)}_swap(t,e){const{key:s,val:i,count:r,height:n}=e,h=this.createNode(s,i,r);return h&&(h.height=n,e.key=t.key,e.val=t.val,e.count=t.count,e.height=t.height,t.key=h.key,t.val=h.val,t.count=h.count,t.height=h.height),e}add(t,e,s=1){let i,r;if(r=t instanceof ht?this.createNode(t.key,t.val,t.count):null===t?null:this.createNode(t,e,s),this.root){let t=this.root,e=!0;for(;e;)t?r&&(this._compare(t.key,r.key)===q.eq?(t.val=r.val,t.count+=r.count,this._setCount(this.count+r.count),e=!1,i=t):this._compare(t.key,r.key)===q.gt?void 0===t.left?(t.left=r,this._setSize(this.size+1),this._setCount(this.count+r.count),e=!1,i=t.left):t.left&&(t=t.left):this._compare(t.key,r.key)===q.lt&&(void 0===t.right?(t.right=r,this._setSize(this.size+1),this._setCount(this.count+r.count),e=!1,i=t.right):t.right&&(t=t.right))):e=!1}else this._setRoot(r),this._setSize(this.size+1),r&&this._setCount(this.count+r.count),i=this.root;return i&&this._balancePath(i),i}_addTo(t,e){return e?void 0===e.left?(e.left=t,null!==t&&(this._setSize(this.size+1),this._setCount(this.count+t.count)),e.left):void 0===e.right?(e.right=t,null!==t&&(this._setSize(this.size+1),this._setCount(this.count+t.count)),e.right):void 0:void 0}addMany(t,e){const s=[];for(let i=0;i<t.length;i++){const r=t[i];r instanceof ht?s.push(this.add(r.key,r.val,r.count)):null!==r?s.push(this.add(r,null==e?void 0:e[i],1)):s.push(this.add(NaN,null,0))}return s}perfectlyBalance(){const t=this.dfs((t=>t),"in"),e=t.length;if(t.length<1)return!1;if(this.clear(),this.loopType===K.RECURSIVE){const s=(e,i)=>{if(e>i)return;const r=e+Math.floor((i-e)/2),n=t[r];this.add(n.key,n.val,n.count),s(e,r-1),s(r+1,i)};return s(0,e-1),!0}{const s=[[0,e-1]];for(;s.length>0;){const e=s.pop();if(e){const[i,r]=e;if(i<=r){const e=i+Math.floor((r-i)/2),n=t[e];this.add(n.key,n.val,n.count),s.push([e+1,r]),s.push([i,e-1])}}}return!0}}delete(t,e=!1){const s=[];if(!this.root)return s;const i=this.get(t);if(!i)return s;const r=(null==i?void 0:i.parent)?i.parent:null;let n=null,h=i;if(i.count>1&&!e)i.count--,this._setCount(this.count-1);else{if(i.left){const t=i.left?this.getRightMost(i.left):null;if(t){const e=t.parent;h=this._swap(i,t),e&&(e.right===t?e.right=t.left:e.left=t.left,n=e)}}else if(r){const{familyPosition:t}=i;t===G.LEFT||t===G.ROOT_LEFT?r.left=i.right:t!==G.RIGHT&&t!==G.ROOT_RIGHT||(r.right=i.right),n=r}else void 0!==i.right&&this._setRoot(i.right);this._setSize(this.size-1),this._setCount(this.count-h.count)}return s.push({deleted:h,needBalanced:n}),n&&this._balancePath(n),s}clear(){super.clear(),this._setCount(0)}_setCount(t){this._count=t}}class lt{constructor(t,e,s){this._key=t,this._value=e||void 0,this._children=s||[]}get key(){return this._key}set key(t){this._key=t}get value(){return this._value}set value(t){this._value=t}get children(){return this._children}set children(t){this._children=t}addChildren(t){this.children||(this.children=[]),t instanceof lt?this.children.push(t):this.children=this.children.concat(t)}getHeight(){let t=0;if(this){const e=(s,i)=>{i>t&&(t=i);const{children:r}=s;if(r)for(let t=0,s=r.length;t<s;t++)e(r[t],i+1)};e(this,0)}return t}}class at extends z{constructor(t=((t,e)=>{if("number"!=typeof t||"number"!=typeof e)throw new Error("The a, b params of compare function must be number");return e-t})){super(t)}}class ut extends z{constructor(t=((t,e)=>{if("number"!=typeof t||"number"!=typeof e)throw new Error("The a, b params of compare function must be number");return t-e})){super(t)}}class ct extends A{constructor(t=((t,e)=>{if("number"!=typeof t||"number"!=typeof e)throw new Error("The a, b params of compare function must be number");return t-e})){super(t)}}class dt extends A{constructor(t=((t,e)=>{if("number"!=typeof t||"number"!=typeof e)throw new Error("The a, b params of compare function must be number");return e-t})){super(t)}}class ft{constructor(t){const{row:e,col:s,initialVal:i}=t;this._matrix=new Array(e).fill(void 0).map((()=>new Array(s).fill(i||0)))}toArray(){return this._matrix}}class gt{constructor(t=0,e=0,s=1){this.x=t,this.y=e,this.w=s}get isZero(){return 0===this.x&&0===this.y}get length(){return Math.sqrt(this.x*this.x+this.y*this.y)}get lengthSq(){return this.x*this.x+this.y*this.y}get rounded(){return new gt(Math.round(this.x),Math.round(this.y))}static add(t,e){return new gt(t.x+e.x,t.y+e.y)}static subtract(t,e){return new gt(t.x-e.x,t.y-e.y)}static subtractValue(t,e){return new gt(t.x-e,t.y-e)}static multiply(t,e){return new gt(t.x*e,t.y*e)}static divide(t,e){return new gt(t.x/e,t.y/e)}static equals(t,e){return t.x===e.x&&t.y===e.y}static equalsRounded(t,e,s=12){const i=gt.abs(gt.subtract(t,e));return i.x<s&&i.y<s}static normalize(t){const e=t.length;return e>2220446049250313e-31?gt.divide(t,e):t}static truncate(t,e){return t.length>e?gt.multiply(gt.normalize(t),e):t}static perp(t){return new gt(-t.y,t.x)}static reverse(t){return new gt(-t.x,-t.y)}static abs(t){return new gt(Math.abs(t.x),Math.abs(t.y))}static dot(t,e){return t.x*e.x+t.y*e.y}static distance(t,e){const s=e.y-t.y,i=e.x-t.x;return Math.sqrt(s*s+i*i)}static distanceSq(t,e){const s=e.y-t.y,i=e.x-t.x;return s*s+i*i}static sign(t,e){return t.y*e.x>t.x*e.y?-1:1}static angle(t){const e=new gt(0,-1),s=Math.acos(gt.dot(t,e)/(t.length*e.length));return 1===gt.sign(t,e)?2*Math.PI-s:s}static random(t,e){const s=Math.floor(Math.random()*t-t/2),i=Math.floor(Math.random()*e-e/2);return new gt(s,i)}zero(){this.x=0,this.y=0}}const _t=gt;class pt{constructor(t){void 0===t?this._matrix=pt.identity:t instanceof _t?(this._matrix=pt.identity,this._matrix[0][0]=t.x,this._matrix[1][0]=t.y,this._matrix[2][0]=t.w):this._matrix=t}static get empty(){return[[],[],[]]}static get identity(){return[[1,0,0],[0,1,0],[0,0,1]]}get m(){return this._matrix}toVector(){return new _t(this._matrix[0][0],this._matrix[1][0])}static add(t,e){const s=pt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]+e.m[i][r];return new pt(s)}static subtract(t,e){const s=pt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]-e.m[i][r];return new pt(s)}static multiply(t,e){const s=pt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++){s[i][r]=0;for(let n=0;n<3;n++)s[i][r]+=t.m[i][n]*e.m[n][r]}return new pt(s)}static multiplyByValue(t,e){const s=pt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]*e;return new pt(s)}static multiplyByVector(t,e){return pt.multiply(t,new pt(e)).toVector()}static view(t,e){const s=t/2,i=e/2,r=Math.cos(Math.PI);return new pt([[1,0,s],[0,1*r,i],[0,0,1]])}static scale(t){return pt.multiplyByValue(new pt,t)}static rotate(t){const e=Math.cos(t),s=Math.sin(t);return new pt([[e,-s,0],[s,e,0],[0,0,1]])}static translate(t){return new pt([[1,0,t.x],[0,1,t.y],[0,0,t.w]])}}class vt{constructor(t,e){this.direction=t,this.turn=()=>new vt(e[t],e)}}class yt{constructor({matrix:t,turning:e,onMove:s,init:{cur:i,charDir:r,VISITED:n}}){this._matrix=t,this._cur=i,this._character=new vt(r,e),this.onMove=s,this.onMove&&this.onMove(this._cur),this._VISITED=n,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){const{direction:t}=this._character;this.check(t)?this.move(t):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(t){let e,s;const i=this._matrix,[r,n]=this._cur;switch(t){case"up":if(s=i[r-1],!s)return!1;e=s[n];break;case"right":e=i[r][n+1];break;case"down":if(s=i[r+1],!s)return!1;e=s[n];break;case"left":e=i[r][n-1]}return void 0!==e&&e!==this._VISITED}move(t){switch(t){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--}const[e,s]=this._cur;this._matrix[e][s]=this._VISITED,this.onMove&&this.onMove(this._cur)}}class mt{constructor(t){this._key=t,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(t){this._key=t}get children(){return this._children}set children(t){this._children=t}get isEnd(){return this._isEnd}set isEnd(t){this._isEnd=t}}class xt{constructor(t,e=!0){if(this._root=new mt(""),this._caseSensitive=e,t)for(const e of t)this.add(e)}get root(){return this._root}set root(t){this._root=t}add(t){t=this._caseProcess(t);let e=this.root;for(const s of t){let t=e.children.get(s);t||(t=new mt(s),e.children.set(s,t)),e=t}return e.isEnd=!0,!0}has(t){t=this._caseProcess(t);let e=this.root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return e.isEnd}_caseProcess(t){return this._caseSensitive||(t=t.toLowerCase()),t}delete(t){t=this._caseProcess(t);let e=!1;const s=(i,r)=>{const n=t[r],h=i.children.get(n);return!!h&&(r===t.length-1?!!h.isEnd&&(h.children.size>0?h.isEnd=!1:i.children.delete(n),e=!0,!0):!(!s(h,r+1)||i.isEnd||0!==h.children.size||(i.children.delete(n),0)))};return s(this.root,0),e}getHeight(){const t=this.root;let e=0;if(t){const s=(t,i)=>{i>e&&(e=i);const{children:r}=t;if(r)for(const t of r.entries())s(t[1],i+1)};s(t,0)}return e}hasPurePrefix(t){t=this._caseProcess(t);let e=this.root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return!e.isEnd}hasPrefix(t){t=this._caseProcess(t);let e=this.root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return!0}hasCommonPrefix(t){t=this._caseProcess(t);let e="";const s=i=>{e+=i.key,e!==t&&(i.isEnd||i&&i.children&&1===i.children.size&&s(Array.from(i.children.values())[0]))};return s(this.root),e===t}getLongestCommonPrefix(){let t="";const e=s=>{t+=s.key,s.isEnd||s&&s.children&&1===s.children.size&&e(Array.from(s.children.values())[0])};return e(this.root),t}getWords(t="",e=Number.MAX_SAFE_INTEGER){t=this._caseProcess(t);const s=[];let i=0,r=this.root;if(t)for(const e of t){const t=r.children.get(e);t&&(r=t)}return r!==this.root&&function t(r,n){for(const e of r.children.keys()){const s=r.children.get(e);void 0!==s&&t(s,n.concat(e))}if(r.isEnd){if(i>e-1)return;s.push(n),i++}}(r,t),s}}return e})()));
|
|
3
3
|
//# sourceMappingURL=bundle.min.js.map
|