data-structure-typed 1.3.0 → 1.3.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/README.md CHANGED
@@ -371,55 +371,103 @@ import {UndirectedGraph} from 'data-structure-typed';
371
371
  </tbody>
372
372
  </table>
373
373
 
374
- ## API docs
375
- <ul>
376
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html" rel="nofollow"><span>AVLTree</span></a></li>
377
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTreeNode.html" rel="nofollow"><span>AVLTreeNode</span></a></li>
378
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractEdge.html" rel="nofollow"><span>AbstractEdge</span></a></li>
379
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html" rel="nofollow"><span>AbstractGraph</span></a></li>
380
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractVertex.html" rel="nofollow"><span>AbstractVertex</span></a></li>
381
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html" rel="nofollow"><span>ArrayDeque</span></a></li>
382
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html" rel="nofollow"><span>BST</span></a></li>
383
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BSTNode.html" rel="nofollow"><span>BSTNode</span></a></li>
384
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html" rel="nofollow"><span>BinaryIndexedTree</span></a></li>
385
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html" rel="nofollow"><span>BinaryTree</span></a></li>
386
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTreeNode.html" rel="nofollow"><span>BinaryTreeNode</span></a></li>
387
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Character.html" rel="nofollow"><span>Character</span></a></li>
388
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateMap.html" rel="nofollow"><span>CoordinateMap</span></a></li>
389
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateSet.html" rel="nofollow"><span>CoordinateSet</span></a></li>
390
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Deque.html" rel="nofollow"><span>Deque</span></a></li>
391
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedEdge.html" rel="nofollow"><span>DirectedEdge</span></a></li>
392
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedGraph.html" rel="nofollow"><span>DirectedGraph</span></a></li>
393
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedVertex.html" rel="nofollow"><span>DirectedVertex</span></a></li>
394
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedList.html" rel="nofollow"><span>DoublyLinkedList</span></a></li>
395
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedListNode.html" rel="nofollow"><span>DoublyLinkedListNode</span></a></li>
396
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Heap.html" rel="nofollow"><span>Heap</span></a></li>
397
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Matrix2D.html" rel="nofollow"><span>Matrix2D</span></a></li>
398
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MatrixNTI2D.html" rel="nofollow"><span>MatrixNTI2D</span></a></li>
399
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxHeap.html" rel="nofollow"><span>MaxHeap</span></a></li>
400
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxPriorityQueue.html" rel="nofollow"><span>MaxPriorityQueue</span></a></li>
401
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MinHeap.html" rel="nofollow"><span>MinHeap</span></a></li>
402
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MinPriorityQueue.html" rel="nofollow"><span>MinPriorityQueue</span></a></li>
403
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Navigator.html" rel="nofollow"><span>Navigator</span></a></li>
404
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html" rel="nofollow"><span>ObjectDeque</span></a></li>
405
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html" rel="nofollow"><span>PriorityQueue</span></a></li>
406
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html" rel="nofollow"><span>Queue</span></a></li>
407
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html" rel="nofollow"><span>SegmentTree</span></a></li>
408
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTreeNode.html" rel="nofollow"><span>SegmentTreeNode</span></a></li>
409
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html" rel="nofollow"><span>SinglyLinkedList</span></a></li>
410
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedListNode.html" rel="nofollow"><span>SinglyLinkedListNode</span></a></li>
411
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html" rel="nofollow"><span>Stack</span></a></li>
412
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiSet.html" rel="nofollow"><span>TreeMultiSet</span></a></li>
413
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html" rel="nofollow"><span>Trie</span></a></li>
414
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/TrieNode.html" rel="nofollow"><span>TrieNode</span></a></li>
415
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedEdge.html" rel="nofollow"><span>UndirectedEdge</span></a></li>
416
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html" rel="nofollow"><span>UndirectedGraph</span></a></li>
417
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedVertex.html" rel="nofollow"><span>UndirectedVertex</span></a></li>
418
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Vector2D.html" rel="nofollow"><span>Vector2D</span></a></li>
419
- </ul>
374
+ [//]: # (## API docs)
375
+
376
+ [//]: # (<ul>)
377
+
378
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html" rel="nofollow"><span>AVLTree</span></a></li>)
379
+
380
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTreeNode.html" rel="nofollow"><span>AVLTreeNode</span></a></li>)
381
+
382
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractEdge.html" rel="nofollow"><span>AbstractEdge</span></a></li>)
383
+
384
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html" rel="nofollow"><span>AbstractGraph</span></a></li>)
385
+
386
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractVertex.html" rel="nofollow"><span>AbstractVertex</span></a></li>)
387
+
388
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html" rel="nofollow"><span>ArrayDeque</span></a></li>)
389
+
390
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html" rel="nofollow"><span>BST</span></a></li>)
391
+
392
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/BSTNode.html" rel="nofollow"><span>BSTNode</span></a></li>)
393
+
394
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html" rel="nofollow"><span>BinaryIndexedTree</span></a></li>)
395
+
396
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html" rel="nofollow"><span>BinaryTree</span></a></li>)
397
+
398
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTreeNode.html" rel="nofollow"><span>BinaryTreeNode</span></a></li>)
399
+
400
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/Character.html" rel="nofollow"><span>Character</span></a></li>)
401
+
402
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateMap.html" rel="nofollow"><span>CoordinateMap</span></a></li>)
403
+
404
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateSet.html" rel="nofollow"><span>CoordinateSet</span></a></li>)
405
+
406
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/Deque.html" rel="nofollow"><span>Deque</span></a></li>)
407
+
408
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedEdge.html" rel="nofollow"><span>DirectedEdge</span></a></li>)
409
+
410
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedGraph.html" rel="nofollow"><span>DirectedGraph</span></a></li>)
411
+
412
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedVertex.html" rel="nofollow"><span>DirectedVertex</span></a></li>)
413
+
414
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedList.html" rel="nofollow"><span>DoublyLinkedList</span></a></li>)
415
+
416
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedListNode.html" rel="nofollow"><span>DoublyLinkedListNode</span></a></li>)
417
+
418
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/Heap.html" rel="nofollow"><span>Heap</span></a></li>)
419
+
420
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/Matrix2D.html" rel="nofollow"><span>Matrix2D</span></a></li>)
421
+
422
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/MatrixNTI2D.html" rel="nofollow"><span>MatrixNTI2D</span></a></li>)
423
+
424
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxHeap.html" rel="nofollow"><span>MaxHeap</span></a></li>)
425
+
426
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxPriorityQueue.html" rel="nofollow"><span>MaxPriorityQueue</span></a></li>)
427
+
428
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/MinHeap.html" rel="nofollow"><span>MinHeap</span></a></li>)
429
+
430
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/MinPriorityQueue.html" rel="nofollow"><span>MinPriorityQueue</span></a></li>)
431
+
432
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/Navigator.html" rel="nofollow"><span>Navigator</span></a></li>)
433
+
434
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html" rel="nofollow"><span>ObjectDeque</span></a></li>)
435
+
436
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html" rel="nofollow"><span>PriorityQueue</span></a></li>)
437
+
438
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html" rel="nofollow"><span>Queue</span></a></li>)
439
+
440
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html" rel="nofollow"><span>SegmentTree</span></a></li>)
441
+
442
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTreeNode.html" rel="nofollow"><span>SegmentTreeNode</span></a></li>)
443
+
444
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html" rel="nofollow"><span>SinglyLinkedList</span></a></li>)
445
+
446
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedListNode.html" rel="nofollow"><span>SinglyLinkedListNode</span></a></li>)
447
+
448
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html" rel="nofollow"><span>Stack</span></a></li>)
449
+
450
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiSet.html" rel="nofollow"><span>TreeMultiSet</span></a></li>)
451
+
452
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html" rel="nofollow"><span>Trie</span></a></li>)
453
+
454
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/TrieNode.html" rel="nofollow"><span>TrieNode</span></a></li>)
455
+
456
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedEdge.html" rel="nofollow"><span>UndirectedEdge</span></a></li>)
457
+
458
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html" rel="nofollow"><span>UndirectedGraph</span></a></li>)
459
+
460
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedVertex.html" rel="nofollow"><span>UndirectedVertex</span></a></li>)
461
+
462
+ [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/Vector2D.html" rel="nofollow"><span>Vector2D</span></a></li>)
463
+
464
+ [//]: # (</ul>)
420
465
 
421
466
  # Why
422
467
 
468
+ ## Code design
469
+ By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the optimal approach to data structure design.
470
+
423
471
  ## Complexities
424
472
 
425
473
  ### performance of Big O
@@ -680,9 +728,6 @@ import {UndirectedGraph} from 'data-structure-typed';
680
728
  </tbody>
681
729
  </table>
682
730
 
683
- ## Code design
684
- By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the optimal approach to data structure design.
685
-
686
731
  [//]: # (![overview diagram]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/overview-diagram-of-data-structures.png?raw=true&#41;)
687
732
 
688
733
  ![complexities](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/complexities-diff.jpg?raw=true)
package/dist/bundle.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see bundle.js.LICENSE.txt */
2
- (()=>{"use strict";var t={1925:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AaTree=void 0,e.AaTree=class{}},6279:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AbstractBinaryTree=e.AbstractBinaryTreeNode=void 0;const r=i(5928),s=i(1230);class n{constructor(t,e){this._height=0,this._id=t,this._val=e}get id(){return this._id}set id(t){this._id=t}get val(){return this._val}set val(t){this._val=t}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get parent(){return this._parent}set parent(t){this._parent=t}get height(){return this._height}set height(t){this._height=t}get familyPosition(){const t=this;return t.parent?t.parent.left===t?t.left||t.right?s.FamilyPosition.ROOT_LEFT:s.FamilyPosition.LEFT:t.parent.right===t?t.left||t.right?s.FamilyPosition.ROOT_RIGHT:s.FamilyPosition.RIGHT:s.FamilyPosition.MAL_NODE:t.left||t.right?s.FamilyPosition.ROOT:s.FamilyPosition.ISOLATED}}e.AbstractBinaryTreeNode=n,e.AbstractBinaryTree=class{constructor(t){if(this._root=null,this._size=0,this._loopType=s.LoopType.ITERATIVE,this._visitedId=[],this._visitedVal=[],this._visitedNode=[],this._visitedLeftSum=[],void 0!==t){const{loopType:e=s.LoopType.ITERATIVE}=t;this._loopType=e}this.clear()}get root(){return this._root}get size(){return this._size}get loopType(){return this._loopType}get visitedId(){return this._visitedId}get visitedVal(){return this._visitedVal}get visitedNode(){return this._visitedNode}get visitedLeftSum(){return this._visitedLeftSum}swapLocation(t,e){const{id:i,val:r,height:s}=e,n=this.createNode(i,r);return n&&(n.height=s,e.id=t.id,e.val=t.val,e.height=t.height,t.id=n.id,t.val=n.val,t.height=n.height),e}clear(){this._root=null,this._size=0,this._clearResults()}isEmpty(){return 0===this.size}add(t,e){let i,r;if(null===t)r=null;else if("number"==typeof t)r=this.createNode(t,e);else{if(!(t instanceof n))return;r=t}const s=t?this.get(t,"id"):void 0;return this.root?s?(s.val=e,i=s):i=((t,e)=>{const i=[t];for(;i.length>0;){const t=i.shift();if(!t)return;{if(e&&t.id===e.id)return;const r=this._addTo(e,t);if(void 0!==r)return r;t.left&&i.push(t.left),t.right&&i.push(t.right)}}})(this.root,r):(this._setRoot(r),null!==r?this._setSize(1):this._setSize(0),i=this.root),i}addMany(t,e){var i;const r=[],s=new Map;for(const e of t)s.set(e,(null!==(i=s.get(e))&&void 0!==i?i:0)+1);for(let i=0;i<t.length;i++){const o=t[i];if(s.has(o)){if(o instanceof n){r.push(this.add(o.id,o.val));continue}if(null===o){r.push(this.add(null));continue}const t=null==e?void 0:e[i];r.push(this.add(o,t)),s.delete(o)}}return r}fill(t,e){return this.clear(),t.length===this.addMany(t,e).length}remove(t,e){const i=[];if(!this.root)return i;const r="number"==typeof t?this.get(t):t;if(!r)return i;const n=(null==r?void 0:r.parent)?r.parent:null;let o=null,h=r;if(r.left){const t=r.left?this.getRightMost(r.left):null;if(t){const e=t.parent;h=this.swapLocation(r,t),e&&(e.right===t?e.right=t.left:e.left=t.left,o=e)}}else if(n){const{familyPosition:t}=r;t===s.FamilyPosition.LEFT||t===s.FamilyPosition.ROOT_LEFT?n.left=r.right:t!==s.FamilyPosition.RIGHT&&t!==s.FamilyPosition.ROOT_RIGHT||(n.right=r.right),o=n}else void 0!==r.right&&this._setRoot(r.right);return this._setSize(this.size-1),i.push({deleted:h,needBalanced:o}),i}getDepth(t){"number"==typeof t&&(t=this.get(t,"id"));let e=0;for(;null==t?void 0:t.parent;)e++,t=t.parent;return e}getHeight(t){if("number"==typeof(t=null!=t?t:this.root)&&(t=this.get(t,"id")),!t)return-1;if(this._loopType===s.LoopType.RECURSIVE){const e=t=>{if(!t)return-1;const i=e(t.left),r=e(t.right);return Math.max(i,r)+1};return e(t)}{if(!t)return-1;const e=[{node:t,depth:0}];let i=0;for(;e.length>0;){const{node:t,depth:r}=e.pop();t.left&&e.push({node:t.left,depth:r+1}),t.right&&e.push({node:t.right,depth:r+1}),i=Math.max(i,r)}return i}}getMinHeight(t){var e,i,r;if(!(t=t||this.root))return-1;if(this._loopType===s.LoopType.RECURSIVE){const e=t=>{if(!t)return 0;if(!t.left&&!t.right)return 0;const i=e(t.left),r=e(t.right);return Math.min(i,r)+1};return e(t)}{const s=[];let n=t,o=null;const h=new Map;for(;s.length>0||n;)if(n)s.push(n),n=n.left;else if(n=s[s.length-1],n.right&&o!==n.right)n=n.right;else if(n=s.pop(),n){const t=n.left&&null!==(e=h.get(n.left))&&void 0!==e?e:-1,r=n.right&&null!==(i=h.get(n.right))&&void 0!==i?i:-1;h.set(n,1+Math.min(t,r)),o=n,n=null}return null!==(r=h.get(t))&&void 0!==r?r:-1}}isPerfectlyBalanced(t){return this.getMinHeight(t)+1>=this.getHeight(t)}getNodes(t,e,i){if(!this.root)return[];e=null!=e?e:"id";const r=[];if(this.loopType===s.LoopType.RECURSIVE){const s=n=>{this._pushByPropertyNameStopOrNot(n,r,t,e,i)||(n.left||n.right)&&(n.left&&s(n.left),n.right&&s(n.right))};s(this.root)}else{const s=[this.root];for(;s.length>0;){const n=s.shift();if(n){if(this._pushByPropertyNameStopOrNot(n,r,t,e,i))return r;n.left&&s.push(n.left),n.right&&s.push(n.right)}}}return r}has(t,e){return e=null!=e?e:"id",this.getNodes(t,e).length>0}get(t,e){var i;return e=null!=e?e:"id",null!==(i=this.getNodes(t,e,!0)[0])&&void 0!==i?i:null}getPathToRoot(t){const e=[];for(;t.parent;)e.unshift(t),t=t.parent;return e.unshift(t),e}getLeftMost(t){if("number"==typeof t&&(t=this.get(t,"id")),!(t=null!=t?t:this.root))return t;if(this._loopType===s.LoopType.RECURSIVE){const e=t=>t.left?e(t.left):t;return e(t)}{const e=(0,r.trampoline)((t=>t.left?e.cont(t.left):t));return e(t)}}getRightMost(t){if(!(t=null!=t?t:this.root))return t;if(this._loopType===s.LoopType.RECURSIVE){const e=t=>t.right?e(t.right):t;return e(t)}{const e=(0,r.trampoline)((t=>t.right?e.cont(t.right):t));return e(t)}}isSubtreeBST(t){if(!t)return!0;if(this._loopType===s.LoopType.RECURSIVE){const e=(t,i,r)=>!t||!(t.id<=i||t.id>=r)&&e(t.left,i,t.id)&&e(t.right,t.id,r);return e(t,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER)}{const e=[];let i=Number.MIN_SAFE_INTEGER,r=t;for(;r||e.length>0;){for(;r;)e.push(r),r=r.left;if(r=e.pop(),!r||i>=r.id)return!1;i=r.id,r=r.right}return!0}}isBST(){return this.isSubtreeBST(this.root)}getSubTreeSize(t){let e=0;if(!t)return e;if(this._loopType===s.LoopType.RECURSIVE){const i=t=>{e++,t.left&&i(t.left),t.right&&i(t.right)};return i(t),e}{const i=[t];for(;i.length>0;){const t=i.pop();e++,t.right&&i.push(t.right),t.left&&i.push(t.left)}return e}}subTreeSum(t,e){if(e=null!=e?e:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return 0;let i=0;const r=t=>{let i;switch(e){case"id":default:i=t.id;break;case"val":i="number"==typeof t.val?t.val:0}return i};if(this._loopType===s.LoopType.RECURSIVE){const e=t=>{i+=r(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();i+=r(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return i}subTreeAdd(t,e,i){if(i=null!=i?i:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const r=t=>{t.id+=e};if(this._loopType===s.LoopType.RECURSIVE){const e=t=>{r(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();r(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return!0}BFS(t){t=null!=t?t:"id",this._clearResults();const e=[this.root];for(;0!==e.length;){const i=e.shift();i&&(this._accumulatedByPropertyName(i,t),null!==(null==i?void 0:i.left)&&e.push(i.left),null!==(null==i?void 0:i.right)&&e.push(i.right))}return this._getResultByPropertyName(t)}DFS(t,e){t=null!=t?t:"in",e=null!=e?e:"id",this._clearResults();const i=r=>{switch(t){case"in":r.left&&i(r.left),this._accumulatedByPropertyName(r,e),r.right&&i(r.right);break;case"pre":this._accumulatedByPropertyName(r,e),r.left&&i(r.left),r.right&&i(r.right);break;case"post":r.left&&i(r.left),r.right&&i(r.right),this._accumulatedByPropertyName(r,e)}};return this.root&&i(this.root),this._getResultByPropertyName(e)}DFSIterative(t,e){if(t=t||"in",e=e||"id",this._clearResults(),!this.root)return this._getResultByPropertyName(e);const i=[{opt:0,node:this.root}];for(;i.length>0;){const r=i.pop();if(r&&r.node)if(1===r.opt)this._accumulatedByPropertyName(r.node,e);else switch(t){case"in":default:i.push({opt:0,node:r.node.right}),i.push({opt:1,node:r.node}),i.push({opt:0,node:r.node.left});break;case"pre":i.push({opt:0,node:r.node.right}),i.push({opt:0,node:r.node.left}),i.push({opt:1,node:r.node});break;case"post":i.push({opt:1,node:r.node}),i.push({opt:0,node:r.node.right}),i.push({opt:0,node:r.node.left})}}return this._getResultByPropertyName(e)}levelIterative(t,e){if(e=e||"id",!(t=t||this.root))return[];this._clearResults();const i=[t];for(;i.length>0;){const t=i.shift();t&&(this._accumulatedByPropertyName(t,e),t.left&&i.push(t.left),t.right&&i.push(t.right))}return this._getResultByPropertyName(e)}listLevels(t,e){if(e=e||"id",!(t=t||this.root))return[];const i=[],r=(t,r)=>{switch(e){case"id":default:i[r].push(t.id);break;case"val":i[r].push(t.val);break;case"node":i[r].push(t)}};if(this.loopType===s.LoopType.RECURSIVE){const e=(t,s)=>{i[s]||(i[s]=[]),r(t,s),t.left&&e(t.left,s+1),t.right&&e(t.right,s+1)};e(t,0)}else{const e=[[t,0]];for(;e.length>0;){const t=e.pop(),[s,n]=t;i[n]||(i[n]=[]),r(s,n),s.right&&e.push([s.right,n+1]),s.left&&e.push([s.left,n+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,e){if(null===this.root)return[];t=t||"in",e=e||"id",this._clearResults();let i=this.root;const r=t=>{let e=null,i=null;for(;t;)i=t.right,t.right=e,e=t,t=i;return e},s=t=>{const i=r(t);let s=i;for(;s;)this._accumulatedByPropertyName(s,e),s=s.right;r(i)};switch(t){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}this._accumulatedByPropertyName(i,e),i=i.right}break;case"pre":for(;i;){if(i.left){const t=this.getPredecessor(i);if(!t.right){t.right=i,this._accumulatedByPropertyName(i,e),i=i.left;continue}t.right=null}else this._accumulatedByPropertyName(i,e);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,s(i.left)}i=i.right}s(this.root)}return this._getResultByPropertyName(e)}_addTo(t,e){return e?void 0===e.left?(e.left=t,t&&this._setSize(this.size+1),e.left):void 0===e.right?(e.right=t,t&&this._setSize(this.size+1),e.right):void 0:void 0}_setLoopType(t){this._loopType=t}_setVisitedId(t){this._visitedId=t}_setVisitedVal(t){this._visitedVal=t}_setVisitedNode(t){this._visitedNode=t}_setVisitedLeftSum(t){this._visitedLeftSum=t}_setRoot(t){t&&(t.parent=void 0),this._root=t}_setSize(t){this._size=t}_clearResults(){this._visitedId=[],this._visitedVal=[],this._visitedNode=[],this._visitedLeftSum=[]}_pushByPropertyNameStopOrNot(t,e,i,r,s){switch(r){case"id":default:if(t.id===i)return e.push(t),!!s;break;case"val":if(t.val===i)return e.push(t),!!s}}_accumulatedByPropertyName(t,e){switch(e=null!=e?e:"id"){case"id":default:this._visitedId.push(t.id);break;case"val":this._visitedVal.push(t.val);break;case"node":this._visitedNode.push(t)}}_getResultByPropertyName(t){switch(t=null!=t?t:"id"){case"id":default:return this._visitedId;case"val":return this._visitedVal;case"node":return this._visitedNode}}}},9993:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AVLTree=e.AVLTreeNode=void 0;const r=i(761);class s extends r.BSTNode{constructor(t,e){super(t,e)}}e.AVLTreeNode=s;class n extends r.BST{constructor(t){super(t)}createNode(t,e){return new s(t,e)}add(t,e){const i=super.add(t,e);return i&&this._balancePath(i),i}remove(t,e){const i=super.remove(t,e);for(const{needBalanced:t}of i)t&&this._balancePath(t);return i}_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);for(let t=e.length-1;t>=0;t--){const i=e[t];switch(this._updateHeight(i),this._balanceFactor(i)){case-2:i&&i.left&&(this._balanceFactor(i.left)<=0?this._balanceLL(i):this._balanceLR(i));break;case 2:i&&i.right&&(this._balanceFactor(i.right)>=0?this._balanceRR(i):this._balanceRL(i))}}}_balanceLL(t){const e=t.parent,i=t.left;t.parent=i,i&&i.right&&(i.right.parent=t),i&&(i.parent=e),t===this.root?i&&this._setRoot(i):(null==e?void 0:e.left)===t?e.left=i:e&&(e.right=i),i&&(t.left=i.right,i.right=t),this._updateHeight(t),i&&this._updateHeight(i)}_balanceLR(t){const e=t.parent,i=t.left;let r=null;i&&(r=i.right),t&&(t.parent=r),i&&(i.parent=r),r&&(r.left&&(r.left.parent=i),r.right&&(r.right.parent=t),r.parent=e),t===this.root?r&&this._setRoot(r):e&&(e.left===t?e.left=r:e.right=r),r&&(t.left=r.right,i&&(i.right=r.left),r.left=i,r.right=t),this._updateHeight(t),i&&this._updateHeight(i),r&&this._updateHeight(r)}_balanceRR(t){const e=t.parent,i=t.right;t.parent=i,i&&(i.left&&(i.left.parent=t),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.right=i.left,i.left=t),this._updateHeight(t),i&&this._updateHeight(i)}_balanceRL(t){const e=t.parent,i=t.right;let r=null;i&&(r=i.left),t.parent=r,i&&(i.parent=r),r&&(r.left&&(r.left.parent=t),r.right&&(r.right.parent=i),r.parent=e),t===this.root?r&&this._setRoot(r):e&&(e.left===t?e.left=r:e.right=r),r&&(t.right=r.left),i&&r&&(i.left=r.right),r&&(r.left=t),r&&(r.right=i),this._updateHeight(t),i&&this._updateHeight(i),r&&this._updateHeight(r)}}e.AVLTree=n},479:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BTree=void 0,e.BTree=class{}},9649:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BinaryIndexedTree=void 0;class i{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+=i.lowBit(t)}getPrefixSum(t){let e=0;for(;t>0;)e+=this._sumTree[t],t-=i.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}}e.BinaryIndexedTree=i},8021:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BinaryTree=e.BinaryTreeNode=void 0;const r=i(6279);class s extends r.AbstractBinaryTreeNode{constructor(t,e){super(t,e)}}e.BinaryTreeNode=s;class n extends r.AbstractBinaryTree{constructor(t){super(t)}createNode(t,e){return new s(t,e)}}e.BinaryTree=n},761:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BST=e.BSTNode=void 0;const r=i(1230),s=i(8021);class n extends s.BinaryTreeNode{constructor(t,e){super(t,e)}}e.BSTNode=n;class o extends s.BinaryTree{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 n(t,e)}add(t,e){let i=null;const s=this.createNode(t,e);if(null===this.root)this._setRoot(s),this._setSize(this.size+1),i=this.root;else{let e=this.root,n=!0;for(;n;)null!==e&&null!==s?this._compare(e.id,t)===r.CP.eq?(s&&(e.val=s.val),n=!1,i=e):this._compare(e.id,t)===r.CP.gt?void 0===e.left?(s&&(s.parent=e),e.left=s,this._setSize(this.size+1),n=!1,i=e.left):e.left&&(e=e.left):this._compare(e.id,t)===r.CP.lt&&(void 0===e.right?(s&&(s.parent=e),e.right=s,this._setSize(this.size+1),n=!1,i=e.right):e.right&&(e=e.right)):n=!1}return i}get(t,e){var i;return e=null!=e?e:"id",null!==(i=this.getNodes(t,e,!0)[0])&&void 0!==i?i:null}lastKey(){var t,e,i,s,n,o;return this._compare(0,1)===r.CP.lt?null!==(e=null===(t=this.getRightMost())||void 0===t?void 0:t.id)&&void 0!==e?e:0:this._compare(0,1)===r.CP.gt?null!==(s=null===(i=this.getLeftMost())||void 0===i?void 0:i.id)&&void 0!==s?s:0:null!==(o=null===(n=this.getRightMost())||void 0===n?void 0:n.id)&&void 0!==o?o:0}getNodes(t,e,i){if(e=null!=e?e:"id",!this.root)return[];const s=[];if(this.loopType===r.LoopType.RECURSIVE){const n=o=>{this._pushByPropertyNameStopOrNot(o,s,t,e,i)||(o.left||o.right)&&("id"===e?(this._compare(o.id,t)===r.CP.gt&&o.left&&n(o.left),this._compare(o.id,t)===r.CP.lt&&o.right&&n(o.right)):(o.left&&n(o.left),o.right&&n(o.right)))};n(this.root)}else{const n=[this.root];for(;n.length>0;){const o=n.shift();if(o){if(this._pushByPropertyNameStopOrNot(o,s,t,e,i))return s;"id"===e?(this._compare(o.id,t)===r.CP.gt&&o.left&&n.push(o.left),this._compare(o.id,t)===r.CP.lt&&o.right&&n.push(o.right)):(o.left&&n.push(o.left),o.right&&n.push(o.right))}}}return s}lesserSum(t,e){if(e=null!=e?e:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return 0;if(!this.root)return 0;const i=t.id,s=t=>{let e;return e=t.id,e};let n=0;if(this.loopType===r.LoopType.RECURSIVE){const t=o=>{const h=this._compare(o.id,i);if(h!==r.CP.eq)if(h===r.CP.lt){if(o.left&&(n+=this.subTreeSum(o.left,e)),n+=s(o),!o.right)return;t(o.right)}else{if(!o.left)return;t(o.left)}else o.right&&(n+=this.subTreeSum(o.right,e))};t(this.root)}else{const t=[this.root];for(;t.length>0;){const o=t.shift();if(o){const h=this._compare(o.id,i);if(h===r.CP.eq)return o.right&&(n+=this.subTreeSum(o.right,e)),n;if(h===r.CP.lt){if(o.left&&(n+=this.subTreeSum(o.left,e)),n+=s(o),!o.right)return n;t.push(o.right)}else{if(!o.left)return n;t.push(o.left)}}}}return n}allGreaterNodesAdd(t,e,i){if(i=null!=i?i:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const s=t.id;if(!this.root)return!1;const n=t=>{t.id+=e};if(this.loopType===r.LoopType.RECURSIVE){const t=e=>{this._compare(e.id,s)===r.CP.gt&&n(e),(e.left||e.right)&&(e.left&&this._compare(e.left.id,s)===r.CP.gt&&t(e.left),e.right&&this._compare(e.right.id,s)===r.CP.gt&&t(e.right))};return t(this.root),!0}{const t=[this.root];for(;t.length>0;){const e=t.shift();e&&(this._compare(e.id,s)===r.CP.gt&&n(e),e.left&&this._compare(e.left.id,s)===r.CP.gt&&t.push(e.left),e.right&&this._compare(e.right.id,s)===r.CP.gt&&t.push(e.right))}return!0}}perfectlyBalance(){const t=this.DFS("in","node"),e=t.length;if(this.clear(),t.length<1)return!1;if(this.loopType===r.LoopType.RECURSIVE){const i=(e,r)=>{if(e>r)return;const s=e+Math.floor((r-e)/2),n=t[s];this.add(n.id,n.val),i(e,s-1),i(s+1,r)};return i(0,e-1),!0}{const i=[[0,e-1]];for(;i.length>0;){const e=i.pop();if(e){const[r,s]=e;if(r<=s){const e=r+Math.floor((s-r)/2),n=t[e];this.add(n.id,n.val),i.push([e+1,s]),i.push([r,e-1])}}}return!0}}isAVLBalanced(){var t,e;if(!this.root)return!0;let i=!0;if(this.loopType===r.LoopType.RECURSIVE){const t=e=>{if(!e)return 0;const r=t(e.left),s=t(e.right);return Math.abs(r-s)>1&&(i=!1),Math.max(r,s)+1};t(this.root)}else{const i=[];let r=this.root,s=null;const n=new Map;for(;i.length>0||r;)if(r)i.push(r),r=r.left;else if(r=i[i.length-1],r.right&&s!==r.right)r=r.right;else if(r=i.pop(),r){const i=r.left&&null!==(t=n.get(r.left))&&void 0!==t?t:-1,o=r.right&&null!==(e=n.get(r.right))&&void 0!==e?e:-1;if(Math.abs(i-o)>1)return!1;n.set(r,1+Math.max(i,o)),s=r,r=null}}return i}_compare(t,e){const i=this._comparator(t,e);return i>0?r.CP.gt:i<0?r.CP.lt:r.CP.eq}}e.BST=o},255:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(6279),e),s(i(8021),e),s(i(761),e),s(i(9649),e),s(i(8207),e),s(i(9993),e),s(i(479),e),s(i(1259),e),s(i(1564),e),s(i(1925),e),s(i(2570),e),s(i(7159),e)},1259:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.RBTree=e.RBTreeNode=void 0;const r=i(1230),s=i(761);class n extends s.BSTNode{constructor(t,e,i=r.RBColor.RED){super(t,e),this._color=i}get color(){return this._color}set color(t){this._color=t}}e.RBTreeNode=n;class o extends s.BST{constructor(t){super(t)}createNode(t,e){return new n(t,e,r.RBColor.RED)}insert(t,e){}leftRotate(t){}rightRotate(t){}insertFixup(t){}deleteFixup(t){}transplant(t,e){}}e.RBTree=o},8207:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SegmentTree=e.SegmentTreeNode=void 0;class i{constructor(t,e,i,r){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=i,this._val=r||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}}e.SegmentTreeNode=i,e.SegmentTree=class{constructor(t,e,i){this._values=[],this._start=0,e=e||0,i=i||t.length-1,this._values=t,this._start=e,this._end=i,this._root=this.build(e,i)}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 i(t,e,this._values[t]);const r=t+Math.floor((e-t)/2),s=this.build(t,r),n=this.build(r+1,e),o=new i(t,e,s.sum+n.sum);return o.left=s,o.right=n,o}updateNode(t,e,i){const r=this.root||null;if(!r)return;const s=(t,e,i,r)=>{t.start!==t.end||t.start!==e?(e<=t.start+Math.floor((t.end-t.start)/2)?t.left&&s(t.left,e,i,r):t.right&&s(t.right,e,i,r),t.left&&t.right&&(t.sum=t.left.sum+t.right.sum)):t.sum=i};s(r,t,e)}querySumByRange(t,e){const i=this.root||null;if(!i)return 0;const r=(t,e,i)=>{if(t.start===e&&t.end===i)return t.sum;const s=t.start+Math.floor((t.end-t.start)/2);return i<=s?t.left?r(t.left,e,i):NaN:e>s?t.right?r(t.right,e,i):NaN:t.left&&t.right?r(t.left,e,s)+r(t.right,s+1,i):NaN};return r(i,t,e)}_setValues(t){this._values=t}_setStart(t){this._start=t}_setEnd(t){this._end=t}_setRoot(t){this._root=t}}},1564:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SplayTree=void 0,e.SplayTree=class{}},2570:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeMultiset=e.TreeMultisetNode=void 0;const r=i(1230),s=i(9993);class n extends s.AVLTreeNode{constructor(t,e,i=1){super(t,e),this._count=i}get count(){return this._count}set count(t){this._count=t}}e.TreeMultisetNode=n;class o extends s.AVLTree{constructor(t){super(Object.assign({},t)),this._count=0}get count(){return this._count}createNode(t,e,i){return new n(t,e,i)}swapLocation(t,e){const{id:i,val:r,count:s,height:n}=e,o=this.createNode(i,r,s);return o&&(o.height=n,e.id=t.id,e.val=t.val,e.count=t.count,e.height=t.height,t.id=o.id,t.val=o.val,t.count=o.count,t.height=o.height),e}add(t,e,i){let s,o;if(i=null!=i?i:1,o=t instanceof n?this.createNode(t.id,t.val,t.count):null===t?null:this.createNode(t,e,i),this.root){let t=this.root,e=!0;for(;e;)t?o&&(this._compare(t.id,o.id)===r.CP.eq?(t.val=o.val,t.count+=o.count,this._setCount(this.count+o.count),e=!1,s=t):this._compare(t.id,o.id)===r.CP.gt?void 0===t.left?(t.left=o,this._setSize(this.size+1),this._setCount(this.count+o.count),e=!1,s=t.left):t.left&&(t=t.left):this._compare(t.id,o.id)===r.CP.lt&&(void 0===t.right?(t.right=o,this._setSize(this.size+1),this._setCount(this.count+o.count),e=!1,s=t.right):t.right&&(t=t.right))):e=!1}else this._setRoot(o),this._setSize(this.size+1),o&&this._setCount(this.count+o.count),s=this.root;return s&&this._balancePath(s),s}_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){var i;const r=[],s=new Map;for(const e of t)s.set(e,(null!==(i=s.get(e))&&void 0!==i?i:0)+1);for(let i=0;i<t.length;i++){const o=t[i];if(s.has(o)){if(o instanceof n){r.push(this.add(o.id,o.val,o.count));continue}if(null===o){r.push(this.add(NaN,null,0));continue}const t=null==e?void 0:e[i],h=s.get(o);r.push(this.add(o,t,h)),s.delete(o)}}return r}perfectlyBalance(){const t=this.DFS("in","node"),e=t.length;if(t.length<1)return!1;if(this.clear(),this.loopType===r.LoopType.RECURSIVE){const i=(e,r)=>{if(e>r)return;const s=e+Math.floor((r-e)/2),n=t[s];this.add(n.id,n.val,n.count),i(e,s-1),i(s+1,r)};return i(0,e-1),!0}{const i=[[0,e-1]];for(;i.length>0;){const e=i.pop();if(e){const[r,s]=e;if(r<=s){const e=r+Math.floor((s-r)/2),n=t[e];this.add(n.id,n.val,n.count),i.push([e+1,s]),i.push([r,e-1])}}}return!0}}remove(t,e){const i=[];if(!this.root)return i;const s=this.get(t);if(!s)return i;const n=(null==s?void 0:s.parent)?s.parent:null;let o=null,h=s;if(s.count>1&&!e)s.count--,this._setCount(this.count-1);else{if(s.left){const t=s.left?this.getRightMost(s.left):null;if(t){const e=t.parent;h=this.swapLocation(s,t),e&&(e.right===t?e.right=t.left:e.left=t.left,o=e)}}else if(n){const{familyPosition:t}=s;t===r.FamilyPosition.LEFT||t===r.FamilyPosition.ROOT_LEFT?n.left=s.right:t!==r.FamilyPosition.RIGHT&&t!==r.FamilyPosition.ROOT_RIGHT||(n.right=s.right),o=n}else void 0!==s.right&&this._setRoot(s.right);this._setSize(this.size-1),this._setCount(this.count-h.count)}return i.push({deleted:h,needBalanced:o}),o&&this._balancePath(o),i}getSubTreeCount(t){const e=[0,0];if(!t)return e;if(this.loopType===r.LoopType.RECURSIVE){const i=t=>{e[0]++,e[1]+=t.count,t.left&&i(t.left),t.right&&i(t.right)};return i(t),e}{const i=[t];for(;i.length>0;){const t=i.pop();e[0]++,e[1]+=t.count,t.right&&i.push(t.right),t.left&&i.push(t.left)}return e}}subTreeSumCount(t){if("number"==typeof t&&(t=this.get(t,"id")),!t)return 0;let e=0;if(this.loopType===r.LoopType.RECURSIVE){const i=t=>{e+=t.count,t.left&&i(t.left),t.right&&i(t.right)};i(t)}else{const i=[t];for(;i.length>0;){const t=i.pop();e+=t.count,t.right&&i.push(t.right),t.left&&i.push(t.left)}}return e}subTreeAddCount(t,e){if("number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const i=t=>{t.count+=e,this._setCount(this.count+e)};if(this.loopType===r.LoopType.RECURSIVE){const e=t=>{i(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();i(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return!0}getNodesByCount(t,e){if(!this.root)return[];const i=[];if(this.loopType===r.LoopType.RECURSIVE){const r=s=>{s.count===t&&(i.push(s),e)||(s.left||s.right)&&(s.left&&r(s.left),s.right&&r(s.right))};r(this.root)}else{const r=[this.root];for(;r.length>0;){const s=r.shift();if(s){if(s.count===t&&(i.push(s),e))return i;s.left&&r.push(s.left),s.right&&r.push(s.right)}}}return i}BFSCount(){return super.BFS("node").map((t=>t.count))}listLevelsCount(t){return super.listLevels(t,"node").map((t=>t.map((t=>t.count))))}morrisCount(t){return t=t||"in",super.morris(t,"node").map((t=>t.count))}DFSIterativeCount(t,e){return t=null!=t?t:"in",super.DFSIterative(t,"node").map((t=>t.count))}DFSCount(t,e){return t=null!=t?t:"in",super.DFS(t,"node").map((t=>t.count))}lesserSumCount(t){if("number"==typeof t&&(t=this.get(t,"id")),!t)return 0;if(!this.root)return 0;const e=t.id;let i=0;if(this.loopType===r.LoopType.RECURSIVE){const t=s=>{const n=this._compare(s.id,e);if(n!==r.CP.eq)if(n===r.CP.lt){if(s.left&&(i+=this.subTreeSumCount(s.left)),i+=s.count,!s.right)return;t(s.right)}else{if(!s.left)return;t(s.left)}else s.right&&(i+=this.subTreeSumCount(s.right))};t(this.root)}else{const t=[this.root];for(;t.length>0;){const s=t.shift();if(s){const n=this._compare(s.id,e);if(n===r.CP.eq)return s.right&&(i+=this.subTreeSumCount(s.right)),i;if(n===r.CP.lt){if(s.left&&(i+=this.subTreeSumCount(s.left)),i+=s.count,!s.right)return i;t.push(s.right)}else{if(!s.left)return i;t.push(s.left)}}}}return i}allGreaterNodesAddCount(t,e){if("number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const i=t.id;if(!this.root)return!1;if(this.loopType===r.LoopType.RECURSIVE){const t=s=>{this._compare(s.id,i)===r.CP.gt&&(s.count+=e),(s.left||s.right)&&(s.left&&this._compare(s.left.id,i)===r.CP.gt&&t(s.left),s.right&&this._compare(s.right.id,i)===r.CP.gt&&t(s.right))};return t(this.root),!0}{const t=[this.root];for(;t.length>0;){const s=t.shift();s&&(this._compare(s.id,i)===r.CP.gt&&(s.count+=e),s.left&&this._compare(s.left.id,i)===r.CP.gt&&t.push(s.left),s.right&&this._compare(s.right.id,i)===r.CP.gt&&t.push(s.right))}return!0}}clear(){super.clear(),this._setCount(0)}_setCount(t){this._count=t}}e.TreeMultiset=o},7159:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TwoThreeTree=void 0,e.TwoThreeTree=class{}},618:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AbstractGraph=e.AbstractEdge=e.AbstractVertex=void 0;const r=i(5928),s=i(7641);class n{constructor(t,e){this._id=t,this._val=e}get id(){return this._id}set id(t){this._id=t}get val(){return this._val}set val(t){this._val=t}}e.AbstractVertex=n;class o{constructor(t,e){this._weight=void 0!==t?t:1,this._val=e,this._hashCode=(0,r.uuidV4)()}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}}e.AbstractEdge=o,e.AbstractGraph=class{constructor(){this._vertices=new Map}get vertices(){return this._vertices}getVertex(t){return this._vertices.get(t)||null}hasVertex(t){return this._vertices.has(this._getVertexId(t))}addVertex(t,e){if(t instanceof n)return this._addVertexOnly(t);{const i=this.createVertex(t,e);return this._addVertexOnly(i)}}removeVertex(t){const e=this._getVertexId(t);return this._vertices.delete(e)}removeAllVertices(t){const e=[];for(const i of t)e.push(this.removeVertex(i));return e.length>0}hasEdge(t,e){return!!this.getEdge(t,e)}addEdge(t,e,i,r){if(t instanceof o)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.id),e instanceof n&&(e=e.id);const s=this.createEdge(t,e,i,r);return this._addEdgeOnly(s)}throw new Error("dest must be a Vertex or vertex id while srcOrEdge is an Edge")}setEdgeWeight(t,e,i){const r=this.getEdge(t,e);return!!r&&(r.weight=i,!0)}getAllPathsBetween(t,e){const i=[],s=this._getVertex(t),n=this._getVertex(e);if(!s||!n)return[];const o=(t,e,n,h)=>{n.set(t,!0),t===e&&i.push([s,...h]);const l=this.getNeighbors(t);for(const t of l)n.get(t)||(h.push(t),o(t,e,n,h),(0,r.arrayRemove)(h,(e=>e===t)));n.set(t,!1)};return o(s,n,new Map,[]),i}getPathSumWeight(t){var e;let i=0;for(let r=0;r<t.length;r++)i+=(null===(e=this.getEdge(t[r],t[r+1]))||void 0===e?void 0:e.weight)||0;return i}getMinCostBetween(t,e,i){if(void 0===i&&(i=!1),i){const i=this.getAllPathsBetween(t,e);let r=1/0;for(const t of i)r=Math.min(this.getPathSumWeight(t),r);return r}{const i=this._getVertex(e),r=this._getVertex(t);if(!r||!i)return null;const s=new Map,n=[r];s.set(r,!0);let o=0;for(;n.length>0;){for(let t=0;t<n.length;t++){const t=n.shift();if(t===i)return o;if(void 0!==t){const e=this.getNeighbors(t);for(const t of e)s.has(t)||(s.set(t,!0),n.push(t))}}o++}return null}}getMinPathBetween(t,e,i){if(void 0===i&&(i=!1),i){const i=this.getAllPathsBetween(t,e);let r=1/0,s=-1,n=0;for(const t of i){const e=this.getPathSumWeight(t);e<r&&(r=e,s=n),n++}return i[s]||null}{let i=[];const s=this._getVertex(t),n=this._getVertex(e);if(!s||!n)return[];const o=(t,e,n,h)=>{if(n.set(t,!0),t===e)return void(i=[s,...h]);const l=this.getNeighbors(t);for(const t of l)n.get(t)||(h.push(t),o(t,e,n,h),(0,r.arrayRemove)(h,(e=>e===t)));n.set(t,!1)};return o(s,n,new Map,[]),i}}dijkstraWithoutHeap(t,e,i,r){void 0===i&&(i=!1),void 0===r&&(r=!1),void 0===e&&(e=null);let s=1/0,o=null,h=[];const l=[],u=this._vertices,a=new Map,c=new Set,d=new Map,f=this._getVertex(t),_=e?this._getVertex(e):null;if(!f)return null;for(const t of u){const e=t[1];e instanceof n&&a.set(e,1/0)}a.set(f,0),d.set(f,null);const p=()=>{let t=1/0,e=null;for(const[i,r]of a)c.has(i)||r<t&&(t=r,e=i);return e},g=t=>{for(const e of u){const i=e[1];if(i instanceof n){const r=[i];let s=d.get(i);for(;s;)r.push(s),s=d.get(s);const n=r.reverse();e[1]===t&&(h=n),l.push(n)}}};for(let t=1;t<u.size;t++){const t=p();if(t){if(c.add(t),_&&_===t)return i&&(s=a.get(_)||1/0),r&&g(_),{distMap:a,preMap:d,seen:c,paths:l,minDist:s,minPath:h};const e=this.getNeighbors(t);for(const i of e)if(!c.has(i)){const e=this.getEdge(t,i);if(e){const r=a.get(t),s=a.get(i);void 0!==r&&void 0!==s&&e.weight+r<s&&(a.set(i,e.weight+r),d.set(i,t))}}}}return i&&a.forEach(((t,e)=>{e!==f&&t<s&&(s=t,r&&(o=e))})),r&&g(o),{distMap:a,preMap:d,seen:c,paths:l,minDist:s,minPath:h}}dijkstra(t,e,i,r){var o;void 0===i&&(i=!1),void 0===r&&(r=!1),void 0===e&&(e=null);let h=1/0,l=null,u=[];const a=[],c=this._vertices,d=new Map,f=new Set,_=new Map,p=this._getVertex(t),g=e?this._getVertex(e):null;if(!p)return null;for(const t of c){const e=t[1];e instanceof n&&d.set(e,1/0)}const v=new s.PriorityQueue({comparator:(t,e)=>t.id-e.id});v.add({id:0,val:p}),d.set(p,0),_.set(p,null);const y=t=>{for(const e of c){const i=e[1];if(i instanceof n){const r=[i];let s=_.get(i);for(;s;)r.push(s),s=_.get(s);const n=r.reverse();e[1]===t&&(u=n),a.push(n)}}};for(;v.size>0;){const t=v.poll(),e=null==t?void 0:t.id,s=null==t?void 0:t.val;if(void 0!==e&&s){if(f.add(s),g&&g===s)return i&&(h=d.get(g)||1/0),r&&y(g),{distMap:d,preMap:_,seen:f,paths:a,minDist:h,minPath:u};const t=this.getNeighbors(s);for(const i of t)if(!f.has(i)){const t=null===(o=this.getEdge(s,i))||void 0===o?void 0:o.weight;if("number"==typeof t){const r=d.get(i);r&&e+t<r&&(v.add({id:e+t,val:i}),_.set(i,s),d.set(i,e+t))}}}}return i&&d.forEach(((t,e)=>{e!==p&&t<h&&(h=t,r&&(l=e))})),r&&y(l),{distMap:d,preMap:_,seen:f,paths:a,minDist:h,minPath:u}}bellmanFord(t,e,i,r){void 0===i&&(i=!1),void 0===r&&(r=!1);const s=this._getVertex(t),o=[],h=new Map,l=new Map;let u,a=1/0,c=[];if(e&&(u=!1),!s)return{hasNegativeCycle:u,distMap:h,preMap:l,paths:o,min:a,minPath:c};const d=this._vertices,f=d.size,_=this.edgeSet(),p=_.length;this._vertices.forEach((t=>{h.set(t,1/0)})),h.set(s,0);for(let t=1;t<f;++t)for(let t=0;t<p;++t){const e=this.getEndsOfEdge(_[t]);if(e){const[i,s]=e,n=_[t].weight,o=h.get(i),u=h.get(s);void 0!==o&&void 0!==u&&h.get(i)!==1/0&&o+n<u&&(h.set(s,o+n),r&&l.set(s,i))}}let g=null;if(i&&h.forEach(((t,e)=>{e!==s&&t<a&&(a=t,r&&(g=e))})),r)for(const t of d){const e=t[1];if(e instanceof n){const i=[e];let r=l.get(e);for(;void 0!==r;)i.push(r),r=l.get(r);const s=i.reverse();t[1]===g&&(c=s),o.push(s)}}for(let t=0;t<p;++t){const e=this.getEndsOfEdge(_[t]);if(e){const[i]=e,r=_[t].weight,s=h.get(i);s&&s!==1/0&&s+r<s&&(u=!0)}}return{hasNegativeCycle:u,distMap:h,preMap:l,paths:o,min:a,minPath:c}}floyd(){var t;const e=[...this._vertices],i=e.length,r=[],s=[];for(let t=0;t<i;t++){r[t]=[],s[t]=[];for(let e=0;e<i;e++)s[t][e]=null}for(let s=0;s<i;s++)for(let n=0;n<i;n++)r[s][n]=(null===(t=this.getEdge(e[s][1],e[n][1]))||void 0===t?void 0:t.weight)||1/0;for(let t=0;t<i;t++)for(let n=0;n<i;n++)for(let o=0;o<i;o++)r[n][o]>r[n][t]+r[t][o]&&(r[n][o]=r[n][t]+r[t][o],s[n][o]=e[t][1]);return{costs:r,predecessor:s}}tarjan(t,e,i,r){const s=!1;void 0===t&&(t=s),void 0===e&&(e=s),void 0===i&&(i=s),void 0===r&&(r=s);const n=new Map,o=new Map,h=this._vertices;h.forEach((t=>{n.set(t,-1),o.set(t,1/0)}));const[l]=h.values(),u=[],a=[];let c=0;const d=(i,r)=>{c++,n.set(i,c),o.set(i,c);const s=this.getNeighbors(i);let h=0;for(const c of s)if(c!==r){-1===n.get(c)&&(h++,d(c,i));const r=o.get(c),s=o.get(i);void 0!==s&&void 0!==r&&o.set(i,Math.min(s,r));const f=n.get(i);if(void 0!==r&&void 0!==f&&(t&&(i===l&&h>=2||i!==l&&r>=f)&&u.push(i),e&&r>f)){const t=this.getEdge(i,c);t&&a.push(t)}}};d(l,null);let f=new Map;const _=()=>{const t=new Map;return o.forEach(((e,i)=>{var r;t.has(e)?null===(r=t.get(e))||void 0===r||r.push(i):t.set(e,[i])})),t};i&&(f=_());const p=new Map;if(r){let t=new Map;t.size<1&&(t=_()),t.forEach(((t,e)=>{t.length>1&&p.set(e,t)}))}return{dfnMap:n,lowMap:o,bridges:a,articulationPoints:u,SCCs:f,cycles:p}}_addVertexOnly(t){return!this.hasVertex(t)&&(this._vertices.set(t.id,t),!0)}_getVertex(t){const e=this._getVertexId(t);return this._vertices.get(e)||null}_getVertexId(t){return t instanceof n?t.id:t}_setVertices(t){this._vertices=t}}},4693:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DirectedGraph=e.DirectedEdge=e.DirectedVertex=void 0;const r=i(5928),s=i(618);class n extends s.AbstractVertex{constructor(t,e){super(t,e)}}e.DirectedVertex=n;class o extends s.AbstractEdge{constructor(t,e,i,r){super(i,r),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}}e.DirectedEdge=o;class h extends s.AbstractGraph{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 n(t,null!=e?e:t)}createEdge(t,e,i,r){return new o(t,e,null!=i?i:1,r)}getEdge(t,e){let i=[];if(null!==t&&null!==e){const r=this._getVertex(t),s=this._getVertex(e);if(r&&s){const t=this._outEdgeMap.get(r);t&&(i=t.filter((t=>t.dest===s.id)))}}return i[0]||null}removeEdgeSrcToDest(t,e){const i=this._getVertex(t),s=this._getVertex(e);let n=null;if(!i||!s)return null;const o=this._outEdgeMap.get(i);o&&(0,r.arrayRemove)(o,(t=>t.dest===s.id));const h=this._inEdgeMap.get(s);return h&&(n=(0,r.arrayRemove)(h,(t=>t.src===i.id))[0]||null),n}removeEdge(t){let e=null;const i=this._getVertex(t.src),s=this._getVertex(t.dest);if(i&&s){const t=this._outEdgeMap.get(i);t&&t.length>0&&(0,r.arrayRemove)(t,(t=>t.src===i.id));const n=this._inEdgeMap.get(s);n&&n.length>0&&(e=(0,r.arrayRemove)(n,(t=>t.dest===s.id))[0])}return e}removeEdgesBetween(t,e){const i=[];if(t&&e){const r=this.removeEdgeSrcToDest(t,e),s=this.removeEdgeSrcToDest(e,t);r&&i.push(r),s&&i.push(s)}return i}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=[],i=this.outgoingEdgesOf(t);for(const t of i){const i=this.getEdgeDest(t);i&&e.push(i)}return e}topologicalSort(t){t=null!=t?t:"id";const e=new Map;for(const t of this.vertices)e.set(t[1],0);let i=[],r=!1;const s=t=>{e.set(t,1);const n=this.getDestinations(t);for(const t of n){const i=e.get(t);0===i?s(t):1===i&&(r=!0)}e.set(t,2),i.push(t)};for(const t of this.vertices)0===e.get(t[1])&&s(t[1]);return r?null:("id"===t&&(i=i.map((t=>t instanceof n?t.id:t))),i.reverse())}edgeSet(){let t=[];return this._outEdgeMap.forEach((e=>{t=[...t,...e]})),t}getNeighbors(t){const e=[],i=this._getVertex(t);if(i){const t=this.outgoingEdgesOf(i);for(const i of t){const t=this._getVertex(i.dest);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.src,t.dest))return null;const e=this._getVertex(t.src),i=this._getVertex(t.dest);return e&&i?[e,i]:null}_addEdgeOnly(t){if(!this.hasVertex(t.src)||!this.hasVertex(t.dest))return!1;const e=this._getVertex(t.src),i=this._getVertex(t.dest);if(e&&i){const r=this._outEdgeMap.get(e);r?r.push(t):this._outEdgeMap.set(e,[t]);const s=this._inEdgeMap.get(i);return s?s.push(t):this._inEdgeMap.set(i,[t]),!0}return!1}_setOutEdgeMap(t){this._outEdgeMap=t}_setInEdgeMap(t){this._inEdgeMap=t}}e.DirectedGraph=h},8079:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(618),e),s(i(4693),e),s(i(5237),e),s(i(5309),e)},5309:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MapGraph=e.MapEdge=e.MapVertex=void 0;const r=i(4693);class s extends r.DirectedVertex{constructor(t,e,i,r){super(t,r),this._lat=e,this._long=i}get lat(){return this._lat}set lat(t){this._lat=t}get long(){return this._long}set long(t){this._long=t}}e.MapVertex=s;class n extends r.DirectedEdge{constructor(t,e,i,r){super(t,e,i,r)}}e.MapEdge=n;class o extends r.DirectedGraph{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,i=this.origin[0],r=this.origin[1]){return new s(t,i,r,e)}createEdge(t,e,i,r){return new n(t,e,i,r)}}e.MapGraph=o},5237:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.UndirectedGraph=e.UndirectedEdge=e.UndirectedVertex=void 0;const r=i(5928),s=i(618);class n extends s.AbstractVertex{constructor(t,e){super(t,e)}}e.UndirectedVertex=n;class o extends s.AbstractEdge{constructor(t,e,i,r){super(i,r),this._vertices=[t,e]}get vertices(){return this._vertices}set vertices(t){this._vertices=t}}e.UndirectedEdge=o;class h extends s.AbstractGraph{constructor(){super(),this._edges=new Map}get edges(){return this._edges}createVertex(t,e){return new n(t,null!=e?e:t)}createEdge(t,e,i,r){return new o(t,e,null!=i?i:1,r)}getEdge(t,e){var i;let r=[];if(null!==t&&null!==e){const s=this._getVertex(t),n=this._getVertex(e);s&&n&&(r=null===(i=this._edges.get(s))||void 0===i?void 0:i.filter((t=>t.vertices.includes(n.id))))}return r&&r[0]||null}removeEdgeBetween(t,e){const i=this._getVertex(t),s=this._getVertex(e);if(!i||!s)return null;const n=this._edges.get(i);let o=null;n&&(o=(0,r.arrayRemove)(n,(t=>t.vertices.includes(s.id)))[0]||null);const h=this._edges.get(s);return h&&(0,r.arrayRemove)(h,(t=>t.vertices.includes(i.id))),o}removeEdge(t){return this.removeEdgeBetween(t.vertices[0],t.vertices[1])}degreeOf(t){var e;const i=this._getVertex(t);return i&&(null===(e=this._edges.get(i))||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=[],i=this._getVertex(t);if(i){const t=this.edgesOf(i);for(const r of t){const t=this._getVertex(r.vertices.filter((t=>t!==i.id))[0]);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.vertices[0],t.vertices[1]))return null;const e=this._getVertex(t.vertices[0]),i=this._getVertex(t.vertices[1]);return e&&i?[e,i]:null}_addEdgeOnly(t){for(const e of t.vertices){const i=this._getVertex(e);if(null===i)return!1;if(i){const e=this._edges.get(i);e?e.push(t):this._edges.set(i,[t])}}return!0}_setEdges(t){this._edges=t}}e.UndirectedGraph=h},2808:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.CoordinateMap=void 0;class i 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}}e.CoordinateMap=i},2130:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.CoordinateSet=void 0;class i 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}}e.CoordinateSet=i},5946:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.HashTable=void 0,e.HashTable=class{}},6841:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(5946),e),s(i(2808),e),s(i(2130),e),s(i(8328),e),s(i(7665),e),s(i(8107),e)},8328:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Pair=void 0,e.Pair=class{}},7665:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeMap=void 0,e.TreeMap=class{}},8107:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeSet=void 0,e.TreeSet=class{}},8049:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Heap=e.HeapItem=void 0;class i{constructor(t=Number.MAX_SAFE_INTEGER,e=null){this._val=e,this._priority=t}get priority(){return this._priority}set priority(t){this._priority=t}get val(){return this._val}set val(t){this._val=t}}e.HeapItem=i,e.Heap=class{constructor(t){if(t){const{priorityExtractor:e}=t;if(void 0!==e&&"function"!=typeof e)throw new Error(".constructor expects a valid priority function");this._priorityExtractor=e||(t=>+t)}else this._priorityExtractor=t=>+t}get pq(){return this._pq}get priorityExtractor(){return this._priorityExtractor}get size(){return this._pq.size}isEmpty(){return this._pq.size<1}peek(t){t=null!=t&&t;const e=this._pq.peek();return t?e:null==e?void 0:e.val}peekLast(t){t=null!=t&&t;const e=this._pq.leaf();return t?e:null==e?void 0:e.val}add(t,e){return e=void 0===e?t:e,this._pq.add(new i(t,e)),this}poll(t){t=null!=t&&t;const e=this._pq.poll();return e?t?e:e.val:null}has(t){return t instanceof i?this.pq.getNodes().includes(t):-1!==this.pq.getNodes().findIndex((e=>e.val===t))}toArray(t){t=null!=t&&t;const e=this._pq.toArray();return t?e:e.map((t=>t.val))}sort(t){t=null!=t&&t;const e=this._pq.sort();return t?e:e.map((t=>t.val))}clear(){this._pq.clear()}}},7888:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(7112),e),s(i(1269),e),s(i(8049),e)},7112:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MaxHeap=void 0;const r=i(8049),s=i(7641);class n extends r.Heap{constructor(t){super(t),this._pq=new s.PriorityQueue({comparator:(t,e)=>e.priority-t.priority})}}e.MaxHeap=n},1269:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MinHeap=void 0;const r=i(8049),s=i(7641);class n extends r.Heap{constructor(t){super(t),this._pq=new s.PriorityQueue({comparator:(t,e)=>t.priority-e.priority})}}e.MinHeap=n},4866:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(6841),e),s(i(2324),e),s(i(9509),e),s(i(2627),e),s(i(8079),e),s(i(255),e),s(i(8456),e),s(i(7888),e),s(i(7641),e),s(i(7619),e),s(i(3543),e)},2198:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DoublyLinkedList=e.DoublyLinkedListNode=void 0;class i{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}}e.DoublyLinkedListNode=i;class r{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 r;for(const i of t)e.push(i);return e}push(t){const e=new i(t);this.head?(e.prev=this.tail,this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}pop(){if(!this.tail)return null;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}shift(){if(!this.head)return null;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}unshift(t){const e=new i(t);this.head?(e.next=this.head,this.head.prev=e,this.head=e):(this.head=e,this.tail=e),this._length++}getAt(t){if(t<0||t>=this.length)return null;let e=this.head;for(let i=0;i<t;i++)e=e.next;return e.val}getNodeAt(t){if(t<0||t>=this.length)return null;let e=this.head;for(let i=0;i<t;i++)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 r=new i(e),s=this.getNodeAt(t-1),n=s.next;return r.prev=s,r.next=n,s.next=r,n.prev=r,this._length++,!0}deleteAt(t){if(t<0||t>=this.length)return null;if(0===t)return this.shift();if(t===this.length-1)return this.pop();const e=this.getNodeAt(t),i=e.prev,r=e.next;return i.next=r,r.prev=i,this._length--,e.val}delete(t){let e;if(e=t instanceof i?t:this.findNode(t),e){if(e===this.head)this.shift();else if(e===this.tail)this.pop();else{const t=e.prev,i=e.next;t.next=i,i.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}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,i=this.head;for(;i;){if(i.val===t)return e;e++,i=i.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,i=0;for(;e;)t(e.val,i),e=e.next,i++}map(t){const e=new r;let i=this.head;for(;i;)e.push(t(i.val)),i=i.next;return e}filter(t){const e=new r;let i=this.head;for(;i;)t(i.val)&&e.push(i.val),i=i.next;return e}reduce(t,e){let i=e,r=this.head;for(;r;)i=t(i,r.val),r=r.next;return i}insertAfter(t,e){let r;if(r=t instanceof i?t:this.findNode(t),r){const t=new i(e);return t.next=r.next,r.next&&(r.next.prev=t),t.prev=r,r.next=t,r===this.tail&&(this.tail=t),this._length++,!0}return!1}insertBefore(t,e){let r;if(r=t instanceof i?t:this.findNode(t),r){const t=new i(e);return t.prev=r.prev,r.prev&&(r.prev.next=t),t.next=r,r.prev=t,r===this.head&&(this.head=t),this._length++,!0}return!1}}e.DoublyLinkedList=r},2324:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(8549),e),s(i(2198),e),s(i(5435),e)},8549:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SinglyLinkedList=e.SinglyLinkedListNode=void 0;class i{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}}e.SinglyLinkedListNode=i;class r{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 r;for(const i of t)e.push(i);return e}getLength(){return this._length}push(t){const e=new i(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 i(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 null;let e=this.head;for(let i=0;i<t;i++)e=e.next;return e.val}getNodeAt(t){let e=this.head;for(let i=0;i<t;i++)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),i=e.next;return e.next=i.next,this._length--,i.val}delete(t){let e;e=t instanceof i?t.val:t;let r=this.head,s=null;for(;r;){if(r.val===e)return null===s?(this.head=r.next,r===this.tail&&(this.tail=null)):(s.next=r.next,r===this.tail&&(this.tail=s)),this._length--,!0;s=r,r=r.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 r=new i(e),s=this.getNodeAt(t-1);return r.next=s.next,s.next=r,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,i=null;for(;e;)i=e.next,e.next=t,t=e,e=i;[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,i=this.head;for(;i;){if(i.val===t)return e;e++,i=i.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 r;if(r=t instanceof i?t.val:t,this.head.val===r)return this.unshift(e),!0;let s=this.head;for(;s.next;){if(s.next.val===r){const t=new i(e);return t.next=s.next,s.next=t,this._length++,!0}s=s.next}return!1}insertAfter(t,e){let r;if(r=t instanceof i?t:this.findNode(t),r){const t=new i(e);return t.next=r.next,r.next=t,r===this.tail&&(this.tail=t),this._length++,!0}return!1}countOccurrences(t){let e=0,i=this.head;for(;i;)i.val===t&&e++,i=i.next;return e}}e.SinglyLinkedList=r},5435:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SkipLinkedList=void 0,e.SkipLinkedList=class{}},7619:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(4824),e),s(i(6090),e),s(i(8723),e),s(i(6690),e)},4824:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MatrixNTI2D=void 0,e.MatrixNTI2D=class{constructor(t){const{row:e,col:i,initialVal:r}=t;this._matrix=new Array(e).fill(void 0).map((()=>new Array(i).fill(r||0)))}toArray(){return this._matrix}}},8723:function(t,e,i){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Matrix2D=void 0;const s=r(i(6090));class n{constructor(t){void 0===t?this._matrix=n.identity:t instanceof s.default?(this._matrix=n.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}get toVector(){return new s.default(this._matrix[0][0],this._matrix[1][0])}static add(t,e){const i=n.empty;for(let r=0;r<3;r++)for(let s=0;s<3;s++)i[r][s]=t.m[r][s]+e.m[r][s];return new n(i)}static subtract(t,e){const i=n.empty;for(let r=0;r<3;r++)for(let s=0;s<3;s++)i[r][s]=t.m[r][s]-e.m[r][s];return new n(i)}static multiply(t,e){const i=n.empty;for(let r=0;r<3;r++)for(let s=0;s<3;s++){i[r][s]=0;for(let n=0;n<3;n++)i[r][s]+=t.m[r][n]*e.m[n][s]}return new n(i)}static multiplyByValue(t,e){const i=n.empty;for(let r=0;r<3;r++)for(let s=0;s<3;s++)i[r][s]=t.m[r][s]*e;return new n(i)}static multiplyByVector(t,e){return n.multiply(t,new n(e)).toVector}static view(t,e){const i=t/2,r=e/2,s=Math.cos(Math.PI);return new n([[1,0,i],[0,1*s,r],[0,0,1]])}static scale(t){return n.multiplyByValue(new n,t)}static rotate(t){const e=Math.cos(t),i=Math.sin(t);return new n([[e,-i,0],[i,e,0],[0,0,1]])}static translate(t){return new n([[1,0,t.x],[0,1,t.y],[0,0,t.w]])}}e.Matrix2D=n,e.default=n},6690:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Navigator=e.Character=void 0;class i{constructor(t,e){this.direction=t,this.turn=()=>new i(e[t],e)}}e.Character=i,e.Navigator=class{constructor({matrix:t,turning:e,onMove:r,init:{cur:s,charDir:n,VISITED:o}}){this._matrix=t,this._cur=s,this._character=new i(n,e),this.onMove=r,this.onMove&&this.onMove(this._cur),this._VISITED=o,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,i;const r=this._matrix,[s,n]=this._cur;switch(t){case"up":if(i=r[s-1],!i)return!1;e=i[n];break;case"right":e=r[s][n+1];break;case"down":if(i=r[s+1],!i)return!1;e=i[n];break;case"left":e=r[s][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,i]=this._cur;this._matrix[e][i]=this._VISITED,this.onMove&&this.onMove(this._cur)}}},6090:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Vector2D=void 0;class i{constructor(t=0,e=0,i=1){this.x=t,this.y=e,this.w=i}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 i(Math.round(this.x),Math.round(this.y))}static add(t,e){return new i(t.x+e.x,t.y+e.y)}static subtract(t,e){return new i(t.x-e.x,t.y-e.y)}static subtractValue(t,e){return new i(t.x-e,t.y-e)}static multiply(t,e){return new i(t.x*e,t.y*e)}static divide(t,e){return new i(t.x/e,t.y/e)}static equals(t,e){return t.x===e.x&&t.y===e.y}static equalsRounded(t,e,r=12){const s=i.abs(i.subtract(t,e));return s.x<r&&s.y<r}static normalize(t){const e=t.length;return e>2220446049250313e-31?i.divide(t,e):t}static truncate(t,e){return t.length>e?i.multiply(i.normalize(t),e):t}static perp(t){return new i(-t.y,t.x)}static reverse(t){return new i(-t.x,-t.y)}static abs(t){return new i(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 i=e.y-t.y,r=e.x-t.x;return Math.sqrt(i*i+r*r)}static distanceSq(t,e){const i=e.y-t.y,r=e.x-t.x;return i*i+r*r}static sign(t,e){return t.y*e.x>t.x*e.y?-1:1}static angle(t){const e=new i(0,-1),r=Math.acos(i.dot(t,e)/(t.length*e.length));return 1===i.sign(t,e)?2*Math.PI-r:r}static random(t,e){const r=Math.floor(Math.random()*t-t/2),s=Math.floor(Math.random()*e-e/2);return new i(r,s)}zero(){this.x=0,this.y=0}}e.Vector2D=i,e.default=i},7641:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(3491),e),s(i(7016),e),s(i(7021),e)},7021:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MaxPriorityQueue=void 0;const r=i(3491);class s extends r.PriorityQueue{constructor(t){super(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>e-t}))}static heapify(t){const e=new s(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>e-t}));return e._fix(),e}}e.MaxPriorityQueue=s},7016:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MinPriorityQueue=void 0;const r=i(3491);class s extends r.PriorityQueue{constructor(t){super(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>t-e}))}static heapify(t){const e=new s(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>t-e}));return e._fix(),e}}e.MinPriorityQueue=s},3491:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.PriorityQueue=void 0;class i{constructor(t){this._nodes=[],this._comparator=(t,e)=>t-e;const{nodes:e,comparator:i,isFix:r=!0}=t;this._comparator=i,e&&Array.isArray(e)&&e.length>0&&(this._nodes=[...e],r&&this._fix())}get nodes(){return this._nodes}get size(){return this.nodes.length}static heapify(t){const e=new i(t);return e._fix(),e}static isPriorityQueueified(t){return new i(Object.assign(Object.assign({},t),{isFix:!1})).isValid()}getNodes(){return this._nodes}add(t){this.nodes.push(t),this._heapifyUp(this.size-1)}has(t){return this.nodes.includes(t)}peek(){return this.size?this.nodes[0]:null}poll(){var t,e;let i=null;return this.size>1?(this._swap(0,this.nodes.length-1),i=null!==(t=this.nodes.pop())&&void 0!==t?t:null,this._heapifyDown(0)):1===this.size&&(i=null!==(e=this.nodes.pop())&&void 0!==e?e:null),i}leaf(){var t;return null!==(t=this.nodes[this.size-1])&&void 0!==t?t:null}isEmpty(){return 0===this.size}clear(){this._setNodes([])}toArray(){return[...this.nodes]}clone(){return new i({nodes:this.nodes,comparator:this._comparator})}isValid(){for(let t=0;t<this.nodes.length;t++){const e=this._getLeft(t),i=this._getRight(t);if(this._isValidIndex(e)&&!this._compare(e,t))return!1;if(this._isValidIndex(i)&&!this._compare(i,t))return!1}return!0}sort(){const t=[];for(;0!==this.size;){const e=this.poll();e&&t.push(e)}return t}DFS(t){const e=[],i=r=>{var s,n,o;const h=this._getLeft(r),l=this._getRight(r);switch(t){case"in":this._isValidIndex(h)&&i(h),e.push(null!==(s=this.nodes[r])&&void 0!==s?s:null),this._isValidIndex(l)&&i(l);break;case"pre":e.push(null!==(n=this.nodes[r])&&void 0!==n?n:null),this._isValidIndex(h)&&i(h),this._isValidIndex(l)&&i(l);break;case"post":this._isValidIndex(h)&&i(h),this._isValidIndex(l)&&i(l),e.push(null!==(o=this.nodes[r])&&void 0!==o?o:null)}};return this._isValidIndex(0)&&i(0),e}_setNodes(t){this._nodes=t}_compare(t,e){return this._comparator(this.nodes[t],this.nodes[e])>0}_swap(t,e){const i=this.nodes[t];this.nodes[t]=this.nodes[e],this.nodes[e]=i}_isValidIndex(t){return t>-1&&t<this.nodes.length}_getParent(t){return Math.floor((t-1)/2)}_getLeft(t){return 2*t+1}_getRight(t){return 2*t+2}_getComparedChild(t){let e=t;const i=this._getLeft(t),r=this._getRight(t);return i<this.size&&this._compare(e,i)&&(e=i),r<this.size&&this._compare(e,r)&&(e=r),e}_heapifyUp(t){for(;t>0&&this._compare(this._getParent(t),t);){const e=this._getParent(t);this._swap(t,e),t=e}}_heapifyDown(t){let e=this._getComparedChild(t);for(;this._compare(t,e);)this._swap(e,t),t=e,e=this._getComparedChild(t)}_fix(){for(let t=Math.floor(this.size/2);t>-1;t--)this._heapifyDown(t)}}e.PriorityQueue=i},7569:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ArrayDeque=e.ObjectDeque=e.Deque=void 0;const r=i(2324);class s extends r.DoublyLinkedList{}e.Deque=s,e.ObjectDeque=class{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}},e.ArrayDeque=class{constructor(){this._nodes=[]}get size(){return this._nodes.length}addLast(t){return this._nodes.push(t)}pollLast(){var t;return null!==(t=this._nodes.pop())&&void 0!==t?t:null}pollFirst(){var t;return null!==(t=this._nodes.shift())&&void 0!==t?t:null}addFirst(t){return this._nodes.unshift(t)}peekFirst(){var t;return null!==(t=this._nodes[0])&&void 0!==t?t:null}peekLast(){var t;return null!==(t=this._nodes[this._nodes.length-1])&&void 0!==t?t:null}get(t){var e;return null!==(e=this._nodes[t])&&void 0!==e?e:null}set(t,e){return this._nodes[t]=e}insert(t,e){return this._nodes.splice(t,0,e)}remove(t){return this._nodes.splice(t,1)}isEmpty(){return 0===this._nodes.length}}},2627:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(3295),e),s(i(7569),e)},3295:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ArrayQueue=e.Queue=void 0;const r=i(2324);class s extends r.SinglyLinkedList{enqueue(t){this.push(t)}dequeue(){return this.shift()}peek(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.val,t=t.next}}e.Queue=s;class n{constructor(t){this._nodes=t||[],this._offset=0}get size(){return this._nodes.length-this._offset}static fromArray(t){return new n(t)}push(t){return this._nodes.push(t),this}shift(){if(0===this.size)return null;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]:null}peekLast(){return this.size>0?this._nodes[this._nodes.length-1]:null}enqueue(t){this.push(t)}dequeue(){return this.shift()}isEmpty(){return 0===this.size}toArray(){return this._nodes.slice(this._offset)}clear(){this._nodes=[],this._offset=0}clone(){return new n(this._nodes.slice(this._offset))}}e.ArrayQueue=n},9509:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(6006),e)},6006:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Stack=void 0;class i{constructor(t){this._elements=Array.isArray(t)?t:[]}static fromArray(t){return new i(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 i(this._elements.slice())}}e.Stack=i},8456:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(301),e)},301:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeNode=void 0;class i{constructor(t,e,i){this._id=t,this._value=e||void 0,this._children=i||[]}get id(){return this._id}set id(t){this._id=t}get value(){return this._value}set value(t){this._value=t}get children(){return this._children}set children(t){this._children=t}addChildren(t){this.children||(this.children=[]),t instanceof i?this.children.push(t):this.children=this.children.concat(t)}getHeight(){const t=this;let e=1;if(t){const i=(t,r)=>{r>e&&(e=r);const{children:s}=t;if(s)for(let t=0,e=s.length;t<e;t++)i(s[t],r+1)};i(t,1)}return e}}e.TreeNode=i},3543:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(2952),e)},2952:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Trie=e.TrieNode=void 0;class i{constructor(t){this._val=t,this._isEnd=!1,this._children=new Map}get val(){return this._val}set val(t){this._val=t}get children(){return this._children}set children(t){this._children=t}get isEnd(){return this._isEnd}set isEnd(t){this._isEnd=t}}e.TrieNode=i,e.Trie=class{constructor(t){if(this._root=new i(""),t)for(const e of t)this.add(e)}get root(){return this._root}set root(t){this._root=t}add(t){let e=this._root;for(const r of t){let t=e.children.get(r);t||(t=new i(r),e.children.set(r,t)),e=t}return e.isEnd=!0,!0}has(t){let e=this._root;for(const i of t){const t=e.children.get(i);if(!t)return!1;e=t}return e.isEnd}remove(t){let e=!1;const i=(r,s)=>{const n=t[s],o=r.children.get(n);return!!o&&(s===t.length-1?!!o.isEnd&&(o.children.size>0?o.isEnd=!1:r.children.delete(n),e=!0,!0):!(!i(o,s+1)||r.isEnd||0!==o.children.size||(r.children.delete(n),0)))};return i(this.root,0),e}isAbsPrefix(t){let e=this._root;for(const i of t){const t=e.children.get(i);if(!t)return!1;e=t}return!e.isEnd}isPrefix(t){let e=this._root;for(const i of t){const t=e.children.get(i);if(!t)return!1;e=t}return!0}isCommonPrefix(t){let e="";const i=r=>{e+=r.val,e!==t&&(r.isEnd||r&&r.children&&1===r.children.size&&i(Array.from(r.children.values())[0]))};return i(this._root),e===t}getLongestCommonPrefix(){let t="";const e=i=>{t+=i.val,i.isEnd||i&&i.children&&1===i.children.size&&e(Array.from(i.children.values())[0])};return e(this._root),t}getAll(t=""){const e=[];let i=this._root;if(t)for(const e of t){const t=i.children.get(e);t&&(i=t)}return function t(i,r){for(const e of i.children.keys()){const s=i.children.get(e);void 0!==s&&t(s,r.concat(e))}i.isEnd&&e.push(r)}(i,t),e}}},3607:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(4866),e),s(i(5928),e),s(i(1247),e),s(i(1230),e)},8709:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1278:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},31:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},3108:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},257:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1265:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},4477:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},2338:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1247:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(8709),e),s(i(1278),e),s(i(31),e),s(i(3108),e),s(i(257),e),s(i(1265),e),s(i(4477),e),s(i(2338),e),s(i(8447),e),s(i(5785),e),s(i(7906),e),s(i(8759),e),s(i(2354),e),s(i(1515),e),s(i(9355),e)},8447:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},5785:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},7906:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},8759:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},2354:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1515:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},9355:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},5177:(t,e)=>{var i,r;Object.defineProperty(e,"__esModule",{value:!0}),e.FamilyPosition=e.LoopType=void 0,(r=e.LoopType||(e.LoopType={})).ITERATIVE="ITERATIVE",r.RECURSIVE="RECURSIVE",(i=e.FamilyPosition||(e.FamilyPosition={})).ROOT="ROOT",i.LEFT="LEFT",i.RIGHT="RIGHT",i.ROOT_LEFT="ROOT_LEFT",i.ROOT_RIGHT="ROOT_RIGHT",i.ISOLATED="ISOLATED",i.MAL_NODE="MAL_NODE"},4086:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},6603:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},2697:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},8222:(t,e)=>{var i;Object.defineProperty(e,"__esModule",{value:!0}),e.CP=void 0,(i=e.CP||(e.CP={})).lt="lt",i.eq="eq",i.gt="gt"},9388:(t,e)=>{var i;Object.defineProperty(e,"__esModule",{value:!0}),e.TopologicalProperty=void 0,(i=e.TopologicalProperty||(e.TopologicalProperty={})).VAL="VAL",i.NODE="NODE",i.ID="ID"},2835:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},8839:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},8720:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(2697),e),s(i(8222),e),s(i(6603),e),s(i(8542),e),s(i(3360),e),s(i(4086),e),s(i(6896),e),s(i(5177),e),s(i(1001),e),s(i(9388),e),s(i(1307),e),s(i(8839),e),s(i(6954),e),s(i(2835),e),s(i(4716),e)},6896:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},4716:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1307:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1001:(t,e)=>{var i;Object.defineProperty(e,"__esModule",{value:!0}),e.RBColor=void 0,(i=e.RBColor||(e.RBColor={})).RED="RED",i.BLACK="BLACK"},8542:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},6954:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},3360:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},5268:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1230:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(8720),e),s(i(5268),e),s(i(9963),e)},9963:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(6016),e),s(i(6706),e)},6016:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},6706:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},5928:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(974),e)},974:function(t,e){var i=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(s,n){function o(t){try{l(r.next(t))}catch(t){n(t)}}function h(t){try{l(r.throw(t))}catch(t){n(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,h)}l((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.trampolineAsync=e.trampoline=e.toThunk=e.isThunk=e.THUNK_SYMBOL=e.arrayRemove=e.uuidV4=void 0,e.uuidV4=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.arrayRemove=function(t,e){let i=-1,r=t?t.length:0;const s=[];for(;++i<r;){const n=t[i];e(n,i,t)&&(s.push(n),Array.prototype.splice.call(t,i--,1),r--)}return s},e.THUNK_SYMBOL=Symbol("thunk"),e.isThunk=t=>"function"==typeof t&&t.__THUNK__===e.THUNK_SYMBOL,e.toThunk=t=>{const i=()=>t();return i.__THUNK__=e.THUNK_SYMBOL,i},e.trampoline=t=>Object.assign(((...i)=>{let r=t(...i);for(;(0,e.isThunk)(r)&&"function"==typeof r;)r=r();return r}),{cont:(...i)=>(0,e.toThunk)((()=>t(...i)))}),e.trampolineAsync=t=>Object.assign(((...r)=>i(void 0,void 0,void 0,(function*(){let i=yield t(...r);for(;(0,e.isThunk)(i)&&"function"==typeof i;)i=yield i();return i}))),{cont:(...i)=>(0,e.toThunk)((()=>t(...i)))})}},e={},i=function i(r){var s=e[r];if(void 0!==s)return s.exports;var n=e[r]={exports:{}};return t[r].call(n.exports,n,n.exports,i),n.exports}(3607);window.dataStructureTyped=i})();
2
+ (()=>{"use strict";var t={1925:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AaTree=void 0,e.AaTree=class{}},6279:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AbstractBinaryTree=e.AbstractBinaryTreeNode=void 0;const r=i(5928),s=i(1230);class n{constructor(t,e){this._height=0,this._id=t,this._val=e}get id(){return this._id}set id(t){this._id=t}get val(){return this._val}set val(t){this._val=t}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get parent(){return this._parent}set parent(t){this._parent=t}get height(){return this._height}set height(t){this._height=t}get familyPosition(){const t=this;return t.parent?t.parent.left===t?t.left||t.right?s.FamilyPosition.ROOT_LEFT:s.FamilyPosition.LEFT:t.parent.right===t?t.left||t.right?s.FamilyPosition.ROOT_RIGHT:s.FamilyPosition.RIGHT:s.FamilyPosition.MAL_NODE:t.left||t.right?s.FamilyPosition.ROOT:s.FamilyPosition.ISOLATED}}e.AbstractBinaryTreeNode=n,e.AbstractBinaryTree=class{constructor(t){if(this._root=null,this._size=0,this._loopType=s.LoopType.ITERATIVE,this._visitedId=[],this._visitedVal=[],this._visitedNode=[],this._visitedLeftSum=[],void 0!==t){const{loopType:e=s.LoopType.ITERATIVE}=t;this._loopType=e}this.clear()}get root(){return this._root}get size(){return this._size}get loopType(){return this._loopType}get visitedId(){return this._visitedId}get visitedVal(){return this._visitedVal}get visitedNode(){return this._visitedNode}get visitedLeftSum(){return this._visitedLeftSum}swapLocation(t,e){const{id:i,val:r,height:s}=e,n=this.createNode(i,r);return n&&(n.height=s,e.id=t.id,e.val=t.val,e.height=t.height,t.id=n.id,t.val=n.val,t.height=n.height),e}clear(){this._root=null,this._size=0,this._clearResults()}isEmpty(){return 0===this.size}add(t,e){let i,r;if(null===t)r=null;else if("number"==typeof t)r=this.createNode(t,e);else{if(!(t instanceof n))return;r=t}const s=t?this.get(t,"id"):void 0;return this.root?s?(s.val=e,i=s):i=((t,e)=>{const i=[t];for(;i.length>0;){const t=i.shift();if(!t)return;{if(e&&t.id===e.id)return;const r=this._addTo(e,t);if(void 0!==r)return r;t.left&&i.push(t.left),t.right&&i.push(t.right)}}})(this.root,r):(this._setRoot(r),null!==r?this._setSize(1):this._setSize(0),i=this.root),i}addMany(t,e){var i;const r=[],s=new Map;for(const e of t)s.set(e,(null!==(i=s.get(e))&&void 0!==i?i:0)+1);for(let i=0;i<t.length;i++){const o=t[i];if(s.has(o)){if(o instanceof n){r.push(this.add(o.id,o.val));continue}if(null===o){r.push(this.add(null));continue}const t=null==e?void 0:e[i];r.push(this.add(o,t)),s.delete(o)}}return r}fill(t,e){return this.clear(),t.length===this.addMany(t,e).length}remove(t,e){const i=[];if(!this.root)return i;const r="number"==typeof t?this.get(t):t;if(!r)return i;const n=(null==r?void 0:r.parent)?r.parent:null;let o=null,h=r;if(r.left){const t=r.left?this.getRightMost(r.left):null;if(t){const e=t.parent;h=this.swapLocation(r,t),e&&(e.right===t?e.right=t.left:e.left=t.left,o=e)}}else if(n){const{familyPosition:t}=r;t===s.FamilyPosition.LEFT||t===s.FamilyPosition.ROOT_LEFT?n.left=r.right:t!==s.FamilyPosition.RIGHT&&t!==s.FamilyPosition.ROOT_RIGHT||(n.right=r.right),o=n}else void 0!==r.right&&this._setRoot(r.right);return this._setSize(this.size-1),i.push({deleted:h,needBalanced:o}),i}getDepth(t){"number"==typeof t&&(t=this.get(t,"id"));let e=0;for(;null==t?void 0:t.parent;)e++,t=t.parent;return e}getHeight(t){if("number"==typeof(t=null!=t?t:this.root)&&(t=this.get(t,"id")),!t)return-1;if(this._loopType===s.LoopType.RECURSIVE){const e=t=>{if(!t)return-1;const i=e(t.left),r=e(t.right);return Math.max(i,r)+1};return e(t)}{if(!t)return-1;const e=[{node:t,depth:0}];let i=0;for(;e.length>0;){const{node:t,depth:r}=e.pop();t.left&&e.push({node:t.left,depth:r+1}),t.right&&e.push({node:t.right,depth:r+1}),i=Math.max(i,r)}return i}}getMinHeight(t){var e,i,r;if(!(t=t||this.root))return-1;if(this._loopType===s.LoopType.RECURSIVE){const e=t=>{if(!t)return 0;if(!t.left&&!t.right)return 0;const i=e(t.left),r=e(t.right);return Math.min(i,r)+1};return e(t)}{const s=[];let n=t,o=null;const h=new Map;for(;s.length>0||n;)if(n)s.push(n),n=n.left;else if(n=s[s.length-1],n.right&&o!==n.right)n=n.right;else if(n=s.pop(),n){const t=n.left&&null!==(e=h.get(n.left))&&void 0!==e?e:-1,r=n.right&&null!==(i=h.get(n.right))&&void 0!==i?i:-1;h.set(n,1+Math.min(t,r)),o=n,n=null}return null!==(r=h.get(t))&&void 0!==r?r:-1}}isPerfectlyBalanced(t){return this.getMinHeight(t)+1>=this.getHeight(t)}getNodes(t,e,i){if(!this.root)return[];e=null!=e?e:"id";const r=[];if(this.loopType===s.LoopType.RECURSIVE){const s=n=>{this._pushByPropertyNameStopOrNot(n,r,t,e,i)||(n.left||n.right)&&(n.left&&s(n.left),n.right&&s(n.right))};s(this.root)}else{const s=[this.root];for(;s.length>0;){const n=s.shift();if(n){if(this._pushByPropertyNameStopOrNot(n,r,t,e,i))return r;n.left&&s.push(n.left),n.right&&s.push(n.right)}}}return r}has(t,e){return e=null!=e?e:"id",this.getNodes(t,e).length>0}get(t,e){var i;return e=null!=e?e:"id",null!==(i=this.getNodes(t,e,!0)[0])&&void 0!==i?i:null}getPathToRoot(t){const e=[];for(;t.parent;)e.unshift(t),t=t.parent;return e.unshift(t),e}getLeftMost(t){if("number"==typeof t&&(t=this.get(t,"id")),!(t=null!=t?t:this.root))return t;if(this._loopType===s.LoopType.RECURSIVE){const e=t=>t.left?e(t.left):t;return e(t)}{const e=(0,r.trampoline)((t=>t.left?e.cont(t.left):t));return e(t)}}getRightMost(t){if(!(t=null!=t?t:this.root))return t;if(this._loopType===s.LoopType.RECURSIVE){const e=t=>t.right?e(t.right):t;return e(t)}{const e=(0,r.trampoline)((t=>t.right?e.cont(t.right):t));return e(t)}}isSubtreeBST(t){if(!t)return!0;if(this._loopType===s.LoopType.RECURSIVE){const e=(t,i,r)=>!t||!(t.id<=i||t.id>=r)&&e(t.left,i,t.id)&&e(t.right,t.id,r);return e(t,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER)}{const e=[];let i=Number.MIN_SAFE_INTEGER,r=t;for(;r||e.length>0;){for(;r;)e.push(r),r=r.left;if(r=e.pop(),!r||i>=r.id)return!1;i=r.id,r=r.right}return!0}}isBST(){return this.isSubtreeBST(this.root)}getSubTreeSize(t){let e=0;if(!t)return e;if(this._loopType===s.LoopType.RECURSIVE){const i=t=>{e++,t.left&&i(t.left),t.right&&i(t.right)};return i(t),e}{const i=[t];for(;i.length>0;){const t=i.pop();e++,t.right&&i.push(t.right),t.left&&i.push(t.left)}return e}}subTreeSum(t,e){if(e=null!=e?e:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return 0;let i=0;const r=t=>{let i;switch(e){case"id":default:i=t.id;break;case"val":i="number"==typeof t.val?t.val:0}return i};if(this._loopType===s.LoopType.RECURSIVE){const e=t=>{i+=r(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();i+=r(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return i}subTreeAdd(t,e,i){if(i=null!=i?i:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const r=t=>{t.id+=e};if(this._loopType===s.LoopType.RECURSIVE){const e=t=>{r(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();r(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return!0}BFS(t){t=null!=t?t:"id",this._clearResults();const e=[this.root];for(;0!==e.length;){const i=e.shift();i&&(this._accumulatedByPropertyName(i,t),null!==(null==i?void 0:i.left)&&e.push(i.left),null!==(null==i?void 0:i.right)&&e.push(i.right))}return this._getResultByPropertyName(t)}DFS(t,e){t=null!=t?t:"in",e=null!=e?e:"id",this._clearResults();const i=r=>{switch(t){case"in":r.left&&i(r.left),this._accumulatedByPropertyName(r,e),r.right&&i(r.right);break;case"pre":this._accumulatedByPropertyName(r,e),r.left&&i(r.left),r.right&&i(r.right);break;case"post":r.left&&i(r.left),r.right&&i(r.right),this._accumulatedByPropertyName(r,e)}};return this.root&&i(this.root),this._getResultByPropertyName(e)}DFSIterative(t,e){if(t=t||"in",e=e||"id",this._clearResults(),!this.root)return this._getResultByPropertyName(e);const i=[{opt:0,node:this.root}];for(;i.length>0;){const r=i.pop();if(r&&r.node)if(1===r.opt)this._accumulatedByPropertyName(r.node,e);else switch(t){case"in":default:i.push({opt:0,node:r.node.right}),i.push({opt:1,node:r.node}),i.push({opt:0,node:r.node.left});break;case"pre":i.push({opt:0,node:r.node.right}),i.push({opt:0,node:r.node.left}),i.push({opt:1,node:r.node});break;case"post":i.push({opt:1,node:r.node}),i.push({opt:0,node:r.node.right}),i.push({opt:0,node:r.node.left})}}return this._getResultByPropertyName(e)}levelIterative(t,e){if(e=e||"id",!(t=t||this.root))return[];this._clearResults();const i=[t];for(;i.length>0;){const t=i.shift();t&&(this._accumulatedByPropertyName(t,e),t.left&&i.push(t.left),t.right&&i.push(t.right))}return this._getResultByPropertyName(e)}listLevels(t,e){if(e=e||"id",!(t=t||this.root))return[];const i=[],r=(t,r)=>{switch(e){case"id":default:i[r].push(t.id);break;case"val":i[r].push(t.val);break;case"node":i[r].push(t)}};if(this.loopType===s.LoopType.RECURSIVE){const e=(t,s)=>{i[s]||(i[s]=[]),r(t,s),t.left&&e(t.left,s+1),t.right&&e(t.right,s+1)};e(t,0)}else{const e=[[t,0]];for(;e.length>0;){const t=e.pop(),[s,n]=t;i[n]||(i[n]=[]),r(s,n),s.right&&e.push([s.right,n+1]),s.left&&e.push([s.left,n+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,e){if(null===this.root)return[];t=t||"in",e=e||"id",this._clearResults();let i=this.root;const r=t=>{let e=null,i=null;for(;t;)i=t.right,t.right=e,e=t,t=i;return e},s=t=>{const i=r(t);let s=i;for(;s;)this._accumulatedByPropertyName(s,e),s=s.right;r(i)};switch(t){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}this._accumulatedByPropertyName(i,e),i=i.right}break;case"pre":for(;i;){if(i.left){const t=this.getPredecessor(i);if(!t.right){t.right=i,this._accumulatedByPropertyName(i,e),i=i.left;continue}t.right=null}else this._accumulatedByPropertyName(i,e);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,s(i.left)}i=i.right}s(this.root)}return this._getResultByPropertyName(e)}_addTo(t,e){return e?void 0===e.left?(e.left=t,t&&this._setSize(this.size+1),e.left):void 0===e.right?(e.right=t,t&&this._setSize(this.size+1),e.right):void 0:void 0}_setLoopType(t){this._loopType=t}_setVisitedId(t){this._visitedId=t}_setVisitedVal(t){this._visitedVal=t}_setVisitedNode(t){this._visitedNode=t}_setVisitedLeftSum(t){this._visitedLeftSum=t}_setRoot(t){t&&(t.parent=void 0),this._root=t}_setSize(t){this._size=t}_clearResults(){this._visitedId=[],this._visitedVal=[],this._visitedNode=[],this._visitedLeftSum=[]}_pushByPropertyNameStopOrNot(t,e,i,r,s){switch(r){case"id":default:if(t.id===i)return e.push(t),!!s;break;case"val":if(t.val===i)return e.push(t),!!s}}_accumulatedByPropertyName(t,e){switch(e=null!=e?e:"id"){case"id":default:this._visitedId.push(t.id);break;case"val":this._visitedVal.push(t.val);break;case"node":this._visitedNode.push(t)}}_getResultByPropertyName(t){switch(t=null!=t?t:"id"){case"id":default:return this._visitedId;case"val":return this._visitedVal;case"node":return this._visitedNode}}}},9993:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AVLTree=e.AVLTreeNode=void 0;const r=i(761);class s extends r.BSTNode{constructor(t,e){super(t,e)}}e.AVLTreeNode=s;class n extends r.BST{constructor(t){super(t)}createNode(t,e){return new s(t,e)}add(t,e){const i=super.add(t,e);return i&&this._balancePath(i),i}remove(t,e){const i=super.remove(t,e);for(const{needBalanced:t}of i)t&&this._balancePath(t);return i}_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);for(let t=e.length-1;t>=0;t--){const i=e[t];switch(this._updateHeight(i),this._balanceFactor(i)){case-2:i&&i.left&&(this._balanceFactor(i.left)<=0?this._balanceLL(i):this._balanceLR(i));break;case 2:i&&i.right&&(this._balanceFactor(i.right)>=0?this._balanceRR(i):this._balanceRL(i))}}}_balanceLL(t){const e=t.parent,i=t.left;t.parent=i,i&&i.right&&(i.right.parent=t),i&&(i.parent=e),t===this.root?i&&this._setRoot(i):(null==e?void 0:e.left)===t?e.left=i:e&&(e.right=i),i&&(t.left=i.right,i.right=t),this._updateHeight(t),i&&this._updateHeight(i)}_balanceLR(t){const e=t.parent,i=t.left;let r=null;i&&(r=i.right),t&&(t.parent=r),i&&(i.parent=r),r&&(r.left&&(r.left.parent=i),r.right&&(r.right.parent=t),r.parent=e),t===this.root?r&&this._setRoot(r):e&&(e.left===t?e.left=r:e.right=r),r&&(t.left=r.right,i&&(i.right=r.left),r.left=i,r.right=t),this._updateHeight(t),i&&this._updateHeight(i),r&&this._updateHeight(r)}_balanceRR(t){const e=t.parent,i=t.right;t.parent=i,i&&(i.left&&(i.left.parent=t),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.right=i.left,i.left=t),this._updateHeight(t),i&&this._updateHeight(i)}_balanceRL(t){const e=t.parent,i=t.right;let r=null;i&&(r=i.left),t.parent=r,i&&(i.parent=r),r&&(r.left&&(r.left.parent=t),r.right&&(r.right.parent=i),r.parent=e),t===this.root?r&&this._setRoot(r):e&&(e.left===t?e.left=r:e.right=r),r&&(t.right=r.left),i&&r&&(i.left=r.right),r&&(r.left=t),r&&(r.right=i),this._updateHeight(t),i&&this._updateHeight(i),r&&this._updateHeight(r)}}e.AVLTree=n},479:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BTree=void 0,e.BTree=class{}},9649:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BinaryIndexedTree=void 0;class i{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+=i.lowBit(t)}getPrefixSum(t){let e=0;for(;t>0;)e+=this._sumTree[t],t-=i.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}}e.BinaryIndexedTree=i},8021:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BinaryTree=e.BinaryTreeNode=void 0;const r=i(6279);class s extends r.AbstractBinaryTreeNode{constructor(t,e){super(t,e)}}e.BinaryTreeNode=s;class n extends r.AbstractBinaryTree{constructor(t){super(t)}createNode(t,e){return new s(t,e)}}e.BinaryTree=n},761:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BST=e.BSTNode=void 0;const r=i(1230),s=i(8021);class n extends s.BinaryTreeNode{constructor(t,e){super(t,e)}}e.BSTNode=n;class o extends s.BinaryTree{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 n(t,e)}add(t,e){let i=null;const s=this.createNode(t,e);if(null===this.root)this._setRoot(s),this._setSize(this.size+1),i=this.root;else{let e=this.root,n=!0;for(;n;)null!==e&&null!==s?this._compare(e.id,t)===r.CP.eq?(s&&(e.val=s.val),n=!1,i=e):this._compare(e.id,t)===r.CP.gt?void 0===e.left?(s&&(s.parent=e),e.left=s,this._setSize(this.size+1),n=!1,i=e.left):e.left&&(e=e.left):this._compare(e.id,t)===r.CP.lt&&(void 0===e.right?(s&&(s.parent=e),e.right=s,this._setSize(this.size+1),n=!1,i=e.right):e.right&&(e=e.right)):n=!1}return i}get(t,e){var i;return e=null!=e?e:"id",null!==(i=this.getNodes(t,e,!0)[0])&&void 0!==i?i:null}lastKey(){var t,e,i,s,n,o;return this._compare(0,1)===r.CP.lt?null!==(e=null===(t=this.getRightMost())||void 0===t?void 0:t.id)&&void 0!==e?e:0:this._compare(0,1)===r.CP.gt?null!==(s=null===(i=this.getLeftMost())||void 0===i?void 0:i.id)&&void 0!==s?s:0:null!==(o=null===(n=this.getRightMost())||void 0===n?void 0:n.id)&&void 0!==o?o:0}getNodes(t,e,i){if(e=null!=e?e:"id",!this.root)return[];const s=[];if(this.loopType===r.LoopType.RECURSIVE){const n=o=>{this._pushByPropertyNameStopOrNot(o,s,t,e,i)||(o.left||o.right)&&("id"===e?(this._compare(o.id,t)===r.CP.gt&&o.left&&n(o.left),this._compare(o.id,t)===r.CP.lt&&o.right&&n(o.right)):(o.left&&n(o.left),o.right&&n(o.right)))};n(this.root)}else{const n=[this.root];for(;n.length>0;){const o=n.shift();if(o){if(this._pushByPropertyNameStopOrNot(o,s,t,e,i))return s;"id"===e?(this._compare(o.id,t)===r.CP.gt&&o.left&&n.push(o.left),this._compare(o.id,t)===r.CP.lt&&o.right&&n.push(o.right)):(o.left&&n.push(o.left),o.right&&n.push(o.right))}}}return s}lesserSum(t,e){if(e=null!=e?e:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return 0;if(!this.root)return 0;const i=t.id,s=t=>{let e;return e=t.id,e};let n=0;if(this.loopType===r.LoopType.RECURSIVE){const t=o=>{const h=this._compare(o.id,i);if(h!==r.CP.eq)if(h===r.CP.lt){if(o.left&&(n+=this.subTreeSum(o.left,e)),n+=s(o),!o.right)return;t(o.right)}else{if(!o.left)return;t(o.left)}else o.right&&(n+=this.subTreeSum(o.right,e))};t(this.root)}else{const t=[this.root];for(;t.length>0;){const o=t.shift();if(o){const h=this._compare(o.id,i);if(h===r.CP.eq)return o.right&&(n+=this.subTreeSum(o.right,e)),n;if(h===r.CP.lt){if(o.left&&(n+=this.subTreeSum(o.left,e)),n+=s(o),!o.right)return n;t.push(o.right)}else{if(!o.left)return n;t.push(o.left)}}}}return n}allGreaterNodesAdd(t,e,i){if(i=null!=i?i:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const s=t.id;if(!this.root)return!1;const n=t=>{t.id+=e};if(this.loopType===r.LoopType.RECURSIVE){const t=e=>{this._compare(e.id,s)===r.CP.gt&&n(e),(e.left||e.right)&&(e.left&&this._compare(e.left.id,s)===r.CP.gt&&t(e.left),e.right&&this._compare(e.right.id,s)===r.CP.gt&&t(e.right))};return t(this.root),!0}{const t=[this.root];for(;t.length>0;){const e=t.shift();e&&(this._compare(e.id,s)===r.CP.gt&&n(e),e.left&&this._compare(e.left.id,s)===r.CP.gt&&t.push(e.left),e.right&&this._compare(e.right.id,s)===r.CP.gt&&t.push(e.right))}return!0}}perfectlyBalance(){const t=this.DFS("in","node"),e=t.length;if(this.clear(),t.length<1)return!1;if(this.loopType===r.LoopType.RECURSIVE){const i=(e,r)=>{if(e>r)return;const s=e+Math.floor((r-e)/2),n=t[s];this.add(n.id,n.val),i(e,s-1),i(s+1,r)};return i(0,e-1),!0}{const i=[[0,e-1]];for(;i.length>0;){const e=i.pop();if(e){const[r,s]=e;if(r<=s){const e=r+Math.floor((s-r)/2),n=t[e];this.add(n.id,n.val),i.push([e+1,s]),i.push([r,e-1])}}}return!0}}isAVLBalanced(){var t,e;if(!this.root)return!0;let i=!0;if(this.loopType===r.LoopType.RECURSIVE){const t=e=>{if(!e)return 0;const r=t(e.left),s=t(e.right);return Math.abs(r-s)>1&&(i=!1),Math.max(r,s)+1};t(this.root)}else{const i=[];let r=this.root,s=null;const n=new Map;for(;i.length>0||r;)if(r)i.push(r),r=r.left;else if(r=i[i.length-1],r.right&&s!==r.right)r=r.right;else if(r=i.pop(),r){const i=r.left&&null!==(t=n.get(r.left))&&void 0!==t?t:-1,o=r.right&&null!==(e=n.get(r.right))&&void 0!==e?e:-1;if(Math.abs(i-o)>1)return!1;n.set(r,1+Math.max(i,o)),s=r,r=null}}return i}_compare(t,e){const i=this._comparator(t,e);return i>0?r.CP.gt:i<0?r.CP.lt:r.CP.eq}}e.BST=o},255:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(6279),e),s(i(8021),e),s(i(761),e),s(i(9649),e),s(i(8207),e),s(i(9993),e),s(i(479),e),s(i(1259),e),s(i(1564),e),s(i(1925),e),s(i(2570),e),s(i(7159),e)},1259:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.RBTree=e.RBTreeNode=void 0;const r=i(1230),s=i(761);class n extends s.BSTNode{constructor(t,e,i=r.RBColor.RED){super(t,e),this._color=i}get color(){return this._color}set color(t){this._color=t}}e.RBTreeNode=n;class o extends s.BST{constructor(t){super(t)}createNode(t,e){return new n(t,e,r.RBColor.RED)}insert(t,e){}leftRotate(t){}rightRotate(t){}insertFixup(t){}deleteFixup(t){}transplant(t,e){}}e.RBTree=o},8207:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SegmentTree=e.SegmentTreeNode=void 0;class i{constructor(t,e,i,r){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=i,this._val=r||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}}e.SegmentTreeNode=i,e.SegmentTree=class{constructor(t,e,i){this._values=[],this._start=0,e=e||0,i=i||t.length-1,this._values=t,this._start=e,this._end=i,this._root=this.build(e,i)}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 i(t,e,this._values[t]);const r=t+Math.floor((e-t)/2),s=this.build(t,r),n=this.build(r+1,e),o=new i(t,e,s.sum+n.sum);return o.left=s,o.right=n,o}updateNode(t,e,i){const r=this.root||null;if(!r)return;const s=(t,e,i,r)=>{t.start!==t.end||t.start!==e?(e<=t.start+Math.floor((t.end-t.start)/2)?t.left&&s(t.left,e,i,r):t.right&&s(t.right,e,i,r),t.left&&t.right&&(t.sum=t.left.sum+t.right.sum)):t.sum=i};s(r,t,e)}querySumByRange(t,e){const i=this.root||null;if(!i)return 0;const r=(t,e,i)=>{if(t.start===e&&t.end===i)return t.sum;const s=t.start+Math.floor((t.end-t.start)/2);return i<=s?t.left?r(t.left,e,i):NaN:e>s?t.right?r(t.right,e,i):NaN:t.left&&t.right?r(t.left,e,s)+r(t.right,s+1,i):NaN};return r(i,t,e)}_setValues(t){this._values=t}_setStart(t){this._start=t}_setEnd(t){this._end=t}_setRoot(t){this._root=t}}},1564:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SplayTree=void 0,e.SplayTree=class{}},2570:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeMultiset=e.TreeMultisetNode=void 0;const r=i(1230),s=i(9993);class n extends s.AVLTreeNode{constructor(t,e,i=1){super(t,e),this._count=i}get count(){return this._count}set count(t){this._count=t}}e.TreeMultisetNode=n;class o extends s.AVLTree{constructor(t){super(Object.assign({},t)),this._count=0}get count(){return this._count}createNode(t,e,i){return new n(t,e,i)}swapLocation(t,e){const{id:i,val:r,count:s,height:n}=e,o=this.createNode(i,r,s);return o&&(o.height=n,e.id=t.id,e.val=t.val,e.count=t.count,e.height=t.height,t.id=o.id,t.val=o.val,t.count=o.count,t.height=o.height),e}add(t,e,i){let s,o;if(i=null!=i?i:1,o=t instanceof n?this.createNode(t.id,t.val,t.count):null===t?null:this.createNode(t,e,i),this.root){let t=this.root,e=!0;for(;e;)t?o&&(this._compare(t.id,o.id)===r.CP.eq?(t.val=o.val,t.count+=o.count,this._setCount(this.count+o.count),e=!1,s=t):this._compare(t.id,o.id)===r.CP.gt?void 0===t.left?(t.left=o,this._setSize(this.size+1),this._setCount(this.count+o.count),e=!1,s=t.left):t.left&&(t=t.left):this._compare(t.id,o.id)===r.CP.lt&&(void 0===t.right?(t.right=o,this._setSize(this.size+1),this._setCount(this.count+o.count),e=!1,s=t.right):t.right&&(t=t.right))):e=!1}else this._setRoot(o),this._setSize(this.size+1),o&&this._setCount(this.count+o.count),s=this.root;return s&&this._balancePath(s),s}_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){var i;const r=[],s=new Map;for(const e of t)s.set(e,(null!==(i=s.get(e))&&void 0!==i?i:0)+1);for(let i=0;i<t.length;i++){const o=t[i];if(s.has(o)){if(o instanceof n){r.push(this.add(o.id,o.val,o.count));continue}if(null===o){r.push(this.add(NaN,null,0));continue}const t=null==e?void 0:e[i],h=s.get(o);r.push(this.add(o,t,h)),s.delete(o)}}return r}perfectlyBalance(){const t=this.DFS("in","node"),e=t.length;if(t.length<1)return!1;if(this.clear(),this.loopType===r.LoopType.RECURSIVE){const i=(e,r)=>{if(e>r)return;const s=e+Math.floor((r-e)/2),n=t[s];this.add(n.id,n.val,n.count),i(e,s-1),i(s+1,r)};return i(0,e-1),!0}{const i=[[0,e-1]];for(;i.length>0;){const e=i.pop();if(e){const[r,s]=e;if(r<=s){const e=r+Math.floor((s-r)/2),n=t[e];this.add(n.id,n.val,n.count),i.push([e+1,s]),i.push([r,e-1])}}}return!0}}remove(t,e){const i=[];if(!this.root)return i;const s=this.get(t);if(!s)return i;const n=(null==s?void 0:s.parent)?s.parent:null;let o=null,h=s;if(s.count>1&&!e)s.count--,this._setCount(this.count-1);else{if(s.left){const t=s.left?this.getRightMost(s.left):null;if(t){const e=t.parent;h=this.swapLocation(s,t),e&&(e.right===t?e.right=t.left:e.left=t.left,o=e)}}else if(n){const{familyPosition:t}=s;t===r.FamilyPosition.LEFT||t===r.FamilyPosition.ROOT_LEFT?n.left=s.right:t!==r.FamilyPosition.RIGHT&&t!==r.FamilyPosition.ROOT_RIGHT||(n.right=s.right),o=n}else void 0!==s.right&&this._setRoot(s.right);this._setSize(this.size-1),this._setCount(this.count-h.count)}return i.push({deleted:h,needBalanced:o}),o&&this._balancePath(o),i}getSubTreeCount(t){const e=[0,0];if(!t)return e;if(this.loopType===r.LoopType.RECURSIVE){const i=t=>{e[0]++,e[1]+=t.count,t.left&&i(t.left),t.right&&i(t.right)};return i(t),e}{const i=[t];for(;i.length>0;){const t=i.pop();e[0]++,e[1]+=t.count,t.right&&i.push(t.right),t.left&&i.push(t.left)}return e}}subTreeSumCount(t){if("number"==typeof t&&(t=this.get(t,"id")),!t)return 0;let e=0;if(this.loopType===r.LoopType.RECURSIVE){const i=t=>{e+=t.count,t.left&&i(t.left),t.right&&i(t.right)};i(t)}else{const i=[t];for(;i.length>0;){const t=i.pop();e+=t.count,t.right&&i.push(t.right),t.left&&i.push(t.left)}}return e}subTreeAddCount(t,e){if("number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const i=t=>{t.count+=e,this._setCount(this.count+e)};if(this.loopType===r.LoopType.RECURSIVE){const e=t=>{i(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();i(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return!0}getNodesByCount(t,e){if(!this.root)return[];const i=[];if(this.loopType===r.LoopType.RECURSIVE){const r=s=>{s.count===t&&(i.push(s),e)||(s.left||s.right)&&(s.left&&r(s.left),s.right&&r(s.right))};r(this.root)}else{const r=[this.root];for(;r.length>0;){const s=r.shift();if(s){if(s.count===t&&(i.push(s),e))return i;s.left&&r.push(s.left),s.right&&r.push(s.right)}}}return i}BFSCount(){return super.BFS("node").map((t=>t.count))}listLevelsCount(t){return super.listLevels(t,"node").map((t=>t.map((t=>t.count))))}morrisCount(t){return t=t||"in",super.morris(t,"node").map((t=>t.count))}DFSIterativeCount(t,e){return t=null!=t?t:"in",super.DFSIterative(t,"node").map((t=>t.count))}DFSCount(t,e){return t=null!=t?t:"in",super.DFS(t,"node").map((t=>t.count))}lesserSumCount(t){if("number"==typeof t&&(t=this.get(t,"id")),!t)return 0;if(!this.root)return 0;const e=t.id;let i=0;if(this.loopType===r.LoopType.RECURSIVE){const t=s=>{const n=this._compare(s.id,e);if(n!==r.CP.eq)if(n===r.CP.lt){if(s.left&&(i+=this.subTreeSumCount(s.left)),i+=s.count,!s.right)return;t(s.right)}else{if(!s.left)return;t(s.left)}else s.right&&(i+=this.subTreeSumCount(s.right))};t(this.root)}else{const t=[this.root];for(;t.length>0;){const s=t.shift();if(s){const n=this._compare(s.id,e);if(n===r.CP.eq)return s.right&&(i+=this.subTreeSumCount(s.right)),i;if(n===r.CP.lt){if(s.left&&(i+=this.subTreeSumCount(s.left)),i+=s.count,!s.right)return i;t.push(s.right)}else{if(!s.left)return i;t.push(s.left)}}}}return i}allGreaterNodesAddCount(t,e){if("number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const i=t.id;if(!this.root)return!1;if(this.loopType===r.LoopType.RECURSIVE){const t=s=>{this._compare(s.id,i)===r.CP.gt&&(s.count+=e),(s.left||s.right)&&(s.left&&this._compare(s.left.id,i)===r.CP.gt&&t(s.left),s.right&&this._compare(s.right.id,i)===r.CP.gt&&t(s.right))};return t(this.root),!0}{const t=[this.root];for(;t.length>0;){const s=t.shift();s&&(this._compare(s.id,i)===r.CP.gt&&(s.count+=e),s.left&&this._compare(s.left.id,i)===r.CP.gt&&t.push(s.left),s.right&&this._compare(s.right.id,i)===r.CP.gt&&t.push(s.right))}return!0}}clear(){super.clear(),this._setCount(0)}_setCount(t){this._count=t}}e.TreeMultiset=o},7159:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TwoThreeTree=void 0,e.TwoThreeTree=class{}},618:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AbstractGraph=e.AbstractEdge=e.AbstractVertex=void 0;const r=i(5928),s=i(7641);class n{constructor(t,e){this._id=t,this._val=e}get id(){return this._id}set id(t){this._id=t}get val(){return this._val}set val(t){this._val=t}}e.AbstractVertex=n;class o{constructor(t,e){this._weight=void 0!==t?t:1,this._val=e,this._hashCode=(0,r.uuidV4)()}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}}e.AbstractEdge=o,e.AbstractGraph=class{constructor(){this._vertices=new Map}get vertices(){return this._vertices}getVertex(t){return this._vertices.get(t)||null}hasVertex(t){return this._vertices.has(this._getVertexId(t))}addVertex(t,e){if(t instanceof n)return this._addVertexOnly(t);{const i=this.createVertex(t,e);return this._addVertexOnly(i)}}removeVertex(t){const e=this._getVertexId(t);return this._vertices.delete(e)}removeAllVertices(t){const e=[];for(const i of t)e.push(this.removeVertex(i));return e.length>0}hasEdge(t,e){return!!this.getEdge(t,e)}addEdge(t,e,i,r){if(t instanceof o)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.id),e instanceof n&&(e=e.id);const s=this.createEdge(t,e,i,r);return this._addEdgeOnly(s)}throw new Error("dest must be a Vertex or vertex id while srcOrEdge is an Edge")}setEdgeWeight(t,e,i){const r=this.getEdge(t,e);return!!r&&(r.weight=i,!0)}getAllPathsBetween(t,e){const i=[],s=this._getVertex(t),n=this._getVertex(e);if(!s||!n)return[];const o=(t,e,n,h)=>{n.set(t,!0),t===e&&i.push([s,...h]);const l=this.getNeighbors(t);for(const t of l)n.get(t)||(h.push(t),o(t,e,n,h),(0,r.arrayRemove)(h,(e=>e===t)));n.set(t,!1)};return o(s,n,new Map,[]),i}getPathSumWeight(t){var e;let i=0;for(let r=0;r<t.length;r++)i+=(null===(e=this.getEdge(t[r],t[r+1]))||void 0===e?void 0:e.weight)||0;return i}getMinCostBetween(t,e,i){if(void 0===i&&(i=!1),i){const i=this.getAllPathsBetween(t,e);let r=1/0;for(const t of i)r=Math.min(this.getPathSumWeight(t),r);return r}{const i=this._getVertex(e),r=this._getVertex(t);if(!r||!i)return null;const s=new Map,n=[r];s.set(r,!0);let o=0;for(;n.length>0;){for(let t=0;t<n.length;t++){const t=n.shift();if(t===i)return o;if(void 0!==t){const e=this.getNeighbors(t);for(const t of e)s.has(t)||(s.set(t,!0),n.push(t))}}o++}return null}}getMinPathBetween(t,e,i){if(void 0===i&&(i=!1),i){const i=this.getAllPathsBetween(t,e);let r=1/0,s=-1,n=0;for(const t of i){const e=this.getPathSumWeight(t);e<r&&(r=e,s=n),n++}return i[s]||null}{let i=[];const s=this._getVertex(t),n=this._getVertex(e);if(!s||!n)return[];const o=(t,e,n,h)=>{if(n.set(t,!0),t===e)return void(i=[s,...h]);const l=this.getNeighbors(t);for(const t of l)n.get(t)||(h.push(t),o(t,e,n,h),(0,r.arrayRemove)(h,(e=>e===t)));n.set(t,!1)};return o(s,n,new Map,[]),i}}dijkstraWithoutHeap(t,e,i,r){void 0===i&&(i=!1),void 0===r&&(r=!1),void 0===e&&(e=null);let s=1/0,o=null,h=[];const l=[],u=this._vertices,a=new Map,c=new Set,d=new Map,f=this._getVertex(t),p=e?this._getVertex(e):null;if(!f)return null;for(const t of u){const e=t[1];e instanceof n&&a.set(e,1/0)}a.set(f,0),d.set(f,null);const _=()=>{let t=1/0,e=null;for(const[i,r]of a)c.has(i)||r<t&&(t=r,e=i);return e},g=t=>{for(const e of u){const i=e[1];if(i instanceof n){const r=[i];let s=d.get(i);for(;s;)r.push(s),s=d.get(s);const n=r.reverse();e[1]===t&&(h=n),l.push(n)}}};for(let t=1;t<u.size;t++){const t=_();if(t){if(c.add(t),p&&p===t)return i&&(s=a.get(p)||1/0),r&&g(p),{distMap:a,preMap:d,seen:c,paths:l,minDist:s,minPath:h};const e=this.getNeighbors(t);for(const i of e)if(!c.has(i)){const e=this.getEdge(t,i);if(e){const r=a.get(t),s=a.get(i);void 0!==r&&void 0!==s&&e.weight+r<s&&(a.set(i,e.weight+r),d.set(i,t))}}}}return i&&a.forEach(((t,e)=>{e!==f&&t<s&&(s=t,r&&(o=e))})),r&&g(o),{distMap:a,preMap:d,seen:c,paths:l,minDist:s,minPath:h}}dijkstra(t,e,i,r){var o;void 0===i&&(i=!1),void 0===r&&(r=!1),void 0===e&&(e=null);let h=1/0,l=null,u=[];const a=[],c=this._vertices,d=new Map,f=new Set,p=new Map,_=this._getVertex(t),g=e?this._getVertex(e):null;if(!_)return null;for(const t of c){const e=t[1];e instanceof n&&d.set(e,1/0)}const v=new s.PriorityQueue({comparator:(t,e)=>t.id-e.id});v.add({id:0,val:_}),d.set(_,0),p.set(_,null);const y=t=>{for(const e of c){const i=e[1];if(i instanceof n){const r=[i];let s=p.get(i);for(;s;)r.push(s),s=p.get(s);const n=r.reverse();e[1]===t&&(u=n),a.push(n)}}};for(;v.size>0;){const t=v.poll(),e=null==t?void 0:t.id,s=null==t?void 0:t.val;if(void 0!==e&&s){if(f.add(s),g&&g===s)return i&&(h=d.get(g)||1/0),r&&y(g),{distMap:d,preMap:p,seen:f,paths:a,minDist:h,minPath:u};const t=this.getNeighbors(s);for(const i of t)if(!f.has(i)){const t=null===(o=this.getEdge(s,i))||void 0===o?void 0:o.weight;if("number"==typeof t){const r=d.get(i);r&&e+t<r&&(v.add({id:e+t,val:i}),p.set(i,s),d.set(i,e+t))}}}}return i&&d.forEach(((t,e)=>{e!==_&&t<h&&(h=t,r&&(l=e))})),r&&y(l),{distMap:d,preMap:p,seen:f,paths:a,minDist:h,minPath:u}}bellmanFord(t,e,i,r){void 0===i&&(i=!1),void 0===r&&(r=!1);const s=this._getVertex(t),o=[],h=new Map,l=new Map;let u,a=1/0,c=[];if(e&&(u=!1),!s)return{hasNegativeCycle:u,distMap:h,preMap:l,paths:o,min:a,minPath:c};const d=this._vertices,f=d.size,p=this.edgeSet(),_=p.length;this._vertices.forEach((t=>{h.set(t,1/0)})),h.set(s,0);for(let t=1;t<f;++t)for(let t=0;t<_;++t){const e=this.getEndsOfEdge(p[t]);if(e){const[i,s]=e,n=p[t].weight,o=h.get(i),u=h.get(s);void 0!==o&&void 0!==u&&h.get(i)!==1/0&&o+n<u&&(h.set(s,o+n),r&&l.set(s,i))}}let g=null;if(i&&h.forEach(((t,e)=>{e!==s&&t<a&&(a=t,r&&(g=e))})),r)for(const t of d){const e=t[1];if(e instanceof n){const i=[e];let r=l.get(e);for(;void 0!==r;)i.push(r),r=l.get(r);const s=i.reverse();t[1]===g&&(c=s),o.push(s)}}for(let t=0;t<_;++t){const e=this.getEndsOfEdge(p[t]);if(e){const[i]=e,r=p[t].weight,s=h.get(i);s&&s!==1/0&&s+r<s&&(u=!0)}}return{hasNegativeCycle:u,distMap:h,preMap:l,paths:o,min:a,minPath:c}}floyd(){var t;const e=[...this._vertices],i=e.length,r=[],s=[];for(let t=0;t<i;t++){r[t]=[],s[t]=[];for(let e=0;e<i;e++)s[t][e]=null}for(let s=0;s<i;s++)for(let n=0;n<i;n++)r[s][n]=(null===(t=this.getEdge(e[s][1],e[n][1]))||void 0===t?void 0:t.weight)||1/0;for(let t=0;t<i;t++)for(let n=0;n<i;n++)for(let o=0;o<i;o++)r[n][o]>r[n][t]+r[t][o]&&(r[n][o]=r[n][t]+r[t][o],s[n][o]=e[t][1]);return{costs:r,predecessor:s}}tarjan(t,e,i,r){const s=!1;void 0===t&&(t=s),void 0===e&&(e=s),void 0===i&&(i=s),void 0===r&&(r=s);const n=new Map,o=new Map,h=this._vertices;h.forEach((t=>{n.set(t,-1),o.set(t,1/0)}));const[l]=h.values(),u=[],a=[];let c=0;const d=(i,r)=>{c++,n.set(i,c),o.set(i,c);const s=this.getNeighbors(i);let h=0;for(const c of s)if(c!==r){-1===n.get(c)&&(h++,d(c,i));const r=o.get(c),s=o.get(i);void 0!==s&&void 0!==r&&o.set(i,Math.min(s,r));const f=n.get(i);if(void 0!==r&&void 0!==f&&(t&&(i===l&&h>=2||i!==l&&r>=f)&&u.push(i),e&&r>f)){const t=this.getEdge(i,c);t&&a.push(t)}}};d(l,null);let f=new Map;const p=()=>{const t=new Map;return o.forEach(((e,i)=>{var r;t.has(e)?null===(r=t.get(e))||void 0===r||r.push(i):t.set(e,[i])})),t};i&&(f=p());const _=new Map;if(r){let t=new Map;t.size<1&&(t=p()),t.forEach(((t,e)=>{t.length>1&&_.set(e,t)}))}return{dfnMap:n,lowMap:o,bridges:a,articulationPoints:u,SCCs:f,cycles:_}}_addVertexOnly(t){return!this.hasVertex(t)&&(this._vertices.set(t.id,t),!0)}_getVertex(t){const e=this._getVertexId(t);return this._vertices.get(e)||null}_getVertexId(t){return t instanceof n?t.id:t}_setVertices(t){this._vertices=t}}},4693:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DirectedGraph=e.DirectedEdge=e.DirectedVertex=void 0;const r=i(5928),s=i(618);class n extends s.AbstractVertex{constructor(t,e){super(t,e)}}e.DirectedVertex=n;class o extends s.AbstractEdge{constructor(t,e,i,r){super(i,r),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}}e.DirectedEdge=o;class h extends s.AbstractGraph{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 n(t,null!=e?e:t)}createEdge(t,e,i,r){return new o(t,e,null!=i?i:1,r)}getEdge(t,e){let i=[];if(null!==t&&null!==e){const r=this._getVertex(t),s=this._getVertex(e);if(r&&s){const t=this._outEdgeMap.get(r);t&&(i=t.filter((t=>t.dest===s.id)))}}return i[0]||null}removeEdgeSrcToDest(t,e){const i=this._getVertex(t),s=this._getVertex(e);let n=null;if(!i||!s)return null;const o=this._outEdgeMap.get(i);o&&(0,r.arrayRemove)(o,(t=>t.dest===s.id));const h=this._inEdgeMap.get(s);return h&&(n=(0,r.arrayRemove)(h,(t=>t.src===i.id))[0]||null),n}removeEdge(t){let e=null;const i=this._getVertex(t.src),s=this._getVertex(t.dest);if(i&&s){const t=this._outEdgeMap.get(i);t&&t.length>0&&(0,r.arrayRemove)(t,(t=>t.src===i.id));const n=this._inEdgeMap.get(s);n&&n.length>0&&(e=(0,r.arrayRemove)(n,(t=>t.dest===s.id))[0])}return e}removeEdgesBetween(t,e){const i=[];if(t&&e){const r=this.removeEdgeSrcToDest(t,e),s=this.removeEdgeSrcToDest(e,t);r&&i.push(r),s&&i.push(s)}return i}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=[],i=this.outgoingEdgesOf(t);for(const t of i){const i=this.getEdgeDest(t);i&&e.push(i)}return e}topologicalSort(t){t=null!=t?t:"id";const e=new Map;for(const t of this.vertices)e.set(t[1],0);let i=[],r=!1;const s=t=>{e.set(t,1);const n=this.getDestinations(t);for(const t of n){const i=e.get(t);0===i?s(t):1===i&&(r=!0)}e.set(t,2),i.push(t)};for(const t of this.vertices)0===e.get(t[1])&&s(t[1]);return r?null:("id"===t&&(i=i.map((t=>t instanceof n?t.id:t))),i.reverse())}edgeSet(){let t=[];return this._outEdgeMap.forEach((e=>{t=[...t,...e]})),t}getNeighbors(t){const e=[],i=this._getVertex(t);if(i){const t=this.outgoingEdgesOf(i);for(const i of t){const t=this._getVertex(i.dest);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.src,t.dest))return null;const e=this._getVertex(t.src),i=this._getVertex(t.dest);return e&&i?[e,i]:null}_addEdgeOnly(t){if(!this.hasVertex(t.src)||!this.hasVertex(t.dest))return!1;const e=this._getVertex(t.src),i=this._getVertex(t.dest);if(e&&i){const r=this._outEdgeMap.get(e);r?r.push(t):this._outEdgeMap.set(e,[t]);const s=this._inEdgeMap.get(i);return s?s.push(t):this._inEdgeMap.set(i,[t]),!0}return!1}_setOutEdgeMap(t){this._outEdgeMap=t}_setInEdgeMap(t){this._inEdgeMap=t}}e.DirectedGraph=h},8079:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(618),e),s(i(4693),e),s(i(5237),e),s(i(5309),e)},5309:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MapGraph=e.MapEdge=e.MapVertex=void 0;const r=i(4693);class s extends r.DirectedVertex{constructor(t,e,i,r){super(t,r),this._lat=e,this._long=i}get lat(){return this._lat}set lat(t){this._lat=t}get long(){return this._long}set long(t){this._long=t}}e.MapVertex=s;class n extends r.DirectedEdge{constructor(t,e,i,r){super(t,e,i,r)}}e.MapEdge=n;class o extends r.DirectedGraph{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,i=this.origin[0],r=this.origin[1]){return new s(t,i,r,e)}createEdge(t,e,i,r){return new n(t,e,i,r)}}e.MapGraph=o},5237:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.UndirectedGraph=e.UndirectedEdge=e.UndirectedVertex=void 0;const r=i(5928),s=i(618);class n extends s.AbstractVertex{constructor(t,e){super(t,e)}}e.UndirectedVertex=n;class o extends s.AbstractEdge{constructor(t,e,i,r){super(i,r),this._vertices=[t,e]}get vertices(){return this._vertices}set vertices(t){this._vertices=t}}e.UndirectedEdge=o;class h extends s.AbstractGraph{constructor(){super(),this._edges=new Map}get edges(){return this._edges}createVertex(t,e){return new n(t,null!=e?e:t)}createEdge(t,e,i,r){return new o(t,e,null!=i?i:1,r)}getEdge(t,e){var i;let r=[];if(null!==t&&null!==e){const s=this._getVertex(t),n=this._getVertex(e);s&&n&&(r=null===(i=this._edges.get(s))||void 0===i?void 0:i.filter((t=>t.vertices.includes(n.id))))}return r&&r[0]||null}removeEdgeBetween(t,e){const i=this._getVertex(t),s=this._getVertex(e);if(!i||!s)return null;const n=this._edges.get(i);let o=null;n&&(o=(0,r.arrayRemove)(n,(t=>t.vertices.includes(s.id)))[0]||null);const h=this._edges.get(s);return h&&(0,r.arrayRemove)(h,(t=>t.vertices.includes(i.id))),o}removeEdge(t){return this.removeEdgeBetween(t.vertices[0],t.vertices[1])}degreeOf(t){var e;const i=this._getVertex(t);return i&&(null===(e=this._edges.get(i))||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=[],i=this._getVertex(t);if(i){const t=this.edgesOf(i);for(const r of t){const t=this._getVertex(r.vertices.filter((t=>t!==i.id))[0]);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.vertices[0],t.vertices[1]))return null;const e=this._getVertex(t.vertices[0]),i=this._getVertex(t.vertices[1]);return e&&i?[e,i]:null}_addEdgeOnly(t){for(const e of t.vertices){const i=this._getVertex(e);if(null===i)return!1;if(i){const e=this._edges.get(i);e?e.push(t):this._edges.set(i,[t])}}return!0}_setEdges(t){this._edges=t}}e.UndirectedGraph=h},2808:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.CoordinateMap=void 0;class i 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}}e.CoordinateMap=i},2130:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.CoordinateSet=void 0;class i 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}}e.CoordinateSet=i},5946:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.HashTable=void 0,e.HashTable=class{}},6841:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(5946),e),s(i(2808),e),s(i(2130),e),s(i(8328),e),s(i(7665),e),s(i(8107),e)},8328:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Pair=void 0,e.Pair=class{}},7665:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeMap=void 0,e.TreeMap=class{}},8107:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeSet=void 0,e.TreeSet=class{}},8049:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Heap=e.HeapItem=void 0;class i{constructor(t=Number.MAX_SAFE_INTEGER,e=null){this._val=e,this._priority=t}get priority(){return this._priority}set priority(t){this._priority=t}get val(){return this._val}set val(t){this._val=t}}e.HeapItem=i,e.Heap=class{constructor(t){if(t){const{priorityExtractor:e}=t;if(void 0!==e&&"function"!=typeof e)throw new Error(".constructor expects a valid priority function");this._priorityExtractor=e||(t=>+t)}else this._priorityExtractor=t=>+t}get pq(){return this._pq}get priorityExtractor(){return this._priorityExtractor}get size(){return this._pq.size}isEmpty(){return this._pq.size<1}peek(t){t=null!=t&&t;const e=this._pq.peek();return t?e:null==e?void 0:e.val}peekLast(t){t=null!=t&&t;const e=this._pq.leaf();return t?e:null==e?void 0:e.val}add(t,e){return e=void 0===e?t:e,this._pq.add(new i(t,e)),this}poll(t){t=null!=t&&t;const e=this._pq.poll();return e?t?e:e.val:null}has(t){return t instanceof i?this.pq.getNodes().includes(t):-1!==this.pq.getNodes().findIndex((e=>e.val===t))}toArray(t){t=null!=t&&t;const e=this._pq.toArray();return t?e:e.map((t=>t.val))}sort(t){t=null!=t&&t;const e=this._pq.sort();return t?e:e.map((t=>t.val))}clear(){this._pq.clear()}}},7888:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(7112),e),s(i(1269),e),s(i(8049),e)},7112:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MaxHeap=void 0;const r=i(8049),s=i(7641);class n extends r.Heap{constructor(t){super(t),this._pq=new s.PriorityQueue({comparator:(t,e)=>e.priority-t.priority})}}e.MaxHeap=n},1269:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MinHeap=void 0;const r=i(8049),s=i(7641);class n extends r.Heap{constructor(t){super(t),this._pq=new s.PriorityQueue({comparator:(t,e)=>t.priority-e.priority})}}e.MinHeap=n},4866:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(6841),e),s(i(2324),e),s(i(9509),e),s(i(2627),e),s(i(8079),e),s(i(255),e),s(i(8456),e),s(i(7888),e),s(i(7641),e),s(i(7619),e),s(i(3543),e)},2198:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DoublyLinkedList=e.DoublyLinkedListNode=void 0;class i{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}}e.DoublyLinkedListNode=i;class r{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 r;for(const i of t)e.push(i);return e}push(t){const e=new i(t);this.head?(e.prev=this.tail,this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}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}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}unshift(t){const e=new i(t);this.head?(e.next=this.head,this.head.prev=e,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 i=0;i<t;i++)e=e.next;return e.val}getNodeAt(t){if(t<0||t>=this.length)return null;let e=this.head;for(let i=0;i<t;i++)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 r=new i(e),s=this.getNodeAt(t-1),n=s.next;return r.prev=s,r.next=n,s.next=r,n.prev=r,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),i=e.prev,r=e.next;return i.next=r,r.prev=i,this._length--,e.val}delete(t){let e;if(e=t instanceof i?t:this.findNode(t),e){if(e===this.head)this.shift();else if(e===this.tail)this.pop();else{const t=e.prev,i=e.next;t.next=i,i.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}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,i=this.head;for(;i;){if(i.val===t)return e;e++,i=i.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,i=0;for(;e;)t(e.val,i),e=e.next,i++}map(t){const e=new r;let i=this.head;for(;i;)e.push(t(i.val)),i=i.next;return e}filter(t){const e=new r;let i=this.head;for(;i;)t(i.val)&&e.push(i.val),i=i.next;return e}reduce(t,e){let i=e,r=this.head;for(;r;)i=t(i,r.val),r=r.next;return i}insertAfter(t,e){let r;if(r=t instanceof i?t:this.findNode(t),r){const t=new i(e);return t.next=r.next,r.next&&(r.next.prev=t),t.prev=r,r.next=t,r===this.tail&&(this.tail=t),this._length++,!0}return!1}insertBefore(t,e){let r;if(r=t instanceof i?t:this.findNode(t),r){const t=new i(e);return t.prev=r.prev,r.prev&&(r.prev.next=t),t.next=r,r.prev=t,r===this.head&&(this.head=t),this._length++,!0}return!1}}e.DoublyLinkedList=r},2324:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(8549),e),s(i(2198),e),s(i(5435),e)},8549:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SinglyLinkedList=e.SinglyLinkedListNode=void 0;class i{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}}e.SinglyLinkedListNode=i;class r{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 r;for(const i of t)e.push(i);return e}getLength(){return this._length}push(t){const e=new i(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 i(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 i=0;i<t;i++)e=e.next;return e.val}getNodeAt(t){let e=this.head;for(let i=0;i<t;i++)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),i=e.next;return e.next=i.next,this._length--,i.val}delete(t){let e;e=t instanceof i?t.val:t;let r=this.head,s=null;for(;r;){if(r.val===e)return null===s?(this.head=r.next,r===this.tail&&(this.tail=null)):(s.next=r.next,r===this.tail&&(this.tail=s)),this._length--,!0;s=r,r=r.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 r=new i(e),s=this.getNodeAt(t-1);return r.next=s.next,s.next=r,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,i=null;for(;e;)i=e.next,e.next=t,t=e,e=i;[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,i=this.head;for(;i;){if(i.val===t)return e;e++,i=i.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 r;if(r=t instanceof i?t.val:t,this.head.val===r)return this.unshift(e),!0;let s=this.head;for(;s.next;){if(s.next.val===r){const t=new i(e);return t.next=s.next,s.next=t,this._length++,!0}s=s.next}return!1}insertAfter(t,e){let r;if(r=t instanceof i?t:this.findNode(t),r){const t=new i(e);return t.next=r.next,r.next=t,r===this.tail&&(this.tail=t),this._length++,!0}return!1}countOccurrences(t){let e=0,i=this.head;for(;i;)i.val===t&&e++,i=i.next;return e}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.val,t=t.next}}e.SinglyLinkedList=r},5435:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SkipLinkedList=void 0,e.SkipLinkedList=class{}},7619:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(4824),e),s(i(6090),e),s(i(8723),e),s(i(6690),e)},4824:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MatrixNTI2D=void 0,e.MatrixNTI2D=class{constructor(t){const{row:e,col:i,initialVal:r}=t;this._matrix=new Array(e).fill(void 0).map((()=>new Array(i).fill(r||0)))}toArray(){return this._matrix}}},8723:function(t,e,i){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Matrix2D=void 0;const s=r(i(6090));class n{constructor(t){void 0===t?this._matrix=n.identity:t instanceof s.default?(this._matrix=n.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}get toVector(){return new s.default(this._matrix[0][0],this._matrix[1][0])}static add(t,e){const i=n.empty;for(let r=0;r<3;r++)for(let s=0;s<3;s++)i[r][s]=t.m[r][s]+e.m[r][s];return new n(i)}static subtract(t,e){const i=n.empty;for(let r=0;r<3;r++)for(let s=0;s<3;s++)i[r][s]=t.m[r][s]-e.m[r][s];return new n(i)}static multiply(t,e){const i=n.empty;for(let r=0;r<3;r++)for(let s=0;s<3;s++){i[r][s]=0;for(let n=0;n<3;n++)i[r][s]+=t.m[r][n]*e.m[n][s]}return new n(i)}static multiplyByValue(t,e){const i=n.empty;for(let r=0;r<3;r++)for(let s=0;s<3;s++)i[r][s]=t.m[r][s]*e;return new n(i)}static multiplyByVector(t,e){return n.multiply(t,new n(e)).toVector}static view(t,e){const i=t/2,r=e/2,s=Math.cos(Math.PI);return new n([[1,0,i],[0,1*s,r],[0,0,1]])}static scale(t){return n.multiplyByValue(new n,t)}static rotate(t){const e=Math.cos(t),i=Math.sin(t);return new n([[e,-i,0],[i,e,0],[0,0,1]])}static translate(t){return new n([[1,0,t.x],[0,1,t.y],[0,0,t.w]])}}e.Matrix2D=n,e.default=n},6690:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Navigator=e.Character=void 0;class i{constructor(t,e){this.direction=t,this.turn=()=>new i(e[t],e)}}e.Character=i,e.Navigator=class{constructor({matrix:t,turning:e,onMove:r,init:{cur:s,charDir:n,VISITED:o}}){this._matrix=t,this._cur=s,this._character=new i(n,e),this.onMove=r,this.onMove&&this.onMove(this._cur),this._VISITED=o,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,i;const r=this._matrix,[s,n]=this._cur;switch(t){case"up":if(i=r[s-1],!i)return!1;e=i[n];break;case"right":e=r[s][n+1];break;case"down":if(i=r[s+1],!i)return!1;e=i[n];break;case"left":e=r[s][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,i]=this._cur;this._matrix[e][i]=this._VISITED,this.onMove&&this.onMove(this._cur)}}},6090:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Vector2D=void 0;class i{constructor(t=0,e=0,i=1){this.x=t,this.y=e,this.w=i}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 i(Math.round(this.x),Math.round(this.y))}static add(t,e){return new i(t.x+e.x,t.y+e.y)}static subtract(t,e){return new i(t.x-e.x,t.y-e.y)}static subtractValue(t,e){return new i(t.x-e,t.y-e)}static multiply(t,e){return new i(t.x*e,t.y*e)}static divide(t,e){return new i(t.x/e,t.y/e)}static equals(t,e){return t.x===e.x&&t.y===e.y}static equalsRounded(t,e,r=12){const s=i.abs(i.subtract(t,e));return s.x<r&&s.y<r}static normalize(t){const e=t.length;return e>2220446049250313e-31?i.divide(t,e):t}static truncate(t,e){return t.length>e?i.multiply(i.normalize(t),e):t}static perp(t){return new i(-t.y,t.x)}static reverse(t){return new i(-t.x,-t.y)}static abs(t){return new i(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 i=e.y-t.y,r=e.x-t.x;return Math.sqrt(i*i+r*r)}static distanceSq(t,e){const i=e.y-t.y,r=e.x-t.x;return i*i+r*r}static sign(t,e){return t.y*e.x>t.x*e.y?-1:1}static angle(t){const e=new i(0,-1),r=Math.acos(i.dot(t,e)/(t.length*e.length));return 1===i.sign(t,e)?2*Math.PI-r:r}static random(t,e){const r=Math.floor(Math.random()*t-t/2),s=Math.floor(Math.random()*e-e/2);return new i(r,s)}zero(){this.x=0,this.y=0}}e.Vector2D=i,e.default=i},7641:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(3491),e),s(i(7016),e),s(i(7021),e)},7021:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MaxPriorityQueue=void 0;const r=i(3491);class s extends r.PriorityQueue{constructor(t){super(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>e-t}))}static heapify(t){const e=new s(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>e-t}));return e._fix(),e}}e.MaxPriorityQueue=s},7016:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MinPriorityQueue=void 0;const r=i(3491);class s extends r.PriorityQueue{constructor(t){super(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>t-e}))}static heapify(t){const e=new s(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>t-e}));return e._fix(),e}}e.MinPriorityQueue=s},3491:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.PriorityQueue=void 0;class i{constructor(t){this._nodes=[],this._comparator=(t,e)=>t-e;const{nodes:e,comparator:i,isFix:r=!0}=t;this._comparator=i,e&&Array.isArray(e)&&e.length>0&&(this._nodes=[...e],r&&this._fix())}get nodes(){return this._nodes}get size(){return this.nodes.length}static heapify(t){const e=new i(t);return e._fix(),e}static isPriorityQueueified(t){return new i(Object.assign(Object.assign({},t),{isFix:!1})).isValid()}getNodes(){return this._nodes}add(t){this.nodes.push(t),this._heapifyUp(this.size-1)}has(t){return this.nodes.includes(t)}peek(){return this.size?this.nodes[0]:null}poll(){var t,e;let i=null;return this.size>1?(this._swap(0,this.nodes.length-1),i=null!==(t=this.nodes.pop())&&void 0!==t?t:null,this._heapifyDown(0)):1===this.size&&(i=null!==(e=this.nodes.pop())&&void 0!==e?e:null),i}leaf(){var t;return null!==(t=this.nodes[this.size-1])&&void 0!==t?t:null}isEmpty(){return 0===this.size}clear(){this._setNodes([])}toArray(){return[...this.nodes]}clone(){return new i({nodes:this.nodes,comparator:this._comparator})}isValid(){for(let t=0;t<this.nodes.length;t++){const e=this._getLeft(t),i=this._getRight(t);if(this._isValidIndex(e)&&!this._compare(e,t))return!1;if(this._isValidIndex(i)&&!this._compare(i,t))return!1}return!0}sort(){const t=[];for(;0!==this.size;){const e=this.poll();e&&t.push(e)}return t}DFS(t){const e=[],i=r=>{var s,n,o;const h=this._getLeft(r),l=this._getRight(r);switch(t){case"in":this._isValidIndex(h)&&i(h),e.push(null!==(s=this.nodes[r])&&void 0!==s?s:null),this._isValidIndex(l)&&i(l);break;case"pre":e.push(null!==(n=this.nodes[r])&&void 0!==n?n:null),this._isValidIndex(h)&&i(h),this._isValidIndex(l)&&i(l);break;case"post":this._isValidIndex(h)&&i(h),this._isValidIndex(l)&&i(l),e.push(null!==(o=this.nodes[r])&&void 0!==o?o:null)}};return this._isValidIndex(0)&&i(0),e}_setNodes(t){this._nodes=t}_compare(t,e){return this._comparator(this.nodes[t],this.nodes[e])>0}_swap(t,e){const i=this.nodes[t];this.nodes[t]=this.nodes[e],this.nodes[e]=i}_isValidIndex(t){return t>-1&&t<this.nodes.length}_getParent(t){return Math.floor((t-1)/2)}_getLeft(t){return 2*t+1}_getRight(t){return 2*t+2}_getComparedChild(t){let e=t;const i=this._getLeft(t),r=this._getRight(t);return i<this.size&&this._compare(e,i)&&(e=i),r<this.size&&this._compare(e,r)&&(e=r),e}_heapifyUp(t){for(;t>0&&this._compare(this._getParent(t),t);){const e=this._getParent(t);this._swap(t,e),t=e}}_heapifyDown(t){let e=this._getComparedChild(t);for(;this._compare(t,e);)this._swap(e,t),t=e,e=this._getComparedChild(t)}_fix(){for(let t=Math.floor(this.size/2);t>-1;t--)this._heapifyDown(t)}}e.PriorityQueue=i},7569:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ArrayDeque=e.ObjectDeque=e.Deque=void 0;const r=i(2324);class s extends r.DoublyLinkedList{}e.Deque=s,e.ObjectDeque=class{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}},e.ArrayDeque=class{constructor(){this._nodes=[]}get size(){return this._nodes.length}addLast(t){return this._nodes.push(t)}pollLast(){var t;return null!==(t=this._nodes.pop())&&void 0!==t?t:null}pollFirst(){var t;return null!==(t=this._nodes.shift())&&void 0!==t?t:null}addFirst(t){return this._nodes.unshift(t)}peekFirst(){var t;return null!==(t=this._nodes[0])&&void 0!==t?t:null}peekLast(){var t;return null!==(t=this._nodes[this._nodes.length-1])&&void 0!==t?t:null}get(t){var e;return null!==(e=this._nodes[t])&&void 0!==e?e:null}set(t,e){return this._nodes[t]=e}insert(t,e){return this._nodes.splice(t,0,e)}remove(t){return this._nodes.splice(t,1)}isEmpty(){return 0===this._nodes.length}}},2627:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(3295),e),s(i(7569),e)},3295:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Queue=e.LinkedListQueue=void 0;const r=i(2324);class s extends r.SinglyLinkedList{enqueue(t){this.push(t)}dequeue(){return this.shift()}peek(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}}e.LinkedListQueue=s;class n{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 n(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 n(this.nodes.slice(this.offset))}*[Symbol.iterator](){for(const t of this.nodes)yield t}}e.Queue=n},9509:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(6006),e)},6006:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Stack=void 0;class i{constructor(t){this._elements=Array.isArray(t)?t:[]}static fromArray(t){return new i(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 i(this._elements.slice())}}e.Stack=i},8456:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(301),e)},301:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TreeNode=void 0;class i{constructor(t,e,i){this._id=t,this._value=e||void 0,this._children=i||[]}get id(){return this._id}set id(t){this._id=t}get value(){return this._value}set value(t){this._value=t}get children(){return this._children}set children(t){this._children=t}addChildren(t){this.children||(this.children=[]),t instanceof i?this.children.push(t):this.children=this.children.concat(t)}getHeight(){const t=this;let e=1;if(t){const i=(t,r)=>{r>e&&(e=r);const{children:s}=t;if(s)for(let t=0,e=s.length;t<e;t++)i(s[t],r+1)};i(t,1)}return e}}e.TreeNode=i},3543:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(2952),e)},2952:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Trie=e.TrieNode=void 0;class i{constructor(t){this._val=t,this._isEnd=!1,this._children=new Map}get val(){return this._val}set val(t){this._val=t}get children(){return this._children}set children(t){this._children=t}get isEnd(){return this._isEnd}set isEnd(t){this._isEnd=t}}e.TrieNode=i,e.Trie=class{constructor(t){if(this._root=new i(""),t)for(const e of t)this.add(e)}get root(){return this._root}set root(t){this._root=t}add(t){let e=this._root;for(const r of t){let t=e.children.get(r);t||(t=new i(r),e.children.set(r,t)),e=t}return e.isEnd=!0,!0}has(t){let e=this._root;for(const i of t){const t=e.children.get(i);if(!t)return!1;e=t}return e.isEnd}remove(t){let e=!1;const i=(r,s)=>{const n=t[s],o=r.children.get(n);return!!o&&(s===t.length-1?!!o.isEnd&&(o.children.size>0?o.isEnd=!1:r.children.delete(n),e=!0,!0):!(!i(o,s+1)||r.isEnd||0!==o.children.size||(r.children.delete(n),0)))};return i(this.root,0),e}isAbsPrefix(t){let e=this._root;for(const i of t){const t=e.children.get(i);if(!t)return!1;e=t}return!e.isEnd}isPrefix(t){let e=this._root;for(const i of t){const t=e.children.get(i);if(!t)return!1;e=t}return!0}isCommonPrefix(t){let e="";const i=r=>{e+=r.val,e!==t&&(r.isEnd||r&&r.children&&1===r.children.size&&i(Array.from(r.children.values())[0]))};return i(this._root),e===t}getLongestCommonPrefix(){let t="";const e=i=>{t+=i.val,i.isEnd||i&&i.children&&1===i.children.size&&e(Array.from(i.children.values())[0])};return e(this._root),t}getAll(t=""){const e=[];let i=this._root;if(t)for(const e of t){const t=i.children.get(e);t&&(i=t)}return function t(i,r){for(const e of i.children.keys()){const s=i.children.get(e);void 0!==s&&t(s,r.concat(e))}i.isEnd&&e.push(r)}(i,t),e}}},3607:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(4866),e),s(i(5928),e),s(i(1247),e),s(i(1230),e)},8709:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1278:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},31:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},3108:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},257:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1265:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},4477:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},2338:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1247:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(8709),e),s(i(1278),e),s(i(31),e),s(i(3108),e),s(i(257),e),s(i(1265),e),s(i(4477),e),s(i(2338),e),s(i(8447),e),s(i(5785),e),s(i(7906),e),s(i(8759),e),s(i(2354),e),s(i(1515),e),s(i(9355),e)},8447:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},5785:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},7906:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},8759:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},2354:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1515:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},9355:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},5177:(t,e)=>{var i,r;Object.defineProperty(e,"__esModule",{value:!0}),e.FamilyPosition=e.LoopType=void 0,(r=e.LoopType||(e.LoopType={})).ITERATIVE="ITERATIVE",r.RECURSIVE="RECURSIVE",(i=e.FamilyPosition||(e.FamilyPosition={})).ROOT="ROOT",i.LEFT="LEFT",i.RIGHT="RIGHT",i.ROOT_LEFT="ROOT_LEFT",i.ROOT_RIGHT="ROOT_RIGHT",i.ISOLATED="ISOLATED",i.MAL_NODE="MAL_NODE"},4086:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},6603:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},2697:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},8222:(t,e)=>{var i;Object.defineProperty(e,"__esModule",{value:!0}),e.CP=void 0,(i=e.CP||(e.CP={})).lt="lt",i.eq="eq",i.gt="gt"},9388:(t,e)=>{var i;Object.defineProperty(e,"__esModule",{value:!0}),e.TopologicalProperty=void 0,(i=e.TopologicalProperty||(e.TopologicalProperty={})).VAL="VAL",i.NODE="NODE",i.ID="ID"},2835:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},8839:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},8720:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(2697),e),s(i(8222),e),s(i(6603),e),s(i(8542),e),s(i(3360),e),s(i(4086),e),s(i(6896),e),s(i(5177),e),s(i(1001),e),s(i(9388),e),s(i(1307),e),s(i(8839),e),s(i(6954),e),s(i(2835),e),s(i(4716),e)},6896:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},4716:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1307:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1001:(t,e)=>{var i;Object.defineProperty(e,"__esModule",{value:!0}),e.RBColor=void 0,(i=e.RBColor||(e.RBColor={})).RED="RED",i.BLACK="BLACK"},8542:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},6954:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},3360:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},5268:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},1230:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(8720),e),s(i(5268),e),s(i(9963),e)},9963:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(6016),e),s(i(6706),e)},6016:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},6706:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},5928:function(t,e,i){var r=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i);var s=Object.getOwnPropertyDescriptor(e,i);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,r,s)}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),s=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||r(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),s(i(974),e)},974:function(t,e){var i=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(s,n){function o(t){try{l(r.next(t))}catch(t){n(t)}}function h(t){try{l(r.throw(t))}catch(t){n(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,h)}l((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.trampolineAsync=e.trampoline=e.toThunk=e.isThunk=e.THUNK_SYMBOL=e.arrayRemove=e.uuidV4=void 0,e.uuidV4=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.arrayRemove=function(t,e){let i=-1,r=t?t.length:0;const s=[];for(;++i<r;){const n=t[i];e(n,i,t)&&(s.push(n),Array.prototype.splice.call(t,i--,1),r--)}return s},e.THUNK_SYMBOL=Symbol("thunk"),e.isThunk=t=>"function"==typeof t&&t.__THUNK__===e.THUNK_SYMBOL,e.toThunk=t=>{const i=()=>t();return i.__THUNK__=e.THUNK_SYMBOL,i},e.trampoline=t=>Object.assign(((...i)=>{let r=t(...i);for(;(0,e.isThunk)(r)&&"function"==typeof r;)r=r();return r}),{cont:(...i)=>(0,e.toThunk)((()=>t(...i)))}),e.trampolineAsync=t=>Object.assign(((...r)=>i(void 0,void 0,void 0,(function*(){let i=yield t(...r);for(;(0,e.isThunk)(i)&&"function"==typeof i;)i=yield i();return i}))),{cont:(...i)=>(0,e.toThunk)((()=>t(...i)))})}},e={},i=function i(r){var s=e[r];if(void 0!==s)return s.exports;var n=e[r]={exports:{}};return t[r].call(n.exports,n,n.exports,i),n.exports}(3607);window.dataStructureTyped=i})();
@@ -22,7 +22,7 @@ export declare class DoublyLinkedListNode<T = number> {
22
22
  get prev(): DoublyLinkedListNode<T> | null;
23
23
  set prev(value: DoublyLinkedListNode<T> | null);
24
24
  }
25
- export declare class DoublyLinkedList<T = number> {
25
+ export declare class DoublyLinkedList<T = any> {
26
26
  /**
27
27
  * The constructor initializes the linked list with an empty head, tail, and length.
28
28
  */
@@ -52,13 +52,13 @@ export declare class DoublyLinkedList<T = number> {
52
52
  * @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
53
53
  * list is empty, it returns null.
54
54
  */
55
- pop(): T | null;
55
+ pop(): T | undefined;
56
56
  /**
57
57
  * The `shift()` function removes and returns the value of the first node in a doubly linked list.
58
58
  * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
59
59
  * list.
60
60
  */
61
- shift(): T | null;
61
+ shift(): T | undefined;
62
62
  /**
63
63
  * The unshift function adds a new node with the given value to the beginning of a doubly linked list.
64
64
  * @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
@@ -72,7 +72,7 @@ export declare class DoublyLinkedList<T = number> {
72
72
  * @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
73
73
  * or the linked list is empty, it will return null.
74
74
  */
75
- getAt(index: number): T | null;
75
+ getAt(index: number): T | undefined;
76
76
  /**
77
77
  * The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
78
78
  * range.
@@ -107,7 +107,7 @@ export declare class DoublyLinkedList<T = number> {
107
107
  * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
108
108
  * bounds.
109
109
  */
110
- deleteAt(index: number): T | null;
110
+ deleteAt(index: number): T | undefined;
111
111
  delete(valOrNode: T): boolean;
112
112
  delete(valOrNode: DoublyLinkedListNode<T>): boolean;
113
113
  /**
@@ -100,7 +100,7 @@ class DoublyLinkedList {
100
100
  */
101
101
  pop() {
102
102
  if (!this.tail)
103
- return null;
103
+ return undefined;
104
104
  const removedNode = this.tail;
105
105
  if (this.head === this.tail) {
106
106
  this.head = null;
@@ -120,7 +120,7 @@ class DoublyLinkedList {
120
120
  */
121
121
  shift() {
122
122
  if (!this.head)
123
- return null;
123
+ return undefined;
124
124
  const removedNode = this.head;
125
125
  if (this.head === this.tail) {
126
126
  this.head = null;
@@ -160,7 +160,7 @@ class DoublyLinkedList {
160
160
  */
161
161
  getAt(index) {
162
162
  if (index < 0 || index >= this.length)
163
- return null;
163
+ return undefined;
164
164
  let current = this.head;
165
165
  for (let i = 0; i < index; i++) {
166
166
  current = current.next;
@@ -240,7 +240,7 @@ class DoublyLinkedList {
240
240
  */
241
241
  deleteAt(index) {
242
242
  if (index < 0 || index >= this.length)
243
- return null;
243
+ return undefined;
244
244
  if (index === 0)
245
245
  return this.shift();
246
246
  if (index === this.length - 1)
@@ -71,7 +71,7 @@ export declare class SinglyLinkedList<T = any> {
71
71
  * @returns The method `getAt(index: number): T | null` returns the value at the specified index in the linked list, or
72
72
  * `null` if the index is out of bounds.
73
73
  */
74
- getAt(index: number): T | null;
74
+ getAt(index: number): T | undefined;
75
75
  /**
76
76
  * The function `getNodeAt` returns the node at a given index in a singly linked list.
77
77
  * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
@@ -153,4 +153,5 @@ export declare class SinglyLinkedList<T = any> {
153
153
  * @returns The count of occurrences of the given value in the linked list.
154
154
  */
155
155
  countOccurrences(value: T): number;
156
+ [Symbol.iterator](): Generator<T, void, unknown>;
156
157
  }
@@ -153,7 +153,7 @@ class SinglyLinkedList {
153
153
  */
154
154
  getAt(index) {
155
155
  if (index < 0 || index >= this.length)
156
- return null;
156
+ return undefined;
157
157
  let current = this.head;
158
158
  for (let i = 0; i < index; i++) {
159
159
  current = current.next;
@@ -437,5 +437,12 @@ class SinglyLinkedList {
437
437
  }
438
438
  return count;
439
439
  }
440
+ *[Symbol.iterator]() {
441
+ let current = this.head;
442
+ while (current) {
443
+ yield current.val;
444
+ current = current.next;
445
+ }
446
+ }
440
447
  }
441
448
  exports.SinglyLinkedList = SinglyLinkedList;
@@ -4,7 +4,7 @@
4
4
  * @class
5
5
  */
6
6
  import { SinglyLinkedList } from '../linked-list';
7
- export declare class Queue<T = any> extends SinglyLinkedList<T> {
7
+ export declare class LinkedListQueue<T = any> extends SinglyLinkedList<T> {
8
8
  /**
9
9
  * The enqueue function adds a value to the end of an array.
10
10
  * @param {T} value - The value parameter represents the value that you want to add to the queue.
@@ -20,11 +20,8 @@ export declare class Queue<T = any> extends SinglyLinkedList<T> {
20
20
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
21
21
  */
22
22
  peek(): T | undefined;
23
- [Symbol.iterator](): Generator<T, void, unknown>;
24
23
  }
25
- export declare class ArrayQueue<T = number> {
26
- protected _nodes: T[];
27
- protected _offset: number;
24
+ export declare class Queue<T = any> {
28
25
  /**
29
26
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
30
27
  * @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
@@ -32,6 +29,12 @@ export declare class ArrayQueue<T = number> {
32
29
  * initialized as an empty array.
33
30
  */
34
31
  constructor(elements?: T[]);
32
+ private _nodes;
33
+ get nodes(): T[];
34
+ set nodes(value: T[]);
35
+ private _offset;
36
+ get offset(): number;
37
+ set offset(value: number);
35
38
  /**
36
39
  * The size function returns the number of elements in an array.
37
40
  * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
@@ -45,31 +48,31 @@ export declare class ArrayQueue<T = number> {
45
48
  * @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
46
49
  * array.
47
50
  */
48
- static fromArray<T>(elements: T[]): ArrayQueue<T>;
51
+ static fromArray<T>(elements: T[]): Queue<T>;
49
52
  /**
50
53
  * The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
51
54
  * @param {T} element - The `element` parameter represents the element that you want to add to the queue.
52
55
  * @returns The `add` method is returning a `Queue<T>` object.
53
56
  */
54
- push(element: T): ArrayQueue<T>;
57
+ push(element: T): Queue<T>;
55
58
  /**
56
59
  * The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
57
60
  * necessary to optimize performance.
58
61
  * @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
59
62
  */
60
- shift(): T | null;
63
+ shift(): T | undefined;
61
64
  /**
62
65
  * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
63
66
  * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
64
67
  * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
65
68
  */
66
- peek(): T | null;
69
+ peek(): T | undefined;
67
70
  /**
68
71
  * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
69
72
  * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
70
73
  * array is empty, it returns `null`.
71
74
  */
72
- peekLast(): T | null;
75
+ peekLast(): T | undefined;
73
76
  /**
74
77
  * The enqueue function adds a value to the end of a queue.
75
78
  * @param {T} value - The value parameter represents the value that you want to add to the queue.
@@ -79,7 +82,8 @@ export declare class ArrayQueue<T = number> {
79
82
  * The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
80
83
  * @returns The method is returning a value of type T or null.
81
84
  */
82
- dequeue(): T | null;
85
+ dequeue(): T | undefined;
86
+ getAt(index: number): T | undefined;
83
87
  /**
84
88
  * The function checks if a data structure is empty by comparing its size to zero.
85
89
  * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
@@ -98,5 +102,6 @@ export declare class ArrayQueue<T = number> {
98
102
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
99
103
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
100
104
  */
101
- clone(): ArrayQueue<T>;
105
+ clone(): Queue<T>;
106
+ [Symbol.iterator](): Generator<T, void, unknown>;
102
107
  }
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayQueue = exports.Queue = void 0;
3
+ exports.Queue = exports.LinkedListQueue = void 0;
4
4
  /**
5
5
  * @license MIT
6
6
  * @copyright Tyler Zeng <zrwusa@gmail.com>
7
7
  * @class
8
8
  */
9
9
  const linked_list_1 = require("../linked-list");
10
- class Queue extends linked_list_1.SinglyLinkedList {
10
+ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
11
11
  /**
12
12
  * The enqueue function adds a value to the end of an array.
13
13
  * @param {T} value - The value parameter represents the value that you want to add to the queue.
@@ -30,16 +30,9 @@ class Queue extends linked_list_1.SinglyLinkedList {
30
30
  var _a;
31
31
  return (_a = this.head) === null || _a === void 0 ? void 0 : _a.val;
32
32
  }
33
- *[Symbol.iterator]() {
34
- let current = this.head;
35
- while (current) {
36
- yield current.val;
37
- current = current.next;
38
- }
39
- }
40
33
  }
41
- exports.Queue = Queue;
42
- class ArrayQueue {
34
+ exports.LinkedListQueue = LinkedListQueue;
35
+ class Queue {
43
36
  /**
44
37
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
45
38
  * @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
@@ -50,12 +43,24 @@ class ArrayQueue {
50
43
  this._nodes = elements || [];
51
44
  this._offset = 0;
52
45
  }
46
+ get nodes() {
47
+ return this._nodes;
48
+ }
49
+ set nodes(value) {
50
+ this._nodes = value;
51
+ }
52
+ get offset() {
53
+ return this._offset;
54
+ }
55
+ set offset(value) {
56
+ this._offset = value;
57
+ }
53
58
  /**
54
59
  * The size function returns the number of elements in an array.
55
60
  * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
56
61
  */
57
62
  get size() {
58
- return this._nodes.length - this._offset;
63
+ return this.nodes.length - this.offset;
59
64
  }
60
65
  /**
61
66
  * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
@@ -66,7 +71,7 @@ class ArrayQueue {
66
71
  * array.
67
72
  */
68
73
  static fromArray(elements) {
69
- return new ArrayQueue(elements);
74
+ return new Queue(elements);
70
75
  }
71
76
  /**
72
77
  * The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
@@ -74,7 +79,7 @@ class ArrayQueue {
74
79
  * @returns The `add` method is returning a `Queue<T>` object.
75
80
  */
76
81
  push(element) {
77
- this._nodes.push(element);
82
+ this.nodes.push(element);
78
83
  return this;
79
84
  }
80
85
  /**
@@ -84,15 +89,15 @@ class ArrayQueue {
84
89
  */
85
90
  shift() {
86
91
  if (this.size === 0)
87
- return null;
92
+ return undefined;
88
93
  const first = this.peek();
89
- this._offset += 1;
90
- if (this._offset * 2 < this._nodes.length)
94
+ this.offset += 1;
95
+ if (this.offset * 2 < this.nodes.length)
91
96
  return first;
92
97
  // only remove dequeued elements when reaching half size
93
98
  // to decrease latency of shifting elements.
94
- this._nodes = this._nodes.slice(this._offset);
95
- this._offset = 0;
99
+ this.nodes = this.nodes.slice(this.offset);
100
+ this.offset = 0;
96
101
  return first;
97
102
  }
98
103
  /**
@@ -101,7 +106,7 @@ class ArrayQueue {
101
106
  * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
102
107
  */
103
108
  peek() {
104
- return this.size > 0 ? this._nodes[this._offset] : null;
109
+ return this.size > 0 ? this.nodes[this.offset] : undefined;
105
110
  }
106
111
  /**
107
112
  * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
@@ -109,7 +114,7 @@ class ArrayQueue {
109
114
  * array is empty, it returns `null`.
110
115
  */
111
116
  peekLast() {
112
- return this.size > 0 ? this._nodes[this._nodes.length - 1] : null;
117
+ return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
113
118
  }
114
119
  /**
115
120
  * The enqueue function adds a value to the end of a queue.
@@ -125,6 +130,9 @@ class ArrayQueue {
125
130
  dequeue() {
126
131
  return this.shift();
127
132
  }
133
+ getAt(index) {
134
+ return this.nodes[index];
135
+ }
128
136
  /**
129
137
  * The function checks if a data structure is empty by comparing its size to zero.
130
138
  * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
@@ -137,21 +145,26 @@ class ArrayQueue {
137
145
  * @returns An array of type T is being returned.
138
146
  */
139
147
  toArray() {
140
- return this._nodes.slice(this._offset);
148
+ return this.nodes.slice(this.offset);
141
149
  }
142
150
  /**
143
151
  * The clear function resets the nodes array and offset to their initial values.
144
152
  */
145
153
  clear() {
146
- this._nodes = [];
147
- this._offset = 0;
154
+ this.nodes = [];
155
+ this.offset = 0;
148
156
  }
149
157
  /**
150
158
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
151
159
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
152
160
  */
153
161
  clone() {
154
- return new ArrayQueue(this._nodes.slice(this._offset));
162
+ return new Queue(this.nodes.slice(this.offset));
163
+ }
164
+ *[Symbol.iterator]() {
165
+ for (const item of this.nodes) {
166
+ yield item;
167
+ }
155
168
  }
156
169
  }
157
- exports.ArrayQueue = ArrayQueue;
170
+ exports.Queue = Queue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Data Structures of Javascript & TypeScript. AVLTree, Binary Search Tree, Binary Tree, Tree Multiset, Graph, Heap, Priority Queue, Linked List.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -19,19 +19,26 @@
19
19
  "url": "git+https://github.com/zrwusa/data-structure-typed.git"
20
20
  },
21
21
  "keywords": [
22
+ "data structure",
22
23
  "Data Structure",
23
24
  "data-structure",
25
+ "data structures",
24
26
  "Data Structures",
25
27
  "data-structures",
26
28
  "algorithm",
29
+ "binary search tree",
27
30
  "Binary Search Tree",
28
31
  "binary-search-tree",
32
+ "binary tree",
29
33
  "Binary Tree",
30
34
  "binary-tree",
35
+ "bst",
31
36
  "BST",
32
37
  "AVL Tree",
38
+ "avl tree",
33
39
  "avl-tree",
34
40
  "avl",
41
+ "tree multiset",
35
42
  "Tree Multiset",
36
43
  "tree-multiset",
37
44
  "Tree Multiset",
@@ -43,21 +50,31 @@
43
50
  "BFS",
44
51
  "graph",
45
52
  "Graph",
53
+ "directed graph",
46
54
  "Directed Graph",
47
55
  "directed-graph",
56
+ "undirected graph",
48
57
  "Undirected Graph",
49
58
  "undirected-graph",
59
+ "heap",
50
60
  "Heap",
61
+ "priority queue",
51
62
  "Priority Queue",
52
63
  "priority-queue",
64
+ "max priority queue",
53
65
  "Max Priority Queue",
54
66
  "max-priority-queue",
67
+ "min priority queue",
55
68
  "Min Priority Queue",
56
69
  "min-priority-queue",
70
+ "deque",
57
71
  "Deque",
72
+ "linked list",
58
73
  "Linked List",
59
74
  "linked-list",
75
+ "trie",
60
76
  "Trie",
77
+ "prefix tree",
61
78
  "Prefix Tree",
62
79
  "prefix-tree",
63
80
  "binary",
@@ -66,26 +83,47 @@
66
83
  "data",
67
84
  "structure",
68
85
  "sort",
86
+ "segment tree",
69
87
  "Segment Tree",
70
88
  "segment-tree",
89
+ "binary indexed tree",
71
90
  "Binary Indexed Tree",
72
91
  "binary-indexed-tree",
92
+ "linked list",
73
93
  "Linked List",
74
94
  "linked-list",
95
+ "singly linked list",
75
96
  "Singly Linked List",
76
97
  "singly-linked-list",
98
+ "doubly linked list",
77
99
  "Doubly Linked List",
78
100
  "doubly-linked-list",
101
+ "queue",
102
+ "array queue",
103
+ "Array Queue",
104
+ "array-queue",
79
105
  "Queue",
106
+ "object deque",
80
107
  "Object Deque",
108
+ "array deque",
81
109
  "Array Deque",
110
+ "stack",
82
111
  "Stack",
112
+ "hash",
83
113
  "Hash",
84
114
  "morris",
85
- "Bellman-Ford ",
86
- "Dijkstra's Algorithm",
87
- "Floyd-Warshall Algorithm",
88
- "Tarjan's Algorithm"
115
+ "Morris",
116
+ "bellman ford",
117
+ "Bellman Ford",
118
+ "bellman-ford",
119
+ "dijkstra",
120
+ "Dijkstra",
121
+ "floyd warshall",
122
+ "Floyd Warshall",
123
+ "floyd-warshall",
124
+ "Tarjan",
125
+ "tarjan",
126
+ "Tarjan's"
89
127
  ],
90
128
  "author": "Tyler Zeng zrwusa@gmail.com",
91
129
  "license": "MIT",