diff --git a/dist/js/app.js b/dist/js/app.js index bc12a95..ee2f496 100644 --- a/dist/js/app.js +++ b/dist/js/app.js @@ -8,7 +8,7 @@ sandboxContainer = document.querySelector(".sandbox"); sandboxContainer.appendChild(Sandbox.render()); -}).call(this,require("oMfpAn"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_e0ea0390.js","/") +}).call(this,require("oMfpAn"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_eb026ccd.js","/") },{"buffer":3,"oMfpAn":7,"rxmarbles/views/sandbox":28}],2:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ @@ -12510,6 +12510,7 @@ Rx = require('rx'); module.exports = { "amb": { + "label": "amb()", "function": Rx.Observable.amb, "inputs": [ [ @@ -12549,6 +12550,7 @@ module.exports = { ] }, "concat": { + "label": "concat()", "function": Rx.Observable.concat, "inputs": [ [ @@ -12574,6 +12576,7 @@ module.exports = { ] }, "merge": { + "label": "merge()", "function": Rx.Observable.merge, "inputs": [ [ @@ -12609,39 +12612,50 @@ module.exports = { }).call(this,require("oMfpAn"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../../node_modules/rxmarbles/models/examples.js","/../../node_modules/rxmarbles/models") },{"buffer":3,"oMfpAn":7,"rx":18}],24:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var Rx, h; +var Examples, Rx, h, renderSelectOptionsArray, setupClickBehavior; h = require('hyperscript'); Rx = require('rx'); +Examples = require('rxmarbles/models/examples'); + +renderSelectOptionsArray = function(examples) { + var example, key, options; + options = []; + for (key in examples) { + example = examples[key]; + if (!examples.hasOwnProperty(key)) { + continue; + } + options.push(h("option", { + value: key + }, example["label"])); + } + return options; +}; + +setupClickBehavior = function(functionBoxElement, selectElement) { + return Rx.Observable.fromEvent(functionBoxElement, "click").subscribe(function() { + var event; + event = document.createEvent('MouseEvents'); + event.initMouseEvent('mousedown', true, true, window); + selectElement.dispatchEvent(event); + return true; + }); +}; + module.exports = { render: function(label) { - var functionBoxElement, select; - functionBoxElement = h("div.function-box", [ - h("span.function-box-label", label), select = h("select", [ - h("option", { - value: "amb" - }, "amb()"), h("option", { - value: "concat" - }, "concat()"), h("option", { - value: "merge" - }, "merge()") - ]), h("div.function-box-dropdown", [h("span.function-box-dropdown-arrow")]) - ]); - Rx.Observable.fromEvent(functionBoxElement, "click").subscribe(function() { - var event; - event = document.createEvent('MouseEvents'); - event.initMouseEvent('mousedown', true, true, window); - select.dispatchEvent(event); - return true; - }); + var functionBoxElement, selectElement; + functionBoxElement = h("div.function-box", [h("span.function-box-label", label), selectElement = h("select", renderSelectOptionsArray(Examples)), h("div.function-box-dropdown", [h("span.function-box-dropdown-arrow")])]); + setupClickBehavior(functionBoxElement, selectElement); return functionBoxElement; } }; }).call(this,require("oMfpAn"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../../node_modules/rxmarbles/views/function-box.js","/../../node_modules/rxmarbles/views") -},{"buffer":3,"hyperscript":8,"oMfpAn":7,"rx":18}],25:[function(require,module,exports){ +},{"buffer":3,"hyperscript":8,"oMfpAn":7,"rx":18,"rxmarbles/models/examples":23}],25:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ var Marble, Rx, createArrowBodyElement, createArrowHeadElement, createMarblesContainerElement, makeDataStream, __slice = [].slice; @@ -15937,4 +15951,4 @@ function isChildren(x) { }).call(this,require("oMfpAn"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/../../node_modules/virtual-hyperscript/svg.js","/../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yZSgnZGF0YS1zZXQnKVxucmVxdWlyZSgnaHRtbC1lbGVtZW50JylcblxuZnVuY3Rpb24gY29udGV4dCAoKSB7XG5cbiAgdmFyIGNsZWFudXBGdW5jcyA9IFtdXG5cbiAgZnVuY3Rpb24gaCgpIHtcbiAgICB2YXIgYXJncyA9IFtdLnNsaWNlLmNhbGwoYXJndW1lbnRzKSwgZSA9IG51bGxcbiAgICBmdW5jdGlvbiBpdGVtIChsKSB7XG4gICAgICB2YXIgclxuICAgICAgZnVuY3Rpb24gcGFyc2VDbGFzcyAoc3RyaW5nKSB7XG4gICAgICAgIHZhciBtID0gc3BsaXQoc3RyaW5nLCAvKFtcXC4jXT9bYS16QS1aMC05XzotXSspLylcbiAgICAgICAgaWYoL15cXC58Iy8udGVzdChtWzFdKSlcbiAgICAgICAgICBlID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgnZGl2JylcbiAgICAgICAgZm9yRWFjaChtLCBmdW5jdGlvbiAodikge1xuICAgICAgICAgIHZhciBzID0gdi5zdWJzdHJpbmcoMSx2Lmxlbmd0aClcbiAgICAgICAgICBpZighdikgcmV0dXJuXG4gICAgICAgICAgaWYoIWUpXG4gICAgICAgICAgICBlID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCh2KVxuICAgICAgICAgIGVsc2UgaWYgKHZbMF0gPT09ICcuJylcbiAgICAgICAgICAgIENsYXNzTGlzdChlKS5hZGQocylcbiAgICAgICAgICBlbHNlIGlmICh2WzBdID09PSAnIycpXG4gICAgICAgICAgICBlLnNldEF0dHJpYnV0ZSgnaWQnLCBzKVxuICAgICAgICB9KVxuICAgICAgfVxuXG4gICAgICBpZihsID09IG51bGwpXG4gICAgICAgIDtcbiAgICAgIGVsc2UgaWYoJ3N0cmluZycgPT09IHR5cGVvZiBsKSB7XG4gICAgICAgIGlmKCFlKVxuICAgICAgICAgIHBhcnNlQ2xhc3MobClcbiAgICAgICAgZWxzZVxuICAgICAgICAgIGUuYXBwZW5kQ2hpbGQociA9IGRvY3VtZW50LmNyZWF0ZVRleHROb2RlKGwpKVxuICAgICAgfVxuICAgICAgZWxzZSBpZignbnVtYmVyJyA9PT0gdHlwZW9mIGxcbiAgICAgICAgfHwgJ2Jvb2xlYW4nID09PSB0eXBlb2YgbFxuICAgICAgICB8fCBsIGluc3RhbmNlb2YgRGF0ZVxuICAgICAgICB8fCBsIGluc3RhbmNlb2YgUmVnRXhwICkge1xuICAgICAgICAgIGUuYXBwZW5kQ2hpbGQociA9IGRvY3VtZW50LmNyZWF0ZVRleHROb2RlKGwudG9TdHJpbmcoKSkpXG4gICAgICB9XG4gICAgICAvL3RoZXJlIG1pZ2h0IGJlIGEgYmV0dGVyIHdheSB0byBoYW5kbGUgdGhpcy4uLlxuICAgICAgZWxzZSBpZiAoaXNBcnJheShsKSlcbiAgICAgICAgZm9yRWFjaChsLCBpdGVtKVxuICAgICAgZWxzZSBpZihpc05vZGUobCkpXG4gICAgICAgIGUuYXBwZW5kQ2hpbGQociA9IGwpXG4gICAgICBlbHNlIGlmKGwgaW5zdGFuY2VvZiBUZXh0KVxuICAgICAgICBlLmFwcGVuZENoaWxkKHIgPSBsKVxuICAgICAgZWxzZSBpZiAoJ29iamVjdCcgPT09IHR5cGVvZiBsKSB7XG4gICAgICAgIGZvciAodmFyIGsgaW4gbCkge1xuICAgICAgICAgIGlmKCdmdW5jdGlvbicgPT09IHR5cGVvZiBsW2tdKSB7XG4gICAgICAgICAgICBpZigvXm9uXFx3Ky8udGVzdChrKSkge1xuICAgICAgICAgICAgICBpZiAoZS5hZGRFdmVudExpc3RlbmVyKXtcbiAgICAgICAgICAgICAgICBlLmFkZEV2ZW50TGlzdGVuZXIoay5zdWJzdHJpbmcoMiksIGxba10sIGZhbHNlKVxuICAgICAgICAgICAgICAgIGNsZWFudXBGdW5jcy5wdXNoKGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICAgICAgICBlLnJlbW92ZUV2ZW50TGlzdGVuZXIoay5zdWJzdHJpbmcoMiksIGxba10sIGZhbHNlKVxuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgIH1lbHNle1xuICAgICAgICAgICAgICAgIGUuYXR0YWNoRXZlbnQoaywgbFtrXSlcbiAgICAgICAgICAgICAgICBjbGVhbnVwRnVuY3MucHVzaChmdW5jdGlvbigpe1xuICAgICAgICAgICAgICAgICAgZS5kZXRhY2hFdmVudChrLCBsW2tdKVxuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIC8vIG9ic2VydmFibGVcbiAgICAgICAgICAgICAgZVtrXSA9IGxba10oKVxuICAgICAgICAgICAgICBjbGVhbnVwRnVuY3MucHVzaChsW2tdKGZ1bmN0aW9uICh2KSB7XG4gICAgICAgICAgICAgICAgZVtrXSA9IHZcbiAgICAgICAgICAgICAgfSkpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGVsc2UgaWYoayA9PT0gJ3N0eWxlJykge1xuICAgICAgICAgICAgaWYoJ3N0cmluZycgPT09IHR5cGVvZiBsW2tdKSB7XG4gICAgICAgICAgICAgIGUuc3R5bGUuY3NzVGV4dCA9IGxba11cbiAgICAgICAgICAgIH1lbHNle1xuICAgICAgICAgICAgICBmb3IgKHZhciBzIGluIGxba10pIChmdW5jdGlvbihzLCB2KSB7XG4gICAgICAgICAgICAgICAgaWYoJ2Z1bmN0aW9uJyA9PT0gdHlwZW9mIHYpIHtcbiAgICAgICAgICAgICAgICAgIC8vIG9ic2VydmFibGVcbiAgICAgICAgICAgICAgICAgIGUuc3R5bGUuc2V0UHJvcGVydHkocywgdigpKVxuICAgICAgICAgICAgICAgICAgY2xlYW51cEZ1bmNzLnB1c2godihmdW5jdGlvbiAodmFsKSB7XG4gICAgICAgICAgICAgICAgICAgIGUuc3R5bGUuc2V0UHJvcGVydHkocywgdmFsKVxuICAgICAgICAgICAgICAgICAgfSkpXG4gICAgICAgICAgICAgICAgfSBlbHNlXG4gICAgICAgICAgICAgICAgICBlLnN0eWxlLnNldFByb3BlcnR5KHMsIGxba11bc10pXG4gICAgICAgICAgICAgIH0pKHMsIGxba11bc10pXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChrLnN1YnN0cigwLCA1KSA9PT0gXCJkYXRhLVwiKSB7XG4gICAgICAgICAgICBEYXRhU2V0KGUpW2suc3Vic3RyKDUpXSA9IGxba11cbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgZVtrXSA9IGxba11cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH0gZWxzZSBpZiAoJ2Z1bmN0aW9uJyA9PT0gdHlwZW9mIGwpIHtcbiAgICAgICAgLy9hc3N1bWUgaXQncyBhbiBvYnNlcnZhYmxlIVxuICAgICAgICB2YXIgdiA9IGwoKVxuICAgICAgICBlLmFwcGVuZENoaWxkKHIgPSBpc05vZGUodikgPyB2IDogZG9jdW1lbnQuY3JlYXRlVGV4dE5vZGUodikpXG5cbiAgICAgICAgY2xlYW51cEZ1bmNzLnB1c2gobChmdW5jdGlvbiAodikge1xuICAgICAgICAgIGlmKGlzTm9kZSh2KSAmJiByLnBhcmVudEVsZW1lbnQpXG4gICAgICAgICAgICByLnBhcmVudEVsZW1lbnQucmVwbGFjZUNoaWxkKHYsIHIpLCByID0gdlxuICAgICAgICAgIGVsc2VcbiAgICAgICAgICAgIHIudGV4dENvbnRlbnQgPSB2XG4gICAgICAgIH0pKVxuICAgICAgfVxuXG4gICAgICByZXR1cm4gclxuICAgIH1cbiAgICB3aGlsZShhcmdzLmxlbmd0aClcbiAgICAgIGl0ZW0oYXJncy5zaGlmdCgpKVxuXG4gICAgcmV0dXJuIGVcbiAgfVxuXG4gIGguY2xlYW51cCA9IGZ1bmN0aW9uICgpIHtcbiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGNsZWFudXBGdW5jcy5sZW5ndGg7IGkrKyl7XG4gICAgICBjbGVhbnVwRnVu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xhc3NMaXN0ID0ge1xuICAgICAgICBhZGQ6IGFkZFxuICAgICAgICAsIHJlbW92ZTogcmVtb3ZlXG4gICAgICAgICwgY29udGFpbnM6IGNvbnRhaW5zXG4gICAgICAgICwgdG9nZ2xlOiB0b2dnbGVcbiAgICAgICAgLCB0b1N0cmluZzogJHRvU3RyaW5nXG4gICAgICAgICwgbGVuZ3RoOiAwXG4gICAgICAgICwgaXRlbTogaXRlbVxuICAgIH1cblxuICAgIHJldHVybiBjbGFzc0xpc3RcblxuICAgIGZ1bmN0aW9uIGFkZCh0b2tlbikge1xuICAgICAgICB2YXIgbGlzdCA9IGdldFRva2VucygpXG4gICAgICAgIGlmIChpbmRleG9mKGxpc3QsIHRva2VuKSA+IC0xKSB7XG4gICAgICAgICAgICByZXR1cm5cbiAgICAgICAgfVxuICAgICAgICBsaXN0LnB1c2godG9rZW4pXG4gICAgICAgIHNldFRva2VucyhsaXN0KVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIHJlbW92ZSh0b2tlbikge1xuICAgICAgICB2YXIgbGlzdCA9IGdldFRva2VucygpXG4gICAgICAgICAgICAsIGluZGV4ID0gaW5kZXhvZihsaXN0LCB0b2tlbilcblxuICAgICAgICBpZiAoaW5kZXggPT09IC0xKSB7XG4gICAgICAgICAgICByZXR1cm5cbiAgICAgICAgfVxuXG4gICAgICAgIGxpc3Quc3BsaWNlKGluZGV4LCAxKVxuICAgICAgICBzZXRUb2tlbnMobGlzdClcbiAgICB9XG5cbiAgICBmdW5jdGlvbiBjb250YWlucyh0b2tlbikge1xuICAgICAgICByZXR1cm4gaW5kZXhvZihnZXRUb2tlbnMoKSwgdG9rZW4pID4gLTFcbiAgICB9XG5cbiAgICBmdW5jdGlvbiB0b2dnbGUodG9rZW4pIHtcbiAgICAgICAgaWYgKGNvbnRhaW5zKHRva2VuKSkge1xuICAgICAgICAgICAgcmVtb3ZlKHRva2VuKVxuICAgICAgICAgICAgcmV0dXJuIGZhbHNlXG4gICAgICAgIH0gZW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2V5ID09ICdtZXNzYWdlJyB8fCBrZXkgPT0gJ25hbWUnKSkpIHtcclxuICAgICAgICByZXN1bHQucHVzaChrZXkpO1xyXG4gICAgICB9XHJcbiAgICB9XHJcblxyXG4gICAgaWYgKHN1cHBvcnQubm9uRW51bVNoYWRvd3MgJiYgb2JqZWN0ICE9PSBvYmplY3RQcm90bykge1xyXG4gICAgICB2YXIgY3RvciA9IG9iamVjdC5jb25zdHJ1Y3RvcixcclxuICAgICAgICAgIGluZGV4ID0gLTEsXHJcbiAgICAgICAgICBsZW5ndGggPSBzaGFkb3dlZFByb3BzLmxlbmd0aDtcclxuXHJcbiAgICAgIGlmIChvYmplY3QgPT09IChjdG9yICYmIGN0b3IucHJvdG90eXBlKSkge1xyXG4gICAgICAgIHZhciBjbGFzc05hbWUgPSBvYmplY3QgPT09IHN0cmluZ1Byb3RvID8gc3RyaW5nQ2xhc3MgOiBvYmplY3QgPT09IGVycm9yUHJvdG8gPyBlcnJvckNsYXNzIDogdG9TdHJpbmcuY2FsbChvYmplY3QpLFxyXG4gICAgICAgICAgICBub25FbnVtID0gbm9uRW51bVByb3BzW2NsYXNzTmFtZV07XHJcbiAgICAgIH1cclxuICAgICAgd2hpbGUgKCsraW5kZXggPCBsZW5ndGgpIHtcclxuICAgICAgICBrZXkgPSBzaGFkb3dlZFByb3BzW2luZGV4XTtcclxuICAgICAgICBpZiAoIShub25FbnVtICYmIG5vbkVudW1ba2V5XSkgJiYgaGFzT3duUHJvcGVydHkuY2FsbChvYmplY3QsIGtleSkpIHtcclxuICAgICAgICAgIHJlc3VsdC5wdXNoKGtleSk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9XHJcbiAgICB9XHJcbiAgICByZXR1cm4gcmVzdWx0O1xyXG4gIH1cclxuXHJcbiAgZnVuY3Rpb24gaW50ZXJuYWxGb3Iob2JqZWN0LCBjYWxsYmFjaywga2V5c0Z1bmMpIHtcclxuICAgIHZhciBpbmRleCA9IC0xLFxyXG4gICAgICBwcm9wc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cmUgZWFjaCBwcm9wZXJ0eSB2YWx1ZS5cclxuICAgICAgICAgIHJldHVybiAocmVzdWx0ID0gaGFzT3duUHJvcGVydHkuY2FsbChhLCBrZXkpICYmIGRlZXBFcXVhbHMoYVtrZXldLCB2YWx1ZSwgc3RhY2tBLCBzdGFja0IpKTtcclxuICAgICAgICB9XHJcbiAgICAgIH0pO1xyXG5cclxuICAgICAgaWYgKHJlc3VsdCkge1xyXG4gICAgICAgIC8vIGVuc3VyZSBib3RoIG9iamVjdHMgaGF2ZSB0aGUgc2FtZSBudW1iZXIgb2YgcHJvcGVydGllc1xyXG4gICAgICAgIGludGVybmFsRm9ySW4oYSwgZnVuY3Rpb24odmFsdWUsIGtleSwgYSkge1xyXG4gICAgICAgICAgaWYgKGhhc093blByb3BlcnR5LmNhbGwoYSwga2V5KSkge1xyXG4gICAgICAgICAgICAvLyBgc2l6ZWAgd2lsbCBiZSBgLTFgIGlmIGBhYCBoYXMgbW9yZSBwcm9wZXJ0aWVzIHRoYW4gYGJgXHJcbiAgICAgICAgICAgIHJldHVybiAocmVzdWx0ID0gLS1zaXplID4gLTEpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG4gICAgICB9XHJcbiAgICB9XHJcbiAgICBzdGFja0EucG9wKCk7XHJcbiAgICBzdGFja0IucG9wKCk7XHJcblxyXG4gICAgcmV0dXJuIHJlc3VsdDtcclxuICB9XHJcbiAgICB2YXIgc2xpY2UgPSBBcnJheS5wcm90b3R5cGUuc2xpY2U7XHJcbiAgICBmdW5jdGlvbiBhcmdzT3JBcnJheShhcmdzLCBpZHgpIHtcclxuICAgICAgICByZXR1cm4gYXJncy5sZW5ndGggPT09IDEgJiYgQXJyYXkuaXNBcnJheShhcmdzW2lkeF0pID9cclxuICAgICAgICAgICAgYXJnc1tpZHhdIDpcclxuICAgICAgICAgICAgc2xpY2UuY2FsbChhcmdzKTtcclxuICAgIH1cclxuICAgIHZhciBoYXNQcm9wID0ge30uaGFzT3duUHJvcGVydHk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgaW5oZXJpdHMgPSB0aGlzLmluaGVyaXRzID0gUnguaW50ZXJuYWxzLmluaGVyaXRzID0gZnVuY3Rpb24gKGNoaWxkLCBwYXJlbnQpIHtcclxuICAgICAgICBmdW5jdGlvbiBfXygpIHsgdGhpcy5jb25zdHJ1Y3RvciA9IGNoaWxkOyB9XHJcbiAgICAgICAgX18ucHJvdG90eXBlID0gcGFyZW50LnByb3RvdHlwZTtcclxuICAgICAgICBjaGlsZC5wcm90b3R5cGUgPSBuZXcgX18oKTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovICAgIFxyXG4gICAgdmFyIGFkZFByb3BlcnRpZXMgPSBSeC5pbnRlcm5hbHMuYWRkUHJvcGVydGllcyA9IGZ1bmN0aW9uIChvYmopIHtcclxuICAgICAgICB2YXIgc291cmNlcyA9IHNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTtcclxuICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gc291cmNlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICB2YXIgc291cmNlID0gc291cmNlc1tpXTtcclxuICAgICAgICAgICAgZm9yICh2YXIgcHJvcCBpbiBzb3VyY2UpIHtcclxuICAgICAgICAgICAgICAgIG9ialtwcm9wXSA9IHNvdXJjZVtwcm9wXTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgIH07XHJcblxyXG4gICAgLy8gUnggVXRpbHNcclxuICAgIHZhciBhZGRSZWYgPSBSeC5pbnRlcm5hbHMuYWRkUmVmID0gZnVuY3Rpb24gKHhzLCByKSB7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGU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iBAcmV0dXJuIFRoZSB1bmRlcmx5aW5nIGRpc3Bvc2FibGUuXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgYm9vbGVhbkRpc3Bvc2FibGVQcm90b3R5cGUuZ2V0RGlzcG9zYWJsZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHRoaXMuY3VycmVudDtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBTZXRzIHRoZSB1bmRlcmx5aW5nIGRpc3Bvc2FibGUuXHJcbiAgICAgICAgICogQHBhcmFtIHtEaXNwb3NhYmxlfSB2YWx1ZSBUaGUgbmV3IHVuZGVybHlpbmcgZGlzcG9zYWJsZS5cclxuICAgICAgICAgKi8gIFxyXG4gICAgICAgIGJvb2xlYW5EaXNwb3NhYmxlUHJvdG90eXBlLnNldERpc3Bvc2FibGUgPSBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgaWYgKHRoaXMuY3VycmVudCAmJiB0aGlzLmlzU2luZ2xlKSB7XHJcbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ0Rpc3Bvc2FibGUgaGFzIGFscmVhZHkgYmVlbiBhc3NpZ25lZCcpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICB2YXIgc2hvdWxkRGlzcG9zZSA9IHRoaXMuaXNEaXNwb3NlZCwgb2xkO1xyXG4gICAgICAgICAgICBpZiAoIXNob3VsZERpc3Bvc2UpIHtcclxuICAgICAgICAgICAgICAgIG9sZCA9IHRoaXMuY3VycmVudDtcclxuICAgICAgICAgICAgICAgIHRoaXMuY3VycmVudCA9IHZhbHVlO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmIChvbGQpIHtcclxuICAgICAgICAgICAgICAgIG9sZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgaWYgKHNob3VsZERpc3Bvc2UgJiYgdmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHZhbHVlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKiBcclxuICAgICAgICAgKiBEaXNwb3NlcyB0aGUgdW5kZXJseWluZyBkaXNwb3NhYmxlIGFzIHdlbGwgYXMgYWxsIGZ1dHVyZSByZXBsYWNlbWVudHMuXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgYm9vbGVhbkRpc3Bvc2FibGVQcm90b3R5cGUuZGlzcG9zZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdmFyIG9sZDtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBvbGQgPSB0aGlzLmN1cnJlbnQ7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmN1cnJlbnQgPSBudWxsO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmIChvbGQpIHtcclxuICAgICAgICAgICAgICAgIG9sZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICByZXR1cm4gQm9vbGVhbkRpc3Bvc2FibGU7XHJcbiAgICB9KCkpO1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogUmVwcmVzZW50cyBhIGRpc3Bvc2FibGUgcmVzb3VyY2Ugd2hpY2ggb25seSBhbGxvd3MgYSBzaW5nbGUgYXNzaWdubWVudCBvZiBpdHMgdW5kZXJseWluZyBkaXNwb3NhYmxlIHJlc291cmNlLlxyXG4gICAgICogSWYgYW4gdW5kZXJseWluZyBkaXNwb3NhYmxlIHJlc291cmNlIGhhcyBhbHJlYWR5IGJlZW4gc2V0LCBmdXR1cmUgYXR0ZW1wdHMgdG8gc2V0IHRoZSB1bmRlcmx5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zLCBmYWxzZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICByZXR1cm4gU2VyaWFsRGlzcG9zYWJsZTtcclxuICAgIH0oQm9vbGVhbkRpc3Bvc2FibGUpKTtcclxuXHJcbiAgICAvKipcclxuICAgICAqIFJlcHJlc2VudHMgYSBkaXNwb3NhYmxlIHJlc291cmNlIHRoYXQgb25seSBkaXNwb3NlcyBpdHMgdW5kZXJseWluZyBkaXNwb3NhYmxlIHJlc291cmNlIHdoZW4gYWxsIGRlcGVuZGVudCBkaXNwb3NhYmxlIG9iamVjdHMgaGF2ZSBiZWVuIGRpc3Bvc2VkLlxyXG4gICAgICovICBcclxuICAgIHZhciBSZWZDb3VudERpc3Bvc2FibGUgPSBSeC5SZWZDb3VudERpc3Bvc2FibGUgPSAoZnVuY3Rpb24gKCkge1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBJbm5lckRpc3Bvc2FibGUoZGlzcG9zYWJsZSkge1xyXG4gICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUgPSBkaXNwb3NhYmxlO1xyXG4gICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUuY291bnQrKztcclxuICAgICAgICAgICAgdGhpcy5pc0lubmVyRGlzcG9zZWQgPSBmYWxzZTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIElubmVyRGlzcG9zYWJsZS5wcm90b3R5cGUuZGlzcG9zZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmRpc3Bvc2FibGUuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzSW5uZXJEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNJbm5lckRpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUuY291bnQtLTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5kaXNwb3Nh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yBoYXZlIGJlZW4gZGlzcG9zZWQgXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgUmVmQ291bnREaXNwb3NhYmxlLnByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzUHJpbWFyeURpc3Bvc2VkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1ByaW1hcnlEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuY291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy51bmRlcmx5aW5nRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogUmV0dXJucyBhIGRlcGVuZGVudCBkaXNwb3NhYmxlIHRoYXQgd2hlbiBkaXNwb3NlZCBkZWNyZWFzZXMgdGhlIHJlZmNvdW50IG9uIHRoZSB1bmRlcmx5aW5nIGRpc3Bvc2FibGUuICAgICAgXHJcbiAgICAgICAgICogQHJldHVybnMge0Rpc3Bvc2FibGV9IEEgZGVwZW5kZW50IGRpc3Bvc2FibGUgY29udHJpYnV0aW5nIHRvIHRoZSByZWZlcmVuY2UgY291bnQgdGhhdCBtYW5hZ2VzIHRoZSB1bmRlcmx5aW5nIGRpc3Bvc2FibGUncyBsaWZldGltZS5cclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIFJlZkNvdW50RGlzcG9zYWJsZS5wcm90b3R5cGUuZ2V0RGlzcG9zYWJsZSA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jaGVkdWxlV2l0aFN0YXRlKHN0YXRlMiwgZnVuY3Rpb24gKHNjaGVkdWxlcjEsIHN0YXRlMykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNBZGRlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaXNEb25lID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICByZWN1cnNpdmVBY3Rpb24oc3RhdGUzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoIWlzRG9uZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBncm91cC5hZGQoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlzQWRkZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICByZWN1cnNpdmVBY3Rpb24oc3RhdGUpO1xyXG4gICAgICAgICAgICByZXR1cm4gZ3JvdXA7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiBpbnZva2VSZWNEYXRlKHNjaGVkdWxlciwgcGFpciwgbWV0aG9kKSB7XHJcbiAgICAgICAgICAgIHZhciBzdGF0ZSA9IHBhaXIuZmlyc3QsIGFjdGlvbiA9IHBhaXIuc2Vjb25kLCBncm91cCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgIHJlY3Vyc2l2ZUFjdGlvbiA9IGZ1bmN0aW9uIChzdGF0ZTEpIHtcclxuICAgICAgICAgICAgICAgIGFjdGlvbihzdGF0ZTEsIGZ1bmN0aW9uIChzdGF0ZTIsIGR1ZVRpbWUxKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGlzQWRkZWQgPSBmYWxzZSwgaXNEb25lID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICAgICAgZCA9IHNjaGVkdWxlclttZXRob2RdLmNhbGwoc2NoZWR1bGVyLCBzdGF0ZTIsIGR1ZVRpbWUxLCBmdW5jdGlvbiAoc2NoZWR1bGVyMSwgc3RhdGUzKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpc0FkZGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBncm91cC5yZW1vdmUoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc0RvbmUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlY3Vyc2l2ZUFjdGlvbihzdGF0ZTMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghaXNEb25lKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLmFkZChkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaXNBZGRlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIHJlY3Vyc2l2ZUFjdGlvbihzdGF0ZSk7XHJcbiAgICAgICAgICAgIHJldHVybiBncm91cDtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIGludm9rZUFjdGlvbihzY2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WR1bGVOb3csIHNjaGVkdWxlUmVsYXRpdmUsIHNjaGVkdWxlQWJzb2x1dGUpO1xyXG4gIH0oKSk7XHJcblxyXG4gICAgLyoqIFxyXG4gICAgICogR2V0cyBhIHNjaGVkdWxlciB0aGF0IHNjaGVkdWxlcyB3b3JrIGFzIHNvb24gYXMgcG9zc2libGUgb24gdGhlIGN1cnJlbnQgdGhyZWFkLlxyXG4gICAgICovXHJcbiAgICB2YXIgY3VycmVudFRocmVhZFNjaGVkdWxlciA9IFNjaGVkdWxlci5jdXJyZW50VGhyZWFkID0gKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICB2YXIgcXVldWU7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHJ1blRyYW1wb2xpbmUgKHEpIHtcclxuICAgICAgICAgICAgdmFyIGl0ZW07XHJcbiAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgIGl0ZW0gPSBxLmRlcXVldWUoKTtcclxuICAgICAgICAgICAgICAgIGlmICghaXRlbS5pc0NhbmNlbGxlZCgpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgLy8gTm90ZSwgZG8gbm90IHNjaGVkdWxlIGJsb2NraW5nIHdvcmshXHJcbiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGl0ZW0uZHVlVGltZSAtIFNjaGVkdWxlci5ub3coKSA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFpdGVtLmlzQ2FuY2VsbGVkKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaXRlbS5pbnZva2UoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0gICAgICAgICAgICBcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHNjaGVkdWxlTm93KHN0YXRlLCBhY3Rpb24pIHtcclxuICAgICAgICAgICAgcmV0dXJuIHRoaXMuc2NoZWR1bGVXaXRoUmVsYXRpdmVBbmRTdGF0ZShzdGF0ZSwgMCwgYWN0aW9uKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHNjaGVkdWxlUmVsYXRpdmUoc3RhdGUsIGR1ZVRpbWUsIGFjdGlvbikge1xyXG4gICAgICAgICAgICB2YXIgZHQgPSB0aGlzLm5vdygpICsgU2NoZWR1bGVyLm5vcm1hbGl6ZShkdWVUaW1lKSxcclxuICAgICAgICAgICAgICAgICAgICBzaSA9IG5ldyBTY2hlZHVsZWRJdGVtKHRoaXMsIHN0YXRlLCBhY3Rpb24sIGR0KSxcclxuICAgICAgICAgICAgICAgICAgICB0O1xyXG4gICAgICAgICAgICBpZiAoIXF1ZXVlKSB7XHJcbiAgICAgICAgICAgICAgICBxdWV1ZSA9IG5ldyBQcmlvcml0eVF1ZXVlKDQpO1xyXG4gICAgICAgICAgICAgICAgcXVldWUuZW5xdWV1ZShzaSk7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJ1blRyYW1wb2xpbmUocXVldWUpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgeyBcclxuICAgICAgICAgICAgICAgICAgICB0aHJvdyBlO1xyXG4gICAgICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgICAgICBxdWV1ZSA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBxdWV1ZS5lbnF1ZXVlKHNpKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICByZXR1cm4gc2kuZGlzcG9zYWJsZTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHNjaGVkdWxlQWJzb2x1dGUoc3RhdGUsIGR1ZVRpbWUsIGFjdGlvbikge1xy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GSVgubGVuZ3RoKSA9PT0gTVNHX1BSRUZJWCkge1xyXG4gICAgICAgICAgICAgIHZhciBoYW5kbGVJZCA9IGV2ZW50LmRhdGEuc3Vic3RyaW5nKE1TR19QUkVGSVgubGVuZ3RoKSxcclxuICAgICAgICAgICAgICAgIGFjdGlvbiA9IHRhc2tzW2hhbmRsZUlkXTtcclxuICAgICAgICAgICAgICBhY3Rpb24oKTtcclxuICAgICAgICAgICAgICBkZWxldGUgdGFza3NbaGFuZGxlSWRdO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgaWYgKHJvb3QuYWRkRXZlbnRMaXN0ZW5lcikge1xyXG4gICAgICAgICAgICByb290LmFkZEV2ZW50TGlzdGVuZXIoJ21lc3NhZ2UnLCBvbkdsb2JhbFBvc3RNZXNzYWdlLCBmYWxzZSk7XHJcbiAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICByb290LmF0dGFjaEV2ZW50KCdvbm1lc3NhZ2UnLCBvbkdsb2JhbFBvc3RNZXNzYWdlLCBmYWxzZSk7XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgc2NoZWR1bGVNZXRob2QgPSBmdW5jdGlvbiAoYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIHZhciBjdXJyZW50SWQgPSB0YXNrSWQrKztcclxuICAgICAgICAgICAgdGFza3NbY3VycmVudElkXSA9IGFjdGlvbjtcclxuICAgICAgICAgICAgcm9vdC5wb3N0TWVzc2FnZShNU0dfUFJFRklYICsgY3VycmVudElkLCAnKicpO1xyXG4gICAgICAgICAgfTtcclxuICAgICAgfSBlbHNlIGlmICghIXJvb3QuTWVzc2FnZUNoYW5uZWwpIHtcclxuICAgICAgICAgIHZhciBjaGFubmVsID0gbmV3IHJvb3QuTWVzc2FnZUNoYW5uZWwoKSxcclxuICAgICAgICAgICAgY2hhbm5lbFRhc2tzID0ge30sXHJcbiAgICAgICAgICAgIGNoYW5uZWxUY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rpb24pIHtcclxuICAgICAgICAgICAgdmFyIHBhcmVudCA9IHRoaXM7XHJcbiAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbiAoc2VsZiwgc3RhdGUpIHtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGFjdGlvbihwYXJlbnQuX2dldFJlY3Vyc2l2ZVdyYXBwZXIoc2VsZiksIHN0YXRlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoIXBhcmVudC5faGFuZGxlcihlKSkgeyB0aHJvdyBlOyB9XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKiogQHByaXZhdGUgKi9cclxuICAgICAgICBDYXRjaFNjaGVkdWxlci5wcm90b3R5cGUuX2dldFJlY3Vyc2l2ZVdyYXBwZXIgPSBmdW5jdGlvbiAoc2NoZWR1bGVyKSB7XHJcbiAgICAgICAgICAgIGlmICh0aGlzLl9yZWN1cnNpdmVPcmlnaW5hbCAhPT0gc2NoZWR1bGVyKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9yZWN1cnNpdmVPcmlnaW5hbCA9IHNjaGVkdWxlcjtcclxuICAgICAgICAgICAgICAgIHZhciB3cmFwcGVyID0gdGhpcy5fY2xvbmUoc2NoZWR1bGVyKTtcclxuICAgICAgICAgICAgICAgIHdyYXBwZXIuX3JlY3Vyc2l2ZU9yaWdpbmFsID0gc2NoZWR1bGVyO1xyXG4gICAgICAgICAgICAgICAgd3JhcHBlci5fcmVjdXJzaXZlV3JhcHBlciA9IHdyYXBwZXI7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9yZWN1cnNpdmVXcmFwcGVyID0gd3JhcHBlcjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fcmVjdXJzaXZlV3JhcHBlcjtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKiogQHByaXZhdGUgKi9cclxuICAgICAgICBDYXRjaFNjaGVkdWxlci5wcm90b3R5cGUuc2NoZWR1bGVQZXJpb2RpY1dpdGhTdGF0ZSA9IGZ1bmN0aW9uIChzdGF0ZSwgcGVyaW9kLCBhY3Rpb24pIHtcclxuICAgICAgICAgICAgdmFyIHNlbGYgPSB0aGlzLCBmYWlsZWQgPSBmYWxzZSwgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG5cclxuICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKHRoaXMuX3NjaGVkdWxlci5zY2hlZHVsZVBlcmlvZGljV2l0aFN0YXRlKHN0YXRlLCBwZXJpb2QsIGZ1bmN0aW9uIChzdGF0ZTEpIHtcclxuICAgICAgICAgICAgICAgIGlmIChmYWlsZWQpIHsgcmV0dXJuIG51bGw7IH1cclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGFjdGlvbihzdGF0ZTEpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGZhaWxlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFzZWxmLl9oYW5kbGVyKGUpKSB7IHRocm93IGU7IH1cclxuICAgICAgICAgICAgICAgICAgICBkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG5cclxuICAgICAgICAgICAgcmV0dXJuIGQ7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgcmV0dXJuIENhdGNoU2NoZWR1bGVyO1xyXG4gICAgfShTY2hlZHV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WNlcyB0aGUgYmVoYXZpb3Igb2YgdGhlIG5vdGlmaWNhdGlvbiB1cG9uIHN1YnNjcmlwdGlvbi5cclxuICAgICAgICAgKi9cclxuICAgICAgICBOb3RpZmljYXRpb25Qcm90b3R5cGUudG9PYnNlcnZhYmxlID0gZnVuY3Rpb24gKHNjaGVkdWxlcikge1xyXG4gICAgICAgICAgICB2YXIgbm90aWZpY2F0aW9uID0gdGhpcztcclxuICAgICAgICAgICAgc2NoZWR1bGVyIHx8IChzY2hlZHVsZXIgPSBpbW1lZGlhdGVTY2hlZHVsZXIpO1xyXG4gICAgICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBub3RpZmljYXRpb24uX2FjY2VwdE9ic2VydmFibGUob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChub3RpZmljYXRpb24ua2luZCA9PT0gJ04nKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIHJldHVybiBOb3RpZmljYXRpb247XHJcbiAgICB9KSgpO1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogQ3JlYXRlcyBhbiBvYmplY3QgdGhhdCByZXByZXNlbnRzIGFuIE9uTmV4dCBub3RpZmljYXRpb24gdG8gYW4gb2JzZXJ2ZXIuXHJcbiAgICAgKiBAcGFyYW0ge0FueX0gdmFsdWUgVGhlIHZhbHVlIGNvbnRhaW5lZCBpbiB0aGUgbm90aWZpY2F0aW9uLlxyXG4gICAgICogQHJldHVybnMge05vdGlmaWNhdGlvbn0gVGhlIE9uTmV4dCBub3RpZmljYXRpb24gY29udGFpbmluZyB0aGUgdmFsdWUuXHJcbiAgICAgKi9cclxuICAgIHZhciBub3RpZmljYXRpb25DcmVhdGVPbk5leHQgPSBOb3RpZmljYXRpb24uY3JlYXRlT25OZXh0ID0gKGZ1bmN0aW9uICgpIHtcclxuXHJcbiAgICAgICAgZnVuY3Rpb24gX2FjY2VwdCAob25OZXh0KSB7XHJcbiAgICAgICAgICAgIHJldHVybiBvbk5leHQodGhpcy52YWx1ZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiBfYWNjZXB0T2JzZXJ2YWJsZShvYnNlcnZlcikge1xyXG4gICAgICAgICAgICByZXR1cm4gb2JzZXJ2ZXIub25OZXh0KHRoaXMudmFsdWUpO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gdG9TdHJpbmcgKCkge1xyXG4gICAgICAgICAgICByZXR1cm4gJ09uTmV4dCgnICsgdGhpcy52YWx1ZSArICcpJztcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHJldHVybiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgdmFyIG5vdGlmaWNhdGlvbiA9IG5ldyBOb3RpZmljYXRpb24oJ04nLCB0cnVlKTtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLnZhbHVlID0gdmFsdWU7XHJcbiAgICAgICAgICAgIG5vdGlmaWNhdGlvbi5fYWNjZXB0ID0gX2FjY2VwdDtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLl9hY2NlcHRPYnNlcnZhYmxlID0gX2FjY2VwdE9ic2VydmFibGU7XHJcbiAgICAgICAgICAgIG5vdGlmaWNhdGlvbi50b1N0cmluZyA9IHRvU3RyaW5nO1xyXG4gICAgICAgICAgICByZXR1cm4gbm90aWZpY2F0aW9uO1xyXG4gICAgICAgIH07XHJcbiAgICB9KCkpO1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogQ3JlYXRlcyBhbiBvYmplY3QgdGhhdCByZXByZXNlbnRzIGFuIE9uRXJyb3Igbm90aWZpY2F0aW9uIHRvIGFuIG9ic2VydmVyLlxyXG4gICAgICogQHBhcmFtIHtBbnl9IGVycm9yIFRoZSBleGNlcHRpb24gY29udGFpbmVkIGluIHRoZSBub3RpZmljYXRpb24uXHJcbiAgICAgKiBAcmV0dXJucyB7Tm90aWZpY2F0aW9ufSBUaGUgT25FcnJvciBub3RpZmljYXRpb24gY29udGFpbmluZyB0aGUgZXhjZXB0aW9uLlxyXG4gICAgICovXHJcbiAgICB2YXIgbm90aWZpY2F0aW9uQ3JlYXRlT25FcnJvciA9IE5vdGlmaWNhdGlvbi5jcmVhdGVPbkVycm9yID0gKGZ1bmN0aW9uICgpIHtcclxuXHJcbiAgICAgICAgZnVuY3Rpb24gX2FjY2VwdCAob25OZXh0LCBvbkVycm9yKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBvbkVycm9yKHRoaXMuZXhjZXB0aW9uKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIF9hY2NlcHRPYnNlcnZhYmxlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBvYnNlcnZlci5vbkVycm9yKHRoaXMuZXhjZXB0aW9uKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHRvU3RyaW5nICgpIHtcclxuICAgICAgICAgICAgcmV0dXJuICdPbkVycm9yKCcgKyB0aGlzLmV4Y2VwdGlvbiArICcpJztcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHJldHVybiBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgIHZhciBub3RpZmljYXRpb24gPSBuZXcgTm90aWZpY2F0aW9uKCdFJyk7XHJcbiAgICAgICAgICAgIG5vdGlmaWNhdGlvbi5leGNlcHRpb24gPSBleGNlcHRpb247XHJcbi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AgdmFyIGlzRGlzcG9zZWQsIFxyXG4gICAgICAgIGxhc3RFeGNlcHRpb24sXHJcbiAgICAgICAgc3Vic2NyaXB0aW9uID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKTtcclxuICAgICAgdmFyIGNhbmNlbGFibGUgPSBpbW1lZGlhdGVTY2hlZHVsZXIuc2NoZWR1bGVSZWN1cnNpdmUoZnVuY3Rpb24gKHNlbGYpIHtcclxuICAgICAgICBpZiAoaXNEaXNwb3NlZCkgeyByZXR1cm47IH1cclxuXHJcbiAgICAgICAgdmFyIGN1cnJlbnRJdGVtO1xyXG4gICAgICAgIHRyeSB7XHJcbiAgICAgICAgICBjdXJyZW50SXRlbSA9IGUubmV4dCgpO1xyXG4gICAgICAgIH0gY2F0Y2ggKGV4KSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGlmIChjdXJyZW50SXRlbS5kb25lKSB7XHJcbiAgICAgICAgICBpZiAobGFzdEV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGxhc3RFeGNlcHRpb24pO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8vIENoZWNrIGlmIHByb21pc2VcclxuICAgICAgICB2YXIgY3VycmVudFZhbHVlID0gY3VycmVudEl0ZW0udmFsdWU7XHJcbiAgICAgICAgaXNQcm9taXNlKGN1cnJlbnRWYWx1ZSkgJiYgKGN1cnJlbnRWYWx1ZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShjdXJyZW50VmFsdWUpKTsgICAgICAgIFxyXG5cclxuICAgICAgICB2YXIgZCA9IG5ldyBTaW5nbGVBc3NpZ25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uIGV4Y2VwdGlvbiBoYXMgb2NjdXJyZWQuXHJcbiAgICAgICAgICogXHJcbiAgICAgICAgICogQG1lbWJlck9mIEFic3RyYWN0T2JzZXJ2ZXJcclxuICAgICAgICAgKiBAcGFyYW0ge0FueX0gZXJyb3IgVGhlIGVycm9yIHRoYXQgaGFzIG9jY3VycmVkLiAgICAgXHJcbiAgICAgICAgICovICAgIFxyXG4gICAgICAgIEFic3RyYWN0T2JzZXJ2ZXIucHJvdG90eXBlLm9uRXJyb3IgPSBmdW5jdGlvbiAoZXJyb3IpIHtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5lcnJvcihlcnJvcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBOb3RpZmllcyB0aGUgb2JzZXJ2ZXIgb2YgdGhlIGVuZCBvZiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICovICAgIFxyXG4gICAgICAgIEFic3RyYWN0T2JzZXJ2ZXIucHJvdG90eXBlLm9uQ29tcGxldGVkID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogRGlzcG9zZXMgdGhlIG9ic2VydmVyLCBjYXVzaW5nIGl0IHRvIHRyYW5zaXRpb24gdG8gdGhlIHN0b3BwZWQgc3RhdGUuXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgQWJzdHJhY3RPYnNlcnZlci5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FxyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTsgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IDA7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUub25FcnJvciA9IGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgICAgdGhpcy5jaGVja0FjY2VzcygpO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7IFxyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTsgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IDI7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUub25Db21wbGV0ZWQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRoaXMuY2hlY2tBY2Nlc3MoKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX29ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlOyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5jaGVja0FjY2VzcyA9IGZ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JucyB7T2JzZXJ2YWJsZX0gVGhlIGdlbmVyYXRlZCBzZXF1ZW5jZS5cclxuICAgICAqL1xyXG4gICAgT2JzZXJ2YWJsZS5nZW5lcmF0ZSA9IGZ1bmN0aW9uIChpbml0aWFsU3RhdGUsIGNvbmRpdGlvbiwgaXRlcmF0ZSwgcmVzdWx0U2VsZWN0b3IsIHNjaGVkdWxlcikge1xyXG4gICAgICAgIHNjaGVkdWxlciB8fCAoc2NoZWR1bGVyID0gY3VycmVudFRocmVhZFNjaGVkdWxlcik7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgZmlyc3QgPSB0cnVlLCBzdGF0ZSA9IGluaXRpYWxTdGF0ZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZShmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICAgICAgdmFyIGhhc1Jlc3VsdCwgcmVzdWx0O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoZmlyc3QpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZmlyc3QgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZSA9IGl0ZXJhdGUoc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBoYXNSZXN1bHQgPSBjb25kaXRpb24oc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3Ioc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzUmVzdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICAgICAgc2VsZigpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIC8qKlxyXG4gICAqICBUaGlzIG1ldGhvZCBjcmVhdGVzIGEgbmV3IE9ic2VydmFibGUgaW5zdGFuY2Ugd2l0aCBhIHZhcmlhYmxlIG51bWJlciBvZiBhcmd1bWVudHMsIHJlZ2FyZGxlc3Mgb2YgbnVtYmVyIG9yIHR5cGUgb2YgdGhlIGFyZ3VtZW50cy5cclxuICAgKiBAZXhhbXBsZVxyXG4gICAqICB2YXIgcmVzID0gUnguT2JzZXJ2YWJsZS5vZigxLDIsMyk7XHJcbiAgICogQHJldHVybnMge09ic2VydmFibGV9IFRoZSBvYnNlcnZhYmxlIHNlcXVlbmNlIHdob3NlIGVsZW1lbnRzIGFyZSBwdWxsZWQgZnJvbSB0aGUgZ2l2ZW4gYXJndW1lbnRzLlxyXG4gICAqL1xyXG4gIE9ic2VydmFibGUub2YgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICB2YXIgbGVuID0gYXJndW1lbnRzLmxlbmd0aCwgYXJncyA9IG5ldyBBcnJheShsZW4pO1xyXG4gICAgZm9yKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7IGF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hbHVlcyk7XHJcbiAgICAgICAgICB9IGNhdGNoIChleCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlcyk7XHJcbiAgICAgICAgfSBlbHNlIGlmIChpc0RvbmUuZmlsdGVyKGZ1bmN0aW9uICh4LCBqKSB7IHJldHVybiBqICE9PSBpOyB9KS5ldmVyeShpZGVudGl0eSkpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9XHJcblxyXG4gICAgICBmdW5jdGlvbiBkb25lIChpKSB7XHJcbiAgICAgICAgaXNEb25lW2ldID0gdHJ1ZTtcclxuICAgICAgICBpZiAoaXNEb25lLmV2ZXJ5KGlkZW50aXR5KSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIHZhciBzdWJzY3JpcHRpb25zID0gbmV3IEFycmF5KG4pO1xyXG4gICAgICBmb3IgKHZhciBpZHggPSAwOyBpZHggPCBuOyBpZHgrKykge1xyXG4gICAgICAgIChmdW5jdGlvbiAoaSkge1xyXG4gICAgICAgICAgdmFyIHNvdXJjZSA9IGFyZ3NbaV0sIHNhZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgaXNQcm9taXNlKHNvdXJjZSkgJiYgKHNvdXJjZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShzb3VyY2UpKTtcclxuICAgICAgICAgIHNhZC5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgdmFsdWVzW2ldID0geDtcclxuICAgICAgICAgICAgbmV4dChpK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dGhlcikge1xyXG4gICAgICAgIGlmICh0eXBlb2YgbWF4Q29uY3VycmVudE9yT3RoZXIgIT09ICdudW1iZXInKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBvYnNlcnZhYmxlTWVyZ2UodGhpcywgbWF4Q29uY3VycmVudE9yT3RoZXIpO1xyXG4gICAgICAgIH1cclxuICAgICAgICB2YXIgc291cmNlcyA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgYWN0aXZlQ291bnQgPSAwLFxyXG4gICAgICAgICAgICAgICAgZ3JvdXAgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgaXNTdG9wcGVkID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICBxID0gW10sXHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmUgPSBmdW5jdGlvbiAoeHMpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgc3Vic2NyaXB0aW9uID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZ3JvdXAuYWRkKHN1YnNjcmlwdGlvbik7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIC8vIENoZWNrIGZvciBwcm9taXNlcyBzdXBwb3J0XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlzUHJvbWlzZSh4cykpIHsgeHMgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UoeHMpOyB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKHhzLnN1YnNjcmliZShvYnNlcnZlci5vbk5leHQuYmluZChvYnNlcnZlciksIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHM7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLnJlbW92ZShzdWJzY3JpcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzID0gcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlKHMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgYWN0aXZlQ291bnQtLTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpc1N0b3BwZWQgJiYgYWN0aXZlQ291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgZ3JvdXAuYWRkKHNvdXJjZXMuc3Vic2NyaWJlKGZ1bmN0aW9uIChpbm5lclNvdXJjZSkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGFjdGl2ZUNvdW50IDwgbWF4Q29uY3VycmVudE9yT3RoZXIpIHtcclxuICAgICAgICAgICAgICAgICAgICBhY3RpdmVDb3VudCsrO1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZShpbm5lclNvdXJjZSk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHEucHVzaChpbm5lclNvdXJjZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlci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GF0IGFueSBwb2ludCBpbiB0aW1lIHByb2R1Y2VzIHRoZSBlbGVtZW50cyBvZiB0aGUgbW9zdCByZWNlbnQgaW5uZXIgb2JzZXJ2YWJsZSBzZXF1ZW5jZSB0aGF0IGhhcyBiZWVuIHJlY2VpdmVkLiAgXHJcbiAgICAgKi9cclxuICAgIG9ic2VydmFibGVQcm90b1snc3dpdGNoJ10gPSBvYnNlcnZhYmxlUHJvdG8uc3dpdGNoTGF0ZXN0ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBzb3VyY2VzID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBoYXNMYXRlc3QgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgIGlubmVyU3Vic2NyaXB0aW9uID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIGlzU3RvcHBlZCA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgbGF0ZXN0ID0gMCxcclxuICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbiA9IHNvdXJjZXMuc3Vic2NyaWJlKGZ1bmN0aW9uIChpbm5lclNvdXJjZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksIGlkID0gKytsYXRlc3Q7XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzTGF0ZXN0ID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBpbm5lclN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKGQpO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICAvLyBDaGVjayBpZiBQcm9taXNlIG9yIE9ic2VydmFibGVcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaXNQcm9taXNlKGlubmVyU291cmNlKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpbm5lclNvdXJjZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShpbm5lclNvdXJjZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICBkLnNldERpc3Bvc2FibGUoaW5uZXJTb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsYXRlc3QgPT09IGlkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAobGF0ZXN0ID09PSBpZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxhdGVzdCA9PT0gaWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhhc0xhdGVzdCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAg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B7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzKTtcclxuICAgICAgICB9IGVsc2UgaWYgKGlzRG9uZS5maWx0ZXIoZnVuY3Rpb24gKHgsIGopIHsgcmV0dXJuIGogIT09IGk7IH0pLmV2ZXJ5KGlkZW50aXR5KSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcbiAgICAgIH07XHJcblxyXG4gICAgICBmdW5jdGlvbiBkb25lKGkpIHtcclxuICAgICAgICBpc0RvbmVbaV0gPSB0cnVlO1xyXG4gICAgICAgIGlmIChpc0RvbmUuZXZlcnkoZnVuY3Rpb24gKHgpIHsgcmV0dXJuIHg7IH0pKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfVxyXG5cclxuICAgICAgdmFyIHN1YnNjcmlwdGlvbnMgPSBuZXcgQXJyYXkobik7XHJcbiAgICAgIGZvciAodmFyIGlkeCA9IDA7IGlkeCA8IG47IGlkeCsrKSB7XHJcbiAgICAgICAgKGZ1bmN0aW9uIChpKSB7XHJcbiAgICAgICAgICB2YXIgc291cmNlID0gc291cmNlc1tpXSwgc2FkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICBpc1Byb21pc2Uoc291cmNlKSAmJiAoc291cmNlID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHNvdXJjZSkpO1xyXG4gICAgICAgICAgc2FkLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICBxdWV1ZXNbaV0ucHVzaCh4KTtcclxuICAgICAgICAgICAgbmV4dChpKTtcclxuICA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ICAgICAgICAgICAgaXNEb25lID0gYXJyYXlJbml0aWFsaXplKG4sIGZ1bmN0aW9uICgpIHsgcmV0dXJuIGZhbHNlOyB9KTtcclxuXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIG5leHQoaSkge1xyXG4gICAgICAgICAgICAgICAgaWYgKHF1ZXVlcy5ldmVyeShmdW5jdGlvbiAoeCkgeyByZXR1cm4geC5sZW5ndGggPiAwOyB9KSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciByZXMgPSBxdWV1ZXMubWFwKGZ1bmN0aW9uICh4KSB7IHJldHVybiB4LnNoaWZ0KCk7IH0pO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXMpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChpc0RvbmUuZmlsdGVyKGZ1bmN0aW9uICh4LCBqKSB7IHJldHVybiBqICE9PSBpOyB9KS5ldmVyeShpZGVudGl0eSkpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIGRvbmUoaSkge1xyXG4gICAgICAgICAgICAgICAgaXNEb25lW2ldID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIGlmIChpc0RvbmUuZXZlcnkoaWRlbnRpdHkpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHZhciBzdWJzY3JpcHRpb25zID0gbmV3IEFycmF5KG4pO1xyXG4gICAgICAgICAgICBmb3IgKHZhciBpZHggPSAwOyBpZHggPCBuOyBpZHgrKykge1xyXG4gICAgICAgICAgICAgICAgKGZ1bmN0aW9uIChpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uc1tpXSA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbnNbaV0uc2V0RGlzcG9zYWJsZShzb3VyY2VzW2ldLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBxdWV1ZXNbaV0ucHVzaCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbmV4dChpKTtcclxuICAgICAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvbmUoaSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfSkoaWR4KTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdmFyIGNvbXBvc2l0ZURpc3Bvc2FibGUgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShzdWJzY3JpcHRpb25zKTtcclxuICAgICAgICAgICAgY29tcG9zaXRlRGlzcG9zYWJsZS5hZGQoZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBxSWR4ID0gMCwgcUxlbiA9IHF1ZXVlcy5sZW5ndGg7IHFJZHggPCBxTGVuOyBxSWR4KyspIHtcclxuICAgICAgICAgICAgICAgICAgICBxdWV1ZXNbcUlkeF0gPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICByZXR1cm4gY29tcG9zaXRlRGlzcG9zYWJsZTtcclxuICAgICAgICB9KTtcclxuICAgIH07X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cih2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGhhc0N1cnJlbnRLZXkpIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBjb21wYXJlckVxdWFscyA9IGNvbXBhcmVyKGN1cnJlbnRLZXksIGtleSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmICghaGFzQ3VycmVudEtleSB8fCAhY29tcGFyZXJFcXVhbHMpIHtcclxuICAgICAgICAgICAgICAgICAgICBoYXNDdXJyZW50S2V5ID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBjdXJyZW50S2V5ID0ga2V5O1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgSW52b2tlcyBhbiBhY3Rpb24gZm9yIGVhY2ggZWxlbWVudCBpbiB0aGUgb2JzZXJ2Y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dCk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb25OZXh0RnVuYyh4KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIW9uRXJyb3IpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFvbkNvbXBsZXRlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIC8qKlxyXG4gICAqICBJbnZva2VzIGEgc3BlY2lmaWVkIGFjdGlvbiBhZnRlciB0aGUgc291cmNlIG9ic2VydmFibGUgc2VxdWVuY2UgdGVybWluYXRlcyBncmFjZWZ1bGx5IG9yIGV4Y2VwdGlvbmFsbHkuXHJcbiAgICogIFxyXG4gICAqIEBleGFtcGxlXHJcbiAgICogIHZhciByZXMgPSBvYnNlcnZhYmxlLmZpbmFsbHlBY3Rpb24oZnVuY3Rpb24gKCkgeyBjb25zb2xlLmxvZygnc2VxdWVuY2UgZW5kZWQnOyB9KTtcclxuICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBmaW5hbGx5QWN0aW9uIEFjdGlvbiB0byBpbnZva2UgYWZ0ZXIgdGhlIHNvdXJjZSBvYnNlcnZhYmxlIHNlcXVlbmNlIHRlcm1pbmF0ZXMuXHJcbiAgICogQHJldHVybnMge09ic2VydmFibGV9IFNvdXJjZSBzZXF1ZW5jZSB3aXRoIHRoZSBhY3Rpb24taW52b2tpbmcgdGVybWluYXRpb24gYmVoYXZpb3IgYXBwbGllZC4gXHJcbiAgICovICBcclxuICBvYnNlcnZhYmxlUHJvdG9bJ2ZpbmFsbHknXSA9IG9ic2VydmFibGVQcm90by5maW5hbGx5QWN0aW9uID0gZnVuY3R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xlUHJvdG8uc2NhbiA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICB2YXIgaGFzU2VlZCA9IGZhbHNlLCBzZWVkLCBhY2N1bXVsYXRvciwgc291cmNlID0gdGhpcztcclxuICAgICAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA9PT0gMikge1xyXG4gICAgICAgICAgICBoYXNTZWVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgc2VlZCA9IGFyZ3VtZW50c1swXTtcclxuICAgICAgICAgICAgYWNjdW11bGF0b3IgPSBhcmd1bWVudHNbMV07ICAgICAgICBcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBhY2N1bXVsYXRvciA9IGFyZ3VtZW50c1swXTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaGFzQWNjdW11bGF0aW9uLCBhY2N1bXVsYXRpb24sIGhhc1ZhbHVlO1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZSAoXHJcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghaGFzVmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgIFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoaGFzQWNjdW11bGF0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY2N1bXVsYXRpb24gPSBhY2N1bXVsYXRvcihhY2N1bXVsYXRpb24sIHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgYWNjdW11bGF0aW9uID0gaGFzU2VlZCA/IGFjY3VtdWxhdG9yKHNlZWQsIHgpIDogeDtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhhc0FjY3VtdWxhdGlvbiA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICBcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWNjdW11bGF0aW9uKTtcclxuICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghaGFzVmFsdWUgJiYgaGFzU2VlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoc2VlZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIEJ5cGFzc2VzIGEgc3BlY2lmaWVkIG51bWJlciBvZiBlbGVtZW50cyBhdCB0aGUgZW5kIG9mIGFuIG9ic2VydmFibGUgc2VxdWVuY2UuXHJcbiAgICAgKiBAZGVzY3JpcHRpb25cclxuICAgICAqICBUaGlzIG9wZXJhdG9yIGFjY3VtdWxhdGVzIGEgcX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O1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAoc2tpcCA8PSAwKSB7XHJcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBtID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICByZWZDb3VudERpc3Bvc2FibGUgPSBuZXcgUmVmQ291bnREaXNwb3NhYmxlKG0pLFxyXG4gICAgICAgICAgICAgICAgbiA9IDAsXHJcbiAgICAgICAgICAgICAgICBxID0gW10sXHJcbiAgICAgICAgICAgICAgICBjcmVhdGVXaW5kb3cgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIHMgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHEucHVzaChzKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgY3JlYXRlV2luZG93KCk7XHJcbiAgICAgICAgICAgIG0uc2V0RGlzcG9zYWJsZShzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgcztcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBxLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcVtpXS5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB2YXIgYyA9IG4gLSBjb3VudCArIDE7XHJcbiAgICAgICAgICAgICAgICBpZiAoYyA+PSAwICYmIGMgJSBza2lwID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcyA9IHEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBuKys7XHJcbiAgICAgICAgICAgICAgICBpZiAobiAlIHNraXAgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBjcmVhdGVXaW5kb3coKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHEuc2hpZnQoKS5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBxLnNoaWZ0KCkub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgcmV0dXJuIHJlZkNvdW50RGlzcG9zYWJsZTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgZnVuY3Rpb24gY29uY2F0TWFwKHNlbGVjdG9yKSB7XHJcbiAgICAgIHJldHVybiB0aGlzLm1hcChmdW5jdGlvbiAoeCwgaSkge1xyXG4gICAgICAgIHZhciByZXN1bHQgPSBzZWxlY3Rvcih4LCBpKTtcclxuICAgICAgICByZXR1cm4gaX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TZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgICAgICBzZXJpYWxpemVkS2V5ID0ga2V5U2VyaWFsaXplcihrZXkpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGZvciAob3RoZXJLZXkgaW4gaGFzaFNldCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChzZXJpYWxpemVkS2V5ID09PSBvdGhlcktleSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBoYXNNYXRjaCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmICghaGFzTWF0Y2gpIHtcclxuICAgICAgICAgICAgICAgICAgICBoYXNoU2V0W3NlcmlhbGl6ZWRLZXldID0gbnVsbDtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgR3JvdXBzIHRoZSBlbGVtZW50cyBvZiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIGFjY29yZGluZyB0byBhIHNwZWNpZmllZCBrZXkgc2VsZWN0b3IgZnVuY3Rpb24gYW5kIGNvbXBhcmVyIGFuZCBzZWxlY3RzIHRoZSByZXN1bHRpbmcgZWxlbWVud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ZGQoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uLCBkdXJhdGlvbkdyb3VwLCBlbGVtZW50LCBmaXJlTmV3TWFwRW50cnksIGdyb3VwLCBrZXksIHNlcmlhbGl6ZWRLZXksIG1kLCB3cml0ZXIsIHc7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGtleSA9IGtleVNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHNlcmlhbGl6ZWRLZXkgPSBrZXlTZXJpYWxpemVyKGtleSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh3IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBtYXBbd10ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBmaXJlTmV3TWFwRW50cnkgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgd3JpdGVyID0gbWFwW3NlcmlhbGl6ZWRLZXldO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghd3JpdGVyKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHdyaXRlciA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG1hcFtzZXJpYWxpemVkS2V5XSA9IHdyaXRlcjtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZmlyZU5ld01hcEVudHJ5ID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh3IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBtYXBbd10ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoZmlyZU5ld01hcEVudHJ5KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZ3JvdXAgPSBuZXcgR3JvdXBlZE9ic2VydmFibGUoa2V5LCB3cml0ZXIsIHJlZkNvdW50RGlzcG9zYWJsZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgZHVyYXRpb25Hcm91cCA9IG5ldyBHcm91cGVkT2JzZXJ2YWJsZShrZXksIHdyaXRlcik7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZHVyYXRpb24gPSBkdXJhdGlvblNlbGVjdG9yKGR1cmF0aW9uR3JvdXApO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yICh3IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZ3JvdXApO1xyXG4gICAgICAgICAgICAgICAgICAgIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLmFkZChtZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzZXJpYWxpemVkS2V5IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVsZXRlIG1hcFtzZXJpYWxpemVkS2V5XTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdyaXRlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwRGlzcG9zYWJsZS5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShub29wLCBmdW5jdGlvbiAoZXhuKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAodyBpbiBtYXApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1hcFt3XS5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleG4pO1xyXG4gICAgICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZXhwaXJlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBlbGVtZW50ID0gZWxlbWVudFNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodyBpbiBtYXApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgd3JpdGVyLm9uTmV4dChlbGVtZW50KTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGV4KSB7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciB3IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG1hcFt3XS5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciB3IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG1hcFt3XS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICByZXR1cm4gcmVmQ291bnREaXNwb3NhYmxlO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBQcm9qZWN0cyBlYWNoIGVsZW1lbnQgb2YgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSBpbnRvIGEgbmV3IGZvcm0gYnkgaW5jb3Jwb3JhdGluZyB0aGUgZWxlbWVudCdzIGluZGV4LlxyXG4gICAgICogQHBhcmFtIHtGdW5jdGlvbn0gc2VsZWN0b3IgQSB0cmFuc2Zvcm0gZnVuY3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clxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAocnVubmluZykge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBSZXR1cm5zIGEgc3BlY2lmaWVkIG51bWJlciBvZiBjb250aWd1b3VzIGVsZW1lbnRzIGZyb20gdGhlIHN0YXJ0IG9mIGFuIG9ic2VydmFibGUgc2VxdWVuY2UsIHVzaW5nIHRoZSBzcGVjaWZpZWQgc2NoZWR1bGVyIGZvciB0aGUgZWRnZSBjYXNlIG9mIHRha2UoMCkuXHJcbiAgICAgKiAgXHJcbiAgICAgKiAgdmFyIHJlcyA9IHNvdXJjZS50YWtlKDUpO1xyXG4gICAgICogIHZhciByZXMgPSBzb3VyY2UudGFrZSgwLCBSeC5TY2hlZHVsZXIudGltZW91dCk7XHJcbiAgICAgKiBAcGFyYW0ge051bWJlcn0gY291bnQgVGhlIG51bWJlciBvZiBlbGVtZW50cyB0byByZXR1cm4uXHJcbiAgICAgKiBAcGFyYW0ge1NjaGVkdWxlcn0gW3NjaGVkdWxlcl0gU2NoZWR1bGVyIHVzZWQgdG8gcHJvZHVjZSBhbiBPbkNvbXBsZXRlZCBtZXNzYWdlIGluIGNhc2UgPHBhcmFtcmVmIG5hbWU9XCJjb3VudCBjb3VudDwvcGFyYW1yZWY+IGlzIHNldCB0byAwLlxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2UgdGhhdCBjb250YWlucyB0aGUgc3BlY2lmaWVkIG51bWJlciBvZiBlbGVtZW50cyBmcm9tIHRoZSBzdGFydCBvZiB0aGUgaW5wdXQgc2VxdWVuY2UuICBcclxuICAgICAqL1xyXG4gICAgb2JzZXJ2YWJsZVByb3RvLnRha2UgPSBmdW5jdGlvbiAoY291bnQsIHNjaGVkdWxlcikge1xyXG4gICAgICAgIGlmIChjb3VudCA8IDApIHtcclxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChjb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICByZXR1cm4gb2JzZXJ2YWJsZUVtcHR5KHNjaGVkdWxlcik7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBvYnNlcnZhYmxlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciByZW1haW5pbmcgPSBjb3VudDtcclxuICAgICAgICAgICAgcmV0dXJuIG9ic2VydmFibGUuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAocmVtYWluaW5nID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJlbWFpbmluZy0tO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAocmVtYWluaW5nID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBvYnNlcnZlci5vbkNvbXBsZXRlZC5iaW5kKG9ic2VydmVyKSk7XHJcbiAgICAgICAg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IHRlc3Qgbm8gbG9uZ2VyIHBhc3Nlcy4gIFxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8udGFrZVdoaWxlID0gZnVuY3Rpb24gKHByZWRpY2F0ZSwgdGhpc0FyZykge1xyXG4gICAgICAgIHZhciBvYnNlcnZhYmxlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBpID0gMCwgcnVubmluZyA9IHRydWU7XHJcbiAgICAgICAgICAgIHJldHVybiBvYnNlcnZhYmxlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKHJ1bm5pbmcpIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBydW5uaW5nID0gcHJlZGljYXRlLmNhbGwodGhpc0FyZywgeCwgaSsrLCBvYnNlcnZhYmxlKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHJ1bm5pbmcpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBvYnNlcnZlci5vbkNvbXBsZXRlZ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ZVByb3RvLmZpbHRlciA9IGZ1bmN0aW9uIChwcmVkaWNhdGUsIHRoaXNBcmcpIHtcclxuICAgICAgICB2YXIgcGFyZW50ID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBjb3VudCA9IDA7XHJcbiAgICAgICAgICAgIHJldHVybiBwYXJlbnQuc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHNob3VsZFJ1bjtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc2hvdWxkUnVuID0gcHJlZGljYXRlLmNhbGwodGhpc0FyZywgdmFsdWUsIGNvdW50KyssIHBhcmVudCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKHNob3VsZFJ1bikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIG9ic2VydmFibGVQcm90by5maW5hbFZhbHVlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyK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ICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBjb21wYXJpc29uID0gMDtcclxuICAgICAgICAgICAgICAgIGlmICghaGFzVmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgbGFzdEtleSA9IGtleTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgY29tcGFyaXNvbiA9IGNvbXBhcmVyKGtleSwgbGFzdEtleSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXgxKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgxKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChjb21wYXJpc29uID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGxhc3RLZXkgPSBrZXk7XHJcbiAgICAgICAgICAgICAgICAgICAgbGlzdCA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGNvbXBhcmlzb24gPj0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGxpc3QucHVzaCh4KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGxpc3QpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbG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bnRhaW5pbmcgYSBzaW5nbGUgZWxlbWVudCB3aXRoIHRoZSBhdmVyYWdlIG9mIHRoZSBzZXF1ZW5jZSBvZiB2YWx1ZXMuXHJcbiAgICAgKi9cclxuICAgIG9ic2VydmFibGVQcm90by5hdmVyYWdlID0gZnVuY3Rpb24gKGtleVNlbGVjdG9yLCB0aGlzQXJnKSB7XHJcbiAgICAgICAgcmV0dXJuIGtleVNlbGVjdG9yID9cclxuICAgICAgICAgICAgdGhpcy5zZWxlY3Qoa2V5U2VsZWN0b3IsIHRoaXNBcmcpLmF2ZXJhZ2UoKSA6XHJcbiAgICAgICAgICAgIHRoaXMuc2Nhbih7XHJcbiAgICAgICAgICAgICAgICBzdW06IDAsXHJcbiAgICAgICAgICAgICAgICBjb3VudDogMFxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAocHJldiwgY3VyKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4ge1xyXG4gICAgICAgICAgICAgICAgICAgIHN1bTogcHJldi5zdW0gKyBjdXIsXHJcbiAgICAgICAgICAgICAgICAgICAgY291bnQ6IHByZXYuY291bnQgKyAxXHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICB9KS5maW5hbFZhbHVlKCkuc2VsZWN0KGZ1bmN0aW9uIChzKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAocy5jb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignVGhlIGlucHV0IHNlcXVlbmNlIHdhcyBlbXB0eScpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHMuc3VtIC8gcy5jb3VudDtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICBmdW5jdGlvbiBzZXF1ZW5jZUVxdWFsQXJyYXkoZmlyc3QsIHNlY29uZCwgY29tcGFyZXIpIHtcclxuICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vd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hYmxlUHJvdG8uc2VxdWVuY2VFcXVhbCA9IGZ1bmN0aW9uIChzZWNvbmQsIGNvbXBhcmVyKSB7XHJcbiAgICB2YXIgZmlyc3QgPSB0aGlzO1xyXG4gICAgY29tcGFyZXIgfHwgKGNvbXBhcmVyID0gZGVmYXVsdENvbXBhcmVyKTtcclxuICAgIGlmIChBcnJheS5pc0FycmF5KHNlY29uZCkpIHtcclxuICAgICAgcmV0dXJuIHNlcXVlbmNlRXF1YWxBcnJheShmaXJzdCwgc2Vjb25kLCBjb21wYXJlcik7XHJcbiAgICB9XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBkb25lbCA9IGZhbHNlLCBkb25lciA9IGZhbHNlLCBxbCA9IFtdLCBxciA9IFtdO1xyXG4gICAgICB2YXIgc3Vic2NyaXB0aW9uMSA9IGZpcnN0LnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgIHZhciBlcXVhbCwgdjtcclxuICAgICAgICBpZiAocXIubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICB2ID0gcXIuc2hpZnQoKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICBlcXVhbCA9IGNvbXBhcmVyKHYsIHgpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgaWYgKCFlcXVhbCkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0gZWxzZSBpZiAoZG9uZXIpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICBxbC5wdXNoKHgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGRvbmVsID0gdHJ1ZTtcclxuICAgICAgICBpZiAocWwubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICBpZiAocXIubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfSBlbHNlIGlmIChkb25lcikge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodHJ1ZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICB9KTtcclxuXHJcbiAgICAgIGlzUHJvbWlzZShzZWNvbmQpICYmIChzZWNvbmQgPSBvYnNlcnZhYmxlRnJvbVByb21pc2Uoc2Vjb25kKSk7XHJcbiAgICAgIHZhciBzdWJzY3JpcHRpb24yID0gc2Vjb25kLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgIHZhciBlcXVhbCwgdjtcclxuICAgICAgICBpZiAocWwubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgdiA9IHFsLnNoaWZ0KCk7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBlcXVhbCA9IGNvbXBhcmVyKHYsIHgpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgaWYgKCFlcXVhbCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0gZWxzZSBpZiAoZG9uZWwpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICBxci5wdXNoKHgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGRvbmVyID0gdHJ1ZTtcclxuICAgICAgICBpZiAocXIubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICBpZiAocWwubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfSBlbHNlIGlmIChkb25lbCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodHJ1ZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICB9KTtcclxuICAgICAgcmV0dXJuIG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKHN1YnNjcmlwdGlvbjEsIHN1YnNjcmlwdGlvbjIpO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBlbGVtZW50QXRPckRlZmF1bHQoc291cmNlLCBpbmRleCwgaGFzRGVmYXVsdCwgZGVmYXVsdFZhbHVlKSB7XHJcbiAgICAgICAgaWYgKGluZGV4IDwgMCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYXJndW1lbnRPdXRPZlJhbmdlKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaSA9IGluZGV4O1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGkgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGktLTtcclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNEZWZhdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihuZXcgRXJyb3IoYXJndW1lbnRPdXRPZlJhbmdlKSk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChkZWZhdWx0VmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIC8qKlxyXG4gICAgICogUmV0dXJucyB0aGUgZWxlbWVudCBhdCBhIHNwZWNpZmll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clxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFsdWUgPSB4O1xyXG4gICAgICAgICAgICAgICAgICAgIHNlZW5WYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghc2VlblZhbHVlICYmICFoYXNEZWZhdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihuZXcgRXJyb3Ioc2VxdWVuY2VDb250YWluc05vRWxlbWVudHMpKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIFJldHVybnMgdGhlIG9ubHkgZWxlbWVudCBvZiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIHRoYXQgc2F0aXNmaWVzIHRoZSBjb25kaXRpb24gaW4gdGhlIG9wdGlvbmFsIHByZWRpY2F0ZSwgYW5kIHJlcG9ydHMgYW4gZXhjZXB0aW9uIGlmIHRoZXJlIGlzIG5vdCBleGFjdGx5IG9uZSBlbGVtZW50IGluIHRoZSBvYnNlcnZhYmxlIHNlcXVlbmNlLlxyXG4gICAgICogQGV4YW1wbGVcclxuICAgICAqIHZhciByZXMgPSByZXMgPSBzb3VyY2Uuc2luZ2xlKCk7XHJcbiAgICAgKiB2YXIgcmVzID0gcmVzID0gc291cmNlLnNpbmdsZShmdW5jdGlvbiAoeCkgeyByZXR1cm4geCA9PT0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VlID0gZGVmYXVsdFZhbHVlLCBzZWVuVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhbHVlID0geDtcclxuICAgICAgICAgICAgICAgIHNlZW5WYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghc2VlblZhbHVlICYmICFoYXNEZWZhdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihuZXcgRXJyb3Ioc2VxdWVuY2VDb250YWluc05vRWxlbWVudHMpKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIFJldHVybnMgdGhlIGxhc3QgZWxlbWVudCBvZiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIHRoYXQgc2F0aXNmaWVzIHRoZSBjb25kaXRpb24gaW4gdGhlIHByZWRpY2F0ZSBpZiBzcGVjaWZpZWQsIGVsc2UgdGhlIGxhc3QgZWxlbWVudC5cclxuICAgICAqIEBleGFtcGxlXHJcbiAgICAgKiB2YXIgcmVzID0gc291cmNlLmxhc3QoKTtcclxuICAgICAqIHZhciByZXMgPSBzb3VyY2UubGFzdChmdW5jdGlvbiAoeCkgeyByZXR1cm4geCA+IDM7IH0pO1xyXG4gICAgICogQHBhcmFtIHtGdW5jdGlvbn0gW3ByZWRpY2F0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UsIHRoaXNBcmcpLmxhc3RPckRlZmF1bHQobnVsbCwgZGVmYXVsdFZhbHVlKSA6XHJcbiAgICAgICAgICAgIGxhc3RPckRlZmF1bHRBc3luYyh0aGlzLCB0cnVlLCBkZWZhdWx0VmFsdWUpO1xyXG4gICAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBmaW5kVmFsdWUgKHNvdXJjZSwgcHJlZGljYXRlLCB0aGlzQXJnLCB5aWVsZEluZGV4KSB7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaSA9IDA7XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgc2hvdWxkUnVuO1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBzaG91bGRSdW4gPSBwcmVkaWNhdGUuY2FsbCh0aGlzQXJnLCB4LCBpLCBzb3VyY2UpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoc2hvdWxkUnVuKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHlpZWxkSW5kZXggPyBpIDogeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaSsrO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLm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gICAgIHNjaGVkdWxlciB8fCAoc2NoZWR1bGVyID0gdGltZW91dFNjaGVkdWxlcik7XHJcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdmFyIGFyZ3MgPSBhcmd1bWVudHMsIFxyXG4gICAgICAgICAgICAgICAgc3ViamVjdCA9IG5ldyBBc3luY1N1YmplY3QoKTtcclxuXHJcbiAgICAgICAgICAgIHNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSBmdW5jLmFwcGx5KGNvbnRleHQsIGFyZ3MpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YmplY3Qub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBzdWJqZWN0Lm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgc3ViamVjdC5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgcmV0dXJuIHN1YmplY3QuYXNPYnNlcnZhYmxlKCk7XHJcbiAgICAgICAgfTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBDb252ZXJ0cyBhIGNhbGxiYWNrIGZ1bmN0aW9uIHRvIGFuIG9ic2VydmFibGUgc2VxdWVuY2UuIFxyXG4gICAgICogXHJcbiAgICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBmdW5jdGlvbiBGdW5jdGlvbiB3aXRoIGEgY2FsbGJhY2sgYXMgdGhlIGxhc3QgcGFyYW1ldGVyIHRvIGNvbnZlcnQgdG8gYW4gT2JzZXJ2YWJsZSBzZXF1Z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bGljZS5jYWxsKGFyZ3VtZW50cywgMCk7XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiBoYW5kbGVyKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHJlc3VsdHMgPSBlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNlbGVjdG9yKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdHMgPSBzZWxlY3Rvcihhcmd1bWVudHMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZXN1bHRzLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdHMgPSByZXN1bHRzWzBdO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0cyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9u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Y3Rpb259IEFuIGFzeW5jIGZ1bmN0aW9uIHdoaWNoIHdoZW4gYXBwbGllZCwgcmV0dXJucyBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIHdpdGggdGhlIGNhbGxiYWNrIGFyZ3VtZW50cyBhcyBhbiBhcnJheS5cclxuICAgICAqL1xyXG4gICAgT2JzZXJ2YWJsZS5mcm9tTm9kZUNhbGxiYWNrID0gZnVuY3Rpb24gKGZ1bmMsIHNjaGVkdWxlciwgY29udGV4dCwgc2VsZWN0b3IpIHtcclxuICAgICAgICBzY2hlZHVsZXIgfHwgKHNjaGVkdWxlciA9IGltbWVkaWF0ZVNjaGVkdWxlcik7XHJcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdmFyIGFyZ3MgPSBzbGljZS5jYWxsKGFyZ3VtZW50cywgMCk7XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiBoYW5kbGVyKGVycikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciByZXN1bHRzID0gc2xpY2UuY2FsbChhcmd1bWVudHMsIDEpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNlbGVjdG9yKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdHMgPSBzZWxlY3RvcihyZXN1bHRzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZXN1bHRzLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdHMgPSByZXN1bHRzWzBdO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0cyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICBhcmdzLnB1c2goaGFuZGxlcik7XHJcbiAgICAgICAgICAgICAgICAgICAgZnVuYy5hcHBseShjb250ZXh0LCBhcmdzKTtcclxuICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9O1xyXG4gICAgfTtcclxuXHJcbiAgZnVuY3Rpb24gY3JlYXRlTGlzdGVuZXIgKGVsZW1lbnQsIG5hbWUsIGhhbmRsZXIpIHtcclxuICAgIC8vIE5vZGUuanMgc3BlY2lmaWNcclxuICAgIGlmIChlbGVtZW50LmFkZExpc3RlbmVyKSB7XHJcbiAgIC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gICAgICAgfVxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlcyk7XHJcbiAgICAgICAgfSBlbHNlIGlmIChpc0RvbmUpIHtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9XHJcblxyXG4gICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoXHJcbiAgICAgICAgc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgIG5leHQoeCwgMCk7XHJcbiAgICAgICAgICB9LFxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgaXNEb25lID0gdHJ1ZTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH0pLFxyXG4gICAgICAgIHN1YmplY3Quc3Vic2NyaWJlKFxyXG4gICAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgbmV4dCh4LCAxKTtcclxuICAgICAgICAgIH0sXHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpKVxyXG4gICAgICAgICk7XHJcbiAgICB9KTtcclxuICB9XHJcblxyXG4gIHZhciBQYXVzYWJsZUJ1ZmZlcmVkT2JzZXJ2YWJsZSA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcblxyXG4gICAgaW5oZXJpdHMoUGF1c2FibGVCdWZmZXJlZE9ic2VydmFibGUsIF9zdXBlcik7XHJcblxyXG4gICAgZnVuY3Rpb24gc3Vic2NyaWJlKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBxID0gW10sIHByZXZpb3VzID0gdHJ1ZTtcclxuICAgICAgXHJcbiAgICAgIHZhciBzdWJzY3JpcHRpb24gPSAgXHJcbiAgICAgICAgY29tYmluZUxhdGVzdFNvdXJjZShcclxuICAgICAgICAgIHRoaXMuc291cmNlLFxyXG4gICAgICAgICAgdGhpcy5zdWJqZWN0LmRpc3RpbmN0VW50aWxDaGFuZ2VkKCksIFxyXG4gICAgICAgICAgZnVuY3Rpb24gKGRhdGEsIHNob3VsZEZpcmUpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHsgZGF0YTogZGF0YSwgc2hvdWxkRmlyZTogc2hvdWxkRmlyZSB9OyAgICAgIFxyXG4gICAgICAgICAgfSlcclxuICAgICAgICAgIC5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIChyZXN1bHRzKSB7XHJcbiAgICAgICAgICAgICAgaWYgKHJlc3VsdHMuc2hvdWxkRmlyZSAmJiBwcmV2aW91cykge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdHMuZGF0YSk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIGlmIChyZXN1bHRzLnNob3VsZEZpcmUgJiYgIXByZXZpb3VzKSB7XHJcbiAgICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChxLnNoaWZ0KCkpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgcHJldmlvdXMgPSB0cnVlO1xyXG4gICAgICAgICAgICAgIH0gZWxzZSBpZiAoIXJlc3VsdHMuc2hvdWxkRmlyZSAmJiAhcHJldmlvdXMpIHtcclxuICAgICAgICAgICAgICAgIHEucHVzaChyZXN1bHRzLmRhdGEpO1xyXG4gICAgICAgICAgICAgIH0gZWxzZSBpZiAoIXJlc3VsdHMuc2hvdWxkRmlyZSAmJiBwcmV2aW91cykge1xyXG4gICAgICAgICAgICAgICAgcHJldmlvdXMgPSBmYWxzZTtcclxuICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICB9LCBcclxuICAgICAgICAgICAgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgICAgIC8vIEVtcHR5IGJ1ZmZlciBiZWZvcmUgc2VuZGluZyBlcnJvclxyXG4gICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChxLnNoaWZ0KCkpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAvLyBFbXB0eSBidWZmZXIgYmVmb3JlIHNlbmRpbmcgY29tcGxldGlvblxyXG4gICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChxLnNoaWZ0KCkpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpOyAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICk7XHJcblxyXG4gICAgICB0aGlzLnN1YmplY3Qub25OZXh0KGZhbHNlKTtcclxuXHJcbiAgICAgIHJldHVybiBzdWJzY3JpcHRpb247ICAgICAgXHJcbiAgICB9XHJcblxyXG4gICAgZnVuY3Rpb24gUGF1c2FibGVCdWZmZXJlZE9ic2VydmFibGUoc291cmNlLCBzdWJqZWN0KSB7XHJcbiAgICAgIHRoaXMuc291cmNlID0gc291cmNlO1xyXG4gICAgICB0aGlzLnN1YmplY3QgPSBzdWJqZWN0IHx8IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgIHRoaXMuaXNQYXVzZWQgPSB0cnVlO1xyXG4gICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmU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hc0NvbXBsZXRlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICB0aGlzLmNvbnRyb2xsZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgYWRkUHJvcGVydGllcyhDb250cm9sbGVkU3ViamVjdC5wcm90b3R5cGUsIE9ic2VydmVyLCB7XHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmhhc0NvbXBsZXRlZCA9IHRydWU7XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmVuYWJsZVF1ZXVlIHx8IHRoaXMucXVldWUubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChlcnJvcikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5oYXNGYWlsZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5lcnJvciA9IGVycm9yO1xyXG5cclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5lbmFibGVRdWV1ZSB8fCB0aGlzLnF1ZXVlLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbkVycm9yKGVycm9yKTtcclxuICAgICAgICAgICAgICAgIH0gICBcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHZhciBoYXNSZXF1ZXN0ZWQgPSBmYWxzZTtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5yZXF1ZXN0ZWRDb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLmVuYWJsZVF1ZXVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucXVldWUucHVzaCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5yZXF1ZXN0ZWRDb3VudCAhPT0gLTEpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMucmVxdWVzdGVkQ291bnQtLSA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlQ3VycmVudFJlcXVlc3QoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBoYXNSZXF1ZXN0ZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIGlmIChoYXNSZXF1ZXN0ZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgX3Byb2Nlc3NSZXF1ZXN0OiBmdW5jdGlvbiAobnVtYmVyT2ZJdGVtcykge1xyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuZW5hYmxlUXVldWUpIHtcclxuICAgICAgICAgICAgICAgICAgICAvL2NvbnNvbGUubG9nKCdxdWV1ZSBsZW5ndGgnLCB0aGlzLnF1ZXVlLmxlbmd0aCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHdoaWxlICh0aGlzLnF1ZXVlLmxlbmd0aCA+PSBudW1iZXJPZkl0ZW1zICYmIG51bWJlck9mSXRlbXMgPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2coJ251bWJlciBvZiBpdGVtcycsIG51bWJlck9mSXRlbXMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25OZXh0KHRoaXMucXVldWUuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG51bWJlck9mSXRlbXMtLTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnF1ZXVlLmxlbmd0aCAhPT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4geyBudW1iZXJPZkl0ZW1zOiBudW1iZXJPZkl0ZW1zLCByZXR1cm5WYWx1ZTogdHJ1ZSB9O1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB7IG51bWJlck9mSXRlbXM6IG51bWJlck9mSXRlbXMsIHJldHVyblZhbHVlOiBmYWxzZSB9O1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5oYXNGYWlsZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25FcnJvcih0aGlzLmVycm9yKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmNvbnRyb2xsZWREaXNwb3NhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmNvbnRyb2xsZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLmhhc0NvbXBsZXRlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7ICAgICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIHJldHVybiB7IG51bWJlck9mSXRlbXM6IG51bWJlck9mSXRlbXMsIHJldHVyblZhbHVlOiBmYWxzZSB9O1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICByZXF1ZXN0OiBmdW5jdGlvbiAobnVtYmVyKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2VDdXJyZW50UmVxdWVzdCgpO1xyXG4gICAgICAgICAgICAgICAgdmFyIHNlbGYgPSB0aGlzLFxyXG4gICAgICAgICAgICAgICAgICAgIHIgPSB0aGlzLl9wcm9jZXNzUmVxdWVzdChudW1iZXIpO1xyXG5cclxuICAgICAgICAgICAgICAgIG51bWJlciA9IHIubnVtYmVyT2ZJdGVtcztcclxuICAgICAgICAgICAgICAgIGlmICghci5yZXR1cm5WYWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkQ291bnQgPSBudW1iZXI7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYucmVxdWVzdGVkQ291bnQgPSAwO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlXHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIGRpc3Bvc2VDdXJyZW50UmVxdWVzdDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgfSxcclxuXHJcbiAgICAgICAgICAgIGRpc3Bvc2U6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmVycm9yID0gbnVsbDtcclxuICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIHJldHVybiBDb250cm9sbGVkU3ViamVjdDtcclxuICAgIH0oT2JzZXJ2YWJsZSkpO1xyXG4gICAgLyoqXHJcbiAgICAgKiBNdWx0aWNhc3RzIHRoZSBzb3VyY2Ugc2VxdWVuY2Ugbm90aWZpY2F0aW9ucyB0aHJvdWdoIGFuIGluc3RhbnRpYXRlZCBzdWJqZWN0IGludG8gYWxsIHVzZXMgb2YgdGhlIHNlcXVlbmNlIHdpdGhpbiBhIHNl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AgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZXhjZXB0aW9uLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSBlcnJvciBUaGUgZXhjZXB0aW9uIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXJyb3IpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBlcnJvcjtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uRXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgYXJyaXZhbCBvZiB0aGUgc3BlY2lmaWVkIGVsZW1lbnQgaW4gdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSB2YWx1ZSBUaGUgdmFsdWUgdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMudmFsdWUgPSB2YWx1ZTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiA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W5kb3dTaXplLCBzY2hlZHVsZXIpIHtcclxuICAgICAgICAgICAgdGhpcy5idWZmZXJTaXplID0gYnVmZmVyU2l6ZSA9PSBudWxsID8gTnVtYmVyLk1BWF9WQUxVRSA6IGJ1ZmZlclNpemU7XHJcbiAgICAgICAgICAgIHRoaXMud2luZG93U2l6ZSA9IHdpbmRvd1NpemUgPT0gbnVsbCA/IE51bWJlci5NQVhfVkFMVUUgOiB3aW5kb3dTaXplO1xyXG4gICAgICAgICAgICB0aGlzLnNjaGVkdWxlciA9IHNjaGVkdWxlciB8fCBjdXJyZW50VGhyZWFkU2NoZWR1bGVyO1xyXG4gICAgICAgICAgICB0aGlzLnEgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuaGFzRXJyb3IgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5lcnJvciA9IG51bGw7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKFJlcGxheVN1YmplY3QucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKiBAcmV0dXJucyB7Qm9vbGVhbn0gSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICBcclxuICAgICAgICAgICAgaGFzT2JzZXJ2ZXJzOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5vYnNlcnZlcnMubGVuZ3RoID4gMDtcclxuICAgICAgICAgICAgfSwgICAgICAgICAgICBcclxuICAgICAgICAgICAgLyogQHByaXZhdGUgICovXHJcbiAgICAgICAgICAgIF90cmltOiBmdW5jdGlvbiAobm93KSB7XHJcbiAgICAgICAgICAgICAgICB3aGlsZSAodGhpcy5xLmxlbmd0aCA+IHRoaXMuYnVmZmVyU2l6ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHRoaXMucS5sZW5ndGggPiAwICYmIChub3cgLSB0aGlzLnFbMF0uaW50ZXJ2YWwpID4gdGhpcy53aW5kb3dTaXplKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5xLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGFycml2YWwgb2YgdGhlIHNwZWNpZmllZCBlbGVtZW50IGluIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gdmFsdWUgVGhlIHZhbHVlIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHZhciBvYnNlcnZlcjtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbm93ID0gdGhpcy5zY2hlZHVsZXIubm93KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5xLnB1c2goeyBpbnRlcnZhbDogbm93LCB2YWx1ZTogdmFsdWUgfSk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fdHJpbShub3cpO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB2YXIgbyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyID0gb1tpXTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIuZW5zdXJlQWN0aXZlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBleGNlcHRpb24uXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IGVycm9yIFRoZSBleGNlcHRpb24gdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXJyb3IpIHtcclxuICAgICAgICAgICAgICAgIHZhciBvYnNlcnZlcjtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lcnJvciA9IGVycm9yO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaGFzRXJyb3IgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBub3cgPSB0aGlzLnNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLl90cmltKG5vdyk7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG8gPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gby5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlciA9IG9baV07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5lbnN1cmVBY3RpdmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG9ic2VydmVyO1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbm93ID0gdGhpcy5zY2hlZHVsZXIubm93KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fdHJpbShub3cpO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG8ubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIgPSBvW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5lbnN1cmVBY3RpdmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIFVuc3Vic2NyaWJlIGFsbCBvYnNlcnZlcnMgYW5kIHJlbGVhc2UgcmVzb3VyY2VzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgZGlzcG9zZTogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gbnVsbDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG5cclxuICAgICAgICByZXR1cm4gUmVwbGF5U3ViamVjdDtcclxuICAgIH0oT2Jz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ICAgICAgICBzdGF0ZS5oYXNTdWJzY3JpcHRpb24gPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gc3RhdGUuc3Vic2NyaXB0aW9uO1xyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgZnVuY3Rpb24gc3Vic2NyaWJlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gc3RhdGUuc3ViamVjdC5zdWJzY3JpYmUob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgQ29ubmVjdGFibGVPYnNlcnZhYmxlXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgQ29ubmVjdGFibGVPYnNlcnZhYmxlLnByb3RvdHlwZS5jb25uZWN0ID0gZnVuY3Rpb24gKCkgeyByZXR1cm4gdGhpcy5jb25uZWN0KCk7IH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIENvbm5lY3RhYmxlT2JzZXJ2YWJsZVxyXG4gICAgICAgICAqLyAgICAgICAgXHJcbiAgICAgICAgQ29ubmVjdGFibGVPYnNlcnZhYmxlLnByb3RvdHlwZS5yZWZDb3VudCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdmFyIGNvbm5lY3RhYmxlU3Vic2NyaXB0aW9uID0gbnVsbCwgY291bnQgPSAwLCBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgc2hvdWxkQ29ubmVjdCwgc3Vic2NyaXB0aW9uO1xyXG4gICAgICAgICAgICAgICAgY291bnQrKztcclxuICAgICAgICAgICAgICAgIHNob3VsZENvbm5lY3QgPSBjb3VudCA9PT0gMTtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbiA9IHNvdXJjZS5zdWJzY3JpYmUob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgaWYgKHNob3VsZENvbm5lY3QpIHtcclxuICAgICAgICAgICAgICAgICAgICBjb25uZWN0YWJsZVN1YnNjcmlwdGlvbiA9IHNvdXJjZS5jb25uZWN0KCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICBjb3VudC0tO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChjb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBjb25uZWN0YWJsZVN1YnNjcmlwdGlvbi5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIHJldHVybiBDb25uZWN0YWJsZU9ic2VydmFibGU7XHJcbiAgICB9KE9ic2VydmFibGUpKTtcclxuXHJcbiAgICAvLyBSZWFsIERpY3Rpb25hcnlcclxuICAgIHZhciBwcmltZXMgPSBbMSwgMywgNywgMTMsIDMxLCA2MSwgMTI3LCAyNTEsIDUwOSwgMTAyMSwgMjAzOSwgNDA5MywgODE5MSwgMTYzODEsIDMyNzQ5LCA2NTUyMSwgMTMxMDcxLCAyNjIxMzksIDUy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iAgICAgICAga2V5ID0ga2V5IF4gKGtleSA+Pj4gNCk7XHJcbiAgICAgICAga2V5ID0ga2V5ICogYzI7XHJcbiAgICAgICAga2V5ID0ga2V5IF4gKGtleSA+Pj4gMTUpO1xyXG4gICAgICAgIHJldHVybiBrZXk7XHJcbiAgICB9XHJcblxyXG4gICAgdmFyIGdldEhhc2hDb2RlID0gKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICB2YXIgdW5pcXVlSWRDb3VudGVyID0gMDtcclxuXHJcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIChvYmopIHtcclxuICAgICAgICAgICAgaWYgKG9iaiA9PSBudWxsKSB7IFxyXG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG5vU3VjaGtleSk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIC8vIENoZWNrIGZvciBidWlsdC1pbnMgYmVmb3JlIHRhY2tpbmcgb24gb3VyIG93biBmb3IgYW55IG9iamVjdFxyXG4gICAgICAgICAgICBpZiAodHlwZW9mIG9iaiA9PT0gJ3N0cmluZycpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBzdHJpbmdIYXNoRm4ob2JqKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgaWYgKHR5cGVvZiBvYmogPT09ICdudW1iZXInKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gbnVtYmVySGFzaEZuKG9iaik7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIGlmICh0eXBlb2Ygb2JqID09PSAnYm9vbGVhbicpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBvYmogPT09IHRydWUgPyAxIDogMDtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgaWYgKG9iaiBpbnN0YW5jZW9mIERhdGUpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBvYmouZ2V0VGltZSgpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBpZiAob2JqLmdldEhhc2hDb2RlKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gb2JqLmdldEhhc2hDb2RlKCk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHZhciBpZCA9IDE3ICogdW5pcXVlSWRDb3VudGVyKys7XHJcbiAgICAgICAgICAgIG9iai5nZXRIYXNoQ29kZSA9IGZ1bmN0aW9uICgpIHsgcmV0dXJuIGlkOyB9O1xyXG4gICAgICAgICAgICByZXR1cm4gaWQ7XHJcbiAgICAgICAgfTtcclxuICAgIH0gKCkpO1xyXG5cclxuICAgIGZ1bmN0aW9uIG5ld0VudHJ5KCkge1xyXG4gICAgICAgIHJldHVybiB7IGtleTogbnVsbCwgdmFsdWU6IG51bGwsIG5leHQ6IDAsIGhhc2hDb2RlOiAwIH07XHJcbiAgICB9XHJcblxyXG4gICAgLy8gRGljdGlvbmFyeSBpbXBsZW1lbnRhdGlvblxyXG5cclxuICAgIHZhciBEaWN0aW9uYXJ5ID0gZnVuY3Rpb24gKGNhcGFjaXR5LCBjb21wYXJlcikge1xyXG4gICAgICAgIGlmIChjYXBhY2l0eSA8IDApIHtcclxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdvdXQgb2YgcmFuZ2UnKVxyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAoY2FwYWNpdHkgPiAwKSB7XHJcbiAgICAgICAgICAgIHRoaXMuX2luaXRpYWxpemUoY2FwYWNpdHkpO1xyXG4gICAgICAgIH1cclxuICAgICAgICBcclxuICAgICAgICB0aGlzLmNvbXBhcmVyID0gY29tcGFyZXIgfHwgZGVmYXVsdENvbXBhcmVyO1xyXG4gICAgICAgIHRoaXMuZnJlZUNvdW50ID0gMDtcclxuICAgICAgICB0aGlzLnNpemUgPSAwO1xyXG4gICAgICAgIHRoaXMuZnJlZUxpc3QgPSAtMTtcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm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ICAgICAgICBmb3IgKHZhciBpbmRleDIgPSB0aGlzLmJ1Y2tldHNbaW5kZXgxXTsgaW5kZXgyID49IDA7IGluZGV4MiA9IHRoaXMuZW50cmllc1tpbmRleDJdLm5leHQpIHtcclxuICAgICAgICAgICAgaWYgKHRoaXMuZW50cmllc1tpbmRleDJdLmhhc2hDb2RlID09PSBudW0gJiYgdGhpcy5jb21wYXJlcih0aGlzLmVudHJpZXNbaW5kZXgyXS5rZXksIGtleSkpIHtcclxuICAgICAgICAgICAgICAgIGlmIChhZGQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoZHVwbGljYXRla2V5KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDJdLnZhbHVlID0gdmFsdWU7XHJcbiAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKHRoaXMuZnJlZUNvdW50ID4gMCkge1xyXG4gICAgICAgICAgICBpbmRleDMgPSB0aGlzLmZyZWVMaXN0O1xyXG4gICAgICAgICAgICB0aGlzLmZyZWVMaXN0ID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAgICAgLS10aGlzLmZyZWVDb3VudDtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBpZiAodGhpcy5zaXplID09PSB0aGlzLmVudHJpZXMubGVuZ3RoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9yZXNpemUoKTtcclxuICAgICAgICAgICAgICAgIGluZGV4MSA9IG51bSAlIHRoaXMuYnVja2V0cy5sZW5ndGg7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgaW5kZXgzID0gdGhpcy5zaXplO1xyXG4gICAgICAgICAgICArK3RoaXMuc2l6ZTtcclxuICAgICAgICB9XHJcbiAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10uaGFzaENvZGUgPSBudW07XHJcbiAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dCA9IHRoaXMuYnVja2V0c1tpbmRleDFdO1xyXG4gICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLmtleSA9IGtleTtcclxuICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS52YWx1ZSA9IHZhbHVlO1xyXG4gICAgICAgIHRoaXMuYnVja2V0c1tpbmRleDFdID0gaW5kZXgzO1xyXG4gICAgfTtcclxuXHJcbiAgICBEaWN0aW9uYXJ5LnByb3RvdHlwZS5fcmVzaXplID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBwcmltZSA9IGdldFByaW1lKHRoaXMuc2l6ZSAqIDIpLFxyXG4gICAgICAgICAgICBudW1BcnJheSA9IG5ldyBBcnJheShwcmltZSk7XHJcbiAgICAgICAgZm9yIChpbmRleCA9IDA7IGluZGV4IDwgbnVtQXJyYXkubGVuZ3RoOyArK2luZGV4KSB7XHJcbiAgICAgICAgICAgIG51bUFycmF5W2luZGV4XSA9IC0xO1xyXG4gICAgICAgIH1cclxuICAgICAgICB2YXIgZW50cnlBcnJheSA9IG5ldyBBcnJheShwcmltZSk7XHJcbiAgICAgICAgZm9yIChpbmRleCA9IDA7IGluZGV4IDwgdGhpcy5zaXplOyArK2luZGV4KSB7XHJcbiAgICAgICAgICAgIGVudHJ5QXJyYXlbaW5kZXhdID0gdGhpcy5lbnRyaWVzW2luZGV4XTtcclxuICAgICAgICB9XHJcbiAgICAgICAgZm9yICh2YXIgaW5kZXggPSB0aGlzLnNpemU7IGluZGV4IDwgcHJpbWU7ICsraW5kZXgpIHtcclxuICAgICAgICAgICAgZW50cnlBcnJheVtpbmRleF0gPSBuZXdFbnRyeSgpO1xyXG4gICAgICAgIH1cclxuICAgICAgICBmb3IgKHZhciBpbmRleDEgPSAwOyBpbmRleDEgPCB0aGlzLnNpemU7ICsraW5kZXgxKSB7XHJcbiAgICAgICAgICAgIHZhciBpbmRleDIgPSBlbnRyeUFycmF5W2luZGV4MV0uaGFzaENvZGUgJSBwcmltZTtcclxuICAgICAgICAgICAgZW50cnlBcnJheVtpbmRleDFdLm5leHQgPSBudW1BcnJheVtpbmRleDJdO1xyXG4gICAgICAgICAgICBudW1BcnJheVtpbmRleDJdID0gaW5kZXgxO1xyXG4gICAgICAgIH1cclxuICAgICAgICB0aGlzLmJ1Y2tldHMgPSBudW1BcnJheTtcclxuICAgICAgICB0aGlzLmVudHJpZXMgPSBlbnRyeUFycmF5O1xyXG4gICAgfTtcclxuXHJcbiAgICBEaWN0aW9uYXJ5LnByb3RvdHlwZS5yZW1vdmUgPSBmdW5jdGlvbiAoa2V5KSB7XHJcbiAgICAgICAgaWYgKHRoaXMuYnVja2V0cykge1xyXG4gICAgICAgICAgICB2YXIgbnVtID0gZ2V0SGFzaENvZGUoa2V5KSAmIDIxNDc0ODM2NDc7XHJcbiAgICAgICAgICAgIHZhciBpbmRleDEgPSBudW0gJSB0aGlzLmJ1Y2tldHMubGVuZ3RoO1xyXG4gICAgICAgICAgICB2YXIgaW5kZXgyID0gLTE7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGluZGV4MyA9IHRoaXMuYnVja2V0c1tpbmRleDFdOyBpbmRleDMgPj0gMDsgaW5kZXgzID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuZW50cmllc1tpbmRleDNdLmhhc2hDb2RlID09PSBudW0gJiYgdGhpcy5jb21wYXJlcih0aGlzLmVudHJpZXNbaW5kZXgzXS5rZXksIGtleSkpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaW5kZXgyIDwgMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmJ1Y2tldHNbaW5kZXgxXSA9IHRoaXMuZW50cmllc1tpbmRleDNdLm5leHQ7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4Ml0ubmV4dCA9IHRoaXMuZW50cmllc1tpbmRleDNdLm5leHQ7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLmhhc2hDb2RlID0gLTE7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dCA9IHRoaXMuZnJlZUxpc3Q7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10ua2V5ID0gbnVsbDtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS52YWx1ZSA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5mcmVlTGlzdCA9IGluZGV4MztcclxuICAgICAgICAgICAgICAgICAgICArK3RoaXMuZnJlZUNvdW50O1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBpbmRleDIgPSBpbmRleDM7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIGZhbHNlO1xyXG4gICAgfTtcclxuXHJcbiAgICBEaWN0aW9uYXJ5LnByb3RvdHlwZS5jbGVhciA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICB2YXIgaW5kZXgsIGxlbjtcclxuICAgICAgICBpZiAodGhpcy5zaXplIDw9IDApIHtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgIH1cclxuICAgICAgICBmb3IgKGluZGV4ID0gMCwgbGVuID0gdGhpcy5idWNrZXRzLmxlbmd0aDsgaW5kZXggPCBsZW47ICsraW5kZXgpIHtcclxuICAgICAgICAgICAgdGhpcy5idWNrZXRzW2luZGV4XSA9IC0xO1xyXG4gICAgICAgIH1cclxuICAgICAgICBmb3IgKGluZGV4ID0gMDsgaW5kZXggPCB0aGlzLnNpemU7ICsraW5kZXgpIHtcclxuICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4XSA9IG5ld0VudHJ5KCk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHRoaXMuZnJlZUxpc3QgPSAtMTtcclxuICAgICAgICB0aGlzLnNpemUgPSAwO1xyXG4gICAgfTtcclxuXHJcbiAgICBEaWN0aW9uYXJ5LnByb3RvdHlwZS5fZmluZEVudHJ5ID0gZnVuY3Rpb24gKGtleSkge1xyXG4gICAgICAgIGlmICh0aGlzLmJ1Y2tldHMpIHtcclxuICAgICAgICAgICAgdmFyIG51bSA9IGdldEhhc2hDb2RlKGtleSkgJiAyMTQ3NDgzNjQ3O1xyXG4gICAgICAgICAgICBmb3IgKHZhciBpbmRleCA9IHRoaXMuYnVja2V0c1tudW0gJSB0aGlzLmJ1Y2tldHMubGVuZ3RoXTsgaW5kZXggPj0gMDsgaW5kZXggPSB0aGlzLmVudHJpZXNbaW5kZXhdLm5leHQpIHtcclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmVudHJpZXNbaW5kZXhdLmhhc2hDb2RlID09PSBudW0gJiYgdGhpcy5jb21wYXJlcih0aGlzLmVudHJpZXNbaW5kZXhdLmtleSwga2V5KSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBpbmRleDtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gLTE7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLmNvdW50ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHJldHVybiB0aGlzLnNpemUgLSB0aGlzLmZyZWVDb3VudDtcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUudHJ5R2V0VmFsdWUgPSBmdW5jdGlvbiAoa2V5KSB7XHJcbiAgICAgICAgdmFyIGVudHJ5ID0gdGhpcy5fZmluZEVudHJ5KGtleSk7XHJcbiAgICAgICAgaWYgKGVudHJ5ID49IDApIHtcclxuICAgICAgICAgICAgcmV0dXJuIHRoaXMuZW50cmllc1tlbnRyeV0udmFsdWU7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiB1bmRlZmluZWQ7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLmdldFZhbHVlcyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICB2YXIgaW5kZXggPSAwLCByZXN1bHRzID0gW107XHJcbiAgICAgICAgaWYgKHRoaXMuZW50cmllcykge1xyXG4gICAgICAgICAgICBmb3IgKHZhciBpbmRleDEgPSAwOyBpbmRleDEgPCB0aGlzLnNpemU7IGluZGV4MSsrKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5lbnRyaWVzW2luZGV4MV0uaGFzaENvZGUgPj0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdHNbaW5kZXgrK10gPSB0aGlzLmVudHJpZXNbaW5kZXgxXS52YWx1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gcmVzdWx0cztcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUuZ2V0ID0gZnVuY3Rpb24gKGtleSkge1xyXG4gICAgICAgIHZhciBlbnRyeSA9IHRoaXMuX2ZpbmRFbnRyeShrZXkpO1xyXG4gICAgICAgIGlmIChlbnRyeSA+PSAwKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLmVudHJpZXNbZW50cnldLnZhbHVlO1xyXG4gICAgICAgIH1cclxuICAgICAgICB0aHJvdyBuZXcgRXJyb3Iobm9TdWNoa2V5KTtcclxuICA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gICAgICAgICAgbGVmdE1hcCA9IG5ldyBEaWN0aW9uYXJ5KCksXHJcbiAgICAgICAgICAgIHJpZ2h0RG9uZSA9IGZhbHNlLFxyXG4gICAgICAgICAgICByaWdodElkID0gMCxcclxuICAgICAgICAgICAgcmlnaHRNYXAgPSBuZXcgRGljdGlvbmFyeSgpO1xyXG4gICAgICAgICAgICBncm91cC5hZGQobGVmdC5zdWJzY3JpYmUoZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgZHVyYXRpb24sXHJcbiAgICAgICAgICAgICAgICBleHBpcmUsXHJcbiAgICAgICAgICAgICAgICBpZCA9IGxlZnRJZCsrLFxyXG4gICAgICAgICAgICAgICAgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHJlc3VsdCxcclxuICAgICAgICAgICAgICAgIHZhbHVlcztcclxuICAgICAgICAgICAgICAgIGxlZnRNYXAuYWRkKGlkLCB2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICBncm91cC5hZGQobWQpO1xyXG4gICAgICAgICAgICAgICAgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChsZWZ0TWFwLnJlbW92ZShpZCkgJiYgbGVmdE1hcC5jb3VudCgpID09PSAwICYmIGxlZnREb25lKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZHVyYXRpb24gPSBsZWZ0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKG5vb3AsIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHsgZXhwaXJlKCk7IH0pKTtcclxuICAgICAgICAgICAgICAgIHZhbHVlcyA9IHJpZ2h0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCB2YWx1ZXMubGVuZ3RoOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3Rvcih2YWx1ZSwgdmFsdWVzW2ldKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBsZWZ0RG9uZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBpZiAocmlnaHREb25lIHx8IGxlZnRNYXAuY291bnQoKSA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgZ3JvdXAuYWRkKHJpZ2h0LnN1YnNjcmliZShmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHZhciBkdXJhdGlvbixcclxuICAgICAgICAgICAgICAgIGV4cGlyZSxcclxuICAgICAgICAgICAgICAgIGlkID0gcmlnaHRJZCsrLFxyXG4gICAgICAgICAgICAgICAgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHJlc3VsdCxcclxuICAgICAgICAgICAgICAgIHZhbHVlcztcclxuICAgICAgICAgICAgICAgIHJpZ2h0TWFwLmFkZChpZCwgdmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgZ3JvdXAuYWRkKG1kKTtcclxuICAgICAgICAgICAgICAgIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAocmlnaHRNYXAucmVtb3ZlKGlkKSAmJiByaWdodE1hcC5jb3VudCgpID09PSAwICYmIHJpZ2h0RG9uZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZ3JvdXAucmVtb3ZlKG1kKTtcclxuICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uID0gcmlnaHREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKG5vb3AsIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHsgZXhwaXJlKCk7IH0pKTtcclxuICAgICAgICAgICAgICAgIHZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHZhbHVlcy5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHZhbHVlc1tpXSwgdmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHJpZ2h0RG9uZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBpZiAobGVmdERvbmUgfHwgcmlnaHRNYXAuY291bnQoKSA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgcmV0dXJuIGdyb3VwO1xyXG4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ZXcgRGljdGlvbmFyeSgpO1xyXG4gICAgICAgICAgICB2YXIgcmlnaHRNYXAgPSBuZXcgRGljdGlvbmFyeSgpO1xyXG4gICAgICAgICAgICB2YXIgbGVmdElEID0gMDtcclxuICAgICAgICAgICAgdmFyIHJpZ2h0SUQgPSAwO1xyXG5cclxuICAgICAgICAgICAgZ3JvdXAuYWRkKGxlZnQuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIHMgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBpZCA9IGxlZnRJRCsrO1xyXG4gICAgICAgICAgICAgICAgICAgIGxlZnRNYXAuYWRkKGlkLCBzKTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgaSwgbGVuLCBsZWZ0VmFsdWVzLCByaWdodFZhbHVlcztcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3Rvcih2YWx1ZSwgYWRkUmVmKHMsIHIpKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBsZWZ0VmFsdWVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzW2ldLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgcmlnaHRWYWx1ZXMgPSByaWdodE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSByaWdodFZhbHVlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzLm9uTmV4dChyaWdodFZhbHVlc1tpXSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB2YXIgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICBncm91cC5hZGQobWQpO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB2YXIgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVmdE1hcC5yZW1vdmUoaWQpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBkdXJhdGlvbjtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbiA9IGxlZnREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBsZWZ0TWFwLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzW2ldLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShcclxuICAgICAgICAgICAgICAgICAgICAgICAgbm90aGluZyxcclxuICAgICAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gbGVmdFZhbHVlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXNbaV0ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGV4cGlyZSlcclxuICAgICAgICAgICAgICAgICAgICApO1xyXG4gICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGxlZnRWYWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBsZWZ0VmFsdWVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXNbaV0ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZC5iaW5kKG9ic2VydmVyKSkpO1xyXG5cclxuICAgICAgICAgICAgZ3JvdXAuYWRkKHJpZ2h0LnN1YnNjcmliZShcclxuICAgICAgICAgICAgICAgIGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBsZWZ0VmFsdWVzLCBpLCBsZW47XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGlkID0gcmlnaHRJRCsrO1xyXG4gICAgICAgICAgICAgICAgICAgIHJpZ2h0TWFwLmFkZChpZCwgdmFsdWUpO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB2YXIgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICBncm91cC5hZGQobWQpO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB2YXIgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByaWdodE1hcC5yZW1vdmUoaWQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBkdXJhdGlvbjtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbiA9IHJpZ2h0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gbGVmdE1hcC5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShcclxuICAgICAgICAgICAgICAgICAgICAgICAgbm90aGluZyxcclxuICAgICAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gbGVmdE1hcC5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXNbaV0ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGV4cGlyZSlcclxuICAgICAgICAgICAgICAgICAgICApO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBsZWZ0VmFsdWVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXNbaV0ub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGxlZnRWYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG5cclxuICAgICAgICAgICAgcmV0dXJuIHI7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFByb2plY3RzIGVhY2ggZWxlbWVudCBvZiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIGludG8gemVybyBvciBtb3JlIGJ1ZmZlcnMuXHJcbiAgICAgKiAgXHJcbiAgICAgKiAgQHBhcmFtIHtNaXhlZH0gYnV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bmRhcmllcykge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHdpbmRvdyA9IG5ldyBTdWJqZWN0KCksIFxyXG4gICAgICAgICAgICAgICAgZCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCksIFxyXG4gICAgICAgICAgICAgICAgciA9IG5ldyBSZWZDb3VudERpc3Bvc2FibGUoZCk7XHJcblxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHdpbmRvdywgcikpO1xyXG5cclxuICAgICAgICAgICAgZC5hZGQoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KSk7XHJcblxyXG4gICAgICAgICAgICBkLmFkZCh3aW5kb3dCb3VuZGFyaWVzLnN1YnNjcmliZShmdW5jdGlvbiAodykge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZih3aW5kb3csIHIpKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KSk7XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gcjtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBvYnNlcnZhYmxlV2luZG93V2l0aENsb3NpbmdTZWxlY3Rvcih3aW5kb3dDbG9zaW5nU2VsZWN0b3IpIHtcclxuICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBjcmVhdGVXaW5kb3dDbG9zZSxcclxuICAgICAgICAgICAgICAgIG0gPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgZCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKG0pLFxyXG4gICAgICAgICAgICAgICAgciA9IG5ldyBSZWZDb3VudERpc3Bvc2FibGUoZCksXHJcbiAgICAgICAgICAgICAgICB3aW5kb3cgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHdpbmRvdywgcikpO1xyXG4gICAgICAgICAgICBkLmFkZChzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25OZXh0KHgpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXgpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgY3JlYXRlV2luZG93Q2xvc2UgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbTEsIHdpbmRvd0Nsb3NlO1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICB3aW5kb3dDbG9zZSA9IHdpbmRvd0Nsb3NpbmdTZWxlY3RvcigpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG0xID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICBtLnNldERpc3Bvc2FibGUobTEpO1xyXG4gICAgICAgICAgICAgICAgbTEuc2V0RGlzcG9zYWJsZSh3aW5kb3dDbG9zZS50YWtlKDEpLnN1YnNjcmliZShub29wLCBmdW5jdGlvbiAoZXgpIHtcclxuICAgICAgICAgICAgICAgICAgICB3aW5kb3cub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAg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AgICB2YXIgaXNPd25lciA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgaWYgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlzT3duZXIgPSAhaXNBY3F1aXJlZDtcclxuICAgICAgICAgICAgICAgICAgICBpc0FjcXVpcmVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChpc093bmVyKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbS5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZShmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgd29yaztcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgd29yayA9IHEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzQWNxdWlyZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgbTEgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZC5hZGQobTEpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBtMS5zZXREaXNwb3NhYmxlKHdvcmsuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgcmVzdWx0ID0gbnVsbDtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gc2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHEucHVzaChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgYWN0aXZlQ291bnQrKztcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkLnJlbW92ZShtMSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY3RpdmVDb3VudC0tO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGFjdGl2ZUNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzZWxmKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgcS5wdXNoKHNvdXJjZSk7XHJcbiAgICAgICAgICAgIGFjdGl2ZUNvdW50Kys7XHJcbiAgICAgICAgICAgIGVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICAgICAgICByZXR1cm4gZDtcclxuICA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HJcbiAgICAgICAgaGFzQ29tcGxldGVkID0gbmV3IEFycmF5KGNvdW50KSxcclxuICAgICAgICByZXN1bHRzID0gbmV3IEFycmF5KGNvdW50KTtcclxuXHJcbiAgICAgIGZvciAodmFyIGlkeCA9IDA7IGlkeCA8IGNvdW50OyBpZHgrKykge1xyXG4gICAgICAgIChmdW5jdGlvbiAoaSkge1xyXG4gICAgICAgICAgdmFyIHNvdXJjZSA9IGFsbFNvdXJjZXNbaV07XHJcbiAgICAgICAgICBpc1Byb21pc2Uoc291cmNlKSAmJiAoc291cmNlID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHNvdXJjZSkpO1xyXG4gICAgICAgICAgZ3JvdXAuYWRkKFxyXG4gICAgICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgIGlmICghZmluaXNoZWQpIHtcclxuICAgICAgICAgICAgICAgIGhhc1Jlc3VsdHNbaV0gPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgcmVzdWx0c1tpXSA9IHZhbHVlO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgZmluaXNoZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgIHN1YnNjcmliZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICBncm91cC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH0sIFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgaWYgKCFmaW5pc2hlZCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNSZXN1bHRzW2ldKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVyb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1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgbGVmdFN0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICBpZiAocmlnaHRTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgaWYgKCFoYXNMZWZ0KSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIGlmICghaGFzUmlnaHQpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKGxhc3RMZWZ0LCBsYXN0UmlnaHQpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9KVxyXG4gICAgICApO1xyXG5cclxuICAgICAgcmlnaHRTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShcclxuICAgICAgICBzZWNvbmQuc3Vic2NyaWJlKGZ1bmN0aW9uIChyaWdodCkge1xyXG4gICAgICAgICAgaGFzUmlnaHQgPSB0cnVlO1xyXG4gICAgICAgICAgbGFzdFJpZ2h0ID0gcmlnaHQ7XHJcbiAgICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgbGVmdFN1YnNjcmlwdGlvbi5kaXNwb3NlKCk7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgcmlnaHRTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgIGlmIChsZWZ0U3RvcHBlZCkge1xyXG4gICAgICAgICAgICBpZiAoIWhhc0xlZnQpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9IGVsc2UgaWYgKCFoYXNSaWdodCkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3IobGFzdExlZnQsIGxhc3RSaWdodCk7XHJcbiAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0pXHJcbiAgICAgICk7XHJcblxyXG4gICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUobGVmdFN1YnNjcmlwdGlvbiwgcmlnaHRTdWJzY3JpcHRpb24pO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqIENvbW9uYWRpYyBiaW5kIG9wZXJhdG9y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AgICAgICAgICAgICAgICAgICAgICAgIGNoYWluID0gY3VycjtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBjdXJyO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pXHJcbiAgICAgICAgICAgICAgICAuZG9BY3Rpb24oXHJcbiAgICAgICAgICAgICAgICAgICAgbm9vcCxcclxuICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoY2hhaW4pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoYWluLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNoYWluKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGFpbi5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSlcclxuICAgICAgICAgICAgICAgIC5vYnNlcnZlT24oc2NoZWR1bGVyKVxyXG4gICAgICAgICAgICAgICAgLnNlbGVjdChmdW5jdGlvbiAoeCwgaSwgbykgeyByZXR1cm4gc2VsZWN0b3IoeCwgaSwgbyk7IH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICB2YXIgQ2hhaW5PYnNlcnZhYmxlID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc3Vic2NyaWJlIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgc2VsZiA9IHRoaXMsIGcgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBnLmFkZChjdXJyZW50VGhyZWFkU2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChzZWxmLmhlYWQpO1xyXG4gICAgICAgICAgICAgICAgZy5hZGQoc2VsZi50YWlsLm1lcmdlT2JzZXJ2YWJsZSgpLnN1YnNjcmliZShvYnNlcnZlcikpO1xyXG4gICAgICAgICAgICB9KSk7XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gZztcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGluaGVyaXRzKENoYWluT2JzZXJ2YWJsZSwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgZnVuY3Rpb24gQ2hhaW5PYnNlcnZhYmxlKGhlYWQpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICAgICAgdGhpcy5oZWFkID0gaGVhZDtcclxuICAgICAgICAgICAgdGhpcy50YWlsID0gbmV3IEFzeW5jU3ViamVjdCgpO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgYWRkUHJvcGVydGllcyhDaGFpbk9ic2VydmFibGUucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vbk5leHQoT2JzZXJ2YWJsZS5lbXB0eSgpKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub25OZXh0KE9ic2VydmFibGUudGhyb3dFeGNlcHRpb24oZSkpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2KSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnRhaWwub25OZXh0KHYpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy50YWlsLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9KTtcclxuXHJcbiAgICAgICAgcmV0dXJuIENoYWluT2JzZXJ2YWJsZTtcclxuXHJcbiAgICB9KE9ic2VydmFibGUpKTtcclxuXHJcbiAgICAvKiogQHByaXZhdGUgKi9cclxuICAgIHZhciBNYXAgPSAoZnVuY3Rpb24gKCkge1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIGZ1bmN0aW9uIE1hcCgpIHtcclxuICAgICAgICAgICAgdGhpcy5rZXlzID0gW107XHJcbiAgICAgICAgICAgIHRoaXMudmFsdWVzID0gW107XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBNYXAjXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgTWFwLnByb3RvdHlwZVsnZGVsZXRlJ10gPSBmdW5jdGlvbiAoa2V5KSB7XHJcbiAgICAgICAgICAgIHZhciBpID0gdGhpcy5rZXlzLmluZGV4T2Yoa2V5KTtcclxuICAgICAgICAgICAgaWYgKGkgIT09IC0xKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmtleXMuc3BsaWNlKGksIDEpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy52YWx1ZXMuc3BsaWNlKGksIDEpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHJldHVybiBpICE9PSAtMTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBNYXAjXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgTWFwLnByb3RvdHlwZS5nZXQgPSBmdW5jdGlvbiAoa2V5LCBmYWxsYmFjaykge1xyXG4gICAgICAgICAgICB2YXIgaSA9IHRoaXMua2V5cy5pbmRleE9mKGtleSk7XHJcbiAgICAgICAgICAgIHJldHVybiBpICE9PSAtMSA/IHRoaXMudmFsdWVzW2ldIDogZmFsbGJhY2s7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgTWFwI1xyXG4gICAgICAgICAqL1xyXG4gICAgICAgIE1hcC5wcm90b3R5cGUuc2V0ID0gZnVuY3Rpb24gKGtleSwgdmFsdWUpIHtcclxuICAgICAgICAgICAgdmFyIGkgPSB0aGlzLmtleXMuaW5kZXhPZihrZXkpO1xyXG4gICAgICAgICAgICBpZiAoaSAhPT0gLTEpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMudmFsdWVzW2ldID0gdmFsdWU7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgdGhpcy52YWx1ZXNbdGhpcy5rZXlzLnB1c2goa2V5KSAtIDFdID0gdmFsdWU7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgTWFwI1xyXG4gICAgICAgICAqL1xyXG4gICAgICAgIE1hcC5wcm90b3R5cGUuc2l6ZSA9IGZ1bmN0aW9uICgpIHsgcmV0dXJuIHRoaXMua2V5cy5sZW5ndGg7IH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIE1hcC5wcm90b3R5cGUuaGFzID0gZnVuY3Rpb24gKGtleSkge1xyXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5rZXlzLmluZGV4T2Yoa2V5KSAhPT0gLTE7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAg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ICAgIEFjdGl2ZVBsYW4ucHJvdG90eXBlLm1hdGNoID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBmaXJzdFZhbHVlcywgaSwgbGVuLCBpc0NvbXBsZXRlZCwgdmFsdWVzLCBoYXNWYWx1ZXMgPSB0cnVlO1xyXG4gICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IHRoaXMuam9pbk9ic2VydmVyQXJyYXkubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgaWYgKHRoaXMuam9pbk9ic2VydmVyQXJyYXlbaV0ucXVldWUubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICBoYXNWYWx1ZXMgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIGJyZWFrO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChoYXNWYWx1ZXMpIHtcclxuICAgICAgICAgICAgZmlyc3RWYWx1ZXMgPSBbXTtcclxuICAgICAgICAgICAgaXNDb21wbGV0ZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gdGhpcy5qb2luT2JzZXJ2ZXJBcnJheS5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgZmlyc3RWYWx1ZXMucHVzaCh0aGlzLmpvaW5PYnNlcnZlckFycmF5W2ldLnF1ZXVlWzBdKTtcclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmpvaW5PYnNlcnZlckFycmF5W2ldLnF1ZXVlWzBdLmtpbmQgPT09ICdDJykge1xyXG4gICAgICAgICAgICAgICAgICAgIGlzQ29tcGxldGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpZiAoaXNDb21wbGV0ZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGVxdWV1ZSgpO1xyXG4gICAgICAgICAgICAgICAgdmFsdWVzID0gW107XHJcbiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgZmlyc3RWYWx1ZXMubGVuZ3RoOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICB2YWx1ZXMucHVzaChmaXJzdFZhbHVlc1tpXS52YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9uTmV4dC5hcHBseSh0aGlzLCB2YWx1ZXMpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgfTtcclxuXHJcbiAgICAvKiogQHByaXZhdGUgKi9cclxuICAgIHZhciBKb2luT2JzZXJ2ZXIgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG5cclxuICAgICAgICBpbmhlcml0cyhKb2luT2JzZXJ2ZXIsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gSm9pbk9ic2VydmVyKHNvdXJjZSwgb25FcnJvcikge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgdGhpcy5zb3VyY2UgPSBzb3VyY2U7XHJcbiAgICAgICAgICAgIHRoaXMub25FcnJvciA9IG9uRXJyb3I7XHJcbiAgICAgICAgICAgIHRoaXMucXVldWUgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy5hY3RpdmVQbGFucyA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLnN1YnNjcmlwdGlvbiA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSBmYWxzZTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHZhciBKb2luT2JzZXJ2ZXJQcm90b3R5cGUgPSBKb2luT2JzZXJ2ZXIucHJvdG90eXBlO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAbWVtYmVyT2YgSm9pbk9ic2VydmVyI1xyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgSm9pbk9ic2VydmVyUHJvdG90eXBlLm5leHQgPSBmdW5jdGlvbiAobm90aWZpY2F0aW9uKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc0Rpc3Bvc2VkKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAobm90aWZpY2F0aW9uLmtpbmQgPT09ICdFJykge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub25FcnJvcihub3RpZmljYXRpb24uZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB0aGlzLnF1ZXVlLnB1c2gobm90aWZpY2F0aW9uKTtcclxuICAgICAgICAgICAgICAgIHZhciBhY3RpdmVQbGFucyA9IHRoaXMuYWN0aXZlUGxhbnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gYWN0aXZlUGxhbnMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICBhY3RpdmVQbGFuc1tpXS5tYXRjaCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQG1lbWJlck9mIEpvaW5PYnNlcnZlciNcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqLyAgICAgICAgXHJcbiAgICAgICAgSm9pbk9ic2VydmVyUHJvdG90eXBlLmVycm9yID0gbm9vcDtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQG1lbWJlck9mIEpvaW5PYnNlcnZlciNcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqLyAgICAgICAgXHJcbiAgICAgICAgSm9pbk9ic2VydmVyUHJvdG90eXBlLmNvbXBsZXRlZCA9IG5vb3A7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi9cclxuICAgICAgICBKb2luT2JzZXJ2ZXJQcm90b3R5cGUuYWRkQWN0aXZlUGxhbiA9IGZ1bmN0aW9uIChhY3RpdmVQbGFuKSB7XHJcbiAgICAgICAgICAgIHRoaXMuYWN0aXZlUGxhbnMucHVzaChhY3RpdmVQbGFuKTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAbWVtYmVyT2YgSm9pbk9ic2VydmVyI1xyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBKb2luT2JzZXJ2ZXJQcm90b3R5cGUuc3Vic2NyaWJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0aGlzLnN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKHRoaXMuc291cmNlLm1hdGVyaWFsaXplKCkuc3Vic2NyaWJlKHRoaXMpKTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAbWVtYmVyT2YgSm9pbk9ic2VydmVyI1xyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBKb2luT2JzZXJ2ZXJQcm90b3R5cGUucmVtb3ZlQWN0aXZlUGxhbiA9IGZ1bmN0aW9uIChhY3RpdmVQbGFuKSB7XHJcbi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ICAgICAgICAgICAgICAgIGZvciAodmFyIGogPSAwLCBqbGVuID0gdmFsdWVzLmxlbmd0aDsgaiA8IGpsZW47IGorKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhbHVlc1tqXS5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IHBsYW5zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgYWN0aXZlUGxhbnMucHVzaChwbGFuc1tpXS5hY3RpdmF0ZShleHRlcm5hbFN1YnNjcmlwdGlvbnMsIG91dE9ic2VydmVyLCBmdW5jdGlvbiAoYWN0aXZlUGxhbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgaWR4ID0gYWN0aXZlUGxhbnMuaW5kZXhPZihhY3RpdmVQbGFuKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgYWN0aXZlUGxhbnMuc3BsaWNlKGlkeCwgMSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhY3RpdmVQbGFucy5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dE9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmFibGVUaHJvdyhlKS5zdWJzY3JpYmUob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGdyb3VwID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgam9pblZhbHVlcyA9IGV4dGVybmFsU3Vic2NyaXB0aW9ucy5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gam9pblZhbHVlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgam9pbk9ic2VydmVyID0gam9pblZhbHVlc1tpXTtcclxuICAgICAgICAgICAgICAgIGpvaW5PYnNlcnZlci5zdWJzY3JpYmUoKTtcclxuICAgICAgICAgICAgICAgIGdyb3VwLmFkZChqb2luT2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHJldHVybiBncm91cDtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgZnVuY3Rpb24gb2JzZXJ2YWJsZVRpbWVyRGF0ZShkdWVUaW1lLCBzY2hlZHVsZXIpIHtcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBzY2hlZHVsZXIuc2NoZWR1bGVXaXRoQWJzb2x1dGUoZHVlVGltZSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KDApO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9XHJcblxyXG4gIGZ1bmN0aW9uIG9ic2VydmFibGVUaW1lckRhdGVBbmRQZXJpb2QoZHVlVGltZSwgcGVyaW9kLCBzY2hlZHVsZXIpIHtcclxuICAgIHZhciBwID0gbm9ybWFsaXplVGltZShwZXJpb2QpO1xyXG4gICAgcmV0dXJuIG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G9ic2VydmFibGVUaW1lckRhdGUoZHVlVGltZS5nZXRUaW1lKCksIHNjaGVkdWxlcik7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChkdWVUaW1lIGluc3RhbmNlb2YgRGF0ZSAmJiBwZXJpb2QgIT09IHVuZGVmaW5lZCkge1xyXG4gICAgICAgICAgICBwZXJpb2QgPSBwZXJpb2RPclNjaGVkdWxlcjtcclxuICAgICAgICAgICAgcmV0dXJuIG9ic2VydmFibGVUaW1lckRhdGVBbmRQZXJpb2QoZHVlVGltZS5nZXRUaW1lKCksIHBlcmlvZCwgc2NoZWR1bGVyKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKHBlcmlvZCA9PT0gdW5kZWZpbmVkKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBvYnNlcnZhYmxlVGltZXJUaW1lU3BhbihkdWVUaW1lLCBzY2hlZHVsZXIpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gb2JzZXJ2YWJsZVRpbWVyVGltZVNwYW5BbmRQZXJpb2QoZHVlVGltZSwgcGVyaW9kLCBzY2hlZHVsZXIpO1xyXG4gICAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBvYnNlcnZhYmxlRGVsYXlUaW1lU3BhbihkdWVUaW1lLCBzY2hlZHVsZXIpIHtcclxuICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBhY3RpdmUgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgIGNhbmNlbGFibGUgPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgZXhjZXB0aW9uID0gbnVsbCxcclxuICAgICAgICAgICAgICAgIHEgPSBbXSxcclxuICAgICAgICAgICAgICAgIHJ1bm5pbmcgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbjtcclxuICAgICAgICAgICAgc3Vic2NyaXB0aW9uID0gc291cmNlLm1hdGVyaWFsaXplKCkudGltZXN0YW1wKHNjaGVkdWxlcikuc3Vic2NyaWJlKGZ1bmN0aW9uIChub3RpZmljYXRpb24pIHtcclxuICAgICAgICAgICAgICAgIHZhciBkLCBzaG91bGRSdW47XHJcbiAgICAgICAgICAgICAgICBpZiAobm90aWZpY2F0aW9uLnZhbHVlLmtpbmQgPT09ICdFJykge1xyXG4gICAgICAgICAgICAgICAgICAgIHEgPSBbXTtcclxuICAgICAgICAgICAgICAgICAgICBxLnB1c2gobm90aWZpY2F0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICBleGNlcHRpb24gPSBub3RpZmljYXRpb24udmFsdWUuZXhjZXB0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgIHNob3VsZFJ1biA9ICFydW5uaW5nO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBxLnB1c2goeyB2YWx1ZTogbm90aWZpY2F0aW9uLnZhbHVlLCB0aW1lc3RhbXA6IG5vdGlmaWNhdGlvbi50aW1lc3RhbXAgKyBkdWVUaW1lIH0pO1xyXG4gICAgICAgICAgICAgICAgICAgIHNob3VsZFJ1biA9ICFhY3RpdmU7XHJcbiAgICAgICAgICAgICAgICAgICAgYWN0aXZlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChzaG91bGRSdW4pIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoZXhjZXB0aW9uICE9PSBudWxsKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGNhbmNlbGFibGUuc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZVdpdGhSZWxhdGl2ZShkdWVUaW1lLCBmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGUsIHJlY3Vyc2VEdWVUaW1lLCByZXN1bHQsIHNob3VsZFJlY3Vyc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZXhjZXB0aW9uICE9PSBudWxsKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcnVubmluZyA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gbnVsbDtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwICYmIHFbMF0udGltZXN0YW1wIC0gc2NoZWR1bGVyLm5vdygpIDw9IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcS5zaGlmdCgpLnZhbHVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocmVzdWx0ICE9PSBudWxsKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdC5hY2NlcHQob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKHJlc3VsdCAhPT0gbnVsbCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG91bGRSZWN1cnNlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZWN1cnNlRHVlVGltZSA9IDA7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvdWxkUmVjdXJzZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVjdXJzZUR1ZVRpbWUgPSBNYXRoLm1heCgwLCBxWzBdLnRpbWVzdGFtcCAtIHNjaGVkdWxlci5ub3coKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFjdGl2ZSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZSA9IGV4Y2VwdGlvbjtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJ1bm5pbmcgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlICE9PSBudWxsKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc2hvdWxkUmVjdXJzZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYocmVjdXJzZUR1ZVRpbWUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgIC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iAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgZ3JvdXBEaXNwb3NhYmxlLFxyXG4gICAgICAgICAgICAgICAgbmV4dFNoaWZ0ID0gdGltZVNoaWZ0LFxyXG4gICAgICAgICAgICAgICAgbmV4dFNwYW4gPSB0aW1lU3BhbixcclxuICAgICAgICAgICAgICAgIHEgPSBbXSxcclxuICAgICAgICAgICAgICAgIHJlZkNvdW50RGlzcG9zYWJsZSxcclxuICAgICAgICAgICAgICAgIHRpbWVyRCA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICB0b3RhbFRpbWUgPSAwO1xyXG4gICAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUodGltZXJEKSxcclxuICAgICAgICAgICAgICAgIHJlZkNvdW50RGlzcG9zYWJsZSA9IG5ldyBSZWZDb3VudERpc3Bvc2FibGUoZ3JvdXBEaXNwb3NhYmxlKTtcclxuXHJcbiAgICAgICAgICAgICBmdW5jdGlvbiBjcmVhdGVUaW1lciAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbSA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgICAgIGlzU3BhbiA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgICAgIGlzU2hpZnQgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIHRpbWVyRC5zZXREaXNwb3NhYmxlKG0pO1xyXG4gICAgICAgICAgICAgICAgaWYgKG5leHRTcGFuID09PSBuZXh0U2hpZnQpIHtcclxuICAgICAgICAgICAgICAgICAgICBpc1NwYW4gPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGlzU2hpZnQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChuZXh0U3BhbiA8IG5leHRTaGlmdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlzU3BhbiA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGlzU2hpZnQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdmFyIG5ld1RvdGFsVGltZSA9IGlzU3BhbiA/IG5leHRTcGFuIDogbmV4dFNoaWZ0LFxyXG4gICAgICAgICAgICAgICAgICAgIHRzID0gbmV3VG90YWxUaW1lIC0gdG90YWxUaW1lO1xyXG4gICAgICAgICAgICAgICAgdG90YWxUaW1lID0gbmV3VG90YWxUaW1lO1xyXG4gICAgICAgICAgICAgICAgaWYgKGlzU3Bhbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG5leHRTcGFuICs9IHRpbWVTaGlmdDtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChpc1NoaWZ0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV4dFNoaWZ0ICs9IHRpbWVTaGlmdDtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG0uc2V0RGlzcG9zYWJsZShzY2hlZHVsZXIuc2NoZWR1bGVXaXRoUmVsYXRpdmUodHMsIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgcztcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaXNTaGlmdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBpZiAoaXNTcGFuKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHMgPSBxLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgY3JlYXRlVGltZXIoKTtcclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgcS5wdXNoKG5ldyBTdWJqZWN0KCkpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHFbMF0sIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICAgICAgICBjcmVhdGVUaW1lcigpO1xyXG4gICAgICAgICAgICBncm91cERpc3Bvc2FibGUuYWRkKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBpLCBzO1xyXG4gICAgICAgICAgICAgICAgZm9yIChpID0gMDsgaSA8IHEubGVuZ3RoOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICBzID0gcVtpXTtcclxuICAgICAgICAgICAgICAgICAgICBzLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgIHZhciBpLCBzO1xyXG4gICAgICAgICAgICAgICAgZm9yIChpID0gMDsgaSA8IHEubGVuZ3RoOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICBzID0gcVtpXTtcclxuICAgICAgICAgICAgICAgICAgICBzLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgaSwgcztc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jdGlvbiAoaWQpIHtcclxuICAgICAgICAgICAgICAgIHZhciBtID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICB0aW1lckQuc2V0RGlzcG9zYWJsZShtKTtcclxuICAgICAgICAgICAgICAgIG0uc2V0RGlzcG9zYWJsZShzY2hlZHVsZXIuc2NoZWR1bGVXaXRoUmVsYXRpdmUodGltZVNwYW4sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbmV3SWQ7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlkICE9PSB3aW5kb3dJZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG4gPSAwO1xyXG4gICAgICAgICAgICAgICAgICAgIG5ld0lkID0gKyt3aW5kb3dJZDtcclxuICAgICAgICAgICAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihzLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgICAgICAgICAgICAgICBjcmVhdGVUaW1lcihuZXdJZCk7XHJcbiAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIHMgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICAgICAgICBjcmVhdGVUaW1lcigwKTtcclxuICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLmFkZChzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbmV3SWQgPSAwLCBuZXdXaW5kb3cgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIHMub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgbisrO1xyXG4gICAgICAgICAgICAgICAgaWYgKG4gPT09IGNvdW50KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV3V2luZG93ID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBuID0gMDtcclxuICAgICAgICAgICAgICAgICAgICBuZXdJZCA9ICsrd2luZG93SWQ7XHJcbiAgICAgICAgICAgICAgICAgICAgcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHMgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAobmV3V2luZG93KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgY3JlYXRlVGltZXIobmV3SWQpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgcy5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICByZXR1cm4gcmVmQ291bnREaXNwb3NhYmxlO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBQcm9qZWN0cyBlYWNoIGVsZW1lbnQgb2YgYW4gb2JzZXJ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09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBhdEVuZCwgdmFsdWUsIGhhc1ZhbHVlO1xyXG5cclxuICAgICAgICAgICAgZnVuY3Rpb24gc2FtcGxlU3Vic2NyaWJlKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1ZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGF0RW5kKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgcmV0dXJuIG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKFxyXG4gICAgICAgICAgICAgICAgc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAobmV3VmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFsdWUgPSBuZXdWYWx1ZTtcclxuICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBhdEVuZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9KSxcclxuICAgICAgICAgICAgICAgIHNhbXBsZXIuc3Vic2NyaWJlKHNhbXBsZVN1YnNjcmliZSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgc2FtcGxlU3Vic2NyaWJlKVxyXG4gICAgICAgICAgICApO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIC8qKlxyXG4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ZSB0aW1lb3V0IHNjaGVkdWxlciBpcyB1c2VkLlxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IFRoZSBnZW5lcmF0ZWQgc2VxdWVuY2UuXHJcbiAgICAgKi9cclxuICAgIE9ic2VydmFibGUuZ2VuZXJhdGVXaXRoQWJzb2x1dGVUaW1lID0gZnVuY3Rpb24gKGluaXRpYWxTdGF0ZSwgY29uZGl0aW9uLCBpdGVyYXRlLCByZXN1bHRTZWxlY3RvciwgdGltZVNlbGVjdG9yLCBzY2hlZHVsZXIpIHtcclxuICAgICAgICBzY2hlZHVsZXIgfHwgKHNjaGVkdWxlciA9IHRpbWVvdXRTY2hlZHVsZXIpO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGZpcnN0ID0gdHJ1ZSxcclxuICAgICAgICAgICAgICAgIGhhc1Jlc3VsdCA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgcmVzdWx0LFxyXG4gICAgICAgICAgICAgICAgc3RhdGUgPSBpbml0aWFsU3RhdGUsXHJcbiAgICAgICAgICAgICAgICB0aW1lO1xyXG4gICAgICAgICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlV2l0aEFic29sdXRlKHNjaGVkdWxlci5ub3coKSwgZnVuY3Rpb24gKHNlbGYpIHtcclxuICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZpcnN0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZpcnN0ID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUgPSBpdGVyYXRlKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzUmVzdWx0ID0gY29uZGl0aW9uKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaGFzUmVzdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGltZSA9IHRpbWVTZWxlY3RvcihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHNlbGYodGltZSk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBHZW5lcmF0ZXMgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSBieSBpdGVyYXRpbmcgYSBzdGF0ZSBmcm9tIGFuIGluaXRpYWwgc3RhdGUgdW50aWwgdGhlIGNvbmRpdGlvbiBmYWlscy5cclxuICAgICAqIFxyXG4gICAgICogQGV4YW1wbGUgXHJcbiAgICAgKiAgcmVzID0gc291cmNlLmdlbmVyYXRlV2l0aFJlbGF0aXZlVGltZSgwLCBcclxuICAgICAqICA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HVsZXIgaXMgdXNlZC5cclxuICAgICAqIEByZXR1cm5zIHtPYnNlcnZhYmxlfSBUaGUgZ2VuZXJhdGVkIHNlcXVlbmNlLlxyXG4gICAgICovXHJcbiAgICBPYnNlcnZhYmxlLmdlbmVyYXRlV2l0aFJlbGF0aXZlVGltZSA9IGZ1bmN0aW9uIChpbml0aWFsU3RhdGUsIGNvbmRpdGlvbiwgaXRlcmF0ZSwgcmVzdWx0U2VsZWN0b3IsIHRpbWVTZWxlY3Rvciwgc2NoZWR1bGVyKSB7XHJcbiAgICAgICAgc2NoZWR1bGVyIHx8IChzY2hlZHVsZXIgPSB0aW1lb3V0U2NoZWR1bGVyKTtcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBmaXJzdCA9IHRydWUsXHJcbiAgICAgICAgICAgICAgICBoYXNSZXN1bHQgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgIHJlc3VsdCxcclxuICAgICAgICAgICAgICAgIHN0YXRlID0gaW5pdGlhbFN0YXRlLFxyXG4gICAgICAgICAgICAgICAgdGltZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZVdpdGhSZWxhdGl2ZSgwLCBmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoZmlyc3QpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZmlyc3QgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZSA9IGl0ZXJhdGUoc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBoYXNSZXN1bHQgPSBjb25kaXRpb24oc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3Ioc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aW1lID0gdGltZVNlbGVjdG9yKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzUmVzdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc2VsZih0aW1lKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFRpbWUgc2hpZnRzIHRoZSBvYnNlcnZhYmxlIHNlcXVlbmNlIGJ5IGRlbGF5aW5nIHRoZSBzdWJzY3JpcHRpb24uXHJcbiAgICAgKiAgXHJcbiAgICAgKiBAZXhhbXBsZVxyXG4gICAgICogIDEgLSByZXMgPSBzb3VyY2UuZGVsYXlTdWJzY3JpcHRpb24oNTAwMCk7IC8vIDVzXHJcbiAgICAgKiAgMiAtIHJlcyA9IHNvdXJjZS5kZWxheVN1YnNjcmlwdGlvbig1MDAwLCBSeC5TY2hlZHVsZXIudGlt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gIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIHN1YkRlbGF5ID0gc3Vic2NyaXB0aW9uRGVsYXk7XHJcbiAgICAgICAgICAgIHNlbGVjdG9yID0gZGVsYXlEdXJhdGlvblNlbGVjdG9yO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBkZWxheXMgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLCBhdEVuZCA9IGZhbHNlLCBkb25lID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGF0RW5kICYmIGRlbGF5cy5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBzdWJzY3JpcHRpb24gPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLCBzdGFydCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgZGVsYXk7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVsYXkgPSBzZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlcnJvcikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycm9yKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB2YXIgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGRlbGF5cy5hZGQoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKGRlbGF5LnN1YnNjcmliZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVsYXlzLnJlbW92ZShkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWxheXMucmVtb3ZlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGF0RW5kID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIGlmICghc3ViRGVsYXkpIHtcclxuICAgICAgICAgICAgICAgIHN0YXJ0KCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShzdWJEZWxheS5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgIC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B8fCAob3RoZXIgPSBvYnNlcnZhYmxlVGhyb3cobmV3IEVycm9yKCdUaW1lb3V0JykpKTtcclxuICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBzdWJzY3JpcHRpb24gPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLCB0aW1lciA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksIG9yaWdpbmFsID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcblxyXG4gICAgICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShvcmlnaW5hbCk7XHJcblxyXG4gICAgICAgICAgICB2YXIgaWQgPSAwLCBzd2l0Y2hlZCA9IGZhbHNlLCBzZXRUaW1lciA9IGZ1bmN0aW9uICh0aW1lb3V0KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbXlJZCA9IGlkLCB0aW1lcldpbnMgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGlkID09PSBteUlkO1xyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgICAgIHZhciBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICB0aW1lci5zZXREaXNwb3NhYmxlKGQpO1xyXG4gICAgICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKHRpbWVvdXQuc3Vic2NyaWJlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGltZXJXaW5zKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUob3RoZXIuc3Vic2NyaWJlKG9ic2VydmVyKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGQuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGltZXJXaW5zKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRpbWVyV2lucygpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKG90aGVyLnN1YnNjcmliZShvYnNlcnZlcikpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIHNldFRpbWVyKGZpcnN0VGltZW91dCk7XHJcbiAgICAgICAgICAgIHZhciBvYnNlcnZlcldpbnMgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgcmVzID0gIXN3aXRjaGVkO1xyXG4gICAgICAgICAgICAgICAgaWYgKHJlcykge1xyXG4gICAgICAgICAgICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gcmVzO1xyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgb3JpZ2luYWwuc2V0RGlzcG9zYWJsZShzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAob2JzZXJ2ZXJXaW5zKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIHRpbWVvdXQ7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGltZW91dCA9IHRpbWVvdXRkdXJhdGlvblNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBzZXRUaW1lcih0aW1lb3V0KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgIGlmIChvYnNlcnZlcldpbnMoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmIChvYnNlcnZlcldpbnMoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgcmV0dXJuIG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKHN1YnNjcmlwdGlvbiwgdGltZXIpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBJZ25vcmVzIHZhbHVlcyBmcm9tIGFuIG9ic2VydmFibGUgc2VxdWVuY2Ugd2hpY2ggYXJlIGZvbGxvd2VkIGJ5IGFub3RoZXIgdmFsdWUgd2l0aGluIGEgY29tcHV0ZWQgdGhyb3R0bGUgZHVyYXRpb24uXHJcbiAgICAgKiAgXHJcbiAgICAgKiBAZXhhbXBsZVxyXG4gICAgICog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2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB2YWx1ZSA9IHg7XHJcbiAgICAgICAgICAgICAgICBpZCsrO1xyXG4gICAgICAgICAgICAgICAgdmFyIGN1cnJlbnRpZCA9IGlkLCBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICBjYW5jZWxhYmxlLnNldERpc3Bvc2FibGUoZCk7XHJcbiAgICAgICAgICAgICAgICBkLnNldERpc3Bvc2FibGUodGhyb3R0bGUuc3Vic2NyaWJlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaGFzVmFsdWUgJiYgaWQgPT09IGN1cnJlbnRpZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIGQuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChoYXNWYWx1ZSAmJiBpZCA9PT0gY3VycmVudGlkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB9KSk7XHJcbi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XN0V2l0aFRpbWUgPSBmdW5jdGlvbiAoZHVyYXRpb24sIHNjaGVkdWxlcikge1xyXG4gICAgICAgIHNjaGVkdWxlciB8fCAoc2NoZWR1bGVyID0gdGltZW91dFNjaGVkdWxlcik7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgcSA9IFtdO1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG5vdyA9IHNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgICAgIHEucHVzaCh7IGludGVydmFsOiBub3csIHZhbHVlOiB4IH0pO1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCAmJiBub3cgLSBxWzBdLmludGVydmFsID49IGR1cmF0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKS52YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBub3cgPSBzY2hlZHVsZXIubm93KCk7XHJcbiAgICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwICYmIG5vdyAtIHFbMF0uaW50ZXJ2YWwgPj0gZHVyYXRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocS5zaGlmdCgpLnZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pO1x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0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGcuYWRkKGlubmVyU3Vic2NyaXB0aW9uKTtcclxuXHJcbiAgICAgICAgICAgIGlubmVyU3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoaW5uZXJTb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dC5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGcucmVtb3ZlKGlubmVyU3Vic2NyaXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIGhhc0N1cnJlbnQgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIGlmIChpc1N0b3BwZWQgJiYgZy5sZW5ndGggPT09IDEpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0sXHJcbiAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBpc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgaWYgKCFoYXNDdXJyZW50ICYmIGcubGVuZ3RoID09PSAxKSB7IFxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0pKTtcclxuXHJcbiAgICAgIHJldHVybiBnO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuICAvKlxyXG4gICAqIFBlcmZvcm1zIGEgZXhjbHVzaXZlIG1hcCB3YWl0aW5nIG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5zZXREaXNwb3NhYmxlKHNvdXJjZXMuc3Vic2NyaWJlKFxyXG4gICAgICAgIGZ1bmN0aW9uIChpbm5lclNvdXJjZSkge1xyXG5cclxuICAgICAgICAgIGlmICghaGFzQ3VycmVudCkge1xyXG4gICAgICAgICAgICBoYXNDdXJyZW50ID0gdHJ1ZTsgICAgICAgICAgXHJcblxyXG4gICAgICAgICAgICBpbm5lclN1YnNjcmlwdGlvbiA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBnLmFkZChpbm5lclN1YnNjcmlwdGlvbik7XHJcblxyXG4gICAgICAgICAgICBpc1Byb21pc2UoaW5uZXJTb3VyY2UpICYmIChpbm5lclNvdXJjZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShpbm5lclNvdXJjZSkpOyAgICAgIFxyXG5cclxuICAgICAgICAgICAgaW5uZXJTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShpbm5lclNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICByZXN1bHQgPSBzZWxlY3Rvci5jYWxsKHRoaXNBcmcsIHgsIGluZGV4KyssIGlubmVyU291cmNlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBnLnJlbW92ZShpbm5lclN1YnNjcmlwdGlvbik7XHJcbiAgICAgICAgICAgICAgICBoYXNDdXJyZW50ID0gZmFsc2U7XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKGlzU3RvcHBlZCAmJiBnLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9LCBcclxuICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIGlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICBpZiAoZy5sZW5ndGggPT09IDEgJiYgIWhhc0N1cnJlbnQpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9KSk7XHJcbiAgICAgIHJldHVybiBnO1xyXG4gICAgfSk7XHJcbiAgfTtcclxuICAgIC8qKiBQcm92aWRlcyBhIHNldCBvZiBleHRlbnNpb24gbWV0aG9kcyBmb3IgdmlydHVhbCB0aW1lIHNjaGVkdWxpbmcuICovXHJcbiAgICBSeC5WaXJ0dWFsVGltZVNjaGVkdWxlciA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIG5vdEltcGxlbWVudGVkKCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ05vdCBpbXBsZW1lbnRlZCcpO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gbG9jYWxOb3coKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLnRvRGF0ZVRpbWVPZ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AgICAgICAgICAgaWYgKG5leHQgIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuY29tcGFyZXIobmV4dC5kdWVUaW1lLCB0aGlzLmNsb2NrKSA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuY2xvY2sgPSBuZXh0LmR1ZVRpbWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgbmV4dC5pbnZva2UoKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmlzRW5hYmxlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gd2hpbGUgKHRoaXMuaXNFbmFibGVkKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKiBcclxuICAgICAgICAgKiBTdG9wcyB0aGUgdmlydHVhbCB0aW1lIHNjaGVkdWxlci4gIFxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIFZpcnR1YWxUaW1lU2NoZWR1bGVyUHJvdG90eXBlLnN0b3AgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRoaXMuaXNFbmFibGVkID0gZmFsc2U7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQWR2YW5jZXMgdGhlIHNjaGVkdWxlcidzIGNsb2NrIHRvIHRoZSBzcGVjaWZpZWQgdGltZSwgcnVubmluZyBhbGwgd29yayB0aWxsIHRoYXQgcG9pbnQuXHJcbiAgICAgICAgICogQHBhcmFtIHtOdW1iZXJ9IHRpbWUgQWJzb2x1dGUgdGltZSB0byBhZHZhbmNlIHRoZSBzY2hlZHVsZXIncyBjbG9jayB0by5cclxuICAgICAgICAgKi9cclxuICAgICAgICBWaXJ0dWFsVGltZVNjaGVkdWxlclByb3RvdHlwZS5hZHZhbmNlVG8gPSBmdW5jdGlvbiAodGltZSkge1xyXG4gICAgICAgICAgICB2YXIgbmV4dDtcclxuICAgICAgICAgICAgdmFyIGR1ZVRvQ2xvY2sgPSB0aGlzLmNvbXBhcmVyKHRoaXMuY2xvY2ssIHRpbWUpO1xyXG4gICAgICAgICAgICBpZiAodGhpcy5jb21wYXJlcih0aGlzLmNsb2NrLCB0aW1lKSA+IDApIHtcclxuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmIChkdWVUb0Nsb2NrID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRW5hYmxlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0VuYWJsZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgZG8ge1xyXG4gICAgICAgICAgICAgICAgICAgIG5leHQgPSB0aGlzLmdldE5leHQoKTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAobmV4dCAhPT0gbnVsbCAmJiB0aGlzLmNvbXBhcmVyKG5leHQuZHVlVGltZSwgdGltZSkgPD0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5jb21wYXJlcihuZXh0LmR1ZVRpbWUsIHRoaXMuY2xvY2spID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5jbG9jayA9IG5leHQuZHVlVGltZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBuZXh0Lmludm9rZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuaXNFbmFibGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSB3aGlsZSAodGhpcy5pc0VuYWJsZWQpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5jbG9jayA9IHRpbWU7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBBZHZhbmNlcyB0aGUgc2NoZWR1bGVyJ3MgY2xvY2sgYnkgdGhlIHNwZWNpZmllZCByZWxhdGl2ZSB0aW1lLCBydW5uaW5nIGFsbCB3b3JrIHNjaGVkdWxlZCBmb3IgdGhhdCB0aW1lc3Bhbi5cclxuICAgICAgICAgKiBAcGFyYW0ge051bWJlcn0gdGltZSBSZWxhdGl2ZSB0aW1lIHRvIGFkdmFuY2UgdGhlIHNjaGVkdWxlcidzIGNsb2NrIGJ5LlxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIFZpcnR1YWxUaW1lU2NoZWR1bGVyUHJvdG90eXBlLmFkdmFuY2VCeSA9IGZ1bmN0aW9uICh0aW1lKSB7XHJcbiAgICAgICAgICAgIHZhciBkdCA9IHRoaXMuYWRkKHRoaXMuY2xvY2ssIHRpbWUpO1xyXG4gICAgICAgICAgICB2YXIgZHVlVG9DbG9jayA9IHRoaXMuY29tcGFyZXIodGhpcy5jbG9jaywgZHQpO1xyXG4gICAgICAgICAgICBpZiAoZHVlVG9DbG9jayA+IDApIHtcclxuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmIChkdWVUb0Nsb2NrID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgdGhpcy5hZHZhbmNlVG8oZHQpO1xyXG4gICAgICAgIH07ICAgICAgICBcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICA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XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5uZXh0ID0gZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgIHZhciBub0Vycm9yID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICBub0Vycm9yID0gdHJ1ZTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkgeyBcclxuICAgICAgICAgICAgICAgIHRocm93IGU7ICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFub0Vycm9yKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUuZXJyb3IgPSBmdW5jdGlvbiAoZXhuKSB7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVyLm9uRXJyb3IoZXhuKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkgeyBcclxuICAgICAgICAgICAgICAgIHRocm93IGU7ICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUuY29tcGxldGVkID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbkNvbX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ICAgcmV0dXJuIEdyb3VwZWRPYnNlcnZhYmxlO1xyXG4gICAgfShPYnNlcnZhYmxlKSk7XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUmVwcmVzZW50cyBhbiBvYmplY3QgdGhhdCBpcyBib3RoIGFuIG9ic2VydmFibGUgc2VxdWVuY2UgYXMgd2VsbCBhcyBhbiBvYnNlcnZlci5cclxuICAgICAqICBFYWNoIG5vdGlmaWNhdGlvbiBpcyBicm9hZGNhc3RlZCB0byBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMuXHJcbiAgICAgKi9cclxuICAgIHZhciBTdWJqZWN0ID0gUnguU3ViamVjdCA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcbiAgICAgICAgZnVuY3Rpb24gc3Vic2NyaWJlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMucHVzaChvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gbmV3IElubmVyU3Vic2NyaXB0aW9uKHRoaXMsIG9ic2VydmVyKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpZiAodGhpcy5leGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IodGhpcy5leGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaW5oZXJpdHMoU3ViamVjdCwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQ3JlYXRlcyBhIHN1YmplY3QuXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICovICAgICAgXHJcbiAgICAgICAgZnVuY3Rpb24gU3ViamVjdCgpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gZmFsc2UsXHJcbiAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gZmFsc2UsXHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKFN1YmplY3QucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKiBAcmV0dXJucyB7Qm9vbGVhbn0gSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICBcclxuICAgICAgICAgICAgaGFzT2JzZXJ2ZXJzOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5vYnNlcnZlcnMubGVuZ3RoID4gMDtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBleGNlcHRpb24uXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IGVycm9yIFRoZSBleGNlcHRpb24gdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmV4Y2VwdGlvbiA9IGV4Y2VwdGlvbjtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgYXJyaXZhbCBvZiB0aGUgc3BlY2lmaWVkIGVsZW1lbnQgaW4gdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSB2YWx1ZSBUaGUgdmFsdWUgdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbk5leHQodmFsdWUpO1xyXG4gICAgICA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vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgfSBlbHNlIGlmIChodikge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHYpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpbmhlcml0cyhBc3luY1N1YmplY3QsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIENyZWF0ZXMgYSBzdWJqZWN0IHRoYXQgY2FuIG9ubHkgcmVjZWl2ZSBvbmUgdmFsdWUgYW5kIHRoYXQgdmFsdWUgaXMgY2FjaGVkIGZvciBhbGwgZnV0dXJlIG9ic2VydmF0aW9ucy5cclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKi8gXHJcbiAgICAgICAgZnVuY3Rpb24gQXN5bmNTdWJqZWN0KCkge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG5cclxuICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMudmFsdWUgPSBudWxsO1xyXG4gICAgICAgICAgICB0aGlzLmhhc1ZhbHVlID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgIHRoaXMuZXhjZXB0aW9uID0gbnVsbDtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFkZFByb3BlcnRpZXMoQXN5bmNTdWJqZWN0LnByb3RvdHlwZSwgT2JzZXJ2ZXIsIHtcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIEluZGljYXRlcyB3aGV0aGVyIHRoZSBzdWJqZWN0IGhhcyBvYnNlcnZlcnMgc3Vic2NyaWJlZCB0byBpdC5cclxuICAgICAgICAgICAgICogQHJldHVybnMge0Jvb2xlYW59IEluZGljYXRlcyB3aGV0aGVyIHRoZSBzdWJqZWN0IGhhcyBvYnNlcnZlcnMgc3Vic2NyaWJlZCB0byBpdC5cclxuICAgICAgICAgICAgICovICAgICAgICAgXHJcbiAgICAgICAgICAgIGhhc09ic2VydmVyczogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMub2JzZXJ2ZXJzLmxlbmd0aCA+IDA7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGVuZCBvZiB0aGUgc2VxdWVuY2UsIGFsc28gY2F1c2luZyB0aGUgbGFzdCByZWNlaXZlZCB2YWx1ZSB0byBiZSBzZW50IG91dCAoaWYgYW55KS5cclxuICAgICAgICAgICAgICovIFxyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG8sIGksIGxlbjtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCksXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHYgPSB0aGlzLnZhbHVlLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBodiA9IHRoaXMuaGFzVmFsdWU7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGlmIChodikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbyA9IG9zW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgby5vbk5leHQodik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZXhjZXB0aW9uLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSBlcnJvciBUaGUgZXhjZXB0aW9uIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovIFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZXhjZXB0aW9uID0gZXhjZXB0aW9uO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIFNlbmRzIGEgdmFsdWUgdG8gdGhlIHN1YmplY3QuIFRoZSBsYXN0IHZhbHVlIHJlY2VpdmVkIGJlZm9yZSBzdWNjZXNzZnVsIHRlcm1pbmF0aW9uIHdpbGwgYmUgc2VudCB0byBhbGwgc3Vic2NyaWJlZCBhbmQgZnV0dXJlIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gdmFsdWUgVGhlIHZhbHVlIHRvIHN0b3JlIGluIHRoZSBzdWJqZWN0LlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy52YWx1ZSA9IHZhbHVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaGFzVmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogVW5zdWJzY3JpYmUgYWxsIG9ic2VydmVycyBhbmQgcmVsZWFzZSByZXNvdXJjZXMuXHJcbiAgICAgICAgICAgICAqL1xyXG4gICAgICAgICAgICBkaXNwb3NlOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgdGhpcy52YWx1ZSA9IG51bGw7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9KTtcclxuXHJcbiAgICAgICAgcmV0dXJuIEFzeW5jU3ViamVjdDtcclxuICAgIH0oT2JzZXJ2YWJsZSkpO1xyXG5cclxuICAgIC8qKiBAcHJpdmF0ZSAqL1xyXG4gICAgdmFyIEFub255bW91c1N1YmplY3QgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG4gICAgICAgIGluaGVyaXRzKEFub255bW91c1N1YmplY3QsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHN1YnNjcmliZShvYnNlcnZlcikge1xyXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5vYnNlcnZhYmxlLnN1YnNjcmliZShvYnNlcnZlcik7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIGZ1bmN0aW9uIEFub255bW91c1N1YmplY3Qob2JzZXJ2ZXIsIG9ic2VydmFibGUpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlciA9IG9ic2VydmVyO1xyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmFibGUgPSBvYnNlcnZhYmxlO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgYWRkUHJvcGVydGllcyhBbm9ueW1vdXNTdWJqZWN0LnByb3RvdHlwZSwgT2JzZXJ2ZXIsIHtcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICAgICAqIEBtZW1iZXJPZiBBbm9ueW1vdXNTdWJqZWN0I1xyXG4gICAgICAgICAgICAqL1xyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgICAgICogQG1lbWJlck9mIEFub255bW91c1N1YmplY3QjXHJcbiAgICAgICAgICAgICovICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgICAgICogQG1lbWJlck9mIEFub255bW91c1N1YmplY3QjXHJcbiAgICAgICAgICAgICovICAgICAgICAgICAgXH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FycmF5LmlzQXJyYXkoYXJnc1tpZHhdKSA/XHJcbiAgICAgICAgICAgIGFyZ3NbaWR4XSA6XHJcbiAgICAgICAgICAgIHNsaWNlLmNhbGwoYXJncyk7XHJcbiAgICB9XHJcblxyXG4gICAgLyoqIFxyXG4gICAgICogQHByaXZhdGUgXHJcbiAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAqL1xyXG4gICAgZnVuY3Rpb24gT25OZXh0UHJlZGljYXRlKHByZWRpY2F0ZSkge1xyXG4gICAgICAgIHRoaXMucHJlZGljYXRlID0gcHJlZGljYXRlO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKiogXHJcbiAgICAgKiBAcHJpdmF0ZSBcclxuICAgICAqIEBtZW1iZXJPZiBPbk5leHRQcmVkaWNhdGUjXHJcbiAgICAgKi8gICAgXHJcbiAgICBPbk5leHRQcmVkaWNhdGUucHJvdG90eXBlLmVxdWFscyA9IGZ1bmN0aW9uIChvdGhlcikge1xyXG4gICAgICAgIGlmIChvdGhlciA9PT0gdGhpcykgeyByZXR1cm4gdHJ1ZTsgfVxyXG4gICAgICAgIGlmIChvdGhlciA9PSBudWxsKSB7IHJldHVybiBmYWxzZTsgfVxyXG4gICAgICAgIGlmIChvdGhlci5raW5kICE9PSAnTicpIHsgcmV0dXJuIGZhbHNlOyB9XHJcbiAgICAgICAgcmV0dXJuIHRoaXMucHJlZGljYXRlKG90aGVyLnZhbHVlKTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqIFxyXG4gICAgICogQHByaXZhdGUgXHJcbiAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAqL1xyXG4gICAgZnVuY3Rpb24gT25FcnJvclByZWRpY2F0ZShwcmVkaWNhdGUpIHtcclxuICAgICAgICB0aGlzLnByZWRpY2F0ZSA9IHByZWRpY2F0ZTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqIFxyXG4gICAgICogQHByaXZhdGUgXHJcbiAgICAgKiBAbWVtYmVyT2YgT25FcnJvclByZWRp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aW9uc1tpbmRleF0uc3Vic2NyaWJlLCBvYnNlcnZhYmxlLnNjaGVkdWxlci5jbG9jayk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaW5oZXJpdHMoSG90T2JzZXJ2YWJsZSwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBIb3RPYnNlcnZhYmxlKHNjaGVkdWxlciwgbWVzc2FnZXMpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICAgICAgdmFyIG1lc3NhZ2UsIG5vdGlmaWNhdGlvbiwgb2JzZXJ2YWJsZSA9IHRoaXM7XHJcbiAgICAgICAgICAgIHRoaXMuc2NoZWR1bGVyID0gc2NoZWR1bGVyO1xyXG4gICAgICAgICAgICB0aGlzLm1lc3NhZ2VzID0gbWVzc2FnZXM7XHJcbiAgICAgICAgICAgIHRoaXMuc3Vic2NyaXB0aW9ucyA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gdGhpcy5tZXNzYWdlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgbWVzc2FnZSA9IHRoaXMubWVzc2FnZXNbaV07XHJcbiAgICAgICAgICAgICAgICBub3RpZmljYXRpb24gPSBtZXNzYWdlLnZhbHVlO1xyXG4gICAgICAgICAgICAgICAgKGZ1bmN0aW9uIChpbm5lck5vdGlmaWNhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIHNjaGVkdWxlci5zY2hlZHVsZUFic29sdXRlV2l0aFN0YXRlKG51bGwsIG1lc3NhZ2UudGltZSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgb2JzID0gb2JzZXJ2YWJsZS5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBqID0gMCwgakxlbiA9IG9icy5sZW5ndGg7IGogPCBqTGVuOyBqKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyTm90aWZpY2F0aW9uLmFjY2VwdChvYnNbal0pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgICAgICB9KShub3RpZmljYXRpb24pO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICByZXR1cm4gSG90T2JzZXJ2YWJsZTtcclxuICAgIH0pKE9ic2VydmFibGUpO1xyXG5cclxuICAgIC8qKiBAcHJpdmF0ZSAqL1xyXG4gICAgdmFyIENvbGRPYnNlcnZhYmxlID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc3Vic2NyaWJlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBtZXNzYWdlLCBub3RpZmljYXRpb24sIG9ic2VydmFibGUgPSB0aGlzO1xyXG4gICAgICAgICAgICB0aGlzLnN1YnNjcmlwdGlvbnMucHVzaChuZXcgU3Vic2NyaXB0aW9uKHRoaXMuc2NoZWR1bGVyLmNsb2NrKSk7XHJcbiAgICAgICAgICAgIHZhciBpbmRleCA9IHRoaXMuc3Vic2NyaXB0aW9ucy5sZW5ndGggLSAxO1xyXG4gICAgICAgICAgICB2YXIgZCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSB0aGlzLm1lc3NhZ2VzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBtZXNzYWdlID0gdGhpcy5tZXNzYWdlc1tpXTtcclxuICAgICAgICAgICAgICAgIG5vdGlmaWNhdGlvbiA9IG1lc3NhZ2UudmFsdWU7XHJcbiAgICAgICAgICAgICAgICAoZnVuY3Rpb24gKGlubmVyTm90aWZpY2F0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZC5hZGQob2JzZXJ2YWJsZS5zY2hlZHVsZXIuc2NoZWR1bGVSZWxhdGl2ZVdpdGhTdGF0ZShudWxsLCBtZXNzYWdlLnRpbWUsIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJOb3RpZmljYXRpb24uYWNjZXB0KG9ic2VydmVyKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9KShub3RpZmljYXRpb24pO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmFibGUuc3Vic2NyaXB0aW9uc1tpbmRleF0gPSBuZXcgU3Vic2NyaXB0aW9uKG9ic2VydmFibGUuc3Vic2NyaXB0aW9uc1tpbmRleF0uc3Vic2NyaWJlLCBvYnNlcnZhYmxlLnNjaGVkdWxlci5jbG9jayk7XHJcbiAgICAgICAgICAgICAgICBkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpbmhlcml0cyhDb2xkT2JzZXJ2YWJsZSwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuIC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J1ZmZlcixfX2FyZ3VtZW50MCxfX2FyZ3VtZW50MSxfX2FyZ3VtZW50MixfX2FyZ3VtZW50MyxfX2ZpbGVuYW1lLF9fZGlybmFtZSl7XG52YXIgUng7XG5cblJ4ID0gcmVxdWlyZSgncngnKTtcblxubW9kdWxlLmV4cG9ydHMgPSB7XG4gIFwiYW1iXCI6IHtcbiAgICBcImZ1bmN0aW9uXCI6IFJ4Lk9ic2VydmFibGUuYW1iLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDEwLFxuICAgICAgICAgIGQ6IDIwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyMCxcbiAgICAgICAgICBkOiA0MFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzAsXG4gICAgICAgICAgZDogNjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQ1LFxuICAgICAgICAgIGQ6IDgwXG4gICAgICAgIH1cbiAgICAgIF0sIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNjgsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogOTAsXG4gICAgICAgICAgZDogM1xuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAyLFxuICAgICAgICAgIGQ6IDBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDc2LFxuICAgICAgICAgIGQ6IDBcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF1cbiAgfSxcbiAgXCJjb25jYXRcIjoge1xuICAgIFwiZnVuY3Rpb25cIjogUnguT2JzZXJ2YWJsZS5jb25jYXQsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxNSxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA1MCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH1cbiAgICAgIF0sIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDEzLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDMwLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF1cbiAgfSxcbiAgXCJtZXJnZVwiOiB7XG4gICAgXCJmdW5jdGlvblwiOiBSeC5PYnNlcnZhYmxlLm1lcmdlLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDAsXG4gICAgICAgICAgZDogMjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDQwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiA2MFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDUsXG4gICAgICAgICAgZDogODBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDYwLFxuICAgICAgICAgIGQ6IDEwMFxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAzNyxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2OCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdXG4gIH1cbn07XG5cbn0pLmNhbGwodGhpcyxyZXF1aXJlKFwib01mcEFuXCIpLHR5cGVvZiBzZWxmICE9PSBcInVuZGVmaW5lZFwiID8gc2VsZiA6IHR5cGVvZiB3aW5kb3cgIT09IFwidW5kZWZpbmVkXCIgPyB3aW5kb3cgOiB7fSxyZXF1aXJlKFwiYnVmZmVyXCIpLkJ1Z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lLFxuICAgICAgICAgICAgICAgIHByZXZpb3VzID8gcHJldmlvdXNbcHJvcE5hbWVdIDogdW5kZWZpbmVkKVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKGlzT2JqZWN0KHByb3BWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICBwYXRjaE9iamVjdChub2RlLCBwcm9wcywgcHJldmlvdXMsIHByb3BOYW1lLCBwcm9wVmFsdWUpO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChwcm9wVmFsdWUgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIG5vZGVbcHJvcE5hbWVdID0gcHJvcFZhbHVlXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbmZ1bmN0aW9uIHJlbW92ZVByb3BlcnR5KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUpIHtcbiAgICBpZiAocHJldmlvdXMpIHtcbiAgICAgICAgdmFyIHByZXZpb3VzVmFsdWUgPSBwcmV2aW91c1twcm9wTmFtZV1cblxuICAgICAgICBpZiAoIWlzSG9vayhwcmV2aW91c1ZhbHVlKSkge1xuICAgICAgICAgICAgaWYgKHByb3BOYW1lID09PSBcImF0dHJpYnV0ZXNcIikge1xuICAgICAgICAgICAgICAgIGZvciAodmFyIGF0dHJOYW1lIGluIHByZXZpb3VzVmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgbm9kZS5yZW1vdmVBdHRyaWJ1dGUoYXR0ck5hbWUpXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmIChwcm9wTmFtZSA9PT0gXCJzdHlsZVwiKSB7XG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaSBpbiBwcmV2aW91c1ZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgIG5vZGUuc3R5bGVbaV0gPSBcIlwiXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmICh0eXB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vZGUsIHRyZWUsIGluZGljZXMsIG5vZGVzLCAwKVxuICAgIH1cbn1cblxuZnVuY3Rpb24gcmVjdXJzZShyb290Tm9kZSwgdHJlZSwgaW5kaWNlcywgbm9kZXMsIHJvb3RJbmRleCkge1xuICAgIG5vZGVzID0gbm9kZXMgfHwge31cblxuXG4gICAgaWYgKHJvb3ROb2RlKSB7XG4gICAgICAgIGlmIChpbmRleEluUmFuZ2UoaW5kaWNlcywgcm9vdEluZGV4LCByb290SW5kZXgpKSB7XG4gICAgICAgICAgICBub2Rlc1tyb290SW5kZXhdID0gcm9vdE5vZGVcbiAgICAgICAgfVxuXG4gICAgICAgIHZhciB2Q2hpbGRyZW4gPSB0cmVlLmNoaWxkcmVuXG5cbiAgICAgICAgaWYgKHZDaGlsZHJlbikge1xuXG4gICAgICAgICAgICB2YXIgY2hpbGROb2RlcyA9IHJvb3ROb2RlLmNoaWxkTm9kZXNcblxuICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCB0cmVlLmNoaWxkcmVuLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICAgICAgcm9vdEluZGV4ICs9IDFcblxuICAgICAgICAgICAgICAgIHZhciB2Q2hpbGQgPSB2Q2hpbGRyZW5baV0gfHwgbm9DaGlsZFxuICAgICAgICAgICAgICAgIHZhciBuZXh0SW5kZXggPSByb290SW5kZXggKyAodkNoaWxkLmNvdW50IHx8IDApXG5cbiAgICAgICAgICAgICAgICAvLyBza2lwIHJlY3Vyc2lvbiBkb3duIHRoZSB0cmVlIGlmIHRoZXJlIGFyZSBubyBub2RlcyBkb3duIGhlcmVcbiAgICAgICAgICAgICAgICBpZiAoaW5kZXhJblJhbmdlKGluZGljZXMsIHJvb3RJbmRleCwgbmV4dEluZGV4KSkge1xuICAgICAgICAgICAgICAgICAgICByZWN1cnNlKGNoaWxkTm9kZXNbaV0sIHZDaGlsZCwgaW5kaWNlcywgbm9kZXMsIHJvb3RJbmRleClcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICByb290SW5kZXggPSBuZXh0SW5kZXhcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiBub2Rlc1xufVxuXG4vLyBCaW5hcnkgc2VhcmNoIGZvciBhbiBpbmRleCBpbiB0aGUgaW50ZXJ2YWwgW2xlZnQsIHJpZ2h0XVxuZnVuY3Rpb24gaW5kZXhJblJhbmdlKGluZGljZXMsIGxlZnQsIHJpZ2h0KSB7XG4gICAgaWYgKGluZGljZXMubGVuZ3RoID09PSAwKSB7XG4gICAgICAgIHJldHVybiBmYWxzZVxuICAgIH1cblxuICAgIHZhciBtaW5JbmRleCA9IDBcbiAgICB2YXIgbWF4SW5kZXggPSBpbmRpY2VzLmxlbmd0aCAtIDFcbiAgICB2YXIgY3VycmVudEluZGV4XG4gICAgdmFyIGN1cnJlbnRJdGVtXG5cbiAgICB3aGlsZSAobWluSW5kZXggPD0gbWF4SW5kZXgpIHtcbiAgICAgICAgY3VycmVudEluZGV4ID0gKChtYXhJbmRleCArIG1pbkluZGV4KSAvIDIpID4+IDBcbiAgICAgICAgY3VycmVudEl0ZW0gPSBpbmRpY2VzW2N1cnJlbnRJbmRleF1cblxuICAgICAgICBpZiAobWluSW5kZXggPT09IG1heEluZGV4KSB7XG4gICAgICAgICAgICByZXR1cm4gY3VycmVudEl0ZW0gPj0gbGVmdCAmJiBjdXJyZW50SXRlbSA8PSByaWdodFxuICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRJdGVtIDwgbGVmdCkge1xuICAgICAgICAgICAgbWluSW5kZXggPSBjdXJyZW50SW5kZXggKyAxXG4gICAgICAgIH0gZWxzZSAgaWYgKGN1cnJlbnRJdGVtID4gcmlnaHQpIHtcbiAgICAgICAgICAgIG1heEluZGV4ID0gY3VycmVudEluZGV4IC0gMVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHRydWVcbiAgICAgICAgfVxuICAgIH1cblxuICA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tcbiAgICAgICAgbW92ZSA9IGJJbmRleFtpXVxuICAgICAgICBpZiAobW92ZSAhPT0gdW5kZWZpbmVkICYmIG1vdmUgIT09IGkpIHtcbiAgICAgICAgICAgIC8vIHRoZSBlbGVtZW50IGN1cnJlbnRseSBhdCB0aGlzIGluZGV4IHdpbGwgYmUgbW92ZWQgbGF0ZXIgc28gaW5jcmVhc2UgdGhlIGluc2VydCBvZmZzZXRcbiAgICAgICAgICAgIGlmIChyZXZlcnNlSW5kZXhbaV0gPiBpKSB7XG4gICAgICAgICAgICAgICAgaW5zZXJ0T2Zmc2V0KytcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgbm9kZSA9IGNoaWxkcmVuW21vdmVdXG4gICAgICAgICAgICBpbnNlcnROb2RlID0gY2hpbGROb2Rlc1tpICsgaW5zZXJ0T2Zmc2V0XVxuICAgICAgICAgICAgaWYgKG5vZGUgIT09IGluc2VydE5vZGUpIHtcbiAgICAgICAgICAgICAgICBkb21Ob2RlLmluc2VydEJlZm9yZShub2RlLCBpbnNlcnROb2RlKVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyB0aGUgbW92ZWQgZWxlbWVudCBjYW1lIGZyb20gdGhlIGZyb250IG9mIHRoZSBhcnJheSBzbyByZWR1Y2UgdGhlIGluc2VydCBvZmZzZXRcbiAgICAgICAgICAgIGlmIChtb3ZlIDwgaSkge1xuICAgICAgICAgICAgICAgIGluc2VydE9mZnNldC0tXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICAvLyBlbGVtZW50IGF0IHRoaXMgaW5kZXggaXMgc2NoZWR1bGVkIHRvIGJlIHJlbW92ZWQgc28gaW5jcmVhc2UgaW5zZXJ0IG9mZnNldFxuICAgICAgICBpZiAoaSBpbiBiSW5kZXgucmVtb3Zlcykge1xuICAgICAgICAgICAgaW5zZXJ0T2Zmc2V0KytcbiAgICAgICAgfVxuICAgIH1cbn1cblxuZnVuY3Rpb24gcmVwbGFjZVJvb3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wYXRjaCwgaW5kZXgpIHtcbiAgICBpZiAoYSA9PT0gYikge1xuICAgICAgICBpZiAoaXNUaHVuayhhKSB8fCBpc1RodW5rKGIpKSB7XG4gICAgICAgICAgICB0aHVua3MoYSwgYiwgcGF0Y2gsIGluZGV4KVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaG9va3MoYiwgcGF0Y2gsIGluZGV4KVxuICAgICAgICB9XG4gICAgICAgIHJldHVyblxuICAgIH1cblxuICAgIHZhciBhcHBseSA9IHBhdGNoW2luZGV4XVxuXG4gICAgaWYgKGIgPT0gbnVsbCkge1xuICAgICAgICBhcHBseSA9IGFwcGVuZFBhdGNoKGFwcGx5LCBuZXcgVlBhdGNoKFZQYXRjaC5SRU1PVkUsIGEsIGIpKVxuICAgICAgICBkZXN0cm95V2lkZ2V0cyhhLCBwYXRjaCwgaW5kZXgpXG4gICAgfSBlbHNlIGlmIChpc1RodW5rKGEpIHx8IGlzVGh1bmsoYikpIHtcbiAgICAgICAgdGh1bmtzKGEsIGIsIHBhdGNoLCBpbmRleClcbiAgICB9IGVsc2UgaWYgKGlzVk5vZGUoYikpIHtcbiAgICAgICAgaWYgKGlzVk5vZGUoYSkpIHtcbiAgICAgICAgICAgIGlmIChhLnRhZ05hbWUgPT09IGIudGFnTmFtZSAmJlxuICAgICAgICAgICAgICAgIGEubmFtZXNwYWNlID09PSBiLm5hbWVzcGFjZSAmJlxuICAgICAgICAgICAgICAgIGEua2V5ID09PSBiLmtleSkge1xuICAgICAgICAgICAgICAgIHZhciBwcm9wc1BhdGNoID0gZGlmZlByb3BzKGEucHJvcGVydGllcywgYi5wcm9wZXJ0aWVzLCBiLmhvb2tzKVxuICAgICAgICAgICAgICAgIGlmIChwcm9wc1BhdGNoKSB7XG4gICAgICAgICAgICAgICAgICAgIGFwcGx5ID0gYXBwZW5kUGF0Y2goYXBwbHksXG4gICAgICAgICAgICAgICAgICAgICAgICBuZXcgVlBhdGNoKFZQYXRjaC5QUk9QUywgYS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gICAgZGVzdHJveVdpZGdldHMoYSwgcGF0Y2gsIGluZGV4KVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgaWYgKGFwcGx5KSB7XG4gICAgICAgIHBhdGNoW2luZGV4XSA9IGFwcGx5XG4gICAgfVxufVxuXG5mdW5jdGlvbiBkaWZmUHJvcHMoYSwgYiwgaG9va3MpIHtcbiAgICB2YXIgZGlmZlxuXG4gICAgZm9yICh2YXIgYUtleSBpbiBhKSB7XG4gICAgICAgIGlmICghKGFLZXkgaW4gYikpIHtcbiAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICBkaWZmW2FLZXldID0gdW5kZWZpbmVkXG4gICAgICAgIH1cblxuICAgICAgICB2YXIgYVZhbHVlID0gYVthS2V5XVxuICAgICAgICB2YXIgYlZhbHVlID0gYlthS2V5XVxuXG4gICAgICAgIGlmIChob29rcyAmJiBhS2V5IGluIGhvb2tzKSB7XG4gICAgICAgICAgICBkaWZmID0gZGlmZiB8fCB7fVxuICAgICAgICAgICAgZGlmZlthS2V5XSA9IGJWYWx1ZVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKGlzT2JqZWN0KGFWYWx1ZSkgJiYgaXNPYmplY3QoYlZhbHVlKSkge1xuICAgICAgICAgICAgICAgIGlmIChnZXRQcm90b3R5cGUoYlZhbHVlKSAhPT0gZ2V0UHJvdG90eXBlKGFWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgICAgICAgICAgZGlmZlthS2V5XSA9IGJWYWx1ZVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBvYmplY3REaWZmID0gZGlmZlByb3BzKGFWYWx1ZSwgYlZhbHVlKVxuICAgICAgICAgICAgICAgICAgICBpZiAob2JqZWN0RGlmZikge1xuICAgICAgICAgICAgICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgICAgICAgICAgICAgIGRpZmZbYUtleV0gPSBvYmplY3REaWZmXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGFWYWx1ZSAhPT0gYlZhbHVlKSB7XG4gICAgICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgICAgICBkaWZmW2FLZXldID0gYlZhbHVlXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBmb3IgKHZhciBiS2V5IGluIGIpIHtcbiAgICAgICAgaWYgKCEoYktleSBpbiBhKSkge1xuICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgIGRpZmZbYktleV0gPSBiW2JLZXldXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gZGlmZlxufVxuXG5mdW5jdGlvbiBnZXRQcm90b3R5cGUodmFsdWUpIHtcbiAgICBpZiAoT2JqZWN0LmdldFByb3RvdHlwZU9mKSB7XG4gICAgICAgIHJldHVybiBPYmplY3QuZ2V0UHJvdG90eXBlT2YodmFsdWUpXG4gICAgfSBlbHNlIGlmICh2YWx1ZS5fX3Byb3RvX18pIHtcbiAgICAgICAgcmV0dXJuIHZhbHVlLl9fcHJvdG9fX1xuICAgIH0gZWxzZSBpZiAodmFsdWUuY29uc3RydWN0b3IpIHtcbiAgICAgICAgcmV0dXJuIHZhbHVlLmNvbnN0cnVjdG9yLnByb3RvdHlwZVxuICAgIH1cbn1cblxuZnVuY3Rpb24gZGlmZkNoaWxkcmVuKGEsIGIsIHBhdGNoLCBhcHBseSwgaW5kZXgpIHtcbiAgICB2YXIgYUNoaWxkcmVuID0gYS5jaGlsZHJlblxuICAgIHZhciBiQ2hpbGRyZW4gPSByZW9yZGVyKGFDaGlsZHJlbiwgYi5jaGlsZHJlbilcblxuICAgIHZhciBhTGVuID0gYUNoaWxkcmVuLmxl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KHZOb2RlLmRlc2NlbmRhbnRIb29rcykge1xuICAgICAgICAgICAgdmFyIGNoaWxkcmVuID0gdk5vZGUuY2hpbGRyZW5cbiAgICAgICAgICAgIHZhciBsZW4gPSBjaGlsZHJlbi5sZW5ndGhcbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHtcbiAgICAgICAgICAgICAgICB2YXIgY2hpbGQgPSBjaGlsZHJlbltpXVxuICAgICAgICAgICAgICAgIGluZGV4ICs9IDFcblxuICAgICAgICAgICAgICAgIGhvb2tzKGNoaWxkLCBwYXRjaCwgaW5kZXgpXG5cbiAgICAgICAgICAgICAgICBpZiAoaXNWTm9kZShjaGlsZCkgJiYgY2hpbGQuY291bnQpIHtcbiAgICAgICAgICAgICAgICAgICAgaW5kZXggKz0gY2hpbGQuY291bnRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbi8vIExpc3QgZGlmZiwgbmFpdmUgbGVmdCB0byByaWdodCByZW9yZGVyaW5nXG5mdW5jdGlvbiByZW9yZGVyKGFDaGlsZHJlbiwgYkNoaWxkcmVuKSB7XG5cbiAgICB2YXIgYktleXMgPSBrZXlJbmRleChiQ2hpbGRyZW4pXG5cbiAgICBpZiAoIWJLZXlzKSB7XG4gICAgICAgIHJldHVybiBiQ2hpbGRyZW5cbiAgICB9XG5cbiAgICB2YXIgYUtleXMgPSBrZXlJbmRleChhQ2hpbGRyZW4pXG5cbiAgICBpZiAoIWFLZXlzKSB7XG4gICAgICAgIHJldHVybiBiQ2hpbGRyZW5cbiAgICB9XG5cbiAgICB2YXIgYk1hdGNoID0ge30sIGFNYXRjaCA9IHt9XG5cbiAgICBmb3IgKHZhciBrZXkgaW4gYktleXMpIHtcbiAgICAgICAgYk1hdGNoW2JLZXlzW2tleV1dID0gYUtleXNba2V5XVxuICAgIH1cblxuICAgIGZvciAodmFyIGtleSBpbiBhS2V5cykge1xuICAgICAg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W92ZXMgPSB0cnVlXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB3aGlsZSAoYk1hdGNoW2ZyZWVJbmRleF0gIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIGZyZWVJbmRleCsrXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChmcmVlSW5kZXggPCBsZW4pIHtcbiAgICAgICAgICAgICAgICB2YXIgZnJlZUNoaWxkID0gYkNoaWxkcmVuW2ZyZWVJbmRleF1cbiAgICAgICAgICAgICAgICBpZiAoZnJlZUNoaWxkKSB7XG4gICAgICAgICAgICAgICAgICAgIHNodWZmbGVbaV0gPSBmcmVlQ2hpbGRcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZyZWVJbmRleCAhPT0gbW92ZUluZGV4KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBoYXNNb3ZlcyA9IHRydWVcbiAgICAgICAgICAgICAgICAgICAgICAgIG1vdmVzW2ZyZWVJbmRleF0gPSBtb3ZlSW5kZXhcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldmVyc2VbbW92ZUluZGV4XSA9IGZyZWVJbmRleFxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIG1vdmVJbmRleCsrXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZyZWVJbmRleCsrXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaSsrXG4gICAgfVxuXG4gICAgaWYgKGhhc01vdmVzKSB7XG4gICAgICAgIHNodWZmbGUubW92ZXMgPSBtb3Zlc1xuICAgIH1cblxuICAgIHJldHVybiBzaHVmZmxlXG59XG5cbmZ1bmN0aW9uIGtleUluZGV4KGNoaWxkcmVuKSB7XG4gICAgdmFyIGksIGtleXNcblxuICAgIGZvciAoaSA9IDA7IGkgPCBjaGlsZHJlbi5sZW5ndGg7IGkrKykge1xuICAgICAgICB2YXIgY2hpbGQgPSBjaGlsZHJlblt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dmFyIGhvb2tzXG5cbiAgICBmb3IgKHZhciBwcm9wTmFtZSBpbiBwcm9wZXJ0aWVzKSB7XG4gICAgICAgIGlmIChwcm9wZXJ0aWVzLmhhc093blByb3BlcnR5KHByb3BOYW1lKSkge1xuICAgICAgICAgICAgdmFyIHByb3BlcnR5ID0gcHJvcGVydGllc1twcm9wTmFtZV1cbiAgICAgICAgICAgIGlmIChpc1ZIb29rKHByb3BlcnR5KSkge1xuICAgICAgICAgICAgICAgIGlmICghaG9va3MpIHtcbiAgICAgICAgICAgICAgICAgICAgaG9va3MgPSB7fVxuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGhvb2tzW3Byb3BOYW1lXSA9IHByb3BlcnR5XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGNvdW50OyBpKyspIHtcbiAgICAgICAgdmFyIGNoaWxkID0gY2hpbGRyZW5baV1cbiAgICAgICAgaWYgKGlzVk5vZGUoY2hpbGQpKSB7XG4gICAgICAgICAgICBkZXNjZW5kYW50cyArPSBjaGlsZC5jb3VudCB8fCAwXG5cbiAgICAgICAgICAgIGlmICghaGFzV2lkZ2V0cyAmJiBjaGlsZC5oYXNXaWRnZXRzKSB7XG4gICAgICAgICAgICAgICAgaGFzV2lkZ2V0cyA9IHRydWVcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKCFkZXNjZW5kYW50SG9va3MgJiYgKGNoaWxkLmhvb2tzIHx8IGNoaWxkLmRlc2NlbmRhbnRIb29rcykpIHtcbiAgICAgICAgICAgICAgICBkZXNjZW5kYW50SG9va3MgPSB0cnVlXG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSBpZiAoIWhhc1dpZGdldHMgJiYgaXNXaWRnZXQoY2hpbGQpKSB7XG4gICAgICAgICAgICBpZiAodHlwZW9mIGNoaWxkLmRlc3Ryb3kgPT09IFwiZnVuY3Rpb25cIikge1xuIC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hpbGRyZW4gJiYgaXNDaGlsZHJlbihwcm9wZXJ0aWVzKSkge1xuICAgICAgICBjaGlsZHJlbiA9IHByb3BlcnRpZXNcbiAgICAgICAgcHJvcGVydGllcyA9IHt9XG4gICAgfVxuXG4gICAgcHJvcGVydGllcyA9IHByb3BlcnRpZXMgfHwge31cblxuICAgIC8vIHNldCBuYW1lc3BhY2UgZm9yIHN2Z1xuICAgIHByb3BlcnRpZXMubmFtZXNwYWNlID0gU1ZHX05BTUVTUEFDRVxuXG4gICAgLy8gZm9yIGVhY2gga2V5LCBpZiBhdHRyaWJ1dGUgJiBzdHJpbmcsIGJvb2wgb3IgbnVtYmVyIHRoZW5cbiAgICAvLyBjb252ZXJ0IGl0IGludG8gYSBzZXRBdHRyaWJ1dGUgaG9va1xuICAgIGZvciAodmFyIGtleSBpbiBwcm9wZXJ0aWVzKSB7XG4gICAgICAgIGlmICghcHJvcGVydGllcy5oYXNPd25Qcm9wZXJ0eShrZXkpKSB7XG4gICAgICAgICAgICBjb250aW51ZVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKEJMQUNLTElTVEVEX0tFWVNba2V5XSkge1xuICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgfVxuXG4gICAgICAgIHZhciB2YWx1ZSA9IHByb3BlcnRpZXNba2V5XVxuICAgICAgICBpZiAodHlwZW9mIHZhbHVlICE9PSBcInN0cmluZ1wiICYmXG4gICAgICAgICAgICB0eXBlb2YgdmFsdWUgIT09IFwibnVtYmVyXCIgJiZcbiAgICAgICAgICAgIHR5cGVvZiB2YWx1ZSAhPT0gXCJib29sZWFuXCJcbiAgICAgICAgKSB7XG4gICAgICAgICAgICBjb250aW51ZVxuICAgICAgICB9XG5cbiAgICAgICAgcHJvcGVydGllc1trZXldID0gYXR0cmlidXRlSG9vayh2YWx1ZSlcbiAgICB9XG5cbiAgICByZXR1cm4gaCh0YWdOYW1lLCBwcm9wZXJ0aWVzLCBjaGlsZHJlbilcbn1cblxuZnVuY3Rpb24ga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kb3cuc2V0SW1tZWRpYXRlO1xuICAgIHZhciBjYW5Qb3N0ID0gdHlwZW9mIHdpbmRvdyAhPT0gJ3VuZGVmaW5lZCdcbiAgICAmJiB3aW5kb3cucG9zdE1lc3NhZ2UgJiYgd2luZG93LmFkZEV2ZW50TGlzdGVuZXJcbiAgICA7XG5cbiAgICBpZiAoY2FuU2V0SW1tZWRpYXRlKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbiAoZikgeyByZXR1cm4gd2luZG93LnNldEltbWVkaWF0ZShmKSB9O1xuICAgIH1cblxuICAgIGlmIChjYW5Qb3N0KSB7XG4gICAgICAgIHZhciBxdWV1ZSA9IFtdO1xuICAgICAgICB3aW5kb3cuYWRkRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsIGZ1bmN0aW9uIChldikge1xuICAgICAgICAgICAgdmFyIHNvdXJjZSA9IGV2LnNvdXJjZTtcbiAgICAgICAgICAgIGlmICgoc291cmNlID09PSB3aW5kb3cgfHwgc291cmNlID09PSBudWxsKSAmJiBldi5kYXRhID09PSAncHJvY2Vzcy10aWNrJykge1xuICAgICAgICAgICAgICAgIGV2LnN0b3BQcm9wYWdhdGlvbigpO1xuICAgICAgICAgICAgICAgIGlmIChxdWV1ZS5sZW5ndGggPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBmbiA9IHF1ZXVlLnNoaWZ0KCk7XG4gICAgICAgICAgICAgICAgICAgIGZuKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9LCB0cnVlKTtcblxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gbmV4dFRpY2soZm4pIHtcbiAgICAgICAgICAgIHF1ZXVlLnB1c2goZm4pO1xuICAgICAgICAgICAgd2luZG93LnBvc3RNZXNzYWdlKCdwcm9jZXNzLXRpY2snLCAnKicpO1xuICAgICAgICB9O1xuICAgIH1cblxuICAgIHJldHVybiBmdW5jdGlvbiBuZXh0VGljayhmbikge1xuICAgICAg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cyA9IHYuc3Vic3RyaW5nKDEsdi5sZW5ndGgpXG4gICAgICAgICAgaWYoIXYpIHJldHVyblxuICAgICAgICAgIGlmKCFlKVxuICAgICAgICAgICAgZSA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQodilcbiAgICAgICAgICBlbHNlIGlmICh2WzBdID09PSAnLicpXG4gICAgICAgICAgICBDbGFzc0xpc3QoZSkuYWRkKHMpXG4gICAgICAgICAgZWxzZSBpZiAodlswXSA9PT0gJyMnKVxuICAgICAgICAgICAgZS5zZXRBdHRyaWJ1dGUoJ2lkJywgcylcbiAgICAgICAgfSlcbiAgICAgIH1cblxuICAgICAgaWYobCA9PSBudWxsKVxuICAgICAgICA7XG4gICAgICBlbHNlIGlmKCdzdHJpbmcnID09PSB0eXBlb2YgbCkge1xuICAgICAgICBpZighZSlcbiAgICAgICAgICBwYXJzZUNsYXNzKGwpXG4gICAgICAgIGVsc2VcbiAgICAgICAgICBlLmFwcGVuZENoaWxkKHIgPSBkb2N1bWVudC5jcmVhdGVUZXh0Tm9kZShsKSlcbiAgICAgIH1cbiAgICAgIGVsc2UgaWYoJ251bWJlcicgPT09IHR5cGVvZiBsXG4gICAgICAgIHx8ICdib29sZWFuJyA9PT0gdHlwZW9mIGxcbiAgICAgICAgfHwgbCBpbnN0YW5jZW9mIERhdGVcbiAgICAgICAgfHwgbCBpbnN0YW5jZW9mIFJlZ0V4cCApIHtcbiAgICAgICAgICBlLmFwcGVuZENoaWxkKHIgPSBkb2N1bWVudC5jcmVhdGVUZXh0Tm9kZShsLnRvU3RyaW5nKCkpKVxuICAgICAgfVxuICAgICAgLy90aGVyZSBtaWdodCBiZSBhIGJldHRlciB3YXkgdG8gaGFuZGxlIHRoaXMuLi5cbiAgICAgIGVsc2UgaWYgKGlzQXJyYXkobCkpXG4gICAgICAgIGZvckVhY2gobCwgaXRlbSlcbiAgICAgIGVsc2UgaWYoaXNOb2RlKGwpKVxuICAgICAgICBlLmFwcGVuZENoaWxkKHIgPSBsKVxuICAgICAgZWxzZSBpZihsIGluc3RhbmNlb2YgVGV4dClcbiAgICAgICAgZS5hcHBlbmRDaGlsZChyID0gbClcbiAgICAgIGVsc2UgaWYgKCdvYmplY3QnID09PSB0eXBlb2YgbCkge1xuICAgICAgICBmb3IgKHZhciBrIGluIGwpIHtcbiAgICAgICAgICBpZignZnVuY3Rpb24nID09PSB0eXBlb2YgbFtrXSkge1xuICAgICAgICAgICAgaWYoL15vblxcdysvLnRlc3QoaykpIHtcbiAgICAgICAgICAgICAgaWYgKGUuYWRkRXZlbnRMaXN0ZW5lcil7XG4gICAgICAgICAgICAgICAgZS5hZGRFdmVudExpc3RlbmVyKGsuc3Vic3RyaW5nKDIpLCBsW2tdLCBmYWxzZSlcbiAgICAgICAgICAgICAgICBjbGVhbnVwRnVuY3MucHVzaChmdW5jdGlvbigpe1xuICAgICAgICAgICAgICAgICAgZS5yZW1vdmVFdmVudExpc3RlbmVyKGsuc3Vic3RyaW5nKDIpLCBsW2tdLCBmYWxzZSlcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICB9ZWxzZXtcbiAgICAgICAgICAgICAgICBlLmF0dGFjaEV2ZW50KGssIGxba10pXG4gICAgICAgICAgICAgICAgY2xlYW51cEZ1bmNzLnB1c2goZnVuY3Rpb24oKXtcbiAgICAgICAgICAgICAgICAgIGUuZGV0YWNoRXZlbnQoaywgbFtrXSlcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAvLyBvYnNlcnZhYmxlXG4gICAgICAgICAgICAgIGVba10gPSBsW2tdKClcbiAgICAgICAgICAgICAgY2xlYW51cEZ1bmNzLnB1c2gobFtrXShmdW5jdGlvbiAodikge1xuICAgICAgICAgICAgICAgIGVba10gPSB2XG4gICAgICAgICAgICAgIH0pKVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBlbHNlIGlmKGsgPT09ICdzdHlsZScpIHtcbiAgICAgICAgICAgIGlmKCdzdHJpbmcnID09PSB0eXBlb2YgbFtrXSkge1xuICAgICAgICAgICAgICBlLnN0eWxlLmNzc1RleHQgPSBsW2tdXG4gICAgICAgICAgICB9ZWxzZXtcbiAgICAgICAgICAgICAgZm9yICh2YXIgcyBpbiBsW2tdKSAoZnVuY3Rpb24ocywgdikge1xuICAgICAgICAgICAgICAgIGlmKCdmdW5jdGlvbicgPT09IHR5cGVvZiB2KSB7XG4gICAgICAgICAgICAgICAgICAvLyBvYnNlcnZhYmxlXG4gICAgICAgICAgICAgICAgICBlLnN0eWxlLnNldFByb3BlcnR5KHMsIHYoKSlcbiAgICAgICAgICAgICAgICAgIGNsZWFudXBGdW5jcy5wdXNoKHYoZnVuY3Rpb24gKHZhbCkge1xuICAgICAgICAgICAgICAgICAgICBlLnN0eWxlLnNldFByb3BlcnR5KHMsIHZhbClcbiAgICAgICAgICAgICAgICAgIH0pKVxuICAgICAgICAgICAgICAgIH0gZWxzZVxuICAgICAgICAgICAgICAgICAgZS5zdHlsZS5zZXRQcm9wZXJ0eShzLCBsW2tdW3NdKVxuICAgICAgICAgICAgICB9KShzLCBsW2tdW3NdKVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAoay5zdWJzdHIoMCwgNSkgPT09IFwiZGF0YS1cIikge1xuICAgICAgICAgICAgRGF0YVNldChlKVtrLnN1YnN0cig1KV0gPSBsW2tdXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGVba10gPSBsW2tdXG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9IGVsc2UgaWYgKCdmdW5jdGlvbicgPT09IHR5cGVvZiBsKSB7XG4gICAgICAgIC8vYXNzdW1lIGl0J3MgYW4gb2JzZXJ2YWJsZSFcbiAgICAgICAgdmFyIHYgPSBsKClcbiAgICAgICAgZS5hcHBlbmRDaGlsZChyID0gaXNOb2RlKHYpID8gdiA6IGRvY3VtZW50LmNyZW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gdmFyIGxpc3QgPSBnZXRUb2tlbnMoKVxuICAgICAgICAgICAgLCBpbmRleCA9IGluZGV4b2YobGlzdCwgdG9rZW4pXG5cbiAgICAgICAgaWYgKGluZGV4ID09PSAtMSkge1xuICAgICAgICAgICAgcmV0dXJuXG4gICAgICAgIH1cblxuICAgICAgICBsaXN0LnNwbGljZShpbmRleCwgMSlcbiAgICAgICAgc2V0VG9rZW5zKGxpc3QpXG4gICAgfVxuXG4gICAgZnVuY3Rpb24gY29udGFpbnModG9rZW4pIHtcbiAgICAgICAgcmV0dXJuIGluZGV4b2YoZ2V0VG9rZW5zKCksIHRva2VuKSA+IC0xXG4gICAgfVxuXG4gICAgZnVuY3Rpb24gdG9nZ2xlKHRva2VuKSB7XG4gICAgICAgIGlmIChjb250YWlucyh0b2tlbikpIHtcbiAgICAgICAgICAgIHJlbW92ZSh0b2tlbilcbiAgICAgICAgICAgIHJldHVybiBmYWxzZVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYWRkKHRva2VuKVxuICAgICAgICAgICAgcmV0dXJuIHRydWVcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGZ1bmN0aW9uICR0b1N0cmluZygpIHtcbiAgICAgICAgcmV0dXJuIGVsZW0uY2xhc3NOYW1lXG4gICAgfVxuXG4gICAgZnVuY3Rpb24gaXRlbShpbmRleCkge1xuICAgICAgICB2YXIgdG9rZW5zID0gZ2V0VG9rZW5zKClcbiAgICAgICAgcmV0dXJuIHRva2Vuc1tpbmRleF0gfHwgbnVsbFxuICAgIH1cblxuICAgIGZ1bmN0aW9uIGdldFRva2VucygpIHtcbiAgICAgICAgdmFyIGNsYXNzTmFtZSA9IGVsZW0uY2xhc3NOYW1lXG5cbiAgICAgICAgcmV0dXJuIGZpbHRlcihjbGFzc05hbWUuc3BsaXQoXCIgXCIpLCBpc1RydXRoeSlcbiAgICB9XG5cbiAgICBmdW5jdGlvbiBzZXRUb2tlbnMobGlzdCkge1xuICAgICAgICB2YXIgbGVu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ob2JqZWN0KSkge1xyXG4gICAgICBvYmplY3QgPSBzbGljZS5jYWxsKG9iamVjdCk7XHJcbiAgICB9XHJcbiAgICB2YXIgc2tpcFByb3RvID0gc3VwcG9ydC5lbnVtUHJvdG90eXBlcyAmJiB0eXBlb2Ygb2JqZWN0ID09ICdmdW5jdGlvbicsXHJcbiAgICAgICAgc2tpcEVycm9yUHJvcHMgPSBzdXBwb3J0LmVudW1FcnJvclByb3BzICYmIChvYmplY3QgPT09IGVycm9yUHJvdG8gfHwgb2JqZWN0IGluc3RhbmNlb2YgRXJyb3IpO1xyXG5cclxuICAgIGZvciAodmFyIGtleSBpbiBvYmplY3QpIHtcclxuICAgICAgaWYgKCEoc2tpcFByb3RvICYmIGtleSA9PSAncHJvdG90eXBlJykgJiZcclxuICAgICAgICAgICEoc2tpcEVycm9yUHJvcHMgJiYgKGtleSA9PSAnbWVzc2FnZScgfHwga2V5ID09ICduYW1lJykpKSB7XHJcbiAgICAgICAgcmVzdWx0LnB1c2goa2V5KTtcclxuICAgICAgfVxyXG4gICAgfVxyXG5cclxuICAgIGlmIChzdXBwb3J0Lm5vbkVudW1TaGFkb3dzICYmIG9iamVjdCAhPT0gb2JqZWN0UHJvdG8pIHtcclxuICAgICAgdmFyIGN0b3IgPSBvYmplY3QuY29uc3RydWN0b3IsXHJcbiAgICAgICAgICBpbmRleCA9IC0xLFxyXG4gICAgICAgICAgbGVuZ3RoID0gc2hhZG93ZWRQcm9wcy5sZW5ndGg7XHJcblxyXG4gICAgICBpZiAob2JqZWN0ID09PSAoY3RvciAmJiBjdG9yLnByb3RvdHlwZSkpIHtcclxuICAgICAgICB2YXIgY2xhc3NOYW1lID0gb2JqZWN0ID09PSBzdHJpbmdQcm90byA/IHN0cmluZ0NsYXNzIDogb2JqZWN0ID09PSBlcnJvclByb3RvID8gZXJyb3JDbGFzcyA6IHRvU3RyaW5nLmNhbGwob2JqZWN0KSxcclxuICAgICAgICAgICAgbm9uRW51bSA9IG5vbkVudW1Qcm9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TtcclxuICAgICAgICBpZiAocGFyZW50IDwgMCB8fCBwYXJlbnQgPT09IGluZGV4KSB7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKHRoaXMuaXNIaWdoZXJQcmlvcml0eShpbmRleCwgcGFyZW50KSkge1xyXG4gICAgICAgICAgICB2YXIgdGVtcCA9IHRoaXMuaXRlbXNbaW5kZXhdO1xyXG4gICAgICAgICAgICB0aGlzLml0ZW1zW2luZGV4XSA9IHRoaXMuaXRlbXNbcGFyZW50XTtcclxuICAgICAgICAgICAgdGhpcy5pdGVtc1twYXJlbnRdID0gdGVtcDtcclxuICAgICAgICAgICAgdGhpcy5wZXJjb2xhdGUocGFyZW50KTtcclxuICAgICAgICB9XHJcbiAgICB9O1xyXG5cclxuICAgIHByaW9yaXR5UHJvdG8uaGVhcGlmeSA9IGZ1bmN0aW9uIChpbmRleCkge1xyXG4gICAgICAgIGlmIChpbmRleCA9PT0gdW5kZWZpbmVkKSB7XHJcbiAgICAgICAgICAgIGluZGV4ID0gMDtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKGluZGV4ID49IHRoaXMubGVuZ3RoIHx8IGluZGV4IDwgMCkge1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBsZWZ0ID0gMiAqIGluZGV4ICsgMSxcclxuICAgICAgICAgICAgcmlnaHQgPSAyICogaW5kZXggKyAyLFxyXG4gICAgICAgICAgICBmaXJzdCA9IGluZGV4O1xyXG4gICAgICAgIGlmIChsZWZ0IDwgdGhpcy5sZW5ndGggJiYgdGhpcy5pc0hpZ2hlclByaW9yaXR5KGxlZnQsIGZpcnN0KSkge1xyXG4gICAgICAgICAgICBmaXJzdCA9IGxlZnQ7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChyaWdodCA8IHRoaXMubGVuZ3RoICYmIHRoaXMuaXNIaWdoZXJQcmlvcml0eShyaWdodCwgZml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dGhpcy5pc1NpbmdsZSkge1xyXG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdEaXNwb3NhYmxlIGhhcyBhbHJlYWR5IGJlZW4gYXNzaWduZWQnKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdmFyIHNob3VsZERpc3Bvc2UgPSB0aGlzLmlzRGlzcG9zZWQsIG9sZDtcclxuICAgICAgICAgICAgaWYgKCFzaG91bGREaXNwb3NlKSB7XHJcbiAgICAgICAgICAgICAgICBvbGQgPSB0aGlzLmN1cnJlbnQ7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmN1cnJlbnQgPSB2YWx1ZTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpZiAob2xkKSB7XHJcbiAgICAgICAgICAgICAgICBvbGQuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmIChzaG91bGREaXNwb3NlICYmIHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICB2YWx1ZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKiogXHJcbiAgICAgICAgICogRGlzcG9zZXMgdGhlIHVuZGVybHlpbmcgZGlzcG9zYWJsZSBhcyB3ZWxsIGFzIGFsbCBmdXR1cmUgcmVwbGFjZW1lbnRzLlxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIGJvb2xlYW5EaXNwb3NhYmxlUHJvdG90eXBlLmRpc3Bvc2UgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHZhciBvbGQ7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc0Rpc3Bvc2VkKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgb2xkID0gdGhpcy5jdXJyZW50O1xyXG4gICAgICAgICAgICAgICAgdGhpcy5jdXJy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gdGhpcy5kaXNwb3NhYmxlID0gZGlzcG9zYWJsZTtcclxuICAgICAgICAgICAgdGhpcy5kaXNwb3NhYmxlLmNvdW50Kys7XHJcbiAgICAgICAgICAgIHRoaXMuaXNJbm5lckRpc3Bvc2VkID0gZmFsc2U7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBJbm5lckRpc3Bvc2FibGUucHJvdG90eXBlLmRpc3Bvc2UgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5kaXNwb3NhYmxlLmlzRGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc0lubmVyRGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzSW5uZXJEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NhYmxlLmNvdW50LS07XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuZGlzcG9zYWJsZS5jb3VudCA9PT0gMCAmJiB0aGlzLmRpc3Bvc2FibGUuaXNQcmltYXJ5RGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NhYmxlLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGUudW5kZXJseWluZ0Rpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEluaXRpYWxpemVzIGEgbmV3IGluc3RhbmNlIG9mIHRoZSBSZWZDb3VudERpc3Bvc2FibGUgd2l0aCB0aGUgc3BlY2lmaWVkIGRpc3Bvc2FibGUuXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgIC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Jzb2x1dGUgPSBzY2hlZHVsZUFic29sdXRlO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gaW52b2tlUmVjSW1tZWRpYXRlKHNjaGVkdWxlciwgcGFpcikge1xyXG4gICAgICAgICAgICB2YXIgc3RhdGUgPSBwYWlyLmZpcnN0LCBhY3Rpb24gPSBwYWlyLnNlY29uZCwgZ3JvdXAgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICByZWN1cnNpdmVBY3Rpb24gPSBmdW5jdGlvbiAoc3RhdGUxKSB7XHJcbiAgICAgICAgICAgICAgICBhY3Rpb24oc3RhdGUxLCBmdW5jdGlvbiAoc3RhdGUyKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGlzQWRkZWQgPSBmYWxzZSwgaXNEb25lID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICAgICAgZCA9IHNjaGVkdWxlci5zY2hlZHVsZVdpdGhTdGF0ZShzdGF0ZTIsIGZ1bmN0aW9uIChzY2hlZHVsZXIxLCBzdGF0ZTMpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzQWRkZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLnJlbW92ZShkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzRG9uZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uKHN0YXRlMyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFpc0RvbmUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXAuYWRkKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpc0FkZGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uKHN0YXRlKTtcclxuICAgICAgICAgICAgcmV0dXJuIGdyb3VwO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gaW52b2tlUmVjRGF0ZShzY2hlZHVsZXIsIHBhaXIsIG1ldGhvZCkge1xyXG4gICAgICAgICAgICB2YXIgc3RhdGUgPSBwYWlyLmZpcnN0LCBhY3Rpb24gPSBwYWlyLnNlY29uZCwgZ3JvdXAgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICByZWN1cnNpdmVBY3Rpb24gPSBmdW5jdGlvbiAoc3RhdGUxKSB7XHJcbiAgICAgICAgICAgICAgICBhY3Rpb24oc3RhdGUxLCBmdW5jdGlvbiAoc3RhdGUyLCBkdWVUaW1lMSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBpc0FkZGVkID0gZmFsc2UsIGlzRG9uZSA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgICAgIGQgPSBzY2hlZHVsZXJbbWV0aG9kXS5jYWxsKHNjaGVkdWxlciwgc3RhdGUyLCBkdWVUaW1lMSwgZnVuY3Rpb24gKHNjaGVkdWxlcjEsIHN0YXRlMykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNBZGRlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaXNEb25lID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICByZWN1cnNpdmVBY3Rpb24oc3RhdGUzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoIWlzRG9uZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBncm91cC5hZGQoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlzQWRkZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICByZWN1cnNpdmVBY3Rpb24oc3RhdGUpO1xyXG4gICAgICAgICAgICByZXR1cm4gZ3JvdXA7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiBpbnZva2VBY3Rpb24oc2NoZWR1bGVyLCBhY3Rpb24pIHtcclxuICAgICAgICAgICAgYWN0aW9uKCk7XHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICB2YXIgc2NoZWR1bGVyUHJvdG8gPSBTY2hlZHVsZXIucHJvdG90eXBlO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBSZXR1cm5zIGEgc2NoZWR1bGVyIHRoYXQgd3JhcHMgdGhlIG9yaWdpbmFsIHNjaGVkdWxlciwgYWRkaW5nIGV4Y2VwdGlvbiBoYW5kbGluZyBmb3Igc2NoZWR1bGVkIGFjdGlvbnMuICAgICAgIFxyXG4gICAgICAgICAqIEBwYXJhbSB7RnVuY3Rpb259IGhhbmRsZXIgSGFuZGxlciB0aGF0J3MgcnVuIGlmIGFuIGV4Y2VwdGlvbiBpcyBjYXVnaHQuIFRoZSBleGNlcHRpb24gd2lsbCBiZSByZXRocm93biBpZiB0aGUgaGFuZGxlciBy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S5cclxuICAgICAgICAgKi9cclxuICAgICAgICBzY2hlZHVsZXJQcm90by5zY2hlZHVsZVBlcmlvZGljV2l0aFN0YXRlID0gZnVuY3Rpb24gKHN0YXRlLCBwZXJpb2QsIGFjdGlvbikge1xyXG4gICAgICAgICAgICB2YXIgcyA9IHN0YXRlLCBpZCA9IHNldEludGVydmFsKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHMgPSBhY3Rpb24ocyk7XHJcbiAgICAgICAgICAgIH0sIHBlcmlvZCk7XHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGNsZWFySW50ZXJ2YWwoaWQpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBTY2hlZHVsZXMgYW4gYWN0aW9uIHRvIGJlIGV4ZWN1dGVkLiAgICAgICAgXHJcbiAgICAgICAgICogQHBhcmFtIHtGdW5jdGlvbn0gYWN0aW9uIEFjdGlvbiB0byBleGVjdXRlLlxyXG4gICAgICAgICAqIEByZXR1cm5zIHtEaXNwb3NhYmxlfSBUaGUgZGlzcG9zYWJsZSBvYmplY3QgdXNlZCB0byBjYW5jZWwgdGhlIHNjaGVkdWxlZCBhY3Rpb24gKGJlc3QgZWZmb3J0KS5cclxuICAgICAgICAgKi9cclxuICAgICAgICBzY2hlZHVsZXJQcm90by5zY2hlZHVsZSA9IGZ1bmN0aW9uIChhY3Rpb24pIHtcclxuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3NjaGVkdWxlKGFjdGlvbiwgaW52b2tlQWN0aW9uKTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBTY2hlZHVsZXMgYW4gYWN0aW9uIHRvIGJlIGV4ZWN1dGVkLiAgICBcclxuICAgICAgICAgKiBAcGFyYW0gc3RhdGUgU3Rhd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ICAgICAgICBpZiAoIWl0ZW0uaXNDYW5jZWxsZWQoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgIC8vIE5vdGUsIGRvIG5vdCBzY2hlZHVsZSBibG9ja2luZyB3b3JrIVxyXG4gICAgICAgICAgICAgICAgICAgIHdoaWxlIChpdGVtLmR1ZVRpbWUgLSBTY2hlZHVsZXIubm93KCkgPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGlmICghaXRlbS5pc0NhbmNlbGxlZCgpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGl0ZW0uaW52b2tlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9ICAgICAgICAgICAgXHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiBzY2hlZHVsZU5vdyhzdGF0ZSwgYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLnNjaGVkdWxlV2l0aFJlbGF0aXZlQW5kU3RhdGUoc3RhdGUsIDAsIGFjdGlvbik7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiBzY2hlZHVsZVJlbGF0aXZlKHN0YXRlLCBkdWVUaW1lLCBhY3Rpb24pIHtcclxuICAgICAgICAgICAgdmFyIGR0ID0gdGhpcy5ub3coKSArIFNjaGVkdWxlci5ub3JtYWxpemUoZHVlVGltZSksXHJcbiAgICAgICAgICAgICAgICAgICAgc2kgPSBuZXcgU2NoZWR1bGVkSXRlbSh0aGlzLCBzdGF0ZSwgYWN0aW9uLCBkdCksXHJcbiAgICAgICAgICAgICAgICAgICAgdDtcclxuICAgICAgICAgICAgaWYgKCFxdWV1ZSkge1xyXG4gICAgICAgICAgICAgICAgcXVldWUgPSBuZXcgUHJpb3JpdHlRdWV1ZSg0KTtcclxuICAgICAgICAgICAgICAgIHF1ZXVlLmVucXVldWUoc2kpO1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBydW5UcmFtcG9saW5lKHF1ZXVlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcXVldWUgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgcXVldWUuZW5xdWV1ZShzaSk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgcmV0dXJuIHNpLmRpc3Bvc2FibGU7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiBzY2hlZHVsZUFic29sdXRlKHN0YXRlLCBkdWVUaW1lLCBhY3Rpb24pIHtcclxuICAgICAgICAgICAgcmV0dXJuIHRoaXMuc2NoZWR1bGVXaXRoUmVsYXRpdmVBbmRTdGF0ZShzdGF0ZSwgZHVlVGltZSAtIHRoaXMubm93KCksIGFjdGlvbik7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICB2YXIgY3VycmVudFNjaGVkdWxlciA9IG5ldyBTY2hlZHVsZXIoZGVmYXVsdE5vdywgc2NoZWR1bGVOb3csIHNjaGVkdWxlUmVsYXRpdmUsIHNjaGVkdWxlQWJzb2x1dGUpO1xyXG4gICAgICAgIGN1cnJlbnRTY2hlZHVsZXIuc2NoZWR1bGVSZXF1aXJlZCA9IGZ1bmN0aW9uICgpIHsgcmV0dXJuIHF1ZXVlID09PSBudWxsOyB9O1xyXG4gICAgICAgIGN1cnJlbnRTY2hlZHVsZXIuZW5zdXJlVHJhbXBvbGluZSA9IGZ1bmN0aW9uIChhY3Rpb24pIHtcclxuICAgICAgICAgICAgaWYgKHF1ZXVlID09PSBudWxsKSB7XHJcbiAgICAgIC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ICBjbGVhck1ldGhvZCA9IGNsZWFySW1tZWRpYXRlO1xyXG4gICAgICB9IGVsc2UgaWYgKHBvc3RNZXNzYWdlU3VwcG9ydGVkKCkpIHtcclxuICAgICAgICAgIHZhciBNU0dfUFJFRklYID0gJ21zLnJ4LnNjaGVkdWxlJyArIE1hdGgucmFuZG9tKCksXHJcbiAgICAgICAgICAgIHRhc2tzID0ge30sXHJcbiAgICAgICAgICAgIHRhc2tJZCA9IDA7XHJcblxyXG4gICAgICAgICAgZnVuY3Rpb24gb25HbG9iYWxQb3N0TWVzc2FnZShldmVudCkge1xyXG4gICAgICAgICAgICAvLyBPbmx5IGlmIHdlJ3JlIGEgbWF0Y2ggdG8gYXZvaWQgYW55IG90aGVyIGdsb2JhbCBldmVudHNcclxuICAgICAgICAgICAgaWYgKHR5cGVvZiBldmVudC5kYXRhID09PSAnc3RyaW5nJyAmJiBldmVudC5kYXRhLnN1YnN0cmluZygwLCBNU0dfUFJFRklYLmxlbmd0aCkgPT09IE1TR19QUkVGSVgpIHtcclxuICAgICAgICAgICAgICB2YXIgaGFuZGxlSWQgPSBldmVudC5kYXRhLnN1YnN0cmluZyhNU0dfUFJFRklYLmxlbmd0aCksXHJcbiAgICAgICAgICAgICAgICBhY3Rpb24gPSB0YXNrc1toYW5kbGVJZF07XHJcbiAgICAgICAgICAgICAgYWN0aW9uKCk7XHJcbiAgICAgICAgICAgICAgZGVsZXRlIHRhc2tzW2hhbmRsZUlkXTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIGlmIChyb290LmFkZEV2ZW50TGlzdGVuZXIpIHtcclxuICAgICAgICAgICAgcm9vdC5hZGRFdmVudExpc3RlbmVyKCdtZXNzYWdlJywgb25HbG9iYWxQb3N0TWVzc2FnZSwgZmFsc2UpO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgcm9vdC5hdHRhY2hFdmVudCgnb25tZXNzYWdlJywgb25HbG9iYWxQb3N0TWVzc2FnZSwgZmFsc2UpO1xyXG4gICAgICAgICAgfVxyXG5cclxuICAgICAgICAgIHNjaGVkdWxlTWV0aG9kID0gZnVuY3Rpb24gKGFjdGlvbikge1xyXG4gICAgICAgICAgICB2YXIgY3VycmVudElkID0gdGFza0lkKys7XHJcbiAgICAgICAgICAgIHRhc2tzW2N1cnJlbnRJZF0gPSBhY3Rpb247XHJcbiAgICAgICAgICAgIHJvb3QucG9zdE1lc3NhZ2UoTVNHX1BSRUZJWCArIGN1cnJlbnRJZCwgJyonKTtcclxuICAgICAgICAgIH07XHJcbiAgICAgIH0gZWxzZSBpZiAoISFyb290Lk1lc3NhZ2VDaGFubmVsKSB7XHJcbiAgICAgICAgICB2YXIgY2hhbm5lbCA9IG5ldyByb290Lk1lc3NhZ2VDaGFubmVsKCksXHJcbiAgICAgICAgICAgIGNoYW5uZWxUYXNrcyA9IHt9LFxyXG4gICAgICAgICAgICBjaGFubmVsVGFza0lkID0gMDtcclxuXHJcbiAgICAgICAgICBjaGFubmVsLnBvcnQxLm9ubWVzc2FnZSA9IGZ1bmN0aW9uIChldmVudCkge1xyXG4gICAgICAgICAgICB2YXIgaWQgPSBldmVudC5kYXRhLFxyXG4gICAgICAgICAgICAgIGFjdGlvbiA9IGNoYW5uZWxUYXNrc1tpZF07XHJcbiAgICAgICAgICAgIGFjdGlvbigpO1xyXG4gICAgICAgICAgICBkZWxldGUgY2hhbm5lbFRhc2tzW2lkXTtcclxuICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgc2NoZWR1bGVNZXRob2QgPSBmdW5jdGlvbiAoYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIHZhciBpZCA9IGNoYW5uZWxUYXNrSWQrKztcclxuICAgICAgICAgICAgY2hhbm5lbFRhc2tzW2lkXSA9IGFjdGlvbjtcclxuICAgICAgICAgICAgY2hhbm5lbC5wb3J0Mi5wb3N0TWVzc2FnZShpZCk7ICAgICBcclxuICAgICAgICAgIH07XHJcbiAgICAg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xsOyB9XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBhY3Rpb24oc3RhdGUxKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBmYWlsZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghc2VsZi5faGFuZGxlcihlKSkgeyB0aHJvdyBlOyB9XHJcbiAgICAgICAgICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG51bGw7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuXHJcbiAgICAgICAgICAgIHJldHVybiBkO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIHJldHVybiBDYXRjaFNjaGVkdWxlcjtcclxuICAgIH0oU2NoZWR1bGVyKSk7XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUmVwcmVzZW50cyBhIG5vdGlmaWNhdGlvbiB0byBhbiBvYnNlcnZlci5cclxuICAgICAqL1xyXG4gICAgdmFyIE5vdGlmaWNhdGlvbiA9IFJ4Lk5vdGlmaWNhdGlvbiA9IChmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZnVuY3Rpb24gTm90aWZpY2F0aW9uKGtpbmQsIGhhc1ZhbHVlKSB7IFxyXG4gICAgICAgICAgICB0aGlzLmhhc1ZhbHVlID0gaGFzVmFsdWUgPT0gbnVsbCA/IGZhbHNlIDogaGFzVmFsdWU7XHJcbiAgICAgICAgICAgIHRoaXMua2luZCA9IGtpbmQ7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICB2YXIgTm90aWZpY2F0aW9uUHJvdG90eXBlID0gTm90aWZpY2F0aW9uLnByb3RvdHlwZTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogSW52b2tlcyB0aGUgZGVsZWdhdGUgY29ycmVz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gICAgICAgICAgICBpZiAobm90aWZpY2F0aW9uLmtpbmQgPT09ICdOJykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICByZXR1cm4gTm90aWZpY2F0aW9uO1xyXG4gICAgfSkoKTtcclxuXHJcbiAgICAvKipcclxuICAgICAqIENyZWF0ZXMgYW4gb2JqZWN0IHRoYXQgcmVwcmVzZW50cyBhbiBPbk5leHQgbm90aWZpY2F0aW9uIHRvIGFuIG9ic2VydmVyLlxyXG4gICAgICogQHBhcmFtIHtBbnl9IHZhbHVlIFRoZSB2YWx1ZSBjb250YWluZWQgaW4gdGhlIG5vdGlmaWNhdGlvbi5cclxuICAgICAqIEByZXR1cm5zIHtOb3RpZmljYXRpb259IFRoZSBPbk5leHQgbm90aWZpY2F0aW9uIGNvbnRhaW5pbmcgdGhlIHZhbHVlLlxyXG4gICAgICovXHJcbiAgICB2YXIgbm90aWZpY2F0aW9uQ3JlYXRlT25OZXh0ID0gTm90aWZpY2F0aW9uLmNyZWF0ZU9uTmV4dCA9IChmdW5jdGlvbiAoKSB7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIF9hY2NlcHQgKG9uTmV4dCkge1xyXG4gICAgICAgICAgICByZXR1cm4gb25OZXh0KHRoaXMudmFsdWUpO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gX2FjY2VwdE9ic2VydmFibGUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgcmV0dXJuIG9ic2VydmVyLm9uTmV4dCh0aGlzLnZhbHVlKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHRvU3RyaW5nICgpIHtcclxuICAgICAgICAgICAgcmV0dXJuICdPbk5leHQoJy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FcnJvcih0aGlzLmV4Y2VwdGlvbik7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiBfYWNjZXB0T2JzZXJ2YWJsZShvYnNlcnZlcikge1xyXG4gICAgICAgICAgICByZXR1cm4gb2JzZXJ2ZXIub25FcnJvcih0aGlzLmV4Y2VwdGlvbik7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiB0b1N0cmluZyAoKSB7XHJcbiAgICAgICAgICAgIHJldHVybiAnT25FcnJvcignICsgdGhpcy5leGNlcHRpb24gKyAnKSc7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICB2YXIgbm90aWZpY2F0aW9uID0gbmV3IE5vdGlmaWNhdGlvbignRScpO1xyXG4gICAgICAgICAgICBub3RpZmljYXRpb24uZXhjZXB0aW9uID0gZXhjZXB0aW9uO1xyXG4gICAgICAgICAgICBub3RpZmljYXRpb24uX2FjY2VwdCA9IF9hY2NlcHQ7XHJcbiAgICAgICAgICAgIG5vdGlmaWNhdGlvbi5fYWNjZXB0T2JzZXJ2YWJsZSA9IF9hY2NlcHRPYnNlcnZhYmxlO1xyXG4gICAgICAgICAgICBub3RpZmljYXRpb24udG9TdHJpbmcgPSB0b1N0cmluZztcclxuICAgICAgICAgICAgcmV0dXJuIG5vdGlmaWNhdGlvbjtcclxuICAgICAgICB9O1xyXG4gICAgfSgpKTtcclxuXHJcbiAgICAvKipcclxuICAgICAqIENyZWF0ZXMgYW4gb2JqZWN0IHRoYXQgcmVwcmVzZW50cyBhbiBPbkNvbXBsZXRlZCBub3RpZmljYXRpb24gdG8gYW4gb2JzZXJ2ZXIuXHJcbiAgICAgKiBAcmV0dXJucyB7Tm90aWZpY2F0aW9ufSBUaGUgT25Db21wbGV0ZWQgbm90aWZpY2F0aW9uLlxyXG4gICAgICovXHJcbiAgICB2YXIgbm90aWZpY2F0aW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oY3VycmVudEl0ZW0uZG9uZSkge1xyXG4gICAgICAgICAgaWYgKGxhc3RFeGNlcHRpb24pIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihsYXN0RXhjZXB0aW9uKTtcclxuICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvLyBDaGVjayBpZiBwcm9taXNlXHJcbiAgICAgICAgdmFyIGN1cnJlbnRWYWx1ZSA9IGN1cnJlbnRJdGVtLnZhbHVlO1xyXG4gICAgICAgIGlzUHJvbWlzZShjdXJyZW50VmFsdWUpICYmIChjdXJyZW50VmFsdWUgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UoY3VycmVudFZhbHVlKSk7ICAgICAgICBcclxuXHJcbiAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICBkLnNldERpc3Bvc2FibGUoY3VycmVudFZhbHVlLnN1YnNjcmliZShcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dC5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgIGZ1bmN0aW9uIChleG4pIHtcclxuICAgICAgICAgICAgbGFzdEV4Y2VwdGlvbiA9IGV4bjtcclxuICAgICAgICAgICAgc2VsZigpO1xyXG4gICAgICAgICAgfSxcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKSk7XHJcbiAgICAgIH0pO1xyXG4gICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uLCBjYW5jZWxhYmxlLCBkaXNwb3NhYmxlQ3JlYXRlKGZ1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yBlbGVtZW50IGluIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgKiAgXHJcbiAgICAgICAgICogQG1lbWJlck9mIEFic3RyYWN0T2JzZXJ2ZXJcclxuICAgICAgICAgKiBAcGFyYW0ge0FueX0gdmFsdWUgTmV4dCBlbGVtZW50IGluIHRoZSBzZXF1ZW5jZS4gXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgQWJzdHJhY3RPYnNlcnZlci5wcm90b3R5cGUub25OZXh0ID0gZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMubmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBOb3RpZmllcyB0aGUgb2JzZXJ2ZXIgdGhhdCBhbiBleGNlcHRpb24gaGFzIG9jY3VycmVkLlxyXG4gICAgICAgICAqIFxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBBYnN0cmFjdE9ic2VydmVyXHJcbiAgICAgICAgICogQHBhcmFtIHtBbnl9IGVycm9yIFRoZSBlcnJvciB0aGF0IGhhcyBvY2N1cnJlZC4gICAgIFxyXG4gICAgICAgICAqLyAgICBcclxuICAgICAgICBBYnN0cmFjdE9ic2VydmVyLnByb3RvdHlwZS5vbkVycm9yID0gZnVuY3Rpb24gKGVycm9yKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogTm90aWZpZXMgdGhlIG9ic2VydmVyIG9mIHRoZSBlbmQgb2YgdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAqLyAgICBcclxuICAgICAgICBBYnN0cmFjdE9ic2VydmVyLnByb3RvdHlwZS5vbkNvbXBsZXRlZCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5jb21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIERpc3Bvc2VzIHRoZSBvYnNlcnZlciwgY2F1c2luZyBpdCB0byB0cmFuc2l0aW9uIHRvIHRoZSBzdG9wcGVkIHN0YXRlLlxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIEFic3RyYWN0T2JzZXJ2ZXIucHJvdG90eXBlLmRpc3Bvc2UgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBBYnN0cmFjdE9ic2VydmVyLnByb3RvdHlwZS5mYWlsID0gZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5lcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gZmFsc2U7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgcmV0dXJuIEFic3RyYWN0T2JzZXJ2ZXI7XHJcbiAgICB9KE9ic2VydmVyKSk7XHJcblxyXG4gIC8qKlxyXG4gICAqIENsYXNzIHRvIGNyZWF0Z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odGhpcyk7XHJcbiAgICAgICAgICAgIHRoaXMuX29ic2VydmVyID0gb2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMDsgLy8gMCAtIGlkbGUsIDEgLSBidXN5LCAyIC0gZG9uZVxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZSA9IENoZWNrZWRPYnNlcnZlci5wcm90b3R5cGU7XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5vbk5leHQgPSBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgdGhpcy5jaGVja0FjY2VzcygpO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkgeyBcclxuICAgICAgICAgICAgICAgIHRocm93IGU7ICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fc3RhdGUgPSAwO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQ2hlY2tlZE9ic2VydmVyUHJvdG90eXBlLm9uRXJyb3IgPSBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgIHRoaXMuY2hlY2tBY2Nlc3MoKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX29ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkgeyBcclxuICAgICAgICAgICAgICAgIHRocm93IGU7ICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5fc3RhdGUgPSAyO1xyXG4gICAgICAgICAgICB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sdDtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZpcnN0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZpcnN0ID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUgPSBpdGVyYXRlKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzUmVzdWx0ID0gY29uZGl0aW9uKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaGFzUmVzdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgICAgIHNlbGYoKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAvKipcclxuICAgKiAgVGhpcyBtZXRob2QgY3JlYXRlcyBhIG5ldyBPYnNlcnZhYmxlIGluc3RhbmNlIHdpdGggYSB2YXJpYWJsZSBudW1iZXIgb2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ICAgICAgICAgcSA9IFtdLFxyXG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlID0gZnVuY3Rpb24gKHhzKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIHN1YnNjcmlwdGlvbiA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGdyb3VwLmFkZChzdWJzY3JpcHRpb24pO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICAvLyBDaGVjayBmb3IgcHJvbWlzZXMgc3VwcG9ydFxyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpc1Byb21pc2UoeHMpKSB7IHhzID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHhzKTsgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZSh4cy5zdWJzY3JpYmUob2JzZXJ2ZXIub25OZXh0LmJpbmQob2JzZXJ2ZXIpLCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBzO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBncm91cC5yZW1vdmUoc3Vic2NyaXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcyA9IHEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZShzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFjdGl2ZUNvdW50LS07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNTdG9wcGVkICYmIGFjdGl2ZUNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIGdyb3VwLmFkZChzb3VyY2VzLnN1YnNjcmliZShmdW5jdGlvbiAoaW5uZXJTb3VyY2UpIHtcclxuICAgICAgICAgICAgICAgIGlmIChhY3RpdmVDb3VudCA8IG1heENvbmN1cnJlbnRPck90aGVyKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgYWN0aXZlQ291bnQrKztcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmUoaW5uZXJTb3VyY2UpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBxLnB1c2goaW5uZXJTb3VyY2UpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgaWYgKGFjdGl2ZUNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICByZXR1cm4gZ3JvdXA7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogTWVyZ2VzIGFsbCB0aGUgb2JzZXJ2YWJsZSBzZXF1ZW5jZXMgaW50byBhIHNpbmdsZSBvYnNlcnZhYmxlIHNlcXVlbmNlLiAgXHJcbiAgICAgKiBUaGUgc2NoZWR1bGVyIGlzIG9wd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biA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICBpc1N0b3BwZWQgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgIGxhdGVzdCA9IDAsXHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24gPSBzb3VyY2VzLnN1YnNjcmliZShmdW5jdGlvbiAoaW5uZXJTb3VyY2UpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpLCBpZCA9ICsrbGF0ZXN0O1xyXG4gICAgICAgICAgICAgICAgICAgIGhhc0xhdGVzdCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgaW5uZXJTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShkKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgLy8gQ2hlY2sgaWYgUHJvbWlzZSBvciBPYnNlcnZhYmxlXHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlzUHJvbWlzZShpbm5lclNvdXJjZSkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJTb3VyY2UgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UoaW5uZXJTb3VyY2UpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKGlubmVyU291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAobGF0ZXN0ID09PSBpZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxhdGVzdCA9PT0gaWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsYXRlc3QgPT09IGlkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBoYXNMYXRlc3QgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFoYXNMYXRlc3QpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgcmV0dXJuIG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKHN1YnNjcmlwdGlvbiwgaW5uZXJTdWJzY3JpcHRpb24pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogUmV0dXJucyB0aGUgdmFsdWVzIGZyb20gdGhlIHNvdXJjZSBvYnNlcnZhYmxlIHNlcXVlbmNlIHVudGlsIHRoZSBvdGhlciBvYnNlcnZhYmxlIHNlcXVlbm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Jlc3BvbmRpbmcgaW5kZXhlcy5cclxuICAgICAqIEBwYXJhbSBhcmd1bWVudHMgT2JzZXJ2YWJsZSBzb3VyY2VzLlxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2UgY29udGFpbmluZyBsaXN0cyBvZiBlbGVtZW50cyBhdCBjb3JyZXNwb25kaW5nIGluZGV4ZXMuXHJcbiAgICAgKi9cclxuICAgIE9ic2VydmFibGUuemlwQXJyYXkgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgdmFyIHNvdXJjZXMgPSBhcmdzT3JBcnJheShhcmd1bWVudHMsIDApO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIG4gPSBzb3VyY2VzLmxlbmd0aCxcclxuICAgICAgICAgICAgICBxdWV1ZXMgPSBhcnJheUluaXRpYWxpemUobiwgZnVuY3Rpb24gKCkgeyByZXR1cm4gW107IH0pLFxyXG4gICAgICAgICAgICAgIGlzRG9uZSA9IGFycmF5SW5pdGlhbGl6ZShuLCBmdW5jdGlvbiAoKSB7IHJldHVybiBmYWxzZTsgfSk7XHJcblxyXG4gICAgICAgICAgICBmdW5jdGlvbiBuZXh0KGkpIHtcclxuICAgICAgICAgICAgICAgIGlmIChxdWV1ZXMuZXZlcnkoZnVuY3Rpb24gKHgpIHsgcmV0dXJuIHgubGVuZ3RoID4gMDsgfSkpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgcmVzID0gcXVldWVzLm1hcChmdW5jdGlvbiAoeCkgeyByZXR1cm4geC5zaGlmdCgpOyB9KTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoaXNEb25lLmZpbHRlcihmdW5jdGlvbiAoeCwgaikgeyByZXR1cm4gaiAhPT0gaTsgfSkuZXZlcnkoaWRlbnRpdHkpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBmdW5jdGlvbiBkb25lKGkpIHtcclxuICAgICAgICAgICAgICAgIGlzRG9uZVtpXSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBpZiAoaXNEb25lLmV2ZXJ5KGlkZW50aXR5KSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICB2YXIgc3Vic2NyaXB0aW9ucyA9IG5ldyBBcnJheShuKTtcclxuICAgICAgICAgICAgZm9yICh2YXIgaWR4ID0gMDsgaWR4IDwgbjsgaWR4KyspIHtcclxuICAgICAgICAgICAgICAgIChmdW5jdGlvbiAoaSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbnNbaV0gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb25zW2ldLnNldERpc3Bvc2FibGUoc291cmNlc1tpXS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcXVldWVzW2ldLnB1c2goeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG5leHQoaSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25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ZCA9IGZ1bmN0aW9uIChrZXlTZWxlY3RvciwgY29tcGFyZXIpIHtcclxuICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICBrZXlTZWxlY3RvciB8fCAoa2V5U2VsZWN0b3IgPSBpZGVudGl0eSk7XHJcbiAgICAgICAgY29tcGFyZXIgfHwgKGNvbXBhcmVyID0gZGVmYXVsdENvbXBhcmVyKTtcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBoYXNDdXJyZW50S2V5ID0gZmFsc2UsIGN1cnJlbnRLZXk7XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGNvbXBhcmVyRXF1YWxzID0gZmFsc2UsIGtleTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAga2V5ID0ga2V5U2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChoYXNDdXJyZW50S2V5KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgY29tcGFyZXJFcXVhbHMgPSBjb21wYXJlcihjdXJyZW50S2V5LCBrZXkpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoIWhhc0N1cnJlbnRLZXkgfHwgIWNvbXBhcmVyRXF1YWxzKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzQ3VycmVudEtleSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgY3VycmVudEtleSA9IGtleTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBvYnNlcnZlci5vbkNvbXBsZXRlZC5iaW5kKG9ic2VydmVyKSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIEludm9rZXMgYW4gYWN0aW9uIGZvciBlYWNoIGVsZW1lbnQgaW4gdGhlIG9ic2VydmFibGUgc2VxdWVuY2UgYW5kIGludm9rZXMgYW4gYWN0aW9uIHVwb24gZ3JhY2VmdWwgb3IgZXhjZXB0aW9uYWwgdGVybWluYXRpb24gb2YgdGhlIG9ic2VydmFibGUgc2VxdWVuY2UuXHJcbiAgICAgKiAgVGhpcyBtZXRob2QgY2FuIGJlIHVzZWQgZm9yIGRlYnVnZ2luZywgbG9nZ2luZywgZXRjLiBvZiBxdWVyeSBiZWhhdmlvciBieSBpbnRlcmNlcHRpbmcgdGhlIG1lc3NhZ2Ugc3RyZWFtIHRvIHJ1biBhcmJpdHJhcnkgYWN0aW9ucyBmb3IgbWVzc2FnZXMgb24gdGhlIHBpcGVsaW5lLlxyXG4gICAgICogIFxyXG4gICAgICogQGV4YW1wbGVcclxuICAgICAqICB2YXIgcmVzID0gb2JzZXJ2YWJsZS5kb0FjdGlvbihvYnNlcnZlcik7XHJcbiAgICAgKiAgd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ICAgaWYgKCFvbkVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghb25Db21wbGV0ZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAvKipcclxuICAgKiAgSW52b2tlcyBhIHNwZWNpZmllZCBhY3Rpb24gYWZ0ZXIgdGhlIHNvdXJjZSBvYnNlcnZhYmxlIHNlcXVlbmNlIHRlcm1pbmF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ZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGhhc0FjY3VtdWxhdGlvbiwgYWNjdW11bGF0aW9uLCBoYXNWYWx1ZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUgKFxyXG4gICAgICAgICAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIWhhc1ZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICBcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGhhc0FjY3VtdWxhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgYWNjdW11bGF0aW9uID0gYWNjdW11bGF0b3IoYWNjdW11bGF0aW9uLCB4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFjY3VtdWxhdGlvbiA9IGhhc1NlZWQgPyBhY2N1bXVsYXRvcihzZWVkLCB4KSA6IHg7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBoYXNBY2N1bXVsYXRpb24gPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFjY3VtdWxhdGlvbik7XHJcbiAgICAgICAgICAgICAgICB9LFxyXG4gICAgICAgIC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9IGZ1bmN0aW9uIChjb3VudCkge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHEgPSBbXTtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHEucHVzaCh4KTtcclxuICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IGNvdW50KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocSk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUHJvamVjdHMgZWFjaCBlbGVtZW50IG9mIGFuIG9ic2VydmFibGUgc2VxdWVuY2UgaW50byB6ZXJvIG9yIG1vcmUgd2luZG93cyB3aGljaCBhcmUgcHJvZHVjZWQgYmFzZWQgb24gZWxlbWVudCBjb3VudCBpbmZvcm1hdGlvbi5cclxuICAgICAqICBcclxuICAgICAqICB2YXIgcmVzID0geHMud2luZG93V2l0aENvdW50KDEwKTtcclxuICAgICAqICB2YXIgcmVzID0geHMud2luZG93V2l0aENvdW50KDEwLCAxKTtcclxuICAgICAqIEBwYXJhbSB7TnVtYmVyfSBjb3VudCBMZW5ndGggb2YgZWFjaCB3aW5kb3cuXHJcbiAgICAgKiBAcGFyYW0ge051bWJlcn0gW3NraXBdIE51bWJlciBvZiBlbGVtZW50cyB0byBza2lwIGJldHdlZW4gY3JlYXRpb24gb2YgY29uc2VjdXRpdmUgd2luZG93cy4gSWYgbm90IHNwZWNpZmllZCwgZGVmYXVsdHMgdG8gdGhlIGNvdW50LlxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2Ugb2Ygd2luZG93cy4gIFxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8ud2luZG93V2l0aENvdW50ID0gZnVuY3Rpb24gKGNvdW50LCBza2lwKSB7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAgaWYgKGNvdW50IDw9IDApIHtcclxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChhcmd1bWVudHMubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgIHNraXAgPSBjb3VudDtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKHNraXAgPD0gMCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYXJndW1lbnRPdXRPZlJhbmdlKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgbSA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShtKSxcclxuICAgICAgICAgICAgICAgIG4gPSAwLFxyXG4gICAgICAgICAgICAgICAgcSA9IFtdLFxyXG4gICAgICAgICAgICAgICAgY3JlYXRlV2luZG93ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgICAgICAgICBxLnB1c2gocyk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihzLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIGNyZWF0ZVdpbmRvdygpO1xyXG4gICAgICAgICAgICBtLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHM7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gcS5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHFbaV0ub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdmFyIGMgPSBuIC0gY291bnQgKyAxO1xyXG4gICAgICAgICAgICAgICAgaWYgKGMgPj0gMCAmJiBjICUgc2tpcCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHMgPSBxLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgbisrO1xyXG4gICAgICAgICAgICAgICAgaWYgKG4gJSBza2lwID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgY3JlYXRlV2luZG93KCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBxLnNoaWZ0KCkub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5zaGlmdCgpLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIHJldHVybiByZWZDb3VudERpc3Bvc2FibGU7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIGNvbmNhdE1hcChzZWxlY3Rvcikge1xyXG4gICAgICByZXR1cm4gdGhpcy5tYXAoZnVuY3Rpb24gKHgsIGkpIHtcclxuICAgICAgICB2YXIgcmVzdWx0ID0gc2VsZWN0b3IoeCwgaSk7XHJcbiAgICAgICAgcmV0dXJuIGlzUHJvbWlzZShyZXN1bHQpID8gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHJlc3VsdCkgOiByZXN1bHQ7XHJcbiAgICAgIH0pLmNvbmNhdEFsbCgpO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIGNvbmNhdE1hcE9ic2VydmVyKG9uTmV4dCwgb25FcnJvciwgb25Db21wbGV0ZWQpIHtcclxuICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICB2YXIgaW5kZXggPSAwO1xyXG5cclxuICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShcclxuICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChvbk5leHQ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FxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8uZGVmYXVsdElmRW1wdHkgPSBmdW5jdGlvbiAoZGVmYXVsdFZhbHVlKSB7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAgaWYgKGRlZmF1bHRWYWx1ZSA9PT0gdW5kZWZpbmVkKSB7XHJcbiAgICAgICAgICAgIGRlZmF1bHRWYWx1ZSA9IG51bGw7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGZvdW5kID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICBmb3VuZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghZm91bmQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZGVmYXVsdFZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBSZXR1cm5zIGFuIG9ic2VydmFibGUgc2VxdWVuY2UgdGhhdCBjb250YWlucyBvbmx5IGRpc3RpbmN0IGVsZW1lbnRzIGFjY29yZGluZyB0byB0aGUga2V5U2VsZWN0b3IgYW5kIHRoZSBjb21wYXJlci5cclxuICAgICAqICBVc2FnZSBvZiB0aG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uICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICBrZXlTZWxlY3RvciB8fCAoa2V5U2VsZWN0b3IgPSBpZGVudGl0eSk7XHJcbiAgICAgICAga2V5U2VyaWFsaXplciB8fCAoa2V5U2VyaWFsaXplciA9IGRlZmF1bHRLZXlTZXJpYWxpemVyKTtcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBoYXNoU2V0ID0ge307XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIga2V5LCBzZXJpYWxpemVkS2V5LCBvdGhlcktleSwgaGFzTWF0Y2ggPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAga2V5ID0ga2V5U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgc2VyaWFsaXplZEtleSA9IGtleVNlcmlhbGl6ZXIoa2V5KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBmb3IgKG90aGVyS2V5IGluIGhhc2hTZXQpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoc2VyaWFsaXplZEtleSA9PT0gb3RoZXJLZXkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaGFzTWF0Y2ggPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBicmVhaztcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgIC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zb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIGVsZW1lbnRTZWxlY3RvciB8fCAoZWxlbWVudFNlbGVjdG9yID0gaWRlbnRpdHkpO1xyXG4gICAgICAgIGtleVNlcmlhbGl6ZXIgfHwgKGtleVNlcmlhbGl6ZXIgPSBkZWZhdWx0S2V5U2VyaWFsaXplcik7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgbWFwID0ge30sXHJcbiAgICAgICAgICAgICAgICBncm91cERpc3Bvc2FibGUgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShncm91cERpc3Bvc2FibGUpO1xyXG4gICAgICAgICAgICBncm91cERpc3Bvc2FibGUuYWRkKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBkdXJhdGlvbiwgZHVyYXRpb25Hcm91cCwgZWxlbWVudCwgZmlyZU5ld01hcEVudHJ5LCBncm91cCwga2V5LCBzZXJpYWxpemVkS2V5LCBtZCwgd3JpdGVyLCB3O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBrZXkgPSBrZXlTZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgICAgICBzZXJpYWxpemVkS2V5ID0ga2V5U2VyaWFsaXplcihrZXkpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodyBpbiBtYXApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgZmlyZU5ld01hcEVudHJ5ID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHdyaXRlciA9IG1hcFtzZXJpYWxpemVkS2V5XTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoIXdyaXRlcikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB3cml0ZXIgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBtYXBbc2VyaWFsaXplZEtleV0gPSB3cml0ZXI7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZpcmVOZXdNYXBFbnRyeSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodyBpbiBtYXApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGZpcmVOZXdNYXBFbnRyeSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGdyb3VwID0gbmV3IEdyb3VwZWRPYnNlcnZhYmxlKGtleSwgd3JpdGVyLCByZWZDb3VudERpc3Bvc2FibGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uR3JvdXAgPSBuZXcgR3JvdXBlZE9ic2VydmFibGUoa2V5LCB3cml0ZXIpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uID0gZHVyYXRpb25TZWxlY3RvcihkdXJhdGlvbkdyb3VwKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAodyBpbiBtYXApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1hcFt3XS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGdyb3VwKTtcclxuICAgICAgICAgICAgICAgICAgICBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGdyb3VwRGlzcG9zYWJsZS5hZGQobWQpO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBleHBpcmUgPSBmdW5jdGlvbiAgKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoc2VyaWFsaXplZEtleSBpbiBtYXApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlbGV0ZSBtYXBbc2VyaWFsaXplZEtleV07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB3cml0ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBncm91cERpc3Bvc2FibGUucmVtb3ZlKG1kKTtcclxuICAgICAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgZnVuY3Rpb24gKGV4bikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXBbd10ub25FcnJvcihleG4pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhuKTtcclxuICAgICAgICAgICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGV4cGlyZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZWxlbWVudCA9IGVsZW1lbnRTZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG1hcFt3XS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHdyaXRlci5vbk5leHQoZWxlbWVudCk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChleCkge1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgdyBpbiBtYXApIHtcclxuICAgICAgICAgICAgICAgICAgICBtYXBbd10ub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICA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B0aGlzQXJnKSB7XHJcbiAgICAgICAgdmFyIHBhcmVudCA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgY291bnQgPSAwO1xyXG4gICAgICAgICAgICByZXR1cm4gcGFyZW50LnN1YnNjcmliZShmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHNlbGVjdG9yLmNhbGwodGhpc0FyZywgdmFsdWUsIGNvdW50KyssIHBhcmVudCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBSZXRyaWV2ZXMgdGhlIHZhbHVlIG9mIGEgc3BlY2lmaWVkIHByb3BlcnR5IGZyb20gYWxsIGVsZW1lbnRzIGluIHRoZSBPYnNlcnZhYmxlIHNlcXVlbmNlLlxyXG4gICAgICogQHBhcmFtIHtTdHJpbmd9IHByb3BlcnR5IFRoZSBwcm9wZXJ0eSB0byBwbHVjay5cclxuICAgICAqIEByZXR1cm5zIHtPYnNlcnZhYmxlfSBSZXR1cm5zIGEgbmV3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lIGlucHV0IHNlcXVlbmNlLiAgIFxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8uc2tpcCA9IGZ1bmN0aW9uIChjb3VudCkge1xyXG4gICAgICAgIGlmIChjb3VudCA8IDApIHtcclxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBvYnNlcnZhYmxlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciByZW1haW5pbmcgPSBjb3VudDtcclxuICAgICAgICAgICAgcmV0dXJuIG9ic2VydmFibGUuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAocmVtYWluaW5nIDw9IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHJlbWFpbmluZy0tO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBvYnNlcnZlci5vbkNvbXBsZXRlZC5iaW5kKG9ic2VydmVyKSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIEJ5cGFzc2VzIGVsZW1lbnRzIGluIGFuIG9ic2VydmFibGUgc2VxdWVuY2UgYXMgbG9uZyBhcyBhIHNwZWNpZmllZCBjb25kaXRpb24gaXMgdHJ1ZSBhbmQgdGhlbiByZXR1cm5zIHRoZSByZW1haW5pbmcgZWxlbWVudHMuXHJcbiAgICAgKiAgVGhlIGVsZW1lbnQncyBpbmRleCBpcyB1c2VkIGluIHRoZSBsb2d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AgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBpID0gMCwgcnVubmluZyA9IGZhbHNlO1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFydW5uaW5nKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcnVubmluZyA9ICFwcmVkaWNhdGUuY2FsbCh0aGlzQXJnLCB4LCBpKyssIHNvdXJjZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKHJ1bm5pbmcpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUmV0dXJucyBhIHNwZWNpZmllZCBudW1iZXIgb2YgY29udGlndW91cyBlbGVtZW50cyBmcm9tIHRoZSBzdGFydCBvZiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlLCB1c2luZyB0aGUgc3BlY2lmaWVkIHNjaGVkdWxlciBmb3IgdGhlIGVkZ2UgY2FzZSBvZiB0YWtlKDApLlxyXG4gICAgICogIFxyXG4gICAg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Q7XHJcbiAgICAgICAgICAgIHJldHVybiBvYnNlcnZhYmxlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKHJlbWFpbmluZyA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICByZW1haW5pbmctLTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHJlbWFpbmluZyA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBSZXR1cm5zIGVsZW1lbnRzIGZyb20gYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSBhcyBsb25nIGFzIGEgc3BlY2lmaWVkIGNvbmRpdGlvbiBpcyB0cnVlLlxyXG4gICAgICogIFRoZSBlbGVtZW50J3MgaW5kZXggaXMgdXNlZCBpbiB0aGUgbG9naWMgb2YgdGhlIHByZWRpY2F0ZSBmdW5jdGlvbi5cclxuICAgICAqICBcclxuICAgICAqIEBleGFtcGxlXHJcbiAgICAgKiAgdmFyIHJlcyA9IHNvdXJjZS50YWtlV2hpbGUoZnVuY3Rpb24gKHZhbHVlKSB7IHJldHVybiB2YWx1ZSA8IDEwOyB9KTtcclxuICAgICAqICB2YXIgcmVzID0gc291cmNlLnRha2VXaGlsZShmdW5jdGlvbiAodmFsdWUsIGluZGV4KSB7IHJldHVybiB2YWx1ZSA8IDEwIHx8IGluZGV4IDwgMTA7IH0pO1xyXG4gICAgICogQHBhcmF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gb2JzZXJ2YWJsZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGlmIChydW5uaW5nKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBGaWx0ZXJzIHRoZSBlbGVtZW50cyBvZiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIGJhc2VkIG9uIGEgcHJlZGljYXRlIGJ5IGluY29ycG9yYXRpbmcgdGhlIGVsZW1lbnQncyBpbmRleC5cclxuICAgICAqICBcclxuICAgICAqIEBleGFtcGxlXHJcbiAgICAgKiAgdmFyIHJlcyA9IHNvdXJjZS53aGVyZShmdW5jdGlvbiAodmFsdWUpIHsgcmV0dXJuIHZhbHVlIDwgMTA7IH0pO1xyXG4gICAgICogIHZhciByZXMgPSBzb3VyY2Uud2hlcmUoZnVuY3Rpb24gKHZhbHVlLCBpbmRleCkgeyByZXR1cm4gdmFsdWUgPCAxMCB8fCBpbmRleCA8IDEwOyB9KTtcclxuICAgICAqIEBwYXJhbSB7RnVuY3Rpb259IHByZWRpY2F0ZSBB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gfSk7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIGV4dHJlbWFCeShzb3VyY2UsIGtleVNlbGVjdG9yLCBjb21wYXJlcikge1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGhhc1ZhbHVlID0gZmFsc2UsIGxhc3RLZXkgPSBudWxsLCBsaXN0ID0gW107XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgY29tcGFyaXNvbiwga2V5O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBrZXkgPSBrZXlTZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgY29tcGFyaXNvbiA9IDA7XHJcbiAgICAgICAgICAgICAgICBpZiAoIWhhc1ZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGxhc3RLZXkgPSBrZXk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbXBhcmlzb24gPSBjb21wYXJlcihrZXksIGxhc3RLZXkpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4MSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4MSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoY29tcGFyaXNvbiA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBsYXN0S2V5ID0ga2V5O1xyXG4gICAgICAgICAgICAgICAgICAgIGxpc3QgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChjb21wYXJpc29uID49IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBsaXN0LnB1c2goeCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChsaXN0KTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIGZpcnN0T25seSh4KSB7XHJcbiAgICAgICAgaWYgKHgubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihzZXF1ZW5jZUNvbnRhaW5zTm9FbGVtZW50cyk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiB4WzBdO1xyXG4gICAgfVxyXG5cclxuICAgIC8qKlxyXG4gICAgICogQXBwbGllcyBhbiBhY2N1bXVsYXRvciBmdW5jdGlvbiBvdmVyIGFuIG9ic2VydmFibGUgc2VxdWVuY2UsIHJldHVybmluZyB0aGUgcmVzdWx0IG9mIHRoZSBhZ2dyZWdhdGlvbiBhcyBhIHNpbmdsZSBlbGVtZW50IGluIHRoZSByZXN1bHQgc2VxdWVuY2UuIFRoZSBzcGVjaWZpZWQgc2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3VyLFxyXG4gICAgICAgICAgICAgICAgICAgIGNvdW50OiBwcmV2LmNvdW50ICsgMVxyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgfSkuZmluYWxWYWx1ZSgpLnNlbGVjdChmdW5jdGlvbiAocykge1xyXG4gICAgICAgICAgICAgICAgaWYgKHMuY291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ1RoZSBpbnB1dCBzZXF1ZW5jZSB3YXMgZW1wdHknKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHJldHVybiBzLnN1bSAvIHMuY291bnQ7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgZnVuY3Rpb24gc2VxdWVuY2VFcXVhbEFycmF5KGZpcnN0LCBzZWNvbmQsIGNvbXBhcmVyKSB7XHJcbiAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICB2YXIgY291bnQgPSAwLCBsZW4gPSBzZWNvbmQubGVuZ3RoO1xyXG4gICAgICAgIHJldHVybiBmaXJzdC5zdWJzY3JpYmUoZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICB2YXIgZXF1YWwgPSBmYWxzZTtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGlmIChjb3VudCA8IGxlbikge1xyXG4gICAgICAgICAgICAgIGVxdWFsID0gY29tcGFyZXIodmFsdWUsIHNlY29uZFtjb3VudCsrXSk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgaWYgKCFlcXVhbCkge1xyXG4gICAgICAgICAgICBv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b24gKHgpIHtcclxuICAgICAgICB2YXIgZXF1YWwsIHY7XHJcbiAgICAgICAgaWYgKHFyLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgdiA9IHFyLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgZXF1YWwgPSBjb21wYXJlcih2LCB4KTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmICghZXF1YWwpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9IGVsc2UgaWYgKGRvbmVyKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgcWwucHVzaCh4KTtcclxuICAgICAgICB9XHJcbiAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBkb25lbCA9IHRydWU7XHJcbiAgICAgICAgaWYgKHFsLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgaWYgKHFyLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH0gZWxzZSBpZiAoZG9uZXIpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHRydWUpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgfSk7XHJcblxyXG4gICAgICBpc1Byb21pc2Uoc2Vjb25kKSAmJiAoc2Vjb25kID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHNlY29uZCkpO1xyXG4gICAgICB2YXIgc3Vic2NyaXB0aW9uMiA9IHNlY29uZC5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICB2YXIgZXF1YWwsIHY7XHJcbiAgICAgICAgaWYgKHFsLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgIHYgPSBxbC5zaGlmdCgpO1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgZXF1YWwgPSBjb21wYXJlcih2LCB4KTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlmICghZXF1YWwpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9IGVsc2UgaWYgKGRvbmVsKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZmFsc2UpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgcXIucHVzaCh4KTtcclxuICAgICAgICB9XHJcbiAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBkb25lciA9IHRydWU7XHJcbiAgICAgICAgaWYgKHFyLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgaWYgKHFsLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH0gZWxzZSBpZiAoZG9uZWwpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHRydWUpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgfSk7XHJcbiAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShzdWJzY3JpcHRpb24xLCBzdWJzY3JpcHRpb24yKTtcclxuICAgIH0pO1xyXG4gIH07XHJcblxyXG4gICAgZnVuY3Rpb24gZWxlbWVudEF0T3JEZWZhdWx0KHNvdXJjZSwgaW5kZXgsIGhhc0RlZmF1bHQsIGRlZmF1bHRWYWx1ZSkge1xyXG4gICAgICAgIGlmIChpbmRleCA8IDApIHtcclxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGkgPSBpbmRleDtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGlmIChpID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpLS07XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghaGFzRGVmYXVsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IobmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSkpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoZGVmYXVsdFZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIFJldHVybnMgdGhlIGVsZW1lbnQgYXQgYSBzcGVjaWZpZWQgaW5kZXggaW4gYSBzZXF1ZW5jZS5cclxuICAgICAqIEBleGFtcGxlXHJcbiAgICAgKiB2YXIgcmVzID0gc291cmNlLmVsZW1lbnRBdCg1KTtcclxuICAgICAqIEBwYXJhbSB7TnVtYmVyfSBpbmRleCBUaGUgemVyby1iYXNlZCBpbmRleCBvZiB0aGUgZWxlbWVudCB0byByZXRyaWV2ZS5cclxuICAgICAqIEByZXR1cm5zIHtPYnNlcnZhYmxlfSBBbiBvYnNlcnZhYmxlIHNlcXVlbmNlIHRoYXQgcHJvZHVjZXMgdGhlIGVsZW1lbnQgYXQgdGhlIHNwZWNpZmllZCBwb3NpdGlvbiBpbiB0aGUgc291cmNlIHNlcXVlbmNlLlxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8uZWxlbWVudEF0ID0gIGZ1bmN0aW9uIChpbmRleCkge1xyXG4gICAgICAgIHJldHVybiBlbGVtZW50QXRPckRlZmF1bHQodGhpcywgaW5kZXgsIG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mFyIHNob3VsZFJ1bjtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc2hvdWxkUnVuID0gcHJlZGljYXRlLmNhbGwodGhpc0FyZywgeCwgaSwgc291cmNlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2goZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKHNob3VsZFJ1bikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh5aWVsZEluZGV4ID8gaSA6IHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGkrKztcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHlpZWxkSW5kZXggPyAtMSA6IHVuZGVmaW5lZCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTsgICAgICAgIFxyXG4gICAgfVxyXG5cclxuICAgIC8qKlxyXG4gICAgICogU2VhcmNoZXMgZm9yIGFuIGVsZW1lbnQgdGhhdCBtYXRjaGVzIHRoZSBjb25kaXRpb25zIGRlZmluZWQgYnkgdGhlIHNwZWNpZmllZCBwcmVkaWNhdGUsIGFuZCByZXR1cm5zIHRoZSBmaXJzdCBvY2N1cnJlbmNlIHdpdGhpbiB0aGUgZW50aXJlIE9ic2VydmFibGUgc2Vxd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W0gdG8geWllbGQgb24gbmV4dC5cclxuICAgICAqIEByZXR1cm5zIHtGdW5jdGlvbn0gQSBmdW5jdGlvbiwgd2hlbiBleGVjdXRlZCB3aXRoIHRoZSByZXF1aXJlZCBwYXJhbWV0ZXJzIG1pbnVzIHRoZSBjYWxsYmFjaywgcHJvZHVjZXMgYW4gT2JzZXJ2YWJsZSBzZXF1ZW5jZSB3aXRoIGEgc2luZ2xlIHZhbHVlIG9mIHRoZSBhcmd1bWVudHMgdG8gdGhlIGNhbGxiYWNrIGFzIGFuIGFycmF5LlxyXG4gICAgICovXHJcbiAgICBPYnNlcnZhYmxlLmZyb21DYWxsYmFjayA9IGZ1bmN0aW9uIChmdW5jLCBzY2hlZHVsZXIsIGNvbnRleHQsIHNlbGVjdG9yKSB7XHJcbiAgICAgICAgc2NoZWR1bGVyIHx8IChzY2hlZHVsZXIgPSBpbW1lZGlhdGVTY2hlZHVsZXIpO1xyXG4gICAgICAgIHJldHVybiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHZhciBhcmdzID0gc2xpY2UuY2FsbChhcmd1bWVudHMsIDApO1xyXG5cclxuICAgICAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gaGFuZGxlcihlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciByZXN1bHRzID0gZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzZWxlY3Rvcikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRzID0gc2VsZWN0b3IoYXJndW1lbnRzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocmVzdWx0cy5sZW5ndGggPT09IDEpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRzID0gcmVzdWx0c1swXTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdHMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgYXJncy5wdXNoKGhhbmRsZXIpO1xyXG4gICAgICAgICAgICAgICAgICAgIGZ1bmMuYXBwbHkoY29udGV4dCwgYXJncyk7XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBDb252ZXJ0cyBhIE5vZGUuanMgY2FsbGJhY2sgc3R5bGUgZnVuY3Rpb24gdG8gYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZS4gIFRoaXMgbXVzdCBiZSBpbiBmdW5jdGlvbiAoZXJyLCAuLi4pIGZvcm1hdC5cclxuICAgICAqIEBwYXJhbSB7RnVuY3Rpb259IGZ1bmMgVGhlIGZ1bmN0aW9uIHRvIG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XJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gaGFuZGxlcihlcnIpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGVycikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgcmVzdWx0cyA9IHNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzZWxlY3Rvcikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRzID0gc2VsZWN0b3IocmVzdWx0cyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocmVzdWx0cy5sZW5ndGggPT09IDEpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRzID0gcmVzdWx0c1swXTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdHMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgYXJncy5wdXNoKGhhbmRsZXIpO1xyXG4gICAgICAgICAgICAgICAgICAgIGZ1bmMuYXBwbHkoY29udGV4dCwgYXJncyk7XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfTtcclxuICAgIH07XHJcblxyXG4gIGZ1bmN0aW9uIGNyZWF0ZUxpc3RlbmVyIChlbGVtZW50LCBuYW1lLCBoYW5kbGVyKSB7XHJcbiAgICAvLyBOb2RlLmpzIHNwZWNpZmljXHJcbiAgICBpZiAoZWxlbWVudC5hZGRMaXN0ZW5lcikge1xyXG4gICAgICBlbGVtZW50LmFkZExpc3RlbmVyKG5hbWUsIGhhbmRsZXIpO1xyXG4gICAgICByZXR1cm4gZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZWxlbWVudC5yZW1vdmVMaXN0ZW5lcihuYW1lLCBoYW5kbGVyKTtcclxuICAgICAgfSk7XHJcbiAgICB9IFxyXG4gICAgaWYgKGVsZW1lbnQuYWRkRXZlbnRMaXN0ZW5lcikge1xyXG4gICAgICBlbGVtZW50LmFkZEV2ZW50TGlzdGVuZXIobmFtZSwgaGFuZGxlciwgZmFsc2UpO1xyXG4gICAgICByZXR1cm4gZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZWxlbWVudC5yZW1vdmVFdmVudExpc3RlbmVyKG5hbWUsIGhhbmRsZXIsIGZhbHNlKTtc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mFtZSwgc2VsZWN0b3IpIHtcclxuICAgIGlmIChlbWJlcikge1xyXG4gICAgICByZXR1cm4gZnJvbUV2ZW50UGF0dGVybihcclxuICAgICAgICBmdW5jdGlvbiAoaCkgeyBFbWJlci5hZGRMaXN0ZW5lcihlbGVtZW50LCBldmVudE5hbWUsIGgpOyB9LFxyXG4gICAgICAgIGZ1bmN0aW9uIChoKSB7IEVtYmVyLnJlbW92ZUxpc3RlbmVyKGVsZW1lbnQsIGV2ZW50TmFtZSwgaCk7IH0sXHJcbiAgICAgICAgc2VsZWN0b3IpO1xyXG4gICAgfSAgICBcclxuICAgIGlmIChqcSkge1xyXG4gICAgICB2YXIgJGVsZW0gPSBqcShlbGVtZW50KTtcclxuICAgICAgcmV0dXJuIGZyb21FdmVudFBhdHRlcm4oXHJcbiAgICAgICAgZnVuY3Rpb24gKGgpIHsgJGVsZW0ub24oZXZlbnROYW1lLCBoKTsgfSxcclxuICAgICAgICBmdW5jdGlvbiAoaCkgeyAkZWxlbS5vZmYoZXZlbnROYW1lLCBoKTsgfSxcclxuICAgICAgICBzZWxlY3Rvcik7XHJcbiAgICB9XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHJldHVybiBjcmVhdGVFdmVudExpc3RlbmVyKFxyXG4gICAgICAgIGVsZW1lbnQsIFxyXG4gICAgICAgIGV2ZW50TmFtZSwgXHJcbiAgICAgICAgZnVuY3Rpb24gaGFuZGxlciAoZSkgeyBcclxuICAgICAgICAgIHZhciByZXN1bHRzID0gZTtcclxuXHJcbiAgICAgICAgICBpZiAoc2VsZWN0b3IpIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICByZXN1bHRzID0gc2VsZWN0b3IoYXJndW1lbnRzKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihl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hc1ZhbHVlQWxsID0gZmFsc2UsXHJcbiAgICAgICAgaXNEb25lID0gZmFsc2UsXHJcbiAgICAgICAgdmFsdWVzID0gbmV3IEFycmF5KG4pO1xyXG5cclxuICAgICAgZnVuY3Rpb24gbmV4dCh4LCBpKSB7XHJcbiAgICAgICAgdmFsdWVzW2ldID0geFxyXG4gICAgICAgIHZhciByZXM7XHJcbiAgICAgICAgaGFzVmFsdWVbaV0gPSB0cnVlO1xyXG4gICAgICAgIGlmIChoYXNWYWx1ZUFsbCB8fCAoaGFzVmFsdWVBbGwgPSBoYXNWYWx1ZS5ldmVyeShpZGVudGl0eSkpKSB7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICByZXMgPSByZXN1bHRTZWxlY3Rvci5hcHBseShudWxsLCB2YWx1ZXMpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZXgpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXMpO1xyXG4gICAgICAgIH0gZWxzZSBpZiAoaXNEb25lKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfVxyXG5cclxuICAgICAgcmV0dXJuIG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKFxyXG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICBuZXh0KHgsIDApO1xyXG4gICAgICAgICAgfSxcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGlzRG9uZSA9IHRydWU7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9KSxcclxuICAgICAgICBzdWJqZWN0LnN1YnNjcmliZShcclxuICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgIG5leHQoeCwgMSk7XHJcbiAgICAgICAgICB9LFxyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSlcclxuICAgICAgICApO1xyXG4gICAgfSk7XHJcbiAgfVxyXG5cclxuICB2YXIgUGF1c2FibGVCdWZmZXJlZE9ic2VydmFibGUgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG5cclxuICAgIGluaGVyaXRzKFBhdXNhYmxlQnVmZmVyZWRPYnNlcnZhYmxlLCBfc3VwZXIpO1xyXG5cclxuICAgIGZ1bmN0aW9uIHN1YnNjcmliZShvYnNlcnZlcikge1xyXG4gICAgICB2YXIgcSA9IFtdLCBwcmV2aW91cyA9IHRydWU7XHJcbiAgICAgIFxyXG4gICAgICB2YXIgc3Vic2NyaXB0aW9uID0gIFxyXG4gICAgICAgIGNvbWJpbmVMYXRlc3RTb3VyY2UoXHJcbiAgICAgICAgICB0aGlzLnNvdXJjZSxcclxuICAgICAgICAgIHRoaXMuc3ViamVjdC5kaXN0aW5jdFVudGlsQ2hhbmdlZCgpLCBcclxuICAgICAgICAgIGZ1bmN0aW9uIChkYXRhLCBzaG91bGRGaXJlKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB7IGRhdGE6IGRhdGEsIHNob3VsZEZpcmU6IHNob3VsZEZpcmUgfTsgICAgICBcclxuICAgICAgICAgIH0pXHJcbiAgICAgICAgICAuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAocmVzdWx0cykge1xyXG4gICAgICAgICAgICAgIGlmIChyZXN1bHRzLnNob3VsZEZpcmUgJiYgcHJldmlvdXMpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHRzLmRhdGEpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICBpZiAocmVzdWx0cy5zaG91bGRGaXJlICYmICFwcmV2aW91cykge1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHByZXZpb3VzID0gdHJ1ZTtcclxuICAgICAgICAgICAgICB9IGVsc2UgaWYgKCFyZXN1bHRzLnNob3VsZEZpcmUgJiYgIXByZXZpb3VzKSB7XHJcbiAgICAgICAgICAgICAgICBxLnB1c2gocmVzdWx0cy5kYXRhKTtcclxuICAgICAgICAgICAgICB9IGVsc2UgaWYgKCFyZXN1bHRzLnNob3VsZEZpcmUgJiYgcHJldmlvdXMpIHtcclxuICAgICAgICAgICAgICAgIHByZXZpb3VzID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgfSwgXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgICAgICAvLyBFbXB0eSBidWZmZXIgYmVmb3JlIHNlbmRpbmcgZXJyb3JcclxuICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgLy8gRW1wdHkgYnVmZmVyIGJlZm9yZSBzZW5kaW5nIGNvbXBsZXRpb25cclxuICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQ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gICAgICBlbmFibGVRdWV1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgICAgIHRoaXMuc3ViamVjdCA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgIHRoaXMuZW5hYmxlUXVldWUgPSBlbmFibGVRdWV1ZTtcclxuICAgICAgICAgICAgdGhpcy5xdWV1ZSA9IGVuYWJsZVF1ZXVlID8gW10gOiBudWxsO1xyXG4gICAgICAgICAgICB0aGlzLnJlcXVlc3RlZENvdW50ID0gMDtcclxuICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICB0aGlzLmVycm9yID0gbnVsbDtcclxuICAgICAgICAgICAgdGhpcy5oYXNGYWlsZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5oYXNDb21wbGV0ZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFkZFByb3BlcnRpZXMoQ29udHJvbGxlZFN1YmplY3QucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5oYXNDb21wbGV0ZWQgPSB0cnVlO1xyXG5cclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5lbmFibGVRdWV1ZSB8fCB0aGlzLnF1ZXVlLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXJyb3IpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHRoaXMuaGFzRmFpbGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IgPSBlcnJvcjtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuZW5hYmxlUXVldWUgfHwgdGhpcy5xdWV1ZS5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25FcnJvcihlcnJvcik7XHJcbiAgICAgICAgICAgICAgICB9ICAgXHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICB2YXIgaGFzUmVxdWVzdGVkID0gZmFsc2U7XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMucmVxdWVzdGVkQ291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5lbmFibGVRdWV1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnF1ZXVlLnB1c2godmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMucmVxdWVzdGVkQ291bnQgIT09IC0xKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50LS0gPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZUN1cnJlbnRSZXF1ZXN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzUmVxdWVzdGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzUmVxdWVzdGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIF9wcm9jZXNzUmVxdWVzdDogZnVuY3Rpb24gKG51bWJlck9mSXRlbXMpIHtcclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmVuYWJsZVF1ZXVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZygncXVldWUgbGVuZ3RoJywgdGhpcy5xdWV1ZS5sZW5ndGgpO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB3aGlsZSAodGhpcy5xdWV1ZS5sZW5ndGggPj0gbnVtYmVyT2ZJdGVtcyAmJiBudW1iZXJPZkl0ZW1zID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAvL2NvbnNvbGUubG9nKCdudW1iZXIgb2YgaXRlbXMnLCBudW1iZXJPZkl0ZW1zKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uTmV4dCh0aGlzLnF1ZXVlLnNoaWZ0KCkpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBudW1iZXJPZkl0ZW1zLS07XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5xdWV1ZS5sZW5ndGggIT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHsgbnVtYmVyT2ZJdGVtczogbnVtYmVyT2ZJdGVtcywgcmV0dXJuVmFsdWU6IHRydWUgfTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4geyBudW1iZXJPZkl0ZW1zOiBudW1iZXJPZkl0ZW1zLCByZXR1cm5WYWx1ZTogZmFsc2UgfTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuaGFzRmFpbGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uRXJyb3IodGhpcy5lcnJvcik7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5oYXNDb21wbGV0ZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmNvbnRyb2xsZWREaXNwb3NhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmNvbnRyb2xsZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUVtcHR5OyAgICAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICByZXR1cm4geyBudW1iZXJPZkl0ZW1zOiBudW1iZXJPZkl0ZW1zLCByZXR1cm5WYWx1ZTogZmFsc2UgfTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgcmVxdWVzdDogZnVuY3Rpb24gKG51bWJlcikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlQ3VycmVudFJlcXVlc3QoKTtcclxuICAgICAgICAgICAgICAgIHZhciBzZWxmID0gdGhpcyxcclxuICAgICAgICAgICAgICAgICAgICByID0gdGhpcy5fcHJvY2Vzc1JlcXVlc3QobnVtYmVyKTtcclxuXHJcbiAgICAgICAgICAgICAgICBudW1iZXIgPSByLm51bWJlck9mSXRlbXM7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXIucmV0dXJuVmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZENvdW50ID0gbnVtYmVyO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVDcmVhdGUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzZWxmLnJlcXVlc3RlZENvdW50ID0gMDtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZVxyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBkaXNwb3NlQ3VycmVudFJlcXVlc3Q6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgIH0sXHJcblxyXG4gICAgICAgICAgICBkaXNwb3NlOiBmdW5jdGlvbi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3ViamVjdCB0byByZWNlaXZlIHRoZSBsYXN0IChvciBpbml0aWFsKSB2YWx1ZSBhbmQgYWxsIHN1YnNlcXVlbnQgbm90aWZpY2F0aW9ucy5cclxuICAgICAqL1xyXG4gICAgdmFyIEJlaGF2aW9yU3ViamVjdCA9IFJ4LkJlaGF2aW9yU3ViamVjdCA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcbiAgICAgICAgZnVuY3Rpb24gc3Vic2NyaWJlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMucHVzaChvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodGhpcy52YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gbmV3IElubmVyU3Vic2NyaXB0aW9uKHRoaXMsIG9ic2VydmVyKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB2YXIgZXggPSB0aGlzLmV4Y2VwdGlvbjtcclxuICAgICAgICAgICAgaWYgKGV4KSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGluaGVyaXRzKEJlaGF2aW9yU3ViamVjdCwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICogIEluaXRpYWxpemVzIGEgbmV3IGluc3RhbmNlIG9mIHRoZSBCZWh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ICAgICAgICBcclxuICAgICAgICAgICAgaGFzT2JzZXJ2ZXJzOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5vYnNlcnZlcnMubGVuZ3RoID4gMDtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICovIFxyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGV4Y2VwdGlvbi5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gZXJyb3IgVGhlIGV4Y2VwdGlvbiB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZXhjZXB0aW9uID0gZXJyb3I7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkVycm9yKGVycm9yKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGFycml2YWwgb2YgdGhlIHNwZWNpZmllZCBlbGVtZW50IGluIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gdmFsdWUgVGhlIHZhbHVlIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnZhbHVlID0gdmFsdWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogVW5zdWJzY3JpYmUgYWxsIG9ic2VydmVycyBhbmQgcmVsZWFzZSByZXNvdXJjZXMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBkaXNwb3NlOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgdGhpcy52YWx1ZSA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmV4Y2VwdGlvbiA9IG51bGw7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9KTtcclxuXHJcbiAgICAgICAgcmV0dXJuIEJlaGF2aW9yU3ViamVjdDtcclxuICAgIH0oT2JzZXJ2YWJsZSkpO1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogUmVwcmVzZW50cyBhbiBvYmplY3QgdGhhdCBpcyBib3RoIGFuIG9ic2VydmFibGUgc2VxdWVuY2UgYXMgd2VsbCBhcyBhbiBvYnN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ic2NyaXB0aW9uID0gbmV3IFJlbW92YWJsZURpc3Bvc2FibGUodGhpcywgc28pO1xyXG4gICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIHRoaXMuX3RyaW0odGhpcy5zY2hlZHVsZXIubm93KCkpO1xyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmVycy5wdXNoKHNvKTtcclxuXHJcbiAgICAgICAgICAgIHZhciBuID0gdGhpcy5xLmxlbmd0aDtcclxuXHJcbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSB0aGlzLnEubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgIHNvLm9uTmV4dCh0aGlzLnFbaV0udmFsdWUpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBpZiAodGhpcy5oYXNFcnJvcikge1xyXG4gICAgICAgICAgICAgICAgbisrO1xyXG4gICAgICAgICAgICAgICAgc28ub25FcnJvcih0aGlzLmVycm9yKTtcclxuICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgbisrO1xyXG4gICAgICAgICAgICAgICAgc28ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgc28uZW5zdXJlQWN0aXZlKG4pO1xyXG4gICAgICAgICAgICByZXR1cm4gc3Vic2NyaXB0aW9uO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaW5oZXJpdHMoUmVwbGF5U3ViamVjdCwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogIEluaXRpYWxpemVzIGEgbmV3IGluc3RhbmNlIG9mIHRoZSBSZXBsYXlTdWJqZWN0IGNsYXNzIHdpdGggdGhlIHNwZWNpZmllZCBidWZmZXIgc2l6ZSwgd2luZG93IHNpemUgYW5kIHNjaGVkdW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bCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgYWRkUHJvcGVydGllcyhSZXBsYXlTdWJqZWN0LnByb3RvdHlwZSwgT2JzZXJ2ZXIsIHtcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIEluZGljYXRlcyB3aGV0aGVyIHRoZSBzdWJqZWN0IGhhcyBvYnNlcnZlcnMgc3Vic2NyaWJlZCB0byBpdC5cclxuICAgICAgICAgICAgICogQHJldHVybnMge0Jvb2xlYW59IEluZGljYXRlcyB3aGV0aGVyIHRoZSBzdWJqZWN0IGhhcyBvYnNlcnZlcnMgc3Vic2NyaWJlZCB0byBpdC5cclxuICAgICAgICAgICAgICovICAgICAgICAgXHJcbiAgICAgICAgICAgIGhhc09ic2VydmVyczogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMub2JzZXJ2ZXJzLmxlbmd0aCA+IDA7XHJcbiAgICAgICAgICAgIH0sICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIC8qIEBwcml2YXRlICAqL1xyXG4gICAgICAgICAgICBfdHJpbTogZnVuY3Rpb24gKG5vdykge1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHRoaXMucS5sZW5ndGggPiB0aGlzLmJ1ZmZlclNpemUpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHdoaWxlICh0aGlzLnEubGVuZ3RoID4gMCAmJiAobm93IC0gdGhpcy5xWzBdLmludGVydmFsKSA+IHRoaXMud2luZG93U2l6ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBhcnJpdmFsIG9mIHRoZSBzcGVjaWZpZWQgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IHZhbHVlIFRoZSB2YWx1ZSB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgb2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG5vdyA9IHRoaXMuc2NoZWR1bGVyLm5vdygpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucS5wdXNoKHsgaW50ZXJ2YWw6IG5vdywgdmFsdWU6IHZhbHVlIH0pO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3RyaW0obm93KTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG8gPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gby5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlciA9IG9baV07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLmVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZXhjZXB0aW9uLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSBlcnJvciBUaGUgZXhjZXB0aW9uIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgb2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IgPSBlcnJvcjtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmhhc0Vycm9yID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbm93ID0gdGhpcy5zY2hlZHVsZXIubm93KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fdHJpbShub3cpO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG8ubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIgPSBvW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycm9yKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIuZW5zdXJlQWN0aXZlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGVuZCBvZiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBvYnNlcnZlcjtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG5vdyA9IHRoaXMuc2NoZWR1bGVyLm5vdygpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3RyaW0obm93KTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyID0gb1tpXTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIuZW5zdXJlQWN0aXZlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBVbnN1YnNjcmliZSBhbGwgb2JzZXJ2ZXJzIGFuZCByZWxlYXNlIHJlc291cmNlcy5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIGRpc3Bvc2U6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IG51bGw7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9KTtcclxuXHJcbiAgICAgICAgcmV0dXJuIFJlcGxheVN1YmplY3Q7XHJcbiAgICB9KE9ic2VydmFibGUpKTtcclxuXHJcbiAgICAvKiogQHByaXZhdGUgKi9cclxuICAgIHZhciBDb25uZWN0YWJsZU9ic2VydmFibGUgPSBSeC5Db25uZWN0YWJsZU9ic2VydmFibGUgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG4gICAgICAgIGluaGVyaXRzKENvbm5lY3RhYmxlT2JzZXJ2YWJsZSwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBDb25uZWN0YWJsZU9ic2VydmFibGUoc291cmNlLCBzdWJqZWN0KSB7XHJcbiAgICAgICAgICAgIHZhciBzdGF0ZSA9IHtcclxuICAgICAgICAgICAgICAgIHN1YmplY3Q6IHN1YmplY3QsXHJcbiAgICAgICAgICAgICAgICBzb3VyY2U6IHNvdXJjZS5hc09ic2VydmFibGUoKSxcclxuICAgICAgICAgICAgICAgIGhhc1N1YnNjcmlwdGlvbjogZmFsc2UsXHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb246IG51bGxcclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIHRoaXMuY29ubmVjdCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghc3RhdGUuaGFzU3Vic2NyaXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGFzU3Vic2NyaXB0aW9uID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBzdGF0ZS5zdWJzY3JpcHRpb24gPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShzdGF0ZS5zb3VyY2Uuc3Vic2NyaWJlKHN0YXRlLnN1YmplY3QpLCBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGFzU3Vic2NyaXB0aW9uID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHN0YXRlLnN1YnNjcmlwdGlvbjtcclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIHN1YnNjcmliZShvYnNlcnZlcikge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHN0YXRlLnN1YmplY3Quc3Vic2NyaWJlKG9ic2VydmVyKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIENvbm5lY3RhYmxlT2JzZXJ2YWJsZVxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIENvbm5lY3RhYmxlT2JzZXJ2YWJsZS5wcm90b3R5cGUuY29ubmVjdCA9IGZ1bmN0aW9uICgpIHsgcmV0dXJuIHRoaXMuY29ubmVjdCgpOyB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBDb25uZWN0YWJsZU9ic2VydmFibGVcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIENvbm5lY3RhYmxlT2JzZXJ2YWJsZS5wcm90b3R5cGUucmVmQ291bnQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHZhciBjb25uZWN0YWJsZVN1YnNjcmlwdGlvbiA9IG51bGwsIGNvdW50ID0gMCwgc291cmNlID0gdGhpcztcclxuICAgICAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICAgICAgdmFyIHNob3VsZENvbm5lY3QsIHN1YnNjcmlwdGlvbjtcclxuICAgICAgICAgICAgICAgIGNvdW50Kys7XHJcbiAgICAgICAgICAgICAgICBzaG91bGRDb25uZWN0ID0gY291bnQgPT09IDE7XHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24gPSBzb3VyY2Uuc3Vic2NyaWJlKG9ic2VydmVyKTtcclxuICAgICAgICAgICAgICAgIGlmIChzaG91bGRDb25uZWN0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgY29ubmVjdGFibGVTdWJzY3JpcHRpb24gPSBzb3VyY2UuY29ubmVjdCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVDcmVhdGUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgY291bnQtLTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoY291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgIC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09IDApIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBudW0yICs9IDI7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiB0cnVlO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIGdldFByaW1lKG1pbikge1xyXG4gICAgICAgIHZhciBpbmRleCwgbnVtLCBjYW5kaWRhdGU7XHJcbiAgICAgICAgZm9yIChpbmRleCA9IDA7IGluZGV4IDwgcHJpbWVzLmxlbmd0aDsgKytpbmRleCkge1xyXG4gICAgICAgICAgICBudW0gPSBwcmltZXNbaW5kZXhdO1xyXG4gICAgICAgICAgICBpZiAobnVtID49IG1pbikge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG51bTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICBjYW5kaWRhdGUgPSBtaW4gfCAxO1xyXG4gICAgICAgIHdoaWxlIChjYW5kaWRhdGUgPCBwcmltZXNbcHJpbWVzLmxlbmd0aCAtIDFdKSB7XHJcbiAgICAgICAgICAgIGlmIChpc1ByaW1lKGNhbmRpZGF0ZSkpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBjYW5kaWRhdGU7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgY2FuZGlkYXRlICs9IDI7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBtaW47XHJcbiAgICB9XHJcblxyXG4gICAgZnVuY3Rpb24gc3RyaW5nSGFzaEZuKHN0cikge1xyXG4gICAgICAgIHZhciBoYXNoID0gNzU3NjAyMDQ2O1xyXG4gICAgICAgIGlmICghc3RyLmxlbmd0aCkge1xyXG4gICAgICAgICAgICByZXR1cm4gaGFzaDtcclxuICAgICAgICB9XHJcbiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IHN0ci5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICB2YXIgY2hhcmFjdGVyID0gc3RyLmNoYXJDb2RlQXQoaSk7XHJcbiAgICAgICAgICAgIGhhc2ggPSAoKGhhc2g8PDUpLWhhc2gpK2NoYXJhY3RlcjtcclxuICAgICAgICAgICAgaGFzaCA9IGhhc2ggJiBoYXNoO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gaGFzaDtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBudW1iZXJIYXNoRm4oa2V5KSB7XHJcbiAgICAgICAgdmFyIGMyID0gMHgyN2Q0ZWIyZDsgXHJcbiAgICAgICAga2V5ID0gKGtleSBeIDYxKSBeIChrZXkgPj4+IDE2KTtcclxuICAgICAgICBrZXkgPSBrZXkgKyAoa2V5IDw8IDMpO1xyXG4gICAgICAgIGtleSA9IGtleSBeIChrZXkgPj4+IDQpO1xyXG4gICAgICAgIGtleSA9IGtleSAqIGMyO1xyXG4gICAgICAgIGtleSA9IGtleSBeIChrZXkgPj4+IDE1KTtcclxuICAgICAgICByZXR1cm4ga2V5O1xyXG4gICAgfVxyXG5cclxuICAgIHZhciBnZXRIYXNoQ29kZSA9IChmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgdmFyIHVuaXF1ZUlkQ291bnRlciA9IDA7XHJcblxyXG4gICAgICAgIHJldHVybiBmdW5jdGlvbiAob2JqKSB7XHJcbiAgICAgICAgICAgIGlmIChvYmogPT0gbnVsbCkgeyBcclxuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihub1N1Y2hrZXkpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAvLyBDaGVjayBmb3IgYnVpbHQtaW5zIGJlZm9yZSB0YWNraW5nIG9uIG91ciBvd24gZm9yIGFueSBvYmplY3RcclxuICAgICAgICAgICAgaWYgKHR5cGVvZiBvYmogPT09ICdzdHJpbmcnKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gc3RyaW5nSGFzaEZuKG9iaik7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIGlmICh0eXBlb2Ygb2JqID09PSAnbnVtYmVyJykge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG51bWJlckhhc2hGbihvYmopO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBpZiAodHlwZW9mIG9iaiA9PT0gJ2Jvb2xlYW4nKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gb2JqID09PSB0cnVlID8gMSA6IDA7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIGlmIChvYmogaW5zdGFuY2VvZiBEYXRlKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gb2JqLmdldFRpbWUoKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgaWYgKG9iai5nZXRIYXNoQ29kZSkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG9iai5nZXRIYXNoQ29kZSgpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICB2YXIgaWQgPSAxNyAqIHVuaXF1ZUlkQ291bnRlcisrO1xyXG4gICAgICAgICAgICBvYmouZ2V0SGFzaENvZGUgPSBmdW5jdGlvbiAoKSB7IHJldHVybiBpZDsgfTtcclxuICAgICAgICAgICAgcmV0dXJuIGlkO1xyXG4gICAgICAgIH07XHJcbiAgICB9ICgpKTtcclxuXHJcbiAgICBmdW5jdGlvbiBuZXdFbnRyeSgpIHtcclxuICAgICAgICByZXR1cm4geyBrZXk6IG51bGwsIHZhbHVlOiBudWxsLCBuZXh0OiAwLCBoYXNoQ29kZTogMCB9O1xyXG4gICAgfVxyXG5cclxuICAgIC8vIERpY3Rpb25hcnkgaW1wbGVtZW50YXRpb25cclxuXHJcbiAgICB2YXIgRGljdGlvbmFyeSA9IGZ1bmN0aW9uIChjYXBhY2l0eSwgY29tcGFyZXIpIHtcclxuICAgICAgICBpZiAoY2FwYWNpdHkgPCAwKSB7XHJcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignb3V0IG9mIHJhbmdlJylcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKGNhcGFjaXR5ID4gMCkge1xyXG4gICAgICAgICAgICB0aGlzLl9pbml0aWFsaXplKGNhcGFjaXR5KTtcclxuICAgICAgICB9XHJcbiAgICAgICAgXHJcbiAgICAgICAgdGhpcy5jb21wYXJlciA9IGNvbXBhcmVyIHx8IGRlZmF1bHRDb21wYXJlcjtcclxuICAgICAgICB0aGlzLmZyZWVDb3VudCA9IDA7XHJcbiAgICAgICAgdGhpcy5zaXplID0gMDtcclxuICAgICAgICB0aGlzLmZyZWVMaXN0ID0gLTE7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLl9pbml0aWFsaXplID0gZnVuY3Rpb24gKGNhcGFjaXR5KSB7XHJcbiAgICAgICAgdmFyIHByaW1lID0gZ2V0UHJpbWUoY2FwYWNpdHkpLCBpO1xyXG4gICAgICAgIHRoaXMuYnVja2V0cyA9IG5ldyBBcnJheShwcmltZSk7XHJcbiAgICAgICAgdGhpcy5lbnRyaWVzID0gbmV3IEFycmF5KHByaW1lKTtcclxuICAgICAgICBmb3IgKGkgPSAwOyBpIDwgcHJpbWU7IGkrKykge1xyXG4gICAgICAgICAgICB0aGlzLmJ1Y2tldHNbaV0gPSAtMTtcclxuICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2ldID0gbmV3RW50cnkoKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgdGhpcy5mcmVlTGlzdCA9IC0xO1xyXG4gICAgfTtcclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLmNvdW50ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHJldHVybiB0aGlzLnNpemU7XHJcbiAgICB9O1xyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUuYWRkID0gZnVuY3Rpb24gKGtleSwgdmFsdWUpIHtcclxuICAgICAgICByZXR1c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AgICAgICAgdmFyIGVudHJ5QXJyYXkgPSBuZXcgQXJyYXkocHJpbWUpO1xyXG4gICAgICAgIGZvciAoaW5kZXggPSAwOyBpbmRleCA8IHRoaXMuc2l6ZTsgKytpbmRleCkge1xyXG4gICAgICAgICAgICBlbnRyeUFycmF5W2luZGV4XSA9IHRoaXMuZW50cmllc1tpbmRleF07XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGZvciAodmFyIGluZGV4ID0gdGhpcy5zaXplOyBpbmRleCA8IHByaW1lOyArK2luZGV4KSB7XHJcbiAgICAgICAgICAgIGVudHJ5QXJyYXlbaW5kZXhdID0gbmV3RW50cnkoKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgZm9yICh2YXIgaW5kZXgxID0gMDsgaW5kZXgxIDwgdGhpcy5zaXplOyArK2luZGV4MSkge1xyXG4gICAgICAgICAgICB2YXIgaW5kZXgyID0gZW50cnlBcnJheVtpbmRleDFdLmhhc2hDb2RlICUgcHJpbWU7XHJcbiAgICAgICAgICAgIGVudHJ5QXJyYXlbaW5kZXgxXS5uZXh0ID0gbnVtQXJyYXlbaW5kZXgyXTtcclxuICAgICAgICAgICAgbnVtQXJyYXlbaW5kZXgyXSA9IGluZGV4MTtcclxuICAgICAgICB9XHJcbiAgICAgICAgdGhpcy5idWNrZXRzID0gbnVtQXJyYXk7XHJcbiAgICAgICAgdGhpcy5lbnRyaWVzID0gZW50cnlBcnJheTtcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUucmVtb3ZlID0gZnVuY3Rpb24gKGtleSkge1xyXG4gICAgICAgIGlmICh0aGlzLmJ1Y2tldHMpIHtcclxuICAgICAgICAgICAgdmFyIG51bSA9IGdldEhhc2hDb2RlKGtleSkgJiAyMTQ3NDgzNjQ3O1xyXG4gICAgICAgICAgICB2YXIgaW5kZXgxID0gbnVtICUgdGhpcy5idWNrZXRzLmxlbmd0aDtcclxuICAgICAgICAgICAgdmFyIGluZGV4MiA9IC0xO1xyXG4gICAgICAgICAgICBmb3IgKHZhciBpbmRleDMgPSB0aGlzLmJ1Y2tldHNbaW5kZXgxXTsgaW5kZXgzID49IDA7IGluZGV4MyA9IHRoaXMuZW50cmllc1tpbmRleDNdLm5leHQpIHtcclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmVudHJpZXNbaW5kZXgzXS5oYXNoQ29kZSA9PT0gbnVtICYmIHRoaXMuY29tcGFyZXIodGhpcy5lbnRyaWVzW2luZGV4M10ua2V5LCBrZXkpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGluZGV4MiA8IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5idWNrZXRzW2luZGV4MV0gPSB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0O1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDJdLm5leHQgPSB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0O1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5oYXNoQ29kZSA9IC0xO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLm5leHQgPSB0aGlzLmZyZWVMaXN0O1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLmtleSA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10udmFsdWUgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZnJlZUxpc3QgPSBpbmRleDM7XHJcbiAgICAgICAgICAgICAgICAgICAgKyt0aGlzLmZyZWVDb3VudDtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaW5kZXgyID0gaW5kZXgzO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBmYWxzZTtcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUuY2xlYXIgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgdmFyIGluZGV4LCBsZW47XHJcbiAgICAgICAgaWYgKHRoaXMuc2l6ZSA8PSAwKSB7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcbiAgICAgICAgZm9yIChpbmRleCA9IDAsIGxlbiA9IHRoaXMuYnVja2V0cy5sZW5ndGg7IGluZGV4IDwgbGVuOyArK2luZGV4KSB7XHJcbiAgICAgICAgICAgIHRoaXMuYnVja2V0c1tpbmRleF0gPSAtMTtcclxuICAgICAgICB9XHJcbiAgICAgICAgZm9yIChpbmRleCA9IDA7IGluZGV4IDwgdGhpcy5zaXplOyArK2luZGV4KSB7XHJcbiAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleF0gPSBuZXdFbnRyeSgpO1xyXG4gICAgICAgIH1cclxuICAgICAgICB0aGlzLmZyZWVMaXN0ID0gLTE7XHJcbiAgICAgICAgdGhpcy5zaXplID0gMDtcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUuX2ZpbmRFbnRyeSA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgICBpZiAodGhpcy5idWNrZXRzKSB7XHJcbiAgICAgICAgICAgIHZhciBudW0gPSBnZXRIYXNoQ29kZShrZXkpICYgMjE0NzQ4MzY0NztcclxuICAgICAgICAgICAgZm9yICh2YXIgaW5kZXggPSB0aGlzLmJ1Y2tldHNbbnVtICUgdGhpcy5idWNrZXRzLmxlbmd0aF07IGluZGV4ID49IDA7IGluZGV4ID0gdGhpcy5lbnRyaWVzW2luZGV4XS5uZXh0KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5lbnRyaWVzW2luZGV4XS5oYXNoQ29kZSA9PT0gbnVtICYmIHRoaXMuY29tcGFyZXIodGhpcy5lbnRyaWVzW2luZGV4XS5rZXksIGtleSkpIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaW5kZXg7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIC0xO1xyXG4gICAgfTtcclxuXHJcbiAgICBEaWN0aW9uYXJ5LnByb3RvdHlwZS5jb3VudCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICByZXR1cm4gdGhpcy5zaXplIC0gdGhpcy5mcmVlQ291bnQ7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLnRyeUdldFZhbHVlID0gZnVuY3Rpb24gKGtleSkge1xyXG4gICAgICAgIHZhciBlbnRyeSA9IHRoaXMuX2ZpbmRFbnRyeShrZXkpO1xyXG4gICAgICAgIGlmIChlbnRyeSA+PSAwKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLmVudHJpZXNbZW50cnldLnZhbHVlO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gdW5kZWZpbmVkO1xyXG4gICAgfTtcclxuXHJcbiAgICBEaWN0aW9uYXJ5LnByb3RvdHlwZS5nZXRWYWx1ZXMgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgdmFyIGluZGV4ID0gMCwgcmVzdWx0cyA9IFtdO1xyXG4gICAgICAgIGlmICh0aGlzLmVudHJpZXMpIHtcclxuICAgICAgICAgICAgZm9yICh2YXIgaW5kZXgxID0gMDsgaW5kZXgxIDwgdGhpcy5zaXplOyBpbmRleDErKykge1xyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuZW50cmllc1tpbmRleDFdLmhhc2hDb2RlID49IDApIHtcclxuICAgICAgIC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VsZW1lbnRzIHRoYXQgaGF2ZSBhbiBvdmVybGFwcGluZyBkdXJhdGlvbi5cclxuICAgICAqLyAgICBcclxuICAgIG9ic2VydmFibGVQcm90by5qb2luID0gZnVuY3Rpb24gKHJpZ2h0LCBsZWZ0RHVyYXRpb25TZWxlY3RvciwgcmlnaHREdXJhdGlvblNlbGVjdG9yLCByZXN1bHRTZWxlY3Rvcikge1xyXG4gICAgICAgIHZhciBsZWZ0ID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBncm91cCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgIGxlZnREb25lID0gZmFsc2UsXHJcbiAgICAgICAgICAgIGxlZnRJZCA9IDAsXHJcbiAgICAgICAgICAgIGxlZnRNYXAgPSBuZXcgRGljdGlvbmFyeSgpLFxyXG4gICAgICAgICAgICByaWdodERvbmUgPSBmYWxzZSxcclxuICAgICAgICAgICAgcmlnaHRJZCA9IDAsXHJcbiAgICAgICAgICAgIHJpZ2h0TWFwID0gbmV3IERpY3Rpb25hcnkoKTtcclxuICAgICAgICAgICAgZ3JvdXAuYWRkKGxlZnQuc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uLFxyXG4gICAgICAgICAgICAgICAgZXhwaXJlLFxyXG4gICAgICAgICAgICAgICAgaWQgPSBsZWZ0SWQrKyxcclxuICAgICAgICAgICAgICAgIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICByZXN1bHQsXHJcbiAgICAgICAgICAgICAgICB2YWx1ZXM7XHJcbiAgICAgICAgICAgICAgICBsZWZ0TWFwLmFkZChpZCwgdmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgZ3JvdXAuYWRkKG1kKTtcclxuICAgICAgICAgICAgICAgIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAobGVmdE1hcC5yZW1vdmUoaWQpICYmIGxlZnRNYXAuY291bnQoKSA9PT0gMCAmJiBsZWZ0RG9uZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZ3JvdXAucmVtb3ZlKG1kKTtcclxuICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uID0gbGVmdER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShub29wLCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7IGV4cGlyZSgpOyB9KSk7XHJcbiAgICAgICAgICAgICAgICB2YWx1ZXMgPSByaWdodE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgdmFsdWVzLmxlbmd0aDsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3IodmFsdWUsIHZhbHVlc1tpXSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgbGVmdERvbmUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgaWYgKHJpZ2h0RG9uZSB8fCBsZWZ0TWFwLmNvdW50KCkgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIGdyb3VwLmFkZChyaWdodC5zdWJzY3JpYmUoZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgZHVyYXRpb24sXHJcbiAgICAgICAgICAgICAgICBleHBpcmUsXHJcbiAgICAgICAgICAgICAgICBpZCA9IHJpZ2h0SWQrKyxcclxuICAgICAgICAgICAgICAgIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICByZXN1bHQsXHJcbiAgICAgICAgICAgICAgICB2YWx1ZXM7XHJcbiAgICAgICAgICAgICAgICByaWdodE1hcC5hZGQoaWQsIHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcbiAgICAgICAgICAgICAgICBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHJpZ2h0TWFwLnJlbW92ZShpZCkgJiYgcmlnaHRNYXAuY291bnQoKSA9PT0gMCAmJiByaWdodERvbmUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbiA9IHJpZ2h0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgbWQuc2V0RGlzcG9zYWJsZShkdXJhdGlvbi50YWtlKDEpLnN1YnNjcmliZShub29wLCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7IGV4cGlyZSgpOyB9KSk7XHJcbiAgICAgICAgICAgICAgICB2YWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCB2YWx1ZXMubGVuZ3RoOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3Rvcih2YWx1ZXNbaV0sIHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRp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VyYXRpb24uXHJcbiAgICAgKi8gICAgXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8uZ3JvdXBKb2luID0gZnVuY3Rpb24gKHJpZ2h0LCBsZWZ0RHVyYXRpb25TZWxlY3RvciwgcmlnaHREdXJhdGlvblNlbGVjdG9yLCByZXN1bHRTZWxlY3Rvcikge1xyXG4gICAgICAgIHZhciBsZWZ0ID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBub3RoaW5nID0gZnVuY3Rpb24gKCkge307XHJcbiAgICAgICAgICAgIHZhciBncm91cCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIHZhciByID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShncm91cCk7XHJcbiAgICAgICAgICAgIHZhciBsZWZ0TWFwID0gbmV3IERpY3Rpb25hcnkoKTtcclxuICAgICAgICAgICAgdmFyIHJpZ2h0TWFwID0gbmV3IERpY3Rpb25hcnkoKTtcclxuICAgICAgICAgICAgdmFyIGxlZnRJRCA9IDA7XHJcbiAgICAgICAgICAgIHZhciByaWdodElEID0gMDtcclxuXHJcbiAgICAgICAgICAgIGdyb3VwLmFkZChsZWZ0LnN1YnNjcmliZShcclxuICAgICAgICAgICAgICAgIGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgaWQgPSBsZWZ0SUQrKztcclxuICAgICAgICAgICAgICAgICAgICBsZWZ0TWFwLmFkZChpZCwgcyk7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGksIGxlbiwgbGVmdFZhbHVlcywgcmlnaHRWYWx1ZXM7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3IodmFsdWUsIGFkZFJlZihzLCByKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gbGVmdFZhbHVlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHJpZ2h0VmFsdWVzID0gcmlnaHRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gcmlnaHRWYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcy5vbk5leHQocmlnaHRWYWx1ZXNbaV0pO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZ3JvdXAuYWRkKG1kKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlZnRNYXAucmVtb3ZlKGlkKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKG1kKTtcclxuICAgICAgICAgICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB2YXIgZHVyYXRpb247XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZHVyYXRpb24gPSBsZWZ0RHVyYXRpb25TZWxlY3Rvcih2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gbGVmdE1hcC5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG5vdGhpbmcsXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGxlZnRWYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzW2ldLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBleHBpcmUpXHJcbiAgICAgICAgICAgICAgICAgICAgKTtcclxuICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBsZWZ0VmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gbGVmdFZhbHVlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzW2ldLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpKTtcclxuXHJcbiAgICAgICAgICAgIGdyb3VwLmFkZChyaWdodC5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbGVmdFZhbHVlcywgaSwgbGVuO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBpZCA9IHJpZ2h0SUQrKztcclxuICAgICAgICAgICAgICAgICAgICByaWdodE1hcC5hZGQoaWQsIHZhbHVlKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG1kID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZ3JvdXAuYWRkKG1kKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGV4cGlyZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmlnaHRNYXAucmVtb3ZlKGlkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKG1kKTtcclxuICAgICAgICAgICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB2YXIgZHVyYXRpb247XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZHVyYXRpb24gPSByaWdodER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGxlZnRNYXAubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXNbaV0ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG5vdGhpbmcsXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGxlZnRNYXAubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzW2ldLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBleHBpcmUpXHJcbiAgICAgICAgICAgICAgICAgICAgKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gbGVmdFZhbHVlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzW2ldLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGxlZnRWYWx1ZXMgPSBsZWZ0TWF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cbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSkpO1xyXG5cclxuICAgICAgICAgICAgZC5hZGQod2luZG93Qm91bmRhcmllcy5zdWJzY3JpYmUoZnVuY3Rpb24gKHcpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgd2luZG93ID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYod2luZG93LCByKSk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSkpO1xyXG5cclxuICAgICAgICAgICAgcmV0dXJuIHI7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9XHJcblxyXG4gICAgZnVuY3Rpb24gb2JzZXJ2YWJsZVdpbmRvd1dpdGhDbG9zaW5nU2VsZWN0b3Iod2luZG93Q2xvc2luZ1NlbGVjdG9yKSB7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgY3JlYXRlV2luZG93Q2xvc2UsXHJcbiAgICAgICAgICAgICAgICBtID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIGQgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShtKSxcclxuICAgICAgICAgICAgICAgIHIgPSBuZXcgUmVmQ291bnREaXNwb3NhYmxlKGQpLFxyXG4gICAgICAgICAgICAgICAgd2luZG93ID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZih3aW5kb3csIHIpKTtcclxuICAgICAgICAgICAgZC5hZGQoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGV4KSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIGNyZWF0ZVdpbmRvd0Nsb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG0xLCB3aW5kb3dDbG9zZTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgd2luZG93Q2xvc2UgPSB3aW5kb3dDbG9zaW5nU2VsZWN0b3IoKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBtMSA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgbS5zZXREaXNwb3NhYmxlKG0xKTtcclxuICAgICAgICAgICAgICAgIG0xLnNldERpc3Bvc2FibGUod2luZG93Q2xvc2UudGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgZnVuY3Rpb24gKGV4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgd2luZG93Lm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHdpbmRvdy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHdpbmRvdyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZih3aW5kb3csIHIpKTtcclxuICAgICAgICAgICAgICAgICAgICBjcmVhdGVXaW5kb3dDbG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICBjcmVhdGVXaW5kb3dDbG9zZSgpO1xyXG4gICAgICAgICAgICByZXR1cm4gcjtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgLyoqXHJcbiAgICogUmV0dXJucyBhIG5ldyBvYnNlcnZhYmxlIHRoYXQgdHJpZ2dlcnMgb24gdGhlIHNlY29uZCBhbmQgc3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nNlcnZhYmxlUHJvdG8uZXhwYW5kID0gZnVuY3Rpb24gKHNlbGVjdG9yLCBzY2hlZHVsZXIpIHtcclxuICAgICAgICBzY2hlZHVsZXIgfHwgKHNjaGVkdWxlciA9IGltbWVkaWF0ZVNjaGVkdWxlcik7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgcSA9IFtdLFxyXG4gICAgICAgICAgICAgICAgbSA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICBkID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUobSksXHJcbiAgICAgICAgICAgICAgICBhY3RpdmVDb3VudCA9IDAsXHJcbiAgICAgICAgICAgICAgICBpc0FjcXVpcmVkID0gZmFsc2U7XHJcblxyXG4gICAgICAgICAgICB2YXIgZW5zdXJlQWN0aXZlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGlzT3duZXIgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBpc093bmVyID0gIWlzQWNxdWlyZWQ7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNBY3F1aXJlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaXNPd25lcikge1xyXG4gICAgICAgICAgICAgICAgICAgIG0uc2V0RGlzcG9zYWJsZShzY2hlZHVsZXIuc2NoZWR1bGVSZWN1cnNpdmUoZnVuY3Rpb24gKHNlbGYpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHdvcms7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmsgPSBxLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc0FjcXVpcmVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIG0xID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGQuYWRkKG0xKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbTEuc2V0RGlzcG9zYWJsZSh3b3JrLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHJlc3VsdCA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBxLnB1c2gocmVzdWx0KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFjdGl2ZUNvdW50Kys7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbnN1cmVBY3RpdmUoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZC5yZW1vdmUobTEpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgYWN0aXZlQ291bnQtLTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhY3RpdmVDb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc2VsZigpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIHEucHVzaChzb3VyY2UpO1xyXG4gICAgICAgICAgICBhY3RpdmVDb3VudCsrO1xyXG4gICAgICAgICAgICBlbnN1cmVBY3RpdmUoKTtcclxuICAgICAgICAgICAgcmV0dXJuIGQ7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgLyoqXHJcbiAgICogIFJ1bnMgYWxsIG9ic2VydmFibGUgc2VxdWVuY2VzIGluIHBhcmFsbGVsIGFuZCBjb2xsZWN0IHRoZWlyIGxhc3QgZWxlbWVudHMuXHJcbiAgICogIFxyXG4gICAqIEBleGFtcGxlXHJcbiAgICogIDEgLSByZXMgPSBSeC5PYnNlcnZhYmxlLmZvcmtKb2luKFtvYnMxLCBvYnMyXSk7XHJcbiAgICogIDEgLSByZXMgPSBSeC5PYnNlcnZhYmxlLmZvcmtKb2luKG9iczEsIG9iczIsIC4uLik7ICBcclxuICAgKiBAcmV0dXJucyB7T2JzZXJ2YWJsZX0gQW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSB3aXRoIGFuIGFycmF5IGNvbGxlY3RpbmcgdGhlIGxhc3Q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tcclxuICAgICAgICAgICAgICBpZiAoIWZpbmlzaGVkKSB7XHJcbiAgICAgICAgICAgICAgICBoYXNSZXN1bHRzW2ldID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHJlc3VsdHNbaV0gPSB2YWx1ZTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgIGZpbmlzaGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgZ3JvdXAuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9LCBcclxuICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgIGlmICghZmluaXNoZWQpIHtcclxuICAgICAgICAgICAgICAgIGlmICghaGFzUmVzdWx0c1tpXSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBoYXNDb21wbGV0ZWRbaV0gPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaXggPSAwOyBpeCA8IGNvdW50OyBpeCsrKSB7XHJcbiAgICAgICAgICAgICAgICAgIGlmICghaGFzQ29tcGxldGVkW2l4XSkgeyByZXR1cm47IH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGZpbmlzaGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIub25OZXh0KHJlc3VsdHMpO1xyXG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgIH0pKGlkeCk7XHJcb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xlZnRTdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKSwgcmlnaHRTdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuXHJcbiAgICAgIGlzUHJvbWlzZShzZWNvbmQpICYmIChzZWNvbmQgPSBvYnNlcnZhYmxlRnJvbVByb21pc2Uoc2Vjb25kKSk7XHJcblxyXG4gICAgICBsZWZ0U3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoXHJcbiAgICAgICAgICBmaXJzdC5zdWJzY3JpYmUoZnVuY3Rpb24gKGxlZnQpIHtcclxuICAgICAgICAgICAgaGFzTGVmdCA9IHRydWU7XHJcbiAgICAgICAgICAgIGxhc3RMZWZ0ID0gbGVmdDtcclxuICAgICAgICAgIH0sIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgICAgcmlnaHRTdWJzY3JpcHRpb24uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGxlZnRTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgaWYgKHJpZ2h0U3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgIGlmICghaGFzTGVmdCkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgIH0gZWxzZSBpZiAoIWhhc1JpZ2h0KSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihsYXN0TGVmdCwgbGFzdFJpZ2h0KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfSlcclxuICAgICAgKTtcclxuXHJcbiAgICAgIHJpZ2h0U3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoXHJcbiAgICAgICAgc2Vjb25kLnN1YnNjcmliZShmdW5jdGlvbiAocmlnaHQpIHtcclxuICAgICAgICAgIGhhc1JpZ2h0ID0gdHJ1ZTtcclxuICAgICAgICAgIGxhc3RSaWdodCA9IHJpZ2h0O1xyXG4gICAgICAgIH0sIGZ1bmN0aW9uIChlcnIpIHtcclxuICAgICAgICAgIGxlZnRTdWJzY3JpcHRpb24uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgIHJpZ2h0U3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICBpZiAobGVmdFN0b3BwZWQpIHtcclxuICAgICAgICAgICAgaWYgKCFoYXNMZWZ0KSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIGlmICghaGFzUmlnaHQpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgIHZhciByZXN1bHQ7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ic2VydmFibGVQcm90by5tYW55U2VsZWN0ID0gZnVuY3Rpb24gKHNlbGVjdG9yLCBzY2hlZHVsZXIpIHtcclxuICAgICAgICBzY2hlZHVsZXIgfHwgKHNjaGVkdWxlciA9IGltbWVkaWF0ZVNjaGVkdWxlcik7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG9ic2VydmFibGVEZWZlcihmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHZhciBjaGFpbjtcclxuXHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2VcclxuICAgICAgICAgICAgICAgIC5zZWxlY3QoXHJcbiAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGN1cnIgPSBuZXcgQ2hhaW5PYnNlcnZhYmxlKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoY2hhaW4pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoYWluLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBjaGFpbiA9IGN1cnI7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gY3VycjtcclxuICAgICAgICAgICAgICAgICAgICB9KVxyXG4gICAgICAgICAgICAgICAgLmRvQWN0aW9uKFxyXG4gICAgICAgICAgICAgICAgICAgIG5vb3AsXHJcbiAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNoYWluKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGFpbi5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjaGFpbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hhaW4ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0pXHJcbiAgICAgICAgICAgICAgICAub2JzZXJ2ZU9uKHNjaGVkdWxlcilcclxuICAgICAgICAgICAgICAgIC5zZWxlY3QoZnVuY3Rpb24gKHgsIGksIG8pIHsgcmV0dXJuIHNlbGVjdG9yKHgsIGksIG8pOyB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgdmFyIENoYWluT2JzZXJ2YWJsZSA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHN1YnNjcmliZSAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHNlbGYgPSB0aGlzLCBnID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgZy5hZGQoY3VycmVudFRocmVhZFNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoc2VsZi5oZWFkKTtcclxuICAgICAgICAgICAgICAgIGcuYWRkKHNlbGYudGFpbC5tZXJnZU9ic2VydmFibGUoKS5zdWJzY3JpYmUob2JzZXJ2ZXIpKTtcclxuICAgICAgICAgICAgfSkpO1xyXG5cclxuICAgICAgICAgICAgcmV0dXJuIGc7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpbmhlcml0cyhDaGFpbk9ic2VydmFibGUsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIENoYWluT2JzZXJ2YWJsZShoZWFkKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgICAgIHRoaXMuaGVhZCA9IGhlYWQ7XHJcbiAgICAgICAgICAgIHRoaXMudGFpbCA9IG5ldyBBc3luY1N1YmplY3QoKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFkZFByb3BlcnRpZXMoQ2hhaW5PYnNlcnZhYmxlLnByb3RvdHlwZSwgT2JzZXJ2ZXIsIHtcclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub25OZXh0KE9ic2VydmFibGUuZW1wdHkoKSk7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9uTmV4dChPYnNlcnZhYmxlLnRocm93RXhjZXB0aW9uKGUpKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodikge1xyXG4gICAgICAgICAgICAgICAgdGhpcy50YWlsLm9uTmV4dCh2KTtcclxuICAgICAgICAgICAgICAgIHRoaXMudGFpbC5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIHJldHVybiBDaGFpbk9ic2VydmFibGU7XHJcblxyXG4gICAgfShPYnNlcnZhYmxlKSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgTWFwID0gKGZ1bmN0aW9uICgpIHtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBNYXAoKSB7XHJcbiAgICAgICAgICAgIHRoaXMua2V5cyA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLnZhbHVlcyA9IFtdO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgTWFwI1xyXG4gICAgICAgICAqL1xyXG4gICAgICAgIE1hcC5wcm90b3R5cGVbJ2RlbGV0ZSddID0gZnVuY3Rpb24gKGtleSkge1xyXG4gICAgICAgICAgICB2YXIgaSA9IHRoaXMua2V5cy5pbmRleE9mKGtleSk7XHJcbiAgICAgICAgICAgIGlmIChpICE9PSAtMSkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5rZXlzLnNwbGljZShpLCAxKTtcclxuICAgICAgICAgICAgICAgIHRoaXMudmFsdWVzLnNwbGljZShpLCAxKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICByZXR1cm4gaSAhPT0gLTE7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgTWFwI1xyXG4gICAgICAgICAqL1xyXG4gICAgICAgIE1hcC5wcm90b3R5cGUuZ2V0ID0gZnVuY3Rpb24gKGtleSwgZmFsbGJhY2spIHtcclxuICAgICAgICAgICAgdmFyIGkgPSB0aGlzLmtleXMuaW5kZXhPZihrZXkpO1xyXG4gICAgICAgICAgICByZXR1cm4gaSAhPT0gLTEgPyB0aGlzLnZhbHVlc1tpXSA6IGZhbGxiYWNrO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi9cclxuICAgICAgICBNYXAucHJvdG90eXBlLnNldCA9IGZ1bmN0aW9uIChrZXksIHZhbHVlKSB7XHJcbiAgICAgICAgICAgIHZhciBpID0gdGhpcy5rZXlzLmluZGV4T2Yoa2V5KTtcclxuICAgICAgICAgICAgaWYgKGkgIT09IC0xKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnZhbHVlc1tpXSA9IHZhbHVlO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHRoaXMudmFsdWVzW3RoaXMua2V5cy5wdXNoKGtleSkgLSAxXSA9IHZhbHVlO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi9cclxuICAgICAgICBNYXAucHJvdG90eXBlLnNpemUgPSBmdW5jdGlvbiAoKSB7IHJldHVybiB0aGlzLmtleXMubGVuZ3RoOyB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBNYXAjXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBNYXAucHJvdG90eXBlLmhhcyA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHRoaXMua2V5cy5pbmRleE9mKGtleSkgIT09IC0xO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIE1hcC5wcm90b3R5cGUuZ2V0S2V5cyA9IGZ1bmN0aW9uICgpIHsgcmV0dXJuIHRoaXMua2V5cy5zbGljZSgwKTsgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgTWFwI1xyXG4gICAgICAgICAqLyAgICAgICAgXHJcbiAgICAgICAgTWFwLnByb3RvdHlwZS5nZXRWYWx1ZXMgPSBmdW5jdGlvbiAoKSB7IHJldHVybiB0aGlzLnZhbHVlcy5zbGljZSgwKTsgfTtcclxuXHJcbiAgICAgICAgcmV0dXJuIE1hcDtcclxuICAgI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AgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAoaGFzVmFsdWVzKSB7XHJcbiAgICAgICAgICAgIGZpcnN0VmFsdWVzID0gW107XHJcbiAgICAgICAgICAgIGlzQ29tcGxldGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IHRoaXMuam9pbk9ic2VydmVyQXJyYXkubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgIGZpcnN0VmFsdWVzLnB1c2godGhpcy5qb2luT2JzZXJ2ZXJBcnJheVtpXS5xdWV1ZVswXSk7XHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5qb2luT2JzZXJ2ZXJBcnJheVtpXS5xdWV1ZVswXS5raW5kID09PSAnQycpIHtcclxuICAgICAgICAgICAgICAgICAgICBpc0NvbXBsZXRlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgaWYgKGlzQ29tcGxldGVkKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRlcXVldWUoKTtcclxuICAgICAgICAgICAgICAgIHZhbHVlcyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgZm9yIChpID0gMDsgaSA8IGZpcnN0VmFsdWVzLmxlbmd0aDsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFsdWVzLnB1c2goZmlyc3RWYWx1ZXNbaV0udmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdGhpcy5vbk5leHQuYXBwbHkodGhpcywgdmFsdWVzKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgIH07XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgSm9pbk9ic2VydmVyID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuXHJcbiAgICAgICAgaW5oZXJpdHMoSm9pbk9ic2VydmVyLCBfc3VwZXIpO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIGZ1bmN0aW9uIEpvaW5PYnNlcnZlcihzb3VyY2UsIG9uRXJyb3IpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIHRoaXMuc291cmNlID0gc291cmNlO1xyXG4gICAgICAgICAgICB0aGlzLm9uRXJyb3IgPSBvbkVycm9yO1xyXG4gICAgICAgICAgICB0aGlzLnF1ZXVlID0gW107XHJcbiAgICAgICAgICAgIHRoaXMuYWN0aXZlUGxhbnMgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy5zdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gZmFsc2U7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICB2YXIgSm9pbk9ic2VydmVyUHJvdG90eXBlID0gSm9pbk9ic2VydmVyLnByb3RvdHlwZTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQG1lbWJlck9mIEpvaW5PYnNlcnZlciNcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5uZXh0ID0gZnVuY3Rpb24gKG5vdGlmaWNhdGlvbikge1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKG5vdGlmaWNhdGlvbi5raW5kID09PSAnRScpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9uRXJyb3Iobm90aWZpY2F0aW9uLmV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdGhpcy5xdWV1ZS5wdXNoKG5vdGlmaWNhdGlvbik7XHJcbiAgICAgICAgICAgICAgICB2YXIgYWN0aXZlUGxhbnMgPSB0aGlzLmFjdGl2ZVBsYW5zLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGFjdGl2ZVBsYW5zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgYWN0aXZlUGxhbnNbaV0ubWF0Y2goKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5lcnJvciA9IG5vb3A7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5jb21wbGV0ZWQgPSBub29wO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAbWVtYmVyT2YgSm9pbk9ic2VydmVyI1xyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgSm9pbk9ic2VydmVyUHJvdG90eXBlLmFkZEFjdGl2ZVBsYW4gPSBmdW5jdGlvbiAoYWN0aXZlUGxhbikge1xyXG4gICAgICAgICAgICB0aGlzLmFjdGl2ZVBsYW5zLnB1c2goYWN0aXZlUGxhbik7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQG1lbWJlck9mIEpvaW5PYnNlcnZlciNcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqLyAgICAgICAgXHJcbiAgICAgICAgSm9pbk9ic2VydmVyUHJvdG90eXBlLnN1YnNjcmliZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdGhpcy5zdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZSh0aGlzLnNvdXJjZS5tYXRlcmlhbGl6ZSgpLnN1YnNjcmliZSh0aGlzKSk7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQG1lbWJlck9mIEpvaW5PYnNlcnZlciNcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqLyAgICAgICAgXHJcbiAgICAgICAgSm9pbk9ic2VydmVyUHJvdG90eXBlLnJlbW92ZUFjdGl2ZVBsYW4gPSBmdW5jdGlvbiAoYWN0aXZlUGxhbikge1xyXG4gICAgICAgICAgICB2YXIgaWR4ID0gdGhpcy5hY3RpdmVQbGFucy5pbmRleE9mKGFjdGl2ZVBsYW4pO1xyXG4gICAgICAgICAgICB0aGlzLmFjdGl2ZVBsYW5zLnNwbGljZShpZHgsIDEpO1xyXG4gICAgICAgICAgICBpZiAodGhpcy5hY3RpdmVQbGFucy5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQG1lbWJlck9mIEpvaW5PYnNlcnZlciNcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqLyAgICAgICAgXHJcbiAgICAgIC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GxhbnMgPSBhcmdzT3JBcnJheShhcmd1bWVudHMsIDApO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGFjdGl2ZVBsYW5zID0gW10sXHJcbiAgICAgICAgICAgICAgICBleHRlcm5hbFN1YnNjcmlwdGlvbnMgPSBuZXcgTWFwKCksXHJcbiAgICAgICAgICAgICAgICBncm91cCxcclxuICAgICAgICAgICAgICAgIGksIGxlbixcclxuICAgICAgICAgICAgICAgIGpvaW5PYnNlcnZlcixcclxuICAgICAgICAgICAgICAgIGpvaW5WYWx1ZXMsXHJcbiAgICAgICAgICAgICAgICBvdXRPYnNlcnZlcjtcclxuICAgICAgICAgICAgb3V0T2JzZXJ2ZXIgPSBvYnNlcnZlckNyZWF0ZShvYnNlcnZlci5vbk5leHQuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIHZhciB2YWx1ZXMgPSBleHRlcm5hbFN1YnNjcmlwdGlvbnMuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBqID0gMCwgamxlbiA9IHZhbHVlcy5sZW5ndGg7IGogPCBqbGVuOyBqKyspIHtcclxuICAgICAgICAgICAgICAgICAgICB2YWx1ZXNbal0ub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkNvbXBsZXRlZC5iaW5kKG9ic2VydmVyKSk7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBwbGFucy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIGFjdGl2ZVBsYW5zLnB1c2gocGxhbnNbaV0uYWN0aXZhdGUoZXh0ZXJuYWxTdWJzY3JpcHRpb25zLCBvdXRPYnNlcnZlciwgZnVuY3Rpb24gKGFjdGl2ZVBsYW4pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGlkeCA9IGFjdGl2ZVBsYW5zLmluZGV4T2YoYWN0aXZlUGxhbik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGFjdGl2ZVBsYW5zLnNwbGljZShpZHgsIDEpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoYWN0aXZlUGxhbnMubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRPYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZhYmxlVGhyb3coZSkuc3Vic2NyaWJlKG9ic2VydmVyKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBncm91cCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIGpvaW5WYWx1ZXMgPSBleHRlcm5hbFN1YnNjcmlwdGlvbnMuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGpvaW5WYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgIGpvaW5PYnNlcnZlciA9IGpvaW5WYWx1ZXNbaV07XHJcbiAgICAgICAgICAgICAgICBqb2luT2JzZXJ2ZXIuc3Vic2NyaWJlKCk7XHJcbiAgICAgICAgICAgICAgICBncm91cC5hZGQoam9pbk9ic2VydmVyKTtcclxuICAgICAgIC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ZXJpb2QgPT09IHVuZGVmaW5lZCkge1xyXG4gICAgICAgICAgICByZXR1cm4gb2JzZXJ2YWJsZVRpbWVyVGltZVNwYW4oZHVlVGltZSwgc2NoZWR1bGVyKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG9ic2VydmFibGVUaW1lclRpbWVTcGFuQW5kUGVyaW9kKGR1ZVRpbWUsIHBlcmlvZCwgc2NoZWR1bGVyKTtcclxuICAgIH07XHJcblxyXG4gICAgZnVuY3Rpb24gb2JzZXJ2YWJsZURlbGF5VGltZVNwYW4oZHVlVGltZSwgc2NoZWR1bGVyKSB7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgYWN0aXZlID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICBjYW5jZWxhYmxlID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIGV4Y2VwdGlvbiA9IG51bGwsXHJcbiAgICAgICAgICAgICAgICBxID0gW10sXHJcbiAgICAgICAgICAgICAgICBydW5uaW5nID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb247XHJcbiAgICAgICAgICAgIHN1YnNjcmlwdGlvbiA9IHNvdXJjZS5tYXRlcmlhbGl6ZSgpLnRpbWVzdGFtcChzY2hlZHVsZXIpLnN1YnNjcmliZShmdW5jdGlvbiAobm90aWZpY2F0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgZCwgc2hvdWxkUnVuO1xyXG4gICAgICAgICAgICAgICAgaWYgKG5vdGlmaWNhdGlvbi52YWx1ZS5raW5kID09PSAnRScpIHtcclxuICAgICAgICAgICAgICAgICAgICBxID0gW107XHJcbiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKG5vdGlmaWNhdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgZXhjZXB0aW9uID0gbm90aWZpY2F0aW9uLnZhbHVlLmV4Y2VwdGlvbjtcclxuICAgICAgICAgICAgICAgICAgICBzaG91bGRSdW4gPSAhcnVubmluZztcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHsgdmFsdWU6IG5vdGlmaWNhdGlvbi52YWx1ZSwgdGltZXN0YW1wOiBub3RpZmljYXRpb24udGltZXN0YW1wICsgZHVlVGltZSB9KTtcclxuICAgICAgICAgICAgICAgICAgICBzaG91bGRSdW4gPSAhYWN0aXZlO1xyXG4gICAgICAgICAgICAgICAgICAgIGFjdGl2ZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoc2hvdWxkUnVuKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGV4Y2VwdGlvbiAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlLnNldERpc3Bvc2FibGUoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZShzY2hlZHVsZXIuc2NoZWR1bGVSZWN1cnNpdmVXaXRoUmVsYXRpdmUoZHVlVGltZSwgZnVuY3Rpb24gKHNlbGYpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhciBlLCByZWN1cnNlRHVlVGltZSwgcmVzdWx0LCBzaG91bGRSZWN1cnNlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGV4Y2VwdGlvbiAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJ1bm5pbmcgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHEubGVuZ3RoID4gMCAmJiBxWzBdLnRpbWVzdGFtcCAtIHNjaGVkdWxlci5ub3coKSA8PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHEuc2hpZnQoKS52YWx1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJlc3VsdCAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQuYWNjZXB0KG9ic2VydmVyKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlIChyZXN1bHQgIT09IG51bGwpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvdWxkUmVjdXJzZSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVjdXJzZUR1ZVRpbWUgPSAwO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3VsZFJlY3Vyc2UgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlY3Vyc2VEdWVUaW1lID0gTWF0aC5tYXgoMCwgcVswXS50aW1lc3RhbXAgLSBzY2hlZHVsZXIubm93KCkpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY3RpdmUgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGUgPSBleGNlcHRpb247XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBydW5uaW5nID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZSAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHNob3VsZFJlY3Vyc2UpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZWxmKHJlY3Vyc2VEdWVUaW1lKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShzdWJzY3JpcHRpb24sIGNhbmNlbGFibGUpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIG9ic2VydmFibGVEZWxheURhdGUoZHVlVGltZSwgc2NoZWR1bGVyKSB7XHJcbiAgICAgICAgdmFyIHNlbGYgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBvYnNlcnZhYmxlRGVmZXIoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgdGltZVNwYW4gPSBkdWVUaW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lciwgc2NoZWR1bGVyKSB7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXMsIHRpbWVTaGlmdDtcclxuICAgICAgICBpZiAodGltZVNoaWZ0T3JTY2hlZHVsZXIgPT09IHVuZGVmaW5lZCkge1xyXG4gICAgICAgICAgICB0aW1lU2hpZnQgPSB0aW1lU3BhbjtcclxuICAgICAgICB9XHJcbiAgICAgICAgaWYgKHNjaGVkdWxlciA9PT0gdW5kZWZpbmVkKSB7XHJcbiAgICAgICAgICAgIHNjaGVkdWxlciA9IHRpbWVvdXRTY2hlZHVsZXI7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmICh0eXBlb2YgdGltZVNoaWZ0T3JTY2hlZHVsZXIgPT09ICdudW1iZXInKSB7XHJcbiAgICAgICAgICAgIHRpbWVTaGlmdCA9IHRpbWVTaGlmdE9yU2NoZWR1bGVyO1xyXG4gICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHRpbWVTaGlmdE9yU2NoZWR1bGVyID09PSAnb2JqZWN0Jykge1xyXG4gICAgICAgICAgICB0aW1lU2hpZnQgPSB0aW1lU3BhbjtcclxuICAgICAgICAgICAgc2NoZWR1bGVyID0gdGltZVNoaWZ0T3JTY2hlZHVsZXI7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGdyb3VwRGlzcG9zYWJsZSxcclxuICAgICAgICAgICAgICAgIG5leHRTaGlmdCA9IHRpbWVTaGlmdCxcclxuICAgICAgICAgICAgICAgIG5leHRTcGFuID0gdGltZVNwYW4sXHJcbiAgICAgICAgICAgICAgICBxID0gW10sXHJcbiAgICAgICAgICAgICAgICByZWZDb3VudERpc3Bvc2FibGUsXHJcbiAgICAgICAgICAgICAgICB0aW1lckQgPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgdG90YWxUaW1lID0gMDtcclxuICAgICAgICAgICAgICAgIGdyb3VwRGlzcG9zYWJsZSA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKHRpbWVyRCksXHJcbiAgICAgICAgICAgICAgICByZWZDb3VudERpc3Bvc2FibGUgPSBuZXcgUmVmQ291bnREaXNwb3NhYmxlKGdyb3VwRGlzcG9zYWJsZSk7XHJcblxyXG4gICAgICAgICAgICAgZnVuY3Rpb24gY3JlYXRlVGltZXIgKCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG0gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgICAgICBpc1NwYW4gPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgICAgICBpc1NoaWZ0ID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICB0aW1lckQuc2V0RGlzcG9zYWJsZShtKTtcclxuICAgICAgICAgICAgICAgIGlmIChuZXh0U3BhbiA9PT0gbmV4dFNoaWZ0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNTcGFuID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBpc1NoaWZ0ID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAobmV4dFNwYW4gPCBuZXh0U2hpZnQpIHtcclxuICAgICAgICAgICAgICAgICAgICBpc1NwYW4gPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBpc1NoaWZ0ID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHZhciBuZXdUb3RhbFRpbWUgPSBpc1NwYW4gPyBuZXh0U3BhbiA6IG5leHRTaGlmdCxcclxuICAgICAgICAgICAgICAgICAgICB0cyA9IG5ld1RvdGFsVGltZSAtIHRvdGFsVGltZTtcclxuICAgICAgICAgICAgICAgIHRvdGFsVGltZSA9IG5ld1RvdGFsVGltZTtcclxuICAgICAgICAgICAgICAgIGlmIChpc1NwYW4pIHtcclxuICAgICAgICAgICAgICAgICAgICBuZXh0U3BhbiArPSB0aW1lU2hpZnQ7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaXNTaGlmdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG5leHRTaGlmdCArPSB0aW1lU2hpZnQ7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBtLnNldERpc3Bvc2FibGUoc2NoZWR1bGVyLnNjaGVkdWxlV2l0aFJlbGF0aXZlKHRzLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIHM7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlzU2hpZnQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHEucHVzaChzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihzLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlzU3Bhbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzID0gcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGNyZWF0ZVRpbWVyKCk7XHJcbiAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIHEucHVzaChuZXcgU3ViamVjdCgpKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihxWzBdLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgICAgICAgY3JlYXRlVGltZXIoKTtcclxuICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLmFkZChzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgaSwgcztcclxuICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBxLmxlbmd0aDsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcyA9IHFbaV07XHJcbiAgICAgICAgICAgICAgICAgICAgcy5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgaSwgcztcclxuICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBxLmxlbmd0aDsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcyA9IHFbaV07XHJcbiAgICAgICAgICAgICAgICAgICAgcy5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGksIHM7XHJcbiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgcS5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHMgPSBxW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgcmV0dXJuIHJlZkNvdW50RGlzcG9zYWJsZTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUHJvamVjdHMg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AgICAgIHNjaGVkdWxlciB8fCAoc2NoZWR1bGVyID0gdGltZW91dFNjaGVkdWxlcik7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgY3JlYXRlVGltZXIsXHJcbiAgICAgICAgICAgICAgICBncm91cERpc3Bvc2FibGUsXHJcbiAgICAgICAgICAgICAgICBuID0gMCxcclxuICAgICAgICAgICAgICAgIHJlZkNvdW50RGlzcG9zYWJsZSxcclxuICAgICAgICAgICAgICAgIHMsXHJcbiAgICAgICAgICAgICAgICB0aW1lckQgPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgd2luZG93SWQgPSAwO1xyXG4gICAgICAgICAgICBncm91cERpc3Bvc2FibGUgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSh0aW1lckQpO1xyXG4gICAgICAgICAgICByZWZDb3VudERpc3Bvc2FibGUgPSBuZXcgUmVmQ291bnREaXNwb3NhYmxlKGdyb3VwRGlzcG9zYWJsZSk7XHJcbiAgICAgICAgICAgIGNyZWF0ZVRpbWVyID0gZnVuY3Rpb24gKGlkKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbSA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgdGltZXJELnNldERpc3Bvc2FibGUobSk7XHJcbiAgICAgICAgICAgICAgICBtLnNldERpc3Bvc2FibGUoc2NoZWR1bGVyLnNjaGVkdWxlV2l0aFJlbGF0aXZlKHRpbWVTcGFuLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG5ld0lkO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpZCAhPT0gd2luZG93SWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBuID0gMDtcclxuICAgICAgICAgICAgICAgICAgICBuZXdJZCA9ICsrd2luZG93SWQ7XHJcbiAgICAgICAgICAgICAgICAgICAgcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHMgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgY3JlYXRlVGltZXIobmV3SWQpO1xyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihzLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgICAgICAgY3JlYXRlVGltZXIoMCk7XHJcbiAgICAgICAgICAgIGdyb3VwRGlzcG9zYWJsZS5hZGQoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG5ld0lkID0gMCwgbmV3V2luZG93ID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICBzLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgIG4rKztcclxuICAgICAgICAgICAgICAgIGlmIChuID09PSBjb3VudCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG5ld1dpbmRvdyA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgbiA9IDA7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV3SWQgPSArK3dpbmRvd0lkO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKG5ld1dpbmRvdykge1xyXG4gICAgICAgICAgICAgICAgICAgIGNyZWF0ZVRpbWVyKG5ld0lkKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgIHMub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgcmV0dXJuIHJlZkNvdW50RGlzcG9zYWJsZTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUHJvamVjdHMgZWFjaCBlbGVtZW50IG9mIGFuIG9ic2VydmFibGUgc2VxdWVuY2UgaW50byB6ZXJvIG9yIG1vcmUgYnVmZmVycyB3aGljaCBhcmUgcHJvZHVjZWQgYmFzZWQgb24gdGltaW5nIGluZm9ybWF0aW9uLlxyXG4gICAgICogIFxyXG4gICAgICogQGV4YW1wbGVcclxuICAgICAqICAxIC0gcmVzID0geHMuYnVmZmVyV2l0aFRpbWUoMTAwMCwgc2NoZWR1bGVyKTsgLy8gbm9uLW92ZXJsYXBwaW5nIHNlZ21lbnRzIG9mIDEgc2Vjb25kXHJcbiAgICAgKiAgMiAtIHJlcyA9IHhzLmJ1ZmZlcldpdGhUaW1lKDEwMDAsIDUwMCwgc2NoZWR1bGVyOyAvLyBzZWdtZW50cyBvZiAxIHNlY29uZCB3aXRoIHRpbWUgc2hpZnQgMC41IHNlY29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yID0gdGltZW91dFNjaGVkdWxlcik7XHJcbiAgICAgICAgcmV0dXJuIG9ic2VydmFibGVEZWZlcihmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHZhciBsYXN0ID0gc2NoZWR1bGVyLm5vdygpO1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnNlbGVjdChmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG5vdyA9IHNjaGVkdWxlci5ub3coKSwgc3BhbiA9IG5vdyAtIGxhc3Q7XHJcbiAgICAgICAgICAgICAgICBsYXN0ID0gbm93O1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHtcclxuICAgICAgICAgICAgICAgICAgICB2YWx1ZTogeCxcclxuICAgICAgICAgICAgICAgICAgICBpbnRlcnZhbDogc3BhblxyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFJlY29yZHMgdGhlIHRpbWVzdGFtcCBmb3IgZWFjaCB2YWx1ZSBpbiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlLlxyXG4gICAgICogIFxyXG4gICAgICogQGV4YW1wbGVcclxuICAgICAqICAxIC0gcmVzID0gc291cmNlLnRpbWVzdGFtcCgpOyAvLyBwcm9kdWNlcyB7IHZhbHVlOiB4LCB0aW1lc3RhbXA6IHRzIH1cclxuICAgICAqICAyIC0gcmVzID0gc291cmNlLnRpbWVzdGFtcChSeC5TY2hlZHVsZXIudGltZW91dCk7XHJcbiAgICAgKiAgICAgIFxyXG4gICAgICogQHBhcmFtIHtTY2hlZHVsZXJ9IFtzY2hlZHVsZXJdICBTY2hlZHVsZXIgdXNlZCB0byBjb21wdXRlIHRpbWVzdGFtcHMuIElmIG5vdCBzcGVjaWZpZWQsIHRoZSB0aW1lb3V0IHNjaGVkdWxlciBpcyB1c2VkLlxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2Ugd2l0aCB0aW1lc3RhbXAgaW5mb3JtYXRpb24gb24gdmFsdWVzLlxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8udGltZXN0YW1wID0gZnVuY3Rpb24gKHNjaGVkdWxlcikge1xyXG4gICAgICAgIHNjaGVkdWxlciB8fCAoc2NoZWR1bGVyID0gdGltZW91dFNjaGVkdWxlcik7XHJcbiAgICAgICAgcmV0dXJuIHRoaXMuc2VsZWN0KGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgIHJldHVybiB7XHJcbiAgICAgICAgICAgICAgICB2YWx1ZTogeCxcclxuICAgICAgICAgICAgICAgIHRpbWVzdGFtcDogc2NoZWR1bGVyLm5vdygpXHJcbiAgICAgICAgICAgIH07XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIHNhbXBsZU9ic2VydmFibGUoc291cmNlLCBzYW1wbGVyKSB7XHJcbiAgICAgICAgXHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgYXRFbmQsIHZhbHVlLCBoYXNWYWx1ZTtcclxuXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIHNhbXBsZVN1YnNjcmliZSgpIHtcclxuICAgICAgICAgICAgICAgIGlmIChoYXNWYWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChhdEVuZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJ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XHJcbiAgICAgICAgICAgIHZhciBmaXJzdCA9IHRydWUsXHJcbiAgICAgICAgICAgICAgICBoYXNSZXN1bHQgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgIHJlc3VsdCxcclxuICAgICAgICAgICAgICAgIHN0YXRlID0gaW5pdGlhbFN0YXRlLFxyXG4gICAgICAgICAgICAgICAgdGltZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZVdpdGhBYnNvbHV0ZShzY2hlZHVsZXIubm93KCksIGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzUmVzdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmaXJzdCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlID0gaXRlcmF0ZShzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1Jlc3VsdCA9IGNvbmRpdGlvbihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRpbWUgPSB0aW1lU2VsZWN0b3Ioc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICBzZWxmKHRpbWUpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgR2VuZXJhdGVzIGFuIG9ic2VydmFibGUgc2VxdWVuY2UgYnkgaXRlcmF0aW5nIGEgc3RhdGUgZnJvbSBhbiBpbml0aWFsIHN0YXRlIHVudGlsIHRoZSBjb25kaXRpb24gZmFpbHMuXHJcbiAgICAgKiBcclxuICAgICAqIEBleGFtcGxlIFxyXG4gICAgICogIHJlcyA9IHNvdXJjZS5nZW5lcmF0ZVdpdGhSZWxhdGl2ZVRpbWUoMCwgXHJcbiAgICAgKiAgICAgIGZ1bmN0aW9uICh4KSB7IHJldHVybiByZXR1cm4gdHJ1ZTsgfSwgXHJcbiAgICAgKiAgICAgIGZ1bmN0aW9uICh4KSB7IHJldHVybiB4ICsgMTsgfSwgXHJcbiAgICAgKiAgICAgIGZ1bmN0aW9uICh4KSB7IHJldHVybiB4OyB9LCBcclxuICAgICAqICAgICAgZnVuY3Rpb24gKHgpIHsgcmV0dXJuIDUwMDsgfVxyXG4gICAgICogICk7XHJcbiAgICAgKiAgICAgIFxyXG4gICAgICogQHBhcmFtIHtNaXhlZH0gaW5pdGlhbFN0YXRlIEluaXRpYWwgc3RhdGUuXHJcbiAgICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBjb25kaXRpb24gQ29uZGl0aW9uIHRvIHRlcm1pbmF0ZSBnZW5lcmF0aW9uICh1cG9uIHJldHVyb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ChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgZmlyc3QgPSB0cnVlLFxyXG4gICAgICAgICAgICAgICAgaGFzUmVzdWx0ID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICByZXN1bHQsXHJcbiAgICAgICAgICAgICAgICBzdGF0ZSA9IGluaXRpYWxTdGF0ZSxcclxuICAgICAgICAgICAgICAgIHRpbWU7XHJcbiAgICAgICAgICAgIHJldHVybiBzY2hlZHVsZXIuc2NoZWR1bGVSZWN1cnNpdmVXaXRoUmVsYXRpdmUoMCwgZnVuY3Rpb24gKHNlbGYpIHtcclxuICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZpcnN0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZpcnN0ID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUgPSBpdGVyYXRlKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzUmVzdWx0ID0gY29uZGl0aW9uKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaGFzUmVzdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGltZSA9IHRpbWVTZWxlY3RvcihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3I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SB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgc3Vic2NyaXB0aW9uID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSwgc3RhcnQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGRlbGF5O1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlbGF5ID0gc2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyb3IpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnJvcik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICBkZWxheXMuYWRkKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZShkZWxheS5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlbGF5cy5yZW1vdmUoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVsYXlzLnJlbW92ZShkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBhdEVuZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBpZiAoIXN1YkRlbGF5KSB7XHJcbiAgICAgICAgICAgICAgICBzdGFydCgpO1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoc3ViRGVsYXkuc3Vic2NyaWJlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBzdGFydCgpO1xyXG4gICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkgeyBzdGFydCgpOyB9KSk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShzdWJzY3JpcHRpb24sIGRlbGF5cyk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFJldHVybnMgdGhlIHNvdXJjZSBvYnNlcnZhYmxlIHNlcXVlbmNlLCBzd2l0Y2hpbmcgdG8gdGhlIG90aGVyIG9ic2VydmFibGUgc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ic2NyaXB0aW9uLnNldERpc3Bvc2FibGUob3JpZ2luYWwpO1xyXG5cclxuICAgICAgICAgICAgdmFyIGlkID0gMCwgc3dpdGNoZWQgPSBmYWxzZSwgc2V0VGltZXIgPSBmdW5jdGlvbiAodGltZW91dCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG15SWQgPSBpZCwgdGltZXJXaW5zID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBpZCA9PT0gbXlJZDtcclxuICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgICAgICB2YXIgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgdGltZXIuc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZSh0aW1lb3V0LnN1YnNjcmliZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRpbWVyV2lucygpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKG90aGVyLnN1YnNjcmliZShvYnNlcnZlcikpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRpbWVyV2lucygpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aW1lcldpbnMoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShvdGhlci5zdWJzY3JpYmUob2JzZXJ2ZXIpKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBzZXRUaW1lcihmaXJzdFRpbWVvdXQpO1xyXG4gICAgICAgICAgICB2YXIgb2JzZXJ2ZXJXaW5zID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHJlcyA9ICFzd2l0Y2hlZDtcclxuICAgICAgICAgICAgICAgIGlmIChyZXMpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZCsrO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHJlcztcclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIG9yaWdpbmFsLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKG9ic2VydmVyV2lucygpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciB0aW1lb3V0O1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRpbWVvdXQgPSB0aW1lb3V0ZHVyYXRpb25TZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgc2V0VGltZXIodGltZW91dCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAob2JzZXJ2ZXJXaW5zKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAob2JzZXJ2ZXJXaW5zKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShzdWJzY3JpcHRpb24sIHRpbWVyKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgSWdub3JlcyB2YWx1ZXMgZnJvbSBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIHdoaWNoIGFyZSBmb2xsb3dlZCBieSBhbm90aGVyIHZhbHVlIHdpdGhpbiBhIGNvbXB1dGVkIHRocm90dGxlIGR1cmF0aW9uLlxyXG4gICAgICogIFxyXG4gICAgICogQGV4YW1wbGVcclxuICAgICAqICAxIC0gcmVzID0gc291cmNlLmRlbGF5V2l0aFNlbGVjdG9yKGZ1bmN0aW9uICh4KSB7IHJldHVybiBSeC5TY2hlZHVsZXIudGltZXIoeCArIHgpOyB9KTsgXHJcbiAgICAgKiBcclxuICAgICAqIEBwYXJhbSB7RnVuY3Rpb259IHRocm90dGxlRHVyYXRpb25TZWxlY3RvciBTZWxlY3RvciBmdW5jdGlvbiB0byByZXRyaWV2ZSBhIHNlcXVlbmNlIGluZGljYXRpbmcgdGhlIHRocm90dGxlIGR1cmF0aW9uIGZvciBlYWNoIGdpdmVuIGVsZW1lbnQuXHJcbiAgICAgKiBAcmV0dXJucyB7T2JzZXJ2YWJsZX0gVGhlIHRocm90dGxlZCBzZXF1ZW5jZS5cclxuICAgICAqL1xyXG4gICAgb2JzZXJ2YWJsZVByb3RvLnRocm90dGxlV2l0aFNlbGVjdG9yID0gZnVuY3Rpb24gKHRocm90dGxlRHVyYXRpb25TZWxlY3Rvcikge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHZhbHVlLCBoYXNWYWx1ZSA9IGZhbHNlLCBjYW5jZWxhYmxlID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSwgaWQgPSAwLCBzdWJzY3JpcHRpb24gPSBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgdGhyb3R0bGU7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRocm90dGxlID0gdGhyb3R0bGVEdXJhdGlvblNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdmFsdWUgPSB4O1xyXG4gICAgICAgICAgICAgICAgaWQrKztcclxuICAgICAgICAgICAgICAgIHZhciBjdXJyZW50aWQgPSBpZCwgZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgY2FuY2VsYWJsZS5zZXREaXNwb3NhYmxlKGQpO1xyXG4gICAgICAgICAgICAgICAgZC5zZXREaXNwb3NhYmxlKHRocm90dGxlLnN1YnNjcmliZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGhhc1ZhbHVlICYmIGlkID09PSBjdXJyZW50aWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICBkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaGFzVmFsdWUgJiYgaWQgPT09IGN1cnJlbnRpZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIGQuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgY2FuY2VsYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGNhbmNlbGFibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1ZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgIC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BxLnB1c2goeyBpbnRlcnZhbDogbm93LCB2YWx1ZTogeCB9KTtcclxuICAgICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDAgJiYgbm93IC0gcVswXS5pbnRlcnZhbCA+PSBkdXJhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChxLnNoaWZ0KCkudmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbm93ID0gc2NoZWR1bGVyLm5vdygpO1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCAmJiBub3cgLSBxWzBdLmludGVydmFsID49IGR1cmF0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKS52YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUmV0dXJucyBlbGVtZW50cyB3aXRoaW4gdGhlIHNwZWNpZmllZCBkdXJhdGlvbiBmcm9tIHRoZSBlbmQgb2YgdGhlIG9ic2VydmFibGUgc291cmNlIHNlcXVlbmNlLCB1c2luZyB0aGUgc3BlY2lmaWVkIHNjaGVkdWxlcnMgdG8gcnVuIHRpbWVycyBhbmQgdG8gZHJhaW4gdGhlIGNvbGxlY3RlZCBlbGVtZW50cy5cclxuICAgICAqICBcclxuICAgICAqIEBleGFtcGxlXHJcbiAgICAgKiAgMSAtIHJlcyA9IHNvdXJjZS50YWtlTGFzdFdpdGhUaW1lKDUwMDAsIFtvcHRpb25hbCB0aW1lci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W5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHEgPSBbXTtcclxuXHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbm93ID0gc2NoZWR1bGVyLm5vdygpO1xyXG4gICAgICAgICAgICAgICAgcS5wdXNoKHsgaW50ZXJ2YWw6IG5vdywgdmFsdWU6IHggfSk7XHJcbiAgICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwICYmIG5vdyAtIHFbMF0uaW50ZXJ2YWwgPj0gZHVyYXRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBxLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBub3cgPSBzY2hlZHVsZXIubm93KCksIHJlcyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBuZXh0ID0gcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChub3cgLSBuZXh0LmludGVydmFsIDw9IGR1cmF0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlcy5wdXNoKG5leHQudmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgIC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4gICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICB2YXIgaGFzQ3VycmVudCA9IGZhbHNlLFxyXG4gICAgICAgIGlzU3RvcHBlZCA9IGZhbHNlLFxyXG4gICAgICAgIG0gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKSxcclxuICAgICAgICBnID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKTtcclxuXHJcbiAgICAgIGcuYWRkKG0pO1xyXG5cclxuICAgICAgbS5zZXREaXNwb3NhYmxlKHNvdXJjZXMuc3Vic2NyaWJlKFxyXG4gICAgICAgIGZ1bmN0aW9uIChpbm5lclNvdXJjZSkge1xyXG4gICAgICAgICAgaWYgKCFoYXNDdXJyZW50KSB7XHJcbiAgICAgICAgICAgIGhhc0N1cnJlbnQgPSB0cnVlO1xyXG4gICAgICAgICAgICBcclxuICAgICAgICAgICAgaXNQcm9taXNlKGlubmVyU291cmNlKSAmJiAoaW5uZXJTb3VyY2UgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UoaW5uZXJTb3VyY2UpKTtcclxuXHJcbiAgICAgICAgICAgIHZhciBpbm5lclN1YnNjcmlwdGlvbiA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBnLmFkZChpbm5lclN1YnNjcmlwdGlvbik7XHJcblxyXG4gICAgICAgICAgICBpbm5lclN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKGlubmVyU291cmNlLnN1YnNjcmliZShcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBnLnJlbW92ZShpbm5lcl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3VyY2UgPSBvYnNlcnZhYmxlRnJvbVByb21pc2UoaW5uZXJTb3VyY2UpKTsgICAgICBcclxuXHJcbiAgICAgICAgICAgIGlubmVyU3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoaW5uZXJTb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gc2VsZWN0b3IuY2FsbCh0aGlzQXJnLCB4LCBpbmRleCsrLCBpbm5lclNvdXJjZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgZy5yZW1vdmUoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgaGFzQ3VycmVudCA9IGZhbHNlO1xyXG5cclxuICAgICAgICAgICAgICAgIGlmIChpc1N0b3BwZWQgJiYgZy5sZW5ndGggPT09IDEpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSwgXHJcbiAgICAgICAgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVy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AgICAqLyAgICAgICAgICBcclxuICAgICAgICBWaXJ0dWFsVGltZVNjaGVkdWxlclByb3RvdHlwZS5zY2hlZHVsZVJlbGF0aXZlID0gZnVuY3Rpb24gKGR1ZVRpbWUsIGFjdGlvbikge1xyXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5zY2hlZHVsZVJlbGF0aXZlV2l0aFN0YXRlKGFjdGlvbiwgZHVlVGltZSwgaW52b2tlQWN0aW9uKTtcclxuICAgICAgICB9OyAgICBcclxuXHJcbiAgICAgICAgLyoqIFxyXG4gICAgICAgICAqIFN0YXJ0cyB0aGUgdmlydHVhbCB0aW1lIHNjaGVkdWxlci4gXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgVmlydHVhbFRpbWVTY2hlZHVsZXJQcm90b3R5cGUuc3RhcnQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHZhciBuZXh0O1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNFbmFibGVkKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzRW5hYmxlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBkbyB7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV4dCA9IHRoaXMuZ2V0TmV4dCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChuZXh0ICE9PSBudWxsKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLmNvbXBhcmVyKG5leHQuZHVlVGltZSwgdGhpcy5jbG9jaykgPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmNsb2NrID0gbmV4dC5kdWVUaW1lO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG5leHQuaW52b2tlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5pc0VuYWJsZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IHdoaWxlICh0aGlzLmlzRW5hYmxlZCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKiogXHJcbiAgICAgICAgICogU3RvcHMgdGhlIHZpcnR1YWwgdGltZSBzY2hlZHVsZXIuICBcclxuICAgICAgICAgKi9cclxuICAgICAgICBWaXJ0dWFsVGltZVNjaGVkdWxlclByb3RvdHlwZS5zdG9wID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0aGlzLmlzRW5hYmxlZCA9IGZhbHNlO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEFkdmFuY2VzIHRoZSBzY2hlZHVsZXIncyBjbG9jayB0byB0aGUgc3BlY2lmaWVkIHRpbWUsIHJ1bm5pbmcgYWxsIHdvcmsgdGlsbCB0aGF0IHBvaW50LlxyXG4gICAgICAgICAqIEBwYXJhbSB7TnVtYmVyfSB0aW1lIEFic29sdXRlIHRpbWUgdG8gYWR2YW5jZSB0aGUgc2NoZWR1bGVyJ3MgY2xvY2sgdG8uXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgVmlydHVhbFRpbWVTY2hlZHVsZXJQcm90b3R5cGUuYWR2YW5jZVRvID0gZnVuY3Rpb24gKHRpbWUpIHtcclxuICAgICAgICAgICAgdmFyIG5leHQ7XHJcbiAgICAgICAgICAgIHZhciBkdWVUb0Nsb2NrID0gdGhpcy5jb21wYXJlcih0aGlzLmNsb2NrLCB0aW1lKTtcclxuICAgICAgICAgICAgaWYgKHRoaXMuY29tcGFyZXIodGhpcy5jbG9jaywgdGltZSkgPiAwKSB7XHJcbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYXJndW1lbnRPdXRPZlJhbmdlKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpZiAoZHVlVG9DbG9jayA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc0VuYWJsZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNFbmFibGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIGRvIHtcclxuICAgICAgICAgICAgICAgICAgICBuZXh0ID0gdGhpcy5nZXROZXh0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKG5leHQgIT09IG51bGwgJiYgdGhpcy5jb21wYXJlcihuZXh0LmR1ZVRpbWUsIHRpbWUpIDw9IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuY29tcGFyZXIobmV4dC5kdWVUaW1lLCB0aGlzLmNsb2NrKSA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuY2xvY2sgPSBuZXh0LmR1ZVRpbWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgbmV4dC5pbnZva2UoKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmlzRW5hYmxlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gd2hpbGUgKHRoaXMuaXNFbmFibGVkKTtcclxuICAgICAgICAgICAgICAgIHRoaXMuY2xvY2sgPSB0aW1lO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQWR2YW5jZXMgdGhlIHNjaGVkdWxlcidzIGNsb2NrIGJ5IHRoZSBzcGVjaWZpZWQgcmVsYXRpdmUgdGltZSwgcnVubmluZyBhbGwgd29yayBzY2hlZHVsZWQgZm9yIHRoYXQgdGltZXNwYW4uXHJcbiAgICAgICAgICogQHB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UpO1xyXG5cclxuICAgICAgICAgICAgaWYgKHRoaXMuY29tcGFyZXIodGhpcy5jbG9jaywgZHQpID49IDApIHtcclxuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICB0aGlzLmNsb2NrID0gZHQ7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogR2V0cyB0aGUgbmV4dCBzY2hlZHVsZWQgaXRlbSB0byBiZSBleGVjdXRlZC4gICAgICAgICAgXHJcbiAgICAgICAgICogQHJldHVybnMge1NjaGVkdWxlZEl0ZW19IFRoZSBuZXh0IHNjaGVkdWxlZCBpdGVtLlxyXG4gICAgICAgICAqLyAgICAgICAgICBcclxuICAgICAgICBWaXJ0dWFsVGltZVNjaGVkdWxlclByb3RvdHlwZS5nZXROZXh0ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgbmV4dDtcclxuICAgICAgICAgICAgd2hpbGUgKHRoaXMucXVldWUubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgbmV4dCA9IHRoaXMucXVldWUucGVlaygpO1xyXG4gICAgICAgICAgICAgICAgaWYgKG5leHQuaXNDYW5jZWxsZWQoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucXVldWUuZGVxdWV1ZSgpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gbmV4dDtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICByZXR1cm4gbnVsbDtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBTY2hlZHVsZXMgYW4gYWN0aW9uIHRvIGJlIGV4ZWN1dGVkIGF0IGR1ZVRpbWUuICAgICAgIFxyXG4gICAgICAg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biBBbm9ueW1vdXNPYnNlcnZhYmxlKHN1YnNjcmliZSkge1xyXG4gICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgQW5vbnltb3VzT2JzZXJ2YWJsZSkpIHtcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoc3Vic2NyaWJlKTtcclxuICAgICAgfVxyXG5cclxuICAgICAgZnVuY3Rpb24gcyhvYnNlcnZlcikge1xyXG4gICAgICAgIHZhciBzZXREaXNwb3NhYmxlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgYXV0b0RldGFjaE9ic2VydmVyLnNldERpc3Bvc2FibGUoZml4U3Vic2NyaWJlcihzdWJzY3JpYmUoYXV0b0RldGFjaE9ic2VydmVyKSkpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICBpZiAoIWF1dG9EZXRhY2hPYnNlcnZlci5mYWlsKGUpKSB7XHJcbiAgICAgICAgICAgICAgdGhyb3cgZTtcclxuICAgICAgICAgICAgfSBcclxuICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICB2YXIgYXV0b0RldGFjaE9ic2VydmVyID0gbmV3IEF1dG9EZXRhY2hPYnNlcnZlcihvYnNlcnZlcik7XHJcbiAgICAgICAgaWYgKGN1cnJlbnRUaHJlYWRTY2hlZHVsZXIuc2NoZWR1bGVSZXF1aXJlZCgpKSB7XHJcbiAgICAgICAgICBjdXJyZW50VGhyZWFkU2NoZWR1bGVyLnNjaGVkdWxlKHNldERpc3Bvc2FibGUpO1xyXG4gICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICBzZXREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICByZXR1cm4gYXV0b0RldGFjaE9ic2VydmVyO1xyXG4gICAgICB9XHJcblxyXG4gICAgICBfX3N1cGVyX18uY2FsbCh0aGlzLCBzKTtcclxuICAgIH1cclxuXHJcbiAgICByZXR1cm4gQW5vbnltb3VzT2JzZXJ2YWJsZTtcclxuXHJcbiAgfShPYnNlcnZhYmxlKSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgQXV0b0RldGFjaE9ic2VydmVyID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuICAgICAgICBpbmhlcml0cyhBdXRvRGV0YWNoT2JzZXJ2ZXIsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIEF1dG9EZXRhY2hPYnNlcnZlcihvYnNlcnZlcikge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlciA9IG9ic2VydmVyO1xyXG4gICAgICAgICAgICB0aGlzLm0gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHZhciBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUgPSBBdXRvRGV0YWNoT2JzZXJ2ZXIucHJvdG90eXBlO1xyXG5cclxuICAgICAgICBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUubmV4dCA9IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICB2YXIgbm9FcnJvciA9IGZhbHNlO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgbm9FcnJvciA9IHRydWU7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlOyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIGlmICghbm9FcnJvcikge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLmVycm9yID0gZnVuY3Rpb24gKGV4bikge1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlOyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLmNvbXBsZXRlZCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkgeyBcclxuICAgICAgICAgICAgICAgIHRocm93IGU7ICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICBBdXRvRGV0YWNoT2JzZXJ2ZXJQcm90b3R5cGUuc2V0RGlzcG9zYWJsZSA9IGZ1bmN0aW9uICh2YWx1ZSkgeyB0aGlzLm0uc2V0RGlzcG9zYWJsZSh2YWx1ZSk7IH07XHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLmdldERpc3Bvc2FibGUgPSBmdW5jdGlvbiAodmFsdWUpIHsgcmV0dXJ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AgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzLnB1c2gob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG5ldyBJbm5lclN1YnNjcmlwdGlvbih0aGlzLCBvYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgaWYgKHRoaXMuZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKHRoaXMuZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGluaGVyaXRzKFN1YmplY3QsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIENyZWF0ZXMgYSBzdWJqZWN0LlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqLyAgICAgIFxyXG4gICAgICAgIGZ1bmN0aW9uIFN1YmplY3QoKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IGZhbHNlLFxyXG4gICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IGZhbHNlLFxyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgYWRkUHJvcGVydGllcyhTdWJqZWN0LnByb3RvdHlwZSwgT2JzZXJ2ZXIsIHtcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIEluZGljYXRlcyB3aGV0aGVyIHRoZSBzdWJqZWN0IGhhcyBvYnNlcnZlcnMgc3Vic2NyaWJlZCB0byBpdC5cclxuICAgICAgICAgICAgICogQHJldHVybnMge0Jvb2xlYW59IEluZGljYXRlcyB3aGV0aGVyIHRoZSBzdWJqZWN0IGhhcyBvYnNlcnZlcnMgc3Vic2NyaWJlZCB0byBpdC5cclxuICAgICAgICAgICAgICovICAgICAgICAgXHJcbiAgICAgICAgICAgIGhhc09ic2VydmVyczogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMub2JzZXJ2ZXJzLmxlbmd0aCA+IDA7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGVuZCBvZiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZXhjZXB0aW9uLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSBlcnJvciBUaGUgZXhjZXB0aW9uIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBleGNlcHRpb247XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGFycml2YWwgb2YgdGhlIHNwZWNpZmllZCBlbGVtZW50IGluIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gdmFsdWUgVGhlIHZhbHVlIHRvIHNlbmQgdG8gYWxsIG9ic2VydmVycy5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBVbnN1YnNjcmliZSBhbGwgb2JzZXJ2ZXJzIGFuZCByZWxlYXNlIHJlc291cmNlcy5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBkaXNwb3NlOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBudWxsO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIENyZWF0Z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BSeC5Bc3luY1N1YmplY3QgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBzdWJzY3JpYmUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICBcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMucHVzaChvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gbmV3IElubmVyU3Vic2NyaXB0aW9uKHRoaXMsIG9ic2VydmVyKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdmFyIGV4ID0gdGhpcy5leGNlcHRpb24sXHJcbiAgICAgICAgICAgICAgICBodiA9IHRoaXMuaGFzVmFsdWUsXHJcbiAgICAgICAgICAgICAgICB2ID0gdGhpcy52YWx1ZTtcclxuXHJcbiAgICAgICAgICAgIGlmIChleCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoaHYpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2KTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaW5oZXJpdHMoQXN5bmNTdWJqZWN0LCBfc3VwZXIpO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBDcmVhdGVzIGEgc3ViamVjdCB0aGF0IGNhbiBvb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AgICAgIHJldHVybiB0aGlzLm9ic2VydmVycy5sZW5ndGggPiAwO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBlbmQgb2YgdGhlIHNlcXVlbmNlLCBhbHNvIGNhdXNpbmcgdGhlIGxhc3QgcmVjZWl2ZWQgdmFsdWUgdG8gYmUgc2VudCBvdXQgKGlmIGFueSkuXHJcbiAgICAgICAgICAgICAqLyBcclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBvLCBpLCBsZW47XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICB2ID0gdGhpcy52YWx1ZSxcclxuICAgICAgICAgICAgICAgICAgICAgICAgaHYgPSB0aGlzLmhhc1ZhbHVlO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICBpZiAoaHYpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG8gPSBvc1tpXTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG8ub25OZXh0KHYpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgby5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGV4Y2VwdGlvbi5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gZXJyb3IgVGhlIGV4Y2VwdGlvbiB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyBcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmV4Y2VwdGlvbiA9IGV4Y2VwdGlvbjtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBTZW5kcyBhIHZhbHVlIHRvIHRoZSBzdWJqZWN0LiBUaGUgbGFzdCB2YWx1ZSByZWNlaXZlZCBiZWZvcmUgc3VjY2Vzc2Z1bCB0ZXJtaW5hdGlvbiB3aWxsIGJlIHNlbnQgdG8gYWxsIHN1YnNjcmliZWQgYW5kIGZ1dHVyZSBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IHZhbHVlIFRoZSB2YWx1ZSB0byBzdG9yZSBpbiB0aGUgc3ViamVjdC5cclxuICAgICAgICAgICAgICovICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMudmFsdWUgPSB2YWx1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmhhc1ZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIFVuc3Vic2NyaWJlIGFsbCBvYnNlcnZlcnMgYW5kIHJlbGVhc2UgcmVzb3VyY2VzLlxyXG4gICAgICAgICAgICAgKi9cclxuICAgICAgICAgICAgZGlzcG9zZTogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gbnVsbDtcclxuICAgICAgICAgICAgICAgIHRoaXMuZXhjZXB0aW9uID0gbnVsbDtcclxuICAgICAgICAgICAgICAgIHRoaXMudmFsdWUgPSBudWxsO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIHJldHVybiBBc3luY1N1YmplY3Q7XHJcbiAgICB9KE9ic2VydmFibGUpKTtcclxuXHJcbiAgICAvKiogQHByaXZhdGUgKi9cclxuICAgIHZhciBBbm9ueW1vdXNTdWJqZWN0ID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuICAgICAgICBpbmhlcml0cyhBbm9ueW1vdXNTdWJqZWN0LCBfc3VwZXIpO1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBzdWJzY3JpYmUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHRoaXMub2JzZXJ2YWJsZS5zdWJzY3JpYmUob2JzZXJ2ZXIpO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBBbm9ueW1vdXNTdWJqZWN0KG9ic2VydmVyLCBvYnNlcnZhYmxlKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIgPSBvYnNlcnZlcjtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZhYmxlID0gb2JzZXJ2YWJsZTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFkZFByb3BlcnRpZXMoQW5vbnltb3VzU3ViamVjdC5wcm90b3R5cGUsIE9ic2VydmVyLCB7XHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAgICAgKiBAbWVtYmVyT2YgQW5vbnltb3VzU3ViamVjdCNcclxuICAgICAgICAgICAgKi9cclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICAgICAqIEBtZW1iZXJPZiBBbm9ueW1vdXNTdWJqZWN0I1xyXG4gICAgICAgICAgICAqLyAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICAgICAqIEBtZW1iZXJPZiBBbm9ueW1vdXNTdWJqZWN0I1xyXG4gICAgICAgICAgICAqLyAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIHJldHVybiBBbm9ueW1vdXNTdWJqZWN0O1xyXG4gICAgfShPYnNlcnZhYmxlKSk7XHJcblxyXG4gICAgaWYgKHR5cGVvZiBkZWZpbmUgPT0gJ2Z1bmN0aW9uJyAmJiB0eXBlb2YgZGVmaW5lLmFtZCA9PSAnb2JqZWN0JyAmJiBkZWZpbmUuYW1kKSB7XHJcbiAgICAg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XZhdGUgXHJcbiAgICAgKiBAbWVtYmVyT2YgT25OZXh0UHJlZGljYXRlI1xyXG4gICAgICovICAgIFxyXG4gICAgT25OZXh0UHJlZGljYXRlLnByb3RvdHlwZS5lcXVhbHMgPSBmdW5jdGlvbiAob3RoZXIpIHtcclxuICAgICAgICBpZiAob3RoZXIgPT09IHRoaXMpIHsgcmV0dXJuIHRydWU7IH1cclxuICAgICAgICBpZiAob3RoZXIgPT0gbnVsbCkgeyByZXR1cm4gZmFsc2U7IH1cclxuICAgICAgICBpZiAob3RoZXIua2luZCAhPT0gJ04nKSB7IHJldHVybiBmYWxzZTsgfVxyXG4gICAgICAgIHJldHVybiB0aGlzLnByZWRpY2F0ZShvdGhlci52YWx1ZSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKiBcclxuICAgICAqIEBwcml2YXRlIFxyXG4gICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgKi9cclxuICAgIGZ1bmN0aW9uIE9uRXJyb3JQcmVkaWNhdGUocHJlZGljYXRlKSB7XHJcbiAgICAgICAgdGhpcy5wcmVkaWNhdGUgPSBwcmVkaWNhdGU7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKiBcclxuICAgICAqIEBwcml2YXRlIFxyXG4gICAgICogQG1lbWJlck9mIE9uRXJyb3JQcmVkaWNhdGUjXHJcbiAgICAgKi8gICAgICAgXHJcbiAgICBPbkVycm9yUHJlZGljYXRlLnByb3RvdHlwZS5lcXVhbHMgPSBmdW5jdGlvbiAob3RoZXIpIHtcclxuICAgICAgICBpZiAob3RoZXIgPT09IHRoaXMpIHsgcmV0dXJuIHRydWU7IH1cclxuICAgICAgICBpZiAob3RoZXIgPT0gbnVsbCkgeyByZXR1cm4gZmFsc2U7IH1cclxuICAgICAgICBpZiAob3RoZXIua2luZCAhPT0gJ0UnKSB7IHJldHVybiBmYWxzZTsgfVxyXG4gICAgICAgIHJldHVybiB0aGlzLnByZWRpY2F0ZShvdGhlci5leGNlcHRpb24pO1xyX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VzKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgICAgIHZhciBtZXNzYWdlLCBub3RpZmljYXRpb24sIG9ic2VydmFibGUgPSB0aGlzO1xyXG4gICAgICAgICAgICB0aGlzLnNjaGVkdWxlciA9IHNjaGVkdWxlcjtcclxuICAgICAgICAgICAgdGhpcy5tZXNzYWdlcyA9IG1lc3NhZ2VzO1xyXG4gICAgICAgICAgICB0aGlzLnN1YnNjcmlwdGlvbnMgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IHRoaXMubWVzc2FnZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgIG1lc3NhZ2UgPSB0aGlzLm1lc3NhZ2VzW2ldO1xyXG4gICAgICAgICAgICAgICAgbm90aWZpY2F0aW9uID0gbWVzc2FnZS52YWx1ZTtcclxuICAgICAgICAgICAgICAgIChmdW5jdGlvbiAoaW5uZXJOb3RpZmljYXRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBzY2hlZHVsZXIuc2NoZWR1bGVBYnNvbHV0ZVdpdGhTdGF0ZShudWxsLCBtZXNzYWdlLnRpbWUsIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIG9icyA9IG9ic2VydmFibGUub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaiA9IDAsIGpMZW4gPSBvYnMubGVuZ3RoOyBqIDwgakxlbjsgaisrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbm5lck5vdGlmaWNhdGlvbi5hY2NlcHQob2JzW2pdKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgfSkobm90aWZpY2F0aW9uKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgcmV0dXJuIEhvdE9ic2VydmFibGU7XHJcbiAgICB9KShPYnNlcnZhYmxlKTtcclxuXHJcbiAgICAvKiogQHByaXZhdGUgKi9cclxuICAgIHZhciBDb2xkT2JzZXJ2YWJsZSA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIHN1YnNjcmliZShvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgbWVzc2FnZSwgbm90aWZpY2F0aW9uLCBvYnNlcnZhYmxlID0gdGhpcztcclxuICAgICAgICAgICAgdGhpcy5zdWJzY3JpcHRpb25zLnB1c2gobmV3IFN1YnNjcmlwdGlvbih0aGlzLnNjaGVkdWxlci5jbG9jaykpO1xyXG4gICAgICAgICAgICB2YXIgaW5kZXggPSB0aGlzLnN1YnNjcmlwdGlvbnMubGVuZ3RoIC0gMTtcclxuICAgICAgICAgICAgdmFyIGQgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gdGhpcy5tZXNzYWdlcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgbWVzc2FnZSA9IHRoaXMubWVzc2FnZXNbaV07XHJcbiAgICAgICAgICAgICAgICBub3RpZmljYXRpb24gPSBtZXNzYWdlLnZhbHVlO1xyXG4gICAgICAgICAgICAgICAgKGZ1bmN0aW9uIChpbm5lck5vdGlmaWNhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIGQuYWRkKG9ic2VydmFibGUuc2NoZWR1bGVyLnNjaGVkdWxlUmVsYXRpdmVXaXRoU3RhdGUobnVsbCwgbWVzc2FnZS50aW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyTm90aWZpY2F0aW9uLmFjY2VwdChvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICAgICAgfSkobm90aWZpY2F0aW9uKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZhYmxlLnN1YnNjcmlwdGlvbnNbaW5kZXhdID0gbmV3IFN1YnNjcmlwdGlvbihvYnNlcnZhYmxlLnN1YnNjcmlwdGlvbnNbaW5kZXhdLnN1YnNjcmliZSwgb2JzZXJ2YWJsZS5zY2hlZHVsZXIuY2xvY2spO1xyXG4gICAgICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgaW5oZXJpdHMoQ29sZE9ic2VydmFibGUsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gQ29sZE9ic2VydmFibGUoc2NoZWR1bGVyLCBtZXNzYWdlcykge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgICAgICB0aGlzLnNjaGVkdWxlciA9IHNjaGVkdWxlcjtcclxuICAgICAgICAgICAgdGhpcy5tZXNzYWdlcyA9IG1lc3NhZ2VzO1xyXG4gICAgICAgICAgICB0aGlzLnN1YnNjcmlwdGlvbnMgPSBbXTtcclx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YnNlcnZhYmxlLmFtYixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAxMCxcbiAgICAgICAgICBkOiAyMFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMjAsXG4gICAgICAgICAgZDogNDBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDMwLFxuICAgICAgICAgIGQ6IDYwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0NSxcbiAgICAgICAgICBkOiA4MFxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDY4LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDkwLFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfVxuICAgICAgXSwgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMixcbiAgICAgICAgICBkOiAwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3NixcbiAgICAgICAgICBkOiAwXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdXG4gIH0sXG4gIFwiY29uY2F0XCI6IHtcbiAgICBcImxhYmVsXCI6IFwiY29uY2F0KClcIixcbiAgICBcImZ1bmN0aW9uXCI6IFJ4Lk9ic2VydmFibGUuY29uY2F0LFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAxMyxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH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ge1xuICAgIGZvciAodmFyIHByb3BOYW1lIGluIHByb3BzKSB7XG4gICAgICAgIHZhciBwcm9wVmFsdWUgPSBwcm9wc1twcm9wTmFtZV1cblxuICAgICAgICBpZiAocHJvcFZhbHVlID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIHJlbW92ZVByb3BlcnR5KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUpO1xuICAgICAgICB9IGVsc2UgaWYgKGlzSG9vayhwcm9wVmFsdWUpKSB7XG4gICAgICAgICAgICBwcm9wVmFsdWUuaG9vayhub2RlLFxuICAgICAgICAgICAgICAgIHByb3BOYW1lLFxuICAgICAgICAgICAgICAgIHByZXZpb3VzID8gcHJldmlvdXNbcHJvcE5hbWVdIDogdW5kZWZpbmVkKVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKGlzT2JqZWN0KHByb3BWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICBwYXRjaE9iamVjdChub2RlLCBwcm9wcywgcHJldmlvdXMsIHByb3BOYW1lLCBwcm9wVmFsdWUpO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChwcm9wVmFsdWUgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIG5vZGVbcHJvcE5hbWVdID0gcHJvcFZhbHVlXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbmZ1bmN0aW9uIHJlbW92ZVByb3BlcnR5KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUpIHtcbiAgICBpZiAocHJldmlvdXMpIHtcbiAgICAgICAgdmFyIHByZXZpb3VzVmFsdWUgPSBwcmV2aW91c1twcm9wTmFtZV1cblxuICAgICAgICBpZiAoIWlzSG9vayhwcmV2aW91c1ZhbHVlKSkge1xuICAgICAgICAgICAgaWYgKHByb3BOYW1lID09PSBcImF0dHJpYnV0ZXNcIikge1xuICAgICAgICAgICAgICAgIGZvciAodmFyIGF0dHJOYW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XggPSByb290SW5kZXggKyAodkNoaWxkLmNvdW50IHx8IDApXG5cbiAgICAgICAgICAgICAgICAvLyBza2lwIHJlY3Vyc2lvbiBkb3duIHRoZSB0cmVlIGlmIHRoZXJlIGFyZSBubyBub2RlcyBkb3duIGhlcmVcbiAgICAgICAgICAgICAgICBpZiAoaW5kZXhJblJhbmdlKGluZGljZXMsIHJvb3RJbmRleCwgbmV4dEluZGV4KSkge1xuICAgICAgICAgICAgICAgICAgICByZWN1cnNlKGNoaWxkTm9kZXNbaV0sIHZDaGlsZCwgaW5kaWNlcywgbm9kZXMsIHJvb3RJbmRleClcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICByb290SW5kZXggPSBuZXh0SW5kZXhcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiBub2Rlc1xufVxuXG4vLyBCaW5hcnkgc2VhcmNoIGZvciBhbiBpbmRleCBpbiB0aGUgaW50ZXJ2YWwgW2xlZnQsIHJpZ2h0XVxuZnVuY3Rpb24gaW5kZXhJblJhbmdlKGluZGljZXMsIGxlZnQsIHJpZ2h0KSB7XG4gICAgaWYgKGluZGljZXMubGVuZ3RoID09PSAwKSB7XG4gICAgICAgIHJldHVybiBmYWxzZVxuICAgIH1cblxuICAgIHZhciBtaW5JbmRleCA9IDBcbiAgICB2YXIgbWF4SW5kZXggPSBpbmRpY2VzLmxlbmd0aCAtIDFcbiAgICB2YXIgY3VycmVudEluZGV4XG4gICAgdmFyIGN1cnJlbnRJdGVtXG5cbiAgICB3aGlsZSAobWluSW5kZXggPD0gbWF4SW5kZXgpIHtcbiAgICAgICAgY3VycmVudEluZGV4ID0gKChtYXhJbmRleCArIG1pbkluZGV4KSAvIDIpID4+IDBcbiAgICAgICAgY3VycmVudEl0ZW0gPSBpbmRpY2VzW2N1cnJlbnRJbmRleF1cblxuICAgICAgICBpZiAobWluSW5kZXggPT09IG1heEluZGV4KSB7XG4gICAgICAgICAgICByZXR1c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gIGEubmFtZXNwYWNlID09PSBiLm5hbWVzcGFjZSAmJlxuICAgICAgICAgICAgICAgIGEua2V5ID09PSBiLmtleSkge1xuICAgICAgICAgICAgICAgIHZhciBwcm9wc1BhdGNoID0gZGlmZlByb3BzKGEucHJvcGVydGllcywgYi5wcm9wZXJ0aWVzLCBiLmhvb2tzKVxuICAgICAgICAgICAgICAgIGlmIChwcm9wc1BhdGNoKSB7XG4gICAgICAgICAgICAgICAgICAgIGFwcGx5ID0gYXBwZW5kUGF0Y2goYXBwbHksXG4gICAgICAgICAgICAgICAgICAgICAgICBuZXcgVlBhdGNoKFZQYXRjaC5QUk9QUywgYSwgcHJvcHNQYXRjaCkpXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBhcHBseSA9IGFwcGVuZFBhdGNoKGFwcGx5LCBuZXcgVlBhdGNoKFZQYXRjaC5WTk9ERSwgYSwgYikpXG4gICAgICAgICAgICAgICAgZGVzdHJveVdpZGdldHMoYSwgcGF0Y2gsIGluZGV4KVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBhcHBseSA9IGRpZmZDaGlsZHJlbihhLCBiLCBwYXRjaCwgYXBwbHksIGluZGV4KVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYXBwbHkgPSBhcHBlbmRQYXRjaChhcHBseSwgbmV3IFZQYXRjaChWUGF0Y2guVk5PREUsIGEsIGIpKVxuICAgICAgICAgICAgZGVzdHJveVdpZGdldHMoYSwgcGF0Y2gsIGluZGV4KVxuICAgICAgICB9XG4gICAgfSBlbHNlIGlmIChpc1ZUZXh0KGIpKSB7XG4gICAgICAgIGlmICghaXNWVGV4dChhKSkge1xuICAgICAgICAgICAgYXBwbHkgPSBhcHBlbmRQYXRjaChhcHBseSwgbmV3IFZQYXRjaChWUGF0Y2guVlRFWFQsIGEsIGIpKVxuICAgICAgICAgICAgZGVzdHJveVdpZGdldHMoYSwgcGF0Y2gsIG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cGUoYlZhbHVlKSAhPT0gZ2V0UHJvdG90eXBlKGFWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgICAgICAgICAgZGlmZlthS2V5XSA9IGJWYWx1ZVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBvYmplY3REaWZmID0gZGlmZlByb3BzKGFWYWx1ZSwgYlZhbHVlKVxuICAgICAgICAgICAgICAgICAgICBpZiAob2JqZWN0RGlmZikge1xuICAgICAgICAgICAgICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgICAgICAgICAgICAgIGRpZmZbYUtleV0gPSBvYmplY3REaWZmXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGFWYWx1ZSAhPT0gYlZhbHVlKSB7XG4gICAgICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgICAgICBkaWZmW2FLZXldID0gYlZhbHVlXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBmb3IgKHZhciBiS2V5IGluIGIpIHtcbiAgICAgICAgaWYgKCEoYktleSBpbiBhKSkge1xuICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgIGRpZmZbYktleV0gPSBiW2JLZXldXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gZGlmZlxufVxuXG5mdW5jdGlvbiBnZXRQcm90b3R5cGUodmFsdWUpIHtcbiAgICBpZiAoT2JqZWN0LmdldFByb3RvdHlwZU9mKSB7XG4gICAgICAgIHJldHVybiBPYmplY3QuZ2V0UHJvdG90eXBlT2YodmFsdWUpXG4gICAgfSBlbHNlIGlmICh2YWx1ZS5fX3Byb3RvX18pIHtcbiAgICAgICAgcmV0dXJuIHZhbHVlLl9fcH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AgICAgICAgICBtb3Zlc1ttb3ZlXSA9IG1vdmVJbmRleFxuICAgICAgICAgICAgICAgIHJldmVyc2VbbW92ZUluZGV4XSA9IG1vdmVcbiAgICAgICAgICAgICAgICBoYXNNb3ZlcyA9IHRydWVcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG1vdmVJbmRleCsrXG4gICAgICAgIH0gZWxzZSBpZiAoaSBpbiBhTWF0Y2gpIHtcbiAgICAgICAgICAgIHNodWZmbGVbaV0gPSB1bmRlZmluZWRcbiAgICAgICAgICAgIHJlbW92ZXNbaV0gPSBtb3ZlSW5kZXgrK1xuICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB3aGlsZSAoYk1hdGNoW2ZyZWVJbmRleF0gIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIGZyZWVJbmRleCsrXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChmcmVlSW5kZXggPCBsZW4pIHtcbiAgICAgICAgICAgICAgICB2YXIgZnJlZUNoaWxkID0gYkNoaWxkcmVuW2ZyZWVJbmRleF1cbiAgICAgICAgICAgICAgICBpZiAoZnJlZUNoaWxkKSB7XG4gICAgICAgICAgICAgICAgICAgIHNodWZmbGVbaV0gPSBmcmVlQ2hpbGRcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZyZWVJbmRleCAhPT0gbW92ZUluZGV4KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBoYXNNb3ZlcyA9IHRydWVcbiAgICAgICAgICAgICAgICAgICAgICAgIG1vdmVzW2ZyZWVJbmRleF0gPSBtb3ZlSW5kZXhcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldmVyc2VbbW92ZUluZGV4XSA9IGZyZWVJbmRleFxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIG1vdmVJbmRleCsrXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZyZWVJbmRleCsrXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaSsrXG4gICAgfVxuXG4gICAgaWYgKGhhc01vdmVzKSB7XG4gICAgICAgIHNodWZmbGUubW92ZXMgPSBtb3Zlc1xuICAgIH1cblxuICAgIHJldHVybiBzaHVmZmxlXG59XG5cbmZ1bmN0aW9uIGtleUluZGV4KGNoaWxkcmVuKSB7XG4gICAgdmFyIGksIGtleXNcblxuICAgIGZvciAoaSA9IDA7IGkgPCBjaGlsZHJlbi5sZW5ndGg7IGkrKykge1xuICAgICAgICB2YXIgY2hpbGQgPSBjaGlsZHJlbltpXVxuXG4gICAgICAgIGlmIChjaGlsZC5rZXkgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAga2V5cyA9IGtleXMgfHwge31cbiAgICAgICAgICAgIGtleXNbY2hpbGQua2V5XSA9IGlcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiBrZXlzXG59XG5cbmZ1bmN0aW9uIGFwcGVuZFBhdGNoKGFwcGx5LCBwYXRjaCkge1xuICAgIGlmIChhcHBseSkge1xuICAgICAgICBpZiAoaXNBcnJheShhcHBseSkpIHtcbiAgICAgICAgICAgIGFwcGx5LnB1c2gocGF0Y2gpXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBhcHBseSA9IFthcHBseSwgcGF0Y2hdXG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gYXBwbHlcbiAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gcGF0Y2hcbiAgICB9XG59XG5cbn0pLmNhbGwodGhpcyxyZXF1aXJlKFwib01mcEFuXCIpLHR5cGVvZiBzZWxmICE9PSBcInVuZGVmaW5lZFwiID8gc2VsZiA6IHR5cGVvZiB3aW5kb3cgIT09IFwidW5kZWZpbmVkXCIgPyB3aW5kb3cgOiB7fSxyZXF1aXJlKFwiYnVmZmVyXCIpLkJ1ZmZlcixhcmd1bWVudHNbM10sYXJndW1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mIHZhbHVlICE9PSBcInN0cmluZ1wiICYmXG4gICAgICAgICAgICB0eXBlb2YgdmFsdWUgIT09IFwibnVtYmVyXCIgJiZcbiAgICAgICAgICAgIHR5cGVvZiB2YWx1ZSAhPT0gXCJib29sZWFuXCJcbiAgICAgICAgKSB7XG4gICAgICAgICAgICBjb250aW51ZVxuICAgICAgICB9XG5cbiAgICAgICAgcHJvcGVydGllc1trZXldID0gYXR0cmlidXRlSG9vayh2YWx1ZSlcbiAgICB9XG5cbiAgICByZXR1cm4gaCh0YWdOYW1lLCBwcm9wZXJ0aWVzLCBjaGlsZHJlbilcbn1cblxuZnVuY3Rpb24gaXNDaGlsZHJlbih4KSB7XG4gICAgcmV0dXJuIHR5cGVvZiB4ID09PSBcInN0cmluZ1wiIHx8IEFycmF5LmlzQXJyYXkoeClcbn1cblxufSkuY2FsbCh0aGlzLHJlcXVpcmUoXCJvTWZwQW5cIiksdHlwZW9mIHNlbGYgIT09IFwidW5kZWZpbmVkXCIgPyBzZWxmIDogdHlwZW9mIHdpbmRvdyAhPT0gXCJ1bmRlZmluZWRcIiA/IHdpbmRvdyA6IHt9LHJlcXVpcmUoXCJidWZmZXJcIikuQnVmZmVyLGFyZ3VtZW50c1szXSxhcmd1bWVudHNbNF0sYXJndW1lbnRzWzVdLGFyZ3VtZW50c1s2XSxcIi8uLi8uLi9ub2RlX21vZHVsZXMvdmlydHVhbC1oeXBlcnNjcmlwdC9zdmcuanNcIixcIi8uLi8uLi9ub2RlX21vZHVsZXMvdmlydHVhbC1oeXBlcnNjcmlwdFwiKSJdfQ== diff --git a/src/models/examples.coffee b/src/models/examples.coffee index 3e407cd..70e24dd 100644 --- a/src/models/examples.coffee +++ b/src/models/examples.coffee @@ -2,6 +2,7 @@ Rx = require 'rx' module.exports = { "amb": { + "label": "amb()" "function": Rx.Observable.amb "inputs": [ [{t:10, d:20}, {t:20, d:40}, {t:30, d:60}, {t:45, d:80}] @@ -10,6 +11,7 @@ module.exports = { ] } "concat": { + "label": "concat()" "function": Rx.Observable.concat "inputs": [ [{t:0, d:1}, {t:15, d:1}, {t:50, d:1}] @@ -17,6 +19,7 @@ module.exports = { ] } "merge": { + "label": "merge()" "function": Rx.Observable.merge "inputs": [ [{t:0, d:20}, {t:15, d:40}, {t:30, d:60}, {t:45, d:80}, {t:60, d:100}] diff --git a/src/views/function-box.coffee b/src/views/function-box.coffee index ffce4fd..e0bf266 100644 --- a/src/views/function-box.coffee +++ b/src/views/function-box.coffee @@ -4,32 +4,33 @@ # h = require 'hyperscript' Rx = require 'rx' +Examples = require 'rxmarbles/models/examples' + +renderSelectOptionsArray = (examples) -> + options = [] + for key,example of examples + if not examples.hasOwnProperty(key) + continue + options.push(h("option", {value: key}, example["label"])) + return options + +setupClickBehavior = (functionBoxElement, selectElement) -> + Rx.Observable.fromEvent(functionBoxElement, "click").subscribe(-> + event = document.createEvent('MouseEvents'); + event.initMouseEvent('mousedown', true, true, window); + selectElement.dispatchEvent(event) + return true + ) module.exports = { render: (label) -> functionBoxElement = h("div.function-box", [ h("span.function-box-label", label) - select = h("select", [ - # h("optgroup", {label:"Type 1 functions"}, [ - h("option", {value:"amb"}, "amb()") - h("option", {value:"concat"}, "concat()") - h("option", {value:"merge"}, "merge()") - # ]) - # h("optgroup", {label:"Type 2 functions"}, [ - # h("option", {value:"debounce"}, "debounce()") - # h("option", {value:"delay"}, "delay()") - # h("option", {value:"take"}, "take()") - # ]) - ]) + selectElement = h("select", renderSelectOptionsArray(Examples)) h("div.function-box-dropdown", [ h("span.function-box-dropdown-arrow") ]) ]) - Rx.Observable.fromEvent(functionBoxElement, "click").subscribe(-> - event = document.createEvent('MouseEvents'); - event.initMouseEvent('mousedown', true, true, window); - select.dispatchEvent(event) - return true - ) + setupClickBehavior(functionBoxElement, selectElement) return functionBoxElement }