From 55668f1f44fcae165a25cf5e3f128312a334d950 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sat, 9 Aug 2014 22:44:18 +0300 Subject: [PATCH] OperatorsMenu should stretch its height --- TODO | 4 ++-- dist/css/main.css | 2 +- dist/js/app.js | 28 +++++++++++++++++++++++----- src/views/operators-menu.coffee | 22 +++++++++++++++++++++- styles/main.less | 2 +- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 4a6f034..65789ff 100644 --- a/TODO +++ b/TODO @@ -22,8 +22,8 @@ + DONE Side menu with list of operators + DONE RxMarbles title and proposition value + DONE Examples for Observable Instance Methods -- TODO OperatorsMenu should stretch its height -- TODO Version number at the bottom of the page ++ DONE OperatorsMenu should stretch its height +- TODO Version number and author at the bottom of the page - from package.json >>> v0.2.0 diff --git a/dist/css/main.css b/dist/css/main.css index e6959d5..a90902b 100644 --- a/dist/css/main.css +++ b/dist/css/main.css @@ -257,8 +257,8 @@ ul.operators-menu { margin: 0; padding: 0; list-style-type: none; - border-top: 1px solid #d4d4d4; overflow-y: scroll; + height: 2px; } ul.operators-menu li > a { color: #7c7c7c; diff --git a/dist/js/app.js b/dist/js/app.js index fa59610..004cf1b 100644 --- a/dist/js/app.js +++ b/dist/js/app.js @@ -14,7 +14,7 @@ operatorsMenuContainer = document.querySelector(".operators-menu-container"); operatorsMenuContainer.appendChild(OperatorsMenu.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_1b45ee8e.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_6b4f4c2d.js","/") },{"buffer":3,"oMfpAn":7,"rxmarbles/views/operators-menu":27,"rxmarbles/views/sandbox":29}],2:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ @@ -13686,7 +13686,7 @@ 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/views/operator-box.js","/../../node_modules/rxmarbles/views") },{"buffer":3,"hyperscript":8,"oMfpAn":7}],27:[function(require,module,exports){ (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){ -var Examples, Rx, h, renderMenuItem, selected$, +var Examples, Rx, fixListHeight, getDocumentHeight, h, renderMenuItem, selected$, __hasProp = {}.hasOwnProperty; h = require('hyperscript'); @@ -13697,6 +13697,13 @@ Examples = require('rxmarbles/models/examples'); selected$ = new Rx.Subject(); +getDocumentHeight = function() { + var body, html; + body = document.body; + html = document.documentElement; + return Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); +}; + renderMenuItem = function(example) { var link; link = h("a", { @@ -13709,12 +13716,21 @@ renderMenuItem = function(example) { return h("li", [link]); }; +fixListHeight = function(listElement) { + return Rx.Observable.timer(1).subscribe(function() { + var height; + height = getDocumentHeight() - listElement.getBoundingClientRect().top; + listElement.style.height = "" + height + "px"; + return true; + }); +}; + module.exports = { getSelected$: function() { return selected$; }, render: function() { - var example, key, menuItems, value; + var example, key, listElement, menuItems, value; menuItems = []; for (key in Examples) { if (!__hasProp.call(Examples, key)) continue; @@ -13722,7 +13738,7 @@ module.exports = { value.key = key; menuItems.push(value); } - return h("ul.operators-menu", (function() { + listElement = h("ul.operators-menu", (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = menuItems.length; _i < _len; _i++) { @@ -13731,6 +13747,8 @@ module.exports = { } return _results; })()); + fixListHeight(listElement); + return listElement; } }; @@ -16808,4 +16826,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","/../../node_modules/virtual-hyperscript") },{"./hooks/attribute-hook.js":52,"./index.js":56,"buffer":3,"oMfpAn":7}]},{},[1]) -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9hbWVkL0hvYmJ5L3J4bWFyYmxlcy9ub2RlX21vZHVsZXMvZ3VscC1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCIvVXNlcnMvYW1lZC9Ib2JieS9yeG1hcmJsZXMvYnVpbGQvc3JjL2Zha2VfMWI0NWVlOGUuanMiLCIvVXNlcnMvYW1lZC9Ib2JieS9yeG1hcmJsZXMvbm9kZV9tb2R1bGVzL2d1bHAtYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvYnJvd3Nlci1yZXNvbHZlL2VtcHR5LmpzIiwiL1VzZXJzL2FtZWQvSG9iYnkvcnhtYXJibGVzL25vZGVfbW9kdWxlcy9ndWxwLWJyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2Jyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2J1ZmZlci9pbmRleC5qcyIsIi9Vc2Vycy9hbWVkL0hvYmJ5L3J4bWFyYmxlcy9ub2RlX21vZHVsZXMvZ3VscC1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9idWZmZXIvbm9kZV9tb2R1bGVzL2Jhc2U2NC1qcy9saWIvYjY0LmpzIiwiL1VzZXJzL2FtZWQvSG9iYnkvcnhtYXJibGVzL25vZGVfbW9kdWxlcy9ndWxwLWJyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2Jyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2J1ZmZlci9ub2RlX21vZHVsZXMvaWVlZTc1N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9IGwpXG4gICAgICBlbHNlIGlmICgnb2JqZWN0JyA9PT0gdHlwZW9mIGwpIHtcbiAgICAgICAgZm9yICh2YXIgayBpbiBsKSB7XG4gICAgICAgICAgaWYoJ2Z1bmN0aW9uJyA9PT0gdHlwZW9mIGxba10pIHtcbiAgICAgICAgICAgIGlmKC9eb25cXHcrLy50ZXN0KGspKSB7XG4gICAgICAgICAgICAgIGlmIChlLmFkZEV2ZW50TGlzdGVuZXIpe1xuICAgICAgICAgICAgICAgIGUuYWRkRXZlbnRMaXN0ZW5lcihrLnN1YnN0cmluZygyKSwgbFtrXSwgZmFsc2UpXG4gICAgICAgICAgICAgICAgY2xlYW51cEZ1bmNzLnB1c2goZnVuY3Rpb24oKXtcbiAgICAgICAgICAgICAgICAgIGUucmVtb3ZlRXZlbnRMaXN0ZW5lcihrLnN1YnN0cmluZygyKSwgbFtrXSwgZmFsc2UpXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfWVsc2V7XG4gICAgICAgICAgICAgICAgZS5hdHRhY2hFdmVudChrLCBsW2tdKVxuICAgICAgICAgICAgICAgIGNsZWFudXBGdW5jcy5wdXNoKGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICAgICAgICBlLmRldGFjaEV2ZW50KGssIGxba10pXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgLy8gb2JzZXJ2YWJsZVxuICAgICAgICAgICAgICBlW2tdID0gbFtrXSgpXG4gICAgICAgICAgICAgIGNsZWFudXBGdW5jcy5wdXNoKGxba10oZnVuY3Rpb24gKHYpIHtcbiAgICAgICAgICAgICAgICBlW2tdID0gdlxuICAgICAgICAgICAgICB9KSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSBpZihrID09PSAnc3R5bGUnKSB7XG4gICAgICAgICAgICBpZignc3RyaW5nJyA9PT0gdHlwZW9mIGxba10pIHtcbiAgICAgICAgICAgICAgZS5zdHlsZS5jc3NUZXh0ID0gbFtrXVxuICAgICAgICAgICAgfWVsc2V7XG4gICAgICAgICAgICAgIGZvciAodmFyIHMgaW4gbFtrXSkgKGZ1bmN0aW9uKHMsIHYpIHtcbiAgICAgICAgICAgICAgICBpZignZnVuY3Rpb24nID09PSB0eXBlb2Ygdikge1xuICAgICAgICAgICAgICAgICAgLy8gb2JzZXJ2YWJsZVxuICAgICAgICAgICAgICAgICAgZS5zdHlsZS5zZXRQcm9wZXJ0eShzLCB2KCkpXG4gICAgICAgICAgICAgICAgICBjbGVhbnVwRnVuY3MucHVzaCh2KGZ1bmN0aW9uICh2YWwpIHtcbiAgICAgICAgICAgICAgICAgICAgZS5zdHlsZS5zZXRQcm9wZXJ0eShzLCB2YWwpXG4gICAgICAgICAgICAgICAgICB9KSlcbiAgICAgICAgICAgICAgICB9IGVsc2VcbiAgICAgICAgICAgICAgICAgIGUuc3R5bGUuc2V0UHJvcGVydHkocywgbFtrXVtzXSlcbiAgICAgICAgICAgICAgfSkocywgbFtrXVtzXSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2UgaWYgKGsuc3Vic3RyKDAsIDUpID09PSBcImRhdGEtXCIpIHtcbiAgICAgICAgICAgIERhdGFTZXQoZSlbay5zdWJzdHIoNSldID0gbFtrXVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBlW2tdID0gbFtrXVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmICgnZnVuY3Rpb24nID09PSB0eXBlb2YgbCkge1xuICAgICAgICAvL2Fzc3VtZSBpdCdzIGFuIG9ic2VydmFibGUhXG4gICAgICAgIHZhciB2ID0gbCgpXG4gICAgICAgIGUuYXBwZW5kQ2hpbGQociA9IGlzTm9kZSh2KSA/IHYgOiBkb2N1bWVudC5jcmVhdGVUZXh0Tm9kZSh2KSlcblxuICAgICAgICBjbGVhbnVwRnVuY3MucHVz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V0VG9rZW5zKClcbiAgICAgICAgICAgICwgaW5kZXggPSBpbmRleG9mKGxpc3QsIHRva2VuKVxuXG4gICAgICAgIGlmIChpbmRleCA9PT0gLTEpIHtcbiAgICAgICAgICAgIHJldHVyblxuICAgICAgICB9XG5cbiAgICAgICAgbGlzdC5zcGxpY2UoaW5kZXgsIDEpXG4gICAgICAgIHNldFRva2VucyhsaXN0KVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIGNvbnRhaW5zKHRva2VuKSB7XG4gICAgICAgIHJldHVybiBpbmRleG9mKGdldFRva2VucygpLCB0b2tlbikgPiAtMVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIHRvZ2dsZSh0b2tlbikge1xuICAgICAgICBpZiAoY29udGFpbnModG9rZW4pKSB7XG4gICAgICAgICAgICByZW1vdmUodG9rZW4pXG4gICAgICAgICAgICByZXR1cm4gZmFsc2VcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGFkZCh0b2tlbilcbiAgICAgICAgICAgIHJldHVybiB0cnVlXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBmdW5jdGlvbiAkdG9TdHJpbmcoKSB7XG4gICAgICAgIHJldHVybiBlbGVtLmNsYXNzTmFtZVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIGl0ZW0oaW5kZXgpIHtcbiAgICAgICAgdmFyIHRva2VucyA9IGdldFRva2VucygpXG4gICAgICAgIHJldHVybiB0b2tlbnNbaW5kZXhdIHx8IG51bGxcbiAgICB9XG5cbiAgICBmdW5jdGlvbiBnZXRUb2tlbnMoKSB7XG4gICAgICAgIHZhciBjbGFzc05hbWUgPSBlbGVtLmNsYXNzTmFtZVxuXG4gICAgICAgIHJldHVybiBmaWx0ZXIoY2xhc3NOYW1lLnNwbGl0KFwiIFwiKSwgaXNUcnV0aHkpXG4gICAgfVxuXG4gICAgZnVuY3Rpb24gc2V0VG9rZW5zKGxpc3QpIHtcbiAgICAgICAgdmFyIGxlbmd0aCA9IGxpc3QubG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Wx1ZTogc3RvcmUgfSk7XHJcbiAgICAgICAgICByZXR1cm4gc3RvcmU7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAvLyBjb21tb24gcGVyLW9iamVjdCBzdG9yYWdlIGFyZWEgbWFkZSB2aXNpYmxlIGJ5IHBhdGNoaW5nIGdldE93blByb3BlcnR5TmFtZXMnXHJcbiAgICBkZWZpbmUoT2JqZWN0LCBmdW5jdGlvbiBnZXRPd25Qcm9wZXJ0eU5hbWVzKG9iail7XHJcbiAgICAgIHZhciBwcm9wcyA9IGdldFByb3BzKG9iaik7XHJcbiAgICAgIGlmIChoYXNPd24uY2FsbChvYmosIGdsb2JhbElEKSlcclxuICAgICAgICBwcm9wcy5zcGxpY2UocHJvcHMuaW5kZXhPZihnbG9iYWxJRCksIDEpO1xyXG4gICAgICByZXR1cm4gcHJvcHM7XHJcbiAgICB9KTtcclxuXHJcbiAgICBmdW5jdGlvbiBEYXRhKCl7XHJcbiAgICAgIHZhciBwdWlkID0gY3JlYXRlVUlEKCksXHJcbiAgICAgICAgICBzZWNyZXQgPSB7fTtcclxuXHJcbiAgICAgIHRoaXMudW5sb2NrID0gZnVuY3Rpb24ob2JqKXtcclxuICAgICAgICB2YXIgc3RvcmUgPSBzdG9yYWdlKG9iaik7XHJcbiAgICAgICAgaWYgKGhhc093bi5jYWxsKHN0b3JlLCBwdWlkKSlcclxuICAgICAgICAgIHJldHVybiBzdG9yZVtwdWlkXShzZWNyZXQpO1xyXG5cclxuICAgICAgICB2YXIgZGF0YSA9IGNyZWF0ZShudWxsLCBkYXRhRGVzYyk7XHJcbiAgICAgICAgZGVmUHJvcChzdG9yZSwgcHVpZCwge1xyXG4gICAgICAgICAgdmFsdWU6IG5ldyBGdW5jdGlvbigncycsICdsJywgZGF0YWxvY2spKHNlY3JldCwgZGF0YSlcclxuICAgICAgICB9KTtcclxuICAgICAgICByZXR1cm4gZGF0YTtcclxuICAgICAgfVxyXG4gICAgfVxyXG5cclxuICAgIGRlZmluZShE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W5kZXggLSAxID4+IDE7XHJcbiAgICAgICAgaWYgKHBhcmVudCA8IDAgfHwgcGFyZW50ID09PSBpbmRleCkge1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmICh0aGlzLmlzSGlnaGVyUHJpb3JpdHkoaW5kZXgsIHBhcmVudCkpIHtcclxuICAgICAgICAgICAgdmFyIHRlbXAgPSB0aGlzLml0ZW1zW2luZGV4XTtcclxuICAgICAgICAgICAgdGhpcy5pdGVtc1tpbmRleF0gPSB0aGlzLml0ZW1zW3BhcmVudF07XHJcbiAgICAgICAgICAgIHRoaXMuaXRlbXNbcGFyZW50XSA9IHRlbXA7XHJcbiAgICAgICAgICAgIHRoaXMucGVyY29sYXRlKHBhcmVudCk7XHJcbiAgICAgICAgfVxyXG4gICAgfTtcclxuXHJcbiAgICBwcmlvcml0eVByb3RvLmhlYXBpZnkgPSBmdW5jdGlvbiAoaW5kZXgpIHtcclxuICAgICAgICBpZiAoaW5kZXggPT09IHVuZGVmaW5lZCkge1xyXG4gICAgICAgICAgICBpbmRleCA9IDA7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChpbmRleCA+PSB0aGlzLmxlbmd0aCB8fCBpbmRleCA8IDApIHtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgIH1cclxuICAgICAgICB2YXIgbGVmdCA9IDIgKiBpbmRleCArIDEsXHJcbiAgICAgICAgICAgIHJpZ2h0ID0gMiAqIGluZGV4ICsgMixcclxuICAgICAgICAgICAgZmlyc3QgPSBpbmRleDtcclxuICAgICAgICBpZiAobGVmdCA8IHRoaXMubGVuZ3RoICYmIHRoaXMuaXNIaWdoZXJQcmlvcml0eShsZWZ0LCBmaXJzdCkpIHtcclxuICAgICAgICAgICAgZmlyc3QgPSBsZWZ0O1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAocmlnaHQgPCB0aGlzLmxlbmd0aCAmJiB0aGlzLmlzSGlnaGVyUH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IXRoaXMuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICB2YXIgaWR4ID0gdGhpcy5kaXNwb3NhYmxlcy5pbmRleE9mKGl0ZW0pO1xyXG4gICAgICAgICAgICBpZiAoaWR4ICE9PSAtMSkge1xyXG4gICAgICAgICAgICAgICAgc2hvdWxkRGlzcG9zZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGVzLnNwbGljZShpZHgsIDEpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5sZW5ndGgtLTtcclxuICAgICAgICAgICAgICAgIGl0ZW0uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gc2hvdWxkRGlzcG9zZTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgRGlzcG9zZXMgYWxsIGRpc3Bvc2FibGVzIGluIHRoZSBncm91cCBhbmQgcmVtb3ZlcyB0aGVtIGZyb20gdGhlIGdyb3VwLiAgXHJcbiAgICAgKi9cclxuICAgIENvbXBvc2l0ZURpc3Bvc2FibGVQcm90b3R5cGUuZGlzcG9zZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBpZiAoIXRoaXMuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICB2YXIgY3VycmVudERpc3Bvc2FibGVzID0gdGhpcy5kaXNwb3NhYmxlcy5zbGljZSgwKTtcclxuICAgICAgICAgICAgdGhpcy5kaXNwb3NhYmxlcyA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLmxlbmd0aCA9IDA7XHJcblxyXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gY3VycmVudERpc3Bvc2FibGVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBjdXJyZW50RGlzcG9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NTaW5nbGUpIHtcclxuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignRGlzcG9zYWJsZSBoYXMgYWxyZWFkeSBiZWVuIGFzc2lnbmVkJyk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHZhciBzaG91bGREaXNwb3NlID0gdGhpcy5pc0Rpc3Bvc2VkLCBvbGQ7XHJcbiAgICAgICAgICAgIGlmICghc2hvdWxkRGlzcG9zZSkge1xyXG4gICAgICAgICAgICAgICAgb2xkID0gdGhpcy5jdXJyZW50O1xyXG4gICAgICAgICAgICAgICAgdGhpcy5jdXJyZW50ID0gdmFsdWU7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgaWYgKG9sZCkge1xyXG4gICAgICAgICAgICAgICAgb2xkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpZiAoc2hvdWxkRGlzcG9zZSAmJiB2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFsdWUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqIFxyXG4gICAgICAgICAqIERpc3Bvc2VzIHRoZSB1bmRlcmx5aW5nIGRpc3Bvc2FibGUgYXMgd2VsbCBhcyBhbGwgZnV0dXJlIHJlcGxhY2VtZW50cy5cclxuICAgICAgICAgKi9cclxuICAgICAgICBib29sZWFuRGlzcG9zYWJsZVByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgb2xkO1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIG9sZCA9IHRoaXMuY3VycmVudDtcclxuICAgICAgICAgICAgICAgIHRoaXMuY3VycmVudCA9IG51bGw7XHJc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oZWR1bGVBYnNvbHV0ZTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIGludm9rZVJlY0ltbWVkaWF0ZShzY2hlZHVsZXIsIHBhaXIpIHtcclxuICAgICAgICAgICAgdmFyIHN0YXRlID0gcGFpci5maXJzdCwgYWN0aW9uID0gcGFpci5zZWNvbmQsIGdyb3VwID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uID0gZnVuY3Rpb24gKHN0YXRlMSkge1xyXG4gICAgICAgICAgICAgICAgYWN0aW9uKHN0YXRlMSwgZnVuY3Rpb24gKHN0YXRlMikge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBpc0FkZGVkID0gZmFsc2UsIGlzRG9uZSA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgICAgIGQgPSBzY2hlZHVsZXIuc2NoZWR1bGVXaXRoU3RhdGUoc3RhdGUyLCBmdW5jdGlvbiAoc2NoZWR1bGVyMSwgc3RhdGUzKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpc0FkZGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBncm91cC5yZW1vdmUoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc0RvbmUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlY3Vyc2l2ZUFjdGlvbihzdGF0ZTMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghaXNEb25lKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLmFkZChkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaXNBZGRlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIHJlY3Vyc2l2ZUFjdGlvbihzdGF0ZSk7XHJcbiAgICAgICAgICAgIHJldHVybiBncm91cDtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIGludm9rZVJlY0RhdGUoc2NoZWR1bGVyLCBwYWlyLCBtZXRob2QpIHtcclxuICAgICAgICAgICAgdmFyIHN0YXRlID0gcGFpci5maXJzdCwgYWN0aW9uID0gcGFpci5zZWNvbmQsIGdyb3VwID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uID0gZnVuY3Rpb24gKHN0YXRlMSkge1xyXG4gICAgICAgICAgICAgICAgYWN0aW9uKHN0YXRlMSwgZnVuY3Rpb24gKHN0YXRlMiwgZHVlVGltZTEpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgaXNBZGRlZCA9IGZhbHNlLCBpc0RvbmUgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgICAgICBkID0gc2NoZWR1bGVyW21ldGhvZF0uY2FsbChzY2hlZHVsZXIsIHN0YXRlMiwgZHVlVGltZTEsIGZ1bmN0aW9uIChzY2hlZHVsZXIxLCBzdGF0ZTMpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzQWRkZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLnJlbW92ZShkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzRG9uZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uKHN0YXRlMyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFpc0RvbmUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXAuYWRkKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpc0FkZGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uKHN0YXRlKTtcclxuICAgICAgICAgICAgcmV0dXJuIGdyb3VwO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gaW52b2tlQWN0aW9uKHNjaGVkdWxlciwgYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIGFjdGlvbigpO1xyXG4gICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIHNjaGVkdWxlclByb3RvID0gU2NoZWR1bGVyLnByb3RvdHlwZTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogUmV0dXJucyBhIHNjaGVkdWxlciB0aGF0IHdyYXBzIHRoZSBvcmlnaW5hbCBzY2hlZHVsZXIsIGFkZGluZyBleGNlcHRpb24gaGFuZGxpbmcgZm9yIHNjaGVkdWxlZCBhY3Rpb25zLiAgICAgICBcclxuICAgICAgICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBoYW5kbGVyIEhhbmRsZXIgdGhhdCdzIHJ1biBpZiBhbiBleGNlcHRpb24gaXMgY2F1Z2h0LiBUaGUgZXhjZXB0aW9uIHdpbGwgYmUgcmV0aHJvd24gaWYgdGhlIGhhbmRsZXIgcmV0dXJucyBmYWxzZS5cclxuICAgICAg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gICAgICAgaWYgKCFpdGVtLmlzQ2FuY2VsbGVkKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICAvLyBOb3RlLCBkbyBub3Qgc2NoZWR1bGUgYmxvY2tpbmcgd29yayFcclxuICAgICAgICAgICAgICAgICAgICB3aGlsZSAoaXRlbS5kdWVUaW1lIC0gU2NoZWR1bGVyLm5vdygpID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBpZiAoIWl0ZW0uaXNDYW5jZWxsZWQoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpdGVtLmludm9rZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSAgICAgICAgICAgIFxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc2NoZWR1bGVOb3coc3RhdGUsIGFjdGlvbikge1xyXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5zY2hlZHVsZVdpdGhSZWxhdGl2ZUFuZFN0YXRlKHN0YXRlLCAwLCBhY3Rpb24pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc2NoZWR1bGVSZWxhdGl2ZShzdGF0ZSwgZHVlVGltZSwgYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIHZhciBkdCA9IHRoaXMubm93KCkgKyBTY2hlZHVsZXIubm9ybWFsaXplKGR1ZVRpbWUpLFxyXG4gICAgICAgICAgICAgICAgICAgIHNpID0gbmV3IFNjaGVkdWxlZEl0ZW0odGhpcywgc3RhdGUsIGFjdGlvbiwgZHQpLFxyXG4gICAgICAgICAgICAgICAgICAgIHQ7XHJcbiAgICAgICAgICAgIGlmICghcXVldWUpIHtcclxuICAgICAgICAgICAgICAgIHF1ZXVlID0gbmV3IFByaW9yaXR5UXVldWUoNCk7XHJcbiAgICAgICAgICAgICAgICBxdWV1ZS5lbnF1ZXVlKHNpKTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcnVuVHJhbXBvbGluZShxdWV1ZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7IFxyXG4gICAgICAgICAgICAgICAgICAgIHRocm93IGU7XHJcbiAgICAgICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgICAgIHF1ZXVlID0gbnVsbDtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIHF1ZXVlLmVucXVldWUoc2kpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHJldHVybiBzaS5kaXNwb3NhYmxlO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc2NoZWR1bGVBYnNvbHV0ZShzdGF0ZSwgZHVlVGltZSwgYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLnNjaGVkdWxlV2l0aFJlbGF0aXZlQW5kU3RhdGUoc3RhdGUsIGR1ZVRpbWUgLSB0aGlzLm5vdygpLCBhY3Rpb24pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIGN1cnJlbnRTY2hlZHVsZXIgPSBuZXcgU2NoZWR1bGVyKGRlZmF1bHROb3csIHNjaGVkdWxlTm93LCBzY2hlZHVsZVJlbGF0aXZlLCBzY2hlZHVsZUFic29sdXRlKTtcclxuICAgICAgICBjdXJyZW50U2NoZWR1bGVyLnNjaGVkdWxlUmVxdWlyZWQgPSBmdW5jdGlvbiAoKSB7IHJldHVybiBxdWV1ZSA9PT0gbnVsbDsgfTtcclxuICAgICAgICBjdXJyZW50U2NoZWR1bGVyLmVuc3VyZVRyYW1wb2xpbmUgPSBmdW5jdGlvbiAoYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIGlmIChxdWV1ZSA9PT0gbnVsbCkge1xyXG4gICAgICAgICA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AgICAgdGhpcy5fcmVjdXJzaXZlV3JhcHBlciA9IG51bGw7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIGxvY2FsTm93LCBzY2hlZHVsZU5vdywgc2NoZWR1bGVSZWxhdGl2ZSwgc2NoZWR1bGVBYnNvbHV0ZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvKiogQHByaXZhdGUgKi9cclxuICAgICAgICBDYXRjaFNjaGVkdWxlci5wcm90b3R5cGUuX2Nsb25lID0gZnVuY3Rpb24gKHNjaGVkdWxlcikge1xyXG4gICAgICAgICAgICByZXR1cm4gbmV3IENhdGNoU2NoZWR1bGVyKHNjaGVkdWxlciwgdGhpcy5faGFuZGxlcik7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqIEBwcml2YXRlICovXHJcbiAgICAgICAgQ2F0Y2hTY2hlZHVsZXIucHJvdG90eXBlLl93cmFwID0gZnVuY3Rpb24gKGFjdGlvbikge1xyXG4gICAgICAgICAgICB2YXIgcGFyZW50ID0gdGhpcztcclxuICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIChzZWxmLCBzdGF0ZSkge1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gYWN0aW9uKHBhcmVudC5fZ2V0UmVjdXJzaXZlV3JhcHBlcihzZWxmKSwgc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghcGFyZW50Ll9oYW5kbGVyKGUpKSB7IHRocm93IGU7IH1cclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKiBAcHJpdmF0ZSAqL1xyXG4gICAgICAgIENhdGNoU2NoZWR1bGVy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YgKGZhaWxlZCkgeyByZXR1cm4gbnVsbDsgfVxyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gYWN0aW9uKHN0YXRlMSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZmFpbGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoIXNlbGYuX2hhbmRsZXIoZSkpIHsgdGhyb3cgZTsgfVxyXG4gICAgICAgICAgICAgICAgICAgIGQuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBudWxsO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSk7XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gZDtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICByZXR1cm4gQ2F0Y2hTY2hlZHVsZXI7XHJcbiAgICB9KFNjaGVkdWxlcikpO1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFJlcHJlc2VudHMgYSBub3RpZmljYXRpb24gdG8gYW4gb2JzZXJ2ZXIuXHJcbiAgICAgKi9cclxuICAgIHZhciBOb3RpZmljYXRpb24gPSBSeC5Ob3RpZmljYXRpb24gPSAoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGZ1bmN0aW9uIE5vdGlmaWNhdGlvbihraW5kLCBoYXNWYWx1ZSkgeyBcclxuICAgICAgICAgICAgdGhpcy5oYXNWYWx1ZSA9IGhhc1ZhbHVlID09IG51bGwgPyBmYWxzZSA6IGhhc1ZhbHVlO1xyXG4gICAgICAgICAgICB0aGlzLmtpbmQgPSBraW5kO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIE5vdGlmaWNhdGlvblByb3RvdHlwZSA9IE5vdGlmaWNhdGlvbi5wcm90b3R5cGU7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEludm9rZ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5fYWNjZXB0T2JzZXJ2YWJsZShvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKG5vdGlmaWNhdGlvbi5raW5kID09PSAnTicpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgcmV0dXJuIE5vdGlmaWNhdGlvbjtcclxuICAgIH0pKCk7XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBDcmVhdGVzIGFuIG9iamVjdCB0aGF0IHJlcHJlc2VudHMgYW4gT25OZXh0IG5vdGlmaWNhdGlvbiB0byBhbiBvYnNlcnZlci5cclxuICAgICAqIEBwYXJhbSB7QW55fSB2YWx1ZSBUaGUgdmFsdWUgY29udGFpbmVkIGluIHRoZSBub3RpZmljYXRpb24uXHJcbiAgICAgKiBAcmV0dXJucyB7Tm90aWZpY2F0aW9ufSBUaGUgT25OZXh0IG5vdGlmaWNhdGlvbiBjb250YWluaW5nIHRoZSB2YWx1ZS5cclxuICAgICAqL1xyXG4gICAgdmFyIG5vdGlmaWNhdGlvbkNyZWF0ZU9uTmV4dCA9IE5vdGlmaWNhdGlvbi5jcmVhdGVPbk5leHQgPSAoZnVuY3Rpb24gKCkge1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBfYWNjZXB0IChvbk5leHQpIHtcclxuICAgICAgICAgICAgcmV0dXJuIG9uTmV4dCh0aGlzLnZhbHVlKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIF9hY2NlcHRPYnNlcnZhYmxlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBvYnNlcnZlci5vbk5leHQodGhpcy52YWx1ZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiB0b1N0cmluZyAoKSB7XHJcbiAgICAgICAgICAgIHJldHVybiAnT25OZXh0KCcgKyB0aGlzLnZhbHVlICsgJyknO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICB2YXIgbm90aWZpY2F0aW9uID0gbmV3IE5vdGlmaWNhdGlvbignTicsIHRydWUpO1xyXG4gICAgICAgICAgICBub3RpZmljYXRpb24udmFsdWUgPSB2YWx1ZTtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLl9hY2NlcHQgPSBfYWNjZXB0O1xyXG4gICAgICAgICAgICBub3RpZmljYXRpb24uX2FjY2VwdE9ic2VydmFibGUgPSBfYWNjZXB0T2JzZXJ2YWJsZTtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLnRvU3RyaW5nID0gdG9TdHJpbmc7XHJcbiAgICAgICAgICAgIHJldHVybiBub3RpZmljYXRpb247XHJcbiAgICAgICAgfTtcclxuICAgIH0oKSk7XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBDcmVhdGVzIGFuIG9iamVjdCB0aGF0IHJlcHJlc2VudHMgYW4gT25FcnJvciBub3RpZmljYXRpb24gdG8gYW4gb2JzZXJ2ZXIuXHJcbiAgICAgKiBAcGFyYW0ge0FueX0gZXJyb3IgVGhlIGV4Y2VwdGlvbiBjb250YWluZWQgaW4gdGhlIG5vdGlmaWNhdGlvbi5cclxuICAgICAqIEByZXR1cm5zIHtOb3RpZmljYXRpb259IFRoZSBPbkVycm9yIG5vdGlmaWNhdGlvbiBjb250YWluaW5nIHRoZSBleGNlcHRpb24uXHJcbiAgICAgKi9cclxuICAgIHZhciBub3RpZmljYXRpb25DcmVhdGVPbkVycm9yID0gTm90aWZpY2F0aW9uLmNyZWF0ZU9uRXJyb3IgPSAoZnVuY3Rpb24gKCkge1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBfYWNjZXB0IChvbk5leHQsIG9uRXJyb3IpIHtcclxuICAgICAgICAgICAgcmV0dXJuIG9uRXJyb3IodGhpcy5leGNlcHRpb24pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gX2FjY2VwdE9ic2VydmFibGUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgcmV0dXJuIG9ic2VydmVyLm9uRXJyb3IodGhpcy5leGNlcHRpb24pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gdG9TdHJpbmcgKCkge1xyXG4gICAgICAgICAgICByZXR1cm4gJ09uRXJyb3IoJyArIHRoaXMuZXhjZXB0aW9uICsgJyknO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgdmFyIG5vdGlmaWNhdGlvbiA9IG5ldyBOb3RpZmljYXRpb24oJ0UnKTtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLmV4Y2VwdGlvbiA9IGV4Y2VwdGlvbjtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLl9hY2NlcHQgPSBfYWNjZXB0O1xyXG4gICAgICAgICAgICBub3RpZmljYXRpb24uX2FjY2VwdE9ic2VydmFibGUgPSBfYWNjZXB0T2JzZXJ2YWJsZTtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLnRvU3RyaW5nID0gdG9TdHJpbmc7XHJcbiAgICAgICAgICAgIHJldHVybiBub3RpZmljYXRpb247XHJcbiAgICAgICAgfTtcclxuICAgIH0oKSk7XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBDcmVhdGVzIGFuIG9iamVjdCB0aGF0IHJlcHJlc2VudHMgYW4gT25Db21wbGV0ZWQgbm90aWZpY2F0aW9uIHRvIGFuIG9ic2VydmVyLlxyXG4gICAgICogQHJldHVybnMge05vdGlmaWNhdGlvbn0gVGhlIE9uQ29tcGxldGVkIG5vdGlmaWNhdGlvbi5c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ZWxmKSB7XHJcbiAgICAgICAgdmFyIGN1cnJlbnRJdGVtO1xyXG4gICAgICAgIGlmIChpc0Rpc3Bvc2VkKSB7IHJldHVybjsgfVxyXG5cclxuICAgICAgICB0cnkge1xyXG4gICAgICAgICAgY3VycmVudEl0ZW0gPSBlLm5leHQoKTtcclxuICAgICAgICB9IGNhdGNoIChleCkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpZiAoY3VycmVudEl0ZW0uZG9uZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8vIENoZWNrIGlmIHByb21pc2VcclxuICAgICAgICB2YXIgY3VycmVudFZhbHVlID0gY3VycmVudEl0ZW0udmFsdWU7XHJcbiAgICAgICAgaXNQcm9taXNlKGN1cnJlbnRWYWx1ZSkgJiYgKGN1cnJlbnRWYWx1ZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShjdXJyZW50VmFsdWUpKTtcclxuXHJcbiAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICBkLnNldERpc3Bvc2FibGUoY3VycmVudFZhbHVlLnN1YnNjcmliZShcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dC5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICBmdW5jdGlvbiAoKSB7IHNlbGYoKTsgfSlcclxuICAgICAgICApO1xyXG4gICAgICB9KTtcclxuXHJcbiAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJs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AgICAgICAgKiBOb3RpZmllcyB0aGUgb2JzZXJ2ZXIgb2YgYSBuZXcgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICogIFxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBBYnN0cmFjdE9ic2VydmVyXHJcbiAgICAgICAgICogQHBhcmFtIHtBbnl9IHZhbHVlIE5leHQgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuIFxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIEFic3RyYWN0T2JzZXJ2ZXIucHJvdG90eXBlLm9uTmV4dCA9IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogTm90aWZpZXMgdGhlIG9ic2VydmVyIHRoYXQgYW4gZXhjZXB0aW9uIGhhcyBvY2N1cnJlZC5cclxuICAgICAgICAgKiBcclxuICAgICAgICAgKiBAbWVtYmVyT2YgQWJzdHJhY3RPYnNlcnZlclxyXG4gICAgICAgICAqIEBwYXJhbSB7QW55fSBlcnJvciBUaGUgZXJyb3IgdGhhdCBoYXMgb2NjdXJyZWQuICAgICBcclxuICAgICAgICAgKi8gICAgXHJcbiAgICAgICAgQWJzdHJhY3RPYnNlcnZlci5wcm90b3R5cGUub25FcnJvciA9IGZ1bmN0aW9uIChlcnJvcikge1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmVycm9yKGVycm9yKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIE5vdGlmaWVzIHRoZSBvYnNlcnZlciBvZiB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgKi8gICAgXHJcbiAgICAgICAgQWJzdHJhY3RPYnNlcnZlci5wcm90b3R5cGUub25Db21wbGV0ZWQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMuY29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBEaXNwb3NlcyB0aGUgb2JzZXJ2ZXIsIGNhdXNpbmcgaXQgdG8gdHJhbnNpdGlvbiB0byB0aGUgc3RvcHBlZCBzdGF0ZS5cclxuICAgICAgICAgKi9cclxuICAgICAgICBBYnN0cmFjdE9ic2VydmVyLnByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQWJzdHJhY3RPYnNlcnZlci5wcm90b3R5cGUuZmFpbCA9IGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIHJldHVybiBBYnN0cmFjdE9ic2VydmVyO1xyXG4gICAgfShPYnNlcnZlcikp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yKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICB0aGlzLl9vYnNlcnZlciA9IG9ic2VydmVyO1xyXG4gICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IDA7IC8vIDAgLSBpZGxlLCAxIC0gYnVzeSwgMiAtIGRvbmVcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHZhciBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUgPSBDaGVja2VkT2JzZXJ2ZXIucHJvdG90eXBlO1xyXG5cclxuICAgICAgICBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUub25OZXh0ID0gZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgIHRoaXMuY2hlY2tBY2Nlc3MoKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX29ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlOyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5vbkVycm9yID0gZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgICB0aGlzLmNoZWNrQWNjZXNzKCk7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9vYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlOyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICA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CA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgdmFyIHNlbGYgPSB0aGlzO1xyXG4gICAgICB0aGlzLnF1ZXVlLnB1c2goZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHNlbGYub2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIFNjaGVkdWxlZE9ic2VydmVyLnByb3RvdHlwZS5lbnN1cmVBY3RpdmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgIHZhciBpc093bmVyID0gZmFsc2UsIHBhcmVudCA9IHRoaXM7XHJcbiAgICAgIGlmICghdGhpcy5oYXNGYXVsdGVkICYmIHRoaXMucXVldWUubGVuZ3RoID4gMCkge1xyXG4gICAgICAgIGlzT3duZXIgPSAhdGhpcy5pc0FjcXVpcmVkO1xyXG4gICAgICAgIHRoaXMuaXNBY3F1aXJlZCA9IHRydWU7XHJcbiAgICAgIH1cclxuICAgICAgaWYgKGlzT3duZXIpIHtcclxuICAgICAgICB0aGlzLmRpc3Bvc2FibGUuc2V0RGlzcG9zYWJsZSh0aGlzLnNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZShmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgdmFyIHdvcms7XHJcbiAgICAgICAgICBpZiAocGFyZW50LnF1ZXVlLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgd29yayA9IHBhcmVudC5xdWV1ZS5zaGlmdCgpO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgcGFyZW50LmlzQWNxdWlyZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgd29yaygpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZXgpIHtcclxuICAgICAgICAgICAgcGFyZW50LnF1ZXVlID0gW107XHJcbiAgICAgICAg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YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IHByb21pc2VDdG9yKGZ1bmN0aW9uIChyZXNvbHZlLCByZWplY3QpIHtcclxuICAgICAgICAgICAgLy8gTm8gY2FuY2VsbGF0aW9uIGNhbiBiZSBkb25lXHJcbiAgICAgICAgICAgIHZhciB2YWx1ZSwgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAodikge1xyXG4gICAgICAgICAgICAgICAgdmFsdWUgPSB2O1xyXG4gICAgICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgICByZWplY3QoZXJyKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1ZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmVzb2x2ZSh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuICAvKipcclxuICAgKiBDcmVhdGVzIGEgbGlzdCBmcm9tIGFuIG9ic2VydmFibGUgc2VxdWVuY2UuXHJcbiAgICogQHJldHVybnMgQW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSBjb250YWluaW5nIGEgc2luZ2xlIGVsZW1lbnQgd2l0aCBhIGxpc3QgY29udGFpbmluZyBhbGwgdGhlIGVsZW1lbnRzIG9mIHRoZSBzb3VyY2Ugc2VxdWVuY2UuICBcclxuICAgKi9cclxuICBvYnNlcnZhYmxlUHJvdG8udG9BcnJheSA9IGZ1bmN0aW9uICgpIHtcclxuICAgIHZhciBzZWxmID0gdGhpcztcclxuICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbihvYnNlcnZlcikge1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zZWxmKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgaGFzUmVzdWx0LCByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmaXJzdCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlID0gaXRlcmF0ZShzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1Jlc3VsdCA9IGNvbmRpdGlvbihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICAgICAgICBzZWxmKCk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogIFRoaXMgbWV0aG9kIGNyZWF0ZXMgYSBu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1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGNob2ljZUwoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSBsZWZ0Q2hvaWNlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSkpO1xyXG5cclxuICAgICAgcmlnaHRTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShyaWdodFNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHJpZ2h0KSB7XHJcbiAgICAgICAgY2hvaWNlUigpO1xyXG4gICAgICAgIGlmIChjaG9pY2UgPT09IHJpZ2h0Q2hvaWNlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmlnaHQpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgIGNob2ljZVIoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSByaWdodENob2ljZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGNob2ljZVIoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSByaWdodENob2ljZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcbiAgICAgIH0pKTtcclxuXHJcbiAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShsZWZ0U3Vic2NyaXB0aW9uLCByaWdodFN1YnNjcmlwdGlvbik7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAvKipcclxuICAgKiBQcm9wYWdhdGVzIHRoZSBvYnNlcnZhYmxlIHNlcXVlbmNlIG9yIFByb21pc2UgdGhhdCByZWFjdHMgZmlyc3QuXHJcbiA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ksXHJcbiAgICAgICAgICAgICAgICBpc1N0b3BwZWQgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgIHEgPSBbXSxcclxuICAgICAgICAgICAgICAgIHN1YnNjcmliZSA9IGZ1bmN0aW9uICh4cykge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBzdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICBncm91cC5hZGQoc3Vic2NyaXB0aW9uKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgLy8gQ2hlY2sgZm9yIHByb21pc2VzIHN1cHBvcnRcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaXNQcm9taXNlKHhzKSkgeyB4cyA9IG9ic2VydmFibGVGcm9tUHJvbWlzZSh4cyk7IH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoeHMuc3Vic2NyaWJlKG9ic2VydmVyLm9uTmV4dC5iaW5kKG9ic2VydmVyKSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgcztcclxuICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKHN1YnNjcmlwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMgPSBxLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmUocyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY3RpdmVDb3VudC0tO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzU3RvcHBlZCAmJiBhY3RpdmVDb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICBncm91cC5hZGQoc291cmNlcy5zdWJzY3JpYmUoZnVuY3Rpb24gKGlubmVyU291cmNlKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoYWN0aXZlQ291bnQgPCBtYXhDb25jdXJyZW50T3JPdGhlcikge1xyXG4gICAgICAgICAgICAgICAgICAgIGFjdGl2ZUNvdW50Kys7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlKGlubmVyU291cmNlKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKGlubmVyU291cmNlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIGlmIChhY3RpdmVDb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgcmV0dXJuIGdyb3VwO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqIE1lcmdlcyBhbGwgdGhlIG9ic2VydmFibGUgc2VxdWVuY2VzIGludG8gYSBzaW5nbGUgb2JzZXJ2YWJsZSBzZXF1ZW5jZS4gIF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zY3JpcHRpb24gPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgaXNTdG9wcGVkID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICBsYXRlc3QgPSAwLFxyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uID0gc291cmNlcy5zdWJzY3JpYmUoZnVuY3Rpb24gKGlubmVyU291cmNlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKSwgaWQgPSArK2xhdGVzdDtcclxuICAgICAgICAgICAgICAgICAgICBoYXNMYXRlc3QgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGlubmVyU3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoZCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIC8vIENoZWNrIGlmIFByb21pc2Ugb3IgT2JzZXJ2YWJsZVxyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpc1Byb21pc2UoaW5uZXJTb3VyY2UpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyU291cmNlID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKGlubmVyU291cmNlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZShpbm5lclNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxhdGVzdCA9PT0gaWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsYXRlc3QgPT09IGlkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAobGF0ZXN0ID09PSBpZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzTGF0ZXN0ID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBpc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghaGFzTGF0ZXN0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShzdWJzY3JpcHRpb24sIGlubmVyU3Vic2NyaXB0aW9uKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIC8qKlxyXG4gICAqIFJldHVybnMgdGhlIHZhbHVlcyBmcm9tIHRoZSBzb3VyY2Ugb2JzZXJ2YWJsZSBzZXF1ZW5jZSB1bnRpbCB0aGUgb3RoZXIgb2JzZXJ2YWJsZSBzZXF1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ICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgZnVuY3Rpb24gZG9uZShpKSB7XHJcbiAgICAgICAgICAgICAgICBpc0RvbmVbaV0gPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgaWYgKGlzRG9uZS5ldmVyeShpZGVudGl0eSkpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdmFyIHN1YnNjcmlwdGlvbnMgPSBuZXcgQXJyYXkobik7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGlkeCA9IDA7IGlkeCA8IG47IGlkeCsrKSB7XHJcbiAgICAgICAgICAgICAgICAoZnVuY3Rpb24gKGkpIHtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb25zW2ldID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uc1tpXS5zZXREaXNwb3NhYmxlKHNvdXJjZXNbaV0uc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHF1ZXVlc1tpXS5wdXNoKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBuZXh0KGkpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZG9uZShpKTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiA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hcmVyKSB7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAga2V5U2VsZWN0b3IgfHwgKGtleVNlbGVjdG9yID0gaWRlbnRpdHkpO1xyXG4gICAgICAgIGNvbXBhcmVyIHx8IChjb21wYXJlciA9IGRlZmF1bHRDb21wYXJlcik7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaGFzQ3VycmVudEtleSA9IGZhbHNlLCBjdXJyZW50S2V5O1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHZhciBjb21wYXJlckVxdWFscyA9IGZhbHNlLCBrZXk7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGtleSA9IGtleVNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzQ3VycmVudEtleSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbXBhcmVyRXF1YWxzID0gY29tcGFyZXIoY3VycmVudEtleSwga2V5KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgIC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kVycm9yLCBvbkNvbXBsZXRlZCkge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzLCBvbk5leHRGdW5jO1xyXG4gICAgICAgIGlmICh0eXBlb2Ygb2JzZXJ2ZXJPck9uTmV4dCA9PT0gJ2Z1bmN0aW9uJykge1xyXG4gICAgICAgICAgICBvbk5leHRGdW5jID0gb2JzZXJ2ZXJPck9uTmV4dDtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBvbk5leHRGdW5jID0gb2JzZXJ2ZXJPck9uTmV4dC5vbk5leHQuYmluZChvYnNlcnZlck9yT25OZXh0KTtcclxuICAgICAgICAgICAgb25FcnJvciA9IG9ic2VydmVyT3JPbk5leHQub25FcnJvci5iaW5kKG9ic2VydmVyT3JPbk5leHQpO1xyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZCA9IG9ic2VydmVyT3JPbk5leHQub25Db21wbGV0ZWQuYmluZChvYnNlcnZlck9yT25OZXh0KTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBvbk5leHRGdW5jKHgpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIGlmICghb25FcnJvcikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIW9uQ29tcGxldGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogIEludm9rZXMgYSBzcGVjaWZpZWQgYWN0aW9uIGFmdGVyIHRoZSBzb3VyY2Ugb2JzZXJ2YWJsZSBzZXF1ZW5jZSB0ZXJtaW5hdGVzIGdyYWNlZnVsbHkgb3IgZXhjZXB0aW9uYWxseS5cclxuICAgKiAgXHJc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IHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlIChcclxuICAgICAgICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFoYXNWYWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXNBY2N1bXVsYXRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFjY3VtdWxhdGlvbiA9IGFjY3VtdWxhdG9yKGFjY3VtdWxhdGlvbiwgeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY2N1bXVsYXRpb24gPSBoYXNTZWVkID8gYWNjdW11bGF0b3Ioc2VlZCwgeCkgOiB4O1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzQWNjdW11bGF0aW9uID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgIFxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhY2N1bXVsYXRpb24pO1xyXG4gICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICA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eHMsIHNjaGVkdWxlcik7IH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBSZXR1cm5zIGFuIGFycmF5IHdpdGggdGhlIHNwZWNpZmllZCBudW1iZXIgb2YgY29udGlndW91cyBlbGVtZW50cyBmcm9tIHRoZSBlbmQgb2YgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZS5cclxuICAgICAqICBcclxuICAgICAqIEBkZXNjcmlwdGlvblxyXG4gICAgICogIFRoaXMgb3BlcmF0b3IgYWNjdW11bGF0ZXMgYSBidWZmZXIgd2l0aCBhIGxlbmd0aCBlbm91Z2ggdG8gc3RvcmUgY291bnQgZWxlbWVudHMuIFVwb24gY29tcGxldGlvbiBvZiB0aGVcclxuICAgICAqICBzb3VyY2Ugc2VxdWVuY2UsIHRoaXMgYnVmZmVyIGlzIHByb2R1Y2VkIG9uIHRoZSByZXN1bHQgc2VxdWVuY2UuICAgICAgIFxyXG4gICAgICogQHBhcmFtIHtOdW1iZXJ9IGNvdW50IE51bWJlciBvZiBlbGVtZW50cyB0byB0YWtlIGZyb20gdGhlIGVuZCBvZiB0aGUgc291cmNlIHNlcXVlbmNlLlxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2UgY29udGFpbmluZyBhIHNpbmdsZSBhcnJheSB3aXRoIHRoZSBzcGVjaWZpZWQgbnVtYmVyIG9mIGVsZW1lbnRzIGZyb20gdGhlIGVuZCBvZiB0aGUgc291cmNlIHNlcXVlbmNlLlxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8udGFrZUxhc3RCdWZmZXIgPSBmdW5jdGlvbiAoY291bnQpIHtcclxuICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBxID0gW107XHJcbiAgICAg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m5zIHtPYnNlcnZhYmxlfSBBbiBvYnNlcnZhYmxlIHNlcXVlbmNlIG9mIHdpbmRvd3MuICBcclxuICAgICAqL1xyXG4gICAgb2JzZXJ2YWJsZVByb3RvLndpbmRvd1dpdGhDb3VudCA9IGZ1bmN0aW9uIChjb3VudCwgc2tpcCkge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIGlmIChjb3VudCA8PSAwKSB7XHJcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAgICAgICBza2lwID0gY291bnQ7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChza2lwIDw9IDApIHtcclxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIG0gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHJlZkNvdW50RGlzcG9zYWJsZSA9IG5ldyBSZWZDb3VudERpc3Bvc2FibGUobSksXHJcbiAgICAgICAgICAgICAgICBuID0gMCxcclxuICAgICAgICAgICAgICAgIHEgPSBbXSxcclxuICAgICAgICAgICAgICAgIGNyZWF0ZVdpbmRvdyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHMpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICBjcmVhdGVXaW5kb3coKTtcclxuICAgICAgICAgICAgbS5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBzO1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IHEubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICBxW2ldLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHZhciBjID0gbiAtIGNvdW50ICsgMTtcclxuICAgICAgICAgICAgICAgIGlmIChjID49IDAgJiYgYyAlIHNraXAgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBzID0gcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG4rKztcclxuICAgICAgICAgICAgICAgIGlmIChuICUgc2tpcCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGNyZWF0ZVdpbmRvdygpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5zaGlmdCgpLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHEuc2hpZnQoKS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICByZXR1cm4gcmVmQ291bnREaXNwb3NhYmxlO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBjb25jYXRNYXAoc2VsZWN0b3IpIHtcclxuICAgICAgcmV0dXJuIHRoaXMubWFwKGZ1bmN0aW9uICh4LCBpKSB7XHJcbiAgICAgICAgdmFyIHJlc3VsdCA9IHNlbGVjdG9yKHgsIGkpO1xyXG4gICAgICAgIHJldHVybiBpc1Byb21pc2UocmVzdWx0KSA/IG9ic2VydmFibGVGcm9tUHJvbWlzZShyZXN1bHQpIDogcmVzdWx0O1xyXG4gICAgICB9KS5jb25jYXRBbGwoKTtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBjb25jYXRNYXBPYnNlcnZlcihvbk5leHQsIG9uRXJyb3IsIG9uQ29tcGxldGVkKSB7XHJcbiAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgdmFyIGluZGV4ID0gMDtcclxuXHJcbiAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQob25OZXh0KHgsIGluZGV4KyspKTtcclxuICAgICAgICAgIH0sXHJcbiAgICAgICAgICBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChvbkVycm9yKGVycikpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5jb21w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dWx0VmFsdWUgPT09IHVuZGVmaW5lZCkge1xyXG4gICAgICAgICAgICBkZWZhdWx0VmFsdWUgPSBudWxsO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBmb3VuZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgZm91bmQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIWZvdW5kKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGRlZmF1bHRWYWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUmV0dXJucyBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIHRoYXQgY29udGFpbnMgb25seSBkaXN0aW5jdCBlbGVtZW50cyBhY2NvcmRpbmcgdG8gdGhlIGtleVNlbGVjdG9yIGFuZCB0aGUgY29tcGFyZXIuXHJcbiAgICAgKiAgVXNhZ2Ugb2YgdGhpcyBvcGVyYXRvciBzaG91bGQgYmUgY29uc2lkZXJlZCBjYXJlZnVsbHkgZHVlIHRvIHRoZSBtYWludGVuYW5jZSBvZiBhbiBpbnRlcm5hbCBsb29rdXAgc3RydWN0dXJlIHdoaWNoIGNhbiBncm93IGxhcmdlLiBcclxu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IgPSBkZWZhdWx0S2V5U2VyaWFsaXplcik7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaGFzaFNldCA9IHt9O1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGtleSwgc2VyaWFsaXplZEtleSwgb3RoZXJLZXksIGhhc01hdGNoID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGtleSA9IGtleVNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHNlcmlhbGl6ZWRLZXkgPSBrZXlTZXJpYWxpemVyKGtleSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgZm9yIChvdGhlcktleSBpbiBoYXNoU2V0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHNlcmlhbGl6ZWRLZXkgPT09IG90aGVyS2V5KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGhhc01hdGNoID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNNYXRjaCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGhhc2hTZXRbc2VyaWFsaXplZEtleV0gPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4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gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIG1hcCA9IHt9LFxyXG4gICAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHJlZkNvdW50RGlzcG9zYWJsZSA9IG5ldyBSZWZDb3VudERpc3Bvc2FibGUoZ3JvdXBEaXNwb3NhYmxlKTtcclxuICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLmFkZChzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgZHVyYXRpb24sIGR1cmF0aW9uR3JvdXAsIGVsZW1lbnQsIGZpcmVOZXdNYXBFbnRyeSwgZ3JvdXAsIGtleSwgc2VyaWFsaXplZEtleSwgbWQsIHdyaXRlciwgdztcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAga2V5ID0ga2V5U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgc2VyaWFsaXplZEtleSA9IGtleVNlcmlhbGl6ZXIoa2V5KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG1hcFt3XS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGZpcmVOZXdNYXBFbnRyeSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICB3cml0ZXIgPSBtYXBbc2VyaWFsaXplZEtleV07XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCF3cml0ZXIpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgd3JpdGVyID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbWFwW3NlcmlhbGl6ZWRLZXldID0gd3JpdGVyO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmaXJlTmV3TWFwRW50cnkgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG1hcFt3XS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChmaXJlTmV3TWFwRW50cnkpIHtcclxuICAgICAgICAgICAgICAgICAgICBncm91cCA9IG5ldyBHcm91cGVkT2JzZXJ2YWJsZShrZXksIHdyaXRlciwgcmVmQ291bnREaXNwb3NhYmxlKTtcclxuICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbkdyb3VwID0gbmV3IEdyb3VwZWRPYnNlcnZhYmxlKGtleSwgd3JpdGVyKTtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbiA9IGR1cmF0aW9uU2VsZWN0b3IoZHVyYXRpb25Hcm91cCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXBbd10ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChncm91cCk7XHJcbiAgICAgICAgICAgICAgICAgICAgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICBncm91cERpc3Bvc2FibGUuYWRkKG1kKTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgZXhwaXJlID0gZnVuY3Rpb24gICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNlcmlhbGl6ZWRLZXkgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWxldGUgbWFwW3NlcmlhbGl6ZWRLZXldO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgd3JpdGVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKG5vb3AsIGZ1bmN0aW9uIChleG4pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yICh3IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uRXJyb3IoZXhuKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBleHBpcmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGVsZW1lbnQgPSBlbGVtZW50U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh3IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBtYXBbd10ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB3cml0ZXIub25OZXh0KGVsZW1lbnQpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXgpIHtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KSk7X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G5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgIH1cclxuICAgICAgICB2YXIgb2JzZXJ2YWJsZSA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgcmVtYWluaW5nID0gY291bnQ7XHJcbiAgICAgICAgICAgIHJldHVybiBvYnNlcnZhYmxlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKHJlbWFpbmluZyA8PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICByZW1haW5pbmctLTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBCeXBhc3NlcyBlbGVtZW50cyBpbiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIGFzIGxvbmcgYXMgYSBzcGVjaWZpZWQgY29uZGl0aW9uIGlzIHRydWUgYW5kIHRoZW4gcmV0dXJucyB0aGUgcmVtYWluaW5nIGVsZW1lbnRzLlxyXG4gICAgICogIFRoZSBlbGVtZW50J3MgaW5kZXggaXMgdXNlZCBpbiB0aGUgbG9naWMgb2YgdGhlIHByZWRpY2F0ZSBmdW5jdGlvbi5cclxuICAgICAqICBcclxuICAgICAqICB2YXIgcmVzID0gc291cmNlLnNraXBXaGlsZShmdW5jdGlvbiAodmFsdWUpIHsgcmV0dXJuIHZhbHVlIDwgMTA7IH0pO1xyXG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pYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghcnVubmluZykge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJ1bm5pbmcgPSAhcHJlZGljYXRlLmNhbGwodGhpc0FyZywgeCwgaSsrLCBzb3VyY2UpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChydW5uaW5nKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBvYnNlcnZlci5vbkNvbXBsZXRlZC5iaW5kKG9ic2VydmVyKSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFJldHVybnMgYSBzcGVjaWZpZWQgbnVtYmVyIG9mIGNvbnRpZ3VvdXMgZWxlbWVudHMgZnJvbSB0aGUgc3RhcnQgb2YgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSwgdXNpbmcgdGhlIHNwZWNpZmllZCBzY2hlZHVsZXIgZm9yIHRoZSBlZGdlIGNhc2Ugb2YgdGFrZSgwKS5cclxuICAgICAqICBcclxuICAgICAqICB2YXIgcmVzID0gc291cmNlLnRha2UoNSk7XHJcbiAgICAgKiAgdmFyIHJlcyA9IHNvdXJjZS50YWtlKDAsIFJ4LlNjaGVkdWxlci50aW1lb3V0KTtcclxuICAgICAqIEBwYXJhbSB7TnVtYmVyfSBjb3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ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBpZiAocnVubmluZykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgRmlsdGVycyB0aGUgZWxlbWVudHMgb2YgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSBiYXNlZCBvbiBhIHByZWRpY2F0ZSBieSBpbmNvcnBvcmF0aW5nIHRoZSBlbGVtZW50J3MgaW5kZXguXHJcbiAgICAgKiAgXHJcbiAgICAgKiBAZXhhbXBsZVxyXG4gICAgICogIHZhciByZXMgPSBzb3VyY2Uud2hlcmUoZnVuY3Rpb24gKHZhbHVlKSB7IHJldHVybiB2YWx1ZSA8IDEwOyB9KTtcclxuICAgICAqICB2YXIgcmVzID0gc291cmNlLndoZXJlKGZ1bmN0aW9uICh2YWx1ZSwgaW5kZXgpIHsgcmV0dXJuIHZhbHVlIDwgMTAgfHwgaW5kZXggPCAxMDsgfSk7XHJcbiAgICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBwcmVkaWNhdGUgQSBmdW5jdGlvbiB0byB0ZXN0IGVhY2ggc291cmNlIGVsZW1lbnQgZm9yIGEgY29uZGl0aW9uOyB0aGUgc2Vjb25kIHBhcmFtZXRlci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ZXlTZWxlY3RvciwgY29tcGFyZXIpIHtcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBoYXNWYWx1ZSA9IGZhbHNlLCBsYXN0S2V5ID0gbnVsbCwgbGlzdCA9IFtdO1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGNvbXBhcmlzb24sIGtleTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAga2V5ID0ga2V5U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGNvbXBhcmlzb24gPSAwO1xyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNWYWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBsYXN0S2V5ID0ga2V5O1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBjb21wYXJpc29uID0gY29tcGFyZXIoa2V5LCBsYXN0S2V5KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChleDEpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleDEpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGNvbXBhcmlzb24gPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbGFzdEtleSA9IGtleTtcclxuICAgICAgICAgICAgICAgICAgICBsaXN0ID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoY29tcGFyaXNvbiA+PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbGlzdC5wdXNoKHgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQobGlzdCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBmaXJzdE9ubHkoeCkge1xyXG4gICAgICAgIGlmICh4Lmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3Ioc2VxdWVuY2VDb250YWluc05vRWxlbWVudHMpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4geFswXTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIEFwcGxpZXMgYW4gYWNjdW11bGF0b3IgZnVuY3Rpb24gb3ZlciBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlLCByZXR1cm5pbmcgdGhlIHJlc3VsdCBvZiB0aGUgYWdncmVnYXRpb24gYXMgYSBzaW5nbGUgZWxlbWVudCBpbiB0aGUgcmVzdWx0IHNlcXVlbmNlLiBUaGUgc3BlY2lmaWVkIHNlZWQgdmFsdWUgaXMgdXNlZCBhcyB0aGUgaW5pdGlhbCBhY2N1bXVsYXRvciB2YWx1ZS5cclxuICAgICAqIEZvciBhZ2dyZWdhdGl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IHJlcyA9IHNvdXJjZS5hdmVyYWdlKCk7XHJcbiAgICAgKiB2YXIgcmVzID0gcmVzID0gc291cmNlLmF2ZXJhZ2UoZnVuY3Rpb24gKHgpIHsgcmV0dXJuIHgudmFsdWU7IH0pO1xyXG4gICAgICogQHBhcmFtIHtGdW5jdGlvbn0gW3NlbGVjdG9yXSBBIHRyYW5zZm9ybSBmdW5jdGlvbiB0byBhcHBseSB0byBlYWNoIGVsZW1lbnQuXHJcbiAgICAgKiBAcGFyYW0ge0FueX0gW3RoaXNBcmddIE9iamVjdCB0byB1c2UgYXMgdGhpcyB3aGVuIGV4ZWN1dGluZyBjYWxsYmFjay4gICAgICAgIFxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2UgY29udGFpbmluZyBhIHNpbmdsZSBlbGVtZW50IHdpdGggdGhlIGF2ZXJhZ2Ugb2YgdGhlIHNlcXVlbmNlIG9mIHZhbHVlcy5cclxuICAgICAqL1xyXG4gICAgb2JzZXJ2YWJsZVByb3RvLmF2ZXJhZ2UgPSBmdW5jdGlvbiAoa2V5U2VsZWN0b3IsIHRoaXNBcmcpIHtcclxuICAgICAgICByZXR1cm4ga2V5U2VsZWN0b3IgP1xyXG4gICAgICAgICAgICB0aGlzLnNlbGVjdChrZXlTZWxlY3RvciwgdGhpc0FyZykuYXZlcmFnZSgpIDpcclxuICAgICAgICAgICAgdGhpcy5zY2FuKHtcclxuICAgICAgICAgICAgICAgIHN1bTogMCxcclxuICAgICAgICAgICAgICAgIGNvdW50OiAwXHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChwcmV2LCBjdXIpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3VtOiBwcmV2LnN1bSArIGN1cixcclxuICAgICAgICAgICAgICAgICAgICBjb3VudDogcHJldi5jb3VudCArIDFcclxuICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIH0pLmZpbmFsVmFsdWUoKS5zZWxlY3QoZnVuY3Rpb24gKHMpIHtcclxuICAgICAgICAgICAgICAgIGlmIChzLmNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdUaGUgaW5wdXQgc2VxdWVuY2Ugd2FzIGVtcHR5Jyk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gcy5zdW0gLyBzLmNvdW50O1xyXG4gICAgICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIGZ1bmN0aW9uIHNlcXVlbmNlRXF1YWxBcnJheShmaXJzdCwgc2Vjb25kLCBjb21wYXJlcikge1xyXG4gICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgdmFyIGNvdW50ID0gMCwgbGVuID0gc2Vjb25kLmxlbmd0aDtcclxuICAgICAgICByZXR1cm4gZmlyc3Quc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgdmFyIGVxdWFsID0gZmFsc2U7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBpZiAoY291bnQgPCBsZW4pIHtcclxuICAgICAgICAgICAgICBlcXVhbCA9IGNvbXBhcmVyKHZhbHVlLCBzZWNvbmRbY291bnQrK10pO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlmICghZXF1YWwpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICA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AgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIGVxdWFsID0gY29tcGFyZXIodiwgeCk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpZiAoIWVxdWFsKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSBlbHNlIGlmIChkb25lcikge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHFsLnB1c2goeCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZG9uZWwgPSB0cnVlO1xyXG4gICAgICAgIGlmIChxbC5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgIGlmIChxci5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9IGVsc2UgaWYgKGRvbmVyKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh0cnVlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgIH0pO1xyXG5cclxuICAgICAgaXNQcm9taXNlKHNlY29uZCkgJiYgKHNlY29uZCA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShzZWNvbmQpKTtcclxuICAgICAgdmFyIHN1YnNjcmlwdGlvbjIgPSBzZWNvbmQuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgdmFyIGVxdWFsLCB2O1xyXG4gICAgICAgIGlmIChxbC5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICB2ID0gcWwuc2hpZnQoKTtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGVxdWFsID0gY29tcGFyZXIodiwgeCk7XHJcbiAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpZiAoIWVxdWFsKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSBlbHNlIGlmIChkb25lbCkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHFyLnB1c2goeCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZG9uZXIgPSB0cnVlO1xyXG4gICAgICAgIGlmIChxci5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgIGlmIChxbC5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9IGVsc2UgaWYgKGRvbmVsKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh0cnVlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgIH0pO1xyXG4gICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uMSwgc3Vic2NyaXB0aW9uMik7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIGVsZW1lbnRBdE9yRGVmYXVsdChzb3VyY2UsIGluZGV4LCBoYXNEZWZhdWx0LCBkZWZhdWx0VmFsdWUpIHtcclxuICAgICAgICBpZiAoaW5kZXggPCAwKSB7XHJcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBpID0gaW5kZXg7XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoaSA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaS0tO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIWhh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c0RlZmF1bHQsIGRlZmF1bHRWYWx1ZSkge1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHZhbHVlID0gZGVmYXVsdFZhbHVlLCBzZWVuVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGlmIChzZWVuVmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKG5ldyBFcnJvcignU2VxdWVuY2UgY29udGFpbnMgbW9yZSB0aGFuIG9uZSBlbGVtZW50JykpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICB2YWx1ZSA9IHg7XHJcbiAgICAgICAgICAgICAgICAgICAgc2VlblZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFzZWVuVmFsdWUgJiYgIWhhc0RlZmF1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKG5ldyBFcnJvcihzZXF1ZW5jZUNvbnRhaW5zTm9FbGVtZW50cykpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIC8qKlxyXG4g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Vycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChzaG91bGRSdW4pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeWllbGRJbmRleCA/IGkgOiB4KTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBpKys7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh5aWVsZEluZGV4ID8gLTEgOiB1bmRlZmluZWQpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7ICAgICAgICBcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIFNlYXJjaGVzIGZvciBhbiBlbGVtZW50IHRoYXQgbWF0Y2hlcyB0aGUgY29uZGl0aW9ucyBkZWZpbmVkIGJ5IHRoZSBzcGVjaWZpZWQgcHJlZGljYXRlLCBhbmQgcmV0dXJucyB0aGUgZmlyc3Qgb2NjdXJyZW5jZSB3aXRoaW4gdGhlIGVudGlyZSBPYnNlcnZhYmxlIHNlcXVlbmNlLlxyXG4gICAgICogQHBhcmFtIHtGdW5jdGlvbn0gcHJlZGljYXRlIFRoZSBwcmVkaWNhdGUgdGhhdCBkZWZpbmVzIHRoZSBjb25kaXRpb25zIG9mIHRoZSBlbGVtZW50IHRvIHNlYXJjaCBmb3IuXHJcbiAgICAgKiBAcGFyYW0ge0FueX0gW3RoaXNBcmddIE9iamVjdCB0byB1c2UgYXMgYHRoaXN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kfSBbY29udGV4dF0gVGhlIGNvbnRleHQgZm9yIHRoZSBmdW5jIHBhcmFtZXRlciB0byBiZSBleGVjdXRlZC4gIElmIG5vdCBzcGVjaWZpZWQsIGRlZmF1bHRzIHRvIHVuZGVmaW5lZC5cclxuICAgICAqIEByZXR1cm5zIHtGdW5jdGlvbn0gQXN5bmNocm9ub3VzIGZ1bmN0aW9uLlxyXG4gICAgICovXHJcbiAgICB2YXIgb2JzZXJ2YWJsZVRvQXN5bmMgPSBPYnNlcnZhYmxlLnRvQXN5bmMgPSBmdW5jdGlvbiAoZnVuYywgc2NoZWR1bGVyLCBjb250ZXh0KSB7XHJcbiAgICAgICAgc2NoZWR1bGVyIHx8IChzY2hlZHVsZXIgPSB0aW1lb3V0U2NoZWR1bGVyKTtcclxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgYXJncyA9IGFyZ3VtZW50cywgXHJcbiAgICAgICAgICAgICAgICBzdWJqZWN0ID0gbmV3IEFzeW5jU3ViamVjdCgpO1xyXG5cclxuICAgICAgICAgICAgc2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IGZ1bmMuYXBwbHkoY29udGV4dCwgYXJncyk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3ViamVjdC5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHN1YmplY3Qub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICBzdWJqZWN0Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICByZXR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mdsZSB2YWx1ZSBvZiB0aGUgYXJndW1lbnRzIHRvIHRoZSBjYWxsYmFjayBhcyBhbiBhcnJheS5cclxuICAgICAqL1xyXG4gICAgT2JzZXJ2YWJsZS5mcm9tQ2FsbGJhY2sgPSBmdW5jdGlvbiAoZnVuYywgc2NoZWR1bGVyLCBjb250ZXh0LCBzZWxlY3Rvcikge1xyXG4gICAgICAgIHNjaGVkdWxlciB8fCAoc2NoZWR1bGVyID0gaW1tZWRpYXRlU2NoZWR1bGVyKTtcclxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgYXJncyA9IHNsaWNlLmNhbGwoYXJndW1lbnRzLCAwKTtcclxuXHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBzY2hlZHVsZXIuc2NoZWR1bGUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uIGhhbmRsZXIoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgcmVzdWx0cyA9IGU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoc2VsZWN0b3IpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0cyA9IHNlbGVjdG9yKGFyZ3VtZW50cyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlcnIpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJlc3VsdHMubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0cyA9IHJlc3VsdHNbMF07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHRzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGFyZ3MucHVzaChoYW5kbGVyKTtcclxuICAgICAgICAgICAgICAgICAgICBmdW5jLmFwcGx5KGNvbnRleHQsIGFyZ3MpO1xyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH07XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogQ29udmVydHMgYSBOb2RlLmpzIGNhbGxiYWNrIHN0eWxlIGZ1bmN0aW9uIHRvIGFuIG9ic2VydmFibGUgc2VxdWVuY2UuICBUaGlzIG11c3QgYmUgaW4gZnVuY3Rpb24gKGVyciwgLi4uKSBmb3JtYXQuXHJcbiAgICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBmdW5jIFRoZSBmdW5jdGlvbiB0byBjYWxsXHJcbiAgICAgKiBAcGFyYW0ge1NjaGVkdWxlcn0gW3NjaGVkdWxlcl0gU2NoZWR1bGVyIHRvIHJ1biB0aGUgZnVuY3Rpb24gb24uIElmIG5vdCBzcGVjaWZpZWQsIGRlZmF1bHRzIHRvIFNjaGVkdWxlci50aW1lb3V0LlxyXG4gICAgICogQHBhcmFtIHtNaXhlZH0gW2NvbnRleHR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uIGhhbmRsZXIoZXJyKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlcnIpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHJlc3VsdHMgPSBzbGljZS5jYWxsKGFyZ3VtZW50cywgMSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoc2VsZWN0b3IpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0cyA9IHNlbGVjdG9yKHJlc3VsdHMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJlc3VsdHMubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0cyA9IHJlc3VsdHNbMF07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHRzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV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ge1xyXG4gICAgICAgIHZhbHVlc1tpXSA9IHhcclxuICAgICAgICB2YXIgcmVzO1xyXG4gICAgICAgIGhhc1ZhbHVlW2ldID0gdHJ1ZTtcclxuICAgICAgICBpZiAoaGFzVmFsdWVBbGwgfHwgKGhhc1ZhbHVlQWxsID0gaGFzVmFsdWUuZXZlcnkoaWRlbnRpdHkpKSkge1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmVzID0gcmVzdWx0U2VsZWN0b3IuYXBwbHkobnVsbCwgdmFsdWVzKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGV4KSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzKTtcclxuICAgICAgICB9IGVsc2UgaWYgKGlzRG9uZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShcclxuICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgbmV4dCh4LCAwKTtcclxuICAgICAgICAgIH0sXHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBpc0RvbmUgPSB0cnVlO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfSksXHJcbiAgICAgICAgc3ViamVjdC5zdWJzY3JpYmUoXHJcbiAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICBuZXh0KHgsIDEpO1xyXG4gICAgICAgICAgfSxcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlcikpXHJcbiAgICAgICAgKTtcclxuICAgIH0pO1xyXG4gIH1cclxuXHJcbiAgdmFyIFBhdXNhYmxlQnVmZmVyZWRPYnNlcnZhYmxlID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuXHJcbiAgICBpbmhlcml0cyhQYXVzYWJsZUJ1ZmZlcmVkT2JzZXJ2YWJsZSwgX3N1cGVyKTtcclxuXHJcbiAgICBmdW5jdGlvbiBzdWJzY3JpYmUob2JzZXJ2ZXIpIHtcclxuICAgICAgdmFyIHEgPSBbXSwgcHJldmlvdXMgPSB0cnVlO1xyXG4gICAgICBcclxuICAgICAgdmFyIHN1YnNjcmlwdGlvbiA9ICBcclxuICAgICAgICBjb21iaW5lTGF0ZXN0U291cmNlKFxyXG4gICAgICAgICAgdGhpcy5zb3VyY2UsXHJcbiAgICAgICAgICB0aGlzLnN1YmplY3QuZGlzdGluY3RVbnRpbENoYW5nZWQoKSwgXHJcbiAgICAgICAgICBmdW5jdGlvbiAoZGF0YSwgc2hvdWxkRmlyZSkge1xyXG4gICAgICAgICAgICByZXR1cm4geyBkYXRhOiBkYXRhLCBzaG91bGRGaXJlOiBzaG91bGRGaXJlIH07ICAgICAgXHJcbiAgICAgICAgICB9KVxyXG4gICAgICAgICAgLnN1YnNjcmliZShcclxuICAgICAgICAgICAgZnVuY3Rpb24gKHJlc3VsdHMpIHtcclxuICAgICAgICAgICAgICBpZiAocmVzdWx0cy5zaG91bGRGaXJlICYmIHByZXZpb3VzKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0cy5kYXRhKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgaWYgKHJlc3VsdHMuc2hvdWxkRmlyZSAmJiAhcHJldmlvdXMpIHtcclxuICAgICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBwcmV2aW91cyA9IHRydWU7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIGlmICghcmVzdWx0cy5zaG91bGRGaXJlICYmICFwcmV2aW91cykge1xyXG4gICAgICAgICAgICAgICAgcS5wdXNoKHJlc3VsdHMuZGF0YSk7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIGlmICghcmVzdWx0cy5zaG91bGRGaXJlICYmIHByZXZpb3VzKSB7XHJcbiAgICAgICAgICAgICAgICBwcmV2aW91cyA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIH0sIFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgLy8gRW1wdHkgYnVmZmVyIGJlZm9yZSBzZW5kaW5nIGVycm9yXHJcbiAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgIC8vIEVtcHR5IGJ1ZmZlciBiZWZvcmUgc2VuZGluZyBjb21wbGV0aW9uXHJcbiAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7ICAgICAgICAgICAgICBcclxuICAgICAgIC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QgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICB0aGlzLmVuYWJsZVF1ZXVlID0gZW5hYmxlUXVldWU7XHJcbiAgICAgICAgICAgIHRoaXMucXVldWUgPSBlbmFibGVRdWV1ZSA/IFtdIDogbnVsbDtcclxuICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWRDb3VudCA9IDA7XHJcbiAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgdGhpcy5lcnJvciA9IG51bGw7XHJcbiAgICAgICAgICAgIHRoaXMuaGFzRmFpbGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuaGFzQ29tcGxldGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKENvbnRyb2xsZWRTdWJqZWN0LnByb3RvdHlwZSwgT2JzZXJ2ZXIsIHtcclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHRoaXMuaGFzQ29tcGxldGVkID0gdHJ1ZTtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuZW5hYmxlUXVldWUgfHwgdGhpcy5xdWV1ZS5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmhhc0ZhaWxlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmVycm9yID0gZXJyb3I7XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmVuYWJsZVF1ZXVlIHx8IHRoaXMucXVldWUubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uRXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgfSAgIFxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdmFyIGhhc1JlcXVlc3RlZCA9IGZhbHNlO1xyXG5cclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuZW5hYmxlUXVldWUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5xdWV1ZS5wdXNoKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50ICE9PSAtMSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5yZXF1ZXN0ZWRDb3VudC0tID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2VDdXJyZW50UmVxdWVzdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1JlcXVlc3RlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1JlcXVlc3RlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBfcHJvY2Vzc1JlcXVlc3Q6IGZ1bmN0aW9uIChudW1iZXJPZkl0ZW1zKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5lbmFibGVRdWV1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2coJ3F1ZXVlIGxlbmd0aCcsIHRoaXMucXVldWUubGVuZ3RoKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKHRoaXMucXVldWUubGVuZ3RoID49IG51bWJlck9mSXRlbXMgJiYgbnVtYmVyT2ZJdGVtcyA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZygnbnVtYmVyIG9mIGl0ZW1zJywgbnVtYmVyT2ZJdGVtcyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbk5leHQodGhpcy5xdWV1ZS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbnVtYmVyT2ZJdGVtcy0tO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMucXVldWUubGVuZ3RoICE9PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB7IG51bWJlck9mSXRlbXM6IG51bWJlck9mSXRlbXMsIHJldHVyblZhbHVlOiB0cnVlIH07XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHsgbnVtYmVyT2ZJdGVtczogbnVtYmVyT2ZJdGVtcywgcmV0dXJuVmFsdWU6IGZhbHNlIH07XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmhhc0ZhaWxlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbkVycm9yKHRoaXMuZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuaGFzQ29tcGxldGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTsgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHsgbnVtYmVyT2ZJdGVtczogbnVtYmVyT2ZJdGVtcywgcmV0dXJuVmFsdWU6IGZhbHNlIH07XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIHJlcXVlc3Q6IGZ1bmN0aW9uIChudW1iZXIpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZUN1cnJlbnRSZXF1ZXN0KCk7XHJcbiAgICAgICAgICAgICAgICB2YXIgc2VsZiA9IHRoaXMsXHJcbiAgICAgICAgICAgICAgICAgICAgciA9IHRoaXMuX3Byb2Nlc3NSZXF1ZXN0KG51bWJlcik7XHJcblxyXG4gICAgICAgICAgICAgICAgbnVtYmVyID0gci5udW1iZXJPZkl0ZW1zO1xyXG4gICAgICAgICAgICAgICAgaWYgKCFyLnJldHVyblZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWRDb3VudCA9IG51bWJlcjtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5yZXF1ZXN0ZWRDb3VudCA9IDA7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGVcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZGlzcG9zZUN1cnJlbnRSZXF1ZXN0OiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICB9LFxyXG5cclxuICAgICAgICAgICAgZGlzcG9zZTogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IgPSBudWxsO1xyXG4gICA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ZW50IG5vdGlmaWNhdGlvbnMuXHJcbiAgICAgKi9cclxuICAgIHZhciBCZWhhdmlvclN1YmplY3QgPSBSeC5CZWhhdmlvclN1YmplY3QgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG4gICAgICAgIGZ1bmN0aW9uIHN1YnNjcmliZShvYnNlcnZlcikge1xyXG4gICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzLnB1c2gob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHRoaXMudmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG5ldyBJbm5lclN1YnNjcmlwdGlvbih0aGlzLCBvYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgdmFyIGV4ID0gdGhpcy5leGNlcHRpb247XHJcbiAgICAgICAgICAgIGlmIChleCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpbmhlcml0cyhCZWhhdmlvclN1YmplY3QsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqICBJbml0aWFsaXplcyBhIG5ldyBpbnN0YW5jZSBvZiB0aGUgQmVoYXZpb3JTdWJqZWN0IGNsYXNzIHdoaWNoIGNyZWF0ZXMgYSBzdWJqZWN0IHRoYXQgY2FjaGVzIG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gICAgICAgICAgcmV0dXJuIHRoaXMub2JzZXJ2ZXJzLmxlbmd0aCA+IDA7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGVuZCBvZiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqLyBcclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBleGNlcHRpb24uXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IGVycm9yIFRoZSBleGNlcHRpb24gdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChlcnJvcikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmV4Y2VwdGlvbiA9IGVycm9yO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25FcnJvcihlcnJvcik7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBhcnJpdmFsIG9mIHRoZSBzcGVjaWZpZWQgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IHZhbHVlIFRoZSB2YWx1ZSB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy52YWx1ZSA9IHZhbHVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIFVuc3Vic2NyaWJlIGFsbCBvYnNlcnZlcnMgYW5kIHJlbGVhc2UgcmVzb3VyY2VzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICBcclxuICAgICAgICAgICAgZGlzcG9zZTogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gbnVsbDtcclxuICAgICAgICAgICAgICAgIHRoaXMudmFsdWUgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBudWxsO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIHJldHVybiBCZWhhdmlvclN1YmplY3Q7XHJcbiAgICB9KE9ic2VydmFibGUpKTtcclxuXHJcbiAgICAvKipcclxuICAgICAqIFJlcHJlc2VudHMgYW4gb2JqZWN0IHRoYXQgaXMgYm90aCBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIGFzIHdlbGwgYXMgYW4gb2JzZXJ2ZXIuXHJcbiAgICAgKiBFYWNoIG5vdGlmaWNhdGlvbiBpcyBicm9hZGNhc3RlZ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cclxuICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICB0aGlzLl90cmltKHRoaXMuc2NoZWR1bGVyLm5vdygpKTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMucHVzaChzbyk7XHJcblxyXG4gICAgICAgICAgICB2YXIgbiA9IHRoaXMucS5sZW5ndGg7XHJcblxyXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gdGhpcy5xLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBzby5vbk5leHQodGhpcy5xW2ldLnZhbHVlKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgaWYgKHRoaXMuaGFzRXJyb3IpIHtcclxuICAgICAgICAgICAgICAgIG4rKztcclxuICAgICAgICAgICAgICAgIHNvLm9uRXJyb3IodGhpcy5lcnJvcik7XHJcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIG4rKztcclxuICAgICAgICAgICAgICAgIHNvLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHNvLmVuc3VyZUFjdGl2ZShuKTtcclxuICAgICAgICAgICAgcmV0dXJuIHN1YnNjcmlwdGlvbjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGluaGVyaXRzKFJlcGxheVN1YmplY3QsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqICBJbml0aWFsaXplcyBhIG5ldyBpbnN0YW5jZSBvZiB0aGUgUmVwbGF5U3ViamVjdCBjbGFzcyB3aXRoIHRoZSBzcGVjaWZpZWQgYnVmZmVyIHNpemUsIHdpbmRvdyBzaXplIGFuZCBzY2hlZHVsZXIuXHJcbiAgICAgICAgICogIEBwYXJhbSB7TnVtYmVyfSBbYnVmZmVyU2l6ZV0gTWF4aW11bSBlbGVtZW50IGNvdW50IG9mIHRoZSByZXBsYXkgYnVmZmVyLlxyXG4gICAgICAgICAqICBAcGFyYW0ge051bWJlcn0gW3dpbmRvd1NpemVdIE1heGltdW0gdGltZSBsZW5ndGggb2YgdGhlIHJlcGxheSBidWZmZXIuXHJcbiAgICAgICAgICogIEBwYXJhbSB7U2NoZWR1bGVyfSBbc2NoZWR1bGVyXSBTY2hlZHVsZXIgdGhlIG9ic2VydmVycyBhcmUgaW52b2tlZCBvbi5cclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBSZXBsYXlTdWJqZWN0KGJ1ZmZlclNpemUsIHdpbmRvd1NpemUsIHNjaGVkdWxlcikge1xyXG4gICAgICAgICAgICB0aGlzLmJ1ZmZlclNpemUgPSBidWZmZXJTaXplID09IG51bGwgPyBOdW1iZXIuTUFYX1ZBTFVFIDogYnVmZmVyU2l6ZTtcclxuICAgICAgICAgICAgdGhpcy53aW5kb3dTaXplID0gd2luZG93U2l6ZSA9PSBudWxsID8gTnVtYmVyLk1BWF9WQUxVRSA6IHdpbmRvd1NpemU7XHJcbiAgICAgICAgICAgIHRoaXMuc2NoZWR1bGVyID0gc2NoZWR1bGVyIHx8IGN1cnJlbnRUaHJlYWRTY2hlZHVsZXI7XHJcbiAgICAgICAgICAgIHRoaXMucSA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5oYXNFcnJvciA9IGZhbHNlO1xyXG4gICAgICAgICAgICB0aGlzLmVycm9yID0gbnVsbDtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFkZFByb3BlcnRpZXMoUmVwbGF5U3ViamVjdC5wcm90b3R5cGUsIE9ic2VydmVyLCB7XHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqIEByZXR1cm5zIHtCb29sZWFufSBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgIFxyXG4gICAgICAgICAgICBoYXNPYnNlcnZlcnM6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLm9ic2VydmVycy5sZW5ndGggPiAwO1xyXG4gICAgICAgICAgICB9LCAgICAgICAgICAgIFxyXG4gICAgICAgICAgICAvKiBAcHJpdmF0ZSAgKi9cclxuICAgICAgICAgICAgX3RyaW06IGZ1bmN0aW9uIChub3cpIHtcclxuICAgICAgICAgICAgICAgIHdoaWxlICh0aGlzLnEubGVuZ3RoID4gdGhpcy5idWZmZXJTaXplKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5xLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB3aGlsZSAodGhpcy5xLmxlbmd0aCA+IDAgJiYgKG5vdyAtIHRoaXMucVswXS5pbnRlcnZhbCkgPiB0aGlzLndpbmRvd1NpemUpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgYXJyaXZhbCBvZiB0aGUgc3BlY2lmaWVkIGVsZW1lbnQgaW4gdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSB2YWx1ZSBUaGUgdmFsdWUgdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG9ic2VydmVyO1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBub3cgPSB0aGlzLnNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnEucHVzaCh7IGludGVydmFsOiBub3csIHZhbHVlOiB2YWx1ZSB9KTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLl90cmltKG5vdyk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG8ubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIgPSBvW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5lbnN1cmVBY3RpdmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGV4Y2VwdGlvbi5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gZXJyb3IgVGhlIGV4Y2VwdGlvbiB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChlcnJvcikge1xyXG4gICAgICAgICAgICAgICAgdmFyIG9ic2VydmVyO1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVycm9yID0gZXJyb3I7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5oYXNFcnJvciA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG5vdyA9IHRoaXMuc2NoZWR1bGVyLm5vdygpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3RyaW0obm93KTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyID0gb1tpXTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnJvcik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLmVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBlbmQgb2YgdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgb2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBub3cgPSB0aGlzLnNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLl90cmltKG5vdyk7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG8gPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gby5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlciA9IG9baV07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLmVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogVW5zdWJzY3JpYmUgYWxsIG9ic2VydmVycyBhbmQgcmVsZWFzZSByZXNvdXJjZXMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBkaXNwb3NlOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBudWxsO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIHJldHVybiBSZXBsYXlTdWJqZWN0O1xyXG4gICAgfShPYnNlcnZhYmxlKSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgQ29ubmVjdGFibGVPYnNlcnZhYmxlID0gUnguQ29ubmVjdGFibGVPYnNlcnZhYmxlID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuICAgICAgICBpbmhlcml0cyhDb25uZWN0YWJsZU9ic2VydmFibGUsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gQ29ubmVjdGFibGVPYnNlcnZhYmxlKHNvdXJjZSwgc3ViamVjdCkge1xyXG4gICAgICAgICAgICB2YXIgc3RhdGUgPSB7XHJcbiAgICAgICAgICAgICAgICBzdWJqZWN0OiBzdWJqZWN0LFxyXG4gICAgICAgICAgICAgICAgc291cmNlOiBzb3VyY2UuYXNPYnNlcnZhYmxlKCksXHJcbiAgICAgICAgICAgICAgICBoYXNTdWJzY3JpcHRpb246IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uOiBudWxsXHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICB0aGlzLmNvbm5lY3QgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXN0YXRlLmhhc1N1YnNjcmlwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIHN0YXRlLmhhc1N1YnNjcmlwdGlvbiA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgc3RhdGUuc3Vic2NyaXB0aW9uID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3RhdGUuc291cmNlLnN1YnNjcmliZShzdGF0ZS5zdWJqZWN0KSwgZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhhc1N1YnNjcmlwdGlvbiA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHJldHVybiBzdGF0ZS5zdWJzY3JpcHRpb247XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBmdW5jdGlvbiBzdWJzY3JpYmUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBzdGF0ZS5zdWJqZWN0LnN1YnNjcmliZShvYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBDb25uZWN0YWJsZU9ic2VydmFibGVcclxuICAgICAgICAgKi9cclxuICAgICAgICBDb25uZWN0YWJsZU9ic2VydmFibGUucHJvdG90eXBlLmNvbm5lY3QgPSBmdW5jdGlvbiAoKSB7IHJldHVybiB0aGlzLmNvbm5lY3QoKTsgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgQ29ubmVjdGFibGVPYnNlcnZhYmxlXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBDb25uZWN0YWJsZU9ic2VydmFibGUucHJvdG90eXBlLnJlZkNvdW50ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgY29ubmVjdGFibGVTdWJzY3JpcHRpb24gPSBudWxsLCBjb3VudCA9IDAsIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgICAgIHZhciBzaG91bGRDb25uZWN0LCBzdWJzY3JpcHRpb247XHJcbiAgICAgICAgICAgICAgICBjb3VudCsrO1xyXG4gICAgICAgICAgICAgICAgc2hvdWxkQ29ubmVjdCA9IGNvdW50ID09PSAxO1xyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uID0gc291cmNlLnN1YnNjcmliZShvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICBpZiAoc2hvdWxkQ29ubmVjdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGNvbm5lY3RhYmxlU3Vic2NyaXB0aW9uID0gc291cmNlLmNvbm5lY3QoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGNvdW50LS07XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbm5lY3RhYmxlU3Vic2NyaXB0aW9uLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAg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AgICAgbnVtMiArPSAyO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gdHJ1ZTtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBnZXRQcmltZShtaW4pIHtcclxuICAgICAgICB2YXIgaW5kZXgsIG51bSwgY2FuZGlkYXRlO1xyXG4gICAgICAgIGZvciAoaW5kZXggPSAwOyBpbmRleCA8IHByaW1lcy5sZW5ndGg7ICsraW5kZXgpIHtcclxuICAgICAgICAgICAgbnVtID0gcHJpbWVzW2luZGV4XTtcclxuICAgICAgICAgICAgaWYgKG51bSA+PSBtaW4pIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBudW07XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgY2FuZGlkYXRlID0gbWluIHwgMTtcclxuICAgICAgICB3aGlsZSAoY2FuZGlkYXRlIDwgcHJpbWVzW3ByaW1lcy5sZW5ndGggLSAxXSkge1xyXG4gICAgICAgICAgICBpZiAoaXNQcmltZShjYW5kaWRhdGUpKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gY2FuZGlkYXRlO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGNhbmRpZGF0ZSArPSAyO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbWluO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIHN0cmluZ0hhc2hGbihzdHIpIHtcclxuICAgICAgICB2YXIgaGFzaCA9IDc1NzYwMjA0NjtcclxuICAgICAgICBpZiAoIXN0ci5sZW5ndGgpIHtcclxuICAgICAgICAgICAgcmV0dXJuIGhhc2g7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBzdHIubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgdmFyIGNoYXJhY3RlciA9IHN0ci5jaGFyQ29kZUF0KGkpO1xyXG4gICAgICAgICAgICBoYXNoID0gKChoYXNoPDw1KS1oYXNoKStjaGFyYWN0ZXI7XHJcbiAgICAgICAgICAgIGhhc2ggPSBoYXNoICYgaGFzaDtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIGhhc2g7XHJcbiAgICB9XHJcblxyXG4gICAgZnVuY3Rpb24gbnVtYmVySGFzaEZuKGtleSkge1xyXG4gICAgICAgIHZhciBjMiA9IDB4MjdkNGViMmQ7IFxyXG4gICAgICAgIGtleSA9IChrZXkgXiA2MSkgXiAoa2V5ID4+PiAxNik7XHJcbiAgICAgICAga2V5ID0ga2V5ICsgKGtleSA8PCAzKTtcclxuICAgICAgICBrZXkgPSBrZXkgXiAoa2V5ID4+PiA0KTtcclxuICAgICAgICBrZXkgPSBrZXkgKiBjMjtcclxuICAgICAgICBrZXkgPSBrZXkgXiAoa2V5ID4+PiAxNSk7XHJcbiAgICAgICAgcmV0dXJuIGtleTtcclxuICAgIH1cclxuXHJcbiAgICB2YXIgZ2V0SGFzaENvZGUgPSAoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciB1bmlxdWVJZENvdW50ZXIgPSAwO1xyXG5cclxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKG9iaikge1xyXG4gICAgICAgICAgICBpZiAob2JqID09IG51bGwpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3Iobm9TdWNoa2V5KTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgLy8gQ2hlY2sgZm9yIGJ1aWx0LWlucyBiZWZvcmUgdGFja2luZyBvbiBvdXIgb3duIGZvciBhbnkgb2JqZWN0XHJcbiAgICAgICAgICAgIGlmICh0eXBlb2Ygb2JqID09PSAnc3RyaW5nJykge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHN0cmluZ0hhc2hGbihvYmopO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBpZiAodHlwZW9mIG9iaiA9PT0gJ251bWJlcicpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBudW1iZXJIYXNoRm4ob2JqKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgaWYgKHR5cGVvZiBvYmogPT09ICdib29sZWFuJykge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG9iaiA9PT0gdHJ1ZSA/IDEgOiAwO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBpZiAob2JqIGluc3RhbmNlb2YgRGF0ZSkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG9iai5nZXRUaW1lKCk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIGlmIChvYmouZ2V0SGFzaENvZGUpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBvYmouZ2V0SGFzaENvZGUoKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdmFyIGlkID0gMTcgKiB1bmlxdWVJZENvdW50ZXIrKztcclxuICAgICAgICAgICAgb2JqLmdldEhhc2hDb2RlID0gZnVuY3Rpb24gKCkgeyByZXR1cm4gaWQ7IH07XHJcbiAgICAgICAgICAgIHJldHVybiBpZDtcclxuICAgICAgICB9O1xyXG4gICAgfSAoKSk7XHJcblxyXG4gICAgZnVuY3Rpb24gbmV3RW50cnkoKSB7XHJcbiAgICAgICAgcmV0dXJuIHsga2V5OiBudWxsLCB2YWx1ZTogbnVsbCwgbmV4dDogMCwgaGFzaENvZGU6IDAgfTtcclxuICAgIH1cclxuXHJcbiAgICAvLyBEaWN0aW9uYXJ5IGltcGxlbWVudGF0aW9uXHJcblxyXG4gICAgdmFyIERpY3Rpb25hcnkgPSBmdW5jdGlvbiAoY2FwYWNpdHksIGNvbXBhcmVyKSB7XHJcbiAgICAgICAgaWYgKGNhcGFjaXR5IDwgMCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ291dCBvZiByYW5nZScpXHJcbiAgICAgICAgfVxyXG4g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gICBEaWN0aW9uYXJ5LnByb3RvdHlwZS5faW5zZXJ0ID0gZnVuY3Rpb24gKGtleSwgdmFsdWUsIGFkZCkge1xyXG4gICAgICAgIGlmICghdGhpcy5idWNrZXRzKSB7XHJcbiAgICAgICAgICAgIHRoaXMuX2luaXRpYWxpemUoMCk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBpbmRleDM7XHJcbiAgICAgICAgdmFyIG51bSA9IGdldEhhc2hDb2RlKGtleSkgJiAyMTQ3NDgzNjQ3O1xyXG4gICAgICAgIHZhciBpbmRleDEgPSBudW0gJSB0aGlzLmJ1Y2tldHMubGVuZ3RoO1xyXG4gICAgICAgIGZvciAodmFyIGluZGV4MiA9IHRoaXMuYnVja2V0c1tpbmRleDFdOyBpbmRleDIgPj0gMDsgaW5kZXgyID0gdGhpcy5lbnRyaWVzW2luZGV4Ml0ubmV4dCkge1xyXG4gICAgICAgICAgICBpZiAodGhpcy5lbnRyaWVzW2luZGV4Ml0uaGFzaENvZGUgPT09IG51bSAmJiB0aGlzLmNvbXBhcmVyKHRoaXMuZW50cmllc1tpbmRleDJdLmtleSwga2V5KSkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGFkZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihkdXBsaWNhdGVrZXkpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4Ml0udmFsdWUgPSB2YWx1ZTtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAodGhpcy5mcmVlQ291bnQgPiAwKSB7XHJcbiAgICAgICAgICAgIGluZGV4MyA9IHRoaXMuZnJlZUxpc3Q7XHJcbiAgICAgICAgICAgIHRoaXMuZnJlZUxpc3QgPSB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0O1xyXG4gICAgICAgICAgICAtLXRoaXMuZnJlZUNvdW50O1xyXG4gICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIGlmICh0aGlzLnNpemUgPT09IHRoaXMuZW50cmllcy5sZW5ndGgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3Jlc2l6ZSgpO1xyXG4gICAgICAgICAgICAgICAgaW5kZXgxID0gbnVtICUgdGhpcy5idWNrZXRzLmxlbmd0aDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpbmRleDMgPSB0aGlzLnNpemU7XHJcbiAgICAgICAgICAgICsrdGhpcy5zaXplO1xyXG4gICAgICAgIH1cclxuICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5oYXNoQ29kZSA9IG51bTtcclxuICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0ID0gdGhpcy5idWNrZXRzW2luZGV4MV07XHJcbiAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10ua2V5ID0ga2V5O1xyXG4gICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLnZhbHVlID0gdmFsdWU7XHJcbiAgICAgICAgdGhpcy5idWNrZXRzW2luZGV4MV0gPSBpbmRleDM7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLl9yZXNpemUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgdmFyIHByaW1lID0gZ2V0UHJpbWUodGhpcy5zaXplICogMiksXHJcbiAgICAgICAgICAgIG51bUFycmF5ID0gbmV3IEFycmF5KHByaW1lKTtcclxuICAgICAgICBmb3IgKGluZGV4ID0gMDsgaW5kZXggPCBudW1BcnJheS5sZW5ndGg7ICsraW5kZXgpIHtcclxuICAgICAgICAgICAgbnVtQXJyYXlbaW5kZXhdID0gLTE7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBlbnRyeUFycmF5ID0gbmV3IEFycmF5KHByaW1lKTtcclxuICAgICAgICBmb3IgKGluZGV4ID0gMDsgaW5kZXggPCB0aGlzLnNpemU7ICsraW5kZXgpIHtcclxuICAgICAgICAgICAgZW50cnlBcnJheVtpbmRleF0gPSB0aGlzLmVudHJpZXNbaW5kZXhdO1xyXG4gICAgICAgIH1cclxuICAgICAgICBmb3IgKHZhciBpbmRleCA9IHRoaXMuc2l6ZTsgaW5kZXggPCBwcmltZTsgKytpbmRleCkge1xyXG4gICAgICAgICAgICBlbnRyeUFycmF5W2luZGV4XSA9IG5ld0VudHJ5KCk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGZvciAodmFyIGluZGV4MSA9IDA7IGluZGV4MSA8IHRoaXMuc2l6ZTsgKytpbmRleDEpIHtcclxuICAgICAgICAgICAgdmFyIGluZGV4MiA9IGVudHJ5QXJyYXlbaW5kZXgxXS5oYXNoQ29kZSAlIHByaW1lO1xyXG4gICAgICAgICAgICBlbnRyeUFycmF5W2luZGV4MV0ubmV4dCA9IG51bUFycmF5W2luZGV4Ml07XHJcbiAgICAgICAgICAgIG51bUFycmF5W2luZGV4Ml0gPSBpbmRleDE7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHRoaXMuYnVja2V0cyA9IG51bUFycmF5O1xyXG4gICAgICAgIHRoaXMuZW50cmllcyA9IGVudHJ5QXJyYXk7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLnJlbW92ZSA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgICBpZiAodGhpcy5idWNrZXRzKSB7XHJcbiAgICAgICAgICAgIHZhciBudW0gPSBnZXRIYXNoQ29kZShrZXkpICYgMjE0NzQ4MzY0NztcclxuICAgICAgICAgICAgdmFyIGluZGV4MSA9IG51bSAlIHRoaXMuYnVja2V0cy5sZW5ndGg7XHJcbiAgICAgICAgICAgIHZhciBpbmRleDIgPSAtMTtcclxuICAgICAgICAgICAgZm9yICh2YXIgaW5kZXgzID0gdGhpcy5idWNrZXRzW2luZGV4MV07IGluZGV4MyA+PSAwOyBpbmRleDMgPSB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5lbnRyaWVzW2luZGV4M10uaGFzaENvZGUgPT09IG51bSAmJiB0aGlzLmNvbXBhcmVyKHRoaXMuZW50cmllc1tpbmRleDNdLmtleSwga2V5KSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpbmRleDIgPCAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuYnVja2V0c1tpbmRleDFdID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgyXS5uZXh0ID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10uaGFzaENvZGUgPSAtMTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0ID0gdGhpcy5mcmVlTGlzdDtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5rZXkgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLnZhbHVlID0gbnVsbDtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmZyZWVMaXN0ID0gaW5kZXgzO1xyXG4gICAgICAgICAgICAgICAgICAgICsrdGhpcy5mcmVlQ291bnQ7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGluZGV4MiA9IGluZGV4MztcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gZmFsc2U7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLmNsZWFyID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBpbmRleCwgbGVuO1xyXG4gICAgICAgIGlmICh0aGlzLnNpemUgPD0gMCkge1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGZvciAoaW5kZXggPSAwLCBsZW4gPSB0aGlzLmJ1Y2tldHMubGVuZ3RoOyBpbmRleCA8IGxlbjsgKytpbmRleCkge1xyXG4gICAgICAgICAgICB0aGlzLmJ1Y2tldHNbaW5kZXhdID0gLTE7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGZvciAoaW5kZXggPSAwOyBpbmRleCA8IHRoaXMuc2l6ZTsgKytpbmRleCkge1xyXG4gICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXhdID0gbmV3RW50cnkoKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgdGhpcy5mcmVlTGlzdCA9IC0xO1xyXG4gICAgICAgIHRoaXMuc2l6ZSA9IDA7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLl9maW5kRW50cnkgPSBmdW5jdGlvbiAoa2V5KSB7XHJcbiAgICAgICAgaWYgKHRoaXMuYnVja2V0cykge1xyXG4gICAgICAgICAgICB2YXIgbnVtID0gZ2V0SGFzaENvZGUoa2V5KSAmIDIxNDc0ODM2NDc7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGluZGV4ID0gdGhpcy5idWNrZXRzW251bSAlIHRoaXMuYnVja2V0cy5sZW5ndGhdOyBpbmRleCA+PSAwOyBpbmRleCA9IHRoaXMuZW50cmllc1tpbmRleF0ubmV4dCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuZW50cmllc1tpbmRleF0uaGFzaENvZGUgPT09IG51bSAmJiB0aGlzLmNvbXBhcmVyKHRoaXMuZW50cmllc1tpbmRleF0ua2V5LCBrZXkpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGluZGV4O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiAtMTtcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUuY291bnQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgcmV0dXJuIHRoaXMuc2l6ZSAtIHRoaXMuZnJlZUNvdW50O1xyXG4gICAgfTtcclxuXHJcbiAgICBEaWN0aW9uYXJ5LnByb3RvdHlwZS50cnlHZXRWYWx1ZSA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgICB2YXIgZW50cnkgPSB0aGlzLl9maW5kRW50cnkoa2V5KTtcclxuICAgICAgICBpZiAoZW50cnkgPj0gMCkge1xyXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5lbnRyaWVzW2VudHJ5XS52YWx1ZTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIHVuZGVmaW5lZDtcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUuZ2V0VmFsdWVzID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBpbmRleCA9IDAsIHJlc3VsdHMgPSBbXTtcclxuICAgICAgICBpZiAodGhpcy5lbnRyaWVzKSB7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGluZGV4MSA9IDA7IGluZGV4MSA8IHRoaXMuc2l6ZTsgaW5kZXgxKyspIHtcclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmVudHJpZXNbaW5kZXgxXS5oYXNoQ29kZSA+PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0c1tpbmRleCsrXSA9IHRoaXMuZW50cmllc1tpbmRleDFdLnZhbHVlO1xyXG4gICAgICAgICAgICAg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lUHJvdG8uam9pbiA9IGZ1bmN0aW9uIChyaWdodCwgbGVmdER1cmF0aW9uU2VsZWN0b3IsIHJpZ2h0RHVyYXRpb25TZWxlY3RvciwgcmVzdWx0U2VsZWN0b3IpIHtcclxuICAgICAgICB2YXIgbGVmdCA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgZ3JvdXAgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICBsZWZ0RG9uZSA9IGZhbHNlLFxyXG4gICAgICAgICAgICBsZWZ0SWQgPSAwLFxyXG4gICAgICAgICAgICBsZWZ0TWFwID0gbmV3IERpY3Rpb25hcnkoKSxcclxuICAgICAgICAgICAgcmlnaHREb25lID0gZmFsc2UsXHJcbiAgICAgICAgICAgIHJpZ2h0SWQgPSAwLFxyXG4gICAgICAgICAgICByaWdodE1hcCA9IG5ldyBEaWN0aW9uYXJ5KCk7XHJcbiAgICAgICAgICAgIGdyb3VwLmFkZChsZWZ0LnN1YnNjcmliZShmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHZhciBkdXJhdGlvbixcclxuICAgICAgICAgICAgICAgIGV4cGlyZSxcclxuICAgICAgICAgICAgICAgIGlkID0gbGVmdElkKyssXHJcbiAgICAgICAgICAgICAgICBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgcmVzdWx0LFxyXG4gICAgICAgICAgICAgICAgdmFsdWVzO1xyXG4gICAgICAgICAgICAgICAgbGVmdE1hcC5hZGQoaWQsIHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcbiAgICAgICAgICAgICAgICBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGxlZnRNYXAucmVtb3ZlKGlkKSAmJiBsZWZ0TWFwLmNvdW50KCkgPT09IDAgJiYgbGVmdERvbmUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbiA9IGxlZnREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkgeyBleHBpcmUoKTsgfSkpO1xyXG4gICAgICAgICAgICAgICAgdmFsdWVzID0gcmlnaHRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHZhbHVlcy5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHZhbHVlLCB2YWx1ZXNbaV0pO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGxlZnREb25lID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIGlmIChyaWdodERvbmUgfHwgbGVmdE1hcC5jb3VudCgpID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICBncm91cC5hZGQocmlnaHQuc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uLFxyXG4gICAgICAgICAgICAgICAgZXhwaXJlLFxyXG4gICAgICAgICAgICAgICAgaWQgPSByaWdodElkKyssXHJcbiAgICAgICAgICAgICAgICBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgcmVzdWx0LFxyXG4gICAgICAgICAgICAgICAgdmFsdWVzO1xyXG4gICAgICAgICAgICAgICAgcmlnaHRNYXAuYWRkKGlkLCB2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICBncm91cC5hZGQobWQpO1xyXG4gICAgICAgICAgICAgICAgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChyaWdodE1hcC5yZW1vdmUoaWQpICYmIHJpZ2h0TWFwLmNvdW50KCkgPT09IDAgJiYgcmlnaHREb25lKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZHVyYXRpb24gPSByaWdodER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkgeyBleHBpcmUoKTsgfSkpO1xyXG4gICAgICAgICAgICAgICAgdmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgdmFsdWVzLmxlbmd0aDsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3IodmFsdWVzW2ldLCB2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICA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gbGVmdER1cmF0aW9uU2VsZWN0b3IsIHJpZ2h0RHVyYXRpb25TZWxlY3RvciwgcmVzdWx0U2VsZWN0b3IpIHtcclxuICAgICAgICB2YXIgbGVmdCA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgbm90aGluZyA9IGZ1bmN0aW9uICgpIHt9O1xyXG4gICAgICAgICAgICB2YXIgZ3JvdXAgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICB2YXIgciA9IG5ldyBSZWZDb3VudERpc3Bvc2FibGUoZ3JvdXApO1xyXG4gICAgICAgICAgICB2YXIgbGVmdE1hcCA9IG5ldyBEaWN0aW9uYXJ5KCk7XHJcbiAgICAgICAgICAgIHZhciByaWdodE1hcCA9IG5ldyBEaWN0aW9uYXJ5KCk7XHJcbiAgICAgICAgICAgIHZhciBsZWZ0SUQgPSAwO1xyXG4gICAgICAgICAgICB2YXIgcmlnaHRJRCA9IDA7XHJcblxyXG4gICAgICAgICAgICBncm91cC5hZGQobGVmdC5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGlkID0gbGVmdElEKys7XHJcbiAgICAgICAgICAgICAgICAgICAgbGVmdE1hcC5hZGQoaWQsIHMpO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBpLCBsZW4sIGxlZnRWYWx1ZXMsIHJpZ2h0VmFsdWVzO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHZhbHVlLCBhZGRSZWYocywgcikpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGxlZnRWYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXNbaV0ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICByaWdodFZhbHVlcyA9IHJpZ2h0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IHJpZ2h0VmFsdWVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHMub25OZXh0KHJpZ2h0VmFsdWVzW2ldKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZWZ0TWFwLnJlbW92ZShpZCkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uID0gbGVmdER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGxlZnRNYXAubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXNbaV0ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBub3RoaW5nLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBsZWZ0VmFsdWVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgICAgICAgICAgZXhwaXJlKVxyXG4gICAgICAgICAgICAgICAgICAgICk7XHJcbiAgICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGxlZnRWYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKSk7XHJcblxyXG4gICAgICAgICAgICBncm91cC5hZGQocmlnaHQuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGxlZnRWYWx1ZXMsIGksIGxlbjtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgaWQgPSByaWdodElEKys7XHJcbiAgICAgICAgICAgICAgICAgICAgcmlnaHRNYXAuYWRkKGlkLCB2YWx1ZSk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJpZ2h0TWFwLnJlbW92ZShpZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uID0gcmlnaHREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBsZWZ0TWFwLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzW2ldLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBub3RoaW5nLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBsZWZ0TWFwLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgICAgICAgICAgZXhwaXJlKVxyXG4gICAgICAgICAgICAgICAgICAgICk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGxlZnRWYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBsZWZ0VmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZ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gICB3aW5kb3cub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pKTtcclxuXHJcbiAgICAgICAgICAgIGQuYWRkKHdpbmRvd0JvdW5kYXJpZXMuc3Vic2NyaWJlKGZ1bmN0aW9uICh3KSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIHdpbmRvdyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHdpbmRvdywgcikpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pKTtcclxuXHJcbiAgICAgICAgICAgIHJldHVybiByO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIG9ic2VydmFibGVXaW5kb3dXaXRoQ2xvc2luZ1NlbGVjdG9yKHdpbmRvd0Nsb3NpbmdTZWxlY3Rvcikge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGNyZWF0ZVdpbmRvd0Nsb3NlLFxyXG4gICAgICAgICAgICAgICAgbSA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICBkID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUobSksXHJcbiAgICAgICAgICAgICAgICByID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShkKSxcclxuICAgICAgICAgICAgICAgIHdpbmRvdyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYod2luZG93LCByKSk7XHJcbiAgICAgICAgICAgIGQuYWRkKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChleCkge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICBjcmVhdGVXaW5kb3dDbG9zZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBtMSwgd2luZG93Q2xvc2U7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHdpbmRvd0Nsb3NlID0gd2luZG93Q2xvc2luZ1NlbGVjdG9yKCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgbTEgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgIG0uc2V0RGlzcG9zYWJsZShtMSk7XHJcbiAgICAgICAgICAgICAgICBtMS5zZXREaXNwb3NhYmxlKHdpbmRvd0Nsb3NlLnRha2UoMSkuc3Vic2NyaWJlKG5vb3AsIGZ1bmN0aW9uIChleCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHdpbmRvdy5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICB3aW5kb3cub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB3aW5kb3cgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYod2luZG93LCByKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgY3JlYXRlV2luZG93Q2xvc2UoKTtcclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgY3JlYXRlV2luZG93Q2xvc2UoKTtcclxuICAgICAgICAgICAgcmV0dXJuIHI7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9XHJcblxyXG4gIC8qKlxyXG4gICAqIFJldHVybnMgYSBuZXcgb2JzZXJ2YWJsZSB0aGF0IHRyaWdnZXJzIG9uIHRoZSBzZWNvbmQgYW5kIHN1YnNlcXVlbnQgdHJpZ2dlcmluZ3Mgb2YgdGhlIGlucHV0IG9ic2VydmF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gICAgICAgc2NoZWR1bGVyIHx8IChzY2hlZHVsZXIgPSBpbW1lZGlhdGVTY2hlZHVsZXIpO1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHEgPSBbXSxcclxuICAgICAgICAgICAgICAgIG0gPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgZCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKG0pLFxyXG4gICAgICAgICAgICAgICAgYWN0aXZlQ291bnQgPSAwLFxyXG4gICAgICAgICAgICAgICAgaXNBY3F1aXJlZCA9IGZhbHNlO1xyXG5cclxuICAgICAgICAgICAgdmFyIGVuc3VyZUFjdGl2ZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBpc093bmVyID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNPd25lciA9ICFpc0FjcXVpcmVkO1xyXG4gICAgICAgICAgICAgICAgICAgIGlzQWNxdWlyZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGlzT3duZXIpIHtcclxuICAgICAgICAgICAgICAgICAgICBtLnNldERpc3Bvc2FibGUoc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlKGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciB3b3JrO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB3b3JrID0gcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaXNBY3F1aXJlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBtMSA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkLmFkZChtMSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG0xLnNldERpc3Bvc2FibGUod29yay5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhciByZXN1bHQgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSBzZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY3RpdmVDb3VudCsrO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZW5zdXJlQWN0aXZlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGQucmVtb3ZlKG0xKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFjdGl2ZUNvdW50LS07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYWN0aXZlQ291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBxLnB1c2goc291cmNlKTtcclxuICAgICAgICAgICAgYWN0aXZlQ291bnQrKztcclxuICAgICAgICAgICAgZW5zdXJlQWN0aXZlKCk7XHJcbiAgICAgICAgICAgIHJldHVybiBkO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgIC8qKlxyXG4gICAqICBSdW5zIGFsbCBvYnNlcnZhYmxlIHNlcXVlbmNlcyBpbiBwYXJhbGxlbCBhbmQgY29sbGVjdCB0aGVpciBsYXN0IGVsZW1lbnRzLlxyXG4gICAqICBcclxuICAgKiBAZXhhbXBsZVxyXG4gICAqICAxIC0gcmVzID0gUnguT2JzZXJ2YWJsZS5mb3JrSm9pbihbb2JzMSwgb2JzMl0pO1xyXG4gICAqICAxIC0gcmVzID0gUnguT2JzZXJ2YWJsZS5mb3JrSm9pbihvYnMxLCBvYnMyLCAuLi4pOyAgXHJcbiAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2Ugd2l0aCBhbiBhcnJheSBjb2xsZWN0aW5nIHRoZSBsYXN0IGVsZW1lbnRzIG9mIGFsbCB0aGUgaW5wdXQgc2VxdWVuY2VzLlxyXG4gICAqL1xyXG4gIE9ic2VydmFibGUuZm9ya0pvaW4gPSBmdW5jdGlvbiAoKSB7XHJcbiAgICB2YXIgYWxsU291cmNlcyA9IGFyZ3NPckFycmF5KGFyZ3VtZW50cywgMCk7XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcclxuICAgICAgdmFyIGNvdW50ID0gYWxsU291cmNlcy5sZW5ndGg7XHJcbiAgICAgIGlmIChjb3VudCA9PT0gMCkge1xyXG4gICAgICAgIHN1YnNjcmliZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICB9XHJcbiAgICAgIHZhciBncm91cCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgZmluaXNoZWQgPSBmYWxzZSxcclxuICAgICAgICBoYXNSZXN1bHRzID0gbmV3IEFycmF5KGNvdW50KSxcclxuICAgICAgICBoYXNDb21wbGV0ZWQgPSBuZXcgQXJyYXkoY291bnQpLFxyXG4gICAgICAgIHJlc3VsdHMgPSBuZXcgQXJyYXkoY291bnQpO1xyXG5cclxuICAgICAgZm9yICh2YXIgaWR4ID0gMDsgaWR4IDwgY291bnQ7IGlkeCsrKSB7XHJcbiAgICAgICAgKGZ1bmN0aW9uIChpKSB7XHJcbiAgICAgICAgICB2YXIgc291cmNlID0gYWxsU291cmNlc1tpXTtcclxuICAgICAgICAgIGlzUHJvbWlzZShzb3VyY2UpICYmIChzb3VyY2UgPSBvYnNlcnZhYmxlRnJvbVByb21pc2Uoc291cmNlKSk7XHJcbiAgICAgICAgICBncm91cC5hZGQoXHJcbiAgICAgICAgICAgIHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgaWYgKCFmaW5pc2hlZCkge1xyXG4gICAgICAgICAgICAgICAgaGFzUmVzdWx0c1tpXSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICByZXN1bHRzW2ldID0gdmFsdWU7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBcclxuICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICBmaW5pc2hlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgc3Vic2NyaWJlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIGdyb3VwLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfSwgXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICBpZiAoIWZpbmlzaGVkKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIWhhc1Jlc3VsdHNbaV0pIHtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaGFzQ29tcGxldGVkW2ldID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIGl4ID0gMDsgaXggPCBjb3VudDsgaXgrKykge1xyXG4gICAgICAgICAgICAgICAgICBpZiAoIWhhc0NvbXBsZXRlZFtpeF0pIHsgcmV0dXJuOyB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBmaW5pc2hlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uTmV4dChyZXN1bHRzKTtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICB9KShpZHgpO1xyXG4gICAgICB9XHJcblxyXG4gICAgICByZXR1cm4gZ3JvdXA7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAgLyoqXHJcbiAgIC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pbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcblxyXG4gICAgICBpc1Byb21pc2Uoc2Vjb25kKSAmJiAoc2Vjb25kID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKHNlY29uZCkpO1xyXG5cclxuICAgICAgbGVmdFN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKFxyXG4gICAgICAgICAgZmlyc3Quc3Vic2NyaWJlKGZ1bmN0aW9uIChsZWZ0KSB7XHJcbiAgICAgICAgICAgIGhhc0xlZnQgPSB0cnVlO1xyXG4gICAgICAgICAgICBsYXN0TGVmdCA9IGxlZnQ7XHJcbiAgICAgICAgICB9LCBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgIHJpZ2h0U3Vic2NyaXB0aW9uLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBsZWZ0U3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgIGlmIChyaWdodFN0b3BwZWQpIHtcclxuICAgICAgICAgICAgICBpZiAoIWhhc0xlZnQpIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9IGVsc2UgaWYgKCFoYXNSaWdodCkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3IobGFzdExlZnQsIGxhc3RSaWdodCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgIH0pXHJcbiAgICAgICk7XHJcblxyXG4gICAgICByaWdodFN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKFxyXG4gICAgICAgIHNlY29uZC5zdWJzY3JpYmUoZnVuY3Rpb24gKHJpZ2h0KSB7XHJcbiAgICAgICAgICBoYXNSaWdodCA9IHRydWU7XHJcbiAgICAgICAgICBsYXN0UmlnaHQgPSByaWdodDtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICBsZWZ0U3Vic2NyaXB0aW9uLmRpc3Bvc2UoKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICByaWdodFN0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgaWYgKGxlZnRTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgIGlmICghaGFzTGVmdCkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIWhhc1JpZ2h0KSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihsYXN0TGVmdCwgbGFzd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IHx8IChzY2hlZHVsZXIgPSBpbW1lZGlhdGVTY2hlZHVsZXIpO1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBvYnNlcnZhYmxlRGVmZXIoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgY2hhaW47XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlXHJcbiAgICAgICAgICAgICAgICAuc2VsZWN0KFxyXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBjdXJyID0gbmV3IENoYWluT2JzZXJ2YWJsZSh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNoYWluKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGFpbi5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgY2hhaW4gPSBjdXJyO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGN1cnI7XHJcbiAgICAgICAgICAgICAgICAgICAgfSlcclxuICAgICAgICAgICAgICAgIC5kb0FjdGlvbihcclxuICAgICAgICAgICAgICAgICAgICBub29wLFxyXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjaGFpbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hhaW4ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoY2hhaW4pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoYWluLm9uQ29tcGxldGVkKCk7XHJc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ICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKENoYWluT2JzZXJ2YWJsZS5wcm90b3R5cGUsIE9ic2VydmVyLCB7XHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9uTmV4dChPYnNlcnZhYmxlLmVtcHR5KCkpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vbk5leHQoT2JzZXJ2YWJsZS50aHJvd0V4Y2VwdGlvbihlKSk7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHYpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMudGFpbC5vbk5leHQodik7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnRhaWwub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG5cclxuICAgICAgICByZXR1cm4gQ2hhaW5PYnNlcnZhYmxlO1xyXG5cclxuICAgIH0oT2JzZXJ2YWJsZSkpO1xyXG5cclxuICAgIC8qKiBAcHJpdmF0ZSAqL1xyXG4gICAgdmFyIE1hcCA9IChmdW5jdGlvbiAoKSB7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gTWFwKCkge1xyXG4gICAgICAgICAgICB0aGlzLmtleXMgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy52YWx1ZXMgPSBbXTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi9cclxuICAgICAgICBNYXAucHJvdG90eXBlWydkZWxldGUnXSA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgICAgICAgdmFyIGkgPSB0aGlzLmtleXMuaW5kZXhPZihrZXkpO1xyXG4gICAgICAgICAgICBpZiAoaSAhPT0gLTEpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMua2V5cy5zcGxpY2UoaSwgMSk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnZhbHVlcy5zcGxpY2UoaSwgMSk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgcmV0dXJuIGkgIT09IC0xO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi9cclxuICAgICAgICBNYXAucHJvdG90eXBlLmdldCA9IGZ1bmN0aW9uIChrZXksIGZhbGxiYWNrKSB7XHJcbiAgICAgICAgICAgIHZhciBpID0gdGhpcy5rZXlzLmluZGV4T2Yoa2V5KTtcclxuICAgICAgICAgICAgcmV0dXJuIGkgIT09IC0xID8gdGhpcy52YWx1ZXNbaV0gOiBmYWxsYmFjaztcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBNYXAjXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgTWFwLnByb3RvdHlwZS5zZXQgPSBmdW5jdGlvbiAoa2V5LCB2YWx1ZSkge1xyXG4gICAgICAgICAgICB2YXIgaSA9IHRoaXMua2V5cy5pbmRleE9mKGtleSk7XHJcbiAgICAgICAgICAgIGlmIChpICE9PSAtMSkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy52YWx1ZXNbaV0gPSB2YWx1ZTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB0aGlzLnZhbHVlc1t0aGlzLmtleXMucHVzaChrZXkpIC0gMV0gPSB2YWx1ZTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBNYXAjXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgTWFwLnByb3RvdHlwZS5zaXplID0gZnVuY3Rpb24gKCkgeyByZXR1cm4gdGhpcy5rZXlzLmxlbmd0aDsgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgTWFwI1xyXG4gICAgICAgICAqLyAgICAgICAgXHJcbiAgICAgICAgTWFwLnByb3RvdHlwZS5oYXMgPSBmdW5jdGlvbiAoa2V5KSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLmtleXMuaW5kZXhPZihrZXkpICE9PSAtMTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBNYXAjXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBNYXAucHJvdG90eXBlLmdldEtleXMgPSBmdW5jdGlvbiAoKSB7IHJldHVybiB0aGlzLmtleXMuc2xpY2UoMCk7IH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIE1hcC5wcm90b3R5cGUuZ2V0VmFsdWVzID0gZnVuY3Rpb24gKCkgeyByZXR1cm4gdGhpcy52YWx1ZXMuc2xpY2UoMCk7IH07XHJcblxyXG4gICAgICAgIHJldHVybiBNYXA7XHJcbiAgICB9KCkpO1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgKiBSZXByZXNlbnRzIGEgam9pb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vbi5wYXR0ZXJucy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICBqb2luT2JzZXJ2ZXJzLnB1c2gocGxhbkNyZWF0ZU9ic2VydmVyKGV4dGVybmFsU3Vic2NyaXB0aW9ucywgdGhpcy5leHByZXNzaW9uLnBhdHRlcm5zW2ldLCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpKSk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBhY3RpdmVQbGFuID0gbmV3IEFjdGl2ZVBsYW4oam9pbk9ic2VydmVycywgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgcmVzdWx0ID0gc2VsZi5zZWxlY3Rvci5hcHBseShzZWxmLCBhcmd1bWVudHMpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGogPSAwLCBqbGVuID0gam9pbk9ic2VydmVycy5sZW5ndGg7IGogPCBqbGVuOyBqKyspIHtcclxuICAgICAgICAgICAgICAgIGpvaW5PYnNlcnZlcnNbal0ucmVtb3ZlQWN0aXZlUGxhbihhY3RpdmVQbGFuKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBkZWFjdGl2YXRlKGFjdGl2ZVBsYW4pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGpvaW5PYnNlcnZlcnMubGVuZ3RoOyBpIDwgbGVuOyBpKyspI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lcyA9IFtdO1xyXG4gICAgICAgICAgICBpc0NvbXBsZXRlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSB0aGlzLmpvaW5PYnNlcnZlckFycmF5Lmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBmaXJzdFZhbHVlcy5wdXNoKHRoaXMuam9pbk9ic2VydmVyQXJyYXlbaV0ucXVldWVbMF0pO1xyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuam9pbk9ic2VydmVyQXJyYXlbaV0ucXVldWVbMF0ua2luZCA9PT0gJ0MnKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNDb21wbGV0ZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmIChpc0NvbXBsZXRlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5kZXF1ZXVlKCk7XHJcbiAgICAgICAgICAgICAgICB2YWx1ZXMgPSBbXTtcclxuICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBmaXJzdFZhbHVlcy5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhbHVlcy5wdXNoKGZpcnN0VmFsdWVzW2ldLnZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHRoaXMub25OZXh0LmFwcGx5KHRoaXMsIHZhbHVlcyk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKiBAcHJpdmF0ZSAqL1xyXG4gICAgdmFyIEpvaW5PYnNlcnZlciA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcblxyXG4gICAgICAgIGluaGVyaXRzKEpvaW5PYnNlcnZlciwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBKb2luT2JzZXJ2ZXIoc291cmNlLCBvbkVycm9yKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICB0aGlzLnNvdXJjZSA9IHNvdXJjZTtcclxuICAgICAgICAgICAgdGhpcy5vbkVycm9yID0gb25FcnJvcjtcclxuICAgICAgICAgICAgdGhpcy5xdWV1ZSA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLmFjdGl2ZVBsYW5zID0gW107XHJcbiAgICAgICAgICAgIHRoaXMuc3Vic2NyaXB0aW9uID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IGZhbHNlO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIEpvaW5PYnNlcnZlclByb3RvdHlwZSA9IEpvaW5PYnNlcnZlci5wcm90b3R5cGU7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi9cclxuICAgICAgICBKb2luT2JzZXJ2ZXJQcm90b3R5cGUubmV4dCA9IGZ1bmN0aW9uIChub3RpZmljYXRpb24pIHtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgIGlmIChub3RpZmljYXRpb24ua2luZCA9PT0gJ0UnKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vbkVycm9yKG5vdGlmaWNhdGlvbi5leGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHRoaXMucXVldWUucHVzaChub3RpZmljYXRpb24pO1xyXG4gICAgICAgICAgICAgICAgdmFyIGFjdGl2ZVBsYW5zID0gdGhpcy5hY3RpdmVQbGFucy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBhY3RpdmVQbGFucy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIGFjdGl2ZVBsYW5zW2ldLm1hdGNoKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAbWVtYmVyT2YgSm9pbk9ic2VydmVyI1xyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBKb2luT2JzZXJ2ZXJQcm90b3R5cGUuZXJyb3IgPSBub29wO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAbWVtYmVyT2YgSm9pbk9ic2VydmVyI1xyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBKb2luT2JzZXJ2ZXJQcm90b3R5cGUuY29tcGxldGVkID0gbm9vcDtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQG1lbWJlck9mIEpvaW5PYnNlcnZlciNcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5hZGRBY3RpdmVQbGFuID0gZnVuY3Rpb24gKGFjdGl2ZVBsYW4pIHtcclxuICAgICAgICAgICAgdGhpcy5hY3RpdmVQbGFucy5wdXNoKGFjdGl2ZVBsYW4pO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5zdWJzY3JpYmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRoaXMuc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUodGhpcy5zb3VyY2UubWF0ZXJpYWxpemUoKS5zdWJzY3JpYmUodGhpcykpO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5yZW1vdmVBY3RpdmVQbGFuID0gZnVuY3Rpb24gKGFjdGl2ZVBsYW4pIHtcclxuICAgICAgICAgICAgdmFyIGlkeCA9IHRoaXMuYWN0aXZlUGxhbnMuaW5kZXhPZihhY3RpdmVQbGFuKTtcclxuICAgICAgICAgICAgdGhpcy5hY3RpdmVQbGFucy5zcGxpY2UoaWR4LCAxKTtcclxuICAgICAgICAgICAgaWYgKHRoaXMuYWN0aXZlUGxhbnMubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBfc3VwZXIucHJvd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KG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBhY3RpdmVQbGFucyA9IFtdLFxyXG4gICAgICAgICAgICAgICAgZXh0ZXJuYWxTdWJzY3JpcHRpb25zID0gbmV3IE1hcCgpLFxyXG4gICAgICAgICAgICAgICAgZ3JvdXAsXHJcbiAgICAgICAgICAgICAgICBpLCBsZW4sXHJcbiAgICAgICAgICAgICAgICBqb2luT2JzZXJ2ZXIsXHJcbiAgICAgICAgICAgICAgICBqb2luVmFsdWVzLFxyXG4gICAgICAgICAgICAgICAgb3V0T2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgIG91dE9ic2VydmVyID0gb2JzZXJ2ZXJDcmVhdGUob2JzZXJ2ZXIub25OZXh0LmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgdmFsdWVzID0gZXh0ZXJuYWxTdWJzY3JpcHRpb25zLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaiA9IDAsIGpsZW4gPSB2YWx1ZXMubGVuZ3RoOyBqIDwgamxlbjsgaisrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFsdWVzW2pdLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gcGxhbnMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICBhY3RpdmVQbGFucy5wdXNoKHBsYW5zW2ldLmFjdGl2YXRlKGV4dGVybmFsU3Vic2NyaXB0aW9ucywgb3V0T2JzZXJ2ZXIsIGZ1bmN0aW9uIChhY3RpdmVQbGFuKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBpZHggPSBhY3RpdmVQbGFucy5pbmRleE9mKGFjdGl2ZVBsYW4pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBhY3RpdmVQbGFucy5zcGxpY2UoaWR4LCAxKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGFjdGl2ZVBsYW5zLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0T2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2YWJsZVRocm93KGUpLnN1YnNjcmliZShvYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgZ3JvdXAgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBqb2luVmFsdWVzID0gZXh0ZXJuYWxTdWJzY3JpcHRpb25zLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBqb2luVmFsdWVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBqb2luT2JzZXJ2ZXIgPSBqb2luVmFsdWVzW2ldO1xyXG4gICAgICAgICAgICAgICAgam9pbk9ic2VydmVyLnN1YnNjcmliZSgpO1xyXG4gICAgICAgICAgICAgICAgZ3JvdXAuYWRkKGpvaW5PYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgcmV0dXJuIGdyb3VwO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBvYnNlcnZhYmxlVGltZXJEYXRlKGR1ZVRpbWUsIHNjaGVkdWxlcikge1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHNjaGVkdWxlci5zY2hlZHVsZVdpdGhBYnNvbHV0ZShkdWVUaW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoMCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgZnVuY3Rpb24gb2JzZXJ2YWJsZVRpbWVyRGF0ZUFuZFBlcmlvZChkdWVUaW1lLCBwZXJpb2QsIHNjaGVkdWxlcikge1xyXG4gICAgdmFyIHAgPSBub3JtYWxpemVUaW1lKHBlcmlvZCk7XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBjb3VudCA9IDAsIGQgPSBkdWVUaW1lO1xyXG4gICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlV2l0aEFic29sdXRlKGQsIGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgdmFyIG5vdztcclxuICAgICAgICBpZiAocCA+IDApIHtcclxuICAgICAgICAgIG5vdyA9IHNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgIGQgPSBkICsgcDtcclxuICAgICAgICAgIGlmIChkIDw9IG5vdykge1xyXG4gICAgICAgICAgICBkID0gbm93ICsgcDtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGNvdW50KyspO1xyXG4gICAgICAgIHNlbGYoZCk7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gICAgICAgIHJldHVybiBvYnNlcnZhYmxlVGltZXJUaW1lU3BhbkFuZFBlcmlvZChkdWVUaW1lLCBwZXJpb2QsIHNjaGVkdWxlcik7XHJcbiAgICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIG9ic2VydmFibGVEZWxheVRpbWVTcGFuKGR1ZVRpbWUsIHNjaGVkdWxlcikge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGFjdGl2ZSA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgY2FuY2VsYWJsZSA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICBleGNlcHRpb24gPSBudWxsLFxyXG4gICAgICAgICAgICAgICAgcSA9IFtdLFxyXG4gICAgICAgICAgICAgICAgcnVubmluZyA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uO1xyXG4gICAgICAgICAgICBzdWJzY3JpcHRpb24gPSBzb3VyY2UubWF0ZXJpYWxpemUoKS50aW1lc3RhbXAoc2NoZWR1bGVyKS5zdWJzY3JpYmUoZnVuY3Rpb24gKG5vdGlmaWNhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgdmFyIGQsIHNob3VsZFJ1bjtcclxuICAgICAgICAgICAgICAgIGlmIChub3RpZmljYXRpb24udmFsdWUua2luZCA9PT0gJ0UnKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcSA9IFtdO1xyXG4gICAgICAgICAgICAgICAgICAgIHEucHVzaChub3RpZmljYXRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIGV4Y2VwdGlvbiA9IG5vdGlmaWNhdGlvbi52YWx1ZS5leGNlcHRpb247XHJcbiAgICAgICAgICAgICAgICAgICAgc2hvdWxkUnVuID0gIXJ1bm5pbmc7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHEucHVzaCh7IHZhbHVlOiBub3RpZmljYXRpb24udmFsdWUsIHRpbWVzdGFtcDogbm90aWZpY2F0aW9uLnRpbWVzdGFtcCArIGR1ZVRpbWUgfSk7XHJcbiAgICAgICAgICAgICAgICAgICAgc2hvdWxkUnVuID0gIWFjdGl2ZTtcclxuICAgICAgICAgICAgICAgICAgICBhY3RpdmUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKHNob3VsZFJ1bikge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChleGNlcHRpb24gIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgY2FuY2VsYWJsZS5zZXREaXNwb3NhYmxlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkLnNldERpc3Bvc2FibGUoc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlV2l0aFJlbGF0aXZlKGR1ZVRpbWUsIGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgZSwgcmVjdXJzZUR1ZVRpbWUsIHJlc3VsdCwgc2hvdWxkUmVjdXJzZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChleGNlcHRpb24gIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBydW5uaW5nID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDAgJiYgcVswXS50aW1lc3RhbXAgLSBzY2hlZHVsZXIubm93KCkgPD0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSBxLnNoaWZ0KCkudmFsdWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZXN1bHQgIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LmFjY2VwdChvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAocmVzdWx0ICE9PSBudWxsKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3VsZFJlY3Vyc2UgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlY3Vyc2VEdWVUaW1lID0gMDtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG91bGRSZWN1cnNlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZWN1cnNlRHVlVGltZSA9IE1hdGgubWF4KDAsIHFbMF0udGltZXN0YW1wIC0gc2NoZWR1bGVyLm5vdygpKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYWN0aXZlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlID0gZXhjZXB0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcnVubmluZyA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGUgIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzaG91bGRSZWN1cnNlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZihyZWN1cnNlRHVlVGltZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uLCBjYW5jZWxhYmxlKTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBvYnNlcnZhYmxlRGVsYXlEYXRlKGR1ZVRpbWUsIHNjaGVkdWxlcikge1xyXG4gICAgICAgIHZhciBzZWxmID0gdGhpcztcclxuICAgICAgICByZXR1cm4gb2JzZXJ2YWJsZURlZmVyKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdmFyIHRpbWVTcGFuID0gZHVlVGltZSAtIHNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgcmV0dXJuIG9ic2VydmFibGVEZWxheVRpbWVTcGFuLmNhbGwoc2VsZiwgdGltZVNwYW4sIHNjaGVkdWxlcik7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9XHJc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ZVNoaWZ0ID0gdGltZVNwYW47XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChzY2hlZHVsZXIgPT09IHVuZGVmaW5lZCkge1xyXG4gICAgICAgICAgICBzY2hlZHVsZXIgPSB0aW1lb3V0U2NoZWR1bGVyO1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAodHlwZW9mIHRpbWVTaGlmdE9yU2NoZWR1bGVyID09PSAnbnVtYmVyJykge1xyXG4gICAgICAgICAgICB0aW1lU2hpZnQgPSB0aW1lU2hpZnRPclNjaGVkdWxlcjtcclxuICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB0aW1lU2hpZnRPclNjaGVkdWxlciA9PT0gJ29iamVjdCcpIHtcclxuICAgICAgICAgICAgdGltZVNoaWZ0ID0gdGltZVNwYW47XHJcbiAgICAgICAgICAgIHNjaGVkdWxlciA9IHRpbWVTaGlmdE9yU2NoZWR1bGVyO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBncm91cERpc3Bvc2FibGUsXHJcbiAgICAgICAgICAgICAgICBuZXh0U2hpZnQgPSB0aW1lU2hpZnQsXHJcbiAgICAgICAgICAgICAgICBuZXh0U3BhbiA9IHRpbWVTcGFuLFxyXG4gICAgICAgICAgICAgICAgcSA9IFtdLFxyXG4gICAgICAgICAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlLFxyXG4gICAgICAgICAgICAgICAgdGltZXJEID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHRvdGFsVGltZSA9IDA7XHJcbiAgICAgICAgICAgICAgICBncm91cERpc3Bvc2FibGUgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSh0aW1lckQpLFxyXG4gICAgICAgICAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShncm91cERpc3Bvc2FibGUpO1xyXG5cclxuICAgICAgICAgICAgIGZ1bmN0aW9uIGNyZWF0ZVRpbWVyICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBtID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICAgICAgaXNTcGFuID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICAgICAgaXNTaGlmdCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgdGltZXJELnNldERpc3Bvc2FibGUobSk7XHJcbiAgICAgICAgICAgICAgICBpZiAobmV4dFNwYW4gPT09IG5leHRTaGlmdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlzU3BhbiA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNTaGlmdCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG5leHRTcGFuIDwgbmV4dFNoaWZ0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNTcGFuID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNTaGlmdCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB2YXIgbmV3VG90YWxUaW1lID0gaXNTcGFuID8gbmV4dFNwYW4gOiBuZXh0U2hpZnQsXHJcbiAgICAgICAgICAgICAgICAgICAgdHMgPSBuZXdUb3RhbFRpbWUgLSB0b3RhbFRpbWU7XHJcbiAgICAgICAgICAgICAgICB0b3RhbFRpbWUgPSBuZXdUb3RhbFRpbWU7XHJcbiAgICAgICAgICAgICAgICBpZiAoaXNTcGFuKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV4dFNwYW4gKz0gdGltZVNoaWZ0O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGlzU2hpZnQpIHtcclxuICAgICAgICAgICAgICAgICAgICBuZXh0U2hpZnQgKz0gdGltZVNoaWZ0O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgbS5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVdpdGhSZWxhdGl2ZSh0cywgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBzO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpc1NoaWZ0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHMgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBxLnB1c2gocyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpc1NwYW4pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcyA9IHEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBjcmVhdGVUaW1lcigpO1xyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICBxLnB1c2gobmV3IFN1YmplY3QoKSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocVswXSwgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgIGNyZWF0ZVRpbWVyKCk7XHJcbiAgICAgICAgICAgIGdyb3VwRGlzcG9zYWJsZS5hZGQoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGksIHM7XHJcbiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgcS5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHMgPSBxW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGksIHM7XHJcbiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgcS5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHMgPSBxW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBpLCBzO1xyXG4gICAgICAgICAgICAgICAgZm9yIChpID0gMDsgaSA8IHEubGVuZ3RoOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICBzID0gcVtpXTtcclxuICAgICAgICAgICAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIHJldHVybiByZWZDb3VudERpc3Bvc2FibGU7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFByb2plY3RzIGVhY2ggZWxlbWVudCBvZiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIGludG8gYSB3aW5kb3cgdGhhdCBpcyBjb21wbGV0ZWQgd2hlbiBlaXRoZXIgaXQncyBmdWxsIG9yIGEgZ2l2ZW4gYW1vdW50IG9mIHRpbWUgaGFzIGVsYXBzZWQuXHJcb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gICAgdmFyIGNyZWF0ZVRpbWVyLFxyXG4gICAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLFxyXG4gICAgICAgICAgICAgICAgbiA9IDAsXHJcbiAgICAgICAgICAgICAgICByZWZDb3VudERpc3Bvc2FibGUsXHJcbiAgICAgICAgICAgICAgICBzLFxyXG4gICAgICAgICAgICAgICAgdGltZXJEID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHdpbmRvd0lkID0gMDtcclxuICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUodGltZXJEKTtcclxuICAgICAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShncm91cERpc3Bvc2FibGUpO1xyXG4gICAgICAgICAgICBjcmVhdGVUaW1lciA9IGZ1bmN0aW9uIChpZCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG0gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgIHRpbWVyRC5zZXREaXNwb3NhYmxlKG0pO1xyXG4gICAgICAgICAgICAgICAgbS5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVdpdGhSZWxhdGl2ZSh0aW1lU3BhbiwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBuZXdJZDtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaWQgIT09IHdpbmRvd0lkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgbiA9IDA7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV3SWQgPSArK3dpbmRvd0lkO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICAgICAgICAgICAgICAgIGNyZWF0ZVRpbWVyKG5ld0lkKTtcclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgIGNyZWF0ZVRpbWVyKDApO1xyXG4gICAgICAgICAgICBncm91cERpc3Bvc2FibGUuYWRkKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBuZXdJZCA9IDAsIG5ld1dpbmRvdyA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgcy5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICBuKys7XHJcbiAgICAgICAgICAgICAgICBpZiAobiA9PT0gY291bnQpIHtcclxuICAgICAgICAgICAgICAgICAgICBuZXdXaW5kb3cgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIG4gPSAwO1xyXG4gICAgICAgICAgICAgICAgICAgIG5ld0lkID0gKyt3aW5kb3dJZDtcclxuICAgICAgICAgICAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihzLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChuZXdXaW5kb3cpIHtcclxuICAgICAgICAgICAgICAgICAgICBjcmVhdG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VByb3RvLnRpbWVzdGFtcCA9IGZ1bmN0aW9uIChzY2hlZHVsZXIpIHtcclxuICAgICAgICBzY2hlZHVsZXIgfHwgKHNjaGVkdWxlciA9IHRpbWVvdXRTY2hlZHVsZXIpO1xyXG4gICAgICAgIHJldHVybiB0aGlzLnNlbGVjdChmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICByZXR1cm4ge1xyXG4gICAgICAgICAgICAgICAgdmFsdWU6IHgsXHJcbiAgICAgICAgICAgICAgICB0aW1lc3RhbXA6IHNjaGVkdWxlci5ub3coKVxyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBzYW1wbGVPYnNlcnZhYmxlKHNvdXJjZSwgc2FtcGxlcikge1xyXG4gICAgICAgIFxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGF0RW5kLCB2YWx1ZSwgaGFzVmFsdWU7XHJcblxyXG4gICAgICAgICAgICBmdW5jdGlvbiBzYW1wbGVTdWJzY3JpYmUoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzVmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoYXRFbmQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoXHJcbiAgICAgICAgICAgICAgICBzb3VyY2Uuc3Vic2Nya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aXRjaGVkID0gZmFsc2UsXHJcbiAgICAgICAgdGltZXIgPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpO1xyXG5cclxuICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUob3JpZ2luYWwpO1xyXG5cclxuICAgICAgdmFyIGNyZWF0ZVRpbWVyID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBteUlkID0gaWQ7XHJcbiAgICAgICAgdGltZXIuc2V0RGlzcG9zYWJsZShzY2hlZHVsZXJbc2NoZWR1bGVyTWV0aG9kXShkdWVUaW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBpZiAoaWQgPT09IG15SWQpIHtcclxuICAgICAgICAgICAgaXNQcm9taXNlKG90aGVyKSAmJiAob3RoZXIgPSBvYnNlcnZhYmxlRnJvbVByb21pc2Uob3RoZXIpKTtcclxuICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUob3RoZXIuc3Vic2NyaWJlKG9ic2VydmVyKSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSkpO1xyXG4gICAgICB9O1xyXG5cclxuICAgICAgY3JlYXRlVGltZXIoKTtcclxuICAgICAgXHJcbiAgICAgIG9yaWdpbmFsLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgIGlmICghc3dpdGNoZWQpIHtcclxuICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICBjcmVhdGVUaW1lcigpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICBpZiAoIXN3aXRjaGVkKSB7XHJcbiAgICAgICAgICBpZCsrO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICB9XHJcbiAgICAgIH0sIGZ1bmN0aW9uICgp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gICAgICByZXN1bHQsXHJcbiAgICAgICAgICAgICAgICBzdGF0ZSA9IGluaXRpYWxTdGF0ZSxcclxuICAgICAgICAgICAgICAgIHRpbWU7XHJcbiAgICAgICAgICAgIHJldHVybiBzY2hlZHVsZXIuc2NoZWR1bGVSZWN1cnNpdmVXaXRoQWJzb2x1dGUoc2NoZWR1bGVyLm5vdygpLCBmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoZmlyc3QpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZmlyc3QgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZSA9IGl0ZXJhdGUoc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBoYXNSZXN1bHQgPSBjb25kaXRpb24oc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3Ioc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aW1lID0gdGltZVNlbGVjdG9yKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzUmVzdWx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LFxyXG4gICAgICAgICAgICAgICAgc3RhdGUgPSBpbml0aWFsU3RhdGUsXHJcbiAgICAgICAgICAgICAgICB0aW1lO1xyXG4gICAgICAgICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlV2l0aFJlbGF0aXZlKDAsIGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzUmVzdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmaXJzdCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlID0gaXRlcmF0ZShzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1Jlc3VsdCA9IGNvbmRpdGlvbihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRpbWUgPSB0aW1lU2VsZWN0b3Ioc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICA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TZXJpYWxEaXNwb3NhYmxlKCksIHN0YXJ0ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBkZWxheTtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWxheSA9IHNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZGVsYXlzLmFkZChkKTtcclxuICAgICAgICAgICAgICAgICAgICBkLnNldERpc3Bvc2FibGUoZGVsYXkuc3Vic2NyaWJlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWxheXMucmVtb3ZlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlbGF5cy5yZW1vdmUoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgYXRFbmQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgaWYgKCFzdWJEZWxheSkge1xyXG4gICAgICAgICAgICAgICAgc3RhcnQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKHN1YkRlbGF5LnN1YnNjcmliZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3RhcnQoKTtcclxuICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHsgc3RhcnQoKTsgfSkpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uLCBkZWxheXMpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBSZXR1cm5zIHRoZSBzb3VyY2Ugb2JzZXJ2YWJsZSBzZXF1ZW5jZSwgc3dpdGNoaW5nIHRvIHRoZSBvdGhlciBvYnNlcnZhYmxlIHNlcXVlbmNlIGlmIGEgdGltZW91dCBpcyBzaWduYWxlZC5cclxuICAgICAqICBcclxuICAgICAqIEBleGFtcGxlXHJcbiAgICAgKiAgMSAtIHJlcyA9IHNvdXJjZS50aW1lb3V0V2l0aFN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HRpbWVvdXQpIHtcclxuICAgICAgICAgICAgICAgIHZhciBteUlkID0gaWQsIHRpbWVyV2lucyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaWQgPT09IG15SWQ7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgIHRpbWVyLnNldERpc3Bvc2FibGUoZCk7XHJcbiAgICAgICAgICAgICAgICBkLnNldERpc3Bvc2FibGUodGltZW91dC5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aW1lcldpbnMoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShvdGhlci5zdWJzY3JpYmUob2JzZXJ2ZXIpKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aW1lcldpbnMoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGltZXJXaW5zKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUob3RoZXIuc3Vic2NyaWJlKG9ic2VydmVyKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgc2V0VGltZXIoZmlyc3RUaW1lb3V0KTtcclxuICAgICAgICAgICAgdmFyIG9ic2VydmVyV2lucyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciByZXMgPSAhc3dpdGNoZWQ7XHJcbiAgICAgICAgICAgICAgICBpZiAocmVzKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWQrKztcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHJldHVybiByZXM7XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBvcmlnaW5hbC5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGlmIChvYnNlcnZlcldpbnMoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgdGltZW91dDtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aW1lb3V0ID0gdGltZW91dGR1cmF0aW9uU2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHNldFRpbWVyKHRpbWVvdXQpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgaWYgKG9ic2VydmVyV2lucygpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgZnVuY3R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gc291cmNlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciB2YWx1ZSwgaGFzVmFsdWUgPSBmYWxzZSwgY2FuY2VsYWJsZSA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksIGlkID0gMCwgc3Vic2NyaXB0aW9uID0gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHRocm90dGxlO1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICB0aHJvdHRsZSA9IHRocm90dGxlRHVyYXRpb25TZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHZhbHVlID0geDtcclxuICAgICAgICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgICAgICAgICB2YXIgY3VycmVudGlkID0gaWQsIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgIGNhbmNlbGFibGUuc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZSh0aHJvdHRsZS5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChoYXNWYWx1ZSAmJiBpZCA9PT0gY3VycmVudGlkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGhhc1ZhbHVlICYmIGlkID09PSBjdXJyZW50aWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICBkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgIGNhbmNlbGFibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICBpZCsrO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBjYW5jZWxhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIGlmIChoYXNWYWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAg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cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG5vdyA9IHNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgICAgIHEucHVzaCh7IGludGVydmFsOiBub3csIHZhbHVlOiB4IH0pO1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCAmJiBub3cgLSBxWzBdLmludGVydmFsID49IGR1cmF0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbm93ID0gc2NoZWR1bGVyLm5vdygpLCByZXMgPSBbXTtcclxuICAgICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbmV4dCA9IHEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAobm93IC0gbmV4dC5pbnRlcnZhbCA8PSBkdXJhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXMucHVzaChuZXh0LnZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlcyk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgVGFrZXMgZWxlbWVudHMgZm9yIHRoZSBzcGVjaWZpZWQgZHVyYXRpb24gZnJvbSB0aGUgc3RhcnQgb2YgdGhlIG9ic2VydmFibGUgc291cmNlIHNl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zZSxcclxuICAgICAgICBtID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksXHJcbiAgICAgICAgZyA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCk7XHJcblxyXG4gICAgICBnLmFkZChtKTtcclxuXHJcbiAgICAgIG0uc2V0RGlzcG9zYWJsZShzb3VyY2VzLnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAoaW5uZXJTb3VyY2UpIHtcclxuICAgICAgICAgIGlmICghaGFzQ3VycmVudCkge1xyXG4gICAgICAgICAgICBoYXNDdXJyZW50ID0gdHJ1ZTtcclxuICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIGlzUHJvbWlzZShpbm5lclNvdXJjZSkgJiYgKGlubmVyU291cmNlID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKGlubmVyU291cmNlKSk7XHJcblxyXG4gICAgICAgICAgICB2YXIgaW5uZXJTdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgZy5hZGQoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG5cclxuICAgICAgICAgICAgaW5uZXJTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShpbm5lclNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0LmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgZy5yZW1vdmUoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgaGFzQ3VycmVudCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgaWYgKGlzU3RvcHBlZCAmJiBnLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAgICA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YnNjcmliZShcclxuICAgICAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHNlbGVjdG9yLmNhbGwodGhpc0FyZywgeCwgaW5kZXgrKywgaW5uZXJTb3VyY2UpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGcucmVtb3ZlKGlubmVyU3Vic2NyaXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIGhhc0N1cnJlbnQgPSBmYWxzZTtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoaXNTdG9wcGVkICYmIGcubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0sIFxyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgIGlmIChnLmxlbmd0aCA9PT0gMSAmJiAhaGFzQ3VycmVudCkge1xyXG4gICAgICAg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HRoaXMuc2NoZWR1bGVSZWxhdGl2ZVdpdGhTdGF0ZShhY3Rpb24sIGR1ZVRpbWUsIGludm9rZUFjdGlvbik7XHJcbiAgICAgICAgfTsgICAgXHJcblxyXG4gICAgICAgIC8qKiBcclxuICAgICAgICAgKiBTdGFydHMgdGhlIHZpcnR1YWwgdGltZSBzY2hlZHVsZXIuIFxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIFZpcnR1YWxUaW1lU2NoZWR1bGVyUHJvdG90eXBlLnN0YXJ0ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgbmV4dDtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRW5hYmxlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0VuYWJsZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgZG8ge1xyXG4gICAgICAgICAgICAgICAgICAgIG5leHQgPSB0aGlzLmdldE5leHQoKTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAobmV4dCAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5jb21wYXJlcihuZXh0LmR1ZVRpbWUsIHRoaXMuY2xvY2spID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5jbG9jayA9IG5leHQuZHVlVGltZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBuZXh0Lmludm9rZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuaXNFbmFibGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSB3aGlsZSAodGhpcy5pc0VuYWJsZWQpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqIFxyXG4gICAgICAgICAqI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WU7XHJcbiAgICAgICAgICAgICAgICBkbyB7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV4dCA9IHRoaXMuZ2V0TmV4dCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChuZXh0ICE9PSBudWxsICYmIHRoaXMuY29tcGFyZXIobmV4dC5kdWVUaW1lLCB0aW1lKSA8PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLmNvbXBhcmVyKG5leHQuZHVlVGltZSwgdGhpcy5jbG9jaykgPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmNsb2NrID0gbmV4dC5kdWVUaW1lO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG5leHQuaW52b2tlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5pc0VuYWJsZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IHdoaWxlICh0aGlzLmlzRW5hYmxlZCk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmNsb2NrID0gdGltZTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEFkdmFuY2VzIHRoZSBzY2hlZHVsZXIncyBjbG9jayBieSB0aGUgc3BlY2lmaWVkIHJlbGF0aXZlIHRpbWUsIHJ1bm5pbmcgYWxsIHdvcmsgc2NoZWR1bGVkIGZvciB0aGF0IHRpbWVzcGFuLlxyXG4gICAgICAgICAqIEBwYXJhbSB7TnVtYmVyfSB0aW1lIFJlbGF0aXZlIHRpbWUgdG8gYWR2YW5jZSB0aGUgc2NoZWR1bGVyJ3MgY2xvY2sgYnkuXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgVmlydHVhbFRpbWVTY2hlZH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XRPZlJhbmdlKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdGhpcy5jbG9jayA9IGR0O1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEdldHMgdGhlIG5leHQgc2NoZWR1bGVkIGl0ZW0gdG8gYmUgZXhlY3V0ZWQuICAgICAgICAgIFxyXG4gICAgICAgICAqIEByZXR1cm5zIHtTY2hlZHVsZWRJdGVtfSBUaGUgbmV4dCBzY2hlZHVsZWQgaXRlbS5cclxuICAgICAgICAgKi8gICAgICAgICAgXHJcbiAgICAgICAgVmlydHVhbFRpbWVTY2hlZHVsZXJQcm90b3R5cGUuZ2V0TmV4dCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdmFyIG5leHQ7XHJcbiAgICAgICAgICAgIHdoaWxlICh0aGlzLnF1ZXVlLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgIG5leHQgPSB0aGlzLnF1ZXVlLnBlZWsoKTtcclxuICAgICAgICAgICAgICAgIGlmIChuZXh0LmlzQ2FuY2VsbGVkKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnF1ZXVlLmRlcXVldWUoKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG5leHQ7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgcmV0dXJuIG51bGw7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogU2NoZWR1bGVzIGFuIGFjdGlvbiB0byBiZSBleGVjdXRlZCBhdCBkdWVUaW1lLiAgICAgICBcclxuICAgICAgICAgKiBAcGFyYW0ge1NjaGVkdWxlcn0gc2NoZWR1bGVyIFNjaGVkdWxlciB0byBleGVjdXRlIHRoZSBhY3Rpb24gb24uXHJcbiAgICAgICAgICogQHBhcm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hY2hPYnNlcnZlciA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcbiAgICAgICAgaW5oZXJpdHMoQXV0b0RldGFjaE9ic2VydmVyLCBfc3VwZXIpO1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBBdXRvRGV0YWNoT2JzZXJ2ZXIob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIgPSBvYnNlcnZlcjtcclxuICAgICAgICAgICAgdGhpcy5tID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICB2YXIgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlID0gQXV0b0RldGFjaE9ic2VydmVyLnByb3RvdHlwZTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLm5leHQgPSBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgdmFyIG5vRXJyb3IgPSBmYWxzZTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIG5vRXJyb3IgPSB0cnVlO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7IFxyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTsgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIW5vRXJyb3IpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5lcnJvciA9IGZ1bmN0aW9uIChleG4pIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25FcnJvcihleG4pO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7IFxyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTsgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5jb21wbGV0ZWQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlOyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLnNldERpc3Bvc2FibGUgPSBmdW5jdGlvbiAodmFsdWUpIHsgdGhpcy5tLnNldERpc3Bvc2FibGUodmFsdWUpOyB9O1xyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5nZXREaXNwb3NhYmxlID0gZnVuY3Rpb24gKHZhbHVlKSB7IHJldHVybiB0aGlzLm0uZ2V0RGlzcG9zYWJsZSgpOyB9O1xyXG4gICAgICAgIC8qIEBwcml2YXRlICovXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLmRpc3Bvc2FibGUgPSBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgcmV0dXJuIGFyZ3VtZW50cy5sZW5ndGggPyB0aGlzLmdldERpc3Bvc2FibGUoKSA6IHNldERpc3Bvc2FibGUodmFsdWUpO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBfc3VwZXIucHJvdG90eXBlLmRpc3Bvc2UuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgdGhpcy5tLmRpc3Bvc2UoKTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICByZXR1cm4gQXV0b0RldGFjaE9ic2VydmVyO1xyXG4gICAgfShBYnN0cmFjdE9ic2VydmVyKSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgR3JvdXBlZE9ic2VydmFibGUgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG4gICAgICAgIGluaGVyaXRzKEdyb3VwZWRPYnNlcnZhYmxlLCBfc3VwZXIpO1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBzdWJzY3JpYmUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHRoaXMudW5kZXJseWluZ09ic2VydmFibGUuc3Vic2NyaWJlKG9ic2VydmVyKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8qKiBcclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIGZ1bmN0aW9uIEdyb3VwZWRPYnNlcnZhYmxlKGtleSwgdW5kZXJseWluZ09ic2VydmFibGUsIG1lcmdlZERpc3Bvc2FibGUpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICAgICAgdGhpcy5rZXkgPSBrZXk7XHJcb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iBuZXcgSW5uZXJTdWJzY3JpcHRpb24odGhpcywgb2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmICh0aGlzLmV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcih0aGlzLmV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpbmhlcml0cyhTdWJqZWN0LCBfc3VwZXIpO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBDcmVhdGVzIGEgc3ViamVjdC5cclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKi8gICAgICBcclxuICAgICAgICBmdW5jdGlvbiBTdWJqZWN0KCkge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSBmYWxzZSxcclxuICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSBmYWxzZSxcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFkZFByb3BlcnRpZXMoU3ViamVjdC5wcm90b3R5cGUsIE9ic2VydmVyLCB7XHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqIEByZXR1cm5zIHtCb29sZWFufSBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgIFxyXG4gICAgICAgICAgICBoYXNPYnNlcnZlcnM6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLm9ic2VydmVycy5sZW5ndGggPiAwO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBlbmQgb2YgdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGV4Y2VwdGlvbi5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gZXJyb3IgVGhlIGV4Y2VwdGlvbiB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZXhjZXB0aW9uID0gZXhjZXB0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBhcnJpdmFsIG9mIHRoZSBzcGVjaWZpZWQgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IHZhbHVlIFRoZSB2YWx1ZSB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogVW5zdWJzY3JpYmUgYWxsIG9ic2VydmVycyBhbmQgcmVsZWFzZSByZXNvdXJjZXMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgZGlzcG9zZTogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gbnVsbDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBDcmVhdGVzIGEgc3ViamVjdCBmcm9tIHRoZSBzcGVjaWZpZWQgb2JzZXJ2ZXIgYW5kIG9ic2VydmFibGUuXHJcbiAgICAgICAgICogQHBhcmFtIHtPYnNlcnZlcn0gb2JzZXJ2ZXIgVGhlIG9ic2VydmVyIHVzZWQgdG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sbCh0aGlzKTtcclxuICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzLnB1c2gob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG5ldyBJbm5lclN1YnNjcmlwdGlvbih0aGlzLCBvYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHZhciBleCA9IHRoaXMuZXhjZXB0aW9uLFxyXG4gICAgICAgICAgICAgICAgaHYgPSB0aGlzLmhhc1ZhbHVlLFxyXG4gICAgICAgICAgICAgICAgdiA9IHRoaXMudmFsdWU7XHJcblxyXG4gICAgICAgICAgICBpZiAoZXgpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICB9IGVsc2UgaWYgKGh2KSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodik7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGluaGVyaXRzKEFzeW5jU3ViamVjdCwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQ3JlYXRlcyBhIHN1YmplY3QgdGhhdCBjYW4gb25seSByZWNlaXZlIG9uZSB2YWx1ZSBhbmQgdGhhdCB2YWx1ZSBpcyBjYWNoZWQgZm9yIGFsbCBmdXR1cmUgb2JzZXJ2YXRpb25zLlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqLyBcclxuICAgICAgICBmdW5jdGlvbiBBc3luY1N1YmplY3QoKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcblxyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy52YWx1ZSA9IG51bGw7XHJcbiAgICAgICAgICAgIHRoaXMuaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBudWxsO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgYWRkUHJvcGVydGllcyhBc3luY1N1YmplY3QucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKiBAcmV0dXJucyB7Qm9vbGVhbn0gSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICBcclxuICAgICAgICAgICAgaGFzT2JzZXJ2ZXJzOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5vYnNlcnZlcnMubGVuZ3RoID4gMDtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZSwgYWxzbyBjYXVzaW5nIHRoZSBsYXN0IHJlY2VpdmVkIHZhbHVlIHRvIGJlIHNlbnQgb3V0IChpZiBhbnkpLlxyXG4gICAgICAgICAgICAgKi8gXHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbywgaSwgbGVuO1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKSxcclxuICAgICAgICAgICAgICAgICAgICAgICAgdiA9IHRoaXMudmFsdWUsXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGh2ID0gdGhpcy5oYXNWYWx1ZTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGh2KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvID0gb3NbaV07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvLm9uTmV4dCh2KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG8ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBleGNlcHRpb24uXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IGVycm9yIFRoZSBleGNlcHRpb24gdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBleGNlcHRpb247XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogU2VuZHMgYSB2YWx1ZSB0byB0aGUgc3ViamVjdC4gVGhlIGxhc3QgdmFsdWUgcmVjZWl2ZWQgYmVmb3JlIHN1Y2Nlc3NmdWwgdGVybWluYXRpb24gd2lsbCBiZSBzZW50IHRvIGFsbCBzdWJzY3JpYmVkIGFuZCBmdXR1cmUgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSB2YWx1ZSBUaGUgdmFsdWUgdG8gc3RvcmUgaW4gdGhlIHN1YmplY3QuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnZhbHVlID0gdmFsdWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5oYXNWYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBVbnN1YnNjcmliZSBhbGwgb2JzZXJ2ZXJzIGFuZCByZWxlYXNlIHJlc291cmNlcy5cclxuICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIGRpc3Bvc2U6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmV4Y2VwdGlvbiA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnZhbHVlID0gbnVsbDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG5cclxuICAgICAgICByZXR1cm4gQXN5bmNTdWJqZWN0O1xyXG4gICAgfShPYnNlcnZhYmxlKSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgQW5vbnltb3VzU3ViamVjdCA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcbiAgICAgICAgaW5oZXJpdHMoQW5vbnltb3VzU3ViamVjdCwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc3Vic2NyaWJlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLm9ic2VydmFibGUuc3Vic2NyaWJlKG9ic2VydmVyKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gQW5vbnltb3VzU3ViamVjdChvYnNlcnZlciwgb2JzZXJ2YWJsZSkge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmVyID0gb2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2YWJsZSA9IG9ic2VydmFibGU7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKEFub255bW91c1N1YmplY3QucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgICAgICogQG1lbWJlck9mIEFub255bW91c1N1YmplY3QjXHJcbiAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAgICAgKiBAbWVtYmVyT2YgQW5vbnltb3VzU3ViamVjdCNcclxuICAgICAgICAgICAgKi8gICAgICAgICAgICBcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAgICAgKiBAbWVtYmVyT2YgQW5vbnltb3VzU3ViamVjdCNcclxuICAgICAgICAgICAgKi8gICAgICAgICAgICBcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG5cclxuICAgICAgICByZXR1cm4gQW5vbnltb3VzU3ViamVjdDtcclxuICAgIH0oT2JzZXJ2YWJsZSkpO1xyXG5cclxuICAgIGlmICh0eXBlb2YgZGVmaW5lID09ICdmdW5jdGlvbicgJiYgdHlwZW9mIGRlZmluZS5hbWQgPT0gJ29iamVjdCcgJiYgZGVmaW5lLmFtZCkge1xyXG4gICAgICAgIHJvb3QuUnggPSBSeDtcclxuXHJcbiAgICAgICAgZGVmaW5lKGZ1bmN0aW9uKCkge1xyXG4gICAgICAgICAgICByZXR1cm4gUng7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9IGVsc2UgaWYgKGZyZWVFeHBvcnRzICYmIGZyZWVNb2R1bGUpIHtcclxuICAgICAgICAvLyBpbiBOb2RlLmpzIG9yIFJpbm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VhdGUsXHJcbiAgICAgICAgQ29tcG9zaXRlRGlzcG9zYWJsZSA9IFJ4LkNvbXBvc2l0ZURpc3Bvc2FibGUsXHJcbiAgICAgICAgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUgPSBSeC5TaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSxcclxuICAgICAgICBzbGljZSA9IEFycmF5LnByb3RvdHlwZS5zbGljZSxcclxuICAgICAgICBpbmhlcml0cyA9IFJ4LmludGVybmFscy5pbmhlcml0cyxcclxuICAgICAgICBkZWZhdWx0Q29tcGFyZXIgPSBSeC5pbnRlcm5hbHMuaXNFcXVhbDtcclxuXHJcbiAgICBmdW5jdGlvbiBhcmdzT3JBcnJheShhcmdzLCBpZHgpIHtcclxuICAgICAgICByZXR1cm4gYXJncy5sZW5ndGggPT09IDEgJiYgQXJyYXkuaXNBcnJheShhcmdzW2lkeF0pID9cclxuICAgICAgICAgICAgYXJnc1tpZHhdIDpcclxuICAgICAgICAgICAgc2xpY2UuY2FsbChhcmdzKTtcclxuICAgIH1cclxuXHJcbiAgICAvKiogXHJcbiAgICAgKiBAcHJpdmF0ZSBcclxuICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICovXHJcbiAgICBmdW5jdGlvbiBPbk5leHRQcmVkaWNhdGUocHJlZGljYXRlKSB7XHJcbiAgICAgICAgdGhpcy5wcmVkaWNhdGUgPSBwcmVkaWNhdGU7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKiBcclxuICAgICAqIEBwcml2YXRlIFxyXG4gICAgICogQG1lbWJlck9mIE9uTmV4dFByZWRpY2F0ZSNcclxuICAgICAqLyAgICBcclxuICAgIE9uTmV4dFByZWRpY2F0ZS5wcm90b3R5cGUuZXF1YWxzID0gZnVuY3Rpb24gKG90aGVyKSB7XHJcbiAgICAgICAgaWYgKG90aGVyID09PSB0aGlzKSB7IHJldHVybiB0cnVlOyB9XHJcbiAgICAgICAgaWYgKG90aGVyID09IG51bGwpIHsgcm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ICAgICAgdGhpcy5zdWJzY3JpcHRpb25zID0gW107XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSB0aGlzLm1lc3NhZ2VzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBtZXNzYWdlID0gdGhpcy5tZXNzYWdlc1tpXTtcclxuICAgICAgICAgICAgICAgIG5vdGlmaWNhdGlvbiA9IG1lc3NhZ2UudmFsdWU7XHJcbiAgICAgICAgICAgICAgICAoZnVuY3Rpb24gKGlubmVyTm90aWZpY2F0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc2NoZWR1bGVyLnNjaGVkdWxlQWJzb2x1dGVXaXRoU3RhdGUobnVsbCwgbWVzc2FnZS50aW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBvYnMgPSBvYnNlcnZhYmxlLm9ic2VydmVycy5zbGljZSgwKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGogPSAwLCBqTGVuID0gb2JzLmxlbmd0aDsgaiA8IGpMZW47IGorKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJOb3RpZmljYXRpb24uYWNjZXB0KG9ic1tqXSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgICAgIH0pKG5vdGlmaWNhdGlvbik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHJldHVybiBIb3RPYnNlcnZhYmxlO1xyXG4gICAgfSkoT2JzZXJ2YWJsZSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAg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2FyZ3VtZW50MSxfX2FyZ3VtZW50MixfX2FyZ3VtZW50MyxfX2ZpbGVuYW1lLF9fZGlybmFtZSl7XG52YXIgUng7XG5cblJ4ID0gcmVxdWlyZSgncngnKTtcblxubW9kdWxlLmV4cG9ydHMgPSB7XG4gIFwibWFwXCI6IHtcbiAgICBcImxhYmVsXCI6IFwibWFwKHggPT4gMTAgKiB4KVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDEwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDIwLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDUwLFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0ubWFwKGZ1bmN0aW9uKHgpIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICBjb250ZW50OiB4LmNvbnRlbnQgKiAxMCxcbiAgICAgICAgICB0aW1lOiB4LnRpbWUsXG4gICAgICAgICAgaWQ6IHguaWRcbiAgICAgICAgfTtcbiAgICAgIH0pO1xuICAgIH1cbiAgfSxcbiAgXCJmaWx0ZXJcIjoge1xuICAgIFwibGFiZWxcIjogXCJmaWx0ZXIoeCA9PiB4ID4gMTApXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogNSxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxNSxcbiAgICAgICAgICBkOiAzMFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMjUsXG4gICAgICAgICAgZDogMjJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDM1LFxuICAgICAgICAgIGQ6IDVcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQ1LFxuICAgICAgICAgIGQ6IDYwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA1NSxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLmZpbHRlcihmdW5jdGlvbih4KSB7XG4gICAgICAgIHJldHVybiB4LmNvbnRlbnQgPiAxMDtcbiAgICAgIH0pO1xuICAgIH1cbiAgfSxcbiAgXCJzY2FuXCI6IHtcbiAgICBcImxhYmVsXCI6IFwic2NhbigoeCwgeSkgPT4geCArIHkpXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogNSxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxNSxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzNSxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLnNjYW4oZnVuY3Rpb24oeCwgeSkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgIGNvbnRlbnQ6IHguY29udGVudCArIHkuY29udGVudCxcbiAgICAgICAgICB0aW1lOiB4LnRpbWUsXG4gICAgICAgICAgaWQ6IHguaWQgKyB5LmlkXG4gICAgICAgIH07XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiYWdncmVnYXRlXCI6IHtcbiAgICBcImxhYmVsXCI6IFwiYWdncmVnYXRlKCh4LCB5KSA9PiB4ICsgeSlcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDM1LFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDY1LFxuICAgICAgICAgIGQ6IDVcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uYWdncmVnYXRlKGZ1bmN0aW9uKHgsIHkpIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICBjb250ZW50OiB4LmNvbnRlbnQgKyB5LmNvbnRlbnQsXG4gICAgICAgICAgdGltZTogeC50aW1lLFxuICAgICAgICAgIGlkOiB4LmlkICsgeS5pZFxuICAgICAgICB9O1xuICAgICAgfSk7XG4gICAgfVxuICB9LFxuICBcImF2ZXJhZ2VcIjoge1xuICAgIFwibGFiZWxcIjogXCJhdmVyYWdlXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogNSxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxNSxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA1MCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLmF2ZXJhZ2UoZnVuY3Rpb24oeCkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50O1xuICAgICAgfSk7XG4gICAgfVxuICB9LFxuICBcIm1pblwiOiB7XG4gICAgXCJsYWJlbFwiOiBcIm1pblwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDUsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTUsXG4gICAgICAgICAgZDogMzBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IDIyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzNSxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0NSxcbiAgICAgICAgICBkOiA2MFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cykge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS5taW4oZnVuY3Rpb24oeCwgeSkge1xuICAgICAgICBpZiAoeC5jb250ZW50ID4geS5jb250ZW50KSB7XG4gICAgICAgICAgcmV0dXJuIDE7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHguY29udGVudCA8IHkuY29udGVudCkge1xuICAgICAgICAgIHJldHVybiAtMTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gMDtcbiAgICAgIH0pO1xuICAgIH1cbiAgfSxcbiAgXCJtYXhcIjoge1xuICAgIFwibGFiZWxcIjogXCJtYXhcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDMwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiAyMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzUsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDUsXG4gICAgICAgICAgZDogNjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDU1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0ubWF4KGZ1bmN0aW9uKHgsIHkpIHtcbiAgICAgICAgaWYgKHguY29udGVudCA+IHkuY29udGVudCkge1xuICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICB9XG4gICAgICAgIGlmICh4LmNvbnRlbnQgPCB5LmNvbnRlbnQpIHtcbiAgICAgICAgICByZXR1cm4gLTE7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIDA7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiY291bnRcIjoge1xuICAgIFwibGFiZWxcIjogXCJjb3VudCh4ID0+IHggPiAxMClcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDMwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiAyMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzUsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDUsXG4gICAgICAgICAgZDogNjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDU1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uY291bnQoZnVuY3Rpb24oeCkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50ID4gMTA7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiY29udGFpbnNcIjoge1xuICAgIFwibGFiZWxcIjogXCJjb250YWlucygyMilcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDMwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiAyMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzUsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDUsXG4gICAgICAgICAgZDogNjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDU1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uY29udGFpbnMoe1xuICAgICAgICBjb250ZW50OiAyMlxuICAgICAgfSwgZnVuY3Rpb24oeCwgeSkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50ID09PSB5LmNvbnRlbnQ7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiYWxsXCI6IHtcbiAgICBcImxhYmVsXCI6IFwiYWxsKHggPT4geCA8IDEwKVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTUsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMjUsXG4gICAgICAgICAgZDogM1xuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzUsXG4gICAgICAgICAgZDogNFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNjUsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cykge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS5hbGwoZnVuY3Rpb24oeCkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50IDwgMTA7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiYW1iXCI6IHtcbiAgICBcImxhYmVsXCI6IFwiYW1iXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMTAsXG4gICAgICAgICAgZDogMjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDIwLFxuICAgICAgICAgIGQ6IDQwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiA2MFxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfVxuICAgICAgXSwgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMjAsXG4gICAgICAgICAgZDogMFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzIsXG4gICAgICAgICAgZDogMFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDQsXG4gICAgICAgICAgZDogMFxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cykge1xuICAgICAgcmV0dXJuIFJ4Lk9ic2VydmFibGUuYW1iKGlucHV0cyk7XG4gICAgfVxuICB9LFxuICBcImNvbmNhdFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImNvbmNhdFwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAxMyxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gUnguT2JzZXJ2YWJsZS5jb25jYXQoaW5wdXRzKTtcbiAgICB9XG4gIH0sXG4gIFwibWVyZ2VcIjoge1xuICAgIFwibGFiZWxcIjogXCJtZXJnZVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDAsXG4gICAgICAgICAgZDogMjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDQwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiA2MFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDUsXG4gICAgICAgICAgZDogODBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDYwLFxuICAgICAgICAgIGQ6IDEwMFxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAzNyxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2OCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gUnguT2JzZXJ2YWJsZS5tZXJnZShpbnB1dHMpO1xuICAgIH1cbiAgfSxcbiAgXCJkZWxheVwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImRlbGF5XCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzLCBzY2hlZHVsZXIpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uZGVsYXkoMjAsIHNjaGVkdWxlcik7XG4gICAgfVxuICB9LFxuICBcInRocm90dGxlXCI6IHtcbiAgICBcImxhYmVsXCI6IFwidGhyb3R0bGVcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI2LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDM0LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQwLFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQ1LFxuICAgICAgICAgIGQ6IDVcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDkwLFxuICAgICAgICAgIGQ6IDZcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMsIHNjaGVkdWxlcikge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS50aHJvdHRsZSgyMCwgc2NoZWR1bGVyKTtcbiAgICB9XG4gIH0sXG4gIFwiY29tYmluZUxhdGVzdFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImNvbWJpbmVMYXRlc3RcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDIwLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDY1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDc1LFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDkyLFxuICAgICAgICAgIGQ6IDVcbiAgICAgICAgfVxuICAgICAgXSwgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMTAsXG4gICAgICAgICAgZDogXCJBXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IFwiQlwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA1MCxcbiAgICAgICAgICBkOiBcIkNcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTcsXG4gICAgICAgICAgZDogXCJEXCJcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBSeC5PYnNlcnZhYmxlLmNvbWJpbmVMYXRlc3QoaW5wdXRzWzBdLCBpbnB1dHNbMV0sIGZ1bmN0aW9uKHgsIHkpIHtcbiAgICAgICAgcmV0dXJuIFwiXCIgKyB4LmNvbnRlbnQgKyB5LmNvbnRlbnQ7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiemlwXCI6IHtcbiAgICBcImxhYmVsXCI6IFwiemlwXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3NSxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA5MixcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH1cbiAgICAgIF0sIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDEwLFxuICAgICAgICAgIGQ6IFwiQVwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiBcIkJcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTAsXG4gICAgICAgICAgZDogXCJDXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDU3LFxuICAgICAgICAgIGQ6IFwiRFwiXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gUnguT2JzZXJ2YWJsZS56aXAoaW5wdXRzWzBdLCBpbnB1dHNbMV0sIGZ1bmN0aW9uKHgsIHkpIHtcbiAgICAgICAgcmV0dXJuIFwiXCIgKyB4LmNvbnRlbnQgKyB5LmNvbnRlbnQ7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwic2FtcGxlXCI6IHtcbiAgICBcImxhYmVsXCI6IFwic2FtcGxlXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2MCxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA4MCxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH1cbiAgICAgIF0sIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDEwLFxuICAgICAgICAgIGQ6IFwiQVwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiBcIkJcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzMsXG4gICAgICAgICAgZDogXCJDXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDcwLFxuICAgICAgICAgIGQ6IFwiRFwiXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLnNhbXBsZShpbnB1dHNbMV0pO1xuICAgIH1cbiAgfSxcbiAgXCJzdGFydFdpdGhcIjoge1xuICAgIFwibGFiZWxcIjogXCJzdGFydFdpdGgoMSlcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzLCBzY2hlZHVsZXIpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uc3RhcnRXaXRoKHNjaGVkdWxlciwgMSk7XG4gICAgfVxuICB9LFxuICBcImZpcnN0XCI6IHtcbiAgICBcImxhYmVsXCI6IFwiZmlyc3RcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3NSxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLmZpcnN0KCk7XG4gICAgfVxuICB9LFxuICBcImxhc3RcIjoge1xuICAgIFwibGFiZWxcIjogXCJsYXN0XCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMzAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDAsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNjUsXG4gICAgICAgICAgZDogM1xuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNzUsXG4gICAgICAgICAgZDogNFxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cykge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS5sYXN0KCk7XG4gICAgfVxuICB9LFxuICBcImVsZW1lbnRBdFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImVsZW1lbnRBdCgyKVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDMwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQwLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDY1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDc1LFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMsIHNjaGVkdWxlcikge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS5lbGVtZW50QXQoMik7XG4gICAgfVxuICB9LFxuICBcImZpbmRcIjoge1xuICAgIFwibGFiZWxcIjogXCJmaW5kKHggPT4geCA+IDEwKVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDUsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTUsXG4gICAgICAgICAgZDogMzBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IDIyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzNSxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0NSxcbiAgICAgICAgICBkOiA2MFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cywgc2NoZWR1bGVyKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLmZpbmQoZnVuY3Rpb24oeCkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50ID4gMTA7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwidGFrZVwiOiB7XG4gICAgXCJsYWJlbFwiOiBcInRha2UoMilcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3NSxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzLCBzY2hlZHVsZXIpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0udGFrZSgyLCBzY2hlZHVsZXIpO1xuICAgIH1cbiAgfSxcbiAgXCJza2lwXCI6IHtcbiAgICBcImxhYmVsXCI6IFwic2tpcCgyKVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDMwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQwLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDY1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDc1LFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uc2tpcCgyKTtcbiAgICB9XG4gIH0sXG4gIFwidGFrZVVudGlsXCI6IHtcbiAgICBcImxhYmVsXCI6IFwidGFrZVVudGlsXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyMCxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA1MCxcbiAgICAgICAgICBkOiA2XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2MCxcbiAgICAgICAgICBkOiA3XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3MCxcbiAgICAgICAgICBkOiA4XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA4MCxcbiAgICAgICAgICBkOiA5XG4gICAgICAgIH1cbiAgICAgIF0sIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDQ3LFxuICAgICAgICAgIGQ6IDBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDczLFxuICAgICAgICAgIGQ6IDBcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0udGFrZVVudGlsKGlucHV0c1sxXSk7XG4gICAgfVxuICB9LFxuICBcInNraXBVbnRpbFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcInNraXBVbnRpbFwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTAsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMjAsXG4gICAgICAgICAgZDogM1xuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzAsXG4gICAgICAgICAgZDogNFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDAsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTAsXG4gICAgICAgICAgZDogNlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNjAsXG4gICAgICAgICAgZDogN1xuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNzAsXG4gICAgICAgICAgZDogOFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogODAsXG4gICAgICAgICAgZDogOVxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA0NyxcbiAgICAgICAgICBkOiAwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3MyxcbiAgICAgICAgICBkOiAwXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLnNraXBVbnRpbChpbnB1dHNbMV0pO1xuICAgIH1cbiAgfSxcbiAgXCJkaXN0aW5jdFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImRpc3RpbmN0XCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogNSxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzNSxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2M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cXVpcmUoXCJpcy1vYmplY3RcIilcbnZhciBpc0hvb2sgPSByZXF1aXJlKFwidnRyZWUvaXMtdmhvb2tcIilcblxubW9kdWxlLmV4cG9ydHMgPSBhcHBseVByb3BlcnRpZXNcblxuZnVuY3Rpb24gYXBwbHlQcm9wZXJ0aWVzKG5vZGUsIHByb3BzLCBwcmV2aW91cykge1xuICAgIGZvciAodmFyIHByb3BOYW1lIGluIHByb3BzKSB7XG4gICAgICAgIHZhciBwcm9wVmFsdWUgPSBwcm9wc1twcm9wTmFtZV1cblxuICAgICAgICBpZiAocHJvcFZhbHVlID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIHJlbW92ZVByb3BlcnR5KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUpO1xuICAgICAgICB9IGVsc2UgaWYgKGlzSG9vayhwcm9wVmFsdWUpKSB7XG4gICAgICAgICAgICBwcm9wVmFsdWUuaG9vayhub2RlLFxuICAgICAgICAgICAgICAgIHByb3BOYW1lLFxuICAgICAgICAgICAgICAgIHByZXZpb3VzID8gcHJldmlvdXNbcHJvcE5hbWVdIDogdW5kZWZpbmVkKVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKGlzT2JqZWN0KHByb3BWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICBwYXRjaE9iamVjdChub2RlLCBwcm9wcywgcHJldmlvdXMsIHByb3BOYW1lLCBwcm9wVmFsdWUpO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChwcm9wVmFsdWUgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIG5vZGVbcHJvcE5hbWVdID0gcHJvcFZhbHVlXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbmZ1bmN0aW9uIHJlbW92ZVByb3BlcnR5KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUpIHtcbiAgICBpZiAocHJldmlvdXMpIHtcbiAgICAgICAgdmFyIHByZXZpb3VzVmFsdWUgPSBwcmV2aW91c1twcm9wTmFtZV1cblxuICAgICAgICBpZiAoIWlzSG9vayhwcmV2aW91c1ZhbHVlKSkge1xuICAgICAgICAgICAgaWYgKHByb3BOYW1lID09PSBcImF0dHJpYnV0ZXNcIikge1xuICAgICAgICAgICAgICAgIGZvciAodmFyIGF0dHJOYW1lIGluIHByZXZpb3VzVmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgbm9kZS5yZW1vdmVBdHRyaWJ1dGUoYXR0ck5hbWUpXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmIChwcm9wTmFtZSA9PT0gXCJzdHlsZVwiKSB7XG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaSBpbiBwcmV2aW91c1ZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgIG5vZGUuc3R5bGVbaV0gPSBcIlwiXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgcHJldmlvdXNWYWx1ZSA9PT0gXCJzdHJpbmdcIikge1xuICAgICAgICAgICAgICAgIG5vZGVbcHJvcE5hbWVdID0gXCJcIlxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBub2RlW3Byb3BOYW1lXSA9IG51bGxcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbn1cblxuZnVuY3Rpb24gcGF0Y2hPYmplY3Qobm9kZSwgcHJvcHMsIHByZXZpb3VzLCBwcm9wTmFtZSwgcHJvcFZhbHVlKSB7XG4gICAgdmFyIHByZXZpb3VzVmFsdWUgPSBwcmV2aW91cyA/IHByZXZpb3VzW3Byb3BOYW1lXSA6IHVuZGVmaW5lZFxuXG4gICAgLy8gU2V0IGF0dHJpYnV0ZXNcbiAgICBpZiAocHJvcE5hbWUgPT09IFwiYXR0cmlidXRlc1wiKSB7XG4gICAgICAgIGZvciAodmFyIGF0dHJOYW1lIGluIHByb3BW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DA7IGkgPCB0cmVlLmNoaWxkcmVuLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICAgICAgcm9vdEluZGV4ICs9IDFcblxuICAgICAgICAgICAgICAgIHZhciB2Q2hpbGQgPSB2Q2hpbGRyZW5baV0gfHwgbm9DaGlsZFxuICAgICAgICAgICAgICAgIHZhciBuZXh0SW5kZXggPSByb290SW5kZXggKyAodkNoaWxkLmNvdW50IHx8IDApXG5cbiAgICAgICAgICAgICAgICAvLyBza2lwIHJlY3Vyc2lvbiBkb3duIHRoZSB0cmVlIGlmIHRoZXJlIGFyZSBubyBub2RlcyBkb3duIGhlcmVcbiAgICAgICAgICAgICAgICBpZiAoaW5kZXhJblJhbmdlKGluZGljZXMsIHJvb3RJbmRleCwgbmV4dEluZGV4KSkge1xuICAgICAgICAgICAgICAgICAgICByZWN1cnNlKGNoaWxkTm9kZXNbaV0sIHZDaGlsZCwgaW5kaWNlcywgbm9kZXMsIHJvb3RJbmRleClcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICByb290SW5kZXggPSBuZXh0SW5kZXhcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiBub2Rlc1xufVxuXG4vLyBCaW5hcnkgc2VhcmNoIGZvciBhbiBpbmRleCBpbiB0aGUgaW50ZXJ2YWwgW2xlZnQsIHJpZ2h0XVxuZnVuY3Rpb24gaW5kZXhJblJhbmdlKGluZGljZXMsIGxlZnQsIHJpZ2h0KSB7XG4gICAgaWYgKGluZGljZXMubGVuZ3RoID09PSAwKSB7XG4gICAgICAgIHJldHVybiBmYWxzZVxuICAgIH1cblxuICAgIHZhciBtaW5JbmRleCA9IDBcbiAgICB2YXIgbWF4SW5kZXggPSBpbmRpY2VzLmxlbmd0aCAtIDFcbiAgICB2YXIgY3VycmVudEluZGV4XG4gICAgdmFyIGN1cnJlbnRJdGVtXG5cbiAgICB3aGlsZSAobWluSW5kZXggPD0gbWF4SW5kZXgpIH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tcbiAgICAgICAgdGh1bmtzKGEsIGIsIHBhdGNoLCBpbmRleClcbiAgICB9IGVsc2UgaWYgKGlzVk5vZGUoYikpIHtcbiAgICAgICAgaWYgKGlzVk5vZGUoYSkpIHtcbiAgICAgICAgICAgIGlmIChhLnRhZ05hbWUgPT09IGIudGFnTmFtZSAmJlxuICAgICAgICAgICAgICAgIGEubmFtZXNwYWNlID09PSBiLm5hbWVzcGFjZSAmJlxuICAgICAgICAgICAgICAgIGEua2V5ID09PSBiLmtleSkge1xuICAgICAgICAgICAgICAgIHZhciBwcm9wc1BhdGNoID0gZGlmZlByb3BzKGEucHJvcGVydGllcywgYi5wcm9wZXJ0aWVzLCBiLmhvb2tzKVxuICAgICAgICAgICAgICAgIGlmIChwcm9wc1BhdGNoKSB7XG4gICAgICAgICAgICAgICAgICAgIGFwcGx5ID0gYXBwZW5kUGF0Y2goYXBwbHksXG4gICAgICAgICAgICAgICAgICAgICAgICBuZXcgVlBhdGNoKFZQYXRjaC5QUk9QUywgYSwgcHJvcHNQYXRjaCkpXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBhcHBseSA9IGFwcGVuZFBhdGNoKGFwcGx5LCBuZXcgVlBhdGNoKFZQYXRjaC5WTk9ERSwgYSwgYikpXG4gICAgICAgICAgICAgICAgZGVzdHJveVdpZGdldHMoYSwgcGF0Y2gsIGluZGV4KVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBhcHBseSA9IGRpZmZDaGlsZHJlbihhLCBiLCBwYXRjaCwgYXBwbHksIGluZGV4KVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYXBwbHkgPSBhcHBlbmRQYXRjaChhcHBseSwgbmV3IFZQYXRjaChWUGF0Y2guVk5PREUsIGEsIGIpKVxuICAgICAgICAgICAgZGVzdHJveVdpZGdldHMoYSwgcGF0Y2gsIGluZGV4KVxuICAgICAgICB9XG4gICAgfSBlbHNlIGlmICh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ZmID0gZGlmZiB8fCB7fVxuICAgICAgICAgICAgZGlmZlthS2V5XSA9IGJWYWx1ZVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKGlzT2JqZWN0KGFWYWx1ZSkgJiYgaXNPYmplY3QoYlZhbHVlKSkge1xuICAgICAgICAgICAgICAgIGlmIChnZXRQcm90b3R5cGUoYlZhbHVlKSAhPT0gZ2V0UHJvdG90eXBlKGFWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgICAgICAgICAgZGlmZlthS2V5XSA9IGJWYWx1ZVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBvYmplY3REaWZmID0gZGlmZlByb3BzKGFWYWx1ZSwgYlZhbHVlKVxuICAgICAgICAgICAgICAgICAgICBpZiAob2JqZWN0RGlmZikge1xuICAgICAgICAgICAgICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgICAgICAgICAgICAgIGRpZmZbYUtleV0gPSBvYmplY3REaWZmXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGFWYWx1ZSAhPT0gYlZhbHVlKSB7XG4gICAgICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgICAgICBkaWZmW2FLZXldID0gYlZhbHVlXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBmb3IgKHZhciBiS2V5IGluIGIpIHtcbiAgICAgICAgaWYgKCEoYktleSBpbiBhKSkge1xuICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgIGRpZmZbYktleV0gPSBiW2JLZXldXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gZGlmZlxufVxuXG5mdW5jdGlvbiBnZXRQcm90b3R5cG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IH1cbn1cblxuZnVuY3Rpb24gaGFzUGF0Y2hlcyhwYXRjaCkge1xuICAgIGZvciAodmFyIGluZGV4IGluIHBhdGNoKSB7XG4gICAgICAgIGlmIChpbmRleCAhPT0gXCJhXCIpIHtcbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgcmV0dXJuIGZhbHNlO1xufVxuXG4vLyBFeGVjdXRlIGhvb2tzIHdoZW4gdHdvIG5vZGVzIGFyZSBpZGVudGljYWxcbmZ1bmN0aW9uIGhvb2tzKHZOb2RlLCBwYXRjaCwgaW5kZXgpIHtcbiAgICBpZiAoaXNWTm9kZSh2Tm9kZSkpIHtcbiAgICAgICAgaWYgKHZOb2RlLmhvb2tzKSB7XG4gICAgICAgICAgICBwYXRjaFtpbmRleF0gPSBuZXcgVlBhdGNoKFZQYXRjaC5QUk9QUywgdk5vZGUuaG9va3MsIHZOb2RlLmhvb2tzKVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHZOb2RlLmRlc2NlbmRhbnRIb29rcykge1xuICAgICAgICAgICAgdmFyIGNoaWxkcmVuID0gdk5vZGUuY2hpbGRyZW5cbiAgICAgICAgICAgIHZhciBsZW4gPSBjaGlsZHJlbi5sZW5ndGhcbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHtcbiAgICAgICAgICAgICAgICB2YXIgY2hpbGQgPSBjaGlsZHJlbltpXVxuICAgICAgICAgICAgICAgIGluZGV4ICs9IDFcblxuICAgICAgICAgICAgICAgIGhvb2tzKGNoaWxkLCBwYXRjaCwgaW5kZXgpXG5cbiAgICAgICAgICAgICAgICBpZiAoaXNWTm9kZShjaGlsZCkgJiYgY2hpbGQuY291bnQpIHtcbiAgICAgICAgICAgICAgICAgICAgaW5kZXggKz0gY2hpbGQuY291bnRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbi8vIEx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AgICAgIHZhciBtb3ZlID0gYU1hdGNoW2ldXG4gICAgICAgIGlmIChtb3ZlICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIHNodWZmbGVbaV0gPSBiQ2hpbGRyZW5bbW92ZV1cbiAgICAgICAgICAgIGlmIChtb3ZlICE9PSBtb3ZlSW5kZXgpIHtcbiAgICAgICAgICAgICAgICBtb3Zlc1ttb3ZlXSA9IG1vdmVJbmRleFxuICAgICAgICAgICAgICAgIHJldmVyc2VbbW92ZUluZGV4XSA9IG1vdmVcbiAgICAgICAgICAgICAgICBoYXNNb3ZlcyA9IHRydWVcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG1vdmVJbmRleCsrXG4gICAgICAgIH0gZWxzZSBpZiAoaSBpbiBhTWF0Y2gpIHtcbiAgICAgICAgICAgIHNodWZmbGVbaV0gPSB1bmRlZmluZWRcbiAgICAgICAgICAgIHJlbW92ZXNbaV0gPSBtb3ZlSW5kZXgrK1xuICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB3aGlsZSAoYk1hdGNoW2ZyZWVJbmRleF0gIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIGZyZWVJbmRleCsrXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChmcmVlSW5kZXggPCBsZW4pIHtcbiAgICAgICAgICAgICAgICB2YXIgZnJlZUNoaWxkID0gYkNoaWxkcmVuW2ZyZWVJbmRleF1cbiAgICAgICAgICAgICAgICBpZiAoZnJlZUNoaWxkKSB7XG4gICAgICAgICAgICAgICAgICAgIHNodWZmbGVbaV0gPSBmcmVlQ2hpbGRcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZyZWVJbmRleCAhPT0gbW92ZUluZGV4KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBoYXNNb3ZlcyA9IHRydWVcbiAgICAgICAgICAgICAgICAgICAgICAgIG1vdmVzW2ZyZWVJbmRleF0gPSBtb3ZlSW5kZXhcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldmVyc2VbbW92ZUluZGV4XSA9IGZyZWVJbmRleFxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIG1vdmVJbmRleCsrXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZyZWVJbmRleCsrXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaSsrXG4gICAgfVxuXG4gICAgaWYgKGhhc01vdmVzKSB7XG4gICAgICAgIHNodWZmbGUubW92ZXMgPSBtb3Zlc1xuICAgIH1cblxuICAgIHJldHVybiBzaHVmZmxlXG59XG5cbmZ1bmN0aW9uIGtleUluZGV4KGNoaWxkcmVuKSB7XG4gICAgdmFyIGksIGtleXNcblxuICAgIGZvciAoaSA9IDA7IGkgPCBjaGlsZHJlbi5sZW5ndGg7IGkrKykge1xuICAgICAgICB2YXIgY2hpbGQgPSBjaGlsZHJlbltpXVxuXG4gICAgICAgIGlmIChjaGlsZC5rZXkgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAga2V5cyA9IGtleXMgfHwge31cbiAgICAgICAgICAgIGtleXNbY2hpbGQua2V5XSA9IGlcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiBrZXlzXG59XG5cbmZ1bmN0aW9uIGFwcGVuZFBhdGNoKGFwcGx5LCBwYXRjaCkge1xuICAgIGlmIChhcHBseSkge1xuICAgICAgICBpZiAoaXNBcnJheShhcHBseSkpIHtcbiAgICAgICAgICAgIGFwcGx5LnB1c2gocGF0Y2gpXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBhcHBseSA9IFthcHBseSwgcGF0Y2hdXG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gYXBwbHlcbiAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gcGF0Y2hcbiAgICB9XG59XG5cbn0pLmNhbGwodGhpcyxyZXF1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dGlvbihsaW5lKSB7XG4gICAgICAgICAgICByZXR1cm4gJyAgJyArIGxpbmU7XG4gICAgICAgICAgfSkuam9pbignXFxuJykuc3Vic3RyKDIpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHN0ciA9ICdcXG4nICsgc3RyLnNwbGl0KCdcXG4nKS5tYXAoZnVuY3Rpb24obGluZSkge1xuICAgICAgICAgICAgcmV0dXJuICcgICAnICsgbGluZTtcbiAgICAgICAgICB9KS5qb2luKCdcXG4nKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH0gZWxzZSB7XG4gICAgICBzdHIgPSBjdHguc3R5bGl6ZSgnW0NpcmN1bGFyXScsICdzcGVjaWFsJyk7XG4gICAgfVxuICB9XG4gIGlmIChpc1VuZGVmaW5lZChuYW1lKSkge1xuICAgIGlmIChhcnJheSAmJiBrZXkubWF0Y2goL15cXGQrJC8pKSB7XG4gICAgICByZXR1cm4gc3RyO1xuICAgIH1cbiAgICBuYW1lID0gSlNPTi5zdHJpbmdpZnkoJycgKyBrZXkpO1xuICAgIGlmIChuYW1lLm1hdGNoKC9eXCIoW2EtekEtWl9dW2EtekEtWl8wLTldKilcIiQvKSkge1xuICAgICAgbmFtZSA9IG5hbWUuc3Vic3RyKDEsIG5hbWUubGVuZ3RoIC0gMik7XG4gICAgICBuYW1lID0gY3R4LnN0eWxpemUobmFtZSwgJ25hbWUnKTtcbiAgICB9IGVsc2Uge1xuICAgICAgbmFtZSA9IG5hbWUucmVwbGFjZSgvJy9nLCBcIlxcXFwnXCIpXG4gICAgICAgICAgICAgICAgIC5yZXBsYWNlKC9cXFxcXCIvZywgJ1wiJylcbiAgICAgICAgICAgICAgICAgLnJlcGxhY2UoLyheXCJ8XCIkKS9nLCBcIidcIik7XG4gICAgICBuYW1lID0gY3R4LnN0eWxpemUobmFtZSwgJ3N0cmluZycpO1xuICAgIH1cbiAgfVxuXG4gIHJldHVybiBuYW1lICsgJzogJyArIHN0cjtcbn1cblxuXG5mdW5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G4gICAgICAgICAgICBjb250aW51ZVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKEJMQUNLTElTVEVEX0tFWVNba2V5XSkge1xuICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgfVxuXG4gICAgICAgIHZhciB2YWx1ZSA9IHByb3BlcnRpZXNba2V5XVxuICAgICAgICBpZiAodHlwZW9mIHZhbHVlICE9PSBcInN0cmluZ1wiICYmXG4gICAgICAgICAgICB0eXBlb2YgdmFsdWUgIT09IFwibnVtYmVyXCIgJiZcbiAgICAgICAgICAgIHR5cGVvZiB2YWx1ZSAhPT0gXCJib29sZWFuXCJcbiAgICAgICAgKSB7XG4gICAgICAgICAgICBjb250aW51ZVxuICAgICAgICB9XG5cbiAgICAgICAgcHJvcGVydGllc1trZXldID0gYXR0cmlidXRlSG9vayh2YWx1ZSlcbiAgICB9XG5cbiAgICByZXR1cm4gaCh0YWdOYW1lLCBwcm9wZXJ0aWVzLCBjaGlsZHJlbilcbn1cblxuZnVuY3Rpb24gaXNDaGlsZHJlbih4KSB7XG4gICAgcmV0dXJuIHR5cGVvZiB4ID09PSBcInN0cmluZ1wiIHx8IEFycmF5LmlzQXJyYXkoeClcbn1cblxufSkuY2FsbCh0aGlzLHJlcXVpcmUoXCJvTWZwQW5cIiksdHlwZW9mIHNlbGYgIT09IFwidW5kZWZpbmVkXCIgPyBzZWxmIDogdHlwZW9mIHdpbmRvdyAhPT0gXCJ1bmRlZmluZWRcIiA/IHdpbmRvdyA6IHt9LHJlcXVpcmUoXCJidWZmZXJcIikuQnVmZmVyLGFyZ3VtZW50c1szXSxhcmd1bWVudHNbNF0sYXJndW1lbnRzWzVdLGFyZ3VtZW50c1s2XSxcIi8uLi8uLi9ub2RlX21vZHVsZXMvdmlydHVhbC1oeXBlcnNjcmlwdC9zdmcuanNcIixcIi8uLi8uLi9ub2RlX21vZHVsZXMvdmlydHVhbC1oeXBlcnNjcmlwdFwiKSJdfQ== +//# sourceMappingURL=data:application/json;base64,eyJ2Z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ociA9IGwpXG4gICAgICBlbHNlIGlmICgnb2JqZWN0JyA9PT0gdHlwZW9mIGwpIHtcbiAgICAgICAgZm9yICh2YXIgayBpbiBsKSB7XG4gICAgICAgICAgaWYoJ2Z1bmN0aW9uJyA9PT0gdHlwZW9mIGxba10pIHtcbiAgICAgICAgICAgIGlmKC9eb25cXHcrLy50ZXN0KGspKSB7XG4gICAgICAgICAgICAgIGlmIChlLmFkZEV2ZW50TGlzdGVuZXIpe1xuICAgICAgICAgICAgICAgIGUuYWRkRXZlbnRMaXN0ZW5lcihrLnN1YnN0cmluZygyKSwgbFtrXSwgZmFsc2UpXG4gICAgICAgICAgICAgICAgY2xlYW51cEZ1bmNzLnB1c2goZnVuY3Rpb24oKXtcbiAgICAgICAgICAgICAgICAgIGUucmVtb3ZlRXZlbnRMaXN0ZW5lcihrLnN1YnN0cmluZygyKSwgbFtrXSwgZmFsc2UpXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfWVsc2V7XG4gICAgICAgICAgICAgICAgZS5hdHRhY2hFdmVudChrLCBsW2tdKVxuICAgICAgICAgICAgICAgIGNsZWFudXBGdW5jcy5wdXNoKGZ1bmN0aW9uKCl7XG4gICAgICAgICAgICAgICAgICBlLmRldGFjaEV2ZW50KGssIGxba10pXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgLy8gb2JzZXJ2YWJsZVxuICAgICAgICAgICAgICBlW2tdID0gbFtrXSgpXG4gICAgICAgICAgICAgIGNsZWFudXBGdW5jcy5wdXNoKGxba10oZnVuY3Rpb24gKHYpIHtcbiAgICAgICAgICAgICAgICBlW2tdID0gdlxuICAgICAgICAgICAgICB9KSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSBpZihrID09PSAnc3R5bGUnKSB7XG4gICAgICAgICAgICBpZignc3RyaW5nJyA9PT0gdHlwZW9mIGxba10pIHtcbiAgICAgICAgICAgICAgZS5zdHlsZS5jc3NUZXh0ID0gbFtrXVxuICAgICAgICAgICAgfWVsc2V7XG4gICAgICAgICAgICAgIGZvciAodmFyIHMgaW4gbFtrXSkgKGZ1bmN0aW9uKHMsIHYpIHtcbiAgICAgICAgICAgICAgICBpZignZnVuY3Rpb24nID09PSB0eXBlb2Ygdikge1xuICAgICAgICAgICAgICAgICAgLy8gb2JzZXJ2YWJsZVxuICAgICAgICAgICAgICAgICAgZS5zdHlsZS5zZXRQcm9wZXJ0eShzLCB2KCkpXG4gICAgICAgICAgICAgICAgICBjbGVhbnVwRnVuY3MucHVzaCh2KGZ1bmN0aW9uICh2YWwpIHtcbiAgICAgICAgICAgICAgICAgICAgZS5zdHlsZS5zZXRQcm9wZXJ0eShzLCB2YWwpXG4gICAgICAgICAgICAgICAgICB9KSlcbiAgICAgICAgICAgICAgICB9IGVsc2VcbiAgICAgICAgICAgICAgICAgIGUuc3R5bGUuc2V0UHJvcGVydHkocywgbFtrXVtzXSlcbiAgICAgICAgICAgICAgfSkocywgbFtrXVtzXSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2UgaWYgKGsuc3Vic3RyKDAsIDUpID09PSBcImRhdGEtXCIpIHtcbiAgICAgICAgICAgIERhdGFTZXQoZSlbay5zdWJzdHIoNSldID0gbFtrXVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBlW2tdID0gbFtrXVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmICgnZnVuY3Rpb24nID09PSB0eXBlb2YgbCkge1xuICAgICAgICAvL2Fzc3VtZSBpdCdzIGFuIG9ic2VydmFibGUhXG4gICAgICAgIHZhciB2ID0gbCgpXG4gICAgICAgIGUuYXBwZW5kQ2hpbGQociA9IGlzTm9kZSh2KSA/IHYgOiBkb2N1bWVudC5jcmVhdGVUZXh0Tm9kZSh2KSlcblxuICAgICAgICBjbGVhbnVwRnVuY3MucH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2V0VG9rZW5zKClcbiAgICAgICAgICAgICwgaW5kZXggPSBpbmRleG9mKGxpc3QsIHRva2VuKVxuXG4gICAgICAgIGlmIChpbmRleCA9PT0gLTEpIHtcbiAgICAgICAgICAgIHJldHVyblxuICAgICAgICB9XG5cbiAgICAgICAgbGlzdC5zcGxpY2UoaW5kZXgsIDEpXG4gICAgICAgIHNldFRva2VucyhsaXN0KVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIGNvbnRhaW5zKHRva2VuKSB7XG4gICAgICAgIHJldHVybiBpbmRleG9mKGdldFRva2VucygpLCB0b2tlbikgPiAtMVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIHRvZ2dsZSh0b2tlbikge1xuICAgICAgICBpZiAoY29udGFpbnModG9rZW4pKSB7XG4gICAgICAgICAgICByZW1vdmUodG9rZW4pXG4gICAgICAgICAgICByZXR1cm4gZmFsc2VcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGFkZCh0b2tlbilcbiAgICAgICAgICAgIHJldHVybiB0cnVlXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBmdW5jdGlvbiAkdG9TdHJpbmcoKSB7XG4gICAgICAgIHJldHVybiBlbGVtLmNsYXNzTmFtZVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIGl0ZW0oaW5kZXgpIHtcbiAgICAgICAgdmFyIHRva2VucyA9IGdldFRva2VucygpXG4gICAgICAgIHJldHVybiB0b2tlbnNbaW5kZXhdIHx8IG51bGxcbiAgICB9XG5cbiAgICBmdW5jdGlvbiBnZXRUb2tlbnMoKSB7XG4gICAgICAgIHZhciBjbGFzc05hbWUgPSBlbGVtLmNsYXNzTmFtZVxuXG4gICAgICAgIHJldHVybiBmaWx0ZXIoY2xhc3NOYW1lLnNwbGl0KFwiIFwiKSwgaXNUcnV0aHkpXG4gICAgfVxuXG4gICAgZnVuY3Rpb24gc2V0VG9rZW5zKGxpc3QpIHtcbiAgICAgICAgdmFyIGxlbmd0aCA9IGxpc3Q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gaW5kZXggLSAxID4+IDE7XHJcbiAgICAgICAgaWYgKHBhcmVudCA8IDAgfHwgcGFyZW50ID09PSBpbmRleCkge1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmICh0aGlzLmlzSGlnaGVyUHJpb3JpdHkoaW5kZXgsIHBhcmVudCkpIHtcclxuICAgICAgICAgICAgdmFyIHRlbXAgPSB0aGlzLml0ZW1zW2luZGV4XTtcclxuICAgICAgICAgICAgdGhpcy5pdGVtc1tpbmRleF0gPSB0aGlzLml0ZW1zW3BhcmVudF07XHJcbiAgICAgICAgICAgIHRoaXMuaXRlbXNbcGFyZW50XSA9IHRlbXA7XHJcbiAgICAgICAgICAgIHRoaXMucGVyY29sYXRlKHBhcmVudCk7XHJcbiAgICAgICAgfVxyXG4gICAgfTtcclxuXHJcbiAgICBwcmlvcml0eVByb3RvLmhlYXBpZnkgPSBmdW5jdGlvbiAoaW5kZXgpIHtcclxuICAgICAgICBpZiAoaW5kZXggPT09IHVuZGVmaW5lZCkge1xyXG4gICAgICAgICAgICBpbmRleCA9IDA7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChpbmRleCA+PSB0aGlzLmxlbmd0aCB8fCBpbmRleCA8IDApIHtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgIH1cclxuICAgICAgICB2YXIgbGVmdCA9IDIgKiBpbmRleCArIDEsXHJcbiAgICAgICAgICAgIHJpZ2h0ID0gMiAqIGluZGV4ICsgMixcclxuICAgICAgICAgICAgZmlyc3QgPSBpbmRleDtcclxuICAgICAgICBpZiAobGVmdCA8IHRoaXMubGVuZ3RoICYmIHRoaXMuaXNIaWdoZXJQcmlvcml0eShsZWZ0LCBmaXJzdCkpIHtcclxuICAgICAgICAgICAgZmlyc3QgPSBsZWZ0O1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAocmlnaHQgPCB0aGlzLmxlbmd0aCAmJiB0aGlzLmlzSGlnaGVy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AoIXRoaXMuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICB2YXIgaWR4ID0gdGhpcy5kaXNwb3NhYmxlcy5pbmRleE9mKGl0ZW0pO1xyXG4gICAgICAgICAgICBpZiAoaWR4ICE9PSAtMSkge1xyXG4gICAgICAgICAgICAgICAgc2hvdWxkRGlzcG9zZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2FibGVzLnNwbGljZShpZHgsIDEpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5sZW5ndGgtLTtcclxuICAgICAgICAgICAgICAgIGl0ZW0uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gc2hvdWxkRGlzcG9zZTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgRGlzcG9zZXMgYWxsIGRpc3Bvc2FibGVzIGluIHRoZSBncm91cCBhbmQgcmVtb3ZlcyB0aGVtIGZyb20gdGhlIGdyb3VwLiAgXHJcbiAgICAgKi9cclxuICAgIENvbXBvc2l0ZURpc3Bvc2FibGVQcm90b3R5cGUuZGlzcG9zZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICBpZiAoIXRoaXMuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICB2YXIgY3VycmVudERpc3Bvc2FibGVzID0gdGhpcy5kaXNwb3NhYmxlcy5zbGljZSgwKTtcclxuICAgICAgICAgICAgdGhpcy5kaXNwb3NhYmxlcyA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLmxlbmd0aCA9IDA7XHJcblxyXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gY3VycmVudERpc3Bvc2FibGVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBjdXJyZW50RGlzc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aXNTaW5nbGUpIHtcclxuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignRGlzcG9zYWJsZSBoYXMgYWxyZWFkeSBiZWVuIGFzc2lnbmVkJyk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHZhciBzaG91bGREaXNwb3NlID0gdGhpcy5pc0Rpc3Bvc2VkLCBvbGQ7XHJcbiAgICAgICAgICAgIGlmICghc2hvdWxkRGlzcG9zZSkge1xyXG4gICAgICAgICAgICAgICAgb2xkID0gdGhpcy5jdXJyZW50O1xyXG4gICAgICAgICAgICAgICAgdGhpcy5jdXJyZW50ID0gdmFsdWU7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgaWYgKG9sZCkge1xyXG4gICAgICAgICAgICAgICAgb2xkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpZiAoc2hvdWxkRGlzcG9zZSAmJiB2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFsdWUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqIFxyXG4gICAgICAgICAqIERpc3Bvc2VzIHRoZSB1bmRlcmx5aW5nIGRpc3Bvc2FibGUgYXMgd2VsbCBhcyBhbGwgZnV0dXJlIHJlcGxhY2VtZW50cy5cclxuICAgICAgICAgKi9cclxuICAgICAgICBib29sZWFuRGlzcG9zYWJsZVByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgb2xkO1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNEaXNwb3NlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIG9sZCA9IHRoaXMuY3VycmVudDtcclxuICAgICAgICAgICAgICAgIHRoaXMuY3VycmVudCA9IG51bGw7XH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2NoZWR1bGVBYnNvbHV0ZTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIGludm9rZVJlY0ltbWVkaWF0ZShzY2hlZHVsZXIsIHBhaXIpIHtcclxuICAgICAgICAgICAgdmFyIHN0YXRlID0gcGFpci5maXJzdCwgYWN0aW9uID0gcGFpci5zZWNvbmQsIGdyb3VwID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uID0gZnVuY3Rpb24gKHN0YXRlMSkge1xyXG4gICAgICAgICAgICAgICAgYWN0aW9uKHN0YXRlMSwgZnVuY3Rpb24gKHN0YXRlMikge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBpc0FkZGVkID0gZmFsc2UsIGlzRG9uZSA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgICAgIGQgPSBzY2hlZHVsZXIuc2NoZWR1bGVXaXRoU3RhdGUoc3RhdGUyLCBmdW5jdGlvbiAoc2NoZWR1bGVyMSwgc3RhdGUzKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpc0FkZGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBncm91cC5yZW1vdmUoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc0RvbmUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlY3Vyc2l2ZUFjdGlvbihzdGF0ZTMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghaXNEb25lKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLmFkZChkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaXNBZGRlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIHJlY3Vyc2l2ZUFjdGlvbihzdGF0ZSk7XHJcbiAgICAgICAgICAgIHJldHVybiBncm91cDtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIGludm9rZVJlY0RhdGUoc2NoZWR1bGVyLCBwYWlyLCBtZXRob2QpIHtcclxuICAgICAgICAgICAgdmFyIHN0YXRlID0gcGFpci5maXJzdCwgYWN0aW9uID0gcGFpci5zZWNvbmQsIGdyb3VwID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uID0gZnVuY3Rpb24gKHN0YXRlMSkge1xyXG4gICAgICAgICAgICAgICAgYWN0aW9uKHN0YXRlMSwgZnVuY3Rpb24gKHN0YXRlMiwgZHVlVGltZTEpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgaXNBZGRlZCA9IGZhbHNlLCBpc0RvbmUgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgICAgICBkID0gc2NoZWR1bGVyW21ldGhvZF0uY2FsbChzY2hlZHVsZXIsIHN0YXRlMiwgZHVlVGltZTEsIGZ1bmN0aW9uIChzY2hlZHVsZXIxLCBzdGF0ZTMpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzQWRkZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLnJlbW92ZShkKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzRG9uZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uKHN0YXRlMyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFpc0RvbmUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXAuYWRkKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpc0FkZGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgcmVjdXJzaXZlQWN0aW9uKHN0YXRlKTtcclxuICAgICAgICAgICAgcmV0dXJuIGdyb3VwO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gaW52b2tlQWN0aW9uKHNjaGVkdWxlciwgYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIGFjdGlvbigpO1xyXG4gICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIHNjaGVkdWxlclByb3RvID0gU2NoZWR1bGVyLnByb3RvdHlwZTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogUmV0dXJucyBhIHNjaGVkdWxlciB0aGF0IHdyYXBzIHRoZSBvcmlnaW5hbCBzY2hlZHVsZXIsIGFkZGluZyBleGNlcHRpb24gaGFuZGxpbmcgZm9yIHNjaGVkdWxlZCBhY3Rpb25zLiAgICAgICBcclxuICAgICAgICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBoYW5kbGVyIEhhbmRsZXIgdGhhdCdzIHJ1biBpZiBhbiBleGNlcHRpb24gaXMgY2F1Z2h0LiBUaGUgZXhjZXB0aW9uIHdpbGwgYmUgcmV0aHJvd24gaWYgdGhlIGhhbmRsZXIgcmV0dXJucyBmYWxzZS5cclxuICAgIC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ICAgICAgICAgaWYgKCFpdGVtLmlzQ2FuY2VsbGVkKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICAvLyBOb3RlLCBkbyBub3Qgc2NoZWR1bGUgYmxvY2tpbmcgd29yayFcclxuICAgICAgICAgICAgICAgICAgICB3aGlsZSAoaXRlbS5kdWVUaW1lIC0gU2NoZWR1bGVyLm5vdygpID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBpZiAoIWl0ZW0uaXNDYW5jZWxsZWQoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpdGVtLmludm9rZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSAgICAgICAgICAgIFxyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc2NoZWR1bGVOb3coc3RhdGUsIGFjdGlvbikge1xyXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5zY2hlZHVsZVdpdGhSZWxhdGl2ZUFuZFN0YXRlKHN0YXRlLCAwLCBhY3Rpb24pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc2NoZWR1bGVSZWxhdGl2ZShzdGF0ZSwgZHVlVGltZSwgYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIHZhciBkdCA9IHRoaXMubm93KCkgKyBTY2hlZHVsZXIubm9ybWFsaXplKGR1ZVRpbWUpLFxyXG4gICAgICAgICAgICAgICAgICAgIHNpID0gbmV3IFNjaGVkdWxlZEl0ZW0odGhpcywgc3RhdGUsIGFjdGlvbiwgZHQpLFxyXG4gICAgICAgICAgICAgICAgICAgIHQ7XHJcbiAgICAgICAgICAgIGlmICghcXVldWUpIHtcclxuICAgICAgICAgICAgICAgIHF1ZXVlID0gbmV3IFByaW9yaXR5UXVldWUoNCk7XHJcbiAgICAgICAgICAgICAgICBxdWV1ZS5lbnF1ZXVlKHNpKTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcnVuVHJhbXBvbGluZShxdWV1ZSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7IFxyXG4gICAgICAgICAgICAgICAgICAgIHRocm93IGU7XHJcbiAgICAgICAgICAgICAgICB9IGZpbmFsbHkge1xyXG4gICAgICAgICAgICAgICAgICAgIHF1ZXVlID0gbnVsbDtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIHF1ZXVlLmVucXVldWUoc2kpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHJldHVybiBzaS5kaXNwb3NhYmxlO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc2NoZWR1bGVBYnNvbHV0ZShzdGF0ZSwgZHVlVGltZSwgYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLnNjaGVkdWxlV2l0aFJlbGF0aXZlQW5kU3RhdGUoc3RhdGUsIGR1ZVRpbWUgLSB0aGlzLm5vdygpLCBhY3Rpb24pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIGN1cnJlbnRTY2hlZHVsZXIgPSBuZXcgU2NoZWR1bGVyKGRlZmF1bHROb3csIHNjaGVkdWxlTm93LCBzY2hlZHVsZVJlbGF0aXZlLCBzY2hlZHVsZUFic29sdXRlKTtcclxuICAgICAgICBjdXJyZW50U2NoZWR1bGVyLnNjaGVkdWxlUmVxdWlyZWQgPSBmdW5jdGlvbiAoKSB7IHJldHVybiBxdWV1ZSA9PT0gbnVsbDsgfTtcclxuICAgICAgICBjdXJyZW50U2NoZWR1bGVyLmVuc3VyZVRyYW1wb2xpbmUgPSBmdW5jdGlvbiAoYWN0aW9uKSB7XHJcbiAgICAgICAgICAgIGlmIChxdWV1ZSA9PT0gbnVsbCkge1xyXG4gICAgICAg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gICAgICAgdGhpcy5fcmVjdXJzaXZlV3JhcHBlciA9IG51bGw7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIGxvY2FsTm93LCBzY2hlZHVsZU5vdywgc2NoZWR1bGVSZWxhdGl2ZSwgc2NoZWR1bGVBYnNvbHV0ZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvKiogQHByaXZhdGUgKi9cclxuICAgICAgICBDYXRjaFNjaGVkdWxlci5wcm90b3R5cGUuX2Nsb25lID0gZnVuY3Rpb24gKHNjaGVkdWxlcikge1xyXG4gICAgICAgICAgICByZXR1cm4gbmV3IENhdGNoU2NoZWR1bGVyKHNjaGVkdWxlciwgdGhpcy5faGFuZGxlcik7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqIEBwcml2YXRlICovXHJcbiAgICAgICAgQ2F0Y2hTY2hlZHVsZXIucHJvdG90eXBlLl93cmFwID0gZnVuY3Rpb24gKGFjdGlvbikge1xyXG4gICAgICAgICAgICB2YXIgcGFyZW50ID0gdGhpcztcclxuICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIChzZWxmLCBzdGF0ZSkge1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gYWN0aW9uKHBhcmVudC5fZ2V0UmVjdXJzaXZlV3JhcHBlcihzZWxmKSwgc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghcGFyZW50Ll9oYW5kbGVyKGUpKSB7IHRocm93IGU7IH1cclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKiBAcHJpdmF0ZSAqL1xyXG4gICAgICAgIENhdGNoU2NoZWR1bG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aWYgKGZhaWxlZCkgeyByZXR1cm4gbnVsbDsgfVxyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gYWN0aW9uKHN0YXRlMSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZmFpbGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoIXNlbGYuX2hhbmRsZXIoZSkpIHsgdGhyb3cgZTsgfVxyXG4gICAgICAgICAgICAgICAgICAgIGQuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBudWxsO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSk7XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gZDtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICByZXR1cm4gQ2F0Y2hTY2hlZHVsZXI7XHJcbiAgICB9KFNjaGVkdWxlcikpO1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFJlcHJlc2VudHMgYSBub3RpZmljYXRpb24gdG8gYW4gb2JzZXJ2ZXIuXHJcbiAgICAgKi9cclxuICAgIHZhciBOb3RpZmljYXRpb24gPSBSeC5Ob3RpZmljYXRpb24gPSAoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGZ1bmN0aW9uIE5vdGlmaWNhdGlvbihraW5kLCBoYXNWYWx1ZSkgeyBcclxuICAgICAgICAgICAgdGhpcy5oYXNWYWx1ZSA9IGhhc1ZhbHVlID09IG51bGwgPyBmYWxzZSA6IGhhc1ZhbHVlO1xyXG4gICAgICAgICAgICB0aGlzLmtpbmQgPSBraW5kO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIE5vdGlmaWNhdGlvblByb3RvdHlwZSA9IE5vdGlmaWNhdGlvbi5wcm90b3R5cGU7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEludm9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bi5fYWNjZXB0T2JzZXJ2YWJsZShvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKG5vdGlmaWNhdGlvbi5raW5kID09PSAnTicpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgcmV0dXJuIE5vdGlmaWNhdGlvbjtcclxuICAgIH0pKCk7XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBDcmVhdGVzIGFuIG9iamVjdCB0aGF0IHJlcHJlc2VudHMgYW4gT25OZXh0IG5vdGlmaWNhdGlvbiB0byBhbiBvYnNlcnZlci5cclxuICAgICAqIEBwYXJhbSB7QW55fSB2YWx1ZSBUaGUgdmFsdWUgY29udGFpbmVkIGluIHRoZSBub3RpZmljYXRpb24uXHJcbiAgICAgKiBAcmV0dXJucyB7Tm90aWZpY2F0aW9ufSBUaGUgT25OZXh0IG5vdGlmaWNhdGlvbiBjb250YWluaW5nIHRoZSB2YWx1ZS5cclxuICAgICAqL1xyXG4gICAgdmFyIG5vdGlmaWNhdGlvbkNyZWF0ZU9uTmV4dCA9IE5vdGlmaWNhdGlvbi5jcmVhdGVPbk5leHQgPSAoZnVuY3Rpb24gKCkge1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBfYWNjZXB0IChvbk5leHQpIHtcclxuICAgICAgICAgICAgcmV0dXJuIG9uTmV4dCh0aGlzLnZhbHVlKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGZ1bmN0aW9uIF9hY2NlcHRPYnNlcnZhYmxlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBvYnNlcnZlci5vbk5leHQodGhpcy52YWx1ZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBmdW5jdGlvbiB0b1N0cmluZyAoKSB7XHJcbiAgICAgICAgICAgIHJldHVybiAnT25OZXh0KCcgKyB0aGlzLnZhbHVlICsgJyknO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICB2YXIgbm90aWZpY2F0aW9uID0gbmV3IE5vdGlmaWNhdGlvbignTicsIHRydWUpO1xyXG4gICAgICAgICAgICBub3RpZmljYXRpb24udmFsdWUgPSB2YWx1ZTtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLl9hY2NlcHQgPSBfYWNjZXB0O1xyXG4gICAgICAgICAgICBub3RpZmljYXRpb24uX2FjY2VwdE9ic2VydmFibGUgPSBfYWNjZXB0T2JzZXJ2YWJsZTtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLnRvU3RyaW5nID0gdG9TdHJpbmc7XHJcbiAgICAgICAgICAgIHJldHVybiBub3RpZmljYXRpb247XHJcbiAgICAgICAgfTtcclxuICAgIH0oKSk7XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBDcmVhdGVzIGFuIG9iamVjdCB0aGF0IHJlcHJlc2VudHMgYW4gT25FcnJvciBub3RpZmljYXRpb24gdG8gYW4gb2JzZXJ2ZXIuXHJcbiAgICAgKiBAcGFyYW0ge0FueX0gZXJyb3IgVGhlIGV4Y2VwdGlvbiBjb250YWluZWQgaW4gdGhlIG5vdGlmaWNhdGlvbi5cclxuICAgICAqIEByZXR1cm5zIHtOb3RpZmljYXRpb259IFRoZSBPbkVycm9yIG5vdGlmaWNhdGlvbiBjb250YWluaW5nIHRoZSBleGNlcHRpb24uXHJcbiAgICAgKi9cclxuICAgIHZhciBub3RpZmljYXRpb25DcmVhdGVPbkVycm9yID0gTm90aWZpY2F0aW9uLmNyZWF0ZU9uRXJyb3IgPSAoZnVuY3Rpb24gKCkge1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBfYWNjZXB0IChvbk5leHQsIG9uRXJyb3IpIHtcclxuICAgICAgICAgICAgcmV0dXJuIG9uRXJyb3IodGhpcy5leGNlcHRpb24pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gX2FjY2VwdE9ic2VydmFibGUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgcmV0dXJuIG9ic2VydmVyLm9uRXJyb3IodGhpcy5leGNlcHRpb24pO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgZnVuY3Rpb24gdG9TdHJpbmcgKCkge1xyXG4gICAgICAgICAgICByZXR1cm4gJ09uRXJyb3IoJyArIHRoaXMuZXhjZXB0aW9uICsgJyknO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgdmFyIG5vdGlmaWNhdGlvbiA9IG5ldyBOb3RpZmljYXRpb24oJ0UnKTtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLmV4Y2VwdGlvbiA9IGV4Y2VwdGlvbjtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLl9hY2NlcHQgPSBfYWNjZXB0O1xyXG4gICAgICAgICAgICBub3RpZmljYXRpb24uX2FjY2VwdE9ic2VydmFibGUgPSBfYWNjZXB0T2JzZXJ2YWJsZTtcclxuICAgICAgICAgICAgbm90aWZpY2F0aW9uLnRvU3RyaW5nID0gdG9TdHJpbmc7XHJcbiAgICAgICAgICAgIHJldHVybiBub3RpZmljYXRpb247XHJcbiAgICAgICAgfTtcclxuICAgIH0oKSk7XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiBDcmVhdGVzIGFuIG9iamVjdCB0aGF0IHJlcHJlc2VudHMgYW4gT25Db21wbGV0ZWQgbm90aWZpY2F0aW9uIHRvIGFuIG9ic2VydmVyLlxyXG4gICAgICogQHJldHVybnMge05vdGlmaWNhdGlvbn0gVGhlIE9uQ29tcGxldGVkIG5vdGlmaWNhdGlvbi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ChzZWxmKSB7XHJcbiAgICAgICAgdmFyIGN1cnJlbnRJdGVtO1xyXG4gICAgICAgIGlmIChpc0Rpc3Bvc2VkKSB7IHJldHVybjsgfVxyXG5cclxuICAgICAgICB0cnkge1xyXG4gICAgICAgICAgY3VycmVudEl0ZW0gPSBlLm5leHQoKTtcclxuICAgICAgICB9IGNhdGNoIChleCkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpZiAoY3VycmVudEl0ZW0uZG9uZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIHJldHVybjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8vIENoZWNrIGlmIHByb21pc2VcclxuICAgICAgICB2YXIgY3VycmVudFZhbHVlID0gY3VycmVudEl0ZW0udmFsdWU7XHJcbiAgICAgICAgaXNQcm9taXNlKGN1cnJlbnRWYWx1ZSkgJiYgKGN1cnJlbnRWYWx1ZSA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShjdXJyZW50VmFsdWUpKTtcclxuXHJcbiAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICBkLnNldERpc3Bvc2FibGUoY3VycmVudFZhbHVlLnN1YnNjcmliZShcclxuICAgICAgICAgIG9ic2VydmVyLm9uTmV4dC5iaW5kKG9ic2VydmVyKSxcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICBmdW5jdGlvbiAoKSB7IHNlbGYoKTsgfSlcclxuICAgICAgICApO1xyXG4gICAgICB9KTtcclxuXHJcbiAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYW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uICAgICAgICAgKiBOb3RpZmllcyB0aGUgb2JzZXJ2ZXIgb2YgYSBuZXcgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICogIFxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBBYnN0cmFjdE9ic2VydmVyXHJcbiAgICAgICAgICogQHBhcmFtIHtBbnl9IHZhbHVlIE5leHQgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuIFxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIEFic3RyYWN0T2JzZXJ2ZXIucHJvdG90eXBlLm9uTmV4dCA9IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogTm90aWZpZXMgdGhlIG9ic2VydmVyIHRoYXQgYW4gZXhjZXB0aW9uIGhhcyBvY2N1cnJlZC5cclxuICAgICAgICAgKiBcclxuICAgICAgICAgKiBAbWVtYmVyT2YgQWJzdHJhY3RPYnNlcnZlclxyXG4gICAgICAgICAqIEBwYXJhbSB7QW55fSBlcnJvciBUaGUgZXJyb3IgdGhhdCBoYXMgb2NjdXJyZWQuICAgICBcclxuICAgICAgICAgKi8gICAgXHJcbiAgICAgICAgQWJzdHJhY3RPYnNlcnZlci5wcm90b3R5cGUub25FcnJvciA9IGZ1bmN0aW9uIChlcnJvcikge1xyXG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmVycm9yKGVycm9yKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIE5vdGlmaWVzIHRoZSBvYnNlcnZlciBvZiB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZS5cclxuICAgICAgICAgKi8gICAgXHJcbiAgICAgICAgQWJzdHJhY3RPYnNlcnZlci5wcm90b3R5cGUub25Db21wbGV0ZWQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMuY29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBEaXNwb3NlcyB0aGUgb2JzZXJ2ZXIsIGNhdXNpbmcgaXQgdG8gdHJhbnNpdGlvbiB0byB0aGUgc3RvcHBlZCBzdGF0ZS5cclxuICAgICAgICAgKi9cclxuICAgICAgICBBYnN0cmFjdE9ic2VydmVyLnByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQWJzdHJhY3RPYnNlcnZlci5wcm90b3R5cGUuZmFpbCA9IGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIHJldHVybiBBYnN0cmFjdE9ic2VydmVyO1xyXG4gICAgfShPYnNlcnZlc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mVyKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICB0aGlzLl9vYnNlcnZlciA9IG9ic2VydmVyO1xyXG4gICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IDA7IC8vIDAgLSBpZGxlLCAxIC0gYnVzeSwgMiAtIGRvbmVcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHZhciBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUgPSBDaGVja2VkT2JzZXJ2ZXIucHJvdG90eXBlO1xyXG5cclxuICAgICAgICBDaGVja2VkT2JzZXJ2ZXJQcm90b3R5cGUub25OZXh0ID0gZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgIHRoaXMuY2hlY2tBY2Nlc3MoKTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX29ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlOyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gMDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIENoZWNrZWRPYnNlcnZlclByb3RvdHlwZS5vbkVycm9yID0gZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgICAgICB0aGlzLmNoZWNrQWNjZXNzKCk7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLl9vYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlOyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxu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lZCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgdmFyIHNlbGYgPSB0aGlzO1xyXG4gICAgICB0aGlzLnF1ZXVlLnB1c2goZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHNlbGYub2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIFNjaGVkdWxlZE9ic2VydmVyLnByb3RvdHlwZS5lbnN1cmVBY3RpdmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgIHZhciBpc093bmVyID0gZmFsc2UsIHBhcmVudCA9IHRoaXM7XHJcbiAgICAgIGlmICghdGhpcy5oYXNGYXVsdGVkICYmIHRoaXMucXVldWUubGVuZ3RoID4gMCkge1xyXG4gICAgICAgIGlzT3duZXIgPSAhdGhpcy5pc0FjcXVpcmVkO1xyXG4gICAgICAgIHRoaXMuaXNBY3F1aXJlZCA9IHRydWU7XHJcbiAgICAgIH1cclxuICAgICAgaWYgKGlzT3duZXIpIHtcclxuICAgICAgICB0aGlzLmRpc3Bvc2FibGUuc2V0RGlzcG9zYWJsZSh0aGlzLnNjaGVkdWxlci5zY2hlZHVsZVJlY3Vyc2l2ZShmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgdmFyIHdvcms7XHJcbiAgICAgICAgICBpZiAocGFyZW50LnF1ZXVlLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgd29yayA9IHBhcmVudC5xdWV1ZS5zaGlmdCgpO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgcGFyZW50LmlzQWNxdWlyZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgd29yaygpO1xyXG4gICAgICAgICAgfSBjYXRjaCAoZXgpIHtcclxuICAgICAgICAgICAgcGFyZW50LnF1ZXVlID0gW107XHJcbiAgICAgIC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B2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IHByb21pc2VDdG9yKGZ1bmN0aW9uIChyZXNvbHZlLCByZWplY3QpIHtcclxuICAgICAgICAgICAgLy8gTm8gY2FuY2VsbGF0aW9uIGNhbiBiZSBkb25lXHJcbiAgICAgICAgICAgIHZhciB2YWx1ZSwgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAodikge1xyXG4gICAgICAgICAgICAgICAgdmFsdWUgPSB2O1xyXG4gICAgICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgICByZWplY3QoZXJyKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1ZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmVzb2x2ZSh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuICAvKipcclxuICAgKiBDcmVhdGVzIGEgbGlzdCBmcm9tIGFuIG9ic2VydmFibGUgc2VxdWVuY2UuXHJcbiAgICogQHJldHVybnMgQW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSBjb250YWluaW5nIGEgc2luZ2xlIGVsZW1lbnQgd2l0aCBhIGxpc3QgY29udGFpbmluZyBhbGwgdGhlIGVsZW1lbnRzIG9mIHRoZSBzb3VyY2Ugc2VxdWVuY2UuICBcclxuICAgKi9cclxuICBvYnNlcnZhYmxlUHJvdG8udG9BcnJheSA9IGZ1bmN0aW9uICgpIHtcclxuICAgIHZhciBzZWxmID0gdGhpcztcclxuICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbihvYnNlcnZlcik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IChzZWxmKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgaGFzUmVzdWx0LCByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmaXJzdCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlID0gaXRlcmF0ZShzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1Jlc3VsdCA9IGNvbmRpdGlvbihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICAgICAgICAgICAgICBzZWxmKCk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogIFRoaXMgbWV0aG9kIGNyZWF0ZXMgYS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pO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGNob2ljZUwoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSBsZWZ0Q2hvaWNlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSkpO1xyXG5cclxuICAgICAgcmlnaHRTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShyaWdodFNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHJpZ2h0KSB7XHJcbiAgICAgICAgY2hvaWNlUigpO1xyXG4gICAgICAgIGlmIChjaG9pY2UgPT09IHJpZ2h0Q2hvaWNlKSB7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmlnaHQpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKGVycikge1xyXG4gICAgICAgIGNob2ljZVIoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSByaWdodENob2ljZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIGNob2ljZVIoKTtcclxuICAgICAgICBpZiAoY2hvaWNlID09PSByaWdodENob2ljZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcbiAgICAgIH0pKTtcclxuXHJcbiAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShsZWZ0U3Vic2NyaXB0aW9uLCByaWdodFN1YnNjcmlwdGlvbik7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAvKipcclxuICAgKiBQcm9wYWdhdGVzIHRoZSBvYnNlcnZhYmxlIHNlcXVlbmNlIG9yIFByb21pc2UgdGhhdCByZWFjdHMgZmlyc3QuXHJcb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KCksXHJcbiAgICAgICAgICAgICAgICBpc1N0b3BwZWQgPSBmYWxzZSxcclxuICAgICAgICAgICAgICAgIHEgPSBbXSxcclxuICAgICAgICAgICAgICAgIHN1YnNjcmliZSA9IGZ1bmN0aW9uICh4cykge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBzdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICBncm91cC5hZGQoc3Vic2NyaXB0aW9uKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgLy8gQ2hlY2sgZm9yIHByb21pc2VzIHN1cHBvcnRcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaXNQcm9taXNlKHhzKSkgeyB4cyA9IG9ic2VydmFibGVGcm9tUHJvbWlzZSh4cyk7IH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoeHMuc3Vic2NyaWJlKG9ic2VydmVyLm9uTmV4dC5iaW5kKG9ic2VydmVyKSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgcztcclxuICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXAucmVtb3ZlKHN1YnNjcmlwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMgPSBxLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmUocyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY3RpdmVDb3VudC0tO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzU3RvcHBlZCAmJiBhY3RpdmVDb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICBncm91cC5hZGQoc291cmNlcy5zdWJzY3JpYmUoZnVuY3Rpb24gKGlubmVyU291cmNlKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoYWN0aXZlQ291bnQgPCBtYXhDb25jdXJyZW50T3JPdGhlcikge1xyXG4gICAgICAgICAgICAgICAgICAgIGFjdGl2ZUNvdW50Kys7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlKGlubmVyU291cmNlKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKGlubmVyU291cmNlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIGlmIChhY3RpdmVDb3VudCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgcmV0dXJuIGdyb3VwO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqIE1lcmdlcyBhbGwgdGhlIG9ic2VydmFibGUgc2VxdWVuY2VzIGludG8gYSBzaW5nbGUgb2JzZXJ2YWJsZSBzZXF1ZW5jZS4g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WJzY3JpcHRpb24gPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgaXNTdG9wcGVkID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICBsYXRlc3QgPSAwLFxyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uID0gc291cmNlcy5zdWJzY3JpYmUoZnVuY3Rpb24gKGlubmVyU291cmNlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKSwgaWQgPSArK2xhdGVzdDtcclxuICAgICAgICAgICAgICAgICAgICBoYXNMYXRlc3QgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGlubmVyU3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoZCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIC8vIENoZWNrIGlmIFByb21pc2Ugb3IgT2JzZXJ2YWJsZVxyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpc1Byb21pc2UoaW5uZXJTb3VyY2UpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyU291cmNlID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKGlubmVyU291cmNlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZShpbm5lclNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxhdGVzdCA9PT0gaWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsYXRlc3QgPT09IGlkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAobGF0ZXN0ID09PSBpZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzTGF0ZXN0ID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBpc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICghaGFzTGF0ZXN0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShzdWJzY3JpcHRpb24sIGlubmVyU3Vic2NyaXB0aW9uKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIC8qKlxyXG4gICAqIFJldHVybnMgdGhlIHZhbHVlcyBmcm9tIHRoZSBzb3VyY2Ugb2JzZXJ2YWJsZSBzZXF1ZW5jZSB1bnRpbCB0aGUgb3RoZXIgb2JzZXJ2YWJsZSBzZXF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AgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgZnVuY3Rpb24gZG9uZShpKSB7XHJcbiAgICAgICAgICAgICAgICBpc0RvbmVbaV0gPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgaWYgKGlzRG9uZS5ldmVyeShpZGVudGl0eSkpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdmFyIHN1YnNjcmlwdGlvbnMgPSBuZXcgQXJyYXkobik7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGlkeCA9IDA7IGlkeCA8IG47IGlkeCsrKSB7XHJcbiAgICAgICAgICAgICAgICAoZnVuY3Rpb24gKGkpIHtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb25zW2ldID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uc1tpXS5zZXREaXNwb3NhYmxlKHNvdXJjZXNbaV0uc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHF1ZXVlc1tpXS5wdXNoKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBuZXh0KGkpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZG9uZShpKTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcb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XBhcmVyKSB7XHJcbiAgICAgICAgdmFyIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAga2V5U2VsZWN0b3IgfHwgKGtleVNlbGVjdG9yID0gaWRlbnRpdHkpO1xyXG4gICAgICAgIGNvbXBhcmVyIHx8IChjb21wYXJlciA9IGRlZmF1bHRDb21wYXJlcik7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaGFzQ3VycmVudEtleSA9IGZhbHNlLCBjdXJyZW50S2V5O1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHZhciBjb21wYXJlckVxdWFscyA9IGZhbHNlLCBrZXk7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGtleSA9IGtleVNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzQ3VycmVudEtleSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbXBhcmVyRXF1YWxzID0gY29tcGFyZXIoY3VycmVudEtleSwga2V5KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICA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vbkVycm9yLCBvbkNvbXBsZXRlZCkge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzLCBvbk5leHRGdW5jO1xyXG4gICAgICAgIGlmICh0eXBlb2Ygb2JzZXJ2ZXJPck9uTmV4dCA9PT0gJ2Z1bmN0aW9uJykge1xyXG4gICAgICAgICAgICBvbk5leHRGdW5jID0gb2JzZXJ2ZXJPck9uTmV4dDtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBvbk5leHRGdW5jID0gb2JzZXJ2ZXJPck9uTmV4dC5vbk5leHQuYmluZChvYnNlcnZlck9yT25OZXh0KTtcclxuICAgICAgICAgICAgb25FcnJvciA9IG9ic2VydmVyT3JPbk5leHQub25FcnJvci5iaW5kKG9ic2VydmVyT3JPbk5leHQpO1xyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZCA9IG9ic2VydmVyT3JPbk5leHQub25Db21wbGV0ZWQuYmluZChvYnNlcnZlck9yT25OZXh0KTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBvbk5leHRGdW5jKHgpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIGlmICghb25FcnJvcikge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIW9uQ29tcGxldGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgLyoqXHJcbiAgICogIEludm9rZXMgYSBzcGVjaWZpZWQgYWN0aW9uIGFmdGVyIHRoZSBzb3VyY2Ugb2JzZXJ2YWJsZSBzZXF1ZW5jZSB0ZXJtaW5hdGVzIGdyYWNlZnVsbHkgb3IgZXhjZXB0aW9uYWxseS5cclxuICAgKiAgXH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AgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlIChcclxuICAgICAgICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFoYXNWYWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXNBY2N1bXVsYXRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFjY3VtdWxhdGlvbiA9IGFjY3VtdWxhdG9yKGFjY3VtdWxhdGlvbiwgeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY2N1bXVsYXRpb24gPSBoYXNTZWVkID8gYWNjdW11bGF0b3Ioc2VlZCwgeCkgOiB4O1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzQWNjdW11bGF0aW9uID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgIFxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhY2N1bXVsYXRpb24pO1xyXG4gICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAoKSB7XHJcbiAgICAg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koeHMsIHNjaGVkdWxlcik7IH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBSZXR1cm5zIGFuIGFycmF5IHdpdGggdGhlIHNwZWNpZmllZCBudW1iZXIgb2YgY29udGlndW91cyBlbGVtZW50cyBmcm9tIHRoZSBlbmQgb2YgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZS5cclxuICAgICAqICBcclxuICAgICAqIEBkZXNjcmlwdGlvblxyXG4gICAgICogIFRoaXMgb3BlcmF0b3IgYWNjdW11bGF0ZXMgYSBidWZmZXIgd2l0aCBhIGxlbmd0aCBlbm91Z2ggdG8gc3RvcmUgY291bnQgZWxlbWVudHMuIFVwb24gY29tcGxldGlvbiBvZiB0aGVcclxuICAgICAqICBzb3VyY2Ugc2VxdWVuY2UsIHRoaXMgYnVmZmVyIGlzIHByb2R1Y2VkIG9uIHRoZSByZXN1bHQgc2VxdWVuY2UuICAgICAgIFxyXG4gICAgICogQHBhcmFtIHtOdW1iZXJ9IGNvdW50IE51bWJlciBvZiBlbGVtZW50cyB0byB0YWtlIGZyb20gdGhlIGVuZCBvZiB0aGUgc291cmNlIHNlcXVlbmNlLlxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2UgY29udGFpbmluZyBhIHNpbmdsZSBhcnJheSB3aXRoIHRoZSBzcGVjaWZpZWQgbnVtYmVyIG9mIGVsZW1lbnRzIGZyb20gdGhlIGVuZCBvZiB0aGUgc291cmNlIHNlcXVlbmNlLlxyXG4gICAgICovXHJcbiAgICBvYnNlcnZhYmxlUHJvdG8udGFrZUxhc3RCdWZmZXIgPSBmdW5jdGlvbiAoY291bnQpIHtcclxuICAgICAgICB2YXIgc291cmNlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBxID0gW107XHJcbiAgIC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1cm5zIHtPYnNlcnZhYmxlfSBBbiBvYnNlcnZhYmxlIHNlcXVlbmNlIG9mIHdpbmRvd3MuICBcclxuICAgICAqL1xyXG4gICAgb2JzZXJ2YWJsZVByb3RvLndpbmRvd1dpdGhDb3VudCA9IGZ1bmN0aW9uIChjb3VudCwgc2tpcCkge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIGlmIChjb3VudCA8PSAwKSB7XHJcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAgICAgICBza2lwID0gY291bnQ7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChza2lwIDw9IDApIHtcclxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGFyZ3VtZW50T3V0T2ZSYW5nZSk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIG0gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHJlZkNvdW50RGlzcG9zYWJsZSA9IG5ldyBSZWZDb3VudERpc3Bvc2FibGUobSksXHJcbiAgICAgICAgICAgICAgICBuID0gMCxcclxuICAgICAgICAgICAgICAgIHEgPSBbXSxcclxuICAgICAgICAgICAgICAgIGNyZWF0ZVdpbmRvdyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHMpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICBjcmVhdGVXaW5kb3coKTtcclxuICAgICAgICAgICAgbS5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBzO1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IHEubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICBxW2ldLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHZhciBjID0gbiAtIGNvdW50ICsgMTtcclxuICAgICAgICAgICAgICAgIGlmIChjID49IDAgJiYgYyAlIHNraXAgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICBzID0gcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG4rKztcclxuICAgICAgICAgICAgICAgIGlmIChuICUgc2tpcCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGNyZWF0ZVdpbmRvdygpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICB3aGlsZSAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5zaGlmdCgpLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHEuc2hpZnQoKS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICByZXR1cm4gcmVmQ291bnREaXNwb3NhYmxlO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBjb25jYXRNYXAoc2VsZWN0b3IpIHtcclxuICAgICAgcmV0dXJuIHRoaXMubWFwKGZ1bmN0aW9uICh4LCBpKSB7XHJcbiAgICAgICAgdmFyIHJlc3VsdCA9IHNlbGVjdG9yKHgsIGkpO1xyXG4gICAgICAgIHJldHVybiBpc1Byb21pc2UocmVzdWx0KSA/IG9ic2VydmFibGVGcm9tUHJvbWlzZShyZXN1bHQpIDogcmVzdWx0O1xyXG4gICAgICB9KS5jb25jYXRBbGwoKTtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBjb25jYXRNYXBPYnNlcnZlcihvbk5leHQsIG9uRXJyb3IsIG9uQ29tcGxldGVkKSB7XHJcbiAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgdmFyIGluZGV4ID0gMDtcclxuXHJcbiAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQob25OZXh0KHgsIGluZGV4KyspKTtcclxuICAgICAgICAgIH0sXHJcbiAgICAgICAgICBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChvbkVycm9yKGVycikpO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5jb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ZhdWx0VmFsdWUgPT09IHVuZGVmaW5lZCkge1xyXG4gICAgICAgICAgICBkZWZhdWx0VmFsdWUgPSBudWxsO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBmb3VuZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgZm91bmQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIWZvdW5kKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGRlZmF1bHRWYWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgUmV0dXJucyBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIHRoYXQgY29udGFpbnMgb25seSBkaXN0aW5jdCBlbGVtZW50cyBhY2NvcmRpbmcgdG8gdGhlIGtleVNlbGVjdG9yIGFuZCB0aGUgY29tcGFyZXIuXHJcbiAgICAgKiAgVXNhZ2Ugb2YgdGhpcyBvcGVyYXRvciBzaG91bGQgYmUgY29uc2lkZXJlZCBjYXJlZnVsbHkgZHVlIHRvIHRoZSBtYWludGVuYW5jZSBvZiBhbiBpbnRlcm5hbCBsb29rdXAgc3RydWN0dXJlIHdoaWNoIGNhbiBncm93IGxhcmdlLiBccl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ZXIgPSBkZWZhdWx0S2V5U2VyaWFsaXplcik7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgaGFzaFNldCA9IHt9O1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGtleSwgc2VyaWFsaXplZEtleSwgb3RoZXJLZXksIGhhc01hdGNoID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGtleSA9IGtleVNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHNlcmlhbGl6ZWRLZXkgPSBrZXlTZXJpYWxpemVyKGtleSk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgZm9yIChvdGhlcktleSBpbiBoYXNoU2V0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHNlcmlhbGl6ZWRLZXkgPT09IG90aGVyS2V5KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGhhc01hdGNoID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNNYXRjaCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGhhc2hTZXRbc2VyaWFsaXplZEtleV0gPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTm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G4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIG1hcCA9IHt9LFxyXG4gICAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHJlZkNvdW50RGlzcG9zYWJsZSA9IG5ldyBSZWZDb3VudERpc3Bvc2FibGUoZ3JvdXBEaXNwb3NhYmxlKTtcclxuICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLmFkZChzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgZHVyYXRpb24sIGR1cmF0aW9uR3JvdXAsIGVsZW1lbnQsIGZpcmVOZXdNYXBFbnRyeSwgZ3JvdXAsIGtleSwgc2VyaWFsaXplZEtleSwgbWQsIHdyaXRlciwgdztcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAga2V5ID0ga2V5U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgc2VyaWFsaXplZEtleSA9IGtleVNlcmlhbGl6ZXIoa2V5KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG1hcFt3XS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGZpcmVOZXdNYXBFbnRyeSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICB3cml0ZXIgPSBtYXBbc2VyaWFsaXplZEtleV07XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCF3cml0ZXIpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgd3JpdGVyID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbWFwW3NlcmlhbGl6ZWRLZXldID0gd3JpdGVyO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmaXJlTmV3TWFwRW50cnkgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG1hcFt3XS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChmaXJlTmV3TWFwRW50cnkpIHtcclxuICAgICAgICAgICAgICAgICAgICBncm91cCA9IG5ldyBHcm91cGVkT2JzZXJ2YWJsZShrZXksIHdyaXRlciwgcmVmQ291bnREaXNwb3NhYmxlKTtcclxuICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbkdyb3VwID0gbmV3IEdyb3VwZWRPYnNlcnZhYmxlKGtleSwgd3JpdGVyKTtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbiA9IGR1cmF0aW9uU2VsZWN0b3IoZHVyYXRpb25Hcm91cCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXBbd10ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChncm91cCk7XHJcbiAgICAgICAgICAgICAgICAgICAgbWQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICBncm91cERpc3Bvc2FibGUuYWRkKG1kKTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgZXhwaXJlID0gZnVuY3Rpb24gICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNlcmlhbGl6ZWRLZXkgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWxldGUgbWFwW3NlcmlhbGl6ZWRLZXldO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgd3JpdGVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKG5vb3AsIGZ1bmN0aW9uIChleG4pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZm9yICh3IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uRXJyb3IoZXhuKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4bik7XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBleHBpcmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGVsZW1lbnQgPSBlbGVtZW50U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh3IGluIG1hcCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBtYXBbd10ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB3cml0ZXIub25OZXh0KGVsZW1lbnQpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXgpIHtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIHcgaW4gbWFwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbWFwW3ddLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KSk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93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgIH1cclxuICAgICAgICB2YXIgb2JzZXJ2YWJsZSA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgcmVtYWluaW5nID0gY291bnQ7XHJcbiAgICAgICAgICAgIHJldHVybiBvYnNlcnZhYmxlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKHJlbWFpbmluZyA8PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICByZW1haW5pbmctLTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBCeXBhc3NlcyBlbGVtZW50cyBpbiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIGFzIGxvbmcgYXMgYSBzcGVjaWZpZWQgY29uZGl0aW9uIGlzIHRydWUgYW5kIHRoZW4gcmV0dXJucyB0aGUgcmVtYWluaW5nIGVsZW1lbnRzLlxyXG4gICAgICogIFRoZSBlbGVtZW50J3MgaW5kZXggaXMgdXNlZCBpbiB0aGUgbG9naWMgb2YgdGhlIHByZWRpY2F0ZSBmdW5jdGlvbi5cclxuICAgICAqICBcclxuICAgICAqICB2YXIgcmVzID0gc291cmNlLnNraXBXaGlsZShmdW5jdGlvbiAodmFsdWUpIHsgcmV0dXJuIHZhbHVlIDwgMTA7IH0pO1xy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3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGlmICghcnVubmluZykge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJ1bm5pbmcgPSAhcHJlZGljYXRlLmNhbGwodGhpc0FyZywgeCwgaSsrLCBzb3VyY2UpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChydW5uaW5nKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBvYnNlcnZlci5vbkNvbXBsZXRlZC5iaW5kKG9ic2VydmVyKSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFJldHVybnMgYSBzcGVjaWZpZWQgbnVtYmVyIG9mIGNvbnRpZ3VvdXMgZWxlbWVudHMgZnJvbSB0aGUgc3RhcnQgb2YgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSwgdXNpbmcgdGhlIHNwZWNpZmllZCBzY2hlZHVsZXIgZm9yIHRoZSBlZGdlIGNhc2Ugb2YgdGFrZSgwKS5cclxuICAgICAqICBcclxuICAgICAqICB2YXIgcmVzID0gc291cmNlLnRha2UoNSk7XHJcbiAgICAgKiAgdmFyIHJlcyA9IHNvdXJjZS50YWtlKDAsIFJ4LlNjaGVkdWxlci50aW1lb3V0KTtcclxuICAgICAqIEBwYXJhbSB7TnVtYmVyfSBj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XIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBpZiAocnVubmluZykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgRmlsdGVycyB0aGUgZWxlbWVudHMgb2YgYW4gb2JzZXJ2YWJsZSBzZXF1ZW5jZSBiYXNlZCBvbiBhIHByZWRpY2F0ZSBieSBpbmNvcnBvcmF0aW5nIHRoZSBlbGVtZW50J3MgaW5kZXguXHJcbiAgICAgKiAgXHJcbiAgICAgKiBAZXhhbXBsZVxyXG4gICAgICogIHZhciByZXMgPSBzb3VyY2Uud2hlcmUoZnVuY3Rpb24gKHZhbHVlKSB7IHJldHVybiB2YWx1ZSA8IDEwOyB9KTtcclxuICAgICAqICB2YXIgcmVzID0gc291cmNlLndoZXJlKGZ1bmN0aW9uICh2YWx1ZSwgaW5kZXgpIHsgcmV0dXJuIHZhbHVlIDwgMTAgfHwgaW5kZXggPCAxMDsgfSk7XHJcbiAgICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBwcmVkaWNhdGUgQSBmdW5jdGlvbiB0byB0ZXN0IGVhY2ggc291cmNlIGVsZW1lbnQgZm9yIGEgY29uZGl0aW9uOyB0aGUgc2Vjb25kIHBhcmFtZXR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BrZXlTZWxlY3RvciwgY29tcGFyZXIpIHtcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBoYXNWYWx1ZSA9IGZhbHNlLCBsYXN0S2V5ID0gbnVsbCwgbGlzdCA9IFtdO1xyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGNvbXBhcmlzb24sIGtleTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAga2V5ID0ga2V5U2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGNvbXBhcmlzb24gPSAwO1xyXG4gICAgICAgICAgICAgICAgaWYgKCFoYXNWYWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBsYXN0S2V5ID0ga2V5O1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBjb21wYXJpc29uID0gY29tcGFyZXIoa2V5LCBsYXN0S2V5KTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChleDEpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleDEpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGNvbXBhcmlzb24gPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbGFzdEtleSA9IGtleTtcclxuICAgICAgICAgICAgICAgICAgICBsaXN0ID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoY29tcGFyaXNvbiA+PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbGlzdC5wdXNoKHgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQobGlzdCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBmaXJzdE9ubHkoeCkge1xyXG4gICAgICAgIGlmICh4Lmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3Ioc2VxdWVuY2VDb250YWluc05vRWxlbWVudHMpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4geFswXTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIEFwcGxpZXMgYW4gYWNjdW11bGF0b3IgZnVuY3Rpb24gb3ZlciBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlLCByZXR1cm5pbmcgdGhlIHJlc3VsdCBvZiB0aGUgYWdncmVnYXRpb24gYXMgYSBzaW5nbGUgZWxlbWVudCBpbiB0aGUgcmVzdWx0IHNlcXVlbmNlLiBUaGUgc3BlY2lmaWVkIHNlZWQgdmFsdWUgaXMgdXNlZCBhcyB0aGUgaW5pdGlhbCBhY2N1bXVsYXRvciB2YWx1ZS5cclxuICAgICAqIEZvciBhZ2dyZWdhd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A9IHJlcyA9IHNvdXJjZS5hdmVyYWdlKCk7XHJcbiAgICAgKiB2YXIgcmVzID0gcmVzID0gc291cmNlLmF2ZXJhZ2UoZnVuY3Rpb24gKHgpIHsgcmV0dXJuIHgudmFsdWU7IH0pO1xyXG4gICAgICogQHBhcmFtIHtGdW5jdGlvbn0gW3NlbGVjdG9yXSBBIHRyYW5zZm9ybSBmdW5jdGlvbiB0byBhcHBseSB0byBlYWNoIGVsZW1lbnQuXHJcbiAgICAgKiBAcGFyYW0ge0FueX0gW3RoaXNBcmddIE9iamVjdCB0byB1c2UgYXMgdGhpcyB3aGVuIGV4ZWN1dGluZyBjYWxsYmFjay4gICAgICAgIFxyXG4gICAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2UgY29udGFpbmluZyBhIHNpbmdsZSBlbGVtZW50IHdpdGggdGhlIGF2ZXJhZ2Ugb2YgdGhlIHNlcXVlbmNlIG9mIHZhbHVlcy5cclxuICAgICAqL1xyXG4gICAgb2JzZXJ2YWJsZVByb3RvLmF2ZXJhZ2UgPSBmdW5jdGlvbiAoa2V5U2VsZWN0b3IsIHRoaXNBcmcpIHtcclxuICAgICAgICByZXR1cm4ga2V5U2VsZWN0b3IgP1xyXG4gICAgICAgICAgICB0aGlzLnNlbGVjdChrZXlTZWxlY3RvciwgdGhpc0FyZykuYXZlcmFnZSgpIDpcclxuICAgICAgICAgICAgdGhpcy5zY2FuKHtcclxuICAgICAgICAgICAgICAgIHN1bTogMCxcclxuICAgICAgICAgICAgICAgIGNvdW50OiAwXHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChwcmV2LCBjdXIpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3VtOiBwcmV2LnN1bSArIGN1cixcclxuICAgICAgICAgICAgICAgICAgICBjb3VudDogcHJldi5jb3VudCArIDFcclxuICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgIH0pLmZpbmFsVmFsdWUoKS5zZWxlY3QoZnVuY3Rpb24gKHMpIHtcclxuICAgICAgICAgICAgICAgIGlmIChzLmNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdUaGUgaW5wdXQgc2VxdWVuY2Ugd2FzIGVtcHR5Jyk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gcy5zdW0gLyBzLmNvdW50O1xyXG4gICAgICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gIGZ1bmN0aW9uIHNlcXVlbmNlRXF1YWxBcnJheShmaXJzdCwgc2Vjb25kLCBjb21wYXJlcikge1xyXG4gICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgdmFyIGNvdW50ID0gMCwgbGVuID0gc2Vjb25kLmxlbmd0aDtcclxuICAgICAgICByZXR1cm4gZmlyc3Quc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgdmFyIGVxdWFsID0gZmFsc2U7XHJcbiAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICBpZiAoY291bnQgPCBsZW4pIHtcclxuICAgICAgICAgICAgICBlcXVhbCA9IGNvbXBhcmVyKHZhbHVlLCBzZWNvbmRbY291bnQrK10pO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGlmICghZXF1YWwpIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAg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gICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgIGVxdWFsID0gY29tcGFyZXIodiwgeCk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpZiAoIWVxdWFsKSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSBlbHNlIGlmIChkb25lcikge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHFsLnB1c2goeCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZG9uZWwgPSB0cnVlO1xyXG4gICAgICAgIGlmIChxbC5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgIGlmIChxci5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9IGVsc2UgaWYgKGRvbmVyKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh0cnVlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgIH0pO1xyXG5cclxuICAgICAgaXNQcm9taXNlKHNlY29uZCkgJiYgKHNlY29uZCA9IG9ic2VydmFibGVGcm9tUHJvbWlzZShzZWNvbmQpKTtcclxuICAgICAgdmFyIHN1YnNjcmlwdGlvbjIgPSBzZWNvbmQuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgdmFyIGVxdWFsLCB2O1xyXG4gICAgICAgIGlmIChxbC5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICB2ID0gcWwuc2hpZnQoKTtcclxuICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgIGVxdWFsID0gY29tcGFyZXIodiwgeCk7XHJcbiAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBpZiAoIWVxdWFsKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSBlbHNlIGlmIChkb25lbCkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGZhbHNlKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHFyLnB1c2goeCk7XHJcbiAgICAgICAgfVxyXG4gICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgZG9uZXIgPSB0cnVlO1xyXG4gICAgICAgIGlmIChxci5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgIGlmIChxbC5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChmYWxzZSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICB9IGVsc2UgaWYgKGRvbmVsKSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh0cnVlKTtcclxuICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgIH0pO1xyXG4gICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uMSwgc3Vic2NyaXB0aW9uMik7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIGVsZW1lbnRBdE9yRGVmYXVsdChzb3VyY2UsIGluZGV4LCBoYXNEZWZhdWx0LCBkZWZhdWx0VmFsdWUpIHtcclxuICAgICAgICBpZiAoaW5kZXggPCAwKSB7XHJcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihhcmd1bWVudE91dE9mUmFuZ2UpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBpID0gaW5kZXg7XHJcbiAgICAgICAgICAgIHJldHVybiBzb3VyY2Uuc3Vic2NyaWJlKGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoaSA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaS0tO1xyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIW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hhc0RlZmF1bHQsIGRlZmF1bHRWYWx1ZSkge1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHZhbHVlID0gZGVmYXVsdFZhbHVlLCBzZWVuVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgcmV0dXJuIHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGlmIChzZWVuVmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKG5ldyBFcnJvcignU2VxdWVuY2UgY29udGFpbnMgbW9yZSB0aGFuIG9uZSBlbGVtZW50JykpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICB2YWx1ZSA9IHg7XHJcbiAgICAgICAgICAgICAgICAgICAgc2VlblZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFzZWVuVmFsdWUgJiYgIWhhc0RlZmF1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKG5ldyBFcnJvcihzZXF1ZW5jZUNvbnRhaW5zTm9FbGVtZW50cykpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIC8qKlxyXG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bkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChzaG91bGRSdW4pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeWllbGRJbmRleCA/IGkgOiB4KTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICBpKys7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh5aWVsZEluZGV4ID8gLTEgOiB1bmRlZmluZWQpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7ICAgICAgICBcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIFNlYXJjaGVzIGZvciBhbiBlbGVtZW50IHRoYXQgbWF0Y2hlcyB0aGUgY29uZGl0aW9ucyBkZWZpbmVkIGJ5IHRoZSBzcGVjaWZpZWQgcHJlZGljYXRlLCBhbmQgcmV0dXJucyB0aGUgZmlyc3Qgb2NjdXJyZW5jZSB3aXRoaW4gdGhlIGVudGlyZSBPYnNlcnZhYmxlIHNlcXVlbmNlLlxyXG4gICAgICogQHBhcmFtIHtGdW5jdGlvbn0gcHJlZGljYXRlIFRoZSBwcmVkaWNhdGUgdGhhdCBkZWZpbmVzIHRoZSBjb25kaXRpb25zIG9mIHRoZSBlbGVtZW50IHRvIHNlYXJjaCBmb3IuXHJcbiAgICAgKiBAcGFyYW0ge0FueX0gW3RoaXNBcmddIE9iamVjdCB0byB1c2UgYXMgYHRoa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GVkfSBbY29udGV4dF0gVGhlIGNvbnRleHQgZm9yIHRoZSBmdW5jIHBhcmFtZXRlciB0byBiZSBleGVjdXRlZC4gIElmIG5vdCBzcGVjaWZpZWQsIGRlZmF1bHRzIHRvIHVuZGVmaW5lZC5cclxuICAgICAqIEByZXR1cm5zIHtGdW5jdGlvbn0gQXN5bmNocm9ub3VzIGZ1bmN0aW9uLlxyXG4gICAgICovXHJcbiAgICB2YXIgb2JzZXJ2YWJsZVRvQXN5bmMgPSBPYnNlcnZhYmxlLnRvQXN5bmMgPSBmdW5jdGlvbiAoZnVuYywgc2NoZWR1bGVyLCBjb250ZXh0KSB7XHJcbiAgICAgICAgc2NoZWR1bGVyIHx8IChzY2hlZHVsZXIgPSB0aW1lb3V0U2NoZWR1bGVyKTtcclxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgYXJncyA9IGFyZ3VtZW50cywgXHJcbiAgICAgICAgICAgICAgICBzdWJqZWN0ID0gbmV3IEFzeW5jU3ViamVjdCgpO1xyXG5cclxuICAgICAgICAgICAgc2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciByZXN1bHQ7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IGZ1bmMuYXBwbHkoY29udGV4dCwgYXJncyk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3ViamVjdC5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHN1YmplY3Qub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICBzdWJqZWN0Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICByZ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pbmdsZSB2YWx1ZSBvZiB0aGUgYXJndW1lbnRzIHRvIHRoZSBjYWxsYmFjayBhcyBhbiBhcnJheS5cclxuICAgICAqL1xyXG4gICAgT2JzZXJ2YWJsZS5mcm9tQ2FsbGJhY2sgPSBmdW5jdGlvbiAoZnVuYywgc2NoZWR1bGVyLCBjb250ZXh0LCBzZWxlY3Rvcikge1xyXG4gICAgICAgIHNjaGVkdWxlciB8fCAoc2NoZWR1bGVyID0gaW1tZWRpYXRlU2NoZWR1bGVyKTtcclxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgYXJncyA9IHNsaWNlLmNhbGwoYXJndW1lbnRzLCAwKTtcclxuXHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBzY2hlZHVsZXIuc2NoZWR1bGUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uIGhhbmRsZXIoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgcmVzdWx0cyA9IGU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoc2VsZWN0b3IpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0cyA9IHNlbGVjdG9yKGFyZ3VtZW50cyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlcnIpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGVycik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJlc3VsdHMubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0cyA9IHJlc3VsdHNbMF07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHRzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGFyZ3MucHVzaChoYW5kbGVyKTtcclxuICAgICAgICAgICAgICAgICAgICBmdW5jLmFwcGx5KGNvbnRleHQsIGFyZ3MpO1xyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH07XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogQ29udmVydHMgYSBOb2RlLmpzIGNhbGxiYWNrIHN0eWxlIGZ1bmN0aW9uIHRvIGFuIG9ic2VydmFibGUgc2VxdWVuY2UuICBUaGlzIG11c3QgYmUgaW4gZnVuY3Rpb24gKGVyciwgLi4uKSBmb3JtYXQuXHJcbiAgICAgKiBAcGFyYW0ge0Z1bmN0aW9ufSBmdW5jIFRoZSBmdW5jdGlvbiB0byBjYWxsXHJcbiAgICAgKiBAcGFyYW0ge1NjaGVkdWxlcn0gW3NjaGVkdWxlcl0gU2NoZWR1bGVyIHRvIHJ1biB0aGUgZnVuY3Rpb24gb24uIElmIG5vdCBzcGVjaWZpZWQsIGRlZmF1bHRzIHRvIFNjaGVkdWxlci50aW1lb3V0LlxyXG4gICAgICogQHBhcmFtIHtNaXhlZH0gW2NvbnRle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W9uIGhhbmRsZXIoZXJyKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlcnIpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHJlc3VsdHMgPSBzbGljZS5jYWxsKGFyZ3VtZW50cywgMSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoc2VsZWN0b3IpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0cyA9IHNlbGVjdG9yKHJlc3VsdHMpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJlc3VsdHMubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0cyA9IHJlc3VsdHNbMF07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHRzKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wb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Skge1xyXG4gICAgICAgIHZhbHVlc1tpXSA9IHhcclxuICAgICAgICB2YXIgcmVzO1xyXG4gICAgICAgIGhhc1ZhbHVlW2ldID0gdHJ1ZTtcclxuICAgICAgICBpZiAoaGFzVmFsdWVBbGwgfHwgKGhhc1ZhbHVlQWxsID0gaGFzVmFsdWUuZXZlcnkoaWRlbnRpdHkpKSkge1xyXG4gICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgcmVzID0gcmVzdWx0U2VsZWN0b3IuYXBwbHkobnVsbCwgdmFsdWVzKTtcclxuICAgICAgICAgIH0gY2F0Y2ggKGV4KSB7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzKTtcclxuICAgICAgICB9IGVsc2UgaWYgKGlzRG9uZSkge1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIHJldHVybiBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZShcclxuICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgbmV4dCh4LCAwKTtcclxuICAgICAgICAgIH0sXHJcbiAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBpc0RvbmUgPSB0cnVlO1xyXG4gICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgfSksXHJcbiAgICAgICAgc3ViamVjdC5zdWJzY3JpYmUoXHJcbiAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICBuZXh0KHgsIDEpO1xyXG4gICAgICAgICAgfSxcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlcikpXHJcbiAgICAgICAgKTtcclxuICAgIH0pO1xyXG4gIH1cclxuXHJcbiAgdmFyIFBhdXNhYmxlQnVmZmVyZWRPYnNlcnZhYmxlID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuXHJcbiAgICBpbmhlcml0cyhQYXVzYWJsZUJ1ZmZlcmVkT2JzZXJ2YWJsZSwgX3N1cGVyKTtcclxuXHJcbiAgICBmdW5jdGlvbiBzdWJzY3JpYmUob2JzZXJ2ZXIpIHtcclxuICAgICAgdmFyIHEgPSBbXSwgcHJldmlvdXMgPSB0cnVlO1xyXG4gICAgICBcclxuICAgICAgdmFyIHN1YnNjcmlwdGlvbiA9ICBcclxuICAgICAgICBjb21iaW5lTGF0ZXN0U291cmNlKFxyXG4gICAgICAgICAgdGhpcy5zb3VyY2UsXHJcbiAgICAgICAgICB0aGlzLnN1YmplY3QuZGlzdGluY3RVbnRpbENoYW5nZWQoKSwgXHJcbiAgICAgICAgICBmdW5jdGlvbiAoZGF0YSwgc2hvdWxkRmlyZSkge1xyXG4gICAgICAgICAgICByZXR1cm4geyBkYXRhOiBkYXRhLCBzaG91bGRGaXJlOiBzaG91bGRGaXJlIH07ICAgICAgXHJcbiAgICAgICAgICB9KVxyXG4gICAgICAgICAgLnN1YnNjcmliZShcclxuICAgICAgICAgICAgZnVuY3Rpb24gKHJlc3VsdHMpIHtcclxuICAgICAgICAgICAgICBpZiAocmVzdWx0cy5zaG91bGRGaXJlICYmIHByZXZpb3VzKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0cy5kYXRhKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgaWYgKHJlc3VsdHMuc2hvdWxkRmlyZSAmJiAhcHJldmlvdXMpIHtcclxuICAgICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBwcmV2aW91cyA9IHRydWU7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIGlmICghcmVzdWx0cy5zaG91bGRGaXJlICYmICFwcmV2aW91cykge1xyXG4gICAgICAgICAgICAgICAgcS5wdXNoKHJlc3VsdHMuZGF0YSk7XHJcbiAgICAgICAgICAgICAgfSBlbHNlIGlmICghcmVzdWx0cy5zaG91bGRGaXJlICYmIHByZXZpb3VzKSB7XHJcbiAgICAgICAgICAgICAgICBwcmV2aW91cyA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIH0sIFxyXG4gICAgICAgICAgICBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgLy8gRW1wdHkgYnVmZmVyIGJlZm9yZSBzZW5kaW5nIGVycm9yXHJcbiAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgIC8vIEVtcHR5IGJ1ZmZlciBiZWZvcmUgc2VuZGluZyBjb21wbGV0aW9uXHJcbiAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHEuc2hpZnQoKSk7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7ICAgICAgICAgICAgICBcclxuICAgICA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Y3QgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICB0aGlzLmVuYWJsZVF1ZXVlID0gZW5hYmxlUXVldWU7XHJcbiAgICAgICAgICAgIHRoaXMucXVldWUgPSBlbmFibGVRdWV1ZSA/IFtdIDogbnVsbDtcclxuICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWRDb3VudCA9IDA7XHJcbiAgICAgICAgICAgIHRoaXMucmVxdWVzdGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgdGhpcy5lcnJvciA9IG51bGw7XHJcbiAgICAgICAgICAgIHRoaXMuaGFzRmFpbGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuaGFzQ29tcGxldGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKENvbnRyb2xsZWRTdWJqZWN0LnByb3RvdHlwZSwgT2JzZXJ2ZXIsIHtcclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHRoaXMuaGFzQ29tcGxldGVkID0gdHJ1ZTtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuZW5hYmxlUXVldWUgfHwgdGhpcy5xdWV1ZS5sZW5ndGggPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnN1YmplY3Qub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmhhc0ZhaWxlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmVycm9yID0gZXJyb3I7XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmVuYWJsZVF1ZXVlIHx8IHRoaXMucXVldWUubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uRXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgfSAgIFxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgdmFyIGhhc1JlcXVlc3RlZCA9IGZhbHNlO1xyXG5cclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuZW5hYmxlUXVldWUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5xdWV1ZS5wdXNoKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnJlcXVlc3RlZENvdW50ICE9PSAtMSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5yZXF1ZXN0ZWRDb3VudC0tID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2VDdXJyZW50UmVxdWVzdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1JlcXVlc3RlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1JlcXVlc3RlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBfcHJvY2Vzc1JlcXVlc3Q6IGZ1bmN0aW9uIChudW1iZXJPZkl0ZW1zKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5lbmFibGVRdWV1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2coJ3F1ZXVlIGxlbmd0aCcsIHRoaXMucXVldWUubGVuZ3RoKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKHRoaXMucXVldWUubGVuZ3RoID49IG51bWJlck9mSXRlbXMgJiYgbnVtYmVyT2ZJdGVtcyA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZygnbnVtYmVyIG9mIGl0ZW1zJywgbnVtYmVyT2ZJdGVtcyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbk5leHQodGhpcy5xdWV1ZS5zaGlmdCgpKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbnVtYmVyT2ZJdGVtcy0tO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMucXVldWUubGVuZ3RoICE9PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB7IG51bWJlck9mSXRlbXM6IG51bWJlck9mSXRlbXMsIHJldHVyblZhbHVlOiB0cnVlIH07XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHsgbnVtYmVyT2ZJdGVtczogbnVtYmVyT2ZJdGVtcywgcmV0dXJuVmFsdWU6IGZhbHNlIH07XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmhhc0ZhaWxlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3ViamVjdC5vbkVycm9yKHRoaXMuZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY29udHJvbGxlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuaGFzQ29tcGxldGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdWJqZWN0Lm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZS5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb250cm9sbGVkRGlzcG9zYWJsZSA9IGRpc3Bvc2FibGVFbXB0eTsgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHsgbnVtYmVyT2ZJdGVtczogbnVtYmVyT2ZJdGVtcywgcmV0dXJuVmFsdWU6IGZhbHNlIH07XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIHJlcXVlc3Q6IGZ1bmN0aW9uIChudW1iZXIpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZUN1cnJlbnRSZXF1ZXN0KCk7XHJcbiAgICAgICAgICAgICAgICB2YXIgc2VsZiA9IHRoaXMsXHJcbiAgICAgICAgICAgICAgICAgICAgciA9IHRoaXMuX3Byb2Nlc3NSZXF1ZXN0KG51bWJlcik7XHJcblxyXG4gICAgICAgICAgICAgICAgbnVtYmVyID0gci5udW1iZXJPZkl0ZW1zO1xyXG4gICAgICAgICAgICAgICAgaWYgKCFyLnJldHVyblZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWRDb3VudCA9IG51bWJlcjtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGUgPSBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5yZXF1ZXN0ZWRDb3VudCA9IDA7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGVcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZGlzcG9zZUN1cnJlbnRSZXF1ZXN0OiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnJlcXVlc3RlZERpc3Bvc2FibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5yZXF1ZXN0ZWREaXNwb3NhYmxlID0gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICB9LFxyXG5cclxuICAgICAgICAgICAgZGlzcG9zZTogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IgPSBudWxsO1xyXG4g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1ZW50IG5vdGlmaWNhdGlvbnMuXHJcbiAgICAgKi9cclxuICAgIHZhciBCZWhhdmlvclN1YmplY3QgPSBSeC5CZWhhdmlvclN1YmplY3QgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG4gICAgICAgIGZ1bmN0aW9uIHN1YnNjcmliZShvYnNlcnZlcikge1xyXG4gICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzLnB1c2gob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHRoaXMudmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG5ldyBJbm5lclN1YnNjcmlwdGlvbih0aGlzLCBvYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgdmFyIGV4ID0gdGhpcy5leGNlcHRpb247XHJcbiAgICAgICAgICAgIGlmIChleCkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpbmhlcml0cyhCZWhhdmlvclN1YmplY3QsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqICBJbml0aWFsaXplcyBhIG5ldyBpbnN0YW5jZSBvZiB0aGUgQmVoYXZpb3JTdWJqZWN0IGNsYXNzIHdoaWNoIGNyZWF0ZXMgYSBzdWJqZWN0IHRoYXQgY2FjaGVz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ICAgICAgICAgICAgcmV0dXJuIHRoaXMub2JzZXJ2ZXJzLmxlbmd0aCA+IDA7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGVuZCBvZiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqLyBcclxuICAgICAgICAgICAgb25Db21wbGV0ZWQ6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBleGNlcHRpb24uXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IGVycm9yIFRoZSBleGNlcHRpb24gdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChlcnJvcikge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmV4Y2VwdGlvbiA9IGVycm9yO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25FcnJvcihlcnJvcik7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBhcnJpdmFsIG9mIHRoZSBzcGVjaWZpZWQgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IHZhbHVlIFRoZSB2YWx1ZSB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy52YWx1ZSA9IHZhbHVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIFVuc3Vic2NyaWJlIGFsbCBvYnNlcnZlcnMgYW5kIHJlbGVhc2UgcmVzb3VyY2VzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICBcclxuICAgICAgICAgICAgZGlzcG9zZTogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gbnVsbDtcclxuICAgICAgICAgICAgICAgIHRoaXMudmFsdWUgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBudWxsO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIHJldHVybiBCZWhhdmlvclN1YmplY3Q7XHJcbiAgICB9KE9ic2VydmFibGUpKTtcclxuXHJcbiAgICAvKipcclxuICAgICAqIFJlcHJlc2VudHMgYW4gb2JqZWN0IHRoYXQgaXMgYm90aCBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIGFzIHdlbGwgYXMgYW4gb2JzZXJ2ZXIuXHJcbiAgICAgKiBFYWNoIG5vdGlmaWNhdGlvbiBpcyBicm9hZGNhc3R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TtcclxuICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICB0aGlzLl90cmltKHRoaXMuc2NoZWR1bGVyLm5vdygpKTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMucHVzaChzbyk7XHJcblxyXG4gICAgICAgICAgICB2YXIgbiA9IHRoaXMucS5sZW5ndGg7XHJcblxyXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gdGhpcy5xLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBzby5vbk5leHQodGhpcy5xW2ldLnZhbHVlKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgaWYgKHRoaXMuaGFzRXJyb3IpIHtcclxuICAgICAgICAgICAgICAgIG4rKztcclxuICAgICAgICAgICAgICAgIHNvLm9uRXJyb3IodGhpcy5lcnJvcik7XHJcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIG4rKztcclxuICAgICAgICAgICAgICAgIHNvLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHNvLmVuc3VyZUFjdGl2ZShuKTtcclxuICAgICAgICAgICAgcmV0dXJuIHN1YnNjcmlwdGlvbjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGluaGVyaXRzKFJlcGxheVN1YmplY3QsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqICBJbml0aWFsaXplcyBhIG5ldyBpbnN0YW5jZSBvZiB0aGUgUmVwbGF5U3ViamVjdCBjbGFzcyB3aXRoIHRoZSBzcGVjaWZpZWQgYnVmZmVyIHNpemUsIHdpbmRvdyBzaXplIGFuZCBzY2hlZHVsZXIuXHJcbiAgICAgICAgICogIEBwYXJhbSB7TnVtYmVyfSBbYnVmZmVyU2l6ZV0gTWF4aW11bSBlbGVtZW50IGNvdW50IG9mIHRoZSByZXBsYXkgYnVmZmVyLlxyXG4gICAgICAgICAqICBAcGFyYW0ge051bWJlcn0gW3dpbmRvd1NpemVdIE1heGltdW0gdGltZSBsZW5ndGggb2YgdGhlIHJlcGxheSBidWZmZXIuXHJcbiAgICAgICAgICogIEBwYXJhbSB7U2NoZWR1bGVyfSBbc2NoZWR1bGVyXSBTY2hlZHVsZXIgdGhlIG9ic2VydmVycyBhcmUgaW52b2tlZCBvbi5cclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBSZXBsYXlTdWJqZWN0KGJ1ZmZlclNpemUsIHdpbmRvd1NpemUsIHNjaGVkdWxlcikge1xyXG4gICAgICAgICAgICB0aGlzLmJ1ZmZlclNpemUgPSBidWZmZXJTaXplID09IG51bGwgPyBOdW1iZXIuTUFYX1ZBTFVFIDogYnVmZmVyU2l6ZTtcclxuICAgICAgICAgICAgdGhpcy53aW5kb3dTaXplID0gd2luZG93U2l6ZSA9PSBudWxsID8gTnVtYmVyLk1BWF9WQUxVRSA6IHdpbmRvd1NpemU7XHJcbiAgICAgICAgICAgIHRoaXMuc2NoZWR1bGVyID0gc2NoZWR1bGVyIHx8IGN1cnJlbnRUaHJlYWRTY2hlZHVsZXI7XHJcbiAgICAgICAgICAgIHRoaXMucSA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5oYXNFcnJvciA9IGZhbHNlO1xyXG4gICAgICAgICAgICB0aGlzLmVycm9yID0gbnVsbDtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFkZFByb3BlcnRpZXMoUmVwbGF5U3ViamVjdC5wcm90b3R5cGUsIE9ic2VydmVyLCB7XHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqIEByZXR1cm5zIHtCb29sZWFufSBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgIFxyXG4gICAgICAgICAgICBoYXNPYnNlcnZlcnM6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLm9ic2VydmVycy5sZW5ndGggPiAwO1xyXG4gICAgICAgICAgICB9LCAgICAgICAgICAgIFxyXG4gICAgICAgICAgICAvKiBAcHJpdmF0ZSAgKi9cclxuICAgICAgICAgICAgX3RyaW06IGZ1bmN0aW9uIChub3cpIHtcclxuICAgICAgICAgICAgICAgIHdoaWxlICh0aGlzLnEubGVuZ3RoID4gdGhpcy5idWZmZXJTaXplKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5xLnNoaWZ0KCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB3aGlsZSAodGhpcy5xLmxlbmd0aCA+IDAgJiYgKG5vdyAtIHRoaXMucVswXS5pbnRlcnZhbCkgPiB0aGlzLndpbmRvd1NpemUpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgYXJyaXZhbCBvZiB0aGUgc3BlY2lmaWVkIGVsZW1lbnQgaW4gdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSB2YWx1ZSBUaGUgdmFsdWUgdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbk5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG9ic2VydmVyO1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBub3cgPSB0aGlzLnNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnEucHVzaCh7IGludGVydmFsOiBub3csIHZhbHVlOiB2YWx1ZSB9KTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLl90cmltKG5vdyk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG8ubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIgPSBvW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5lbnN1cmVBY3RpdmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGV4Y2VwdGlvbi5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gZXJyb3IgVGhlIGV4Y2VwdGlvbiB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChlcnJvcikge1xyXG4gICAgICAgICAgICAgICAgdmFyIG9ic2VydmVyO1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVycm9yID0gZXJyb3I7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5oYXNFcnJvciA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG5vdyA9IHRoaXMuc2NoZWR1bGVyLm5vdygpO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3RyaW0obm93KTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyID0gb1tpXTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnJvcik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLmVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBlbmQgb2YgdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgb2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBub3cgPSB0aGlzLnNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLl90cmltKG5vdyk7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG8gPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gby5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlciA9IG9baV07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLmVuc3VyZUFjdGl2ZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogVW5zdWJzY3JpYmUgYWxsIG9ic2VydmVycyBhbmQgcmVsZWFzZSByZXNvdXJjZXMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBkaXNwb3NlOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBudWxsO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIHJldHVybiBSZXBsYXlTdWJqZWN0O1xyXG4gICAgfShPYnNlcnZhYmxlKSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgQ29ubmVjdGFibGVPYnNlcnZhYmxlID0gUnguQ29ubmVjdGFibGVPYnNlcnZhYmxlID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcclxuICAgICAgICBpbmhlcml0cyhDb25uZWN0YWJsZU9ic2VydmFibGUsIF9zdXBlcik7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gQ29ubmVjdGFibGVPYnNlcnZhYmxlKHNvdXJjZSwgc3ViamVjdCkge1xyXG4gICAgICAgICAgICB2YXIgc3RhdGUgPSB7XHJcbiAgICAgICAgICAgICAgICBzdWJqZWN0OiBzdWJqZWN0LFxyXG4gICAgICAgICAgICAgICAgc291cmNlOiBzb3VyY2UuYXNPYnNlcnZhYmxlKCksXHJcbiAgICAgICAgICAgICAgICBoYXNTdWJzY3JpcHRpb246IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uOiBudWxsXHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICB0aGlzLmNvbm5lY3QgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXN0YXRlLmhhc1N1YnNjcmlwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgIHN0YXRlLmhhc1N1YnNjcmlwdGlvbiA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgc3RhdGUuc3Vic2NyaXB0aW9uID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3RhdGUuc291cmNlLnN1YnNjcmliZShzdGF0ZS5zdWJqZWN0KSwgZGlzcG9zYWJsZUNyZWF0ZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhhc1N1YnNjcmlwdGlvbiA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHJldHVybiBzdGF0ZS5zdWJzY3JpcHRpb247XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBmdW5jdGlvbiBzdWJzY3JpYmUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBzdGF0ZS5zdWJqZWN0LnN1YnNjcmliZShvYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBDb25uZWN0YWJsZU9ic2VydmFibGVcclxuICAgICAgICAgKi9cclxuICAgICAgICBDb25uZWN0YWJsZU9ic2VydmFibGUucHJvdG90eXBlLmNvbm5lY3QgPSBmdW5jdGlvbiAoKSB7IHJldHVybiB0aGlzLmNvbm5lY3QoKTsgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgQ29ubmVjdGFibGVPYnNlcnZhYmxlXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBDb25uZWN0YWJsZU9ic2VydmFibGUucHJvdG90eXBlLnJlZkNvdW50ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgY29ubmVjdGFibGVTdWJzY3JpcHRpb24gPSBudWxsLCBjb3VudCA9IDAsIHNvdXJjZSA9IHRoaXM7XHJcbiAgICAgICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgICAgIHZhciBzaG91bGRDb25uZWN0LCBzdWJzY3JpcHRpb247XHJcbiAgICAgICAgICAgICAgICBjb3VudCsrO1xyXG4gICAgICAgICAgICAgICAgc2hvdWxkQ29ubmVjdCA9IGNvdW50ID09PSAxO1xyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uID0gc291cmNlLnN1YnNjcmliZShvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICBpZiAoc2hvdWxkQ29ubmVjdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGNvbm5lY3RhYmxlU3Vic2NyaXB0aW9uID0gc291cmNlLmNvbm5lY3QoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlQ3JlYXRlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGNvdW50LS07XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGNvdW50ID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbm5lY3RhYmxlU3Vic2NyaXB0aW9uLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgIC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gICAgICAgbnVtMiArPSAyO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gdHJ1ZTtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBnZXRQcmltZShtaW4pIHtcclxuICAgICAgICB2YXIgaW5kZXgsIG51bSwgY2FuZGlkYXRlO1xyXG4gICAgICAgIGZvciAoaW5kZXggPSAwOyBpbmRleCA8IHByaW1lcy5sZW5ndGg7ICsraW5kZXgpIHtcclxuICAgICAgICAgICAgbnVtID0gcHJpbWVzW2luZGV4XTtcclxuICAgICAgICAgICAgaWYgKG51bSA+PSBtaW4pIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBudW07XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgY2FuZGlkYXRlID0gbWluIHwgMTtcclxuICAgICAgICB3aGlsZSAoY2FuZGlkYXRlIDwgcHJpbWVzW3ByaW1lcy5sZW5ndGggLSAxXSkge1xyXG4gICAgICAgICAgICBpZiAoaXNQcmltZShjYW5kaWRhdGUpKSB7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gY2FuZGlkYXRlO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGNhbmRpZGF0ZSArPSAyO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbWluO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIHN0cmluZ0hhc2hGbihzdHIpIHtcclxuICAgICAgICB2YXIgaGFzaCA9IDc1NzYwMjA0NjtcclxuICAgICAgICBpZiAoIXN0ci5sZW5ndGgpIHtcclxuICAgICAgICAgICAgcmV0dXJuIGhhc2g7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBzdHIubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgdmFyIGNoYXJhY3RlciA9IHN0ci5jaGFyQ29kZUF0KGkpO1xyXG4gICAgICAgICAgICBoYXNoID0gKChoYXNoPDw1KS1oYXNoKStjaGFyYWN0ZXI7XHJcbiAgICAgICAgICAgIGhhc2ggPSBoYXNoICYgaGFzaDtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIGhhc2g7XHJcbiAgICB9XHJcblxyXG4gICAgZnVuY3Rpb24gbnVtYmVySGFzaEZuKGtleSkge1xyXG4gICAgICAgIHZhciBjMiA9IDB4MjdkNGViMmQ7IFxyXG4gICAgICAgIGtleSA9IChrZXkgXiA2MSkgXiAoa2V5ID4+PiAxNik7XHJcbiAgICAgICAga2V5ID0ga2V5ICsgKGtleSA8PCAzKTtcclxuICAgICAgICBrZXkgPSBrZXkgXiAoa2V5ID4+PiA0KTtcclxuICAgICAgICBrZXkgPSBrZXkgKiBjMjtcclxuICAgICAgICBrZXkgPSBrZXkgXiAoa2V5ID4+PiAxNSk7XHJcbiAgICAgICAgcmV0dXJuIGtleTtcclxuICAgIH1cclxuXHJcbiAgICB2YXIgZ2V0SGFzaENvZGUgPSAoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciB1bmlxdWVJZENvdW50ZXIgPSAwO1xyXG5cclxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKG9iaikge1xyXG4gICAgICAgICAgICBpZiAob2JqID09IG51bGwpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3Iobm9TdWNoa2V5KTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgLy8gQ2hlY2sgZm9yIGJ1aWx0LWlucyBiZWZvcmUgdGFja2luZyBvbiBvdXIgb3duIGZvciBhbnkgb2JqZWN0XHJcbiAgICAgICAgICAgIGlmICh0eXBlb2Ygb2JqID09PSAnc3RyaW5nJykge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIHN0cmluZ0hhc2hGbihvYmopO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBpZiAodHlwZW9mIG9iaiA9PT0gJ251bWJlcicpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBudW1iZXJIYXNoRm4ob2JqKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgaWYgKHR5cGVvZiBvYmogPT09ICdib29sZWFuJykge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG9iaiA9PT0gdHJ1ZSA/IDEgOiAwO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICBpZiAob2JqIGluc3RhbmNlb2YgRGF0ZSkge1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG9iai5nZXRUaW1lKCk7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIGlmIChvYmouZ2V0SGFzaENvZGUpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiBvYmouZ2V0SGFzaENvZGUoKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdmFyIGlkID0gMTcgKiB1bmlxdWVJZENvdW50ZXIrKztcclxuICAgICAgICAgICAgb2JqLmdldEhhc2hDb2RlID0gZnVuY3Rpb24gKCkgeyByZXR1cm4gaWQ7IH07XHJcbiAgICAgICAgICAgIHJldHVybiBpZDtcclxuICAgICAgICB9O1xyXG4gICAgfSAoKSk7XHJcblxyXG4gICAgZnVuY3Rpb24gbmV3RW50cnkoKSB7XHJcbiAgICAgICAgcmV0dXJuIHsga2V5OiBudWxsLCB2YWx1ZTogbnVsbCwgbmV4dDogMCwgaGFzaENvZGU6IDAgfTtcclxuICAgIH1cclxuXHJcbiAgICAvLyBEaWN0aW9uYXJ5IGltcGxlbWVudGF0aW9uXHJcblxyXG4gICAgdmFyIERpY3Rpb25hcnkgPSBmdW5jdGlvbiAoY2FwYWNpdHksIGNvbXBhcmVyKSB7XHJcbiAgICAgICAgaWYgKGNhcGFjaXR5IDwgMCkge1xyXG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ291dCBvZiByYW5nZScpXHJcbiAgICAgICAgfVxyXG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iAgICBEaWN0aW9uYXJ5LnByb3RvdHlwZS5faW5zZXJ0ID0gZnVuY3Rpb24gKGtleSwgdmFsdWUsIGFkZCkge1xyXG4gICAgICAgIGlmICghdGhpcy5idWNrZXRzKSB7XHJcbiAgICAgICAgICAgIHRoaXMuX2luaXRpYWxpemUoMCk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBpbmRleDM7XHJcbiAgICAgICAgdmFyIG51bSA9IGdldEhhc2hDb2RlKGtleSkgJiAyMTQ3NDgzNjQ3O1xyXG4gICAgICAgIHZhciBpbmRleDEgPSBudW0gJSB0aGlzLmJ1Y2tldHMubGVuZ3RoO1xyXG4gICAgICAgIGZvciAodmFyIGluZGV4MiA9IHRoaXMuYnVja2V0c1tpbmRleDFdOyBpbmRleDIgPj0gMDsgaW5kZXgyID0gdGhpcy5lbnRyaWVzW2luZGV4Ml0ubmV4dCkge1xyXG4gICAgICAgICAgICBpZiAodGhpcy5lbnRyaWVzW2luZGV4Ml0uaGFzaENvZGUgPT09IG51bSAmJiB0aGlzLmNvbXBhcmVyKHRoaXMuZW50cmllc1tpbmRleDJdLmtleSwga2V5KSkge1xyXG4gICAgICAgICAgICAgICAgaWYgKGFkZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihkdXBsaWNhdGVrZXkpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4Ml0udmFsdWUgPSB2YWx1ZTtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAodGhpcy5mcmVlQ291bnQgPiAwKSB7XHJcbiAgICAgICAgICAgIGluZGV4MyA9IHRoaXMuZnJlZUxpc3Q7XHJcbiAgICAgICAgICAgIHRoaXMuZnJlZUxpc3QgPSB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0O1xyXG4gICAgICAgICAgICAtLXRoaXMuZnJlZUNvdW50O1xyXG4gICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgIGlmICh0aGlzLnNpemUgPT09IHRoaXMuZW50cmllcy5sZW5ndGgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuX3Jlc2l6ZSgpO1xyXG4gICAgICAgICAgICAgICAgaW5kZXgxID0gbnVtICUgdGhpcy5idWNrZXRzLmxlbmd0aDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBpbmRleDMgPSB0aGlzLnNpemU7XHJcbiAgICAgICAgICAgICsrdGhpcy5zaXplO1xyXG4gICAgICAgIH1cclxuICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5oYXNoQ29kZSA9IG51bTtcclxuICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0ID0gdGhpcy5idWNrZXRzW2luZGV4MV07XHJcbiAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10ua2V5ID0ga2V5O1xyXG4gICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLnZhbHVlID0gdmFsdWU7XHJcbiAgICAgICAgdGhpcy5idWNrZXRzW2luZGV4MV0gPSBpbmRleDM7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLl9yZXNpemUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgdmFyIHByaW1lID0gZ2V0UHJpbWUodGhpcy5zaXplICogMiksXHJcbiAgICAgICAgICAgIG51bUFycmF5ID0gbmV3IEFycmF5KHByaW1lKTtcclxuICAgICAgICBmb3IgKGluZGV4ID0gMDsgaW5kZXggPCBudW1BcnJheS5sZW5ndGg7ICsraW5kZXgpIHtcclxuICAgICAgICAgICAgbnVtQXJyYXlbaW5kZXhdID0gLTE7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBlbnRyeUFycmF5ID0gbmV3IEFycmF5KHByaW1lKTtcclxuICAgICAgICBmb3IgKGluZGV4ID0gMDsgaW5kZXggPCB0aGlzLnNpemU7ICsraW5kZXgpIHtcclxuICAgICAgICAgICAgZW50cnlBcnJheVtpbmRleF0gPSB0aGlzLmVudHJpZXNbaW5kZXhdO1xyXG4gICAgICAgIH1cclxuICAgICAgICBmb3IgKHZhciBpbmRleCA9IHRoaXMuc2l6ZTsgaW5kZXggPCBwcmltZTsgKytpbmRleCkge1xyXG4gICAgICAgICAgICBlbnRyeUFycmF5W2luZGV4XSA9IG5ld0VudHJ5KCk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGZvciAodmFyIGluZGV4MSA9IDA7IGluZGV4MSA8IHRoaXMuc2l6ZTsgKytpbmRleDEpIHtcclxuICAgICAgICAgICAgdmFyIGluZGV4MiA9IGVudHJ5QXJyYXlbaW5kZXgxXS5oYXNoQ29kZSAlIHByaW1lO1xyXG4gICAgICAgICAgICBlbnRyeUFycmF5W2luZGV4MV0ubmV4dCA9IG51bUFycmF5W2luZGV4Ml07XHJcbiAgICAgICAgICAgIG51bUFycmF5W2luZGV4Ml0gPSBpbmRleDE7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHRoaXMuYnVja2V0cyA9IG51bUFycmF5O1xyXG4gICAgICAgIHRoaXMuZW50cmllcyA9IGVudHJ5QXJyYXk7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLnJlbW92ZSA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgICBpZiAodGhpcy5idWNrZXRzKSB7XHJcbiAgICAgICAgICAgIHZhciBudW0gPSBnZXRIYXNoQ29kZShrZXkpICYgMjE0NzQ4MzY0NztcclxuICAgICAgICAgICAgdmFyIGluZGV4MSA9IG51bSAlIHRoaXMuYnVja2V0cy5sZW5ndGg7XHJcbiAgICAgICAgICAgIHZhciBpbmRleDIgPSAtMTtcclxuICAgICAgICAgICAgZm9yICh2YXIgaW5kZXgzID0gdGhpcy5idWNrZXRzW2luZGV4MV07IGluZGV4MyA+PSAwOyBpbmRleDMgPSB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5lbnRyaWVzW2luZGV4M10uaGFzaENvZGUgPT09IG51bSAmJiB0aGlzLmNvbXBhcmVyKHRoaXMuZW50cmllc1tpbmRleDNdLmtleSwga2V5KSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpbmRleDIgPCAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuYnVja2V0c1tpbmRleDFdID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgyXS5uZXh0ID0gdGhpcy5lbnRyaWVzW2luZGV4M10ubmV4dDtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbnRyaWVzW2luZGV4M10uaGFzaENvZGUgPSAtMTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5uZXh0ID0gdGhpcy5mcmVlTGlzdDtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXgzXS5rZXkgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW50cmllc1tpbmRleDNdLnZhbHVlID0gbnVsbDtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmZyZWVMaXN0ID0gaW5kZXgzO1xyXG4gICAgICAgICAgICAgICAgICAgICsrdGhpcy5mcmVlQ291bnQ7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIGluZGV4MiA9IGluZGV4MztcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gZmFsc2U7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLmNsZWFyID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBpbmRleCwgbGVuO1xyXG4gICAgICAgIGlmICh0aGlzLnNpemUgPD0gMCkge1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGZvciAoaW5kZXggPSAwLCBsZW4gPSB0aGlzLmJ1Y2tldHMubGVuZ3RoOyBpbmRleCA8IGxlbjsgKytpbmRleCkge1xyXG4gICAgICAgICAgICB0aGlzLmJ1Y2tldHNbaW5kZXhdID0gLTE7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGZvciAoaW5kZXggPSAwOyBpbmRleCA8IHRoaXMuc2l6ZTsgKytpbmRleCkge1xyXG4gICAgICAgICAgICB0aGlzLmVudHJpZXNbaW5kZXhdID0gbmV3RW50cnkoKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgdGhpcy5mcmVlTGlzdCA9IC0xO1xyXG4gICAgICAgIHRoaXMuc2l6ZSA9IDA7XHJcbiAgICB9O1xyXG5cclxuICAgIERpY3Rpb25hcnkucHJvdG90eXBlLl9maW5kRW50cnkgPSBmdW5jdGlvbiAoa2V5KSB7XHJcbiAgICAgICAgaWYgKHRoaXMuYnVja2V0cykge1xyXG4gICAgICAgICAgICB2YXIgbnVtID0gZ2V0SGFzaENvZGUoa2V5KSAmIDIxNDc0ODM2NDc7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGluZGV4ID0gdGhpcy5idWNrZXRzW251bSAlIHRoaXMuYnVja2V0cy5sZW5ndGhdOyBpbmRleCA+PSAwOyBpbmRleCA9IHRoaXMuZW50cmllc1tpbmRleF0ubmV4dCkge1xyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuZW50cmllc1tpbmRleF0uaGFzaENvZGUgPT09IG51bSAmJiB0aGlzLmNvbXBhcmVyKHRoaXMuZW50cmllc1tpbmRleF0ua2V5LCBrZXkpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGluZGV4O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHJldHVybiAtMTtcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUuY291bnQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgcmV0dXJuIHRoaXMuc2l6ZSAtIHRoaXMuZnJlZUNvdW50O1xyXG4gICAgfTtcclxuXHJcbiAgICBEaWN0aW9uYXJ5LnByb3RvdHlwZS50cnlHZXRWYWx1ZSA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgICB2YXIgZW50cnkgPSB0aGlzLl9maW5kRW50cnkoa2V5KTtcclxuICAgICAgICBpZiAoZW50cnkgPj0gMCkge1xyXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5lbnRyaWVzW2VudHJ5XS52YWx1ZTtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIHVuZGVmaW5lZDtcclxuICAgIH07XHJcblxyXG4gICAgRGljdGlvbmFyeS5wcm90b3R5cGUuZ2V0VmFsdWVzID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBpbmRleCA9IDAsIHJlc3VsdHMgPSBbXTtcclxuICAgICAgICBpZiAodGhpcy5lbnRyaWVzKSB7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGluZGV4MSA9IDA7IGluZGV4MSA8IHRoaXMuc2l6ZTsgaW5kZXgxKyspIHtcclxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmVudHJpZXNbaW5kZXgxXS5oYXNoQ29kZSA+PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0c1tpbmRleCsrXSA9IHRoaXMuZW50cmllc1tpbmRleDFdLnZhbHVlO1xyXG4gICAgICAgICAgIC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mxlUHJvdG8uam9pbiA9IGZ1bmN0aW9uIChyaWdodCwgbGVmdER1cmF0aW9uU2VsZWN0b3IsIHJpZ2h0RHVyYXRpb25TZWxlY3RvciwgcmVzdWx0U2VsZWN0b3IpIHtcclxuICAgICAgICB2YXIgbGVmdCA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgZ3JvdXAgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICBsZWZ0RG9uZSA9IGZhbHNlLFxyXG4gICAgICAgICAgICBsZWZ0SWQgPSAwLFxyXG4gICAgICAgICAgICBsZWZ0TWFwID0gbmV3IERpY3Rpb25hcnkoKSxcclxuICAgICAgICAgICAgcmlnaHREb25lID0gZmFsc2UsXHJcbiAgICAgICAgICAgIHJpZ2h0SWQgPSAwLFxyXG4gICAgICAgICAgICByaWdodE1hcCA9IG5ldyBEaWN0aW9uYXJ5KCk7XHJcbiAgICAgICAgICAgIGdyb3VwLmFkZChsZWZ0LnN1YnNjcmliZShmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHZhciBkdXJhdGlvbixcclxuICAgICAgICAgICAgICAgIGV4cGlyZSxcclxuICAgICAgICAgICAgICAgIGlkID0gbGVmdElkKyssXHJcbiAgICAgICAgICAgICAgICBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgcmVzdWx0LFxyXG4gICAgICAgICAgICAgICAgdmFsdWVzO1xyXG4gICAgICAgICAgICAgICAgbGVmdE1hcC5hZGQoaWQsIHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcbiAgICAgICAgICAgICAgICBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGxlZnRNYXAucmVtb3ZlKGlkKSAmJiBsZWZ0TWFwLmNvdW50KCkgPT09IDAgJiYgbGVmdERvbmUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbiA9IGxlZnREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkgeyBleHBpcmUoKTsgfSkpO1xyXG4gICAgICAgICAgICAgICAgdmFsdWVzID0gcmlnaHRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHZhbHVlcy5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHZhbHVlLCB2YWx1ZXNbaV0pO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGxlZnREb25lID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIGlmIChyaWdodERvbmUgfHwgbGVmdE1hcC5jb3VudCgpID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICBncm91cC5hZGQocmlnaHQuc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uLFxyXG4gICAgICAgICAgICAgICAgZXhwaXJlLFxyXG4gICAgICAgICAgICAgICAgaWQgPSByaWdodElkKyssXHJcbiAgICAgICAgICAgICAgICBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgcmVzdWx0LFxyXG4gICAgICAgICAgICAgICAgdmFsdWVzO1xyXG4gICAgICAgICAgICAgICAgcmlnaHRNYXAuYWRkKGlkLCB2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICBncm91cC5hZGQobWQpO1xyXG4gICAgICAgICAgICAgICAgZXhwaXJlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChyaWdodE1hcC5yZW1vdmUoaWQpICYmIHJpZ2h0TWFwLmNvdW50KCkgPT09IDAgJiYgcmlnaHREb25lKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBncm91cC5yZW1vdmUobWQpO1xyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZHVyYXRpb24gPSByaWdodER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG1kLnNldERpc3Bvc2FibGUoZHVyYXRpb24udGFrZSgxKS5zdWJzY3JpYmUobm9vcCwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkgeyBleHBpcmUoKTsgfSkpO1xyXG4gICAgICAgICAgICAgICAgdmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgdmFsdWVzLmxlbmd0aDsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3IodmFsdWVzW2ldLCB2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAg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CwgbGVmdER1cmF0aW9uU2VsZWN0b3IsIHJpZ2h0RHVyYXRpb25TZWxlY3RvciwgcmVzdWx0U2VsZWN0b3IpIHtcclxuICAgICAgICB2YXIgbGVmdCA9IHRoaXM7XHJcbiAgICAgICAgcmV0dXJuIG5ldyBBbm9ueW1vdXNPYnNlcnZhYmxlKGZ1bmN0aW9uIChvYnNlcnZlcikge1xyXG4gICAgICAgICAgICB2YXIgbm90aGluZyA9IGZ1bmN0aW9uICgpIHt9O1xyXG4gICAgICAgICAgICB2YXIgZ3JvdXAgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICB2YXIgciA9IG5ldyBSZWZDb3VudERpc3Bvc2FibGUoZ3JvdXApO1xyXG4gICAgICAgICAgICB2YXIgbGVmdE1hcCA9IG5ldyBEaWN0aW9uYXJ5KCk7XHJcbiAgICAgICAgICAgIHZhciByaWdodE1hcCA9IG5ldyBEaWN0aW9uYXJ5KCk7XHJcbiAgICAgICAgICAgIHZhciBsZWZ0SUQgPSAwO1xyXG4gICAgICAgICAgICB2YXIgcmlnaHRJRCA9IDA7XHJcblxyXG4gICAgICAgICAgICBncm91cC5hZGQobGVmdC5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGlkID0gbGVmdElEKys7XHJcbiAgICAgICAgICAgICAgICAgICAgbGVmdE1hcC5hZGQoaWQsIHMpO1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBpLCBsZW4sIGxlZnRWYWx1ZXMsIHJpZ2h0VmFsdWVzO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdFNlbGVjdG9yKHZhbHVlLCBhZGRSZWYocywgcikpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGxlZnRWYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXNbaV0ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICByaWdodFZhbHVlcyA9IHJpZ2h0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IHJpZ2h0VmFsdWVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHMub25OZXh0KHJpZ2h0VmFsdWVzW2ldKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZWZ0TWFwLnJlbW92ZShpZCkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uID0gbGVmdER1cmF0aW9uU2VsZWN0b3IodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGxlZnRNYXAubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXNbaV0ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBub3RoaW5nLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBsZWZ0VmFsdWVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgICAgICAgICAgZXhwaXJlKVxyXG4gICAgICAgICAgICAgICAgICAgICk7XHJcbiAgICAgICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGxlZnRWYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkLmJpbmQob2JzZXJ2ZXIpKSk7XHJcblxyXG4gICAgICAgICAgICBncm91cC5hZGQocmlnaHQuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGxlZnRWYWx1ZXMsIGksIGxlbjtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgaWQgPSByaWdodElEKys7XHJcbiAgICAgICAgICAgICAgICAgICAgcmlnaHRNYXAuYWRkKGlkLCB2YWx1ZSk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBtZCA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGdyb3VwLmFkZChtZCk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBleHBpcmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJpZ2h0TWFwLnJlbW92ZShpZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwLnJlbW92ZShtZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uID0gcmlnaHREdXJhdGlvblNlbGVjdG9yKHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBsZWZ0TWFwLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZWZ0VmFsdWVzW2ldLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBtZC5zZXREaXNwb3NhYmxlKGR1cmF0aW9uLnRha2UoMSkuc3Vic2NyaWJlKFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBub3RoaW5nLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlcyA9IGxlZnRNYXAuZ2V0VmFsdWVzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBsZWZ0TWFwLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgICAgICAgICAgZXhwaXJlKVxyXG4gICAgICAgICAgICAgICAgICAgICk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGxlZnRWYWx1ZXMgPSBsZWZ0TWFwLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGxlZnRWYWx1ZXMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgbGVmdFZhbHVlc1tpXS5vbk5leHQodmFsdWUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBsZWZ0VmFsdWVzID0gbGVmdE1hcC5nZXRWYWx1ZXMoKTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgK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ICAgICB3aW5kb3cub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pKTtcclxuXHJcbiAgICAgICAgICAgIGQuYWRkKHdpbmRvd0JvdW5kYXJpZXMuc3Vic2NyaWJlKGZ1bmN0aW9uICh3KSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIHdpbmRvdyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHdpbmRvdywgcikpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlcnIpO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB3aW5kb3cub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0pKTtcclxuXHJcbiAgICAgICAgICAgIHJldHVybiByO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfVxyXG5cclxuICAgIGZ1bmN0aW9uIG9ic2VydmFibGVXaW5kb3dXaXRoQ2xvc2luZ1NlbGVjdG9yKHdpbmRvd0Nsb3NpbmdTZWxlY3Rvcikge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGNyZWF0ZVdpbmRvd0Nsb3NlLFxyXG4gICAgICAgICAgICAgICAgbSA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICBkID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUobSksXHJcbiAgICAgICAgICAgICAgICByID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShkKSxcclxuICAgICAgICAgICAgICAgIHdpbmRvdyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYod2luZG93LCByKSk7XHJcbiAgICAgICAgICAgIGQuYWRkKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uIChleCkge1xyXG4gICAgICAgICAgICAgICAgd2luZG93Lm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleCk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHdpbmRvdy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICBjcmVhdGVXaW5kb3dDbG9zZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBtMSwgd2luZG93Q2xvc2U7XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIHdpbmRvd0Nsb3NlID0gd2luZG93Q2xvc2luZ1NlbGVjdG9yKCk7XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgbTEgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgIG0uc2V0RGlzcG9zYWJsZShtMSk7XHJcbiAgICAgICAgICAgICAgICBtMS5zZXREaXNwb3NhYmxlKHdpbmRvd0Nsb3NlLnRha2UoMSkuc3Vic2NyaWJlKG5vb3AsIGZ1bmN0aW9uIChleCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHdpbmRvdy5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGV4KTtcclxuICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICB3aW5kb3cub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB3aW5kb3cgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYod2luZG93LCByKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgY3JlYXRlV2luZG93Q2xvc2UoKTtcclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgY3JlYXRlV2luZG93Q2xvc2UoKTtcclxuICAgICAgICAgICAgcmV0dXJuIHI7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9XHJcblxyXG4gIC8qKlxyXG4gICAqIFJldHVybnMgYSBuZXcgb2JzZXJ2YWJsZSB0aGF0IHRyaWdnZXJzIG9uIHRoZSBzZWNvbmQgYW5kIHN1YnNlcXVlbnQgdHJpZ2dlcmluZ3Mgb2YgdGhlIGlucHV0IG9ic2Vyd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iAgICAgICAgc2NoZWR1bGVyIHx8IChzY2hlZHVsZXIgPSBpbW1lZGlhdGVTY2hlZHVsZXIpO1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIHEgPSBbXSxcclxuICAgICAgICAgICAgICAgIG0gPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpLFxyXG4gICAgICAgICAgICAgICAgZCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKG0pLFxyXG4gICAgICAgICAgICAgICAgYWN0aXZlQ291bnQgPSAwLFxyXG4gICAgICAgICAgICAgICAgaXNBY3F1aXJlZCA9IGZhbHNlO1xyXG5cclxuICAgICAgICAgICAgdmFyIGVuc3VyZUFjdGl2ZSA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBpc093bmVyID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNPd25lciA9ICFpc0FjcXVpcmVkO1xyXG4gICAgICAgICAgICAgICAgICAgIGlzQWNxdWlyZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGlzT3duZXIpIHtcclxuICAgICAgICAgICAgICAgICAgICBtLnNldERpc3Bvc2FibGUoc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlKGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciB3b3JrO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAocS5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB3b3JrID0gcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaXNBY3F1aXJlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBtMSA9IG5ldyBTaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkLmFkZChtMSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG0xLnNldERpc3Bvc2FibGUod29yay5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhciByZXN1bHQgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSBzZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY3RpdmVDb3VudCsrO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZW5zdXJlQWN0aXZlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGQucmVtb3ZlKG0xKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFjdGl2ZUNvdW50LS07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYWN0aXZlQ291bnQgPT09IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBxLnB1c2goc291cmNlKTtcclxuICAgICAgICAgICAgYWN0aXZlQ291bnQrKztcclxuICAgICAgICAgICAgZW5zdXJlQWN0aXZlKCk7XHJcbiAgICAgICAgICAgIHJldHVybiBkO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgIC8qKlxyXG4gICAqICBSdW5zIGFsbCBvYnNlcnZhYmxlIHNlcXVlbmNlcyBpbiBwYXJhbGxlbCBhbmQgY29sbGVjdCB0aGVpciBsYXN0IGVsZW1lbnRzLlxyXG4gICAqICBcclxuICAgKiBAZXhhbXBsZVxyXG4gICAqICAxIC0gcmVzID0gUnguT2JzZXJ2YWJsZS5mb3JrSm9pbihbb2JzMSwgb2JzMl0pO1xyXG4gICAqICAxIC0gcmVzID0gUnguT2JzZXJ2YWJsZS5mb3JrSm9pbihvYnMxLCBvYnMyLCAuLi4pOyAgXHJcbiAgICogQHJldHVybnMge09ic2VydmFibGV9IEFuIG9ic2VydmFibGUgc2VxdWVuY2Ugd2l0aCBhbiBhcnJheSBjb2xsZWN0aW5nIHRoZSBsYXN0IGVsZW1lbnRzIG9mIGFsbCB0aGUgaW5wdXQgc2VxdWVuY2VzLlxyXG4gICAqL1xyXG4gIE9ic2VydmFibGUuZm9ya0pvaW4gPSBmdW5jdGlvbiAoKSB7XHJcbiAgICB2YXIgYWxsU291cmNlcyA9IGFyZ3NPckFycmF5KGFyZ3VtZW50cywgMCk7XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcclxuICAgICAgdmFyIGNvdW50ID0gYWxsU291cmNlcy5sZW5ndGg7XHJcbiAgICAgIGlmIChjb3VudCA9PT0gMCkge1xyXG4gICAgICAgIHN1YnNjcmliZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICB9XHJcbiAgICAgIHZhciBncm91cCA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgZmluaXNoZWQgPSBmYWxzZSxcclxuICAgICAgICBoYXNSZXN1bHRzID0gbmV3IEFycmF5KGNvdW50KSxcclxuICAgICAgICBoYXNDb21wbGV0ZWQgPSBuZXcgQXJyYXkoY291bnQpLFxyXG4gICAgICAgIHJlc3VsdHMgPSBuZXcgQXJyYXkoY291bnQpO1xyXG5cclxuICAgICAgZm9yICh2YXIgaWR4ID0gMDsgaWR4IDwgY291bnQ7IGlkeCsrKSB7XHJcbiAgICAgICAgKGZ1bmN0aW9uIChpKSB7XHJcbiAgICAgICAgICB2YXIgc291cmNlID0gYWxsU291cmNlc1tpXTtcclxuICAgICAgICAgIGlzUHJvbWlzZShzb3VyY2UpICYmIChzb3VyY2UgPSBvYnNlcnZhYmxlRnJvbVByb21pc2Uoc291cmNlKSk7XHJcbiAgICAgICAgICBncm91cC5hZGQoXHJcbiAgICAgICAgICAgIHNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgaWYgKCFmaW5pc2hlZCkge1xyXG4gICAgICAgICAgICAgICAgaGFzUmVzdWx0c1tpXSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICByZXN1bHRzW2ldID0gdmFsdWU7XHJcbiAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBcclxuICAgICAgICAgICAgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICBmaW5pc2hlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgc3Vic2NyaWJlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgIGdyb3VwLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfSwgXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICBpZiAoIWZpbmlzaGVkKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIWhhc1Jlc3VsdHNbaV0pIHtcclxuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaGFzQ29tcGxldGVkW2ldID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIGl4ID0gMDsgaXggPCBjb3VudDsgaXgrKykge1xyXG4gICAgICAgICAgICAgICAgICBpZiAoIWhhc0NvbXBsZXRlZFtpeF0pIHsgcmV0dXJuOyB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBmaW5pc2hlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm9uTmV4dChyZXN1bHRzKTtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pKTtcclxuICAgICAgICB9KShpZHgpO1xyXG4gICAgICB9XHJcblxyXG4gICAgICByZXR1cm4gZ3JvdXA7XHJcbiAgICB9KTtcclxuICB9O1xyXG5cclxuICAgLyoqXHJcbiA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ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgIH0pXHJcbiAgICAgICk7XHJcblxyXG4gICAgICByaWdodFN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKFxyXG4gICAgICAgIHNlY29uZC5zdWJzY3JpYmUoZnVuY3Rpb24gKHJpZ2h0KSB7XHJcbiAgICAgICAgICBoYXNSaWdodCA9IHRydWU7XHJcbiAgICAgICAgICBsYXN0UmlnaHQgPSByaWdodDtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoZXJyKSB7XHJcbiAgICAgICAgICBsZWZ0U3Vic2NyaXB0aW9uLmRpc3Bvc2UoKTtcclxuICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyKTtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICByaWdodFN0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgaWYgKGxlZnRTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgIGlmICghaGFzTGVmdCkge1xyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIWhhc1JpZ2h0KSB7XHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihsYXN0TGVmdCwgbGF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VyIHx8IChzY2hlZHVsZXIgPSBpbW1lZGlhdGVTY2hlZHVsZXIpO1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBvYnNlcnZhYmxlRGVmZXIoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgY2hhaW47XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gc291cmNlXHJcbiAgICAgICAgICAgICAgICAuc2VsZWN0KFxyXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uICh4KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBjdXJyID0gbmV3IENoYWluT2JzZXJ2YWJsZSh4KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNoYWluKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGFpbi5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgY2hhaW4gPSBjdXJyO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGN1cnI7XHJcbiAgICAgICAgICAgICAgICAgICAgfSlcclxuICAgICAgICAgICAgICAgIC5kb0FjdGlvbihcclxuICAgICAgICAgICAgICAgICAgICBub29wLFxyXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjaGFpbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hhaW4ub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoY2hhaW4pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoYWluLm9uQ29tcGxldGVkKCk7XH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AgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKENoYWluT2JzZXJ2YWJsZS5wcm90b3R5cGUsIE9ic2VydmVyLCB7XHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9uTmV4dChPYnNlcnZhYmxlLmVtcHR5KCkpO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vbk5leHQoT2JzZXJ2YWJsZS50aHJvd0V4Y2VwdGlvbihlKSk7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHYpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMudGFpbC5vbk5leHQodik7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnRhaWwub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG5cclxuICAgICAgICByZXR1cm4gQ2hhaW5PYnNlcnZhYmxlO1xyXG5cclxuICAgIH0oT2JzZXJ2YWJsZSkpO1xyXG5cclxuICAgIC8qKiBAcHJpdmF0ZSAqL1xyXG4gICAgdmFyIE1hcCA9IChmdW5jdGlvbiAoKSB7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gTWFwKCkge1xyXG4gICAgICAgICAgICB0aGlzLmtleXMgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy52YWx1ZXMgPSBbXTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi9cclxuICAgICAgICBNYXAucHJvdG90eXBlWydkZWxldGUnXSA9IGZ1bmN0aW9uIChrZXkpIHtcclxuICAgICAgICAgICAgdmFyIGkgPSB0aGlzLmtleXMuaW5kZXhPZihrZXkpO1xyXG4gICAgICAgICAgICBpZiAoaSAhPT0gLTEpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMua2V5cy5zcGxpY2UoaSwgMSk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnZhbHVlcy5zcGxpY2UoaSwgMSk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgcmV0dXJuIGkgIT09IC0xO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi9cclxuICAgICAgICBNYXAucHJvdG90eXBlLmdldCA9IGZ1bmN0aW9uIChrZXksIGZhbGxiYWNrKSB7XHJcbiAgICAgICAgICAgIHZhciBpID0gdGhpcy5rZXlzLmluZGV4T2Yoa2V5KTtcclxuICAgICAgICAgICAgcmV0dXJuIGkgIT09IC0xID8gdGhpcy52YWx1ZXNbaV0gOiBmYWxsYmFjaztcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBNYXAjXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgTWFwLnByb3RvdHlwZS5zZXQgPSBmdW5jdGlvbiAoa2V5LCB2YWx1ZSkge1xyXG4gICAgICAgICAgICB2YXIgaSA9IHRoaXMua2V5cy5pbmRleE9mKGtleSk7XHJcbiAgICAgICAgICAgIGlmIChpICE9PSAtMSkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy52YWx1ZXNbaV0gPSB2YWx1ZTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB0aGlzLnZhbHVlc1t0aGlzLmtleXMucHVzaChrZXkpIC0gMV0gPSB2YWx1ZTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBNYXAjXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgTWFwLnByb3RvdHlwZS5zaXplID0gZnVuY3Rpb24gKCkgeyByZXR1cm4gdGhpcy5rZXlzLmxlbmd0aDsgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKiBAbWVtYmVyT2YgTWFwI1xyXG4gICAgICAgICAqLyAgICAgICAgXHJcbiAgICAgICAgTWFwLnByb3RvdHlwZS5oYXMgPSBmdW5jdGlvbiAoa2V5KSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLmtleXMuaW5kZXhPZihrZXkpICE9PSAtMTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBNYXAjXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBNYXAucHJvdG90eXBlLmdldEtleXMgPSBmdW5jdGlvbiAoKSB7IHJldHVybiB0aGlzLmtleXMuc2xpY2UoMCk7IH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQG1lbWJlck9mIE1hcCNcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIE1hcC5wcm90b3R5cGUuZ2V0VmFsdWVzID0gZnVuY3Rpb24gKCkgeyByZXR1cm4gdGhpcy52YWx1ZXMuc2xpY2UoMCk7IH07XHJcblxyXG4gICAgICAgIHJldHVybiBNYXA7XHJcbiAgICB9KCkpO1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgKiBSZXByZXNlbnRzIGEgam9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2lvbi5wYXR0ZXJucy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICBqb2luT2JzZXJ2ZXJzLnB1c2gocGxhbkNyZWF0ZU9ic2VydmVyKGV4dGVybmFsU3Vic2NyaXB0aW9ucywgdGhpcy5leHByZXNzaW9uLnBhdHRlcm5zW2ldLCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpKSk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHZhciBhY3RpdmVQbGFuID0gbmV3IEFjdGl2ZVBsYW4oam9pbk9ic2VydmVycywgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgcmVzdWx0O1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgcmVzdWx0ID0gc2VsZi5zZWxlY3Rvci5hcHBseShzZWxmLCBhcmd1bWVudHMpO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBvYnNlcnZlci5vbk5leHQocmVzdWx0KTtcclxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIGZvciAodmFyIGogPSAwLCBqbGVuID0gam9pbk9ic2VydmVycy5sZW5ndGg7IGogPCBqbGVuOyBqKyspIHtcclxuICAgICAgICAgICAgICAgIGpvaW5PYnNlcnZlcnNbal0ucmVtb3ZlQWN0aXZlUGxhbihhY3RpdmVQbGFuKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBkZWFjdGl2YXRlKGFjdGl2ZVBsYW4pO1xyXG4gICAgICAgIH0pO1xyXG4gICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGpvaW5PYnNlcnZlcnMubGVuZ3RoOyBpIDwgbGVuOyBpKy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HVlcyA9IFtdO1xyXG4gICAgICAgICAgICBpc0NvbXBsZXRlZCA9IGZhbHNlO1xyXG4gICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSB0aGlzLmpvaW5PYnNlcnZlckFycmF5Lmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBmaXJzdFZhbHVlcy5wdXNoKHRoaXMuam9pbk9ic2VydmVyQXJyYXlbaV0ucXVldWVbMF0pO1xyXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuam9pbk9ic2VydmVyQXJyYXlbaV0ucXVldWVbMF0ua2luZCA9PT0gJ0MnKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNDb21wbGV0ZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmIChpc0NvbXBsZXRlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5kZXF1ZXVlKCk7XHJcbiAgICAgICAgICAgICAgICB2YWx1ZXMgPSBbXTtcclxuICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBmaXJzdFZhbHVlcy5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhbHVlcy5wdXNoKGZpcnN0VmFsdWVzW2ldLnZhbHVlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHRoaXMub25OZXh0LmFwcGx5KHRoaXMsIHZhbHVlcyk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKiBAcHJpdmF0ZSAqL1xyXG4gICAgdmFyIEpvaW5PYnNlcnZlciA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcblxyXG4gICAgICAgIGluaGVyaXRzKEpvaW5PYnNlcnZlciwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi9cclxuICAgICAgICBmdW5jdGlvbiBKb2luT2JzZXJ2ZXIoc291cmNlLCBvbkVycm9yKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICB0aGlzLnNvdXJjZSA9IHNvdXJjZTtcclxuICAgICAgICAgICAgdGhpcy5vbkVycm9yID0gb25FcnJvcjtcclxuICAgICAgICAgICAgdGhpcy5xdWV1ZSA9IFtdO1xyXG4gICAgICAgICAgICB0aGlzLmFjdGl2ZVBsYW5zID0gW107XHJcbiAgICAgICAgICAgIHRoaXMuc3Vic2NyaXB0aW9uID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IGZhbHNlO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgdmFyIEpvaW5PYnNlcnZlclByb3RvdHlwZSA9IEpvaW5PYnNlcnZlci5wcm90b3R5cGU7XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi9cclxuICAgICAgICBKb2luT2JzZXJ2ZXJQcm90b3R5cGUubmV4dCA9IGZ1bmN0aW9uIChub3RpZmljYXRpb24pIHtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRGlzcG9zZWQpIHtcclxuICAgICAgICAgICAgICAgIGlmIChub3RpZmljYXRpb24ua2luZCA9PT0gJ0UnKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5vbkVycm9yKG5vdGlmaWNhdGlvbi5leGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHRoaXMucXVldWUucHVzaChub3RpZmljYXRpb24pO1xyXG4gICAgICAgICAgICAgICAgdmFyIGFjdGl2ZVBsYW5zID0gdGhpcy5hY3RpdmVQbGFucy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBhY3RpdmVQbGFucy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIGFjdGl2ZVBsYW5zW2ldLm1hdGNoKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAbWVtYmVyT2YgSm9pbk9ic2VydmVyI1xyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBKb2luT2JzZXJ2ZXJQcm90b3R5cGUuZXJyb3IgPSBub29wO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBAbWVtYmVyT2YgSm9pbk9ic2VydmVyI1xyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICovICAgICAgICBcclxuICAgICAgICBKb2luT2JzZXJ2ZXJQcm90b3R5cGUuY29tcGxldGVkID0gbm9vcDtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQG1lbWJlck9mIEpvaW5PYnNlcnZlciNcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5hZGRBY3RpdmVQbGFuID0gZnVuY3Rpb24gKGFjdGl2ZVBsYW4pIHtcclxuICAgICAgICAgICAgdGhpcy5hY3RpdmVQbGFucy5wdXNoKGFjdGl2ZVBsYW4pO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5zdWJzY3JpYmUgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRoaXMuc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUodGhpcy5zb3VyY2UubWF0ZXJpYWxpemUoKS5zdWJzY3JpYmUodGhpcykpO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5yZW1vdmVBY3RpdmVQbGFuID0gZnVuY3Rpb24gKGFjdGl2ZVBsYW4pIHtcclxuICAgICAgICAgICAgdmFyIGlkeCA9IHRoaXMuYWN0aXZlUGxhbnMuaW5kZXhPZihhY3RpdmVQbGFuKTtcclxuICAgICAgICAgICAgdGhpcy5hY3RpdmVQbGFucy5zcGxpY2UoaWR4LCAxKTtcclxuICAgICAgICAgICAgaWYgKHRoaXMuYWN0aXZlUGxhbnMubGVuZ3RoID09PSAwKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBtZW1iZXJPZiBKb2luT2JzZXJ2ZXIjXHJcbiAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgKi8gICAgICAgIFxyXG4gICAgICAgIEpvaW5PYnNlcnZlclByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBfc3VwZXIucHJ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24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBhY3RpdmVQbGFucyA9IFtdLFxyXG4gICAgICAgICAgICAgICAgZXh0ZXJuYWxTdWJzY3JpcHRpb25zID0gbmV3IE1hcCgpLFxyXG4gICAgICAgICAgICAgICAgZ3JvdXAsXHJcbiAgICAgICAgICAgICAgICBpLCBsZW4sXHJcbiAgICAgICAgICAgICAgICBqb2luT2JzZXJ2ZXIsXHJcbiAgICAgICAgICAgICAgICBqb2luVmFsdWVzLFxyXG4gICAgICAgICAgICAgICAgb3V0T2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgIG91dE9ic2VydmVyID0gb2JzZXJ2ZXJDcmVhdGUob2JzZXJ2ZXIub25OZXh0LmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgdmFsdWVzID0gZXh0ZXJuYWxTdWJzY3JpcHRpb25zLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICAgICAgZm9yICh2YXIgaiA9IDAsIGpsZW4gPSB2YWx1ZXMubGVuZ3RoOyBqIDwgamxlbjsgaisrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFsdWVzW2pdLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXhjZXB0aW9uKTtcclxuICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25Db21wbGV0ZWQuYmluZChvYnNlcnZlcikpO1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gcGxhbnMubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICBhY3RpdmVQbGFucy5wdXNoKHBsYW5zW2ldLmFjdGl2YXRlKGV4dGVybmFsU3Vic2NyaXB0aW9ucywgb3V0T2JzZXJ2ZXIsIGZ1bmN0aW9uIChhY3RpdmVQbGFuKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBpZHggPSBhY3RpdmVQbGFucy5pbmRleE9mKGFjdGl2ZVBsYW4pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBhY3RpdmVQbGFucy5zcGxpY2UoaWR4LCAxKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGFjdGl2ZVBsYW5zLmxlbmd0aCA9PT0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0T2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2YWJsZVRocm93KGUpLnN1YnNjcmliZShvYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgZ3JvdXAgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSgpO1xyXG4gICAgICAgICAgICBqb2luVmFsdWVzID0gZXh0ZXJuYWxTdWJzY3JpcHRpb25zLmdldFZhbHVlcygpO1xyXG4gICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBqb2luVmFsdWVzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBqb2luT2JzZXJ2ZXIgPSBqb2luVmFsdWVzW2ldO1xyXG4gICAgICAgICAgICAgICAgam9pbk9ic2VydmVyLnN1YnNjcmliZSgpO1xyXG4gICAgICAgICAgICAgICAgZ3JvdXAuYWRkKGpvaW5PYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgcmV0dXJuIGdyb3VwO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBvYnNlcnZhYmxlVGltZXJEYXRlKGR1ZVRpbWUsIHNjaGVkdWxlcikge1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHNjaGVkdWxlci5zY2hlZHVsZVdpdGhBYnNvbHV0ZShkdWVUaW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoMCk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgZnVuY3Rpb24gb2JzZXJ2YWJsZVRpbWVyRGF0ZUFuZFBlcmlvZChkdWVUaW1lLCBwZXJpb2QsIHNjaGVkdWxlcikge1xyXG4gICAgdmFyIHAgPSBub3JtYWxpemVUaW1lKHBlcmlvZCk7XHJcbiAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgIHZhciBjb3VudCA9IDAsIGQgPSBkdWVUaW1lO1xyXG4gICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlV2l0aEFic29sdXRlKGQsIGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgdmFyIG5vdztcclxuICAgICAgICBpZiAocCA+IDApIHtcclxuICAgICAgICAgIG5vdyA9IHNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgIGQgPSBkICsgcDtcclxuICAgICAgICAgIGlmIChkIDw9IG5vdykge1xyXG4gICAgICAgICAgICBkID0gbm93ICsgcDtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGNvdW50KyspO1xyXG4gICAgICAgIHNlbGYoZC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G4gICAgICAgIHJldHVybiBvYnNlcnZhYmxlVGltZXJUaW1lU3BhbkFuZFBlcmlvZChkdWVUaW1lLCBwZXJpb2QsIHNjaGVkdWxlcik7XHJcbiAgICB9O1xyXG5cclxuICAgIGZ1bmN0aW9uIG9ic2VydmFibGVEZWxheVRpbWVTcGFuKGR1ZVRpbWUsIHNjaGVkdWxlcikge1xyXG4gICAgICAgIHZhciBzb3VyY2UgPSB0aGlzO1xyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGFjdGl2ZSA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgY2FuY2VsYWJsZSA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICBleGNlcHRpb24gPSBudWxsLFxyXG4gICAgICAgICAgICAgICAgcSA9IFtdLFxyXG4gICAgICAgICAgICAgICAgcnVubmluZyA9IGZhbHNlLFxyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uO1xyXG4gICAgICAgICAgICBzdWJzY3JpcHRpb24gPSBzb3VyY2UubWF0ZXJpYWxpemUoKS50aW1lc3RhbXAoc2NoZWR1bGVyKS5zdWJzY3JpYmUoZnVuY3Rpb24gKG5vdGlmaWNhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgdmFyIGQsIHNob3VsZFJ1bjtcclxuICAgICAgICAgICAgICAgIGlmIChub3RpZmljYXRpb24udmFsdWUua2luZCA9PT0gJ0UnKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcSA9IFtdO1xyXG4gICAgICAgICAgICAgICAgICAgIHEucHVzaChub3RpZmljYXRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIGV4Y2VwdGlvbiA9IG5vdGlmaWNhdGlvbi52YWx1ZS5leGNlcHRpb247XHJcbiAgICAgICAgICAgICAgICAgICAgc2hvdWxkUnVuID0gIXJ1bm5pbmc7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHEucHVzaCh7IHZhbHVlOiBub3RpZmljYXRpb24udmFsdWUsIHRpbWVzdGFtcDogbm90aWZpY2F0aW9uLnRpbWVzdGFtcCArIGR1ZVRpbWUgfSk7XHJcbiAgICAgICAgICAgICAgICAgICAgc2hvdWxkUnVuID0gIWFjdGl2ZTtcclxuICAgICAgICAgICAgICAgICAgICBhY3RpdmUgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKHNob3VsZFJ1bikge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChleGNlcHRpb24gIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihleGNlcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgY2FuY2VsYWJsZS5zZXREaXNwb3NhYmxlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkLnNldERpc3Bvc2FibGUoc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlV2l0aFJlbGF0aXZlKGR1ZVRpbWUsIGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgZSwgcmVjdXJzZUR1ZVRpbWUsIHJlc3VsdCwgc2hvdWxkUmVjdXJzZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChleGNlcHRpb24gIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBydW5uaW5nID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSBudWxsO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDAgJiYgcVswXS50aW1lc3RhbXAgLSBzY2hlZHVsZXIubm93KCkgPD0gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSBxLnNoaWZ0KCkudmFsdWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZXN1bHQgIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LmFjY2VwdChvYnNlcnZlcik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAocmVzdWx0ICE9PSBudWxsKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3VsZFJlY3Vyc2UgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlY3Vyc2VEdWVUaW1lID0gMDtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG91bGRSZWN1cnNlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZWN1cnNlRHVlVGltZSA9IE1hdGgubWF4KDAsIHFbMF0udGltZXN0YW1wIC0gc2NoZWR1bGVyLm5vdygpKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYWN0aXZlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlID0gZXhjZXB0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcnVubmluZyA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGUgIT09IG51bGwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzaG91bGRSZWN1cnNlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZihyZWN1cnNlRHVlVGltZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uLCBjYW5jZWxhYmxlKTtcclxuICAgICAgICB9KTtcclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBvYnNlcnZhYmxlRGVsYXlEYXRlKGR1ZVRpbWUsIHNjaGVkdWxlcikge1xyXG4gICAgICAgIHZhciBzZWxmID0gdGhpcztcclxuICAgICAgICByZXR1cm4gb2JzZXJ2YWJsZURlZmVyKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdmFyIHRpbWVTcGFuID0gZHVlVGltZSAtIHNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgcmV0dXJuIG9ic2VydmFibGVEZWxheVRpbWVTcGFuLmNhbGwoc2VsZiwgdGltZVNwYW4sIHNjaGVkdWxlcik7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9XH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GltZVNoaWZ0ID0gdGltZVNwYW47XHJcbiAgICAgICAgfVxyXG4gICAgICAgIGlmIChzY2hlZHVsZXIgPT09IHVuZGVmaW5lZCkge1xyXG4gICAgICAgICAgICBzY2hlZHVsZXIgPSB0aW1lb3V0U2NoZWR1bGVyO1xyXG4gICAgICAgIH1cclxuICAgICAgICBpZiAodHlwZW9mIHRpbWVTaGlmdE9yU2NoZWR1bGVyID09PSAnbnVtYmVyJykge1xyXG4gICAgICAgICAgICB0aW1lU2hpZnQgPSB0aW1lU2hpZnRPclNjaGVkdWxlcjtcclxuICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB0aW1lU2hpZnRPclNjaGVkdWxlciA9PT0gJ29iamVjdCcpIHtcclxuICAgICAgICAgICAgdGltZVNoaWZ0ID0gdGltZVNwYW47XHJcbiAgICAgICAgICAgIHNjaGVkdWxlciA9IHRpbWVTaGlmdE9yU2NoZWR1bGVyO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciBncm91cERpc3Bvc2FibGUsXHJcbiAgICAgICAgICAgICAgICBuZXh0U2hpZnQgPSB0aW1lU2hpZnQsXHJcbiAgICAgICAgICAgICAgICBuZXh0U3BhbiA9IHRpbWVTcGFuLFxyXG4gICAgICAgICAgICAgICAgcSA9IFtdLFxyXG4gICAgICAgICAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlLFxyXG4gICAgICAgICAgICAgICAgdGltZXJEID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHRvdGFsVGltZSA9IDA7XHJcbiAgICAgICAgICAgICAgICBncm91cERpc3Bvc2FibGUgPSBuZXcgQ29tcG9zaXRlRGlzcG9zYWJsZSh0aW1lckQpLFxyXG4gICAgICAgICAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShncm91cERpc3Bvc2FibGUpO1xyXG5cclxuICAgICAgICAgICAgIGZ1bmN0aW9uIGNyZWF0ZVRpbWVyICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBtID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksXHJcbiAgICAgICAgICAgICAgICAgICAgaXNTcGFuID0gZmFsc2UsXHJcbiAgICAgICAgICAgICAgICAgICAgaXNTaGlmdCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgdGltZXJELnNldERpc3Bvc2FibGUobSk7XHJcbiAgICAgICAgICAgICAgICBpZiAobmV4dFNwYW4gPT09IG5leHRTaGlmdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlzU3BhbiA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNTaGlmdCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG5leHRTcGFuIDwgbmV4dFNoaWZ0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNTcGFuID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaXNTaGlmdCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB2YXIgbmV3VG90YWxUaW1lID0gaXNTcGFuID8gbmV4dFNwYW4gOiBuZXh0U2hpZnQsXHJcbiAgICAgICAgICAgICAgICAgICAgdHMgPSBuZXdUb3RhbFRpbWUgLSB0b3RhbFRpbWU7XHJcbiAgICAgICAgICAgICAgICB0b3RhbFRpbWUgPSBuZXdUb3RhbFRpbWU7XHJcbiAgICAgICAgICAgICAgICBpZiAoaXNTcGFuKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV4dFNwYW4gKz0gdGltZVNoaWZ0O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgaWYgKGlzU2hpZnQpIHtcclxuICAgICAgICAgICAgICAgICAgICBuZXh0U2hpZnQgKz0gdGltZVNoaWZ0O1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgbS5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVdpdGhSZWxhdGl2ZSh0cywgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBzO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpc1NoaWZ0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHMgPSBuZXcgU3ViamVjdCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBxLnB1c2gocyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGlmIChpc1NwYW4pIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcyA9IHEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcy5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBjcmVhdGVUaW1lcigpO1xyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICBxLnB1c2gobmV3IFN1YmplY3QoKSk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocVswXSwgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgIGNyZWF0ZVRpbWVyKCk7XHJcbiAgICAgICAgICAgIGdyb3VwRGlzcG9zYWJsZS5hZGQoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGksIHM7XHJcbiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgcS5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHMgPSBxW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgdmFyIGksIHM7XHJcbiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgcS5sZW5ndGg7IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgIHMgPSBxW2ldO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZSk7XHJcbiAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBpLCBzO1xyXG4gICAgICAgICAgICAgICAgZm9yIChpID0gMDsgaSA8IHEubGVuZ3RoOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICBzID0gcVtpXTtcclxuICAgICAgICAgICAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgIHJldHVybiByZWZDb3VudERpc3Bvc2FibGU7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKlxyXG4gICAgICogIFByb2plY3RzIGVhY2ggZWxlbWVudCBvZiBhbiBvYnNlcnZhYmxlIHNlcXVlbmNlIGludG8gYSB3aW5kb3cgdGhhdCBpcyBjb21wbGV0ZWQgd2hlbiBlaXRoZXIgaXQncyBmdWxsIG9yIGEgZ2l2ZW4gYW1vdW50IG9mIHRpbWUgaGFzIGVsYXBzZWQuXHJ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ICAgICAgdmFyIGNyZWF0ZVRpbWVyLFxyXG4gICAgICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlLFxyXG4gICAgICAgICAgICAgICAgbiA9IDAsXHJcbiAgICAgICAgICAgICAgICByZWZDb3VudERpc3Bvc2FibGUsXHJcbiAgICAgICAgICAgICAgICBzLFxyXG4gICAgICAgICAgICAgICAgdGltZXJEID0gbmV3IFNlcmlhbERpc3Bvc2FibGUoKSxcclxuICAgICAgICAgICAgICAgIHdpbmRvd0lkID0gMDtcclxuICAgICAgICAgICAgZ3JvdXBEaXNwb3NhYmxlID0gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUodGltZXJEKTtcclxuICAgICAgICAgICAgcmVmQ291bnREaXNwb3NhYmxlID0gbmV3IFJlZkNvdW50RGlzcG9zYWJsZShncm91cERpc3Bvc2FibGUpO1xyXG4gICAgICAgICAgICBjcmVhdGVUaW1lciA9IGZ1bmN0aW9uIChpZCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG0gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgIHRpbWVyRC5zZXREaXNwb3NhYmxlKG0pO1xyXG4gICAgICAgICAgICAgICAgbS5zZXREaXNwb3NhYmxlKHNjaGVkdWxlci5zY2hlZHVsZVdpdGhSZWxhdGl2ZSh0aW1lU3BhbiwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBuZXdJZDtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoaWQgIT09IHdpbmRvd0lkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgbiA9IDA7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV3SWQgPSArK3dpbmRvd0lkO1xyXG4gICAgICAgICAgICAgICAgICAgIHMub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICBzID0gbmV3IFN1YmplY3QoKTtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoYWRkUmVmKHMsIHJlZkNvdW50RGlzcG9zYWJsZSkpO1xyXG4gICAgICAgICAgICAgICAgICAgIGNyZWF0ZVRpbWVyKG5ld0lkKTtcclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChhZGRSZWYocywgcmVmQ291bnREaXNwb3NhYmxlKSk7XHJcbiAgICAgICAgICAgIGNyZWF0ZVRpbWVyKDApO1xyXG4gICAgICAgICAgICBncm91cERpc3Bvc2FibGUuYWRkKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIHZhciBuZXdJZCA9IDAsIG5ld1dpbmRvdyA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgcy5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICBuKys7XHJcbiAgICAgICAgICAgICAgICBpZiAobiA9PT0gY291bnQpIHtcclxuICAgICAgICAgICAgICAgICAgICBuZXdXaW5kb3cgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIG4gPSAwO1xyXG4gICAgICAgICAgICAgICAgICAgIG5ld0lkID0gKyt3aW5kb3dJZDtcclxuICAgICAgICAgICAgICAgICAgICBzLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgcyA9IG5ldyBTdWJqZWN0KCk7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KGFkZFJlZihzLCByZWZDb3VudERpc3Bvc2FibGUpKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChuZXdXaW5kb3cpIHtcclxuICAgICAgICAgICAgICAgICAgICBjcmVh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sZVByb3RvLnRpbWVzdGFtcCA9IGZ1bmN0aW9uIChzY2hlZHVsZXIpIHtcclxuICAgICAgICBzY2hlZHVsZXIgfHwgKHNjaGVkdWxlciA9IHRpbWVvdXRTY2hlZHVsZXIpO1xyXG4gICAgICAgIHJldHVybiB0aGlzLnNlbGVjdChmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICByZXR1cm4ge1xyXG4gICAgICAgICAgICAgICAgdmFsdWU6IHgsXHJcbiAgICAgICAgICAgICAgICB0aW1lc3RhbXA6IHNjaGVkdWxlci5ub3coKVxyXG4gICAgICAgICAgICB9O1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICBmdW5jdGlvbiBzYW1wbGVPYnNlcnZhYmxlKHNvdXJjZSwgc2FtcGxlcikge1xyXG4gICAgICAgIFxyXG4gICAgICAgIHJldHVybiBuZXcgQW5vbnltb3VzT2JzZXJ2YWJsZShmdW5jdGlvbiAob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgdmFyIGF0RW5kLCB2YWx1ZSwgaGFzVmFsdWU7XHJcblxyXG4gICAgICAgICAgICBmdW5jdGlvbiBzYW1wbGVTdWJzY3JpYmUoKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzVmFsdWUpIHtcclxuICAgICAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoYXRFbmQpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoXHJcbiAgICAgICAgICAgICAgICBzb3VyY2Uuc3Vic2N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N3aXRjaGVkID0gZmFsc2UsXHJcbiAgICAgICAgdGltZXIgPSBuZXcgU2VyaWFsRGlzcG9zYWJsZSgpO1xyXG5cclxuICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUob3JpZ2luYWwpO1xyXG5cclxuICAgICAgdmFyIGNyZWF0ZVRpbWVyID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgIHZhciBteUlkID0gaWQ7XHJcbiAgICAgICAgdGltZXIuc2V0RGlzcG9zYWJsZShzY2hlZHVsZXJbc2NoZWR1bGVyTWV0aG9kXShkdWVUaW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICBpZiAoaWQgPT09IG15SWQpIHtcclxuICAgICAgICAgICAgaXNQcm9taXNlKG90aGVyKSAmJiAob3RoZXIgPSBvYnNlcnZhYmxlRnJvbVByb21pc2Uob3RoZXIpKTtcclxuICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUob3RoZXIuc3Vic2NyaWJlKG9ic2VydmVyKSk7XHJcbiAgICAgICAgICB9XHJcbiAgICAgICAgfSkpO1xyXG4gICAgICB9O1xyXG5cclxuICAgICAgY3JlYXRlVGltZXIoKTtcclxuICAgICAgXHJcbiAgICAgIG9yaWdpbmFsLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgIGlmICghc3dpdGNoZWQpIHtcclxuICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICBjcmVhdGVUaW1lcigpO1xyXG4gICAgICAgIH1cclxuICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICBpZiAoIXN3aXRjaGVkKSB7XHJcbiAgICAgICAgICBpZCsrO1xyXG4gICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICB9XHJcbiAgICAgIH0sIGZ1bmN0aW9uIC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ICAgICAgICByZXN1bHQsXHJcbiAgICAgICAgICAgICAgICBzdGF0ZSA9IGluaXRpYWxTdGF0ZSxcclxuICAgICAgICAgICAgICAgIHRpbWU7XHJcbiAgICAgICAgICAgIHJldHVybiBzY2hlZHVsZXIuc2NoZWR1bGVSZWN1cnNpdmVXaXRoQWJzb2x1dGUoc2NoZWR1bGVyLm5vdygpLCBmdW5jdGlvbiAoc2VsZikge1xyXG4gICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dChyZXN1bHQpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoZmlyc3QpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZmlyc3QgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZSA9IGl0ZXJhdGUoc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICBoYXNSZXN1bHQgPSBjb25kaXRpb24oc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0U2VsZWN0b3Ioc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aW1lID0gdGltZVNlbGVjdG9yKHN0YXRlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzUmVzd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x0LFxyXG4gICAgICAgICAgICAgICAgc3RhdGUgPSBpbml0aWFsU3RhdGUsXHJcbiAgICAgICAgICAgICAgICB0aW1lO1xyXG4gICAgICAgICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlUmVjdXJzaXZlV2l0aFJlbGF0aXZlKDAsIGZ1bmN0aW9uIChzZWxmKSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoaGFzUmVzdWx0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBmaXJzdCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlID0gaXRlcmF0ZShzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1Jlc3VsdCA9IGNvbmRpdGlvbihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGhhc1Jlc3VsdCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHRTZWxlY3RvcihzdGF0ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRpbWUgPSB0aW1lU2VsZWN0b3Ioc3RhdGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGlmIChoYXNSZXN1bHQpIHtcclxuICAgICAgICAg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yBTZXJpYWxEaXNwb3NhYmxlKCksIHN0YXJ0ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUoc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBkZWxheTtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWxheSA9IHNlbGVjdG9yKHgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycm9yKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXJyb3IpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHZhciBkID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZGVsYXlzLmFkZChkKTtcclxuICAgICAgICAgICAgICAgICAgICBkLnNldERpc3Bvc2FibGUoZGVsYXkuc3Vic2NyaWJlKGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWxheXMucmVtb3ZlKGQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgb2JzZXJ2ZXIub25FcnJvci5iaW5kKG9ic2VydmVyKSwgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlbGF5cy5yZW1vdmUoZCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KSk7XHJcbiAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgYXRFbmQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgaWYgKCFzdWJEZWxheSkge1xyXG4gICAgICAgICAgICAgICAgc3RhcnQoKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi5zZXREaXNwb3NhYmxlKHN1YkRlbGF5LnN1YnNjcmliZShmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc3RhcnQoKTtcclxuICAgICAgICAgICAgICAgIH0sIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksIGZ1bmN0aW9uICgpIHsgc3RhcnQoKTsgfSkpO1xyXG4gICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gbmV3IENvbXBvc2l0ZURpc3Bvc2FibGUoc3Vic2NyaXB0aW9uLCBkZWxheXMpO1xyXG4gICAgICAgIH0pO1xyXG4gICAgfTtcclxuXHJcbiAgICAvKipcclxuICAgICAqICBSZXR1cm5zIHRoZSBzb3VyY2Ugb2JzZXJ2YWJsZSBzZXF1ZW5jZSwgc3dpdGNoaW5nIHRvIHRoZSBvdGhlciBvYnNlcnZhYmxlIHNlcXVlbmNlIGlmIGEgdGltZW91dCBpcyBzaWduYWxlZC5cclxuICAgICAqICBcclxuICAgICAqIEBleGFtcGxlXHJcbiAgICAgKiAgMSAtIHJlcyA9IHNvdXJjZS50aW1lb3V0V2l0a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gKHRpbWVvdXQpIHtcclxuICAgICAgICAgICAgICAgIHZhciBteUlkID0gaWQsIHRpbWVyV2lucyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaWQgPT09IG15SWQ7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICAgICAgdmFyIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgIHRpbWVyLnNldERpc3Bvc2FibGUoZCk7XHJcbiAgICAgICAgICAgICAgICBkLnNldERpc3Bvc2FibGUodGltZW91dC5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aW1lcldpbnMoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShvdGhlci5zdWJzY3JpYmUob2JzZXJ2ZXIpKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aW1lcldpbnMoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAodGltZXJXaW5zKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnNldERpc3Bvc2FibGUob3RoZXIuc3Vic2NyaWJlKG9ic2VydmVyKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgICB9O1xyXG5cclxuICAgICAgICAgICAgc2V0VGltZXIoZmlyc3RUaW1lb3V0KTtcclxuICAgICAgICAgICAgdmFyIG9ic2VydmVyV2lucyA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHZhciByZXMgPSAhc3dpdGNoZWQ7XHJcbiAgICAgICAgICAgICAgICBpZiAocmVzKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWQrKztcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIHJldHVybiByZXM7XHJcbiAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICBvcmlnaW5hbC5zZXREaXNwb3NhYmxlKHNvdXJjZS5zdWJzY3JpYmUoZnVuY3Rpb24gKHgpIHtcclxuICAgICAgICAgICAgICAgIGlmIChvYnNlcnZlcldpbnMoKSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh4KTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgdGltZW91dDtcclxuICAgICAgICAgICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB0aW1lb3V0ID0gdGltZW91dGR1cmF0aW9uU2VsZWN0b3IoeCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIHNldFRpbWVyKHRpbWVvdXQpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoZSkge1xyXG4gICAgICAgICAgICAgICAgaWYgKG9ic2VydmVyV2lucygpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSwgZnVuY3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XIgc291cmNlID0gdGhpcztcclxuICAgICAgICByZXR1cm4gbmV3IEFub255bW91c09ic2VydmFibGUoZnVuY3Rpb24gKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHZhciB2YWx1ZSwgaGFzVmFsdWUgPSBmYWxzZSwgY2FuY2VsYWJsZSA9IG5ldyBTZXJpYWxEaXNwb3NhYmxlKCksIGlkID0gMCwgc3Vic2NyaXB0aW9uID0gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHRocm90dGxlO1xyXG4gICAgICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgICAgICB0aHJvdHRsZSA9IHRocm90dGxlRHVyYXRpb25TZWxlY3Rvcih4KTtcclxuICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHZhbHVlID0geDtcclxuICAgICAgICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgICAgICAgICB2YXIgY3VycmVudGlkID0gaWQsIGQgPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgICAgIGNhbmNlbGFibGUuc2V0RGlzcG9zYWJsZShkKTtcclxuICAgICAgICAgICAgICAgIGQuc2V0RGlzcG9zYWJsZSh0aHJvdHRsZS5zdWJzY3JpYmUoZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChoYXNWYWx1ZSAmJiBpZCA9PT0gY3VycmVudGlkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgZC5kaXNwb3NlKCk7XHJcbiAgICAgICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGhhc1ZhbHVlICYmIGlkID09PSBjdXJyZW50aWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICBkLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIH0pKTtcclxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKGUpIHtcclxuICAgICAgICAgICAgICAgIGNhbmNlbGFibGUuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcihlKTtcclxuICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICBpZCsrO1xyXG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBjYW5jZWxhYmxlLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIGlmIChoYXNWYWx1ZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgIGlkKys7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gIC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R1cm4gc291cmNlLnN1YnNjcmliZShmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIG5vdyA9IHNjaGVkdWxlci5ub3coKTtcclxuICAgICAgICAgICAgICAgIHEucHVzaCh7IGludGVydmFsOiBub3csIHZhbHVlOiB4IH0pO1xyXG4gICAgICAgICAgICAgICAgd2hpbGUgKHEubGVuZ3RoID4gMCAmJiBub3cgLSBxWzBdLmludGVydmFsID49IGR1cmF0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcS5zaGlmdCgpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LCBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbm93ID0gc2NoZWR1bGVyLm5vdygpLCByZXMgPSBbXTtcclxuICAgICAgICAgICAgICAgIHdoaWxlIChxLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgbmV4dCA9IHEuc2hpZnQoKTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAobm93IC0gbmV4dC5pbnRlcnZhbCA8PSBkdXJhdGlvbikge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICByZXMucHVzaChuZXh0LnZhbHVlKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlcyk7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICB9KTtcclxuICAgIH07XHJcblxyXG4gICAgLyoqXHJcbiAgICAgKiAgVGFrZXMgZWxlbWVudHMgZm9yIHRoZSBzcGVjaWZpZWQgZHVyYXRpb24gZnJvbSB0aGUgc3RhcnQgb2YgdGhlIG9ic2VydmFibGUgc291cmNlIH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WxzZSxcclxuICAgICAgICBtID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCksXHJcbiAgICAgICAgZyA9IG5ldyBDb21wb3NpdGVEaXNwb3NhYmxlKCk7XHJcblxyXG4gICAgICBnLmFkZChtKTtcclxuXHJcbiAgICAgIG0uc2V0RGlzcG9zYWJsZShzb3VyY2VzLnN1YnNjcmliZShcclxuICAgICAgICBmdW5jdGlvbiAoaW5uZXJTb3VyY2UpIHtcclxuICAgICAgICAgIGlmICghaGFzQ3VycmVudCkge1xyXG4gICAgICAgICAgICBoYXNDdXJyZW50ID0gdHJ1ZTtcclxuICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIGlzUHJvbWlzZShpbm5lclNvdXJjZSkgJiYgKGlubmVyU291cmNlID0gb2JzZXJ2YWJsZUZyb21Qcm9taXNlKGlubmVyU291cmNlKSk7XHJcblxyXG4gICAgICAgICAgICB2YXIgaW5uZXJTdWJzY3JpcHRpb24gPSBuZXcgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUoKTtcclxuICAgICAgICAgICAgZy5hZGQoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG5cclxuICAgICAgICAgICAgaW5uZXJTdWJzY3JpcHRpb24uc2V0RGlzcG9zYWJsZShpbm5lclNvdXJjZS5zdWJzY3JpYmUoXHJcbiAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0LmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgZy5yZW1vdmUoaW5uZXJTdWJzY3JpcHRpb24pO1xyXG4gICAgICAgICAgICAgICAgaGFzQ3VycmVudCA9IGZhbHNlO1xyXG4gICAgICAgICAgICAgICAgaWYgKGlzU3RvcHBlZCAmJiBnLmxlbmd0aCA9PT0gMSkge1xyXG4gICAgICAg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N1YnNjcmliZShcclxuICAgICAgICAgICAgICBmdW5jdGlvbiAoeCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHJlc3VsdDtcclxuICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHNlbGVjdG9yLmNhbGwodGhpc0FyZywgeCwgaW5kZXgrKywgaW5uZXJTb3VyY2UpO1xyXG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xyXG4gICAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yKGUpO1xyXG4gICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25OZXh0KHJlc3VsdCk7XHJcbiAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICBvYnNlcnZlci5vbkVycm9yLmJpbmQob2JzZXJ2ZXIpLFxyXG4gICAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIGcucmVtb3ZlKGlubmVyU3Vic2NyaXB0aW9uKTtcclxuICAgICAgICAgICAgICAgIGhhc0N1cnJlbnQgPSBmYWxzZTtcclxuXHJcbiAgICAgICAgICAgICAgICBpZiAoaXNTdG9wcGVkICYmIGcubGVuZ3RoID09PSAxKSB7XHJcbiAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgfSkpO1xyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH0sIFxyXG4gICAgICAgIG9ic2VydmVyLm9uRXJyb3IuYmluZChvYnNlcnZlciksXHJcbiAgICAgICAgZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgIGlmIChnLmxlbmd0aCA9PT0gMSAmJiAhaGFzQ3VycmVudCkge1xyXG4gICAgIC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uIHRoaXMuc2NoZWR1bGVSZWxhdGl2ZVdpdGhTdGF0ZShhY3Rpb24sIGR1ZVRpbWUsIGludm9rZUFjdGlvbik7XHJcbiAgICAgICAgfTsgICAgXHJcblxyXG4gICAgICAgIC8qKiBcclxuICAgICAgICAgKiBTdGFydHMgdGhlIHZpcnR1YWwgdGltZSBzY2hlZHVsZXIuIFxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIFZpcnR1YWxUaW1lU2NoZWR1bGVyUHJvdG90eXBlLnN0YXJ0ID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICB2YXIgbmV4dDtcclxuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRW5hYmxlZCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0VuYWJsZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgZG8ge1xyXG4gICAgICAgICAgICAgICAgICAgIG5leHQgPSB0aGlzLmdldE5leHQoKTtcclxuICAgICAgICAgICAgICAgICAgICBpZiAobmV4dCAhPT0gbnVsbCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5jb21wYXJlcihuZXh0LmR1ZVRpbWUsIHRoaXMuY2xvY2spID4gMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5jbG9jayA9IG5leHQuZHVlVGltZTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBuZXh0Lmludm9rZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuaXNFbmFibGVkID0gZmFsc2U7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSB3aGlsZSAodGhpcy5pc0VuYWJsZWQpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqIFxyXG4gICAgICAgICA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RydWU7XHJcbiAgICAgICAgICAgICAgICBkbyB7XHJcbiAgICAgICAgICAgICAgICAgICAgbmV4dCA9IHRoaXMuZ2V0TmV4dCgpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmIChuZXh0ICE9PSBudWxsICYmIHRoaXMuY29tcGFyZXIobmV4dC5kdWVUaW1lLCB0aW1lKSA8PSAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLmNvbXBhcmVyKG5leHQuZHVlVGltZSwgdGhpcy5jbG9jaykgPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmNsb2NrID0gbmV4dC5kdWVUaW1lO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG5leHQuaW52b2tlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5pc0VuYWJsZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9IHdoaWxlICh0aGlzLmlzRW5hYmxlZCk7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmNsb2NrID0gdGltZTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEFkdmFuY2VzIHRoZSBzY2hlZHVsZXIncyBjbG9jayBieSB0aGUgc3BlY2lmaWVkIHJlbGF0aXZlIHRpbWUsIHJ1bm5pbmcgYWxsIHdvcmsgc2NoZWR1bGVkIGZvciB0aGF0IHRpbWVzcGFuLlxyXG4gICAgICAgICAqIEBwYXJhbSB7TnVtYmVyfSB0aW1lIFJlbGF0aXZlIHRpbWUgdG8gYWR2YW5jZSB0aGUgc2NoZWR1bGVyJ3MgY2xvY2sgYnkuXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgVmlydHVhbFRpbWVTY2hl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PdXRPZlJhbmdlKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgdGhpcy5jbG9jayA9IGR0O1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEdldHMgdGhlIG5leHQgc2NoZWR1bGVkIGl0ZW0gdG8gYmUgZXhlY3V0ZWQuICAgICAgICAgIFxyXG4gICAgICAgICAqIEByZXR1cm5zIHtTY2hlZHVsZWRJdGVtfSBUaGUgbmV4dCBzY2hlZHVsZWQgaXRlbS5cclxuICAgICAgICAgKi8gICAgICAgICAgXHJcbiAgICAgICAgVmlydHVhbFRpbWVTY2hlZHVsZXJQcm90b3R5cGUuZ2V0TmV4dCA9IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgdmFyIG5leHQ7XHJcbiAgICAgICAgICAgIHdoaWxlICh0aGlzLnF1ZXVlLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgIG5leHQgPSB0aGlzLnF1ZXVlLnBlZWsoKTtcclxuICAgICAgICAgICAgICAgIGlmIChuZXh0LmlzQ2FuY2VsbGVkKCkpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnF1ZXVlLmRlcXVldWUoKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG5leHQ7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgcmV0dXJuIG51bGw7XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogU2NoZWR1bGVzIGFuIGFjdGlvbiB0byBiZSBleGVjdXRlZCBhdCBkdWVUaW1lLiAgICAgICBcclxuICAgICAgICAgKiBAcGFyYW0ge1NjaGVkdWxlcn0gc2NoZWR1bGVyIFNjaGVkdWxlciB0byBleGVjdXRlIHRoZSBhY3Rpb24gb24uXHJcbiAgICAgICAgICogQHBh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XRhY2hPYnNlcnZlciA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcbiAgICAgICAgaW5oZXJpdHMoQXV0b0RldGFjaE9ic2VydmVyLCBfc3VwZXIpO1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBBdXRvRGV0YWNoT2JzZXJ2ZXIob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIgPSBvYnNlcnZlcjtcclxuICAgICAgICAgICAgdGhpcy5tID0gbmV3IFNpbmdsZUFzc2lnbm1lbnREaXNwb3NhYmxlKCk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICB2YXIgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlID0gQXV0b0RldGFjaE9ic2VydmVyLnByb3RvdHlwZTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLm5leHQgPSBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgdmFyIG5vRXJyb3IgPSBmYWxzZTtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgICAgIG5vRXJyb3IgPSB0cnVlO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7IFxyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTsgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoIW5vRXJyb3IpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5lcnJvciA9IGZ1bmN0aW9uIChleG4pIHtcclxuICAgICAgICAgICAgdHJ5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25FcnJvcihleG4pO1xyXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7IFxyXG4gICAgICAgICAgICAgICAgdGhyb3cgZTsgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIH0gZmluYWxseSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmRpc3Bvc2UoKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5jb21wbGV0ZWQgPSBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsgXHJcbiAgICAgICAgICAgICAgICB0aHJvdyBlOyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgfSBmaW5hbGx5IHtcclxuICAgICAgICAgICAgICAgIHRoaXMuZGlzcG9zZSgpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLnNldERpc3Bvc2FibGUgPSBmdW5jdGlvbiAodmFsdWUpIHsgdGhpcy5tLnNldERpc3Bvc2FibGUodmFsdWUpOyB9O1xyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5nZXREaXNwb3NhYmxlID0gZnVuY3Rpb24gKHZhbHVlKSB7IHJldHVybiB0aGlzLm0uZ2V0RGlzcG9zYWJsZSgpOyB9O1xyXG4gICAgICAgIC8qIEBwcml2YXRlICovXHJcbiAgICAgICAgQXV0b0RldGFjaE9ic2VydmVyUHJvdG90eXBlLmRpc3Bvc2FibGUgPSBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgcmV0dXJuIGFyZ3VtZW50cy5sZW5ndGggPyB0aGlzLmdldERpc3Bvc2FibGUoKSA6IHNldERpc3Bvc2FibGUodmFsdWUpO1xyXG4gICAgICAgIH07XHJcblxyXG4gICAgICAgIEF1dG9EZXRhY2hPYnNlcnZlclByb3RvdHlwZS5kaXNwb3NlID0gZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICBfc3VwZXIucHJvdG90eXBlLmRpc3Bvc2UuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgdGhpcy5tLmRpc3Bvc2UoKTtcclxuICAgICAgICB9O1xyXG5cclxuICAgICAgICByZXR1cm4gQXV0b0RldGFjaE9ic2VydmVyO1xyXG4gICAgfShBYnN0cmFjdE9ic2VydmVyKSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgR3JvdXBlZE9ic2VydmFibGUgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xyXG4gICAgICAgIGluaGVyaXRzKEdyb3VwZWRPYnNlcnZhYmxlLCBfc3VwZXIpO1xyXG5cclxuICAgICAgICBmdW5jdGlvbiBzdWJzY3JpYmUob2JzZXJ2ZXIpIHtcclxuICAgICAgICAgICAgcmV0dXJuIHRoaXMudW5kZXJseWluZ09ic2VydmFibGUuc3Vic2NyaWJlKG9ic2VydmVyKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8qKiBcclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAqL1xyXG4gICAgICAgIGZ1bmN0aW9uIEdyb3VwZWRPYnNlcnZhYmxlKGtleSwgdW5kZXJseWluZ09ic2VydmFibGUsIG1lcmdlZERpc3Bvc2FibGUpIHtcclxuICAgICAgICAgICAgX3N1cGVyLmNhbGwodGhpcywgc3Vic2NyaWJlKTtcclxuICAgICAgICAgICAgdGhpcy5rZXkgPSBrZXk7XHJ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VybiBuZXcgSW5uZXJTdWJzY3JpcHRpb24odGhpcywgb2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGlmICh0aGlzLmV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25FcnJvcih0aGlzLmV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gZGlzcG9zYWJsZUVtcHR5O1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIG9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIHJldHVybiBkaXNwb3NhYmxlRW1wdHk7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBpbmhlcml0cyhTdWJqZWN0LCBfc3VwZXIpO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBDcmVhdGVzIGEgc3ViamVjdC5cclxuICAgICAgICAgKiBAY29uc3RydWN0b3JcclxuICAgICAgICAgKi8gICAgICBcclxuICAgICAgICBmdW5jdGlvbiBTdWJqZWN0KCkge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSBmYWxzZSxcclxuICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSBmYWxzZSxcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGFkZFByb3BlcnRpZXMoU3ViamVjdC5wcm90b3R5cGUsIE9ic2VydmVyLCB7XHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqIEByZXR1cm5zIHtCb29sZWFufSBJbmRpY2F0ZXMgd2hldGhlciB0aGUgc3ViamVjdCBoYXMgb2JzZXJ2ZXJzIHN1YnNjcmliZWQgdG8gaXQuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgIFxyXG4gICAgICAgICAgICBoYXNPYnNlcnZlcnM6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLm9ic2VydmVycy5sZW5ndGggPiAwO1xyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBlbmQgb2YgdGhlIHNlcXVlbmNlLlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICAgICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbkNvbXBsZXRlZDogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBvcyA9IHRoaXMub2JzZXJ2ZXJzLnNsaWNlKDApO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gb3MubGVuZ3RoOyBpIDwgbGVuOyBpKyspIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3NbaV0ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBOb3RpZmllcyBhbGwgc3Vic2NyaWJlZCBvYnNlcnZlcnMgYWJvdXQgdGhlIGV4Y2VwdGlvbi5cclxuICAgICAgICAgICAgICogQHBhcmFtIHtNaXhlZH0gZXJyb3IgVGhlIGV4Y2VwdGlvbiB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICBvbkVycm9yOiBmdW5jdGlvbiAoZXhjZXB0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZXhjZXB0aW9uID0gZXhjZXB0aW9uO1xyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBhcnJpdmFsIG9mIHRoZSBzcGVjaWZpZWQgZWxlbWVudCBpbiB0aGUgc2VxdWVuY2UuXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IHZhbHVlIFRoZSB2YWx1ZSB0byBzZW5kIHRvIGFsbCBvYnNlcnZlcnMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIG9uTmV4dDogZnVuY3Rpb24gKHZhbHVlKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNTdG9wcGVkKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIG9zID0gdGhpcy5vYnNlcnZlcnMuc2xpY2UoMCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIG9zW2ldLm9uTmV4dCh2YWx1ZSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogVW5zdWJzY3JpYmUgYWxsIG9ic2VydmVycyBhbmQgcmVsZWFzZSByZXNvdXJjZXMuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgZGlzcG9zZTogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5pc0Rpc3Bvc2VkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gbnVsbDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG5cclxuICAgICAgICAvKipcclxuICAgICAgICAgKiBDcmVhdGVzIGEgc3ViamVjdCBmcm9tIHRoZSBzcGVjaWZpZWQgb2JzZXJ2ZXIgYW5kIG9ic2VydmFibGUuXHJcbiAgICAgICAgICogQHBhcmFtIHtPYnNlcnZlcn0gb2JzZXJ2ZXIgVGhlIG9ic2VydmVyIHVzZWQg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2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgXHJcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzLnB1c2gob2JzZXJ2ZXIpO1xyXG4gICAgICAgICAgICAgICAgcmV0dXJuIG5ldyBJbm5lclN1YnNjcmlwdGlvbih0aGlzLCBvYnNlcnZlcik7XHJcbiAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgIHZhciBleCA9IHRoaXMuZXhjZXB0aW9uLFxyXG4gICAgICAgICAgICAgICAgaHYgPSB0aGlzLmhhc1ZhbHVlLFxyXG4gICAgICAgICAgICAgICAgdiA9IHRoaXMudmFsdWU7XHJcblxyXG4gICAgICAgICAgICBpZiAoZXgpIHtcclxuICAgICAgICAgICAgICAgIG9ic2VydmVyLm9uRXJyb3IoZXgpO1xyXG4gICAgICAgICAgICB9IGVsc2UgaWYgKGh2KSB7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbk5leHQodik7XHJcbiAgICAgICAgICAgICAgICBvYnNlcnZlci5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgb2JzZXJ2ZXIub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIGluaGVyaXRzKEFzeW5jU3ViamVjdCwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgLyoqXHJcbiAgICAgICAgICogQ3JlYXRlcyBhIHN1YmplY3QgdGhhdCBjYW4gb25seSByZWNlaXZlIG9uZSB2YWx1ZSBhbmQgdGhhdCB2YWx1ZSBpcyBjYWNoZWQgZm9yIGFsbCBmdXR1cmUgb2JzZXJ2YXRpb25zLlxyXG4gICAgICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICAgICAqLyBcclxuICAgICAgICBmdW5jdGlvbiBBc3luY1N1YmplY3QoKSB7XHJcbiAgICAgICAgICAgIF9zdXBlci5jYWxsKHRoaXMsIHN1YnNjcmliZSk7XHJcblxyXG4gICAgICAgICAgICB0aGlzLmlzRGlzcG9zZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5pc1N0b3BwZWQgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy52YWx1ZSA9IG51bGw7XHJcbiAgICAgICAgICAgIHRoaXMuaGFzVmFsdWUgPSBmYWxzZTtcclxuICAgICAgICAgICAgdGhpcy5vYnNlcnZlcnMgPSBbXTtcclxuICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBudWxsO1xyXG4gICAgICAgIH1cclxuXHJcbiAgICAgICAgYWRkUHJvcGVydGllcyhBc3luY1N1YmplY3QucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKiBAcmV0dXJucyB7Qm9vbGVhbn0gSW5kaWNhdGVzIHdoZXRoZXIgdGhlIHN1YmplY3QgaGFzIG9ic2VydmVycyBzdWJzY3JpYmVkIHRvIGl0LlxyXG4gICAgICAgICAgICAgKi8gICAgICAgICBcclxuICAgICAgICAgICAgaGFzT2JzZXJ2ZXJzOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICBjaGVja0Rpc3Bvc2VkLmNhbGwodGhpcyk7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5vYnNlcnZlcnMubGVuZ3RoID4gMDtcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgLyoqXHJcbiAgICAgICAgICAgICAqIE5vdGlmaWVzIGFsbCBzdWJzY3JpYmVkIG9ic2VydmVycyBhYm91dCB0aGUgZW5kIG9mIHRoZSBzZXF1ZW5jZSwgYWxzbyBjYXVzaW5nIHRoZSBsYXN0IHJlY2VpdmVkIHZhbHVlIHRvIGJlIHNlbnQgb3V0IChpZiBhbnkpLlxyXG4gICAgICAgICAgICAgKi8gXHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgbywgaSwgbGVuO1xyXG4gICAgICAgICAgICAgICAgY2hlY2tEaXNwb3NlZC5jYWxsKHRoaXMpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzU3RvcHBlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKSxcclxuICAgICAgICAgICAgICAgICAgICAgICAgdiA9IHRoaXMudmFsdWUsXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGh2ID0gdGhpcy5oYXNWYWx1ZTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGh2KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvID0gb3NbaV07XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvLm9uTmV4dCh2KTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIG8ub25Db21wbGV0ZWQoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IG9zLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkNvbXBsZXRlZCgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogTm90aWZpZXMgYWxsIHN1YnNjcmliZWQgb2JzZXJ2ZXJzIGFib3V0IHRoZSBleGNlcHRpb24uXHJcbiAgICAgICAgICAgICAqIEBwYXJhbSB7TWl4ZWR9IGVycm9yIFRoZSBleGNlcHRpb24gdG8gc2VuZCB0byBhbGwgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKi8gXHJcbiAgICAgICAgICAgIG9uRXJyb3I6IGZ1bmN0aW9uIChleGNlcHRpb24pIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB2YXIgb3MgPSB0aGlzLm9ic2VydmVycy5zbGljZSgwKTtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5leGNlcHRpb24gPSBleGNlcHRpb247XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSBvcy5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBvc1tpXS5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IFtdO1xyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogU2VuZHMgYSB2YWx1ZSB0byB0aGUgc3ViamVjdC4gVGhlIGxhc3QgdmFsdWUgcmVjZWl2ZWQgYmVmb3JlIHN1Y2Nlc3NmdWwgdGVybWluYXRpb24gd2lsbCBiZSBzZW50IHRvIGFsbCBzdWJzY3JpYmVkIGFuZCBmdXR1cmUgb2JzZXJ2ZXJzLlxyXG4gICAgICAgICAgICAgKiBAcGFyYW0ge01peGVkfSB2YWx1ZSBUaGUgdmFsdWUgdG8gc3RvcmUgaW4gdGhlIHN1YmplY3QuXHJcbiAgICAgICAgICAgICAqLyAgICAgICAgICAgICBcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIGNoZWNrRGlzcG9zZWQuY2FsbCh0aGlzKTtcclxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1N0b3BwZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICB0aGlzLnZhbHVlID0gdmFsdWU7XHJcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5oYXNWYWx1ZSA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBVbnN1YnNjcmliZSBhbGwgb2JzZXJ2ZXJzIGFuZCByZWxlYXNlIHJlc291cmNlcy5cclxuICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIGRpc3Bvc2U6IGZ1bmN0aW9uICgpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMuaXNEaXNwb3NlZCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVycyA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICB0aGlzLmV4Y2VwdGlvbiA9IG51bGw7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnZhbHVlID0gbnVsbDtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG5cclxuICAgICAgICByZXR1cm4gQXN5bmNTdWJqZWN0O1xyXG4gICAgfShPYnNlcnZhYmxlKSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbiAgICB2YXIgQW5vbnltb3VzU3ViamVjdCA9IChmdW5jdGlvbiAoX3N1cGVyKSB7XHJcbiAgICAgICAgaW5oZXJpdHMoQW5vbnltb3VzU3ViamVjdCwgX3N1cGVyKTtcclxuXHJcbiAgICAgICAgZnVuY3Rpb24gc3Vic2NyaWJlKG9ic2VydmVyKSB7XHJcbiAgICAgICAgICAgIHJldHVybiB0aGlzLm9ic2VydmFibGUuc3Vic2NyaWJlKG9ic2VydmVyKTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8qKlxyXG4gICAgICAgICAqIEBwcml2YXRlXHJcbiAgICAgICAgICogQGNvbnN0cnVjdG9yXHJcbiAgICAgICAgICovXHJcbiAgICAgICAgZnVuY3Rpb24gQW5vbnltb3VzU3ViamVjdChvYnNlcnZlciwgb2JzZXJ2YWJsZSkge1xyXG4gICAgICAgICAgICBfc3VwZXIuY2FsbCh0aGlzLCBzdWJzY3JpYmUpO1xyXG4gICAgICAgICAgICB0aGlzLm9ic2VydmVyID0gb2JzZXJ2ZXI7XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2YWJsZSA9IG9ic2VydmFibGU7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICBhZGRQcm9wZXJ0aWVzKEFub255bW91c1N1YmplY3QucHJvdG90eXBlLCBPYnNlcnZlciwge1xyXG4gICAgICAgICAgICAvKipcclxuICAgICAgICAgICAgICogQHByaXZhdGVcclxuICAgICAgICAgICAgICogQG1lbWJlck9mIEFub255bW91c1N1YmplY3QjXHJcbiAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgIG9uQ29tcGxldGVkOiBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICB0aGlzLm9ic2VydmVyLm9uQ29tcGxldGVkKCk7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAgICAgKiBAbWVtYmVyT2YgQW5vbnltb3VzU3ViamVjdCNcclxuICAgICAgICAgICAgKi8gICAgICAgICAgICBcclxuICAgICAgICAgICAgb25FcnJvcjogZnVuY3Rpb24gKGV4Y2VwdGlvbikge1xyXG4gICAgICAgICAgICAgICAgdGhpcy5vYnNlcnZlci5vbkVycm9yKGV4Y2VwdGlvbik7XHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIC8qKlxyXG4gICAgICAgICAgICAgKiBAcHJpdmF0ZVxyXG4gICAgICAgICAgICAgKiBAbWVtYmVyT2YgQW5vbnltb3VzU3ViamVjdCNcclxuICAgICAgICAgICAgKi8gICAgICAgICAgICBcclxuICAgICAgICAgICAgb25OZXh0OiBmdW5jdGlvbiAodmFsdWUpIHtcclxuICAgICAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXIub25OZXh0KHZhbHVlKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH0pO1xyXG5cclxuICAgICAgICByZXR1cm4gQW5vbnltb3VzU3ViamVjdDtcclxuICAgIH0oT2JzZXJ2YWJsZSkpO1xyXG5cclxuICAgIGlmICh0eXBlb2YgZGVmaW5lID09ICdmdW5jdGlvbicgJiYgdHlwZW9mIGRlZmluZS5hbWQgPT0gJ29iamVjdCcgJiYgZGVmaW5lLmFtZCkge1xyXG4gICAgICAgIHJvb3QuUnggPSBSeDtcclxuXHJcbiAgICAgICAgZGVmaW5lKGZ1bmN0aW9uKCkge1xyXG4gICAgICAgICAgICByZXR1cm4gUng7XHJcbiAgICAgICAgfSk7XHJcbiAgICB9IGVsc2UgaWYgKGZyZWVFeHBvcnRzICYmIGZyZWVNb2R1bGUpIHtcclxuICAgICAgICAvLyBpbiBOb2RlLmpzIG9yIFJp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cmVhdGUsXHJcbiAgICAgICAgQ29tcG9zaXRlRGlzcG9zYWJsZSA9IFJ4LkNvbXBvc2l0ZURpc3Bvc2FibGUsXHJcbiAgICAgICAgU2luZ2xlQXNzaWdubWVudERpc3Bvc2FibGUgPSBSeC5TaW5nbGVBc3NpZ25tZW50RGlzcG9zYWJsZSxcclxuICAgICAgICBzbGljZSA9IEFycmF5LnByb3RvdHlwZS5zbGljZSxcclxuICAgICAgICBpbmhlcml0cyA9IFJ4LmludGVybmFscy5pbmhlcml0cyxcclxuICAgICAgICBkZWZhdWx0Q29tcGFyZXIgPSBSeC5pbnRlcm5hbHMuaXNFcXVhbDtcclxuXHJcbiAgICBmdW5jdGlvbiBhcmdzT3JBcnJheShhcmdzLCBpZHgpIHtcclxuICAgICAgICByZXR1cm4gYXJncy5sZW5ndGggPT09IDEgJiYgQXJyYXkuaXNBcnJheShhcmdzW2lkeF0pID9cclxuICAgICAgICAgICAgYXJnc1tpZHhdIDpcclxuICAgICAgICAgICAgc2xpY2UuY2FsbChhcmdzKTtcclxuICAgIH1cclxuXHJcbiAgICAvKiogXHJcbiAgICAgKiBAcHJpdmF0ZSBcclxuICAgICAqIEBjb25zdHJ1Y3RvclxyXG4gICAgICovXHJcbiAgICBmdW5jdGlvbiBPbk5leHRQcmVkaWNhdGUocHJlZGljYXRlKSB7XHJcbiAgICAgICAgdGhpcy5wcmVkaWNhdGUgPSBwcmVkaWNhdGU7XHJcbiAgICB9O1xyXG5cclxuICAgIC8qKiBcclxuICAgICAqIEBwcml2YXRlIFxyXG4gICAgICogQG1lbWJlck9mIE9uTmV4dFByZWRpY2F0ZSNcclxuICAgICAqLyAgICBcclxuICAgIE9uTmV4dFByZWRpY2F0ZS5wcm90b3R5cGUuZXF1YWxzID0gZnVuY3Rpb24gKG90aGVyKSB7XHJcbiAgICAgICAgaWYgKG90aGVyID09PSB0aGlzKSB7IHJldHVybiB0cnVlOyB9XHJcbiAgICAgICAgaWYgKG90aGVyID09IG51bGwpIHsg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AgICAgICAgdGhpcy5zdWJzY3JpcHRpb25zID0gW107XHJcbiAgICAgICAgICAgIHRoaXMub2JzZXJ2ZXJzID0gW107XHJcbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwLCBsZW4gPSB0aGlzLm1lc3NhZ2VzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XHJcbiAgICAgICAgICAgICAgICBtZXNzYWdlID0gdGhpcy5tZXNzYWdlc1tpXTtcclxuICAgICAgICAgICAgICAgIG5vdGlmaWNhdGlvbiA9IG1lc3NhZ2UudmFsdWU7XHJcbiAgICAgICAgICAgICAgICAoZnVuY3Rpb24gKGlubmVyTm90aWZpY2F0aW9uKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgc2NoZWR1bGVyLnNjaGVkdWxlQWJzb2x1dGVXaXRoU3RhdGUobnVsbCwgbWVzc2FnZS50aW1lLCBmdW5jdGlvbiAoKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBvYnMgPSBvYnNlcnZhYmxlLm9ic2VydmVycy5zbGljZSgwKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAodmFyIGogPSAwLCBqTGVuID0gb2JzLmxlbmd0aDsgaiA8IGpMZW47IGorKykge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJOb3RpZmljYXRpb24uYWNjZXB0KG9ic1tqXSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRpc3Bvc2FibGVFbXB0eTtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgICAgIH0pKG5vdGlmaWNhdGlvbik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHJldHVybiBIb3RPYnNlcnZhYmxlO1xyXG4gICAgfSkoT2JzZXJ2YWJsZSk7XHJcblxyXG4gICAgLyoqIEBwcml2YXRlICovXHJcbi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fX2FyZ3VtZW50MSxfX2FyZ3VtZW50MixfX2FyZ3VtZW50MyxfX2ZpbGVuYW1lLF9fZGlybmFtZSl7XG52YXIgUng7XG5cblJ4ID0gcmVxdWlyZSgncngnKTtcblxubW9kdWxlLmV4cG9ydHMgPSB7XG4gIFwibWFwXCI6IHtcbiAgICBcImxhYmVsXCI6IFwibWFwKHggPT4gMTAgKiB4KVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDEwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDIwLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDUwLFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0ubWFwKGZ1bmN0aW9uKHgpIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICBjb250ZW50OiB4LmNvbnRlbnQgKiAxMCxcbiAgICAgICAgICB0aW1lOiB4LnRpbWUsXG4gICAgICAgICAgaWQ6IHguaWRcbiAgICAgICAgfTtcbiAgICAgIH0pO1xuICAgIH1cbiAgfSxcbiAgXCJmaWx0ZXJcIjoge1xuICAgIFwibGFiZWxcIjogXCJmaWx0ZXIoeCA9PiB4ID4gMTApXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogNSxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxNSxcbiAgICAgICAgICBkOiAzMFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMjUsXG4gICAgICAgICAgZDogMjJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDM1LFxuICAgICAgICAgIGQ6IDVcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQ1LFxuICAgICAgICAgIGQ6IDYwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA1NSxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLmZpbHRlcihmdW5jdGlvbih4KSB7XG4gICAgICAgIHJldHVybiB4LmNvbnRlbnQgPiAxMDtcbiAgICAgIH0pO1xuICAgIH1cbiAgfSxcbiAgXCJzY2FuXCI6IHtcbiAgICBcImxhYmVsXCI6IFwic2NhbigoeCwgeSkgPT4geCArIHkpXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogNSxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxNSxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzNSxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLnNjYW4oZnVuY3Rpb24oeCwgeSkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgIGNvbnRlbnQ6IHguY29udGVudCArIHkuY29udGVudCxcbiAgICAgICAgICB0aW1lOiB4LnRpbWUsXG4gICAgICAgICAgaWQ6IHguaWQgKyB5LmlkXG4gICAgICAgIH07XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiYWdncmVnYXRlXCI6IHtcbiAgICBcImxhYmVsXCI6IFwiYWdncmVnYXRlKCh4LCB5KSA9PiB4ICsgeSlcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDM1LFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDY1LFxuICAgICAgICAgIGQ6IDVcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uYWdncmVnYXRlKGZ1bmN0aW9uKHgsIHkpIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICBjb250ZW50OiB4LmNvbnRlbnQgKyB5LmNvbnRlbnQsXG4gICAgICAgICAgdGltZTogeC50aW1lLFxuICAgICAgICAgIGlkOiB4LmlkICsgeS5pZFxuICAgICAgICB9O1xuICAgICAgfSk7XG4gICAgfVxuICB9LFxuICBcImF2ZXJhZ2VcIjoge1xuICAgIFwibGFiZWxcIjogXCJhdmVyYWdlXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogNSxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxNSxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA1MCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLmF2ZXJhZ2UoZnVuY3Rpb24oeCkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50O1xuICAgICAgfSk7XG4gICAgfVxuICB9LFxuICBcIm1pblwiOiB7XG4gICAgXCJsYWJlbFwiOiBcIm1pblwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDUsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTUsXG4gICAgICAgICAgZDogMzBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IDIyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzNSxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0NSxcbiAgICAgICAgICBkOiA2MFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cykge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS5taW4oZnVuY3Rpb24oeCwgeSkge1xuICAgICAgICBpZiAoeC5jb250ZW50ID4geS5jb250ZW50KSB7XG4gICAgICAgICAgcmV0dXJuIDE7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHguY29udGVudCA8IHkuY29udGVudCkge1xuICAgICAgICAgIHJldHVybiAtMTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gMDtcbiAgICAgIH0pO1xuICAgIH1cbiAgfSxcbiAgXCJtYXhcIjoge1xuICAgIFwibGFiZWxcIjogXCJtYXhcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDMwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiAyMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzUsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDUsXG4gICAgICAgICAgZDogNjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDU1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0ubWF4KGZ1bmN0aW9uKHgsIHkpIHtcbiAgICAgICAgaWYgKHguY29udGVudCA+IHkuY29udGVudCkge1xuICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICB9XG4gICAgICAgIGlmICh4LmNvbnRlbnQgPCB5LmNvbnRlbnQpIHtcbiAgICAgICAgICByZXR1cm4gLTE7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIDA7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiY291bnRcIjoge1xuICAgIFwibGFiZWxcIjogXCJjb3VudCh4ID0+IHggPiAxMClcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDMwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiAyMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzUsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDUsXG4gICAgICAgICAgZDogNjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDU1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uY291bnQoZnVuY3Rpb24oeCkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50ID4gMTA7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiY29udGFpbnNcIjoge1xuICAgIFwibGFiZWxcIjogXCJjb250YWlucygyMilcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDMwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiAyMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzUsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDUsXG4gICAgICAgICAgZDogNjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDU1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uY29udGFpbnMoe1xuICAgICAgICBjb250ZW50OiAyMlxuICAgICAgfSwgZnVuY3Rpb24oeCwgeSkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50ID09PSB5LmNvbnRlbnQ7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiYWxsXCI6IHtcbiAgICBcImxhYmVsXCI6IFwiYWxsKHggPT4geCA8IDEwKVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTUsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMjUsXG4gICAgICAgICAgZDogM1xuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzUsXG4gICAgICAgICAgZDogNFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNjUsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cykge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS5hbGwoZnVuY3Rpb24oeCkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50IDwgMTA7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiYW1iXCI6IHtcbiAgICBcImxhYmVsXCI6IFwiYW1iXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMTAsXG4gICAgICAgICAgZDogMjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDIwLFxuICAgICAgICAgIGQ6IDQwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiA2MFxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA1LFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfVxuICAgICAgXSwgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMjAsXG4gICAgICAgICAgZDogMFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzIsXG4gICAgICAgICAgZDogMFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDQsXG4gICAgICAgICAgZDogMFxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cykge1xuICAgICAgcmV0dXJuIFJ4Lk9ic2VydmFibGUuYW1iKGlucHV0cyk7XG4gICAgfVxuICB9LFxuICBcImNvbmNhdFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImNvbmNhdFwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAxMyxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gUnguT2JzZXJ2YWJsZS5jb25jYXQoaW5wdXRzKTtcbiAgICB9XG4gIH0sXG4gIFwibWVyZ2VcIjoge1xuICAgIFwibGFiZWxcIjogXCJtZXJnZVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDAsXG4gICAgICAgICAgZDogMjBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDE1LFxuICAgICAgICAgIGQ6IDQwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiA2MFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDUsXG4gICAgICAgICAgZDogODBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDYwLFxuICAgICAgICAgIGQ6IDEwMFxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAzNyxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2OCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gUnguT2JzZXJ2YWJsZS5tZXJnZShpbnB1dHMpO1xuICAgIH1cbiAgfSxcbiAgXCJkZWxheVwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImRlbGF5XCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzLCBzY2hlZHVsZXIpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uZGVsYXkoMjAsIHNjaGVkdWxlcik7XG4gICAgfVxuICB9LFxuICBcInRocm90dGxlXCI6IHtcbiAgICBcImxhYmVsXCI6IFwidGhyb3R0bGVcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI2LFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDM0LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQwLFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQ1LFxuICAgICAgICAgIGQ6IDVcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDkwLFxuICAgICAgICAgIGQ6IDZcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMsIHNjaGVkdWxlcikge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS50aHJvdHRsZSgyMCwgc2NoZWR1bGVyKTtcbiAgICB9XG4gIH0sXG4gIFwiY29tYmluZUxhdGVzdFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImNvbWJpbmVMYXRlc3RcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDIwLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDY1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDc1LFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDkyLFxuICAgICAgICAgIGQ6IDVcbiAgICAgICAgfVxuICAgICAgXSwgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMTAsXG4gICAgICAgICAgZDogXCJBXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IFwiQlwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA1MCxcbiAgICAgICAgICBkOiBcIkNcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTcsXG4gICAgICAgICAgZDogXCJEXCJcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBSeC5PYnNlcnZhYmxlLmNvbWJpbmVMYXRlc3QoaW5wdXRzWzBdLCBpbnB1dHNbMV0sIGZ1bmN0aW9uKHgsIHkpIHtcbiAgICAgICAgcmV0dXJuIFwiXCIgKyB4LmNvbnRlbnQgKyB5LmNvbnRlbnQ7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwiemlwXCI6IHtcbiAgICBcImxhYmVsXCI6IFwiemlwXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3NSxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA5MixcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH1cbiAgICAgIF0sIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDEwLFxuICAgICAgICAgIGQ6IFwiQVwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiBcIkJcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTAsXG4gICAgICAgICAgZDogXCJDXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDU3LFxuICAgICAgICAgIGQ6IFwiRFwiXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gUnguT2JzZXJ2YWJsZS56aXAoaW5wdXRzWzBdLCBpbnB1dHNbMV0sIGZ1bmN0aW9uKHgsIHkpIHtcbiAgICAgICAgcmV0dXJuIFwiXCIgKyB4LmNvbnRlbnQgKyB5LmNvbnRlbnQ7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwic2FtcGxlXCI6IHtcbiAgICBcImxhYmVsXCI6IFwic2FtcGxlXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2MCxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA4MCxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH1cbiAgICAgIF0sIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDEwLFxuICAgICAgICAgIGQ6IFwiQVwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyNSxcbiAgICAgICAgICBkOiBcIkJcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzMsXG4gICAgICAgICAgZDogXCJDXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDcwLFxuICAgICAgICAgIGQ6IFwiRFwiXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLnNhbXBsZShpbnB1dHNbMV0pO1xuICAgIH1cbiAgfSxcbiAgXCJzdGFydFdpdGhcIjoge1xuICAgIFwibGFiZWxcIjogXCJzdGFydFdpdGgoMSlcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzLCBzY2hlZHVsZXIpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uc3RhcnRXaXRoKHNjaGVkdWxlciwgMSk7XG4gICAgfVxuICB9LFxuICBcImZpcnN0XCI6IHtcbiAgICBcImxhYmVsXCI6IFwiZmlyc3RcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3NSxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLmZpcnN0KCk7XG4gICAgfVxuICB9LFxuICBcImxhc3RcIjoge1xuICAgIFwibGFiZWxcIjogXCJsYXN0XCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMzAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDAsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNjUsXG4gICAgICAgICAgZDogM1xuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNzUsXG4gICAgICAgICAgZDogNFxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cykge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS5sYXN0KCk7XG4gICAgfVxuICB9LFxuICBcImVsZW1lbnRBdFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImVsZW1lbnRBdCgyKVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDMwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQwLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDY1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDc1LFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMsIHNjaGVkdWxlcikge1xuICAgICAgcmV0dXJuIGlucHV0c1swXS5lbGVtZW50QXQoMik7XG4gICAgfVxuICB9LFxuICBcImZpbmRcIjoge1xuICAgIFwibGFiZWxcIjogXCJmaW5kKHggPT4geCA+IDEwKVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDUsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTUsXG4gICAgICAgICAgZDogMzBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDI1LFxuICAgICAgICAgIGQ6IDIyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzNSxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0NSxcbiAgICAgICAgICBkOiA2MFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTUsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9XG4gICAgICBdXG4gICAgXSxcbiAgICBcImFwcGx5XCI6IGZ1bmN0aW9uKGlucHV0cywgc2NoZWR1bGVyKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLmZpbmQoZnVuY3Rpb24oeCkge1xuICAgICAgICByZXR1cm4geC5jb250ZW50ID4gMTA7XG4gICAgICB9KTtcbiAgICB9XG4gIH0sXG4gIFwidGFrZVwiOiB7XG4gICAgXCJsYWJlbFwiOiBcInRha2UoMilcIixcbiAgICBcImlucHV0c1wiOiBbXG4gICAgICBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2NSxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3NSxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzLCBzY2hlZHVsZXIpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0udGFrZSgyLCBzY2hlZHVsZXIpO1xuICAgIH1cbiAgfSxcbiAgXCJza2lwXCI6IHtcbiAgICBcImxhYmVsXCI6IFwic2tpcCgyKVwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDMwLFxuICAgICAgICAgIGQ6IDFcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDQwLFxuICAgICAgICAgIGQ6IDJcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDY1LFxuICAgICAgICAgIGQ6IDNcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDc1LFxuICAgICAgICAgIGQ6IDRcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0uc2tpcCgyKTtcbiAgICB9XG4gIH0sXG4gIFwidGFrZVVudGlsXCI6IHtcbiAgICBcImxhYmVsXCI6IFwidGFrZVVudGlsXCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogMCxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAxMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyMCxcbiAgICAgICAgICBkOiAzXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzMCxcbiAgICAgICAgICBkOiA0XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA0MCxcbiAgICAgICAgICBkOiA1XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA1MCxcbiAgICAgICAgICBkOiA2XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA2MCxcbiAgICAgICAgICBkOiA3XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3MCxcbiAgICAgICAgICBkOiA4XG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA4MCxcbiAgICAgICAgICBkOiA5XG4gICAgICAgIH1cbiAgICAgIF0sIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDQ3LFxuICAgICAgICAgIGQ6IDBcbiAgICAgICAgfSwge1xuICAgICAgICAgIHQ6IDczLFxuICAgICAgICAgIGQ6IDBcbiAgICAgICAgfVxuICAgICAgXVxuICAgIF0sXG4gICAgXCJhcHBseVwiOiBmdW5jdGlvbihpbnB1dHMpIHtcbiAgICAgIHJldHVybiBpbnB1dHNbMF0udGFrZVVudGlsKGlucHV0c1sxXSk7XG4gICAgfVxuICB9LFxuICBcInNraXBVbnRpbFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcInNraXBVbnRpbFwiLFxuICAgIFwiaW5wdXRzXCI6IFtcbiAgICAgIFtcbiAgICAgICAge1xuICAgICAgICAgIHQ6IDAsXG4gICAgICAgICAgZDogMVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMTAsXG4gICAgICAgICAgZDogMlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMjAsXG4gICAgICAgICAgZDogM1xuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogMzAsXG4gICAgICAgICAgZDogNFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNDAsXG4gICAgICAgICAgZDogNVxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNTAsXG4gICAgICAgICAgZDogNlxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNjAsXG4gICAgICAgICAgZDogN1xuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogNzAsXG4gICAgICAgICAgZDogOFxuICAgICAgICB9LCB7XG4gICAgICAgICAgdDogODAsXG4gICAgICAgICAgZDogOVxuICAgICAgICB9XG4gICAgICBdLCBbXG4gICAgICAgIHtcbiAgICAgICAgICB0OiA0NyxcbiAgICAgICAgICBkOiAwXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA3MyxcbiAgICAgICAgICBkOiAwXG4gICAgICAgIH1cbiAgICAgIF1cbiAgICBdLFxuICAgIFwiYXBwbHlcIjogZnVuY3Rpb24oaW5wdXRzKSB7XG4gICAgICByZXR1cm4gaW5wdXRzWzBdLnNraXBVbnRpbChpbnB1dHNbMV0pO1xuICAgIH1cbiAgfSxcbiAgXCJkaXN0aW5jdFwiOiB7XG4gICAgXCJsYWJlbFwiOiBcImRpc3RpbmN0XCIsXG4gICAgXCJpbnB1dHNcIjogW1xuICAgICAgW1xuICAgICAgICB7XG4gICAgICAgICAgdDogNSxcbiAgICAgICAgICBkOiAxXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAyMCxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiAzNSxcbiAgICAgICAgICBkOiAyXG4gICAgICAgIH0sIHtcbiAgICAgICAgICB0OiA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HtcbiAgICBmb3IgKHZhciBwcm9wTmFtZSBpbiBwcm9wcykge1xuICAgICAgICB2YXIgcHJvcFZhbHVlID0gcHJvcHNbcHJvcE5hbWVdXG5cbiAgICAgICAgaWYgKHByb3BWYWx1ZSA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICByZW1vdmVQcm9wZXJ0eShub2RlLCBwcm9wcywgcHJldmlvdXMsIHByb3BOYW1lKTtcbiAgICAgICAgfSBlbHNlIGlmIChpc0hvb2socHJvcFZhbHVlKSkge1xuICAgICAgICAgICAgcHJvcFZhbHVlLmhvb2sobm9kZSxcbiAgICAgICAgICAgICAgICBwcm9wTmFtZSxcbiAgICAgICAgICAgICAgICBwcmV2aW91cyA/IHByZXZpb3VzW3Byb3BOYW1lXSA6IHVuZGVmaW5lZClcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChpc09iamVjdChwcm9wVmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgcGF0Y2hPYmplY3Qobm9kZSwgcHJvcHMsIHByZXZpb3VzLCBwcm9wTmFtZSwgcHJvcFZhbHVlKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAocHJvcFZhbHVlICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBub2RlW3Byb3BOYW1lXSA9IHByb3BWYWx1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufVxuXG5mdW5jdGlvbiByZW1vdmVQcm9wZXJ0eShub2RlLCBwcm9wcywgcHJldmlvdXMsIHByb3BOYW1lKSB7XG4gICAgaWYgKHByZXZpb3VzKSB7XG4gICAgICAgIHZhciBwcmV2aW91c1ZhbHVlID0gcHJldmlvdXNbcHJvcE5hbWVdXG5cbiAgICAgICAgaWYgKCFpc0hvb2socHJldmlvdXNWYWx1ZSkpIHtcbiAgICAgICAgICAgIGlmIChwcm9wTmFtZSA9PT0gXCJhdHRyaWJ1dGVzXCIpIHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBhdHRyTmFtZSBpbiBwcmV2aW91c1ZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgIG5vZGUucmVtb3ZlQXR0cmlidXRlKGF0dHJOYW1lKVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAocHJvcE5hbWUgPT09IFwic3R5bGVcIikge1xuICAgICAgICAgICAgICAgIGZvciAodmFyIGkgaW4gcHJldmlvdXNWYWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICBub2RlLnN0eWxlW2ldID0gXCJcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHByZXZpb3VzVmFsdWUgPT09IFwic3RyaW5nXCIpIHtcbiAgICAgICAgICAgICAgICBub2RlW3Byb3BOYW1lXSA9IFwiXCJcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgbm9kZVtwcm9wTmFtZV0gPSBudWxsXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbmZ1bmN0aW9uIHBhdGNoT2JqZWN0KG5vZGUsIHByb3BzLCBwcmV2aW91cywgcHJvcE5hbWUsIHByb3BWYWx1ZSkge1xuICAgIHZhciBwcmV2aW91c1ZhbHVlID0gcHJldmlvdXMgPyBwcmV2aW91c1twcm9wTmFtZV0gOiB1bmRlZmluZWRcblxuICAgIC8vIFNldCBhdHRyaWJ1dGVzXG4gICAgaWYgKHByb3BOYW1lID09PSBcImF0dHJpYnV0ZXNcIikge1xuICAgICAgICBmb3IgKHZhciBhdHRyTmFtZSBpbiBwcm9wVmFsdWUpIHtcbiAgICAgICAgICAgIHZhciBhdHRyVmFsdWUgPSBwcm9wVmFsdWVbYXR0ck5hbWVdXG5cbiAgICAgICAgICAgIGlmIChhdHRyVmFsdWUgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIG5vZGUucmVtb3ZlQXR0cmlidXRlKGF0dHJOYW1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AgICB2YXIgbmV4dEluZGV4ID0gcm9vdEluZGV4ICsgKHZDaGlsZC5jb3VudCB8fCAwKVxuXG4gICAgICAgICAgICAgICAgLy8gc2tpcCByZWN1cnNpb24gZG93biB0aGUgdHJlZSBpZiB0aGVyZSBhcmUgbm8gbm9kZXMgZG93biBoZXJlXG4gICAgICAgICAgICAgICAgaWYgKGluZGV4SW5SYW5nZShpbmRpY2VzLCByb290SW5kZXgsIG5leHRJbmRleCkpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVjdXJzZShjaGlsZE5vZGVzW2ldLCB2Q2hpbGQsIGluZGljZXMsIG5vZGVzLCByb290SW5kZXgpXG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgcm9vdEluZGV4ID0gbmV4dEluZGV4XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gbm9kZXNcbn1cblxuLy8gQmluYXJ5IHNlYXJjaCBmb3IgYW4gaW5kZXggaW4gdGhlIGludGVydmFsIFtsZWZ0LCByaWdodF1cbmZ1bmN0aW9uIGluZGV4SW5SYW5nZShpbmRpY2VzLCBsZWZ0LCByaWdodCkge1xuICAgIGlmIChpbmRpY2VzLmxlbmd0aCA9PT0gMCkge1xuICAgICAgICByZXR1cm4gZmFsc2VcbiAgICB9XG5cbiAgICB2YXIgbWluSW5kZXggPSAwXG4gICAgdmFyIG1heEluZGV4ID0gaW5kaWNlcy5sZW5ndGggLSAxXG4gICAgdmFyIGN1cnJlbnRJbmRleFxuICAgIHZhciBjdXJyZW50SXRlbVxuXG4gICAgd2hpbGUgKG1pbkluZGV4IDw9IG1heEluZGV4KSB7XG4gICAgICAgIGN1cnJlbnRJbmRleCA9ICgobWF4SW5kZXggKyBtaW5JbmRleCkgLyAyKSA+PiAwXG4gICAgICAgIGN1cnJlbnRJdGVtID0gaW5kaWNlc1tjdXJyZW50SW5kZXhdXG5cbiAgICAgICAgaWYgKG1pbkluZGV4ID09PSBtYXhJ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iZcbiAgICAgICAgICAgICAgICBhLm5hbWVzcGFjZSA9PT0gYi5uYW1lc3BhY2UgJiZcbiAgICAgICAgICAgICAgICBhLmtleSA9PT0gYi5rZXkpIHtcbiAgICAgICAgICAgICAgICB2YXIgcHJvcHNQYXRjaCA9IGRpZmZQcm9wcyhhLnByb3BlcnRpZXMsIGIucHJvcGVydGllcywgYi5ob29rcylcbiAgICAgICAgICAgICAgICBpZiAocHJvcHNQYXRjaCkge1xuICAgICAgICAgICAgICAgICAgICBhcHBseSA9IGFwcGVuZFBhdGNoKGFwcGx5LFxuICAgICAgICAgICAgICAgICAgICAgICAgbmV3IFZQYXRjaChWUGF0Y2guUFJPUFMsIGEsIHByb3BzUGF0Y2gpKVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgYXBwbHkgPSBhcHBlbmRQYXRjaChhcHBseSwgbmV3IFZQYXRjaChWUGF0Y2guVk5PREUsIGEsIGIpKVxuICAgICAgICAgICAgICAgIGRlc3Ryb3lXaWRnZXRzKGEsIHBhdGNoLCBpbmRleClcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgYXBwbHkgPSBkaWZmQ2hpbGRyZW4oYSwgYiwgcGF0Y2gsIGFwcGx5LCBpbmRleClcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGFwcGx5ID0gYXBwZW5kUGF0Y2goYXBwbHksIG5ldyBWUGF0Y2goVlBhdGNoLlZOT0RFLCBhLCBiKSlcbiAgICAgICAgICAgIGRlc3Ryb3lXaWRnZXRzKGEsIHBhdGNoLCBpbmRleClcbiAgICAgICAgfVxuICAgIH0gZWxzZSBpZiAoaXNWVGV4dChiKSkge1xuICAgICAgICBpZiAoIWlzVlRleHQoYSkpIHtcbiAgICAgICAgICAgIGFwcGx5ID0gYXBwZW5kUGF0Y2goYXBwbHksIG5ldyBWUGF0Y2goVlBhdGNoLlZURVhULCBhLCBiKSlcbiAgICAgICAgICAgIGRlc3Ryb3lXaWRnZXRzKGEsIHBhdGNoLCBpbmRleClcbiAgICAgICAgfSBlbHNlIGlmIChhLnRleHQgIT09IGIudGV4dCkge1xuICAgICAgICAgICAgYXBwbHkgPSBhcHBlbmRQYXRjaChhcHBseSwgbmV3IFZQYXRjaChWUGF0Y2guVlRFWFQsIGEsIGIpKVxuICAgICAgICB9XG4gICAgfSBlbHNlIGlmIChpc1dpZGdldChiKSkge1xuICAgICAgICBhcHBseSA9IGFwcGVuZFBhdGNoKGFwcGx5LCBuZXcgVlBhdGNoKFZQYXRjaC5XSURHRVQsIGEsIGIpKVxuXG4gICAgICAgIGlmICghaXNXaWRnZXQoYSkpIHtcbiAgICAgICAgICAgIGRlc3Ryb3lXaWRnZXRzKGEsIHBhdGNoLCBpbmRleClcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGlmIChhcHBseSkge1xuICAgICAgICBwYXRjaFtpbmRleF0gPSBhcHBseVxuICAgIH1cbn1cblxuZnVuY3Rpb24gZGlmZlByb3BzKGEsIGIsIGhvb2tzKSB7XG4gICAgdmFyIGRpZmZcblxuICAgIGZvciAodmFyIGFLZXkgaW4gYSkge1xuICAgICAgICBpZiAoIShhS2V5IGluIGIpKSB7XG4gICAgICAgICAgICBkaWZmID0gZGlmZiB8fCB7fVxuICAgICAgICAgICAgZGlmZlthS2V5XSA9IHVuZGVmaW5lZFxuICAgICAgICB9XG5cbiAgICAgICAgdmFyIGFWYWx1ZSA9IGFbYUtleV1cbiAgICAgICAgdmFyIGJWYWx1ZSA9IGJbYUtleV1cblxuICAgICAgICBpZiAoaG9va3MgJiYgYUtleSBpbiBob29rcykge1xuICAgICAgICAgICAgZGlmZiA9IGRpZmYgfHwge31cbiAgICAgICAgICAgIGRpZmZbYUtleV0gPSBiVmFsdWVcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChpc09iamVjdChhVmFsdWUpICYmIGlzT2JqZWN0KGJWYWx1ZSkpIHtcbiAgICAgICAgICAgICAgICBpZiAoZ2V0UHJvdG90eXBlKGJWYWx1ZSkgIT09IGdldFByb3RvdHlwZShhVmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgICAgIGRpZmZbYUtleV0gPSBiVmFsdWVcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB2YXIgb2JqZWN0RGlmZiA9IGRpZmZQcm9wcyhhVmFsdWUsIGJWYWx1ZSlcbiAgICAgICAgICAgICAgICAgICAgaWYgKG9iamVjdERpZmYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgICAgICAgICBkaWZmW2FLZXldID0gb2JqZWN0RGlmZlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmIChhVmFsdWUgIT09IGJWYWx1ZSkge1xuICAgICAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICAgICAgZGlmZlthS2V5XSA9IGJWYWx1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZm9yICh2YXIgYktleSBpbiBiKSB7XG4gICAgICAgIGlmICghKGJLZXkgaW4gYSkpIHtcbiAgICAgICAgICAgIGRpZmYgPSBkaWZmIHx8IHt9XG4gICAgICAgICAgICBkaWZmW2JLZXldID0gYltiS2V5XVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgcmV0dXJuIGRpZmZcbn1cblxuZnVuY3Rpb24gZ2V0UHJvdG90eXBlKHZhbHVlKSB7XG4gICAgaWYgKE9iamVjdC5nZXRQcm90b3R5cGVPZikge1xuICAgICAgICByZXR1cm4gT2JqZWN0LmdldFByb3RvdHlwZU9mKHZhbHVlKVxuICAgIH0gZWxzZSBpZiAodmFsdWUuX19wcm90b19fKSB7XG4gIC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09IFwiYVwiKSB7XG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiBmYWxzZTtcbn1cblxuLy8gRXhlY3V0ZSBob29rcyB3aGVuIHR3byBub2RlcyBhcmUgaWRlbnRpY2FsXG5mdW5jdGlvbiBob29rcyh2Tm9kZSwgcGF0Y2gsIGluZGV4KSB7XG4gICAgaWYgKGlzVk5vZGUodk5vZGUpKSB7XG4gICAgICAgIGlmICh2Tm9kZS5ob29rcykge1xuICAgICAgICAgICAgcGF0Y2hbaW5kZXhdID0gbmV3IFZQYXRjaChWUGF0Y2guUFJPUFMsIHZOb2RlLmhvb2tzLCB2Tm9kZS5ob29rcylcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh2Tm9kZS5kZXNjZW5kYW50SG9va3MpIHtcbiAgICAgICAgICAgIHZhciBjaGlsZHJlbiA9IHZOb2RlLmNoaWxkcmVuXG4gICAgICAgICAgICB2YXIgbGVuID0gY2hpbGRyZW4ubGVuZ3RoXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgdmFyIGNoaWxkID0gY2hpbGRyZW5baV1cbiAgICAgICAgICAgICAgICBpbmRleCArPSAxXG5cbiAgICAgICAgICAgICAgICBob29rcyhjaGlsZCwgcGF0Y2gsIGluZGV4KVxuXG4gICAgICAgICAgICAgICAgaWYgKGlzVk5vZGUoY2hpbGQpICYmIGNoaWxkLmNvdW50KSB7XG4gICAgICAgICAgICAgICAgICAgIGluZGV4ICs9IGNoaWxkLmNvdW50XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufVxuXG4vLyBMaXN0IGRpZmYsIG5haXZlIGxlZnQgdG8gcmlnaHQgcmVvcmRlcmluZ1xuZnVuY3Rpb24gcmVvcmRlcihhQ2hpbGRyZW4sIGJDaGlsZHJlbikge1xuXG4gICAgd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AgICAgICAgICBpZiAobW92ZSAhPT0gbW92ZUluZGV4KSB7XG4gICAgICAgICAgICAgICAgbW92ZXNbbW92ZV0gPSBtb3ZlSW5kZXhcbiAgICAgICAgICAgICAgICByZXZlcnNlW21vdmVJbmRleF0gPSBtb3ZlXG4gICAgICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBtb3ZlSW5kZXgrK1xuICAgICAgICB9IGVsc2UgaWYgKGkgaW4gYU1hdGNoKSB7XG4gICAgICAgICAgICBzaHVmZmxlW2ldID0gdW5kZWZpbmVkXG4gICAgICAgICAgICByZW1vdmVzW2ldID0gbW92ZUluZGV4KytcbiAgICAgICAgICAgIGhhc01vdmVzID0gdHJ1ZVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgd2hpbGUgKGJNYXRjaFtmcmVlSW5kZXhdICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBmcmVlSW5kZXgrK1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoZnJlZUluZGV4IDwgbGVuKSB7XG4gICAgICAgICAgICAgICAgdmFyIGZyZWVDaGlsZCA9IGJDaGlsZHJlbltmcmVlSW5kZXhdXG4gICAgICAgICAgICAgICAgaWYgKGZyZWVDaGlsZCkge1xuICAgICAgICAgICAgICAgICAgICBzaHVmZmxlW2ldID0gZnJlZUNoaWxkXG4gICAgICAgICAgICAgICAgICAgIGlmIChmcmVlSW5kZXggIT09IG1vdmVJbmRleCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaGFzTW92ZXMgPSB0cnVlXG4gICAgICAgICAgICAgICAgICAgICAgICBtb3Zlc1tmcmVlSW5kZXhdID0gbW92ZUluZGV4XG4gICAgICAgICAgICAgICAgICAgICAgICByZXZlcnNlW21vdmVJbmRleF0gPSBmcmVlSW5kZXhcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBtb3ZlSW5kZXgrK1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBmcmVlSW5kZXgrK1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGkrK1xuICAgIH1cblxuICAgIGlmIChoYXNNb3Zlcykge1xuICAgICAgICBzaHVmZmxlLm1vdmVzID0gbW92ZXNcbiAgICB9XG5cbiAgICByZXR1cm4gc2h1ZmZsZVxufVxuXG5mdW5jdGlvbiBrZXlJbmRleChjaGlsZHJlbikge1xuICAgIHZhciBpLCBrZXlzXG5cbiAgICBmb3IgKGkgPSAwOyBpIDwgY2hpbGRyZW4ubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgdmFyIGNoaWxkID0gY2hpbGRyZW5baV1cblxuICAgICAgICBpZiAoY2hpbGQua2V5ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIGtleXMgPSBrZXlzIHx8IHt9XG4gICAgICAgICAgICBrZXlzW2NoaWxkLmtleV0gPSBpXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4ga2V5c1xufVxuXG5mdW5jdGlvbiBhcHBlbmRQYXRjaChhcHBseSwgcGF0Y2gpIHtcbiAgICBpZiAoYXBwbHkpIHtcbiAgICAgICAgaWYgKGlzQXJyYXkoYXBwbHkpKSB7XG4gICAgICAgICAgICBhcHBseS5wdXNoKHBhdGNoKVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYXBwbHkgPSBbYXBwbHksIHBhdGNoXVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIGFwcGx5XG4gICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIHBhdGNoXG4gICAgfVxufVxuXG59KS5jYWxsKHRoaXMscmVxdWlyZShcIm9NZnBBblwiKSx0eXBlb2Ygc2VsZiAhPT0gXCJ1bmRlZmluZWRcIiA/IHNlbGYgOiB0eXBlb2Ygd2luZG93ICE9PSBcInVuZGVmaW5lZFwiID8gd2luZG93IDoge30scmVxdWlyZShcIm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0aWVzW2tleV1cbiAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gXCJzdHJpbmdcIiAmJlxuICAgICAgICAgICAgdHlwZW9mIHZhbHVlICE9PSBcIm51bWJlclwiICYmXG4gICAgICAgICAgICB0eXBlb2YgdmFsdWUgIT09IFwiYm9vbGVhblwiXG4gICAgICAgICkge1xuICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgfVxuXG4gICAgICAgIHByb3BlcnRpZXNba2V5XSA9IGF0dHJpYnV0ZUhvb2sodmFsdWUpXG4gICAgfVxuXG4gICAgcmV0dXJuIGgodGFnTmFtZSwgcHJvcGVydGllcywgY2hpbGRyZW4pXG59XG5cbmZ1bmN0aW9uIGlzQ2hpbGRyZW4oeCkge1xuICAgIHJldHVybiB0eXBlb2YgeCA9PT0gXCJzdHJpbmdcIiB8fCBBcnJheS5pc0FycmF5KHgpXG59XG5cbn0pLmNhbGwodGhpcyxyZXF1aXJlKFwib01mcEFuXCIpLHR5cGVvZiBzZWxmICE9PSBcInVuZGVmaW5lZFwiID8gc2VsZiA6IHR5cGVvZiB3aW5kb3cgIT09IFwidW5kZWZpbmVkXCIgPyB3aW5kb3cgOiB7fSxyZXF1aXJlKFwiYnVmZmVyXCIpLkJ1ZmZlcixhcmd1bWVudHNbM10sYXJndW1lbnRzWzRdLGFyZ3VtZW50c1s1XSxhcmd1bWVudHNbNl0sXCIvLi4vLi4vbm9kZV9tb2R1bGVzL3ZpcnR1YWwtaHlwZXJzY3JpcHQvc3ZnLmpzXCIsXCIvLi4vLi4vbm9kZV9tb2R1bGVzL3ZpcnR1YWwtaHlwZXJzY3JpcHRcIikiXX0= diff --git a/src/views/operators-menu.coffee b/src/views/operators-menu.coffee index 253c4e2..640abda 100644 --- a/src/views/operators-menu.coffee +++ b/src/views/operators-menu.coffee @@ -7,6 +7,17 @@ Examples = require 'rxmarbles/models/examples' selected$ = new Rx.Subject() +getDocumentHeight = -> + body = document.body + html = document.documentElement + return Math.max( + body.scrollHeight, + body.offsetHeight, + html.clientHeight, + html.scrollHeight, + html.offsetHeight + ) + renderMenuItem = (example) -> link = h("a", {href: "##{example.key}"}, example.key) Rx.Observable.fromEvent(link, "click").subscribe(-> @@ -15,6 +26,13 @@ renderMenuItem = (example) -> ) return h("li", [link]) +fixListHeight = (listElement) -> + Rx.Observable.timer(1).subscribe(-> + height = getDocumentHeight() - listElement.getBoundingClientRect().top + listElement.style.height = "#{height}px" + return true + ) + module.exports = { getSelected$: -> return selected$ @@ -24,7 +42,9 @@ module.exports = { for own key,value of Examples value.key = key menuItems.push(value) - return h("ul.operators-menu", + listElement = h("ul.operators-menu", (renderMenuItem(example) for example in menuItems) ) + fixListHeight(listElement) + return listElement } diff --git a/styles/main.less b/styles/main.less index 4673f44..f3ec700 100644 --- a/styles/main.less +++ b/styles/main.less @@ -64,8 +64,8 @@ ul.operators-menu { margin: 0; padding: 0; list-style-type: none; - border-top: 1px solid @color-grey-light; overflow-y: scroll; + height: 2px; li > a { color: @color-grey-dark; font-size: 1rem;