UNPKG

ts-ds-tool

Version:

Data structure and algorithm of TypeScript

25 lines 65 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.DataStructure={})}(this,function(t){"use strict";function e(t,e){return t<=e}function r(t,e){return t<=e}function n(t){for(var e=0,r=0;r<t.length;r++)e=31*e+t.charCodeAt(r)|0;return a(e)}function i(t){var e=typeof t;return"string"===e?t:"number"===e||"boolean"===e||"function"===e?""+t:JSON.stringify(t)}function o(t,e,r){return r?t[r]>=e[r]:t>=e}function u(t,e){return t===e?0:t>e?1:-1}function s(t,e,r){var n=t[r];t[r]=t[e],t[e]=n}function a(t){return t>>>1&1073741824|3221225471&t}function h(t){Object.defineProperty(t,"toString",{value:function(){return JSON.stringify(this)}})}function f(t){return t?t.Color:Gt.Black}function p(t){return null==t?null:t.Left}function c(t){return t?t.parent:null}function l(t){return t?t.Right:null}function d(t,e){t&&t.setColor(e)}function g(t,e){if(!t||!t.length)return-1;for(var r=0,n=t.length-1,i="function"==typeof e?e:function(t){return u(e,t)};r<=n;){var o=parseInt(""+(r+n)/2,10),s=i(t[o]);if(0===s)return o;1===s?r=o+1:n=o-1}return-1}function y(t){for(var e=[0],r=1,n=0;r<t.length;)t[n]===t[r]?(e[r]=n+1,n++,r++):0===n?(e[r]=0,r++):n=e[n-1];return e}function v(t,e){if(null===t||void 0===t)return-1;if(null===e||void 0===e)return-1;if(0===e.length)return 0;for(var r=y(e),n=0,i=0;i<t.length;)if(t[i]===e[n]){if(n===e.length-1)return i-n;i++,n++}else n>0?n=r[n-1]:(n=0,i++);return-1}function N(t,e){if(!t||!e)return"";for(var r=t.length,n=e.length,i=Array(r+1),o=0;o<=r;o++)i[o]=Array(n+1).fill(0);for(var u=1;u<=r;u++)for(var s=1;s<=n;s++)i[u][s]=t[u-1]===e[s-1]?i[u-1][s-1]+1:Math.max(i[u][s-1],i[u-1][s]);if(!i[r][n])return"";for(var a=r,h=n,f=[];a>0&&h>0;)t[a-1]===e[h-1]?(f.unshift(t[a-1]),a--,h--):i[a][h]===i[a][h-1]?h--:a--;return f.join("")}function x(t,e){if(!t||!e)return"";for(var r=t.length,n=e.length,i=Array(r+1),o=0;o<=r;o++)i[o]=Array(n+1).fill(0);for(var u=0,s=0,a=0,h=1;h<=r;h++)for(var f=1;f<=n;f++)t[h-1]===e[f-1]&&(i[h][f]=i[h-1][f-1]+1), i[h][f]>a&&(a=i[h][f],s=h,u=f);for(var p=[];i[s][u]>0;)p.unshift(t[s-1]),s--,u--;return p.join("")}function m(t,e){if(!t||!e)return"";for(var r=t.length,n=e.length,i=Array(n+1).fill(0),o=Array(n+1).fill(0),u=0,s=0,a=1;a<=r;a++){for(var h=1;h<=n;h++)(i[h]=t[a-1]===e[h-1]?o[h-1]+1:0)>s&&(s=i[h],u=h);for(var f=0;f<i.length;f++)o[f]=i[f]}for(var p=[];s>0;)p.unshift(e[u-1]),u--,s--;return p.join("")}function b(t,e){for(var r=t.length,n=e.length,i=Array(r+1).fill(0).map(function(){return Array(n+1).fill(0)}),o=0;o<=r;o++)i[o][0]=o;for(var u=0;u<=n;u++)i[0][u]=u;for(var s=1;s<=r;s++)for(var a=1;a<=n;a++){var h=t[s-1]===e[a-1]?0:1;i[s][a]=Math.min(i[s][a-1]+1,i[s-1][a]+1,i[s-1][a-1]+h)}return i[r][n]}function k(t,e){if(!t||!t.length)return{low:-1,high:-1,sum:-(1/0)};for(var r,n,i=0,o=-(1/0),u=0,s=0;s<t.length;s++){var a=e?t[s][e]:t[s];i+a>a?i+=a:(i=a,u=s),i>o&&(o=i,n=s,r=u)}return{low:r,high:n,sum:o}}function L(t,e){return t&&t.length?R(t,0,t.length-1,e):{low:-1,high:-1,sum:-(1/0)}}function R(t,e,r,n){var i=V(n);if(e===r)return{low:e,high:r,sum:i(t[e])};var o=Math.floor((e+r)/2),u=R(t,e,o,n),s=R(t,o+1,r,n),a=E(t,e,o,r,n);return u.sum>=s.sum&&u.sum>=a.sum?u:s.sum>=u.sum&&s.sum>=a.sum?s:a}function V(t){return t?function(e){return e[t]}:function(t){return t}}function E(t,e,r,n,i){for(var o,u=V(i),s=-(1/0),a=0,h=r;h>=e;h--)(a+=u(t[h]))>s&&(s=a,o=h);for(var f,p=-(1/0),c=0,l=r+1;l<=n;l++)(c+=u(t[l]))>p&&(p=c,f=l);return{low:o,high:f,sum:s+p}}function K(t,e){if(void 0===e&&(e=o),!t||!t.length)return null;var r,n,i=t.length,u=0;1&i?(u=1,r=n=t[0]):(u=2,r=e(t[0],t[1])?t[1]:t[0],n=r===t[0]?t[1]:t[0]);for(var s,a,h=u;h<i;h+=2){var f=t[h],p=t[h+1];e(f,p)?(s=p,a=f):(s=f,a=p),e(a,n)&&(n=a),e(r,s)&&(r=s)}return{min:r,max:n}}function S(t,e){if(e||(e=t.getVertexs()[0]),!e||!t.findVertex(e.Key))return{};for(var r=t.getVertexs(),n=new Mt(r.length),i=new Mt(r.length),o=0,u=r;o<u.length;o+=1){var s=u[o];s===e?n.put(s.Key,0):n.put(s.Key,1/0)}for(var a=t.getEdges(),h=0,f=r;h<f.length;h+=1)for(var p=0,c=a;p<c.length;p+=1){ var l=c[p],d=n.get(l.StartVertex.Key),g=l.EndVertex;n.get(g.Key)>d+l.Weight&&(i.put(g.Key,l.StartVertex),n.put(g.Key,d+l.Weight))}for(var y=0,v=a;y<v.length;y+=1){var N=v[y],x=n.get(N.StartVertex.Key);if(n.get(N.EndVertex.Key)>x+N.Weight)throw Error("Graph contains negative weight cycle")}var m=i.keys(),b=m.reduce(function(t,e){return t[e]=i.get(e).Key,t},{});return{distance:n.keys().reduce(function(t,e){return t[e]=n.get(e),t},{}),prev:b}}function w(t,e){if(e||(e=t.getVertexs()[0]),!e||!t.findVertex(e.Key))return[];var r=new mt;r.enqueue(e);for(var n=new Mt(t.getKeys().length),i=[];!r.isEmpty();){var o=r.dequeue();n.put(o.Key,!0),i.push(o.Node);for(var u=o.getNeighbors(),s=0,a=u;s<a.length;s+=1){var h=a[s];n.get(h.Key)||r.enqueue(h)}}return i}function _(t,e,r,n){if(e||(e=t.getVertexs()[0]),!e||!t.findVertex(e.Key))return[];var i=[];i.push(e);for(var o=new Mt(t.getKeys().length),u=[];i.length;){var s=i.pop();o.get(s.Key)||(r&&r(s),u.push(s.Node),n&&n(s),o.put(s.Key,!0));for(var a=s.getNeighbors().reverse(),h=0,f=a;h<f.length;h+=1){var p=f[h];o.get(p.Key)||i.push(p)}}return u}function P(t,e){if(e||(e=t.getVertexs()[0]),!e||!t.findVertex(e.Key))return{};var r=t.getVertexs(),n=new Mt(r.length),i=new Mt(r.length),o=new Mt(r.length);o.put(e.Key,e);for(var u=0,s=r;u<s.length;u+=1){var a=s[u];a.Key===e.Key?n.put(a.Key,0):n.put(a.Key,1/0)}var h=new It;h.enqueue(e,0);for(;!h.isEmpty();)!function(){var t=h.dequeue().Value,e=n.get(t.Key);t.getNeighbors().forEach(function(r){if(!i.get(r.Key)){var u=n.get(r.Key),s=t.getEdge(r.Key).Weight;u>e+s&&(n.put(r.Key,e+s),h.has(r)&&(h.changePriority(r,e+s),o.put(r.Key,t))),h.has(r)||(h.enqueue(r,-n.get(r.Key)),o.put(r.Key,t))}}),i.put(t.Key,!0)}();return{distance:n.keys().reduce(function(t,e){return t[e]=n.get(e),t},{}),prev:o.keys().reduce(function(t,e){return t[e]=o.get(e).Key,t},{})}}function C(t,e){if(e||(e=t.getVertexs()[0]),!e||!t.findVertex(e.Key))return{};for(var r=t.toAdjacencyMatrix(),n=r.matrix,i=0;i<n.length;i++)for(var o=0;o<n.length;o++){ for(var u=0;u<n.length;u++)n[o][u]>n[o][i]+n[i][u]&&(n[o][u]=n[o][i]+n[i][u]);if(n[o][o]<0)throw Error("Graph contains negative weight cycle")}var s=r.keyIndexs,a=s[e.Key],h={};for(var f in s)h[f]=n[a][s[f]];return{distance:h}}function A(t,e){function r(t,e){var u=t.getNeighbors();n.add(t.Key),u.forEach(function(u){if(u.Key!==e){var s=JSON.stringify([t.Key,u.Key].sort(function(t,e){return t>e?1:-1}));i.has(s)||(n.has(u.Key)?o.push(t.getEdge(u.Key)):(n.add(u.Key),r(u,t.Key),o.push(t.getEdge(u.Key))),i.add(s))}})}if(!t)return[];if(e||(e=t.getVertexs()[0]),!e||!t.findVertex(e.Key))return[];var n=new qt,i=new qt,o=[];return r(e),o.reverse()}function T(t){var e=t.getVertexs(),r=new me;e.forEach(function(t){var e=t.getNeighbors();e&&e.length?e.forEach(function(e){var n=t,i=e;r.find(n.Key)||r.makeSet(n.Key),r.find(i.Key)||r.makeSet(i.Key),r.union(n.Key,i.Key)}):r.makeSet(t.Key)});var n=r.RootItems;return!(Object.keys(n).length>1)}function O(t){return!!t&&(!t.Directed&&(!!T(t)&&t.getVertexs().every(function(t){return!(1&t.getDegree())})))}function z(t){if(!t)return!1;if(!t.Directed)return!1;var e=t.getVertexs();return w(t).length===e.length&&e.every(function(t){return t.getInDegree()===t.getOutDegree()})}function j(t){for(var e=t.getEdges().sort(function(t,e){return t.Weight>e.Weight?1:-1}),r=t.getVertexs().length,n=[],i=[],o=new me,u=0,s=e;u<s.length;u+=1){var a=s[u];if(o.find(a.StartVertex.Key)||(o.makeSet(a.StartVertex.Key),n.push(a.StartVertex)),o.find(a.EndVertex.Key)||(o.makeSet(a.EndVertex.Key),n.push(a.EndVertex)),o.inSameSet(a.StartVertex.Key,a.EndVertex.Key)||(o.union(a.StartVertex.Key,a.EndVertex.Key),i.push(a)),i.length===r-1)break}return{visitedVertices:n,visitedEdges:i}}function H(t){function e(){for(var t,r,n=1/0,s=0,a=o;s<a.length;s+=1)for(var h=a[s],f=h.getEdges().getHeadNode();f;){var p=f.Value;!i.has(p.EndVertex.Key)&&f.Value.Weight<n&&(n=f.Value.Weight,t=f.Value.EndVertex,r=p),f=f.Next}t&&(i.add(t.Key),o.push(t),u.push(r),e())}var r=t.getEdges(),n=r.reduce(function(t,e){ return null===t?e:e.Weight<t.Weight?e:t},null).StartVertex,i=new qt,o=[n],u=[];return i.add(n.Key),e(),i.clear(),{visitedVertices:o,visitedEdges:u}}function I(t){function e(t,r,n,u,s){if(void 0===n&&(n=new Mt),void 0===u&&(u=new Mt),void 0===s&&(s=1),!o.get(t.Key)){s++,r.push(t),n.put(t.Key,s),u.put(t.Key,s);t.getNeighbors().forEach(function(i){if(n.get(i.Key)||e(i,r,n,u,s),!o.get(i.Key)){var a=u.get(i.Key),h=u.get(t.Key);u.put(t.Key,Math.min(h,a))}});if(u.get(t.Key)===n.get(t.Key)){var a,h=[];do{a=r.pop().Key,o.put(a,!0),h.push(a)}while(a!==t.Key);i.push(h)}}}var r=t.getVertexs(),n=[],i=[],o=new Mt;return r.forEach(function(t){return e(t,n)}),i}function B(t){if(!t)return null;var e=new It,r=t.getVertexs();if(r.length<=1)return{cost:0,path:[]};e.enqueue({vertex:r[0],visitedKeys:[]},-M(r));for(var n,i=F(r[0],r.length);!e.isEmpty();)!function(){var o=e.dequeue(),u=o.Value,s=o.Priority,a=u.vertex,h=[].concat(u.visitedKeys);h.push(a.Key);var f=qt.fromArray(h),p=!0;a.getNeighbors().forEach(function(n){if(!f.has(n.Key)){p=!1;var o=D(t,h,n,r);o<=i&&e.enqueue({vertex:n,visitedKeys:h},-o)}}),p&&i<=Math.abs(s)&&(i=Math.abs(s),n=h)}();return{cost:i,path:n}}function D(t,e,r,n){for(var i=0,o=0;o<e.length-1;o++){i+=t.findVertex(e[o]).getEdge(e[o+1]).Weight}var u=t.findVertex(e[0]);i+=t.findVertex(e[e.length-1]).getEdge(r.Key).Weight,i*=2;var s=qt.fromArray(e);s.add(r.Key);var a=U(u,s),h=U(r,s);return h||(a=h=r.getEdge(e[0])),a?(i+=a.Weight+h.Weight,n.forEach(function(t){if(!s.has(t.Key)){var e=q(W(t.getEdges()));i+=e.firstMin.Weight+e.secondMin.Weight}}),i/2):1/0}function W(t){for(var e=t.getHeadNode(),r=[];e;)r.push(e.Value),e=e.Next;return r}function M(t){return t.reduce(function(t,e){var r=q(W(e.getEdges()));return t+(r.firstMin.Weight+r.secondMin.Weight)},0)/2}function F(t,e){var r,n=t,i=new qt(e);i.add(n.Key);for(var o=1,u=0;o<e;){if(!(r=U(n,i)))throw Error("the graph is not connected");n=r.EndVertex,i.add(n.Key),u+=r.Weight,o++}var s=n.getEdge(t.Key);if(!s)throw Error("the graph is not connected");return u+=s.Weight, i.clear(),u}function U(t,e){for(var r,n=t.getEdges().getHeadNode();n;){var i=n.Value;n=n.Next,e.has(i.EndVertex.Key)||(!r||r.Weight>i.Weight)&&(r=i)}return r}function q(t){if(!t.length)throw Error("the vertex hasn't edges");var e,r,n=t.length,i=0;1&n?(i=1,e=r=t[0]):(i=2,e=t[1].Weight>t[0].Weight?t[1]:t[0],r=e===t[0]?t[1]:t[0]);for(var o,u,s=i;s<t.length;s+=2){var a=t[i],h=t[i+1];a.Weight>h.Weight?(o=h,u=a):(o=a,u=h),o.Weight>r.Weight||(u.Weight<=e.Weight?(e=o,r=u):r=o)}return{firstMin:e,secondMin:r}}function G(t,e){if(!t||!t.length)return t;for(var r=t.length,n=0;n<r-1;n++)for(var i=0;i<r-1-n;i++){var o=e?t[i][e]>t[i+1][e]:t[i]>t[i+1];o&&s(t,i,i+1)}return t}function J(t,e){if(!t||!t.length)return t;for(var r=t.length,n=1;n<r;n++)for(var i=n;i>0;){var o=t[i],u=t[i-1],a=e?o[e]<u[e]:o<u;a&&s(t,i,i-1),i--}return t}function Z(t,e){if(!t||!t.length)return t;var r=t.length;if(r<2)return t;var n=Math.floor(r/2),i=t.slice(0,n),o=t.slice(n);return function(t,e,r){for(var n=[];t.length>0&&e.length>0;){n.push((r?t[0][r]<=e[0][r]:t[0]<=e[0])?t.shift():e.shift())}for(;t.length;)n.push(t.shift());for(;e.length;)n.push(e.shift());return n}(this.mergeSort(i,e),this.mergeSort(o,e),e)}function Q(t,e){function r(t,n,i){if(!(n>=i)){for(var u=n,s=i,a=t[n];n<i;){for(;n<i&&o(t[i],a,e);)--i;for(t[n]=t[i];n<i&&!o(t[n],a,e);)++n;t[i]=t[n]}t[n]=a,r(t,u,n-1),r(t,n+1,s)}}return r(t,0,t.length-1),t}function X(t,e){if(!t||!t.length)return t;for(var r,n=t.length,i=0;i<n;i++){r=i;for(var o=i;o<n;o++){var u=t[r],a=t[o];(e?u[e]>a[e]:u>a)&&(r=o)}s(t,i,r)}return t}function Y(t,e){if(!t||!t.length)return t;for(var r=t.length,n=1;Math.floor(r/(2*n));){for(var i=Math.floor(r/(2*n)),o=0;o<2*n;o++)for(var u=o;u+i<r;){var a=t[u],h=t[u+i],f=e?h[e]<a[e]:h<a;f&&s(t,u,u+i),u+=i}n++}}function $(t,e){if(1===e)return t.map(function(t){return[t]});var r=[];return t.forEach(function(n,i){$(t.slice(i+1),e-1).forEach(function(t){r.push([n].concat(t))})}),r}function tt(t,e){if(1===e)return t.map(function(t){return[t]});var r=[];return t.forEach(function(n,i){ $(t.slice(i),e-1).forEach(function(t){r.push([n].concat(t))})}),r}function et(t,e){return 0===e?t:et(e,t%e)}function rt(t,e){var r=et(t,e);return r*(t/r)*(e/r)}function nt(t,e){if(1===e)return t.map(function(t){return[t]});var r=[];return t.forEach(function(n,i){var o=[].concat(t);o.splice(i,1),nt(o,e-1).forEach(function(t){r.push([n].concat(t))})}),r}function it(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=[]),void 0===n&&(n=0),0===n&&e.push([]);for(var i=n;i<t.length;i++)r.push(t[i]),e.push([].concat(r)),it(t,e,r,i+1),r.pop();return e}var ot=function(t){this.array=t,this.index=0},ut={Current:{configurable:!0}};ot.prototype.next=function(){return this.index++,this},ut.Current.get=function(){return{value:this.array[this.index],done:!(this.array.length>0)||this.index===this.array.length-1}},Object.defineProperties(ot.prototype,ut);var st=function(){};st.prototype.getEnumerator=function(){return new ot(this.toArray())},st.prototype.toArray=function(){var t=[];return this.__iterate(function(e,r){t[r]=e}),t};var at=function(t,e,r){void 0===e&&(e=null),void 0===r&&(r=null),this.value=t,this.next=e,this.prev=r},ht={Value:{configurable:!0},Next:{configurable:!0},Prev:{configurable:!0}};ht.Value.get=function(){return this.value},ht.Next.get=function(){return this.next},ht.Prev.get=function(){return this.prev},at.prototype.setValue=function(t){this.value=t},at.prototype.setNext=function(t){this.next=t,t&&(t.prev=this)},at.prototype.toString=function(){return""+this.value},Object.defineProperties(at.prototype,ht);var ft=function(t){function e(){t.call(this),this.headNode=null,this.tailNode=null,this.size=0}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={Size:{configurable:!0}};return r.Size.get=function(){return this.size},e.prototype.append=function(t){if(this.size++,!this.headNode)return this.headNode=this.tailNode=new at(t,null,null);if(this.headNode===this.tailNode)return this.tailNode=new at(t),this.headNode.setNext(this.tailNode),this.headNode;var e=new at(t) ;return this.tailNode.setNext(e),this.tailNode=e,this.headNode},e.prototype.prepend=function(t){if(this.headNode){var e=this.headNode;this.headNode=new at(t),this.headNode.setNext(e)}else this.headNode=this.tailNode=new at(t);return this.size++,this.headNode},e.prototype.emptyList=function(){this.headNode=this.tailNode=null,this.size=0},e.prototype.clear=function(){this.emptyList()},e.prototype.deleteNode=function(t){for(var e,r=this,n=this.headNode,i=!1;n;){if(("function"==typeof t?t(n.Value):n.Value===t)&&(r.size--,i=!0,n===r.headNode?r.headNode=n.Next:n===r.tailNode?(e.setNext(null),r.tailNode=e):e.setNext(n.Next)),n.Next&&n.Next===r.headNode)break;if(0===r.size){r.emptyList();break}e=n,n=n.Next}return i},e.prototype.findNode=function(t){for(var e,r=this.headNode;r;){if("function"==typeof t?t(r.Value):r.Value===t){e=r;break}r=r.Next}return e},e.prototype.insertAfter=function(t,e){var r=new at(t);if(e){var n=e.Next;return n||(this.tailNode=r),r.setNext(n),e.setNext(r),!0}return!1},e.prototype.getHeadNode=function(){return this.headNode},e.prototype.getTailNode=function(){return this.tailNode},e.prototype.shift=function(){if(0===this.size)return null;1===this.size&&(this.tailNode=null);var t=this.headNode;return this.headNode=t.Next,this.size--,t},e.prototype.pop=function(){var t,e,r=this,n=this.headNode;if(0===this.size)return null;if(1===this.size)t=this.headNode,this.emptyList();else{for(;n;){if(!n.Next){t=n,r.tailNode=e,e.setNext(null);break}e=n,n=n.Next}this.size--}return t},e.prototype.__iterate=function(t){for(var e=this,r=this.headNode,n=0;r;){t(r,n),n++;var i=r.Next;if(!i||i===e.headNode)break;r=i}},e.prototype.toString=function(){return""+this.toArray().map(function(t){return""+t})},e.fromArray=function(t){if(!t)return new e;var r=new e;return t.forEach(function(t){r.append(t)}),r},Object.defineProperties(e.prototype,r),e}(st),pt=function(t,e){void 0===e&&(e=null),this.value=t,this.next=e},ct={Value:{configurable:!0},Next:{configurable:!0}};ct.Value.get=function(){return this.value}, ct.Next.get=function(){return this.next},pt.prototype.setValue=function(t){this.value=t},pt.prototype.setNext=function(t){this.next=t},pt.prototype.toString=function(){return""+this.value},Object.defineProperties(pt.prototype,ct);var lt=function(t){function e(){t.call(this),this.headNode=null,this.tailNode=null,this.size=0}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={Size:{configurable:!0}};return r.Size.get=function(){return this.size},e.prototype.append=function(t){if(this.size++,!this.headNode)return this.headNode=this.tailNode=new pt(t);if(this.headNode===this.tailNode)return this.tailNode=new pt(t),this.headNode.setNext(this.tailNode),this.headNode;var e=new pt(t);return this.tailNode.setNext(e),this.tailNode=e,this.headNode},e.prototype.prepend=function(t){return this.headNode=this.headNode?new pt(t,this.headNode):this.tailNode=new pt(t),this.size++,this.headNode},e.prototype.emptyList=function(){this.headNode=this.tailNode=null,this.size=0},e.prototype.clear=function(){this.emptyList()},e.prototype.deleteNode=function(t){for(var e,r=this,n=this.headNode,i=!1;n;){if(("function"==typeof t?t(n.Value):n.Value===t)&&(r.size--,i=!0,n===r.headNode?r.headNode=n.Next:n===r.tailNode?(e.setNext(null),r.tailNode=e):e.setNext(n.Next)),n.Next&&n.Next===r.headNode)break;if(0===r.size){r.emptyList();break}e=n,n=n.Next}return i},e.prototype.findNode=function(t){for(var e,r=this.headNode;r;){if("function"==typeof t?t(r.Value):r.Value===t){e=r;break}r=r.Next}return e},e.prototype.insertAfter=function(t,e){var r=new pt(t);if(e){var n=e.Next;return n&&n!==this.headNode||(this.tailNode=r),r.setNext(n),e.setNext(r),this.size++,!0}return!1},e.prototype.getHeadNode=function(){return this.headNode},e.prototype.getTailNode=function(){return this.tailNode},e.prototype.shift=function(){if(0===this.size)return null;1===this.size&&(this.tailNode=null);var t=this.headNode;return this.headNode=t.Next,this.size--,t},e.prototype.pop=function(){var t,e,r=this,n=this.headNode ;if(0===this.size)return null;if(1===this.size)return t=this.headNode,this.emptyList(),t;for(;n;){var i=n.Next;if(!i||i===r.headNode){t=n,r.tailNode=e,e.setNext(i);break}e=n,n=i}return this.size--,t},e.prototype.__iterate=function(t){for(var e=this,r=this.headNode,n=0;r;){t(r,n),n++;var i=r.Next;if(!i||i===e.headNode)break;r=i}},e.prototype.toString=function(){return""+this.toArray().map(function(t){return""+t})},e.fromArray=function(t){if(!t)return new e;var r=new e;return t.forEach(function(t){r.append(t)}),r},e.prototype.toDoubleLinkList=function(){if(!this.headNode)return new ft;var t=this.toArray(),e=new ft;return t.forEach(function(t){e.append(t.Value)}),e},e.prototype.toCycleLinkList=function(){var t=new dt;return this.toArray().forEach(function(e){t.append(e.Value)}),t},Object.defineProperties(e.prototype,r),e}(st),dt=function(){this.linklist=new lt},gt={Size:{configurable:!0}};dt.prototype.setCircle=function(){this.getTailNode().setNext(this.getHeadNode())},gt.Size.get=function(){return this.linklist.Size},dt.prototype.append=function(t){var e=this.linklist.append(t);return this.setCircle(),e},dt.prototype.prepend=function(t){var e=this.linklist.prepend(t);return this.setCircle(),e},dt.prototype.deleteNode=function(t){var e=this.linklist.findNode(t)===this.getHeadNode()||this.linklist.findNode(t)===this.getTailNode(),r=this.linklist.deleteNode(t);return e&&this.setCircle(),r},dt.prototype.findNode=function(t){return this.linklist.findNode(t)},dt.prototype.getHeadNode=function(){return this.linklist.getHeadNode()},dt.prototype.getTailNode=function(){return this.linklist.getTailNode()},dt.prototype.shift=function(){var t=this.linklist.shift();return this.Size&&this.setCircle(),t},dt.prototype.pop=function(){var t=this.linklist.pop();return this.Size&&this.setCircle(),t},dt.prototype.insertAfter=function(t,e){return this.linklist.insertAfter(t,e)},dt.prototype.clear=function(){this.linklist.clear()},dt.prototype.toString=function(){return""+this.linklist},dt.fromArray=function(t){if(!t)return new dt ;var e=new dt;return t.forEach(function(t){e.append(t)}),e},dt.prototype.toArray=function(){return this.linklist.toArray()},dt.prototype.getEnumerator=function(){var t=this.getHeadNode(),e={next:function(){return t=t.Next,e.Current={value:t.Value,done:!1},e},Current:{value:t.Value,done:!1}};return e},Object.defineProperties(dt.prototype,gt);var yt=function(t){this.value=t},vt={Next:{configurable:!0},Prev:{configurable:!0}};yt.prototype.setNext=function(t){this.next=t},yt.prototype.setPre=function(t){this.pre=t},vt.Next.get=function(){return this.next},vt.Prev.get=function(){return this.pre},yt.prototype.toString=function(){return""+this.value},Object.defineProperties(yt.prototype,vt);var Nt=function(){this.headNode=null,this.tailNode=null,this.size=0},xt={Size:{configurable:!0}};xt.Size.get=function(){return this.size},Nt.prototype.append=function(t){var e=new yt(t);return this.tailNode?(e.setPre(this.tailNode),e.setNext(this.headNode),this.tailNode.setNext(e),this.headNode.setPre(e),this.tailNode=e):(this.headNode=this.tailNode=e,this.headNode.setNext(this.tailNode),this.tailNode.setPre(this.headNode)),this.size++,this},Nt.prototype.prepend=function(t){var e=new yt(t);return this.headNode?(this.headNode.setPre(e),e.setNext(this.headNode),e.setPre(this.tailNode),this.tailNode.setNext(e),this.headNode=e):(this.headNode=this.tailNode=e,this.headNode.setNext(this.tailNode),this.tailNode.setPre(this.headNode)),this.size++,this},Nt.prototype.emptyList=function(){this.headNode=this.tailNode=null,this.size=0},Nt.prototype.shift=function(){var t=this.headNode;return this.headNode===this.tailNode?this.emptyList():(this.headNode=this.headNode.next,this.headNode.setPre(this.tailNode),this.size--),t},Nt.prototype.pop=function(){var t=this.tailNode;return this.headNode===this.tailNode?this.emptyList():(this.tailNode=this.tailNode.Prev,this.tailNode.setNext(this.headNode),this.size--),t},Nt.prototype.deleteNode=function t(e){var r=this,n=[];if(this.isEmpty())return n;for(var i=this.headNode,o=0;i;){ var u="function"==typeof e?e(i.value):i.value===e,t=null;if(u){if(r.headNode===r.tailNode){r.emptyList();break}i.Prev.setNext(i.Next),i.Next.setPre(i.Prev),t=i,n.push(o)}i=i.Next;var s=i===r.headNode;if(t&&(t===r.headNode&&(r.headNode=t.Next),t===r.tailNode&&(r.tailNode=t.Prev),t.setNext(null),t.setPre(null)),s)break;o++}},Nt.prototype.findNode=function(t){for(var e=this,r=this.headNode,n=null;r;){if("function"==typeof t?t(r.value):r.value===t){n=r;break}if(r===e.tailNode)break;r=r.Next}return n},Nt.prototype.getHeadNode=function(){return this.headNode},Nt.prototype.getTailNode=function(){return this.tailNode},Nt.prototype.isEmpty=function(){return!this.Size},Nt.prototype.toString=function(){for(var t=this,e=this.headNode,r=[];e&&(r.push(e),(e=e.Next)!==t.headNode););return""+r},Nt.prototype.getEnumerator=function(){var t=this.getHeadNode(),e={next:function(){return t=t.Next,e.Current={value:t.value,done:!1},e},Current:{value:t.value,done:!1}};return e},Object.defineProperties(Nt.prototype,xt);var mt=function(t){function e(){t.call(this),this.linkList=new lt}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.isEmpty=function(){return!this.linkList.getTailNode()},e.prototype.peek=function(){return this.linkList.getHeadNode()?this.linkList.getHeadNode().Value:null},e.prototype.enqueue=function(t){this.linkList.append(t)},e.prototype.dequeue=function(){var t=this.linkList.shift();return t?t.Value:null},e.prototype.toString=function(){return""+this.linkList},e.prototype.__iterate=function(t){for(var e=this.linkList.getHeadNode(),r=0;e;)t(e,r),r++,e=e.Next},e}(st),bt=function(t){void 0===t&&(t=null),this.item=t,this.next=[],this.prev=[]};bt.prototype.getItem=function(){return this.item},bt.prototype.getNext=function(t){return this.next[t]},bt.prototype.setNext=function(t,e){this.next[t]=e},bt.prototype.getPrev=function(t){return this.prev[t]},bt.prototype.setPrev=function(t,e){this.prev[t]=e},bt.prototype.deleteLastLevel=function(){this.next.length--}, bt.prototype.getNextLevel=function(){return this.next.length},bt.prototype.getPrevLevel=function(){return this.prev.length},bt.prototype.getHeight=function(){return Math.max(this.getPrevLevel(),this.getNextLevel())};var kt=function(t){this.compareKey=t,this.level=0,this.count=0,this.head=new bt},Lt={Level:{configurable:!0},Count:{configurable:!0},Head:{configurable:!0}};Lt.Level.get=function(){return this.level},Lt.Count.get=function(){return this.count},Lt.Head.get=function(){return this.head},kt.prototype.isEmpty=function(){return 0===this.count},kt.prototype.randomLevel=function(){for(var t=0,e=parseInt(""+10*Math.random(),10);e%2==0;)t++,e=parseInt(""+10*Math.random(),10);return t>this.level?this.level:t},kt.prototype.findNode=function(t){for(var e,r=null,n=this.head,i=this.level-1;i>=0;i--)for(;n.getNext(i)&&this.compare(n.getNext(i).getItem(),this.compareKey?(e={},e[this.compareKey]=t,e):t);)n=n.getNext(i);if(!n.getNext(0))return r;var o=!1;return o=this.compareKey?n.getNext(0).getItem()[this.compareKey]===t:n.getNext(0).getItem()===t,o&&(r=n.getNext(0)),r},kt.prototype.insert=function(t){var e=this.findUpdateNodes(t);if(e[0]&&e[0].getNext(0)&&e[0].getNext(0).getItem()===t)return this;var r=this.randomLevel();return r===this.level&&(e[r]=this.head,this.level++),this.insertNode(new bt(t),e,r),this.count++,this},kt.prototype.remove=function(t){var e=this,r=this.findNode(t);if(r){for(var n=r.getHeight(),i=0;i<n;i++){var o=r.getPrev(i),u=r.getNext(i);o.setNext(i,u),u&&u.setPrev(i,o)}for(;this.level&&!this.head.getNext(this.level-1);)e.head.deleteLastLevel(),e.level--;this.count--}return this},kt.prototype.getSkipTables=function(){for(var t=this,e=[],r=0;r<this.level;r++){for(var n=[],i=t.head;i=i.getNext(r);)n.push(i);e[r]=n}return e},kt.prototype.toString=function(){return this.getSkipTables().reverse().reduce(function(t,e){return t.push(""+e.map(function(t){return""+t.getItem()})),t},[]).join("\n")},kt.prototype.compare=function(t,e){return this.compareKey?t[this.compareKey]<e[this.compareKey]:t<e}, kt.prototype.findUpdateNodes=function(t){for(var e=this,r=[],n=this.level-1;n>=0;n--){for(var i=e.head.getNext(n),o=null;i&&this.compare(i.getItem(),t);)o=i,i=i.getNext(n);r[n]=i?i.getPrev(n):o}return r},kt.prototype.insertNode=function(t,e,r){for(var n=r;n>=0;n--){var i=e[n].getNext(n);i&&(i.setPrev(n,t),t.setNext(n,i)),e[n].setNext(n,t),t.setPrev(n,e[n])}},Object.defineProperties(kt.prototype,Lt);var Rt=function(t){function e(){t.call(this),this.linkList=new lt}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(t){return this.linkList.append(t)},e.prototype.pop=function(){var t=this.linkList.pop();return t?t.Value:null},e.prototype.peek=function(){return this.linkList.getTailNode()?this.linkList.getTailNode().Value:null},e.prototype.isEmpty=function(){return!this.linkList.getTailNode()},e.prototype.toString=function(){return""+this.linkList},e.prototype.__iterate=function(t){for(var e=this.linkList.getHeadNode(),r=0;e;)t(e.Value,r),r++,e=e.Next},e.prototype.toArray=function(){return t.prototype.toArray.call(this).reverse()},e}(st),Vt=function(t){void 0===t&&(t=e),this.compare=t,this.count=0},Et={Count:{configurable:!0},Head:{configurable:!0}};Et.Count.get=function(){return this.count},Et.Head.get=function(){return this.head},Vt.prototype.setHead=function(t){this.head=new pt({value:t,degree:0}),this.count=1},Vt.prototype.clear=function(){this.head=null,this.count=0},Vt.prototype.isEmpty=function(){return!this.head},Vt.prototype.insert=function(t){var e=new Vt;e.setHead(t);var r=e.Head;return this.union(e),r},Vt.prototype.deleteExtremum=function(){if(!this.head)return null;var t=this._findExtremum();t.minPrev?t.minPrev.setNext(t.minNode.Next):this.head=t.minNode.Next;for(var e=t.minNode.Value.child,r=e;e;)e.Value.parent=null,e=e.Next;var n=new Vt(this.compare);return n.head=r,this.union(n),this.count--,t.minNode.Value.value},Vt.prototype._findExtremum=function(){ for(var t=this,e=this.head.Next,r=this.head,n=this.head,i=null,o=r.Value.value;e;)t.compare(o,e.Value.value)||(i=n,r=e,o=r.Value.value),n=e,e=e.Next;return{minNode:r,minPrev:i}},Vt.prototype.findExtremum=function(){return this.head?this._findExtremum().minNode.Value.value:null},Vt.prototype.union=function(t){var e=this;if(!t)return this;this.count+=t.Count;var r=this.mergeHeaps(t);if(!r)return this;this.head=null,t.head=null;for(var n,i=r,o=r.Next;o;)o.Value.degree!==i.Value.degree||o.Next&&o.Next.Value.degree===i.Value.degree?(n=i,i=o):e.compare(i.Value.value,o.Value.value)?(i.setNext(o.Next),e.link(i,o)):(n?n.setNext(o):r=o,e.link(o,i),i=o),o=i.Next;return this.head=r,this},Vt.prototype.link=function(t,e){e.setNext(t.Value.child),e.Value.parent=t,t.Value.child=e,t.Value.degree++},Vt.prototype.mergeHeaps=function(t){var e=this.head,r=t.Head;if(!e)return t.head;if(!r)return this.head;var n;e.Value.degree<=r.Value.degree?(n=this.head,e=e.Next):(n=t.head,r=r.Next);for(var i=n;e&&r;)e.Value.degree<=r.Value.degree?(i.setNext(e),e=e.Next):(i.setNext(r),r=r.Next),i=i.Next;return i.setNext(e?e:r),n},Object.defineProperties(Vt.prototype,Et);var Kt=function(){this.container=[]},St={Size:{configurable:!0}};St.Size.get=function(){return this.container.length},Kt.prototype.getLeftChildIndex=function(t){return 2*t+1},Kt.prototype.getRigthChildIndex=function(t){return 2*t+2},Kt.prototype.getParentIndex=function(t){return Math.floor((t-1)/2)},Kt.prototype.getLeftChild=function(t){return this.container[this.getLeftChildIndex(t)]},Kt.prototype.getRightChild=function(t){return this.container[this.getRigthChildIndex(t)]},Kt.prototype.getParent=function(t){return this.container[this.getParentIndex(t)]},Kt.prototype.hasLeftChild=function(t){return this.getLeftChildIndex(t)<this.container.length},Kt.prototype.hasRightChild=function(t){return this.getRigthChildIndex(t)<this.container.length},Kt.prototype.hasParent=function(t){return this.getParentIndex(t)>=0},Kt.prototype.swap=function(t,e){var r=this.container[e] ;this.container[e]=this.container[t],this.container[t]=r},Kt.prototype.heapifyUp=function(t){for(var e=this,r=t||this.container.length-1;this.hasParent(r)&&!this.compare(this.getParent(r),this.container[r]);)e.swap(r,e.getParentIndex(r)),r=e.getParentIndex(r)},Kt.prototype.heapifyDown=function(t){for(var e=this,r=t||0,n=null;this.hasLeftChild(r)&&(n=e.hasRightChild(r)&&e.compare(e.getRightChild(r),e.getLeftChild(r))?e.getRigthChildIndex(r):e.getLeftChildIndex(r),!e.compare(e.container[r],e.container[n]));)e.swap(r,n),r=n},Kt.prototype.poll=function(){if(0===this.container.length)return null;if(1===this.container.length)return this.container.pop();var t=this.container[0];return this.container[0]=this.container.pop(),this.heapifyDown(),t},Kt.prototype.peek=function(){return 0===this.container.length?null:this.container[0]},Kt.prototype.add=function(t){return this.container.push(t),this.heapifyUp(),this},Kt.prototype.remove=function(t){for(var e=this,r=this.findAll(t).length,n=0;n<r;n+=1){var i=e.findAllIndex(t).pop();if(i===e.container.length-1)e.container.pop();else{e.container[i]=e.container.pop();var o=e.getParent(i);!e.hasLeftChild(i)||o&&!e.compare(o,e.container[i])?e.heapifyUp(i):e.heapifyDown(i)}}return r>0},Kt.prototype.toString=function(){return""+this.container},Kt.prototype.isEmpty=function(){return!this.container.length},Kt.prototype.find=function(t){for(var e=this,r=null,n=0;n<this.container.length;n++){var i=e.container[n];if("function"==typeof t?t(i):t===i){r=i;break}}return r},Kt.prototype.findAll=function(t){var e=[];return this.container.forEach(function(r){("function"==typeof t?t(r):t===r)&&e.push(r)}),e},Kt.prototype.clear=function(){this.container.length=0},Kt.prototype.entries=function(){return[].concat(this.container)},Kt.prototype.findAllIndex=function(t){var e=[];return this.container.forEach(function(r,n){("function"==typeof t?t(r):t===r)&&e.push(n)}),e},Object.defineProperties(Kt.prototype,St);var wt=function(t){function e(e){t.call(this),this.key=e}return t&&(e.__proto__=t), e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.compare=function(t,e){return this.key?t[this.key]>=e[this.key]:t>=e},e}(Kt),_t=function(t){function e(e){t.call(this),this.key=e}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.compare=function(t,e){return this.key?t[this.key]<=e[this.key]:t<=e},e}(Kt),Pt=function(){};Pt.preTraversal=function(t){var e=[];return this._preTraversal(t,function(t){e.push(t)}),e},Pt._preTraversal=function(t,e){t&&(e(t.Value),this._preTraversal(t.Left,e),this._preTraversal(t.Right,e))},Pt.inTraversal=function(t){var e=[];return this._inTraversal(t,function(t){e.push(t)}),e},Pt._inTraversal=function(t,e){t&&(this._inTraversal(t.Left,e),e(t.Value),this._inTraversal(t.Right,e))},Pt.postOrderTraversal=function(t){var e=[];return this._postOrderTraversal(t,function(t){e.push(t)}),e},Pt._postOrderTraversal=function(t,e){t&&(this._postOrderTraversal(t.Left,e),this._postOrderTraversal(t.Right,e),e(t.Value))},Pt.getHeight=function(t){if(!t)return 0;var e=1;return e+=Math.max(this.getHeight(t.Left),this.getHeight(t.Right))};var Ct=function(t){this.value=t},At={Value:{configurable:!0},Left:{configurable:!0},Right:{configurable:!0}};At.Value.get=function(){return this.value},At.Left.get=function(){return this.left},At.Right.get=function(){return this.right},Ct.prototype.setValue=function(t){this.value=t},Ct.prototype.setLeft=function(t){return this.left=t,t&&(this.left.parent=this),this},Ct.prototype.setRight=function(t){return this.right=t,t&&(this.right.parent=this),this},Ct.prototype.removeChild=function(t){return t===this.left?(this.left.parent=null,this.left=null,!0):t===this.right&&(this.right.parent=null,this.right=null,!0)},Ct.prototype.getHeight=function(){return Math.max(this.getLeftHeight(),this.getRightHeight())},Ct.prototype.getRightHeight=function(){return this.right?this.right.getHeight()+1:0},Ct.prototype.getLeftHeight=function(){return this.left?this.left.getHeight()+1:0}, Ct.prototype.balanceFactor=function(){return this.getLeftHeight()-this.getRightHeight()},Ct.prototype.getSibling=function(){if(this.parent)return this.parent.Left===this?this.parent.Right:this.parent.Left},Ct.prototype.getUncle=function(){if(this.parent&&this.parent.parent){var t=this.parent;return t.parent.Left===t?t.parent.Right:t.parent.Left}},Ct.prototype.toString=function(){return""+Pt.inTraversal(this)},Object.defineProperties(Ct.prototype,At);var Tt=function(t){function e(e,r){t.call(this,e),this.rank=r}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={Rank:{configurable:!0}};return r.Rank.set=function(t){this.rank=t},r.Rank.get=function(){return this.rank},Object.defineProperties(e.prototype,r),e}(Ct),Ot=function(t,e){void 0===t&&(t=r),this.compare=t,this.count=0,void 0!==e&&(this.root=new Tt(e,0),this.count=1)},zt={Root:{configurable:!0},Count:{configurable:!0}};zt.Root.get=function(){return this.root},zt.Count.get=function(){return this.count},Ot.prototype.isEmpty=function(){return!this.root},Ot.prototype.fixNode=function(t){var e=t.Left,r=t.Right;if(e&&r&&e.Rank<r.Rank){var n=t.Right;t.setRight(t.Left),t.setLeft(n)}else t.Right&&!t.Left&&(t.setLeft(t.Right),t.setRight(null));t.Rank=t.Right?t.Right.Rank+1:0},Ot.prototype._merge=function(t,e){if(!t)return e;if(!e)return t;if(!this.compare(t.Value,e.Value)){var r=e;e=t,t=r}return t.setRight(this._merge(t.Right,e)),this.fixNode(t),t},Ot.prototype.merge=function(t){return!t||t.isEmpty()?this:this.root?(this.root=this._merge(this.Root,t.Root),this.count+=t.Count,this):(this.root=t.Root,this.count=t.Count,this)},Ot.prototype.findExtremum=function(){return this.root?this.root.Value:null},Ot.prototype.insert=function(t){var e=new Ot(this.compare,t);return this.merge(e),e},Ot.prototype.deleteExtremum=function(){if(!this.root)return null;var t=this.root.Value;return this.root=this._merge(this.root.Left,this.root.Right),this.count--,t},Object.defineProperties(Ot.prototype,zt);var jt=function(t,e){this.value=t, this.priority=e},Ht={Value:{configurable:!0},Priority:{configurable:!0}};Ht.Value.get=function(){return this.value},Ht.Priority.get=function(){return this.priority},jt.prototype.toString=function(){return'{"priority":'+this.priority+',"value":'+this.value+"}"},Object.defineProperties(jt.prototype,Ht);var It=function(t){function e(){t.call(this),this.heap=new wt("Priority")}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.peek=function(){return this.heap.peek()},e.prototype.enqueue=function(t,e){return this.heap.add(new jt(t,e)),this},e.prototype.dequeue=function(){return this.heap.poll()},e.prototype.changePriority=function(t,e){this.heap.remove(function(e){return e.Value===t}),this.heap.add(new jt(t,e))},e.prototype.has=function(t){return!!this.heap.find(function(e){return e.Value===t})},e.prototype.clear=function(){this.heap.clear()},e.prototype.isEmpty=function(){return this.heap.isEmpty()},e.prototype.toString=function(){return""+this.heap},e.prototype.__iterate=function(t){this.heap.entries().forEach(function(e,r){return t(e.Value,r)})},e}(st),Bt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Error),Dt=function t(e){void 0===e&&(e=t.DEFAULT_TABLE_SIZE),this.buckets=Array(e).fill(null).map(function(){return new lt}),this.count=0,this.keys={},this.threshold=e*t.LOADFACTOR},Wt={Count:{configurable:!0},TableSize:{configurable:!0}};Dt.setDefaultTableSize=function(t){this.DEFAULT_TABLE_SIZE=t},Wt.Count.get=function(){return this.count},Wt.TableSize.get=function(){return this.buckets.length},Dt.prototype.put=function(t,e){if(null===t||void 0===t)throw new Bt;var r=i(t),o=n(r),u=this.mod(o),s=this.buckets[u],a=s.findNode(function(e){return e.key===t});return a?void(a.Value.value=e):(this.count>=this.threshold&&(this.rehash(),u=this.mod(o),s=this.buckets[u]),this.keys[r]=u,s.append({key:t,value:e}),this.count++,this)},Dt.prototype.get=function(t){ var e=i(t),r=n(e),o=this.mod(r),u=this.buckets[o],s=u.findNode(function(e){return e.key===t});return s?s.Value.value:null},Dt.prototype.remove=function(t){var e=i(t),r=n(e),o=this.mod(r),u=this.buckets[o],s=u.findNode(function(e){return e.key===t});return!!s&&(this.count--,u.deleteNode(s.Value))},Dt.prototype.contains=function(t){return null!==this.get(t)},Dt.prototype.getKeys=function(){return Object.keys(this.keys)},Dt.prototype.getOrignalKeys=function(){var t=Array(this.count);return this.iterate(function(e,r){t[r]=e.key}),t},Dt.prototype.values=function(){var t=Array(this.count);return this.iterate(function(e,r){t[r]=e.value}),t},Dt.prototype.clear=function(){this.buckets.length=0,this.keys={},this.count=0,this.buckets=Array(Dt.DEFAULT_TABLE_SIZE).fill(null).map(function(){return new lt})},Dt.prototype.getHashKey=function(t){return this.keys[i(t)]},Dt.prototype.toString=function(){var t=[];return this.iterate(function(e){var r={key:e.key,value:e.value};h(r),t.push(r)}),""+t},Dt.prototype.iterate=function(t){for(var e=this,r=0,n=0,i=this.buckets.length;n<i;n++)for(var o=e.buckets[n].toArray(),u=r,s=u,a=u+o.length;s<a;s++)t(o[s-u].Value,r),r++},Dt.prototype.rehash=function(){var t=this,e=this.buckets,r=2*e.length+1,o=Array(r).fill(null).map(function(){return new lt});this.buckets=o,this.keys={};for(var u=0,s=e.length;u<s;u++)e[u].toArray().forEach(function(e){var r=e.Value,u=n(i(r.key)),s=t.mod(u);o[s].append(r),t.keys[i(r.key)]=s});e.length=0,this.threshold=r*Dt.LOADFACTOR},Dt.prototype.mod=function(t){var e=t%this.buckets.length;return t<0?e*-1:e},Object.defineProperties(Dt.prototype,Wt),Dt.DEFAULT_TABLE_SIZE=11,Dt.LOADFACTOR=.75;var Mt=function(t){this.map=new Dt(t)},Ft={Count:{configurable:!0}};Ft.Count.get=function(){return this.map.Count},Mt.prototype.put=function(t,e){var r=this;return r.map.put(t,e),r},Mt.prototype.get=function(t){return this.map.get(t)},Mt.prototype.clear=function(){return this.map.clear()},Mt.prototype.remove=function(t){return this.map.remove(t)},Mt.prototype.keys=function(){ return this.map.getKeys()},Mt.prototype.values=function(){return this.map.values()},Mt.prototype.contains=function(t){return this.map.contains(t)},Object.defineProperties(Mt.prototype,Ft);var Ut=function(){};Ut.prototype.diff=function(t){if(!t)return this.entries();for(var e=this.entries(),r=[],n=0,i=e;n<i.length;n+=1){var o=i[n];t.has(o)||r.push(o)}return r},Ut.prototype.union=function(t){var e=this;if(!t)return this.entries();for(var r=t.entries(),n=this.entries(),i=0,o=r;i<o.length;i+=1){var u=o[i];e.has(u)||n.push(u)}return n},Ut.prototype.intersect=function(t){if(!t)return[];var e,r,n=[];this.Size>t.Size?(e=this,r=t.entries()):(e=t,r=this.entries());for(var i=0,o=r;i<o.length;i+=1){var u=o[i];e.has(u)&&n.push(u)}return n},Ut.prototype.isEmpty=function(){return 0===this.Size};var qt=function(t){function e(r){void 0===r&&(r=e.DEFAULT_TABLE_SIZE),t.call(this),this.hashtable=new Dt(r)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={Size:{configurable:!0}};return r.Size.get=function(){return this.hashtable.Count},e.prototype.add=function(t){return this.hashtable.put(t,!0),this},e.prototype.has=function(t){return this.hashtable.contains(t)},e.prototype.remove=function(t){return this.hashtable.remove(t)},e.prototype.clear=function(){this.hashtable.clear()},e.prototype.entries=function(){return this.hashtable.getOrignalKeys()},e.prototype.diff=function(e){return t.prototype.diff.call(this,e)},e.prototype.union=function(e){return t.prototype.union.call(this,e)},e.prototype.intersect=function(e){return t.prototype.intersect.call(this,e)},e.fromArray=function(t){var r=new e(t.length);return t.forEach(function(t){return r.add(t)}),r},Object.defineProperties(e.prototype,r),e}(Ut);qt.DEFAULT_TABLE_SIZE=11;var Gt,Jt=function(t){function e(){t.call(this),this.set=[],this.count=0}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={Size:{configurable:!0}};return r.Size.get=function(){return this.count},e.prototype.has=function(t){ return void 0===t?this.set.indexOf(void 0)>-1:isNaN(t)?this.set.findIndex(function(e){return JSON.stringify(e)===JSON.stringify(t)})>-1:this.set.findIndex(function(e){return JSON.stringify(e)===JSON.stringify(t)&&!isNaN(e)})>-1},e.prototype.findIndex=function(t){return void 0===t?this.set.indexOf(t):this.set.findIndex(isNaN(t)?function(e){return JSON.stringify(e)===JSON.stringify(t)}:function(e){return JSON.stringify(e)===JSON.stringify(t)&&!isNaN(e)})},e.prototype.add=function(t){return this.has(t)||(this.set.push(t),this.count++),this},e.prototype.entries=function(){return this.set},e.prototype.remove=function(t){var e=this.findIndex(t);return e>-1&&(this.set.splice(e,1),this.count--,!0)},e.prototype.union=function(e){return t.prototype.union.call(this,e)},e.prototype.intersect=function(e){return t.prototype.intersect.call(this,e)},e.prototype.diff=function(e){return t.prototype.diff.call(this,e)},Object.defineProperties(e.prototype,r),e}(Ut);!function(t){t[t.Red=1]="Red",t[t.Black=2]="Black"}(Gt||(Gt={}));var Zt=function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={Color:{configurable:!0}};return r.Color.get=function(){return this.color},e.prototype.setColor=function(t){this.color=t},e.prototype.setValue=function(e){t.prototype.setValue.call(this,e)},e.prototype.find=function(t,e){var r,n;return e?(r=this.Value[e],n=t[e]):(r=this.Value,n=t),r===n?this:r>n&&this.Left?this.Left.find(t,e):r<n&&this.Right?this.Right.find(t,e):null},e.prototype.findMin=function(){return this.Left?this.Left.findMin():this},e.prototype.findMax=function(){return this.Right?this.Right.findMax():this},e.prototype.insert=function(t,r){if(null!==t&&void 0!==t){var n=function(t,e){return t<e};r&&(n=function(t,e){return t[r]<e[r]});var i;return n(t,this.Value)?this.Left?i=this.Left.insert(t,r):(i=new e(t),this.setLeft(i)):this.Right?i=this.Right.insert(t,r):(i=new e(t),this.setRight(i)),i}},e.prototype.contains=function(t,e){return!!this.find(t,e)}, Object.defineProperties(e.prototype,r),e}(Ct),Qt=function(t){this.compareKey=t},Xt={Root:{configurable:!0}};Xt.Root.get=function(){return this.root},Xt.Root.set=function(t){this.root=t},Qt.prototype.insert=function(t){if(null!==t&&void 0!==t)return this.root?this.root.insert(t,this.compareKey):this.root=new Zt(t)},Qt.prototype.remove=function(t){var e=this.find(t);return!!e&&(this.removeNode(e),!0)},Qt.prototype.clear=function(){this.Root=null},Qt.prototype.removeNode=function(t){if(!t)return!1;var e,r=null;return e=t.Left&&t.Right?this.successor(t):t,r=e.Left?e.Left:e.Right,r&&(r.parent=e.parent),e.parent?e.parent.Left===e?(e=this.copyNode(e),e.parent.setLeft(r)):(e=this.copyNode(e),e.parent.setRight(r)):this.root=r,t.setValue(e.Value),{successorChild:r,nodeSuccessor:e}},Qt.prototype.successor=function(t){for(var e=t.Right;e.Left;)e=e.Left;return e},Qt.prototype.copyNode=function(t){var e=new Zt(t.Value);for(var r in t)e[r]=t[r];return e},Qt.prototype.contains=function(t){return!!this.root&&this.root.contains(t,this.compareKey)},Qt.prototype.find=function(t){return this.root?this.root.find(t,this.compareKey):null},Qt.prototype.getAscSeq=function(){return Pt.inTraversal(this.root)},Qt.prototype.toString=function(){return this.root?""+this.root:""},Object.defineProperties(Qt.prototype,Xt);var Yt=function(t){function e(e){t.call(this,e)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.insert=function(e){if(null!==e&&void 0!==e){var r=t.prototype.insert.call(this,e);return r===this.Root?(r.setColor(Gt.Black),r):(r.setColor(Gt.Red),this.blance(r),r)}},e.prototype.remove=function(t){if(null===t||void 0===t)return!1;var e=this.find(t);if(!e)return!1;if(e.Left&&e.Right){var r=this.getSuccessor(e);e.setValue(r.Value),e=r}var n=e.Left?e.Left:e.Right;return n?(n.parent=e.parent,e.parent?e===e.parent.Left?e.parent.setLeft(n):e.parent.setRight(n):this.Root=n,e.setLeft(null),e.setRight(null),e.parent=null, e.Color===Gt.Black&&this.deleteFixUp(n)):e.parent?(e.Color===Gt.Black&&this.deleteFixUp(e),e.parent&&(e===e.parent.Left?e.parent.setLeft(null):e===e.parent.Right&&e.parent.setRight(null),e.parent=null)):this.Root=null,!0},e.prototype.getSuccessor=function(t){if(null==t)return null;if(t.Right){for(var e=t.Right;e.Left;)e=e.Left;return e}for(var r=t.parent,n=t;r&&n===r.Right;)n=r,r=r.parent;return r},e.prototype.deleteFixUp=function(t){for(var e=this;t!==this.Root&&f(t)===Gt.Black;)if(t===p(c(t))){var r=l(c(t));f(r)===Gt.Red&&(d(r,Gt.Black),d(c(t),Gt.Red),e.leftRotate(c(t),!1),r=l(c(t))),f(p(r))===Gt.Black&&f(l(r))===Gt.Black?(d(r,Gt.Red),t=c(t)):(f(l(r))===Gt.Black&&(d(p(r),Gt.Black),d(r,Gt.Red),e.rightRotate(r,!1),r=l(c(t))),d(r,f(c(t))),d(c(t),Gt.Black),d(l(r),Gt.Black),e.leftRotate(c(t),!1),t=e.Root)}else{var n=p(c(t));f(n)===Gt.Red&&(d(n,Gt.Black),d(c(t),Gt.Red),e.rightRotate(c(t),!1),n=p(c(t))),f(l(n))===Gt.Black&&f(p(n))===Gt.Black?(d(n,Gt.Red),t=c(t)):(f(p(n))===Gt.Black&&(d(l(n),Gt.Black),d(n,Gt.Red),e.leftRotate(n,!1),n=p(c(t))),d(n,f(c(t))),d(c(t),Gt.Black),d(p(n),Gt.Black),e.rightRotate(c(t),!1),t=e.Root)}d(t,Gt.Black)},e.prototype.blance=function(t){if(t!==this.Root){var e=t.parent;if(e.Color!==Gt.Black){var r=t.getUncle(),n=e.parent;if(r&&r.Color===Gt.Red){if(e.setColor(Gt.Black),r.setColor(Gt.Black),n===this.Root)return;n.setColor(Gt.Red),this.blance(e.parent)}else{var i;i=e===e.parent.Left?t===e.Left?this.rightRotate(n):this.leftRightRotate(n):t===e.Right?this.leftRotate(n):this.rightLeftRotate(n),i.parent||(this.Root=i,this.Root.setColor(Gt.Black)),this.blance(i)}}}},e.prototype.rightRotate=function(t,e){void 0===e&&(e=!0);var r,n=t.parent;n&&(r=n.Left===t);var i=t.Left,o=i.Right;return i.setRight(t),t.setLeft(o),n?r?n.setLeft(i):n.setRight(i):(i.parent=null,this.Root=i),e&&this.swapColor(i,t),i},e.prototype.leftRightRotate=function(t){var e=t.Left,r=e.Right,n=r.Left;return r.setLeft(e),e.setRight(n),t.setLeft(r),this.rightRotate(t)},e.prototype.leftRotate=function(t,e){void 0===e&&(e=!0) ;var r,n=t.parent;n&&(r=n.Left===t);var i=t.Right,o=i.Left;return i.setLeft(t),t.setRight(o),n?r?n.setLeft(i):n.setRight(i):(i.parent=null,this.Root=i),e&&this.swapColor(i,t),i},e.prototype.rightLeftRotate=function(t){var e=t.Right,r=e.Left,n=r.Right;return r.setRight(e),e.setLeft(n),t.setRight(r),this.leftRotate(t)},e.prototype.swapColor=function(t,e){var r=t.Color;t.setColor(e.Color),e.setColor(r)},e}(Qt),$t=function(){this.size=0,this.tree=new Yt("key")},te={Count:{configurable:!0}};te.Count.get=function(){return this.size},$t.prototype.put=function(t,e){var r=this.get(t);if(r){var n=r.findNode(function(e){return e.key===t});return n?(n.Value.value=e,this):(r.append({key:t,value:e}),this.size++,this)}this.size++;var i=this.getHashKey(t),o=this.tree.insert({key:i});return r=new lt,r.append({key:t,value:e}),o.Value.value=r,this},$t.prototype.get=function(t){var e=this.getHashKey(t),r=this.tree.find({key:e});return r?r.Value.value:null},$t.prototype.getVal=function(t){var e=this.getHashKey(t),r=this.tree.find({key:e});if(r){var n=r.Value.value,i=n.findNode(function(e){return e.key===t});return i?i.Value.value:null}return null},$t.prototype.clear=function(){return this.size=0,this.tree.clear()},$t.prototype.remove=function(t){var e=this.getHashKey(t),r=this.get(t);if(r){if(r.deleteNode(func