diff --git a/PR-247/COMMITHASH b/PR-247/COMMITHASH
index b6ab3b95..b2da21f4 100644
--- a/PR-247/COMMITHASH
+++ b/PR-247/COMMITHASH
@@ -1 +1 @@
-fc452e9506a5679aeaf546fb7bb346a5232fc976
\ No newline at end of file
+61e6ae2518f026a049e0ac484cc4f126cf9c91bb
\ No newline at end of file
diff --git a/PR-247/VERSION b/PR-247/VERSION
index 07989bba..2117f645 100644
--- a/PR-247/VERSION
+++ b/PR-247/VERSION
@@ -1 +1 @@
-fc452e9
\ No newline at end of file
+61e6ae2
\ No newline at end of file
diff --git a/PR-247/index.html b/PR-247/index.html
index c877066a..17e28a9f 100644
--- a/PR-247/index.html
+++ b/PR-247/index.html
@@ -8,7 +8,7 @@
1.4.1 - Firebolt Certification App - version 1.4.1
-
+
NBQVM7QUFDVDtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBLFNBQVM7QUFDVDtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSxTQUFTO0FBQ1Q7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSxhQUFhO0FBQ2I7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EsU0FBUztBQUNUO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EsU0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yJJywgJ82jJywgJ82kJywgJ82lJyxcbiAgICAgICfNpicsICfNpycsICfNqCcsICfNqScsXG4gICAgICAnzaonLCAnzasnLCAnzawnLCAnza0nLFxuICAgICAgJ82uJywgJ82vJywgJ8y+JywgJ82bJyxcbiAgICAgICfNhicsICfMmicsXG4gICAgXSxcbiAgICAnZG93bic6IFtcbiAgICAgICfMlicsICfMlycsICfMmCcsICfMmScsXG4gICAgICAnzJwnLCAnzJ0nLCAnzJ4nLCAnzJ8nLFxuICAgICAgJ8ygJywgJ8ykJywgJ8ylJywgJ8ymJyxcbiAgICAgICfMqScsICfMqicsICfMqycsICfMrCcsXG4gICAgICAnzK0nLCAnzK4nLCAnzK8nLCAnzLAnLFxuICAgICAgJ8yxJywgJ8yyJywgJ8yzJywgJ8y5JyxcbiAgICAgICfMuicsICfMuycsICfMvCcsICfNhScsXG4gICAgICAnzYcnLCAnzYgnLCAnzYknLCAnzY0nLFxuICAgICAgJ82OJywgJ82TJywgJ82UJywgJ82VJyxcbiAgICAgICfNlicsICfNmScsICfNmicsICfMoycsXG4gICAgXSxcbiAgICAnbWlkJzogW1xuICAgICAgJ8yVJywgJ8ybJywgJ8yAJywgJ8yBJyxcbiAgICAgICfNmCcsICfMoScsICfMoicsICfMpycsXG4gICAgICAnzKgnLCAnzLQnLCAnzLUnLCAnzLYnLFxuICAgICAgJ82cJywgJ82dJywgJ82eJyxcbiAgICAgICfNnycsICfNoCcsICfNoicsICfMuCcsXG4gICAgICAnzLcnLCAnzaEnLCAnINKJJyxcbiAgICBdLFxuICB9O1xuICB2YXIgYWxsID0gW10uY29uY2F0KHNvdWwudXAsIHNvdWwuZG93biwgc291bC5taWQpO1xuXG4gIGZ1bmN0aW9uIHJhbmRvbU51bWJlcihyYW5nZSkge1xuICAgIHZhciByID0gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogcmFuZ2UpO1xuICAgIHJldHVybiByO1xuICB9XG5cbiAgZnVuY3Rpb24gaXNDaGFyKGNoYXJhY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cbiAgICAgICAgY2FzZSAnbWluaSc6XG4gICAgICAgICAgY291bnRzLnVwID0gcmFuZG9tTnVtYmVyKDgpO1xuICAgICAgICAgIGNvdW50cy5taWQgPSByYW5kb21OdW1iZXIoMik7XG4gICAgICAgICAgY291bnRzLmRvd24gPSByYW5kb21OdW1iZXIoOCk7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIGNhc2UgJ21heGknOlxuICAgICAgICAgIGNvdW50cy51cCA9IHJhbmRvbU51bWJlcigxNikgKyAzO1xuICAgICAgICAgIGNvdW50cy5taWQgPSByYW5kb21OdW1iZXIoNCkgKyAxO1xuICAgICAgICAgIGNvdW50cy5kb3duID0gcmFuZG9tTnVtYmVyKDY0KSArIDM7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgY291bnRzLnVwID0gcmFuZG9tTnVtYmVyKDgpICsgMTtcbiAgICAgICAgICBjb3VudHMubWlkID0gcmFuZG9tTnVtYmVyKDYpIC8gMjtcbiAgICAgICAgICBjb3VudHMuZG93biA9IHJhbmRvbU51bWJlcig4KSArIDE7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICB9XG5cbiAgICAgIHZhciBhcnIgPSBbJ3VwJywgJ21pZCcsICdkb3duJ107XG4gICAgICBmb3IgKHZhciBkIGluIGFycikge1xuICAgICAgICB2YXIgaW5kZXggPSBhcnJbZF07XG4gICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDw9IGNvdW50c1tpbmRleF07IGkrKykge1xuICAgICAgICAgIGlmIChvcHRpb25zW2luZGV4XSkge1xuICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgc291bFtpbmRleF1bcmFuZG9tTnVtYmVyKHNvdWxbaW5kZXhdLmxlbmd0aCldO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4gcmVzdWx0O1xuICB9XG4gIC8vIGRvbid0IHN1bW1vbiBoaW1cb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XG4gICAgfSlcblxuICAgIGxldCByZXNvbHZlLCByZWplY3RcbiAgICBsZXQgcCA9IG5ldyBQcm9taXNlKChyZXMsIHJlaikgPT4ge1xuICAgICAgcmVzb2x2ZSA9IHJlc1xuICAgICAgcmVqZWN0ID0gcmVqXG4gICAgfSlcblxuICAgIGlmIChwcm9taXNlcy5sZW5ndGgpIHtcbiAgICAgIFByb21pc2UuYWxsKHByb21pc2VzKVxuICAgICAgICAudGhlbigocmVzcG9uc2VzKSA9PiB7XG4gICAgICAgICAgcmVzb2x2ZShsaXN0ZW5lcklkKVxuICAgICAgICB9KVxuICAgICAgICAuY2F0Y2goKGVycm9yKSA9PiB7XG4gICAgICAgICAgLy8gUHJvbWlzZS5hbGwgcmVqZWN0cyBpZiBhdCBsZWFzdCBvbmUgcHJvbWlzZSByZWplY3RzLi4uIHdlIGRvbid0IHdhbnQgdGhhdCBiZWhhdmlvciBoZXJlXG4gICAgICAgICAgLy8gVE9ETzogRG8gc29tZXRoaW5nIGJldHRlciB0aGFuIGZhaWwgc2lsZW50bHlcbiAgICAgICAgICBpZiAoZXZlbnQgPT09ICcqJykge1xuICAgICAgICAgICAgcmVzb2x2ZShsaXN0ZW5lcklkKVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZWplY3QoZXJyb3IpXG4gICAgICAgICAgfVxuICAgICAgICB9KVxuICAgIH0gZWxzZSB7XG4gICAgICByZXNvbHZlKGxpc3RlbmVySWQpXG4gICAgfVxuICAgIHJldHVybiBwXG4gIH1cbn1cblxuY29uc3QgZ2V0TGlzdGVuQXJncyA9IGZ1bmN0aW9uICguLi5hcmdzKSB7XG4gIGNvbnN0IGNhbGxiYWNrID0gYXJncy5wb3AoKVxuICBjb25zdCBbbW9kdWxlLCBldmVudCwgY29udGV4dF0gPSBnZXRDbGVhckFyZ3MoLi4uYXJncylcblxuICByZXR1cm4gW21vZHVsZSwgZXZlbnQsIGNhbGxiYWNrLCBjb250ZXh0XVxufVxuXG5jb25zd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2ZW50TWFwW2tleV0gPT09XG4gICAgICAgICAgbW9kdWxlLnRvTG93ZXJDYXNlKCkgK1xuICAgICAgICAgICAgJy4nICtcbiAgICAgICAgICAgIG1ldGhvZFsyXS50b0xvd2VyQ2FzZSgpICtcbiAgICAgICAgICAgIG1ldGhvZC5zdWJzdHIoMylcbiAgICAgICAgKSB7XG4gICAgICAgICAgZGVsZXRlIGV2ZW50TWFwW2tleV1cbiAgICAgICAgfVxuICAgICAgfSlcbiAgICB9XG4gIH1cblxuICBpZiAobW9jaykgaGFuZGxlKGpzb24pXG4gIGVsc2UgcGVuZGluZy5wdXNoKGpzb24pXG59XG5cbmZ1bmN0aW9uIGhhbmRsZShqc29uKSB7XG4gIGxldCByZXN1bHRcbiAgdHJ5IHtcbiAgICByZXN1bHQgPSBnZXRSZXN1bHQoanNvbi5tZXRob2QsIGpzb24ucGFyYW1zKVxuICB9IGNhdGNoIChlcnJvcikge1xuICAgIHNldFRpbWVvdXQoKCkgPT5cbiAgICAgIGNhbGxiYWNrKFxuICAgICAgICBKU09OLnN0cmluZ2lmeSh7XG4gICAgICAgICAganNvbnJwYzogJzIuMCcsXG4gICAgICAgICAgZXJyb3I6IHtcbiAgICAgICAgICAgIGNvZGU6IC0zMjYwMixcbiAgICAgICAgICAgIG1lc3NhZ2U6XG4gICAgICAgICAgICAgICdJbnZhbGlkIHBhcmFtcyAodGhpcyBpcyBhIG1vY2sgZXJyb3IgZnJvbSB0aGUgbW9jayB0cmFuc3BvcnQgbGF5ZXIpJyxcbiAgICAgICAgICB9LFxuICAgICAgICAgIGlkOiBqc29uLmlkLFxuICAgICAgICB9KSxcbiAgICAgICksXG4gICAgKVxuICB9XG5cbiAgc2V0VGltZW91dCgoKSA9PlxuICAgIGNhbGxiYWNrKFxuICAgICAgSlNPTi5zdHJpbmdpZnkoe1xuICAgICAgICBqc29ucnBjOiAnMi4wJyxcbiAgICAgICAgcmVzdWx0OiByZXN1bHQsXG4gICAgICAgIGlkOiBqc29uLmlkL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NhbGxiYWNrICE9PSAnZnVuY3Rpb24nKSB7XG4gICAgcmV0dXJuIFByb21pc2UucmVqZWN0KCdObyB2YWxpZCBjYWxsYmFjayBmdW5jdGlvbiBwcm92aWRlZC4nKVxuICB9IGVsc2Uge1xuICAgIGlmIChtb2R1bGUgPT09ICcqJykge1xuICAgICAgcmV0dXJuIFByb21pc2UucmVqZWN0KCdObyB2YWxpZCBtb2R1bGUgbmFtZSBwcm92aWRlZCcpXG4gICAgfVxuXG4gICAgY29uc3Qgd2lsZGNhcmQgPSBldmVudCA9PT0gJyonXG4gICAgY29uc3QgZXZlbnRzID0gd2lsZGNhcmQgPyB2YWxpZEV2ZW50c1ttb2R1bGVdIDogW2V2ZW50XSAvLyBleHBsb2RlcyB3aWxkY2FyZHMgaW50byBhbiBhcnJheVxuICAgIGNvbnN0IHByb21pc2VzID0gW11cbiAgICBjb25zdCBoYXNDb250ZXh0ID0gT2JqZWN0LnZhbHVlcyhjb250ZXh0KS5sZW5ndGggPiAwXG4gICAgY29uc3QgY29udGV4dEtleSA9IE9iamVjdC5rZXlzKGNvbnRleHQpXG4gICAgICAuc29ydCgpXG4gICAgICAubWFwKChrZXkpID0+IGtleSArICc9JyArIEpTT04uc3RyaW5naWZ5KGNvbnRleHRba2V5XSkpXG4gICAgICAuam9pbignJicpXG5cbiAgICBsaXN0ZW5lcklkKytcblxuICAgIGlmIChvbmNlKSB7XG4gICAgICBvbmNlcnMucHVzaChsaXN0ZW5lcklkKVxuICAgIH1cblxuICAgIGV2ZW50cy5mb3JFYWNoKChldmVudCkgPT4ge1xuICAgICAgY29uc3Qga2V5ID0gbW9kdWxlICsgJy4nICsgZXZlbnQgKyAoaGFzQ29udGV4dCA/IGAuJHtjb250ZXh0S2V5fWAgOiAnJylcblxuICAgICAgaWYgKE9iamVjdC52YWx1ZXMobGlzdGVuZXJzLmdldChrZXkpKS5sZW5ndGggPT09IDApIHtcbiAgICAgICAgY29uc3QgYXJncyA9IE9iamVjdC5hc3NpZ24oeyBsaXN0ZW46IHRydWUgfSwgY29udGV4dClcbiAgICAgICAgY29uc3QgeyBpZCwgcHJvbWlzZSB9ID0gVHJhbnNwb3J0Lmxpc3RlbihcbiAgICAgICAgICBtb2R1bGUsXG4gICAgICAgICAgJ29uJyArIGV2ZW50WzBdLnRvVXBwZXJDYXNlKCkgKyBldmVudC5zdWJzdHJpbmcoMSksXG4gICAgICAgICAgYXJncyxcbiAgICAgICAgKVxuICAgICAgICBrZXlzW2lkXSA9IGtleVxuICAgICAgICBwcm9taXNlcy5wdXNoKHByb21pc2UpXG4gICAgICB9XG5cbiAgICAgIGNvbnN0IHNldHRlciA9IGludGVybmFsID8gbGlzdGVuZXJzLnNldEludGVybmFsIDogbGlzdGVuZXJzLnNldFxuXG4gICAgICBpZiAod2lsZGNhcmQpIHtcbiAgICAgICAgc2V0dGVyKGtleSwgJycgKyBsaXN0ZW5lcklkLCAodmFsdWUpID0+IGNhbGxiYWNrKGV2ZW50LCB2YWx1ZSkpXG4gICAgICB9IGVsc2Uge1xuICAgICAgICBzZXR0ZXIoa2V5LCAnJyArIGxpc3RlbmVySWQsIGNhbGxiYWNrKVxuICAgICAgfVxuICAgIH0pXG5cbiAgICBsZXQgcmVzb2x2ZSwgcmVqZWN0XG4gICAgbGV0IHAgPSBuZXcgUHJvbWlzZSgocmVzLCByZWopID0+IHtcbiAgICAgIHJlc29sdmUgPSByZXNcbiAgICAgIHJlamVjdCA9IHJlalxuICAgIH0pXG5cbiAgICBpZiAocHJvbWlzZXMubGVuZ3RoKSB7XG4gICAgICBQcm9taXNlLmFsbChwcm9taXNlcylcbiAgICAgICAgLnRoZW4oKHJlc3BvbnNlcykgPT4ge1xuICAgICAgICAgIHJlc29sdmUobGlzdGVuZXJJZClcbiAgICAgICAgfSlcbiAgICAgICAgLmNhdGNoKChlcnJvcikgPT4ge1xuICAgICAgICAgIC8vIFByb21pc2UuYWxsIHJlamVjdHMgaWYgYXQgbGVhc3Qgb25lIHByb21pc2UgcmVqZWN0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HVybiBmYWxzZVxuICB9IGVsc2Uge1xuICAgIGlmICghbW9kdWxlT3JJZCAmJiAhZXZlbnQpIHtcbiAgICAgIGxpc3RlbmVycy5rZXlzKCkuZm9yRWFjaCgoa2V5KSA9PiB7XG4gICAgICAgIGxpc3RlbmVycy5yZW1vdmVLZXkoa2V5KVxuICAgICAgICB1bnN1YnNjcmliZShrZXkpXG4gICAgICB9KVxuICAgIH0gZWxzZSBpZiAoIWV2ZW50KSB7XG4gICAgICBsaXN0ZW5lcnMua2V5cygpLmZvckVhY2goKGtleSkgPT4ge1xuICAgICAgICBpZiAoa2V5LmluZGV4T2YobW9kdWxlT3JJZC50b0xvd2VyQ2FzZSgpKSA9PT0gMCkge1xuICAgICAgICAgIGxpc3RlbmVycy5yZW1vdmVLZXkoa2V5KVxuICAgICAgICAgIHVuc3Vic2NyaWJlKGtleSlcbiAgICAgICAgfVxuICAgICAgfSlcbiAgICB9IGVsc2Uge1xuICAgICAgY29uc3QgaGFzQ29udGV4dCA9IE9iamVjdC52YWx1ZXMoY29udGV4dCkubGVuZ3RoID4gMFxuICAgICAgY29uc3QgY29udGV4dEtleSA9IE9iamVjdC5rZXlzKGNvbnRleHQpXG4gICAgICAgIC5zb3J0KClcbiAgICAgICAgLm1hcCgoa2V5KSA9PiBrZXkgKyAnPScgKyBKU09OLnN0cmluZ2lmeShjb250ZXh0W2tleV0pKVxuICAgICAgICAuam9pbignJicpXG4gICAgICBjb25zdCBrZXkgPVxuICAgICAgICBtb2R1bGVPcklkICsgJy4nICsgZXZlbnQgKyAoaGFzQ29udGV4dCA/IGAuJHtjb250ZXh0S2V5fWAgOiAnJylcblxuICAgICAgbGlzdGVuZXJzLnJlbW92ZUtleShrZXkpXG4gICAgICB1bnN1YnNjcmliZShrZXksIGNvbnRleHQpXG4gICAgfVxuICB9XG59XG5cbmNvbnN0IGluaXQgPSAoKSA9PiB7XG4gIGlmICghdHJhbnNwb3J0SW5pdGlhbGl6ZWQpIHtcbiAgICBUcmFuc3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VyQ2FsbEFyZ3MucHVzaChudWxsKVxuICAgICAgICB9XG5cbiAgICAgICAgY29uc3Qgc2Vzc2lvbiA9IHtcbiAgICAgICAgICBjb3JyZWxhdGlvbklkOiAoKSA9PiB7XG4gICAgICAgICAgICByZXR1cm4gcmVxdWVzdC5jb3JyZWxhdGlvbklkXG4gICAgICAgICAgfSxcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIG9ubHkgcGFzcyBpbiB0aGUgZm9jdXMgaGFuZHNoYWtlIGlmIG5lZWRlZFxuICAgICAgICBpZiAoaW1ldGhvZC5mb2N1cykge1xuICAgICAgICAgIHNlc3Npb24uZm9jdXMgPSAoKSA9PiB7XG4gICAgICAgICAgICBUcmFuc3BvcnQuc2VuZChtb2R1bGUsIGAke21ldGhvZH1Gb2N1c2AsIHtcbiAgICAgICAgICAgICAgY29ycmVsYXRpb25JZDogcmVxdWVzdC5jb3JyZWxhdGlvbklkLFxuICAgICAgICAgICAgfSlcbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBwcm92aWRlckNhbGxBcmdzLnB1c2goc2Vzc2lvbilcblxuICAgICAgICBjb25zdCByZXNwb25zZSA9IHtcbiAgICAgICAgICBjb3JyZWxhdGlvbklkOiByZXF1ZXN0LmNvcnJlbGF0aW9uSWQsXG4gICAgICAgIH1cbiAgICAgICAgbGV0IGhhbmRsZUVycm9yID0gKGVycm9yKSA9PiB7XG4gICAgICAgICAgcmVzcG9uc2UuZXJyb3IgPSB7XG4gICAgICAgICAgICBjb2RlOiBlcnJvci5jb2RlIHx8IDEwMDAsIC8vIHRvZG86IHNob3VsZCBiZSBzb21lIHJlc2VydmVkIGNvZGUgZm9yIFwiVW5rbm93blwiXG4gICAgICAgICAgICBtZXNzYWdlOlxuICAgICAgICAgICAgICBlcnJvci5tZXNzYWdlIHx8XG4gICAgICAgICAgICAgIGBBbiBlcnJvciBvY2N1cmVkIHdoaWxlIGNhbGxpbmcgcHJvdmlkZWQgJHttZXRob2R9IG1ldGhvZC5gLFxuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChlcnJvci5kYXRhKSB7XG4gICAgICAgICAgICByZXNwb25zZS5lcnJvci5kYXRhID0gSlNPTi5wYXJzZShKU09OLnN0cmluZ2lmeShlcnJvci5kYXRhKSlcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBUcmFuc3BvcnQuc2VuZChtb2R1bGUsIGAke21ldGhvZH1FcnJvcmAsIHJlc3BvbnNlKVxuICAgICAgICB9XG5cbiAgICAgICAgdHJ5IHtcbiAgICAgICAgICBjb25zdCByZXN1bHQgPSBwcm92aWRlclttZXRob2RdLmFwcGx5KHByb3ZpZGVyLCBwcm92aWRlckNhbGxBcmdzKVxuXG4gICAgICAgICAgaWYgKCEocmVzdWx0IGluc3RhbmNlb2YgUHJvbWlzZSkpIHtcbiAgICAgICAgICAgIHRocm93IGBQcm92aWRlciBtZXRob2QgJHttZXRob2R9IGRpZCBub3QgcmV0dXJuIGEgUHJvbWlzZS5gXG4gICAgICAgICAgfVxuXG4gICAgICAgICAgcmVzdWx0XG4gICAgICAgICAgICAudGhlbigocmVzdWx0KSA9PiB7XG4gICAgICAgICAgICAgIGlmIChpbWV0aG9kLnJlc3BvbnNlKSB7XG4gICAgICAgICAgICAgICAgLy8gdm9pZCByZXN1bHRzIHNob3VsZCBiZSBudWxsIGluIHRoZSBKU09OUlBDIG1lc3NhZ2VcbiAgICAgICAgICAgICAgICByZXNwb25zZS5yZXN1bHQgPSByZXN1bHQgPT0gbnVsbCA/IG51bGwgOiByZXN1bHRcbiAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgIFRyYW5zcG9ydC5zZW5kKG1vZHVsZSwgYCR7bWV0aG9kfVJlc3BvbnNlYCwgcmVzcG9uc2UpXG4gICAgICAgICAgICB9KVxuICAgICAgICAgICAgLmNhdGNoKChlcnIpID0+IGhhbmRsZUVycm9yKGVycikpXG4gICAgICAgIH0gY2F0Y2ggKGVycm9yKSB7XG4gICAgICAgICAg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PT4ge1xuICAgICAgICAgICAgICBjb25zdCBtc2cgPVxuICAgICAgICAgICAgICAgIHR5cGVvZiBlcnJvciA9PT0gJ3N0cmluZydcbiAgICAgICAgICAgICAgICAgID8gZXJyb3JcbiAgICAgICAgICAgICAgICAgIDogZXJyb3IubWVzc2FnZSB8fCAnVW5rbm93biBFcnJvcidcbiAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihcbiAgICAgICAgICAgICAgICBgRmFpbGVkIHRvIHNlbmQgZW50aXR5SW5mbyBwdWxsIHJlc3BvbnNlIHRocm91Z2ggVHJhbnNwb3J0IExheWVyOiAke21zZ31gLFxuICAgICAgICAgICAgICApXG4gICAgICAgICAgICB9KVxuICAgICAgICAgIH0pXG4gICAgICAgICAgLmNhdGNoKChlcnJvcikgPT4ge1xuICAgICAgICAgICAgY29uc3QgbXNnID1cbiAgICAgICAgICAgICAgdHlwZW9mIGVycm9yID09PSAnc3RyaW5nJ1xuICAgICAgICAgICAgICAgID8gZXJyb3JcbiAgICAgICAgICAgICAgICA6IGVycm9yLm1lc3NhZ2UgfHwgJ1Vua25vd24gRXJyb3InXG4gICAgICAgICAgICBjb25zb2xlLmVycm9yKGBBcHAgJ2VudGl0eUluZm8nIGNhbGxiYWNrIGZhaWxlZDogJHttc2d9YClcbiAgICAgICAgICB9KVxuICAgICAgfSBjYXRjaCAoZXJyb3IpIHtcbiAgICAgICAgY29uc3QgbXNnID1cbiAgICAgICAgICB0eXBlb2YgZXJyb3IgPT09ICdzdHJpbmcnID8gZXJyb3IgOiBlcnJvci5tZXNzYWdlIHx8ICdVbmtub3duIEVycm9yJ1xuICAgICAgICBjb25zb2xlLmVycm9yKGBBcHAgJ2VudGl0eUluZm8nIGNhbGxiYWNrIGZhaWxlZDogJHttc2d9YClcbiAgICAgIH1cbiAgICB9KVxuICB9IGVsc2Uge1xuICAgIHJldHVybiBUcmFuc3BvcnQuc2VuZCgnRGlzY292ZXJ5JywgJ2VudGl0eUluZm8nLCB7XG4gICAgICBj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S5jYXRjaChcbiAgICAgICAgICAgICAgKGVycm9yKSA9PiB7XG4gICAgICAgICAgICAgICAgY29uc3QgbXNnID1cbiAgICAgICAgICAgICAgICAgIHR5cGVvZiBlcnJvciA9PT0gJ3N0cmluZydcbiAgICAgICAgICAgICAgICAgICAgPyBlcnJvclxuICAgICAgICAgICAgICAgICAgICA6IGVycm9yLm1lc3NhZ2UgfHwgJ1Vua25vd24gRXJyb3InXG4gICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihcbiAgICAgICAgICAgICAgICAgIGBGYWlsZWQgdG8gc2VuZCBwdXJjaGFzZWRDb250ZW50IHB1bGwgcmVzcG9uc2UgdGhyb3VnaCBUcmFuc3BvcnQgTGF5ZXI6ICR7bXNnfWAsXG4gICAgICAgICAgICAgICAgKVxuICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgKVxuICAgICAgICAgIH0pXG4gICAgICAgICAgLmNhdGNoKChlcnJvcikgPT4ge1xuICAgICAgICAgICAgY29uc3QgbXNnID1cbiAgICAgICAgICAgICAgdHlwZW9mIGVycm9yID09PSAnc3RyaW5nJ1xuICAgICAgICAgICAgICAgID8gZXJyb3JcbiAgICAgICAgICAgICAgICA6IGVycm9yLm1lc3NhZ2UgfHwgJ1Vua25vd24gRXJyb3InXG4gICAgICAgICAgICBjb25zb2xlLmVycm9yKGBBcHAgJ3B1cmNoYXNlZENvbnRlbnQnIGNhbGxiYWNrIGZhaWxlZDogJHttc2d9YClcbiAgICAgICAgICB9KVxuICAgICAgfSBjYXRjaCAoZXJyb3IpIHtcbiAgICAgICAgY29uc3QgbXNnID1cbiAgICAgICAgICB0eXBlb2YgZXJyb3IgPT09ICdzdHJpbmcnID8gZXJyb3IgOiBlcnJvci5tZXNzYWdlIHx8ICdVbmtub3duIEVycm9yJ1xuICAgICAgICBjb25zb2xlLmVycm9yKGBBcHAgJ3B1cmNoYXNlZENvbnRlbnQnIGNhbGxiYWNrIGZhaWxlZDogJHttc2d9YClcbiAgICAgIH1cb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0KGtleSkpLmxlbmd0aCA9PT0gMCkge1xuICAgICAgICBjb25zdCBhcmdzID0gT2JqZWN0LmFzc2lnbih7IGxpc3RlbjogdHJ1ZSB9LCBjb250ZXh0KVxuICAgICAgICBjb25zdCB7IGlkLCBwcm9taXNlIH0gPSBUcmFuc3BvcnQubGlzdGVuKFxuICAgICAgICAgIG1vZHVsZSxcbiAgICAgICAgICAnb24nICsgZXZlbnRbMF0udG9VcHBlckNhc2UoKSArIGV2ZW50LnN1YnN0cmluZygxKSxcbiAgICAgICAgICBhcmdzLFxuICAgICAgICApXG4gICAgICAgIGtleXNbaWRdID0ga2V5XG4gICAgICAgIHByb21pc2VzLnB1c2gocHJvbWlzZSlcbiAgICAgIH1cblxuICAgICAgY29uc3Qgc2V0dGVyID0gaW50ZXJuYWwgPyBsaXN0ZW5lcnMuc2V0SW50ZXJuYWwgOiBsaXN0ZW5lcnMuc2V0XG5cbiAgICAgIGlmICh3aWxkY2FyZCkge1xuICAgICAgICBzZXR0ZXIoa2V5LCAnJyArIGxpc3RlbmVySWQsICh2YWx1ZSkgPT4gY2FsbGJhY2soZXZlbnQsIHZhbHVlKSlcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHNldHRlcihrZXksICcnICsgbGlzdGVuZXJJZCwgY2FsbGJhY2spXG4gICAgICB9XG4gICAgfSlcblxuICAgIGxldCByZXNvbHZlLCByZWplY3RcbiAgICBsZXQgcCA9IG5ldyBQcm9taXNlKChyZXMsIHJlaikgPT4ge1xuICAgICAgcmVzb2x2ZSA9IHJlc1xuICAgICAgcmVqZWN0ID0gcmVqXG4gICAgfSlcblxuICAgIGlmIChwcm9taXNlcy5sZW5ndGgpIHtcbiAgICAgIFByb21pc2UuYWxsKHByb21pc2VzKVxuICAgICAgICAudGhlbigocmVzcG9uc2VzKSA9PiB7XG4gICAgICAgICAgcmVzb2x2ZShsaXN0ZW5lcklkKVxuICAgICAgICB9KVxuICAgICAgICAuY2F0Y2goKGVycm9yKSA9PiB7XG4g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iAgICAgICAgdW5zdWJzY3JpYmUoa2V5KVxuICAgICAgfVxuICAgICAgcmV0dXJuIHRydWVcbiAgICB9XG4gICAgcmV0dXJuIGZhbHNlXG4gIH0gZWxzZSB7XG4gICAgaWYgKCFtb2R1bGVPcklkICYmICFldmVudCkge1xuICAgICAgbGlzdGVuZXJzLmtleXMoKS5mb3JFYWNoKChrZXkpID0+IHtcbiAgICAgICAgbGlzdGVuZXJzLnJlbW92ZUtleShrZXkpXG4gICAgICAgIHVuc3Vic2NyaWJlKGtleSlcbiAgICAgIH0pXG4gICAgfSBlbHNlIGlmICghZXZlbnQpIHtcbiAgICAgIGxpc3RlbmVycy5rZXlzKCkuZm9yRWFjaCgoa2V5KSA9PiB7XG4gICAgICAgIGlmIChrZXkuaW5kZXhPZihtb2R1bGVPcklkLnRvTG93ZXJDYXNlKCkpID09PSAwKSB7XG4gICAgICAgICAgbGlzdGVuZXJzLnJlbW92ZUtleShrZXkpXG4gICAgICAgICAgdW5zdWJzY3JpYmUoa2V5KVxuICAgICAgICB9XG4gICAgICB9KVxuICAgIH0gZWxzZSB7XG4gICAgICBjb25zdCBoYXNDb250ZXh0ID0gT2JqZWN0LnZhbHVlcyhjb250ZXh0KS5sZW5ndGggPiAwXG4gICAgICBjb25zdCBjb250ZXh0S2V5ID0gT2JqZWN0LmtleXMoY29udGV4dClcbiAgICAgICAgLnNvcnQoKVxuICAgICAgICAubWFwKChrZXkpID0+IGtleSArICc9JyArIEpTT04uc3RyaW5naWZ5KGNvbnRleHRba2V5XSkpXG4gICAgICAgIC5qb2luKCcmJylcbiAgICAgIGNvbnN0IGtleSA9XG4gICAgICAgIG1vZHVsZU9ySWQgKyAnLicgKyBldmVudCArIChoYXNDb250ZXh0ID8gYC4ke2NvbnRleHRLZXl9YCA6ICcnKVxuXG4gICAgICBsaXN0ZW5lcnMucmVtb3ZlS2V5KGtleSlcbiAgICAgIHVuc3Vic2NyaWJlKGtleSwgY29udGV4dClcbiAgICB9XG4gIH1cbn1c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CJcbiAgICAgICAgICAgIG1lc3NhZ2U6XG4gICAgICAgICAgICAgIGVycm9yLm1lc3NhZ2UgfHxcbiAgICAgICAgICAgICAgYEFuIGVycm9yIG9jY3VyZWQgd2hpbGUgY2FsbGluZyBwcm92aWRlZCAke21ldGhvZH0gbWV0aG9kLmAsXG4gICAgICAgICAgfVxuXG4gICAgICAgICAgaWYgKGVycm9yLmRhdGEpIHtcbiAgICAgICAgICAgIHJlc3BvbnNlLmVycm9yLmRhdGEgPSBKU09OLnBhcnNlKEpTT04uc3RyaW5naWZ5KGVycm9yLmRhdGEpKVxuICAgICAgICAgIH1cblxuICAgICAgICAgIFRyYW5zcG9ydC5zZW5kKG1vZHVsZSwgYCR7bWV0aG9kfUVycm9yYCwgcmVzcG9uc2UpXG4gICAgICAgIH1cblxuICAgICAgICB0cnkge1xuICAgICAgICAgIGNvbnN0IHJlc3VsdCA9IHByb3ZpZGVyW21ldGhvZF0uYXBwbHkocHJvdmlkZXIsIHByb3ZpZGVyQ2FsbEFyZ3MpXG5cbiAgICAgICAgICBpZiAoIShyZXN1bHQgaW5zdGFuY2VvZiBQcm9taXNlKSkge1xuICAgICAgICAgICAgdGhyb3cgYFByb3ZpZGVyIG1ldGhvZCAke21ldGhvZH0gZGlkIG5vdCByZXR1cm4gYSBQcm9taXNlLmBcbiAgICAgICAgICB9XG5cbiAgICAgICAgICByZXN1bHRcbiAgICAgICAgICAgIC50aGVuKChyZXN1bHQpID0+IHtcbiAgICAgICAgICAgICAgaWYgKGltZXRob2QucmVzcG9uc2UpIHtcbiAgICAgICAgICAgICAgICAvLyB2b2lkIHJlc3VsdHMgc2hvdWxkIGJlIG51bGwgaW4gdGhlIEpTT05SUEMgbWVzc2FnZVxuICAgICAgICAgICAgICAgIHJlc3BvbnNlLnJlc3VsdCA9IHJlc3VsdCA9PSBudWxsID8gbnVsbCA6IHJlc3VsdFxuICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgVHJhbnNwb3J0LnNlbmQobW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gICAgIH1cbiAgICAgIH0pXG4gICAgfVxuICB9XG5cbiAgaWYgKG1vY2spIGhhbmRsZShqc29uKVxuICBlbHNlIHBlbmRpbmcucHVzaChqc29uKVxufVxuXG5mdW5jdGlvbiBoYW5kbGUoanNvbikge1xuICBsZXQgcmVzdWx0XG4gIHRyeSB7XG4gICAgcmVzdWx0ID0gZ2V0UmVzdWx0KGpzb24ubWV0aG9kLCBqc29uLnBhcmFtcylcbiAgfSBjYXRjaCAoZXJyb3IpIHtcbiAgICBzZXRUaW1lb3V0KCgpID0+XG4gICAgICBjYWxsYmFjayhcbiAgICAgICAgSlNPTi5zdHJpbmdpZnkoe1xuICAgICAgICAgIGpzb25ycGM6ICcyLjAnLFxuICAgICAgICAgIGVycm9yOiB7XG4gICAgICAgICAgICBjb2RlOiAtMzI2MDIsXG4gICAgICAgICAgICBtZXNzYWdlOlxuICAgICAgICAgICAgICAnSW52YWxpZCBwYXJhbXMgKHRoaXMgaXMgYSBtb2NrIGVycm9yIGZyb20gdGhlIG1vY2sgdHJhbnNwb3J0IGxheWVyKScsXG4gICAgICAgICAgfSxcbiAgICAgICAgICBpZDoganNvbi5pZCxcbiAgICAgICAgfSksXG4gICAgICApLFxuICAgIClcbiAgfVxuXG4gIHNldFRpbWVvdXQoKCkgPT5cbiAgICBjYWxsYmFjayhcbiAgICAgIEpTT04uc3RyaW5naWZ5KHtcbiAgICAgICAganNvbnJwYzogJzIuMCcsXG4gICAgICAgIHJlc3VsdDogcmVzdWx0LFxuICAgICAgICBpZDoganNvbi5pZCxcbiAgICAgIH0pLFxuICAgICksXG4gIClcbn1cblxuZnVuY3Rpb24gcmVjZWl2ZShfY2FsbGJhY2spIHtcbiAgY2FsbGJhY2sgPSBfY2FsbGJhY2tcblxuICBpZiAodGVzdEhhcm5lc3MgJiYgdHlwZW9mIHRlc3RIYXJuZXNzLmluaXRpYWxpemUgPT09ICdmdW5jdGlvbicpIHtcbiAgICB0ZXN0SGFybmVzcy5pbml0aWFsaXplKH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DYWxsLnRlc3QobGluZSkpIHtcbiAgICAgICAgICAgICAgICBpZiAob25vU3RhcnQgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgICAgICAvLyBXZSBmb3VuZCB0aGUgZmlyc3QgT25vIGNhbGwgaW4gdGhlIHN0YWNrIHRyYWNlLlxuICAgICAgICAgICAgICAgICAgICAvLyBUaGVyZSBtYXkgYmUgb3RoZXIgc3Vic2VxdWVudCBPbm8gY2FsbHMgYXMgd2VsbC5cbiAgICAgICAgICAgICAgICAgICAgb25vU3RhcnQgPSBpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2UgaWYgKG9ub1N0YXJ0ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAvLyBXZSBmb3VuZCB0aGUgZmlyc3Qgbm9uLU9ubyBjYWxsIGFmdGVyIG9uZSBvciBtb3JlIE9ubyBjYWxscy5cbiAgICAgICAgICAgICAgICAvLyBTbyByZW1vdmUgdGhlIE9ubyBjYWxsIGxpbmVzIGZyb20gdGhlIHN0YWNrIHRyYWNlXG4gICAgICAgICAgICAgICAgbGluZXMuc3BsaWNlKG9ub1N0YXJ0LCBpIC0gb25vU3RhcnQpO1xuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmIChsaW5lcy5sZW5ndGggPiAwKSB7XG4gICAgICAgICAgICByZXR1cm4gbGluZXMuam9pbihcIlxcblwiKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICAvLyBJZiB3ZSBnZXQgaGVyZSwgdGhlbiB0aGUgc3RhY2sgZG9lc24ndCBjb250YWluIGEgY2FsbCB0byBgb25vYC5cbiAgICAvLyBUaGlzIG1heSBiZSBkdWUgdG8gbWluaWZpY2F0aW9uIG9yIHNvbWUgb3B0aW1pemF0aW9uIG9mIHRoZSBKUyBlbmdpbmUuXG4gICAgLy8gU28ganVzdCByZXR1c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NieDtcbiAgICAgICAgaWYgKGR4ID4gLTFlLTggJiYgZHggPCAxZS04KSB7XG4gICAgICAgICAgcmV0dXJuIHQgKiAodCAqICh0ICogeWEgKyB5YikgKyB5Yyk7XG4gICAgICAgIH1cbiAgICAgICAgY2J4ZCA9IHQgKiAodCAqICgzICogeGEpICsgMiAqIHhiKSArIHhjO1xuICAgICAgICBpZiAoY2J4ZCA+IDFlLTEwICYmIGNieGQgPCAxZS0xMCkge1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIHQgKz0gZHggLyBjYnhkO1xuICAgICAgfVxuICAgICAgbGV0IG1pblQgPSAwO1xuICAgICAgbGV0IG1heFQgPSAxO1xuICAgICAgZm9yIChsZXQgaXQgPSAwOyBpdCA8IDIwOyBpdCsrKSB7XG4gICAgICAgIHQgPSAwLjUgKiAobWluVCArIG1heFQpO1xuICAgICAgICBjYnggPSB0ICogKHQgKiAodCAqIHhhICsgeGIpICsgeGMpO1xuICAgICAgICBkeCA9IHRpbWUgLSBjYng7XG4gICAgICAgIGlmIChkeCA+IC0xZS04ICYmIGR4IDwgMWUtOCkge1xuICAgICAgICAgIHJldHVybiB0ICogKHQgKiAodCAqIHlhICsgeWIpICsgeWMpO1xuICAgICAgICB9XG4gICAgICAgIGlmIChkeCA8IDApIHtcbiAgICAgICAgICBtYXhUID0gdDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBtaW5UID0gdDtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH07XG4gIH1cbiAgc3RhdGljIGdldFRpbWluZ0Z1bmN0aW9uKHN0cikge1xuICAgIHN3aXRjaCAoc3RyKSB7XG4gICAgICBjYXNlIFwibGluZWFyXCI6XG4gICAgICAgIHJldHVybiBmdW5jdGlvbih0aW1lKSB7XG4gICAgICAgICAgcmV0dXJuIHRpbWU7XG4gICAgICAgIH07XG4gICAgICBjYXNlIFwiZWFzZVwiOlxuICAgICAgICByZXR1cm4gU3RhZ2VVdGlscy5n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gIHJldHVybiB0aW1lO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgICB9XG4gICAgICAgICAgbGV0IGEgPSBwYXJzZUZsb2F0KHBhcnRzWzBdKTtcbiAgICAgICAgICBsZXQgYiA9IHBhcnNlRmxvYXQocGFydHNbMV0pO1xuICAgICAgICAgIGxldCBjID0gcGFyc2VGbG9hdChwYXJ0c1syXSk7XG4gICAgICAgICAgbGV0IGQgPSBwYXJzZUZsb2F0KHBhcnRzWzNdKTtcbiAgICAgICAgICBpZiAoaXNOYU4oYSkgfHwgaXNOYU4oYikgfHwgaXNOYU4oYykgfHwgaXNOYU4oZCkpIHtcbiAgICAgICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIFVua25vd24gdGltaW5nIGZ1bmN0aW9uOiBcIiArIHN0cik7XG4gICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24odGltZSkge1xuICAgICAgICAgICAgICByZXR1cm4gdGltZTtcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybiBTdGFnZVV0aWxzLmdldFRpbWluZ0JlemllcihhLCBiLCBjLCBkKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBjb25zb2xlLndhcm4oXCJbTGlnaHRuaW5nXSBVbmtub3duIHRpbWluZyBmdW5jdGlvbjogXCIgKyBzdHIpO1xuICAgICAgICAgIHJldHVybiBmdW5jdGlvbih0aW1lKSB7XG4gICAgICAgICAgICByZXR1cm4gdGltZTtcbiAgICAgICAgICB9O1xuICAgICAgICB9XG4gICAgfVxuICB9XG59XG5sZXQgVXRpbHMkMSA9IGNsYXNzIFV0aWxzIHtcbiAgc3RhdGljIGlzRnVuY3Rpb24odmFsdWUpIHtcbiAgICByZXR1cm4gdHlwZW9mIHZhbHVlID09PSBcImZ1bmN0aW9uXCI7XG4gIH1cbiAgc3RhdGljIGlzTnVtYmVyKHZhbHVlKSB7XG4gICAgcmV0dXJuIHR5cGVvZiB2YWx1ZSA9PT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tBbW91bnQgPSB0aGlzLl9nZXRUb3RhbFNocmlua0Ftb3VudCgpO1xuICAgIGlmICh0b3RhbFNocmlua0Ftb3VudCkge1xuICAgICAgY29uc3QgaXRlbXMgPSB0aGlzLl9saW5lLml0ZW1zO1xuICAgICAgZG8ge1xuICAgICAgICBsZXQgYW1vdW50UGVyU2hyaW5rID0gdGhpcy5fYW1vdW50UmVtYWluaW5nIC8gdG90YWxTaHJpbmtBbW91bnQ7XG4gICAgICAgIGZvciAobGV0IGkgPSB0aGlzLl9saW5lLnN0YXJ0SW5kZXg7IGkgPD0gdGhpcy5fbGluZS5lbmRJbmRleDsgaSsrKSB7XG4gICAgICAgICAgY29uc3QgaXRlbSA9IGl0ZW1zW2ldO1xuICAgICAgICAgIGNvbnN0IGZsZXhJdGVtID0gaXRlbS5mbGV4SXRlbTtcbiAgICAgICAgICBjb25zdCBzaHJpbmtBbW91bnQgPSBmbGV4SXRlbS5zaHJpbms7XG4gICAgICAgICAgY29uc3QgaXNTaHJpbmthYmxlSXRlbSA9IHNocmlua0Ftb3VudCA+IDA7XG4gICAgICAgICAgaWYgKGlzU2hyaW5rYWJsZUl0ZW0pIHtcbiAgICAgICAgICAgIGxldCBzaHJpbmsgPSBzaHJpbmtBbW91bnQgKiBhbW91bnRQZXJTaHJpbms7XG4gICAgICAgICAgICBjb25zdCBtaW5TaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTWluU2l6ZSgpO1xuICAgICAgICAgICAgY29uc3Qgc2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc0xheW91dFNpemUoKTtcbiAgICAgICAgICAgIGlmIChzaXplID4gbWluU2l6ZSkge1xuICAgICAgICAgICAgICBjb25zdCBtYXhTaHJpbmsgPSBzaXplIC0gbWluU2l6ZTtcbiAgICAgICAgICAgICAgY29uc3QgaXNGdWxseVNocnVuayA9IHNocmluayA+PSBtYXhTaHJpbms7XG4gICAgICAgICAgICAgIGlmIChpc0Z1bGx5U2hydW5rKSB7XG4gICAgICAgICAgICAgICAgc2hyaW5rID0gbWF4U2hyaW5rO1xuICAgICAgICAgICAgICAgIHRvdGFsU2hyaW5rQW1vdW50IC09IHNocmlua0Ftb3VudDtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBjb25zdCBmaW5hbFNpemUgPSBzaXplIC0gc2hyaW5rO1xuICAgICAgICAgICAgICBmbGV4SXRlbS5fcmVzaXplTWFpbkF4aXMoZmluYWxTaXplKTtcbiAgICAgICAgICAgICAgdGhpcy5fc2hydW5rU2l6ZSArPSBzaHJpbms7XG4gICAgICAgICAgICAgIHRoaXMuX2Ftb3VudFJlbWFpbmluZyAtPSBzaHJpbms7XG4gICAgICAgICAgICAgIGlmIChNYXRoLmFicyh0aGlzLl9hbW91bnRSZW1haW5pbmcpIDwgMWUtNSkge1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSB3aGlsZSAodG90YWxTaHJpbmtBbW91bnQgJiYgTWF0aC5hYnModGhpcy5fYW1vdW50UmVtYWluaW5nKSA+IDFlLTUpO1xuICAgIH1cbiAgfVxuICBfZ2V0VG90YWxTaHJpbmtBbW91bnQoKSB7XG4gICAgbGV0IHRvdGFsID0gMDtcbiAgICBjb25zdCBpdGVtcyA9IHRoaXMuX2xpbmUuaXRlbXM7XG4gICAgZm9yIChsZXQgaSA9IHRoaXMuX2xpbmUuc3RhcnRJbmRleDsgaSA8PSB0aGlzLl9saW5lLmVuZEluZGV4OyBpKyspIHtcbiAgICAgIGNvbnN0IGl0ZW0gPSBpdGVtc1tpXTtcbiAgICAgIGNvbnN0IGZsZXhJdGVtID0gaXRlbS5mbGV4SXRlbTtcbiAgICAgIGlmIChmbGV4SXRlbS5zaHJpbmspIHtcbiAgICAgICAgY29uc3QgbWluU2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc01pblNpemUoKTtcbiAgICAgIC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Lmdyb3c7XG4gICAgICAgICAgY29uc3QgaXNHcm93YWJsZUl0ZW0gPSBncm93QW1vdW50ID4gMDtcbiAgICAgICAgICBpZiAoaXNHcm93YWJsZUl0ZW0pIHtcbiAgICAgICAgICAgIGxldCBncm93ID0gZ3Jvd0Ftb3VudCAqIGFtb3VudFBlckdyb3c7XG4gICAgICAgICAgICBjb25zdCBtYXhTaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTWF4U2l6ZVNldHRpbmcoKTtcbiAgICAgICAgICAgIGNvbnN0IHNpemUgPSBmbGV4SXRlbS5fZ2V0TWFpbkF4aXNMYXlvdXRTaXplKCk7XG4gICAgICAgICAgICBpZiAobWF4U2l6ZSA+IDApIHtcbiAgICAgICAgICAgICAgaWYgKHNpemUgPj0gbWF4U2l6ZSkge1xuICAgICAgICAgICAgICAgIGdyb3cgPSAwO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGNvbnN0IG1heEdyb3cgPSBtYXhTaXplIC0gc2l6ZTtcbiAgICAgICAgICAgICAgICBjb25zdCBpc0Z1bGx5R3Jvd24gPSBncm93ID49IG1heEdyb3c7XG4gICAgICAgICAgICAgICAgaWYgKGlzRnVsbHlHcm93bikge1xuICAgICAgICAgICAgICAgICAgZ3JvdyA9IG1heEdyb3c7XG4gICAgICAgICAgICAgICAgICB0b3RhbEdyb3dBbW91bnQgLT0gZ3Jvd0Ftb3VudDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChncm93ID4gMCkge1xuICAgICAgICAgICAgICBjb25zdCBmaW5hbFNpemUgPSBzaXplICsgZ3JvdztcbiAgICAgICAgICAgICAgZmxleEl0ZW0uX3Jlc2l6ZU1haW5BeGlzKGZpbmFsU2l6ZSk7XG4gICAgICAgICAgICAgIHRoaXMuX2dyb3duU2l6ZSArPSBncm93O1xuICAgICAgICAgICAgICB0aGlzLl9hbW91bnRSZW1haW5pbmcgLT0gZ3JvdztcbiAgICAgICAgICAgICAgaWYgKE1hdGguYWJzKHRoaXMuX2Ftb3VudFJlbWFpbmluZykgPCAxZS01KSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9IHdoaWxlICh0b3RhbEdyb3dBbW91bnQgJiYgTWF0aC5hYnModGhpcy5fYW1vdW50UmVtYWluaW5nKSA+IDFlLTUpO1xuICAgIH1cbiAgfVxuICBfZ2V0VG90YWxHcm93QW1vdW50KCkge1xuICAgIGxldCB0b3RhbCA9IDA7XG4gICAgY29uc3QgaXRlbXMgPSB0aGlzLl9saW5lLml0ZW1zO1xuICAgIGZvciAobGV0IGkgPSB0aGlzLl9saW5lLnN0YXJ0SW5kZXg7IGkgPD0gdGhpcy5fbGluZS5lbmRJbmRleDsgaSsrKSB7XG4gICAgICBjb25zdCBpdGVtID0gaXRlbXNbaV07XG4gICAgICBjb25zdCBmbGV4SXRlbSA9IGl0ZW0uZmxleEl0ZW07XG4gICAgICBpZiAoZmxleEl0ZW0uZ3Jvdykge1xuICAgICAgICBjb25zdCBtYXhTaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTWF4U2l6ZVNldHRpbmcoKTtcbiAgICAgICAgY29uc3Qgc2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc0xheW91dFNpemUoKTtcbiAgICAgICAgaWYgKG1heFNpemUgPT09IDAgfHwgc2l6ZSA8IG1heFNpemUpIHtcbiAgICAgICAgICB0b3RhbCArPSBmbGV4SXRlbS5ncm93O1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIHJldHVybiB0b3RhbDtcbiAgfVxuICBnZXRHcm93blNpemUoKSB7XG4gICAgcmV0dXJuIHRoaXMuX2dyb3duU2l6ZTtcbiAgfVxufVxuY2xhc3MgSXRlbVBvc2l0aW9uZXIge1xuICBjb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fYWxpZ25JdGVtcyA9PT0gdilcbiAgICAgIHJldHVybjtcbiAgICBpZiAoRmxleENvbnRhaW5lci5BTElHTl9JVEVNUy5pbmRleE9mKHYpID09PSAtMSkge1xuICAgICAgdGhyb3cgbmV3IEVycm9yKFwiVW5rbm93biBhbGlnbkl0ZW1zLCBvcHRpb25zOiBcIiArIEZsZXhDb250YWluZXIuQUxJR05fSVRFTVMuam9pbihcIixcIikpO1xuICAgIH1cbiAgICB0aGlzLl9hbGlnbkl0ZW1zID0gdjtcbiAgICB0aGlzLl9jaGFuZ2VkQ29udGVudHMoKTtcbiAgfVxuICBnZXQgYWxpZ25Db250ZW50KCkge1xuICAgIHJldHVybiB0aGlzLl9hbGlnbkNvbnRlbnQ7XG4gIH1cbiAgc2V0IGFsaWduQ29udGVudCh2KSB7XG4gICAgaWYgKHRoaXMuX2FsaWduQ29udGVudCA9PT0gdilcbiAgICAgIHJldHVybjtcbiAgICBpZiAoRmxleENvbnRhaW5lci5BTElHTl9DT05URU5ULmluZGV4T2YodikgPT09IC0xKSB7XG4gICAgICB0aHJvdyBuZXcgRXJyb3IoXCJVbmtub3duIGFsaWduQ29udGVudCwgb3B0aW9uczogXCIgKyBGbGV4Q29udGFpbmVyLkFMSUdOX0NPTlRFTlQuam9pbihcIixcIikpO1xuICAgIH1cbiAgICB0aGlzLl9hbGlnbkNvbnRlbnQgPSB2O1xuICAgIHRoaXMuX2NoYW5nZWRDb250ZW50cygpO1xuICB9XG4gIGdldCBqdXN0aWZ5Q29udGVudCgpIHtcbiAgICByZXR1cm4gdGhpcy5fanVzdGlmeUNvbnRlbnQ7XG4gIH1cbiAgc2V0IGp1c3RpZnlDb250ZW50KHYpIHtcbiAgICBpZiAodGhpcy5fanVzdGlmeUNvbnRlbnQgPT09IHYpXG4gICAgICByZXR1cm47XG4gICAgaWYgKEZsZXhDb250YWluZXIuSlVTVElGWV9DT05URU5ULmluZGV4T2YodikgPT09IC0xKSB7XG4gICAgICB0aHJvdyBuZXcgRX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AgIGlmIChwcmV2UGFyZW50KSB7XG4gICAgICAgIHByZXZQYXJlbnQuc2V0SGFzUmVuZGVyVXBkYXRlcygzKTtcbiAgICAgIH1cbiAgICAgIHRoaXMuX3NldFJlY2FsYygxICsgMiArIDQpO1xuICAgICAgaWYgKHRoaXMuX3BhcmVudCkge1xuICAgICAgICB0aGlzLl9wYXJlbnQuX3NldEhhc1VwZGF0ZXMoKTtcbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl96SW5kZXggPT09IDApIHtcbiAgICAgICAgdGhpcy5zZXRaUGFyZW50KHBhcmVudCk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICB0aGlzLnNldFpQYXJlbnQocGFyZW50ID8gcGFyZW50LmZpbmRaQ29udGV4dCgpIDogbnVsbCk7XG4gICAgICB9XG4gICAgICBpZiAocHJldklzWkNvbnRleHQgIT09IHRoaXMuaXNaQ29udGV4dCgpKSB7XG4gICAgICAgIGlmICghdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgICB0aGlzLmRpc2FibGVaQ29udGV4dCgpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuZW5hYmxlWkNvbnRleHQocHJldlBhcmVudC5maW5kWkNvbnRleHQoKSk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHRoaXMuX3pJbmRleFJlc29ydCA9IHRydWU7XG4gICAgICBpZiAodGhpcy5felBhcmVudCkge1xuICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICB9XG4gICAgICBpZiAoIXRoaXMuX3NoYWRlcikge1xuICAgICAgICBsZXQgbmV3U2hhZGVyT3duZXIgPSBwYXJlbnQgJiYgIXBhcmVudC5fcmVuZGVyVG9UZXh0dXJlRW5hYmxlZCA/IHBhcmVudC5fc2hhZGVyT3duZXIgOiBudWxsO1xuICAgICAgICBpZiAobmV3U2hhZGVyT3duZXIgIT09IHRoaXMuX3NoYWRlck93bmVyKSB7XG4g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dGhpcy5felBhcmVudDtcbiAgICAgIGxldCBwcmV2SXNaQ29udGV4dCA9IHRoaXMuaXNaQ29udGV4dCgpO1xuICAgICAgaWYgKHpJbmRleCA9PT0gMCAmJiB0aGlzLl96SW5kZXggIT09IDApIHtcbiAgICAgICAgaWYgKHRoaXMuX3BhcmVudCA9PT0gdGhpcy5felBhcmVudCkge1xuICAgICAgICAgIGlmICh0aGlzLl96UGFyZW50KSB7XG4gICAgICAgICAgICB0aGlzLl96UGFyZW50LmRlY1pDb250ZXh0VXNhZ2UoKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgbmV3WlBhcmVudCA9IHRoaXMuX3BhcmVudDtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmICh6SW5kZXggIT09IDAgJiYgdGhpcy5fekluZGV4ID09PSAwKSB7XG4gICAgICAgIG5ld1pQYXJlbnQgPSB0aGlzLl9wYXJlbnQgPyB0aGlzLl9wYXJlbnQuZmluZFpDb250ZXh0KCkgOiBudWxsO1xuICAgICAgICBpZiAobmV3WlBhcmVudCA9PT0gdGhpcy5felBhcmVudCkge1xuICAgICAgICAgIGlmICh0aGlzLl96UGFyZW50KSB7XG4gICAgICAgICAgICB0aGlzLl96UGFyZW50LmluY1pDb250ZXh0VXNhZ2UoKTtcbiAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZW5hYmxlWlNvcnQoKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH0gZWxzZSBpZiAoekluZGV4ICE9PSB0aGlzLl96SW5kZXgpIHtcbiAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQgJiYgdGhpcy5felBhcmVudC5fekNvbnRleHRVc2FnZSkge1xuICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZW5hYmxlWlNvcnQoKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgaWYgKG5ld1pQYXJlbnQgIT09IHRoaXMuX3pQYXJlbnQpIHtcbiAgICA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pc2libGUgfHwgdy5hbHBoYSAmJiAhdmlzaWJsZSkge1xuICAgICAgbGV0IHJlY2FsYyA9IHRoaXMuX3JlY2FsYztcbiAgICAgIGlmIChyZWNhbGMgJiAxKSB7XG4gICAgICAgIGlmICghdy5hbHBoYSAmJiB2aXNpYmxlKSB7XG4gICAgICAgICAgdGhpcy5faGFzUmVuZGVyVXBkYXRlcyA9IDM7XG4gICAgICAgIH1cbiAgICAgICAgdy5hbHBoYSA9IHB3LmFscGhhICogdGhpcy5fbG9jYWxBbHBoYTtcbiAgICAgICAgaWYgKHcuYWxwaGEgPCAxZS0xNCkge1xuICAgICAgICAgIHcuYWxwaGEgPSAwO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpZiAocmVjYWxjICYgNikge1xuICAgICAgICB3LnB4ID0gcHcucHggKyB0aGlzLl9sb2NhbFB4ICogcHcudGE7XG4gICAgICAgIHcucHkgPSBwdy5weSArIHRoaXMuX2xvY2FsUHkgKiBwdy50ZDtcbiAgICAgICAgaWYgKHB3LnRiICE9PSAwKVxuICAgICAgICAgIHcucHggKz0gdGhpcy5fbG9jYWxQeSAqIHB3LnRiO1xuICAgICAgICBpZiAocHcudGMgIT09IDApXG4gICAgICAgICAgdy5weSArPSB0aGlzLl9sb2NhbFB4ICogcHcudGM7XG4gICAgICB9XG4gICAgICBpZiAocmVjYWxjICYgNCkge1xuICAgICAgICB3LnRhID0gdGhpcy5fbG9jYWxUYSAqIHB3LnRhO1xuICAgICAgICB3LnRiID0gdGhpcy5fbG9jYWxUZCAqIHB3LnRiO1xuICAgICAgICB3LnRjID0gdGhpcy5fbG9jYWxUYSAqIHB3LnRjO1xuICAgICAgICB3LnRkID0gdGhpcy5fbG9jYWxUZCAqIHB3LnRkO1xuICAgICAgICBpZiAodGhpcy5faXNDb21wbGV4KSB7XG4gICAgICAgICAgdy50YSArPSB0aGlzLl9sb2NhbFRjICogcHcudGI7XG4gICAgICAgICAgdy50YiArPSB0aGlzLl9sb2NhbFRiICogcHcudGE7XG4gICAgICAgICAgdy50YyArPSB0aGlzLl9sb2NhbFRjICogcHcudGQ7XG4gICAgICAgICAgdy50ZCArPSB0aGlzLl9sb2NhbFRiICogcHcudGM7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGNvbnN0IHByID0gdGhpcy5fcGFyZW50Ll9yZW5kZXJDb250ZXh0O1xuICAgICAgaWYgKHRoaXMuX3BhcmVudC5faGFzUmVuZGVyQ29udGV4dCgpKSB7XG4gICAgICAgIGNvbnN0IGluaXQgPSB0aGlzLl9yZW5kZXJDb250ZXh0ID09PSB0aGlzLl93b3JsZENvbnRleHQ7XG4gICAgICAgIGlmIChpbml0KSB7XG4gICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IG5ldyBFbGVtZW50Q29yZUNvbnRleHQoKTtcbiAgICAgICAgfVxuICAgICAgICBjb25zdCByMiA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgICAgIGlmIChpbml0IHx8IHJlY2FsYyAmIDEpIHtcbiAgICAgICAgICByMi5hbHBoYSA9IHByLmFscGhhICogdGhpcy5fbG9jYWxBbHBoYTtcbiAgICAgICAgICBpZiAocjIuYWxwaGEgPCAxZS0xNCkge1xuICAgICAgICAgICAgcjIuYWxwaGEgPSAwO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAoaW5pdCB8fCByZWNhbGMgJiA2KSB7XG4gICAgICAgICAgcjIucHggPSBwci5weCArIHRoaXMuX2xvY2FsUHggKiBwci50YTtcbiAgICAgICAgICByMi5weSA9IHByLnB5ICsgdGhpcy5fbG9jYWxQeSAqIHByLnRkO1xuICAgICAgICAgIGlmIChwci50YiAhPT0gMClcbiAgICAgICAgICAgIHIyLnB4ICs9IHRoaXMuX2xvY2FsUHkgKiBwci50YjtcbiAgICAgICAgICBpZiAocHIudGMgIT09IDApXG4gICAgICAgICAgICByMi5weSArPSB0aGlzLl9sb2NhbFB4ICogcHIudGM7XG4gICAgICAgIH1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4dHVyaXplci5tdXN0UmVuZGVyVG9UZXh0dXJlKCk7XG4gICAgICBpZiAodGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlICE9PSB1c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgdGhpcy5fcmVjYWxjIHw9IDIgKyA0O1xuICAgICAgICByZWNhbGMgfD0gMjtcbiAgICAgICAgaWYgKCF0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLnJlbGVhc2UoKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgdGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlID0gdXNlUmVuZGVyVG9UZXh0dXJlO1xuICAgICAgY29uc3QgciA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgICBjb25zdCBiYm94VyA9IHRoaXMuX2RpbXNVbmtub3duID8gMjA0OCA6IHRoaXMuX3c7XG4gICAgICBjb25zdCBiYm94SCA9IHRoaXMuX2RpbXNVbmtub3duID8gMjA0OCA6IHRoaXMuX2g7XG4gICAgICBsZXQgc3gsIHN5LCBleCwgZXk7XG4gICAgICBjb25zdCByQ29tcGxleCA9IHIudGIgIT09IDAgfHwgci50YyAhPT0gMCB8fCByLnRhIDwgMCB8fCByLnRkIDwgMDtcbiAgICAgIGlmIChyQ29tcGxleCkge1xuICAgICAgICBzeCA9IE1hdGgubWluKDAsIGJib3hXICogci50YSwgYmJveFcgKiByLnRhICsgYmJveEggKiByLnRiLCBiYm94SCAqIHIudGIpICsgci5weDtcbiAgICAgICAgZXggPSBNYXRoLm1heCgwLCBiYm94VyAqIHIudGEsIGJib3hXICogci50YSArIGJib3hIICogci50YiwgYmJveEggKiByLnRiKSArIHIucHg7XG4gICAgICAgIHN5ID0gTWF0aC5taW4oMCwgYmJveFcgKiByLnRjLCBiYm94VyAqIHIudGMgKyBiYm94SCAqIHIudGQsIGJib3hIICogci50ZCkgKyByLnB5O1xuICAgICAgICBleSA9IE1hdGgubWF4KDAsIGJib3hXICogci50YywgYmJveFcgKiByLnRjICsgYmJveEggKiByLnRkLCBiYm94SCAqIHIudGQpICsgci5weTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHN4ID0gci5weDtcbiAgICAgICAgZXggPSByLnB4ICsgci50YSAqIGJib3hXO1xuICAgICAgICBzeSA9IHIucHk7XG4gICAgICAgIGV5ID0gci5weSArIHIudGQgKiBiYm94SDtcbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl9kaW1zVW5rbm93biAmJiAockNvbXBsZXggfHwgdGhpcy5fbG9jYWxUYSA8IDEgfHwgdGhpcy5fbG9jYWxUYiA8IDEpKSB7XG4gICAgICAgIGNvbnN0IG54ID0gdGhpcy5feCAqIHByLnRhICsgdGhpcy5feSAqIHByLnRiICsgcHIucHg7XG4gICAgICAgIGNvbnN0IG55ID0gdGhpcy5feCAqIHByLnRjICsgdGhpcy5feSAqIHByLnRkICsgcHIucHk7XG4gICAgICAgIGlmIChueCA8IHN4KVxuICAgICAgICAgIHN4ID0gbng7XG4gICAgICAgIGlmIChueSA8IHN5KVxuICAgICAgICAgIHN5ID0gbnk7XG4gICAgICAgIGlmIChueCA+IGV4KVxuICAgICAgICAgIGV4ID0gbng7XG4gICAgICAgIGlmIChueSA+IGV5KVxuICAgICAgICAgIGV5ID0gbnk7XG4gICAgICB9XG4gICAgICBpZiAocmVjYWxjICYgNiB8fCAhdGhpcy5fc2Npc3Nvcikge1xuICAgICAgICBpZiAodGhpcy5fY2xpcHBpbmcgJiYgci5pc1NxdWFyZSgpKSB7XG4gICAgICAgICAgY29uc3QgYXJlYSA9IHRoaXMuX3BhcmVudC5fdXNlUmVuZGVyVG9UZXh0dXJlID8gdGhpcy5fcGFyZW50Ll92aWV3cG9ydCA6IHRoaXMuX3BhcmVudC5fc2Npc3NvcjtcbiAgICAgICAgICBpZiAoYXJlYSkge1xuICAgICAgICAgICAgY29uc3QgbHggPSBNYXRoLm1heChhcmVhWzBd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AqIHIudGIpICsgci5weDtcbiAgICAgICAgICAgIGV4ID0gTWF0aC5tYXgoMCwgYmJveFcgKiByLnRhLCBiYm94VyAqIHIudGEgKyBiYm94SCAqIHIudGIsIGJib3hIICogci50YikgKyByLnB4O1xuICAgICAgICAgICAgc3kgPSBNYXRoLm1pbigwLCBiYm94VyAqIHIudGMsIGJib3hXICogci50YyArIGJib3hIICogci50ZCwgYmJveEggKiByLnRkKSArIHIucHk7XG4gICAgICAgICAgICBleSA9IE1hdGgubWF4KDAsIGJib3hXICogci50YywgYmJveFcgKiByLnRjICsgYmJveEggKiByLnRkLCBiYm94SCAqIHIudGQpICsgci5weTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3ggPSByLnB4O1xuICAgICAgICAgICAgZXggPSByLnB4ICsgci50YSAqIGJib3hXO1xuICAgICAgICAgICAgc3kgPSByLnB5O1xuICAgICAgICAgICAgZXkgPSByLnB5ICsgci50ZCAqIGJib3hIO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAodGhpcy5fZGltc1Vua25vd24gJiYgKHJDb21wbGV4IHx8IHRoaXMuX2xvY2FsVGEgPCAxIHx8IHRoaXMuX2xvY2FsVGIgPCAxKSkge1xuICAgICAgICAgICAgY29uc3QgbnggPSB0aGlzLl94ICogcHIudGEgKyB0aGlzLl95ICogcHIudGIgKyBwci5weDtcbiAgICAgICAgICAgIGNvbnN0IG55ID0gdGhpcy5feCAqIHByLnRjICsgdGhpcy5feSAqIHByLnRkICsgcHIucHk7XG4gICAgICAgICAgICBpZiAobnggPCBzeClcbiAgICAgICAgICAgICAgc3ggPSBueDtcbiAgICAgICAgICAgIGlmIChueSA8IHN5KVxuICAgICAgICAgICAgICBzeSA9IG55O1xuICAgICAgICAgICAgaWYgKG54ID4gZXgpXG4gICAgICAgICAgICAgIGV4ID0gbng7XG4gICAgICAgICAgICBpZiAobnkgPiBleSlcbiAgICAgICAgICAgICAgZXkgPSBueTtcbiAgICAgICAgICB9XG4g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lzc29yWzNdICsgMTAwKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBpZiAod2l0aGluTWFyZ2luICYmIHRoaXMuX291dE9mQm91bmRzID09PSAyKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0T2ZCb3VuZHMgPSAxO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmICh0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4gIT09IHdpdGhpbk1hcmdpbikge1xuICAgICAgICAgICAgdGhpcy5fd2l0aGluQm91bmRzTWFyZ2luID0gd2l0aGluTWFyZ2luO1xuICAgICAgICAgICAgaWYgKHRoaXMuX3dpdGhpbkJvdW5kc01hcmdpbikge1xuICAgICAgICAgICAgICB0aGlzLl9oYXNVcGRhdGVzID0gdHJ1ZTtcbiAgICAgICAgICAgICAgY29uc3QgcmVjYWxjMiA9IHRoaXMuX3JlY2FsYztcbiAgICAgICAgICAgICAgdGhpcy5fcmVjYWxjID0gMDtcbiAgICAgICAgICAgICAgdGhpcy5lbGVtZW50Ll9lbmFibGVXaXRoaW5Cb3VuZHNNYXJnaW4oKTtcbiAgICAgICAgICAgICAgaWYgKHRoaXMuX3JlY2FsYykge1xuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnVwZGF0ZSgpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHRoaXMuX3JlY2FsYyA9IHJlY2FsYzI7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICB0aGlzLmVsZW1lbnQuX2Rpc2FibGVXaXRoaW5Cb3VuZHNNYXJnaW4oKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgaWYgKHRoaXMuX3ZpZXdwb3J0KSB7XG4gICAgICAgICAgdGhpcy5fdmlld3BvcnRbMl0gPSBiYm94VztcbiAgICAgICAgICB0aGlzLl92aWV3cG9ydFszXSA9IGJib3hIO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuX3ZpZXdwb3J0ID0gWzAsIDAsIGJib3hXLCBiYm94SF07XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHRoaXMuX3BSZWNhbGMgPSB0aGlzLl9yZWNhbGMgJiAxMzU7XG4gICAgICB0aGlzLl9yZWNhbGMgPSAwO1xuICAgICAgdGhpcy5faGFzVXBkYXRlcyA9IGZhbHNlO1xuICAgICAgaWYgKHRoaXMuX291dE9mQm91bmRzIDwgMikge1xuICAgICAgICBpZiAodGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlKSB7XG4gICAgICAgICAgaWYgKHRoaXMuX3dvcmxkQ29udGV4dC5pc0lkZW50aXR5KCkpIHtcbiAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSB0aGlzLl93b3JsZENvbnRleHQ7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSBFbGVtZW50Q29yZUNvbnRleHQuSURFTlRJVFk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS51cGRhdGUoKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSByO1xuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICBmb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aFRleENvb3JkcygpO1xuICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0VGV4dHVyaXplcihudWxsKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmIChyZW5kZXJUZXh0dXJlSW5mbyAmJiByZW5kZXJUZXh0dXJlSW5mby5jYWNoZSkge1xuICAgICAgICByZW5kZXJTdGF0ZS5pc0NhY2hpbmdUZXh0dXJpemVyID0gZmFsc2U7XG4gICAgICB9XG4gICAgfVxuICB9XG4gIGdldCB6U29ydCgpIHtcbiAgICByZXR1cm4gdGhpcy5felNvcnQ7XG4gIH1cbiAgc29ydFpJbmRleGVkQ2hpbGRyZW4oKSB7XG4gICAgY29uc3QgbiA9IHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4ubGVuZ3RoO1xuICAgIGxldCBwdHIgPSAwO1xuICAgIGNvbnN0IGEgPSB0aGlzLl96SW5kZXhlZENoaWxkcmVuO1xuICAgIGNvbnN0IGIgPSBbXTtcbiAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgaWYgKGFbaV0uX3pQYXJlbnQgPT09IHRoaXMpIHtcbiAgICAgICAgaWYgKGFbaV0uX3pJbmRleFJlc29ydCkge1xuICAgICAgICAgIGIucHVzaChhW2ldKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBpZiAocHRyICE9PSBpKSB7XG4gICAgICAgICAgICBhW3B0cl0gPSBhW2ldO1xuICAgICAgICAgIH1cbiAgICAgICAgICBwdHIrKztcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBjb25zdCBtID0gYi5sZW5ndGg7XG4gICAgaWYgKG0pIHtcbiAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgbTsgaisrKSB7XG4gICAgICAgIGJbal0uX3pJbmRleFJlc29ydCA9IGZhbHNlO1xuICAgICAgfVxuICAgICAgYi5zb3J0KEVsZW1lbnRDb3JlLnNvcnRaSW5kZXhlZENoaWxkcmVuKTtcbiAgICAgIGNvbnN0IG4yID0gcHRyO1xuICAgICAgaWYgKCFuMikge1xuICAgICAgICBwdHIgPSAwO1xuICAgICAgICBsZXQgaiA9IDA7XG4gICAgICAgIGRvIHtcbiAgICAgICAgICBhW3B0cisrXSA9IGJbaisrXTtcbiAgICAgICAgfSB3aGlsZSAoaiA8IG0pO1xuICAgICAgICBpZiAoYS5sZW5ndGggPiBwdHIpIHtcbiAgICAgICAgICBhLnNwbGljZShwdHIpO1xuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBwdHIgPSAwO1xuICAgICAgICBsZXQgaSA9IDA7XG4gICAgICAgIGxldCBqID0gMDtcbiAgICAgICAgY29uc3QgbWVyZ2VSZXN1bHQgPSBbXTtcbiAgICAgICAgZG8ge1xuICAgICAgICAgIGNvbnN0IHYgPSBhW2ldLl96SW5kZXggPT09IGJbal0uX3pJbmRleCA/IGFbaV0uX3VwZGF0ZVRyZWVPcmRlciAtIGJbal0uX3VwZGF0ZVRyZWVPcmRlciA6IGFbaV0uX3pJbmRleCAtIGJbal0uX3pJbmRleDtcbiAgICAgICAgICBjb25zdCBhZGQgPSB2ID4gMCA/IGJbaisrXSA6IGFbaSsrXTtcbiAgICAgICAgICBpZiAocHRyID09PSAwIHx8IG1lcmdlUmVzdWx0W3B0ciAtIDFdICE9PSBhZGQpIHtcbiAgICAgICAgICAgIG1lcmdlUmVzdWx0W3B0cisrXSA9IGFkZDtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKGkgPj0gbjIpIHtcbiAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgY29uc3QgYWRkMiA9IGJbaisrXTtcbiAgICAgICAgICAgICAgaWYgKHB0ciA9PT0gMCB8fCBtZXJnZVJlc3VsdFtwdHIgLSAxXSAhPT0gYWRkMikge1xuICAgICAgICAgICAgICAgIG1lcmdlUmVzdWx0W3B0cisrXSA9IGFkZDI7XG4gICAgICAgICAgICAgIH1cbiAgICAgIC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QgdGV4dHVyaXplcigpIHtcbiAgICBpZiAoIXRoaXMuX3RleHR1cml6ZXIpIHtcbiAgICAgIHRoaXMuX3RleHR1cml6ZXIgPSBuZXcgRWxlbWVudFRleHR1cml6ZXIodGhpcyk7XG4gICAgfVxuICAgIHJldHVybiB0aGlzLl90ZXh0dXJpemVyO1xuICB9XG4gIGdldENvcm5lclBvaW50cygpIHtcbiAgICBsZXQgdyA9IHRoaXMuX3dvcmxkQ29udGV4dDtcbiAgICByZXR1cm4gW1xuICAgICAgdy5weCxcbiAgICAgIHcucHksXG4gICAgICB3LnB4ICsgdGhpcy5fdyAqIHcudGEsXG4gICAgICB3LnB5ICsgdGhpcy5fdyAqIHcudGMsXG4gICAgICB3LnB4ICsgdGhpcy5fdyAqIHcudGEgKyB0aGlzLl9oICogdy50YixcbiAgICAgIHcucHkgKyB0aGlzLl93ICogdy50YyArIHRoaXMuX2ggKiB3LnRkLFxuICAgICAgdy5weCArIHRoaXMuX2ggKiB3LnRiLFxuICAgICAgdy5weSArIHRoaXMuX2ggKiB3LnRkXG4gICAgXTtcbiAgfVxuICBnZXRSZW5kZXJUZXh0dXJlQ29vcmRzKHJlbFgsIHJlbFkpIHtcbiAgICBsZXQgciA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgcmV0dXJuIFtcbiAgICAgIHIucHggKyByLnRhICogcmVsWCArIHIudGIgKiByZWxZLFxuICAgICAgci5weSArIHIudGMgKiByZWxYICsgci50ZCAqIHJlbFlcbiAgICBdO1xuICB9XG4gIGdldEFic29sdXRlQ29vcmRzKHJlbFgsIHJlbFkpIHtcbiAgICBsZXQgdyA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgcmV0dXJuIFtcbiAgICAgIHcucHggKyB3LnRhICogcmVsWCArIHcudGIgKiByZWxZLFxuICAgICAgdy5weSArIHcudGMgKiByZWxYICsgdy50ZCAqIHJlbFlcbiAgICBdO1xuICB9XG4gIGNvbGxlY3RBdENvb3JkKHgsIHksIG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cbiAgICB9XG4gICAgaWYgKHRoaXMuaXNVc2VkKCkpIHtcbiAgICAgIGlmIChuZXdTb3VyY2UpIHtcbiAgICAgICAgaWYgKG5ld1NvdXJjZS5pc0xvYWRlZCgpKSB7XG4gICAgICAgICAgaWYgKHRoaXMuX3Jlc2l6ZU1vZGUpIHtcbiAgICAgICAgICAgIHRoaXMuX2FwcGx5UmVzaXplTW9kZSgpO1xuICAgICAgICAgIH1cbiAgICAgICAgICB0aGlzLmVsZW1lbnRzLmZvckVhY2goKGVsZW1lbnQpID0+IHtcbiAgICAgICAgICAgIGlmIChlbGVtZW50LmFjdGl2ZSkge1xuICAgICAgICAgICAgICBlbGVtZW50Ll9zZXREaXNwbGF5ZWRUZXh0dXJlKHRoaXMpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGNvbnN0IGxvYWRFcnJvciA9IG5ld1NvdXJjZS5sb2FkRXJyb3I7XG4gICAgICAgICAgaWYgKGxvYWRFcnJvcikge1xuICAgICAgICAgICAgdGhpcy5lbGVtZW50cy5mb3JFYWNoKChlbGVtZW50KSA9PiB7XG4gICAgICAgICAgICAgIGlmIChlbGVtZW50LmFjdGl2ZSkge1xuICAgICAgICAgICAgICAgIGVsZW1lbnQub25UZXh0dXJlU291cmNlTG9hZEVycm9yKGxvYWRFcnJvcik7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgdGhpcy5lbGVtZW50cy5mb3JFYWNoKChlbGVtZW50KSA9PiB7XG4gICAgICAgICAgaWYgKGVsZW1lbnQuYWN0aXZlKSB7XG4gICAgICAgICAgICBlbGVtZW50Ll9zZXREaXNwbGF5ZWRUZXh0dXJlKG51bGwpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICB9XG4gICAgfVxuICB9XG4gIGxvYWQoKSB7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luZyhcbiAgICAgICAgdGhpcy5fc2V0dGluZ3MuZm9udEZhY2UsXG4gICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRTdHlsZSxcbiAgICAgICAgdGhpcy5fc2V0dGluZ3MuZm9udFNpemUsXG4gICAgICAgIHRoaXMuZ2V0UHJlY2lzaW9uKCksXG4gICAgICAgIHRoaXMuX3N0YWdlLmdldE9wdGlvbihcImRlZmF1bHRGb250RmFjZVwiKVxuICAgICAgKTtcbiAgICAgIHRyeSB7XG4gICAgICAgIGlmICghZG9jdW1lbnQuZm9udHMuY2hlY2soZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpKSB7XG4gICAgICAgICAgcmV0dXJuIGRvY3VtZW50LmZvbnRzLmxvYWQoZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpLmNhdGNoKChlcnIpID0+IHtcbiAgICAgICAgICAgIGNvbnNvbGUud2FybihcIkZvbnQgbG9hZCBlcnJvclwiLCBlcnIsIGZvbnRTZXR0aW5nKTtcbiAgICAgICAgICB9KS50aGVuKCgpID0+IHtcbiAgICAgICAgICAgIGlmICghZG9jdW1lbnQuZm9udHMuY2hlY2soZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpKSB7XG4gICAgICAgICAgICAgIGNvbnNvbGUud2FybihcIkZvbnQgbm90IGZvdW5kXCIsIGZvbnRTZXR0aW5nKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICBjb25zb2xlLndhcm4oXCJDYW4ndCBjaGVjayBmb250IGxvYWRpbmcgZm9yIFwiICsgZm9udFNldHRpbmcpO1xuICAgICAgfVxuICAgIH1cbiAgfVxuICBkcmF3KCkge1xuICAgIGNvbnN0IGxvYWRQcm9taXNlID0gdGhpcy5fbG9hZCgpO1xuICAgIGlmICghbG9hZFByb21pc2UpIHtcbiAgICAgIHJldHVybiBVdG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c2lzXCI6XG4gICAgICAgICAgc3VmZml4ID0gdGhpcy5fc2V0dGluZ3MubWF4TGluZXNTdWZmaXg7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgc3VmZml4ID0gdGhpcy5fc2V0dGluZ3MudGV4dE92ZXJmbG93O1xuICAgICAgfVxuICAgICAgdGV4dCA9IHRoaXMud3JhcFdvcmQodGV4dCwgd29yZFdyYXBXaWR0aCB8fCByZW5kZXJJbmZvLncsIHN1ZmZpeCk7XG4gICAgfVxuICAgIHRleHQgPSB0aGlzLnRva2VuaXplKHRleHQpO1xuICAgIHRleHQgPSB0aGlzLnBhcnNlKHRleHQpO1xuICAgIHRleHQgPSB0aGlzLm1lYXN1cmUodGV4dCwgbGV0dGVyU3BhY2luZywgcmVuZGVySW5mby5iYXNlRm9udCk7XG4gICAgaWYgKHJlbmRlckluZm8udGV4dEluZGVudCkge1xuICAgICAgdGV4dCA9IHRoaXMuaW5kZW50KHRleHQsIHJlbmRlckluZm8udGV4dEluZGVudCk7XG4gICAgfVxuICAgIGlmIChyZW5kZXJJbmZvLndvcmRCcmVhaykge1xuICAgICAgdGV4dCA9IHRleHQucmVkdWNlKChhY2MsIHQpID0+IGFjYy5jb25jYXQodGhpcy53b3JkQnJlYWsodCwgd3JhcFdpZHRoLCByZW5kZXJJbmZvLmJhc2VGb250KSksIFtdKTtcbiAgICAgIHRoaXMucmVzZXRGb250U3R5bGUoKTtcbiAgICB9XG4gICAgbGV0IHggPSBwYWRkaW5nTGVmdDtcbiAgICBsZXQgbGluZU5vID0gMDtcbiAgICBmb3IgKGNvbnN0IHQgb2YgdGV4dCkge1xuICAgICAgaWYgKHJlbmRlckluZm8ud29yZFdyYXAgJiYgeCArIHQud2lkdGggPiB3cmFwV2lkdGggfHwgdC50ZXh0ID09IFwiXFxuXCIpIHtcbiAgICAgICAgeCA9IHBhZGRpbmdMZWZ0O1xuICAgICAgICBsaW5lTm8gKz0gMTtcbiAgICAgIH1cbiAgICAgIHQubGluZU5vID0gbGluZU5vO1xuICAgICAgaWYgKHQudGV4dCA9PSBcIlxcblwiKSB7XG4gICAgICAgIGNvbnRpbnVlO1xuICAgICAgfVxuICAgICAgdC54ID0geDtcbiAgICAgIHggKz0gdC53aWR0aDtcbiAgICB9XG4gICAgcmVuZGVySW5mby5saW5lTnVtID0gbGluZU5vICsgMTtcbiAgICBpZiAodGhpcy5fc2V0dGluZ3MuaCkge1xuICAgICAgcmVuZGVySW5mby5oID0gdGhpcy5fc2V0dGluZ3MuaDtcbiAgICB9IGVsc2UgaWYgKHJlbmRlckluZm8ubWF4TGluZXMgJiYgcmVuZGVySW5mby5tYXhMaW5lcyA8IHJlbmRlckluZm8ubGluZU51bSkge1xuICAgICAgcmVuZGVySW5mby5oID0gcmVuZGVySW5mby5tYXhMaW5lcyAqIHJlbmRlckluZm8ubGluZUhlaWdodCArIGZvbnRTaXplIC8gMjtcbiAgICB9IGVsc2Uge1xuICAgICAgcmVuZGVySW5mby5oID0gcmVuZGVySW5mby5saW5lTnVtICogcmVuZGVySW5mby5saW5lSGVpZ2h0ICsgZm9udFNpemUgLyAyO1xuICAgIH1cbiAgICBjb25zdCBiYXNlbGluZU9mZnNldEluUHggPSByZW5kZXJJbmZvLmZvbnRCYXNlbGluZVJhdGlvICogcmVuZGVySW5mby5mb250U2l6ZTtcbiAgICBsZXQgdmFPZmZzZXQgPSAwO1xuICAgIGlmIChyZW5kZXJJbmZvLnZlcnRpY2FsQWxpZ24gPT0gXCJ0b3BcIiAmJiB0aGlzLl9jb250ZXh0LnRleHRCYXNlbGluZSA9PSBcImFscGhhYmV0aWNcIikge1xuICAgICAgdmFPZmZzZXQgPSAtYmFzZWxpbmVPZmZzZXRJblB4O1xuICAgIH0gZWxzZSBpZiAocmVuZGVySW5mby52ZXJ0aWNhbEFsaWduID09IFwibWlkZGxlXCIpIHtcbiAgICAgIHZhT2Zmc2V0ID0gKHJlbmRlckluZm8ubGluZUhlaWdodCAtIHJlbmRlckluZm8uZm9udFNpemUgLSBiYXNlbGluZU9mZnNldEluUHgpIC8gMjtcbiAgICB9IGVsc2UgaWYgKHRoaXMuX3NldHRpbmdzLnZlcnRpY2FsQWxpZ24gPT0gXCJib3R0b21cIikge1xuICAgICAgdmFPZmZzZXQgPSByZW5kZXJJbmZvLmxpbmVIZWlnaHQgLSByZW5kZXJJbmZvLmZvbnRTaXplO1xuICAgIH1cbiAgICByZW5kZXJJbmZvLmxpbmVzID0gW107XG4gICAgZm9yIChsZXQgaSA9IDA7IGkgPCByZW5kZXJJbmZvLmxpbmVOdW07IGkrKykge1xuICAgICAgcmVuZGVySW5mby5saW5lc1tpXSA9IHtcbiAgICAgICAgd2lkdGg6IDAsXG4gICAgICAgIHg6IDAsXG4gICAgICAgIHk6IHJlbmRlckluZm8ubGluZUhlaWdodCAqIGkgKyB2YU9mZnNldCxcbiAgICAgICAgdGV4dDogW11cbiAgICAgIH07XG4gICAgfVxuICAgIGZvciAobGV0IHQgb2YgdGV4dCkge1xuICAgICAgcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10udGV4dC5wdXNoKHQpO1xuICAgIH1cbiAgICBmb3IgKGNvbnN0IGwgb2YgcmVuZGVySW5mby5saW5lcykge1xuICAgICAgaWYgKGwudGV4dC5sZW5ndGggPT0gMCkge1xuICAgICAgICBjb250aW51ZTtcbiAgICAgIH1cbiAgICAgIGNvbnN0IGZpcnN0V29yZCA9IGwudGV4dFswXS50ZXh0O1xuICAgICAgY29uc3QgbGFzdFdvcmQgPSBsLnRleHRbbC50ZXh0Lmxlbmd0aCAtIDFdLnRleHQ7XG4gICAgICBpZiAoZmlyc3RXb3JkID09IFwiXFxuXCIpIHtcbiAgICAgICAgbC50ZXh0LnNoaWZ0KCk7XG4gICAgICB9XG4gICAgICBpZiAoaXNTcGFjZShsYXN0V29yZCkgfHwgbGFzdFdvcmQgPT0gXCJcXG5cIikge1xuICAgICAgICBsLnRleHQucG9wKCk7XG4gICAgICB9XG4gICAgfVxuICAgIGZvciAobGV0IGwgb2YgcmVuZGVySW5mby5saW5lcykge1xuICAgICAgbC53aWR0aCA9IGwudGV4dC5yZWR1Y2UoKGFjYywgdCkgPT4gYWNjICsgdC53aWR0aCwgMCk7XG4gICAgfVxuICAgIHJlbmRlckluZm8ud2lkdGggPSB0aGlzLl9zZXR0aW5ncy53ICE9IDAgPyB0aGlzLl9zZXR0aW5ncy53ICogcHJlY2lzaW9uIDogTWF0aC5tYXgoLi4ucmVuZGVySW5mby5saW5lcy5tYXAoKGwpID0+IGwud2lkdGgpKSArIHBhZGRpbmdSaWdodDtcbiAgICByZW5kZXJJbmZvLncgPSByZW5kZXJJbmZvLndpZHRoO1xuICAgIGlmIChyZW5kZXJJbmZvLm1heExpbmVzICYmIHJlbmRlckluZm8ubGluZU51bSA+IHJlbmRlckluZm8ubWF4TGluZXMgJiYgcmVuZGVySW5mby5tYXhMaW5lc1N1ZmZpeCkge1xuICAgICAgY29uc3QgaW5kZXggPSByZW5kZXJJbmZvLm1heExpbmVzIC0gMTtcbiAgICAgIGxldCBsYXN0TGluZVRleHQgPSB0ZXh0LmZpbHRlcigodCkgPT4gdC5saW5lTm8gPT0gaW5kZXgpO1xuICAgICAgbGV0IHN1ZmZpeCA9IHJlbmRlckluZm8ubWF4TGluZXNTdWZmaXg7XG4gICAgICBzdWZmaXggPSB0aGlzLnRva2VuaXplKHN1ZmZpeCk7XG4gICAgICBzdWZmaXggPSB0aGlzLnBhcnNlKHN1ZmZpeCk7XG4gICAgICBzdWZmaXggPSB0aGlzLm1lYXN1cmUoc3VmZml4LCByZW5kZXJJbmZvLmxldHRlclNwYWNpbmcsIHJlbmRlckluZm8uYmFzZUZvbnQpO1xuICAgICAgZm9yIChjb25zdCBzIG9mIHN1ZmZpeCkge1xuICAgICAgICBzLmxpbmVObyA9IGluZGV4O1xuICAgICAgICBzLnggPSAwO1xuICAgICAgICBsYXN0TGluZVRleHQucHVzaChzKTtcbiAgICAgIH1cbiAgICAgIGNvb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KiBwcmVjaXNpb247XG4gICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd09mZnNldFkgPSB0aGlzLl9zZXR0aW5ncy5zaGFkb3dPZmZzZXRZICogcHJlY2lzaW9uO1xuICAgICAgdGhpcy5fY29udGV4dC5zaGFkb3dCbHVyID0gdGhpcy5fc2V0dGluZ3Muc2hhZG93Qmx1ciAqIHByZWNpc2lvbjtcbiAgICB9XG4gICAgY29uc3QgZGVmYXVsdENvbG9yID0gU3RhZ2VVdGlscy5nZXRSZ2JhU3RyaW5nKHRoaXMuX3NldHRpbmdzLnRleHRDb2xvcik7XG4gICAgbGV0IGN1cnJlbnRDb2xvciA9IGRlZmF1bHRDb2xvcjtcbiAgICB0aGlzLl9jb250ZXh0LmZpbGxTdHlsZSA9IGRlZmF1bHRDb2xvcjtcbiAgICBmb3IgKGNvbnN0IGxpbmUgb2YgcmVuZGVySW5mby5saW5lcykge1xuICAgICAgZm9yIChjb25zdCB0IG9mIGxpbmUudGV4dCkge1xuICAgICAgICBsZXQgbHggPSAwO1xuICAgICAgICBpZiAodC50ZXh0ID09IFwiXFxuXCIpIHtcbiAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgfVxuICAgICAgICBpZiAocmVuZGVySW5mby5tYXhMaW5lcyAmJiB0LmxpbmVObyA+PSByZW5kZXJJbmZvLm1heExpbmVzKSB7XG4gICAgICAgICAgY29udGludWU7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHQuY29sb3IgIT0gY3VycmVudENvbG9yKSB7XG4gICAgICAgICAgY3VycmVudENvbG9yID0gdC5jb2xvcjtcbiAgICAgICAgICB0aGlzLl9jb250ZXh0LmZpbGxTdHlsZSA9IGN1cnJlbnRDb2xvcjtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9jb250ZXh0LmZvbnQgPSB0LmZvbnRTdHlsZTtcbiAgICAgICAgaWYgKHQubGV0dGVycykge1xuICAgICAgICAgIGZvciAobGV0IGwgb2YgdC5sZXR0ZXJzKSB7XG4gICAgICAgICAgICBjb25zdCBfeCA9IHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnggKyB0LnggKyBseDtcbiAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuZmlsbFRleHQobC50ZXh0LCBfeCwgcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10ueSArIHJlbmRlckluZm8uZm9udFNpemUpO1xuICAgICAgICAgICAgbHggKz0gbC53aWR0aDtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgY29uc3QgX3ggPSByZW5kZXJJbmZvLmxpbmVzW3QubGluZU5vXS54ICsgdC54O1xuICAgICAgICAgIHRoaXMuX2NvbnRleHQuZmlsbFRleHQodC50ZXh0LCBfeCwgcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10ueSArIHJlbmRlckluZm8uZm9udFNpemUpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIGlmIChwcmV2U2hhZG93U2V0dGluZ3MpIHtcbiAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93Q29sb3IgPSBwcmV2U2hhZG93U2V0dGluZ3NbMF07XG4gICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd09mZnNldFggPSBwcmV2U2hhZG93U2V0dGluZ3NbMV07XG4gICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd09mZnNldFkgPSBwcmV2U2hhZG93U2V0dGluZ3NbMl07XG4gICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd0JsdXIgPSBwcmV2U2hhZG93U2V0dGluZ3NbM107XG4gICAgfVxuICAgIGlmIChyZW5kZXJJbmZvLmN1dFN4IHx8IHJlbmRlckluZm8uY3V0U3kpIHtcbiAgICAgIHRoaXMuX2NvbnRleHQudHJhbnNsYXRlKHJlbmRlckluZm8uY3V0U3gsIHJlbmRlckluZm8uY3V0U3kpO1xuICAgIH1cbiAgICByZW5kZXJJbmZvLmxpbmVzID0gcmVuZGVySW5mby5saW5lcy5tYXAoKGwpID0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ICAgdCA9IFwiXCI7XG4gICAgICB9IGVsc2UgaWYgKHQgPT0gXCI8Yj5cIikge1xuICAgICAgICBib2xkICs9IDE7XG4gICAgICAgIHQgPSBcIlwiO1xuICAgICAgfSBlbHNlIGlmICh0ID09IFwiPC9iPlwiICYmIGJvbGQgPiAwKSB7XG4gICAgICAgIGJvbGQgLT0gMTtcbiAgICAgICAgdCA9IFwiXCI7XG4gICAgICB9IGVsc2UgaWYgKHQgPT0gXCI8L2NvbG9yPlwiKSB7XG4gICAgICAgIGlmIChjb2xvclN0YWNrLmxlbmd0aCA+IDEpIHtcbiAgICAgICAgICBjb2xvciAtPSAxO1xuICAgICAgICAgIGNvbG9yU3RhY2sucG9wKCk7XG4gICAgICAgIH1cbiAgICAgICAgdCA9IFwiXCI7XG4gICAgICB9IGVsc2UgaWYgKGNvbG9yUmVnZXhwLnRlc3QodCkpIHtcbiAgICAgICAgY29uc3QgbWF0Y2hlZCA9IGNvbG9yUmVnZXhwLmV4ZWModCk7XG4gICAgICAgIGNvbG9yU3RhY2sucHVzaChcbiAgICAgICAgICBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcocGFyc2VJbnQobWF0Y2hlZFsxXSkpXG4gICAgICAgICk7XG4gICAgICAgIGNvbG9yICs9IDE7XG4gICAgICAgIHQgPSBcIlwiO1xuICAgICAgfVxuICAgICAgcmV0dXJuIHtcbiAgICAgICAgdGV4dDogdCxcbiAgICAgICAgaXRhbGljLFxuICAgICAgICBib2xkLFxuICAgICAgICBjb2xvcjogY29sb3JTdGFja1tjb2xvcl1cbiAgICAgIH07XG4gICAgfSkuZmlsdGVyKChvKSA9PiBvLnRleHQgIT0gXCJcIik7XG4gIH1cbiAgYXBwbHlGb250U3R5bGUod29yZCwgYmFzZUZvbnQpIHtcbiAgICBsZXQgZm9udCA9IGJhc2VGb250O1xuICAgIGlmICh3b3JkLmJvbGQpIHtcbiAgICAgIGZvbnQgPSBcImJvbGQgXCIgKyBmb250O1xuICAgIH1cbiAgICB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IDFdLnRleHQgPSB0ZXh0LnNsaWNlKDAsIGJyZWFrSW5kZXgpO1xuICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS53aWR0aCA9IHRydW5jV29yZFdpZHRoO1xuICAgICAgICBpZiAoYnJlYWtJbmRleCA9PT0gdGV4dC5sZW5ndGgpIHtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICB0ZXh0ID0gdGV4dC5zbGljZShicmVha0luZGV4KTtcbiAgICAgIH1cbiAgICB9IGVsc2Uge1xuICAgICAgbGV0IHRvdGFsV2lkdGggPSAwO1xuICAgICAgbGV0IGxldHRlcnMgPSBbXTtcbiAgICAgIGxldCBicmVha0luZGV4ID0gMDtcbiAgICAgIGZvciAoY29uc3QgbCBvZiB3b3JkLmxldHRlcnMpIHtcbiAgICAgICAgaWYgKHRvdGFsV2lkdGggKyBsLndpZHRoID49IHdpZHRoKSB7XG4gICAgICAgICAgcGFydHMucHVzaCh7IC4uLndvcmQgfSk7XG4gICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0udGV4dCA9IHRleHQuc2xpY2UoMCwgYnJlYWtJbmRleCk7XG4gICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ud2lkdGggPSB0b3RhbFdpZHRoO1xuICAgICAgICAgIHBhcnRzW3BhcnRzLmxlbmd0aCAtIDFdLmxldHRlcnMgPSBsZXR0ZXJzO1xuICAgICAgICAgIHRleHQgPSB0ZXh0LnNsaWNlKGJyZWFrSW5kZXgpO1xuICAgICAgICAgIHRvdGFsV2lkdGggPSAwO1xuICAgICAgICAgIGxldHRlcnMgPSBbXTtcbiAgICAgICAgICBicmVha0luZGV4ID0gMDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBicmVha0luZGV4ICs9IDE7XG4gICAgICAgICAgbGV0dGVycy5wdXNoKGwpO1xuICAgICAgICAgIHRvdGFsV2lkdGggKz0gbC53aWR0aDtcbiAgICAgICAgfV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zID0gbnVsbDtcbiAgICBsZXQgbiA9IDA7XG4gICAgaWYgKHRoaXMuX190cmVlVGFncykge1xuICAgICAgaWYgKCF0aGlzLl9fdGFnUm9vdCkge1xuICAgICAgICB0YWdzID0gVXRpbHMkMS5pdGVyYXRvclRvQXJyYXkodGhpcy5fX3RyZWVUYWdzLmtleXMoKSk7XG4gICAgICAgIG4gPSB0YWdzLmxlbmd0aDtcbiAgICAgICAgaWYgKG4gPiAwKSB7XG4gICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGxldCB0YWdTZXQgPSB0aGlzLl9fdHJlZVRhZ3MuZ2V0KHRhZ3NbaV0pO1xuICAgICAgICAgICAgbGV0IHAgPSB0aGlzO1xuICAgICAgICAgICAgd2hpbGUgKHAgPSBwLl9fcGFyZW50KSB7XG4gICAgICAgICAgICAgIGxldCBwYXJlbnRUcmVlVGFncyA9IHAuX190cmVlVGFncy5nZXQodGFnc1tpXSk7XG4gICAgICAgICAgICAgIHRhZ1NldC5mb3JFYWNoKGZ1bmN0aW9uKGNvbXApIHtcbiAgICAgICAgICAgICAgICBwYXJlbnRUcmVlVGFncy5kZWxldGUoY29tcCk7XG4gICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICBpZiAocC5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgfVxuICBfc2V0VGFnc1BhcmVudCgpIHtcbiAgICBpZiAodGhpcy5fX3RhZ3MpIHtcbiAgICAgIHRoaXMuX190YWdzLmZvckVhY2goKHRhZykgPT4ge1xuICAgICAgICBsZXQgcCA9IHRoaXM7XG4gICAgICAgIHdoaWxlIChwID0gcC5fX3BhcmVudCkge1xuICAgICAgICAgIGlmICghcC5fX3RyZWVUYWdzKSB7XG4gICAgICAgICAgICBwLl9fdHJlZVRhZ3MgPSAvKiBAX19QVVJFX18gKi8gbmV3IE1hcCgpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBsZXQgcyA9IHAuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgICAgICBpZiAoIXMpIHtcbiAgICAgICAgICAgIHMgPSAvKiBAX19QVVJFX18gKi8gbmV3IFNldCgpO1xuICAgICAgICAgICAgcC5fX3RyZWVUYWdzLnNldCh0YWcsIHMpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBzLmFkZCh0aGlzKTtcbiAgICAgICAgICBpZiAocC5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSk7XG4gICAgfVxuICAgIGlmICh0aGlzLl9fdHJlZVRhZ3MgJiYgdGhpcy5fX3RyZWVUYWdzLnNpemUpIHtcbiAgICAgIGlmICghdGhpcy5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgdGhpcy5fX3RyZWVUYWdzLmZvckVhY2goKHRhZ1NldCwgdGFnKSA9PiB7XG4gICAgICAgICAgbGV0IHAgPSB0aGlzO1xuICAgICAgICAgIHdoaWxlICghcC5fX3RhZ1Jvb3QgJiYgKHAgPSBwLl9fcGFyZW50KSkge1xuICAgICAgICAgICAgaWYgKHAuX190YWdSb290KVxuICAgICAgICAgICAgICA7XG4gICAgICAgICAgICBpZiAoIXAuX190cmVlVGFncykge1xuICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3MgPSAvKiBAX19QVVJFX18gKi8gbmV3IE1hcCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgbGV0IHMgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICBpZiAoIXMpIHtcbiAgICAgICAgICAgICAgcyA9IC8qIEBfX1BVUkVfXyAqLyBuZXcgU2V0KCk7XG4gICAgICAgICAgICAgIHAuX190cmVlVGFncy5zZXQodGFnLCBzKTtcb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AgfVxuICB9XG4gIF9hZGRUYWcodGFnKSB7XG4gICAgaWYgKCF0aGlzLl9fdGFncykge1xuICAgICAgdGhpcy5fX3RhZ3MgPSBbXTtcbiAgICB9XG4gICAgaWYgKHRoaXMuX190YWdzLmluZGV4T2YodGFnKSA9PT0gLTEpIHtcbiAgICAgIHRoaXMuX190YWdzLnB1c2godGFnKTtcbiAgICAgIGxldCBwID0gdGhpcy5fX3BhcmVudDtcbiAgICAgIGlmIChwKSB7XG4gICAgICAgIGRvIHtcbiAgICAgICAgICBpZiAoIXAuX190cmVlVGFncykge1xuICAgICAgICAgICAgcC5fX3RyZWVUYWdzID0gLyogQF9fUFVSRV9fICovIG5ldyBNYXAoKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgbGV0IHMgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgaWYgKCFzKSB7XG4gICAgICAgICAgICBzID0gLyogQF9fUFVSRV9fICovIG5ldyBTZXQoKTtcbiAgICAgICAgICAgIHAuX190cmVlVGFncy5zZXQodGFnLCBzKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgcy5hZGQodGhpcyk7XG4gICAgICAgIH0gd2hpbGUgKCFwLl9fdGFnUm9vdCAmJiAocCA9IHAuX19wYXJlbnQpKTtcbiAgICAgIH1cbiAgICB9XG4gIH1cbiAgcmVtb3ZlVGFnKHRhZykge1xuICAgIGxldCBpID0gdGhpcy5fX3RhZ3MuaW5kZXhPZih0YWcpO1xuICAgIGlmIChpICE9PSAtMSkge1xuICAgICAgdGhpcy5fX3RhZ3Muc3BsaWNlKGksIDEpO1xuICAgICAgbGV0IHAgPSB0aGlzLl9fcGFyZW50O1xuICAgICAgaWYgKHApIHtcbiAgICAgICAgZG8ge1xuICAgICAgICAgIGxldCBsaXN0ID0gcC5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgICAgIGlmIChsaXN0KSB7XG4gICAgICAgICAgICBsaXN0LmRlbGV0ZSh0aGlzKTtcb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tcbiAgICBjb25zdCBwb2ludElkeCA9IHBhdGguaW5kZXhPZihcIi5cIik7XG4gICAgY29uc3QgYXJyb3dJZHggPSBwYXRoLmluZGV4T2YoXCI+XCIpO1xuICAgIGlmIChwb2ludElkeCA9PT0gLTEgJiYgYXJyb3dJZHggPT09IC0xKSB7XG4gICAgICBpZiAoaXNSZWYpIHtcbiAgICAgICAgY29uc3QgcmVmID0gdGhpcy5nZXRCeVJlZihwYXRoKTtcbiAgICAgICAgcmV0dXJuIHJlZiA/IFtyZWZdIDogW107XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gdGhpcy5tdGFnKHBhdGgpO1xuICAgICAgfVxuICAgIH1cbiAgICBpZiAoYXJyb3dJZHggPT09IC0xIHx8IHBvaW50SWR4ICE9PSAtMSAmJiBwb2ludElkeCA8IGFycm93SWR4KSB7XG4gICAgICBsZXQgbmV4dDtcbiAgICAgIGNvbnN0IHN0ciA9IHBhdGguc3Vic3RyKDAsIHBvaW50SWR4KTtcbiAgICAgIGlmIChpc1JlZikge1xuICAgICAgICBjb25zdCByZWYgPSB0aGlzLmdldEJ5UmVmKHN0cik7XG4gICAgICAgIG5leHQgPSByZWYgPyBbcmVmXSA6IFtdO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgbmV4dCA9IHRoaXMubXRhZyhzdHIpO1xuICAgICAgfVxuICAgICAgbGV0IHRvdGFsID0gW107XG4gICAgICBjb25zdCBzdWJQYXRoID0gcGF0aC5zdWJzdHIocG9pbnRJZHggKyAxKTtcbiAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gbmV4dC5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgdG90YWwgPSB0b3RhbC5jb25jYXQobmV4dFtpXS5fc2VsZWN0Q2hpbGRzKHN1YlBhdGgsIGZhbHNlKSk7XG4gICAgICB9XG4gICAgICByZXR1cm4gdG90YWw7XG4gICAgfSBlbHNlIHtcbiAgICAgIGxldCBuZXh0O1xuICAgICAgY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GluZ3NbcGF0aF07XG4gICAgICBjb25zdCBmaXJzdENoYXJDb2RlID0gcGF0aC5jaGFyQ29kZUF0KDApO1xuICAgICAgaWYgKFV0aWxzJDEuaXNVY0NoYXIoZmlyc3RDaGFyQ29kZSkpIHtcbiAgICAgICAgY29uc3QgY2hpbGQgPSB0aGlzLmdldEJ5UmVmKHBhdGgpO1xuICAgICAgICBpZiAoIWNoaWxkKSB7XG4gICAgICAgICAgaWYgKHYgIT09IHZvaWQgMCkge1xuICAgICAgICAgICAgbGV0IGM7XG4gICAgICAgICAgICBpZiAoVXRpbHMkMS5pc09iamVjdExpdGVyYWwodikpIHtcbiAgICAgICAgICAgICAgYyA9IHRoaXMuY2hpbGRMaXN0LmNyZWF0ZUl0ZW0odik7XG4gICAgICAgICAgICAgIGMucGF0Y2godik7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKFV0aWxzJDEuaXNPYmplY3QodikpIHtcbiAgICAgICAgICAgICAgYyA9IHY7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoYy5pc0VsZW1lbnQpIHtcbiAgICAgICAgICAgICAgYy5yZWYgPSBwYXRoO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QuYShjKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHYgPT09IHZvaWQgMCkge1xuICAgICAgICAgICAgaWYgKGNoaWxkLnBhcmVudCkge1xuICAgICAgICAgICAgICBjaGlsZC5wYXJlbnQuY2hpbGRMaXN0LnJlbW92ZShjaGlsZCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChVdGlscyQxLmlzT2JqZWN0TGl0ZXJhbCh2KSkge1xuICAgICAgICAgICAgY2hpbGQucGF0Y2godik7XG4gICAgICAgICAgfSBlbHNlIGlmICh2LmlzRWxlbWVudCkge1xuICAgICAgICAgICAgdi5yZWYgPSBwYXRoO1xuICAgICAgICAgICAgdG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AgdHJlZVtyZWZdLmNoaWxkcmVuLFxuICAgICAgICAgIGVsZW1lbnQuX19jaGlsZExpc3RcbiAgICAgICAgKTtcbiAgICAgIH1cbiAgICB9XG4gIH1cbiAgc3RhdGljIGdldFByb3BlcnRpZXMoZWxlbWVudCkge1xuICAgIGNvbnN0IHByb3BzID0ge307XG4gICAgY29uc3QgbGlzdCA9IFtcbiAgICAgIFwiYWxwaGFcIixcbiAgICAgIFwiYWN0aXZlXCIsXG4gICAgICBcImF0dGFjaGVkXCIsXG4gICAgICBcImJvdW5kc01hcmdpblwiLFxuICAgICAgXCJjb2xvclwiLFxuICAgICAgXCJjbGlwcGluZ1wiLFxuICAgICAgXCJlbmFibGVkXCIsXG4gICAgICBcImhcIixcbiAgICAgIFwiaWRcIixcbiAgICAgIFwiaXNDb21wb25lbnRcIixcbiAgICAgIFwibW91bnRcIixcbiAgICAgIFwibW91bnRZXCIsXG4gICAgICBcIm1vdW50WFwiLFxuICAgICAgXCJwaXZvdFwiLFxuICAgICAgXCJwaXZvdFhcIixcbiAgICAgIFwicGl2b3RZXCIsXG4gICAgICBcInJlZlwiLFxuICAgICAgXCJyZW5kZXJPZmZzY3JlZW5cIixcbiAgICAgIFwicmVuZGVyVG9UZXh0dXJlXCIsXG4gICAgICBcInNjYWxlXCIsXG4gICAgICBcInNjYWxlWFwiLFxuICAgICAgXCJzY2FsZVlcIixcbiAgICAgIFwic3RhdGVcIixcbiAgICAgIFwidGFnXCIsXG4gICAgICBcInZpc2libGVcIixcbiAgICAgIFwid1wiLFxuICAgICAgXCJ4XCIsXG4gICAgICBcInlcIixcbiAgICAgIFwiekluZGV4XCIsXG4gICAgICBcIiEhZmxleFwiLFxuICAgICAgXCIhIWZsZXhJdGVtXCIsXG4gICAgICBcImhhc0ZvY3VzKClcIixcbiAgICAgIFwiaGFzRmluYWxGb2N1cygpXCJcbiAgICBdO1xuICAgIGxldCBuID0gbGlzdC5sZW5ndGg7XG4gICAgd2hpbGUgKG4tLSkge1xuIC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ZtdCA9PT0gZ2wuUkdCQSkge1xuICAgICAgc3dpdGNoICh0eXBlKSB7XG4gICAgICAgIGNhc2UgZ2wuVU5TSUdORURfQllURTpcbiAgICAgICAgICByZXR1cm4gNDtcbiAgICAgICAgY2FzZSBnbC5VTlNJR05FRF9TSE9SVF80XzRfNF80OlxuICAgICAgICAgIHJldHVybiAyO1xuICAgICAgICBjYXNlIGdsLlVOU0lHTkVEX1NIT1JUXzVfNV81XzE6XG4gICAgICAgICAgcmV0dXJuIDI7XG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiSW52YWxpZCB0eXBlIHNwZWNpZmllZCBmb3IgR0xfUkdCQSBmb3JtYXRcIik7XG4gICAgICB9XG4gICAgfSBlbHNlIGlmIChmbXQgPT09IGdsLlJHQikge1xuICAgICAgc3dpdGNoICh0eXBlKSB7XG4gICAgICAgIGNhc2UgZ2wuVU5TSUdORURfQllURTpcbiAgICAgICAgICByZXR1cm4gMztcbiAgICAgICAgY2FzZSBnbC5VTlNJR05FRF9CWVRFXzVfNl81OlxuICAgICAgICAgIHJldHVybiAyO1xuICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgIHRocm93IG5ldyBFcnJvcihcIkludmFsaWQgdHlwZSBzcGVjaWZpZWQgZm9yIEdMX1JHQiBmb3JtYXRcIik7XG4gICAgICB9XG4gICAgfSBlbHNlIHtcbiAgICAgIHRocm93IG5ldyBFcnJvcihcIkludmFsaWQgZm9ybWF0IHNwZWNpZmllZCBpbiBjYWxsIHRvIF9nZXRCeXRlc1BlclBpeGVsKClcIik7XG4gICAgfVxuICB9XG4gIHVwbG9hZFRleHR1cmVTb3VyY2UodGV4dHVyZVNvdXJjZSwgb3B0aW9ucykge1xuICAgIGNvbnN0IGdsID0gdGhpcy5zdGFnZS5nbDtcbiAgICBjb25zdCBzb3VyY2UgPSBvcHRpb25zLnNvdXJjZTtcbiAgICBsZXQgY29tcHJlc3NlZCA9IGZhbHNlO1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gICB1aW50c1tvZmZzZXQrK10gPSBtY2EoZWxlbWVudENvcmUuX2NvbG9yVXIsIHIuYWxwaGEpO1xuICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHggKyBlbGVtZW50Q29yZS5fdyAqIHIudGEgKyBlbGVtZW50Q29yZS5faCAqIHIudGI7XG4gICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weSArIGVsZW1lbnRDb3JlLl93ICogci50YyArIGVsZW1lbnRDb3JlLl9oICogci50ZDtcbiAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ4O1xuICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl9icnk7XG4gICAgICB1aW50c1tvZmZzZXQrK10gPSBtY2EoZWxlbWVudENvcmUuX2NvbG9yQnIsIHIuYWxwaGEpO1xuICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHggKyBlbGVtZW50Q29yZS5faCAqIHIudGI7XG4gICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weSArIGVsZW1lbnRDb3JlLl9oICogci50ZDtcbiAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fdWx4O1xuICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl9icnk7XG4gICAgICB1aW50c1tvZmZzZXRdID0gbWNhKGVsZW1lbnRDb3JlLl9jb2xvckJsLCByLmFscGhhKTtcbiAgICB9IGVsc2Uge1xuICAgICAgbGV0IGN4ID0gci5weCArIGVsZW1lbnRDb3JlLl93ICogci50YTtcbiAgICAgIGxldCBjeSA9IHIucHkgKyBlbGVtZW50Q29yZS5faCAqIHIudGQ7XG4gICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weDtcbiAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSByLnB5O1xuICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl91bHg7XG4gICAgICBmb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yA9IE11bHRpU3BsaW5lLmdldFJnYmFDb21wb25lbnRzKHBpLmx2KTtcbiAgICAgICAgICAgICAgY29uc3QgZCA9IDEgLyAobmkucCAtIHBpLnApO1xuICAgICAgICAgICAgICBpdGVtc1tpXS5zID0gW1xuICAgICAgICAgICAgICAgIGQgKiAobmNbMF0gLSBwY1swXSksXG4gICAgICAgICAgICAgICAgZCAqIChuY1sxXSAtIHBjWzFdKSxcbiAgICAgICAgICAgICAgICBkICogKG5jWzJdIC0gcGNbMl0pLFxuICAgICAgICAgICAgICAgIGQgKiAobmNbM10gLSBwY1szXSlcbiAgICAgICAgICAgICAgXTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIGl0ZW1zW2ldLnMgPSAobmkubHYgLSBwaS5sdikgLyAobmkucCAtIHBpLnApO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBmb3IgKGkgPSAwOyBpIDwgbiAtIDE7IGkrKykge1xuICAgICAgaWYgKCFpdGVtc1tpXS5mKSB7XG4gICAgICAgIGxldCBsYXN0ID0gaSA9PT0gbiAtIDE7XG4gICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoXCJ2ZVwiKSkge1xuICAgICAgICAgIGl0ZW1zW2ldLnZlID0gbGFzdCA/IGl0ZW1zW2ldLmx2IDogaXRlbXNbaSArIDFdLmx2O1xuICAgICAgICB9XG4gICAgICAgIGlmIChVdGlscyQxLmlzTnVtYmVyKGl0ZW1zW2ldLnYpICYmIFV0aWxzJDEuaXNOdW1iZXIoaXRlbXNbaV0ubHYpKSB7XG4gICAgICAgICAgaWYgKCFpdGVtc1tpXS5oYXNPd25Qcm9wZXJ0eShcInNtZVwiKSkge1xuICAgICAgICAgICAgaXRlbXNbaV0uc21lID0gbGFzdCA/IGRlZmF1bHRTbW9vdGhuZXNzIDogaXRlbXNbaSArIDFdLnNtO1xuICAgICAgICAgIH1c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R1cm4gZnVuY3Rpb24ocCkge1xuICAgICAgICBpZiAocCA9PT0gMClcbiAgICAgICAgICByZXR1cm4gdjE7XG4gICAgICAgIGlmIChwID09PSAxKVxuICAgICAgICAgIHJldHVybiB2MjtcbiAgICAgICAgcmV0dXJuIE11bHRpU3BsaW5lLm1lcmdlQ29sb3JzKHYyLCB2MSwgcCk7XG4gICAgICB9O1xuICAgIH0gZWxzZSB7XG4gICAgICByZXR1cm4gZnVuY3Rpb24ocCkge1xuICAgICAgICBpZiAocCA9PT0gMClcbiAgICAgICAgICByZXR1cm4gdjE7XG4gICAgICAgIGlmIChwID09PSAxKVxuICAgICAgICAgIHJldHVybiB2MjtcbiAgICAgICAgcmV0dXJuIE11bHRpU3BsaW5lLmdldEFyZ2JOdW1iZXIoW1xuICAgICAgICAgIE1hdGgubWluKDI1NSwgTXVsdGlTcGxpbmUuY2FsY3VsYXRlU3BsaW5lKGhlbHBlcnNbMF0sIHApKSxcbiAgICAgICAgICBNYXRoLm1pbigyNTUsIE11bHRpU3BsaW5lLmNhbGN1bGF0ZVNwbGluZShoZWxwZXJzWzFdLCBwKSksXG4gICAgICAgICAgTWF0aC5taW4oMjU1LCBNdWx0aVNwbGluZS5jYWxjdWxhdGVTcGxpbmUoaGVscGVyc1syXSwgcCkpLFxuICAgICAgICAgIE1hdGgubWluKDI1NSwgTXVsdGlTcGxpbmUuY2FsY3VsYXRlU3BsaW5lKGhlbHBlcnNbM10sIHApKVxuICAgICAgICBdKTtcbiAgICAgIH07XG4gICAgfVxuICB9XG4gIHN0YXRpYyBnZXRTcGxpbmVIZWxwZXJzKHYxLCB2MiwgbzEsIGkyLCBzMSwgczIpIHtcbiAgICBpZiAoIW8xICYmICFpMikge1xuICAgICAgcmV0dXJuIG51bGw7XG4gICAgfVxuICAgIGxldCBjc3ggPSBvMTtcbiAgICBsZXQgY3N5ID0gdjEgKyBzMSAqIG8xO1xuICAgIGxldCBjZXggPSAxIC0gaTI7XG4gICAgbGV0IGNleSA9IH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2hpbGRyZW5bbl07XG4gICAgICBjb25zdCBwcmVjaXNpb24gPSB0aGlzLnN0YWdlLmdldFJlbmRlclByZWNpc2lvbigpIC8gdGhpcy5zdGFnZS5nZXRPcHRpb24oXCJkZXZpY2VQaXhlbFJhdGlvXCIpO1xuICAgICAgY29uc3QgY3R4ID0gY2hpbGQuY29yZS5fd29ybGRDb250ZXh0O1xuICAgICAgY29uc3QgY3ggPSBjdHgucHggKiBwcmVjaXNpb247XG4gICAgICBjb25zdCBjeSA9IGN0eC5weSAqIHByZWNpc2lvbjtcbiAgICAgIGNvbnN0IGN3ID0gY2hpbGQuZmluYWxXICogY3R4LnRhICogcHJlY2lzaW9uO1xuICAgICAgY29uc3QgY2ggPSBjaGlsZC5maW5hbEggKiBjdHgudGQgKiBwcmVjaXNpb247XG4gICAgICBpZiAoY3ggPiB0aGlzLnN0YWdlLncgfHwgY3kgPiB0aGlzLnN0YWdlLmgpIHtcbiAgICAgICAgY29udGludWU7XG4gICAgICB9XG4gICAgICBpZiAoY2hpbGQucGFyZW50LmNvcmUuX3NjaXNzb3IpIHtcbiAgICAgICAgY29uc3Qgc2Npc3NvciA9IGNoaWxkLnBhcmVudC5jb3JlLl9zY2lzc29yLm1hcCgodikgPT4gdiAqIHByZWNpc2lvbik7XG4gICAgICAgIGlmICghdGhpcy5fdGVzdENvbGxpc2lvbihjdXJzb3JYLCBjdXJzb3JZLCAuLi5zY2lzc29yKSlcbiAgICAgICAgICBjb250aW51ZTtcbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl90ZXN0Q29sbGlzaW9uKGN1cnNvclgsIGN1cnNvclksIGN4LCBjeSwgY3csIGNoKSkge1xuICAgICAgICBjYW5kaWRhdGVzLnB1c2goY2hpbGQpO1xuICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4gY2FuZGlkYXRlcztcbiAgfVxuICBfdGVzdENvbGxpc2lvbihweCwgcHksIGN4LCBjeSwgY3csIGNoKSB7XG4gICAgaWYgKHB4ID49IGN4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rZXldID0gLTE7XG4gICAgICBiaVtrZXldID0gaTtcbiAgICB9XG4gICAgZm9yIChsZXQgaSA9IDAsIG4gPSBha3MubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICBjb25zdCBrZXkgPSBha3NbaV07XG4gICAgICBhaVtrZXldID0gaTtcbiAgICAgIGlmIChiaVtrZXldID09PSB2b2lkIDApIHtcbiAgICAgICAgYmlba2V5XSA9IC0xO1xuICAgICAgfVxuICAgIH1cbiAgICBjb25zdCBha3NsID0gYWtzLmxlbmd0aDtcbiAgICBjb25zdCByZXN1bHQgPSB7fTtcbiAgICBmb3IgKGxldCBpID0gMCwgbiA9IGJrcy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgIGNvbnN0IGtleSA9IGJrc1tpXTtcbiAgICAgIGNvbnN0IGFJbmRleCA9IGFpW2tleV07XG4gICAgICBsZXQgY3VySW5kZXgyID0gYUluZGV4O1xuICAgICAgd2hpbGUgKC0tY3VySW5kZXgyID49IDApIHtcbiAgICAgICAgY29uc3QgYWtleSA9IGFrc1tjdXJJbmRleDJdO1xuICAgICAgICBpZiAoYmlbYWtleV0gIT09IC0xKSB7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHdoaWxlICgrK2N1ckluZGV4MiA8IGFJbmRleCkge1xuICAgICAgICBjb25zdCBha2V5ID0gYWtzW2N1ckluZGV4Ml07XG4gICAgICAgIHJlc3VsdFtha2V5XSA9IGFbYWtleV07XG4gICAgICB9XG4gICAgICBjb25zdCBidiA9IGJba2V5XTtcbiAgICAgIGNvbnN0IGF2ID0gYVtrZXldO1xuICAgICAgbGV0IHI7XG4gICAgICBpZiAodGhpcy5pc01mKGJ2KSkge1xuICAgICAgICByID0gYnYoYXYpO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKCFVdGlscyQxLmlzT2JqZWN0TGl0ZXJhbChhdikgfHwgIVV0aWxzJDEuaXNPYmplY3RMa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ICAgICBpZihmYWRlWzBdID4gMC4wKSB7XG4gICAgICAgICAgICBwb3MxID0gdmVjMihwb2ludC54LCBwb2ludC55KTtcbiAgICAgICAgICAgIHBvczIgPSB2ZWMyKHBvaW50LngsIHBvaW50LnkgKyBmYWRlWzBdKTtcbiAgICAgICAgICAgIGQgPSBwb3MyIC0gcG9zMTtcbiAgICAgICAgICAgIGMgPSBkb3QocG9zMSwgZCkgLyBkb3QoZCwgZCk7XG4gICAgICAgICAgICB0ID0gc21vb3Roc3RlcCgwLjAsIDEuMCwgY2xhbXAoYywgMC4wLCAxLjApKTtcbiAgICAgICAgICAgIGNvbG9yID0gbWl4KHZlYzQoMC4wKSwgY29sb3IsIHQpO1xuICAgICAgICB9XG4gICAgICAgIFxuICAgICAgICBpZihmYWRlWzFdID4gMC4wKSB7XG4gICAgICAgICAgICB2ZWMyIHBvczEgPSB2ZWMyKHBvaW50LnggLSByZXNvbHV0aW9uLnggLSBmYWRlWzFdLCB2VGV4dHVyZUNvb3JkLnkpO1xuICAgICAgICAgICAgdmVjMiBwb3MyID0gdmVjMihwb2ludC54IC0gcmVzb2x1dGlvbi54LCB2VGV4dHVyZUNvb3JkLnkpO1xuICAgICAgICAgICAgZCA9IHBvczEgLSBwb3MyO1xuICAgICAgICAgICAgYyA9IGRvdChwb3MyLCBkKSAvIGRvdChkLCBkKTtcbiAgICAgICAgICAgIHQgPSBzbW9vdGhzdGVwKDAuMCwgMS4wLCBjbGFtcChjLCAwLjAsIDEuMCkpO1xuICAgICAgICAgICAgY29sb3IgPSBtaXgodmVjNCgwLjApLCBjb2xvciwgdCk7XG4gICAgICAgIH1cbiAgICAgICAgXG4gICAgICAgIGlmKGZhZGVbMl0gPiAwLjApIHtcbiAgICAgICAgICAgIHZlYzIgcG9zMSA9IHZlYzIodlRleHR1cmVDb29yZC54LCBwb2ludC55IC0gcmVzb2x1dGlvbi55IC0gZmFkZVsyXSk7XG4gICAgICAgICAgICB2ZWMyIHBvczIgPSB2ZWMyKHZUZXh0dXJlQ29vcmQueCwgcG9pbnQueSAtIHJlc29sdXRpb24ueSk7XG4gICAgICAgICAgICBkID0gcG9zMSAtIHBvczI7XG4gICAgICAgICAgICBjID0gZG90KHBvczIsIGQpIC8gZG90KGQsIGQpO1xuICAgICAgICAgICAgdCA9IHNtb290aHN0ZXAoMC4wLCAxLjAsIGNsYW1wKGMsIDAuMCwgMS4wKSk7XG4gICAgICAgICAgICBjb2xvciA9IG1peCh2ZWM0KDAuMCksIGNvbG9yLCB0KTtcbiAgICAgICAgfVxuICAgICAgICBcbiAgICAgICAgaWYoZmFkZVszXSA+IDAuMCkge1xuICAgICAgICAgICAgcG9zMSA9IHZlYzIocG9pbnQueCwgcG9pbnQueSk7XG4gICAgICAgICAgICBwb3MyID0gdmVjMihwb2ludC54ICsgZmFkZVszXSwgcG9pbnQueSk7XG4gICAgICAgICAgICBkID0gcG9zMiAtIHBvczE7XG4gICAgICAgICAgICBjID0gZG90KHBvczEsIGQpIC8gZG90KGQsIGQpO1xuICAgICAgICAgICAgdCA9IHNtb290aHN0ZXAoMC4wLCAxLjAsIGNsYW1wKGMsIDAuMCwgMS4wKSk7XG4gICAgICAgICAgICBjb2xvciA9IG1peCh2ZWM0KDAuMCksIGNvbG9yLCB0KTtcbiAgICAgICAgfVxuICAgICAgICBcbiAgICAgICAgZ2xfRnJhZ0NvbG9yID0gY29sb3I7XG4gICAgfVxuYDtcbmNsYXNzIFZpZ25ldHRlU2hhZGVyIGV4dGVuZHMgRGVmYXVsdFNoYWRlciQxIHtcbiAgY29uc3RydWN0b3IoY29udGV4dCkge1xuICAgIHN1cGVyKGNvbnRleHQpO1xuICAgIHRoaXMuX21hZ25pdHVkZSA9IDEuMztcbiAgICB0aGlzLl9pbnRlbnNpdHkgPSAwLjc7XG4gICAgdGhpcy5fcGl2b3QgPSBbMC41LCAwLjVdO1xuICB9XG4gIHNldHVwVW5pZm9ybXMob3BlcmF0aW9uKSB7XG4gICAgc3VwZXIuc2V0dXBVbmlmb3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aW9uLnh5LCB6KTtcbiAgICAgICAgXG4gICAgICAgIHBvcyAtPSBwaXZvdDtcbiAgICAgICAgXG4gICAgICAgIC8vIFVuZG8gWFkgcm90YXRpb25cbiAgICAgICAgbWF0MiBpUm90WHkgPSBtYXQyKCBjb3Mocm90LnopLCBzaW4ocm90LnopLCBcbiAgICAgICAgICAgICAgICAgICAgICAgICAgIC1zaW4ocm90LnopLCBjb3Mocm90LnopKTtcbiAgICAgICAgcG9zLnh5ID0gaVJvdFh5ICogcG9zLnh5O1xuICAgICAgICBcbiAgICAgICAgLy8gUGVyZm9ybSAzZCByb3RhdGlvbnNcbiAgICAgICAgZ2xfUG9zaXRpb24ueCA9IGNvcyhyb3QueCkgKiBwb3MueCAtIHNpbihyb3QueCkgKiBwb3MuejtcbiAgICAgICAgZ2xfUG9zaXRpb24ueSA9IHBvcy55O1xuICAgICAgICBnbF9Qb3NpdGlvbi56ID0gc2luKHJvdC54KSAqIHBvcy54ICsgY29zKHJvdC54KSAqIHBvcy56O1xuICAgICAgICBcbiAgICAgICAgcG9zLnggPSBnbF9Qb3NpdGlvbi54O1xuICAgICAgICBwb3MueSA9IGNvcyhyb3QueSkgKiBnbF9Qb3NpdGlvbi55IC0gc2luKHJvdC55KSAqIGdsX1Bvc2l0aW9uLno7XG4gICAgICAgIHBvcy56ID0gc2luKHJvdC55KSAqIGdsX1Bvc2l0aW9uLnkgKyBjb3Mocm90LnkpICogZ2xfUG9zaXRpb24uejtcbiAgICAgICAgXG4gICAgICAgIC8vIFJlZG8gWFkgcm90YXRpb25cbiAgICAgICAgaVJvdFh5WzBdWzFdID0gLWlSb3RYeVswXVsxXTtcbiAgICAgICAgaVJvdFh5WzFdWzBdID0gLWlSb3RYeVsxXVswXTtcbiAgICAgICAgcG9zLnh5ID0gaVJvdFh5ICogcG9zLnh5OyBcblxuICAgICAgICAvLyBVbmRvIHRyYW5zbGF0ZSB0byBwaXZvdCBwb3NpdGlvblxuICAgICAgICBwb3MueHl6ICs9IHBp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AgICAgIFxuICAgICAgICAvLyBVbmRvIFhZIHJvdGF0aW9uXG4gICAgICAgIG1hdDIgaVJvdFh5ID0gbWF0MiggY29zKHJvdC56KSwgc2luKHJvdC56KSwgXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAtc2luKHJvdC56KSwgY29zKHJvdC56KSk7XG4gICAgICAgIHBvcy54eSA9IGlSb3RYeSAqIHBvcy54eTtcbiAgICAgICAgXG4gICAgICAgIC8vIFBlcmZvcm0gM2Qgcm90YXRpb25zXG4gICAgICAgIGdsX1Bvc2l0aW9uLnggPSBjb3Mocm90LngpICogcG9zLnggLSBzaW4ocm90LngpICogcG9zLno7XG4gICAgICAgIGdsX1Bvc2l0aW9uLnkgPSBwb3MueTtcbiAgICAgICAgZ2xfUG9zaXRpb24ueiA9IHNpbihyb3QueCkgKiBwb3MueCArIGNvcyhyb3QueCkgKiBwb3MuejtcbiAgICAgICAgXG4gICAgICAgIHBvcy54ID0gZ2xfUG9zaXRpb24ueDtcbiAgICAgICAgcG9zLnkgPSBjb3Mocm90LnkpICogZ2xfUG9zaXRpb24ueSAtIHNpbihyb3QueSkgKiBnbF9Qb3NpdGlvbi56O1xuICAgICAgICBwb3MueiA9IHNpbihyb3QueSkgKiBnbF9Qb3NpdGlvbi55ICsgY29zKHJvdC55KSAqIGdsX1Bvc2l0aW9uLno7XG4gICAgICAgIFxuICAgICAgICAvLyBSZWRvIFhZIHJvdGF0aW9uXG4gICAgICAgIGlSb3RYeVswXVsxXSA9IC1pUm90WHlbMF1bMV07XG4gICAgICAgIGlSb3RYeVsxXVswXSA9IC1pUm90WHlbMV1bMF07XG4gICAgICAgIHBvcy54eSA9IGlSb3RYeSAqIHBvcy54eTsgXG5cbiAgICAgICAgLy8gVW5kbyB0cmFuc2xhdGUgdG8gcGl2b3QgcG9zaXRpb25cbiAgICAgICAgcG9zLnh5eiArPSBwaXZvdDtcblxuICAgICAgICBwb3MgPSB2ZWMzKHBvcy54ICogcHJvamVjdGlvbi54IC0gM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CBjLCBkKSB7XG4gICAgICBsZXQgeGMgPSAzICogYTtcbiAgICAgIGxldCB4YiA9IDMgKiAoYyAtIGEpIC0geGM7XG4gICAgICBsZXQgeGEgPSAxIC0geGMgLSB4YjtcbiAgICAgIGxldCB5YyA9IDMgKiBiO1xuICAgICAgbGV0IHliID0gMyAqIChkIC0gYikgLSB5YztcbiAgICAgIGxldCB5YSA9IDEgLSB5YyAtIHliO1xuICAgICAgcmV0dXJuIGZ1bmN0aW9uKHRpbWUpIHtcbiAgICAgICAgaWYgKHRpbWUgPj0gMSkge1xuICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aW1lIDw9IDApIHtcbiAgICAgICAgICByZXR1cm4gMDtcbiAgICAgICAgfVxuICAgICAgICBsZXQgdCA9IDAuNSwgY2J4LCBjYnhkLCBkeDtcbiAgICAgICAgZm9yIChsZXQgaXQgPSAwOyBpdCA8IDIwOyBpdCsrKSB7XG4gICAgICAgICAgY2J4ID0gdCAqICh0ICogKHQgKiB4YSArIHhiKSArIHhjKTtcbiAgICAgICAgICBkeCA9IHRpbWUgLSBjYng7XG4gICAgICAgICAgaWYgKGR4ID4gLTFlLTggJiYgZHggPCAxZS04KSB7XG4gICAgICAgICAgICByZXR1cm4gdCAqICh0ICogKHQgKiB5YSArIHliKSArIHljKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgY2J4ZCA9IHQgKiAodCAqICgzICogeGEpICsgMiAqIHhiKSArIHhjO1xuICAgICAgICAgIGlmIChjYnhkID4gMWUtMTAgJiYgY2J4ZCA8IDFlLTEwKSB7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG4gICAgICAgICAgdCArPSBkeCAvIGNieGQ7XG4gICAgICAgIH1cbiAgICAgICAgbGV0IG1pblQgPSAwO1xuICAgICAgICBsZXQgbWF4VCA9IDE7XG4gICAgICAgIGZvciAobGV0IGl0ID0gMDsgaXQgPCAyMDsgaXQrKykge1xuICAgICAgICAgIHQgPSAwLjUgKiAobWluVCArIG1heFQpO1xuICAgICAgICAgIGNieCA9IHQgKiAodCAqICh0ICogeGEgKyB4YikgKyB4Yyk7XG4gICAgICAgICAgZHggPSB0aW1lIC0gY2J4O1xuICAgICAgICAgIGlmIChkeCA+IC0xZS04ICYmIGR4IDwgMWUtOCkge1xuICAgICAgICAgICAgcmV0dXJuIHQgKiAodCAqICh0ICogeWEgKyB5YikgKyB5Yyk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChkeCA8IDApIHtcbiAgICAgICAgICAgIG1heFQgPSB0O1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBtaW5UID0gdDtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXRUaW1pbmdGdW5jdGlvbihzdHIpIHtcbiAgICAgIHN3aXRjaCAoc3RyKSB7XG4gICAgICAgIGNhc2UgXCJsaW5lYXJcIjpcbiAgICAgICAgICByZXR1cm4gZnVuY3Rpb24odGltZSkge1xuICAgICAgICAgICAgcmV0dXJuIHRpbWU7XG4gICAgICAgICAgfTtcbiAgICAgICAgY2FzZSBcImVhc2VcIjpcbiAgICAgICAgICByZXR1cm4gU3RhZ2VVdGlscy5nZXRUaW1pbmdCZXppZXIoMC4yNSwgMC4xLCAwLjI1LCAxKTtcbiAgICAgICAgY2FzZSBcImVhc2UtaW5cIjpcbiAgICAgICAgICByZXR1cm4gU3RhZ2VVdGlscy5nZXRUaW1pbmdCZXppZXIoMC40MiwgMCwgMSwgMSk7XG4gICAgICAgIGNhc2UgXCJlYXNlLW91dFwiOlxuICAgICAgICAgIHJldHVybiBTdGFnZVV0aWxzLmdldFRpbWluZ0JlemllcigwLCAwLCAwLjU4LCAxKTtcbiAgICAgICAgY2FzZSBcImVhc2UtaW4tb3V0XCI6XG4gICAgICAgICAgcmV0dXJuIFN0YWdlVXRpbHMuZ2V0VGltaW5nQmV6aWVyKDAuNDIsIDAsIDAuNTgsIDEpO1xuICAgICAgICBjYXNlIFwic3RlcC1zdGFydFwiOlxuICAgICAgICAgIHJldHVybiBmdW5jdGlvbigpIHtcbiAgICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICAgIH07XG4gICAgICAgIGNhc2UgXCJzdGVwLWVuZFwiOlxuICAgICAgICAgIHJldHVybiBmdW5jdGlvbih0aW1lKSB7XG4gICAgICAgICAgICByZXR1cm4gdGltZSA9PT0gMSA/IDEgOiAwO1xuICAgICAgICAgIH07XG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgbGV0IHMgPSBcImN1YmljLWJlemllcihcIjtcbiAgICAgICAgICBpZiAoc3RyICYmIHN0ci5pbmRleE9mKHMpID09PSAwKSB7XG4gICAgICAgICAgICBsZXQgcGFydHMgPSBzdHIuc3Vic3RyKHMubGVuZ3RoLCBzdHIubGVuZ3RoIC0gcy5sZW5ndGggLSAxKS5zcGxpdChcIixcIik7XG4gICAgICAgICAgICBpZiAocGFydHMubGVuZ3RoICE9PSA0KSB7XG4gICAgICAgICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIFVua25vd24gdGltaW5nIGZ1bmN0aW9uOiBcIiArIHN0cik7XG4gICAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbih0aW1lKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRpbWU7XG4gICAgICAgICAgICAgIH07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBsZXQgYSA9IHBhcnNlRmxvYXQocGFydHNbMF0pO1xuICAgICAgICAgICAgbGV0IGIgPSBwYXJzZUZsb2F0KHBhcnRzWzFdKTtcbiAgICAgICAgICAgIGxldCBjID0gcGFyc2VGbG9hdChwYXJ0c1syXSk7XG4gICAgICAgICAgICBsZXQgZCA9IHBhcnNlRmxvYXQocGFydHNbM10pO1xuICAgICAgICAgICAgaWYgKGlzTmFOKGEpIHx8IGlzTmFOKGIpIHx8IGlzTmFOKGMpIHx8IGlzTmFOKGQpKSB7XG4gICAgICAgICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIFVua25vd24gdGltaW5nIGZ1bmN0aW9uOiBcIiArIHN0cik7XG4gICAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbih0aW1lKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRpbWU7XG4gICAgICAgICAgICAgIH07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gU3RhZ2VVdGlscy5nZXRUaW1pbmdCZXppZXIoYSwgYiwgYywgZCk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIFVua25vd24gdGltaW5nIGZ1bmN0aW9uOiBcIiArIHN0cik7XG4gICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24odGltZSkge1xuICAgICAgICAgICAgICByZXR1cm4gdGltZTtcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgfVxuICBsZXQgVXRpbHMkMSA9IGNsYXNzIFV0aWxzIHtcbiAgICBzdGF0aWMgaXNGdW5jdGlvbih2YWx1ZSkge1xuICAgICAgcmV0dXJuIHR5cGVvZiB2YWx1ZSA9PT0gXCJmdW5jdGlvblwiO1xuICAgIH1cbiAgICBzdGF0aWMgaXNOdW1iZXIodmFsdWUpIHtcbiAgICAgIHJldHVybiB0eXBlb2YgdmFsdWUgPT09IFwibnVtYmVyXCI7XG4gICAgfVxuICAgIHN0YXRpYyBpc0ludGVnZXIodmFsdWUpIHtcbiAgICAgIHJldHVybiB0eXBlb2YgdmFsdWUgPT09IFwibnVtYmVyXCIgJiYgdmFsdWUgJSAxID09PSAwO1xuICAgIH1cbiAgICBzdGF0aWMgaXNCb29sZWFuKHZhbHVlKSB7XG4gICAgICByZXR1cm4gdmFsdWUgPT09IHRydWUgfHwgdmFsdWUgPT09IGZhbHNlO1xuICAgIH1cbiAgICBzdGF0aWMgaXNTdHJpbmcodmFsdWUp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Mi5sZW5ndGgpIHtcbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgfVxuICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBrZXlzMS5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgY29uc3QgazEgPSBrZXlzMVtpXTtcbiAgICAgICAgY29uc3QgazIgPSBrZXlzMltpXTtcbiAgICAgICAgaWYgKGsxICE9PSBrMikge1xuICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgICBjb25zdCB2MSA9IG9iajFbazFdO1xuICAgICAgICBjb25zdCB2MiA9IG9iajJbazJdO1xuICAgICAgICBpZiAoIVV0aWxzJDEuZXF1YWxWYWx1ZXModjEsIHYyKSkge1xuICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIHRydWU7XG4gICAgfVxuICAgIHN0YXRpYyBlcXVhbEFycmF5cyh2MSwgdjIpIHtcbiAgICAgIGlmICh2MS5sZW5ndGggIT09IHYyLmxlbmd0aCkge1xuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICB9XG4gICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHYxLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICBpZiAoIXRoaXMuZXF1YWxWYWx1ZXModjFbaV0sIHYyW2ldKSkge1xuICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIHRydWU7XG4gICAgfVxuICAgIHN0YXRpYyBzZXRUb0FycmF5KHMpIHtcbiAgICAgIGxldCByZXN1bHQgPSBbXTtcbiAgICAgIHMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSkge1xuICAgICAgICByZXN1bHQucHVzaCh2YWx1ZSk7XG4gICAgICB9KTtcbiAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgfVxuICAgIHN0YXRpYyBpdGVyYXRvclRvQXJyY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gICAgICAgICBjb25zdCBpdGVtID0gaXRlbXNbaV07XG4gICAgICAgICAgICBjb25zdCBmbGV4SXRlbSA9IGl0ZW0uZmxleEl0ZW07XG4gICAgICAgICAgICBjb25zdCBzaHJpbmtBbW91bnQgPSBmbGV4SXRlbS5zaHJpbms7XG4gICAgICAgICAgICBjb25zdCBpc1Nocmlua2FibGVJdGVtID0gc2hyaW5rQW1vdW50ID4gMDtcbiAgICAgICAgICAgIGlmIChpc1Nocmlua2FibGVJdGVtKSB7XG4gICAgICAgICAgICAgIGxldCBzaHJpbmsgPSBzaHJpbmtBbW91bnQgKiBhbW91bnRQZXJTaHJpbms7XG4gICAgICAgICAgICAgIGNvbnN0IG1pblNpemUgPSBmbGV4SXRlbS5fZ2V0TWFpbkF4aXNNaW5TaXplKCk7XG4gICAgICAgICAgICAgIGNvbnN0IHNpemUgPSBmbGV4SXRlbS5fZ2V0TWFpbkF4aXNMYXlvdXRTaXplKCk7XG4gICAgICAgICAgICAgIGlmIChzaXplID4gbWluU2l6ZSkge1xuICAgICAgICAgICAgICAgIGNvbnN0IG1heFNocmluayA9IHNpemUgLSBtaW5TaXplO1xuICAgICAgICAgICAgICAgIGNvbnN0IGlzRnVsbHlTaHJ1bmsgPSBzaHJpbmsgPj0gbWF4U2hyaW5rO1xuICAgICAgICAgICAgICAgIGlmIChpc0Z1bGx5U2hydW5rKSB7XG4gICAgICAgICAgICAgICAgICBzaHJpbmsgPSBtYXhTaHJpbms7XG4gICAgICAgICAgICAgICAgICB0b3RhbFNocmlua0Ftb3VudCAtPSBzaHJpbmtBbW91bnQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNvbnN0IGZpbmFsU2l6ZSA9IHNpemUgLSBzaHJpbms7XG4gICAgICAgICAgICAgICAgZmxleEl0ZW0uX3Jlc2l6ZU1haW5BeGlzKGZpbmFsU2l6ZSk7XG4gICAgICAgICAgICAgICAgdGhpcy5fc2hydW5rU2l6ZSArPSBzaHJpbms7XG4gICAgICAgICAgICAgICAgdGhpcy5fYW1vdW50UmVtYWluaW5nIC09IHNocmluaztcbiAgICAgICAgICAgICAgICBpZiAoTWF0aC5hYnModGhpcy5fYW1vdW50UmVtYWluaW5nKSA8IDFlLTUpIHtcbiAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH0gd2hpbGUgKHRvdGFsU2hyaW5rQW1vdW50ICYmIE1hdGguYWJzKHRoaXMuX2Ftb3VudFJlbWFpbmluZykgPiAxZS01KTtcbiAgICAgIH1cbiAgICB9XG4gICAgX2dldFRvdGFsU2hyaW5rQW1vdW50KCkge1xuICAgICAgbGV0IHRvdGFsID0gMDtcbiAgICAgIGNvbnN0IGl0ZW1zID0gdGhpcy5fbGluZS5pdGVtcztcbiAgICAgIGZvciAobGV0IGkgPSB0aGlzLl9saW5lLnN0YXJ0SW5kZXg7IGkgPD0gdGhpcy5fbGluZS5lbmRJbmRleDsgaSsrKSB7XG4gICAgICAgIGNvbnN0IGl0ZW0gPSBpdGVtc1tpXTtcbiAgICAgICAgY29uc3QgZmxleEl0ZW0gPSBpdGVtLmZsZXhJdGVtO1xuICAgICAgICBpZiAoZmxleEl0ZW0uc2hyaW5rKSB7XG4gICAgICAgICAgY29uc3QgbWluU2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc01pblNpemUoKTtcbiAgICAgICAgICBjb25zdCBzaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTGF5b3V0U2l6ZSgpO1xuICAgICAgICAgIGlmIChzaXplID4gbWluU2l6ZSkge1xuICAgICAgICAgICAgdG90YWwgKz0gZmxleEl0ZW0uc2hyaW5rO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIHRvdGFsO1xuICAgIH1cbiAgICBnZXRTaHJ1bmtTaXplKCkge1xuICAgICAgcm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ICAgICAgICAgICAgIGNvbnN0IG1heFNpemUgPSBmbGV4SXRlbS5fZ2V0TWFpbkF4aXNNYXhTaXplU2V0dGluZygpO1xuICAgICAgICAgICAgICBjb25zdCBzaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTGF5b3V0U2l6ZSgpO1xuICAgICAgICAgICAgICBpZiAobWF4U2l6ZSA+IDApIHtcbiAgICAgICAgICAgICAgICBpZiAoc2l6ZSA+PSBtYXhTaXplKSB7XG4gICAgICAgICAgICAgICAgICBncm93ID0gMDtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgY29uc3QgbWF4R3JvdyA9IG1heFNpemUgLSBzaXplO1xuICAgICAgICAgICAgICAgICAgY29uc3QgaXNGdWxseUdyb3duID0gZ3JvdyA+PSBtYXhHcm93O1xuICAgICAgICAgICAgICAgICAgaWYgKGlzRnVsbHlHcm93bikge1xuICAgICAgICAgICAgICAgICAgICBncm93ID0gbWF4R3JvdztcbiAgICAgICAgICAgICAgICAgICAgdG90YWxHcm93QW1vdW50IC09IGdyb3dBbW91bnQ7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGlmIChncm93ID4gMCkge1xuICAgICAgICAgICAgICAgIGNvbnN0IGZpbmFsU2l6ZSA9IHNpemUgKyBncm93O1xuICAgICAgICAgICAgICAgIGZsZXhJdGVtLl9yZXNpemVNYWluQXhpcyhmaW5hbFNpemUpO1xuICAgICAgICAgICAgICAgIHRoaXMuX2dyb3duU2l6ZSArPSBncm93O1xuICAgICAgICAgICAgICAgIHRoaXMuX2Ftb3VudFJlbWFpbmluZyAtPSBncm93O1xuICAgICAgICAgICAgICAgIGlmIChNYXRoLmFicyh0aGlzLl9hbW91bnRSZW1haW5pbmcpIDwgMWUtNSkge1xuICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfSB3aGlsZSAodG90YWxHcm93QW1vdW50ICYmIE1hdGguYWJzKHRoaXMuX2Ftb3VudFJlbWFpbmluZykgPiAxZS01KTtcbiAgICAgIH1cbiAgICB9XG4gICAgX2dldFRvdGFsR3Jvd0Ftb3VudCgpIHtcbiAgICAgIGxldCB0b3RhbCA9IDA7XG4gICAgICBjb25zdCBpdGVtcyA9IHRoaXMuX2xpbmUuaXRlbXM7XG4gICAgICBmb3IgKGxldCBpID0gdGhpcy5fbGluZS5zdGFydEluZGV4OyBpIDw9IHRoaXMuX2xpbmUuZW5kSW5kZXg7IGkrKykge1xuICAgICAgICBjb25zdCBpdGVtID0gaXRlbXNbaV07XG4gICAgICAgIGNvbnN0IGZsZXhJdGVtID0gaXRlbS5mbGV4SXRlbTtcbiAgICAgICAgaWYgKGZsZXhJdGVtLmdyb3cpIHtcbiAgICAgICAgICBjb25zdCBtYXhTaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTWF4U2l6ZVNldHRpbmcoKTtcbiAgICAgICAgICBjb25zdCBzaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTGF5b3V0U2l6ZSgpO1xuICAgICAgICAgIGlmIChtYXhTaXplID09PSAwIHx8IHNpemUgPCBtYXhTaXplKSB7XG4gICAgICAgICAgICB0b3RhbCArPSBmbGV4SXRlbS5ncm93O1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIHRvdGFsO1xuICAgIH1cbiAgICBnZXRHcm93blNpemUoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fZ3Jvd25TaXplO1xuICAgIH1cbiAgfVxuICBjbGFzcyBJdGVtUG9zaXRpb25lciB7XG4gICAgY29uc3RydWN0b3IobGluZUxheW91dCkge1xuICAgICAgdGhpcy5fbGluZSA9IGxpbmVMYXlvdXQ7XG4gICAgfVxuICAgIGdldCBfbGF5b3V0KCk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3JhcCh2KSB7XG4gICAgICB0aGlzLl93cmFwID0gdjtcbiAgICAgIHRoaXMuX2NoYW5nZWRDb250ZW50cygpO1xuICAgIH1cbiAgICBnZXQgd3JhcCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl93cmFwO1xuICAgIH1cbiAgICBnZXQgYWxpZ25JdGVtcygpIHtcbiAgICAgIHJldHVybiB0aGlzLl9hbGlnbkl0ZW1zO1xuICAgIH1cbiAgICBzZXQgYWxpZ25JdGVtcyh2KSB7XG4gICAgICBpZiAodGhpcy5fYWxpZ25JdGVtcyA9PT0gdilcbiAgICAgICAgcmV0dXJuO1xuICAgICAgaWYgKEZsZXhDb250YWluZXIuQUxJR05fSVRFTVMuaW5kZXhPZih2KSA9PT0gLTEpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiVW5rbm93biBhbGlnbkl0ZW1zLCBvcHRpb25zOiBcIiArIEZsZXhDb250YWluZXIuQUxJR05fSVRFTVMuam9pbihcIixcIikpO1xuICAgICAgfVxuICAgICAgdGhpcy5fYWxpZ25JdGVtcyA9IHY7XG4gICAgICB0aGlzLl9jaGFuZ2VkQ29udGVudHMoKTtcbiAgICB9XG4gICAgZ2V0IGFsaWduQ29udGVudCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl9hbGlnbkNvbnRlbnQ7XG4gICAgfVxuICAgIHNldCBhbGlnbkNvbnRlbnQodikge1xuICAgICAgaWYgKHRoaXMuX2FsaWduQ29udGVudCA9PT0gdilcbiAgICAgICAgcmV0dXJuO1xuICAgICAgaWYgKEZsZXhDb250YWluZXIuQUxJR05fQ09OVEVOVC5pbmRleE9mKHYpID09PSAtMSkge1xuICAgICAgICB0aHJvdyBuZXcgRXJyb3IoXCJVbmtub3duIGFsaWduQ29udGVudCwgb3B0aW9uczogXCIgKyBGbGV4Q29udGFpbmVyLkFMSUdOX0NPTlRFTlQuam9pbihcIixcIikpO1xuICAgICAgfVxuICAgICAgdGhpcy5fYWxpZ25Db250ZW50ID0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JJTktfQVVUTykge1xuICAgICAgICByZXR1cm4gdGhpcy5fZ2V0RGVmYXVsdFNocmluaygpO1xuICAgICAgfVxuICAgICAgcmV0dXJuIHRoaXMuX3NocmluaztcbiAgICB9XG4gICAgX2dldERlZmF1bHRTaHJpbmsoKSB7XG4gICAgICBpZiAodGhpcy5pdGVtLmlzRmxleEVuYWJsZWQoKSkge1xuICAgICAgICByZXR1cm4gMTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHJldHVybiAwO1xuICAgICAgfVxuICAgIH1cbiAgICBzZXQgc2hyaW5rKHYpIHtcbiAgICAgIGlmICh0aGlzLl9zaHJpbmsgPT09IHYpXG4gICAgICAgIHJldHVybjtcbiAgICAgIHRoaXMuX3NocmluayA9IHBhcnNlSW50KHYpIHx8IDA7XG4gICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgfVxuICAgIGdldCBhbGlnblNlbGYoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fYWxpZ25TZWxmO1xuICAgIH1cbiAgICBzZXQgYWxpZ25TZWxmKHYpIHtcbiAgICAgIGlmICh0aGlzLl9hbGlnblNlbGYgPT09IHYpXG4gICAgICAgIHJldHVybjtcbiAgICAgIGlmICh2ID09PSB2b2lkIDApIHtcbiAgICAgICAgdGhpcy5fYWxpZ25TZWxmID0gdm9pZCAwO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKEZsZXhDb250YWluZXIuQUxJR05fSVRFTVMuaW5kZXhPZih2KSA9PT0gLTEpIHtcbiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoXCJVbmtub3duIGFsaWduU2VsZiwgb3B0aW9uczogXCIgKyBGbGV4Q29udGFpbmVyLkFMSUdOX0lURU1TLmpvaW4oXCIsXCIpKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9hbGlnblNlbGYgPSB2O1xuICAgICAgfVxuICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgIH1cbiAgICBnZXQgbWluV2lkd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Y2xpcGJveCA9IHRydWU7XG4gICAgICB0aGlzLnJlbmRlciA9IHRoaXMuX3JlbmRlclNpbXBsZTtcbiAgICAgIHRoaXMuX2xheW91dCA9IG51bGw7XG4gICAgfVxuICAgIGdldCBvZmZzZXRYKCkge1xuICAgICAgaWYgKHRoaXMuX2Z1bmNYKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9mdW5jWDtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGlmICh0aGlzLmhhc0ZsZXhMYXlvdXQoKSkge1xuICAgICAgICAgIHJldHVybiB0aGlzLl9sYXlvdXQub3JpZ2luYWxYO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHJldHVybiB0aGlzLl94O1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIHNldCBvZmZzZXRYKHYpIHtcbiAgICAgIGlmIChVdGlscyQxLmlzRnVuY3Rpb24odikpIHtcbiAgICAgICAgdGhpcy5mdW5jWCA9IHY7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICB0aGlzLl9kaXNhYmxlRnVuY1goKTtcbiAgICAgICAgaWYgKHRoaXMuaGFzRmxleExheW91dCgpKSB7XG4gICAgICAgICAgdGhpcy54ICs9IHYgLSB0aGlzLl9sYXlvdXQub3JpZ2luYWxYO1xuICAgICAgICAgIHRoaXMuX2xheW91dC5zZXRPcmlnaW5hbFhXaXRob3V0VXBkYXRpbmdMYXlvdXQodik7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhpcy54ID0gdjtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBnZXQgeCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl94O1xuICAgIH1cbiAgICBzZXQgeCh2KSB7XG4gICAgICBpZiAodiAhPT0gdGhpcy5feCkge1xuICAgICAgICB0aGlzLl91cGRhdGVMb2NhbFRyYW5zbGF0ZURlbHRhKHYgLSB0aGlzLl94LCAwKTtcbiAgICAgICAgdGhpcy5feCA9IHY7X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G4gICAgfVxuICAgIGdldCBtb3VudCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl9tb3VudFg7XG4gICAgfVxuICAgIHNldCBtb3VudCh2KSB7XG4gICAgICBpZiAodGhpcy5fbW91bnRYICE9PSB2IHx8IHRoaXMuX21vdW50WSAhPT0gdikge1xuICAgICAgICB0aGlzLl9tb3VudFggPSB2O1xuICAgICAgICB0aGlzLl9tb3VudFkgPSB2O1xuICAgICAgICB0aGlzLl91cGRhdGVMb2NhbFRyYW5zbGF0ZSgpO1xuICAgICAgfVxuICAgIH1cbiAgICBnZXQgcm90YXRpb24oKSB7XG4gICAgICByZXR1cm4gdGhpcy5fcm90YXRpb247XG4gICAgfVxuICAgIHNldCByb3RhdGlvbih2KSB7XG4gICAgICBpZiAodGhpcy5fcm90YXRpb24gIT09IHYpIHtcbiAgICAgICAgdGhpcy5fcm90YXRpb24gPSB2O1xuICAgICAgICB0aGlzLl91cGRhdGVMb2NhbFRyYW5zZm9ybSgpO1xuICAgICAgfVxuICAgIH1cbiAgICBnZXQgYWxwaGEoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fYWxwaGE7XG4gICAgfVxuICAgIHNldCBhbHBoYSh2KSB7XG4gICAgICB2ID0gdiA+IDEgPyAxIDogdiA8IDFlLTE0ID8gMCA6IHY7XG4gICAgICBpZiAodGhpcy5fYWxwaGEgIT09IHYpIHtcbiAgICAgICAgbGV0IHByZXYgPSB0aGlzLl9hbHBoYTtcbiAgICAgICAgdGhpcy5fYWxwaGEgPSB2O1xuICAgICAgICB0aGlzLl91cGRhdGVMb2NhbEFscGhhKCk7XG4gICAgICAgIGlmIChwcmV2ID09PSAwICE9PSAodiA9PT0gMCkpIHtcbiAgICAgICAgICB0aGlzLl9lbGVtZW50Ll91cGRhdGVFbmFibGVkRmxhZygpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIGdldCB2aXNpYmxlKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX3Zpc2libGU7XG4g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gICAgdGhpcy5sYXlvdXQuc2V0UGFyZW50KHByZXZQYXJlbnQsIHBhcmVudCk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHByZXZQYXJlbnQpIHtcbiAgICAgICAgICBwcmV2UGFyZW50LnNldEhhc1JlbmRlclVwZGF0ZXMoMyk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fc2V0UmVjYWxjKDEgKyAyICsgNCk7XG4gICAgICAgIGlmICh0aGlzLl9wYXJlbnQpIHtcbiAgICAgICAgICB0aGlzLl9wYXJlbnQuX3NldEhhc1VwZGF0ZXMoKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fekluZGV4ID09PSAwKSB7XG4gICAgICAgICAgdGhpcy5zZXRaUGFyZW50KHBhcmVudCk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhpcy5zZXRaUGFyZW50KHBhcmVudCA/IHBhcmVudC5maW5kWkNvbnRleHQoKSA6IG51bGwpO1xuICAgICAgICB9XG4gICAgICAgIGlmIChwcmV2SXNaQ29udGV4dCAhPT0gdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgICBpZiAoIXRoaXMuaXNaQ29udGV4dCgpKSB7XG4gICAgICAgICAgICB0aGlzLmRpc2FibGVaQ29udGV4dCgpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmVuYWJsZVpDb250ZXh0KHByZXZQYXJlbnQuZmluZFpDb250ZXh0KCkpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB0aGlzLl96SW5kZXhSZXNvcnQgPSB0cnVlO1xuICAgICAgICBpZiAodGhpcy5felBhcmVudCkge1xuICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZW5hYmxlWlNvcnQoKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoIXRoaXMuX3NoYWRlcikge1xuICAgICAgICAgIGxldCBuZXdTaGFkZXJPd25lciA9IHBhcmVudCAmJiAhcGFy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0gbnVsbCkge1xuICAgICAgICAgIGxldCBoYWRaQ29udGV4dFVzYWdlID0gbmV3WlBhcmVudC5fekNvbnRleHRVc2FnZSA+IDA7XG4gICAgICAgICAgaWYgKHRoaXMuX3pJbmRleCAhPT0gMCkge1xuICAgICAgICAgICAgbmV3WlBhcmVudC5pbmNaQ29udGV4dFVzYWdlKCk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChuZXdaUGFyZW50Ll96Q29udGV4dFVzYWdlID4gMCkge1xuICAgICAgICAgICAgaWYgKCFoYWRaQ29udGV4dFVzYWdlICYmIHRoaXMuX3BhcmVudCA9PT0gbmV3WlBhcmVudClcbiAgICAgICAgICAgICAgO1xuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgIG5ld1pQYXJlbnQuX3pJbmRleGVkQ2hpbGRyZW4ucHVzaCh0aGlzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG5ld1pQYXJlbnQuZW5hYmxlWlNvcnQoKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5felBhcmVudCA9IG5ld1pQYXJlbnQ7XG4gICAgICAgIHRoaXMuX3pJbmRleFJlc29ydCA9IHRydWU7XG4gICAgICB9XG4gICAgfVxuICAgIGluY1pDb250ZXh0VXNhZ2UoKSB7XG4gICAgICB0aGlzLl96Q29udGV4dFVzYWdlKys7XG4gICAgICBpZiAodGhpcy5fekNvbnRleHRVc2FnZSA9PT0gMSkge1xuICAgICAgICBpZiAoIXRoaXMuX3pJbmRleGVkQ2hpbGRyZW4pIHtcbiAgICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuID0gW107XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuKSB7XG4gICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9jaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4ucHVzaCh0aGlzLl9jaGlsZHJlbltpXSk7XG4gICAgICAgICAgfVxuICAgICAgICAgIHRoaXMuX3pTb3J0ID0gZmFsc2U7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgZGVjWkNvbnRleHRVc2FnZSgpIHtcbiAgICAgIHRoaXMuX3pDb250ZXh0VXNhZ2UtLTtcbiAgICAgIGlmICh0aGlzLl96Q29udGV4dFVzYWdlID09PSAwKSB7XG4gICAgICAgIHRoaXMuX3pTb3J0ID0gZmFsc2U7XG4gICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4uc3BsaWNlKDApO1xuICAgICAgfVxuICAgIH1cbiAgICBnZXQgekluZGV4KCkge1xuICAgICAgcmV0dXJuIHRoaXMuX3pJbmRleDtcbiAgICB9XG4gICAgc2V0IHpJbmRleCh6SW5kZXgpIHtcbiAgICAgIGlmICh0aGlzLl96SW5kZXggIT09IHpJbmRleCkge1xuICAgICAgICB0aGlzLnNldEhhc1JlbmRlclVwZGF0ZXMoMSk7XG4gICAgICAgIGxldCBuZXdaUGFyZW50ID0gdGhpcy5felBhcmVudDtcbiAgICAgICAgbGV0IHByZXZJc1pDb250ZXh0ID0gdGhpcy5pc1pDb250ZXh0KCk7XG4gICAgICAgIGlmICh6SW5kZXggPT09IDAgJiYgdGhpcy5fekluZGV4ICE9PSAwKSB7XG4gICAgICAgICAgaWYgKHRoaXMuX3BhcmVudCA9PT0gdGhpcy5felBhcmVudCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgdGhpcy5felBhcmVudC5kZWNaQ29udGV4dFVzYWdlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIG5ld1pQYXJlbnQgPSB0aGlzLl9wYXJlbnQ7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHpJbmRleCAhPT0gMCAmJiB0aGlzLl96SW5kZXggPT09IDApIHtcbiAgICAgICAgICBuZXdaUGFyZW50ID0gdGhpcy5fcGFyZW50ID8gdGhpcy5fcGFyZW50LmZpbmRaQ29udGV4dCgpIDogbnVsbDtcbiAgICAgICAgICBpZiAobmV3WlBhcmVudCA9PT0gdGhpcy5felBhcmVudCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgdGhpcy5felBhcmVudC5pbmNaQ29udGV4dFVzYWdlKCk7XG4gICAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZW5hYmxlWlNvcnQoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSBpZiAoekluZGV4ICE9PSB0aGlzLl96SW5kZXgpIHtcbiAgICAgICAgICBpZiAodGhpcy5felBhcmVudCAmJiB0aGlzLl96UGFyZW50Ll96Q29udGV4dFVzYWdlKSB7XG4gICAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmIChuZXdaUGFyZW50ICE9PSB0aGlzLl96UGFyZW50KSB7XG4gICAgICAgICAgdGhpcy5zZXRaUGFyZW50KG51bGwpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX3pJbmRleCA9IHpJbmRleDtcbiAgICAgICAgaWYgKG5ld1pQYXJlbnQgIT09IHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICB0aGlzLnNldFpQYXJlbnQobmV3WlBhcmVudCk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHByZXZJc1pDb250ZXh0ICE9PSB0aGlzLmlzWkNvbnRleHQoKSkge1xuICAgICAgICAgIGlmICghdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgICAgIHRoaXMuZGlzYWJsZVpDb250ZXh0KCk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHR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pcy5felNvcnQpIHtcbiAgICAgICAgICB0aGlzLnNvcnRaSW5kZXhlZENoaWxkcmVuKCk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fekluZGV4ZWRDaGlsZHJlbi5zbGljZSgpLmZvckVhY2goZnVuY3Rpb24oYykge1xuICAgICAgICAgIGlmIChjLl96SW5kZXggIT09IDApIHtcbiAgICAgICAgICAgIGMuc2V0WlBhcmVudChuZXdaUGFyZW50KTtcbiAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgfVxuICAgIH1cbiAgICBnZXQgY29sb3JVbCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl9jb2xvclVsO1xuICAgIH1cbiAgICBzZXQgY29sb3JVbChjb2xvcikge1xuICAgICAgaWYgKHRoaXMuX2NvbG9yVWwgIT09IGNvbG9yKSB7XG4gICAgICAgIHRoaXMuc2V0SGFzUmVuZGVyVXBkYXRlcyh0aGlzLl9kaXNwbGF5ZWRUZXh0dXJlU291cmNlID8gMyA6IDEpO1xuICAgICAgICB0aGlzLl9jb2xvclVsID0gY29sb3I7XG4gICAgICB9XG4gICAgfVxuICAgIGdldCBjb2xvclVyKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX2NvbG9yVXI7XG4gICAgfVxuICAgIHNldCBjb2xvclVyKGNvbG9yKSB7XG4gICAgICBpZiAodGhpcy5fY29sb3JVciAhPT0gY29sb3IpIHtcbiAgICAgICAgdGhpcy5zZXRIYXNSZW5kZXJVcGRhdGVzKHRoaXMuX2Rpc3BsYXllZFRleHR1cmVTb3VyY2UgPyAzIDogMSk7XG4gICAgICAgIHRoaXMuX2NvbG9yVXIgPSBjb2xvcjtcbiAgICAgIH1cbiAgICB9XG4gICAgZ2V0IGNvbG9yQmwoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fY29sb3JCbDtcbiAgICB9XG4gICAgc2V0IGNvbG9yQmwoY29sb3IpIHtcbiAgICAgIGlmICh0aGlzLl9jb2xvckJsICE9PSBjb2xvcikge1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uc3QgcHcgPSB0aGlzLl9wYXJlbnQuX3dvcmxkQ29udGV4dDtcbiAgICAgIGxldCB3ID0gdGhpcy5fd29ybGRDb250ZXh0O1xuICAgICAgY29uc3QgdmlzaWJsZSA9IHB3LmFscGhhICYmIHRoaXMuX2xvY2FsQWxwaGE7XG4gICAgICBpZiAodGhpcy5faGFzVXBkYXRlcyB8fCB0aGlzLl9yZWNhbGMgJiYgdmlzaWJsZSB8fCB3LmFscGhhICYmICF2aXNpYmxlKSB7XG4gICAgICAgIGxldCByZWNhbGMgPSB0aGlzLl9yZWNhbGM7XG4gICAgICAgIGlmIChyZWNhbGMgJiAxKSB7XG4gICAgICAgICAgaWYgKCF3LmFscGhhICYmIHZpc2libGUpIHtcbiAgICAgICAgICAgIHRoaXMuX2hhc1JlbmRlclVwZGF0ZXMgPSAzO1xuICAgICAgICAgIH1cbiAgICAgICAgICB3LmFscGhhID0gcHcuYWxwaGEgKiB0aGlzLl9sb2NhbEFscGhhO1xuICAgICAgICAgIGlmICh3LmFscGhhIDwgMWUtMTQpIHtcbiAgICAgICAgICAgIHcuYWxwaGEgPSAwO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAocmVjYWxjICYgNikge1xuICAgICAgICAgIHcucHggPSBwdy5weCArIHRoaXMuX2xvY2FsUHggKiBwdy50YTtcbiAgICAgICAgICB3LnB5ID0gcHcucHkgKyB0aGlzLl9sb2NhbFB5ICogcHcudGQ7XG4gICAgICAgICAgaWYgKHB3LnRiICE9PSAwKVxuICAgICAgICAgICAgdy5weCArPSB0aGlzLl9sb2NhbFB5ICogcHcudGI7XG4gICAgICAgICAgaWYgKHB3LnRjICE9PSAwKVxuICAgICAgICAgICAgdy5weSArPSB0aGlzLl9sb2NhbFB4ICogcHcudGM7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHJlY2FsYyAmIDQpIHtcbiAgICAgICAgICB3LnRhID0gdGhpcy5fbG9jYWxUYSAqIHB3LnRhO1xuICAgICAgICAgIHcudGIgPSB0aGlzLl9sb2NhbFRkICogcHcudGI7XG4gICAgICAgICAgdy50YyA9IHRoaXMuX2xvY2FsVGEgKiBwdy50YztcbiAgICAgICAgICB3LnRkID0gdGhpcy5fbG9jYWxUZCAqIHB3LnRkO1xuICAgICAgICAgIGlmICh0aGlzLl9pc0NvbXBsZXgpIHtcbiAgICAgICAgICAgIHcudGEgKz0gdGhpcy5fbG9jYWxUYyAqIHB3LnRiO1xuICAgICAgICAgICAgdy50YiArPSB0aGlzLl9sb2NhbFRiICogcHcudGE7XG4gICAgICAgICAgICB3LnRjICs9IHRoaXMuX2xvY2FsVGMgKiBwdy50ZDtcbiAgICAgICAgICAgIHcudGQgKz0gdGhpcy5fbG9jYWxUYiAqIHB3LnRjO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBjb25zdCBwciA9IHRoaXMuX3BhcmVudC5fcmVuZGVyQ29udGV4dDtcbiAgICAgICAgaWYgKHRoaXMuX3BhcmVudC5faGFzUmVuZGVyQ29udGV4dCgpKSB7XG4gICAgICAgICAgY29uc3QgaW5pdCA9IHRoaXMuX3JlbmRlckNvbnRleHQgPT09IHRoaXMuX3dvcmxkQ29udGV4dDtcbiAgICAgICAgICBpZiAoaW5pdCkge1xuICAgICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IG5ldyBFbGVtZW50Q29yZUNvbnRleHQoKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgY29uc3QgcjIgPSB0aGlzLl9yZW5kZXJDb250ZXh0O1xuICAgICAgICAgIGlmIChpbml0IHx8IHJlY2FsYyAmIDEpIHtcbiAgICAgICAgICAgIHIyLmFscGhhID0gcHIuYWxwaGEgKiB0aGlzLl9sb2NhbEFscGhhO1xuICAgICAgICAgICAgaWYgKHIyLmFscGhhIDwgMWUtMTQpIHtcbiAgICAgICAgICAgICAgcjIuYWxwaGEgPSAwO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoaW5pdCB8fCByZWNhbGMgJiA2KSB7XG4gICAgICAgICAgICByMi5weCA9IHByLnB4ICsgdGhpcy5fbG9jYWxQeCAqIHByLnRhO1xuICAgICAgICAgICAgcjIucHkgPSBwci5weSArIHRoaXMuX2xvY2FsUHkgKiBwci50ZDtcbiAgICAgICAgICAgIGlmIChwci50YiAhPT0gMClcbiAgICAgICAgICAgICAgcjIucHggKz0gdGhpcy5fbG9jYWxQeSAqIHByLnRiO1xuICAgICAgICAgICAgaWYgKHByLnRjICE9PSAwKVxuICAgICAgICAgICAgICByMi5weSArPSB0aGlzLl9sb2NhbFB4ICogcHIudGM7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChpbml0KSB7XG4gICAgICAgICAgICByZWNhbGMgfD0gMjtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKGluaXQgfHwgcmVjYWxjICYgNCkge1xuICAgICAgICAgICAgcjIudGEgPSB0aGlzLl9sb2NhbFRhICogcHIudGE7XG4gICAgICAgICAgICByMi50YiA9IHRoaXMuX2xvY2FsVGQgKiBwci50YjtcbiAgICAgICAgICAgIHIyLnRjID0gdGhpcy5fbG9jYWxUYSAqIHByLnRjO1xuICAgICAgICAgICAgcjIudGQgPSB0aGlzLl9sb2NhbFRkICogcHIudGQ7XG4gICAgICAgICAgICBpZiAodGhpcy5faXNDb21wbGV4KSB7XG4gICAgICAgICAgICAgIHIyLnRhICs9IHRoaXMuX2xvY2FsVGMgKiBwci50YjtcbiAgICAgICAgICAgICAgcjIudGIgKz0gdGhpcy5fbG9jYWxUYiAqIHByLnRhO1xuICAgICAgICAgICAgICByMi50YyArPSB0aGlzLl9sb2NhbFRjICogcHIudGQ7XG4gICAgICAgICAgICAgIHIyLnRkICs9IHRoaXMuX2xvY2FsVGIgKiBwci50YztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IHRoaXMuX3dvc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nRiICE9PSAwIHx8IHIudGMgIT09IDAgfHwgci50YSA8IDAgfHwgci50ZCA8IDA7XG4gICAgICAgIGlmIChyQ29tcGxleCkge1xuICAgICAgICAgIHN4ID0gTWF0aC5taW4oMCwgYmJveFcgKiByLnRhLCBiYm94VyAqIHIudGEgKyBiYm94SCAqIHIudGIsIGJib3hIICogci50YikgKyByLnB4O1xuICAgICAgICAgIGV4ID0gTWF0aC5tYXgoMCwgYmJveFcgKiByLnRhLCBiYm94VyAqIHIudGEgKyBiYm94SCAqIHIudGIsIGJib3hIICogci50YikgKyByLnB4O1xuICAgICAgICAgIHN5ID0gTWF0aC5taW4oMCwgYmJveFcgKiByLnRjLCBiYm94VyAqIHIudGMgKyBiYm94SCAqIHIudGQsIGJib3hIICogci50ZCkgKyByLnB5O1xuICAgICAgICAgIGV5ID0gTWF0aC5tYXgoMCwgYmJveFcgKiByLnRjLCBiYm94VyAqIHIudGMgKyBiYm94SCAqIHIudGQsIGJib3hIICogci50ZCkgKyByLnB5O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHN4ID0gci5weDtcbiAgICAgICAgICBleCA9IHIucHggKyByLnRhICogYmJveFc7XG4gICAgICAgICAgc3kgPSByLnB5O1xuICAgICAgICAgIGV5ID0gci5weSArIHIudGQgKiBiYm94SDtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fZGltc1Vua25vd24gJiYgKHJDb21wbGV4IHx8IHRoaXMuX2xvY2FsVGEgPCAxIHx8IHRoaXMuX2xvY2FsVGIgPCAxKSkge1xuICAgICAgICAgIGNvbnN0IG54ID0gdGhpcy5feCAqIHByLnRhICsgdGhpcy5feSAqIHByLnRiICsgcHIucHg7XG4gICAgICAgICAgY29uc3QgbnkgPSB0aGlzLl94ICogcHIudGMgKyB0aGlzLl95ICogcHIudGQgKyBwci5weTtcbiAgICAgICAgICBpZiAobnggPCBzeClcbiAgICAgICAgICAgIHN4ID0gbng7XG4gICAgICAgICAgaWYgKG55IDwgc3kpXG4gICAgICAgICAgICBzeSA9IG55O1xuICAgICAgICAgIGlmIChueCA+IGV4KVxuICAgICAgICAgICAgZXggPSBueDtcbiAgICAgICAgICBpZiAobnkgPiBleSlcbiAgICAgICAgICAgIGV5ID0gbnk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHJlY2FsYyAmIDYgfHwgIXRoaXMuX3NjaXNzb3IpIHtcbiAgICAgICAgICBpZiAodGhpcy5fY2xpcHBpbmcgJiYgci5pc1NxdWFyZSgpKSB7XG4gICAgICAgICAgICBjb25zdCBhcmVhID0gdGhpcy5fcGFyZW50Ll91c2VSZW5kZXJUb1RleHR1cmUgPyB0aGlzLl9wYXJlbnQuX3ZpZXdwb3J0IDogdGhpcy5fcGFyZW50Ll9zY2lzc29yO1xuICAgICAgICAgICAgaWYgKGFyZWEpIHtcbiAgICAgICAgICAgICAgY29uc3QgbHggPSBNYXRoLm1heChhcmVhWzBdLCBzeCk7XG4gICAgICAgICAgICAgIGNvbnN0IGx5ID0gTWF0aC5tYXgoYXJlYVsxXSwgc3kpO1xuICAgICAgICAgICAgICB0aGlzLl9zY2lzc29yID0gW1xuICAgICAgICAgICAgICAgIGx4LFxuICAgICAgICAgICAgICAgIGx5LFxuICAgICAgICAgICAgICAgIE1hdGgubWluKGFyZWFbMl0gKyBhcmVhWzBdLCBleCkgLSBseCxcbiAgICAgICAgICAgICAgICBNYXRoLm1pbihhcmVhWzNdICsgYXJlYVsxXSwgZXkpIC0gbHlcbiAgICAgICAgICAgICAgXTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHRoaXMuX3NjaXNzb3IgPSBbc3gsIHN5LCBleCAtIHN4LCBleSAtIHN5XTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fc2Npc3NvciA9IHRoaXMuX3BhcmVudC5fdXNlUmVuZGVyVG9UZXh0dXJlID8gdGhpcy5fcGFyZW50Ll92aWV3cG9ydCA6IHRoaXMuX3BhcmVudC5fc2Npc3NvcjtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX2JvdW5kc01hcmdpbikge1xuICAgICAgICAgIHRoaXMuX3JlY0JvdW5kc01hcmdpbiA9IHRoaXMuX2JvdW5kc01hcmdpbjtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB0aGlzLl9yZWNCb3VuZHNNYXJnaW4gPSB0aGlzLl9wYXJlbnQuX3JlY0JvdW5kc01hcmdpbjtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fb25BZnRlckNhbGNzKSB7XG4gICAgICAgICAgaWYgKHRoaXMuX29uQWZ0ZXJDYWxjcyh0aGlzLmVsZW1lbnQpKSB7XG4gICAgICAgICAgICBpZiAockNvbXBsZXgpIHtcbiAgICAgICAgICAgICAgc3ggPSBNYXRoLm1pbigwLCBiYm94VyAqIHIudGEsIGJib3hXICogci50YSArIGJib3hIICogci50YiwgYmJveEggKiByLnRiKSArIHIucHg7XG4gICAgICAgICAgICAgIGV4ID0gTWF0aC5tYXgoMCwgYmJveFcgKiByLnRhLCBiYm94VyAqIHIudGEgKyBiYm94SCAqIHIudGIsIGJib3hIICogci50YikgKyByLnB4O1xuICAgICAgICAgICAgICBzeSA9IE1hdGgubWluKDAsIGJib3hXICogci50YywgYmJveFcgKiByLnRjICsgYmJveEggKiByLnRkLCBiYm94SCAqIHIudGQpICsgci5weTtcbiAgICAgICAgICAgICAgZXkgPSBNYXRoLm1heCgwLCBiYm94VyAqIHIudGMsIGJib3hXICogci50YyArIGJib3hIICogci50ZCwgYmJveEggKiByLnRkKSArIHIucHk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBzeCA9IHIucHg7XG4gICAgICAgICAgICAgIGV4ID0gci5weCArIHIudGEgKiBiYm94VztcbiAgICAgICAgICAgICAgc3kgPSByLnB5O1xuICAgICAgICAgICAgICBleSA9IHIucHkgKyByLnRkICogYmJveEg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy5fZGltc1Vua25vd24gJiYgKHJDb21wbGV4IHx8IHRoaXMuX2xvY2FsVGEgPCAxIHx8IHRoaXMuX2xvY2FsVGIgPCAxKSkge1xuICAgICAgICAgICAgICBjb25zdCBueCA9IHRoaXMuX3ggKiBwci50YSArIHRoaXMuX3kgKiBwci50YiArIHByLnB4O1xuICAgICAgICAgICAgICBjb25zdCBueSA9IHRoaXMuX3ggKiBwci50YyArIHRoaXMuX3kgKiBwci50ZCArIHByLnB5O1xuICAgICAgICAgICAgICBpZiAobnggPCBzeClcbiAgICAgICAgICAgICAgICBzeCA9IG54O1xuICAgICAgICAgICAgICBpZiAobnkgPCBzeSlcbiAgICAgICAgICAgICAgICBzeSA9IG55O1xuICAgICAgICAgICAgICBpZiAobnggPiBleClcbiAgICAgICAgICAgICAgICBleCA9IG54O1xuICAgICAgICAgICAgICBpZiAobnkgPiBleSlcbiAgICAgICAgICAgICAgICBleSA9IG55O1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fcGFyZW50Ll9vdXRPZkJvdW5kcyA9PT0gMikge1xuICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMjtcbiAgICAgICAgICBpZiAodGhpcy5fd2l0aGluQm91bmRzTWFyZ2luKSB7XG4gICAgICAgICAgICB0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4gPSBmYWxzZTtcbiAgICAgICAgICAgIHRoaXMuZWxlbWVudC5fZGlzYWJsZVdpdGhpbkJvdW5kc01hcmdpbigpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBpZiAocmVjYWxjICYgNikge1xuICAgICAgICAgICAgdGhpcy5fb3V0T2ZCb3VuZHMgPSAwO1xuICAgICAgICAgICAgbGV0IHdpdGhpbk1hcmdpbiA9IHRydWU7XG4gICAgICAgICAgICBpZiAoIXRoaXMuX3JlbmRlclRvVGV4dHVyZUVuYWJsZWQgfHwgIXRoaXMuX3RleHR1cml6ZXIgfHwgIXRoaXMuX3RleHR1cml6ZXIucmVuZGVyT2Zmc2NyZWVuKSB7XG4gICAgICAgICAgICAgIGlmICh0aGlzLl9zY2lzc29yICYmICh0aGlzLl9zY2lzc29yWzJdIDw9IDAgfHwgdGhpcy5fc2Npc3NvclszXSA8PSAwKSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMjtcbiAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fc2Npc3NvclswXSA+IGV4IHx8IHRoaXMuX3NjaXNzb3JbMV0gPiBleSB8fCBzeCA+IHRoaXMuX3NjaXNzb3JbMF0gKyB0aGlzLl9zY2lzc29yWzJdIHx8IHN5ID4gdGhpcy5fc2Npc3NvclsxXSArIHRoaXMuX3NjaXNzb3JbM10pIHtcbiAgICAgICAgICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX291dE9mQm91bmRzKSB7XG4gICAgICAgICAgICAgICAgICBpZiAodGhpcy5fY2xpcHBpbmcgfHwgdGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlIHx8IHRoaXMuX2NsaXBib3ggJiYgKGJib3hXICYmIGJib3hIKSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9vdXRPZkJvdW5kcyA9IDI7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHdpdGhpbk1hcmdpbiA9IHRoaXMuX291dE9mQm91bmRzID09PSAwO1xuICAgICAgICAgICAgICBpZiAoIXdpdGhpbk1hcmdpbikge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9yZWNCb3VuZHNNYXJnaW4pIHtcbiAgICAgICAgICAg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ikge1xuICAgICAgICAgICAgICAgIHRoaXMuX2hhc1VwZGF0ZXMgPSB0cnVlO1xuICAgICAgICAgICAgICAgIGNvbnN0IHJlY2FsYzIgPSB0aGlzLl9yZWNhbGM7XG4gICAgICAgICAgICAgICAgdGhpcy5fcmVjYWxjID0gMDtcbiAgICAgICAgICAgICAgICB0aGlzLmVsZW1lbnQuX2VuYWJsZVdpdGhpbkJvdW5kc01hcmdpbigpO1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9yZWNhbGMpIHtcbiAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnVwZGF0ZSgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0aGlzLl9yZWNhbGMgPSByZWNhbGMyO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuZWxlbWVudC5fZGlzYWJsZVdpdGhpbkJvdW5kc01hcmdpbigpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICBpZiAodGhpcy5fdmlld3BvcnQpIHtcbiAgICAgICAgICAgIHRoaXMuX3ZpZXdwb3J0WzJdID0gYmJveFc7XG4gICAgICAgICAgICB0aGlzLl92aWV3cG9ydFszXSA9IGJib3hIO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl92aWV3cG9ydCA9IFswLCAwLCBiYm94VywgYmJveEhdO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9wUmVjYWxjID0gdGhpcy5fcmVjYWxjICYgMTM1O1xuICAgICAgICB0aGlzLl9yZWNhbGMgPSAwO1xuICAgICAgICB0aGlzLl9oYXNVcGRhdGVzID0gZmFsc2U7XG4gICAgICAgIGlmICh0aGlzLl9vdXRPZkJvdW5kcyA8IDIpIHtcbiAgICAgICAgICBpZiAodGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fd29ybGRDb250ZXh0LmlzSWRlbnRpdHkoKSkge1xuICAgICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gdGhpcy5fd29ybGRDb250ZXh0O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IEVsZW1lbnRDb3JlQ29udGV4dC5JREVOVElUWTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS51cGRhdGUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IHI7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9jaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuW2ldLl9oYXNVcGRhdGVzKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0udXBkYXRlKCk7XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0uX3JlY2FsYyB8PSB0aGlzLl9wUmVjYWxjO1xuICAgICAgICAgICAgICAgIHRoaX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ICB9XG4gICAgICBpZiAodGhpcy5fb3V0T2ZCb3VuZHMgPCAyICYmIHRoaXMuX3JlbmRlckNvbnRleHQuYWxwaGEpIHtcbiAgICAgICAgbGV0IHJlbmRlclN0YXRlID0gdGhpcy5yZW5kZXJTdGF0ZTtcbiAgICAgICAgbGV0IG11c3RSZW5kZXJDaGlsZHJlbiA9IHRydWU7XG4gICAgICAgIGxldCByZW5kZXJUZXh0dXJlSW5mbztcbiAgICAgICAgbGV0IHByZXZSZW5kZXJUZXh0dXJlSW5mbztcbiAgICAgICAgaWYgKHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgIGlmICh0aGlzLl93ID09PSAwIHx8IHRoaXMuX2ggPT09IDApIHtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICB9IGVsc2UgaWYgKCF0aGlzLl90ZXh0dXJpemVyLmhhc1JlbmRlclRleHR1cmUoKSB8fCBoYXNSZW5kZXJVcGRhdGVzID49IDMpIHtcbiAgICAgICAgICAgIHRoaXMuY3R4LnJlbmRlclRvVGV4dHVyZUNvdW50Kys7XG4gICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRTaGFkZXIocmVuZGVyU3RhdGUuZGVmYXVsdFNoYWRlciwgdGhpcyk7XG4gICAgICAgICAgICBwcmV2UmVuZGVyVGV4dHVyZUluZm8gPSByZW5kZXJTdGF0ZS5yZW5kZXJUZXh0dXJlSW5mbztcbiAgICAgICAgICAgIHJlbmRlclRleHR1cmVJbmZvID0ge1xuICAgICAgICAgICAgICBuYXRpdmVUZXh0dXJlOiBudWxsLFxuICAgICAgICAgICAgICBvZmZzZXQ6IDAsXG4gICAgICAgICAgICAgIHc6IHRoaXMuX3csXG4gICAgICAgICAgICAgIGg6IHRoaXMuX2gsXG4gICAgICAgICAgICAgIGVtcHR5OiB0cnVlLFxuICAgICAgICAgICAgICBjbGVhcmVkOiBmYWxzZSxcbiAgICAgICAgICAgICAgaWdub3JlOiBmYWxzZSxcbiAgICAgICAgICAgICAgY2FjaGU6IGZhbHNlXG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKHRoaXMuX3RleHR1cml6ZXIuaGFzUmVzdWx0VGV4dHVyZSgpIHx8ICFyZW5kZXJTdGF0ZS5pc0NhY2hpbmdUZXh0dXJpemVyICYmIGhhc1JlbmRlclVwZGF0ZXMgPCAzKSB7XG4gICAgICAgICAgICAgIHJlbmRlclRleHR1cmVJbmZvLmNhY2hlID0gdHJ1ZTtcbiAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuaXNDYWNoaW5nVGV4dHVyaXplciA9IHRydWU7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoIXRoaXMuX3RleHR1cml6ZXIuaGFzUmVzdWx0VGV4dHVyZSgpKSB7XG4gICAgICAgICAgICAgIHRoaXMuX3RleHR1cml6ZXIucmVsZWFzZVJlbmRlclRleHR1cmUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFJlbmRlclRleHR1cmVJbmZvKHJlbmRlclRleHR1cmVJbmZvKTtcbiAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFNjaXNzb3IobnVsbCk7XG4gICAgICAgICAgICBpZiAodGhpcy5fZGlzcGxheWVkVGV4dHVyZVNvdXJjZSkge1xuICAgICAgICAgICAgICBsZXQgciA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSBFbGVtZW50Q29yZUNvbnRleHQuSURFTlRJVFk7XG4gICAgICAgICAgICAgIHRoaXMucmVuZGVyU3RhdGUuYWRkUXVhZCh0aGlzKTtcbiAgICAgICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IHI7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIG11c3RSZW5kZXJDaGlsZHJlbiA9IGZhbHNlO1xuICAgICAgICAgIH1cbiA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gPSBmYWxzZTtcbiAgICAgICAgICBpZiAobXVzdFJlbmRlckNoaWxkcmVuKSB7XG4gICAgICAgICAgICByZW5kZXJTdGF0ZS5maW5pc2hlZFJlbmRlclRleHR1cmUoKTtcbiAgICAgICAgICAgIHRoaXMuX3RleHR1cml6ZXIuZW1wdHkgPSByZW5kZXJUZXh0dXJlSW5mby5lbXB0eTtcbiAgICAgICAgICAgIGlmIChyZW5kZXJUZXh0dXJlSW5mby5lbXB0eSkge1xuICAgICAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLnJlbGVhc2VSZW5kZXJUZXh0dXJlKCk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHJlbmRlclRleHR1cmVJbmZvLm5hdGl2ZVRleHR1cmUpIHtcbiAgICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci5yZXVzZVRleHR1cmVBc1JlbmRlclRleHR1cmUocmVuZGVyVGV4dHVyZUluZm8ubmF0aXZlVGV4dHVyZSk7XG4gICAgICAgICAgICAgIHJlbmRlclRleHR1cmVJbmZvLmlnbm9yZSA9IHRydWU7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBpZiAodGhpcy5fdGV4dHVyaXplci5yZW5kZXJUZXh0dXJlUmV1c2VkKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci5yZWxlYXNlUmVuZGVyVGV4dHVyZSgpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHJlbmRlclRleHR1cmVJbmZvLm5hdGl2ZVRleHR1cmUgPSB0aGlzLl90ZXh0dXJpemVyLmdldFJlbmRlclRleHR1cmUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFJlbmRlclRleHR1cmVJbmZvKHByZXZSZW5kZXJUZXh0dXJlSW5mbyk7XG4gICAgICAgICAgICB1cGRhdGVSZXN1bHRUZXh0dXJlID0gdHJ1ZTtcbiAgICAgICAgICB9XG4gICAgIC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CB0cnVlKTtcbiAgICAgICAgICAgICAgaWYgKCF0aGlzLl90ZXh0dXJpemVyLmNvbG9yaXplKVxuICAgICAgICAgICAgICAgIHRoaXMuX3Vuc3Rhc2hDb2xvcnMoKTtcbiAgICAgICAgICAgICAgdGhpcy5fdW5zdGFzaFRleENvb3JkcygpO1xuICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRUZXh0dXJpemVyKG51bGwpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAocmVuZGVyVGV4dHVyZUluZm8gJiYgcmVuZGVyVGV4dHVyZUluZm8uY2FjaGUpIHtcbiAgICAgICAgICByZW5kZXJTdGF0ZS5pc0NhY2hpbmdUZXh0dXJpemVyID0gZmFsc2U7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgZ2V0IHpTb3J0KCkge1xuICAgICAgcmV0dXJuIHRoaXMuX3pTb3J0O1xuICAgIH1cbiAgICBzb3J0WkluZGV4ZWRDaGlsZHJlbigpIHtcbiAgICAgIGNvbnN0IG4gPSB0aGlzLl96SW5kZXhlZENoaWxkcmVuLmxlbmd0aDtcbiAgICAgIGxldCBwdHIgPSAwO1xuICAgICAgY29uc3QgYSA9IHRoaXMuX3pJbmRleGVkQ2hpbGRyZW47XG4gICAgICBjb25zdCBiID0gW107XG4gICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICBpZiAoYVtpXS5felBhcmVudCA9PT0gdGhpcykge1xuICAgICAgICAgIGlmIChhW2ldLl96SW5kZXhSZXNvcnQpIHtcbiAgICAgICAgICAgIGIucHVzaChhW2ldKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHB0ciAhPT0gaSkge1xuICAgICAgICAgICAgICBhW3B0cl0gPSBhW2ldO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcHRyKys7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBjb25zdCBtID0gYi5sZW5ndGg7XG4gICAgICBpZiAobSkge1xuICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IG07IGorKykge1xuICAgICAgICAgIGJbal0uX3pJbmRleFJlc29ydCA9IGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIGIuc29ydChFbGVtZW50Q29yZS5zb3J0WkluZGV4ZWRDaGlsZHJlbik7XG4gICAgICAgIGNvbnN0IG4yID0gcHRyO1xuICAgICAgICBpZiAoIW4yKSB7XG4gICAgICAgICAgcHRyID0gMDtcbiAgICAgICAgICBsZXQgaiA9IDA7XG4gICAgICAgICAgZG8ge1xuICAgICAgICAgICAgYVtwdHIrK10gPSBiW2orK107XG4gICAgICAgICAgfSB3aGlsZSAoaiA8IG0pO1xuICAgICAgICAgIGlmIChhLmxlbmd0aCA+IHB0cikge1xuICAgICAgICAgICAgYS5zcGxpY2UocHRyKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgcHRyID0gMDtcbiAgICAgICAgICBsZXQgaSA9IDA7XG4gICAgICAgICAgbGV0IGogPSAwO1xuICAgICAgICAgIGNvbnN0IG1lcmdlUmVzdWx0ID0gW107XG4gICAgICAgICAgZG8ge1xuICAgICAgICAgICAgY29uc3QgdiA9IGFbaV0uX3pJbmRleCA9PT0gYltqXS5fekluZGV4ID8gYVtpXS5fdXBkYXRlVHJlZU9yZGVyIC0gYltqXS5fdXBkYXRlVHJlZU9yZGVyIDogYVtpXS5fekluZGV4IC0gYltqXS5fekluZGV4O1xuICAgICAgICAgICAgY29uc3QgYWRkID0gdiA+IDAgPyBiW2orK10gOiBhW2krK107XG4gICAgICAgICAgICBpZiAocHRyID09PSAwIHx8IG1lcmdlUmVzdWx0W3B0ciAtIDFdICE9PSBhZGQpIHtcbiAgICAgICAgICAgICAgbWVyZ2VSZXN1bHRbcHRyKytdID0gYWRkO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKGkgPj0gbjIpIHtcbiAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgIGNvbnN0IGFkZDIgPSBiW2orK107XG4gICAgICAgICAgICAgICAgaWYgKHB0ciA9PT0gMCB8fCBtZXJnZVJlc3VsdFtwdHIgLSAxXSAhPT0gYWRkMikge1xuICAgICAgICAgICAgICAgICAgbWVyZ2VSZXN1bHRbcHRyKytdID0gYWRkMjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH0gd2hpbGUgKGogPCBtKTtcbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGogPj0gbSkge1xuICAgICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgY29uc3QgYWRkMiA9IGFbaSsrXTtcbiAgICAgICAgICAgICAgICBpZiAocHRyID09PSAwIHx8IG1lcmdlUmVzdWx0W3B0ciAtIDFdICE9PSBhZGQyKSB7XG4gICAgICAgICAgICAgICAgICBtZXJnZVJlc3VsdFtwdHIrK10gPSBhZGQyO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfSB3aGlsZSAoaSA8IG4yKTtcbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSB3aGlsZSAodHJ1ZSk7XG4gICAgICAgICAgdGhpcy5fekluZGV4ZWRDaGlsZHJlbiA9IG1lcmdlUmVzdWx0O1xuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBpZiAoYS5sZW5ndGggPiBwdHIpIHtcbiAgICAgICAgICBhLnNwbGljZShwdHIpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICB0aGlzLl96U29ydCA9IGZhbHNlO1xuICAgIH1cbiAgICBnZXQgbG9jYWxUYSgpIHtcbiAgICAgIHJldHVybiB0aGlzLl9sb2NhbFRhO1xuICAgIH1cbiAgICBnZXQgbG9jYWxUYigpIHtcbiAgICAgIHJldHVybiB0aGlzLl9sb2NhbFRiO1xuICAgIH1cbiAgICBnZXQgbG9jYWxUYygpIHtcbiAgICAgIHJldHVybiB0aGlzLl9sb2NhbFRjO1xuICAgIH1cbiAgICBnZXQgbG9jYWxUZCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl9sb2NhbFRkO1xuICAgIH1cbiAgICBnZXQgZWxlbWVudCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl9lbGVtZW50O1xuICAgIH1cbiAgICBnZXQgcmVuZGVyVXBkYXRlcygpIHtcbiAgICAgIHJldHVybiB0aGlzLl9oYXNSZW5kZXJVcGRhdGVzO1xuICAgIH1cbiAgICBnZXQgdGV4dHVyaXplcigpIHtcbiAgICAgIGlmICghdGhpcy5fdGV4dHVyaXplcikge1xuICAgICAgICB0aGlzLl90ZXh0dXJpemVyID0gbmV3IEVsZW1lbnRUZXh0dXJpemVyKHRoaXMpO1xuICAgICAgfVxuICAgICAgcmV0dXJuIHRoaXMuX3RleHR1cml6ZXI7XG4gICAgfVxuICAgIGdldENvcm5lclBvaW50cygpIHtcbiAgICAgIGxldCB3ID0gdGhpcy5fd29ybGRDb250ZXh0O1xuICAgICAgcmV0dXJuIFtcbiAgICAgICAgdy5weCxcbiAgICAgICAgdy5weSxcbiAgICAgICAgdy5weCArIHRoaXMuX3cgKiB3LnRhLFxuICAgICAgICB3LnB5ICsgdGhpcy5fdyAqIHcudGMsXG4gICAgICAgIHcucHggKyB0aGlzLl93ICogdy50YSArIHRoaXMuX2ggKiB3LnRiLFxuICAgICAgICB3LnB5ICsgdGhpcy5fdyAqIHcudGMgKyB0aGlzLl9oICogdy50ZCxcbiAgICAgICAgdy5weCArIHRoaXMuX2ggKiB3LnRiLFxuICAgICAgICB3LnB5ICsgdGhpcy5faCAqIHcudGRcbiAgICAgIF07XG4gICAgfVxuICAgIGdldFJlbmRlclRleHR1cmVDb29yZHMocmVsWCwgcmVsWSkge1xuICAgICAgbGV0IHIgPSB0aGlzLl9yZW5kZXJDb250ZXh0O1xuICAgICAgcmV0dXJuIFtcbiAgICAgICAgci5weCArIHIudGEgKiByZWxYICsgci50YiAqIHJlbFksXG4gICAgICAgIHIucHkgKyByLnRjICogcmVsWCArIHIudGQgKiByZWxZXG4gICAgICBdO1xuICAgIH1cbiAgICBnZXRBYnNvbHV0ZUNvb3JkcyhyZWxYLCByZWxZKSB7XG4gICAgICBsZXQgdyA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgICByZXR1cm4gW1xuICAgICAgICB3LnB4ICsgdy50YSAqIHJlbFggKyB3LnRiICogcmVsWSxcbiAgICAgICAgdy5weSArIHcudGMgKiByZWxYICsgdy50ZCAqIHJlbFlcbiAgICAgIF07XG4gICAgfVxuICAgIGNvbGxlY3RBdENvb3JkKHgsIHksIGNoaWxkcmVuKSB7XG4gICAgICBpZiAodGhpcy5fcmVuZGVyQ29udGV4dC5hbHBoYSA9PT0gMCkge1xuICAgICAgICByZXR1cm47XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5pbkJvdW5kKHgsIHkpKSB7XG4gICAgICAgIGlmICh0aGlzLl9zY2lzc29yKSB7XG4gICAgICAgICAgaWYgKHRoaXMuaW5TY2lzc29yKCkpIHtcbiAgICAgICAgICAgIGNoaWxkcmVuLnB1c2godGhpcyk7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGNoaWxkcmVuLnB1c2godGhpcyk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICBjb25zdCBqID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoO1xuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGo7IGkrKykge1xuICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLmNvbGxlY3RBdENvb3JkKHgsIHksIGNoaWxkcmVuKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIGNoaWxkcmVuLnNvcnQoRWxlbWVudENvcmUuc29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AgIGNvbnN0IGxpc3RlbmVycyA9IHRoaXMuX2V2ZW50TGlzdGVuZXJzW25hbWVdO1xuICAgICAgICAgICAgZm9yIChjb25zdCBsIG9mIGxpc3RlbmVycykge1xuICAgICAgICAgICAgICBpZiAobCA9PT0gbGlzdGVuZXIgfHwgbC5fX29yaWdpbmFsRnVuYyA9PSBsaXN0ZW5lcikge1xuICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdID09PSBsaXN0ZW5lciB8fCB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdLl9fb3JpZ2luYWxGdW5jID09PSBsaXN0ZW5lcikge1xuICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuICAgIG9mZihuYW1lLCBsaXN0ZW5lcikge1xuICAgICAgaWYgKHRoaXMuX2hhc0V2ZW50TGlzdGVuZXJzKSB7XG4gICAgICAgIGNvbnN0IGN1cnJlbnQgPSB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdO1xuICAgICAgICBpZiAoY3VycmVudCkge1xuICAgICAgICAgIGlmIChjdXJyZW50ID09PSBFdmVudEVtaXR0ZXIuY29tYmluZXIpIHtcbiAgICAgICAgICAgIGNvbnN0IGxpc3RlbmVycyA9IHRoaXMuX2V2ZW50TGlzdGVuZXJzW25hbWVdO1xuICAgICAgICAgICAgbGV0IGluZGV4ID0gbGlzdGVuZXJzLmluZGV4T2YobGlzdGVuZXIpO1xuICAgICAgICAgICAgaWYgKGluZGV4ID49IDApIHtcbiAgICAgICAgICAgICAgbGlzdGVuZXJzLnNwbGljZShpbmRleCwgMSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpbmRleCA9IGxpc3RlbmVycy5tYXA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291bnQoKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICByZW1vdmVFbGVtZW50KHYpIHtcbiAgICAgIGlmICh0aGlzLmVsZW1lbnRzLmRlbGV0ZSh2KSkge1xuICAgICAgICBpZiAodGhpcy5lbGVtZW50cy5zaXplID09PSAwKSB7XG4gICAgICAgICAgaWYgKHRoaXMuX3NvdXJjZSkge1xuICAgICAgICAgICAgdGhpcy5fc291cmNlLnJlbW92ZVRleHR1cmUodGhpcyk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmICh2LmFjdGl2ZSkge1xuICAgICAgICAgIHRoaXMuZGVjQWN0aXZlQ291bnQoKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBpbmNBY3RpdmVDb3VudCgpIHtcbiAgICAgIGNvbnN0IHNvdXJjZSA9IHRoaXMuc291cmNlO1xuICAgICAgaWYgKHNvdXJjZSkge1xuICAgICAgICB0aGlzLl9jaGVja0Zvck5ld2VyUmV1c2FibGVUZXh0dXJlU291cmNlKCk7XG4gICAgICB9XG4gICAgICB0aGlzLl9hY3RpdmVDb3VudCsrO1xuICAgICAgaWYgKHRoaXMuX2FjdGl2ZUNvdW50ID09PSAxKSB7XG4gICAgICAgIHRoaXMuYmVjb21lc1VzZWQoKTtcbiAgICAgIH1cbiAgICB9XG4gICAgZGVjQWN0aXZlQ291bnQoKSB7XG4gICAgICB0aGlzLnNvdXJjZTtcbiAgICAgIHRoaXMuX2FjdGl2ZUNvdW50LS07XG4gICAgICBpZiAoIXRoaXMuX2FjdGl2ZUNvdW50KSB7XG4gICAgICAgIHRoaXMuYmVjb21lc1VudXNlZCgpO1xuICAgICAgfVxuICAgIH1cbiAgICBiZWNvbWVzVXNlZCgpIHtcbiAgICAgIGlmICh0aGlzLnNvdXJjZSkge1xuICAgICAgICB0aGlzLnNvdXJjZS5pbmNBY3RpdmVUZXh0dXJlQ291bnQoKTtcbiAgICAgIH1cbiAgICB9XG4gICAg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RoaXMubWFuYWdlci5mcmVlVGV4dHVyZVNvdXJjZShvbGRTb3VyY2UpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAobmV3U291cmNlKSB7XG4gICAgICAgICAgbmV3U291cmNlLmFkZFRleHR1cmUodGhpcyk7XG4gICAgICAgICAgaWYgKHRoaXMuX2FjdGl2ZUNvdW50KSB7XG4gICAgICAgICAgICBuZXdTb3VyY2UuaW5jQWN0aXZlVGV4dHVyZUNvdW50KCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5pc1VzZWQoKSkge1xuICAgICAgICBpZiAobmV3U291cmNlKSB7XG4gICAgICAgICAgaWYgKG5ld1NvdXJjZS5pc0xvYWRlZCgpKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fcmVzaXplTW9kZSkge1xuICAgICAgICAgICAgICB0aGlzLl9hcHBseVJlc2l6ZU1vZGUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuZWxlbWVudHMuZm9yRWFjaCgoZWxlbWVudCkgPT4ge1xuICAgICAgICAgICAgICBpZiAoZWxlbWVudC5hY3RpdmUpIHtcbiAgICAgICAgICAgICAgICBlbGVtZW50Ll9zZXREaXNwbGF5ZWRUZXh0dXJlKHRoaXMpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29uc3QgbG9hZEVycm9yID0gbmV3U291cmNlLmxvYWRFcnJvcjtcbiAgICAgICAgICAgIGlmIChsb2FkRXJyb3IpIHtcbiAgICAgICAgICAgICAgdGhpcy5lbGVtZW50cy5mb3JFYWNoKChlbGVtZW50KSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKGVsZW1lbnQuYWN0aXZlKSB7XG4gICAgICAgICAgICAgICAgICBlbGVtZW50Lm9uVGV4dHVyZVNvdXJjZUxvYWRFcnJvcihsb2FkRXJyb3IpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuZWxlbWVudHMuZm9yRWFjaCgoZWxlbWVudCkgPT4ge1xuICAgICAgICAgICAgaWYgKGVsZW1lbnQuYWN0aXZlKSB7XG4gICAgICAgICAgICAgIGVsZW1lbnQuX3NldERpc3BsYXllZFRleHR1cmUobnVsbCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgbG9hZCgpIHtcbiAgICAgIGlmICh0aGlzLnNvdXJjZSkge1xuICAgICAgICBpZiAoIXRoaXMuaXNMb2FkZWQoKSkge1xuICAgICAgICAgIHRoaXMuc291cmNlLmxvYWQodHJ1ZSk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgaXNMb2FkZWQoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fc291cmNlICYmIHRoaXMuX3NvdXJjZS5pc0xvYWRlZCgpO1xuICAgIH1cbiAgICBnZXQgbG9hZEVycm9yKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX3NvdXJjZSAmJiB0aGlzLl9zb3VyY2UubG9hZEVycm9yO1xuICAgIH1cbiAgICBmcmVlKCkge1xuICAgICAgaWYgKHRoaXMuX3NvdXJjZSkge1xuICAgICAgICB0aGlzLl9zb3VyY2UuZnJlZSgpO1xuICAgICAgfVxuICAgIH1cbiAgICBzZXQgcmVzaXplTW9kZSh7IHR5cGUgPSBcImNvdmVyXCIsIHcgPSAwLCBoID0gMCwgY2xpcFggPSAwLjUsIGNsaXBZID0gMC41IH0pIHtcbiAgICAgIHRoaXMuX3Jlc2l6ZU1vZGUgPSB7IHR5cGUsIHcsIGgsIGNsaXBYLCBjbGlwWSB9O1xuICAgICAgaWYgKHRoaXMuaXNMb2FkZWQoKSkge1xuICAgICAgICB0aG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tcbiAgICAgICAgfVxuICAgICAgICBsZXQgaSwgbiA9IGxpbmVzLmxlbmd0aDtcbiAgICAgICAgbGV0IGogPSAwO1xuICAgICAgICBsZXQgbSA9IGxpbmVzSW5mby5uLmxlbmd0aDtcbiAgICAgICAgZm9yIChpID0gdGhpcy5fc2V0dGluZ3MubWF4TGluZXM7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICBvdGhlckxpbmVzW2pdICs9IChvdGhlckxpbmVzW2pdID8gXCIgXCIgOiBcIlwiKSArIGxpbmVzW2ldO1xuICAgICAgICAgIGlmIChpICsgMSA8IG0gJiYgbGluZXNJbmZvLm5baSArIDFdKSB7XG4gICAgICAgICAgICBqKys7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJlbmRlckluZm8ucmVtYWluaW5nVGV4dCA9IG90aGVyTGluZXMuam9pbihcIlxcblwiKTtcbiAgICAgICAgcmVuZGVySW5mby5tb3JlVGV4dExpbmVzID0gdHJ1ZTtcbiAgICAgICAgbGluZXMgPSB1c2VkTGluZXM7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZW5kZXJJbmZvLm1vcmVUZXh0TGluZXMgPSBmYWxzZTtcbiAgICAgICAgcmVuZGVySW5mby5yZW1haW5pbmdUZXh0ID0gXCJcIjtcbiAgICAgIH1cbiAgICAgIGxldCBtYXhMaW5lV2lkdGggPSAwO1xuICAgICAgbGV0IGxpbmVXaWR0aHMgPSBbXTtcbiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGluZXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgbGV0IGxpbmVXaWR0aCA9IHRoaXMubWVhc3VyZVRleHQobGluZXNbaV0sIGxldHRlclNwYWNpbmcpICsgKGkgPT09IDAgPyB0ZXh0SW5kZW50IDogMCk7XG4gICAgICAgIGxpbmVXaWR0aHMucHVzaChsaW5lV2lkdGgpO1xuICAgICAgICBtYXhMaW5lV2lkdGggPSBNYXRoLm1heChtYXhMaW5lV2lkdGg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uICAgICAgdGhpcy5fc2V0dGluZ3MgPSBzZXR0aW5ncztcbiAgICB9XG4gICAgZ2V0UHJlY2lzaW9uKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX3NldHRpbmdzLnByZWNpc2lvbjtcbiAgICB9XG4gICAgc2V0Rm9udFByb3BlcnRpZXMoKSB7XG4gICAgICBjb25zdCBmb250ID0gZ2V0Rm9udFNldHRpbmcoXG4gICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRGYWNlLFxuICAgICAgICB0aGlzLl9zZXR0aW5ncy5mb250U3R5bGUsXG4gICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRTaXplLFxuICAgICAgICB0aGlzLmdldFByZWNpc2lvbigpLFxuICAgICAgICB0aGlzLl9zdGFnZS5nZXRPcHRpb24oXCJkZWZhdWx0Rm9udEZhY2VcIilcbiAgICAgICk7XG4gICAgICB0aGlzLl9jb250ZXh0LmZvbnQgPSBmb250O1xuICAgICAgdGhpcy5fY29udGV4dC50ZXh0QmFzZWxpbmUgPSB0aGlzLl9zZXR0aW5ncy50ZXh0QmFzZWxpbmU7XG4gICAgICByZXR1cm4gZm9udDtcbiAgICB9XG4gICAgX2xvYWQoKSB7XG4gICAgICBpZiAoVXRpbHMkMS5pc1dlYiAmJiBkb2N1bWVudC5mb250cykge1xuICAgICAgICBjb25zdCBmb250U2V0dGluZyA9IGdldEZvbnRTZXR0aW5nKFxuICAgICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRGYWNlLFxuICAgICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRTdHlsZSxcbiAgICAgICAgICB0aGlzLl9zZXR0aW5ncy5mb250U2l6ZSxcbiAgICAgICAgICB0aGlzLmdldFByZWNpc2lvbigpLFxuICAgICAgICAgIHRoaXMuX3N0YWdlLmdldE9wdGlvbihcImRlZmF1bHRGb250RmFjZVwiKVxuICAgICAgICApO1xuICAgICAgICB0cnkge1xuICAgICAgICAgIGlmICghZG9jdW1lbnQuZm9udHMuY2hlY2soZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpKSB7XG4gICAgICAgICAgICByZXR1cm4gZG9jdW1lbnQuZm9udHMubG9hZChmb250U2V0dGluZywgdGhpcy5fc2V0dGluZ3MudGV4dCkuY2F0Y2goKGVycikgPT4ge1xuICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJGb250IGxvYWQgZXJyb3JcIiwgZXJyLCBmb250U2V0dGluZyk7XG4gICAgICAgICAgICB9KS50aGVuKCgpID0+IHtcbiAgICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5mb250cy5jaGVjayhmb250U2V0dGluZywgdGhpcy5fc2V0dGluZ3MudGV4dCkpIHtcbiAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJGb250IG5vdCBmb3VuZFwiLCBmb250U2V0dGluZyk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICAgIGNvbnNvbGUud2FybihcIkNhbid0IGNoZWNrIGZvbnQgbG9hZGluZyBmb3IgXCIgKyBmb250U2V0dGluZyk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgZHJhdygpIHtcbiAgICAgIGNvbnN0IGxvYWRQcm9taXNlID0gdGhpcy5fbG9hZCgpO1xuICAgICAgaWYgKCFsb2FkUHJvbWlzZSkge1xuICAgICAgICByZXR1cm4gVXRpbHMkMS5pc1NwYXJrID8gdGhpcy5fc3RhZ2UucGxhdGZvcm0uZHJhd1RleHQodGhpcykgOiB0aGlzLl9kcmF3KCk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gbG9hZFByb21pc2UudGhlbigoKSA9PiB7XG4gICAgICAgICAgcmV0dXJuIFV0aWxzJDEuaXNTcGFyayA/IHRoaXMuX3N0YWdlLnBsYXRmb3JtLmRyYXdUZXh0KHRoaXMpIDogdGhpcy5fZHJhdygpO1xuICA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7XG4gICAgICAgICAgY29udGludWU7XG4gICAgICAgIH1cbiAgICAgICAgdC54ID0geDtcbiAgICAgICAgeCArPSB0LndpZHRoO1xuICAgICAgfVxuICAgICAgcmVuZGVySW5mby5saW5lTnVtID0gbGluZU5vICsgMTtcbiAgICAgIGlmICh0aGlzLl9zZXR0aW5ncy5oKSB7XG4gICAgICAgIHJlbmRlckluZm8uaCA9IHRoaXMuX3NldHRpbmdzLmg7XG4gICAgICB9IGVsc2UgaWYgKHJlbmRlckluZm8ubWF4TGluZXMgJiYgcmVuZGVySW5mby5tYXhMaW5lcyA8IHJlbmRlckluZm8ubGluZU51bSkge1xuICAgICAgICByZW5kZXJJbmZvLmggPSByZW5kZXJJbmZvLm1heExpbmVzICogcmVuZGVySW5mby5saW5lSGVpZ2h0ICsgZm9udFNpemUgLyAyO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcmVuZGVySW5mby5oID0gcmVuZGVySW5mby5saW5lTnVtICogcmVuZGVySW5mby5saW5lSGVpZ2h0ICsgZm9udFNpemUgLyAyO1xuICAgICAgfVxuICAgICAgY29uc3QgYmFzZWxpbmVPZmZzZXRJblB4ID0gcmVuZGVySW5mby5mb250QmFzZWxpbmVSYXRpbyAqIHJlbmRlckluZm8uZm9udFNpemU7XG4gICAgICBsZXQgdmFPZmZzZXQgPSAwO1xuICAgICAgaWYgKHJlbmRlckluZm8udmVydGljYWxBbGlnbiA9PSBcInRvcFwiICYmIHRoaXMuX2NvbnRleHQudGV4dEJhc2VsaW5lID09IFwiYWxwaGFiZXRpY1wiKSB7XG4gICAgICAgIHZhT2Zmc2V0ID0gLWJhc2VsaW5lT2Zmc2V0SW5QeDtcbiAgICAgIH0gZWxzZSBpZiAocmVuZGVySW5mby52ZXJ0aWNhbEFsaWduID09IFwibWlkZGxlXCIpIHtcbiAgICAgICAgdmFPZmZzZXQgPSAocmVuZGVySW5mby5saW5lSGVpZ2h0IC0gcmVuZGVySW5mby5mb250U2l6ZSAtIGJhc2VsaW5lT2Zmc2V0SW5QeCkgLyAyO1xuICAgICAgfSBlbHNlIGlmICh0aGlzLl9zZXR0aW5ncy52ZXJ0aWNhbEFsaWduID09IFwiYm90dG9tXCIpIHtcbiAgICAgICAgdmFPZmZzZXQgPSByZW5kZXJJbmZvLmxpbmVIZWlnaHQgLSByZW5kZXJJbmZvLmZvbnRTaXplO1xuICAgICAgfVxuICAgICAgcmVuZGVySW5mby5saW5lcyA9IFtdO1xuICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCByZW5kZXJJbmZvLmxpbmVOdW07IGkrKykge1xuICAgICAgICByZW5kZXJJbmZvLmxpbmVzW2ldID0ge1xuICAgICAgICAgIHdpZHRoOiAwLFxuICAgICAgICAgIHg6IDAsXG4gICAgICAgICAgeTogcmVuZGVySW5mby5saW5lSGVpZ2h0ICogaSArIHZhT2Zmc2V0LFxuICAgICAgICAgIHRleHQ6IFtdXG4gICAgICAgIH07XG4gICAgICB9XG4gICAgICBmb3IgKGxldCB0IG9mIHRleHQpIHtcbiAgICAgICAgcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10udGV4dC5wdXNoKHQpO1xuICAgICAgfVxuICAgICAgZm9yIChjb25zdCBsIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgICAgaWYgKGwudGV4dC5sZW5ndGggPT0gMCkge1xuICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICB9XG4gICAgICAgIGNvbnN0IGZpcnN0V29yZCA9IGwudGV4dFswXS50ZXh0O1xuICAgICAgICBjb25zdCBsYXN0V29yZCA9IGwudGV4dFtsLnRleHQubGVuZ3RoIC0gMV0udGV4dDtcbiAgICAgICAgaWYgKGZpcnN0V29yZCA9PSBcIlxcblwiKSB7XG4gICAgICAgICAgbC50ZXh0LnNoaWZ0KCk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGlzU3BhY2UobGFzdFdvcmQpIHx8IGxhc3RXb3JkID09IFwiXFxuXCIpIHtcbiAgICAgICAgICBsLnRleH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y54ID0gMDtcbiAgICAgICAgICBsYXN0TGluZVRleHQucHVzaChzKTtcbiAgICAgICAgfVxuICAgICAgICBjb25zdCBzcGwgPSBzdWZmaXgubGVuZ3RoICsgMTtcbiAgICAgICAgbGV0IF93ID0gbGFzdExpbmVUZXh0LnJlZHVjZSgoYWNjLCB0KSA9PiBhY2MgKyB0LndpZHRoLCAwKTtcbiAgICAgICAgd2hpbGUgKF93ID4gcmVuZGVySW5mby53aWR0aCB8fCBpc1NwYWNlKGxhc3RMaW5lVGV4dFtsYXN0TGluZVRleHQubGVuZ3RoIC0gc3BsXS50ZXh0KSkge1xuICAgICAgICAgIGxhc3RMaW5lVGV4dC5zcGxpY2UobGFzdExpbmVUZXh0Lmxlbmd0aCAtIHNwbCwgMSk7XG4gICAgICAgICAgX3cgPSBsYXN0TGluZVRleHQucmVkdWNlKChhY2MsIHQpID0+IGFjYyArIHQud2lkdGgsIDApO1xuICAgICAgICAgIGlmIChsYXN0TGluZVRleHQubGVuZ3RoIDwgc3BsKSB7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5hbGlnbkxpbmUobGFzdExpbmVUZXh0LCBsYXN0TGluZVRleHRbMF0ueCk7XG4gICAgICAgIHJlbmRlckluZm8ubGluZXNbaW5kZXhdLnRleHQgPSBsYXN0TGluZVRleHQ7XG4gICAgICAgIHJlbmRlckluZm8ubGluZXNbaW5kZXhdLndpZHRoID0gX3c7XG4gICAgICB9XG4gICAgICBpZiAocmVuZGVySW5mby50ZXh0QWxpZ24gPT0gXCJjZW50ZXJcIikge1xuICAgICAgICBmb3IgKGxldCBsIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgICAgICBsLnggPSAocmVuZGVySW5mby53aWR0aCAtIGwud2lkdGggLSBwYWRkaW5nTGVmdCkgLyAyO1xuICAgICAgICB9XG4gICAgICB9IGVsc2UgaWYgKHJlbmRlckluZm8udGV4dEFsaWduID09IFwicmln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29udGV4dC5zaGFkb3dDb2xvciA9IFN0YWdlVXRpbHMuZ2V0UmdiYVN0cmluZyh0aGlzLl9zZXR0aW5ncy5zaGFkb3dDb2xvcik7XG4gICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93T2Zmc2V0WCA9IHRoaXMuX3NldHRpbmdzLnNoYWRvd09mZnNldFggKiBwcmVjaXNpb247XG4gICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93T2Zmc2V0WSA9IHRoaXMuX3NldHRpbmdzLnNoYWRvd09mZnNldFkgKiBwcmVjaXNpb247XG4gICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93Qmx1ciA9IHRoaXMuX3NldHRpbmdzLnNoYWRvd0JsdXIgKiBwcmVjaXNpb247XG4gICAgICB9XG4gICAgICBjb25zdCBkZWZhdWx0Q29sb3IgPSBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcodGhpcy5fc2V0dGluZ3MudGV4dENvbG9yKTtcbiAgICAgIGxldCBjdXJyZW50Q29sb3IgPSBkZWZhdWx0Q29sb3I7XG4gICAgICB0aGlzLl9jb250ZXh0LmZpbGxTdHlsZSA9IGRlZmF1bHRDb2xvcjtcbiAgICAgIGZvciAoY29uc3QgbGluZSBvZiByZW5kZXJJbmZvLmxpbmVzKSB7XG4gICAgICAgIGZvciAoY29uc3QgdCBvZiBsaW5lLnRleHQpIHtcbiAgICAgICAgICBsZXQgbHggPSAwO1xuICAgICAgICAgIGlmICh0LnRleHQgPT0gXCJcXG5cIikge1xuICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChyZW5kZXJJbmZvLm1heExpbmVzICYmIHQubGluZU5vID49IHJlbmRlckluZm8ubWF4TGluZXMpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAodC5jb2xvciAhPSBjdXJyZW50Q29sb3IpIHtcbiAgICAgICAgICAgIGN1cnJlbnRDb2xvciA9IHQuY29sb3I7XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LmZpbGxTdHlsZSA9IGN1cnJlbnRDb2xvcjtcbiAgICAgICAgICB9XG4gICAgICAgICAgdGhpcy5fY29udGV4dC5mb250ID0gdC5mb250U3R5bGU7XG4gICAgICAgICAgaWYgKHQubGV0dGVycykge1xuICAgICAgICAgICAgZm9yIChsZXQgbCBvZiB0LmxldHRlcnMpIHtcbiAgICAgICAgICAgICAgY29uc3QgX3ggPSByZW5kZXJJbmZvLmxpbmVzW3QubGluZU5vXS54ICsgdC54ICsgbHg7XG4gICAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuZmlsbFRleHQobC50ZXh0LCBfeCwgcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10ueSArIHJlbmRlckluZm8uZm9udFNpemUpO1xuICAgICAgICAgICAgICBseCArPSBsLndpZHRoO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb25zdCBfeCA9IHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnggKyB0Lng7XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LmZpbGxUZXh0KHQudGV4dCwgX3gsIHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnkgKyByZW5kZXJJbmZvLmZvbnRTaXplKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmIChwcmV2U2hhZG93U2V0dGluZ3MpIHtcbiAgICAgICAgdGhpcy5fY29udGV4dC5zaGFkb3dDb2xvciA9IHByZXZTaGFkb3dTZXR0aW5nc1swXTtcbiAgICAgICAgdGhpcy5fY29udGV4dC5zaGFkb3dPZmZzZXRYID0gcHJldlNoYWRvd1NldHRpbmdzWzFdO1xuICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd09mZnNldFkgPSBwcmV2U2hhZG93U2V0dGluZ3NbMl07XG4gICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93Q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DA7XG4gICAgICBjb25zdCBjb2xvclJlZ2V4cCA9IC88Y29sb3I9KDBbeFhdWzAtOWEtZkEtRl17OH0pPi87XG4gICAgICByZXR1cm4gdG9rZW5zLm1hcCgodCkgPT4ge1xuICAgICAgICBpZiAodCA9PSBcIjxpPlwiKSB7XG4gICAgICAgICAgaXRhbGljICs9IDE7XG4gICAgICAgICAgdCA9IFwiXCI7XG4gICAgICAgIH0gZWxzZSBpZiAodCA9PSBcIjwvaT5cIiAmJiBpdGFsaWMgPiAwKSB7XG4gICAgICAgICAgaXRhbGljIC09IDE7XG4gICAgICAgICAgdCA9IFwiXCI7XG4gICAgICAgIH0gZWxzZSBpZiAodCA9PSBcIjxiPlwiKSB7XG4gICAgICAgICAgYm9sZCArPSAxO1xuICAgICAgICAgIHQgPSBcIlwiO1xuICAgICAgICB9IGVsc2UgaWYgKHQgPT0gXCI8L2I+XCIgJiYgYm9sZCA+IDApIHtcbiAgICAgICAgICBib2xkIC09IDE7XG4gICAgICAgICAgdCA9IFwiXCI7XG4gICAgICAgIH0gZWxzZSBpZiAodCA9PSBcIjwvY29sb3I+XCIpIHtcbiAgICAgICAgICBpZiAoY29sb3JTdGFjay5sZW5ndGggPiAxKSB7XG4gICAgICAgICAgICBjb2xvciAtPSAxO1xuICAgICAgICAgICAgY29sb3JTdGFjay5wb3AoKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgdCA9IFwiXCI7XG4gICAgICAgIH0gZWxzZSBpZiAoY29sb3JSZWdleHAudGVzdCh0KSkge1xuICAgICAgICAgIGNvbnN0IG1hdGNoZWQgPSBjb2xvclJlZ2V4cC5leGVjKHQpO1xuICAgICAgICAgIGNvbG9yU3RhY2sucHVzaChcbiAgICAgICAgICAgIFN0YWdlVXRpbHMuZ2V0UmdiYVN0cmluZyhwYXJzZUludChtYXRjaGVkWzFdKSlcbiAgICAgICAgICApO1xuICAgICAgICAgIGNvbG9yICs9IDE7XG4gICAgICAgICAgdCA9IFwiXCI7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICB0ZXh0OiB0LFxuICAgICAgICAgIGl0YWxpYyxcbiAgICAgICAgICBib2xkLFxuICAgICAgICAgIGNvbG9yOiBjb2xvclN0YWNrW2NvbG9yXVxuICAgICAgICB9O1xuICAgICAgfSkuZmlsdGVyKChvKSA9PiBvLnRleHQgIT0gXCJcIik7XG4gICAgfVxuICAgIGFwcGx5Rm9udFN0eWxlKHdvcmQsIGJhc2VGb250KSB7XG4gICAgICBsZXQgZm9udCA9IGJhc2VGb250O1xuICAgICAgaWYgKHdvcmQuYm9sZCkge1xuICAgICAgICBmb250ID0gXCJib2xkIFwiICsgZm9udDtcbiAgICAgIH1cbiAgICAgIGlmICh3b3JkLml0YWxpYykge1xuICAgICAgICBmb250ID0gXCJpdGFsaWMgXCIgKyBmb250O1xuICAgICAgfVxuICAgICAgdGhpcy5fY29udGV4dC5mb250ID0gZm9udDtcbiAgICAgIHdvcmQuZm9udFN0eWxlID0gZm9udDtcbiAgICB9XG4gICAgcmVzZXRGb250U3R5bGUoYmFzZUZvbnQpIHtcbiAgICAgIHRoaXMuX2NvbnRleHQuZm9udCA9IGJhc2VGb250O1xuICAgIH1cbiAgICBtZWFzdXJlKHBhcnNlZCwgbGV0dGVyU3BhY2luZyA9IDAsIGJhc2VGb250KSB7XG4gICAgICBmb3IgKGNvbnN0IHAgb2YgcGFyc2VkKSB7XG4gICAgICAgIHRoaXMuYXBwbHlGb250U3R5bGUocCwgYmFzZUZvbnQpO1xuICAgICAgICBwLndpZHRoID0gdGhpcy5tZWFzdXJlVGV4dChwLnRleHQsIGxldHRlclNwYWNpbmcpO1xuICAgICAgICBpZiAobGV0dGVyU3BhY2luZyA+IDApIHtcbiAgICAgICAgICBwLmxldHRlcnMgPSBwLnRleHQuc3BsaXQoXCJcIikubWFwKChsKSA9PiB7XG4gICAgICAgICAgICByZXR1cm4geyB0ZXh0OiBsIH07XG4gICAgICAgICAgfSk7XG4gICAgICAgICAgZm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iAgICAgICAgICBpZiAodG90YWxXaWR0aCArIGwud2lkdGggPj0gd2lkdGgpIHtcbiAgICAgICAgICAgIHBhcnRzLnB1c2goeyAuLi53b3JkIH0pO1xuICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0udGV4dCA9IHRleHQuc2xpY2UoMCwgYnJlYWtJbmRleCk7XG4gICAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS53aWR0aCA9IHRvdGFsV2lkdGg7XG4gICAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS5sZXR0ZXJzID0gbGV0dGVycztcbiAgICAgICAgICAgIHRleHQgPSB0ZXh0LnNsaWNlKGJyZWFrSW5kZXgpO1xuICAgICAgICAgICAgdG90YWxXaWR0aCA9IDA7XG4gICAgICAgICAgICBsZXR0ZXJzID0gW107XG4gICAgICAgICAgICBicmVha0luZGV4ID0gMDtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYnJlYWtJbmRleCArPSAxO1xuICAgICAgICAgICAgbGV0dGVycy5wdXNoKGwpO1xuICAgICAgICAgICAgdG90YWxXaWR0aCArPSBsLndpZHRoO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAodG90YWxXaWR0aCA+IDApIHtcbiAgICAgICAgICBwYXJ0cy5wdXNoKHsgLi4ud29yZCB9KTtcbiAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS50ZXh0ID0gdGV4dC5zbGljZSgwLCBicmVha0luZGV4KTtcbiAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS53aWR0aCA9IHRvdGFsV2lkdGg7XG4gICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ubGV0dGVycyA9IGxldHRlcnM7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHJldHVybiBwYXJ0cztcbiAgICB9XG4gICAgYWxpZ25MaW5lKHBhcnNlZCwg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kdCkge1xuICAgICAgaWYgKCF0aGlzLmlzQXR0YWNoZWQoKSkge1xuICAgICAgICB0aGlzLl9wID0gMTtcbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLnAgPCAxKSB7XG4gICAgICAgIGlmICh0aGlzLmRlbGF5TGVmdCA+IDApIHtcbiAgICAgICAgICB0aGlzLl9kZWxheUxlZnQgLT0gZHQ7XG4gICAgICAgICAgaWYgKHRoaXMuZGVsYXlMZWZ0IDwgMCkge1xuICAgICAgICAgICAgZHQgPSAtdGhpcy5kZWxheUxlZnQ7XG4gICAgICAgICAgICB0aGlzLl9kZWxheUxlZnQgPSAwO1xuICAgICAgICAgICAgdGhpcy5lbWl0KFwiZGVsYXlFbmRcIik7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX3NldHRpbmdzLmR1cmF0aW9uID09IDApIHtcbiAgICAgICAgICB0aGlzLl9wID0gMTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB0aGlzLl9wICs9IGR0IC8gdGhpcy5fc2V0dGluZ3MuZHVyYXRpb247XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX3AgPj0gMSkge1xuICAgICAgICAgIHRoaXMuX3AgPSAxO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICB0aGlzLl91cGRhdGVEcmF3VmFsdWUoKTtcbiAgICAgIHRoaXMuaW52b2tlTGlzdGVuZXJzKCk7XG4gICAgfVxuICAgIGludm9rZUxpc3RlbmVycygpIHtcbiAgICAgIHRoaXMuZW1pdChcInByb2dyZXNzXCIsIHRoaXMucCk7XG4gICAgICBpZiAodGhpcy5wID09PSAxKSB7XG4gICAgICAgIHRoaXMuZW1pdChcImZpbmlzaFwiKTtcbiAgICAgIH1cbiAgICB9XG4gICAgdXBkYXRlVGFyZ2V0VmFsdWUodGFyZ2V0VmFsdWUpIHtcbiAgIC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cbiAgICAgICAgICAgIGNvbnN0IGZyb21JbmRleCA9IGN1cnJlbnRJbmRleDtcbiAgICAgICAgICAgIGlmIChmcm9tSW5kZXggIT09IGluZGV4KSB7XG4gICAgICAgICAgICAgIHRoaXMuX2l0ZW1zLnNwbGljZShmcm9tSW5kZXgsIDEpO1xuICAgICAgICAgICAgICB0aGlzLl9pdGVtcy5zcGxpY2UoaW5kZXgsIDAsIGl0ZW0pO1xuICAgICAgICAgICAgICB0aGlzLm9uTW92ZShpdGVtLCBmcm9tSW5kZXgsIGluZGV4KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKGluZGV4IDwgdGhpcy5faXRlbXMubGVuZ3RoKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5faXRlbXNbaW5kZXhdLnJlZikge1xuICAgICAgICAgICAgICB0aGlzLl9yZWZzW3RoaXMuX2l0ZW1zW2luZGV4XS5yZWZdID0gdm9pZCAwO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBjb25zdCBwcmV2SXRlbSA9IHRoaXMuX2l0ZW1zW2luZGV4XTtcbiAgICAgICAgICB0aGlzLl9pdGVtc1tpbmRleF0gPSBpdGVtO1xuICAgICAgICAgIGlmIChpdGVtLnJlZikge1xuICAgICAgICAgICAgdGhpcy5fcmVmc1tpdGVtLnJlZl0gPSBpdGVtO1xuICAgICAgICAgIH1cbiAgICAgICAgICB0aGlzLm9uU2V0KGl0ZW0sIGluZGV4LCBwcmV2SXRlbSk7XG4gICAgICAgIH1cbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHRocm93IG5ldyBFcnJvcihcInNldEF0OiBUaGUgaW5kZXggXCIgKyBpbmRleCArIFwiIGlzIG91dCBvZiBib3VuZHMgXCIgKyB0aGlzLl9pdGVtcy5sZW5ndGgpO1xuICAgICAgfVxuICAgIH1cbiAgICBnZXRBdChpbmRleCkge1xuICAgICAgcmV0dX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gdGhpcy5vblN5bmMocHJldiwgW10sIFtdKTtcbiAgICAgIH1cbiAgICB9XG4gICAgYShvKSB7XG4gICAgICBpZiAoVXRpbHMkMS5pc09iamVjdExpdGVyYWwobykpIHtcbiAgICAgICAgbGV0IGMgPSB0aGlzLmNyZWF0ZUl0ZW0obyk7XG4gICAgICAgIGMucGF0Y2gobyk7XG4gICAgICAgIHRoaXMuYWRkKGMpO1xuICAgICAgICByZXR1cm4gYztcbiAgICAgIH0gZWxzZSBpZiAoQXJyYXkuaXNBcnJheShvKSkge1xuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IG8ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgdGhpcy5hKG9baV0pO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBudWxsO1xuICAgICAgfSBlbHNlIGlmICh0aGlzLmlzSXRlbShvKSkge1xuICAgICAgICB0aGlzLmFkZChvKTtcbiAgICAgICAgcmV0dXJuIG87XG4gICAgICB9XG4gICAgfVxuICAgIGdldCBsZW5ndGgoKSB7XG4gICAgICByZXR1cm4gdGhpcy5faXRlbXMubGVuZ3RoO1xuICAgIH1cbiAgICBfZ2V0UmVmcygpIHtcbiAgICAgIHJldHVybiB0aGlzLl9yZWZzO1xuICAgIH1cbiAgICBnZXRCeVJlZihyZWYpIHtcbiAgICAgIHJldHVybiB0aGlzLl9yZWZzW3JlZl07XG4gICAgfVxuICAgIGNsZWFyUmVmKHJlZikge1xuICAgICAgZGVsZXRlIHRoaXMuX3JlZnNbcmVmXTtcbiAgICB9XG4gICAgc2V0UmVmKHJlZiwgY2hpbGQpIHtcbiAgICAgIHRoaXMuX3JlZnNbcmVmXSA9IGNoaWxkO1xuICAgIH1cbiAgICBwYXRjaChzZXR0aW5ncykge1xuICAgICAgaWYgKFV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKHNldHRpbmdzKSkge1xuICAgICAgICB0aGlzLl9zZXRCeU9iamVjdChzZXR0aW5ncyk7XG4gICAgICB9IGVsc2UgaWYgKEFycmF5LmlzQXJyYXkoc2V0dGluZ3MpKSB7XG4gICAgICAgIHRoaXMuX3NldEJ5QXJyYXkoc2V0dGluZ3MpO1xuICAgICAgfVxuICAgIH1cbiAgICBfc2V0QnlPYmplY3Qoc2V0dGluZ3MpIHtcbiAgICAgIGxldCByZWZzID0gdGhpcy5fZ2V0UmVmcygpO1xuICAgICAgbGV0IGNyZWZzID0gT2JqZWN0LmtleXMoc2V0dGluZ3MpO1xuICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBjcmVmcy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgbGV0IGNyZWYgPSBjcmVmc1tpXTtcbiAgICAgICAgbGV0IHMgPSBzZXR0aW5nc1tjcmVmXTtcbiAgICAgICAgbGV0IGMgPSByZWZzW2NyZWZdO1xuICAgICAgICBpZiAoIWMpIHtcbiAgICAgICAgICBpZiAodGhpcy5pc0l0ZW0ocykpIHtcbiAgICAgICAgICAgIHMucmVmID0gY3JlZjtcbiAgICAgICAgICAgIHRoaXMuYWRkKHMpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjID0gdGhpcy5jcmVhdGVJdGVtKHMpO1xuICAgICAgICAgICAgYy5yZWYgPSBjcmVmO1xuICAgICAgICAgICAgYy5wYXRjaChzKTtcbiAgICAgICAgICAgIHRoaXMuYWRkKGMpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBpZiAodGhpcy5pc0l0ZW0ocykpIHtcbiAgICAgICAgICAgIGlmIChjICE9PSBzKSB7XG4gICAgICAgICAgICAgIGxldCBpZHggPSB0aGlzLmdldEluZGV4KGMpO1xuICAgICAgICAgICAgICBzLnJlZiA9IGNyZWY7XG4gICAgICAgICAgICAgIHRoaXMuc2V0QXQocywgaWR4KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYy5wYXRjaChzKTtcb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ZXQgcCA9IHRoaXM7XG4gICAgICB3aGlsZSAocCkge1xuICAgICAgICBhLnB1c2gocCk7XG4gICAgICAgIHAgPSBwLl9fcGFyZW50O1xuICAgICAgfVxuICAgICAgcmV0dXJuIGE7XG4gICAgfVxuICAgIGdldEFuY2VzdG9yQXREZXB0aChkZXB0aCkge1xuICAgICAgbGV0IGxldmVscyA9IHRoaXMuZ2V0RGVwdGgoKSAtIGRlcHRoO1xuICAgICAgaWYgKGxldmVscyA8IDApIHtcbiAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICB9XG4gICAgICByZXR1cm4gdGhpcy5nZXRBbmNlc3RvcihsZXZlbHMpO1xuICAgIH1cbiAgICBpc0FuY2VzdG9yT2YoYykge1xuICAgICAgbGV0IHAgPSBjO1xuICAgICAgd2hpbGUgKHAgPSBwLnBhcmVudCkge1xuICAgICAgICBpZiAodGhpcyA9PT0gcCkge1xuICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuICAgIGdldFNoYXJlZEFuY2VzdG9yKGMpIHtcbiAgICAgIGxldCBvMSA9IHRoaXM7XG4gICAgICBsZXQgbzIgPSBjO1xuICAgICAgbGV0IGwxID0gbzEuZ2V0RGVwdGgoKTtcbiAgICAgIGxldCBsMiA9IG8yLmdldERlcHRoKCk7XG4gICAgICBpZiAobDEgPiBsMikge1xuICAgICAgICBvMSA9IG8xLmdldEFuY2VzdG9yKGwxIC0gbDIpO1xuICAgICAgfSBlbHNlIGlmIChsMiA+IGwxKSB7XG4gICAgICAgIG8yID0gbzIuZ2V0QW5jZXN0b3IobDIgLSBsMSk7XG4gICAgICB9XG4gICAgICBkbyB7XG4gICAgICAgIGlmIChvMSA9PT0gbzIpIHtcbiAgICAgICAgICByZXR1cm4gbzE7XG4gICAgICAgIH1cbiAgICAgICAgbzEgPSBvMS5fX3BhcmVudDtcbiAgICAgICAgbzIgPSBvMi5fX3BhcmVud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BjaGlsZHJlbiA9IHRoaXMuX2NoaWxkcmVuLmdldCgpO1xuICAgICAgICBpZiAoY2hpbGRyZW4pIHtcbiAgICAgICAgICBsZXQgbSA9IGNoaWxkcmVuLmxlbmd0aDtcbiAgICAgICAgICBpZiAobSA+IDApIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbTsgaSsrKSB7XG4gICAgICAgICAgICAgIGNoaWxkcmVuW2ldLl91cGRhdGVBdHRhY2hlZEZsYWcoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKG5ld0F0dGFjaGVkKSB7XG4gICAgICAgICAgdGhpcy5fb25BdHRhY2goKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB0aGlzLl9vbkRldGFjaCgpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVFbmFibGVkRmxhZygpIHtcbiAgICAgIGxldCBuZXdFbmFibGVkID0gdGhpcy5faXNFbmFibGVkKCk7XG4gICAgICBpZiAodGhpcy5fX2VuYWJsZWQgIT09IG5ld0VuYWJsZWQpIHtcbiAgICAgICAgaWYgKG5ld0VuYWJsZWQpIHtcbiAgICAgICAgICB0aGlzLl9vbkVuYWJsZWQoKTtcbiAgICAgICAgICB0aGlzLl9zZXRFbmFibGVkRmxhZygpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuX29uRGlzYWJsZWQoKTtcbiAgICAgICAgICB0aGlzLl91bnNldEVuYWJsZWRGbGFnKCk7XG4gICAgICAgIH1cbiAgICAgICAgbGV0IGNoaWxkcmVuID0gdGhpcy5fY2hpbGRyZW4uZ2V0KCk7XG4gICAgICAgIGlmIChjaGlsZHJlbikge1xuICAgICAgICAgIGxldCBtID0gY2hpbGRyZW4ubGVuZ3RoO1xuICAgICAgICAgIGlmIChtID4gMCkge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB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odi5pc1RleHR1cmVTb3VyY2UpIHtcbiAgICAgICAgICB0ZXh0dXJlID0gbmV3IFNvdXJjZVRleHR1cmUodGhpcy5zdGFnZSk7XG4gICAgICAgICAgdGV4dHVyZS50ZXh0dXJlU291cmNlID0gdjtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBjb25zb2xlLmVycm9yKFwiW0xpZ2h0bmluZ10gUGxlYXNlIHNwZWNpZnkgYSB0ZXh0dXJlIHR5cGUuXCIpO1xuICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgY29uc3QgcHJldlRleHR1cmUgPSB0aGlzLl9fdGV4dHVyZTtcbiAgICAgIGlmICh0ZXh0dXJlICE9PSBwcmV2VGV4dHVyZSkge1xuICAgICAgICB0aGlzLl9fdGV4dHVyZSA9IHRleHR1cmU7XG4gICAgICAgIGlmICh0aGlzLl9fdGV4dHVyZSkge1xuICAgICAgICAgIGlmICh0aGlzLl9fZW5hYmxlZCkge1xuICAgICAgICAgICAgdGhpcy5fX3RleHR1cmUuYWRkRWxlbWVudCh0aGlzKTtcbiAgICAgICAgICAgIGlmICh0aGlzLndpdGhpbkJvdW5kc01hcmdpbikge1xuICAgICAgICAgICAgICBpZiAodGhpcy5fX3RleHR1cmUuaXNMb2FkZWQoKSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3NldERpc3BsYXllZFRleHR1cmUodGhpcy5fX3RleHR1cmUpO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX2VuYWJsZVRleHR1cmVFcnJvcigpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuX3NldERpc3BsYXllZFRleHR1cmUobnVsbCk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHByZXZUZXh0dXJlICYmIHByZXZUZXh0dXJlICE9PSB0aGlzLl9fZGlz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mUucHk7XG4gICAgICAgICAgdHgxID0gaXc7XG4gICAgICAgICAgdHkxID0gaWg7XG4gICAgICAgICAgdHgyID0gdHgyICogcncgKyBpdztcbiAgICAgICAgICB0eTIgPSB0eTIgKiByaCArIGloO1xuICAgICAgICAgIHR4MSA9IE1hdGgubWF4KDAsIHR4MSk7XG4gICAgICAgICAgdHkxID0gTWF0aC5tYXgoMCwgdHkxKTtcbiAgICAgICAgICB0eDIgPSBNYXRoLm1pbigxLCB0eDIpO1xuICAgICAgICAgIHR5MiA9IE1hdGgubWluKDEsIHR5Mik7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGRpc3BsYXllZFRleHR1cmVTb3VyY2UuX2ZsaXBUZXh0dXJlWSkge1xuICAgICAgICAgIGxldCB0ZW1wdHkgPSB0eTI7XG4gICAgICAgICAgdHkyID0gdHkxO1xuICAgICAgICAgIHR5MSA9IHRlbXB0eTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9fY29yZS5zZXRUZXh0dXJlQ29vcmRzKHR4MSwgdHkxLCB0eDIsIHR5Mik7XG4gICAgICB9XG4gICAgfVxuICAgIGdldENvcm5lclBvaW50cygpIHtcbiAgICAgIHJldHVybiB0aGlzLl9fY29yZS5nZXRDb3JuZXJQb2ludHMoKTtcbiAgICB9XG4gICAgX3Vuc2V0VGFnc1BhcmVudCgpIHtcbiAgICAgIGlmICh0aGlzLl9fdGFncykge1xuICAgICAgICB0aGlzLl9fdGFncy5mb3JFYWNoKCh0YWcpID0+IHtcbiAgICAgICAgICBsZXQgcCA9IHRoaXM7XG4gICAgICAgICAgd2hpbGUgKHAgPSBwLl9fcGFyZW50KSB7XG4gICAgICAgICAgICBsZXQgcGFyZW50VHJlZVRhZ3MgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICBwYXJlbnRUcmVlVGFncy5kZWxldGUodGhpcyk7XG4gICAgICAgICAgICBpZiAocC5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgIH1cbiAgICAgIGxldCB0YWdzID0gbnVsbDtcbiAgICAgIGxldCBuID0gMDtcbiAgICAgIGlmICh0aGlzLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9fdGFnUm9vdCkge1xuICAgICAgICAgIHRhZ3MgPSBVdGlscyQxLml0ZXJhdG9yVG9BcnJheSh0aGlzLl9fdHJlZVRhZ3Mua2V5cygpKTtcbiAgICAgICAgICBuID0gdGFncy5sZW5ndGg7XG4gICAgICAgICAgaWYgKG4gPiAwKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICBsZXQgdGFnU2V0ID0gdGhpcy5fX3RyZWVUYWdzLmdldCh0YWdzW2ldKTtcbiAgICAgICAgICAgICAgbGV0IHAgPSB0aGlzO1xuICAgICAgICAgICAgICB3aGlsZSAocCA9IHAuX19wYXJlbnQpIHtcbiAgICAgICAgICAgICAgICBsZXQgcGFyZW50VHJlZVRhZ3MgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZ3NbaV0pO1xuICAgICAgICAgICAgICAgIHRhZ1NldC5mb3JFYWNoKGZ1bmN0aW9uKGNvbXApIHtcbiAgICAgICAgICAgICAgICAgIHBhcmVudFRyZWVUYWdzLmRlbGV0ZShjb21wKTtcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICBpZiAocC5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBfc2V0VGFnc1BhcmVudCgpIHtcbiAgICAgIGlmICh0aGlzLl9fdGFncykge1xuICAgICAgICB0aGlzLl9fdGFncy5mb3JFYWNoKCh0YWcpID0+IHtcbiAgICAgICAgICBsZXQgcCA9IHRoaXM7XG4gICAgICAgICAgd2hpbGUgKHAgPSBwLl9fcGFyZW50KSB7XG4gICAgICAgICAgICBpZiAoIXAuX190cmVlVGFncykge1xuICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3MgPSAvKiBAX19QVVJFX18gKi8gbmV3IE1hcCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgbGV0IHMgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICBpZiAoIXMpIHtcbiAgICAgICAgICAgICAgcyA9IC8qIEBfX1BVUkVfXyAqLyBuZXcgU2V0KCk7XG4gICAgICAgICAgICAgIHAuX190cmVlVGFncy5zZXQodGFnLCBzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHMuYWRkKHRoaXMpO1xuICAgICAgICAgICAgaWYgKHAuX190YWdSb290KSB7XG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5fX3RyZWVUYWdzICYmIHRoaXMuX190cmVlVGFncy5zaXplKSB7XG4gICAgICAgIGlmICghdGhpcy5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICB0aGlzLl9fdHJlZVRhZ3MuZm9yRWFjaCgodGFnU2V0LCB0YWcpID0+IHtcbiAgICAgICAgICAgIGxldCBwID0gdGhpcztcbiAgICAgICAgICAgIHdoaWxlICghcC5fX3RhZ1Jvb3QgJiYgKHAgPSBwLl9fcGFyZW50KSkge1xuICAgICAgICAgICAgICBpZiAocC5fX3RhZ1Jvb3QpXG4gICAgICAgICAgICAgICAgO1xuICAgICAgICAgICAgICBpZiAoIXAuX190cmVlVGFncykge1xuICAgICAgICAgICAgICAgIHAuX190cmVlVGFncyA9IC8qIEBfX1BVUkVfXyAqLyBuZXcgTWFwKCk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgbGV0IHMgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICAgIGlmICghcykge1xuICAgICAgICAgICAgICAgIHMgPSAvKiBAX19QVVJFX18gKi8gbmV3IFNldCgpO1xuICAgICAgICAgICAgICAgIHAuX190cmVlVGFncy5zZXQodGFnLCBzKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB0YWdTZXQuZm9yRWFjaChmdW5jdGlvbihjb21wKSB7XG4gICAgICAgICAgICAgICAgcy5hZGQoY29tcCk7XG4gICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIF9nZXRCeVRhZyh0YWcpIHtcbiAgICAgIGlmICghdGhpcy5fX3RyZWVUYWdzKSB7XG4gICAgICAgIHJldHVybiBbXTtcbiAgICAgIH1cbiAgICAgIGxldCB0ID0gdGhpcy5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgcmV0dXJuIHQgPyBVdGlscyQxLnNldFRvQXJyYXkodCkgOiBbXTtcbiAgICB9XG4gICAgZ2V0VGFncygpIHtcbiAgICAgIHJldHVybiB0aGlzLl9fdGFncyA/IHRoaXMuX190YWdzIDogW107XG4gICAgfVxuICAgIHNldFRhZ3ModGFncykge1xuICAgICAgdGFncyA9IHRhZ3MucmVkdWNlKChhY2MsIHRhZykgPT4ge1xuICAgICAgICByZXR1cm4gYWNjLmNvbmNhdCh0YWcuc3BsaXQoXCIgXCIpKTtcbiAgICAgIH0sIFtdKTtcbiAgICAgIGlmICh0aGlzLl9fcmVmKSB7XG4gICAgICAgIHRhZ3MucHVzaCh0aGlzLl9fcmVmKTtcbiAgICAgIH1cbiAgICAgIGxldCBpLCBuID0gdGFncy5sZW5ndGg7XG4gICAgICBsZXQgcmVtb3ZlcyA9IFtdO1xuICAgICAgbGV0IGFkZHMgPSBbXTtcbiAg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G0gPSB0YWdzLmxlbmd0aDsgaSA8IG07IGkrKykge1xuICAgICAgICAgIGNvbnN0IHRhZzIgPSB0YWdzW2ldO1xuICAgICAgICAgIGlmIChVdGlscyQxLmlzVWNDaGFyKHRhZzIuY2hhckNvZGVBdCgwKSkpIHtcbiAgICAgICAgICAgIHRoaXMuX3Rocm93RXJyb3IoXCJUYWcgbWF5IG5vdCBzdGFydCB3aXRoIGFuIHVwcGVyIGNhc2UgY2hhcmFjdGVyLlwiKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgdGhpcy5fYWRkVGFnKHRhZzIpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIF9hZGRUYWcodGFnKSB7XG4gICAgICBpZiAoIXRoaXMuX190YWdzKSB7XG4gICAgICAgIHRoaXMuX190YWdzID0gW107XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5fX3RhZ3MuaW5kZXhPZih0YWcpID09PSAtMSkge1xuICAgICAgICB0aGlzLl9fdGFncy5wdXNoKHRhZyk7XG4gICAgICAgIGxldCBwID0gdGhpcy5fX3BhcmVudDtcbiAgICAgICAgaWYgKHApIHtcbiAgICAgICAgICBkbyB7XG4gICAgICAgICAgICBpZiAoIXAuX190cmVlVGFncykge1xuICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3MgPSAvKiBAX19QVVJFX18gKi8gbmV3IE1hcCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgbGV0IHMgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICBpZiAoIXMpIHtcbiAgICAgICAgICAgICAgcyA9IC8qIEBfX1BVUkVfXyAqLyBuZXcgU2V0KCk7XG4gICAgICAgICAgICAgIHAuX190cmVlVGFncy5zZXQodGFnLCBzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHMuYWRkKHRoaXMpO1xuICAgICAgICAgIH0gd2hpbGUgKCFwLl9fdGFnUm9vdCAmJiAocCA9IHAuX19wYXJlbnQpKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICByZW1vdmVUYWcodGFnKSB7XG4gICAgICBsZXQgaSA9IHRoaXMuX190YWdzLmluZGV4T2YodGFnKTtcbiAgICAgIGlmIChpICE9PSAtMSkge1xuICAgICAgICB0aGlzLl9fdGFncy5zcGxpY2UoaSwgMSk7XG4gICAgICAgIGxldCBwID0gdGhpcy5fX3BhcmVudDtcbiAgICAgICAgaWYgKHApIHtcbiAgICAgICAgICBkbyB7XG4gICAgICAgICAgICBsZXQgbGlzdCA9IHAuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgICAgICAgIGlmIChsaXN0KSB7XG4gICAgICAgICAgICAgIGxpc3QuZGVsZXRlKHRoaXMpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gd2hpbGUgKCFwLl9fdGFnUm9vdCAmJiAocCA9IHAuX19wYXJlbnQpKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBoYXNUYWcodGFnKSB7XG4gICAgICByZXR1cm4gdGhpcy5fX3RhZ3MgJiYgdGhpcy5fX3RhZ3MuaW5kZXhPZih0YWcpICE9PSAtMTtcbiAgICB9XG4gICAgX3RhZyh0YWcpIHtcbiAgICAgIGlmICh0YWcuaW5kZXhPZihcIi5cIikgIT09IC0xKSB7XG4gICAgICAgIHJldHVybiB0aGlzLm10YWcodGFnKVswXTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGlmICh0aGlzLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICBsZXQgdCA9IHRoaXMuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgICAgICBpZiAodCkge1xuICAgICAgICAgICAgY29uc3QgaXRlbSA9IHQudmFsdWVzKCkubmV4dCgpO1xuICAgICAgICAgICAgcmV0dXJuIGl0ZW0gPyBpdGVtLnZhbHVlIDogdm9pZCAwO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBnZXQ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ZHggPT09IC0xIHx8IHBvaW50SWR4ICE9PSAtMSAmJiBwb2ludElkeCA8IGFycm93SWR4KSB7XG4gICAgICAgIGxldCBuZXh0O1xuICAgICAgICBjb25zdCBzdHIgPSBwYXRoLnN1YnN0cigwLCBwb2ludElkeCk7XG4gICAgICAgIGlmIChpc1JlZikge1xuICAgICAgICAgIGNvbnN0IHJlZiA9IHRoaXMuZ2V0QnlSZWYoc3RyKTtcbiAgICAgICAgICBuZXh0ID0gcmVmID8gW3JlZl0gOiBbXTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBuZXh0ID0gdGhpcy5tdGFnKHN0cik7XG4gICAgICAgIH1cbiAgICAgICAgbGV0IHRvdGFsID0gW107XG4gICAgICAgIGNvbnN0IHN1YlBhdGggPSBwYXRoLnN1YnN0cihwb2ludElkeCArIDEpO1xuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IG5leHQubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgdG90YWwgPSB0b3RhbC5jb25jYXQobmV4dFtpXS5fc2VsZWN0Q2hpbGRzKHN1YlBhdGgsIGZhbHNlKSk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRvdGFsO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgbGV0IG5leHQ7XG4gICAgICAgIGNvbnN0IHN0ciA9IHBhdGguc3Vic3RyKDAsIGFycm93SWR4KTtcbiAgICAgICAgaWYgKGlzUmVmKSB7XG4gICAgICAgICAgY29uc3QgcmVmID0gdGhpcy5nZXRCeVJlZihzdHIpO1xuICAgICAgICAgIG5leHQgPSByZWYgPyBbcmVmXSA6IFtdO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIG5leHQgPSB0aGlzLm10YWcoc3RyKTtcbiAgICAgICAgfVxuICAgICAgICBsZXQgdG90YWwgPSBbXTtcbiAgICAgICAgY29uc3Qgc3ViUGF0aCA9IHBhdGguc3Vic3RyKGFycm93SWR4ICsgMSk7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BpZiAodGhpcy5fX3JlZikge1xuICAgICAgICBzZXR0aW5ncy5yZWYgPSB0aGlzLl9fcmVmO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMuX190YWdzICYmIHRoaXMuX190YWdzLmxlbmd0aCkge1xuICAgICAgICBzZXR0aW5ncy50YWdzID0gdGhpcy5fX3RhZ3M7XG4gICAgICB9XG4gICAgICBpZiAodGhpcy54ICE9PSAwKVxuICAgICAgICBzZXR0aW5ncy54ID0gdGhpcy54O1xuICAgICAgaWYgKHRoaXMueSAhPT0gMClcbiAgICAgICAgc2V0dGluZ3MueSA9IHRoaXMueTtcbiAgICAgIGlmICh0aGlzLncgIT09IDApXG4gICAgICAgIHNldHRpbmdzLncgPSB0aGlzLnc7XG4gICAgICBpZiAodGhpcy5oICE9PSAwKVxuICAgICAgICBzZXR0aW5ncy5oID0gdGhpcy5oO1xuICAgICAgaWYgKHRoaXMuc2NhbGVYID09PSB0aGlzLnNjYWxlWSkge1xuICAgICAgICBpZiAodGhpcy5zY2FsZVggIT09IDEpXG4gICAgICAgICAgc2V0dGluZ3Muc2NhbGUgPSB0aGlzLnNjYWxlWDtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGlmICh0aGlzLnNjYWxlWCAhPT0gMSlcbiAgICAgICAgICBzZXR0aW5ncy5zY2FsZVggPSB0aGlzLnNjYWxlWDtcbiAgICAgICAgaWYgKHRoaXMuc2NhbGVZICE9PSAxKVxuICAgICAgICAgIHNldHRpbmdzLnNjYWxlWSA9IHRoaXMuc2NhbGVZO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMucGl2b3RYID09PSB0aGlzLnBpdm90WSkge1xuICAgICAgICBpZiAodGhpcy5waXZvdFggIT09IDAuNSlcbiAgICAgICAgICBzZXR0aW5ncy5waXZvdCA9IHRoaXMucGl2b3RYO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKHRoaXMucGl2b3RYICE9PSAwLjUpXG4gICAgICAgICAgc2V0dGluZ3MucGl2b3RYID0gdGhpcy5waXZvdFg7XG4gICAgICAgIGlmICh0aGlzLnBpdm90WSAhPT0gMC41KVxuICAgICAgICAgIHNldHRpbmdzLnBpdm90WSA9IHRoaXMucGl2b3RZO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMubW91bnRYID09PSB0aGlzLm1vdW50WSkge1xuICAgICAgICBpZiAodGhpcy5tb3VudFggIT09IDApXG4gICAgICAgICAgc2V0dGluZ3MubW91bnQgPSB0aGlzLm1vdW50WDtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGlmICh0aGlzLm1vdW50WCAhPT0gMClcbiAgICAgICAgICBzZXR0aW5ncy5tb3VudFggPSB0aGlzLm1vdW50WDtcbiAgICAgICAgaWYgKHRoaXMubW91bnRZICE9PSAwKVxuICAgICAgICAgIHNldHRpbmdzLm1vdW50WSA9IHRoaXMubW91bnRZO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMuYWxwaGEgIT09IDEpXG4gICAgICAgIHNldHRpbmdzLmFscGhhID0gdGhpcy5hbHBoYTtcbiAgICAgIGlmICghdGhpcy52aXNpYmxlKVxuICAgICAgICBzZXR0aW5ncy52aXNpYmxlID0gZmFsc2U7XG4gICAgICBpZiAodGhpcy5yb3RhdGlvbiAhPT0gMClcbiAgICAgICAgc2V0dGluZ3Mucm90YXRpb24gPSB0aGlzLnJvdGF0aW9uO1xuICAgICAgaWYgKHRoaXMuY29sb3JVbCA9PT0gdGhpcy5jb2xvclVyICYmIHRoaXMuY29sb3JCbCA9PT0gdGhpcy5jb2xvckJyICYmIHRoaXMuY29sb3JVbCA9PT0gdGhpcy5jb2xvckJsKSB7XG4gICAgICAgIGlmICh0aGlzLmNvbG9yVWwgIT09IDQyOTQ5NjcyOTUpXG4gICAgICAgICAgc2V0dGluZ3MuY29sb3IgPSB0aGlzLmNvbG9yVWwudG9TdHJpbmcoMTYpO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKHRoaXMuY29sb3JVbCAhPT0gN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sb3JCcigpIHtcbiAgICAgIHJldHVybiB0aGlzLl9fY29yZS5jb2xvckJyO1xuICAgIH1cbiAgICBzZXQgY29sb3JCcih2KSB7XG4gICAgICB0aGlzLl9fY29yZS5jb2xvckJyID0gdjtcbiAgICB9XG4gICAgZ2V0IGNvbG9yKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLmNvbG9yVWw7XG4gICAgfVxuICAgIHNldCBjb2xvcih2KSB7XG4gICAgICBpZiAodGhpcy5jb2xvclVsICE9PSB2IHx8IHRoaXMuY29sb3JVciAhPT0gdiB8fCB0aGlzLmNvbG9yQmwgIT09IHYgfHwgdGhpcy5jb2xvckJyICE9PSB2KSB7XG4gICAgICAgIHRoaXMuY29sb3JVbCA9IHY7XG4gICAgICAgIHRoaXMuY29sb3JVciA9IHY7XG4gICAgICAgIHRoaXMuY29sb3JCbCA9IHY7XG4gICAgICAgIHRoaXMuY29sb3JCciA9IHY7XG4gICAgICB9XG4gICAgfVxuICAgIGdldCBjb2xvclRvcCgpIHtcbiAgICAgIHJldHVybiB0aGlzLmNvbG9yVWw7XG4gICAgfVxuICAgIHNldCBjb2xvclRvcCh2KSB7XG4gICAgICBpZiAodGhpcy5jb2xvclVsICE9PSB2IHx8IHRoaXMuY29sb3JVciAhPT0gdikge1xuICAgICAgICB0aGlzLmNvbG9yVWwgPSB2O1xuICAgICAgICB0aGlzLmNvbG9yVXIgPSB2O1xuICAgICAgfVxuICAgIH1cbiAgICBnZXQgY29sb3JCb3R0b20oKSB7XG4gICAgICByZXR1cm4gdGhpcy5jb2xvckJsO1xuICAgIH1cbiAgICBzZXQgY29sb3JCb3R0b20odikge1xuICAgICAgaWYgKHRoaXMuY29sb3JCbCAhPT0gdiB8fCB0aGlzLmNvbG9yQnIgIT09IHYpIHtcbiAgICAgICAgdGhpcy5jb2xvckJsID0gdjtcbiAgICAgICAgdGhpcy5jb2xvckJyID0gdjtcbiAgICAgIH1cbiAgICB9XG4gICAgZ2V0IGNvbG9yTGVmdCgpIHtcbiAgICAgIHJldHVybiB0aGlzLmNvbG9yVWw7XG4gICAgfVxuICAgIHNldCBjb2xvckxlZnQodikge1xuICAgICAgaWYgKHRoaXMuY29sb3JVbCAhPT0gdiB8fCB0aGlzLmNvbG9yQmwgIT09IHYpIHtcbiAgICAgICAgdGhpcy5jb2xvclVsID0gdjtcbiAgICAgICAgdGhpcy5jb2xvckJsID0gdjtcbiAgICAgIH1cbiAgICB9XG4gICAgZ2V0IGNvbG9yUmlnaHQoKSB7XG4gICAgICByZXR1cm4gdGhpcy5jb2xvclVyO1xuICAgIH1cbiAgICBzZXQgY29sb3JSaWdodCh2KSB7XG4gICAgICBpZiAodGhpcy5jb2xvclVyICE9PSB2IHx8IHRoaXMuY29sb3JCciAhPT0gdikge1xuICAgICAgICB0aGlzLmNvbG9yVXIgPSB2O1xuICAgICAgICB0aGlzLmNvbG9yQnIgPSB2O1xuICAgICAgfVxuICAgIH1cbiAgICBnZXQgekluZGV4KCkge1xuICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLnpJbmRleDtcbiAgICB9XG4gICAgc2V0IHpJbmRleCh2KSB7XG4gICAgICB0aGlzLl9fY29yZS56SW5kZXggPSB2O1xuICAgIH1cbiAgICBnZXQgZm9yY2VaSW5kZXhDb250ZXh0KCkge1xuICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLmZvcmNlWkluZGV4Q29udGV4dDtcbiAgICB9XG4gICAgc2V0IGZvcmNlWkluZGV4Q29udGV4dCh2KSB7XG4gICAgICB0aGlzLl9fY29yZS5mb3JjZVpJbmRleENvbnRleHQgPSB2O1xuICAgIH1cbiAgICBnZXQgY2xpcHBpbmcoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fX2NvcmUuY2xpcHBpbmc7XG4gICAgfVxuICAgIHNldCBjbGlwcGluZyh2KSB7XG4gICAgICB0aGlzLl9fY29yZS5jbGlwcGluZyA9IHY7XG4gICAgfVxuICAgIGdldCBjbGlwYm94KCkge1xuICAgICAgcmV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IoZmlyc3RDaGFyQ29kZSkpIHtcbiAgICAgICAgICBjb25zdCBjaGlsZCA9IHRoaXMuZ2V0QnlSZWYocGF0aCk7XG4gICAgICAgICAgaWYgKCFjaGlsZCkge1xuICAgICAgICAgICAgaWYgKHYgIT09IHZvaWQgMCkge1xuICAgICAgICAgICAgICBsZXQgYztcbiAgICAgICAgICAgICAgaWYgKFV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKHYpKSB7XG4gICAgICAgICAgICAgICAgYyA9IHRoaXMuY2hpbGRMaXN0LmNyZWF0ZUl0ZW0odik7XG4gICAgICAgICAgICAgICAgYy5wYXRjaCh2KTtcbiAgICAgICAgICAgICAgfSBlbHNlIGlmIChVdGlscyQxLmlzT2JqZWN0KHYpKSB7XG4gICAgICAgICAgICAgICAgYyA9IHY7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgaWYgKGMuaXNFbGVtZW50KSB7XG4gICAgICAgICAgICAgICAgYy5yZWYgPSBwYXRoO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmEoYyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh2ID09PSB2b2lkIDApIHtcbiAgICAgICAgICAgICAgaWYgKGNoaWxkLnBhcmVudCkge1xuICAgICAgICAgICAgICAgIGNoaWxkLnBhcmVudC5jaGlsZExpc3QucmVtb3ZlKGNoaWxkKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmIChVdGlscyQxLmlzT2JqZWN0TGl0ZXJhbCh2KSkge1xuICAgICAgICAgICAgICBjaGlsZC5wYXRjaCh2KTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodi5pc0VsZW1lbnQpIHtcbiAgICAgICAgICAgICAgdi5yZWYgPSBwYXRoO1xuICAgICAgICAgICAgICB0aGlzLmNoaWxkTGlzdC5yZXBsYWNlKHYsIGNoaWxkKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHRoaXMuX3Rocm93RXJyb3IoXCJVbmV4cGVjdGVkIHZhbHVlIGZvciBwYXRoOiBcIiArIHBhdGgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBCYXNlLnBhdGNoT2JqZWN0UHJvcGVydHkodGhpcywgcGF0aCwgdik7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgX3Rocm93RXJyb3IobWVzc2FnZSkge1xuICAgICAgdGhyb3cgbmV3IEVycm9yKHRoaXMuY29uc3RydWN0b3IubmFtZSArIFwiIChcIiArIHRoaXMuZ2V0TG9jYXRpb25TdHJpbmcoKSArIFwiKTogXCIgKyBtZXNzYWdlKTtcbiAgICB9XG4gICAgYW5pbWF0aW9uKHNldHRpbmdzKSB7XG4gICAgICByZXR1cm4gdGhpcy5zdGFnZS5hbmltYXRpb25zLmNyZWF0ZUFuaW1hdGlvbih0aGlzLCBzZXR0aW5ncyk7XG4gICAgfVxuICAgIHRyYW5zaXRpb24ocHJvcGVydHksIHNldHRpbmdzID0gbnVsbCkge1xuICAgICAgaWYgKHNldHRpbmdzID09PSBudWxsKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9nZXRUcmFuc2l0aW9uKHByb3BlcnR5KTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHRoaXMuX3NldFRyYW5zaXRpb24ocHJvcGVydHksIHNldHRpbmdzKTtcbiAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICB9XG4gICAgfVxuICAgIHNldCB0cmFuc2l0aW9ucyhvYmplY3QpIHtcbiAgICAgIGxldCBrZXlzID0gT2JqZWN0LmtleXMob2JqZWN0KTtcbiAgICAgIGtleXMuZm9yRWFjaCgocHJvcGVydHkpID0+IHtcbiAgICAgICAgdGhpcy50cmFuc2l0aW9uKHByb3BlcnR5LCBvYmplY3RbcHJvcGVydHldKTt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MoZWxlbWVudCk7XG4gICAgICAgIHRyZWVbcmVmXSA9IHsgLi4ucHJvcGVydGllcyB9O1xuICAgICAgICBpZiAoZWxlbWVudC5oYXNDaGlsZHJlbigpKSB7XG4gICAgICAgICAgdHJlZVtyZWZdLmNoaWxkcmVuID0ge307XG4gICAgICAgICAgdGhpcy5jb2xsZWN0Q2hpbGRyZW4oXG4gICAgICAgICAgICB0cmVlW3JlZl0uY2hpbGRyZW4sXG4gICAgICAgICAgICBlbGVtZW50Ll9fY2hpbGRMaXN0XG4gICAgICAgICAgKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBzdGF0aWMgZ2V0UHJvcGVydGllcyhlbGVtZW50KSB7XG4gICAgICBjb25zdCBwcm9wcyA9IHt9O1xuICAgICAgY29uc3QgbGlzdCA9IFtcbiAgICAgICAgXCJhbHBoYVwiLFxuICAgICAgICBcImFjdGl2ZVwiLFxuICAgICAgICBcImF0dGFjaGVkXCIsXG4gICAgICAgIFwiYm91bmRzTWFyZ2luXCIsXG4gICAgICAgIFwiY29sb3JcIixcbiAgICAgICAgXCJjbGlwcGluZ1wiLFxuICAgICAgICBcImVuYWJsZWRcIixcbiAgICAgICAgXCJoXCIsXG4gICAgICAgIFwiaWRcIixcbiAgICAgICAgXCJpc0NvbXBvbmVudFwiLFxuICAgICAgICBcIm1vdW50XCIsXG4gICAgICAgIFwibW91bnRZXCIsXG4gICAgICAgIFwibW91bnRYXCIsXG4gICAgICAgIFwicGl2b3RcIixcbiAgICAgICAgXCJwaXZvdFhcIixcbiAgICAgICAgXCJwaXZvdFlcIixcbiAgICAgICAgXCJyZWZcIixcbiAgICAgICAgXCJyZW5kZXJPZmZzY3JlZW5cIixcbiAgICAgICAgXCJyZW5kZXJUb1RleHR1cmVcIixcbiAgICAgICAgXCJzY2FsZVwiLFxuICAgICAgICBcInNjYWxlWFwiLFxuICAgICAgICBcInNjYWxlWVwiLFxuICAgICAgICBcInN0YXRlXCIsXG4gICAgICAgIFwidGFnXCIsXG4gICAgICAgIFwidmlzaWJsZVwiLFxuICAgICAgICBcIndcIixcbiAgICAgICAgXCJ4XCIsXG4gICAgICAgIFwieVwiLFxuICAgICAgICBcInpJbmRleFwiLFxuICAgICAgICBcIiEhZmxleFwiLFxuICAgICAgICBcIiEhZmxleEl0ZW1cIixcbiAgICAgICAgXCJoYXNGb2N1cygpXCIsXG4gICAgICAgIFwiaGFzRmluYWxGb2N1cygpXCJcbiAgICAgIF07XG4gICAgICBsZXQgbiA9IGxpc3QubGVuZ3RoO1xuICAgICAgd2hpbGUgKG4tLSkge1xuICAgICAgICBsZXQga2V5ID0gbGlzdFtuXTtcbiAgICAgICAgY29uc3QgZ2V0Qm9vbGVhbiA9IC9eIXsyfS87XG4gICAgICAgIGNvbnN0IGlzRnVuY3Rpb24gPSAvXFwoXFwpJC87XG4gICAgICAgIGlmIChnZXRCb29sZWFuLnRlc3Qoa2V5KSkge1xuICAgICAgICAgIGtleSA9IGtleS5zdWJzdHJpbmcoMiwga2V5Lmxlbmd0aCk7XG4gICAgICAgICAgcHJvcHNba2V5XSA9ICEhZWxlbWVudFtrZXldO1xuICAgICAgICB9IGVsc2UgaWYgKGlzRnVuY3Rpb24udGVzdChrZXkpKSB7XG4gICAgICAgICAga2V5ID0ga2V5LnN1YnN0cmluZygwLCBrZXkubGVuZ3RoIC0gMik7XG4gICAgICAgICAgaWYgKHR5cGVvZiBlbGVtZW50W2tleV0gPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICAgICAgcHJvcHNba2V5XSA9IGVsZW1lbnRba2V5XSgpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBwcm9wc1trZXldID0gZWxlbWVudFtrZXldO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4geyAuLi5wcm9wcywgLi4uZWxlbWVudC5nZXROb25EZWZhdWx0cygpIH07XG4gICAgfVxuICB9XG4gIEV2ZW50RW1pdHRlci5hZGRBc01peGlu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N0YXRlLCBhcmdzLCBjb250ZXh0KTtcbiAgICAgICAgICAgICAgY29uc3Qgc3RhdGVDaGFuZ2VPdmVycmlkZGVuID0gdGhpcy5fc2V0U3RhdGVJZCAhPT0gc2V0U3RhdGVJZDtcbiAgICAgICAgICAgICAgaWYgKHN0YXRlQ2hhbmdlT3ZlcnJpZGRlbikge1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9fc2V0U3RhdGUobmV3U3RhdGUpO1xuICAgICAgICBpZiAodGhpcy5fY2hhbmdlZFN0YXRlKSB7XG4gICAgICAgICAgY29uc3QgY29udGV4dCA9IHtcbiAgICAgICAgICAgIG5ld1N0YXRlOiBuZXdTdGF0ZS5fX3BhdGgsXG4gICAgICAgICAgICBwcmV2U3RhdGU6IHByZXZTdGF0ZS5fX3BhdGhcbiAgICAgICAgICB9O1xuICAgICAgICAgIGlmIChhcmdzKSB7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkU3RhdGUoY29udGV4dCwgLi4uYXJncyk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWRTdGF0ZShjb250ZXh0KTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX29uU3RhdGVDaGFuZ2UpIHtcbiAgICAgICAgICBjb25zdCBjb250ZXh0ID0ge1xuICAgICAgICAgICAgbmV3U3RhdGU6IG5ld1N0YXRlLl9fcGF0aCxcbiAgICAgICAgICAgIHByZXZTdGF0ZTogcHJldlN0YXRlLl9fcGF0aFxuICAgICAgICAgIH07XG4gICAgICAgICAgdGhpcy5fb25TdGF0ZUNoYW5nZShjb250ZXh0KTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBfY2FsbEVudGVyKHN0YXRlLCBhcmdzID0gW10sIGNvbnRleHQp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GlmIChhbGlhcyAhPT0gY3VyKSB7XG4gICAgICAgICAgaWYgKGN1cikge1xuICAgICAgICAgICAgaWYgKHN1cHBvcnRzU3ByZWFkKSB7XG4gICAgICAgICAgICAgIGNvZGUucHVzaChgaWYgKGkgPCAke2l9KSByZXR1cm4gdGhpc1tcIiR7Y3VyfVwiXSguLi5hcmd1bWVudHMpOyBlbHNlYCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBjb2RlLnB1c2goYGlmIChpIDwgJHtpfSkgcmV0dXJuIHRoaXNbXCIke2N1cn1cIl0uYXBwbHkodGhpcywgYXJndW1lbnRzKTsgZWxzZWApO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb2RlLnB1c2goYGlmIChpIDwgJHtpfSkgcmV0dXJuIDsgZWxzZWApO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBjdXIgPSBhbGlhcztcbiAgICAgIH1cbiAgICAgIGlmIChjdXIpIHtcbiAgICAgICAgaWYgKHN1cHBvcnRzU3ByZWFkKSB7XG4gICAgICAgICAgY29kZS5wdXNoKGByZXR1cm4gdGhpc1tcIiR7Y3VyfVwiXSguLi5hcmd1bWVudHMpO2ApO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGNvZGUucHVzaChgcmV0dXJuIHRoaXNbXCIke2N1cn1cIl0uYXBwbHkodGhpcywgYXJndW1lbnRzKTtgKTtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgY29kZS5wdXNoKGA7YCk7XG4gICAgICB9XG4gICAgICBjb25zdCBmdW5jdGlvbkJvZHkgPSBjb2RlLmpvaW4oXCJcXG5cIik7XG4gICAgICBjb25zdCByb3V0ZXIgPSBuZXcgRnVuY3Rpb24oW10sIGZ1bmN0aW9uQm9keSk7XG4gICAgICBjb25zdCBkZXNjcmlwdG9yID0geyB2YWx1ZTogcm91dGVyIH07XG4gICAgICBP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AgICAgYWxpYXNlc1tpbmRleF0gPSBhbGlhcztcbiAgICAgICAgICBpZiAoIXRoaXMuX3JvdXRlci5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkoYWxpYXMpKSB7XG4gICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcy5fcm91dGVyLnByb3RvdHlwZSwgYWxpYXMsIGRlc2NyaXB0b3IpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBhbGlhc2VzW2luZGV4XSA9IG51bGw7XG4gICAgICAgIH1cbiAgICAgIH0pO1xuICAgICAgY29uc3QgY29kZSA9IFtcbiAgICAgICAgXCIvL0Agc291cmNlVVJMPVN0YXRlTWFjaGluZVJvdXRlci5qc1wiLFxuICAgICAgICBcInZhciBpID0gdGhpcy5fc3RhdGVJbmRleDtcIlxuICAgICAgXTtcbiAgICAgIGxldCBjdXIgPSBhbGlhc2VzWzBdO1xuICAgICAgZm9yIChsZXQgaSA9IDEsIG4gPSBhbGlhc2VzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICBjb25zdCBhbGlhcyA9IGFsaWFzZXNbaV07XG4gICAgICAgIGlmIChhbGlhcyAhPT0gY3VyKSB7XG4gICAgICAgICAgaWYgKGN1cikge1xuICAgICAgICAgICAgY29kZS5wdXNoKGBpZiAoaSA8ICR7aX0pIHJldHVybiB0aGlzW1wiJHtjdXJ9XCJdOyBlbHNlYCk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGNvZGUucHVzaChgaWYgKGkgPCAke2l9KSByZXR1cm4gOyBlbHNlYCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGN1ciA9IGFsaWFzO1xuICAgICAgfVxuICAgICAgaWYgKGN1cikge1xuICAgICAgICBjb2RlLnB1c2goYHJldHVybiB0aGlzW1wiJHtjdXJ9XCJdO2ApO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgY29kZS5wdX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3RoIC0gMX1dKWApO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBpZiAoa2V5ID09PSBcInRleHRcIikge1xuICAgICAgICAgICAgY29uc3QgcHJvcEtleSA9IGN1cnNvciArIFwiX190ZXh0XCI7XG4gICAgICAgICAgICBsb2MucHVzaChgdmFyICR7cHJvcEtleX0gPSAke2N1cnNvcn0uZW5hYmxlVGV4dFRleHR1cmUoKWApO1xuICAgICAgICAgICAgaWYgKHZhbHVlLl9fcHJvcGVydHlCaW5kaW5nID09PSB0cnVlKSB7XG4gICAgICAgICAgICAgIHN0b3JlLnB1c2godmFsdWUpO1xuICAgICAgICAgICAgICBsb2MucHVzaChgZWxlbWVudC5fX2JpbmRQcm9wZXJ0eShzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XSwgJHtjdXJzb3J9LCBcIiR7a2V5fVwiKWApO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgdGhpcy5wYXJzZVRlbXBsYXRlUHJvcFJlYyh2YWx1ZSwgY29udGV4dCwgcHJvcEtleSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChrZXkgPT09IFwic2hhZGVyXCIgJiYgVXRpbHMkMS5pc09iamVjdExpdGVyYWwodmFsdWUpKSB7XG4gICAgICAgICAgICBjb25zdCBzaGFkZXJDdXJzb3IgPSBgJHtjdXJzb3J9W1wic2hhZGVyXCJdYDtcbiAgICAgICAgICAgIHN0b3JlLnB1c2godmFsdWUpO1xuICAgICAgICAgICAgbG9jLnB1c2goYCR7Y3Vyc29yfVtcIiR7a2V5fVwiXSA9IHN0b3JlWyR7c3RvcmUubGVuZ3RoIC0gMX1dYCk7XG4gICAgICAgICAgICB0aGlzLnBhcnNlUHJvcGVydHlCaW5kaW5ncyh2YWx1ZSwgY29udGV4dCwgc2hhZGVyQ3Vyc29yKTtcbiAgICAgICAgICB9IGVsc2UgaWYgKGtleSA9PT0gXCJ0Z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nN0IHN0b3JlID0gY29udGV4dC5zdG9yZTtcbiAgICAgIGNvbnN0IGxvYyA9IGNvbnRleHQubG9jO1xuICAgICAgY29uc3Qga2V5cyA9IE9iamVjdC5rZXlzKG9iaik7XG4gICAgICBrZXlzLmZvckVhY2goKGtleSkgPT4ge1xuICAgICAgICBpZiAoa2V5ICE9PSBcInR5cGVcIikge1xuICAgICAgICAgIGNvbnN0IHZhbHVlID0gb2JqW2tleV07XG4gICAgICAgICAgaWYgKFV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKHZhbHVlKSAmJiB2YWx1ZS5fX3Byb3BlcnR5QmluZGluZyA9PT0gdHJ1ZSkge1xuICAgICAgICAgICAgc3RvcmUucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICBsb2MucHVzaChgZWxlbWVudC5fX2JpbmRQcm9wZXJ0eShzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XSwgJHtjdXJzb3J9LCBcIiR7a2V5fVwiKWApO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSk7XG4gICAgfVxuICAgIF9vblNldHVwKCkge1xuICAgICAgaWYgKCF0aGlzLl9faW5pdGlhbGl6ZWQpIHtcbiAgICAgICAgdGhpcy5fc2V0dXAoKTtcbiAgICAgIH1cbiAgICB9XG4gICAgX3NldHVwKCkge1xuICAgIH1cbiAgICBfb25BdHRhY2goKSB7XG4gICAgICBpZiAoIXRoaXMuX19pbml0aWFsaXplZCkge1xuICAgICAgICB0aGlzLl9faW5pdCgpO1xuICAgICAgICB0aGlzLl9faW5pdGlhbGl6ZWQgPSB0cnVlO1xuICAgICAgfVxuICAgICAgdGhpcy5fYXR0YWNoKCk7XG4gICAgfVxuICAgIF9hdHRhY2goKSB7XG4gICAgfVxuICAgIF9vbkRldGFjaCgpIHtcbiAgICAgIHRoaXMuX2RldGFjaCgpO1xuICAgIH1cbiAgICBfZGV0YWNoKCkge1xuICAgIH1cbiAgICBfb25FbmFibGVkKCkge1xuICAgICAgaWY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21wb25lbnQoZWxlbWVudCkge1xuICAgICAgbGV0IGFuY2VzdG9yID0gdGhpcy5nZXRTaGFyZWRBbmNlc3RvcihlbGVtZW50KTtcbiAgICAgIHdoaWxlIChhbmNlc3RvciAmJiAhYW5jZXN0b3IuaXNDb21wb25lbnQpIHtcbiAgICAgICAgYW5jZXN0b3IgPSBhbmNlc3Rvci5wYXJlbnQ7XG4gICAgICB9XG4gICAgICByZXR1cm4gYW5jZXN0b3I7XG4gICAgfVxuICAgIGdldCBzaWduYWxzKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX19zaWduYWxzO1xuICAgIH1cbiAgICBzZXQgc2lnbmFscyh2KSB7XG4gICAgICBpZiAoIVV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKHYpKSB7XG4gICAgICAgIHRoaXMuX3Rocm93RXJyb3IoXCJTaWduYWxzOiBzcGVjaWZ5IGFuIG9iamVjdCB3aXRoIHNpZ25hbC10by1maXJlIG1hcHBpbmdzXCIpO1xuICAgICAgfVxuICAgICAgdGhpcy5fX3NpZ25hbHMgPSB2O1xuICAgIH1cbiAgICBzZXQgYWx0ZXJTaWduYWxzKHYpIHtcbiAgICAgIGlmICghVXRpbHMkMS5pc09iamVjdExpdGVyYWwodikpIHtcbiAgICAgICAgdGhpcy5fdGhyb3dFcnJvcihcIlNpZ25hbHM6IHNwZWNpZnkgYW4gb2JqZWN0IHdpdGggc2lnbmFsLXRvLWZpcmUgbWFwcGluZ3NcIik7XG4gICAgICB9XG4gICAgICBpZiAoIXRoaXMuX19zaWduYWxzKSB7XG4gICAgICAgIHRoaXMuX19zaWduYWxzID0ge307XG4gICAgICB9XG4gICAgICBmb3IgKGxldCBrZXkgaW4gdikge1xuICAgICAgICBjb25zdCBkID0gdltrZXldO1xuICAgICAgICBpZiAoZCA9PT0gdm9pZCAwKSB7XG4gICAgICAgICAgZGVsZXRlIHRoaXMuX19zaWduYWxzW2tleV07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhp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W50U2lnbmFsSGFuZGxlcigpO1xuICAgICAgaWYgKHNpZ25hbFBhcmVudCkge1xuICAgICAgICBpZiAodGhpcy5fX3NpZ25hbHMpIHtcbiAgICAgICAgICBsZXQgZmlyZUV2ZW50ID0gdGhpcy5fX3NpZ25hbHNbZXZlbnRdO1xuICAgICAgICAgIGlmIChmaXJlRXZlbnQgPT09IGZhbHNlKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChmaXJlRXZlbnQpIHtcbiAgICAgICAgICAgIGlmIChmaXJlRXZlbnQgPT09IHRydWUpIHtcbiAgICAgICAgICAgICAgZmlyZUV2ZW50ID0gZXZlbnQ7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoVXRpbHMkMS5pc0Z1bmN0aW9uKGZpcmVFdmVudCkpIHtcbiAgICAgICAgICAgICAgcmV0dXJuIGZpcmVFdmVudCguLi5hcmdzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChzaWduYWxQYXJlbnQuX2hhc01ldGhvZChmaXJlRXZlbnQpKSB7XG4gICAgICAgICAgICAgIHJldHVybiBzaWduYWxQYXJlbnRbZmlyZUV2ZW50XSguLi5hcmdzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgbGV0IHBhc3NTaWduYWwgPSB0aGlzLl9fcGFzc1NpZ25hbHMgJiYgdGhpcy5fX3Bhc3NTaWduYWxzW2V2ZW50XTtcbiAgICAgICAgaWYgKHBhc3NTaWduYWwpIHtcbiAgICAgICAgICBpZiAocGFzc1NpZ25hbCAmJiBwYXNzU2lnbmFsICE9PSB0cnVlKSB7XG4gICAgICAgICAgICBldmVudCA9IHBhc3NTaWduYWw7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybiBzaWduYWxQYXJlbnQuX3NpZ25hbChldmVudCwgYXJncyk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4g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IpIHtcbiAgICAgICAgICB0aGlzLl9zaGFkZXIgPSBzaGFkZXI7XG4gICAgICAgICAgdGhpcy5fc2hhZGVyT3duZXIgPSBvd25lcjtcbiAgICAgICAgICB0aGlzLl9jaGVjayA9IHRydWU7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgZ2V0IHJlbmRlclRleHR1cmVJbmZvKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX3JlbmRlclRleHR1cmVJbmZvO1xuICAgIH1cbiAgICBzZXRTY2lzc29yKGFyZWEpIHtcbiAgICAgIGlmICh0aGlzLl9zY2lzc29yICE9PSBhcmVhKSB7XG4gICAgICAgIGlmIChhcmVhKSB7XG4gICAgICAgICAgdGhpcy5fc2Npc3NvciA9IGFyZWE7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhpcy5fc2Npc3NvciA9IG51bGw7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fY2hlY2sgPSB0cnVlO1xuICAgICAgfVxuICAgIH1cbiAgICBnZXRTY2lzc29yKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX3NjaXNzb3I7XG4gICAgfVxuICAgIHNldFJlbmRlclRleHR1cmVJbmZvKHJlbmRlclRleHR1cmVJbmZvKSB7XG4gICAgICBpZiAodGhpcy5fcmVuZGVyVGV4dHVyZUluZm8gIT09IHJlbmRlclRleHR1cmVJbmZvKSB7XG4gICAgICAgIHRoaXMuX3JlbmRlclRleHR1cmVJbmZvID0gcmVuZGVyVGV4dHVyZUluZm87XG4gICAgICAgIHRoaXMuX3NjaXNzb3IgPSBudWxsO1xuICAgICAgICB0aGlzLl9jaGVjayA9IHRydWU7XG4gICAgICB9XG4gICAgfVxuICAgIHNldFRleHR1cml6ZXIodGV4dHVyaXplciwgY2FjaGUgPSBmYWxzZSkge1xuICAgICAgdGhpcy5fdGV4dHVyaXplciA9IHRleHR1cml6ZXI7XG4gICAgICB0aGlzLl9jYWNoZVRleHR1cml6ZXIgPSBjYW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9IHIucHkgKyBlbGVtZW50Q29yZS5fdyAqIHIudGM7XG4gICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ4O1xuICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX3VseTtcbiAgICAgICAgdWludHNbb2Zmc2V0KytdID0gbWNhKGVsZW1lbnRDb3JlLl9jb2xvclVyLCByLmFscGhhKTtcbiAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHggKyBlbGVtZW50Q29yZS5fdyAqIHIudGEgKyBlbGVtZW50Q29yZS5faCAqIHIudGI7XG4gICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSByLnB5ICsgZWxlbWVudENvcmUuX3cgKiByLnRjICsgZWxlbWVudENvcmUuX2ggKiByLnRkO1xuICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX2JyeDtcbiAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl9icnk7XG4gICAgICAgIHVpbnRzW29mZnNldCsrXSA9IG1jYShlbGVtZW50Q29yZS5fY29sb3JCciwgci5hbHBoYSk7XG4gICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSByLnB4ICsgZWxlbWVudENvcmUuX2ggKiByLnRiO1xuICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weSArIGVsZW1lbnRDb3JlLl9oICogci50ZDtcbiAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl91bHg7XG4gICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ5O1xuICAgICAgICB1aW50c1tvZmZzZXRdID0gbWNhKGVsZW1lbnRDb3JlLl9jb2xvckJsLCByLmFscGhhKTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGxldCBjeCA9IHIucHggKyBlbGVtZW50Q29yZS5fdyAqIHIudGE7XG4gICAgICAgI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RjID8gMSA6IHZjLl9icnggLSB2Yy5fdWx4KSAqIHR4Lnc7XG4gICAgICAgICAgY29uc3Qgc291cmNlSCA9IChzdGMgPyAxIDogdmMuX2JyeSAtIHZjLl91bHkpICogdHguaDtcbiAgICAgICAgICBsZXQgY29sb3JpemUgPSAhd2hpdGU7XG4gICAgICAgICAgaWYgKGNvbG9yaXplKSB7XG4gICAgICAgICAgICBsZXQgY29sb3IgPSB2Yy5fY29sb3JVbDtcbiAgICAgICAgICAgIGlmICh2Yy5fY29sb3JVbCAhPT0gdmMuX2NvbG9yVXIgfHwgdmMuX2NvbG9yVXIgIT09IHZjLl9jb2xvckJsIHx8IHZjLl9jb2xvckJyICE9PSB2Yy5fY29sb3JCbCkge1xuICAgICAgICAgICAgICBjb2xvciA9IFN0YWdlVXRpbHMubWVyZ2VNdWx0aUNvbG9yc0VxdWFsKFt2Yy5fY29sb3JVbCwgdmMuX2NvbG9yVXIsIHZjLl9jb2xvckJsLCB2Yy5fY29sb3JCcl0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY29uc3QgYWxwaGEgPSAoY29sb3IgLyAxNjc3NzIxNiB8IDApIC8gMjU1O1xuICAgICAgICAgICAgY3R4Lmdsb2JhbEFscGhhICo9IGFscGhhO1xuICAgICAgICAgICAgY29uc3QgcmdiID0gY29sb3IgJiAxNjc3NzIxNTtcbiAgICAgICAgICAgIGNvbnN0IHRpbnRUZXh0dXJlID0gdGhpcy5fdGludE1hbmFnZXIuZ2V0VGludFRleHR1cmUodHgsIHJnYik7XG4gICAgICAgICAgICBjdHguZmlsbFN0eWxlID0gXCJ3aGl0ZVwiO1xuICAgICAgICAgICAgY3R4LmRyYXdJbWFnZSh0aW50VGV4dHVyZSwgc291cmNlWCwgc291cmNlWSwgc291cmNlVywgc291cmNlSCwgMCwgMCwgdmMudywgdmMuaCk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGN0eC5maWxsU3R5bGUgPSBcIndoaXRlXCI7XG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ZnVuY3Rpb24oKSB7XG4gICAgICAgICAgY2IobnVsbCwge1xuICAgICAgICAgICAgc291cmNlOiBpbWFnZSxcbiAgICAgICAgICAgIHJlbmRlckluZm86IHsgc3JjLCBjb21wcmVzc2VkOiBmYWxzZSB9LFxuICAgICAgICAgICAgaGFzQWxwaGE6IGlzUG5nIHx8IGhhc0FscGhhXG4gICAgICAgICAgfSk7XG4gICAgICAgIH07XG4gICAgICAgIGltYWdlLnNyYyA9IHNyYztcbiAgICAgICAgY2FuY2VsQ2IgPSBmdW5jdGlvbigpIHtcbiAgICAgICAgICBpbWFnZS5vbmVycm9yID0gbnVsbDtcbiAgICAgICAgICBpbWFnZS5vbmxvYWQgPSBudWxsO1xuICAgICAgICAgIGltYWdlLnJlbW92ZUF0dHJpYnV0ZShcInNyY1wiKTtcbiAgICAgICAgfTtcbiAgICAgIH1cbiAgICAgIHJldHVybiBjYW5jZWxDYjtcbiAgICB9XG4gICAgY3JlYXRlV2ViR0xDb250ZXh0KHcsIGgpIHtcbiAgICAgIGxldCBjYW52YXMgPSB0aGlzLnN0YWdlLmdldE9wdGlvbihcImNhbnZhc1wiKSB8fCBkb2N1bWVudC5jcmVhdGVFbGVtZW50KFwiY2FudmFzXCIpO1xuICAgICAgaWYgKHcgJiYgaCkge1xuICAgICAgICBjYW52YXMud2lkdGggPSB3O1xuICAgICAgICBjYW52YXMuaGVpZ2h0ID0gaDtcbiAgICAgIH1cbiAgICAgIGxldCBvcHRzID0ge1xuICAgICAgICBhbHBoYTogdHJ1ZSxcbiAgICAgICAgYW50aWFsaWFzOiBmYWxzZSxcbiAgICAgICAgcHJlbXVsdGlwbGllZEFscGhhOiB0cnVlLFxuICAgICAgICBzdGVuY2lsOiB0cnVlLFxuICAgICAgICBwcmVzZXJ2ZURyYXdpbmdCdWZmZXI6IGZhbHNlXG4gICAgICB9O1xuICAgICAgbGV0IGdsID0gY2FudmFzLmdldENvbnRleHQoXCJ3ZWJnbFwiLCBvcHRzKSB8fCBjYW52Y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W5ncyk7XG4gICAgICByZXR1cm4gdHJhbnNpdGlvblNldHRpbmdzO1xuICAgIH1cbiAgICBhZGRBY3RpdmUodHJhbnNpdGlvbikge1xuICAgICAgdGhpcy5hY3RpdmUuYWRkKHRyYW5zaXRpb24pO1xuICAgIH1cbiAgICByZW1vdmVBY3RpdmUodHJhbnNpdGlvbikge1xuICAgICAgdGhpcy5hY3RpdmUuZGVsZXRlKHRyYW5zaXRpb24pO1xuICAgIH1cbiAgfVxuICBjbGFzcyBNdWx0aVNwbGluZSB7XG4gICAgY29uc3RydWN0b3IoKSB7XG4gICAgICB0aGlzLl9jbGVhcigpO1xuICAgIH1cbiAgICBfY2xlYXIoKSB7XG4gICAgICB0aGlzLl9wID0gW107XG4gICAgICB0aGlzLl9wZSA9IFtdO1xuICAgICAgdGhpcy5faWRwID0gW107XG4gICAgICB0aGlzLl9mID0gW107XG4gICAgICB0aGlzLl92ID0gW107XG4gICAgICB0aGlzLl9sdiA9IFtdO1xuICAgICAgdGhpcy5fc20gPSBbXTtcbiAgICAgIHRoaXMuX3MgPSBbXTtcbiAgICAgIHRoaXMuX3ZlID0gW107XG4gICAgICB0aGlzLl9zbWUgPSBbXTtcbiAgICAgIHRoaXMuX3NlID0gW107XG4gICAgICB0aGlzLl9sZW5ndGggPSAwO1xuICAgIH1cbiAgICBwYXJzZShyZ2JhLCBkZWYpIHtcbiAgICAgIGxldCBpLCBuO1xuICAgICAgaWYgKCFVdGlscyQxLmlzT2JqZWN0TGl0ZXJhbChkZWYpKSB7XG4gICAgICAgIGRlZiA9IHsgMDogZGVmIH07XG4gICAgICB9XG4gICAgICBsZXQgZGVmYXVsdFNtb290aG5lc3MgPSAwLjU7XG4gICAgICBsZXQgaXRlbXMgPSBbXTtcbiAgICAgIGZvciAobGV0IGtleSBpbiBkZWYpIHtcbiAgICAgICAgaWYgKGRlZi5oYXNPd25Qcm9wZXJ0eShrZXkpKSB7XG4gICAgICAgICAgbGV0IG9iaiA9IGRlZltrZXldO1xuICAgICAgICAgIGlmICghVXRpbHMkMS5pc09iamVjdExpdGVyYWwob2JqKSkge1xuICAgICAgICAgICAgb2JqID0geyB2OiBvYmogfTtcbiAgICAgICAgICB9XG4gICAgICAgICAgbGV0IHAgPSBwYXJzZUZsb2F0KGtleSk7XG4gICAgICAgICAgaWYgKGtleSA9PT0gXCJzbVwiKSB7XG4gICAgICAgICAgICBkZWZhdWx0U21vb3RobmVzcyA9IG9iai52O1xuICAgICAgICAgIH0gZWxzZSBpZiAoIWlzTmFOKHApICYmIHAgPj0gMCAmJiBwIDw9IDIpIHtcbiAgICAgICAgICAgIG9iai5wID0gcDtcbiAgICAgICAgICAgIG9iai5mID0gVXRpbHMkMS5pc0Z1bmN0aW9uKG9iai52KTtcbiAgICAgICAgICAgIG9iai5sdiA9IG9iai5mID8gb2JqLnYoMCwgMCkgOiBvYmoudjtcbiAgICAgICAgICAgIGl0ZW1zLnB1c2gob2JqKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGl0ZW1zID0gaXRlbXMuc29ydChmdW5jdGlvbihhLCBiKSB7XG4gICAgICAgIHJldHVybiBhLnAgLSBiLnA7XG4gICAgICB9KTtcbiAgICAgIG4gPSBpdGVtcy5sZW5ndGg7XG4gICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgIGxldCBsYXN0ID0gaSA9PT0gbiAtIDE7XG4gICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoXCJwZVwiKSkge1xuICAgICAgICAgIGl0ZW1zW2ldLnBlID0gbGFzdCA/IGl0ZW1zW2ldLnAgPD0gMSA/IDEgOiAyIDogaXRlbXNbaSArIDFdLnA7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgY29uc3QgbWF4ID0gaSA8IG4gLSAxID8gaXRlbXNbaSArIDFdLnAgOiAxO1xuICAgICAgICAgIGlmIChpdGVtc1tpXS5wZSA+IG1heCkge1xuICAgICAgICAgICAgaXRlbXNbaV0ucGUgPSBtYXg7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmIChpdGVtc1tpXS5wZSA9PT0gaXRlbXNbaV0ucCkge1xuICAgICAgICAgIGl0ZW1zW2ldLmlkcCA9IDA7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaXRlbXNbaV0uaWRwID0gMSAvIChpdGVtc1tpXS5wZSAtIGl0ZW1zW2ldLnApO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoXCJzbVwiKSkge1xuICAgICAgICAgIGl0ZW1zW2ldLnNtID0gZGVmYXVsdFNtb290aG5lc3M7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCFpdGVtc1tpXS5oYXNPd25Qcm9wZXJ0eShcInNcIikpIHtcbiAgICAgICAgICBpZiAoaSA9PT0gMCB8fCBpID09PSBuIC0gMSB8fCBpdGVtc1tpXS5wID09PSAxKSB7XG4gICAgICAgICAgICBpdGVtc1tpXS5zID0gcmdiYSA/IFswLCAwLCAwLCAwXSA6IDA7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGNvbnN0IHBpID0gaXRlbXNbaSAtIDFdO1xuICAgICAgICAgICAgY29uc3QgbmkgPSBpdGVtc1tpICsgMV07XG4gICAgICAgICAgICBpZiAocGkucCA9PT0gbmkucCkge1xuICAgICAgICAgICAgICBpdGVtc1tpXS5zID0gcmdiYSA/IFswLCAwLCAwLCAwXSA6IDA7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBpZiAocmdiYSkge1xuICAgICAgICAgICAgICAgIGNvbnN0IG5jID0gTXVsdGlTcGxpbmUuZ2V0UmdiYUNvbXBvbmVudHMobmkubHYpO1xuICAgICAgICAgICAgICAgIGNvbnN0IHBjID0gTXVsdGlTcGxpbmUuZ2V0UmdiYUNvbXBvbmVudHMocGkubHYpO1xuICAgICAgICAgICAgICAgIGNvbnN0IGQgPSAxIC8gKG5pLnAgLSBwaS5wKTtcbiAgICAgICAgICAgICAgICBpdGVtc1tpXS5zID0gW1xuICAgICAgICAgICAgICAgICAgZCAqIChuY1swXSAtIHBjWzBdKSxcbiAgICAgICAgICAgICAgICAgIGQgKiAobmNbMV0gLSBwY1sxXSksXG4gICAgICAgICAgICAgICAgICBkICogKG5jWzJdIC0gcGNbMl0pLFxuICAgICAgICAgICAgICAgICAgZCAqIChuY1szXSAtIHBjWzNdKVxuICAgICAgICAgICAgICAgIF07XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaXRlbXNbaV0ucyA9IChuaS5sdiAtIHBpLmx2KSAvIChuaS5wIC0gcGkucCk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGZvciAoaSA9IDA7IGkgPCBuIC0gMTsgaSsrKSB7XG4gICAgICAgIGlmICghaXRlbXNbaV0uZikge1xuICAgICAgICAgIGxldCBsYXN0ID0gaSA9PT0gbiAtIDE7XG4gICAgICAgICAgaWYgKCFpdGVtc1tpXS5oYXNPd25Qcm9wZXJ0eShcInZlXCIpKSB7XG4gICAgICAgICAgICBpdGVtc1tpXS52ZSA9IGxhc3QgPyBpdGVtc1tpXS5sdiA6IGl0ZW1zW2kgKyAxXS5sdjtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKFV0aWxzJDEuaXNOdW1iZXIoaXRlbXNbaV0udikgJiYgVXRpbHMkMS5pc051bWJlcihpdGVtc1tpXS5sdikpIHtcbiAgICAgICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoXCJzbWVcIikpIHtcbiAgICAgICAgICAgICAgaXRlbXNbaV0uc21lID0gbGFzdCA/IGRlZmF1bHRTbW9vdGhuZXNzIDogaXRlbX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uICAgICAgICAgIGlmIChwID09PSAxKVxuICAgICAgICAgICAgcmV0dXJuIHYyO1xuICAgICAgICAgIHJldHVybiB2MiAqIHAgKyB2MSAqICgxIC0gcCk7XG4gICAgICAgIH07XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24ocCkge1xuICAgICAgICAgIGlmIChwID09PSAwKVxuICAgICAgICAgICAgcmV0dXJuIHYxO1xuICAgICAgICAgIGlmIChwID09PSAxKVxuICAgICAgICAgICAgcmV0dXJuIHYyO1xuICAgICAgICAgIHJldHVybiBNdWx0aVNwbGluZS5jYWxjdWxhdGVTcGxpbmUoaGVscGVycywgcCk7XG4gICAgICAgIH07XG4gICAgICB9XG4gICAgfVxuICAgIHN0YXRpYyBnZXRTcGxpbmVSZ2JhVmFsdWVGdW5jdGlvbih2MSwgdjIsIHAxLCBwMiwgbzEsIGkyLCBzMSwgczIpIHtcbiAgICAgIGxldCBkcCA9IHAyIC0gcDE7XG4gICAgICBzMVswXSAqPSBkcDtcbiAgICAgIHMxWzFdICo9IGRwO1xuICAgICAgczFbMl0gKj0gZHA7XG4gICAgICBzMVszXSAqPSBkcDtcbiAgICAgIHMyWzBdICo9IGRwO1xuICAgICAgczJbMV0gKj0gZHA7XG4gICAgICBzMlsyXSAqPSBkcDtcbiAgICAgIHMyWzNdICo9IGRwO1xuICAgICAgbGV0IGN2MSA9IE11bHRpU3BsaW5lLmdldFJnYmFDb21wb25lbnRzKHYxKTtcbiAgICAgIGxldCBjdjIgPSBNdWx0aVNwbGluZS5nZXRSZ2JhQ29tcG9uZW50cyh2Mik7XG4gICAgICBsZXQgaGVscGVycyA9IFtcbiAgICAgICAgTXVsdGlTcGxpbmUuZ2V0U3BsaW5lSGVscGVycyhjdjFbMF0sIGN2MlswXSwgbzEsIGkyLCBzMVswXSwgczJbMF0pLFxuICAgICAgICBNdWx0aVNwbGluZS5nZXRTcGxpbmVIZWxwZXJzKGN2MVsxXSwgY3YyWzFdLCBvMSwgaTIsIHMxWzFdLCBzMlsxXSksXG4gICAgICAgIE11bHRpU3BsaW5lLmdldFNwbGluZUhlbHBlcnMoY3YxWzJdLCBjdjJbMl0sIG8xLCBpMiwgczFbMl0sIHMyWzJdKSxcbiAgICAgICAgTXVsdGlTcGxpbmUuZ2V0U3BsaW5lSGVscGVycyhjdjFbM10sIGN2MlszXSwgbzEsIGkyLCBzMVszXSwgczJbM10pXG4gICAgICBdO1xuICAgICAgaWYgKCFoZWxwZXJzWzBdKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbihwKSB7XG4gICAgICAgICAgaWYgKHAgPT09IDApXG4gICAgICAgICAgICByZXR1cm4gdjE7XG4gICAgICAgICAgaWYgKHAgPT09IDEpXG4gICAgICAgICAgICByZXR1cm4gdjI7XG4gICAgICAgICAgcmV0dXJuIE11bHRpU3BsaW5lLm1lcmdlQ29sb3JzKHYyLCB2MSwgcCk7XG4gICAgICAgIH07XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24ocCkge1xuICAgICAgICAgIGlmIChwID09PSAwKVxuICAgICAgICAgICAgcmV0dXJuIHYxO1xuICAgICAgICAgIGlmIChwID09PSAxKVxuICAgICAgICAgICAgcmV0dXJuIHYyO1xuICAgICAgICAgIHJldHVybiBNdWx0aVNwbGluZS5nZXRBcmdiTnVtYmVyKFtcbiAgICAgICAgICAgIE1hdGgubWluKDI1NSwgTXVsdGlTcGxpbmUuY2FsY3VsYXRlU3BsaW5lKGhlbHBlcnNbMF0sIHApKSxcbiAgICAgICAgICAgIE1hdGgubWluKDI1NSwgTXVsdGlTcGxpbmUuY2FsY3VsYXRlU3BsaW5lKGhlbHBlcnNbMV0sIHApKSxcbiAgICAgICAgICAgIE1hdGgubWluKDI1NSwgTXVsdGlTcGxpbmUuY2FsY3VsYXRlU3BsaW5lKGhlbHBlcnNbMl0sIHApKSxcbiAgICAgICAgICAgIE1hdGgubWluKDI1NSwgTXVsdGlTcGxpbmUuY2FsY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EgPT09IC0yICYmIHhjID09PSAwICYmIHljID09PSAwKSB7XG4gICAgICAgIHJldHVybiBwO1xuICAgICAgfVxuICAgICAgbGV0IHQgPSAwLjUsIGNieCwgZHg7XG4gICAgICBmb3IgKGxldCBpdCA9IDA7IGl0IDwgMjA7IGl0KyspIHtcbiAgICAgICAgY2J4ID0gdCAqICh0ICogKHQgKiB4YSArIHhiKSArIHhjKTtcbiAgICAgICAgZHggPSBwIC0gY2J4O1xuICAgICAgICBpZiAoZHggPiAtMWUtOCAmJiBkeCA8IDFlLTgpIHtcbiAgICAgICAgICByZXR1cm4gdCAqICh0ICogKHQgKiB5YSArIHliKSArIHljKSArIHlkO1xuICAgICAgICB9XG4gICAgICAgIGxldCBjYnhkID0gdCAqICh0ICogKDMgKiB4YSkgKyAyICogeGIpICsgeGM7XG4gICAgICAgIGlmIChjYnhkID4gMWUtMTAgJiYgY2J4ZCA8IDFlLTEwKSB7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgdCArPSBkeCAvIGNieGQ7XG4gICAgICB9XG4gICAgICBsZXQgbWluVCA9IDA7XG4gICAgICBsZXQgbWF4VCA9IDE7XG4gICAgICBmb3IgKGxldCBpdCA9IDA7IGl0IDwgMjA7IGl0KyspIHtcbiAgICAgICAgdCA9IDAuNSAqIChtaW5UICsgbWF4VCk7XG4gICAgICAgIGNieCA9IHQgKiAodCAqICh0ICogeGEgKyB4YikgKyB4Yyk7XG4gICAgICAgIGR4ID0gcCAtIGNieDtcbiAgICAgICAgaWYgKGR4ID4gLTFlLTggJiYgZHggPCAxZS04KSB7XG4gICAgICAgICAgcmV0dXJuIHQgKiAodCAqICh0ICogeWEgKyB5YikgKyB5YykgKyB5ZDtcbiAgICAgICAgfVxuICAgICAgICBpZiAoZHggPCAwKSB7XG4gICAgICAgICAgbWF4VCA9IHQ7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgbWluVCA9IHQ7XG4gICAgICAgIH1cbiAgICAgIH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aXMuX3AgPCAxKSB7XG4gICAgICAgICAgICAgIHRoaXMuX3AgKz0gZHQgLyB0aGlzLnNldHRpbmdzLmR1cmF0aW9uO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgdGhpcy5fcCArPSBkdCAvIGR1cmF0aW9uO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAodGhpcy5fcCA+PSAyKSB7XG4gICAgICAgICAgICB0aGlzLl9wID0gMjtcbiAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gQW5pbWF0aW9uLlNUQVRFUy5TVE9QUEVEO1xuICAgICAgICAgICAgdGhpcy5lbWl0KFwic3RvcEZpbmlzaFwiKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5lbWl0KFwicHJvZ3Jlc3NcIiwgdGhpcy5fcCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9IGVsc2UgaWYgKHRoaXMuc2V0dGluZ3Muc3RvcE1ldGhvZCA9PSBBbmltYXRpb25TZXR0aW5ncy5TVE9QX01FVEhPRFMuRk9SV0FSRCkge1xuICAgICAgICBpZiAodGhpcy5fcCA8IDEpIHtcbiAgICAgICAgICBpZiAodGhpcy5zZXR0aW5ncy5kdXJhdGlvbiA9PSAwKSB7XG4gICAgICAgICAgICB0aGlzLl9wID0gMTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fcCArPSBkdCAvIHRoaXMuc2V0dGluZ3MuZHVyYXRpb247XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmICh0aGlzLl9wID49IDEpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLnNldHRpbmdzLnN0b3BNZXRob2QgPT0gQW5pbWF0aW9uU2V0dGluZ3MuU1RPUF9NRVRIT0RTLkZPUldBUkQpIHtcbiAgICAgICAgICAgICAgdGhpcy5fcCA9IDE7XG4gICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gQW5pbWF0aW9uLlNUQVRFUy5TVE9QUEVEO1xuICAgICAgICAgICAgICB0aGlzLmVtaXQoXCJzdG9wRmluaXNoXCIpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgaWYgKHRoaXMuX3JlcGVhdHNMZWZ0ID4gMCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3JlcGVhdHNMZWZ0LS07XG4gICAgICAgICAgICAgICAgdGhpcy5fcCA9IDA7XG4gICAgICAgICAgICAgICAgdGhpcy5lbWl0KFwicmVwZWF0XCIsIHRoaXMuX3JlcGVhdHNMZWZ0KTtcbiAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9wID0gMTtcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IEFuaW1hdGlvbi5TVEFURVMuU1RPUFBFRDtcbiAgICAgICAgICAgICAgICB0aGlzLmVtaXQoXCJzdG9wRmluaXNoXCIpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuZW1pdChcInByb2dyZXNzXCIsIHRoaXMuX3ApO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBfcHJvZ3Jlc3NTdG9wVHJhbnNpdGlvbihkdCkge1xuICAgICAgaWYgKHRoaXMuX3N0b3BQIDwgMSkge1xuICAgICAgICBpZiAodGhpcy5fc3RvcERlbGF5TGVmdCA+IDApIHtcbiAgICAgICAgICB0aGlzLl9zdG9wRGVsYXlMZWZ0IC09IGR0O1xuICAgICAgICAgIGlmICh0aGlzLl9zdG9wRGVsYXlMZWZ0IDwgMCkge1xuICAgICAgICAgICAgZHQgPSAtdGhpcy5fc3RvcERlbGF5TGVmdDtcbiAgICAgICAgICAgIHRoaXMuX3N0b3BEZWxheUxlZnQgPSAwO1xuICAgICAgICAgICAgdGhpcy5lbWl0KFwiZGV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Zy5jcm9zc09yaWdpbiA9IFwiQW5vbnltb3VzXCI7XG4gICAgICB9XG4gICAgICBpbWcuc3JjID0gdXJsO1xuICAgIH1cbiAgfVxuICBjbGFzcyBPYmpNZXJnZXIge1xuICAgIHN0YXRpYyBpc01mKGYpIHtcbiAgICAgIHJldHVybiBVdGlscyQxLmlzRnVuY3Rpb24oZikgJiYgZi5fX21mO1xuICAgIH1cbiAgICBzdGF0aWMgbWYoZikge1xuICAgICAgZi5fX21mID0gdHJ1ZTtcbiAgICAgIHJldHVybiBmO1xuICAgIH1cbiAgICBzdGF0aWMgbWVyZ2UoYSwgYikge1xuICAgICAgY29uc3QgYWtzID0gT2JqZWN0LmtleXMoYSk7XG4gICAgICBjb25zdCBia3MgPSBPYmplY3Qua2V5cyhiKTtcbiAgICAgIGlmICghYmtzLmxlbmd0aCkge1xuICAgICAgICByZXR1cm4gYTtcbiAgICAgIH1cbiAgICAgIGNvbnN0IGFpID0ge307XG4gICAgICBjb25zdCBiaSA9IHt9O1xuICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBia3MubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgIGNvbnN0IGtleSA9IGJrc1tpXTtcbiAgICAgICAgYWlba2V5XSA9IC0xO1xuICAgICAgICBiaVtrZXldID0gaTtcbiAgICAgIH1cbiAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gYWtzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICBjb25zdCBrZXkgPSBha3NbaV07XG4gICAgICAgIGFpW2tleV0gPSBpO1xuICAgICAgICBpZiAoYmlba2V5XSA9PT0gdm9pZCAwKSB7XG4gICAgICAgICAgYmlba2V5XSA9IC0xO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICBjb25zdCBha3NsID0gYWtzLmxlbmd0aDtcbiAgICAgIGNvbnN0IHJlc3VsdCA9IHt9O1xuICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBia3MubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgIGNvbnN0IGtleSA9IGJrc1tpXTtcbiAgICAgICAgY29uc3QgYUluZGV4ID0gYWlba2V5XTtcbiAgICAgICAgbGV0IGN1ckluZGV4MiA9IGFJbmRleDtcbiAgICAgICAgd2hpbGUgKC0tY3VySW5kZXgyID49IDApIHtcbiAgICAgICAgICBjb25zdCBha2V5ID0gYWtzW2N1ckluZGV4Ml07XG4gICAgICAgICAgaWYgKGJpW2FrZXldICE9PSAtMSkge1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHdoaWxlICgrK2N1ckluZGV4MiA8IGFJbmRleCkge1xuICAgICAgICAgIGNvbnN0IGFrZXkgPSBha3NbY3VySW5kZXgyXTtcbiAgICAgICAgICByZXN1bHRbYWtleV0gPSBhW2FrZXldO1xuICAgICAgICB9XG4gICAgICAgIGNvbnN0IGJ2ID0gYltrZXldO1xuICAgICAgICBjb25zdCBhdiA9IGFba2V5XTtcbiAgICAgICAgbGV0IHI7XG4gICAgICAgIGlmICh0aGlzLmlzTWYoYnYpKSB7XG4gICAgICAgICAgciA9IGJ2KGF2KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBpZiAoIVV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKGF2KSB8fCAhVXRpbHMkMS5pc09iamVjdExpdGVyYWwoYnYpKSB7XG4gICAgICAgICAgICByID0gYnY7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHIgPSBPYmpNZXJnZXIubWVyZ2UoYXYsIGJ2KTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHIgIT09IHZvaWQgMCkge1xuICAgICAgICAgIHJlc3VsdFtrZXldID0gcjtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgbGV0IGN1ckluZGV4ID0gYWtzbDtcbiAgICAgIHdoaWxlICgtLWN1ckluZGV4ID49IDApIHtcbiAgICAgICA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XRoLmNlaWwodiAvIHRoaXMuX2l0ZW1TaXplKTtcbiAgICAgICAgcHMgPSAxICsgdiAvIHRoaXMuX2l0ZW1TaXplIC0gcztcbiAgICAgICAgZSA9IE1hdGguY2VpbCgodiAtIHZpZXdwb3J0U2l6ZSkgLyB0aGlzLl9pdGVtU2l6ZSk7XG4gICAgICAgIHBlID0gZSAtICh2IC0gdmlld3BvcnRTaXplKSAvIHRoaXMuX2l0ZW1TaXplO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMuX3JvbGwgfHwgdmlld3BvcnRTaXplID4gdGhpcy5faXRlbVNpemUgKiBuRWxlbWVudHMpIHtcbiAgICAgICAgaWYgKGUgPj0gbkVsZW1lbnRzKSB7XG4gICAgICAgICAgZSA9IG5FbGVtZW50cyAtIDE7XG4gICAgICAgICAgcGUgPSAxO1xuICAgICAgICB9XG4gICAgICAgIGlmIChzID49IG5FbGVtZW50cykge1xuICAgICAgICAgIHMgPSBuRWxlbWVudHMgLSAxO1xuICAgICAgICAgIHBzID0gMTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoZSA8PSAtMSkge1xuICAgICAgICAgIGUgPSAwO1xuICAgICAgICAgIHBlID0gMTtcbiAgICAgICAgfVxuICAgICAgICBpZiAocyA8PSAtMSkge1xuICAgICAgICAgIHMgPSAwO1xuICAgICAgICAgIHBzID0gMTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgbGV0IG9mZnNldCA9IC1kaXJlY3Rpb24gKiBzICogdGhpcy5faXRlbVNpemU7XG4gICAgICBsZXQgaXRlbTtcbiAgICAgIGZvciAobGV0IGluZGV4ID0gczsgZGlyZWN0aW9uID09IC0xID8gaW5kZXggPD0gZSA6IGluZGV4ID49IGU7IGRpcmVjdGlvbiA9PSAtMSA/IGluZGV4KysgOiBpbmRleC0tKSB7XG4gICAgICAgIGxldCByZWFsSW5kZXggPSBVdGlscyQxLmdldE1vZHVsb0luZGV4KGluZGV4LCBuRWxlbWVudHMpO1xuICAgICAgICB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gpIHtcbiAgICAgICAgICBjb25zdCB3ID0gZWxlbWVudENvcmUudztcbiAgICAgICAgICBjb25zdCBoID0gZWxlbWVudENvcmUuaDtcbiAgICAgICAgICBsZXQgY3VyID0gZWxlbWVudENvcmU7XG4gICAgICAgICAgZG8ge1xuICAgICAgICAgICAgY3VyID0gY3VyLl9jaGlsZHJlblswXTtcbiAgICAgICAgICAgIGN1ci5fZWxlbWVudC53ID0gdztcbiAgICAgICAgICAgIGN1ci5fZWxlbWVudC5oID0gaDtcbiAgICAgICAgICB9IHdoaWxlIChjdXIuX2NoaWxkcmVuKTtcbiAgICAgICAgfVxuICAgICAgfTtcbiAgICAgIHJldHVybiB7XG4gICAgICAgIFRleHR3cmFwOiB7XG4gICAgICAgICAgcnR0OiB0cnVlLFxuICAgICAgICAgIGZvcmNlWkluZGV4Q29udGV4dDogdHJ1ZSxcbiAgICAgICAgICByZW5kZXJPZmZzY3JlZW46IHRydWUsXG4gICAgICAgICAgQmxvb21CYXNlOiB7XG4gICAgICAgICAgICBzaGFkZXI6IHsgdHlwZTogQmxvb21CYXNlU2hhZGVyIH0sXG4gICAgICAgICAgICBDb250ZW50OiB7fVxuICAgICAgICAgIH1cbiAgICAgICAgfSxcbiAgICAgICAgTGF5ZXJzOiB7XG4gICAgICAgICAgTDA6IHsgcnR0OiB0cnVlLCBvblVwZGF0ZSwgc2NhbGU6IDIsIHBpdm90OiAwLCB2aXNpYmxlOiBmYWxzZSwgQ29udGVudDogeyBzaGFkZXI6IHsgdHlwZTogQm94Qmx1clNoYWRlciB9IH0gfSxcbiAgICAgICAgICBMMTogeyBydHQ6IHRydWUsIG9uVXBkYXRlLCBzY2FsZTogNCwgcGl2b3Q6IDAsIHZpc2libGU6IGZhbHNlLCBDb250ZW50OiB7IHNoYWRlcjogeyB0eXBlOiBCb3hCbHVyU2hhZGVyIH0gfSB9LFxuICAgICAgICAgIEwyOiB7IHJ0dDogdHJ1ZSwgb25VcGRhdGUsIHNjYWxlOiA4LCBwaXZ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AgICB9XG4gICAgc3RhdGljIF91cGRhdGVEaW1lbnNpb25zKGNvbnRlbnRXcmFwLCBmb3JjZSkge1xuICAgICAgY29uc3QgY29udGVudCA9IGNvbnRlbnRXcmFwLmNoaWxkcmVuWzBdO1xuICAgICAgbGV0IHcgPSBjb250ZW50LnJlbmRlcldpZHRoO1xuICAgICAgbGV0IGggPSBjb250ZW50LnJlbmRlckhlaWdodDtcbiAgICAgIGlmICh3ICE9PSBjb250ZW50V3JhcC53IHx8IGggIT09IGNvbnRlbnRXcmFwLmggfHwgZm9yY2UpIHtcbiAgICAgICAgY29udGVudFdyYXAudyA9IHc7XG4gICAgICAgIGNvbnRlbnRXcmFwLmggPSBoO1xuICAgICAgICBjb25zdCBzY2FsZXJzID0gY29udGVudFdyYXAucGFyZW50LnRhZyhcIlNjYWxlXCIpLmNoaWxkcmVuO1xuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHNjYWxlcnMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgdyA9IHcgKiAwLjU7XG4gICAgICAgICAgaCA9IGggKiAwLjU7XG4gICAgICAgICAgc2NhbGVyc1tpXS53ID0gdztcbiAgICAgICAgICBzY2FsZXJzW2ldLmggPSBoO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIGdldCBfc2lnbmFsUHJveHkoKSB7XG4gICAgICByZXR1cm4gdHJ1ZTtcbiAgICB9XG4gIH1cbiAgY2xhc3MgQm9yZGVyQ29tcG9uZW50IGV4dGVuZHMgQ29tcG9uZW50IHtcbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgcmV0dXJuIHtcbiAgICAgICAgQ29udGVudDoge30sXG4gICAgICAgIEJvcmRlcnM6IHtcbiAgICAgICAgICBUb3A6IHsgcmVjdDogdHJ1ZSwgdmlzaWJsZTogZmFsc2UsIG1vdW50WTogMSB9LFxuICAgICAgICAgIFJpZ2h0OiB7IHJlY3Q6IHRydWUsIHZpc2libGU6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ICAgdmVjMiBwb3MyID0gdmVjMihwb2ludC54IC0gcmVzb2x1dGlvbi54LCB2VGV4dHVyZUNvb3JkLnkpO1xuICAgICAgICAgICAgZCA9IHBvczEgLSBwb3MyO1xuICAgICAgICAgICAgYyA9IGRvdChwb3MyLCBkKSAvIGRvdChkLCBkKTtcbiAgICAgICAgICAgIHQgPSBzbW9vdGhzdGVwKDAuMCwgMS4wLCBjbGFtcChjLCAwLjAsIDEuMCkpO1xuICAgICAgICAgICAgY29sb3IgPSBtaXgodmVjNCgwLjApLCBjb2xvciwgdCk7XG4gICAgICAgIH1cbiAgICAgICAgXG4gICAgICAgIGlmKGZhZGVbMl0gPiAwLjApIHtcbiAgICAgICAgICAgIHZlYzIgcG9zMSA9IHZlYzIodlRleHR1cmVDb29yZC54LCBwb2ludC55IC0gcmVzb2x1dGlvbi55IC0gZmFkZVsyXSk7XG4gICAgICAgICAgICB2ZWMyIHBvczIgPSB2ZWMyKHZUZXh0dXJlQ29vcmQueCwgcG9pbnQueSAtIHJlc29sdXRpb24ueSk7XG4gICAgICAgICAgICBkID0gcG9zMSAtIHBvczI7XG4gICAgICAgICAgICBjID0gZG90KHBvczIsIGQpIC8gZG90KGQsIGQpO1xuICAgICAgICAgICAgdCA9IHNtb290aHN0ZXAoMC4wLCAxLjAsIGNsYW1wKGMsIDAuMCwgMS4wKSk7XG4gICAgICAgICAgICBjb2xvciA9IG1peCh2ZWM0KDAuMCksIGNvbG9yLCB0KTtcbiAgICAgICAgfVxuICAgICAgICBcbiAgICAgICAgaWYoZmFkZVszXSA+IDAuMCkge1xuICAgICAgICAgICAgcG9zMSA9IHZlYzIocG9pbnQueCwgcG9pbnQueSk7XG4gICAgICAgICAgICBwb3MyID0gdmVjMihwb2ludC54ICsgZmFkZVszXSwgcG9pbnQueSk7XG4gICAgICAgICAgICBkID0gcG9zMiAtIHBvczE7XG4gICAgICAgICAgICBjID0gZG90KHBvczEsIGQpIC8gZG90KGQsIGQpO1xuICAgICAgICAgICAgdC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Rpb25bbmFtZV0sIGxpc3RlbmVyXTtcbiAgICAgICAgICAgICAgICB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdID0gRXZlbnRFbWl0dGVyLmNvbWJpbmVyO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9ldmVudExpc3RlbmVyc1tuYW1lXS5wdXNoKGxpc3RlbmVyKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIG9uY2UobmFtZSwgbGlzdGVuZXIpIHtcbiAgICAgICAgY29uc3Qgd3JhcHBlciA9IChhcmcxLCBhcmcyLCBhcmczKSA9PiB7XG4gICAgICAgICAgICBsaXN0ZW5lcihhcmcxLCBhcmcyLCBhcmczKTtcbiAgICAgICAgICAgIHRoaXMub2ZmKG5hbWUsIHdyYXBwZXIpO1xuICAgICAgICB9XG4gICAgICAgIHdyYXBwZXIuX19vcmlnaW5hbEZ1bmMgPSBsaXN0ZW5lcjtcbiAgICAgICAgdGhpcy5vbihuYW1lLCB3cmFwcGVyKTtcbiAgICB9XG5cbiAgICBoYXMobmFtZSwgbGlzdGVuZXIpIHtcbiAgICAgICAgaWYgKHRoaXMuX2hhc0V2ZW50TGlzdGVuZXJzKSB7XG4gICAgICAgICAgICBjb25zdCBjdXJyZW50ID0gdGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXTtcbiAgICAgICAgICAgIGlmIChjdXJyZW50KSB7XG4gICAgICAgICAgICAgICAgaWYgKGN1cnJlbnQgPT09IEV2ZW50RW1pdHRlci5jb21iaW5lcikge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBsaXN0ZW5lcnMgPSB0aGlzLl9ldmVudExpc3RlbmVyc1tuYW1lXTtcbiAgICAgICAgICAgICAgICAgICAgZm9yIChjb25zdCBsIG9mIGxpc3RlbmVycykge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGwgPT09IGxpc3RlbmVyIHx8IGwuX19vcmlnaW5hbEZ1bmMgPT0gbGlzdGVuZXIpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXSA9PT0gbGlzdGVuZXIgfHwgdGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXS5fX29yaWdpbmFsRnVuYyA9PT0gbGlzdGVuZXIpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9XG5cbiAgICBvZmYobmFtZSwgbGlzdGVuZXIpIHtcbiAgICAgICAgaWYgKHRoaXMuX2hhc0V2ZW50TGlzdGVuZXJzKSB7XG4gICAgICAgICAgICBjb25zdCBjdXJyZW50ID0gdGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXTtcbiAgICAgICAgICAgIGlmIChjdXJyZW50KSB7XG4gICAgICAgICAgICAgICAgaWYgKGN1cnJlbnQgPT09IEV2ZW50RW1pdHRlci5jb21iaW5lcikge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBsaXN0ZW5lcnMgPSB0aGlzLl9ldmVudExpc3RlbmVyc1tuYW1lXTtcbiAgICAgICAgICAgICAgICAgICAgbGV0IGluZGV4ID0gbGlzdGVuZXJzLmluZGV4T2YobGlzdGVuZXIpO1xuICAgICAgICAgICAgICAgICAgICBpZiAoaW5kZXggPj0gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgbGlzdGVuZXJzLnNwbGljZShpbmRleCwgMSk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgaW5kZXggPSBsaXN0ZW5lcnMubWFwKChsKSA9PiBsLl9fb3JpZ2luYWxGdW5jKS5pbmRleE9mKGxpc3RlbmVyKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGluZGV4ID49IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxpc3RlbmVycy5zcGxpY2UoaW5kZXgsIDEpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGlmIChsaXN0ZW5lcnMubGVuZ3RoID09PSAxKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdID0gbGlzdGVuZXJzWzBdO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fZXZlbnRMaXN0ZW5lcnNbbmFtZV0gPSB1bmRlZmluZWQ7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2V2ZW50RnVuY3Rpb25bbmFtZV0gPT09IGxpc3RlbmVyIHx8IHRoaXMuX2V2ZW50RnVuY3Rpb25bbmFtZV0uX19vcmlnaW5hbEZ1bmMgPT09IGxpc3RlbmVyKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2V2ZW50RnVuY3Rpb25bbmFtZV0gPSB1bmRlZmluZWQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgcmVtb3ZlTGlzdGVuZXIobmFtZSwgbGlzdGVuZXIpIHtcbiAgICAgICAgdGhpcy5vZmYobmFtZSwgbGlzdGVuZXIpO1xuICAgIH1cblxuICAgIGVtaXQobmFtZSwgYXJnMSwgYXJnMiwgYXJnMykge1xuICAgICAgICBpZiAodGhpcy5faGFzRXZlbnRMaXN0ZW5lcnMpIHtcbiAgICAgICAgICAgIGNvbnN0IGZ1bmMgPSB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdO1xuICAgICAgICAgICAgaWYgKGZ1bmMpIHtcbiAgICAgICAgICAgICAgICBpZiAoZnVuYyA9PT0gRXZlbnRFbWl0dGVyLmNvbWJpbmVyKSB7XG4gICAgICAgICAgICAgICAgICAgIGZ1bmModGhpcywgbmFtZSwgYXJnMSwgYXJnMiwgYXJnMyk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgZnVuYyhhcmcxLCBhcmcyLCBhcmczKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBsaXN0ZW5lckNvdW50KG5hbWUpIHtcbiAgICAgICAgaWYgKHRoaXMuX2hhc0V2ZW50TGlzdGVuZXJzKSB7XG4gICAgICAgICAgICBjb25zdCBmdW5jID0gdGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXTtcbiAgICAgICAgICAgIGlmIChmdW5jKSB7XG4gICAgICAgICAgICAgICAgaWYgKGZ1bmMgPT09IEV2ZW50RW1pdHRlci5jb21iaW5lcikge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5fZXZlbnRMaXN0ZW5lcnNbbmFtZV0ubGVuZ3RoO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gMDtcbiAgICB9XG5cbiAgICByZW1vdmVBbGxMaXN0ZW5lcnMobmFtZSkge1xuICAgICAgICBpZiAodGhpcy5faGFzRXZlbnRMaXN0ZW5lcnMpIHtcbiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdO1xuICAgICAgICAgICAgZGVsZXRlIHRoaXMuX2V2ZW50TGlzdGVuZXJzW25hbWVdO1xuICAgICAgICB9XG4gICAgfVxuXG59XG5cbkV2ZW50RW1pdHRlci5jb21iaW5lciA9IGZ1bmN0aW9uKG9iamVjdCwgbmFtZSwgYXJnMSwgYXJnM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KGR0KSB7XG4gICAgICAgIGlmICghdGhpcy5fZWxlbWVudCkgcmV0dXJuO1xuICAgICAgICB0aGlzLl9wcm9ncmVzcyhkdCk7XG4gICAgICAgIHRoaXMuYXBwbHkoKTtcbiAgICB9XG5cbiAgICBfcHJvZ3Jlc3MoZHQpIHtcbiAgICAgICAgaWYgKHRoaXMuX3N0YXRlID09IEFuaW1hdGlvbi5TVEFURVMuU1RPUFBJTkcpIHtcbiAgICAgICAgICAgIHRoaXMuX3N0b3BQcm9ncmVzcyhkdCk7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5fc3RhdGUgIT0gQW5pbWF0aW9uLlNUQVRFUy5QTEFZSU5HKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5fZGVsYXlMZWZ0ID4gMCkge1xuICAgICAgICAgICAgdGhpcy5fZGVsYXlMZWZ0IC09IGR0O1xuXG4gICAgICAgICAgICBpZiAodGhpcy5fZGVsYXlMZWZ0IDwgMCkge1xuICAgICAgICAgICAgICAgIGR0ID0gLXRoaXMuX2RlbGF5TGVmdDtcbiAgICAgICAgICAgICAgICB0aGlzLl9kZWxheUxlZnQgPSAwO1xuXG4gICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdkZWxheUVuZCcpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5zZXR0aW5ncy5kdXJhdGlvbiA9PT0gMCkge1xuICAgICAgICAgICAgdGhpcy5fcCA9IDE7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5zZXR0aW5ncy5kdXJhdGlvbiA+IDApIHtcbiAgICAgICAgICAgIHRoaXMuX3AgKz0gZHQgLyB0aGlzLnNldHRpbmdzLmR1cmF0aW9uO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9wID49IDEpIHtcbiAgICAgICAgICAgIC8vIEZpbmlzaGVkITtcbiAgICAgICAgICAgIGlmICh0aGlzLnNldHRpbmdzLnJlcGVhdCA9PSAtMSB8fCB0aGlzLl9yZXBlYXRzTGVmdCA+IDApIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fcmVwZWF0c0xlZnQgPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlcGVhdHNMZWZ0LS07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHRoaXMuX3AgPSB0aGlzLnNldHRpbmdzLnJlcGVhdE9mZnNldDtcbiAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3Byb2dyZXNzJywgdGhpcy5fcCk7XG4gICAgICAgICAgICAgICAgXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuc2V0dGluZ3MucmVwZWF0RGVsYXkpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZGVsYXlMZWZ0ID0gdGhpcy5zZXR0aW5ncy5yZXBlYXREZWxheTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3JlcGVhdCcsIHRoaXMuX3JlcGVhdHNMZWZ0KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcCA9IDE7XG4gICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdwcm9ncmVzcycsIHRoaXMuX3ApO1xuICAgICAgICAgICAgICAgIFxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gQW5pbWF0aW9uLlNUQVRFUy5GSU5JU0hFRDtcbiAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ2ZpbmlzaCcpO1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLnNldHRpbmdzLmF1dG9zdG9wKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3RvcCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuZW1pdCgncHJvZ3Jlc3MnLCB0aGlzLl9wKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBcbiAgICBfc3RvcFByb2dyZXNzKGR0KSB7XG4gICAgICAgIGxldCBkdXJhdGlvbiA9IHRoaXMuX2dldFN0b3BEdXJhdGlvbigpO1xuXG4gICAgICAgIGlmICh0aGlzLl9zdG9wRGVsYXlMZWZ0ID4gMCkge1xuICAgICAgICAgICAgdGhpcy5fc3RvcERlbGF5TGVmdCAtPSBkdDtcblxuICAgICAgICAgICAgaWYgKHRoaXMuX3N0b3BEZWxheUxlZnQgPCAwKSB7XG4gICAgICAgICAgICAgICAgZHQgPSAtdGhpcy5fc3RvcERlbGF5TGVmdDtcbiAgICAgICAgICAgICAgICB0aGlzLl9zdG9wRGVsYXlMZWZ0ID0gMDtcblxuICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgnc3RvcERlbGF5RW5kJyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5zZXR0aW5ncy5zdG9wTWV0aG9kID09IEFuaW1hdGlvblNldHRpbmdzLlNUT1BfTUVUSE9EUy5JTU1FRElBVEUpIHtcbiAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gQW5pbWF0aW9uLlNUQVRFUy5TVE9QUEVEO1xuICAgICAgICAgICAgdGhpcy5lbWl0KCdzdG9wRmluaXNoJyk7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5zZXR0aW5ncy5zdG9wTWV0aG9kID09IEFuaW1hdGlvblNldHRpbmdzLlNUT1BfTUVUSE9EUy5SRVZFUlNFKSB7XG4gICAgICAgICAgICBpZiAoZHVyYXRpb24gPT09IDApIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9wID0gMDtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoZHVyYXRpb24gPiAwKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcCAtPSBkdCAvIGR1cmF0aW9uO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAodGhpcy5fcCA8PSAwKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcCA9IDA7XG4gICAgICAgICAgICAgICAgdGhpcy5fc3RhdGUgPSBBbmltYXRpb24uU1RBVEVTLlNUT1BQRUQ7XG4gICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdzdG9wRmluaXNoJyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5zZXR0aW5ncy5zdG9wTWV0aG9kID09IEFuaW1hdGlvblNldHRpbmdzLlNUT1BfTUVUSE9EUy5GQURFKSB7XG4gICAgICAgICAgICB0aGlzLl9wcm9ncmVzc1N0b3BUcmFuc2l0aW9uKGR0KTtcbiAgICAgICAgICAgIGlmICh0aGlzLl9zdG9wUCA+PSAxKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcCA9IDA7XG4gICAgICAgICAgICAgICAgdGhpcy5fc3RhdGUgPSBBbmltYXRpb24uU1RBVEVTLlNUT1BQRUQ7XG4gICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdzdG9wRmluaXNoJyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5zZXR0aW5ncy5zdG9wTWV0aG9kID09IEFuaW1hdGlvblNldHRpbmdzLlNUT1BfTUVUSE9EUy5PTkVUT1RXTykge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3AgPCAyKSB7XG4gICAgICAgICAgICAgICAgaWYgKGR1cmF0aW9uID09PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3AgPSAyO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoZHVyYXRpb24gPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9wIDwgMSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcCArPSBkdCAvIHRoaXMuc2V0dGluZ3MuZHVyYXRpb247XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9wICs9IGR0IC8gZHVyYXRpb247XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3AgPj0gMikge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9wID0gMjtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fc3RhdGUgPSBBbmltYXRpb24uU1RBVEVTLlNUT1BQRUQ7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgnc3RvcEZpbmlzaCcpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgncHJvZ3Jlc3MnLCB0aGlzLl9wKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5zZXR0aW5ncy5zdG9wTWV0aG9kID09IEFuaW1hdGlvblNldHRpbmdzLlNUT1BfTUVUSE9EUy5GT1JXQVJEKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fcCA8IDEpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5zZXR0aW5ncy5kdXJhdGlvbiA9PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3AgPSAxO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3AgKz0gZHQgLyB0aGlzLnNldHRpbmdzLmR1cmF0aW9uO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fcCA+PSAxKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnNldHRpbmdzLnN0b3BNZXRob2QgPT0gQW5pbWF0aW9uU2V0dGluZ3MuU1RPUF9NRVRIT0RTLkZPUldBUkQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3AgPSAxO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fc3RhdGUgPSBBbmltYXRpb24uU1RBVEVTLlNUT1BQRUQ7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3N0b3BGaW5pc2gnKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9yZXBlYXRzTGVmdCA+IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZXBlYXRzTGVmdC0tO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3AgPSAwO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgncmVwZWF0JywgdGhpcy5fcmVwZWF0c0xlZnQpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9wID0gMTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IEFuaW1hdGlvbi5TVEFURVMuU1RPUFBFRDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3N0b3BGaW5pc2gnKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgncHJvZ3Jlc3MnLCB0aGlzLl9wKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgXG4gICAgfVxuICAgIFxuICAgIF9wcm9ncmVzc1N0b3BUcmFuc2l0aW9uKGR0KSB7XG4gICAgICAgIGlmICh0aGlzLl9zdG9wUCA8IDEpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9zdG9wRGVsYXlMZWZ0ID4gMCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3N0b3BEZWxheUxlZnQgLT0gZHQ7XG5cbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fc3RvcERlbGF5TGVmdCA8IDApIHtcbiAgICAgICAgICAgICAgICAgICAgZHQgPSAtdGhpcy5fc3RvcERlbGF5TGVmdDtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fc3RvcERlbGF5TGVmdCA9IDA7XG5cbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdkZWxheUVuZCcpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBcbiAgICAgICAgICAgIGNvbnN0IGR1cmF0aW9uID0gdGhpcy5fZ2V0U3RvcER1cmF0aW9uKCk7XG5cbiAgICAgICAgICAgIGlmIChkdXJhdGlvbiA9PSAwKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fc3RvcFAgPSAxO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9zdG9wUCArPSBkdCAvIGR1cmF0aW9uO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRoaXMuX3N0b3BQID49IDEpIHtcbiAgICAgICAgICAgICAgICAvLyBGaW5pc2hlZCE7XG4gICAgICAgICAgICAgICAgdGhpcy5fc3RvcFAgPSAxO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2dldFN0b3BEdXJhdGlvbigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuc2V0dGluZ3Muc3RvcER1cmF0aW9uIHx8IHRoaXMuc2V0dGluZ3M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AgICogQHByaXZhdGU7XG4gICAgICAgICAqL1xuICAgICAgICB0aGlzLl9wcm9wU2V0dGVycyA9IFtdO1xuXG4gICAgICAgIHRoaXMuX3Jlc2V0VmFsdWUgPSB1bmRlZmluZWQ7XG4gICAgICAgIHRoaXMuX2hhc1Jlc2V0VmFsdWUgPSBmYWxzZTtcblxuICAgICAgICB0aGlzLl9oYXNDb2xvclByb3BlcnR5ID0gdW5kZWZpbmVkO1xuICAgIH1cblxuICAgIGdldFJlc2V0VmFsdWUoKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNSZXNldFZhbHVlKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fcmVzZXRWYWx1ZTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9pdGVtcy5nZXRWYWx1ZSgwKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGFwcGx5KGVsZW1lbnQsIHAsIGZhY3Rvcikge1xuICAgICAgICBjb25zdCBlbGVtZW50cyA9IHRoaXMuZ2V0QW5pbWF0ZWRFbGVtZW50cyhlbGVtZW50KTtcblxuICAgICAgICBsZXQgdiA9IHRoaXMuX2l0ZW1zLmdldFZhbHVlKHApO1xuXG4gICAgICAgIGlmICh2ID09PSB1bmRlZmluZWQgfHwgIWVsZW1lbnRzLmxlbmd0aCkge1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKGZhY3RvciAhPT0gMSkge1xuICAgICAgICAgICAgLy8gU3RvcCBmYWN0b3IuO1xuICAgICAgICAgICAgbGV0IHN2ID0gdGhpcy5nZXRSZXNldFZhbHVlKCk7XG5cbiAgICAgICAgICAgIGlmIChVdGlscy5pc051bWJlcih2KSAmJiBVdGlscy5pc051bWJlcihzdikpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5oYXNDb2xvclByb3BlcnR5KCkpIHtcbiAgICAgICAgICAgICAgICAgICAgdiA9IFN0YWdlVXRpbHMubWVyZ2VDb2xvcnModiwgc3YsIGZhY3Rvcik7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdiA9IFN0YWdlVXRpbHMubWVyZ2VOdW1iZXJzKHYsIHN2LCBmYWN0b3IpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEFwcGx5IHRyYW5zZm9ybWF0aW9uIHRvIGFsbCBjb21wb25lbnRzLjtcbiAgICAgICAgY29uc3QgbiA9IHRoaXMuX3Byb3BTZXR0ZXJzLmxlbmd0aDtcblxuICAgICAgICBjb25zdCBtID0gZWxlbWVudHMubGVuZ3RoO1xuICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IG07IGorKykge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9wcm9wU2V0dGVyc1tpXShlbGVtZW50c1tqXSwgdik7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgXG4gICAgZ2V0QW5pbWF0ZWRFbGVtZW50cyhlbGVtZW50KSB7XG4gICAgICAgIHJldHVybiBlbGVtZW50LnNlbGVjdCh0aGlzLl9zZWxlY3Rvcik7XG4gICAgfVxuXG4gICAgcmVzZXQoZWxlbWVudCkge1xuICAgICAgICBjb25zdCBlbGVtZW50cyA9IHRoaXMuZ2V0QW5pbWF0ZWRFbGVtZW50cyhlbGVtZW50KTtcblxuICAgICAgICBsZXQgdiA9IHRoaXMuZ2V0UmVzZXRWYWx1ZSgpO1xuXG4gICAgICAgIGlmICh2ID09PSB1bmRlZmluZWQgfHwgIWVsZW1lbnRzLmxlbmd0aCkge1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gQXBwbHkgdHJhbnNmb3JtYXRpb24gdG8gYWxsIGNvbXBvbmVudHMuXG4gICAgICAgIGNvbnN0IG4gPSB0aGlzLl9wcm9wU2V0dGVycy5sZW5ndGg7XG5cbiAgICAgICAgY29uc3QgbSA9IGVsZW1lbnRzLmxlbmd0aDtcbiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBtOyBqKyspIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcHJvcFNldHRlcnNbaV0oZWxlbWVudHNbal0sIHYpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuICAgIFxuICAgIHNldCBzZWxlY3Rvcih2KSB7XG4gICAgICAgIHRoaXMuX3NlbGVjdG9yID0gdjtcbiAgICB9XG5cbiAgICBzZXQgdCh2KSB7XG4gICAgICAgIHRoaXMuc2VsZWN0b3IgPSB2O1xuICAgIH1cblxuICAgIGdldCByZXNldFZhbHVlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcmVzZXRWYWx1ZTtcbiAgICB9XG4gICAgXG4gICAgc2V0IHJlc2V0VmFsdWUodikge1xuICAgICAgICB0aGlzLl9yZXNldFZhbHVlID0gdjtcbiAgICAgICAgdGhpcy5faGFzUmVzZXRWYWx1ZSA9ICh2ICE9PSB1bmRlZmluZWQpO1xuICAgIH1cblxuICAgIHNldCBydih2KSB7XG4gICAgICAgIHRoaXMucmVzZXRWYWx1ZSA9IHY7XG4gICAgfVxuXG4gICAgc2V0IHZhbHVlKHYpIHtcbiAgICAgICAgdGhpcy5faXRlbXMucGFyc2UodGhpcy5oYXNDb2xvclByb3BlcnR5KCksIHYpO1xuICAgIH1cblxuICAgIHNldCB2KHYpIHtcbiAgICAgICAgdGhpcy52YWx1ZSA9IHY7XG4gICAgfVxuXG4gICAgc2V0IHByb3BlcnRpZXModikge1xuICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkodikpIHtcbiAgICAgICAgICAgIHYgPSBbdl07XG4gICAgICAgIH1cblxuICAgICAgICB0aGlzL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Y2hlZDtcbiAgICB9XG5cbiAgICBpc1J1bm5pbmcoKSB7XG4gICAgICAgIHJldHVybiAodGhpcy5fcCA8IDEuMCk7XG4gICAgfVxuXG4gICAgcHJvZ3Jlc3MoZHQpIHtcbiAgICAgICAgaWYgKCF0aGlzLmlzQXR0YWNoZWQoKSkge1xuICAgICAgICAgICAgLy8gU2tpcCB0byBlbmQgb2YgdHJhbnNpdGlvbiBzbyB0aGF0IGl0IGlzIHJlbW92ZWQuXG4gICAgICAgICAgICB0aGlzLl9wID0gMTtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLnAgPCAxKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5kZWxheUxlZnQgPiAwKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fZGVsYXlMZWZ0IC09IGR0O1xuXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuZGVsYXlMZWZ0IDwgMCkge1xuICAgICAgICAgICAgICAgICAgICBkdCA9IC10aGlzLmRlbGF5TGVmdDtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZGVsYXlMZWZ0ID0gMDtcblxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ2RlbGF5RW5kJyk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX3NldHRpbmdzLmR1cmF0aW9uID09IDApIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9wID0gMTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcCArPSBkdCAvIHRoaXMuX3NldHRpbmdzLmR1cmF0aW9uO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRoaXMuX3AgPj0gMSkge1xuICAgICAgICAgICAgICAgIC8vIEZpbmlzaGVkITtcbiAgICAgICAgICAgICAg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igoZSkgPT4ge1xuICAgICAgICAgICAgICAgIHRoaXMuX3JlY2VpdmVLZXl1cChlKTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuZ2V0T3B0aW9uKFwiZW5hYmxlUG9pbnRlclwiKSkge1xuICAgICAgICAgICAgdGhpcy5zdGFnZS5wbGF0Zm9ybS5yZWdpc3RlckNsaWNrSGFuZGxlcigoZSkgPT4ge1xuICAgICAgICAgICAgICAgIHRoaXMuX3JlY2VpdmVDbGljayhlKTtcbiAgICAgICAgICAgIH0pO1xuXG4gICAgICAgICAgICB0aGlzLnN0YWdlLnBsYXRmb3JtLnJlZ2lzdGVySG92ZXJIYW5kbGVyKChlKSA9PiB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcmVjZWl2ZUhvdmVyKGUpO1xuICAgICAgICAgICAgfSk7XG5cbiAgICAgICAgICAgIHRoaXMuc3RhZ2UucGxhdGZvcm0ucmVnaXN0ZXJTY3JvbGxXaGVlbEhhbmRsZXIoKGUpID0+IHtcbiAgICAgICAgICAgICAgICB0aGlzLl9yZWNpZXZlU2Nyb2xsV2hlZWwoZSk7XG4gICAgICAgICAgICB9KTtcblxuICAgICAgICAgICAgdGhpcy5jdXJzb3IgPSAnZGVmYXVsdCc7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXRPcHRpb24obmFtZSkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX29wdGlvbnNbbmFtZV07XG4gICAgfVxuXG4gICAgX3NldE9wdGlvbnMobykge1xuICAgICAgICB0aGlzLl9fb3B0aW9ucyA9IHt9O1xuXG4gICAgICAgIGxldCBvcHQgPSAobmFtZSwgZGVmKSA9PiB7XG4gICAgICAgICAgICBsZXQgdmFsdWUgPSBvW25hbWVdO1xuXG4gICAgICAgICAgICBpZiAodmFsdWUgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX19vcHRpb25zW25hbWVdID0gZGVmO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9fb3B0aW9uc1tuYW1lXSA9IHZhbHVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgb3B0KCdkZWJ1ZycsIGZhbHNlKTtcbiAgICAgICAgb3B0KCdrZXlzJywge1xuICAgICAgICAgICAgMzg6IFwiVXBcIixcbiAgICAgICAgICAgIDQwOiBcIkRvd25cIixcbiAgICAgICAgICAgIDM3OiBcIkxlZnRcIixcbiAgICAgICAgICAgIDM5OiBcIlJpZ2h0XCIsXG4gICAgICAgICAgICAxMzogXCJFbnRlclwiLFxuICAgICAgICAgICAgODogXCJCYWNrXCIsXG4gICAgICAgICAgICAyNzogXCJFeGl0XCJcbiAgICAgICAgfSk7XG4gICAgICAgIG9wdCgnZW5hYmxlUG9pbnRlcicsIGZhbHNlKTtcbiAgICB9XG5cbiAgICBfX2NvbnN0cnVjdCgpIHtcbiAgICAgICAgdGhpcy5zdGFnZS5zZXRBcHBsaWNhdGlvbih0aGlzKTtcblxuICAgICAgICB0aGlzLl9zZXRPcHRpb25zKEFwcGxpY2F0aW9uLl90ZW1wX29wdGlvbnMpO1xuICAgICAgICBkZWxldGUgQXBwbGljYXRpb24uX3RlbXBfb3B0aW9ucztcblxuICAgICAgICBzdXBlci5fX2NvbnN0cnVjdCgpO1xuICAgIH1cblxuICAgIF9faW5pdCgpIHtcbiAgICAgICAgc3VwZXIuX19pbml0KCk7XG4gICAgICAgIHRoaXMuX191cGRhdGVGb2N1cygpO1xuICAgIH1cblxuICAgIHVwZGF0ZUZvY3VzUGF0aCgpIHtcbiAgICAgICAgdGhpcy5fX3VwZGF0ZUZvY3VzKCk7XG4gICAgfVxuXG4gICAgX191cGRhdGVGb2N1cygpIHtcbiAgICAgICAgY29uc3Qgbm90T3ZlcnJpZGRlbiA9IHRoaXMuX191cGRhdGVGb2N1c1JlYygpO1xuXG4gICAgICAgIGlmICghQXBwbGljYXRpb24uYm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GF0ZUZvY3VzSWQgIT09IHVwZGF0ZUZvY3VzSWQpO1xuICAgICAgICAgICAgICAgIGlmIChmb2N1c092ZXJyaWRkZW4pIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbGV0IG0gPSBNYXRoLm1pbih0aGlzLl9mb2N1c1BhdGgubGVuZ3RoLCBuZXdGb2N1c1BhdGgubGVuZ3RoKTtcbiAgICAgICAgICAgIGxldCBpbmRleDtcbiAgICAgICAgICAgIGZvciAoaW5kZXggPSAwOyBpbmRleCA8IG07IGluZGV4KyspIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fZm9jdXNQYXRoW2luZGV4XSAhPT0gbmV3Rm9jdXNQYXRoW2luZGV4XSkge1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9mb2N1c1BhdGgubGVuZ3RoICE9PSBuZXdGb2N1c1BhdGgubGVuZ3RoIHx8IGluZGV4ICE9PSBuZXdGb2N1c1BhdGgubGVuZ3RoKSB7XG5cbiAgICAgICAgICAgICAgICBpZiAodGhpcy5nZXRPcHRpb24oJ2RlYnVnJykpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coJ1tMaWdodG5pbmddIEZvY3VzIGNoYW5nZWQ6ICcgKyBuZXdGb2N1c2VkQ29tcG9uZW50LmdldExvY2F0aW9uU3RyaW5nKCkpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIC8vIFVuZm9jdXMgZXZlbnRzLlxuICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSB0aGlzLl9mb2N1c1BhdGgubGVuZ3RoIC0gMTsgaSA+PSBpbmRleDsgaS0tKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHVuZm9jdXNlZEVsZW1lbnQgPSB0aGlzLl9mb2N1c1BhdGgucG9wKCk7XG4gICAgICAgICAgICAgICAgICAgIHVuZm9jdXNlZEVsZW1lbnQuX3VuZm9jdXMobmV3Rm9jdXNlZENvbXBvbmVudCwgcHJldkZvY3VzZWRDb21wb25lbnQpO1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBmb2N1c092ZXJyaWRkZW4gPSAodGhpcy5fX3VwZGF0ZUZvY3VzSWQgIT09IHVwZGF0ZUZvY3VzSWQpO1xuICAgICAgICAgICAgICAgICAgICBpZiAoZm9jdXNPdmVycmlkZGVuKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAvLyBGb2N1cyBldmVudHMuXG4gICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IGluZGV4LCBuID0gbmV3Rm9jdXNQYXRoLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9mb2N1c1BhdGgucHVzaChuZXdGb2N1c1BhdGhbaV0pO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9mb2N1c1BhdGhbaV0uX2ZvY3VzKG5ld0ZvY3VzZWRDb21wb25lbnQsIHByZXZGb2N1c2VkQ29tcG9uZW50KTtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgZm9jdXNPdmVycmlkZGVuID0gKHRoaXMuX191cGRhdGVGb2N1c0lkICE9PSB1cGRhdGVGb2N1c0lkKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZvY3VzT3ZlcnJpZGRlbikge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICA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CFuZXh0Rm9jdXMgfHwgKG5leHRGb2N1cyA9PT0gY3VycmVudCkpIHtcbiAgICAgICAgICAgICAgICAvLyBGb3VuZCE7XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG5cblxuICAgICAgICAgICAgbGV0IHB0ciA9IG5leHRGb2N1cy5jcGFyZW50O1xuICAgICAgICAgICAgaWYgKHB0ciA9PT0gY3VycmVudCkge1xuICAgICAgICAgICAgICAgIHBhdGgucHVzaChuZXh0Rm9jdXMpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAvLyBOb3QgYW4gaW1tZWRpYXRlIGNoaWxkOiBpbmNsdWRlIGZ1bGwgcGF0aCB0byBkZXNjZW5kYW50LlxuICAgICAgICAgICAgICAgIGNvbnN0IG5ld1BhcnRzID0gW25leHRGb2N1c107XG4gICAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgICAgICBpZiAoIXB0cikge1xuICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudC5fdGhyb3dFcnJvcihcIlJldHVybiB2YWx1ZSBmb3IgX2dldEZvY3VzZWQgbXVzdCBiZSBhbiBhdHRhY2hlZCBkZXNjZW5kYW50IGNvbXBvbmVudCBidXQgaXRzICdcIiArIG5leHRGb2N1cy5nZXRMb2NhdGlvblN0cmluZygpICsgXCInXCIpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIG5ld1BhcnRzLnB1c2gocHRyKTtcbiAgICAgICAgICAgICAgICAgICAgcHRyID0gcHRyLmNwYXJlbnQ7XG4gICAgICAgICAgICAgICAgfSB3aGlsZSAocHRyICE9PSBjdXJyZW50KTtcblxuICAgICAgICAgICAgICAgIC8vIEFkZCB0aGVtIHJldmVyc2VkLlxuICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gbmV3UGFydHMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAg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ZhbHNlO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIEluamVjdHMgYW4gZXZlbnQgaW4gdGhlIHN0YXRlIG1hY2hpbmVzLCBib3R0b20tdXAgZnJvbSBmb2N1c2VkIGNvbXBvbmVudCB0byBhcHBsaWNhdGlvbi5cbiAgICAgKi9cbiAgICBmb2N1c0JvdHRvbVVwRXZlbnQoZXZlbnRzLCAuLi5hcmdzKSB7XG4gICAgICAgIGNvbnN0IHBhdGggPSB0aGlzLmZvY3VzUGF0aDtcbiAgICAgICAgY29uc3QgbiA9IHBhdGgubGVuZ3RoO1xuXG4gICAgICAgIC8vIE11bHRpcGxlIGV2ZW50cy5cbiAgICAgICAgZm9yIChsZXQgaSA9IG4gLSAxOyBpID49IDA7IGktLSkge1xuICAgICAgICAgICAgY29uc3QgZXZlbnQgPSBwYXRoW2ldLl9nZXRNb3N0U3BlY2lmaWNIYW5kbGVkTWVtYmVyKGV2ZW50cyk7XG4gICAgICAgICAgICBpZiAoZXZlbnQgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIGNvbnN0IHJldHVyblZhbHVlID0gcGF0aFtpXVtldmVudF0oLi4uYXJncyk7XG4gICAgICAgICAgICAgICAgaWYgKHJldHVyblZhbHVlICE9PSBmYWxzZSkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuXG4gICAgX3JlY2VpdmVLZXlkb3duKGUpIHtcbiAgICAgICAgY29uc3Qgb2JqID0gZTtcbiAgICAgICAgY29uc3Qga2V5ID0gdGhpcy5fX2tleW1hcFtlLmtleUNvZGVdO1xuICAgICAgICBjb25zdCBwYXRoID0gdGhpcy5mb2N1c1BhdGg7XG5cbiAgICAgICAgbGV0IGtleXM7XG4gICAgICAgIGlmIChrZXkpIHtcbiAgICAgICAgICAgIGtleXMgPS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mopO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgdGhpcy51cGRhdGVGb2N1c1BhdGgoKTtcblxuICAgICAgICBjb25zdCBjb25zdW1lciA9IHBhdGhbcGF0aC5sZW5ndGggLSAxXTtcblxuICAgICAgICBpZiAoa2V5cyAmJiBjb25zdW1lci5sb25ncHJlc3MpIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0ga2V5cy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGFydExvbmdwcmVzc1RpbWVyKGtleXNbaV0sIGNvbnN1bWVyKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIC8qKlxuICAgICAqIEtleXVwIGxpc3RlbmVyXG4gICAgICogVG8gdGFrZSBhd2F5IHNvbWUgY29uZnVzaW9uIHdlIGFkZCBgUmVsZWFzZWAgdG8gdGhlIGV2ZW50IHRvIHByZXZlbnQgZW5kaW5nIHVwIHdpdGggbWV0aG9kIG5hbWVzIGxpa2U6XG4gICAgICogIF9oYW5kbGVMZWZ0VXAgLyBfaGFuZGxlVXBVcCAvIF9oYW5kbGVFbnRlclVwIGV0Y1xuICAgICAqXG4gICAgICogQHBhcmFtIGVcbiAgICAgKiBAcHJpdmF0ZVxuICAgICAqL1xuICAgIF9yZWNlaXZlS2V5dXAoZSkge1xuICAgICAgICBjb25zdCBvYmogPSBlO1xuICAgICAgICBjb25zdCBrZXkgPSB0aGlzLl9fa2V5bWFwW2Uua2V5Q29kZV07XG5cbiAgICAgICAgbGV0IGtleXM7XG4gICAgICAgIGlmIChrZXkpIHtcbiAgICAgICAgICAgIGtleXMgPSBBcnJheS5pc0FycmF5KGtleSkgPyBrZXkgOiBba2V5XTtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChrZXlzKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IGtleXMubGVuZ3RoOyBpIDwgbj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0TG9uZ3ByZXNzVGltZXIoa2V5LCBlbGVtZW50KSB7XG4gICAgICAgIGNvbnN0IGNvbmZpZyA9IGVsZW1lbnQubG9uZ3ByZXNzO1xuICAgICAgICBjb25zdCBsb29rdXAgPSBrZXkudG9Mb3dlckNhc2UoKTtcblxuICAgICAgICBpZiAoY29uZmlnW2xvb2t1cF0pIHtcbiAgICAgICAgICAgIGNvbnN0IHRpbWVvdXQgPSBjb25maWdbbG9va3VwXTtcbiAgICAgICAgICAgIGlmICghVXRpbHMuaXNOdW1iZXIodGltZW91dCkpIHtcbiAgICAgICAgICAgICAgICBlbGVtZW50Ll90aHJvd0Vycm9yKFwiY29uZmlnIHZhbHVlIGZvciBsb25ncHJlc3MgbXVzdCBiZSBhIG51bWJlclwiKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fX2tleXByZXNzVGltZXJzLnNldChrZXksIHNldFRpbWVvdXQoKCkgPT4ge1xuICAgICAgICAgICAgICAgICAgICBpZiAoIXRoaXMuc3RhZ2UuYXBwbGljYXRpb24uZm9jdXNUb3BEb3duRXZlbnQoW2BfY2FwdHVyZSR7a2V5fUxvbmdgLCBcIl9jYXB0dXJlS2V5XCJdLCB7fSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuc3RhZ2UuYXBwbGljYXRpb24uZm9jdXNCb3R0b21VcEV2ZW50KFtgX2hhbmRsZSR7a2V5fUxvbmdgLCBcIl9oYW5kbGVLZXlcIl0sIHt9KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX19rZXlwcmVzc1RpbWVycy5kZWxldGUoa2V5KTtcbiAgICAgICAgICAgICAgICB9LCB0aW1lb3V0IHx8IDUwMCAvKiBwcmV2ZW50IDBtcyAqLykpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybjtcbiAgICB9XG5cbiAgICBfcmVjaWV2ZVN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ikge1xuICAgICAgICBjb25zdCB7IGNsaWVudFgsIGNsaWVudFkgfSA9IG9iajtcbiAgICAgICAgY29uc3QgdGFyZ2V0ID0gdGhpcy5fZ2V0VGFyZ2V0Q2hpbGQoY2xpZW50WCwgY2xpZW50WSk7XG4gICAgICAgIGxldCBjaGlsZCA9IHRhcmdldDtcblxuICAgICAgICAvLyBTZWFyY2ggdHJlZSBib3R0b20gdXAgZm9yIGEgaGFuZGxlclxuICAgICAgICB3aGlsZSAoY2hpbGQgIT09IG51bGwpIHtcbiAgICAgICAgICAgIGlmIChjaGlsZCAmJiBjaGlsZFtldmVudF0pIHtcbiAgICAgICAgICAgICAgICBjaGlsZC5faGFuZGxlU2Nyb2xsKG9iaik7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjaGlsZCA9IGNoaWxkLnBhcmVudDtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuXG4gICAgX3JlY2VpdmVDbGljayhlKSB7XG4gICAgICAgIGNvbnN0IG9iaiA9IGU7XG4gICAgICAgIGNvbnN0IHsgY2xpZW50WCwgY2xpZW50WSB9ID0gb2JqO1xuXG4gICAgICAgIGlmIChjbGllbnRYIDw9IHRoaXMuc3RhZ2UudyAmJiBjbGllbnRZIDw9IHRoaXMuc3RhZ2UuaCkge1xuICAgICAgICAgICAgdGhpcy5zdGFnZS5hcHBsaWNhdGlvbi5maXJlQm90dG9tVXBDbGlja0hhbmRsZXIob2JqKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGZpcmVCb3R0b21VcENsaWNrSGFuZGxlcihvYmopIHtcbiAgICAgICAgY29uc3QgeyBjbGllbnRYLCBjbGllbnRZIH0gPSBvYmo7XG4gICAgICAgIGNvbnN0IHRhcmdldCA9IHRoaXMuX2dldFRhcmdldENoaWxkKGNsaWVudFgsIGNsaWVudFkpO1xuICAgICAgICBjb25zdCBwcmVjaXNpb24gPSB0aGlzLnN0YWdlLmdldFJlbmRlclByZWNpc2lvbigpIC8gdGhpcy5zdGFnZS5nZXRPcHRpb24oJ2RldmljZVBpeGVsUmF0aW8nKTtcbiAgICAgICAgbGV0IGNoaWxkID0gdGFyZ2V0O1xuXG4gICAgICAgIC8vIFNlYXJjaCB0cmVlIGJvdHRvbSB1cCBmb3IgYSBoYW5kbGVyXG4gICAgICAgIHdoaWxlIChjaGlsZCAhPT0gbnVsbCkge1xuICAgICAgICAgICAgaWYgKGNoaWxkICYmIGNoaWxkW1wiX2hhbmRsZUNsaWNrXCJdKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgeyBweCwgcHkgfSA9IGNoaWxkLmNvcmUuX3dvcmxkQ29udGV4dDtcbiAgICAgICAgICAgICAgICBjb25zdCBjeCA9IHB4ICogcHJlY2lzaW9uO1xuICAgICAgICAgICAgICAgIGNvbnN0IGN5ID0gcHkgKiBwcmVjaXNpb247XG5cbiAgICAgICAgICAgICAgICBjb25zdCBsb2NhbENvb3JkcyA9IHtcbiAgICAgICAgICAgICAgICAgICAgeDogY2xpZW50WCAtIGN4LFxuICAgICAgICAgICAgICAgICAgICB5OiBjbGllbnRZIC0gY3lcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBjb25zdCByZXR1cm5WYWx1ZSA9IGNoaWxkLl9oYW5kbGVDbGljayh0YXJnZXQsIGxvY2FsQ29vcmRzKTtcbiAgICAgICAgICAgICAgICBpZiAocmV0dXJuVmFsdWUgIT09IGZhbHNlKSB7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGNoaWxkID0gY2hpbGQucGFyZW50O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX3JlY2VpdmVIb3ZlcihlKSB7XG4gICAgICAgIGNvbnN0IG9iaiA9IGU7XG4gICAgICAgIGNvbnN0IHsgY2xpZW50WCwgY2xpZW50WSB9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UpKSkge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBjID0gQ29tcG9uZW50LmdldENvbXBvbmVudChlbGVtKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGNbXCJfaGFuZGxlVW5ob3ZlclwiXSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgYy5faGFuZGxlVW5ob3ZlcihlbGVtKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBpZiAoZWxlbS5wYXJlbnQgJiYgZWxlbS5wYXJlbnQuY3Vyc29yKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnN0YWdlLmdldENhbnZhcygpLnN0eWxlLmN1cnNvciA9IGVsZW0ucGFyZW50LmN1cnNvcjtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdGhpcy5fX2hvdmVyZWRDaGlsZCA9IHRhcmdldDtcblxuICAgICAgICAgICAgY29uc3QgZGlmZkJyYW5jaCA9IFsuLi5uZXdIb3ZlcmVkQnJhbmNoXS5maWx0ZXIoKGUpID0+ICFob3ZlcmVkQnJhbmNoLmhhcyhlKSlcbiAgICAgICAgICAgIGZvciAoY29uc3QgZWxlbSBvZiBkaWZmQnJhbmNoKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgYyA9IENvbXBvbmVudC5nZXRDb21wb25lbnQoZWxlbSk7XG4gICAgICAgICAgICAgICAgaWYgKGNbXCJfaGFuZGxlSG92ZXJcIl0pIHtcbiAgICAgICAgICAgICAgICAgICAgYy5faGFuZGxlSG92ZXIoZWxlbSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBOZXcgZWxlbWVudCBob3ZlciBjdXJzb3JcbiAgICAgICAgICAgIGNvbnN0IGxhc3RFbGVtZW50ID0gZGlmZkJyYW5jaFswXTtcbiAgICAgICAgICAgIGlmIChsYXN0RWxl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ChhLnpJbmRleCA+IGIuekluZGV4KSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIDE7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGEuekluZGV4IDwgYi56SW5kZXgpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gLTE7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJldHVybiBhLmlkID4gYi5pZCA/IDEgOiAtMTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG5cbiAgICAgICAgaWYgKGhvdmVyYWJsZUNoaWxkcmVuLmxlbmd0aCkge1xuICAgICAgICAgICAgLy8gQXNzdW1lIHRhcmdldCBoYXMgaGlnaGVzdCB6SW5kZXggKGlkIHdoZW4gekluZGV4IGVxdWFsKVxuICAgICAgICAgICAgcmV0dXJuIGhvdmVyYWJsZUNoaWxkcmVuLnNsaWNlKC0xKVswXTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiBudWxsO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2ZpbmRDaGlsZHJlbihidWNrZXQsIGNoaWxkcmVuKSB7XG4gICAgICAgIGxldCBuID0gY2hpbGRyZW4ubGVuZ3RoO1xuICAgICAgICB3aGlsZSAobi0tKSB7XG4gICAgICAgICAgICBjb25zdCBjaGlsZCA9IGNoaWxkcmVuW25dO1xuICAgICAgICAgICAgLy8gb25seSBhZGQgYWN0aXZlIGNoaWxkcmVuXG4gICAgICAgICAgICBpZiAoY2hpbGQuX19hY3RpdmUgJiYgY2hpbGQuY29sbGlzaW9uKSB7XG4gICAgICAgICAgICAgICAgaWYgKGNoaWxkLmNvbGxpc2lvbiA9PT0gdHJ1ZSkge1xuICAgICAgICAgICAgICAgICAgICBidWNrZXQucHVzaChjaGlsZCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChjaGlsZC5oYXNDaGlsZHJlbigpKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXM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lzLnN0YWdlLmgpIHtcbiAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGNoaWxkLnBhcmVudC5jb3JlLl9zY2lzc29yKSB7XG4gICAgICAgICAgICAgICAgY29uc3Qgc2Npc3NvciA9IGNoaWxkLnBhcmVudC5jb3JlLl9zY2lzc29yLm1hcCgodikgPT4gdiAqIHByZWNpc2lvbik7XG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLl90ZXN0Q29sbGlzaW9uKGN1cnNvclgsIGN1cnNvclksIC4uLnNjaXNzb3IpKVxuICAgICAgICAgICAgICAgICAgICBjb250aW51ZVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAodGhpcy5fdGVzdENvbGxpc2lvbihjdXJzb3JYLCBjdXJzb3JZLCBjeCwgY3ksIGN3LCBjaCkpIHtcbiAgICAgICAgICAgICAgICBjYW5kaWRhdGVzLnB1c2goY2hpbGQpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBjYW5kaWRhdGVzO1xuICAgIH1cblxuICAgIF90ZXN0Q29sbGlzaW9uKHB4LCBweSwgY3gsIGN5LCBjdywgY2gpIHtcbiAgICAgICAgaWYgKHB4ID49IGN4ICYmXG4gICAgICAgICAgICBweCA8PSBjeCArIGN3ICYmXG4gICAgICAgICAgICBweSA+PSBjeSAmJlxuICAgICAgICAgICAgcHkgPD0gY3kgKyBjaCkge1xuICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cblxuICAgIGRlc3Ryb3koKSB7XG4gICAgICAgIGlmICghdGhpcy5fZGVzdHJveWVkKSB7XG4gICAgICAgICAgICB0aGlzLl9kZXN0cm95KCk7XG4gICAgICAgICAgICB0aGlzLnN0YWdlLmRlc3Ryb3koKTtcbiAgICAgICAgICAgIHRoaXMuX2Rlc3Ryb3llZCA9IHRyd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ZSBzZXR0ZXJzIGZvciBldmVyeSBnaXZlbiBkZXBlbmRlbmN5XG4gICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgcHJvcERlcGVuZGVuY2llcy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgY29uc3QgcHJvcE5hbWUgPSBwcm9wRGVwZW5kZW5jaWVzW2ldO1xuICAgICAgICAgICAgY29uc3QgZnVuYyA9IHByb3BPYmouX19mdW5jID8gcHJvcE9iai5fX2Z1bmMgOiAoY29udGV4dCkgPT4gY29udGV4dFtwcm9wTmFtZV07XG5cbiAgICAgICAgICAgIGlmICghdGhpcy5oYXNPd25Qcm9wZXJ0eShwcm9wTmFtZSkpIHtcbiAgICAgICAgICAgICAgICB0aGlzW2BfX3Byb3BfYmluZGluZ3NfJHtwcm9wTmFtZX1gXSA9IFt7X19vYmo6IG9iaiwgX19wcm9wOiBwcm9wLCBfX2Z1bmM6IGZ1bmN9XTtcbiAgICAgICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgcHJvcE5hbWUsIHtcbiAgICAgICAgICAgICAgICAgICAgc2V0OiAodmFsdWUpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXNbYF9fcHJvcF8ke3Byb3BOYW1lfWBdID0gdmFsdWU7XG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGNvbnN0IHtfX29iaiwgX19wcm9wLCBfX2Z1bmN9IG9mIHRoaXNbYF9fcHJvcF9iaW5kaW5nc18ke3Byb3BOYW1lfWBdKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgX19vYmpbX19wcm9wXSA9IF9fZnVuYyh0aGlzKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgZ2V0OiAoKSA9PiB0aGlzW2BfX3Byb3BfJHtwcm9wTmFtZX1gXVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICA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0LCBcImVsZW1lbnRcIik7XG5cbiAgICAgICAgY29uc3QgY29kZSA9IGNvbnRleHQubG9jLmpvaW4oXCI7XFxuXCIpO1xuICAgICAgICBjb25zdCBmID0gbmV3IEZ1bmN0aW9uKFwiZWxlbWVudFwiLCBcInN0b3JlXCIsIGNvZGUpO1xuICAgICAgICByZXR1cm4ge2Y6IGYsIGE6IGNvbnRleHQuc3RvcmV9O1xuICAgIH1cblxuICAgIHN0YXRpYyBwYXJzZVRlbXBsYXRlUmVjKG9iaiwgY29udGV4dCwgY3Vyc29yKSB7XG4gICAgICAgIGNvbnN0IHN0b3JlID0gY29udGV4dC5zdG9yZTtcbiAgICAgICAgY29uc3QgbG9jID0gY29udGV4dC5sb2M7XG4gICAgICAgIGNvbnN0IGtleXMgPSBPYmplY3Qua2V5cyhvYmopO1xuICAgICAgICBrZXlzLmZvckVhY2goa2V5ID0+IHtcbiAgICAgICAgICAgIGxldCB2YWx1ZSA9IG9ialtrZXldO1xuICAgICAgICAgICAgaWYgKFV0aWxzLmlzVWNDaGFyKGtleS5jaGFyQ29kZUF0KDApKSkge1xuICAgICAgICAgICAgICAgIC8vIFZhbHVlIG11c3QgYmUgZXhwYW5kZWQgYXMgd2VsbC5cbiAgICAgICAgICAgICAgICBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKHZhbHVlKSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBSZWYuXG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGNoaWxkQ3Vyc29yID0gYHIke2tleS5yZXBsYWNlKC9bXmEtejAtOV0vZ2ksIFwiXCIpICsgY29udGV4dC5yaWR9YDtcbiAgICAgICAgICAgICAgICAgICAgbGV0IHR5cGUgPSB2YWx1ZS50eXBlID8gdmFsdWUudHlwZSA6IEVsZW1lbnQ7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0eXBlID09PSBFbGVtZW50KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgdmFyICR7Y2hpbGRDdXJzb3J9ID0gZWxlbWVudC5zdGFnZS5jcmVhdGVFbGVtZW50KClgKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0b3JlLnB1c2godHlwZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgdmFyICR7Y2hpbGRDdXJzb3J9ID0gbmV3IHN0b3JlWyR7c3RvcmUubGVuZ3RoIC0gMX1dKCR7Y3Vyc29yfS5zdGFnZSlgKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtjaGlsZEN1cnNvcn0ucmVmID0gXCIke2tleX1cImApO1xuICAgICAgICAgICAgICAgICAgICBjb250ZXh0LnJpZCsrO1xuXG4gICAgICAgICAgICAgICAgICAgIC8vIEVudGVyIHN1Yi5cbiAgICAgICAgICAgICAgICAgICAgdGhpcy5wYXJzZVRlbXBsYXRlUmVjKHZhbHVlLCBjb250ZXh0LCBjaGlsZEN1cnNvcik7XG5cbiAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYCR7Y3Vyc29yfS5jaGlsZExpc3QuYWRkKCR7Y2hpbGRDdXJzb3J9KWApO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMuaXNPYmplY3QodmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIER5bmFtaWMgYXNzaWdubWVudC5cbiAgICAgICAgICAgICAgICAgICAgc3RvcmUucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn0uY2hpbGRMaXN0LmFkZChzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XSlgKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGlmIChrZXkgPT09IFwidGV4dFwiKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHByb3BLZXkgPSBjdXJzb3IgKyBcIl9fdGV4dFwiO1xuICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgdmFyICR7cHJvcEtleX0gPSAke2N1cnNvcn0uZW5hYmxlVGV4dFRleHR1cmUoKWApO1xuICAgICAgICAgICAgICAgICAgICBpZiAodmFsdWUuX19wcm9wZXJ0eUJpbmRpbmcgPT09IHRydWUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEFsbG93IGJpbmRpbmcgZW50aXJlIG9iamVjdHMgdG8gdGV4dCBwcm9wZXJ0eVxuICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmUucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgZWxlbWVudC5fX2JpbmRQcm9wZXJ0eShzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XSwgJHtjdXJzb3J9LCBcIiR7a2V5fVwiKWApO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5wYXJzZVRlbXBsYXRlUHJvcFJlYyh2YWx1ZSwgY29udGV4dCwgcHJvcEtleSk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGtleSA9PT0gXCJzaGFkZXJcIiAmJiBVdGlscy5pc09iamVjdExpdGVyYWwodmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHNoYWRlckN1cnNvciA9IGAke2N1cnNvcn1bXCJzaGFkZXJcIl1gXG4gICAgICAgICAgICAgICAgICAgIHN0b3JlLnB1c2godmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtjdXJzb3J9W1wiJHtrZXl9XCJdID0gc3RvcmVbJHtzdG9yZS5sZW5ndGggLSAxfV1gKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5wYXJzZVByb3BlcnR5QmluZGluZ3ModmFsdWUsIGNvbnRleHQsIHNoYWRlckN1cnNvcik7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChrZXkgPT09IFwidGV4dHVyZVwiICYmIFV0aWxzLmlzT2JqZWN0TGl0ZXJhbCh2YWx1ZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgcHJvcEtleSA9IGN1cnNvciArIFwiX190ZXh0dXJlXCI7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHR5cGUgPSB2YWx1ZS50eXBlO1xuICAgICAgICAgICAgICAgICAgICBpZiAodHlwZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmUucHVzaCh0eXBlKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGB2YXIgJHtwcm9wS2V5fSA9IG5ldyBzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XSgke2N1cnNvcn0uc3RhZ2UpYCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnBhcnNlVGVtcGxhdGVQcm9wUmVjKHZhbHVlLCBjb250ZXh0LCBwcm9wS2V5KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn1bXCIke2tleX1cIl0gPSAke3Byb3BLZXl9YCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtwcm9wS2V5fSA9ICR7Y3Vyc29yfS50ZXh0dXJlYCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnBhcnNlVGVtcGxhdGVQcm9wUmVjKHZhbHVlLCBjb250ZXh0LCBwcm9wS2V5KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKHZhbHVlKSAmJiB2YWx1ZS5fX3Byb3BlcnR5QmluZGluZyA9PT0gdHJ1ZSkge1xuICAgICAgICAgICAgICAgICAgICBzdG9yZS5wdXNoKHZhbHVlKTtcbiAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYGVsZW1lbnQuX19iaW5kUHJvcGVydHkoc3RvcmVbJHtzdG9yZS5sZW5ndGggLSAxfV0sICR7Y3Vyc29yfSwgXCIke2tleX1cIilgKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAvLyBQcm9wZXJ0eTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKFV0aWxzLmlzTnVtYmVyKHZhbHVlKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYCR7Y3Vyc29yfVtcIiR7a2V5fVwiXSA9ICR7dmFsdWV9YCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMuaXNCb29sZWFuKHZhbHVlKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYCR7Y3Vyc29yfVtcIiR7a2V5fVwiXSA9ICR7dmFsdWUgPyBcInRydWVcIiA6IFwiZmFsc2VcIn1gKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChVdGlscy5pc09iamVjdCh2YWx1ZSkgfHwgQXJyYXkuaXNBcnJheSh2YWx1ZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIER5bmFtaWMgYXNzaWdubWVudC5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEJlY2F1c2UgbGl0ZXJhbCBvYmplY3RzIG1heSBjb250YWluIGR5bmFtaWNzLCB3ZSBzdG9yZSB0aGUgZnVsbCBvYmplY3QuXG4gICAgICAgICAgICAgICAgICAgICAgICBzdG9yZS5wdXNoKHZhbHVlKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn1bXCIke2tleX1cIl0gPSBzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XWApO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gU3RyaW5nIGV0Yy5cbiAgICAgICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn1bXCIke2tleX1cIl0gPSAke0pTT04uc3RyaW5naWZ5KHZhbHVlKX1gKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgc3RhdGljIHBhcnNlVGVtcGxhdGVQcm9wUmVjKG9iaiwgY29udGV4dCwgY3Vyc29yKSB7XG4gICAgICAgIGNvbnN0IHN0b3JlID0gY29udGV4dC5zdG9yZTtcbiAgICAgICAgY29uc3QgbG9jID0gY29udGV4dC5sb2M7XG4gICAgICAgIGNvbnN0IGtleXMgPSBPYmplY3Qua2V5cyhvYmopO1xuICAgICAgICBrZXlzLmZvckVhY2goa2V5ID0+IHtcbiAgICAgICAgICAgIGlmIChrZXkgIT09IFwidHlwZVwiKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgdmFsdWUgPSBvYmpba2V5XTtcbiAgICAgICAgICAgICAgICBpZiAoVXRpbHMuaXNOdW1iZXIodmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn1bXCIke2tleX1cIl0gPSAke3ZhbHVlfWApO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMuaXNCb29sZWFuKHZhbHVlKSkge1xuICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtjdXJzb3J9W1wiJHtrZXl9XCJdID0gJHt2YWx1ZSA/IFwidHJ1ZVwiIDogXCJmYWxzZVwifWApO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMuaXNPYmplY3QodmFsdWUpICYmIHZhbHVlLl9fcHJvcGVydHlCaW5kaW5nID09PSB0cnVlKSB7XG4gICAgICAgICAgICAgICAgICAgIHN0b3JlLnB1c2godmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgZWxlbWVudC5fX2JpbmRQcm9wZXJ0eShzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XSwgJHtjdXJzb3J9LCBcIiR7a2V5fVwiKWApO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMuaXNPYmplY3QodmFsdWUpIHx8IEFycmF5LmlzQXJyYXkodmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIER5bmFtaWMgYXNzaWdubWVudC5cbiAgICAgICAgICAgICAgICAgICAgLy8gQmVjYXVzZSBsaXRlcmFsIG9iamVjdHMgbWF5IGNvbnRhaW4gZHluYW1pY3MsIHdlIHN0b3JlIHRoZSBmdWxsIG9iamVjdC5cbiAgICAgICAgICAgICAgICAgICAgc3RvcmUucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn1bXCIke2tleX1cIl0gPSBzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XWApO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFN0cmluZyBldGMuXG4gICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn1bXCIke2tleX1cIl0gPSAke0pTT04uc3RyaW5naWZ5KHZhbHVlKX1gKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIHN0YXRpYyBwYXJzZVByb3BlcnR5QmluZGluZ3Mob2JqLCBjb250ZXh0LCBjdXJzb3IpIHtcbiAgICAgICAgY29uc3Qgc3RvcmUgPSBjb250ZXh0LnN0b3JlO1xuICAgICAgICBjb25zdCBsb2MgPSBjb250ZXh0LmxvYztcbiAgICAgICAgY29uc3Qga2V5cyA9IE9iamVjdC5rZXlzKG9iaik7XG4gICAgICAgIGtleXMuZm9yRWFjaChrZXkgPT4ge1xuICAgICAgICAgICAgaWYgKGtleSAhPT0gXCJ0eXBlXCIpIHtcbiAgICAgICAgICAgICAgICBjb25zdCB2YWx1ZSA9IG9ialtrZXldO1xuICAgICAgICAgICAgICAgIGlmIChVdGlscy5pc09iamVjdExpdGVyYWwodmFsdWUpICYmIHZhbHVlLl9fcHJvcGVydHlCaW5kaW5nID09PSB0cnVlKSB7XG4gICAgICAgICAgICAgICAgICAgIHN0b3JlLnB1c2godmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgZWxlbWVudC5fX2JpbmRQcm9wZXJ0eShzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XSwgJHtjdXJzb3J9LCBcIiR7a2V5fVwiKWApO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgX29uU2V0dXAoKSB7XG4gICAgICAgIGlmICghdGhpcy5fX2luaXRpYWxpemVkKSB7XG4gICAgICAgICAgICB0aGlzLl9zZXR1cCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX3NldHVwKCkge1xuICAgIH1cblxuICAgIF9vbkF0dGFjaCgpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9faW5pdGlhbGl6ZWQpIHtcbiAgICAgICAgICAgIHRoaXMuX19pbml0KCk7XG4gICAgICAgICAgICB0aGlzLl9faW5pdGlhbGl6ZWQgPSB0cnVlO1xuICAgICAgICB9XG5cbiAgICAgICAgdGhpcy5fYXR0YWNoKCk7XG4gICAgfVxuXG4gICAgX2F0dGFjaCgpIHtcbiAgICB9XG5cbiAgICBfb25EZXRhY2goKSB7XG4gICAgICAgIHRoaXMuX2RldGFjaCgpO1xuICAgIH1cblxuICAgIF9kZXRhY2goKSB7XG4gICAgfVxuXG4gICAgX29uRW5hYmxlZCgpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9fZmlyc3RFbmFibGUpIHtcbiAgICAgICAgICAgIHRoaXMuX2ZpcnN0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uICAgIH1cblxuICAgIGdldCBjcGFyZW50KCkge1xuICAgICAgICByZXR1cm4gQ29tcG9uZW50LmdldFBhcmVudCh0aGlzKTtcbiAgICB9XG5cbiAgICBzZWVrQW5jZXN0b3JCeVR5cGUodHlwZSkge1xuICAgICAgICBsZXQgYyA9IHRoaXMuY3BhcmVudDtcbiAgICAgICAgd2hpbGUgKGMpIHtcbiAgICAgICAgICAgIGlmIChjLmNvbnN0cnVjdG9yID09PSB0eXBlKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGM7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjID0gYy5jcGFyZW50O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0U2hhcmVkQW5jZXN0b3JDb21wb25lbnQoZWxlbWVudCkge1xuICAgICAgICBsZXQgYW5jZXN0b3IgPSB0aGlzLmdldFNoYXJlZEFuY2VzdG9yKGVsZW1lbnQpO1xuICAgICAgICB3aGlsZSAoYW5jZXN0b3IgJiYgIWFuY2VzdG9yLmlzQ29tcG9uZW50KSB7XG4gICAgICAgICAgICBhbmNlc3RvciA9IGFuY2VzdG9yLnBhcmVudDtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gYW5jZXN0b3I7XG4gICAgfVxuXG4gICAgZ2V0IHNpZ25hbHMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fc2lnbmFscztcbiAgICB9XG5cbiAgICBzZXQgc2lnbmFscyh2KSB7XG4gICAgICAgIGlmICghVXRpbHMuaXNPYmplY3RMaXRlcmFsKHYpKSB7XG4gICAgICAgICAgICB0aGlzLl90aHJvd0Vycm9yKFwiU2lnbmFsczogc3BlY2lmeSBhbiBvYmplY3Qgd2l0aCBzaWduYWwtdG8tZmlyZSBtYXBwaW5nc1wiKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9fc2lnbmFscyA9IHY7XG4gICAgfVxuXG4gICAgc2V0IGFsdGVyU2lnbmFscyh2KSB7XG4gICAgICAgIGlmICghVXRpbHMuaXNPYmplY3RMaXRlcmFsKHYpKSB7XG4gICAgICAgICAgICB0aGlzLl90aHJvd0Vycm9yKFwiU2lnbmFsczogc3BlY2lmeSBhbiBvYmplY3Qgd2l0aCBzaWduYWwtdG8tZmlyZSBtYXBwaW5nc1wiKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoIXRoaXMuX19zaWduYWxzKSB7XG4gICAgICAgICAgICB0aGlzLl9fc2lnbmFscyA9IHt9O1xuICAgICAgICB9XG4gICAgICAgIGZvciAobGV0IGtleSBpbiB2KSB7XG4gICAgICAgICAgICBjb25zdCBkID0gdltrZXldO1xuICAgICAgICAgICAgaWYgKGQgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIGRlbGV0ZSB0aGlzLl9fc2lnbmFsc1trZXldO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9fc2lnbmFsc1trZXldID0gdjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBwYXNzU2lnbmFscygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19wYXNzU2lnbmFscyB8fCB7fTtcbiAgICB9XG5cbiAgICBzZXQgcGFzc1NpZ25hbHModikge1xuICAgICAgICB0aGlzLl9fcGFzc1NpZ25hbHMgPSBPYmplY3QuYXNzaWduKHRoaXMuX19wYXNzU2lnbmFscyB8fCB7fSwgdik7XG4gICAgfVxuXG4gICAgc2V0IGFsdGVyUGFzc1NpZ25hbHModikge1xuICAgICAgICBpZiAoIVV0aWxzLmlzT2JqZWN0TGl0ZXJhbCh2KSkge1xuICAgICAgICAgICAgdGhpcy5fdGhyb3dFcnJvcihcIlNpZ25hbHM6IHNwZWNpZnkgYW4gb2JqZWN0IHdpdGggc2lnbmFsLXRvLWZpcmUgbWFwcGluZ3NcIik7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLl9fcGFzc1NpZ25hbHMpIHtcbiAgICAgICAgICAgIHRoaXMuX19wYXNzU2lnbmFscyA9IHt9O1xuICAgICAgICB9XG4gICAgICAgIGZvciAobGV0IGtleSBpbiB2KSB7XG4gICAgICAgICAgICBjb25zdCBkID0gdltrZXldO1xuICAgICAgICAgICAgaWYgKGQgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIGRlbGV0ZSB0aGlzLl9fcGFzc1NpZ25hbHNba2V5XTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fX3Bhc3NTaWduYWxzW2tleV0gPSB2O1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogU2lnbmFscyB0aGUgcGFyZW50IG9mIHRoZSBzcGVjaWZpZWQgZXZlbnQuXG4gICAgICogQSBwYXJlbnQvYW5jZXN0b3IgdGhhdCB3aXNoZXMgdG8gaGFuZGxlIHRoZSBzaWduYWwgc2hvdWxkIHNldCB0aGUgJ3NpZ25hbHMnIHByb3BlcnR5IG9uIHRoaXMgY29tcG9uZW50LlxuICAgICAqIEBwYXJhbSB7c3RyaW5nfSBldmVudFxuICAgICAqIEBwYXJhbSB7Li4uKn0gYXJnc1xuICAgICAqL1xuICAgIHNpZ25hbChldmVudCwgLi4uYXJncykge1xuICAgICAgICByZXR1cm4gdGhpcy5fc2lnbmFsKGV2ZW50LCBhcmdzKTtcbiAgICB9XG5cbiAgICBfc2lnbmFsKGV2ZW50LCBhcmdzKSB7XG4gICAgICAgIGNvbnN0IHNpZ25hbFBhcmVudCA9IHRoaXMuX2dldFBhcmVudFNpZ25hbEhhbmRsZXIoKTtcbiAgICAgICAgaWYgKHNpZ25hbFBhcmVudCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX19zaWduYWxzKSB7XG4gICAgICAgICAgICAgICAgbGV0IGZpcmVFdmVudCA9IHRoaXMuX19zaWduYWxzW2V2ZW50XTtcbiAgICAgICAgICAgICAgICBpZiAoZmlyZUV2ZW50ID09PSBmYWxzZSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBJZ25vcmUgZXZlbnQuXG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaWYgKGZpcmVFdmVudCkge1xuICAgICAgICAgICAgICAgICAgICBpZiAoZmlyZUV2ZW50ID09PSB0cnVlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBmaXJlRXZlbnQgPSBldmVudDtcbiAgICAgICAgICAgICAgICAgICAgfVxuIFxuICAgICAgICAgICAgICAgICAgICBpZiAoVXRpbHMuaXNGdW5jdGlvbihmaXJlRXZlbnQpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZmlyZUV2ZW50KC4uLmFyZ3MpO1xuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHNpZ25hbFBhcmVudC5faGFzTWV0aG9kKGZpcmVFdmVudCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBzaWduYWxQYXJlbnRbZmlyZUV2ZW50XSguLi5hcmdzKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgbGV0IHBhc3NTaWduYWwgPSAodGhpcy5fX3Bhc3NTaWduYWxzICYmIHRoaXMuX19wYXNzU2lnbmFsc1tldmVudF0pO1xuICAgICAgICAgICAgaWYgKHBhc3NTaWduYWwpIHtcbiAgICAgICAgICAgICAgICAvLyBCdWJibGUgdXAuXG4gICAgICAgICAgICAgICAgaWYgKHBhc3NTaWduYWwgJiYgcGFzc1NpZ25hbCAhPT0gdHJ1ZSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBSZXBsYWNlIHNpZ25hbCBuYW1lLlxuICAgICAgICAgICAgICAgICAgICBldmVudCA9IHBhc3NTaWduYWw7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgIC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KSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuZmlyZShuYW1lLCAuLi5hcmdzKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGNvbnN0IHNpZ25hbFBhcmVudCA9IHRoaXMuX2dldFBhcmVudFNpZ25hbEhhbmRsZXIoKTtcbiAgICAgICAgICAgIGlmIChzaWduYWxQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gc2lnbmFsUGFyZW50Ll9kb0ZpcmVBbmNlc3RvcnMobmFtZSwgYXJncyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgY29sbGVjdFN1YkNvbXBvbmVudHMoc3VicywgZWxlbWVudCkge1xuICAgICAgICBpZiAoZWxlbWVudC5oYXNDaGlsZHJlbigpKSB7XG4gICAgICAgICAgICBjb25zdCBjaGlsZExpc3QgPSBlbGVtZW50Ll9fY2hpbGRMaXN0O1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBjaGlsZExpc3QubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgY2hpbGQgPSBjaGlsZExpc3QuZ2V0QXQoaSk7XG4gICAgICAgICAgICAgICAgaWYgKGNoaWxkLmlzQ29tcG9uZW50KSB7XG4gICAgICAgICAgICAgICAgICAgIHN1YnMucHVzaChjaGlsZCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgQ29tcG9uZW50LmNvbGxlY3RTdWJDb21wb25lbnRzKHN1YnMsIGNoaWxkKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0Q29tcG9uZW50KGVsZW1lbnQpIHtcbiAgICAgICAgbGV0IHBhcmVudCA9IGVsZW1lbnQ7XG4gICAgICAgIHdoaWxlIChwYXJlbnQgJiYgIXBhc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SB7XG4gICAgICAgICAgICAgICAgICAgIG5ld1N0YXRlOiBuZXdTdGF0ZS5fX3BhdGgsXG4gICAgICAgICAgICAgICAgICAgIHByZXZTdGF0ZTogcHJldlN0YXRlLl9fcGF0aCxcbiAgICAgICAgICAgICAgICAgICAgc2hhcmVkU3RhdGU6IHNoYXJlZFN0YXRlLl9fcGF0aFxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgY29uc3Qgc2hhcmVkTGV2ZWwgPSBzaGFyZWRTdGF0ZS5fX2xldmVsO1xuXG4gICAgICAgICAgICAgICAgaWYgKGhhc0RpZmZlcmVudEV4aXRNZXRob2QpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgZXhpdFN0YXRlcyA9IFN0YXRlTWFjaGluZS5fZ2V0U3RhdGVzVW50aWxMZXZlbCh0aGlzLl9zdGF0ZSwgc2hhcmVkTGV2ZWwpO1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IGV4aXRTdGF0ZXMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9fc2V0U3RhdGUoZXhpdFN0YXRlc1tpXSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9jYWxsRXhpdCh0aGlzLl9zdGF0ZSwgYXJncywgY29udGV4dCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzdGF0ZUNoYW5nZU92ZXJyaWRkZW4gPSAodGhpcy5fc2V0U3RhdGVJZCAhPT0gc2V0U3RhdGVJZCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGVDaGFuZ2VPdmVycmlkZGVuKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaWYgKGhhc0RpZmZlcmVudEVudGVyTWV0aG9kKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGVudGVyU3RhdGVzID0gU3RhdGVNYWNoaW5lLl9nZXRTdGF0ZXNVbnRpbExldmVsKG5ld1N0YXRlLCBzaGFyZWRMZXZlbCkucmV2ZXJzZSgpO1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IGVudGVyU3RhdGVzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fX3NldFN0YXRlKGVudGVyU3RhdGVzW2ldKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2NhbGxFbnRlcih0aGlzLl9zdGF0ZSwgYXJncywgY29udGV4dCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzdGF0ZUNoYW5nZU92ZXJyaWRkZW4gPSAodGhpcy5fc2V0U3RhdGVJZCAhPT0gc2V0U3RhdGVJZCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGVDaGFuZ2VPdmVycmlkZGVuKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRoaXMuX19zZXRTdGF0ZShuZXdTdGF0ZSk7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9jaGFuZ2VkU3RhdGUpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBjb250ZXh0ID0ge1xuICAgICAgICAgICAgICAgICAgICBuZXdTdGF0ZTogbmV3U3RhdGUuX19wYXRoLFxuICAgICAgICAgICAgICAgICAgICBwcmV2U3RhdGU6IHByZXZTdGF0ZS5fX3BhdGhcbiAgICAgICAgICAgICAgICB9O1xuXG4gICAgICAgICAgICAgICAgaWYgKGFyZ3MpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fY2hhbmdlZFN0YXRlKGNvbnRleHQsIC4uLmFyZ3MpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2NoYW5nZWRTdGF0ZShjb250ZXh0KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9vblN0YXRlQ2hhbmdlKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgY29udGV4dCA9IHtcbiAgICAgICAgICAgICAgICAgICAgbmV3U3RhdGU6IG5ld1N0YXRlLl9fcGF0aCxcbiAgICAgICAgICAgICAgICAgICAgcHJldlN0YXRlOiBwcmV2U3RhdGUuX19wYXRoXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICB0aGlzLl9vblN0YXRlQ2hhbmdlKGNvbnRleHQpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfY2FsbEVudGVyKHN0YXRlLCBhcmdzID0gW10sIGNvbnRleHQpIHtcbiAgICAgICAgY29uc3QgaGFzUGFyZW50ID0gISFzdGF0ZS5fX3BhcmVudDtcbiAgICAgICAgaWYgKHN0YXRlLnByb3RvdHlwZS4kZW50ZXIpIHtcbiAgICAgICAgICAgIGlmICghaGFzUGFyZW50IHx8IChzdGF0ZS5fX3BhcmVudC5wcm90b3R5cGUuJGVudGVyICE9PSBzdGF0ZS5wcm90b3R5cGUuJGVudGVyKSkge1xuICAgICAgICAgICAgICAgIHN0YXRlLnByb3RvdHlwZS4kZW50ZXIuYXBwbHkodGhpcywgW2NvbnRleHQsIC4uLmFyZ3NdKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9jYWxsRXhpdChzdGF0ZSwgYXJncyA9IFtdLCBjb250ZXh0KSB7XG4gICAgICAgIGNvbnN0IGhhc1BhcmVudCA9ICEhc3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IGluZGV4KSA9PiB7XG4gICAgICAgICAgICBjb25zdCBzdGF0ZSA9IHRoaXMuX3N0YXRlTWFwW3N0YXRlUGF0aF07XG4gICAgICAgICAgICBjb25zdCBkZXNjcmlwdG9yID0gdGhpcy5fZ2V0RGVzY3JpcHRvcihzdGF0ZSwgbWVtYmVyKTtcbiAgICAgICAgICAgIGlmIChkZXNjcmlwdG9yKSB7XG4gICAgICAgICAgICAgICAgZGVzY3JpcHRvcnNbaW5kZXhdID0gZGVzY3JpcHRvcjtcblxuICAgICAgICAgICAgICAgIC8vIEFkZCB0byBwcm90b3R5cGUuXG4gICAgICAgICAgICAgICAgY29uc3QgYWxpYXMgPSBTdGF0ZU1hY2hpbmVUeXBlLmdldFN0YXRlTWVtYmVyQWxpYXMoZGVzY3JpcHRvci5fc291cmNlLl9fcGF0aCwgbWVtYmVyKTtcbiAgICAgICAgICAgICAgICBhbGlhc2VzW2luZGV4XSA9IGFsaWFzO1xuXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLl9yb3V0ZXIucHJvdG90eXBlLmhhc093blByb3BlcnR5KGFsaWFzKSkge1xuICAgICAgICAgICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcy5fcm91dGVyLnByb3RvdHlwZSwgYWxpYXMsIGRlc2NyaXB0b3IpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgZGVzY3JpcHRvcnNbaW5kZXhdID0gbnVsbDtcbiAgICAgICAgICAgICAgICBhbGlhc2VzW2luZGV4XSA9IG51bGw7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuXG4gICAgICAgIGxldCB0eXBlID0gdW5kZWZpbmVkO1xuICAgICAgICBkZXNjcmlwdG9ycy5mb3JFYWNoKGRlc2NyaXB0b3IgPT4ge1xuICAgICAgICAgICAgaWYgKGRlc2NyaXB0b3IpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBkZXNjVHlwZSA9IHRoaXMuX2dldERlc2NyaXB0b3JUeXBlKGRlc2NyaXB0b3IpO1xuICAgICAgICAgICAgICAgIGlmICh0eXBlICYmICh0eXBlICE9PSBkZXNjVHlwZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS53YXJuKGBbTGlnaHRuaW5nXSBNZW1iZXIgJHttZW1iZXJ9IGluICR7dGhpcy5fdHlwZS5uYW1lfSBoYXMgaW5jb25zaXN0ZW50IHR5cGVzLmApO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHR5cGUgPSBkZXNjVHlwZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG5cbiAgICAgICAgc3dpdGNoKHR5cGUpIHtcbiAgICAgICAgICAgIGNhc2UgXCJtZXRob2RcIjpcbiAgICAgICAgICAgICAgICB0aGlzLl9hZGRNZXRob2RSb3V0ZXIobWVtYmVyLCBkZXNjcmlwdG9ycywgYWxpYXNlcyk7XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICBjYXNlIFwiZ2V0dGVyXCI6XG4gICAgICAgICAgICAgICAgdGhpcy5fYWRkR2V0dGVyU2V0dGVyUm91dGVycyhtZW1iZXIpO1xuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgY2FzZSBcInByb3BlcnR5XCI6XG4gICAgICAgICAgICAgICAgY29uc29sZS53YXJuKFwiW0xpZ2h0bmluZ10gRml4ZWQgcHJvcGVydGllcyBhcmUgbm90IHN1cHBvcnRlZDsgcGxlYXNlIHVzZSBhIGdldHRlciBpbnN0ZWFkIVwiKVxuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2dldERlc2NyaXB0b3Ioc3RhdGUsIG1lbWJlciwgaXNWYWxpZCA9ICgpID0+IHRydWUpIHtcbiAgICAgICAgbGV0IHR5cGUgPSBzdGF0ZTtcbiAgICAgICAgbGV0IGN1clN0YXRlID0gc3RhdGU7XG5cbiAgICAgICAgZG8ge1xuICAgICAgICAgICAgY29uc3QgZGVzY3JpcHRvciA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eURlc2NyaXB0b3IodHlwZS5wcm90b3R5cGUsIG1lbWJlcik7XG4gICAgICAgICAgICBpZiAoZGVzY3JpcHRvcikge1xuICAgICAgICAgICAgICAgIGlmIChpc1ZhbGlkKGRlc2NyaXB0b3IpKSB7XG4gICAgICAgICAgICAgICAgICAgIGRlc2NyaXB0b3IuX3NvdXJjZSA9IGN1clN0YXRlO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZGVzY3JpcHRvcjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0eXBlID0gT2JqZWN0LmdldFByb3RvdHlwZU9mKHR5cGUpO1xuICAgICAgICAgICAgaWYgKHR5cGUgJiYgdHlwZS5oYXNPd25Qcm9wZXJ0eSgnX19zdGF0ZScpKSB7XG4gICAgICAgICAgICAgICAgY3VyU3RhdGUgPSB0eXBlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IHdoaWxlKHR5cGUgJiYgdHlwZS5wcm90b3R5cGUpO1xuICAgICAgICByZXR1cm4gdW5kZWZpbmVkO1xuICAgIH1cblxuICAgIF9nZXREZXNjcmlwdG9yVHlwZShkZXNjcmlwdG9yKSB7XG4gICAgICAgIGlmIChkZXNjcmlwdG9yLmdldCB8fCBkZXNjcmlwdG9yLnNldCkge1xuICAgICAgICAgICAgcmV0dXJuICdnZXR0ZXInO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHR5cGVvZiBkZXNjcmlwdG9yLnZhbHVlID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gJ21ldGhvZCc7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJldHVybiAncHJvcGVydHknO1xuICAgICA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uOyBpKyspIHtcbiAgICAgICAgICAgIGNvbnN0IGFsaWFzID0gYWxpYXNlc1tpXTtcbiAgICAgICAgICAgIGlmIChhbGlhcyAhPT0gY3VyKSB7XG4gICAgICAgICAgICAgICAgaWYgKGN1cikge1xuICAgICAgICAgICAgICAgICAgICBpZiAoc3VwcG9ydHNTcHJlYWQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvZGUucHVzaChgaWYgKGkgPCAke2l9KSByZXR1cm4gdGhpc1tcIiR7Y3VyfVwiXSguLi5hcmd1bWVudHMpOyBlbHNlYCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb2RlLnB1c2goYGlmIChpIDwgJHtpfSkgcmV0dXJuIHRoaXNbXCIke2N1cn1cIl0uYXBwbHkodGhpcywgYXJndW1lbnRzKTsgZWxzZWApO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgY29kZS5wdXNoKGBpZiAoaSA8ICR7aX0pIHJldHVybiA7IGVsc2VgKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjdXIgPSBhbGlhcztcbiAgICAgICAgfVxuICAgICAgICBpZiAoY3VyKSB7XG4gICAgICAgICAgICBpZiAoc3VwcG9ydHNTcHJlYWQpIHtcbiAgICAgICAgICAgICAgICBjb2RlLnB1c2goYHJldHVybiB0aGlzW1wiJHtjdXJ9XCJdKC4uLmFyZ3VtZW50cyk7YCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGNvZGUucHVzaChgcmV0dXJuIHRoaXNbXCIke2N1cn1cIl0uYXBwbHkodGhpcywgYXJndW1lbnRzKTtgKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGNvZGUucHVzaChgO2ApO1xuICAgICAgICB9XG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mVSb3V0ZXIuanNcIixcbiAgICAgICAgICAgIFwidmFyIGkgPSB0aGlzLl9zdGF0ZUluZGV4O1wiXG4gICAgICAgIF07XG4gICAgICAgIGxldCBjdXIgPSBhbGlhc2VzWzBdO1xuICAgICAgICBmb3IgKGxldCBpID0gMSwgbiA9IGFsaWFzZXMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCBhbGlhcyA9IGFsaWFzZXNbaV07XG4gICAgICAgICAgICBpZiAoYWxpYXMgIT09IGN1cikge1xuICAgICAgICAgICAgICAgIGlmIChjdXIpIHtcbiAgICAgICAgICAgICAgICAgICAgY29kZS5wdXNoKGBpZiAoaSA8ICR7aX0pIHJldHVybiB0aGlzW1wiJHtjdXJ9XCJdOyBlbHNlYCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgY29kZS5wdXNoKGBpZiAoaSA8ICR7aX0pIHJldHVybiA7IGVsc2VgKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjdXIgPSBhbGlhcztcbiAgICAgICAgfVxuICAgICAgICBpZiAoY3VyKSB7XG4gICAgICAgICAgICBjb2RlLnB1c2goYHJldHVybiB0aGlzW1wiJHtjdXJ9XCJdO2ApO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29kZS5wdXNoKGA7YCk7XG4gICAgICAgIH1cbiAgICAgICAgY29uc3QgZnVuY3Rpb25Cb2R5ID0gY29kZS5qb2luKFwiXFxuXCIpO1xuICAgICAgICBjb25zdCByb3V0ZXIgPSBuZXcgRnVuY3Rpb24oW10sIGZ1bmN0aW9uQm9keSk7XG4gICAgICAgIHJldHVybiByb3V0ZXI7XG4gICAgfVxuXG4gICAgX2dldFNldHRlclJvdXRlcihtZW1iZXIpIHtcbiAgICAgICAgY29uc3Qgc3RhdGVQYXRocyA9IE9iamVjdC5rZXlzKHRoaXMuX3N0YXRlTWFwKTtcbiAgICAgICAgY29uc3QgZGVzY3JpcHRvcnMgPSBbXTtcbiAgICAgICAgY29uc3QgYWxpYXNlcyA9IFtdO1xuICAgICAgICBzdGF0ZVBhdGhzLmZvckVhY2goKHN0YXRlUGF0aCwgaW5kZXgpID0+IHtcbiAgICAgICAgICAgIGNvbnN0IHN0YXRlID0gdGhpcy5fc3RhdGVNYXBbc3RhdGVQYXRoXTtcbiAgICAgICAgICAgIGNvbnN0IGRlc2NyaXB0b3IgPSB0aGlzLl9nZXREZXNjcmlwdG9yKHN0YXRlLCBtZW1iZXIsIChkZXNjcmlwdG9yID0+IGRlc2NyaXB0b3Iuc2V0KSk7XG4gICAgICAgICAgICBpZiAoZGVzY3JpcHRvcikge1xuICAgICAgICAgICAgICAgIGRlc2NyaXB0b3JzW2luZGV4XSA9IGRlc2NyaXB0b3I7XG5cbiAgICAgICAgICAgICAgICAvLyBBZGQgdG8gcHJvdG90eXBlLlxuICAgICAgICAgICAgICAgIGNvbnN0IGFsaWFzID0gU3RhdGVNYWNoaW5lVHlwZS5nZXRTdGF0ZU1lbWJlckFsaWFzKGRlc2NyaXB0b3IuX3NvdXJjZS5fX3BhdGgsIG1lbWJlcik7XG4gICAgICAgICAgICAgICAgYWxpYXNlc1tpbmRleF0gPSBhbGlhcztcblxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5fcm91dGVyLnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eShhbGlhcykpIHtcbiAgICAgICAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMuX3JvdXRlci5wcm90b3R5cGUsIGFsaWFzLCBkZXNjcmlwdG9yKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGRlc2NyaXB0b3JzW2luZGV4XSA9IG51bGw7XG4gICAgICAgICAgICAgICAgYWxpYXNlc1tpbmRleF0gPSBudWxsO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcblxuICAgICAgICBjb25zdCBjb2RlID0gW1xuICAgICAgICAgICAgLy8gVGhlIGxpbmUgZW5zdXJlcyB0aGF0LCB3aGlsZSBkZWJ1Z2dpbmcsIHlvdXIgSURFIHdvbid0IG9wZW4gbWFueSB0YWJzLlxuICAgICAgICAgICAgXCIvL0Agc291cmNlVVJMPVN0YXRlTWFjaGluZVJvdXRlci5qc1wiLFxuICAgICAgICAgICAgXCJ2YXIgaSA9IHRoaXMuX3N0YXRlSW5kZXg7XCJcbiAgICAgICAgXTtcbiAgICAgICAgbGV0IGN1ciA9IGFsaWFzZXNbMF07XG4gICAgICAgIGZvciAobGV0IGkgPSAxLCBuID0gYWxpYXNlcy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGNvbnN0IGFsaWFzID0gYWxpYXNlc1tpXTtcbiAgICAgICAgICAgIGlmIChhbGlhcyAhPT0gY3VyKSB7XG4gICAgICAgICAgICAgICAgaWYgKGN1cikge1xuICAgICAgICAgICAgICAgICAgICBjb2RlLnB1c2goYGlmIChpIDwgJHtpfSkgdGhpc1tcIiR7Y3VyfVwiXSA9IGFyZzsgZWxzZWApO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNvZGUucHVzaChgaWYgKGkgPCAke2l9KSA7IGVsc2VgKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjdXIgPSBhbGlhcztcbiAgICAgICAgfVxuICAgICAgICBpZiAoY3VyKSB7XG4gICAgICAgICAgICBjb2RlLnB1c2goYHRoaXNbXCIke2N1cn1cIl0gPSBhcmc7YCk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb2RlLnB1c2goYDtgKTtcbiAgICAgICAgfVxuICAgICAgICBjb25zdCBmdW5jdGlvbkJvZHkgPSBjb2RlLmpvaW4oXCJcXG5cIik7XG4gICAgICAgIGNvbnN0IHJvdXRlciA9IG5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XCI7XG5pbXBvcnQgTGluZWFyQmx1clNoYWRlciBmcm9tIFwiLi4vcmVuZGVyZXIvd2ViZ2wvc2hhZGVycy9MaW5lYXJCbHVyU2hhZGVyLm1qc1wiO1xuaW1wb3J0IEJveEJsdXJTaGFkZXIgZnJvbSBcIi4uL3JlbmRlcmVyL3dlYmdsL3NoYWRlcnMvQm94Qmx1clNoYWRlci5tanNcIjtcbmltcG9ydCBEZWZhdWx0U2hhZGVyIGZyb20gXCIuLi9yZW5kZXJlci93ZWJnbC9zaGFkZXJzL0RlZmF1bHRTaGFkZXIubWpzXCI7XG5cbmV4cG9ydCBkZWZhdWx0IGNsYXNzIEJsb29tQ29tcG9uZW50IGV4dGVuZHMgQ29tcG9uZW50IHtcblxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIGNvbnN0IG9uVXBkYXRlID0gZnVuY3Rpb24oZWxlbWVudCwgZWxlbWVudENvcmUpIHtcbiAgICAgICAgICAgIGlmICgoZWxlbWVudENvcmUuX3JlY2FsYyAmICgyICsgMTI4KSkpIHtcbiAgICAgICAgICAgICAgICBjb25zdCB3ID0gZWxlbWVudENvcmUudztcbiAgICAgICAgICAgICAgICBjb25zdCBoID0gZWxlbWVudENvcmUuaDtcbiAgICAgICAgICAgICAgICBsZXQgY3VyID0gZWxlbWVudENvcmU7XG4gICAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgICAgICBjdXIgPSBjdXIuX2NoaWxkcmVuWzBdO1xuICAgICAgICAgICAgICAgICAgICBjdXIuX2VsZW1lbnQudyA9IHc7XG4gICAgICAgICAgICAgICAgICAgIGN1ci5fZWxlbWVudC5oID0gaDtcbiAgICAgICAgICAgICAgICB9IHdoaWxlKGN1ci5fY2hpbGRyZW4pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuXG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBUZXh0d3JhcDoge3J0dDogdHJ1ZSwgZm9yY2VaSW5kZXhDb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GF5ZXJDb250ZW50cygzKS5oID0gZmggLyAxNjtcbiAgICAgICAgdGhpcy5fdGV4dHdyYXAueSA9IC1wYWRkaW5nWTtcblxuICAgICAgICB0aGlzLncgPSB3O1xuICAgICAgICB0aGlzLmggPSBoO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFNldHMgdGhlIGFtb3VudCBvZiBibHVyLiBBIHZhbHVlIGJldHdlZW4gMCBhbmQgNC4gR29lcyB1cCBleHBvbmVudGlhbGx5IGZvciBibHVyLlxuICAgICAqIEJlc3QgcmVzdWx0cyBmb3Igbm9uLWZyYWN0aW9uYWwgdmFsdWVzLlxuICAgICAqIEBwYXJhbSB2O1xuICAgICAqL1xuICAgIHNldCBhbW91bnQodikge1xuICAgICAgICB0aGlzLl9hbW91bnQgPSB2O1xuICAgICAgICB0aGlzLl91cGRhdGUoKTtcbiAgICB9XG5cbiAgICBnZXQgYW1vdW50KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fYW1vdW50O1xuICAgIH1cblxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIGxldCB2ID0gTWF0aC5taW4oNCwgTWF0aC5tYXgoMCwgdGhpcy5fYW1vdW50KSk7XG4gICAgICAgIGlmICh2ID4gMCkge1xuICAgICAgICAgICAgdGhpcy5nZXRMYXllcigwKS52aXNpYmxlID0gKHYgPiAwKTtcbiAgICAgICAgICAgIHRoaXMuZ2V0TGF5ZXIoMSkudmlzaWJsZSA9ICh2ID4gMSk7XG4gICAgICAgICAgICB0aGlzLmdldExheWVyKDIpLnZpc2libGUgPSAodiA+IDIpO1xuICAgICAgICAgICAgdGhpcy5nZXRMYXllcigzKS52aXNpYmxlID0gKHYgPiAzKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHNldCBzaGFkZXIocykge1xuICAgICAgICBzdXBlci5zaGFkZXIgPSBzO1xuICAgICAgICBpZiAoIXRoaXMucmVuZGVyVG9UZXh0dXJlKSB7XG4gICAgICAgICAgICBjb25zb2xlLndhcm4o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IHtcbiAgICAgICAgICAgICAgICAgICAgY3VyID0gY3VyLl9jaGlsZHJlblswXTtcbiAgICAgICAgICAgICAgICAgICAgY3VyLl9lbGVtZW50LncgPSB3O1xuICAgICAgICAgICAgICAgICAgICBjdXIuX2VsZW1lbnQuaCA9IGg7XG4gICAgICAgICAgICAgICAgfSB3aGlsZShjdXIuX2NoaWxkcmVuKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcblxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgVGV4dHdyYXA6IHtydHQ6IHRydWUsIGZvcmNlWkluZGV4Q29udGV4dDogdHJ1ZSwgcmVuZGVyT2Zmc2NyZWVuOiB0cnVlLCBDb250ZW50OiB7fX0sXG4gICAgICAgICAgICBMYXllcnM6IHtcbiAgICAgICAgICAgICAgICBMMDoge3J0dDogdHJ1ZSwgb25VcGRhdGU6IG9uVXBkYXRlLCByZW5kZXJPZmZzY3JlZW46IHRydWUsIHZpc2libGU6IGZhbHNlLCBDb250ZW50OiB7c2hhZGVyOiB7dHlwZTogQm94Qmx1clNoYWRlcn19fSxcbiAgICAgICAgICAgICAgICBMMToge3J0dDogdHJ1ZSwgb25VcGRhdGU6IG9uVXBkYXRlLCByZW5kZXJPZmZzY3JlZW46IHRydWUsIHZpc2libGU6IGZhbHNlLCBDb250ZW50OiB7c2hhZGVyOiB7dHlwZTogQm94Qmx1clNoYWRlcn19fSxcbiAgICAgICAgICAgICAgICBMMjoge3J0dDogdHJ1ZSwgb25VcGRhdGU6IG9uVXBkYXRlLCByZW5kZXJPZmZzY3JlZW46IHRydWUsIHZpc2libGU6IGZhbHNlLCBDb250ZW50OiB7c2hhZGVyOiB7dHlwZTogQm94Qmx1clNoYWRlcn19fSxcbiAgICAgICAgICAgICAgICBMMzoge3J0dDogdHJ1ZSwgb25VcGRhdGU6IG9uVXBkYXRlLCByZW5kZXJPZmZzY3JlZW46IHRydWUsIHZpc2libGU6IGZhbHNlLCBDb250ZW50OiB7c2hhZGVyOi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pcy5fbGF5ZXJzLnNlbChcIkxcIiArIGkpO1xuICAgIH1cblxuICAgIGdldExheWVyQ29udGVudHMoaSkge1xuICAgICAgICByZXR1cm4gdGhpcy5nZXRMYXllcihpKS5zZWwoXCJDb250ZW50XCIpO1xuICAgIH1cblxuICAgIF9vblJlc2l6ZSgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlQmx1clNpemUoKTtcbiAgICB9XG5cbiAgICBfdXBkYXRlQmx1clNpemUoKSB7XG4gICAgICAgIGxldCB3ID0gdGhpcy5yZW5kZXJXaWR0aDtcbiAgICAgICAgbGV0IGggPSB0aGlzLnJlbmRlckhlaWdodDtcblxuICAgICAgICBsZXQgcGFkZGluZ1ggPSB0aGlzLl9wYWRkaW5nWDtcbiAgICAgICAgbGV0IHBhZGRpbmdZID0gdGhpcy5fcGFkZGluZ1k7XG5cbiAgICAgICAgbGV0IGZ3ID0gdyArIHBhZGRpbmdYICogMjtcbiAgICAgICAgbGV0IGZoID0gaCArIHBhZGRpbmdZICogMjtcbiAgICAgICAgdGhpcy5fdGV4dHdyYXAudyA9IGZ3O1xuICAgICAgICB0aGlzLl93cmFwcGVyLnggPSBwYWRkaW5nWDtcbiAgICAgICAgdGhpcy5nZXRMYXllcigwKS53ID0gdGhpcy5nZXRMYXllckNvbnRlbnRzKDApLncgPSBmdyAvIDI7XG4gICAgICAgIHRoaXMuZ2V0TGF5ZXIoMSkudyA9IHRoaXMuZ2V0TGF5ZXJDb250ZW50cygxKS53ID0gZncgLyA0O1xuICAgICAgICB0aGlzLmdldExheWVyKDIpLncgPSB0aGlzLmdldExheWVyQ29udGVudHMoMikudyA9IGZ3IC8gODtcbiAgICAgICAgdGhpcy5nZXRMYXllcigzKS53ID0gdGhpcy5nZXRMYXllckNvbnRlbnRzKDMpLncgPSBmdyAvIDE2O1xuICAgICAgICB0aGlzLl9vdXRwdXQueCA9IC1wYWRkaW5nWDtcbiAgICAgICAgdGhpcy5fdGV4dHdyYXAueCA9IC1wYWRkaW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AgICAgICAgICAgIHRoaXMuX291dHB1dC50ZXh0dXJlID0gdGhpcy5nZXRMYXllcigwKS5nZXRUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0cHV0LnNoYWRlci5vdGhlclRleHR1cmVTb3VyY2UgPSB0aGlzLmdldExheWVyKDEpLmdldFRleHR1cmUoKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9vdXRwdXQuc2hhZGVyLmEgPSB2IC0gMTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodiA8PSAzKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0cHV0LnRleHR1cmUgPSB0aGlzLmdldExheWVyKDEpLmdldFRleHR1cmUoKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9vdXRwdXQuc2hhZGVyLm90aGVyVGV4dHVyZVNvdXJjZSA9IHRoaXMuZ2V0TGF5ZXIoMikuZ2V0VGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgIHRoaXMuX291dHB1dC5zaGFkZXIuYSA9IHYgLSAyO1xuICAgICAgICAgICAgfSBlbHNlIGlmICh2IDw9IDQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9vdXRwdXQudGV4dHVyZSA9IHRoaXMuZ2V0TGF5ZXIoMikuZ2V0VGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgIHRoaXMuX291dHB1dC5zaGFkZXIub3RoZXJUZXh0dXJlU291cmNlID0gdGhpcy5nZXRMYXllcigzKS5nZXRUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0cHV0LnNoYWRlci5hID0gdiAtIDM7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzZXQgc2hhZGVyKHMpIHtcbiAgICAgICAgc3VwZXIuc2hhZGVyID0gcztcbiAgICAgICAgaWYgKCF0aGlzLnJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgICAgY29uc29sZS53YXJuKFwiW0xpZ2h0bmluZ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aXMubGVuZ3RoO1xuICAgICAgICBpZiAoIW5FbGVtZW50cykgcmV0dXJuO1xuXG4gICAgICAgIHRoaXMuZW1pdCgndW5mb2N1cycsIHRoaXMuZ2V0RWxlbWVudCh0aGlzLnJlYWxJbmRleCksIHRoaXMuX2luZGV4LCB0aGlzLnJlYWxJbmRleCk7XG5cbiAgICAgICAgaWYgKGNsb3Nlc3QpIHtcbiAgICAgICAgICAgIC8vIFNjcm9sbCB0byBzYW1lIG9mZnNldCBjbG9zZXN0IHRvIHRoZSBpbmRleC5cbiAgICAgICAgICAgIGxldCBvZmZzZXQgPSBVdGlscy5nZXRNb2R1bG9JbmRleChpbmRleCwgbkVsZW1lbnRzKTtcbiAgICAgICAgICAgIGxldCBvID0gVXRpbHMuZ2V0TW9kdWxvSW5kZXgodGhpcy5pbmRleCwgbkVsZW1lbnRzKTtcbiAgICAgICAgICAgIGxldCBkaWZmID0gb2Zmc2V0IC0gbztcbiAgICAgICAgICAgIGlmIChkaWZmID4gMC41ICogbkVsZW1lbnRzKSB7XG4gICAgICAgICAgICAgICAgZGlmZiAtPSBuRWxlbWVudHM7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGRpZmYgPCAtMC41ICogbkVsZW1lbnRzKSB7XG4gICAgICAgICAgICAgICAgZGlmZiArPSBuRWxlbWVudHM7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9pbmRleCArPSBkaWZmO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5faW5kZXggPSBpbmRleDtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLl9yb2xsIHx8ICh0aGlzLnZpZXdwb3J0U2l6ZSA+IHRoaXMuX2l0ZW1TaXplICogbkVsZW1lbnRzKSkge1xuICAgICAgICAgICAgdGhpcy5faW5kZXggPSBVdGlscy5nZXRNb2R1bG9JbmRleCh0aGlzLl9pbmRleCwgbkVsZW1lbnRzKTtcbiAgICAgICAgfVxuXG4gICAgICAgI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pIC8gdGhpcy5faXRlbVNpemUpO1xuICAgICAgICAgICAgcGUgPSAoKCh2aWV3cG9ydFNpemUgLSB2KSAvIHRoaXMuX2l0ZW1TaXplKSAtIGUpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcyA9IE1hdGguY2VpbCh2IC8gdGhpcy5faXRlbVNpemUpO1xuICAgICAgICAgICAgcHMgPSAxICsgKHYgLyB0aGlzLl9pdGVtU2l6ZSkgLSBzO1xuICAgICAgICAgICAgZSA9IE1hdGguY2VpbCgodiAtIHZpZXdwb3J0U2l6ZSkgLyB0aGlzLl9pdGVtU2l6ZSk7XG4gICAgICAgICAgICBwZSA9IGUgLSAoKHYgLSB2aWV3cG9ydFNpemUpIC8gdGhpcy5faXRlbVNpemUpO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9yb2xsIHx8ICh2aWV3cG9ydFNpemUgPiB0aGlzLl9pdGVtU2l6ZSAqIG5FbGVtZW50cykpIHtcbiAgICAgICAgICAgIC8vIERvbid0IHNob3cgYWRkaXRpb25hbCBpdGVtcy5cbiAgICAgICAgICAgIGlmIChlID49IG5FbGVtZW50cykge1xuICAgICAgICAgICAgICAgIGUgPSBuRWxlbWVudHMgLSAxO1xuICAgICAgICAgICAgICAgIHBlID0gMTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChzID49IG5FbGVtZW50cykge1xuICAgICAgICAgICAgICAgIHMgPSBuRWxlbWVudHMgLSAxO1xuICAgICAgICAgICAgICAgIHBzID0gMTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChlIDw9IC0xKSB7XG4gICAgICAgICAgICAgICAgZSA9IDA7XG4gICAgICAgICAgICAgICAgcGUgPSAxO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHMgPD0gLTEpIHtcbiAgICAgICAgICAgICAgICBzID0gMDtcbiAgICAgICAgICAgICAgICBwcyA9IDE7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBsZXQgb2Zmc2V0ID0gLWRpcmVjdGlvbiAqIHMgKiB0aGlzLl9pdGVtU2l6ZTtcblxuICAgICAgICBsZXQgaXRlbTtcbiAgICAgICAgZm9yIChsZXQgaW5kZXggPSBzOyAoZGlyZWN0aW9uID09IC0xID8gaW5kZXggPD0gZSA6IGluZGV4ID49IGUpOyAoZGlyZWN0aW9uID09IC0xID8gaW5kZXgrKyA6IGluZGV4LS0pKSB7XG4gICAgICAgICAgICBsZXQgcmVhbEluZGV4ID0gVXRpbHMuZ2V0TW9kdWxvSW5kZXgoaW5kZXgsIG5FbGVtZW50cyk7XG5cbiAgICAgICAgICAgIGxldCBlbGVtZW50ID0gdGhpcy5nZXRFbGVtZW50KHJlYWxJbmRleCk7XG4gICAgICAgICAgICBpdGVtID0gZWxlbWVudC5wYXJlbnQ7XG4gICAgICAgICAgICB0aGlzLl92aXNpYmxlSXRlbXMuZGVsZXRlKGl0ZW0pO1xuICAgICAgICAgICAgaWYgKHRoaXMuX2hvcml6b250YWwpIHtcbiAgICAgICAgICAgICAgICBpdGVtLnggPSBvZmZzZXQgKyBzY3JvbGxEZWx0YTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaXRlbS55ID0gb2Zmc2V0ICsgc2Nyb2xsRGVsdGE7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGxldCB3YXNWaXNpYmxlID0gaXRlbS52aXNpYmxlO1xuICAgICAgICAgICAgaXRlbS52aXNpYmxlID0gdHJ1ZTtcblxuICAgICAgICAgICAgaWYgKCF3YXNWaXNpYmxlIHx8IHRoaXMuX3JlbG9hZFZpc2libGVFbGVtZW50cykge1xuICAgICAgICAgICAgICAgIC8vIFR1cm5lZCB2aXNpYmxlLlxuICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgndmlzaWJsZScsIGluZGV4LCByZWFsSW5kZXgpO1xuICAgICAgICAgICAgfVxuXG5cblxuICAgICAgICAgICAgaWYgKHRoaXMuX3Byb2dyZXNzQW5pbWF0aW9uKSB7XG4gICAgICAgICAgICAgICAgbGV0IHAgPSAxO1xuICAgICAgICAgICAgICAgIGlmIChpbmRleCA9PSBzKSB7XG4gICAgICAgICAgICAgICAgICAgIHAgPSBwcztcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGluZGV4ID09IGUpIHtcbiAgICAgICAgICAgICAgICAgICAgcCA9IHBlO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIC8vIFVzZSBhbmltYXRpb24gdG8gcHJvZ3Jlc3MuXG4gICAgICAgICAgICAgICAgdGhpcy5fcHJvZ3Jlc3NBbmltYXRpb24uYXBwbHkoZWxlbWVudCwgcCk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIG9mZnNldCArPSB0aGlzLl9pdGVtU2l6ZTtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEhhbmRsZSBpdGVtIHZpc2liaWxpdHkuXG4gICAgICAgIGxldCBzZWxmID0gdGhpcztcbiAgICAgICAgdGhpcy5fdmlzaWJsZUl0ZW1zLmZvckVhY2goZnVuY3Rpb24oaW52aXNpYmxlSXRlbSkge1xuICAgICAgICAgICAgaW52aXNpYmxlSXRlbS52aXNpYmxlID0gZmFsc2U7XG4gICAgICAgICAgICBzZWxmLl92aXNpYmxlSXRlbXMuZGVsZXRlKGludmlzaWJsZUl0ZW0pO1xuICAgICAgICB9KTtcblxuICAgICAgICBmb3IgKGxldCBpbmRleCA9IHM7IChkaXJlY3Rpb24gPT0gLTEgPyBpbmRleCA8PSBlIDogaW5kZXggPj0gZSk7IChkaXJlY3Rpb24gPT0gLTEgPyBpbmRleCsrIDogaW5kZXgtLSkpIHtcbiAgICAgICAgICAgIGxldCByZWFsSW5kZXggPSBVdGlscy5nZXRNb2R1bG9JbmRleChpbmRleCwgbkVsZW1lbnRzKTtcbiAgICAgICAgICAgIHRoaXMuX3Zpc2libGVJdGVtcy5hZGQodGhpcy5nZXRXc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W4odikge1xuICAgICAgICB0aGlzLl9yb2xsTWluID0gdjtcbiAgICAgICAgdGhpcy51cGRhdGUoKTtcbiAgICB9XG5cbiAgICBnZXQgcm9sbE1heCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JvbGxNYXg7XG4gICAgfVxuXG4gICAgc2V0IHJvbGxNYXgodikge1xuICAgICAgICB0aGlzLl9yb2xsTWF4ID0gdjtcbiAgICAgICAgdGhpcy51cGRhdGUoKTtcbiAgICB9XG5cbiAgICBnZXQgaW52ZXJ0RGlyZWN0aW9uKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faW52ZXJ0RGlyZWN0aW9uO1xuICAgIH1cblxuICAgIHNldCBpbnZlcnREaXJlY3Rpb24odikge1xuICAgICAgICBpZiAoIXRoaXMuX3N0YXJ0ZWQpIHtcbiAgICAgICAgICAgIHRoaXMuX2ludmVydERpcmVjdGlvbiA9IHY7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgaG9yaXpvbnRhbCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2hvcml6b250YWw7XG4gICAgfVxuXG4gICAgc2V0IGhvcml6b250YWwodikge1xuICAgICAgICBpZiAodiAhPT0gdGhpcy5faG9yaXpvbnRhbCkge1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9zdGFydGVkKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5faG9yaXpvbnRhbCA9IHY7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbn1cblxuaW1wb3J0IE9iamVjdExpc3RXcmFwcGVyIGZyb20gXCIuLi90b29scy9PYmplY3RMaXN0V3JhcHBlci5tanNcIjtcbmNsYXNzIExpc3RJdGVtcyBleHRlbmRzIE9iamVjdExpc3RXcmFwcGVyIHtcbiAgICBjb25zdHJ1Y3RvcihsaXN0KSB7XG4gICAgICAgIGxldCB3cmFwID0gKGl0ZW0gPT4ge1xuICAgICAgICAgICAgbGV0IHBhcmVudCA9IGl0ZW0uc3RhZ2UuY3JlYXRlRWxlbWVudCgpO1xuICAgICAgICAgICAgcGFyZW50LmFkZChpdGVtKTtcbiAgICAgICAgICAgIHBhcmVudC52aXNpYmxlID0gZmFsc2U7XG4gICAgICAgICAgICByZXR1cm4gcGFyZW50O1xuICAgICAgICB9KVxuXG4gICAgICAgIHN1cGVyKGxpc3QuX3dyYXBwZXIuX2NoaWxkcmVuLCB3cmFwKTtcbiAgICAgICAgdGhpcy5saXN0ID0gbGlzdDtcbiAgICB9XG5cbiAgICBvbkFkZChpdGVtLCBpbmRleCkge1xuICAgICAgICBzdXBlci5vbkFkZChpdGVtLCBpbmRleCk7XG4gICAgICAgIHRoaXMuY2hlY2tTdGFydGVkKGluZGV4KTtcbiAgICB9XG5cbiAgICBjaGVja1N0YXJ0ZWQoaW5kZXgpIHtcbiAgICAgICAgdGhpcy5saXN0Ll9yZWxvYWRWaXNpYmxlRWxlbWVudHMgPSB0cnVlO1xuICAgICAgICBpZiAoIXRoaXMubGlzdC5fc3RhcnRlZCkge1xuICAgICAgICAgICAgdGhpcy5saXN0LnN0YXJ0KCk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodGhpcy5saXN0Lmxlbmd0aCA9PT0gMSkge1xuICAgICAgICAgICAgICAgIHRoaXMubGlzdC5zZXRJbmRleCgwLCB0cnVlLCB0cnVlKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMubGlzdC5faW5kZXggPj0gdGhpcy5saXN0Lmxlbmd0aCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmxpc3Quc2V0SW5kZXgoMCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5saXN0LnVwZGF0ZSgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgb25SZW1vdmUoaXRlbSwgaW5kZXgpIHtcbiAgICAgICAgc3VwZXIub25SZW1vdmUoaXRlbSwgaW5kZXgpO1xuICAgICAgICBsZXQgcmkgPSB0aGlzLmxpc3QucmVhbEluZGV4O1xuICAgICAgICBpZiAocmkgPT09IGluZGV4KSB7XG4gICAgICAgICAgICBpZiAocmkgPT09IHRoaXMubGlzdC5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICByaS0tO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHJpID49IDApIHtcbiAgICAgICAgICAgICAgICB0aGlzLmxpc3Quc2V0SW5kZXgocmkpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHJpID4gaW5kZXgpIHtcbiAgICAgICAgICAgIHRoaXMubGlzdC5zZXRJbmRleChyaSAtIDEpO1xuICAgICAgICB9XG5cbiAgICAgICAgdGhpcy5saXN0Ll9yZWxvYWRWaXNpYmxlRWxlbWVudHMgPSB0cnVlO1xuICAgIH1cblxuICAgIG9uU2V0KGl0ZW0sIGluZGV4KSB7XG4gICAgICAgIHN1cGVyLm9uU2V0KGl0ZW0sIGluZGV4KTtcbiAgICAgICAgdGhpcy5jaGVja1N0YXJ0ZWQoaW5kZXgpO1xuICAgIH1cblxuICAgIG9uU3luYyhyZW1vdmVkLCBhZGRlZCwgb3JkZXIpIHtcbiAgICAgICAgc3VwZXIub25TeW5jKHJlbW92ZWQsIGFkZGVkLCBvcmRlcik7XG4gICAgICAgIHRoaXMuY2hlY2tTdGFydGVkKDApO1xuICAgIH1cblxuICAgIGdldCBfc2lnbmFsUHJveHkoKSB7XG4gICAgICAgIHJldHVybiB0cnVlO1xuICAgIH1cblxufVxuXG5pbXBvcnQgVXRpbHMgZnJvbSBcIi4uL3RyZWUvVXRpbHMubWpzXCI7XG4iLCIvKlxuICogSWYgbm90IHN0YXRlZCBvdGhlcndpc2UgaW4gdGhpcyBmaWxlIG9yIHRoaXMgY29tcG9uZW50J3MgTElDRU5TRSBmaWxlIHRoZVxuICogZm9sbG93aW5nIGNvcHlyaWdodCBhbmQgbGljZW5zZXMg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ge3JlbmRlck9mZnNjcmVlbjogdHJ1ZSwgZm9yY2VaSW5kZXhDb250ZXh0OiB0cnVlLCBvbkFmdGVyVXBkYXRlOiBTbW9vdGhTY2FsZUNvbXBvbmVudC5fdXBkYXRlRGltZW5zaW9ucyxcbiAgICAgICAgICAgICAgICBDb250ZW50OiB7fVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIFNjYWxlOiB7dmlzaWJsZTogZmFsc2V9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBjb25zdHJ1Y3RvcihzdGFnZSkge1xuICAgICAgICBzdXBlcihzdGFnZSk7XG5cbiAgICAgICAgdGhpcy5fc21vb3RoU2NhbGUgPSAxO1xuICAgICAgICB0aGlzLl9pdGVyYXRpb25zID0gMDtcbiAgICB9XG5cbiAgICBnZXQgY29udGVudCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMudGFnKCdDb250ZW50Jyk7XG4gICAgfVxuXG4gICAgc2V0IGNvbnRlbnQodikge1xuICAgICAgICB0aGlzLnRhZygnQ29udGVudCcpLnBhdGNoKHYsIHRydWUpO1xuICAgIH1cblxuICAgIGdldCBzbW9vdGhTY2FsZSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3Ntb290aFNjYWxlO1xuICAgIH1cblxuICAgIHNldCBzbW9vdGhTY2FsZSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9zbW9vdGhTY2FsZSAhPT0gdikge1xuICAgICAgICAgICAgbGV0IGl0cyA9IDA7XG4gICAgICAgICAgICB3aGlsZSh2IDwgMC41ICYmIGl0cyA8IDEyKSB7XG4gICAgICAgICAgICAgICAgaXRzKys7XG4gICAgICAgICAgICAgICAgdiA9IHYgKiAyO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLnNjYWxlID0gdjtcbiAgICAgICAgICAgIHRoaXMuX3NldEl0ZXJhdGlvbnMoaXRzKTtcblxuICAgICAgICAgICAgdGhpcy5fc21vb3RoU2NhbGUgPSB2O1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srKSB7XG4gICAgICAgICAgICAgICAgc2NhbGVycy5nZXRBdChpKS5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIHZpc2libGU6IGkgPCBpdHMsXG4gICAgICAgICAgICAgICAgICAgIHJlbmRlck9mZnNjcmVlbjogaSAhPT0gaXRzIC0gMVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5faXRlcmF0aW9ucyA9IGl0cztcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHN0YXRpYyBfdXBkYXRlRGltZW5zaW9ucyhjb250ZW50V3JhcCwgZm9yY2UpIHtcbiAgICAgICAgY29uc3QgY29udGVudCA9IGNvbnRlbnRXcmFwLmNoaWxkcmVuWzBdO1xuICAgICAgICBsZXQgdyA9IGNvbnRlbnQucmVuZGVyV2lkdGg7XG4gICAgICAgIGxldCBoID0gY29udGVudC5yZW5kZXJIZWlnaHQ7XG4gICAgICAgIGlmICh3ICE9PSBjb250ZW50V3JhcC53IHx8IGggIT09IGNvbnRlbnRXcmFwLmggfHwgZm9yY2UpIHtcbiAgICAgICAgICAgIGNvbnRlbnRXcmFwLncgPSB3O1xuICAgICAgICAgICAgY29udGVudFdyYXAuaCA9IGg7XG5cbiAgICAgICAgICAgIGNvbnN0IHNjYWxlcnMgPSBjb250ZW50V3JhcC5wYXJlbnQudGFnKFwiU2NhbGVcIikuY2hpbGRyZW47XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHNjYWxlcnMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgdyA9IHcgKiAwLjU7XG4gICAgICAgICAgICAgICAgaCA9IGggKiAwLjU7XG4gICAgICAgICAgICAgICAgc2NhbGVyc1tpXS53ID0gdztcbiAgICAgICAgICAgICAgICBzY2FsZXJzW2ldLmggPSBoO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IF9zaWduYWxQcm94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l9jaGFuZ2VkQ29udGVudHMoKTtcbiAgICB9XG5cbiAgICBnZXQgYWxpZ25Db250ZW50KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fYWxpZ25Db250ZW50O1xuICAgIH1cblxuICAgIHNldCBhbGlnbkNvbnRlbnQodikge1xuICAgICAgICBpZiAodGhpcy5fYWxpZ25Db250ZW50ID09PSB2KSByZXR1cm47XG4gICAgICAgIGlmIChGbGV4Q29udGFpbmVyLkFMSUdOX0NPTlRFTlQuaW5kZXhPZih2KSA9PT0gLTEpIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihcIlVua25vd24gYWxpZ25Db250ZW50LCBvcHRpb25zOiBcIiArIEZsZXhDb250YWluZXIuQUxJR05fQ09OVEVOVC5qb2luKFwiLFwiKSk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fYWxpZ25Db250ZW50ID0gdjtcblxuICAgICAgICB0aGlzLl9jaGFuZ2VkQ29udGVudHMoKTtcbiAgICB9XG5cbiAgICBnZXQganVzdGlmeUNvbnRlbnQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9qdXN0aWZ5Q29udGVudDtcbiAgICB9XG5cbiAgICBzZXQganVzdGlmeUNvbnRlbnQodikge1xuICAgICAgICBpZiAodGhpcy5fanVzdGlmeUNvbnRlbnQgPT09IHYpIHJldHVybjtcblxuICAgICAgICBpZiAoRmxleENvbnRhaW5lci5KVVNUSUZZX0NPTlRFTlQuaW5kZXhPZih2KSA9PT0gLTEpIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihcIlVua25vd24ganVzdGlmeUNvbnRlbnQsIG9wdGlvbnM6IFwiICsgRmxleENvbnRhaW5lci5KVVNUSUZZX0NPTlRFTlQuam9pbihcIixcIikpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX2p1c3RpZnlDb250ZW50ID0gdjtcblxuICAgICAgICB0aGlzLl9jaGFuZ2VkQ29udGVudHMoKTtcbiAgICB9XG5cbiAgICB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VmaW5lZDtcbiAgICAgICAgdGhpcy5fbWluV2lkdGggPSAwO1xuICAgICAgICB0aGlzLl9taW5IZWlnaHQgPSAwO1xuICAgICAgICB0aGlzLl9tYXhXaWR0aCA9IDA7XG4gICAgICAgIHRoaXMuX21heEhlaWdodCA9IDA7XG5cbiAgICAgICAgdGhpcy5fbWFyZ2luTGVmdCA9IDA7XG4gICAgICAgIHRoaXMuX21hcmdpblRvcCA9IDA7XG4gICAgICAgIHRoaXMuX21hcmdpblJpZ2h0ID0gMDtcbiAgICAgICAgdGhpcy5fbWFyZ2luQm90dG9tID0gMDtcbiAgICB9XG5cbiAgICBnZXQgaXRlbSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2l0ZW07XG4gICAgfVxuXG4gICAgZ2V0IGdyb3coKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9ncm93O1xuICAgIH1cblxuICAgIHNldCBncm93KHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX2dyb3cgPT09IHYpIHJldHVybjtcblxuICAgICAgICB0aGlzLl9ncm93ID0gcGFyc2VJbnQodikgfHwgMDtcblxuICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgfVxuXG4gICAgZ2V0IHNocmluaygpIHtcbiAgICAgICAgaWYgKHRoaXMuX3NocmluayA9PT0gRmxleEl0ZW0uU0hSSU5LX0FVVE8pIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9nZXREZWZhdWx0U2hyaW5rKCk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRoaXMuX3NocmluaztcbiAgICB9XG5cbiAgICBfZ2V0RGVmYXVsdFNocmluaygpIHtcbiAgICAgICAgaWYgKHRoaXMuaXRlbS5pc0ZsZXhFbmFibGVkKCkpIHtcbiAgICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgLy8gQWxsIG5vbi1mbGV4IGNvbnRhaW5lcnMgYXJlIGFic29sdXRlbHkgcG9zaXRpb25lZCBpdGVtcyB3aXRoIGZpeGVkIGRpbWVuc2lvbnMsIGFuZCBieSBkZWZhdWx0IG5vdCBzaHJpbmthYmxlLlxuICAgICAgICAgICAgcmV0dXJuIDA7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzZXQgc2hyaW5rKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX3NocmluayA9PT0gdikgcmV0dXJuO1xuXG4gICAgICAgIHRoaXMuX3NocmluayA9IHBhcnNlSW50KHYpIHx8IDA7XG5cbiAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgIH1cblxuICAgIGdldCBhbGlnblNlbGYoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9hbGlnblNlbGY7XG4gICAgfVxuXG4gICAgc2V0IGFsaWduU2VsZih2KSB7XG4gICAgICAgIGlmICh0aGlzLl9hbGlnblNlbGYgPT09IHYpIHJldHVybjtcblxuICAgICAgICBpZiAodiA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICB0aGlzLl9hbGlnblNlbGYgPSB1bmRlZmluZWQ7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAoRmxleENvbnRhaW5lci5BTElHTl9JVEVNUy5pbmRleE9mKHYpID09PSAtMSkge1xuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihcIlVua25vd24gYWxpZ25TZWxmLCBvcHRpb25zOiBcIiArIEZsZXhDb250YWluZXIuQUxJR05fSVRFTVMuam9pbihcIixcIikpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fYWxpZ25TZWxmID0gdjtcbiAgICAgICAgfVxuXG4gICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICB9XG5cbiAgICBnZXQgbWluV2lkdGgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9taW5XaWR0aDtcbiAgICB9XG5cbiAgICBzZXQgbWluV2lkdGgodikge1xuICAgICAgICB0aGlzLl9taW5XaWR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RoaXMuaXNDaGFuZ2VkKCkpIHtcbiAgICAgICAgICAgIHRoaXMuZmxleExheW91dC5sYXlvdXRUcmVlKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgdGFyZ2V0KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdGFyZ2V0O1xuICAgIH1cblxuICAgIGdldCBmbGV4KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fZmxleDtcbiAgICB9XG5cbiAgICBzZXQgZmxleCh2KSB7XG4gICAgICAgIGlmICghdikge1xuICAgICAgICAgICAgaWYgKHRoaXMuaXNGbGV4RW5hYmxlZCgpKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fZGlzYWJsZUZsZXgoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5pc0ZsZXhFbmFibGVkKCkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9lbmFibGVGbGV4KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9mbGV4LnBhdGNoKHYpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGZsZXhJdGVtKCkge1xuICAgICAgICBpZiAodGhpcy5fZmxleEl0ZW1EaXNhYmxlZCkge1xuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX2Vuc3VyZUZsZXhJdGVtKCk7XG4gICAgICAgIHJldHVybiB0aGlzLl9mbGV4SXRlbTtcbiAgICB9XG5cbiAgICBzZXQgZmxleEl0ZW0odikge1xuICAgICAgICBpZiAodiA9PT0gZmFsc2UpIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5fZmxleEl0ZW1EaXNhYmxlZCkge1xuICAgICAgICAgICAgICAgIGNvbnN0IHBhcmVudCA9IHRoaXMuZmxleFBhcmVudDtcbiAgICAgICAgICAgICAgICB0aGlzLl9mbGV4SXRlbURpc2FibGVkID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICB0aGlzLl9jaGVja0VuYWJsZWQoKTtcbiAgICAgICAgICAgICAgICBpZiAocGFyZW50KSB7XG4gICAgICAgICAgICAgICAgICAgIHBhcmVudC5fY2xlYXJGbGV4SXRlbXNDYWNoZSgpO1xuICAgICAgICAgICAgICAgICAgICBwYXJlbnQuY2hhbmdlZENvbnRlbnRzKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fZW5zdXJlRmxleEl0ZW0oKTtcblxuICAgICAgICAgICAgdGhpcy5fZmxleEl0ZW0ucGF0Y2godik7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9mbGV4SXRlbURpc2FibGVkKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fZmxleEl0ZW1EaXNhYmxlZCA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIHRoaXMuX2NoZWNrRW5hYmxlZCgpO1xuICAgICAgICAgICAgICAgIGNvbnN0IHBhcmVudCA9IHRoaXMuZmxleFBhcmVudDtcbiAgICAgICAgICAgICAgICBpZiAocGFyZW50KSB7XG4gICAgICAgICAgICAgICAgICAgIHBhcmVudC5fY2xlYXJGbGV4SXRlbXNDYWNoZSgpO1xuICAgICAgICAgICAgICAgICAgICBwYXJlbnQuY2hhbmdlZENvbnRlbnRzKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2VuYWJsZUZsZXgoKSB7XG4gICAgICAgIHRoaXMuX2ZsZXggPSBuZXcgRmxleENvbnRhaW5lcih0aGlzKTtcbiAgICAgICAgdGhpcy5fY2hlY2tFbmFibGVkKCk7XG4gICAgICAgIHRoaXMuY2hhbmdlZERpbWVuc2lvbnMoKTtcbiAgICAgICAgdGhpcy5fZW5hYmxlQ2hpbGRyZW5Bc0ZsZXhJdGVtcygpO1xuICAgIH1cblxuICAgIF9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XJlbnQuX2xheW91dDtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gbnVsbDtcbiAgICB9XG5cbiAgICBzZXRWaXNpYmxlKHYpIHtcbiAgICAgICAgY29uc3QgcGFyZW50ID0gdGhpcy5mbGV4UGFyZW50O1xuICAgICAgICBpZiAocGFyZW50KSB7XG4gICAgICAgICAgICBwYXJlbnQuX2NoYW5nZWRDaGlsZHJlbigpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGl0ZW1zKCkge1xuICAgICAgICBpZiAoIXRoaXMuX2l0ZW1zKSB7XG4gICAgICAgICAgICB0aGlzLl9pdGVtcyA9IHRoaXMuX2dldEZsZXhJdGVtcygpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0aGlzLl9pdGVtcztcbiAgICB9XG5cbiAgICBfZ2V0RmxleEl0ZW1zKCkge1xuICAgICAgICBjb25zdCBpdGVtcyA9IFtdO1xuICAgICAgICBjb25zdCBjaGlsZHJlbiA9IHRoaXMuX3RhcmdldC5fY2hpbGRyZW47XG4gICAgICAgIGlmIChjaGlsZHJlbikge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBjaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICBjb25zdCBpdGVtID0gY2hpbGRyZW5baV07XG4gICAgICAgICAgICAgICAgaWYgKGl0ZW0udmlzaWJsZSkge1xuICAgICAgICAgICAgICAgICAgICBpZiAoaXRlbS5pc0ZsZXhJdGVtKCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGl0ZW1zLnB1c2goaXRlbS5sYXlvdXQpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBpdGVtcztcbiAgICB9XG5cbiAgICBfY2hhbmdlZENoaWxkcmVuKCkge1xuICAgICAgICB0aGlzLl9jbGVhckZsZXhJd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ICAgICAgICAgIGNvbnN0IGNyb3NzQXhpc0lzRml0VG9Db250ZW50cyA9IGxheW91dC5pc0Nyb3NzQXhpc0ZpdFRvQ29udGVudHMoKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGNyb3NzQXhpc0lzRml0VG9Db250ZW50cykge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gU3BlY2lhbCBjYXNlOiBkdWUgdG8gd3JhcHBpbmcsIHRoZSBjcm9zcyBheGlzIHNpemUgbWF5IGJlIGNoYW5nZWQuXG4gICAgICAgICAgICAgICAgICAgICAgICBjaGlsZFJlY2FsYyArPSBjcm9zc0F4aXNSZWNhbGNGbGFnO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgbGV0IGlzV2lkdGhEeW5hbWljID0gbGF5b3V0LmlzQXhpc0ZpdFRvQ29udGVudHModHJ1ZSk7XG4gICAgICAgIGxldCBpc0hlaWdodER5bmFtaWMgPSBsYXlvdXQuaXNBeGlzRml0VG9Db250ZW50cyhmYWxzZSk7XG5cbiAgICAgICAgaWYgKGxheW91dC5zaHJ1bmspIHtcbiAgICAgICAgICAgIC8vIElmIGR1cmluZyBwcmV2aW91cyBsYXlvdXQgdGhpcyBjb250YWluZXIgd2FzICdzaHJ1bmsnLCBhbnkgY2hhbmdlcyBtYXkgY2hhbmdlIHRoZSAnbWluIGF4aXMgc2l6ZScgb2YgdGhlXG4gICAgICAgICAgICAvLyBjb250ZW50cywgbGVhZGluZyB0byBhIGRpZmZlcmVudCBheGlzIHNpemUgb24gdGhpcyBjb250YWluZXIgZXZlbiB3aGVuIGl0IHdhcyBub3QgJ2ZpdCB0byBjb250ZW50cycuXG4gICAgICAgICAgICBpZiAobGF5b3V0Ll9ob3Jpem9udGFsKSB7XG4gICAgICAgICAgICAgICAgaXNXaWR0aER5bmFtaWMgPSB0cnVlO1xuICAgICAgICAgICAgfSBlbHNlIH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iAwO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29uc3QgZmxleFBhcmVudCA9IGl0ZW0uZmxleFBhcmVudDtcbiAgICAgICAgICAgIGlmIChmbGV4UGFyZW50KSB7XG4gICAgICAgICAgICAgICAgLy8gVXNlIHBlbmRpbmcgbGF5b3V0IHNpemUuXG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuZ2V0QXhpc0xheW91dFNpemUoZmxleFBhcmVudCwgaG9yaXpvbnRhbCkgKyB0aGlzLmdldFRvdGFsUGFkZGluZyhmbGV4UGFyZW50LCBob3Jpem9udGFsKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gVXNlICdhYnNvbHV0ZScgc2l6ZS5cbiAgICAgICAgICAgICAgICByZXR1cm4gaG9yaXpvbnRhbCA/IHBhcmVudC53IDogcGFyZW50Lmg7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0UmVsQXhpc1NpemUoaXRlbSwgaG9yaXpvbnRhbCkge1xuICAgICAgICBpZiAoaG9yaXpvbnRhbCkge1xuICAgICAgICAgICAgaWYgKGl0ZW0uZnVuY1cpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYWxsb3dSZWxBeGlzU2l6ZUZ1bmN0aW9uKGl0ZW0sIHRydWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBpdGVtLmZ1bmNXKHRoaXMuZ2V0UGFyZW50QXhpc1NpemVXaXRoUGFkZGluZyhpdGVtLCB0cnVlKSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gaXRlbS5vcmlnaW5hbFdpZHRoO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKGl0ZW0uZnVuY0gpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYWxsb3dSZWxBeGlzU2l6ZUZ1bmN0aW9uKGl0ZW0sIGZhbHNlKSkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaXRlbS5mdW5jSCh0aGlzLmdldFBhcmVudEF4aXNTaXplV2l0aFBhZGRpbmcoaXRlbSwgZmFsc2UpKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gMDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJldHVybiBpdGVtLm9yaWdpbmFsSGVpZ2h0O1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIF9hbGxvd1JlbEF4aXNTaXplRnVuY3Rpb24oaXRlbSwgaG9yaXpvbnRhbCkge1xuICAgICAgICBjb25zdCBmbGV4UGFyZW50ID0gaXRlbS5mbGV4UGFyZW50O1xuICAgICAgICBpZiAoZmxleFBhcmVudCAmJiBmbGV4UGFyZW50Ll9mbGV4Ll9sYXlvdXQuaXNBeGlzRml0VG9Db250ZW50cyhob3Jpem9udGFsKSkge1xuICAgICAgICAgICAgLy8gV2UgZG9uJ3QgYWxsb3cgcmVsYXRpdmUgd2lkdGggb24gZml0LXRvLWNvbnRlbnRzIGJlY2F1c2UgaXQgbGVhZHMgdG8gY29uZmxpY3RzLlxuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0cnVlO1xuICAgIH1cblxuICAgIHN0YXRpYyBpc1plcm9BeGlzU2l6ZShpdGVtLCBob3Jpem9udGFsKSB7XG4gICAgICAgIGlmIChob3Jpem9udGFsKSB7XG4gICAgICAgICAgICByZXR1cm4gIWl0ZW0ub3JpZ2luYWxXaWR0aCAmJiAhaXRlbS5mdW5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WJsZWQoKSkge1xuICAgICAgICAgICAgZmxleEl0ZW1NaW5TaXplID0gaXRlbS5fZmxleEl0ZW0uX2dldE1pblNpemVTZXR0aW5nKGhvcml6b250YWwpO1xuICAgICAgICB9XG5cbiAgICAgICAgY29uc3QgaGFzTGltaXRlZE1pblNpemUgPSAoZmxleEl0ZW1NaW5TaXplID4gMCk7XG4gICAgICAgIGlmIChoYXNMaW1pdGVkTWluU2l6ZSkge1xuICAgICAgICAgICAgbWluU2l6ZSA9IE1hdGgubWF4KG1pblNpemUsIGZsZXhJdGVtTWluU2l6ZSk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIG1pblNpemU7XG4gICAgfVxuXG4gICAgc3RhdGljIGdldFBsYWluQXhpc01pblNpemUoaXRlbSwgaG9yaXpvbnRhbCkge1xuICAgICAgICBpZiAoaXRlbS5pc0ZsZXhFbmFibGVkKCkpIHtcbiAgICAgICAgICAgIHJldHVybiBpdGVtLl9mbGV4Ll9sYXlvdXQuZ2V0QXhpc01pblNpemUoaG9yaXpvbnRhbCk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb25zdCBpc1Nocmlua2FibGUgPSAoaXRlbS5mbGV4SXRlbS5zaHJpbmsgIT09IDApO1xuICAgICAgICAgICAgaWYgKGlzU2hyaW5rYWJsZSkge1xuICAgICAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5nZXRSZWxBeGlzU2l6ZShpdGVtLCBob3Jpem9udGFsKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHN0YXRpYyByZXNpemVBeGlzKGl0ZW0sIGhvcml6b250YWwsIHNpemUpIHtcbiAgICAgICAgaWYgKGl0ZW0uaXNGbGV4RW5hYmxlZCgpKSB7XG4gICAgICAgICAgICBjb25zdCBpc01haW5BeGlzID0gKGl0ZW0uX2ZsZXguX2hvcml6b250YWwgPT09IGhvcml6b250YWwpO1xuICAgICAgICAgICAgaWYgKGlzTWFpbkF4aXMpIHtcbiAgICAgICAgICAgICAgICBpdGVtLl9mbGV4Ll9sYXlvdXQucmVzaXplTWFpbkF4aXMoc2l6ZSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGl0ZW0uX2ZsZXguX2xheW91dC5yZXNpemVDcm9zc0F4aXMoc2l6ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLnNldEF4aXNMYXlvdXRTaXplKGl0ZW0sIGhvcml6b250YWwsIHNpemUpO1xuICAgICAgICB9XG4gICAgfVxuXG5cbiAgICBzdGF0aWMgZ2V0UGFkZGluZ09mZnNldChpdGVtLCBob3Jpem9udGFsKSB7XG4gICAgICAgIGlmIChpdGVtLmlzRmxleEVuYWJsZWQoKSkge1xuICAgICAgICAgICAgY29uc3QgZmxleCA9IGl0ZW0uX2ZsZXg7XG4gICAgICAgICAgICBpZiAoaG9yaXpvbnRhbCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBmbGV4LnBhZGRpbmdMZWZ0O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmxleC5wYWRkaW5nVG9wO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIDA7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0VG90YWxQYWRkaW5nKGl0ZW0sIGhvcml6b250YWwpIHtcbiAgICAgICAgaWYgKGl0ZW0uaXNGbGV4RW5hYmxlZCgpKSB7XG4gICAgICAgICAgICBjb25zdCBmbGV4ID0gaXRlbS5fZmxleDtcbiAgICAgICAgICAgIGlmIChob3Jpem9udGFsKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZsZXgucGFkZGluZ1JpZ2h0ICsgZmxleC5wYWRkaW5nTGVmdDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZsZXgucGFkZGluZ1RvcCArIGZsZXgucGFkZGluZ0JvdHRvbTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGdldE1hcmdpbk9mZnNldChpdGVtLCBob3Jpem9udGFsKSB7XG4gICAgICAgIGNvbnN0IGZsZXhJdGVtID0gaXRlbS5mbGV4SXRlbTtcbiAgICAgICAgaWYgKGZsZXhJdGVtKSB7XG4gICAgICAgICAgICBpZiAoaG9yaXpvbnRhbCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBmbGV4SXRlbS5tYXJnaW5MZWZ0O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmxleEl0ZW0ubWFyZ2luVG9wO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIDA7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0VG90YWxNYXJnaW4oaXRlbSwgaG9yaXpvbnRhbCkge1xuICAgICAgICBjb25zdCBmbGV4SXRlbSA9IGl0ZW0uZmxleEl0ZW07XG4gICAgICAgIGlmIChmbGV4SXRlbSkge1xuICAgICAgICAgICAgaWYgKGhvcml6b250YWwpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmxleEl0ZW0ubWFyZ2luUmlnaHQgKyBmbGV4SXRlbS5tYXJnaW5MZWZ0O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmxleEl0ZW0ubWFyZ2luVG9wICsgZmxleEl0ZW0ubWFyZ2luQm90dG9tO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIDA7XG4gICA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dDcm9zc0F4aXMgPSBmYWxzZTtcbiAgICAgICAgdGhpcy5fc2hydW5rID0gZmFsc2U7XG4gICAgfVxuXG4gICAgX2xheW91dEF4ZXMoKSB7XG4gICAgICAgIHRoaXMuX2xheW91dE1haW5BeGlzKCk7XG4gICAgICAgIHRoaXMuX2xheW91dENyb3NzQXhpcygpO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIEBwcmUgbWFpbkF4aXNTaXplIHNob3VsZCBleGNsdWRlIHBhZGRpbmcuXG4gICAgICovXG4gICAgX2xheW91dE1haW5BeGlzKCkge1xuICAgICAgICB0aGlzLl9sYXlvdXRMaW5lcygpO1xuICAgICAgICB0aGlzLl9maXRNYWluQXhpc1NpemVUb0NvbnRlbnRzKCk7XG4gICAgfVxuXG4gICAgX2xheW91dExpbmVzKCkge1xuICAgICAgICB0aGlzLl9saW5lTGF5b3V0ZXIubGF5b3V0TGluZXMoKTtcbiAgICB9XG5cbiAgICBnZXQgX2xpbmVzKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbGluZUxheW91dGVyLmxpbmVzO1xuICAgIH1cblxuICAgIF9maXRNYWluQXhpc1NpemVUb0NvbnRlbnRzKCkge1xuICAgICAgICBpZiAoIXRoaXMuX3Jlc2l6aW5nTWFpbkF4aXMpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLmlzTWFpbkF4aXNGaXRUb0NvbnRlbnRzKCkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLm1haW5BeGlzU2l6ZSA9IHRoaXMuX2xpbmVMYXlvdXRlci5tYWluQXhpc0NvbnRlbnRTaXplO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogQHByZSBjcm9zc0F4aXNTaXplIHNob3VsZCBleGNsdWRlIHBhZGRpbmcuXG4gICAgICovXG4gICAgX2xheW91dENyb3NzQXhpcygpIHtcbiAgICAgICAgY29uc3QgYWxpZ25lciA9IG5ldyBDb250ZW50QWxpZ25lcih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lc2l6ZU1haW5BeGlzKHNpemUpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fY2hlY2tWYWxpZENhY2hlTWFpbkF4aXNSZXNpemUoKSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLm1haW5BeGlzU2l6ZSA9IHNpemU7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2ZpdENyb3NzQXhpc1NpemVUb0NvbnRlbnRzKCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gQ2FjaGUgbWlzcy5cbiAgICAgICAgICAgICAgICAgICAgdGhpcy5pdGVtLmVuYWJsZUxvY2FsUmVjYWxjRmxhZygpO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnBlcmZvcm1SZXNpemVNYWluQXhpcyhzaXplKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfY2hlY2tWYWxpZENhY2hlTWFpbkF4aXNSZXNpemUoc2l6ZSkge1xuICAgICAgICBjb25zdCBpc0ZpbmFsTWFpbkF4aXNTaXplID0gKHNpemUgPT09IHRoaXMudGFyZ2V0TWFpbkF4aXNTaXplKTtcbiAgICAgICAgaWYgKGlzRmluYWxNYWluQXhpc1NpemUpIHtcbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG4gICAgICAgIGNvbnN0IGNhbklnbm9yZUNhY2hlTWlzcyA9ICF0aGlzLmlzQ3Jvc3NBeGlzRml0VG9Db250ZW50cygpO1xuICAgICAgICBpZiAoY2FuSWdub3JlQ2FjaGVNaXNzKSB7XG4gICAgICAgICAgICAvLyBBbGxvdyBvdGhlciBtYWluIGF4aXMgcmVzaXplcyBhbmQgY2hlY2sgaWYgZmluYWwgcmVzaXplIG1hdGNoZXMgdGhlIHRhcmdldCBtYWluIGF4aXMgc2l6ZVxuICAgICAgICAgICAgLy8gI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bkF4aXNTaXplID4gdGhpcy5fbWFpbkF4aXNTaXplKTtcbiAgICAgICAgICAgICAgICBpZiAoaXNPdmVyZmxvd2luZykge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9sYXlvdXRMaW5lKHN0YXJ0SW5kZXgsIGkgLSAxKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fY3VyTWFpbkF4aXNQb3MgPSAwO1xuICAgICAgICAgICAgICAgICAgICBzdGFydEluZGV4ID0gaTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRoaXMuX2FkZFRvTWFpbkF4aXNQb3MoaXRlbU1haW5BeGlzU2l6ZSk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoc3RhcnRJbmRleCA8IGkpIHtcbiAgICAgICAgICAgIHRoaXMuX2xheW91dExpbmUoc3RhcnRJbmRleCwgaSAtIDEpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2xheW91dEZsZXhJdGVtKGl0ZW0pIHtcbiAgICAgICAgaWYgKGl0ZW0uaXNGbGV4RW5hYmxlZCgpKSB7XG4gICAgICAgICAgICBpdGVtLmZsZXhMYXlvdXQudXBkYXRlVHJlZUxheW91dCgpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaXRlbS5mbGV4SXRlbS5fcmVzZXRMYXlvdXRTaXplKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfc2V0dXAoKSB7XG4gICAgICAgIHRoaXMuX21haW5BeGlzU2l6ZSA9IHRoaXMuX2xheW91dC5tYWluQXhpc1NpemU7XG4gICAgICAgIHRoaXMuX2N1ck1haW5BeGlzUG9zID0gMDtcbiAgICAgICAgdGhpcy5fbWF4TWFpbkF4aXNQb3MgPSAwO1xuICAgICAgICB0aGlzLl9saW5lcyA9IFtdO1xuXG4gICAgICAgIHRoaXMuX21haW5BeGlzTWluU2l6ZSA9IC0xO1xuICAgICAgICB0aGlzLl9jcm9zc0F4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AgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICBjYXNlIFwic3BhY2UtYXJvdW5kXCI6XG4gICAgICAgICAgICAgICAgaWYgKHJlbWFpbmluZ1NwYWNlIDwgMCkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5nZXRTcGFjaW5nKFwiY2VudGVyXCIsIG51bWJlck9mSXRlbXMsIHJlbWFpbmluZ1NwYWNlKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBzcGFjZVBlckdhcCA9IHJlbWFpbmluZ1NwYWNlIC8gKGl0ZW1HYXBzICsgMSk7XG4gICAgICAgICAgICAgICAgICAgIHNwYWNpbmdCZWZvcmUgPSAwLjUgKiBzcGFjZVBlckdhcDtcbiAgICAgICAgICAgICAgICAgICAgc3BhY2luZ0JldHdlZW4gPSBzcGFjZVBlckdhcDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICBjYXNlIFwic3BhY2UtZXZlbmx5XCI6XG4gICAgICAgICAgICAgICAgaWYgKHJlbWFpbmluZ1NwYWNlIDwgMCkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5nZXRTcGFjaW5nKFwiY2VudGVyXCIsIG51bWJlck9mSXRlbXMsIHJlbWFpbmluZ1NwYWNlKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBzcGFjZVBlckdhcCA9IHJlbWFpbmluZ1NwYWNlIC8gKGl0ZW1HYXBzICsgMik7XG4gICAgICAgICAgICAgICAgICAgIHNwYWNpbmdCZWZvcmUgPSBzcGFjZVBlckdhcDtcbiAgICAgICAgICAgICAgICAgICAgc3BhY2luZ0JldHdlZW4gPSBzcGFjZVBlckdhcDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICBjYXNlIFwic3RyZXRjaFwiOlx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6ZSA9IDA7XG5cbiAgICAgICAgdGhpcy5fYW1vdW50UmVtYWluaW5nID0gYW1vdW50O1xuICAgICAgICBsZXQgdG90YWxHcm93QW1vdW50ID0gdGhpcy5fZ2V0VG90YWxHcm93QW1vdW50KCk7XG4gICAgICAgIGlmICh0b3RhbEdyb3dBbW91bnQpIHtcbiAgICAgICAgICAgIGNvbnN0IGl0ZW1zID0gdGhpcy5fbGluZS5pdGVtcztcbiAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICBsZXQgYW1vdW50UGVyR3JvdyA9IHRoaXMuX2Ftb3VudFJlbWFpbmluZyAvIHRvdGFsR3Jvd0Ftb3VudDtcbiAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gdGhpcy5fbGluZS5zdGFydEluZGV4OyBpIDw9IHRoaXMuX2xpbmUuZW5kSW5kZXg7IGkrKykge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBpdGVtID0gaXRlbXNbaV07XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGZsZXhJdGVtID0gaXRlbS5mbGV4SXRlbTtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgZ3Jvd0Ftb3VudCA9IGZsZXhJdGVtLmdyb3c7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGlzR3Jvd2FibGVJdGVtID0gKGdyb3dBbW91bnQgPiAwKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlzR3Jvd2FibGVJdGVtKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBsZXQgZ3JvdyA9IGdyb3dBbW91bnQgKiBhbW91bnRQZXJHcm93O1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgbWF4U2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc01heFNpemVTZXR0aW5nKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTGF5b3V0U2l6ZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG1heFNpemUgPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNpemUgPj0gbWF4U2l6ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBBbHJlYWR5IGZ1bGx5IGdyb3duLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBncm93ID0gMDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBtYXhHcm93ID0gbWF4U2l6ZSAtIHNpemU7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGlzRnVsbHlHcm93biA9IChncm93ID49IG1heEdyb3cpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNGdWxseUdyb3duKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBncm93ID0gbWF4R3JvdztcblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gRGVzdHJpYnV0ZSByZW1haW5pbmcgYW1vdW50IG92ZXIgdGhlIG90aGVyIGZsZXggaXRlbXMuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0b3RhbEdyb3dBbW91bnQgLT0gZ3Jvd0Ftb3VudDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGdyb3cgPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgZmluYWxTaXplID0gc2l6ZSArIGdyb3c7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZmxleEl0ZW0uX3Jlc2l6ZU1haW5BeGlzKGZpbmFsU2l6ZSk7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9ncm93blNpemUgKz0gZ3JvdztcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9hbW91bnRSZW1haW5pbmcgLT0gZ3JvdztcblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChNYXRoLmFicyh0aGlzLl9hbW91bnRSZW1haW5pbmcpIDwgMTBlLTYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gd2hpbGUodG90YWxHcm93QW1vdW50ICYmIChNYXRoLmFicyh0aGlzLl9hbW91bnRSZW1haW5pbmcpID4gMTBlLTYpKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9nZXRUb3RhbEdyb3dBbW91bnQoKSB7XG4gICAgICAgIGxldCB0b3RhbCA9IDA7XG4gICAgICAgIGNvbnN0IGl0ZW1zID0gdGhpcy5fbGluZS5pdGVtcztcbiAgICAgICAgZm9yIChsZXQgaSA9IHRoaXMuX2xpbmUuc3RhcnRJbmRleDsgaSA8PSB0aGlzLl9saW5lLmVuZEluZGV4OyBpKyspIHtcbiAgICAgICAgICAgIGNvbnN0IGl0ZW0gPSBpdGVtc1tpXTtcbiAgICAgICAgICAgIGNvbnN0IGZsZXhJdGVtID0gaXRlbS5mbGV4SXRlbTtcblxuICAgICAgICAgICAgaWYgKGZsZXhJdGVtLmdyb3cpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBtYXhTaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTWF4U2l6ZVNldHRpbmcoKTtcbiAgICAgICAgICAgICAgICBjb25zdCBzaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTGF5b3V0U2l6ZSgpO1xuXG4gICAgICAgICAgICAgICAgLy8gRXhjbHV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CBXQVJSQU5USUVTIE9SIENPTkRJVElPTlMgT0YgQU5ZIEtJTkQsIGVpdGhlciBleHByZXNzIG9yIGltcGxpZWQuXG4gKiBTZWUgdGhlIExpY2Vuc2UgZm9yIHRoZSBzcGVjaWZpYyBsYW5ndWFnZSBnb3Zlcm5pbmcgcGVybWlzc2lvbnMgYW5kXG4gKiBsaW1pdGF0aW9ucyB1bmRlciB0aGUgTGljZW5zZS5cbiAqL1xuXG5leHBvcnQgZGVmYXVsdCBjbGFzcyBTaXplU2hyaW5rZXIge1xuXG4gICAgY29uc3RydWN0b3IobGluZSkge1xuICAgICAgICB0aGlzLl9saW5lID0gbGluZTtcbiAgICAgICAgdGhpcy5fYW1vdW50UmVtYWluaW5nID0gMDtcbiAgICAgICAgdGhpcy5fc2hydW5rU2l6ZSA9IDA7XG4gICAgfVxuXG4gICAgc2hyaW5rKGFtb3VudCkge1xuICAgICAgICB0aGlzLl9zaHJ1bmtTaXplID0gMDtcblxuICAgICAgICB0aGlzLl9hbW91bnRSZW1haW5pbmcgPSBhbW91bnQ7XG4gICAgICAgIGxldCB0b3RhbFNocmlua0Ftb3VudCA9IHRoaXMuX2dldFRvdGFsU2hyaW5rQW1vdW50KCk7XG4gICAgICAgIGlmICh0b3RhbFNocmlua0Ftb3VudCkge1xuICAgICAgICAgICAgY29uc3QgaXRlbXMgPSB0aGlzLl9saW5lLml0ZW1zO1xuICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgIGxldCBhbW91bnRQZXJTaHJpbmsgPSB0aGlzLl9hbW91bnRSZW1haW5pbmcgLyB0b3RhbFNocmlua0Ftb3VudDtcbiAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gdGhpcy5fbGluZS5zdGFydEluZGV4OyBpIDw9IHRoaXMuX2xpbmUuZW5kSW5kZXg7IGkrKykge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBpdGVtID0gaXRlbXNbaV07XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGZsZXhJdGVtID0gaXRlbS5mbGV4SXRlbTtcbiAgICAgICAgICAgICAgICAgICAgY29uc3Qgc2hyaW5rQW1vdW50ID0gZmxleEl0ZW0uc2hyaW5rO1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBpc1Nocmlua2FibGVJdGVtID0gKHNocmlua0Ftb3VudCA+IDApO1xuICAgICAgICAgICAgICAgICAgICBpZiAoaXNTaHJpbmthYmxlSXRlbSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHNocmluayA9IHNocmlua0Ftb3VudCAqIGFtb3VudFBlclNocmluaztcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IG1pblNpemUgPSBmbGV4SXRlbS5fZ2V0TWFpbkF4aXNNaW5TaXplKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTGF5b3V0U2l6ZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNpemUgPiBtaW5TaXplKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgbWF4U2hyaW5rID0gc2l6ZSAtIG1pblNpemU7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgaXNGdWxseVNocnVuayA9IChzaHJpbmsgPj0gbWF4U2hyaW5rKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNGdWxseVNocnVuaykge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaHJpbmsgPSBtYXhTaHJpbms7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gRGVzdHJpYnV0ZSByZW1haW5pbmcgYW1vdW50IG92ZXIgdGhlIG90aGVyIGZsZXggaXRlbXMuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRvdGFsU2hyaW5rQW1vdW50IC09IHNocmlua0Ftb3VudDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBmaW5hbFNpemUgPSBzaXplIC0gc2hyaW5rO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZsZXhJdGVtLl9yZXNpemVNYWluQXhpcyhmaW5hbFNpemUpO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fc2hydW5rU2l6ZSArPSBzaHJpbms7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fYW1vdW50UmVtYWluaW5nIC09IHNocmluaztcblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChNYXRoLmFicyh0aGlzLl9hbW91bnRSZW1haW5pbmcpIDwgMTBlLTYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gd2hpbGUodG90YWxTaHJpbmtBbW91bnQgJiYgKE1hdGguYWJzKHRoaXMuX2Ftb3VudFJlbWFpbmluZykgPiAxMGUtNikpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2dldFRvdGFsU2hyaW5rQW1vdW50KCkge1xuICAgICAgICBsZXQgdG90YWwgPSAwO1xuICAgICAgICBjb25zdCBpdGVtcyA9IHRoaXMuX2xpbmUuaXRlbXM7XG4gICAgICAgIGZvciAobGV0IGkgPSB0aGlzLl9saW5lLnN0YXJ0SW5kZXg7IGkgPD0gdGhpcy5fbGluZS5lbmRJbmRleDsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCBpdGVtID0gaXRlbXNbaV07XG4gICAgICAgICAgICBjb25zdCBmbGV4SXRlbSA9IGl0ZW0uZmxleEl0ZW07XG5cbiAgICAgICAgICAgIGlmIChmbGV4SXRlbS5zaHJpbmspIHtcbiAgICAgICAgICAgICAgICBjb25zdCB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S5pZCkge1xuICAgICAgICAgICAgICAgIGNvbnN0IGlkID0gZS5kYXRhLmlkO1xuICAgICAgICAgICAgICAgIGNvbnN0IGl0ZW0gPSB0aGlzLl9pdGVtcy5nZXQoaWQpO1xuICAgICAgICAgICAgICAgIGlmIChpdGVtKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChlLmRhdGEudHlwZSA9PSAnZGF0YScpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZmluaXNoKGl0ZW0sIGUuZGF0YS5pbmZvKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZXJyb3IoaXRlbSwgZS5kYXRhLmluZm8pO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgY3JlYXRlKHNyYykge1xuICAgICAgICBjb25zdCBpZCA9ICsrdGhpcy5faWQ7XG4gICAgICAgIGNvbnN0IGl0ZW0gPSBuZXcgSW1hZ2VXb3JrZXJJbWFnZSh0aGlzLCBpZCwgc3JjKTtcbiAgICAgICAgdGhpcy5faXRlbXMuc2V0KGlkLCBpdGVtKTtcbiAgICAgICAgdGhpcy5fd29ya2VyLnBvc3RNZXNzYWdlKHt0eXBlOiBcImFkZFwiLCBpZDogaWQsIHNyYzogc3JjfSk7XG4gICAgICAgIHJldHVybiBpdGVtO1xuICAgIH1cblxuICAgIGNhbmNlbChpbWFnZSkge1xuICAgICAgICB0aGlzLl93b3JrZXIucG9zdE1lc3NhZ2Uoe3R5cGU6IFwiY2FuY2VsXCIsIGlkOiBpbWFnZS5pZH0pO1xuICAgICAgICB0aGlzLl9pdGVtcy5kZWxldGUoaW1hZ2UuaWQpO1xuICAgIH1cblxuICAgIGVycm9yKGltYWdlLCBpbmZvKSB7XG4gICAgICAgIGltYWdlLmVycm9yKGluZm8pO1xuICAgICAgICB0aGlzLl9p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ICAgICAgICAgICAgICAgaWYgKHRoaXMuc3RhZ2UuY3R4Lmhhc1JlbmRlclVwZGF0ZXMoKSkge1xuICAgICAgICAgICAgICAgICAgICBjbGVhckludGVydmFsKHRoaXMuX2xvb3BIYW5kbGVyKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdGFydExvb3AoKTtcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfSwgMTAwMCAvIDYwKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX2lkbGVMb29wQ291bnRlciA9IDA7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBsb29wKCkge1xuICAgICAgICBsZXQgc2VsZiA9IHRoaXM7XG4gICAgICAgIGxldCBscCA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIHNlbGYuX2F3YWl0aW5nTG9vcCA9IGZhbHNlO1xuICAgICAgICAgICAgc2VsZi5fb25JZGxlID0gZmFsc2U7XG4gICAgICAgICAgICBpZiAoc2VsZi5fbG9vcGluZykge1xuICAgICAgICAgICAgICAgIHNlbGYuc3RhZ2UudXBkYXRlRnJhbWUoKTtcbiAgICAgICAgICAgICAgICBpZiAoc2VsZi5zdGFnZS5nZXRPcHRpb24oXCJwYXVzZVJhZkxvb3BPbklkbGVcIikpIHtcbiAgICAgICAgICAgICAgICAgICAgc2VsZi5zd2l0Y2hMb29wKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHNlbGYuc3RhZ2UucmVuZGVyRnJhbWUoKTtcbiAgICAgICAgICAgICAgICByZXF1ZXN0QW5pbWF0aW9uRnJhbWUobHApO1xuICAgICAgICAgICAgICAgIHNlbGYuX2F3YWl0aW5nTG9vcCA9IHRydWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmVxdWVzdEFuaW1hdGlvbkZyYW1lKGxwKTtcbiAgICB9XG5cbiAgICB1cGxvYWRDb21wcmVzc2VkR2xUZXh0dX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WludDMyKDQ0LCBsaXR0bGVFbmRpYW4pLFxuICAgICAgICAgICAgICAgIG51bWJlck9mQXJyYXlFbGVtZW50czogdmlldy5nZXRVaW50MzIoNDgsIGxpdHRsZUVuZGlhbiksXG4gICAgICAgICAgICAgICAgbnVtYmVyT2ZGYWNlczogdmlldy5nZXRVaW50MzIoNTIsIGxpdHRsZUVuZGlhbiksXG4gICAgICAgICAgICAgICAgbnVtYmVyT2ZNaXBtYXBMZXZlbHM6IHZpZXcuZ2V0VWludDMyKDU2LCBsaXR0bGVFbmRpYW4pLFxuICAgICAgICAgICAgICAgIGJ5dGVzT2ZLZXlWYWx1ZURhdGE6IHZpZXcuZ2V0VWludDMyKDYwLCBsaXR0bGVFbmRpYW4pLFxuICAgICAgICAgICAgICAgIGt2cHM6IFtdLFxuICAgICAgICAgICAgICAgIG1pcG1hcHM6IFtdLFxuICAgICAgICAgICAgICAgIGdldCB3aWR0aCgpIHsgcmV0dXJuIHRoaXMucGl4ZWxXaWR0aCB9LFxuICAgICAgICAgICAgICAgIGdldCBoZWlnaHQoKSB7IHJldHVybiB0aGlzLnBpeGVsSGVpZ2h0IH0sXG4gICAgICAgICAgICB9O1xuXG4gICAgICAgICAgICBjb25zdCBwcm9wcyA9IChvYmopID0+IHtcbiAgICAgICAgICAgICAgICBjb25zdCBwID0gW107XG4gICAgICAgICAgICAgICAgZm9yIChsZXQgdiBpbiBvYmopIHtcbiAgICAgICAgICAgICAgICAgICAgcC5wdXNoKG9ialt2XSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybiBwO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBjb25zdCBmb3JtYXRzID0gT2JqZWN0LnZhbHVlcyhzZWxmLnN0YWdlLnJlbmRlcmVyLmdldENvbXByZXNzZWRUZXh0dXJlRXh0ZW5zaW9ucygpKVxuICAgICAgICAgICAgICAgIC5maWx0ZXIoKG9iaikgPT4gb2JqICE9IG51bGwpXG4gICAgICAgICA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nZVNpemVcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgY2IobnVsbCwge1xuICAgICAgICAgICAgICAgIHNvdXJjZTogZGF0YSxcbiAgICAgICAgICAgICAgICByZW5kZXJJbmZvOiB7IHNyYzogc3JjLCBjb21wcmVzc2VkOiB0cnVlIH0sXG4gICAgICAgICAgICB9KVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgaGFuZGxlUHZyTG9hZChjYiwgc3JjKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAvLyBwdnIgaGVhZGVyIGxlbmd0aCBpbiAzMiBiaXRzXG4gICAgICAgICAgICBjb25zdCBwdnJIZWFkZXJMZW5ndGggPSAxMztcbiAgICAgICAgICAgIC8vIGZvciBub3cgb25seSB3ZSBvbmx5IHN1cHBvcnQ6IENPTVBSRVNTRURfUkdCX0VUQzFfV0VCR0xcbiAgICAgICAgICAgIGNvbnN0IHB2ckZvcm1hdEV0YzEgPSAweDhENjQ7XG4gICAgICAgICAgICBjb25zdCBwdnJXaWR0aCA9IDc7XG4gICAgICAgICAgICBjb25zdCBwdnJIZWlnaHQgPSA2O1xuICAgICAgICAgICAgY29uc3QgcHZyTWlwbWFwQ291bnQgPSAxMTtcbiAgICAgICAgICAgIGNvbnN0IHB2ck1ldGFkYXRhID0gMTI7XG4gICAgICAgICAgICBjb25zdCBhcnJheUJ1ZmZlciA9IHRoaXMucmVzcG9uc2U7XG4gICAgICAgICAgICBjb25zdCBoZWFkZXIgPSBuZXcgSW50MzJBcnJheShhcnJheUJ1ZmZlciwgMCwgcHZySGVhZGVyTGVuZ3RoKTtcbiAgICAgICAgICAgIGNvbnN0IGRhdGFPZmZzZXQgPSBoZWFkZXJbcHZyTWV0YWRhdGFdICsgNTI7XG4gICAgICAgICAgICBjb25zdCBwdnJ0Y0RhdGEgPSBuZXcgVWludDhBcnJheShhcnJheUJ1ZmZlciwgZGF0YU9mZnNldCk7XG5cbiAgICAgICAgICAgIHZhciBkYXRhID0ge1xuICAgICAgICAgICAgICAgIGdsSW50ZXJuYWxGb3JtYXQ6IHB2ckZvcm1hdEV0YzEsXG4gICAgICAgICAgICAgICAgcGl4ZWxXaWR0aDogaGVhZGVyW3B2cldpZHRoXSxcbiAgICAgICAgICAgICAgICBwaXhlbEhlaWdodDogaGVhZGVyW3B2ckhlaWdodF0sXG4gICAgICAgICAgICAgICAgbnVtYmVyT2ZNaXBtYXBMZXZlbHM6IGhlYWRlcltwdnJNaXBtYXBDb3VudF0sXG4gICAgICAgICAgICAgICAgbWlwbWFwczogW10sXG4gICAgICAgICAgICAgICAgcHZyOiB0cnVlLFxuICAgICAgICAgICAgICAgIGdldCB3aWR0aCgpIHsgcmV0dXJuIHRoaXMucGl4ZWxXaWR0aCB9LFxuICAgICAgICAgICAgICAgIGdldCBoZWlnaHQoKSB7IHJldHVybiB0aGlzLnBpeGVsSGVpZ2h0IH0sXG4gICAgICAgICAgICB9O1xuXG4gICAgICAgICAgICBsZXQgb2Zmc2V0ID0gMFxuICAgICAgICAgICAgbGV0IHdpZHRoID0gZGF0YS5waXhlbFdpZHRoO1xuICAgICAgICAgICAgbGV0IGhlaWdodCA9IGRhdGEucGl4ZWxIZWlnaHQ7XG5cbiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgZGF0YS5udW1iZXJPZk1pcG1hcExldmVsczsgaSsrKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgbGV2ZWwgPSAoKHdpZHRoICsgMykgPj4gMikgKiAoKGhlaWdodCArIDMpID4+IDIpICogODtcbiAgICAgICAgICAgICAgICBjb25zdCB2aWV3ID0gbmV3IFVpbnQ4QXJyYXkoYXJyYXlCdWZmZXIsIHB2cnRjRGF0YS5ieXRlT2Zmc2V0ICsgb2Zmc2V0LCBsZXZlbCk7XG4gICAgICAgICAgICAgICAgZGF0YS5taXBtYXBzLnB1c2godmlldyk7XG4gICAgICAgICAgICAgICAgb2Zmc2V0ICs9IGxldmVsO1xuICAgICAgICAgICAgICAgIHdpZHRoID0gd2lkdGggPj4gMTtcbiAgICAgICAgICAgICAgICBoZWlnaHQgPSBoZWlnaHQgPj4gMTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgY2IobnVsbCwge1xuICAgICAgICAgICAgICAgIHNvdXJjZTogZGF0YSxcbiAgICAgICAgICAgICAgICByZW5kZXJJbmZvOiB7IHNyYzogc3JjLCBjb21wcmVzc2VkOiB0cnVlIH0sXG4gICAgICAgICAgICB9KVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgbG9hZFNyY1RleHR1cmUoeyBzcmMsIGhhc0FscGhhIH0sIGNiKSB7XG4gICAgICAgIGxldCBjYW5jZWxDYiA9IHVuZGVmaW5lZDtcbiAgICAgICAgbGV0IGlzUG5nID0gKHNyYy50b0xvd2VyQ2FzZSgpLmluZGV4T2YoXCIucG5nXCIpID49IDApIHx8IHNyYy5zdWJzdHIoMCwgMjEpID09ICdkYXRhOmltYWdlL3BuZztiYXNlNjQnO1xuICAgICAgICBsZXQgaXNLdHggPSBzcmMuaW5kZXhPZignLmt0eCcpID49IDA7XG4gICAgICAgIGxldCBpc1B2ciA9IHNyYy5pbmRleE9mKCcucHZyJykgPj0gMDtcbiAgICAgICAgaWYgKGlzS3R4IHx8IGlzUHZyKSB7XG4gICAgICAgICAgICBsZXQgcmVxdWVzdCA9IG5ldyBYTUxIdHRwUmVxdWVzdCgpO1xuICAgICAgICAgICAgcmVxdWVzdC5hZGRFdmVudExpc3RlbmVyKFxuICAgICAgICAgICAgICAgIFwibG9hZFwiLCBpc0t0eCA/IHRoaXMuaGFuZGxlS3R4TG9hZChjYiwgc3JjKSA6IHRoaXMuaGFuZGxlUHZyTG9hZChjYiwgc3JjKVxuICAgICAgICAgICAgKTtcbiAgICAgICAgICAgIHJlcXVlc3Qub3BlbihcIkdFVFwiLCBzcmMpO1xuICAgICAgICAgICAgcmVxdWVzdC5yZXNwb25zZVR5cGUgPSBcImFycmF5YnVmZmVyXCI7XG4gICAgICAgICAgICByZXF1ZXN0LnNlbmQoKTtcbiAgICAgICAgICAgIGNhbmNlbENiID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHJlcXVlc3QuYWJvcnQoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9pbWFnZVdvcmtlcikge1xuICAgICAgICAgICAgLy8gV1BFLXNwZWNpZmljIGltYWdlIHBhcnNlci5cbiAgICAgICAgICAgIGNvbnN0IGltYWdlID0gdGhpcy5faW1hZ2VXb3JrZXIuY3JlYXRlKHNyYyk7XG4gICAgICAgICAgICBpbWFnZS5vbkVycm9yID0gZnVuY3Rpb24gKGVycikge1xuICAgICAgICAgICAgICAgIHJldHVybiBjYihcIkltYWdlIGxvYWQgZXJyb3JcIik7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaW1hZ2Uub25Mb2FkID0gZnVuY3Rpb24gKHsgaW1hZ2VCaXRtYXAsIGhhc0FscGhhQ2hhbm5lbCB9KSB7XG4gICAgICAgICAgICAgICAgY2IobnVsbCwge1xuICAgICAgICAgICAgICAgICAgICBzb3VyY2U6IGltYWdlQml0bWFwLFxuICAgICAgICAgICAgICAgICAgICByZW5kZXJJbmZvOiB7IHNyYzogc3JjLCBjb21wcmVzc2VkOiBmYWxzZSB9LFxuICAgICAgICAgICAgICAgICAgICBoYXNBbHBoYTogaGFzQWxwaGFDaGFubmVsLFxuICAgICAgICAgICAgICAgICAgICBwcmVtdWx0aXBseUFscGhhOiB0cnVlXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgY2FuY2VsQ2IgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgaW1hZ2UuY2FuY2VsKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBsZXQgaW1hZ2UgPSBuZXcgSW1hZ2UoKTtcblxuICAgICAgICAgICAgLy8gT24gdGhlIFBTNCBwbGF0Zm9ybSBzZXR0aW5nIHRoZSBgY3Jvc3NPcmlnaW5gIGF0dHJpYnV0ZSBvblxuICAgICAgICAgICAgLy8gaW1hZ2VzIGNhbiBjYXVzZSBDT1JTIGZhaWx1cmVzLlxuICAgICAgICAgICAgaWYgKCEoc3JjLnN1YnN0cigwLCA1KSA9PSBcImRhdGE6XCIpICYmICFVdGlscy5pc1BTNCkge1xuICAgICAgICAgICAgICAgIC8vIEJhc2U2NC5cbiAgICAgICAgICAgICAgICBpbWFnZS5jcm9zc09yaWdpbiA9IFwiQW5vbnltb3VzXCI7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpbWFnZS5vbmVycm9yID0gZnVuY3Rpb24gKGVycikge1xuICAgICAgICAgICAgICAgIC8vIElnbm9yZSBlcnJvciBtZXNzYWdlIHdoZW4gY2FuY2VsbGVkLlxuICAgICAgICAgICAgICAgIGlmIChpbWFnZS5zcmMpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNiKFwiSW1hZ2UgbG9hZCBlcnJvclwiKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaW1hZ2Uub25sb2FkID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIGNiKG51bGwsIHtcbiAgICAgICAgICAgICAgICAgICAgc291cmNlOiBpbWFnZSxcbiAgICAgICAgICAgICAgICAgICAgcmVuZGVySW5mbzogeyBzcmM6IHNyYywgY29tcHJlc3NlZDogZmFsc2UgfSxcbiAgICAgICAgICAgICAgICAgICAgaGFzQWxwaGE6IGlzUG5nIHx8IGhhc0FscGhhXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaW1hZ2Uuc3JjID0gc3JjO1xuXG4gICAgICAgICAgICBjYW5jZWxDYiA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICBpbWFnZS5vbmVycm9yID0gbnVsb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GNsYXNzIEMyZENvcmVRdWFkTGlzdCBleHRlbmRzIENvcmVRdWFkTGlzdCB7XG5cbiAgICBjb25zdHJ1Y3RvcihjdHgpIHtcbiAgICAgICAgc3VwZXIoY3R4KTtcblxuICAgICAgICB0aGlzLnJlbmRlckNvbnRleHRzID0gW107XG4gICAgICAgIHRoaXMubW9kZXMgPSBbXTtcbiAgICB9XG5cbiAgICBzZXRSZW5kZXJDb250ZXh0KGluZGV4LCB2KSB7XG4gICAgICAgIHRoaXMucmVuZGVyQ29udGV4dHNbaW5kZXhdID0gdjtcbiAgICB9XG5cbiAgICBzZXRTaW1wbGVUYyhpbmRleCwgdikge1xuICAgICAgICBpZiAodikge1xuICAgICAgICAgICAgdGhpcy5tb2Rlc1tpbmRleF0gfD0gMTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMubW9kZXNbaW5kZXhdIC09ICh0aGlzLm1vZGVzW2luZGV4XSAmIDEpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2V0V2hpdGUoaW5kZXgsIHYpIHtcbiAgICAgICAgaWYgKHYpIHtcbiAgICAgICAgICAgIHRoaXMubW9kZXNbaW5kZXhdIHw9IDI7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLm1vZGVzW2luZGV4XSAtPSAodGhpcy5tb2Rlc1tpbmRleF0gJiAyKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldFJlbmRlckNvbnRleHQoaW5kZXgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMucmVuZGVyQ29udGV4dHNbaW5kZXhdO1xuICAgIH1cblxuICAgIGdldFNpbXBsZVRjKGluZGV4KSB7XG4gICAgICAgIHJldHVybiAodGhpcy5tb2Rlc1tpbmRleF0gJiAxKTtcbiAgICB9XG5cbiAgICBnZXRXaGl0ZShpbmRleCkge1xuICAgICAgICByZXR1cm4gKHRoaXMubW9kZXNbaW5kZXhdICYgMik7XG4gICAgfVxuXG59XG4iL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AgIC8vIFdlIGNhbid0IHJlc2V0IGNsaXBwaW5nIGFsb25lIHNvIHdlIG5lZWQgdG8gcmVzdG9yZSB0aGUgZnVsbCBjb250ZXh0LlxuICAgICAgICAgICAgdGhpcy5fcmVzdG9yZUNvbnRleHQoKTtcblxuICAgICAgICAgICAgbGV0IHByZWNpc2lvbiA9IHRoaXMuY3R4LnN0YWdlLmdldFJlbmRlclByZWNpc2lvbigpO1xuICAgICAgICAgICAgaWYgKGFyZWEpIHtcbiAgICAgICAgICAgICAgICBjdHguYmVnaW5QYXRoKCk7XG4gICAgICAgICAgICAgICAgY3R4LnJlY3QoTWF0aC5yb3VuZChhcmVhWzBdICogcHJlY2lzaW9uKSwgTWF0aC5yb3VuZChhcmVhWzFdICogcHJlY2lzaW9uKSwgTWF0aC5yb3VuZChhcmVhWzJdICogcHJlY2lzaW9uKSwgTWF0aC5yb3VuZChhcmVhWzNdICogcHJlY2lzaW9uKSk7XG4gICAgICAgICAgICAgICAgY3R4LmNsb3NlUGF0aCgpO1xuICAgICAgICAgICAgICAgIGN0eC5jbGlwKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjdHguX3NjaXNzb3IgPSBhcmVhO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIF9lcXVhbFNjaXNzb3JBcmVhcyhjYW52YXMsIGFyZWEsIGN1cnJlbnQpIHtcbiAgICAgICAgaWYgKCFhcmVhKSB7XG4gICAgICAgICAgICBhcmVhID0gWzAsIDAsIGNhbnZhcy53aWR0aCwgY2FudmFzLmhlaWdodF1cbiAgICAgICAgfVxuICAgICAgICBpZiAoIWN1cnJlbnQpIHtcbiAgICAgICAgICAgIGN1cnJlbnQgPSBbMCwgMCwgY2FudmFzLndpZHRoLCBjYW52YXMuaGVpZ2h0XVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBVdGlscy5lcXVhbFZhbHVlcyhhcmVhLCBjdXJyZW50KVxuICAgIH1cblxufVxuIiwiLypcbiAqIElmIG5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N0IHJjID0gb3BlcmF0aW9uLmdldFJlbmRlckNvbnRleHQoaSk7XG4gICAgICAgICAgICBjb25zdCB3aGl0ZSA9IG9wZXJhdGlvbi5nZXRXaGl0ZShpKTtcbiAgICAgICAgICAgIGNvbnN0IHN0YyA9IG9wZXJhdGlvbi5nZXRTaW1wbGVUYyhpKTtcblxuICAgICAgICAgICAgLy9AdG9kbzogdHJ5IHRvIG9wdGltaXplIG91dCBwZXItZHJhdyB0cmFuc2Zvcm0gc2V0dGluZy4gc3BsaXQgdHJhbnNsYXRlLCB0cmFuc2Zvcm0uXG4gICAgICAgICAgICBjb25zdCBwcmVjaXNpb24gPSB0aGlzLmN0eC5zdGFnZS5nZXRSZW5kZXJQcmVjaXNpb24oKTtcbiAgICAgICAgICAgIGN0eC5zZXRUcmFuc2Zvcm0ocmMudGEgKiBwcmVjaXNpb24sIHJjLnRjICogcHJlY2lzaW9uLCByYy50YiAqIHByZWNpc2lvbiwgcmMudGQgKiBwcmVjaXNpb24sIHJjLnB4ICogcHJlY2lzaW9uLCByYy5weSAqIHByZWNpc2lvbik7XG5cbiAgICAgICAgICAgIGNvbnN0IHJlY3QgPSAodHggPT09IHRoaXMuX3JlY3RhbmdsZVRleHR1cmUpO1xuICAgICAgICAgICAgY29uc3QgaW5mbyA9IHtvcGVyYXRpb24sIHRhcmdldCwgaW5kZXg6IGksIHJlY3R9O1xuXG4gICAgICAgICAgICBpZiAocmVjdCkge1xuICAgICAgICAgICAgICAgIC8vIENoZWNrIGZvciBncmFkaWVudC5cbiAgICAgICAgICAgICAgICBpZiAod2hpdGUpIHtcbiAgICAgICAgICAgICAgICAgICAgY3R4LmZpbGxTdHlsZSA9ICd3aGl0ZSc7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fc2V0Q29sb3JHcmFkaWVudChjdHgsIHZjKTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBjdHguZ2xvYmFs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ckJsKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb2xvciA9IFN0YWdlVXRpbHMubWVyZ2VNdWx0aUNvbG9yc0VxdWFsKFt2Yy5fY29sb3JVbCwgdmMuX2NvbG9yVXIsIHZjLl9jb2xvckJsLCB2Yy5fY29sb3JCcl0pO1xuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgY29uc3QgYWxwaGEgPSAoKGNvbG9yIC8gMTY3NzcyMTYpIHwgMCkgLyAyNTUuMDtcbiAgICAgICAgICAgICAgICAgICAgY3R4Lmdsb2JhbEFscGhhICo9IGFscGhhO1xuXG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHJnYiA9IGNvbG9yICYgMHgwMEZGRkZGRjtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgdGludFRleHR1cmUgPSB0aGlzLl90aW50TWFuYWdlci5nZXRUaW50VGV4dHVyZSh0eCwgcmdiKTtcblxuICAgICAgICAgICAgICAgICAgICAvLyBBY3R1YWxseSBkcmF3IHJlc3VsdC5cbiAgICAgICAgICAgICAgICAgICAgY3R4LmZpbGxTdHlsZSA9ICd3aGl0ZSc7XG4gICAgICAgICAgICAgICAgICAgIGN0eC5kcmF3SW1hZ2UodGludFRleHR1cmUsIHNvdXJjZVgsIHNvdXJjZVksIHNvdXJjZVcsIHNvdXJjZUgsIDAsIDAsIHZjLncsIHZjLmgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGN0eC5maWxsU3R5bGUgPSAnd2hpdGUnO1xuICAgICAgICAgICAgICAgICAgICBjdHguZHJhd0ltYWdlKHR4LCBzb3VyY2VYLCBzb3VyY2VZLCBzb3VyY2VXLCBzb3VyY2VILCAwLCAwLCB2Yy53LCB2Yy5oKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdGhpcy5fYWZ0ZXJEcmF3RWwoaW5mbyk7XG4gICAgICAgICAgICAgICAgY3R4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luZyh2Yy5fY29sb3JCbCkpO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgZ3JhZGllbnQuYWRkQ29sb3JTdG9wKDAsIFN0YWdlVXRpbHMuZ2V0UmdiU3RyaW5nKHZjLl9jb2xvclVsKSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBncmFkaWVudC5hZGRDb2xvclN0b3AoMSwgU3RhZ2VVdGlscy5nZXRSZ2JTdHJpbmcodmMuX2NvbG9yQmwpKTtcblxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAvLyBOb3Qgc3VwcG9ydGVkIGdyYWRpZW50LlxuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHZjLl9jb2xvclVsID09PSB2Yy5fY29sb3JCbCAmJiB2Yy5fY29sb3JVciA9PT0gdmMuX2NvbG9yQnIpIHtcbiAgICAgICAgICAgICAgICAvLyBIb3Jpem9udGFsIGdyYWRpZW50LlxuICAgICAgICAgICAgICAgIGdyYWRpZW50ID0gY3R4LmNyZWF0ZUxpbmVhckdyYWRpZW50KDAsIDAsIHcsIDApO1xuICAgICAgICAgICAgICAgIGlmICh0cmFuc3BhcmVuY3kpIHtcbiAgICAgICAgICAgICAgICAgICAgZ3JhZGllbnQuYWRkQ29sb3JTdG9wKDAsIFN0YWdlVXRpbHMuZ2V0UmdiYVN0cmluZyh2Yy5fY29sb3JVbCkpO1xuICAgICAgICAgICAgICAgICAgICBncmFkaWVudC5hZGRDb2xvclN0b3AoMSwgU3RhZ2VVdGlscy5nZXRSZ2JhU3RyaW5nKHZjLl9jb2xvckJyKSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgZ3JhZGllbnQuYWRkQ29sb3JTdG9wKDAsIFN0YWdlVXRpbHMuZ2V0U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dsVGV4dHVyZS5vcHRpb25zLmltYWdlUmVmLCB2Yy5fd29ybGRDb250ZXh0LnB4KnByZWNpc2lvbiwgdmMuX3dvcmxkQ29udGV4dC5weSpwcmVjaXNpb24sIHZjLl9jb2xvclVsLCB2Yyk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBnbC5iaW5kVGV4dHVyZShnbC5URVhUVVJFXzJELCBnbFRleHR1cmUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgZ2wuZHJhd0VsZW1lbnRzKGdsLlRSSUFOR0xFUywgNiAqIChpIC0gcG9zKSwgZ2wuVU5TSUdORURfU0hPUlQsIChwb3MgKyBvcGVyYXRpb24uaW5kZXgpICogNiAqIDIpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGdsVGV4dHVyZSA9IHR4O1xuICAgICAgICAgICAgICAgICAgICBwb3MgPSBpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChwb3MgPCBsZW5ndGgpIHtcbiAgICAgICAgICAgICAgICBpZiAoZ2xUZXh0dXJlLm9wdGlvbnMgJiYgZ2xUZXh0dXJlLm9wdGlvbnMuaW1hZ2VSZWYpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgcHJlY2lzaW9uID0gdGhpcy5jdHguc3RhZ2UuZ2V0T3B0aW9uKCdwcmVjaXNpb24nKTtcbiAgICAgICAgICAgICAgICAgICAgbGV0IHZjID0gb3BlcmF0aW9uLmdldEVsZW1lbnRDb3JlKHBvcyk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY3R4LnN0YWdlLnBsYXRmb3JtLnBhaW50KGdsLCBnbFRleHR1cmUub3B0aW9ucy5pbWFnZVJlZiwgdmMuX3dvcmxkQ29udGV4dC5weCpwcmVjaXNpb24sIHZjLl93b3JsZENvbnRleHQucHkqcHJlY2lzaW9uLCB2Yy5fY29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IgR0xfUkdCQSBmb3JtYXQnKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBlbHNlIGlmIChmbXQgPT09IGdsLlJHQikge1xuICAgICAgICAgICAgc3dpdGNoICh0eXBlKSB7XG4gICAgICAgICAgICAgICAgY2FzZSBnbC5VTlNJR05FRF9CWVRFOlxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gMztcblxuICAgICAgICAgICAgICAgIGNhc2UgZ2wuVU5TSUdORURfQllURV81XzZfNTpcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDI7XG5cbiAgICAgICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ0ludmFsaWQgdHlwZSBzcGVjaWZpZWQgZm9yIEdMX1JHQiBmb3JtYXQnKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignSW52YWxpZCBmb3JtYXQgc3BlY2lmaWVkIGluIGNhbGwgdG8gX2dldEJ5dGVzUGVyUGl4ZWwoKScpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgdXBsb2FkVGV4dHVyZVNvdXJjZSh0ZXh0dXJlU291cmNlLCBvcHRpb25zKSB7XG4gICAgICAgIGNvbnN0IGdsID0gdGhpcy5zdGFnZS5nbDtcblxuICAgICAgICBjb25zdCBzb3VyY2UgPSBvcHRpb25zLnNvdXJjZTtcbiAgICAgICAgbGV0IGNvbXByZXNzZWQgPSBmYWxzZTtcbiAgICAgICAgaWYgKG9wdGlvbnMucmVuZGVySW5mbykge1xuICAgICAgICAgICAgY29tcHJlc3NlZCA9IG9wdGlvbnMucmVuZGVySW5mby5jb21wcmVzc2VkIHx8IGZhbHNlXG4gICAgICAgIH1cblxuICAgICAgICBjb25zdCBmb3JtYXQgPSB7XG4gICAgICAgICAgICBwcmVtdWx0aXBseUFscGhhOiB0cnVlLFxuICA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KyBlbGVtZW50Q29yZS5fdyAqIHIudGE7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weSArIGVsZW1lbnRDb3JlLl93ICogci50YztcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl91bHk7XG4gICAgICAgICAgICB1aW50c1tvZmZzZXQrK10gPSBtY2EoZWxlbWVudENvcmUuX2NvbG9yVXIsIHIuYWxwaGEpO1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHggKyBlbGVtZW50Q29yZS5fdyAqIHIudGEgKyBlbGVtZW50Q29yZS5faCAqIHIudGI7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weSArIGVsZW1lbnRDb3JlLl93ICogci50YyArIGVsZW1lbnRDb3JlLl9oICogci50ZDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl9icnk7XG4gICAgICAgICAgICB1aW50c1tvZmZzZXQrK10gPSBtY2EoZWxlbWVudENvcmUuX2NvbG9yQnIsIHIuYWxwaGEpO1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHggKyBlbGVtZW50Q29yZS5faCAqIHIudGI7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weSArIGVsZW1lbnRDb3JlLl9oICogci50ZDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fdWx4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl9icnk7XG4gICAgICAgICAgICB1aW50c1tvZmZzZXRdID0gbWNhKGVsZW1lbnRDb3JlLl9jb2xvckJsLCByLmFscGhhKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIC8vIFNpbXBsZS5cbiAgICAgICAgICAgIGxldCBjeCA9IHIucHggKyBlbGVtZW50Q29yZS5fdyAqIHIudGE7XG4gICAgICAgICAgICBsZXQgY3kgPSByLnB5ICsgZWxlbWVudENvcmUuX2ggKiByLnRkO1xuXG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSByLnB5O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl91bHg7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX3VseTtcbiAgICAgICAgICAgIHVpbnRzW29mZnNldCsrXSA9IG1jYShlbGVtZW50Q29yZS5fY29sb3JVbCwgci5hbHBoYSk7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gY3g7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weTtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl91bHk7XG4gICAgICAgICAgICB1aW50c1tvZmZzZXQrK10gPSBtY2EoZWxlbWVudENvcmUuX2NvbG9yVXIsIHIuYWxwaGEpO1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGN4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGN5O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl9icng7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX2JyeTtcbiAgICAgICAgICAgIHVpbnRzW29mZnNldCsrXSA9IG1jYShlbGVtZW50Q29yZS5fY29sb3JCciwgci5hbHBoYSk7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBjeTtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fdWx4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl9icnk7XG4gICAgICAgICAgICB1aW50c1tvZmZzZXRdID0gbWNhKGVsZW1lbnRDb3JlLl9jb2xvckJsLCByLmFscGhhKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGlzUmVuZGVyVGV4dHVyZVJldXNhYmxlKHJlbmRlclN0YXRlLCByZW5kZXJUZXh0dXJlSW5mbykge1xuICAgICAgICBsZXQgb2Zmc2V0ID0gKHJlbmRlclN0YXRlLl9yZW5kZXJUZXh0dXJlSW5mby5vZmZzZXQgKiA4MCkgLyA0O1xuICAgICAgICBsZXQgZmxvYXRzID0gcmVuZGVyU3RhdGUucXVhZHMuZmxvYXRzO1xuICAgICAgICBsZXQgdWludHMgPSByZW5kZXJTdGF0ZS5xdWFkcy51aW50cztcbiAgICAgICAgcmV0dXJuICgoZmxvYXRzW29mZnNldF0gPT09IDApICYmXG4gICAgICAgICAgICAoZmxvYXRzW29mZnNldCArIDFdID09PSAwKSAmJlxuICAgICAgICAgICAgKGZsb2F0c1tvZmZzZXQgKyAyXSA9PT0gMCkgJiZcbiAgICAgICAgICAgIChmbG9hdHNbb2Zmc2V0ICsgM10gPT09IDApICYmXG4gICAgICAgICAgICAodWludHNbb2Zmc2V0ICsgNF0gPT09IDB4RkZGRkZGRkYpICYmXG4gICAgICAgICAgICAoZmxvYXRzW29mZnNldCArIDVdID09PSByZW5kZXJUZXh0dXJlSW5mby53KSAmJlxuICAgICAgICAgICAgKGZsb2F0c1tvZmZzZXQgKyA2XSA9PT0gMCkgJiZcbiAgICAgICAgICAgIChmbG9hdHNbb2Zmc2V0ICsgN10gPT09IDEpICYmXG4gICAgICAgICAgICAoZmxvYXRzW29mZnNldCArIDhdID09PSAwKSAmJlxuICAgICAgICAgICAgKHVpbnRzW29mZnNldCArIDldID09PSAweEZGRkZGRkZGKSAmJlxuICAgICAgICAgICAgKGZsb2F0c1tvZmZzZXQgKyAxMF0gPT09IHJlbmRlclRleHR1cmVJbmZvLncpICYmXG4gICAgICAgICAgICAoZmxvYXRzW29mZnNldCArIDExXSA9PT0gcmVuZGVyVGV4dHVyZUluZm8uaCkgJiZcbiAgICAgICAgICAgIChmbG9hdHNbb2Zmc2V0ICsgMTJdID09PSAxKSAmJlxuICAgICAgICAgICAgKGZsb2F0c1tvZmZzZXQgKyAxM10gPT09IDEpICYmXG4gICAgICAgICAgICAodWludHNbb2Zmc2V0ICsgMTRdID09PSAweEZGRkZGRkZGKSAmJlxuICAgICAgICAgICAgKGZsb2F0c1tvZmZzZXQgKyAxNV0gPT09IDApICYmXG4gICAgICAgICAgICAoZmxvYXRzW29mZnNldCArIDE2XSA9PT0gcmVuZGVyVGV4dHVyZUluZm8uaCkgJiZcbiAgICAgICAgICAgIChmbG9hdHNbb2Zmc2V0ICsgMTddID09PSAwKSAmJlxuICAgICAgICAgICAgKGZsb2F0c1tvZmZzZXQgKyAxOF0gPT09IDEpICYmXG4gICAgICAgICAgICAodWludHNbb2Zmc2V0ICsgMTldID09PSAweEZGRkZGRkZGKSk7XG4gICAgfVxuXG4gICAgZmluaXNoUmVuZGVyU3RhdGUocmVuZGVyU3RhdGUpIHtcbiAgICAgICAgLy8gU2V0IGV4dHJhIHNoYWRlciBhdHRyaWJ1dGUgZGF0YS5cbiAgICAgICAgbGV0IG9mZnNldCA9IHJlbmRlclN0YXRlLmxlbmd0aCAqIDgwO1xuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHJlbmRlclN0YXRlLnF1YWRPcGVyYXRpb25zLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAg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uc3QgdCA9IHVseDtcbiAgICAgICAgICAgICAgICAgICAgdWx4ID0gYnJ4O1xuICAgICAgICAgICAgICAgICAgICBicnggPSB0O1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmIChNYXRoLnJhbmRvbSgpIDwgMC41KSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIEZsaXAgZm9yIG1vcmUgcmFuZG9tbmVzcy5cbiAgICAgICAgICAgICAgICAgICAgY29uc3QgdCA9IHVseTtcbiAgICAgICAgICAgICAgICAgICAgdWx5ID0gYnJ5O1xuICAgICAgICAgICAgICAgICAgICBicnkgPSB0O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gU3BlY2lmeSBhbGwgY29ybmVyIHBvaW50cy5cbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXRdID0gdWx4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCArIDFdID0gdWx5O1xuXG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0ICsgMl0gPSBicng7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0ICsgM10gPSB1bHk7XG5cbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQgKyA0XSA9IGJyeDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQgKyA1XSA9IGJyeTtcblxuICAgICAgICAgICAgZmxvYXRzW29mZnNldCArIDZdID0gdWx4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCArIDddID0gYnJ5O1xuXG4gICAgICAgICAgICBvZmZzZXQgKz0gODtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGJlZm9yZURyYXcob3BlcmF0aW9uKSB7XG4gICAgICAgIGxldCBnbCA9IHRoaXMuZ2w7XG4gICAgICAgIGdsLnZlcnRleEF0dHJpYlBvaW50ZXIodGhpcy5fYXR0cmliKFwiYU5vaXNlVGV4dHVyZUNvb3JkXCIpLCAyLCBnbC5GTE9BVCwg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AgICAgZmxvYXQgdCA9IDAuMDtcbiAgICAgICAgICAgICBcbiAgICAgICAgaWYoZmFkZVswXSA+IDAuMCkge1xuICAgICAgICAgICAgcG9zMSA9IHZlYzIocG9pbnQueCwgcG9pbnQueSk7XG4gICAgICAgICAgICBwb3MyID0gdmVjMihwb2ludC54LCBwb2ludC55ICsgZmFkZVswXSk7XG4gICAgICAgICAgICBkID0gcG9zMiAtIHBvczE7XG4gICAgICAgICAgICBjID0gZG90KHBvczEsIGQpIC8gZG90KGQsIGQpO1xuICAgICAgICAgICAgdCA9IHNtb290aHN0ZXAoMC4wLCAxLjAsIGNsYW1wKGMsIDAuMCwgMS4wKSk7XG4gICAgICAgICAgICBjb2xvciA9IG1peCh2ZWM0KDAuMCksIGNvbG9yLCB0KTtcbiAgICAgICAgfVxuICAgICAgICBcbiAgICAgICAgaWYoZmFkZVsxXSA+IDAuMCkge1xuICAgICAgICAgICAgdmVjMiBwb3MxID0gdmVjMihwb2ludC54IC0gcmVzb2x1dGlvbi54IC0gZmFkZVsxXSwgdlRleHR1cmVDb29yZC55KTtcbiAgICAgICAgICAgIHZlYzIgcG9zMiA9IHZlYzIocG9pbnQueCAtIHJlc29sdXRpb24ueCwgdlRleHR1cmVDb29yZC55KTtcbiAgICAgICAgICAgIGQgPSBwb3MxIC0gcG9zMjtcbiAgICAgICAgICAgIGMgPSBkb3QocG9zMiwgZCkgLyBkb3QoZCwgZCk7XG4gICAgICAgICAgICB0ID0gc21vb3Roc3RlcCgwLjAsIDEuMCwgY2xhbXAoYywgMC4wLCAxLjApKTtcbiAgICAgICAgICAgIGNvbG9yID0gbWl4KHZlYzQoMC4wKSwgY29sb3IsIHQpO1xuICAgICAgICB9XG4gICAgICAgIFxuICAgICAgICBpZihmYWRlWzJdID4gMC4wKSB7XG4gICAgICAgICAgICB2ZWMyIHBvczEgPSB2ZWMyKHZUZXh0dXJlQ29vcmQueCwgcG9pbnQueSAtIHJlc29sdXRpb24ueSAtIGZhZGVbMl0pO1xu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XVzID0gMDtcbiAgICB9XG5cbiAgICBnZXQgeCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3g7XG4gICAgfVxuXG4gICAgc2V0IHgodikge1xuICAgICAgICB0aGlzLl94ID0gdjtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgeSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3k7XG4gICAgfVxuXG4gICAgc2V0IHkodikge1xuICAgICAgICB0aGlzLl95ID0gdjtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgdygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3c7XG4gICAgfVxuXG4gICAgc2V0IHcodikge1xuICAgICAgICB0aGlzLl93ID0gdjtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgaCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2g7XG4gICAgfVxuXG4gICAgc2V0IGgodikge1xuICAgICAgICB0aGlzLl9oID0gdjtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgcmFkaXVzKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcmFkaXVzO1xuICAgIH1cblxuICAgIHNldCByYWRpdXModikge1xuICAgICAgICB0aGlzLl9yYWRpdXMgPSB2O1xuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIHNldHVwVW5pZm9ybXMob3BlcmF0aW9uKSB7XG4gICAgICAgIHN1cGVyLnNldHVwVW5pZm9ybXMob3BlcmF0aW9uKTtcblxuICAgICAgICBjb25zdCBvd25lciA9IG9wZXJhdGlvbi5zaGFkZXJPd25lcjtcbiAgICAgICAgY29uc3QgcmVuZGVyUHJlY2lzaW9uID0gdGhpcy5jdHguc3RhZ2UuZ2V0UmVuZGVyUHJlY2lzaW9uKClcblxuICAgICAgICB0aGlzLl9zZXRVbml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V0IHoodikge1xuICAgICAgICB0aGlzLl96ID0gdjtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgcGl2b3RYKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcGl2b3RYO1xuICAgIH1cblxuICAgIHNldCBwaXZvdFgodikge1xuICAgICAgICB0aGlzLl9waXZvdFggPSB2ICsgMTtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgcGl2b3RZKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcGl2b3RZO1xuICAgIH1cblxuICAgIHNldCBwaXZvdFkodikge1xuICAgICAgICB0aGlzLl9waXZvdFkgPSB2ICsgMTtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgbGlnaHRZKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbGlnaHRZO1xuICAgIH1cblxuICAgIHNldCBsaWdodFkodikge1xuICAgICAgICB0aGlzLl9saWdodFkgPSB2O1xuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIGdldCBwaXZvdFooKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9waXZvdFo7XG4gICAgfVxuXG4gICAgc2V0IHBpdm90Wih2KSB7XG4gICAgICAgIHRoaXMuX3Bpdm90WiA9IHY7XG4gICAgICAgIHRoaXMucmVkcmF3KCk7XG4gICAgfVxuXG4gICAgZ2V0IGxpZ2h0WigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2xpZ2h0WjtcbiAgICB9XG5cbiAgICBzZXQgbGlnaHRaKHYpIHtcbiAgICAgICAgdGhpcy5fbGlnaHRaID0gdjtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICB1c2VEZWZhdWx0KCkge1xuICAgICAgICByZXR1cm4gKHRoaXMuX3J4ID09PSAwICYmIHRoaXMuX3J5ID09PSAwICYmIHRoaXMuX3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vIFVuZG8gWFkgcm90YXRpb25cbiAgICAgICAgbWF0MiBpUm90WHkgPSBtYXQyKCBjb3Mocm90LnopLCBzaW4ocm90LnopLCBcbiAgICAgICAgICAgICAgICAgICAgICAgICAgIC1zaW4ocm90LnopLCBjb3Mocm90LnopKTtcbiAgICAgICAgcG9zLnh5ID0gaVJvdFh5ICogcG9zLnh5O1xuICAgICAgICBcbiAgICAgICAgLy8gUGVyZm9ybSAzZCByb3RhdGlvbnNcbiAgICAgICAgZ2xfUG9zaXRpb24ueCA9IGNvcyhyb3QueCkgKiBwb3MueCAtIHNpbihyb3QueCkgKiBwb3MuejtcbiAgICAgICAgZ2xfUG9zaXRpb24ueSA9IHBvcy55O1xuICAgICAgICBnbF9Qb3NpdGlvbi56ID0gc2luKHJvdC54KSAqIHBvcy54ICsgY29zKHJvdC54KSAqIHBvcy56O1xuICAgICAgICBcbiAgICAgICAgcG9zLnggPSBnbF9Qb3NpdGlvbi54O1xuICAgICAgICBwb3MueSA9IGNvcyhyb3QueSkgKiBnbF9Qb3NpdGlvbi55IC0gc2luKHJvdC55KSAqIGdsX1Bvc2l0aW9uLno7XG4gICAgICAgIHBvcy56ID0gc2luKHJvdC55KSAqIGdsX1Bvc2l0aW9uLnkgKyBjb3Mocm90LnkpICogZ2xfUG9zaXRpb24uejtcbiAgICAgICAgXG4gICAgICAgIC8vIFJlZG8gWFkgcm90YXRpb25cbiAgICAgICAgaVJvdFh5WzBdWzFdID0gLWlSb3RYeVswXVsxXTtcbiAgICAgICAgaVJvdFh5WzFdWzBdID0gLWlSb3RYeVsxXVswXTtcbiAgICAgICAgcG9zLnh5ID0gaVJvdFh5ICogcG9zLnh5OyBcblxuICAgICAgICAvLyBVbmRvIHRyYW5zbGF0ZSB0byBwaXZvdCBwb3NpdGlvblxuICAgICAgICBwb3MueHl6ICs9IHBpdm90O1xuXG4gICAgICAgIHBvcyA9IHZlYzMocG9zLnggKiBwcm9qZWN0aW9uLnggLSAxLjAsIHBvcy55ICogLWF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DID0gdGhpcy5fZ2V0Tm9ybWFsaXplZENvbG9yKGFyZ2IpO1xuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIHNldCBjb2xvcihhcmdiKSB7XG4gICAgICAgIHRoaXMuaW5uZXJDb2xvciA9IGFyZ2I7XG4gICAgfVxuXG4gICAgZ2V0IGNvbG9yKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5pbm5lckNvbG9yO1xuICAgIH1cblxuICAgIGdldCBvdXRlckNvbG9yKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faWM7XG4gICAgfVxuXG4gICAgc2V0IHgoZikge1xuICAgICAgICB0aGlzLl94ID0gZjtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBzZXQgeShmKSB7XG4gICAgICAgIHRoaXMuX3kgPSBmO1xuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIHNldCBwaXZvdCh2KSB7XG4gICAgICAgIGlmKEFycmF5LmlzQXJyYXkodikgJiYgdi5sZW5ndGggPT09IDIpIHtcbiAgICAgICAgICAgIHRoaXMuX3Bpdm90ID0gdjtcbiAgICAgICAgfVxuICAgICAgICBlbHNlIGlmKEFycmF5LmlzQXJyYXkodikpIHtcbiAgICAgICAgICAgIHRoaXMuX3Bpdm90ID0gW3ZbMF0sIHZbMV0gfHwgdlswXV07XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9waXZvdCA9IFt2LCB2XTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIGdldCBwaXZvdCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3Bpdm90WzBdO1xuICAgIH1cblxuICAgIHNldCBwaXZvdFkoZikge1xuICAgICAgICB0aGlzLl9waXZvdFsxXSA9IGY7XG4gICAgICAgIHRoaXMucmVkcmF3KCk7XG4gICAgfVxuXG4gICAgZ2V0IHBpdm90WSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3Bpdm90WzFdO1xuICAgIH1cblxuICAgIHNldCBwaXZvdFgoZikge1xuICAgICAgICB0aGlzLl9waXZvdFswXSA9IGY7XG4gICAgICAgIHRoaXMucmVkcmF3KCk7XG4gICAgfVxuXG4gICAgZ2V0IHBpdm90WCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3Bpdm90WzBdO1xuICAgIH1cblxuICAgIF9nZXROb3JtYWxpemVkQ29sb3IoY29sb3IpIHtcbiAgICAgICAgY29uc3QgY29sID0gU3RhZ2VVdGlscy5nZXRSZ2JhQ29tcG9uZW50c05vcm1hbGl6ZWQoY29sb3IpO1xuICAgICAgICBjb2xbMF0gKj0gY29sWzNdO1xuICAgICAgICBjb2xbMV0gKj0gY29sWzNdO1xuICAgICAgICBjb2xbMl0gKj0gY29sWzNdO1xuICAgICAgICByZXR1cm4gbmV3IEZsb2F0MzJBcnJheShjb2wpO1xuICAgIH1cblxuICAgIHNldHVwVW5pZm9ybXMob3BlcmF0aW9uKSB7XG4gICAgICAgIHN1cGVyLnNldHVwVW5pZm9ybXMob3BlcmF0aW9uKTtcbiAgICAgICAgY29uc3Qgb3duZXIgPSBvcGVyYXRpb24uc2hhZGVyT3duZXI7XG5cbiAgICAgICAgaWYodGhpcy5feCkge1xuICAgICAgICAgICAgdGhpcy5fcGl2b3RbMF0gPSB0aGlzLl94IC8gb3duZXIudztcbiAgICAgICAgfVxuICAgICAgICBpZih0aGlzLl95KSB7XG4gICAgICAgICAgICB0aGlzLl9waXZvdFsxXSA9IHRoaXMuX3kgLyBvd25lci5oO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYodGhpcy5fcmFkaXVzID09PSAwKSB7XG4gICAgICAgICAgICB0aGlzLl9yYWRpdXMgPSBvd25lci53ICogMC41O1xuICAgICAgICB9XG5cbiAgICAgICAgdGhpcy5fc2V0VW5pZm9ybSgnaW5uZXJDb2xvcicsIHRoaXMuX25v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XG4gICAgICAgICAgICBlbHNlIGlmKHYubGVuZ3RoID09PSAzKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcmFkaXVzID0gW3ZbMF0sIHZbMV0sIHZbMl0sIHRoaXMuX3JhZGl1c1szXV07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIGlmICh2Lmxlbmd0aCA9PT0gNCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3JhZGl1cyA9IHY7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9yYWRpdXMgPSBbdlswXSwgdlswXSwgdlswXSwgdlswXV07XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9yYWRpdXMgPSBbdiwgdiwgdiwgdl07XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgcmFkaXVzKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcmFkaXVzO1xuICAgIH1cblxuICAgIHNldCB0b3BMZWZ0KG51bSkge1xuICAgICAgICB0aGlzLl9yYWRpdXNbMF0gPSBudW07XG4gICAgICAgIHRoaXMucmVkcmF3KCk7XG4gICAgfVxuXG4gICAgZ2V0IHRvcExlZnQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9yYWRpdXNbMF07XG4gICAgfVxuXG4gICAgc2V0IHRvcFJpZ2h0KG51bSkge1xuICAgICAgICB0aGlzLl9yYWRpdXNbMV0gPSBudW07XG4gICAgICAgIHRoaXMucmVkcmF3KCk7XG4gICAgfVxuXG4gICAgZ2V0IHRvcFJpZ2h0KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcmFkaXVzWzFdO1xuICAgIH1cblxuICAgIHNldCBib3R0b21SaWdodChudW0pIHtcbiAgICAgICAgdGhpcy5fcmFkaXVzWzJdID0gbnVtO1xuICAgICAgICB0aGlz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iUGxlYXNlIGluY2x1ZGUgaHRtbDJjYW52YXMgKGh0dHBzOi8vaHRtbDJjYW52YXMuaGVydHplbi5jb20vKVwiKSk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGNvbnN0IGFyZWEgPSBIdG1sVGV4dHVyZS5nZXRQcmVsb2FkQXJlYSgpO1xuICAgICAgICAgICAgYXJlYS5hcHBlbmRDaGlsZChodG1sRWxlbWVudCk7XG5cbiAgICAgICAgICAgIGh0bWwyY2FudmFzKGh0bWxFbGVtZW50LCB7YmFja2dyb3VuZENvbG9yOiBudWxsLCBzY2FsZTogc2NhbGV9KS50aGVuKGZ1bmN0aW9uKGNhbnZhcykge1xuICAgICAgICAgICAgICAgIGFyZWEucmVtb3ZlQ2hpbGQoaHRtbEVsZW1lbnQpO1xuICAgICAgICAgICAgICAgIGlmIChjYW52YXMuaGVpZ2h0ID09PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYihuZXcgRXJyb3IoXCJDYW52YXMgaGVpZ2h0IGlzIDBcIikpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjYihudWxsLCB7c291cmNlOiBjYW52YXMsIHdpZHRoOiBjYW52YXMud2lkdGgsIGhlaWdodDogY2FudmFzLmhlaWdodH0pO1xuICAgICAgICAgICAgfSkuY2F0Y2goZSA9PiB7XG4gICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcignW0xpZ2h0bmluZ10nLCBlKTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGdldFByZWxvYWRBcmVhKCkge1xuICAgICAgICBpZiAoIXRoaXMuX3ByZWxvYWRBcmVhKSB7XG4gICAgICAgICAgICAvLyBQcmVsb2FkIGFyZWEgbXVzdCBiZSBpbmNsdWRlZCBpbiBkb2N1bWVudCBib2R5IGFuZCBtdXN0IGJlIHZpc2libGUgdG8gdHJpZ2dlciBodG1sIGVsZW1lbnQgcmVuZGVy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TtcblxuICAgICAgICB0aGlzLl9zcmMgPSB1bmRlZmluZWQ7XG4gICAgICAgIHRoaXMuX2hhc0FscGhhID0gZmFsc2U7XG4gICAgfVxuXG4gICAgZ2V0IHNyYygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3NyYztcbiAgICB9XG5cbiAgICBzZXQgc3JjKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX3NyYyAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fc3JjID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBoYXNBbHBoYSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2hhc0FscGhhO1xuICAgIH1cblxuICAgIHNldCBoYXNBbHBoYSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNBbHBoYSAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5faGFzQWxwaGEgPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2dldElzVmFsaWQoKSB7XG4gICAgICAgIHJldHVybiAhIXRoaXMuX3NyYztcbiAgICB9XG5cbiAgICBfZ2V0TG9va3VwSWQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9zcmM7XG4gICAgfVxuXG4gICAgX2dldFNvdXJjZUxvYWRlcigpIHtcbiAgICAgICAgbGV0IHNyYyA9IHRoaXMuX3NyYztcbiAgICAgICAgbGV0IGhhc0FscGhhID0gdGhpcy5faGFzQWxwaGE7XG4gICAgICAgIGlmICh0aGlzLnN0YWdlLmdldE9wdGlvbignc3JjQmFzZVBhdGgnKSkge1xuICAgICAgICAgICAgdmFyIGZjID0gc3JjLmNoYXJDb2RlQXQoMCk7XG4gICAgICAgICAgICBpZiAoKHNyYy5pbmRleE9mKFwiLy9cIikgPT09IC0xKSAmJiAoKGZjID49IDY1ICYmIGZjIDw9IDkwKSB8fC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N0eWxlKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX2ZvbnRTdHlsZSAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fZm9udFN0eWxlID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBmb250QmFzZWxpbmVSYXRpbygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2ZvbnRCYXNlbGluZVJhdGlvO1xuICAgIH1cbiAgICBcbiAgICBzZXQgZm9udEJhc2VsaW5lUmF0aW8odikge1xuICAgICAgICBpZiAodGhpcy5fZm9udEJhc2VsaW5lUmF0aW8gIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX2ZvbnRCYXNlbGluZVJhdGlvID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBmb250U2l6ZSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2ZvbnRTaXplO1xuICAgIH1cblxuICAgIHNldCBmb250U2l6ZSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9mb250U2l6ZSAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fZm9udFNpemUgPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGZvbnRGYWNlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fZm9udEZhY2U7XG4gICAgfVxuXG4gICAgc2V0IGZvbnRGYWNlKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX2ZvbnRGYWNlICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9mb250RmFjZSA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgd29yZFdyYXAoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl93b3JkV3JhcDtcbiAgICB9XG5cbiAgICBzZXQgd29yZFdyYXAodikge1xuICAgICAgICBpZiAodGhpcy5fd29yZFdyYXAgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX3dvcmRXcmFwID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCB3b3JkV3JhcFdpZHRoKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fd29yZFdyYXBXaWR0aDtcbiAgICB9XG5cbiAgICBzZXQgd29yZFdyYXBXaWR0aCh2KSB7XG4gICAgICAgIGlmICh0aGlzLl93b3JkV3JhcFdpZHRoICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl93b3JkV3JhcFdpZHRoID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCB3b3JkQnJlYWsoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl93b3JkQnJlYWs7XG4gICAgfVxuXG4gICAgc2V0IHdvcmRCcmVhayh2KSB7XG4gICAgICAgIGlmICh0aGlzLl93b3JkQnJlYWsgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX3dvcmRCcmVhayA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgdGV4dE92ZXJmbG93KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdGV4dE92ZXJmbG93O1xuICAgIH1cblxuICAgIHNldCB0ZXh0T3ZlcmZsb3codikge1xuICAgICAgICBpZiAodiAhPSB0aGlzLl90ZXh0T3ZlcmZsb3cpIHtcbiAgICAgICAgICAgIHRoaXMuX3RleHRPdmVyZmxvdyA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgbGluZUhlaWdodCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2xpbmVIZWlnaHQ7XG4gICAgfVxuXG4gICAgc2V0IGxpbmVIZWlnaHQodikge1xuICAgICAgICBpZiAodGhpcy5fbGluZUhlaWdodCAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fbGluZUhlaWdodCA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgdGV4dEJhc2VsaW5lKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdGV4dEJhc2VsaW5lO1xuICAgIH1cblxuICAgIHNldCB0ZXh0QmFzZWxpbmUodikge1xuICAgICAgICBpZiAodGhpcy5fdGV4dEJhc2VsaW5lICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl90ZXh0QmFzZWxpbmUgPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHRleHRBbGlnbigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3RleHRBbGlnbjtcbiAgICB9XG5cbiAgICBzZXQgdGV4dEFsaWduKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX3RleHRBbGlnbiAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fdGV4dEFsaWduID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCB2ZXJ0aWNhbEFsaWduKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdmVydGljYWxBbGlnbjtcbiAgICB9XG5cbiAgICBzZXQgdmVydGljYWxBbGlnbih2KSB7XG4gICAgICAgIGlmICh0aGlzLl92ZXJ0aWNhbEFsaWduICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl92ZXJ0aWNhbEFsaWduID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBvZmZzZXRZKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fb2Zmc2V0WTtcbiAgICB9XG5cbiAgICBzZXQgb2Zmc2V0WSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9vZmZzZXRZICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9vZmZzZXRZID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBtYXhMaW5lcygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX21heExpbmVzO1xuICAgIH1cblxuICAgIHNldCBtYXhMaW5lcyh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9tYXhMaW5lcyAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fbWF4TGluZXMgPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IG1heExpbmVzU3VmZml4KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbWF4TGluZXNTdWZmaXg7XG4gICAgfVxuXG4gICAgc2V0IG1heExpbmVzU3VmZml4KHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX21heExpbmVzU3VmZml4ICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9tYXhMaW5lc1N1ZmZpeCA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgdGV4dENvbG9yKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdGV4dENvbG9yO1xuICAgIH1cblxuICAgIHNldCB0ZXh0Q29sb3Iodikge1xuICAgICAgICBpZiAodGhpcy5fdGV4dENvbG9yICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl90ZXh0Q29sb3IgPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAg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AgfVxuXG4gICAgZ2V0IGxldHRlclNwYWNpbmcoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9sZXR0ZXJTcGFjaW5nO1xuICAgIH1cblxuICAgIHNldCB0ZXh0SW5kZW50KHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX3RleHRJbmRlbnQgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX3RleHRJbmRlbnQgPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHRleHRJbmRlbnQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl90ZXh0SW5kZW50O1xuICAgIH1cblxuICAgIHNldCBydGwodikge1xuICAgICAgICBpZiAodGhpcy5fcnRsICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9ydGwgPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHJ0bCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3J0bDtcbiAgICB9XG5cbiAgICBnZXQgcHJlY2lzaW9uKCkge1xuICAgICAgICByZXR1cm4gc3VwZXIucHJlY2lzaW9uO1xuICAgIH1cblxuICAgIHNldCBwcmVjaXNpb24odikge1xuICAgICAgICAvLyBXZSBhY3R1YWxseSBkcmF3IGRpZmZlcmVudGx5IHdoZW4gdGhlIHByZWNpc2lvbiBjaGFuZ2VzLlxuICAgICAgICBpZiAodGhpcy5wcmVjaXNpb24gIT09IHYpIHtcbiAgICAgICAgICAgIHN1cGVyLnByZWNpc2lvbiA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZ2V0SXNWYWxpZCgpIHtcbiAgICAgICAgcmV0dXJuICEhdGhpcy50ZXh0O1xuICAgIH1cblxuICAgIF9nZXRMb29rdXBJZCgpIHtcbiAgICAgICAgb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Npc2lvbiAmJiBhcmdzLmZvbnRTaXplIDw9IHNoYXJwQ2ZnLmZvbnRTaXplO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoZ2wgJiYgc2hhcnBlbikge1xuICAgICAgICAgICAgICAgIHRleFBhcmFtc1tnbC5URVhUVVJFX01BR19GSUxURVJdID0gZ2wuTkVBUkVTVDtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHApIHtcbiAgICAgICAgICAgICAgICBwLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgICAgICAgICAvKiBGSVhNRTogb24gc29tZSBwbGF0Zm9ybXMgKGUuZy4gUlBJKSwgdGhyb3R0bGluZyB0ZXh0IHRleHR1cmVzIGNhdXNlIGFydGlmYWN0cyAqL1xuICAgICAgICAgICAgICAgICAgICBjYihudWxsLCBPYmplY3QuYXNzaWduKHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlbmRlckluZm86IHJlbmRlcmVyLnJlbmRlckluZm8sXG4gICAgICAgICAgICAgICAgICAgICAgICB0aHJvdHRsZTogZmFsc2UsXG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXhQYXJhbXM6IHRleFBhcmFtcyxcbiAgICAgICAgICAgICAgICAgICAgfSwgdGhpcy5zdGFnZS5wbGF0Zm9ybS5nZXRUZXh0dXJlT3B0aW9uc0ZvckRyYXdpbmdDYW52YXMoY2FudmFzKSkpO1xuICAgICAgICAgICAgICAgIH0pLmNhdGNoKChlcnIpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgY2IoZXJyKTtcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgY2IobnVsbCwgT2JqZWN0LmFzc2lnbih7XG4gICAgICAgICAgICAgICAgICAgIHJlbmRlckluZm86IHJlbmRlcmVyLnJlbmRlckluZm8sXG4gICAgICAgICAgICAgICAgICAgIHRocm90dGxlOiBmYWxzZSxcbiAgICAgICAgICA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ICAgIHRoaXMuZ2V0UHJlY2lzaW9uKCksXG4gICAgICAgICAgICAgICAgdGhpcy5fc3RhZ2UuZ2V0T3B0aW9uKCdkZWZhdWx0Rm9udEZhY2UnKVxuICAgICAgICAgICAgKTtcbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5mb250cy5jaGVjayhmb250U2V0dGluZywgdGhpcy5fc2V0dGluZ3MudGV4dCkpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gVXNlIGEgcHJvbWlzZSB0aGF0IHdhaXRzIGZvciBsb2FkaW5nLlxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZG9jdW1lbnQuZm9udHMubG9hZChmb250U2V0dGluZywgdGhpcy5fc2V0dGluZ3MudGV4dCkuY2F0Y2goZXJyID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEp1c3QgbG9hZCB0aGUgZmFsbGJhY2sgZm9udC5cbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybignW0xpZ2h0bmluZ10gRm9udCBsb2FkIGVycm9yJywgZXJyLCBmb250U2V0dGluZyk7XG4gICAgICAgICAgICAgICAgICAgIH0pLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5mb250cy5jaGVjayhmb250U2V0dGluZywgdGhpcy5fc2V0dGluZ3MudGV4dCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oJ1tMaWdodG5pbmddIEZvbnQgbm90IGZvdW5kJywgZm9udFNldHRpbmcpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGNhdGNoKGUpIHtcbiAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJbTGlnaHRuaW5nXSBDYW4ndCBjaGVjayBmb250IGxvYWRpbmc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Ll9zdGFnZS5nZXRPcHRpb24oJ3cnKTtcblxuICAgICAgICAvLyBJbm5lciB3aWR0aC5cbiAgICAgICAgbGV0IGlubmVyV2lkdGggPSB3aWR0aCAtIChwYWRkaW5nTGVmdCk7XG4gICAgICAgIGlmIChpbm5lcldpZHRoIDwgMTApIHtcbiAgICAgICAgICAgIHdpZHRoICs9ICgxMCAtIGlubmVyV2lkdGgpO1xuICAgICAgICAgICAgaW5uZXJXaWR0aCA9IDEwO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKCF3b3JkV3JhcFdpZHRoKSB7XG4gICAgICAgICAgICB3b3JkV3JhcFdpZHRoID0gaW5uZXJXaWR0aFxuICAgICAgICB9XG5cbiAgICAgICAgLy8gVGV4dCBvdmVyZmxvd1xuICAgICAgICBpZiAodGhpcy5fc2V0dGluZ3MudGV4dE92ZXJmbG93ICYmICF0aGlzLl9zZXR0aW5ncy53b3JkV3JhcCkge1xuICAgICAgICAgICAgbGV0IHN1ZmZpeDtcbiAgICAgICAgICAgIHN3aXRjaCAodGhpcy5fc2V0dGluZ3MudGV4dE92ZXJmbG93KSB7XG4gICAgICAgICAgICAgICAgY2FzZSAnY2xpcCc6XG4gICAgICAgICAgICAgICAgICAgIHN1ZmZpeCA9ICcnO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBjYXNlICdlbGxpcHNpcyc6XG4gICAgICAgICAgICAgICAgICAgIHN1ZmZpeCA9IHRoaXMuX3NldHRpbmdzLm1heExpbmVzU3VmZml4O1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgICAgICBzdWZmaXggPSB0aGlzLl9zZXR0aW5ncy50ZXh0T3ZlcmZsb3c7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9zZXR0aW5ncy50ZXh0ID0gdGhpcy53cmFwV29yZCh0aGlzLl9zZXR0aW5ncy50ZXh0LCB3b3JkV3JhcFdpZHRoIC0gdGV4dEluZGVudCwgc3VmZml4KVxuICAgICAgICB9XG5cbiAgICAgICAgLy8gd29yZCB3cmFwXG4gICAgICAgIC8vIHByZXNlcnZlIG9yaWdpbmFsIHRleHRcbiAgICAgICAgbGV0IGxpbmVzSW5mbztcbiAgICAgICAgaWYgKHRoaXMuX3NldHRpbmdzLndvcmRXcmFwKSB7XG4gICAgICAgICAgICBsaW5lc0luZm8gPSB0aGlzLndyYXBUZXh0KHRoaXMuX3NldHRpbmdzLnRleHQsIHdvcmRXcmFwV2lkdGgsIGxldHRlclNwYWNpbmcsIHRleHRJbmRlbnQpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbGluZXNJbmZvID0ge2w6IHRoaXMuX3NldHRpbmdzLnRleHQuc3BsaXQoLyg/OlxcclxcbnxcXHJ8XFxuKS8pLCBuOiBbXX07XG4gICAgICAgICAgICBsZXQgaSwgbiA9IGxpbmVzSW5mby5sLmxlbmd0aDtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbiAtIDE7IGkrKykge1xuICAgICAgICAgICAgICAgIGxpbmVzSW5mby5uLnB1c2goaSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgbGV0IGxpbmVzID0gbGluZXNJbmZvLmw7XG5cbiAgICAgICAgaWYgKHRoaXMuX3NldHRpbmdzLm1heExpbmVzICYmIGxpbmVzLmxlbmd0aCA+IHRoaXMuX3NldHRpbmdzLm1heExpbmVzKSB7XG4gICAgICAgICAgICBsZXQgdXNlZExpbmVzID0gbGluZXMuc2xpY2UoMCwgdGhpcy5fc2V0dGluZ3MubWF4TGluZXMpO1xuXG4gICAgICAgICAgICBsZXQgb3RoZXJMaW5lcyA9IG51bGw7XG4gICAgICAgICAgICBpZiAodGhpcy5fc2V0dGluZ3MubWF4TGluZXNTdWZmaXgpIHtcbiAgICAgICAgICAgICAgICAvLyBXcmFwIGFnYWluIHdpdGggbWF4IGxpbmVzIHN1ZmZpeCBlbmFibGVkLlxuICAgICAgICAgICAgICAgIGxldCB3ID0gdGhpcy5fc2V0dGluZ3MubWF4TGluZXNTdWZmaXggPyB0aGlzLm1lYXN1cmVUZXh0KHRoaXMuX3NldHRpbmdzLm1heExpbmVzU3VmZml4KSA6IDA7XG4gICAgICAgICAgICAgICAgbGV0IGFsID0gdGhpcy53cmFwVGV4dCh1c2VkTGluZXNbdXNlZExpbmVzLmxlbmd0aCAtIDFdLCB3b3JkV3JhcFdpZHRoIC0gdywgbGV0dGVyU3BhY2luZywgdGV4dEluZGVudCk7XG4gICAgICAgICAgICAgICAgdXNlZExpbmVzW3VzZWRMaW5lcy5sZW5ndGggLSAxXSA9IGFsLmxbMF0gKyB0aGlzLl9zZXR0aW5ncy5tYXhMaW5lc1N1ZmZpeDtcbiAgICAgICAgICAgICAgICBvdGhlckxpbmVzID0gW2FsLmwubGVuZ3RoID4gMSA/IGFsLmxbMV0gOiAnJ107XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIG90aGVyTGluZXMgPSBbJyddO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBSZS1hc3NlbWJsZSB0aGUgcmVtYWluaW5nIHRleHQuXG4gICAgICAgICAgICBsZXQgaSwgbiA9IGxpbmVzLmxlbmd0aDtcbiAgICAgICAgICAgIGxldCBqID0gMDtcbiAgICAgICAgICAgIGxldCBtID0gbGluZXNJbmZvLm4ubGVuZ3RoO1xuICAgICAgICAgICAgZm9yIChpID0gdGhpcy5fc2V0dGluZ3MubWF4TGluZXM7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICBvdGhlckxpbmVzW2pdICs9IChvdGhlckxpbmVzW2pdID8gXCIgXCIgOiBcIlwiKSArIGxpbmVzW2ldO1xuICAgICAgICAgICAgICAgIGlmIChpICsgMSA8IG0gJiYgbGluZXNJbmZvLm5baSArIDFdKSB7XG4gICAgICAgICAgICAgICAgICAgIGorKztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHJlbmRlckluZm8ucmVtYWluaW5nVGV4dCA9IG90aGVyTGluZXMuam9pbihcIlxcblwiKTtcblxuICAgICAgICAgICAgcmVuZGVySW5mby5tb3JlVGV4dExpbmVzID0gdHJ1ZTtcblxuICAgICAgICAgICAgbGluZXMgPSB1c2VkTGluZXM7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZW5kZXJJbmZvLm1vcmVUZXh0TGluZXMgPSBmYWxzZTtcbiAgICAgICAgICAgIHJlbmRlckluZm8ucmVtYWluaW5nVGV4dCA9IFwiXCI7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBjYWxjdWxhdGUgdGV4dCB3aWR0aFxuICAgICAgICBsZXQgbWF4TGluZVdpZHRoID0gMDtcbiAgICAgICAgbGV0IGxpbmVXaWR0aHMgPSBbXTtcbiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsaW5lcy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgbGV0IGxpbmVXaWR0aCA9IHRoaXMubWVhc3VyZVRleHQobGluZXNbaV0sIGxldHRlclNwYWNpbmcpICsgKGkgPT09IDAgPyB0ZXh0SW5kZW50IDogMCk7XG4gICAgICAgICAgICBsaW5lV2lkdGhzLnB1c2gobGluZVdpZHRoKTtcbiAgICAgICAgICAgIG1heExpbmVXaWR0aCA9IE1hdGgubWF4KG1heExpbmVXaWR0aCwgbGluZVdpZHRoKTtcbiAgICAgICAgfVxuXG4gICAgICAgIHJlbmRlckluZm8ubGluZVdpZHRocyA9IGxpbmVXaWR0aHM7XG5cbiAgICAgICAgaWYgKCF3KSB7XG4gICAgICAgICAgICAvLyBBdXRvLXNldCB3aWR0aCB0byBtYXggdGV4dCBsZW5ndGguXG4gICAgICAgICAgICB3aWR0aCA9IG1heExpbmVXaWR0aCArIHBhZGRpbmdMZWZ0ICsgcGFkZGluZ1JpZ2h0O1xuICAgICAgICAgICAgaW5uZXJXaWR0aCA9IG1heExpbmVXaWR0aDtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIGNhbGN1bGF0ZSB0ZXh0IGhlaWdodFxuICAgICAgICBsaW5lSGVpZ2h0ID0gbGluZUhlaWdodCB8fCBmb250U2l6ZTtcblxuICAgICAgICBsZXQgaGVpZ2h0O1xuICAgICAgICBpZiAoaCkge1xuICAgICAgICAgICAgaGVpZ2h0ID0gaDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGNvbnN0IGJhc2VsaW5lT2Zmc2V0ID0gKHRoaXMuX3NldHRpbmdzLnRleHRCYXNlbGluZSAhPSAnYm90dG9tJykgPyAwLjUgKiBmb250U2l6ZSA6IDA7XG4gICAgICAgICAgICBoZWlnaHQgPSBsaW5lSGVpZ2h0ICogKGxpbmVzLmxlbmd0aCAtIDEpICsgYmFzZWxpbmVPZmZzZXQgKyBNYXRoLm1heChsaW5lSGVpZ2h0LCBmb250U2l6ZSkgKyBvZmZzZXRZO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKG9mZnNldFkgPT09IG51bGwpIHtcbiAgICAgICAgICAgIG9mZnNldFkgPSBmb250U2l6ZTtcbiAgICAgICAgfVxuXG4gICAgICAgIHJlbmRlckluZm8udyA9IHdpZHRoO1xuICAgICAgICByZW5kZXJJbmZvLmggPSBoZWlnaHQ7XG4gICAgICAgIHJlbmRlckluZm8ubGluZXMgPSBsaW5lcztcbiAgICAgICAgcmVuZGVySW5mby5wcmVjaXNpb24gPSBwcmVjaXNpb247XG5cbiAgICAgICAgaWYgKCF3aWR0aCkge1xuICAgICAgICAgICAgLy8gVG8gcHJldmVudCBjYW52YXMgZXJyb3JzLlxuICAgICAgICAgICAgd2lkdGggPSAxO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKCFoZWlnaHQpIHtcbiAgICAgICAgICAgIC8vIFRvIHByZXZlbnQgY2FudmFzIGVycm9ycy5cbiAgICAgICAgICAgIGhlaWdodCA9IDE7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoY3V0U3ggfHwgY3V0RXgpIHtcbiAgICAgICAgICAgIHdpZHRoID0gTWF0aC5taW4od2lkdGgsIGN1dEV4IC0gY3V0U3gpO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKGN1dFN5IHx8IGN1dEV5KSB7XG4gICAgICAgICAgICBoZWlnaHQgPSBNYXRoLm1pbihoZWlnaHQsIGN1dEV5IC0gY3V0U3kpO1xuICAgICAgICB9XG5cbiAgICAgICAgcmVuZGVySW5mby53aWR0aCA9IHdpZHRoO1xuICAgICAgICByZW5kZXJJbmZvLmlubmVyV2lkdGggPSBpbm5lcldpZHRoO1xuICAgICAgICByZW5kZXJJbmZvLmhlaWdodCA9IGhlaWdodDtcbiAgICAgICAgcmVuZGVySW5mby5mb250U2l6ZSA9IGZvbnRTaXplO1xuICAgICAgICByZW5kZXJJbmZvLmN1dFN4ID0gY3V0U3g7XG4gICAgICAgIHJlbmRlckluZm8uY3V0U3kgPSBjdXRTeTtcbiAgICAgICAgcmVuZGVySW5mby5jdXRFeCA9IGN1dEV4O1xuICAgICAgICByZW5kZXJJbmZvLmN1dEV5ID0gY3V0RXk7XG4gICAgICAgIHJlbmRlckluZm8ubGluZUhlaWdodCA9IGxpbmVIZWlnaHQ7XG4gICAgICAgIHJlbmRlckluZm8ubGluZVdpZHRocyA9IGxpbmVXaWR0aHM7XG4gICAgICAgIHJlbmRlckluZm8ub2Zmc2V0WSA9IG9mZnNldFk7XG4gICAgICAgIHJlbmRlckluZm8ucGFkZGluZ0xlZnQgPSBwYWRkaW5nTGVmdDtcbiAgICAgICAgcmVuZGVySW5mby5wYWRkaW5nUmlnaHQgPSBwYWRkaW5nUmlnaHQ7XG4gICAgICAgIHJlbmRlckluZm8ubGV0dGVyU3BhY2luZyA9IGxldHRlclNwYWNpbmc7XG4gICAgICAgIHJlbmRlckluZm8udGV4dEluZGVudCA9IHRleHRJbmRlbnQ7XG5cbiAgICAgICAgcmV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IHx8IHJlbmRlckluZm8uY3V0U3kpIHtcbiAgICAgICAgICAgIHRoaXMuX2NvbnRleHQudHJhbnNsYXRlKC1yZW5kZXJJbmZvLmN1dFN4LCAtcmVuZGVySW5mby5jdXRTeSk7XG4gICAgICAgIH1cblxuICAgICAgICBsZXQgbGluZVBvc2l0aW9uWDtcbiAgICAgICAgbGV0IGxpbmVQb3NpdGlvblk7XG5cbiAgICAgICAgbGV0IGRyYXdMaW5lcyA9IFtdO1xuXG4gICAgICAgIC8vIERyYXcgbGluZXMgbGluZSBieSBsaW5lLlxuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHJlbmRlckluZm8ubGluZXMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBsaW5lUG9zaXRpb25YID0gaSA9PT0gMCA/IHJlbmRlckluZm8udGV4dEluZGVudCA6IDA7XG5cbiAgICAgICAgICAgIC8vIEJ5IGRlZmF1bHQsIHRleHQgaXMgYWxpZ25lZCB0byB0b3BcbiAgICAgICAgICAgIGxpbmVQb3NpdGlvblkgPSAoaSAqIHJlbmRlckluZm8ubGluZUhlaWdodCkgKyByZW5kZXJJbmZvLm9mZnNldFk7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9zZXR0aW5ncy52ZXJ0aWNhbEFsaWduID09ICdtaWRkbGUnKSB7XG4gICAgICAgICAgICAgICAgbGluZVBvc2l0aW9uWSArPSAocmVuZGVySW5mby5saW5lSGVpZ2h0IC0gcmVuZGVySW5mby5mb250U2l6ZSkgLyAyO1xuICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9zZXR0aW5ncy52ZXJ0aWNhbEFsaWduID09ICdib3R0b20nKSB7XG4gICAgICAgICAgICAgICAgbGluZVBvc2l0aW9uWSArPSByZW5kZXJJbmZvLmxpbmVIZWlnaHQgLSByZW5kZXJJbmZvLmZvbnRTaXplO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAodGhpcy5fc2V0dGluZ3MudGV4dEFsaWduID09PSAncmlnaHQnKSB7XG4gICAgICAgICAgICAgICAgbGluZVBvc2l0aW9uWCArPSAocmVuZGVySW5mby5pbm5lcldpZHRoIC0gcmVuZGVySW5mby5saW5lV2lkdGhzW2ldKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fc2V0dGluZ3MudGV4dEFsaWduID09PSAnY2VudGVyJykge1xuICAgICAgICAgICAgICAgIGxpbmVQb3NpdGlvblggKz0gKChyZW5kZXJJbmZvLmlubmVyV2lkdGggLSByZW5kZXJJbmZvLmxpbmVXaWR0aHNbaV0pIC8gMik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBsaW5lUG9zaXRpb25YICs9IHJlbmRlckluZm8ucGFkZGluZ0xlZnQ7XG4gICAgICAgICAgICBpZiAodGhpcy5fc2V0dGluZ3MucnRsKSB7XG4gICAgICAgICAgICAgICAgbGluZVBvc2l0aW9uWCArPSByZW5kZXJJbmZvLmxpbmVXaWR0aHNbaV07XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGRyYXdMaW5lcy5wdXNoKHt0ZXh0OiByZW5kZXJJbmZvLmxpbmVzW2ldLCB4OiBsaW5lUG9zaXRpb25YLCB5OiBsaW5lUG9zaXRpb25ZLCB3OiByZW5kZXJJbmZvLmxpbmVXaWR0aHNbaV19KTtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEhpZ2hsaWdodC5cbiAgICAgICAgaWYgKHRoaXMuX3NldHRpbmdzLmhpZ2hsaWdodCkge1xuICAgICAgICAgICAgbGV0IGNvbG9yID0gdGhpcy5fc2V0dGluZ3MuaGlnaGxpZ2h0Q29sb3IgfHwgMHgwMDAwMDAwMDtcblxuICAgICAgICAgICAgbGV0IGhsSGVpZ2h0ID0gKHRoaXMuX3NldHRpbmdzLmhpZ2hsaWdodEhlaWdodCAqIHByZWNpc2lvbiB8fCByZW5kZXJJbmZvLmZvbnRTaXplICogMS41KTtcbiAgICAgICAgICAgIGNvbnN0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dCwgZHJhd0xpbmUueCwgZHJhd0xpbmUueSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGNvbnN0IHRleHRTcGxpdCA9IGRyYXdMaW5lLnRleHQuc3BsaXQoJycpO1xuICAgICAgICAgICAgICAgIGxldCB4ID0gZHJhd0xpbmUueDtcbiAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgaiA9IHRleHRTcGxpdC5sZW5ndGg7IGkgPCBqOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fY29udGV4dC5maWxsVGV4dCh0ZXh0U3BsaXRbaV0sIHgsIGRyYXdMaW5lLnkpO1xuICAgICAgICAgICAgICAgICAgICB4ICs9IHRoaXMubWVhc3VyZVRleHQodGV4dFNwbGl0W2ldLCByZW5kZXJJbmZvLmxldHRlclNwYWNpbmcpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChwcmV2U2hhZG93U2V0dGluZ3MpIHtcbiAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93Q29sb3IgPSBwcmV2U2hhZG93U2V0dGluZ3NbMF07XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd09mZnNldFggPSBwcmV2U2hhZG93U2V0dGluZ3NbMV07XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd09mZnNldFkgPSBwcmV2U2hhZG93U2V0dGluZ3NbMl07XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd0JsdXIgPSBwcmV2U2hhZG93U2V0dGluZ3NbM107XG4gICAgICAgIH1cblxuICAgICAgICBpZiAocmVuZGVySW5mby5jdXRTeCB8fCByZW5kZXJJbmZvLmN1dFN5KSB7XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnRyYW5zbGF0ZShyZW5kZXJJbmZvLmN1dFN4LCByZW5kZXJJbmZvLmN1dFN5KTt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CwgY3V0b2ZmSW5kZXgpKSArIHN1ZmZpeFdpZHRoO1xuICAgICAgICAgICAgICAgIGlmICh0cnVuY1dvcmRXaWR0aCA+IHdvcmRXcmFwV2lkdGgpIHtcbiAgICAgICAgICAgICAgICAgICAgY3V0b2ZmSW5kZXggLT0gMTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgLyogSW4gY2FzZSBndWVzcyB3YXMgdW5kZXJlc3RpbWF0ZWQsIGV4dGVuZCBpdCBsZXR0ZXIgYnkgbGV0dGVyLiAqL1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgd2hpbGUgKGN1dG9mZkluZGV4IDwgd29yZExlbikge1xuICAgICAgICAgICAgICAgIHRydW5jV29yZFdpZHRoID0gdGhpcy5tZWFzdXJlVGV4dCh3b3JkLnN1YnN0cmluZygwLCBjdXRvZmZJbmRleCkpICsgc3VmZml4V2lkdGg7XG4gICAgICAgICAgICAgICAgaWYgKHRydW5jV29yZFdpZHRoIDwgd29yZFdyYXBXaWR0aCkge1xuICAgICAgICAgICAgICAgICAgICBjdXRvZmZJbmRleCArPSAxO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIEZpbmFsbHksIHdoZW4gYm91bmQgaXMgY3Jvc3NlZCwgcmV0cmFjdCBsYXN0IGxldHRlci5cbiAgICAgICAgICAgICAgICAgICAgY3V0b2ZmSW5kZXggLT0xO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICAvKiBJZiB3cmFwV2lkdGggaXMgdG9vIHNob3J0IHRvIGV2ZW4gY29udGFpbiBzdWZmaXggYWxvbmUsIHJldHVybiBlbXB0eSBzdHJpbmcgKi9cbiAgICAgICAgcmV0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7XG4gICAgICAgICAgICBjb25zdCBmb250U2V0dGluZyA9IGdldEZvbnRTZXR0aW5nKFxuICAgICAgICAgICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRGYWNlLFxuICAgICAgICAgICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRTdHlsZSxcbiAgICAgICAgICAgICAgICB0aGlzLl9zZXR0aW5ncy5mb250U2l6ZSxcbiAgICAgICAgICAgICAgICB0aGlzLmdldFByZWNpc2lvbigpLFxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YWdlLmdldE9wdGlvbignZGVmYXVsdEZvbnRGYWNlJylcbiAgICAgICAgICAgICk7XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgIGlmICghZG9jdW1lbnQuZm9udHMuY2hlY2soZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFVzZSBhIHByb21pc2UgdGhhdCB3YWl0cyBmb3IgbG9hZGluZy5cbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRvY3VtZW50LmZvbnRzLmxvYWQoZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpLmNhdGNoKGVyciA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBKdXN0IGxvYWQgdGhlIGZhbGxiYWNrIGZvbnQuXG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oJ0ZvbnQgbG9hZCBlcnJvcicsIGVyciwgZm9udFNldHRpbmcpO1xuICAgICAgICAgICAgICAgICAgICB9KS50aGVuKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghZG9jdW1lbnQuZm9udHMuY2hlY2soZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS53YXJuKCdGb250IG5vdCBmb3VuZCcsIGZvbnRTZXR0aW5n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W5ncy5zaGFkb3dPZmZzZXRYO1xuICAgICAgICByZW5kZXJJbmZvLnNoYWRvd09mZnNldFkgPSB0aGlzLl9zZXR0aW5ncy5zaGFkb3dPZmZzZXRZO1xuICAgICAgICByZW5kZXJJbmZvLnNoYWRvd0JsdXIgPSB0aGlzLl9zZXR0aW5ncy5zaGFkb3dCbHVyO1xuICAgICAgICByZW5kZXJJbmZvLmN1dFN4ID0gY3V0U3g7XG4gICAgICAgIHJlbmRlckluZm8uY3V0RXggPSBjdXRFeDtcbiAgICAgICAgcmVuZGVySW5mby5jdXRTeSA9IGN1dFN5O1xuICAgICAgICByZW5kZXJJbmZvLmN1dEV5ID0gY3V0RXk7XG4gICAgICAgIHJlbmRlckluZm8udGV4dEluZGVudCA9IHRoaXMuX3NldHRpbmdzLnRleHRJbmRlbnQgKiBwcmVjaXNpb247XG4gICAgICAgIHJlbmRlckluZm8ud29yZEJyZWFrID0gdGhpcy5fc2V0dGluZ3Mud29yZEJyZWFrO1xuXG4gICAgICAgIGxldCB0ZXh0ID0gcmVuZGVySW5mby50ZXh0O1xuICAgICAgICBsZXQgd3JhcFdpZHRoID0gcmVuZGVySW5mby53b3JkV3JhcCA/IChyZW5kZXJJbmZvLndvcmRXcmFwV2lkdGggfHwgcmVuZGVySW5mby53aWR0aCkgOiByZW5kZXJJbmZvLndpZHRoO1xuXG4gICAgICAgIC8vIFRleHQgb3ZlcmZsb3dcbiAgICAgICAgaWYgKHJlbmRlckluZm8udGV4dE92ZXJmbG93ICYmICFyZW5kZXJJbmZvLndvcmRXcmFwKSB7XG4gICAgICAgICAgICBsZXQgc3VmZml4O1xuICAgICAgICAgICAgc3dpdGNoICh0aGlzLl9zZXR0aW5ncy50ZXh0T3ZlcmZsb3cpIHtcbiAgICAgICAgICAgICAgICBjYXNlICdjbGlwJzpcbiAgICAgICAgICAgICAgICAgICAgc3VmZml4ID0gJyc7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIGNh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ldCBsaW5lTm8gPSAwO1xuXG4gICAgICAgIGZvciAoY29uc3QgdCBvZiB0ZXh0KSB7XG4gICAgICAgICAgICAvLyBXcmFwIHRleHRcbiAgICAgICAgICAgIGlmIChyZW5kZXJJbmZvLndvcmRXcmFwICYmIHggKyB0LndpZHRoID4gd3JhcFdpZHRoIHx8IHQudGV4dCA9PSAnXFxuJykge1xuICAgICAgICAgICAgICAgIHggPSBwYWRkaW5nTGVmdDtcbiAgICAgICAgICAgICAgICBsaW5lTm8gKz0gMTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHQubGluZU5vID0gbGluZU5vO1xuXG4gICAgICAgICAgICBpZiAodC50ZXh0ID09ICdcXG4nKSB7XG4gICAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHQueCA9IHg7XG4gICAgICAgICAgICB4ICs9IHQud2lkdGg7XG4gICAgICAgIH1cbiAgICAgICAgcmVuZGVySW5mby5saW5lTnVtID0gbGluZU5vICsgMTtcblxuICAgICAgICBpZiAodGhpcy5fc2V0dGluZ3MuaCkge1xuICAgICAgICAgICAgcmVuZGVySW5mby5oID0gdGhpcy5fc2V0dGluZ3MuaDtcbiAgICAgICAgfSBlbHNlIGlmIChyZW5kZXJJbmZvLm1heExpbmVzICYmIHJlbmRlckluZm8ubWF4TGluZXMgPCByZW5kZXJJbmZvLmxpbmVOdW0pIHtcbiAgICAgICAgICAgIHJlbmRlckluZm8uaCA9IHJlbmRlckluZm8ubWF4TGluZXMgKiByZW5kZXJJbmZvLmxpbmVIZWlnaHQgKyBmb250U2l6ZSAvIDI7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZW5kZXJJbmZvLmggPSByZW5kZXJJbmZvLmxpbmVOdW0gKiByZW5kZXJJbmZvLmxpbmVIZWlnaHQgKyBmb250U2l6ZSAvIDI7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBUaGlzIGNhbGN1bGF0ZXMgdGhlIGJh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gpIC8gMjtcbiAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9zZXR0aW5ncy52ZXJ0aWNhbEFsaWduID09ICdib3R0b20nKSB7XG4gICAgICAgICAgICB2YU9mZnNldCA9IHJlbmRlckluZm8ubGluZUhlaWdodCAtIHJlbmRlckluZm8uZm9udFNpemU7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBDYWxjdWxhdGUgbGluZXMgaW5mb3JtYXRpb25cbiAgICAgICAgcmVuZGVySW5mby5saW5lcyA9IFtdXG4gICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgcmVuZGVySW5mby5saW5lTnVtOyBpKyspIHtcbiAgICAgICAgICAgIHJlbmRlckluZm8ubGluZXNbaV0gPSB7XG4gICAgICAgICAgICAgICAgd2lkdGg6IDAsXG4gICAgICAgICAgICAgICAgeDogMCxcbiAgICAgICAgICAgICAgICB5OiByZW5kZXJJbmZvLmxpbmVIZWlnaHQgKiBpICsgdmFPZmZzZXQsXG4gICAgICAgICAgICAgICAgdGV4dDogW10sXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBmb3IgKGxldCB0IG9mIHRleHQpIHtcbiAgICAgICAgICAgIHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnRleHQucHVzaCh0KTtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEZpbHRlciBvdXQgd2hpdGUgc3BhY2VzIGF0IGJlZ2lubmluZyBhbmQgZW5kIG9mIGVhY2ggbGluZVxuICAgICAgICBmb3IgKGNvbnN0IGwgb2YgcmVuZGVySW5mby5saW5lcykge1xuICAgICAgICAgICAgaWYgKGwudGV4dC5sZW5ndGggPT0gMCkge1xuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBjb25zdCBmaXJzdFdvcmQgPSBsLnRleHRbMF0udGV4dDtcbiAgICAgICAgICAgIGNvbnN0IGxhc3RXb3JkID0gbC50ZXh0W2wudGV4dC5sZW5ndGggLSAxXS50ZXh0O1xuXG4gICAgICAgICAgICBpZiAoZmlyc3RXb3JkID09ICdcXG4nKSB7XG4gICAgICAgICAgICAgICAgbC50ZXh0LnNoaWZ0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoaXNTcGFjZShsYXN0V29yZCkgfHwgbGFzdFdvcmQgPT0gJ1xcbicpIHtcbiAgICAgICAgICAgICAgICBsLnRleHQucG9wKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuXG4gICAgICAgIC8vIENhbGN1bGF0ZSBsaW5lIHdpZHRoXG4gICAgICAgIGZvciAobGV0IGwgb2YgcmVuZGVySW5mby5saW5lcykge1xuICAgICAgICAgICAgbC53aWR0aCA9IGwudGV4dC5yZWR1Y2UoKGFjYywgdCkgPT4gYWNjICsgdC53aWR0aCwgMCk7XG4gICAgICAgIH1cblxuICAgICAgICByZW5kZXJJbmZvLndpZHRoID0gdGhpcy5fc2V0dGluZ3MudyAhPSAwID8gdGhpcy5fc2V0dGluZ3MudyAqIHByZWNpc2lvbiA6IE1hdGgubWF4KC4uLnJlbmRlckluZm8ubGluZXMubWFwKChsKSA9PiBsLndpZHRoKSkgKyBwYWRkaW5nUmlnaHQ7XG4gICAgICAgIHJlbmRlckluZm8udyA9IHJlbmRlckluZm8ud2lkdGg7XG5cbiAgICAgICAgLy8gQXBwbHkgbWF4TGluZXNTdWZmaXhcbiAgICAgICAgaWYgKHJlbmRlckluZm8ubWF4TGluZXMgJiYgcmVuZGVySW5mby5saW5lTnVtID4gcmVuZGVySW5mby5tYXhMaW5lcyAmJiByZW5kZXJJbmZvLm1heExpbmVzU3VmZml4KSB7XG4gICAgICAgICAgICBjb25zdCBpbmRleCA9IHJlbmRlckluZm8ubWF4TGluZXMgLSAxO1xuICAgICAgICAgICAgbGV0IGxhc3RMaW5lVGV4dCA9IHRleHQuZmlsdGVyKCh0KSA9PiB0LmxpbmVObyA9PSBpbmRleClcbiAgICAgICAgICAgIGxldCBzdWZmaXggPSByZW5kZXJJbmZvLm1heExpbmVzU3VmZml4O1xuICAgICAgICAgICAgc3VmZml4ID0gdGhpcy50b2tlbml6ZShzdWZmaXgpO1xuICAgICAgICAgICAgc3VmZml4ID0gdGhpcy5wYXJzZShzdWZmaXgpO1xuICAgICAgICAgICAgc3VmZml4ID0gdGhpcy5tZWFzdXJlKHN1ZmZpeCwgcmVuZGVySW5mby5sZXR0ZXJTcGFjaW5nLCByZW5kZXJJbmZvLmJhc2VGb250KTtcbiAgICAgICAgICAgIGZvciAoY29uc3QgcyBvZiBzdWZmaXgpIHtcbiAgICAgICAgICAgICAgICBzLmxpbmVObyA9IGluZGV4O1xuICAgICAgICAgICAgICAgIHMueCA9IDA7XG4gICAgICAgICAgICAgICAgbGFzdExpbmVUZXh0LnB1c2gocylcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgY29uc3Qgc3BsID0gc3VmZml4Lmxlbmd0aCArIDFcbiAgICAgICAgICAgIGxldCBfdyA9IGxhc3RMaW5lVGV4dC5yZWR1Y2UoKGFjYywgdCkgPT4gYWNjICsgdC53aWR0aCwgMCk7XG4gICAgICAgICAgICB3aGlsZSAoX3cgPiByZW5kZXJJbmZvLndpZHRoIHx8IGlzU3BhY2UobGFzdExpbmVUZXh0W2xhc3RMaW5lVGV4dC5sZW5ndGggLSBzcGxdLnRleHQpKSB7XG4gICAgICAgICAgICAgICAgbGFzdExpbmVUZXh0LnNwbGljZShsYXN0TGluZVRleHQubGVuZ3RoIC0gc3BsLCAxKTtcbiAgICAgICAgICAgICAgICBfdyA9IGxhc3RMaW5lVGV4dC5yZWR1Y2UoKGFjYywgdCkgPT4gYWNjICsgdC53aWR0aCwgMCk7XG4gICAgICAgICAgICAgICAgaWYgKGxhc3RMaW5lVGV4dC5sZW5ndGggPCBzcGwpIHtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5hbGlnbkxpbmUobGFzdExpbmVUZXh0LCBsYXN0TGluZVRleHRbMF0ueClcblxuICAgICAgICAgICAgcmVuZGVySW5mby5saW5lc1tpbmRleF0udGV4dCA9IGxhc3RMaW5lVGV4dDtcbiAgICAgICAgICAgIHJlbmRlckluZm8ubGluZXNbaW5kZXhdLndpZHRoID0gX3c7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBIb3Jpem9udGFsIGFsaWdubWVudCBvZmZzZXRcbiAgICAgICAgaWYgKHJlbmRlckluZm8udGV4dEFsaWduID09ICdjZW50ZXInKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBsIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgICAgICAgICAgICBsLnggPSAocmVuZGVySW5mby53aWR0aCAtIGwud2lkdGggLSBwYWRkaW5nTGVmdCkgLyAyO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHJlbmRlckluZm8udGV4dEFsaWduID09ICdyaWdodCcpIHtcbiAgICAgICAgICAgIGZvciAobGV0IGwgb2YgcmVuZGVySW5mby5saW5lcykge1xuICAgICAgICAgICAgICAgIGwueCA9IHJlbmRlckluZm8ud2lkdGggLSBsLndpZHRoIC0gcGFkZGluZ0xlZnQ7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gcmVuZGVySW5mbztcbiAgICB9XG5cbiAgICBfZHJhdygpIHtcbiAgICAgICAgY29uc3QgcmVuZGVySW5mbyA9IHRoaXMuX2NhbGN1bGF0ZVJlbmRlckluZm8oKTtcbiAgICAgICAgY29uc3QgcHJlY2lzaW9uID0gdGhpcy5nZXRQcmVjaXNpb24oKTtcbiAgICAgICAgY29uc3QgcGFkZGluZ0xlZnQgPSByZW5kZXJJbmZvLnBhZGRpbmdMZWZ0ICogcHJlY2lzaW9uO1xuXG4gICAgICAgIC8vIFNldCBjYW52YXMgZGltZW5zaW9uc1xuICAgICAgICBsZXQgY2FudmFzV2lkdGggPSByZW5k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aHQgIT09IG51bGwgPyByZW5kZXJJbmZvLmhpZ2hsaWdodFBhZGRpbmdSaWdodCAqIHByZWNpc2lvbiA6IHJlbmRlckluZm8ucGFkZGluZ1JpZ2h0KTtcblxuICAgICAgICAgICAgdGhpcy5fY29udGV4dC5maWxsU3R5bGUgPSBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcoaGxDb2xvcik7XG4gICAgICAgICAgICBjb25zdCBsaW5lTnVtID0gcmVuZGVySW5mby5tYXhMaW5lcyA/IE1hdGgubWluKHJlbmRlckluZm8ubWF4TGluZXMsIHJlbmRlckluZm8ubGluZU51bSkgOiByZW5kZXJJbmZvLmxpbmVOdW07XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxpbmVOdW07IGkrKykge1xuICAgICAgICAgICAgICAgIGNvbnN0IGwgPSByZW5kZXJJbmZvLmxpbmVzW2ldO1xuICAgICAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuZmlsbFJlY3QobC54IC0gaGxQYWRkaW5nTGVmdCArIHBhZGRpbmdMZWZ0LCBsLnkgKyBobE9mZnNldCwgbC53aWR0aCArIGhsUGFkZGluZ0xlZnQgKyBobFBhZGRpbmdSaWdodCwgaGxIZWlnaHQpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgLy8gVGV4dCBzaGFkb3cuXG4gICAgICAgIGxldCBwcmV2U2hhZG93U2V0dGluZ3MgPSBudWxsO1xuICAgICAgICBpZiAodGhpcy5fc2V0dGluZ3Muc2hhZG93KSB7XG4gICAgICAgICAgICBwcmV2U2hhZG93U2V0dGluZ3MgPSBbdGhpcy5fY29udGV4dC5zaGFkb3dDb2xvciwgdGhpcy5fY29udGV4dC5zaGFkb3dPZmZzZXRYLCB0aGlzLl9jb250ZXh0LnNoYWRvd09mZnNldFksIHRoaXMuX2NvbnRleHQuc2hhZG93Qmx1cl07XG5cbiAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93Q29sb3IgPSBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcodGhpcy5fc2V0dGluZ3Muc2hhZG93Q29sb3IpO1xuICAgICAgICAgICAgdGhpcy5fY29udGV4dC5zaGFkb3dPZmZzZXRYID0gdGhpcy5fc2V0dGluZ3Muc2hhZG93T2Zmc2V0WCAqIHByZWNpc2lvbjtcbiAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93T2Zmc2V0WSA9IHRoaXMuX3NldHRpbmdzLnNoYWRvd09mZnNldFkgKiBwcmVjaXNpb247XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd0JsdXIgPSB0aGlzLl9zZXR0aW5ncy5zaGFkb3dCbHVyICogcHJlY2lzaW9uO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gRHJhdyB0ZXh0XG4gICAgICAgIGNvbnN0IGRlZmF1bHRDb2xvciA9IFN0YWdlVXRpbHMuZ2V0UmdiYVN0cmluZyh0aGlzLl9zZXR0aW5ncy50ZXh0Q29sb3IpO1xuICAgICAgICBsZXQgY3VycmVudENvbG9yID0gZGVmYXVsdENvbG9yO1xuICAgICAgICB0aGlzLl9jb250ZXh0LmZpbGxTdHlsZSA9IGRlZmF1bHRDb2xvcjtcbiAgICAgICAgZm9yIChjb25zdCBsaW5lIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgICAgICAgIGZvciAoY29uc3QgdCBvZiBsaW5lLnRleHQpIHtcbiAgICAgICAgICAgICAgICBsZXQgbHggPSAwO1xuXG4gICAgICAgICAgICAgICAgaWYgKHQudGV4dCA9PSAnXFxuJykge1xuICAgICAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAocmVuZGVySW5mby5tYXhMaW5lcyAmJiB0LmxpbmVObyA+PSByZW5kZXJJbmZvLm1heExpbmVzKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmICh0LmNvbG9yICE9IGN1cnJlbnRDb2xvcikge1xuICAgICAgICAgICAgICAgICAgICBjdXJyZW50Q29sb3IgPSB0LmNvbG9yO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9jb250ZXh0LmZpbGxTdHlsZSA9IGN1cnJlbnRDb2xvcjtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICB0aGlzLl9jb250ZXh0LmZvbnQgPSB0LmZvbnRTdHlsZTtcblxuICAgICAgICAgICAgICAgIC8vIERyYXcgd2l0aCBsZXR0ZXIgc3BhY2luZ1xuICAgICAgICAgICAgICAgIGlmICh0LmxldHRlcnMpIHtcbiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgbCBvZiB0LmxldHRlcnMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IF94ID0gcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10ueCArIHQueCArIGx4O1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fY29udGV4dC5maWxsVGV4dChsLnRleHQsIF94LCByZW5kZXJJbmZvLmxpbmVzW3QubGluZU5vXS55ICsgcmVuZGVySW5mby5mb250U2l6ZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBseCArPSBsLndpZHRoO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgLy8gU3RhbmRhcmQgZHJhd2luZ1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IF94ID0gcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10ueCArIHQueDtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fY29udGV4dC5maWxsVGV4dCh0LnRleHQsIF94LCByZW5kZXJJbmZvLmxpbmVzW3QubGluZU5vXS55ICsgcmVuZGVySW5mby5mb250U2l6ZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxu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ICB0aGlzLnJlbmRlckluZm8gPSByZW5kZXJJbmZvO1xuXG4gICAgfTtcblxuICAgIC8qKlxuICAgICAqIFNlZSB7QGxpbmsgbWVhc3VyZVRleHR9XG4gICAgICpcbiAgICAgKiBAcGFyYW0ge3N0cmluZ30gd29yZFxuICAgICAqIEBwYXJhbSB7bnVtYmVyfSBzcGFjZVxuICAgICAqIEByZXR1cm5zIHtudW1iZXJ9XG4gICAgICovXG4gICAgbWVhc3VyZVRleHQod29yZCwgc3BhY2UgPSAwKSB7XG4gICAgICAgIHJldHVybiBtZWFzdXJlVGV4dCh0aGlzLl9jb250ZXh0LCB3b3JkLCBzcGFjZSk7XG4gICAgfVxuXG4gICAgdG9rZW5pemUodGV4dCkge1xuICAgICAgICByZXR1cm4gdG9rZW5pemVTdHJpbmcoLyB8XFx1MjAwQnxcXG58PGk+fDxcXC9pPnw8Yj58PFxcL2I+fDxjb2xvcj0wW3hYXVswLTlhLWZBLUZdezh9Pnw8XFwvY29sb3I+L2csIHRleHQpO1xuICAgIH1cblxuICAgIHBhcnNlKHRva2Vucykge1xuICAgICAgICBsZXQgaXRhbGljID0gMDtcbiAgICAgICAgbGV0IGJvbGQgPSAwO1xuICAgICAgICBsZXQgY29sb3JTdGFjayA9IFtTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcodGhpcy5fc2V0dGluZ3MudGV4dENvbG9yKV07XG4gICAgICAgIGxldCBjb2xvciA9IDA7XG5cbiAgICAgICAgY29uc3QgY29sb3JSZWdleHAgPSAvPGNvbG9yPSgwW3hYXVswLTlhLWZBLUZdezh9KT4vO1xuXG4gICAgICAgIHJldHVybiB0b2tlbnMubWFwKCh0KSA9PiB7XG4gICAgICAgICAgICBpZiAodCA9PSAnPGk+Jykge1xuICAgICAgICAgICAgICAgIGl0YWxpYyArPSAxO1xuICAgICAgICAgICAgICAgIHQgPSAnJztcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodCA9PSAnPC9pPicgJiYgaXRhbGljID4gMCkge1xuICAgICAgICAgICAgICAgIGl0YWxpYyAtPSAxO1xuICAgICAgICAgICAgICAgIHQgPSAnJztcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodCA9PSAnPGI+Jykge1xuICAgICAgICAgICAgICAgIGJvbGQgKz0gMTtcbiAgICAgICAgICAgICAgICB0ID0gJyc7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHQgPT0gJzwvYj4nICYmIGJvbGQgPiAwKSB7XG4gICAgICAgICAgICAgICAgYm9sZCAtPSAxO1xuICAgICAgICAgICAgICAgIHQgPSAnJztcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodCA9PSAnPC9jb2xvcj4nKSB7XG4gICAgICAgICAgICAgICAgaWYgKGNvbG9yU3RhY2subGVuZ3RoID4gMSkge1xuICAgICAgICAgICAgICAgICAgICBjb2xvciAtPSAxO1xuICAgICAgICAgICAgICAgICAgICBjb2xvclN0YWNrLnBvcCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0ID0gJyc7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGNvbG9yUmVnZXhwLnRlc3QodCkpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBtYXRjaGVkID0gY29sb3JSZWdleHAuZXhlYyh0KTtcbiAgICAgICAgICAgICAgICBjb2xvclN0YWNrLnB1c2goXG4gICAgICAgICAgICAgICAgICAgIFN0YWdlVXRpbHMuZ2V0UmdiYVN0cmluZyhwYXJzZUludChtYXRjaGVkWzFdKSlcbiAgICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgICAgIGNvbG9yICs9IDE7XG4gICAgICAgICAgICAgICAgdCA9ICcnO1xuXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgdGV4dDogdCxcbiAgICAgICAgICAgICAgICBpdGFsaWM6IGl0YWxpYyxcbiAgICAgICAgICAgICAgICBib2xkOiBib2xkLFxuICAgICAgICAgICAgICAgIGNvbG9yOiBjb2xvclN0YWNrW2NvbG9yXSxcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSlcbiAgICAgICAgLmZpbHRlcigobykgPT4gby50ZXh0ICE9ICcnKTtcbiAgICB9XG5cbiAgICBhcHBseUZvbnRTdHlsZSh3b3JkLCBiYXNlRm9udCkge1xuICAgICAgICBsZXQgZm9udCA9IGJhc2VGb250O1xuICAgICAgICBpZiAod29yZC5ib2xkKSB7XG4gICAgICAgICAgICBmb250ID0gJ2JvbGQgJyArIGZvbnQ7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHdvcmQuaXRhbGljKSB7XG4gICAgICAgICAgICBmb250ID0gJ2l0YWxpYyAnICsgZm9udDtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9jb250ZXh0LmZvbnQgPSBmb250XG4gICAgICAgIHdvcmQuZm9udFN0eWxlID0gZm9udDtcbiAgICB9XG5cbiAgICByZXNldEZvbnRTdHlsZShiYXNlRm9udCkge1xuICAgICAgICB0aGlzLl9jb250ZXh0LmZvbnQgPSBiYXNlRm9udDtcbiAgICB9XG5cbiAgICBtZWFzdXJlKHBhcnNlZCwgbGV0dGVyU3BhY2luZyA9IDAsIGJhc2VGb250KSB7XG4gICAgICAgIGZvciAoY29uc3QgcCBvZiBwYXJzZWQpIHtcbiAgICAgICAgICAgIHRoaXMuYXBwbHlGb250U3R5bGUocCwgYmFzZUZvbnQpO1xuICAgICAgICAgICAgcC53aWR0aCA9IHRoaXMubWVhc3VyZVRleHQocC50ZXh0LCBsZXR0ZXJTcGFjaW5nKTtcblxuICAgICAgICAgICAgLy8gTGV0dGVyIGJ5IGxldHRlciBkZXRhaWwgZm9yIGxldHRlciBzcGFjaW5nXG4gICAgICAgICAgICBpZiAobGV0dGVyU3BhY2luZyA+IDApIHtcbiAgICAgICAgICAgICAgICBwLmxldHRlcnMgPSBwLnRleHQuc3BsaXQoJycpLm1hcCgobCkgPT4ge3JldHVybiB7dGV4dDogbH19KTtcbiAgICAgICAgICAgICAgICBmb3Ig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tcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAvLyBGaW5hbGx5LCB3aGVuIGJvdW5kIGlzIGNyb3NzZWQsIHJldHJhY3QgbGFzdCBsZXR0ZXIuXG4gICAgICAgICAgICAgICAgICAgIGN1dG9mZkluZGV4IC09MTtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgLyogSWYgd3JhcFdpZHRoIGlzIHRvbyBzaG9ydCB0byBldmVuIGNvbnRhaW4gc3VmZml4IGFsb25lLCByZXR1cm4gZW1wdHkgc3RyaW5nICovXG4gICAgICAgIHJldHVybiB3b3JkLnN1YnN0cmluZygwLCBjdXRvZmZJbmRleCkgKyAod29yZFdyYXBXaWR0aCA+PSBzdWZmaXhXaWR0aCA/IHN1ZmZpeCA6ICcnKVxuICAgIH1cblxuICAgIF9nZXRCcmVha0luZGV4KHdvcmQsIHdpZHRoKSB7XG4gICAgICAgIGNvbnN0IHdvcmRMZW4gPSB3b3JkLmxlbmd0aDtcbiAgICAgICAgY29uc3Qgd29yZFdpZHRoID0gdGhpcy5tZWFzdXJlVGV4dCh3b3JkKTtcblxuICAgICAgICBpZiAod29yZFdpZHRoIDw9IHdpZHRoKSB7XG4gICAgICAgICAgICByZXR1cm4ge2JyZWFrSW5kZXg6IHdvcmQubGVuZ3RoLCB0cnVuY1dvcmRXaWR0aDogd29yZFdpZHRofTtcbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBicmVha0luZGV4ID0gTWF0aC5mbG9vcigod2lkdGggKiB3b3JkTGVuKSAvIHdvcmRXaWR0aCk7XG4gICAgICAgIGxldCB0cnVuY1dvcmRXaWR0aCA9IHRoaXMubWVhc3VyZVRleHQod29yZC5zdWJzdHJpbmcoMCwgYnJlYWtJbmRleCkpXG5cbiAgICAgICAgLyogSW4gY2FzZSBndWVzcyB3YXMgb3ZlcmVzdGltYXRlZCwgc2hyaW5rIGl0IGxldHRlciBieSBsZXR0ZXIuICovXG4gICAgICAgIGlmICh0cnVuY1dvcmRXaWR0aCA+IHdpZHRoKSB7XG4gICAgICAgICAgICB3aGlsZSAoYnJlYWtJbmRleCA+IDApIHtcbiAgICAgICAgICAgICAgICB0cnVuY1dvcmRXaWR0aCA9IHRoaXMubWVhc3VyZVRleHQod29yZC5zdWJzdHJpbmcoMCwgYnJlYWtJbmRleCkpO1xuICAgICAgICAgICAgICAgIGlmICh0cnVuY1dvcmRXaWR0aCA+IHdpZHRoKSB7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrSW5kZXggLT0gMTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgLyogSW4gY2FzZSBndWVzcyB3YXMgdW5kZXJlc3RpbWF0ZWQsIGV4dGVuZCBpdCBsZXR0ZXIgYnkgbGV0dGVyLiAqL1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgd2hpbGUgKGJyZWFrSW5kZXggPCB3b3JkTGVuKSB7XG4gICAgICAgICAgICAgICAgdHJ1bmNXb3JkV2lkdGggPSB0aGlzLm1lYXN1cmVUZXh0KHdvcmQuc3Vic3RyaW5nKDAsIGJyZWFrSW5kZXgpKTtcbiAgICAgICAgICAgICAgICBpZiAodHJ1bmNXb3JkV2lkdGggPCB3aWR0aCkge1xuICAgICAgICAgICAgICAgICAgICBicmVha0luZGV4ICs9IDE7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gRmluYWxseSwgd2hlbiBib3VuZCBpcyBjcm9zc2VkLCByZXRyYWN0IGxhc3QgbGV0dGVyLlxuICAgICAgICAgICAgICAgICAgICBicmVha0luZGV4IC09MTtcbiAgICAgICAgICAgICAgICAgICAgdHJ1bmNXb3JkV2lkdGggPSB0aGlzLm1lYXN1cmVUZXh0KHdvcmQuc3Vic3RyaW5nKDAsIGJyZWFrSW5kZXgpKTtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiB7YnJlYWtJbmRleCwgdHJ1bmNXb3JkV2lkdGh9O1xuXG4gICAgfVxuXG4gICAgd29yZEJyZWFrKHdvcmQsIHdpZHRoLCBiYXNlRm9udCkge1xuICAgICAgICBpZiAoIXdvcmQudGV4dCkge1xuICAgICAgICAgICAgcmV0dXJuIHdvcmRcbiAgICAgICAgfVxuICAgICAgICB0aGlzLmFwcGx5Rm9udFN0eWxlKHdvcmQsIGJhc2VGb250KVxuICAgICAgICBjb25zdCBwYXJ0cyA9IFtdO1xuICAgICAgICBsZXQgdGV4dCA9IHdvcmQudGV4dDtcbiAgICAgICAgaWYgKCF3b3JkLmxldHRlcnMpIHtcbiAgICAgICAgICAgIHdoaWxlICh0cnVlKSB7XG4gICAgICAgICAgICAgICAgY29uc3Qge2JyZWFrSW5kZXgsIHRydW5jV29yZFdpZHRofSA9IHRoaXMuX2dldEJyZWFrSW5kZXgodGV4dCwgd2lkdGgpO1xuICAgICAgICAgICAgICAgIHBhcnRzLnB1c2goey4uLndvcmR9KTtcbiAgICAgICAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS50ZXh0ID0gdGV4dC5zbGljZSgwLCBicmVha0luZGV4KTtcbiAgICAgICAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS53aWR0aCA9IHRydW5jV29yZFdpZHRoO1xuXG4gICAgICAgICAgICAgICAgaWYgKGJyZWFrSW5kZXggPT09IHRleHQubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIHRleHQgPSB0ZXh0LnNsaWNlKGJyZWFrSW5kZXgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbGV0IHRvdGFsV2lkdGggPSAwO1xuICAgICAgICAgICAgbGV0IGxldHRlcnMgPSBbXTtcbiAgICAgICAgICAgIGxldCBicmVha0luZGV4ID0gMDtcbiAgICAgICAgICAgIGZvciAoY29uc3QgbCBvZiB3b3JkLmxldHRlcnMpIHtcbiAgICAgICAgICAgICAgICBpZiAodG90YWxXaWR0aCArIGwud2lkdGggPj0gd2lkdGgpIHtcbiAgICAgICAgICAgICAgICAgICAgcGFydHMucHVzaCh7Li4ud29yZH0pO1xuICAgICAgICAgICAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS50ZXh0ID0gdGV4dC5zbGljZSgwLCBicmVha0luZGV4KTtcbiAgICAgICAgICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ud2lkdGggPSB0b3RhbFdpZHRoO1xuICAgICAgICAgICAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS5sZXR0ZXJzID0gbGV0dGVycztcbiAgICAgICAgICAgICAgICAgICAgdGV4dCA9IHRleHQuc2xpY2UoYnJlYWtJbmRleCk7XG4gICAgICAgICAgICAgICAgICAgIHRvdGFsV2lkdGggPSAwO1xuICAgICAgICAgICAgICAgICAgICBsZXR0ZXJzID0gW107XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrSW5kZXggPSAwO1xuXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWtJbmRleCArPSAxO1xuICAgICAgICAgICAgICAgICAgICBsZXR0ZXJzLnB1c2gobCk7XG4gICAgICAgICAgICAgICAgICAgIHRvdGFsV2lkdGggKz0gbC53aWR0aDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0b3RhbFdpZHRoID4gMCkge1xuICAgICAgICAgICAgICAgIHBhcnRzLnB1c2goey4uLndvcmR9KTtcbiAgICAgICAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS50ZXh0ID0gdGV4dC5zbGljZSgwLCBicmVha0luZGV4KTtcbiAgICAgICAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS53aWR0aCA9IHRvdGFsV2lkdGg7XG4gICAgICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ubGV0dGVycyA9IGxldHRlcnM7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gcGFydHM7XG4gICAgfVxuXG4gICAgYWxpZ25MaW5lKHBhcnNlZCwgaW5pdGlhbFggPSAwKSB7XG4gICAgICAgIGxldCBwcmV2V2lkdGggPSAwO1xuICAgICAgICBsZXQgcHJldlggPSBpbml0aWFsWDtcbiAgICAgICAgZm9yIChjb25zdCB3b3JkIG9mIHBhcnNlZCkge1xuICAgICAgICAgICAgaWYgKHdvcmQudGV4dCA9PSAnXFxuJykge1xuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgd29yZC54ID0gcHJldlggKyBwcmV2V2lkdGg7XG4gICAgICAgICAgICBwcmV2WCA9IHdvcmQueDtcbiAgICAgICAgICAgIHByZXZXaWR0aCA9IHdvcmQud2lkdGg7XG4gICAgICAgIH1cblxuICAgIH1cbn0iLCIvKlxuICogSWYgbm90IHN0YXRlZCBvdGhlcndpc2UgaW4gdGhpcyBmaWxlIG9yIHRoaXMgY29tcG9uZW50J3MgTElDRU5TRSBmaWxlIHRoZVxuICogZm9sbG93aW5nIGNvcHlyaWdodCBhbmQgbGljZW5zZXMgYXBwbHk6XG4gKlxuICogQ29weXJpZ2h0IDIwMjAgTWV0cm9sb2dpY2FsXG4gKlxuICogTGljZW5zZWQgdW5kZXIgdGhlIEFwYWNoZSBMaWNlbnNlLCBWZXJzaW9uIDIuMCAodGhlIExpY2Vuc2UpO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dCkge1xuICAgICAgICAgICAgICAgIC8vIFNraXAgcHJpbnRpbmcgdGhlIG5ld2xpbmUgaWYgaXQncyB0aGUgZmlyc3Qgd29yZCBvZiB0aGUgbGluZSB0aGF0IGlzLlxuICAgICAgICAgICAgICAgIC8vIGdyZWF0ZXIgdGhhbiB0aGUgd29yZCB3cmFwIHdpZHRoLlxuICAgICAgICAgICAgICAgIGlmIChqID4gMCkge1xuICAgICAgICAgICAgICAgICAgICByZXN1bHRMaW5lcy5wdXNoKHJlc3VsdCk7XG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9ICcnO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXN1bHQgKz0gd29yZDtcbiAgICAgICAgICAgICAgICBzcGFjZUxlZnQgPSB3b3JkV3JhcFdpZHRoIC0gd29yZFdpZHRoIC0gKGogPT09IDAgPyBpbmRlbnQgOiAwKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgIHNwYWNlTGVmdCAtPSB3b3JkV2lkdGhXaXRoU3BhY2U7XG4gICAgICAgICAgICAgICAgcmVzdWx0ICs9IHNwYWNlICsgd29yZDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXN1bHRMaW5lcy5wdXNoKHJlc3VsdCk7XG4gICAgICAgIHJlc3VsdCA9ICcnO1xuICAgICAgICBhbGxMaW5lcyA9IGFsbExpbmVzLmNvbmNhdChyZXN1bHRMaW5lcyk7XG4gICAgICAgIGlmIChpIDwgbGluZXMubGVuZ3RoIC0gMSkge1xuICAgICAgICAgICAgcmVhbE5ld2xpbmVzLnB1c2goYWxsTGluZXMubGVuZ3RoKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4geyBsOiBhbGxMaW5lcywgbjogcmVhbE5ld2xpbmVzIH07XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1UZXh0VGV4dHVyZVJlbmRlcmVyVXRpbHMubW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GRlZmF1bHQgY2xhc3MgTXVsdGlTcGxpbmUge1xuXG4gICAgY29uc3RydWN0b3IoKSB7XG4gICAgICAgIHRoaXMuX2NsZWFyKCk7XG4gICAgfVxuXG4gICAgX2NsZWFyKCkge1xuICAgICAgICB0aGlzLl9wID0gW107XG4gICAgICAgIHRoaXMuX3BlID0gW107XG4gICAgICAgIHRoaXMuX2lkcCA9IFtdO1xuICAgICAgICB0aGlzLl9mID0gW107XG4gICAgICAgIHRoaXMuX3YgPSBbXTtcbiAgICAgICAgdGhpcy5fbHYgPSBbXTtcbiAgICAgICAgdGhpcy5fc20gPSBbXTtcbiAgICAgICAgdGhpcy5fcyA9IFtdO1xuICAgICAgICB0aGlzLl92ZSA9IFtdO1xuICAgICAgICB0aGlzLl9zbWUgPSBbXTtcbiAgICAgICAgdGhpcy5fc2UgPSBbXTtcblxuICAgICAgICB0aGlzLl9sZW5ndGggPSAwO1xuICAgIH1cblxuICAgIHBhcnNlKHJnYmEsIGRlZikge1xuICAgICAgICBsZXQgaSwgbjtcbiAgICAgICAgaWYgKCFVdGlscy5pc09iamVjdExpdGVyYWwoZGVmKSkge1xuICAgICAgICAgICAgZGVmID0gezA6IGRlZn1cbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBkZWZhdWx0U21vb3RobmVzcyA9IDAuNTtcblxuICAgICAgICBsZXQgaXRlbXMgPSBbXTtcbiAgICAgICAgZm9yIChsZXQga2V5IGluIGRlZikge1xuICAgICAgICAgICAgaWYgKGRlZi5oYXNPd25Qcm9wZXJ0eShrZXkpKSB7XG4gICAgICAgICAgICAgICAgbGV0IG9iaiA9IGRlZltrZXldO1xuICAgICAgICAgICAgICAgIGlmICghVXRpbHMuaXNPYmplY3RMaXRlcmFsKG9iaikpIHtcbiAgICAgICAgICAgICAgICAgICAgb2JqID0ge3Y6IG9ian1cbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBsZXQgcCA9IHBhcnNlRmxvYXQoa2V5KTtcblxuICAgICAgICAgICAgICAgIGlmIChrZXkgPT09IFwic21cIikge1xuICAgICAgICAgICAgICAgICAgICBkZWZhdWx0U21vb3RobmVzcyA9IG9iai52O1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoIWlzTmFOKHApICYmIHAgPj0gMCAmJiBwIDw9IDIpIHtcbiAgICAgICAgICAgICAgICAgICAgb2JqLnAgPSBwO1xuXG4gICAgICAgICAgICAgICAgICAgIG9iai5mID0gVXRpbHMuaXNGdW5jdGlvbihvYmoudik7XG4gICAgICAgICAgICAgICAgICAgIG9iai5sdiA9IG9iai5mID8gb2JqLnYoMCwgMCkgOiBvYmoudjtcblxuICAgICAgICAgICAgICAgICAgICBpdGVtcy5wdXNoKG9iaik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgLy8gU29ydCBieSBwcm9ncmVzcyB2YWx1ZS5cbiAgICAgICAgaXRlbXMgPSBpdGVtcy5zb3J0KGZ1bmN0aW9uKGEsIGIpIHtyZXR1cm4gYS5wIC0gYi5wfSk7XG5cbiAgICAgICAgbiA9IGl0ZW1zLmxlbmd0aDtcblxuICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBsZXQgbGFzdCA9IChpID09PSBuIC0gMSk7XG4gICAgICAgICAgICBpZiAoIWl0ZW1zW2ldLmhhc093blByb3BlcnR5KCdwZScpKSB7XG4gICAgICAgICAgICAgICAgLy8gUHJvZ3Jlc3MuXG4gICAgICAgICAgICAgICAgaXRlbXNbaV0ucGUgPSBsYXN0ID8gKGl0ZW1zW2ldLnAgPD0gMSA/IDEgOiAyIC8qIHN1cHBvcnQgb25ldG90d28gc3RvcCAqLykgOiBpdGVtc1tpICsgMV0ucDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gUHJldmVudCBtdWx0aXBsZSBpdGVtcyBhdCB0aGUgc2FtZSB0aW1lLlxuICAgICAgICAgICAgICAgIGNvbnN0IG1heCA9IGkgPCBuIC0gMSA/IGl0ZW1zW2kgKyAxXS5wIDogMTtcbiAgICAgICAgICAgICAgICBpZiAoaXRlbXNbaV0ucGUgPiBtYXgpIHtcbiAgICAgICAgICAgICAgICAgICAgaXRlbXNbaV0ucGUgPSBtYXg7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKGl0ZW1zW2ldLnBlID09PSBpdGVtc1tpXS5wKSB7XG4gICAgICAgICAgICAgICAgaXRlbXNbaV0uaWRwID0gMDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaXRlbXNbaV0uaWRwID0gMSAvIChpdGVtc1tpXS5wZSAtIGl0ZW1zW2ldLnApO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgLy8gQ29sb3IgbWVyZ2VyOiB3ZSBuZWVkIHRvIHNwbGl0L2NvbWJpbmUgUkdCQSBjb21wb25lbnRzLlxuXG4gICAgICAgIC8vIENhbGN1bGF0ZSBiZXppZXIgaGVscGVyIHZhbHVlcy47XG4gICAgICAgIGZvciAoaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoJ3NtJykpIHtcbiAgICAgICAgICAgICAgICAvLyBTbW9vdGhuZXNzLjtcbiAgICAgICAgICAgICAgICBpdGVtc1tpXS5zbSA9IGRlZmF1bHRTbW9vdGhuZXNzO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKCFpdGVtc1tpXS5oYXNPd25Qcm9wZXJ0eSgncycpKSB7XG4gICAgICAgICAgICAgICAgLy8gU2xvcGUuO1xuICAgICAgICAgICAgICAgIGlmIChpID09PSAwIHx8IGkgPT09IG4gLSAxIHx8IChpdGVtc1tpXS5wID09PSAxIC8qIGZvciBvbmV0b3R3byAqLykpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gSG9yaXpvbnRhbCBzbG9wZSBhdCBzdGFydCBhbmQgZW5kLjtcbiAgICAgICAgICAgICAgICAgICAgaXRlbXNbaV0ucyA9IHJnYmEgPyBbMCwgMCwgMCwgMF0gOiAwO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHBpID0gaXRlbXNbaSAtIDFdO1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBuaSA9IGl0ZW1zW2kgKyAxXTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHBpLnAgPT09IG5pLnApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGl0ZW1zW2ldLnMgPSByZ2JhID8gWzAsIDAsIDAsIDBdIDogMDtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZ2JhKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgbmMgPSBNdWx0aVNwbGluZS5nZXRSZ2JhQ29tcG9uZW50cyhuaS5sdik7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgcGMgPSBNdWx0aVNwbGluZS5nZXRSZ2JhQ29tcG9uZW50cyhwaS5sdik7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgZCA9IDEgLyAobmkucCAtIHBpLnApO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGl0ZW1zW2ldLnMgPSBbXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGQgKiAobmNbMF0gLSBwY1swXSksXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGQgKiAobmNbMV0gLSBwY1sxXSksXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGQgKiAobmNbMl0gLSBwY1syXSksXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGQgKiAobmNbM10gLSBwY1szXSlcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBdO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpdGVtc1tpXS5zID0gKG5pLmx2IC0gcGkubHYpIC8gKG5pLnAgLSBwaS5wKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGZvciAoaSA9IDA7IGkgPCBuIC0gMTsgaSsrKSB7XG4gICAgICAgICAgICAvLyBDYWxjdWxhdGUgdmFsdWUgZnVuY3Rpb24uO1xuICAgICAgICAgICAgaWYgKCFpdGVtc1tpXS5mKSB7XG5cbiAgICAgICAgICAgICAgICBsZXQgbGFzdCA9IChpID09PSBuIC0gMSk7XG4gICAgICAgICAgICAgICAgaWYgKCFpdGVtc1tpXS5oYXNPd25Qcm9wZXJ0eSgndmUnKSkge1xuICAgICAgICAgICAgICAgICAgICBpdGVtc1tpXS52ZSA9IGxhc3QgPyBpdGVtc1tpXS5sdiA6IGl0ZW1zW2kgKyAxXS5sdjtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAvLyBXZSBjYW4gb25seSBpbnRlcnBvbGF0ZSBvbiBudW1lcmljIHZhbHVlcy4gTm9uLW51bWVyaWMgdmFsdWVzIGFyZSBzZXQgbGl0ZXJhbGx5IHdoZW4gcmVhY2hlZCB0aW1lLlxuICAgICAgICAgICAgICAgIGlmIChVdGlscy5pc051bWJlcihpdGVtc1tpXS52KSAmJiBVdGlscy5pc051bWJlcihpdGVtc1tpXS5sdikpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFpdGVtc1tpXS5oYXNPd25Qcm9wZXJ0eSgnc21lJykpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGl0ZW1zW2ldLnNtZSA9IGxhc3QgPyBkZWZhdWx0U21vb3RobmVzcyA6IGl0ZW1zW2kgKyAxXS5zbTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBpZiAoIWl0ZW1zW2ldLmhhc093blByb3BlcnR5KCdzZScpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpdGVtc1tpXS5zZSA9IGxhc3QgPyAocmdiYSA/IFswLCAwLCAwLCAwXSA6IDApIDogaXRlbXNbaSArIDFdLnM7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICAvLyBHZW5lcmF0ZSBzcGxpbmUuO1xuICAgICAgICAgICAgICAgICAgICBpZiAocmdiYSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaXRlbXNbaV0udiA9IE11bHRpU3BsaW5lLmdldFNwbGluZVJnYmFWYWx1ZUZ1bmN0aW9uKGl0ZW1zW2ldLnYsIGl0ZW1zW2ldLnZlLCBpdGVtc1tpXS5wLCBpdGVtc1tpXS5wZSwgaXRlbXNbaV0uc20sIGl0ZW1zW2ldLnNtZSwgaXRlbXNbaV0ucywgaXRlbXNbaV0uc2UpO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgaXRlbXNbaV0udiA9IE11bHRpU3BsaW5lLmdldFNwbGluZVZhbHVlRnVuY3Rpb24oaXRlbXNbaV0udiwgaXRlbXNbaV0udmUsIGl0ZW1zW2ldLnAsIGl0ZW1zW2ldLnBlLCBpdGVtc1tpXS5zbSwgaXRlbXNbaV0uc21lLCBpdGVtc1tpXS5zLCBpdGVtc1tpXS5zZSk7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICBpdGVtc1tpXS5mID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5sZW5ndGgpIHtcbiAgICAgICAgICAgIHRoaXMuX2NsZWFyKCk7XG4gICAgICAgIH1cblxuICAgICAgICB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xuICAgICAgICAgICAgaWYgKHRoaXMuX3BbaV0gPD0gcCAmJiBwIDwgdGhpcy5fcGVbaV0pIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gaTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiBuIC0gMTtcbiAgICB9XG5cbiAgICBnZXRWYWx1ZShwKSB7XG4gICAgICAgIGNvbnN0IGkgPSB0aGlzLl9nZXRJdGVtKHApO1xuICAgICAgICBpZiAoaSA9PT0gLTEpIHtcbiAgICAgICAgICAgIHJldHVybiB1bmRlZmluZWQ7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fZltpXSkge1xuICAgICAgICAgICAgICAgIGNvbnN0IG8gPSBNYXRoLm1pbigxLCBNYXRoLm1heCgwLCAocCAtIHRoaXMuX3BbaV0pICogdGhpcy5faWRwW2ldKSk7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3ZbaV0obyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLl92W2ldO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGxlbmd0aCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2xlbmd0aDtcbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0UmdiYUNvbXBvbmVudHMoYXJnYikge1xuICAgICAgICBsZXQgciA9ICgoYXJnYiAvIDY1NTM2KSB8IDApICUgMjU2O1xuICAgICAgICBsZXQgZyA9ICgoYXJnYiAvIDI1NikgfCAwKSAlIDI1NjtcbiAgICAgICAgbGV0IGIgPSBhcmdiICUgMjU2O1xuICAgICAgICBsZXQgYSA9ICgoYXJnYiAvIDE2Nzc3MjE2KSB8IDApO1xuICAgICAgICByZXR1cm4gW3IsIGcsIGIsIGFdO1xuICAgIH07XG5cbiAgICBzdGF0aWMgZ2V0U3BsaW5lVmFsdWVGdW5jdGlvbih2MSwgdjIsIHAxLCBwMiwgbzEsIGkyLCBzMSwgczIpIHtcbiAgICAgICAgLy8gTm9ybWFsaXplIHNsb3BlcyBiZWNhdXNlIHdlIHVzZSBhIHNwbGluZSB0aGF0IGdvZXMgZnJvbSAwIHRvIDEuXG4gICAgICAgIGxldCBkcCA9IHAyIC0gcDE7XG4gICAgICAgIHMxICo9IGRwO1xuICAgICAgICBzMiAqPSBkcDtcblxuICAgICAgICBsZXQgaGVscGVycyA9IE11bHRpU3BsaW5lLmdldFNwbGluZUhlbHBlcnModjEsIHYyLCBvMSwgaTIsIHMxLCBzMik7XG4gICAgICAgIGlmICghaGVscGVycykge1xuICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIChwKSB7XG4gICAgICAgICAgICAgICAgaWYgKHAgPT09IDApIHJldHVybiB2MTtcbiAgICAgICAgICAgICAgICBpZiAocCA9PT0gMSkgcmV0dXJuIHYyO1xuXG4gICAgICAgICAgICAgICAgcmV0dXJuIHYyICogcCArIHYxICogKDEgLSBwKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24gKHApIHtcbiAgICAgICAgICAgICAgICBpZiAocCA9PT0gMCkgcmV0dXJuIHYxO1xuICAgICAgICAgICAgICAgIGlmIChwID09PSAxKSByZXR1cm4gdjI7XG4gICAgICAgICAgICAgICAgcmV0dXJuIE11bHRpU3BsaW5lLmNhbGN1bGF0ZVNwbGluZShoZWxwZXJzLCBwKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgc3RhdGljIGdldFNwbGluZVJnYmFWYWx1ZUZ1bmN0aW9uKHYxLCB2MiwgcDEsIHAyLCBvMSwgaTIsIHMxLCBzMikge1xuICAgICAgICAvLyBOb3JtYWxpemUgc2xvcGVzIGJlY2F1c2Ugd2UgdXNlIGEgc3BsaW5lIHRoYXQgZ29lcyBmcm9tIDAgdG8gMS5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1cm4gdjI7XG5cbiAgICAgICAgICAgICAgICByZXR1cm4gTXVsdGlTcGxpbmUubWVyZ2VDb2xvcnModjIsIHYxLCBwKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24gKHApIHtcbiAgICAgICAgICAgICAgICBpZiAocCA9PT0gMCkgcmV0dXJuIHYxO1xuICAgICAgICAgICAgICAgIGlmIChwID09PSAxKSByZXR1cm4gdjI7XG5cbiAgICAgICAgICAgICAgICByZXR1cm4gTXVsdGlTcGxpbmUuZ2V0QXJnYk51bWJlcihbXG4gICAgICAgICAgICAgICAgICAgIE1hdGgubWluKDI1NSwgTXVsdGlTcGxpbmUuY2FsY3VsYXRlU3BsaW5lKGhlbHBlcnNbMF0sIHApKSxcbiAgICAgICAgICAgICAgICAgICAgTWF0aC5taW4oMjU1LCBNdWx0aVNwbGluZS5jYWxjdWxhdGVTcGxpbmUoaGVscGVyc1sxXSwgcCkpLFxuICAgICAgICAgICAgICAgICAgICBNYXRoLm1pbigyNTUsIE11bHRpU3BsaW5lLmNhbGN1bGF0ZVNwbGluZShoZWxwZXJzWzJdLCBwKSksXG4gICAgICAgICAgICAgICAgICAgIE1hdGgubWluKDI1NSwgTXVsdGlTcGxpbmUuY2FsY3VsYXRlU3BsaW5lKGhlbHBlcnNbM10sIHApKVxuICAgICAgICAgICAgICAgIF0pO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgfVxuXG4gICAgfTtcblxuICAgIC8qKlxuICAgICAqIENyZWF0ZXMgaGVscGVycyB0byBiZSB1c2VkIGluIHRoZSBzcGxpbmUgZnVuY3Rpb24uXG4gICAgICogQHBhcmFtIHtudW1iZXJ9IHYxXG4gICAgICogICBGcm9tIHZhbHVlLlxuICAgICAqIEBwYXJhbSB7bnVtYmVyfSB2MlxuICAgICAqICAgVG8gdmFsdWUuXG4gICAgICogQHBhcmFtIHtudW1iZXJ9IG8xXG4gICAgICogICBGcm9tIHNtb290aG5lc3MgKDAgPSBsaW5lYXIsIDEgPSBzbW9vdGgpLlxuICAgICAqIEBwYXJhbSB7bnVtYmVyfSBzMVxuICAgICAqICAgRnJvbSBzbG9wZSAoMCA9IGhvcml6b250YWwsIGluZmluaXRlID0gdmVydGljYWwpLlxuICAgICAqIEBwYXJhbSB7bnVtYmVyfSBpMlxuICAgICAqICAgVG8gc21vb3RobmVzcy5cbiAgICAgKiBAcGFyYW0ge251bWJlcn0gczJcbiAgICAgKiAgIFRvIHNsb3BlLlxuICAgICAqIEByZXR1cm5zIHtOdW1iZXJbXX1cbiAgICAgKiAgIFRoZSBoZWxwZXIgdmFsdWVzIHRvIGJlIHN1cHBsaWVkIHRvIHRoZSBzcGxpbmUgZnVuY3Rpb24uXG4gICAgICogICBJZiB0aGUgY29uZmlndXJhdGlvbiBpcyBhY3R1YWxseSBsaW5lYXIsIG51bGwgaXMgcmV0dXJuZWQuXG4gICAgICovXG4gICAgc3RhdGljIGdldFNwbGluZUhlbHBlcnModjEsIHYyLCBvMSwgaTIsIHMxLCBzMikge1xuICAgICAgICBpZiAoIW8xICYmICFpMikge1xuICAgICAgICAgICAgLy8gTGluZWFyLlxuICAgICAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBDdWJpYyBiZXppZXIgcG9pbnRzLlxuICAgICAgICAvLyBodHRwOi8vY3ViaWMtYmV6aWVyLmNvbS9cbiAgICAgICAgbGV0IGNzeCA9IG8xO1xuICAgICAgICBsZXQgY3N5ID0gdjEgKyBzMSAqIG8xO1xuICAgICAgICBsZXQgY2V4ID0gMSAtIGkyO1xuICAgICAgICBsZXQgY2V5ID0gdjIgLSBzMiAqIGkyO1xuXG4gICAgICAgIGxldCB4YSA9IDMgKiBjc3ggLSAzICogY2V4ICsgMTtcbiAgICAgICAgbGV0IHhiID0gLTYgKiBjc3ggKyAzICogY2V4O1xuICAgICAgICBsZXQgeGMgPSAzICogY3N4O1xuXG4gICAgICAgIGxldCB5YSA9IDMgKiBjc3kgLSAzICogY2V5ICsgdjIgLSB2MTtcbiAgICAgICAgbGV0IHliID0gMyAqIChjZXkgKyB2MSkgLSA2ICogY3N5O1xuICAgICAgICBsZXQgeWMgPSAzICogKGNzeSAtIHYxKTtcbiAgICAgICAgbGV0IHlkID0gdjE7XG5cbiAgICAgICAgcmV0dXJuIFt4YSwgeGIsIHhjLCB5YSwgeWIsIHljLCB5ZF07XG4gICAgfTtcblxuICAgIC8qKlxuICAgICAqIENhbGN1bGF0ZXMgdGhlIGludGVybWVkaWF0ZSBzcGxpbmUgdmFsdWUgYmFzZWQgb24gdGhlIHNwZWNpZmllZCBoZWxwZXJzLlxuICAgICAqIEBwYXJhbSB7bnVtYmVyW119IGhlbHBlcnNcbiAgICAgKiAgIE9idGFpbmVkIGZyb20gZ2V0U3BsaW5lSGVscGVycy5cbiAgICAgKiBAcGFyYW0ge251bWJlcn0gcFxuICAgICAqIEByZXR1cm4ge251bWJlcn1cbiAgICAgKi9cbiAgICBzdGF0aWMgY2FsY3VsYXRlU3BsaW5lKGhlbHBlcnMsIHApIHtcbiAgICAgICAgbGV0IHhhID0gaGVscGVyc1swXTtcbiAgICAgICAgbGV0IHhiID0gaGVscGVyc1sxXTtcbiAgICAgICAgbGV0IHhjID0gaGVscGVyc1syXTtcbiAgICAgICAgbGV0IHlhID0gaGVscGVyc1szXTtcbiAgICAgICAgbGV0IHliID0gaGVscGVyc1s0XTtcbiAgICAgICAgbGV0IHljID0gaGVscGVyc1s1XTtcbiAgICAgICAgbGV0IHlkID0gaGVscGVyc1s2XTtcblxuICAgICAgICBpZiAoeGEgPT09IC0yICYmIHlhID09PSAtMiAmJiB4YyA9PT0gMCAmJiB5YyA9PT0gMCkge1xuICAgICAgICAgICAgLy8gTGluZWFyLlxuICAgICAgICAgICAgcmV0dXJuIHA7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBGaW5kIHQgZm9yIHAuXG4gICAgICAgIGxldCB0ID0gMC41LCBjYngsIGR4O1xuXG4gICAgICAgIGZvciAobGV0IGl0ID0gMDsgaXQgPCAyMDsgaXQrKykge1xuICAgICAgICAgICAgLy8gQ3ViaWMgYmV6aWVyIGZ1bmN0aW9uOiBmKHQpPXQqKHQqKHQqYStiKStjKS5cbiAgICAgICAgICAgIGNieCA9IHQgKiAodCAqICh0ICogeGEgKyB4YikgKyB4Yyk7XG5cbiAgICAgICAgICAgIGR4ID0gcCAtIGNieDtcbiAgICAgICAgICAgIGlmIChkeCA+IC0xZS04ICYmIGR4IDwgMWUtOCkge1xuICAgICAgICAgICAgICAgIC8vIFNvbHV0aW9uIGZvdW5kIVxuICAgICAgICAgICAgICAgIHJldHVybiB0ICogKHQgKiAodCAqIHlhICsgeWIpICsgeWMpICsgeWQ7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIEN1YmljIGJlemllciBkZXJpdmF0aXZlIGZ1bmN0aW9uOiBmJyh0KT10Kih0KigzKmEpKzIqYikrY1xuICAgICAgICAgICAgbGV0IGNieGQgPSB0ICogKHQgKiAoMyAqIHhhKSArIDIgKiB4YikgKyB4YztcblxuICAgICAgICAgICAgaWYgKGNieGQgPiAxZS0xMCAmJiBjYnhkIDwgMWUtMTApIHtcbiAgICAgICAgICAgICAgICAvLyBQcm9ibGVtYXRpYy4gRmFsbCBiYWNrIHRvIGJpbmFyeSBzZWFyY2ggbWV0aG9kLlxuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0ICs9IGR4IC8gY2J4ZDtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEZhbGxiYWNrOiBiaW5hcnkgc2VhcmNoIG1ldGhvZC4gVGhpcyBpcyBtb3JlIHJlbGlhYmxlIHdoZW4gdGhlcmUgYXJlIG5lYXItMCBzbG9wZXMuXG4gICAgICAgIGxldCBtaW5UID0gMDtcbiAgICAgICAgbGV0IG1heFQgPSAxO1xuICAgICAgICBmb3IgKGxldCBpdCA9IDA7IGl0IDwgMjA7IGl0KyspIHtcbiAgICAgICAgICAgIHQgPSAwLjUgKiAobWluVCArIG1heFQpO1xuXG4gICAgICAgICAgICAvLyBDdWJpYyBiZXppZXIgZnVuY3Rpb246IGYodCk9dCoodCoodCphK2IpK2MpK2QuXG4gICAgICAgICAgICBjYnggPSB0ICogKHQgKiAodCAqIHhhICsgeGIpICsgeGMpO1xuXG4gICAgICAgICAgICBkeCA9IHAgLSBjYng7XG4gICAgICAgICAgICBpZiAoZHggPiAtMWUtOCAmJiBkeCA8IDFlLTgpIHtcbiAgICAgICAgICAgICAgICAvLyBTb2x1dGlvbiBmb3VuZCFcbiAgICAgICAgICAgICAgICByZXR1cm4gdCAqICh0ICogKHQgKiB5YSArIHliKSArIHljKSArIHlkO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoZHggPCAwKSB7XG4gICAgICAgICAgICAgICAgbWF4VCA9IHQ7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIG1pblQgPSB0O1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIHQ7XG4gICAgfTtcblxuICAgIHN0YXRpYyBtZXJnZUNvbG9ycyhjMSwgYzIsIHApIHtcbiAgICAgICAgbGV0IHIxID0gKChjMSAvIDY1NTM2KSB8IDApICUgMjU2O1xuICAgICAgICBsZXQgZzEgPSAoKGMxIC8gMjU2KSB8IDApICUgMjU2O1xuICAgICAgICBsZXQgYjEgPSBjMSAlIDI1NjtcbiAgICAgICAgbGV0IGExID0gKChjMSAvIDE2Nzc3MjE2KSB8IDApO1xuXG4gICAgICAgIGxldCByMiA9ICgoYzIgLyA2NTUzNikgfCAwKSAlIDI1NjtcbiAgICAgICAgbGV0IGcyID0gKChjMiAvIDI1NikgfCAwKSAlIDI1NjtcbiAgICAgICAgbGV0IGIyID0gYzIgJSAyNTY7XG4gICAgICAgIGxldCBhMiA9ICgoYzIgLyAxNjc3NzIxNikgfCAwKTtcblxuICAgICAgICBsZXQgciA9IHIxICogcCArIHIyICogKDEgLSBwKTtcbiAgICAgICAgbGV0IGcgPSBnMSAqIHAgKyBnMiAqICgxIC0gcCk7XG4gICAgICAgIGxldCBiID0gYjEgKiBwICsgYjIgKiAoMSAtIHApO1xuICAgICAgICBsZXQgYSA9IGExICogcCArIGEyICogKDEgLSBwKTtcblxuICAgICAgICByZXR1cm4gTWF0aC5yb3VuZChhKSAqIDE2Nzc3MjE2ICsgTWF0aC5yb3VuZChyKSAqIDY1NTM2ICsgTWF0aC5yb3VuZChnKSAqIDI1NiArIE1hdGgucm91bmQoYik7XG4gICAgfTtcblxuICAgIHN0YXRpYyBnZXRBcmdiTnVtYmVyKHJnYmEpIHtcbiAgICAgICAgcmdiYVswXSA9IE1hdGgubWF4KDAsIE1hdGgubWluKDI1NSwgcmdiYVswXSkpO1xuICAgICAgICByZ2JhWzFdID0gTWF0aC5tYXgoMCwgTWF0aC5taW4oMjU1LCByZ2JhWzFdKSk7XG4gICAgICAgIHJnYmFbMl0gPSBNYXRoLm1heCgwLCBNYXRoLm1pbigyNTUsIHJnYmFbMl0pKTtcbiAgICAgICAgcmdiYVszXSA9IE1hdGgubWF4KDAsIE1hdGgubWluKDI1NSwgcmdiYVszXSkpO1xuICAgICAgICBsZXQgdiA9ICgocmdiYVszXSB8IDApIDw8IDI0KSArICgocmdiYVswXSB8IDApIDw8IDE2KSArICgocmdiYVsxXSB8IDApIDw8IDgpICsgKHJnYmFbMl0gfCAwKTtcbiAgICAgICAgaWYgKHYgPCAwKSB7XG4gICAgICAgICAgICB2ID0gMHhGRkZGRkZGRiArIHYgKyAxO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB2O1xuICAgIH07XG59XG4iLCIvKlxuICogSWYgbm90IHN0YXRlZCBvdGhlcndpc2UgaW4gdGhpcyBmaWxlIG9yIHRoaXMgY29tcG9uZW50J3MgTElDRU5TRSBmaWxlIHRoZVxuICogZm9sbG93aW5nIGNvcHlyaWdodCB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1xuICAgICAgICAvLyBTZXQgYXMgbWVyZ2UgZnVuY3Rpb24uXG4gICAgICAgIGYuX19tZiA9IHRydWU7XG4gICAgICAgIHJldHVybiBmO1xuICAgIH1cblxuICAgIHN0YXRpYyBtZXJnZShhLCBiKSB7XG4gICAgICAgIGNvbnN0IGFrcyA9IE9iamVjdC5rZXlzKGEpO1xuICAgICAgICBjb25zdCBia3MgPSBPYmplY3Qua2V5cyhiKTtcblxuICAgICAgICBpZiAoIWJrcy5sZW5ndGgpIHtcbiAgICAgICAgICAgIHJldHVybiBhO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gQ3JlYXRlIGluZGV4IGFycmF5IGZvciBhbGwgZWxlbWVudHMuXG4gICAgICAgIGNvbnN0IGFpID0ge307XG4gICAgICAgIGNvbnN0IGJpID0ge307XG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gYmtzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgY29uc3Qga2V5ID0gYmtzW2ldO1xuICAgICAgICAgICAgYWlba2V5XSA9IC0xO1xuICAgICAgICAgICAgYmlba2V5XSA9IGk7XG4gICAgICAgIH1cbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBha3MubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCBrZXkgPSBha3NbaV07XG4gICAgICAgICAgICBhaVtrZXldID0gaTtcbiAgICAgICAgICAgIGlmIChiaVtrZXldID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBiaVtrZXldID0gLTE7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBjb25zdCBha3NsID0gYWtzLmxlbmd0aDtcblxuICAgICAgICBjb25zdCByZXN1bHQgPSB7fTtcbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBia3MubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCBrZXkgPSBia3NbaV07XG5cbiAgICAgICAgICAgIC8vIFByZXBlbmQgYWxsIGl0ZW1zIGluIGEgdGhhdCBhcmUgbm90IGluIGIgLSBiZWZvcmUgdGhlIG5vdyBhZGRlZCBiIGF0dHJpYnV0ZS5cbiAgICAgICAgICAgIGNvbnN0IGFJbmRleCA9IGFpW2tleV07XG4gICAgICAgICAgICBsZXQgY3VySW5kZXggPSBhSW5kZXg7XG4gICAgICAgICAgICB3aGlsZSgtLWN1ckluZGV4ID49IDApIHtcbiAgICAgICAgICAgICAgICBjb25zdCBha2V5ID0gYWtzW2N1ckluZGV4XTtcbiAgICAgICAgICAgICAgICBpZiAoYmlbYWtleV0gIT09IC0xKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIEFscmVhZHkgZm91bmQ/IFN0b3AgcHJvY2Vzc2luZy5cbiAgICAgICAgICAgICAgICAgICAgLy8gTm90IHlldCBmb3VuZCBidXQgZXhpc3RzIGluIGI/IEFsc28gc3RvcCBwcm9jZXNzaW5nOiB3YWl0IHVudGlsIHdlIGZpbmQgaXQgaW4gYi5cbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgd2hpbGUoKytjdXJJbmRleCA8IGFJbmRleCkge1xuICAgICAgICAgICAgICAgIGNvbnN0IGFrZXkgPSBha3NbY3VySW5kZXhdO1xuICAgICAgICAgICAgICAgIHJlc3VsdFtha2V5XSA9IGFbYWtleV07XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGNvbnN0IGJ2ID0gYltrZXldO1xuICAgICAgICAgICAgY29uc3QgYXYgPSBhW2tleV07XG4gICAgICAgICAgICBsZXQgcjtcbiAgICAgICAgICAgIGlmICh0aGlzLmlzTWYoYnYpKSB7XG4gICAgICAgICAgICAgICAgciA9IGJ2KGF2KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaWYgKCFVdGlscy5pc09iamVjdExpdGVyYWwoYXYpIHx8ICFVdGlscy5pc09iamVjdExpdGVyYWwoYnYpKSB7XG4gICAgICAgICAgICAgICAgICAgIHIgPSBidjtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByID0gT2JqTWVyZ2VyLm1lcmdlKGF2LCBidik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBXaGVuIG1hcmtlZCBhcyB1bmRlZmluZWQsIHByb3BlcnR5IGlzIGRlbGV0ZWQuXG4gICAgICAgICAgICBpZiAociAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgcmVzdWx0W2tleV0gPSByO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgLy8gQXBwZW5kIHJlbWFpbmluZyBmaW5hbCBpdGVtcyBpbiBhLlxuICAgICAgICBsZXQgY3VySW5kZXggPSBha3NsO1xuICAgICAgICB3aGlsZSgtLWN1ckluZGV4ID49IDApIHtcbiAgICAgICAgICAgIGNvbnN0IGFrZXkgPSBha3NbY3VySW5kZXhdO1xuICAgICAgICAgICAgaWYgKGJpW2FrZXldICE9PSAtMSkge1xuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHdoaWxlKCsrY3VySW5kZXggPCBha3NsKSB7XG4gICAgICAgICAgICBjb25zdCBha2V5ID0gYWtzW2N1ckluZGV4XTtcbiAgICAgICAgICAgIHJlc3VsdFtha2V5XSA9IGFbYWtleV07XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gcmVzdWx0O1xuICAgIH1cblxufVxuIiwiLypcbiAqIElmIG5vdCBzdGF0ZWQgb3RoZXJ3aXNlIGluIHRoaXMgZmlsZSBvciB0aGlzIGNvbXBvbmVudCdzIExJQ0VOU0UgZmlsZSB0aGVcbiAqIGZvbGxvd2luZyBjb3B5cmlnaHQgYW5kIGxpY2Vuc2VzIGFw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AgIHJldHVybiBVdGlscy5nZXRNb2R1bG9JbmRleChpbmRleCwgYXJyLmxlbmd0aCk7XG4gICAgfVxuXG4gICAgc3RhdGljIGVxdWFsVmFsdWVzKHYxLCB2Mikge1xuICAgICAgICBpZiAoKHR5cGVvZiB2MSkgIT09ICh0eXBlb2YgdjIpKSByZXR1cm4gZmFsc2VcbiAgICAgICAgaWYgKFV0aWxzLmlzT2JqZWN0TGl0ZXJhbCh2MSkpIHtcbiAgICAgICAgICAgIHJldHVybiBVdGlscy5pc09iamVjdExpdGVyYWwodjIpICYmIFV0aWxzLmVxdWFsT2JqZWN0TGl0ZXJhbHModjEsIHYyKVxuICAgICAgICB9IGVsc2UgaWYgKEFycmF5LmlzQXJyYXkodjEpKSB7XG4gICAgICAgICAgICByZXR1cm4gQXJyYXkuaXNBcnJheSh2MikgJiYgVXRpbHMuZXF1YWxBcnJheXModjEsIHYyKVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHYxID09PSB2MlxuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGVxdWFsT2JqZWN0TGl0ZXJhbHMob2JqMSwgb2JqMikge1xuICAgICAgICBsZXQga2V5czEgPSBPYmplY3Qua2V5cyhvYmoxKTtcbiAgICAgICAgbGV0IGtleXMyID0gT2JqZWN0LmtleXMob2JqMik7XG4gICAgICAgIGlmIChrZXlzMS5sZW5ndGggIT09IGtleXMyLmxlbmd0aCkge1xuICAgICAgICAgICAgcmV0dXJuIGZhbHNlXG4gICAgICAgIH1cblxuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IGtleXMxLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgY29uc3QgazEgPSBrZXlzMVtpXTtcbiAgICAgICAgICAgIGNvbnN0IGsyID0ga2V5czJbaV07XG4gICAgICAgICAgICBpZiAoazEgIT09IGsyKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlXG4gICAgICAgICAgICB9X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bnN0IGNoYW5nZSA9IHRoaXMuX3Byb2dyYW0gIT09IHByb2dyYW07XG4gICAgICAgIHRoaXMuX3Byb2dyYW0gPSBwcm9ncmFtO1xuICAgICAgICByZXR1cm4gY2hhbmdlXG4gICAgfVxuXG4gICAgc2V0U2V0dGluZyhmdW5jLCB2KSB7XG4gICAgICAgIGNvbnN0IHMgPSB0aGlzLl9zZXR0aW5ncy5nZXQoZnVuYyk7XG4gICAgICAgIGNvbnN0IGNoYW5nZSA9ICFzIHx8ICFVdGlscy5lcXVhbFZhbHVlcyhzLCB2KTtcbiAgICAgICAgdGhpcy5fc2V0dGluZ3Muc2V0KGZ1bmMsIHYpO1xuICAgICAgICByZXR1cm4gY2hhbmdlXG4gICAgfVxuXG4gICAgZGlzYWJsZVZlcnRleEF0dHJpYkFycmF5KGluZGV4KSB7XG4gICAgICAgIGNvbnN0IHZhID0gdGhpcy5fdmVydGV4QXR0cmlic1tpbmRleF07XG4gICAgICAgIGlmICh2YSAmJiB2YVs1XSkge1xuICAgICAgICAgICAgdmFbNV0gPSBmYWxzZTtcbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9XG5cbiAgICBlbmFibGVWZXJ0ZXhBdHRyaWJBcnJheShpbmRleCkge1xuICAgICAgICBjb25zdCB2YSA9IHRoaXMuX3ZlcnRleEF0dHJpYnNbaW5kZXhdO1xuICAgICAgICBpZiAodmEpIHtcbiAgICAgICAgICAgIGlmICghdmFbMF0pIHtcbiAgICAgICAgICAgICAgICB2YVswXSA9IHRydWU7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl92ZXJ0ZXhBdHRyaWJzW2luZGV4XSA9IFswLCAwLCAwLCAwLCAwLCB0cnVlXTtcbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG4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vckVhY2goKGF0dHJpYiwgaW5kZXgpID0+IHtcbiAgICAgICAgICAgICAgICB0aGlzLl9nbC5fdmVydGV4QXR0cmliUG9pbnRlcihpbmRleCwgYXR0cmliWzBdLCBhdHRyaWJbMV0sIGF0dHJpYlsyXSwgYXR0cmliWzRdKTtcbiAgICAgICAgICAgICAgICBpZiAoYXR0cmliWzVdKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2dsLl9lbmFibGVWZXJ0ZXhBdHRyaWJBcnJheShpbmRleCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZ2wuX2Rpc2FibGVWZXJ0ZXhBdHRyaWJBcnJheShpbmRleCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAvLyBXaGVuIGJ1ZmZlcnMgYXJlIGNoYW5nZWQsIHByZXZpb3VzIGF0dHJpYnV0ZXMgd2VyZSByZXNldCBhdXRvbWF0aWNhbGx5LlxuICAgICAgICAgICAgcy5fdmVydGV4QXR0cmlicy5mb3JFYWNoKChhdHRyaWIsIGluZGV4KSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKGF0dHJpYlswXSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBEbyBub3Qgc2V0IHZlcnRleCBhdHRyaWIgcG9pbnRlciB3aGVuIGl0IHdhcyBqdXN0IHRoZSBkZWZhdWx0IHZhbHVlLlxuICAgICAgICAgICAgICAgICAgICB0aGlzLl9nbC5fdmVydGV4QXR0cmliUG9pbnRlcihpbmRleCwgYXR0cmliWzBdLCBhdHRyaWJbMV0sIGF0dHJpYlsyXSwgYXR0cmliWzNdLCBhdHRyaWJbNF0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAoYXR0cmliWzVdKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2dsLl9lbmFibGVWZXJ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ICAgICAgICAgICAgIGZ1bmMuYXBwbHkodGhpcy5fZ2wsIHZhbHVlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgX21pZ3JhdGVGbGFncyh0LCBzKSB7XG4gICAgICAgIHQuX25vbkRlZmF1bHRGbGFncy5mb3JFYWNoKHNldHRpbmcgPT4ge1xuICAgICAgICAgICAgaWYgKCFzLl9ub25EZWZhdWx0RmxhZ3MuaGFzKHNldHRpbmcpKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2dldERlZmF1bHRGbGFnKHNldHRpbmcpKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2dsLl9lbmFibGUoc2V0dGluZyk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZ2wuX2Rpc2FibGUoc2V0dGluZyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgcy5fbm9uRGVmYXVsdEZsYWdzLmZvckVhY2goc2V0dGluZyA9PiB7XG4gICAgICAgICAgICBpZiAoIXQuX25vbkRlZmF1bHRGbGFncy5oYXMoc2V0dGluZykpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fZ2V0RGVmYXVsdEZsYWcoc2V0dGluZykpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZ2wuX2Rpc2FibGUoc2V0dGluZyk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZ2wuX2VuYWJsZShzZXR0aW5nKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIHN0YXRpYyBnZXREZWZhdWx0U2V0dGluZ3MoKSB7XG4gICAgICAgIGlmICghdGhpcy5fZGVmYXVsdFNldHRpbmdzKSB7XG4gICAgICAgICAgICB0aGlzL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V8yRCAqL1xuICAgICAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICAgICAgY2FzZSAweDg1MTM6XG4gICAgICAgICAgICAgICAgLyogVEVYVFVSRV9DVUJFX01BUCAqL1xuICAgICAgICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICAgICAgZGVmYXVsdDpcbiAgICAgICAgICAgICAgICAvLyBTaG91bGRuJ3QgaGFwcGVuLlxuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignVW5rbm93biB0ZXh0dXJlIHRhcmdldDogJyArIHRhcmdldCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgX2dldFRleHR1cmVUYXJnZXRCeUluZGV4KGluZGV4KSB7XG4gICAgICAgIGlmICghdGhpcy5fdGV4dHVyZVRhcmdldEluZGljZXMpIHtcbiAgICAgICAgICAgIHRoaXMuX3RleHR1cmVUYXJnZXRJbmRpY2VzID0gWzB4MERFMSwgMHg4NTEzXTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdGhpcy5fdGV4dHVyZVRhcmdldEluZGljZXNbaW5kZXhdXG4gICAgfVxuXG4gICAgc3RhdGljIF9nZXRUZXh0dXJlSW5kZXgoaW5kZXgpIHtcbiAgICAgICAgcmV0dXJuIGluZGV4IC0gMHg4NEMwIC8qIEdMX1RFWFRVUkUwICovO1xuICAgIH1cblxuICAgIHN0YXRpYyBfZ2V0VGV4dHVyZUJ5SW5kZXgoaW5kZXgpIHtcbiAgICAgICAgcmV0dXJuIGluZGV4ICsgMHg4NEMwO1xuICAgIH1cblxuICAgIHN0YXRpYyBfZ2V0UGl4ZWxTdG9yZWlJbmRleChwbmFtZSkge1xuICAgICAgICBzd2l0Y2gocG5hbWUpIHtcbiAgICAgICAgICAgIGNhc2UgMHgwRDA1OlxuICAgICAgICAgICAgICAgIC8qIFBBQ0tfQUxJR05NRU5UICovXG4gICAgICAgICAgICAgICAgcmV0dXJuIDA7XG4gICAgICAgICAgICBjYXNlIDB4MENGNTpcbiAgICAgICAgICAgICAgICAvKiBVTlBBQ0tfQUxJR05NRU5UICovXG4gICAgICAgICAgICAgICAgcmV0dXJuIDE7XG4gICAgICAgICAgICBjYXNlIDB4OTI0MDpcbiAgICAgICAgICAgICAgICAvKiBVTlBBQ0tfRkxJUF9ZX1dFQkdMICovXG4gICAgICAgICAgICAgICAgcmV0dXJuIDI7XG4gICAgICAgICAgICBjYXNlIDB4OTI0MTpcbiAgICAgICAgICAgICAgICAvKiBVTlBBQ0tfUFJFTVVMVElQTFlfQUxQSEFfV0VCR0wgKi9cbiAgICAgICAgICAgICAgICByZXR1cm4gMztcbiAgICAgICAgICAgIGNhc2UgMHg5MjQzOlxuICAgICAgICAgICAgICAgIC8qIFVOUEFDS19DT0xPUlNQQUNFX0NPTlZFUlNJT05fV0VCR0wgKi9cbiAgICAgICAgICAgICAgICByZXR1cm4gNDtcbiAgICAgICAgICAgICAgICAvL0B0b2RvOiBzdXBwb3J0IFdlYkdMMiBwcm9wZXJ0aWVzLCBzZWUgaHR0cHM6Ly9kZXZlbG9wZXIubW96aWxsYS5vcmcvZW4tVVMvZG9jcy9XZWIvQVBJL1dlYkdMUmVuZGVyaW5nQ29udGV4dC9waXhlbFN0b3JlaVxuICAgICAgICAgICAgY2FzZSAweDkyNDU6XG4gICAgICAgICAgICAgICAgLyogVU5QQUNLX0ZMSVBfQkxVRV9SRUQgKi9cbiAgICAgICAgICAgICAgICByZXR1cm4gNTtcbiAgICAgICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgICAgICAgLy8gU2hvdWxkbid0IGhhcHBlbi5cbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ1Vua25vd24gcGl4ZWxzdG9yZWk6ICcgKyBwbmFtZSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgX2dldFBpeGVsU3RvcmVpQnlJbmRleChpbmRleCkge1xuICAgICAgICBpZiAoIXRoaXMuX3BpeGVsU3RvcmVpSW5ka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HJvdG90eXBlKTtcbiAgICAgICAgY29uc3QgV2ViR0xSZW5kZXJpbmdDb250ZXh0UHJvdG8gPSBnbC5fX3Byb3RvX187XG4gICAgICAgIG5hbWVzLmZvckVhY2gobmFtZSA9PiB7XG4gICAgICAgICAgICBpZiAobmFtZSAhPT0gXCJjb25zdHJ1Y3RvclwiKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgbWV0aG9kID0gV2ViR0xTdGF0ZU1hbmFnZXIucHJvdG90eXBlW25hbWVdO1xuICAgICAgICAgICAgICAgIGlmIChuYW1lLmNoYXJBdCgwKSA9PT0gXCIkXCIpIHtcbiAgICAgICAgICAgICAgICAgICAgbmFtZSA9IG5hbWUuc3Vic3RyKDEpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAoZ2xbbmFtZV0gIT09IG1ldGhvZCkge1xuICAgICAgICAgICAgICAgICAgICBpZiAoZ2xbbmFtZV0pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghZ2xbbmFtZV0ubmFtZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIFdlIGRvIHRoaXMgZm9yIGNvbXBhdGliaWxpdHkgd2l0aCB0aGUgQ2hyb21lIFdlYkdMIEluc3BlY3RvciBwbHVnaW4uXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZ2xbbmFtZV0ueG5hbWUgPSBuYW1lO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgZ2xbJ18nICsgbmFtZV0gPSBnbFtuYW1lXTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBnbFtuYW1lXSA9IG1ldGhvZDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuXG4gICAgICAgIFdlYkdMU3RhdGVNYW5hZ2VyLnByb3RvdHlwZS5faW5pdFN0YXRlTWFuYWdlci5jYWxsKGdsLCBp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BAdHlwZSB7Ym9vbGVhbn1cbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX19lbmFibGVkID0gZmFsc2U7XG5cbiAgICAgICAgLyoqXG4gICAgICAgICAqIEFuIGVsZW1lbnQgaXMgYWN0aXZlIHdoZW4gaXQgaXMgZW5hYmxlZCBhbmQgaXQgaXMgd2l0aGluIGJvdW5kcy5cbiAgICAgICAgICogQHR5cGUge2Jvb2xlYW59XG4gICAgICAgICAqL1xuICAgICAgICB0aGlzLl9fYWN0aXZlID0gZmFsc2U7XG5cbiAgICAgICAgLyoqXG4gICAgICAgICAqIEB0eXBlIHtFbGVtZW50fVxuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5fX3BhcmVudCA9IG51bGw7XG5cbiAgICAgICAgLyoqXG4gICAgICAgICAqIFRoZSB0ZXh0dXJlIHRoYXQgaXMgY3VycmVudGx5IHNldC5cbiAgICAgICAgICogQHR5cGUge1RleHR1cmV9XG4gICAgICAgICAqL1xuICAgICAgICB0aGlzLl9fdGV4dHVyZSA9IG51bGw7XG5cbiAgICAgICAgLyoqXG4gICAgICAgICAqIFRoZSBjdXJyZW50bHkgZGlzcGxheWVkIHRleHR1cmUuIFdoaWxlIHRoaXMudGV4dHVyZSBpcyBsb2FkaW5nLCB0aGlzIG9uZSBtYXkgYmUgZGlmZmVyZW50LlxuICAgICAgICAgKiBAdHlwZSB7VGV4dHVyZX1cbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX19kaXNwbGF5ZWRUZXh0dXJlID0gbnVsbDtcblxuICAgICAgICAvKipcbiAgICAgICAgICogVGFncyB0aGF0IGNhbiBiZSB1c2VkIHRvIGlkZW50aWZ5L3NlYXJjaCBmb3IgYSBzcGVjaWZpYyBlbGVtZW50LlxuICAgICAgICAgKiBAdHlwZSB7U3RyaW5nW119XG4gICAgICAgICAqL1xuICAgICAgICB0aGlzLl9fdGFncyA9IG51bGw7XG5cbiAgICAgICAgLyoqXG4gICAgICAgICAqIFRoZSB0cmVlJ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hpcy5fdGhyb3dFcnJvcihcIlJlZiBtdXN0IHN0YXJ0IHdpdGggYW4gdXBwZXIgY2FzZSBjaGFyYWN0ZXI6IFwiICsgcmVmKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLl9fcmVmICE9PSBudWxsKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVUYWcodGhpcy5fX3JlZik7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX19wYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fX3BhcmVudC5fX2NoaWxkTGlzdC5jbGVhclJlZih0aGlzLl9fcmVmKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRoaXMuX19yZWYgPSByZWY7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9fcmVmKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fYWRkVGFnKHRoaXMuX19yZWYpO1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9fcGFyZW50KSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX19wYXJlbnQuX19jaGlsZExpc3Quc2V0UmVmKHRoaXMuX19yZWYsIHRoaXMpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCByZWYoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fcmVmO1xuICAgIH1cblxuICAgIGdldCBjb3JlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmU7XG4gICAgfVxuXG4gICAgc2V0QXNSb290KCkge1xuICAgICAgICB0aGlzLl9fY29yZS5zZXRBc1Jvb3QoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlQXR0YWNoZWRGbGFnKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUVuYWJsZWRGbGFnKCk7XG4gICAgfVxuXG4gICAgZ2V0IGlzUm9vdCgpIHt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mVudCkge1xuICAgICAgICAgICAgcCA9IHAuX19wYXJlbnQ7XG4gICAgICAgICAgICBsLS07XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHA7XG4gICAgfTtcblxuICAgIGdldEFuY2VzdG9ycygpIHtcbiAgICAgICAgY29uc3QgYSA9IFtdO1xuICAgICAgICBsZXQgcCA9IHRoaXM7XG4gICAgICAgIHdoaWxlIChwKSB7XG4gICAgICAgICAgICBhLnB1c2gocCk7XG4gICAgICAgICAgICBwID0gcC5fX3BhcmVudDtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gYTtcbiAgICB9XG5cbiAgICBnZXRBbmNlc3RvckF0RGVwdGgoZGVwdGgpIHtcbiAgICAgICAgbGV0IGxldmVscyA9IHRoaXMuZ2V0RGVwdGgoKSAtIGRlcHRoO1xuICAgICAgICBpZiAobGV2ZWxzIDwgMCkge1xuICAgICAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRoaXMuZ2V0QW5jZXN0b3IobGV2ZWxzKTtcbiAgICB9O1xuXG4gICAgaXNBbmNlc3Rvck9mKGMpIHtcbiAgICAgICAgbGV0IHAgPSBjO1xuICAgICAgICB3aGlsZShwID0gcC5wYXJlbnQpIHtcbiAgICAgICAgICAgIGlmICh0aGlzID09PSBwKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH07XG5cbiAgICBnZXRTaGFyZWRBbmNlc3RvcihjKSB7XG4gICAgICAgIGxldCBvMSA9IHRoaXM7XG4gICAgICAgIGxldCBvMiA9IGM7XG4gICAgICAgIGxldCBsMSA9IG8xLmdldERlcHRoKCk7XG4gICAgICAgIGxldCBsMiA9IG8yLmdldERlcHRoKCk7XG4gICAgICAgIGlmIChsMSA+IGwyKSB7XG4gICAgICAgICAgICBvMSA9IG8xLmdldEFuY2VzdG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AmJiB0aGlzLndpdGhpbkJvdW5kc01hcmdpbjtcbiAgICB9O1xuXG4gICAgLyoqXG4gICAgICogVXBkYXRlcyB0aGUgJ2F0dGFjaGVkJyBmbGFnIGZvciB0aGlzIGJyYW5jaC5cbiAgICAgKi9cbiAgICBfdXBkYXRlQXR0YWNoZWRGbGFnKCkge1xuICAgICAgICBsZXQgbmV3QXR0YWNoZWQgPSB0aGlzLl9pc0F0dGFjaGVkKCk7XG4gICAgICAgIGlmICh0aGlzLl9fYXR0YWNoZWQgIT09IG5ld0F0dGFjaGVkKSB7XG4gICAgICAgICAgICB0aGlzLl9fYXR0YWNoZWQgPSBuZXdBdHRhY2hlZDtcblxuICAgICAgICAgICAgaWYgKG5ld0F0dGFjaGVkKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb25TZXR1cCgpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBsZXQgY2hpbGRyZW4gPSB0aGlzLl9jaGlsZHJlbi5nZXQoKTtcbiAgICAgICAgICAgIGlmIChjaGlsZHJlbikge1xuICAgICAgICAgICAgICAgIGxldCBtID0gY2hpbGRyZW4ubGVuZ3RoO1xuICAgICAgICAgICAgICAgIGlmIChtID4gMCkge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG07IGkrKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgY2hpbGRyZW5baV0uX3VwZGF0ZUF0dGFjaGVkRmxhZygpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAobmV3QXR0YWNoZWQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9vbkF0dGFjaCgpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9vbkRldGFjaCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfTtcblxuICAgIC8qKlxuICAgICAqIFVwZGF0ZXMgdGhlICdlbmFibGVkJyBmbGFnIGZvciB0aGlzIGJyYW5jaC5cbiAgICAgKi9cbiAgICBfdXBkYXRlRW5hYmxlZEZsYWcoKSB7XG4gICAgICAgIGxldCBuZXdFbmFibGVkID0gdGhpcy5faXNFbmFibGVkKCk7XG4gICAgICAgIGlmICh0aGlzLl9fZW5hYmxlZCAhPT0gbmV3RW5hYmxlZCkge1xuICAgICAgICAgICAgaWYgKG5ld0VuYWJsZWQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9vbkVuYWJsZWQoKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9zZXRFbmFibGVkRmxhZygpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9vbkRpc2FibGVkKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fdW5zZXRFbmFibGVkRmxhZygpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBsZXQgY2hpbGRyZW4gPSB0aGlzLl9jaGlsZHJlbi5nZXQoKTtcbiAgICAgICAgICAgIGlmIChjaGlsZHJlbikge1xuICAgICAgICAgICAgICAgIGxldCBtID0gY2hpbGRyZW4ubGVuZ3RoO1xuICAgICAgICAgICAgICAgIGlmIChtID4gMCkge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG07IGkrKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgY2hpbGRyZW5baV0uX3VwZGF0ZUVuYWJsZWRGbGFnKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgX3NldEVuYWJsZWRGbGFnKCkge1xuICAgICAgICB0aGlzLl9fZW5hYmxlZCA9IHRydWU7XG5cbiAgICAgICAgLy8gRm9yY2UgcmUtY2hlY2sgb2YgdGV4dHVyZSBiZWNhdXNlIGRpbWVuc2lvbnMgbWlnaHQgaGF2ZSBjaGFuZ2VkIChjdXR0aW5nKS5cbiAgICAgICAgdGhpcy5fdXBkYXRlRGltZW5zaW9ucygpO1xuICAgICAgICB0aGlzLl91cGRhdGVUZXh0dXJlQ29vcmRzKCk7XG5cbiAgICAgICAgaWYgKHRoaXMuX190ZXh0dXJlKSB7XG4gICAgICAgICAgICB0aGlzLl9fdGV4dHVyZS5hZGRFbGVtZW50KHRoaXMpO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMud2l0aGluQm91bmRzTWFyZ2luKSB7XG4gICAgICAgICAgICB0aGlzLl9zZXRBY3RpdmVGbGFnKCk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5fX2NvcmUuc2hhZGVyKSB7XG4gICAgICAgICAgICB0aGlzLl9fY29yZS5zaGFkZXIuYWRkRWxlbWVudCh0aGlzLl9fY29yZSk7XG4gICAgICAgIH1cblxuICAgIH1cblxuICAgIF91bnNldEVuYWJsZWRGbGFnKCkge1xuICAgICAgICBpZiAodGhpcy5fX2FjdGl2ZSkge1xuICAgICAgICAgICAgdGhpcy5fdW5zZXRBY3RpdmVGbGFnKCk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5fX3RleHR1cmUpIHtcbiAgICAgICAgICAgIHRoaXMuX190ZXh0dXJlLnJlbW92ZUVsZW1lbnQodGhpcyk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5fX2NvcmUuc2hhZGVyKSB7XG4gICAgICAgICAgICB0aGlzLl9fY29yZS5zaGFkZXIucmVtb3ZlRWxlbWVudCh0aGlzLl9fY29yZSk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5fdGV4dHVyaXplcikge1xuICAgICAgICAgICAgdGhpcy50ZXh0dXJpemVyLmZpbHRlcnMuZm9yRWFjaChmaWx0ZXIgPT4gZmlsdGVyLnJlbW92ZUVsZW1lbnQodGhpcy5fX2NvcmUpKTtcbiAgICAgICAgfVxuXG4gICAgICAgIHRoaXM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gbmV3IHYudHlwZSh0aGlzLnN0YWdlKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGV4dHVyZSA9IHRoaXMudGV4dHVyZTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRleHR1cmUpIHtcbiAgICAgICAgICAgICAgICBCYXNlLnBhdGNoT2JqZWN0KHRleHR1cmUsIHYpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKCF2KSB7XG4gICAgICAgICAgICB0ZXh0dXJlID0gbnVsbDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh2LmlzVGV4dHVyZSkge1xuICAgICAgICAgICAgICAgIHRleHR1cmUgPSB2O1xuICAgICAgICAgICAgfSBlbHNlIGlmICh2LmlzVGV4dHVyZVNvdXJjZSkge1xuICAgICAgICAgICAgICAgIHRleHR1cmUgPSBuZXcgU291cmNlVGV4dHVyZSh0aGlzLnN0YWdlKTtcbiAgICAgICAgICAgICAgICB0ZXh0dXJlLnRleHR1cmVTb3VyY2UgPSB2O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjb25zb2xlLmVycm9yKFwiW0xpZ2h0bmluZ10gUGxlYXNlIHNwZWNpZnkgYSB0ZXh0dXJlIHR5cGUuXCIpO1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGNvbnN0IHByZXZUZXh0dXJlID0gdGhpcy5fX3RleHR1cmU7XG4gICAgICAgIGlmICh0ZXh0dXJlICE9PSBwcmV2VGV4dHVyZSkge1xuICAgICAgICAgICAgdGhpcy5fX3RleHR1cmUgPSB0ZXh0dXJlO1xuXG4gICAgICAgICAgICBpZiAodGhpcy5fX3RleHR1cmUpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fX2VuYWJsZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fX3RleHR1cmUuYWRkRWxlbWVudCh0aGlzKTtcblxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy53aXRoaW5Cb3VuZHNNYXJnaW4pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9fdGV4dHVyZS5pc0xvYWRlZCgpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fc2V0RGlzcGxheWVkVGV4dHVyZSh0aGlzLl9fdGV4dHVyZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2VuYWJsZVRleHR1cmVFcnJvcigpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAvLyBNYWtlIHN1cmUgdGhhdCBjdXJyZW50IHRleHR1cmUgaXMgY2xlYXJlZCB3aGVuIHRoZSB0ZXh0dXJlIGlzIGV4cGxpY2l0bHkgc2V0IHRvIG51bGwuXG4gICAgICAgICAgICAgICAgdGhpcy5fc2V0RGlzcGxheWVkVGV4dHVyZShudWxsKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHByZXZUZXh0dXJlICYmIHByZXZUZXh0dXJlICE9PSB0aGlzLl9fZGlzcGxheWVkVGV4dHVyZSkge1xuICAgICAgICAgICAgICAgIHByZXZUZXh0dXJlLnJlbW92ZUVsZW1lbnQodGhpcyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZURpbWVuc2lvbnMoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBkaXNwbGF5ZWRUZXh0dXJlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2Rpc3BsYXllZFRleHR1cmU7XG4gICAgfVxuXG4gICAgX3NldERpc3BsYXllZFRleHR1cmUodikge1xuICAgICAgICBsZXQgcHJldlRleHR1cmUgPSB0aGlzLl9fZGlzcGxheWVkVGV4dHVyZTtcblxuICAgICAgICBpZiAocHJldlRleHR1cmUgJiYgKHYgIT09IHByZXZUZXh0dXJlKSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX190ZXh0dXJlICE9PSBwcmV2VGV4dHVyZSkge1xuICAgICAgICAgICAgICAgIC8vIFRoZSBvbGQgZGlzcGxheWVkIHRleHR1cmUgaXMgZGVwcmVjYXRlZC5cbiAgICAgICAgICAgICAgICBwcmV2VGV4dHVyZS5yZW1vdmVFbGVtZW50KHRoaXMpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgY29uc3QgcHJldlNvdXJjZSA9IHRoaXMuX19jb3JlLmRpc3BsYXllZFRleHR1cmVTb3VyY2U7XG4gICAgICAgIGNvbnN0IHNvdXJjZUNoYW5nZWQgPSAodiA/IHYuX3NvdXJjZSA6IG51bGwpICE9PSBwcmV2U291cmNlO1xuXG4gICAgICAgIHRoaXMuX19kaXNwbGF5ZWRUZXh0dXJlID0gdjtcbiAgICAgICAgdGhpcy5fdXBkYXRlRGltZW5zaW9ucygpO1xuXG4gICAgICAgIGlmICh0aGlzLl9fZGlzcGxheWVkVGV4dHVyZSkge1xuICAgICAgICAgICAgaWYgKHNvdXJjZUNoYW5nZWQpIHtcbiAgICAgICAgICAgICAgICAvLyBXZSBkb24ndCBuZWVkIHRvIHJlZmVyZW5jZSB0aGUgZGlzcGxheWVkIHRleHR1cmUgYmVjYXVzZSBpdCB3YXMgYWxyZWFkeSByZWZlcmVuY2VkICh0aGlzLnRleHR1cmUgPT09IHRoaXMuZGlzcGxheWVkVGV4dHVyZSkuXG4gICAgICAgICAgICAgICAgdGhpcy5fdXBkYXRlVGV4dHVyZUNvb3JkcygpO1xuICAgICAgICAgICAgICAgIHRoaXMuX19jb3JlLnNldERpc3BsYXllZFRleHR1cmVTb3VyY2UodGhpcy5fX2Rpc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mcpIHtcbiAgICAgICAgICAgICAgICAvLyBBcHBseSB0ZXh0dXJlIGNsaXBwaW5nLlxuICAgICAgICAgICAgICAgIGxldCB3ID0gZGlzcGxheWVkVGV4dHVyZVNvdXJjZS5nZXRSZW5kZXJXaWR0aCgpO1xuICAgICAgICAgICAgICAgIGxldCBoID0gZGlzcGxheWVkVGV4dHVyZVNvdXJjZS5nZXRSZW5kZXJIZWlnaHQoKTtcbiAgICAgICAgICAgICAgICBsZXQgaXcsIGloLCBydywgcmg7XG4gICAgICAgICAgICAgICAgaXcgPSAxIC8gdztcbiAgICAgICAgICAgICAgICBpaCA9IDEgLyBoO1xuXG4gICAgICAgICAgICAgICAgaWYgKGRpc3BsYXllZFRleHR1cmUucHcpIHtcbiAgICAgICAgICAgICAgICAgICAgcncgPSAoZGlzcGxheWVkVGV4dHVyZS5wdykgKiBpdztcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBydyA9ICh3IC0gZGlzcGxheWVkVGV4dHVyZS5weCkgKiBpdztcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAoZGlzcGxheWVkVGV4dHVyZS5waCkge1xuICAgICAgICAgICAgICAgICAgICByaCA9IGRpc3BsYXllZFRleHR1cmUucGggKiBpaDtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByaCA9IChoIC0gZGlzcGxheWVkVGV4dHVyZS5weSkgKiBpaDtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpdyAqPSAoZGlzcGxheWVkVGV4dHVyZS5weCk7XG4gICAgICAgICAgICAgICAgaWggKj0gKGRpc3BsYXllZFRleHR1cmUucHkpO1xuXG4gICAgICAgICAgICAgICAgdHgxID0gaXc7XG4gICAgICAgICAgICAgICAgdHkxID0gaWg7XG4gICAgICAgICAgICAgICAgdHgyID0gdHgyICogcncgKyBpdztcbiAgICAgICAgICAgICAgICB0eTIgPSB0eTIgKiByaCArIGloO1xuXG4gICAgICAgICAgICAgICAgdHgxID0gTWF0aC5tYXgoMCwgdHgxKTtcbiAgICAgICAgICAgICAgICB0eTEgPSBNYXRoLm1heCgwLCB0eTEpO1xuICAgICAgICAgICAgICAgIHR4MiA9IE1hdGgubWluKDEsIHR4Mik7XG4gICAgICAgICAgICAgICAgdHkyID0gTWF0aC5taW4oMSwgdHkyKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGRpc3BsYXllZFRleHR1cmVTb3VyY2UuX2ZsaXBUZXh0dXJlWSkge1xuICAgICAgICAgICAgICAgIGxldCB0ZW1wdHkgPSB0eTI7XG4gICAgICAgICAgICAgICAgdHkyID0gdHkxO1xuICAgICAgICAgICAgICAgIHR5MSA9IHRlbXB0eTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX19jb3JlLnNldFRleHR1cmVDb29yZHModHgxLCB0eTEsIHR4MiwgdHkyKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldENvcm5lclBvaW50cygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLmdldENvcm5lclBvaW50cygpO1xuICAgIH1cblxuICAgIF91bnNldFRhZ3NQYXJlbnQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9fdGFncykge1xuICAgICAgICAgICAgdGhpcy5fX3RhZ3MuZm9yRWFjaCgodGFnKSA9PiB7XG4gICAgICAgICAgICAgICAgLy8gUmVtb3ZlIGZyb20gdHJlZVRhZ3MuXG4gICAgICAgICAgICAgICAgbGV0IHAgPSB0aGlzO1xuICAgICAgICAgICAgICAgIHdoaWxlIChwID0gcC5fX3BhcmVudCkge1xuICAgICAgICAgICAgICAgICAgICBsZXQgcGFyZW50VHJlZVRhZ3MgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICAgICAgICAgIHBhcmVudFRyZWVUYWdzLmRlbGV0ZSh0aGlzKTtcblxuICAgICAgICAgICAgICAgICAgICBpZiAocC5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cblxuICAgICAgICBsZXQgdGFncyA9IG51bGw7XG4gICAgICAgIGxldCBuID0gMDtcbiAgICAgICAgaWYgKHRoaXMuX190cmVlVGFncykge1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9fdGFnUm9vdCkge1xuICAgICAgICAgICAgICAgIHRhZ3MgPSBVdGlscy5pdGVyYXRvclRvQXJyYXkodGhpcy5fX3RyZWVUYWdzLmtleXMoKSk7XG4gICAgICAgICAgICAgICAgbiA9IHRhZ3MubGVuZ3RoO1xuXG4gICAgICAgICAgICAgICAgaWYgKG4gPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBsZXQgdGFnU2V0ID0gdGhpcy5fX3RyZWVUYWdzLmdldCh0YWdzW2ldKTtcblxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gUmVtb3ZlIGZyb20gdHJlZVRhZ3MuXG4gICAgICAgICAgICAgICAgICAgICAgICBsZXQgcCA9IHRoaXM7XG4gICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoKHAgPSBwLl9fcGFyZW50KSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBwYXJlbnRUcmVlVGFncyA9IHAuX190cmVlVGFncy5nZXQodGFnc1tpXSk7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0YWdTZXQuZm9yRWFjaChmdW5jdGlvbiAoY29tcCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRUcmVlVGFncy5kZWxldGUoY29tcCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSk7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocC5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfTtcblxuICAgIF9zZXRUYWdzUGFyZW50KCkge1xuICAgICAgICAvLyBKdXN0IGNvcHkgb3ZlciB0aGUgJ2xvY2FsJyB0YWdzLlxuICAgICAgICBpZiAodGhpcy5fX3RhZ3MpIHtcbiAgICAgICAgICAgIHRoaXMuX190YWdzLmZvckVhY2goKHRhZykgPT4ge1xuICAgICAgICAgICAgICAgIGxldCBwID0gdGhpcztcbiAgICAgICAgICAgICAgICB3aGlsZSAocCA9IHAuX19wYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFwLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHAuX190cmVlVGFncyA9IG5ldyBNYXAoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIGxldCBzID0gcC5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgICAgICAgICAgICAgICBpZiAoIXMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHMgPSBuZXcgU2V0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3Muc2V0KHRhZywgcyk7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICBzLmFkZCh0aGlzKTtcblxuICAgICAgICAgICAgICAgICAgICBpZiAocC5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5fX3RyZWVUYWdzICYmIHRoaXMuX190cmVlVGFncy5zaXplKSB7XG4gICAgICAgICAgICBpZiAoIXRoaXMuX190YWdSb290KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fX3RyZWVUYWdzLmZvckVhY2goKHRhZ1NldCwgdGFnKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgIGxldCBwID0gdGhpcztcbiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKCFwLl9fdGFnUm9vdCAmJiAocCA9IHAuX19wYXJlbnQpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAocC5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBEbyBub3QgY29weSBhbGwgc3Vicy5cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghcC5fX3RyZWVUYWdzKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcC5fX3RyZWVUYWdzID0gbmV3IE1hcCgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgICAgICBsZXQgcyA9IHAuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghcykge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMgPSBuZXcgU2V0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcC5fX3RyZWVUYWdzLnNldCh0YWcsIHMpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgICAgICB0YWdTZXQuZm9yRWFjaChmdW5jdGlvbiAoY29tcCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMuYWRkKGNvbXApO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG5cblxuICAgIF9nZXRCeVRhZyh0YWcpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICAgIHJldHVybiBbXTtcbiAgICAgICAgfVxuICAgICAgICBsZXQgdCA9IHRoaXMuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgICAgcmV0dXJuIHQgPyBVdGlscy5zZXRUb0FycmF5KHQpIDogW107XG4gICAgfTtcblxuICAgIGdldFRhZ3MoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fdGFncyA/IHRoaXMuX190YWdzIDogW107XG4gICAgfTtcblxuICAgIHNldFRhZ3ModGFncykge1xuICAgICAgICB0YWdzID0gdGFncy5yZWR1Y2UoKGFjYywgdGFnKSA9PiB7XG4gICAgICAgICAgICByZXR1cm4gYWNjLmNvbmNhdCh0YWcuc3BsaXQoJyAnKSk7XG4gICAgICAgIH0sIFtdKTtcblxuICAgICAgICBpZiAodGhpcy5fX3JlZikge1xuICAgICAgICAgICAgdGFncy5wdXNoKHRoaXMuX19yZWYpO1xuICAgICAgICB9XG5cbiAgICAgICAgbGV0IGksIG4gPSB0YWdzLmxlbmd0aDtcbiAgICAgICAgbGV0IHJlbW92ZXMgPSBbXTtcbiAgICAgICAgbGV0IGFkZHMgPSBbXTtcbiAgICAgICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgaWYgKCF0aGlzLmhhc1RhZyh0YWdzW2ldKSkge1xuICAgICAgICAgICAgICAgIGFkZHMucHVzaCh0YWdzW2ldKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBjdXJyZW50VGFncyA9IHRoaXMudGFncyB8fCBbXTtcbiAgICAgICAgbiA9IGN1cnJlbnRUYWdzLmxlbmd0aDtcbiAgICAgICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgaWYgKHRhZ3MuaW5kZXhPZihjdXJyZW50VGFnc1tpXSkgPT0gLTEpIHtcbiAgICAgICAgICAgICAgICByZW1vdmVzLnB1c2goY3VycmVudFRhZ3NbaV0pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgZm9yIChpID0gMDsgaSA8IHJlbW92ZXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgIHRoaXMucmVtb3ZlVGFnKHJlbW92ZXNbaV0pO1xuICAgICAgICB9XG5cbiAgICAgICAgZm9yIChpID0gMDsgaSA8IGFkZHMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgIHRoaXMuYWRkVGFnKGFkZHNbaV0pO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgYWRkVGFnKHRhZykge1xuICAgICAgICBpZiAodGFnLmluZGV4T2YoJyAnKSA9PT0gLTEpIHtcbiAgICAgICAgICAgIGlmIChVdGlscy5pc1VjQ2hhcih0YWcuY2hhckNvZGVBdCgwKSkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl90aHJvd0Vycm9yKFwiVGFnIG1heSBub3Qgc3RhcnQgd2l0aCBhbiB1cHBlciBjYXNlIGNoYXJhY3Rlci5cIik7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRoaXMuX2FkZFRhZyh0YWcpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29uc3QgdGFncyA9IHRhZy5zcGxpdCgnICcpO1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG0gPSB0YWdzLmxlbmd0aDsgaSA8IG07IGkrKykge1xuICAgICAgICAgICAgICAgIGNvbnN0IHRhZyA9IHRhZ3NbaV07XG5cbiAgICAgICAgICAgICAgICBpZiAoVXRpbHMuaXNVY0NoYXIodGFnLmNoYXJDb2RlQXQoMCkpKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3Rocm93RXJyb3IoXCJUYWcgbWF5IG5vdCBzdGFydCB3aXRoIGFuIHVwcGVyIGNhc2UgY2hhcmFjdGVyLlwiKTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICB0aGlzLl9hZGRUYWcodGFnKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9hZGRUYWcodGFnKSB7XG4gICAgICAgIGlmICghdGhpcy5fX3RhZ3MpIHtcbiAgICAgICAgICAgIHRoaXMuX190YWdzID0gW107XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX190YWdzLmluZGV4T2YodGFnKSA9PT0gLTEpIHtcbiAgICAgICAgICAgIHRoaXMuX190YWdzLnB1c2godGFnKTtcblxuICAgICAgICAgICAgLy8gQWRkIHRvIHRyZWVUYWdzIGhpZXJhcmNoeS5cbiAgICAgICAgICAgIGxldCBwID0gdGhpcy5fX3BhcmVudDtcbiAgICAgICAgICAgIGlmIChwKSB7XG4gICAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgICAgICBpZiAoIXAuX190cmVlVGFncykge1xuICAgICAgICAgICAgICAgICAgICAgICAgcC5fX3RyZWVUYWdzID0gbmV3IE1hcCgpO1xuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgbGV0IHMgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICAgICAgICAgIGlmICghcykge1xuICAgICAgICAgICAgICAgICAgICAgICAgcyA9IG5ldyBTZXQoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHAuX190cmVlVGFncy5zZXQodGFnLCBzKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIHMuYWRkKHRoaXMpO1xuXG4gICAgICAgICAgICAgICAgfSB3aGlsZSAoIXAuX190YWdSb290ICYmIChwID0gcC5fX3BhcmVudCkpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgcmVtb3ZlVGFnKHRhZykge1xuICAgICAgICBsZXQgaSA9IHRoaXMuX190YWdzLmluZGV4T2YodGFnKTtcbiAgICAgICAgaWYgKGkgIT09IC0xKSB7XG4gICAgICAgICAgICB0aGlzLl9fdGFncy5zcGxpY2UoaSwgMSk7XG5cbiAgICAgICAgICAgIC8vIFJlbW92ZSBmcm9tIHRyZWVUYWdzIGhpZXJhcmNoeS5cbiAgICAgICAgICAgIGxldCBwID0gdGhpcy5fX3BhcmVudDtcbiAgICAgICAgICAgIGlmIChwKSB7XG4gICAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgICAgICBsZXQgbGlzdCA9IHAuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGxpc3QpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxpc3QuZGVsZXRlKHRoaXMpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSB3aGlsZSAoIXAuX190YWdSb290ICYmIChwID0gcC5fX3BhcmVudCkpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgaGFzVGFnKHRhZykge1xuICAgICAgICByZXR1cm4gKHRoaXMuX190YWdzICYmICh0aGlzLl9fdGFncy5pbmRleE9mKHRhZykgIT09IC0xKSk7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogUmV0dXJucyBvbmUgb2YgdGhlIGVsZW1lbnRzIGZyb20gdGhlIHN1YnRyZWUgdGhhdCBoYXZlIHRoaXMgdGFnLlxuICAgICAqIEBwYXJhbSB7c3RyaW5nfSB0YWdcbiAgICAgKiBAcmV0dXJucyB7RWxlbWVudH1cbiAgICAgKi9cbiAgICBfdGFnKHRhZykge1xuICAgICAgICBpZiAodGFnLmluZGV4T2YoXCIuXCIpICE9PSAtMSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMubXRhZyh0YWcpWzBdO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHRoaXMuX190cmVlVGFncykge1xuICAgICAgICAgICAgICAgIGxldCB0ID0gdGhpcy5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgICAgICAgICAgIGlmICh0KSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGl0ZW0gPSB0LnZhbHVlcygpLm5leHQoKTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGl0ZW0gPyBpdGVtLnZhbHVlIDogdW5kZWZpbmVkO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBnZXQgdGFnKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdGFnO1xuICAgIH1cblxuICAgIHNldCB0YWcodCkge1xuICAgICAgICB0aGlzLnRhZ3MgPSB0O1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFJldHVybnMgYWxsIGVsZW1lbnRzIGZyb20gdGhlIHN1YnRyZWUgdGhhdCBoYXZlIHRoaXMgdGFnLlxuICAgICAqIEBwYXJhbSB7c3RyaW5nfSB0YWdcbiAgICAgKiBAcmV0dXJucyB7RWxlbWVudFtdfVxuICAgICAqL1xuICAgIG10YWcodGFnKSB7XG4gICAgICAgIGxldCBpZHggPSB0YWcuaW5kZXhPZihcIi5cIik7XG4gICAgICAgIGlmIChpZHggPj0gMCkge1xuICAgICAgICAgICAgbGV0IHBhcnRzID0gdGFnLnNwbGl0KCcuJyk7XG4gICAgICAgICAgICBsZXQgcmVzID0gdGhpcy5fZ2V0QnlUYWcocGFydHNbMF0pO1xuICAgICAgICAgICAgbGV0IGxldmVsID0gMTtcbiAgICAgICAgICAgIGxldCBjID0gcGFydHMubGVuZ3RoO1xuICAgICAgICAgICAgd2hpbGUgKHJlcy5sZW5ndGggJiYgbGV2ZWwgPCBjKSB7XG4gICAgICAgICAgICAgICAgbGV0IHJlc24gPSBbXTtcbiAgICAgICAgICAgICAgICBmb3IgKGxldCBqID0gMCwgbiA9IHJlcy5sZW5ndGg7IGogPCBuOyBqKyspIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzbiA9IHJlc24uY29uY2F0KHJlc1tqXS5fZ2V0QnlUYWcocGFydHNbbGV2ZWxdKSk7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgcmVzID0gcmVzbjtcbiAgICAgICAgICAgICAgICBsZXZlbCsrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIHJlcztcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9nZXRCeVRhZyh0YWcpO1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIHN0YWcodGFnLCBzZXR0aW5ncykge1xuICAgICAgICBsZXQgdCA9IHRoaXMubXRhZyh0YWcpO1xuICAgICAgICBsZXQgbiA9IHQubGVuZ3RoO1xuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgQmFzZS5wYXRjaE9iamVjdCh0W2ldLCBzZXR0aW5ncyk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgdGFnUm9vdCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX190YWdSb290O1xuICAgIH1cblxuICAgIHNldCB0YWdSb290KHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX190YWdSb290ICE9PSB2KSB7XG4gICAgICAgICAgICBpZiAoIXYpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9zZXRUYWdzUGFyZW50KCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX3Vuc2V0VGFnc1BhcmVudCgpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLl9fdGFnUm9vdCA9IHY7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzZWwocGF0aCkge1xuICAgICAgICBjb25zdCByZXN1bHRzID0gdGhpcy5zZWxlY3QocGF0aCk7XG4gICAgICAgIGlmIChyZXN1bHRzLmxlbmd0aCkge1xuICAgICAgICAgICAgcmV0dXJuIHJlc3VsdHNbMF07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdW5kZWZpbmVkO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2VsZWN0KHBhdGgpIHtcbiAgICAgICAgaWYgKHBhdGguaW5kZXhPZihcIixcIikgIT09IC0xKSB7XG4gICAgICAgICAgICBsZXQgc2VsZWN0b3JzID0gcGF0aC5zcGxpdCgnLCcpO1xuICAgICAgICAgICAgbGV0IHJlcyA9IFtdO1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzZWxlY3RvcnMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgICAgICByZXMgPSByZXMuY29uY2F0KHRoaXMuX3NlbGVjdChzZWxlY3RvcnNbaV0pKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiByZXM7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fc2VsZWN0KHBhdGgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX3NlbGVjdChwYXRoKSB7XG4gICAgICAgIGlmIChwYXRoID09PSBcIlwiKSByZXR1cm4gW3RoaXNdO1xuXG5cbiAgICAgICAgbGV0IHBvaW50SWR4ID0gcGF0aC5pbmRleE9mKFwiLlwiKTtcbiAgICAgICAgbGV0IGFycm93SWR4ID0gcGF0aC5pbmRleE9mKFwiPlwiKTtcbiAgICAgICAgaWYgKHBvaW50SWR4ID09PSAtMSAmJiBhcnJvd0lkeCA9PT0gLTEpIHtcbiAgICAgICAgICAgIC8vIFF1aWNrIGNhc2UuXG4gICAgICAgICAgICByZXR1cm4gdGhpcy5tdGFnKHBhdGgpO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gRGV0ZWN0IGJ5IGZpcnN0IGNoYXIuXG4gICAgICAgIGxldCBpc1JlZjtcbiAgICAgICAgaWYgKGFycm93SWR4ID09PSAwKSB7XG4gICAgICAgICAgICBpc1JlZiA9IHRydWU7XG4gICAgICAgICAgICBwYXRoID0gcGF0aC5zdWJzdHIoMSk7XG4gICAgICAgIH0gZWxzZSBpZiAocG9pbnRJZHggPT09IDApIHtcbiAgICAgICAgICAgIGlzUmVmID0gZmFsc2U7XG4gICAgICAgICAgICBwYXRoID0gcGF0aC5zdWJzdHIoMSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpc1JlZiA9IGZhbHNlO1xuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIHRoaXMuX3NlbGVjdENoaWxkcyhwYXRoLCBpc1JlZik7XG4gICAgfVxuXG4gICAgX3NlbGVjdENoaWxkcyhwYXRoLCBpc1JlZikge1xuICAgICAgICBjb25zdCBwb2ludElkeCA9IHBhdGguaW5kZXhPZihcIi5cIik7XG4gICAgICAgIGNvbnN0IGFycm93SWR4ID0gcGF0aC5pbmRleE9mKFwiPlwiKTtcblxuICAgICAgICBpZiAocG9pbnRJZHggPT09IC0xICYmIGFycm93SWR4ID09PSAtMSkge1xuICAgICAgICAgICAgaWYgKGlzUmVmKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgcmVmID0gdGhpcy5nZXRCeVJlZihwYXRoKTtcbiAgICAgICAgICAgICAgICByZXR1cm4gcmVmID8gW3JlZl0gOiBbXTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubXRhZyhwYXRoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmICgoYXJyb3dJZHggPT09IC0xKSB8fCAocG9pbnRJZHggIT09IC0xICYmIHBvaW50SWR4IDwgYXJyb3dJZHgpKSB7XG4gICAgICAgICAgICBsZXQgbmV4dDtcbiAgICAgICAgICAgIGNvbnN0IHN0ciA9IHBhdGguc3Vic3RyKDAsIHBvaW50SWR4KTtcbiAgICAgICAgICAgIGlmIChpc1JlZikge1xuICAgICAgICAgICAgICAgIGNvbnN0IHJlZiA9IHRoaXMuZ2V0QnlSZWYoc3RyKTtcbiAgICAgICAgICAgICAgICBuZXh0ID0gcmVmID8gW3JlZl0gOiBbXTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgbmV4dCA9IHRoaXMubXRhZyhzdHIpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgbGV0IHRvdGFsID0gW107XG4gICAgICAgICAgICBjb25zdCBzdWJQYXRoID0gcGF0aC5zdWJzdHIocG9pbnRJZHggKyAxKTtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gbmV4dC5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICB0b3RhbCA9IHRvdGFsLmNvbmNhdChuZXh0W2ldLl9zZWxlY3RDaGlsZHMoc3ViUGF0aCwgZmFsc2UpKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiB0b3RhbDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGxldCBuZXh0O1xuICAgICAgICAgICAgY29uc3Qgc3RyID0gcGF0aC5zdWJzdHIoMCwgYXJyb3dJZHgpO1xuICAgICAgICAgICAgaWYgKGlzUmVmKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgcmVmID0gdGhpcy5nZXRCeVJlZihzdHIpO1xuICAgICAgICAgICAgICAgIG5leHQgPSByZWYgPyBbcmVmXSA6IFtdO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBuZXh0ID0gdGhpcy5tdGFnKHN0cik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBsZXQgdG90YWwgPSBbXTtcbiAgICAgICAgICAgIGNvbnN0IHN1YlBhdGggPSBwYXRoLnN1YnN0cihhcnJvd0lkeCArIDEpO1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAs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mV0dXJuIEVsZW1lbnQuZ2V0UHJldHR5U3RyaW5nKG9iaiwgXCJcIik7XG4gICAgfTtcblxuICAgIHN0YXRpYyBnZXRQcmV0dHlTdHJpbmcob2JqLCBpbmRlbnQpIHtcbiAgICAgICAgbGV0IGNoaWxkcmVuID0gb2JqLmNoaWxkcmVuO1xuICAgICAgICBkZWxldGUgb2JqLmNoaWxkcmVuO1xuXG5cbiAgICAgICAgLy8gQ29udmVydCBzaW5ndWxhciBqc29uIHNldHRpbmdzIG9iamVjdC5cbiAgICAgICAgbGV0IGNvbG9yS2V5cyA9IFtcImNvbG9yXCIsIFwiY29sb3JVbFwiLCBcImNvbG9yVXJcIiwgXCJjb2xvckJsXCIsIFwiY29sb3JCclwiXTtcbiAgICAgICAgbGV0IHN0ciA9IEpTT04uc3RyaW5naWZ5KG9iaiwgZnVuY3Rpb24gKGssIHYpIHtcbiAgICAgICAgICAgIGlmIChjb2xvcktleXMuaW5kZXhPZihrKSAhPT0gLTEpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gXCJDT0xPUltcIiArIHYudG9TdHJpbmcoMTYpICsgXCJdXCI7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gdjtcbiAgICAgICAgfSk7XG4gICAgICAgIHN0ciA9IHN0ci5yZXBsYWNlKC9cIkNPTE9SXFxbKFthLWYwLTldezEsOH0pXFxdXCIvZywgXCIweCQxXCIpO1xuXG4gICAgICAgIGlmIChjaGlsZHJlbikge1xuICAgICAgICAgICAgbGV0IGNoaWxkU3RyID0gXCJcIjtcbiAgICAgICAgICAgIGlmIChVdGlscy5pc09iamVjdExpdGVyYWwoY2hpbGRyZW4pKSB7XG4gICAgICAgICAgICAgICAgbGV0IHJlZnMgPSBPYmplY3Qua2V5cyhjaGlsZHJlbik7XG4gICAgICAgICAgICAgICAgY2hpbGRTdHIgPSBcIlwiO1xuICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gcmVmcy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgY2hpbGRTdHIgKz0gYFxcbiR7aW5kZW50fSAgXCIke3JlZnNbaV19XCI6YFxuICAgICAgICAgICAgICAgICAgICBkZWxldGUgY2hpbGRyZW5bcmVmc1tpXV0ucmVmO1xuICAgICAgICAgICAgICAgICAgICBjaGlsZFN0ciArPSBFbGVtZW50LmdldFByZXR0eVN0cmluZyhjaGlsZHJlbltyZWZzW2ldXSwgaW5kZW50ICsgXCIgIFwiKSArIChpIDwgbiAtIDEgPyBcIixcIiA6IFwiXCIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBsZXQgaXNFbXB0eSA9IChzdHIgPT09IFwie31cIik7XG4gICAgICAgICAgICAgICAgc3RyID0gc3RyLnN1YnN0cigwLCBzdHIubGVuZ3RoIC0gMSkgKyAoaXNFbXB0eSA/IFwiXCIgOiBcIixcIikgKyBjaGlsZFN0ciArIFwiXFxuXCIgKyBpbmRlbnQgKyBcIn1cIjtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgbGV0IG4gPSBjaGlsZHJlbi5sZW5ndGg7XG4gICAgICAgICAgICAgICAgY2hpbGRTdHIgPSBcIltcIjtcbiAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICBjaGlsZFN0ciArPSBFbGVtZW50LmdldFByZXR0eVN0cmluZyhjaGlsZHJlbltpXSwgaW5kZW50ICsgXCIgIFwiKSArIChpIDwgbiAtIDEgPyBcIixcIiA6IFwiXCIpICsgXCJcXG5cIjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgY2hpbGRTdHIgKz0gaW5kZW50ICsgXCJdfVwiO1xuICAgICAgICAgICAgICAgIGxldCBpc0VtcHR5ID0gKHN0ciA9PT0gXCJ7fVwiKTtcbiAgICAgICAgICAgICAgICBzdHIgPSBzdHIuc3Vic3RyKDAsIHN0ci5sZW5ndGggLSAxKSArIChpc0VtcHR5ID8gXCJcIiA6IFwiLFwiKSArIFwiXFxcImNoaWxkcmVuXFxcIjpcXG5cIiArIGluZGVudCArIGNoaWxkU3RyICsgXCJ9XCI7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiBzdHI7XG4gICAgfVxuXG4gICAgZ2V0U2V0dGluZ3MoKSB7XG4gICAgICAgIGxldCBzZXR0aW5ncyA9IHRoaXMuZ2V0Tm9uRGVmYXVsdHMoKTtcblxuICAgICAgICBsZXQgY2hpbGRyZW4gPSB0aGlzLl9jaGlsZHJlbi5nZXQoKTtcbiAgICAgICAgaWYgKGNoaWxkcmVuKSB7XG4gICAgICAgICAgICBsZXQgbiA9IGNoaWxkcmVuLmxlbmd0aDtcbiAgICAgICAgICAgIGlmIChuKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgY2hpbGRBcnJheSA9IFtdO1xuICAgICAgICAgICAgICAgIGxldCBtaXNzaW5nID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgY2hpbGRBcnJheS5wdXNoKGNoaWxkcmVuW2ldLmdldFNldHRpbmdzKCkpO1xuICAgICAgICAgICAgICAgICAgICBtaXNzaW5nID0gbWlzc2luZyB8fCAhY2hpbGRyZW5baV0ucmVmO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmICghbWlzc2luZykge1xuICAgICAgICAgICAgICAgICAgICBzZXR0aW5ncy5jaGlsZHJlbiA9IHt9XG4gICAgICAgICAgICAgICAgICAgIGNoaWxkQXJyYXkuZm9yRWFjaChjaGlsZCA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzZXR0aW5ncy5jaGlsZHJlbltjaGlsZC5yZWZdID0gY2hpbGQ7XG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHNldHRpbmdzLmNoaWxkcmVuID0gY2hpbGRBcnJheTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBzZXR0aW5ncy5pZCA9IHRoaXMuaWQ7XG5cbiAgICAgICAgcmV0dXJuIHNldHRpbmdzO1xuICAgIH1cblxuICAgIGdldE5vbkRlZmF1bHRzKCkge1xuICAgICAgICBsZXQgc2V0dGluZ3MgPSB7fTtcblxuICAgICAgICBpZiAodGhpcy5jb25zdHJ1Y3RvciAhPT0gRWxlbWVudCkge1xuICAgICAgICAgICAgc2V0dGluZ3MudHlwZSA9IHRoaXMuY29uc3RydWN0b3IubmFtZTtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLl9fcmVmKSB7XG4gICAgICAgICAgICBzZXR0aW5ncy5yZWYgPSB0aGlzLl9fcmVmO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuX190YWdzICYmIHRoaXMuX190YWdzLmxlbmd0aCkge1xuICAgICAgICAgICAgc2V0dGluZ3MudGFncyA9IHRoaXMuX190YWdzO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMueCAhPT0gMCkgc2V0dGluZ3MueCA9IHRoaXMueDtcbiAgICAgICAgaWYgKHRoaXMueSAhPT0gMCkgc2V0dGluZ3MueSA9IHRoaXMueTtcbiAgICAgICAgaWYgKHRoaXMudyAhPT0gMCkgc2V0dGluZ3MudyA9IHRoaXMudztcbiAgICAgICAgaWYgKHRoaXMuaCAhPT0gMCkgc2V0dGluZ3MuaCA9IHRoaXMuaDtcblxuICAgICAgICBpZiAodGhpcy5zY2FsZVggPT09IHRoaXMuc2NhbGVZKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5zY2FsZVggIT09IDEpIHNldHRpbmdzLnNjYWxlID0gdGhpcy5zY2FsZVg7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodGhpcy5zY2FsZVggIT09IDEpIHNldHRpbmdzLnNjYWxlWCA9IHRoaXMuc2NhbGVYO1xuICAgICAgICAgICAgaWYgKHRoaXMuc2NhbGVZICE9PSAxKSBzZXR0aW5ncy5zY2FsZVkgPSB0aGlzLnNjYWxlWTtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLnBpdm90WCA9PT0gdGhpcy5waXZvdFkpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLnBpdm90WCAhPT0gMC41KSBzZXR0aW5ncy5waXZvdCA9IHRoaXMucGl2b3RYO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHRoaXMucGl2b3RYICE9PSAwLjUpIHNldHRpbmdzLnBpdm90WCA9IHRoaXMucGl2b3RYO1xuICAgICAgICAgICAgaWYgKHRoaXMucGl2b3RZICE9PSAwLjUpIHNldHRpbmdzLnBpdm90WSA9IHRoaXMucGl2b3RZO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMubW91bnRYID09PSB0aGlzLm1vdW50WSkge1xuICAgICAgICAgICAgaWYgKHRoaXMubW91bnRYICE9PSAwKSBzZXR0aW5ncy5tb3VudCA9IHRoaXMubW91bnRYO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHRoaXMubW91bnRYICE9PSAwKSBzZXR0aW5ncy5tb3VudFggPSB0aGlzLm1vdW50WDtcbiAgICAgICAgICAgIGlmICh0aGlzLm1vdW50WSAhPT0gMCkgc2V0dGluZ3MubW91bnRZID0gdGhpcy5tb3VudFk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5hbHBoYSAhPT0gMSkgc2V0dGluZ3MuYWxwaGEgPSB0aGlzLmFscGhhO1xuXG4gICAgICAgIGlmICghdGhpcy52aXNpYmxlKSBzZXR0aW5ncy52aXNpYmxlID0gZmFsc2U7XG5cbiAgICAgICAgaWYgKHRoaXMucm90YXRpb24gIT09IDAp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uICAgICAgICBpZiAoIXRoaXMuY2xpcGJveCkgc2V0dGluZ3MuY2xpcGJveCA9IHRoaXMuY2xpcGJveDtcblxuICAgICAgICBpZiAodGhpcy5fX3RleHR1cmUpIHtcbiAgICAgICAgICAgIGxldCB0bmQgPSB0aGlzLl9fdGV4dHVyZS5nZXROb25EZWZhdWx0cygpO1xuICAgICAgICAgICAgaWYgKE9iamVjdC5rZXlzKHRuZCkubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgc2V0dGluZ3MudGV4dHVyZSA9IHRuZDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLnNoYWRlciAmJiBVdGlscy5pc0Z1bmN0aW9uKHRoaXMuc2hhZGVyLmdldE5vbkRlZmF1bHRzKSkge1xuICAgICAgICAgICAgbGV0IHRuZCA9IHRoaXMuc2hhZGVyLmdldE5vbkRlZmF1bHRzKCk7XG4gICAgICAgICAgICBpZiAoT2JqZWN0LmtleXModG5kKS5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICBzZXR0aW5ncy5zaGFkZXIgPSB0bmQ7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5faGFzVGV4dHVyaXplcigpKSB7XG4gICAgICAgICAgICBpZiAodGhpcy50ZXh0dXJpemVyLmVuYWJsZWQpIHtcbiAgICAgICAgICAgICAgICBzZXR0aW5ncy5yZW5kZXJUb1RleHR1cmUgPSB0aGlzLnRleHR1cml6ZXIuZW5hYmxlZDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLnRleHR1cml6ZXIubGF6eSkge1xuICAgICAgICAgICAgICAgIHNldHRpbmdzLnJlbmRlclRvVGV4dHVyZUxhenkgPSB0aGlzLnRleHR1cml6ZXIubGF6eTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLnRleHR1cml6ZXIuY29sb3JpemUpIHtcbiAgICAgICAgICAgICAgICBzZXR0aW5ncy5jb2xvcml6ZVJlc3VsdFRleHR1cmUgPSB0aGlzLnRleHR1cml6ZXIuY29sb3JpemU7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy50ZXh0dXJpemVyLnJlbmRlck9mZnNjcmVlbikge1xuICAgICAgICAgICAgICAgIHNldHRpbmdzLnJlbmRlck9mZnNjcmVlbiA9IHRoaXMudGV4dHVyaXplci5yZW5kZXJPZmZzY3JlZW47XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gc2V0dGluZ3M7XG4gICAgfTtcblxuICAgIHN0YXRpYyBnZXRHZXR0ZXIocHJvcGVydHlQYXRoKSB7XG4gICAgICAgIGxldCBnZXR0ZXIgPSBFbGVtZW50LlBST1BfR0VUVEVSUy5nZXQocHJvcGVydHlQYXRoKTtcbiAgICAgICAgaWYgKCFnZXR0ZXIpIHtcbiAgICAgICAgICAgIGdldHRlciA9IG5ldyBGdW5jdGlvbignb2JqJywgJ3JldHVybiBvYmouJyArIHByb3BlcnR5UGF0aCk7XG4gICAgICAgICAgICBFbGVtZW50LlBST1BfR0VUVEVSUy5zZXQocHJvcGVydHlQYXRoLCBnZXR0ZXIpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBnZXR0ZXI7XG4gICAgfVxuXG4gICAgc3RhdGljIGdldFNldHRlcihwcm9wZXJ0eVBhdGgpIHtcbiAgICAgICAgbGV0IHNldHRlciA9IEVsZW1lbnQuUFJPUF9TRVRURVJTLmdldChwcm9wZXJ0eVBhdGgpO1xuICAgICAgICBpZiAoIXNldHRlcikge1xuICAgICAgICAgICAgc2V0dGVyID0gbmV3IEZ1bmN0aW9uKCdvYmonLCAndicsICdvYmouJyArIHByb3BlcnR5UGF0aCArICcgPSB2Jyk7XG4gICAgICAgICAgICBFbGVtZW50LlBST1BfU0VUVEVSUy5zZXQocHJvcGVydHlQYXRoLCBzZXR0ZXIpO1xuICAgICAgICB9XG4gICAgICAgIH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ybiB0aGlzLl9fY29yZS5vZmZzZXRYO1xuICAgIH1cblxuICAgIHNldCB4KHYpIHtcbiAgICAgICAgdGhpcy5fX2NvcmUub2Zmc2V0WCA9IHY7XG4gICAgfVxuXG4gICAgZ2V0IHkoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fY29yZS5vZmZzZXRZO1xuICAgIH1cblxuICAgIHNldCB5KHYpIHtcbiAgICAgICAgdGhpcy5fX2NvcmUub2Zmc2V0WSA9IHY7XG4gICAgfVxuXG4gICAgZ2V0IHcoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl93O1xuICAgIH1cblxuICAgIHNldCB3KHYpIHtcbiAgICAgICAgaWYgKFV0aWxzLmlzRnVuY3Rpb24odikpIHtcbiAgICAgICAgICAgIHRoaXMuX3cgPSAwO1xuICAgICAgICAgICAgdGhpcy5fX2NvcmUuZnVuY1cgPSB2O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdiA9IE1hdGgubWF4KHYsIDApO1xuICAgICAgICAgICAgaWYgKHRoaXMuX3cgIT09IHYpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9fY29yZS5kaXNhYmxlRnVuY1coKTtcbiAgICAgICAgICAgICAgICB0aGlzLl93ID0gdjtcbiAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVEaW1lbnNpb25zKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgaCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2g7XG4gICAgfVxuXG4gICAgc2V0IGgodikge1xuICAgICAgICBpZiAoVXRpbHMuaXNGdW5jdGlvbih2KSkge1xuICAgICAgICAgICAgdGhpcy5faCA9IDA7XG4gICAgICAgICAgICB0aGlzLl9fY29yZS5mdW5jSCA9IHY7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB2ID0gTWF0aC5tYXgodiwgMCk7XG4gICAgICAgICAgICBpZiAodGhpcy5faCAhPT0gd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JlLnNjYWxlWTtcbiAgICB9XG5cbiAgICBzZXQgc2NhbGVZKHYpIHtcbiAgICAgICAgdGhpcy5fX2NvcmUuc2NhbGVZID0gdjtcbiAgICB9XG5cbiAgICBnZXQgc2NhbGUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fY29yZS5zY2FsZTtcbiAgICB9XG5cbiAgICBzZXQgc2NhbGUodikge1xuICAgICAgICB0aGlzLl9fY29yZS5zY2FsZSA9IHY7XG4gICAgfVxuXG4gICAgZ2V0IHBpdm90WCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLnBpdm90WDtcbiAgICB9XG5cbiAgICBzZXQgcGl2b3RYKHYpIHtcbiAgICAgICAgdGhpcy5fX2NvcmUucGl2b3RYID0gdjtcbiAgICB9XG5cbiAgICBnZXQgcGl2b3RZKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUucGl2b3RZO1xuICAgIH1cblxuICAgIHNldCBwaXZvdFkodikge1xuICAgICAgICB0aGlzLl9fY29yZS5waXZvdFkgPSB2O1xuICAgIH1cblxuICAgIGdldCBwaXZvdCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLnBpdm90O1xuICAgIH1cblxuICAgIHNldCBwaXZvdCh2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLnBpdm90ID0gdjtcbiAgICB9XG5cbiAgICBnZXQgbW91bnRYKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUubW91bnRYO1xuICAgIH1cblxuICAgIHNldCBtb3VudFgodikge1xuICAgICAgICB0aGlzLl9fY29yZS5tb3VudFggPSB2O1xuICAgIH1cblxuICAgIGdldCBtb3VudFkoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fY29yZS5tb3VudFk7XG4gICAgfVxuXG4gICAgc2V0IG1vdW50WSh2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLm1vdW50WSA9IHY7XG4gICAgfVxuXG4gICAgZ2V0IG1vdW50KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUubW91bnQ7XG4gICAgfVxuXG4gICAgc2V0IG1vdW50KHYpIHtcbiAgICAgICAgdGhpcy5fX2NvcmUubW91bnQgPSB2O1xuICAgIH1cblxuICAgIGdldCByb3RhdGlvbigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLnJvdGF0aW9uO1xuICAgIH1cblxuICAgIHNldCByb3RhdGlvbih2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLnJvdGF0aW9uID0gdjtcbiAgICB9XG5cbiAgICBnZXQgYWxwaGEoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fY29yZS5hbHBoYTtcbiAgICB9XG5cbiAgICBzZXQgYWxwaGEodikge1xuICAgICAgICB0aGlzLl9fY29yZS5hbHBoYSA9IHY7XG4gICAgfVxuXG4gICAgZ2V0IHZpc2libGUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fY29yZS52aXNpYmxlO1xuICAgIH1cblxuICAgIHNldCB2aXNpYmxlKHYpIHtcbiAgICAgICAgdGhpcy5fX2NvcmUudmlzaWJsZSA9IHY7XG4gICAgfVxuICAgIFxuICAgIGdldCBjb2xvclVsKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUuY29sb3JVbDtcbiAgICB9XG5cbiAgICBzZXQgY29sb3JVbCh2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLmNvbG9yVWwgPSB2O1xuICAgIH1cblxuICAgIGdldCBjb2xvclVyKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUuY29sb3JVcjtcbiAgICB9XG5cbiAgICBzZXQgY29sb3JVcih2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLmNvbG9yVXIgPSB2O1xuICAgIH1cblxuICAgIGdldCBjb2xvckJsKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUuY29sb3JCbDtcbiAgICB9XG5cbiAgICBzZXQgY29sb3JCbCh2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLmNvbG9yQmwgPSB2O1xuICAgIH1cblxuICAgIGdldCBjb2xvckJyKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUuY29sb3JCcjtcbiAgICB9XG5cbiAgICBzZXQgY29sb3JCcih2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLmNvbG9yQnIgPSB2O1xuICAgIH1cblxuICAgIGdldCBjb2xvcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLmNvbG9yVWw7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuY29sb3JVbCAhPT0gdiB8fCB0aGlzLmNvbG9yVXIgIT09IHYgfHwgdGhpcy5jb2xvckJsICE9PSB2IHx8IHRoaXMuY29sb3JCciAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5jb2xvclVsID0gdjtcbiAgICAgICAgICAgIHRoaXMuY29sb3JVciA9IHY7XG4gICAgICAgICAgICB0aGlzLmNvbG9yQmwgPSB2O1xuICAgICAgICAgICAgdGhpcy5jb2xvckJyID0gdjtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBjb2xvclRvcCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuY29sb3JVbDtcbiAgICB9XG5cbiAgICBzZXQgY29sb3JUb3Aodikge1xuICAgICAgICBpZiAodGhpcy5jb2xvclVsICE9PSB2IHx8IHRoaXMuY29sb3JVciAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5jb2xvclVsID0gdjtcbiAgICAgICAgICAgIHRoaXMuY29sb3JVciA9IHY7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgY29sb3JCb3R0b20oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLmNvbG9yQmw7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yQm90dG9tKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuY29sb3JCbCAhPT0gdiB8fCB0aGlzLmNvbG9yQnIgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuY29sb3JCbCA9IHY7XG4gICAgICAgICAgICB0aGlzLmNvbG9yQnIgPSB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGNvbG9yTGVmdCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuY29sb3JVbDtcbiAgICB9XG5cbiAgICBzZXQgY29sb3JMZWZ0KHYpIHtcbiAgICAgICAgaWYgKHRoaXMuY29sb3JVbCAhPT0gdiB8fCB0aGlzLmNvbG9yQmwgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuY29sb3JVbCA9IHY7XG4gICAgICAgICAgICB0aGlzLmNvbG9yQmwgPSB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGNvbG9yUmlnaHQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLmNvbG9yVXI7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yUmlnaHQodikge1xuICAgICAgICBpZiAodGhpcy5jb2xvclVyICE9PSB2IHx8IHRoaXMuY29sb3JCciAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5jb2xvclVyID0gdjtcbiAgICAgICAgICAgIHRoaXMuY29sb3JCciA9IHY7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgekluZGV4KCkge3JldHVybiB0aGlzLl9fY29yZS56SW5kZXh9XG4gICAgc2V0IHpJbmRleCh2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLnpJbmRleCA9IHY7XG4gICAgfVxuXG4gICAgZ2V0IGZvcmNlWkluZGV4Q29udGV4dCgpIHtyZXR1cm4gdGhpcy5fX2NvcmUuZm9yY2VaSW5kZXhDb250ZXh0fVxuICAgIHNldCBmb3JjZVpJbmRleENvbnRleHQodikge1xuICAgICAgICB0aGlzLl9fY29yZS5mb3JjZVpJbmRleENvbnRleHQgPSB2O1xuICAgIH1cblxuICAgIGdldCBjbGlwcG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3ZlRWxlbWVudCh0aGlzLl9fY29yZSk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRoaXMuX19jb3JlLnNoYWRlciA9IHNoYWRlcjtcblxuICAgICAgICAgICAgaWYgKHRoaXMuX19lbmFibGVkICYmIHRoaXMuX19jb3JlLnNoYWRlcikge1xuICAgICAgICAgICAgICAgIHRoaXMuX19jb3JlLnNoYWRlci5hZGRFbGVtZW50KHRoaXMuX19jb3JlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9oYXNUZXh0dXJpemVyKCkge1xuICAgICAgICByZXR1cm4gISF0aGlzLl9fY29yZS5fdGV4dHVyaXplcjtcbiAgICB9XG5cbiAgICBnZXQgcmVuZGVyVG9UZXh0dXJlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5ydHRcbiAgICB9XG5cbiAgICBzZXQgcmVuZGVyVG9UZXh0dXJlKHYpIHtcbiAgICAgICAgdGhpcy5ydHQgPSB2XG4gICAgfVxuXG4gICAgZ2V0IHJ0dCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2hhc1RleHR1cml6ZXIoKSAmJiB0aGlzLnRleHR1cml6ZXIuZW5hYmxlZDtcbiAgICB9XG5cbiAgICBzZXQgcnR0KHYpIHtcbiAgICAgICAgdGhpcy50ZXh0dXJpemVyLmVuYWJsZWQgPSB2O1xuICAgIH1cblxuICAgIGdldCBydHRMYXp5KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faGFzVGV4dHVyaXplcigpICYmIHRoaXMudGV4dHVyaXplci5sYXp5O1xuICAgIH1cblxuICAgIHNldCBydHRMYXp5KHYpIHtcbiAgICAgICAgdGhpcy50ZXh0dXJpemVyLmxhenkgPSB2O1xuICAgIH1cblxuICAgIGdldCByZW5kZXJPZmZzY3JlZW4oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9oYXNUZXh0dXJpemVyKCkgJiYgdGhpcy50ZXh0dXJpemVyLnJlbmRlck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mKHBhdGgpO1xuICAgICAgICAgICAgICAgIGlmICghY2hpbGQpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHYgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gQWRkIHRvIGxpc3QgaW1tZWRpYXRlbHkuXG4gICAgICAgICAgICAgICAgICAgICAgICBsZXQgYztcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChVdGlscy5pc09iamVjdExpdGVyYWwodikpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBDYXRjaCB0aGlzIGNhc2UgdG8gY2FwdHVyZSBjcmVhdGVNb2RlIGZsYWcuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgYyA9IHRoaXMuY2hpbGRMaXN0LmNyZWF0ZUl0ZW0odik7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgYy5wYXRjaCh2KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMuaXNPYmplY3QodikpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjID0gdjtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjLmlzRWxlbWVudCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGMucmVmID0gcGF0aDtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QuYShjKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICh2ID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjaGlsZC5wYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGlsZC5wYXJlbnQuY2hpbGRMaXN0LnJlbW92ZShjaGlsZCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKHYpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjaGlsZC5wYXRjaCh2KTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICh2LmlzRWxlbWVudCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gUmVwbGFjZSBlbGVtZW50IGJ5IG5ldyBlbGVtZW50LlxuICAgICAgICAgICAgICAgICAgICAgICAgdi5yZWYgPSBwYXRoO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QucmVwbGFjZSh2LCBjaGlsZCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl90aHJvd0Vycm9yKFwiVW5leHBlY3RlZCB2YWx1ZSBmb3IgcGF0aDogXCIgKyBwYXRoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gUHJvcGVydHkuXG4gICAgICAgICAgICAgICAgQmFzZS5wYXRjaE9iamVjdFByb3BlcnR5KHRoaXMsIHBhdGgsIHYpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgX3Rocm93RXJyb3IobWVzc2FnZSkge1xuICAgICAgICB0aHJvdyBuZXcgRXJyb3IodGhpcy5jb25zdHJ1Y3Rvci5uYW1lICsgXCIgKFwiICsgdGhpcy5nZXRMb2NhdGlvblN0cmluZygpICsgXCIpOiBcIiArIG1lc3NhZ2UpO1xuICAgIH1cblxuICAgIGFuaW1hdGlvbihzZXR0aW5ncykge1xuICAgICAgICByZXR1cm4gdGhpcy5zdGFnZS5hbmltYXRpb25zLmNyZWF0ZUFuaW1hdGlvbih0aGlzLCBzZXR0aW5ncyk7XG4gICAg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G4gICAgICAgICAgICAgICAgdGhpcy5zZXRTbW9vdGgocHJvcGVydHksIHZhbHVlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgZmFzdEZvcndhcmQocHJvcGVydHkpIHtcbiAgICAgICAgaWYgKHRoaXMuX3RyYW5zaXRpb25zKSB7XG4gICAgICAgICAgICBsZXQgdCA9IHRoaXMuX3RyYW5zaXRpb25zW3Byb3BlcnR5XTtcbiAgICAgICAgICAgIGlmICh0ICYmIHQuaXNUcmFuc2l0aW9uKSB7XG4gICAgICAgICAgICAgICAgdC5maW5pc2goKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9nZXRUcmFuc2l0aW9uKHByb3BlcnR5KSB7XG4gICAgICAgIGlmICghdGhpcy5fdHJhbnNpdGlvbnMpIHtcbiAgICAgICAgICAgIHRoaXMuX3RyYW5zaXRpb25zID0ge307XG4gICAgICAgIH1cbiAgICAgICAgbGV0IHQgPSB0aGlzLl90cmFuc2l0aW9uc1twcm9wZXJ0eV07XG4gICAgICAgIGlmICghdCkge1xuICAgICAgICAgICAgLy8gQ3JlYXRlIGRlZmF1bHQgdHJhbnNpdGlvbi5cbiAgICAgICAgICAgIHQgPSBuZXcgVHJhbnNpdGlvbih0aGlzLnN0YWdlLnRyYW5zaXRpb25zLCB0aGlzLnN0YWdlLnRyYW5zaXRpb25zLmRlZmF1bHRUcmFuc2l0aW9uU2V0dGluZ3MsIHRoaXMsIHByb3BlcnR5KTtcbiAgICAgICAgfSBlbHNlIGlmICh0LmlzVHJhbnNpdGlvblNldHRpbmdzKSB7XG4gICAgICAgICAgICAvLyBVcGdyYWRlIHRvICdyZWFsJyB0cmFuc2l0aW9uLlxuICAgICAgICAgICAgdCA9IG5ldyBUcmFuc2l0aW9uKFxuICAgICAgICAgICAgICAgIHRoaXMuc3RhZ2UudHJhbnNpdGlvbnMsXG4gICAgICAgICAgICAgICAgdCxcbiAgICAgICAgICAgICAgICB0aGlzLFxuICAgICAgICAgICAgICAgIHByb3BlcnR5XG4gICAgICAgICAgICApO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX3RyYW5zaXRpb25zW3Byb3BlcnR5XSA9IHQ7XG4gICAgICAgIHJldHVybiB0O1xuICAgIH1cblxuICAgIF9zZXRUcmFuc2l0aW9uKHByb3BlcnR5LCBzZXR0aW5ncykge1xuICAgICAgICBpZiAoIXNldHRpbmdzKSB7XG4gICAgICAgICAgICB0aGlzLl9yZW1vdmVUcmFuc2l0aW9uKHByb3BlcnR5KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChVdGlscy5pc09iamVjdExpdGVyYWwoc2V0dGluZ3MpKSB7XG4gICAgICAgICAgICAgICAgLy8gQ29udmVydCBwbGFpbiBvYmplY3QgdG8gcHJvcGVyIHNldHRpbmdzIG9iamVjdC5cbiAgICAgICAgICAgICAgICBzZXR0aW5ncyA9IHRoaXMuc3RhZ2UudHJhbnNpdGlvbnMuY3JlYXRlU2V0dGluZ3Moc2V0dGluZ3MpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoIXRoaXMuX3RyYW5zaXRpb25zKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fdHJhbnNpdGlvbnMgPSB7fTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgbGV0IGN1cnJlbnQgPSB0aGlzLl90cmFuc2l0aW9uc1twcm9wZXJ0eV07XG4gICAgICAgICAgICBpZiAoY3VycmVudCAmJiBjdXJyZW50LmlzVHJhbnNpdGlvbikge1xuICAgICAgICAgICAgICAgIC8vIFJ1bnRpbWUgc2V0dGluZ3MgY2hhbmdlLlxuICAgICAgICAgICAgICAgIGN1cnJlbnQuc2V0dGluZ3MgPSBzZXR0aW5ncztcbiAgICAgICAgICAgICAgICByZXR1cm4gY3VycmVudDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gSW5pdGl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CJtb3VudFwiLCBcIm1vdW50WVwiLCBcIm1vdW50WFwiLCBcInBpdm90XCIsIFwicGl2b3RYXCIsIFwicGl2b3RZXCIsIFwicmVmXCIsIFwicmVuZGVyT2Zmc2NyZWVuXCIsIFwicmVuZGVyVG9UZXh0dXJlXCIsIFwic2NhbGVcIixcbiAgICAgICAgICAgIFwic2NhbGVYXCIsIFwic2NhbGVZXCIsIFwic3RhdGVcIiwgXCJ0YWdcIiwgXCJ2aXNpYmxlXCIsIFwid1wiLCBcInhcIiwgXCJ5XCIsIFwiekluZGV4XCIsXG4gICAgICAgICAgICBcIiEhZmxleFwiLCBcIiEhZmxleEl0ZW1cIiwgXCJoYXNGb2N1cygpXCIsIFwiaGFzRmluYWxGb2N1cygpXCJcbiAgICAgICAgXTtcbiAgICAgICAgbGV0IG4gPSBsaXN0Lmxlbmd0aDtcblxuICAgICAgICB3aGlsZSAobi0tKSB7XG4gICAgICAgICAgICBsZXQga2V5ID0gbGlzdFtuXTtcbiAgICAgICAgICAgIGNvbnN0IGdldEJvb2xlYW4gPSAvXiF7Mn0vO1xuICAgICAgICAgICAgY29uc3QgaXNGdW5jdGlvbiA9IC9cXChcXCkkLztcblxuICAgICAgICAgICAgaWYgKGdldEJvb2xlYW4udGVzdChrZXkpKSB7XG4gICAgICAgICAgICAgICAga2V5ID0ga2V5LnN1YnN0cmluZygyLCBrZXkubGVuZ3RoKTtcbiAgICAgICAgICAgICAgICBwcm9wc1trZXldID0gISFlbGVtZW50W2tleV07XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGlzRnVuY3Rpb24udGVzdChrZXkpKSB7XG4gICAgICAgICAgICAgICAga2V5ID0ga2V5LnN1YnN0cmluZygwLCBrZXkubGVuZ3RoIC0gMik7XG4gICAgICAgICAgICAgICAgaWYgKHR5cGVvZiBlbGVtZW50W2tleV0gPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICAgICAgICAgICAgICBwcm9wc1trZXldID0gZWxlbWVudFtrZXldKCk7XG4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XG4gICAgfVxuXG4gICAgZ2V0KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faXRlbXM7XG4gICAgfVxuXG4gICAgZ2V0IGZpcnN0KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faXRlbXNbMF07XG4gICAgfVxuXG4gICAgZ2V0IGxhc3QoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9pdGVtcy5sZW5ndGggPyB0aGlzLl9pdGVtc1t0aGlzLl9pdGVtcy5sZW5ndGggLSAxXSA6IHVuZGVmaW5lZDtcbiAgICB9XG5cbiAgICBhZGQoaXRlbSkge1xuICAgICAgICB0aGlzLmFkZEF0KGl0ZW0sIHRoaXMuX2l0ZW1zLmxlbmd0aCk7XG4gICAgfVxuXG4gICAgYWRkQXQoaXRlbSwgaW5kZXgpIHtcbiAgICAgICAgaWYgKGluZGV4ID49IDAgJiYgaW5kZXggPD0gdGhpcy5faXRlbXMubGVuZ3RoKSB7XG4gICAgICAgICAgICBsZXQgY3VycmVudEluZGV4ID0gdGhpcy5faXRlbXMuaW5kZXhPZihpdGVtKTtcbiAgICAgICAgICAgIGlmIChjdXJyZW50SW5kZXggPT09IGluZGV4KSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGl0ZW07XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChVdGlscy5pc09iamVjdExpdGVyYWwoaXRlbSkpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBvID0gaXRlbTtcbiAgICAgICAgICAgICAgICBpdGVtID0gdGhpcy5jcmVhdGVJdGVtKG8pO1xuICAgICAgICAgICAgICAgIGl0ZW0ucGF0Y2gobyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChjdXJyZW50SW5kZXggIT0gLTEpIHtcbiAgICAgICAgICAgICAgICB0aGlzLnNldEF0KGl0ZW0sIGluZGV4KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaWYgKGl0ZW0ucmVmKSB7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LmdldEluZGV4KHByZXZJdGVtKTtcbiAgICAgICAgaWYgKGluZGV4ID09PSAtMSkge1xuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdyZXBsYWNlOiBUaGUgcHJldmlvdXMgaXRlbSBkb2VzIG5vdCBleGlzdCcpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuc2V0QXQoaXRlbSwgaW5kZXgpO1xuICAgIH1cblxuICAgIHNldEF0KGl0ZW0sIGluZGV4KSB7XG4gICAgICAgIGlmIChpbmRleCA+PSAwICYmIGluZGV4IDw9IHRoaXMuX2l0ZW1zLmxlbmd0aCkge1xuXG4gICAgICAgICAgICBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKGl0ZW0pKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgbyA9IGl0ZW07XG4gICAgICAgICAgICAgICAgaXRlbSA9IHRoaXMuY3JlYXRlSXRlbShvKTtcbiAgICAgICAgICAgICAgICBpdGVtLnBhdGNoKG8pO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBsZXQgY3VycmVudEluZGV4ID0gdGhpcy5faXRlbXMuaW5kZXhPZihpdGVtKTtcbiAgICAgICAgICAgIGlmIChjdXJyZW50SW5kZXggIT0gLTEpIHtcbiAgICAgICAgICAgICAgICBpZiAoY3VycmVudEluZGV4ICE9PSBpbmRleCkge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBmcm9tSW5kZXggPSBjdXJyZW50SW5kZXg7XG4gICAgICAgICAgICAgICAgICAgIGlmIChmcm9tSW5kZXggIT09IGluZGV4KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9pdGVtcy5zcGxpY2UoZnJvbUluZGV4LCAxKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2l0ZW1zLnNwbGljZShpbmRleCwgMCwgaXRlbSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLm9uTW92ZShpdGVtLCBmcm9tSW5kZXgsIGluZGV4KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaWYoIGluZGV4IDwgdGhpcy5faXRlbXMubGVuZ3RoKXtcblxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5faXRlbXNbaW5kZXhdLnJlZikge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcmVmc1t0aGlzLl9pdGVtc1tpbmRleF0ucmVmXSA9IHVuZGVmaW5lZDtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHByZXZJdGVtID0gdGhpcy5faXRlbXNbaW5kZXhdO1xuXG4gICAgICAgICAgICAgICAgICAgIC8vIERvZXNuJ3QgZXhpc3QgeWV0OiBvdmVyd3JpdGUgY3VycmVudC5cbiAgICAgICAgICAgICAgICAgICAgdGhpcy5faXRlbXNbaW5kZXhdID0gaXRlbTtcblxuICAgICAgICAgICAgICAgICAgICBpZiAoaXRlbS5yZWYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlZnNbaXRlbS5yZWZdID0gaXRlbTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMub25TZXQoaXRlbSwgaW5kZXgsIHByZXZJdGVtKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ3NldEF0OiBUaGUgaW5kZXggJyArIGluZGV4ICsgJyBpcyBvdXQgb2YgYm91bmRzICcgKyB0aGlzLl9pdGVtcy5sZW5ndGgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignc2V0QXQ6IFRoZSBpbmRleCAnICsgaW5kZXggKyAnIGlzIG91dCBvZiBib3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iAgICAgICAgbGV0IG4gPSB0aGlzLl9pdGVtcy5sZW5ndGg7XG4gICAgICAgIGlmIChuKSB7XG4gICAgICAgICAgICBsZXQgcHJldiA9IHRoaXMuX2l0ZW1zO1xuICAgICAgICAgICAgdGhpcy5faXRlbXMgPSBbXTtcbiAgICAgICAgICAgIHRoaXMuX3JlZnMgPSB7fVxuICAgICAgICAgICAgdGhpcy5vblN5bmMocHJldiwgW10sIFtdKTtcbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBhKG8pIHtcbiAgICAgICAgaWYgKFV0aWxzLmlzT2JqZWN0TGl0ZXJhbChvKSkge1xuICAgICAgICAgICAgbGV0IGMgPSB0aGlzLmNyZWF0ZUl0ZW0obyk7XG4gICAgICAgICAgICBjLnBhdGNoKG8pO1xuICAgICAgICAgICAgdGhpcy5hZGQoYyk7XG4gICAgICAgICAgICByZXR1cm4gYztcbiAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KG8pKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IG8ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5hKG9baV0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5pc0l0ZW0obykpIHtcbiAgICAgICAgICAgIHRoaXMuYWRkKG8pO1xuICAgICAgICAgICAgcmV0dXJuIG87XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgZ2V0IGxlbmd0aCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2l0ZW1zLmxlbmd0aDtcbiAgICB9XG5cbiAgICBfZ2V0UmVmcygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JlZnM7XG4gICAgfVxuXG4gICAgZ2V0QnlSZWYocmVmKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9yZWZzW3JlZl07XG4gICAgfVxuXG4gICAgY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AgICAgICAgIHRoaXMuYWRkKHMpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIENyZWF0ZSBuZXcgaXRlbS5cbiAgICAgICAgICAgICAgICAgICAgYyA9IHRoaXMuY3JlYXRlSXRlbShzKTtcbiAgICAgICAgICAgICAgICAgICAgYy5yZWYgPSBjcmVmO1xuICAgICAgICAgICAgICAgICAgICBjLnBhdGNoKHMpO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmFkZChjKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLmlzSXRlbShzKSkge1xuICAgICAgICAgICAgICAgICAgICBpZiAoYyAhPT0gcykge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gUmVwbGFjZSBwcmV2aW91cyBpdGVtO1xuICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGlkeCA9IHRoaXMuZ2V0SW5kZXgoYyk7XG4gICAgICAgICAgICAgICAgICAgICAgICBzLnJlZiA9IGNyZWY7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnNldEF0KHMsIGlkeCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBjLnBhdGNoKHMpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9lcXVhbHNBcnJheShhcnJheSkge1xuICAgICAgICBsZXQgc2FtZSA9IHRydWU7XG4gICAgICAgIGlmIChhcnJheS5sZW5ndGggPT09IHRoaXMuX2l0ZW1zLmxlbmd0aCkge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9pdGVtcy5sZW5ndGg7IChpIDwgbikgJiYgc2FtZTsgaSsrKSB7XG4gICAgICAgICAgICAgICAgc2FtZSA9IHNhbWUgJiYgKHRoaXMuX2l0ZW1zW2ldID09PSBhcnJheVtpXSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzYW1lID0gZmFsc2U7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHNhbWU7XG4gICAgfVxuXG4gICAgX3NldEJ5QXJyYXkoYXJyYXkpIHtcbiAgICAgICAgLy8gRm9yIHBlcmZvcm1hbmNlIHJlYXNvbnMsIGZpcnN0IGNoZWNrIGlmIHRoZSBhcnJheXMgbWF0Y2ggZXhhY3RseSBhbmQgYmFpbCBvdXQgaWYgdGhleSBkby5cbiAgICAgICAgaWYgKHRoaXMuX2VxdWFsc0FycmF5KGFycmF5KSkge1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG5cbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9pdGVtcy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIHRoaXMuX2l0ZW1zW2ldLm1hcmtlciA9IHRydWU7XG4gICAgICAgIH1cblxuICAgICAgICBsZXQgcmVmcztcbiAgICAgICAgbGV0IG5ld0l0ZW1zID0gW107XG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gYXJyYXkubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBsZXQgcyA9IGFycmF5W2ldO1xuICAgICAgICAgICAgaWYgKHRoaXMuaXNJdGVtKHMpKSB7XG4gICAgICAgICAgICAgICAgcy5tYXJrZXIgPSBmYWxzZTtcbiAgICAgICAgICAgICAgICBuZXdJdGVtcy5wdXNoKHMpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBsZXQgY3JlZiA9IHMucmVmO1xuICAgICAgICAgICAgICAgIGxldCBjO1xuICAgICAgICAgICAgICAgIGlmIChjcmVmKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICghcmVmcykgcmVmcyA9IHRoaXMuX2dldFJlZnMoKTtcbiAgICAgICAgICAgICAgICAgICAgYyA9IHJlZnNbY3JlZl07XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaWYgKCFjKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIENyZWF0ZSBuZXcgaXRlbS5cbiAgICAgICAgICAgICAgICAgICAgYyA9IHRoaXMuY3JlYXRlSXRlbShzKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBjLm1hcmtlciA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmIChVdGlscy5pc09iamVjdExpdGVyYWwocykpIHtcbiAgICAgICAgICAgICAgICAgICAgYy5wYXRjaChzKTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBuZXdJdGVtcy5wdXNoKGMpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgdGhpcy5fc2V0SXRlbXMobmV3SXRlbXMpO1xuICAgIH1cblxuICAgIF9zZXRJdGVtcyhuZXdJdGVtcykge1xuICAgICAgICBsZXQgcHJldkl0ZW1zID0gdGhpcy5faXRlbXM7XG4gICAgICAgIHRoaXMuX2l0ZW1zID0gbmV3SXRlbXM7XG5cbiAgICAgICAgLy8gUmVtb3ZlIHRoZSBpdGVtcy5cbiAgICAgICAgbGV0IHJlbW92ZWQgPSBwcmV2SXRlbXMuZmlsdGVyKGl0ZW0gPT4ge2xldCBtID0gaXRlbS5tYXJrZXI7IGRlbGV0ZSBpdGVtLm1hcmtlcjsgcmV0dXJuIG19KTtcbiAgICAgICAgbGV0IGFkZGVkID0gbmV3SXRlbXMuZmlsdGVyKGl0ZW0gPT4gKHByZXZJdGVtcy5pbmRleE9mKGl0ZW0pID09PSAtMSkpO1xuXG4gICAgICAgIGlmIChyZW1vdmVkLmxlbmd0aCB8fCBhZGRlZC5sZW5ndGgpIHtcbiAgICAgICAgICAgI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GFkZXIgPSBzdGFnZS5jdHgucmVuZGVyU3RhdGUuZGVmYXVsdFNoYWRlcjtcbiAgICAgICAgfSBlbHNlIGlmICh2ID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIHNoYWRlciA9IG51bGw7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodi5pc1NoYWRlcikge1xuICAgICAgICAgICAgICAgIGlmICghc3RhZ2UucmVuZGVyZXIuaXNWYWxpZFNoYWRlclR5cGUodi5jb25zdHJ1Y3RvcikpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihcIltMaWdodG5pbmddIEludmFsaWQgc2hhZGVyIHR5cGVcIik7XG4gICAgICAgICAgICAgICAgICAgIHYgPSBudWxsO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBzaGFkZXIgPSB2O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjb25zb2xlLmVycm9yKFwiW0xpZ2h0bmluZ10gUGxlYXNlIHNwZWNpZnkgYSBzaGFkZXIgdHlwZS5cIik7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIHNoYWRlcjtcbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0V2ViR0woKSB7XG4gICAgICAgIHJldHVybiB1bmRlZmluZWQ7XG4gICAgfVxuXG4gICAgc3RhdGljIGdldEMyZCgpIHtcbiAgICAgICAgcmV0dXJuIHVuZGVmaW5lZDtcbiAgICB9XG5cbiAgICBhZGRFbGVtZW50KGVsZW1lbnRDb3JlKSB7XG4gICAgICAgIHRoaXMuX2VsZW1lbnRzLmFkZChlbGVtZW50Q29yZSk7XG4gICAgfVxuXG4gICAgcmVtb3ZlRWxlbWVudChlbGVtZW50Q29yZSkge1xuICAgICAgICB0aGlzLl9lbGVtZW50cy5kZWxldGUoZWxlbWVudENvcmUpO1xuICAg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Z2xTdXBwb3J0ZWQoKSB7XG4gICAgICAgIGlmIChVdGlscy5pc05vZGUpIHtcbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG5cbiAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgIHJldHVybiAhIXdpbmRvdy5XZWJHTFJlbmRlcmluZ0NvbnRleHQ7XG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFJldHVybnMgdGhlIHJlbmRlcmluZyBtb2RlLlxuICAgICAqIEByZXR1cm5zIHtudW1iZXJ9XG4gICAgICogIDA6IFdlYkdMXG4gICAgICogIDE6IENhbnZhczJkXG4gICAgICovXG4gICAgZ2V0IG1vZGUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9tb2RlO1xuICAgIH1cblxuICAgIGlzV2ViZ2woKSB7XG4gICAgICAgIHJldHVybiB0aGlzLm1vZGUgPT09IDA7XG4gICAgfVxuXG4gICAgaXNDMmQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLm1vZGUgPT09IDE7XG4gICAgfVxuXG4gICAgZ2V0T3B0aW9uKG5hbWUpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX29wdGlvbnNbbmFtZV07XG4gICAgfVxuXG4gICAgX3NldE9wdGlvbnMobykge1xuICAgICAgICB0aGlzLl9vcHRpb25zID0ge307XG5cbiAgICAgICAgbGV0IG9wdCA9IChuYW1lLCBkZWYpID0+IHtcbiAgICAgICAgICAgIGxldCB2YWx1ZSA9IG9bbmFtZV07XG5cbiAgICAgICAgICAgIGlmICh2YWx1ZSA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3B0aW9uc1tuYW1lXSA9IGRlZjtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3B0aW9uc1tuYW1lXSA9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ldCByMSA9ICgoY1tpXSAvIDY1NTM2KSB8IDApICUgMjU2O1xuICAgICAgICAgICAgbGV0IGcxID0gKChjW2ldIC8gMjU2KSB8IDApICUgMjU2O1xuICAgICAgICAgICAgbGV0IGIxID0gY1tpXSAlIDI1NjtcbiAgICAgICAgICAgIGxldCBhMSA9ICgoY1tpXSAvIDE2Nzc3MjE2KSB8IDApO1xuICAgICAgICAgICAgciArPSByMSAqIHBbaV07XG4gICAgICAgICAgICBnICs9IGcxICogcFtpXTtcbiAgICAgICAgICAgIGIgKz0gYjEgKiBwW2ldO1xuICAgICAgICAgICAgYSArPSBhMSAqIHBbaV07XG4gICAgICAgICAgICB0ICs9IHBbaV07XG4gICAgICAgIH1cblxuICAgICAgICB0ID0gMSAvIHQ7XG4gICAgICAgIHJldHVybiBNYXRoLnJvdW5kKGEgKiB0KSAqIDE2Nzc3MjE2ICsgTWF0aC5yb3VuZChyICogdCkgKiA2NTUzNiArIE1hdGgucm91bmQoZyAqIHQpICogMjU2ICsgTWF0aC5yb3VuZChiICogdCk7XG4gICAgfTtcblxuICAgIHN0YXRpYyBtZXJnZU11bHRpQ29sb3JzRXF1YWwoYykge1xuICAgICAgICBsZXQgciA9IDAsIGcgPSAwLCBiID0gMCwgYSA9IDAsIHQgPSAwO1xuICAgICAgICBsZXQgbiA9IGMubGVuZ3RoO1xuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgbGV0IHIxID0gKChjW2ldIC8gNjU1MzYpIHwgMCkgJSAyNTY7XG4gICAgICAgICAgICBsZXQgZzEgPSAoKGNbaV0gLyAyNTYpIHwgMCkgJSAyNTY7XG4gICAgICAgICAgICBsZXQgYjEgPSBjW2ldICUgMjU2O1xuICAgICAgICAgICAgbGV0IGExID0gKChjW2ldIC8gMTY3NzcyMTYpIHwgMCk7XG4gICAgICAgICAgICByICs9IHIxO1xuICAgICAgICAgICAgZyArPSBnMTtcbiAgICAgICAgICAgIGIgKz0gYjE7XG4gICAgICAgICAgICBhICs9IGExO1xuICAgICAgICAgICAgdCArPSAxLjA7XG4gICAgICAgIH1cblxuICAgICAgICB0ID0gMSAvIHQ7XG4gICAgICAgIHJldHVybiBNYXRoLnJvdW5kKGEgKiB0KSAqIDE2Nzc3MjE2ICsgTWF0aC5yb3VuZChyICogdCkgKiA2NTUzNiArIE1hdGgucm91bmQoZyAqIHQpICogMjU2ICsgTWF0aC5yb3VuZChiICogdCk7XG4gICAgfTtcblxuICAgIHN0YXRpYyBtZXJnZUNvbG9yQWxwaGEoYywgYWxwaGEpIHtcbiAgICAgICAgbGV0IGEgPSAoKGMgLyAxNjc3NzIxNiB8IDApICogYWxwaGEpIHwgMDtcbiAgICAgICAgcmV0dXJuICgoKCgoYyA+PiAxNikgJiAweGZmKSAqIGEpIC8gMjU1KSAmIDB4ZmYpICtcbiAgICAgICAgICAgICgoKChjICYgMHhmZjAwKSAqIGEpIC8gMjU1KSAmIDB4ZmYwMCkgK1xuICAgICAgICAgICAgKCgoKChjICYgMHhmZikgPDwgMTYpICogYSkgLyAyNTUpICYgMHhmZjAwMDApICtcbiAgICAgICAgICAgIChhIDw8IDI0KTtcbiAgICB9O1xuXG4gICAgc3RhdGljIHJhZChkZWcpIHtcbiAgICAgICAgcmV0dXJuIGRlZyAqIChNYXRoLlBJIC8gMTgwKTtcbiAgICB9O1xuXG4gICAgc3RhdGljIGdldFRpbWluZ0JlemllcihhLCBiLCBjLCBkKSB7XG4gICAgICAgIGxldCB4YyA9IDMuMCAqIGE7XG4gICAgICAgIGxldCB4YiA9IDMuMCAqIChjIC0gYSkgLSB4YztcbiAgICAgICAgbGV0IHhhID0gMS4wIC0geGMgLSB4YjtcbiAgICAgICAgbGV0IHljID0gMy4wICogYjtcbiAgICAgICAgbGV0IHliID0gMy4wICogKGQgLSBiKSAtIHljO1xuICAgICAgICBsZXQgeWEgPSAxLjAgLSB5YyAtIHliO1xuXG4gICAgICAgIHJldHVybiBmdW5jdGlvbiAodGltZSkge1xuICAgICAgICAgICAgaWYgKHRpbWUgPj0gMS4wKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIDE7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGltZSA8PSAwKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIDA7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGxldCB0ID0gMC41LCBjYngsIGNieGQsIGR4O1xuXG4gICAgICAgICAgICBmb3IgKGxldCBpdCA9IDA7IGl0IDwgMjA7IGl0KyspIHtcbiAgICAgICAgICAgICAgICBjYnggPSB0ICogKHQgKiAodCAqIHhhICsgeGIpICsgeGMpO1xuICAgICAgICAgICAgICAgIGR4ID0gdGltZSAtIGNieDtcbiAgICAgICAgICAgICAgICBpZiAoZHggPiAtMWUtOCAmJiBkeCA8IDFlLTgpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHQgKiAodCAqICh0ICogeWEgKyB5YikgKyB5Yyk7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgLy8gQ3ViaWMgYmV6aWVyIGRlcml2YXRpdmUuXG4gICAgICAgICAgICAgICAgY2J4ZCA9IHQgKiAodCAqICgzICogeGEpICsgMiAqIHhiKSArIHhjO1xuXG4gICAgICAgICAgICAgICAgaWYgKGNieGQgPiAxZS0xMCAmJiBjYnhkIDwgMWUtMTApIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gUHJvYmxlbWF0aWMuIEZhbGwgYmFjayB0byBiaW5hcnkgc2VhcmNoIG1ldGhvZC5cbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgdCArPSBkeCAvIGNieGQ7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIEZhbGxiYWNrOiBiaW5hcnkgc2VhcmNoIG1ldGhvZC4gVGhpcyBpcyBtb3JlIHJlbGlhYmxlIHdoZW4gdGhlcmUgYXJlIG5lYXItMCBzbG9wZXMuXG4gICAgICAgICAgICBsZXQgbWluVCA9IDA7XG4gICAgICAgICAgICBsZXQgbWF4VCA9IDE7XG4gICAgICAgICAgICBmb3IgKGxldCBpdCA9IDA7IGl0IDwgMjA7IGl0KyspIHtcbiAgICAgICAgICAgICAgICB0ID0gMC41ICogKG1pblQgKyBtYXhUKTtcblxuICAgICAgICAgICAgICAgIGNieCA9IHQgKiAodCAqICh0ICogeGEgKyB4YikgKyB4Yyk7XG5cbiAgICAgICAgICAgICAgICBkeCA9IHRpbWUgLSBjYng7XG4gICAgICAgICAgICAgICAgaWYgKGR4ID4gLTFlLTggJiYgZHggPCAxZS04KSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFNvbHV0aW9uIGZvdW5kIVxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdCAqICh0ICogKHQgKiB5YSArIHliKSArIHljKTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAoZHggPCAwKSB7XG4gICAgICAgICAgICAgICAgICAgIG1heFQgPSB0O1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIG1pblQgPSB0O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICB9O1xuICAgIH07XG5cbiAgICBzdGF0aWMgZ2V0VGltaW5nRnVuY3Rpb24oc3RyKSB7XG4gICAgICAgIHN3aXRjaCAoc3RyKSB7XG4gICAgICAgICAgICBjYXNlIFwibGluZWFyXCI6XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICh0aW1lKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0aW1lXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGNhc2UgXCJlYXNlXCI6XG4gICAgICAgICAgICAgICAgcmV0dXJuIFN0YWdlVXRpbHMuZ2V0VGltaW5nQmV6aWVyKDAuMjUsIDAuMSwgMC4yNSwgMS4wKTtcbiAgICAgICAgICAgIGNhc2UgXCJlYXNlLWluXCI6XG4gICAgICAgICAgICAgICAgcmV0dXJuIFN0YWdlVXRpbHMuZ2V0VGltaW5nQmV6aWVyKDAuNDIsIDAsIDEuMCwgMS4wKTtcbiAgICAgICAgICAgIGNhc2UgXCJlYXNlLW91dFwiOlxuICAgICAgICAgICAgICAgIHJldHVybiBTdGFnZVV0aWxzLmdldFRpbWluZ0JlemllcigwLCAwLCAwLjU4LCAxLjApO1xuICAgICAgICAgICAgY2FzZSBcImVhc2UtaW4tb3V0XCI6XG4gICAgICAgICAgICAgICAgcmV0dXJuIFN0YWdlVXRpbHMuZ2V0VGltaW5nQmV6aWVyKDAuNDIsIDAsIDAuNTgsIDEuMCk7XG4gICAgICAgICAgICBjYXNlIFwic3RlcC1zdGFydFwiOlxuICAgICAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiAxXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGNhc2UgXCJzdGVwLWVuZFwiOlxuICAgICAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbiAodGltZSkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGltZSA9PT0gMSA/IDEgOiAwO1xuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgIGxldCBzID0gXCJjdWJpYy1iZXppZXIoXCI7XG4gICAgICAgICAgICAgICAgaWYgKHN0ciAmJiBzdHIuaW5kZXhPZihzKSA9PT0gMCkge1xuICAgICAgICAgICAgICAgICAgICBsZXQgcGFydHMgPSBzdHIuc3Vic3RyKHMubGVuZ3RoLCBzdHIubGVuZ3RoIC0gcy5sZW5ndGggLSAxKS5zcGxpdChcIixcIik7XG4gICAgICAgICAgICAgICAgICAgIGlmIChwYXJ0cy5sZW5ndGggIT09IDQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIFVua25vd24gdGltaW5nIGZ1bmN0aW9uOiBcIiArIHN0cik7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEZhbGxiYWNrOiB1c2UgbGluZWFyLlxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICh0aW1lKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRpbWVcbiAgICAgICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgbGV0IGEgPSBwYXJzZUZsb2F0KHBhcnRzWzBdKTtcbiAgICAgICAgICAgICAgICAgICAgbGV0IGIgPSBwYXJzZUZsb2F0KHBhcnRzWzFdKTtcbiAgICAgICAgICAgICAgICAgICAgbGV0IGMgPSBwYXJzZUZsb2F0KHBhcnRzWzJdKTtcbiAgICAgICAgICAgICAgICAgICAgbGV0IGQgPSBwYXJzZUZsb2F0KHBhcnRzWzNdKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlzTmFOKGEpIHx8IGlzTmFOKGIpIHx8IGlzTmFOKGMpIHx8IGlzTmFOKGQpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJbTGlnaHRuaW5nXSBVbmtub3duIHRpbWluZyBmdW5jdGlvbjogXCIgKyBzdHIpO1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gRmFsbGJhY2s6IHVzZSBsaW5lYXIuXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24gKHRpbWUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGltZVxuICAgICAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBTdGFnZVV0aWxzLmdldFRpbWluZ0JlemllcihhLCBiLCBjLCBkKTtcbiA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lhdGVkIHRleHR1cmUgc291cmNlLlxuICAgICAgICAgKiBTaG91bGQgbm90IGJlIGNoYW5nZWQuXG4gICAgICAgICAqIEB0eXBlIHtUZXh0dXJlU291cmNlfVxuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5fc291cmNlID0gbnVsbDtcblxuICAgICAgICAvKipcbiAgICAgICAgICogQSByZXNpemUgbW9kZSBjYW4gYmUgc2V0IHRvIGNvdmVyIG9yIGNvbnRhaW4gYSBjZXJ0YWluIGFyZWEuXG4gICAgICAgICAqIEl0IHdpbGwgcmVzZXQgdGhlIHRleHR1cmUgY2xpcHBpbmcgc2V0dGluZ3MuXG4gICAgICAgICAqIFdoZW4gbWFudWFsIHRleHR1cmUgY2xpcHBpbmcgaXMgcGVyZm9ybWVkLCB0aGUgcmVzaXplTW9kZSBpcyByZXNldC5cbiAgICAgICAgICogQHR5cGUge3t0eXBlOiBzdHJpbmcsIHdpZHRoOiBudW1iZXIsIGhlaWdodDogbnVtYmVyfX1cbiAgICAgICAgICogQHByaXZhdGVcbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX3Jlc2l6ZU1vZGUgPSBudWxsO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBUaGUgdGV4dHVyZSBjbGlwcGluZyB4LW9mZnNldC5cbiAgICAgICAgICogQHR5cGUge251bWJlcn1cbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX3ggPSAwO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBUaGUgdGV4dHVyZSBjbGlwcGluZyB5LW9mZnNldC5cbiAgICAgICAgICogQHR5cGUge251bWJlcn1cbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX3kgPSAwO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBUaGUgdGV4dHVyZSBjbGlwcGluZyB3aWR0aC4gSWYgMCB0aGVuIGZ1bGwgd2lkdGguXG4gICAgICAgICAqIEB0eXBlIHtudW1iZXJ9XG4gICAgICAgICAqL1xuICAgIC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ICAgICAgICAgICAgICAgICAgIHRoaXMuX3NvdXJjZS5hZGRUZXh0dXJlKHRoaXMpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHYuYWN0aXZlKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5pbmNBY3RpdmVDb3VudCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgcmVtb3ZlRWxlbWVudCh2KSB7XG4gICAgICAgIGlmICh0aGlzLmVsZW1lbnRzLmRlbGV0ZSh2KSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuZWxlbWVudHMuc2l6ZSA9PT0gMCkge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9zb3VyY2UpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fc291cmNlLnJlbW92ZVRleHR1cmUodGhpcyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAodi5hY3RpdmUpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmRlY0FjdGl2ZUNvdW50KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBpbmNBY3RpdmVDb3VudCgpIHtcbiAgICAgICAgLy8gRW5zdXJlIHRoYXQgdGV4dHVyZSBzb3VyY2UncyBhY3RpdmVDb3VudCBoYXMgdHJhbnNmZXJyZWQgb3duZXJzaGlwLlxuICAgICAgICBjb25zdCBzb3VyY2UgPSB0aGlzLnNvdXJjZTtcblxuICAgICAgICBpZiAoc291cmNlKSB7XG4gICAgICAgICAgICB0aGlzLl9jaGVja0Zvck5ld2VyUmV1c2FibGVUZXh0dXJlU291cmNlKCk7XG4gICAgICAgIH1cblxuICAgICAgICB0aGlzLl9hY3RpdmVDb3VudCsrO1xuICAgICAgICBpZiAodGhpcy5fYWN0aXZlQ291bnQgPT09IDEpIHtcbiAgICAgICAgICAgIHRoaXMuYmVjb21lc1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hpcy5fZ2V0SXNWYWxpZCgpKSB7XG4gICAgICAgICAgICBjb25zdCBsb29rdXBJZCA9IHRoaXMuX2dldExvb2t1cElkKCk7XG4gICAgICAgICAgICBzb3VyY2UgPSB0aGlzLl9nZXRSZXVzYWJsZVRleHR1cmVTb3VyY2UobG9va3VwSWQpO1xuICAgICAgICAgICAgaWYgKCFzb3VyY2UpIHtcbiAgICAgICAgICAgICAgICBzb3VyY2UgPSB0aGlzLm1hbmFnZXIuZ2V0VGV4dHVyZVNvdXJjZSh0aGlzLl9nZXRTb3VyY2VMb2FkZXIoKSwgbG9va3VwSWQpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBzb3VyY2U7XG4gICAgfVxuXG4gICAgX2dldFJldXNhYmxlVGV4dHVyZVNvdXJjZShsb29rdXBJZCA9IHRoaXMuX2dldExvb2t1cElkKCkpIHtcbiAgICAgICAgaWYgKHRoaXMuX2dldElzVmFsaWQoKSkge1xuICAgICAgICAgICAgaWYgKGxvb2t1cElkKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubWFuYWdlci5nZXRSZXVzYWJsZVRleHR1cmVTb3VyY2UobG9va3VwSWQpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBudWxsO1xuICAgIH1cblxuICAgIF9yZXBsYWNlVGV4dHVyZVNvdXJjZShuZXdTb3VyY2UgPSBudWxsKSB7XG4gICAgICAgIGxldCBvbGRTb3VyY2UgPSB0aGlzLl9zb3VyY2U7XG5cbiAgICAgICAgdGhpcy5fc291cmNlID0gbmV3U291cmNlO1xuXG4gICAgICAgIGlmICh0aGlzLmVsZW1lbnRzLnNpemUpIHtcbiAgICAgICAgICAgIGlmIChvbGRTb3VyY2UpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYWN0aXZlQ291bnQpIHtcbiAgICAgICAgICAgICAgICAgICAgb2xkU291cmNlLmRlY0FjdGl2ZVRleHR1cmVDb3VudCgpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIG9sZFNvdXJjZS5yZW1vdmVUZXh0dXJlKHRoaXMpO1xuXG4gICAgICAgICAgICAgICAgLy8gZnJlZSB1cCB1bnVzZWQgVGV4dFRleHR1cmVzIGltbWVkaWF0ZWx5IGFzIHRoZXkgYXJlIG5vdCByZXVzZWQgYW55d2F5XG4gICAgICAgICAgICAgICAgaWYodGhpc1sndGV4dCddICYmICFvbGRTb3VyY2UuaXNVc2VkKCkpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5tYW5hZ2VyLmZyZWVUZXh0dXJlU291cmNlKG9sZFNvdXJjZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAobmV3U291cmNlKSB7XG4gICAgICAgICAgICAgICAgLy8gTXVzdCBoYXBwZW4gYmVmb3JlIHNldERpc3BsYXllZFRleHR1cmUgdG8gZW5zdXJlIHNwcml0ZSBtYXAgdGV4Y29vcmRzIGFyZSB1c2VkLlxuICAgICAgICAgICAgICAgIG5ld1NvdXJjZS5hZGRUZXh0dXJlKHRoaXMpO1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9hY3RpdmVDb3VudCkge1xuICAgICAgICAgICAgICAgICAgICBuZXdTb3VyY2UuaW5jQWN0aXZlVGV4dHVyZUNvdW50KCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuaXNVc2VkKCkpIHtcbiAgICAgICAgICAgIGlmIChuZXdTb3VyY2UpIHtcbiAgICAgICAgICAgICAgICBpZiAobmV3U291cmNlLmlzTG9hZGVkKCkpIHtcblxuICAgICAgICAgICAgICAgICAgICAvLyBBcHBseSByZXNpemVNb2RlXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9yZXNpemVNb2RlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9hcHBseVJlc2l6ZU1vZGUoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZWxlbWVudHMuZm9yRWFjaChlbGVtZW50ID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlbGVtZW50LmFjdGl2ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnQuX3NldERpc3BsYXllZFRleHR1cmUodGhpcyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGxvYWRFcnJvciA9IG5ld1NvdXJjZS5sb2FkRXJyb3I7XG4gICAgICAgICAgICAgICAgICAgIGlmIChsb2FkRXJyb3IpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZWxlbWVudHMuZm9yRWFjaChlbGVtZW50ID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZWxlbWVudC5hY3RpdmUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlbWVudC5vblRleHR1cmVTb3VyY2VMb2FkRXJyb3IobG9hZEVycm9yKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5lbGVtZW50cy5mb3JFYWNoKGVsZW1lbnQgPT4ge1xuICAgICAgICAgICAgICAgICAgICBpZiAoZWxlbWVudC5hY3RpdmUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnQuX3NldERpc3BsYXllZFRleHR1cmUobnVsbCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgIC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RoaXMuX3ByZWNpc2lvbjtcbiAgICAgICAgeSAqPSB0aGlzLl9wcmVjaXNpb247XG4gICAgICAgIHcgKj0gdGhpcy5fcHJlY2lzaW9uO1xuICAgICAgICBoICo9IHRoaXMuX3ByZWNpc2lvbjtcbiAgICAgICAgaWYgKHRoaXMuX3ggIT09IHggfHwgdGhpcy5feSAhPT0geSB8fCB0aGlzLl93ICE9PSB3IHx8IHRoaXMuX2ggIT09IGgpIHtcbiAgICAgICAgICAgIHRoaXMuX3ggPSB4O1xuICAgICAgICAgICAgdGhpcy5feSA9IHk7XG4gICAgICAgICAgICB0aGlzLl93ID0gdztcbiAgICAgICAgICAgIHRoaXMuX2ggPSBoO1xuXG4gICAgICAgICAgICB0aGlzLl91cGRhdGVDbGlwcGluZyh0cnVlKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGRpc2FibGVDbGlwcGluZygpIHtcbiAgICAgICAgdGhpcy5fY2xlYXJSZXNpemVNb2RlKCk7XG5cbiAgICAgICAgaWYgKHRoaXMuX3ggfHwgdGhpcy5feSB8fCB0aGlzLl93IHx8IHRoaXMuX2gpIHtcbiAgICAgICAgICAgIHRoaXMuX3ggPSAwO1xuICAgICAgICAgICAgdGhpcy5feSA9IDA7XG4gICAgICAgICAgICB0aGlzLl93ID0gMDtcbiAgICAgICAgICAgIHRoaXMuX2ggPSAwO1xuXG4gICAgICAgICAgICB0aGlzLl91cGRhdGVDbGlwcGluZygpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX3VwZGF0ZUNsaXBwaW5nKCkge1xuICAgICAgICB0aGlzLmNsaXBwaW5nID0gISEodGhpcy5feCB8fCB0aGlzLl95IHx8IHRoaXMuX3cgfHwgdGhpcy5faCk7XG5cbiAgICAgICAgbGV0IHNlbGYgPSB0aGlzO1xuICAgICAgICB0aGlzLmVsZW1lbnRzLmZvckVhY2goZnVuY3Rpb24oZWxlbWVudCkge1xuICAgICAgICAgICAgLy8gSWdub3JlIGlmIG5vdCB0aGUgY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MSkgbm9uRGVmYXVsdHNbJ3ByZWNpc2lvbiddID0gdGhpcy5wcmVjaXNpb247XG4gICAgICAgIHJldHVybiBub25EZWZhdWx0cztcbiAgICB9XG5cbiAgICBnZXQgcHgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl94O1xuICAgIH1cblxuICAgIGdldCBweSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3k7XG4gICAgfVxuXG4gICAgZ2V0IHB3KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdztcbiAgICB9XG5cbiAgICBnZXQgcGgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9oO1xuICAgIH1cblxuICAgIGdldCB4KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5feCAvIHRoaXMuX3ByZWNpc2lvbjtcbiAgICB9XG4gICAgc2V0IHgodikge1xuICAgICAgICB0aGlzLl9jbGVhclJlc2l6ZU1vZGUoKTtcbiAgICAgICAgdiA9IHYgKiB0aGlzLl9wcmVjaXNpb247XG4gICAgICAgIGlmICh0aGlzLl94ICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl94ID0gdjtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUNsaXBwaW5nKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgeSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3kgLyB0aGlzLl9wcmVjaXNpb247XG4gICAgfVxuICAgIHNldCB5KHYpIHtcbiAgICAgICAgdGhpcy5fY2xlYXJSZXNpemVNb2RlKCk7XG4gICAgICAgIHYgPSB2ICogdGhpcy5fcHJlY2lzaW9uO1xuICAgICAgICBpZiAodGhpcy5feSAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5feSA9IHY7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVDbGlwcGluZygpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHcoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl93IC8gdGhpcy5fcHJlY2lzaW9uO1xuICAgIH1cblxuICAgIHNldCB3KHYpIHtcbiAgICAgICAgdGhpcy5fY2xlYXJSZXNpemVNb2RlKCk7XG4gICAgICAgIHYgPSB2ICogdGhpcy5fcHJlY2lzaW9uO1xuICAgICAgICBpZiAodGhpcy5fdyAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fdyA9IHY7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVDbGlwcGluZygpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9oIC8gdGhpcy5fcHJlY2lzaW9uO1xuICAgIH1cblxuICAgIHNldCBoKHYpIHtcbiAgICAgICAgdGhpcy5fY2xlYXJSZXNpemVNb2RlKCk7XG4gICAgICAgIHYgPSB2ICogdGhpcy5fcHJlY2lzaW9uO1xuICAgICAgICBpZiAodGhpcy5faCAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5faCA9IHY7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVDbGlwcGluZygpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHByZWNpc2lvbigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3ByZWNpc2lvbjtcbiAgICB9XG5cbiAgICBzZXQgcHJlY2lzaW9uKHYpIHtcbiAgICAgICAgdGhpcy5fY2xlYXJSZXNpemVNb2RlKCk7XG4gICAgICAgIGlmICh0aGlzLl9wcmVjaXNpb24gIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX3ByZWNpc2lvbiA9IHY7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVQcmVjaXNpb24oKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGlzQXV0b3NpemVUZXh0dXJlKCkge1xuICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICB9XG5cbiAgICBnZXRSZW5kZXJXaWR0aCgpIHtcbiAgICAgICAgaWYgKCF0aGlzLmlzQXV0b3NpemVU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XhlbCk7XG5cbiAgICAgICAgdGhpcy5zdGFnZS5hZGRWcmFtVXNhZ2UodXNhZ2UsIHRleHR1cmVTb3VyY2UuaGFzQWxwaGEpO1xuICAgIH1cblxuICAgIGFkZFRvTG9va3VwTWFwKHRleHR1cmVTb3VyY2UpIHtcbiAgICAgICAgY29uc3QgbG9va3VwSWQgPSB0ZXh0dXJlU291cmNlLmxvb2t1cElkO1xuICAgICAgICBpZiAobG9va3VwSWQpIHtcbiAgICAgICAgICAgIGlmICghdGhpcy50ZXh0dXJlU291cmNlSGFzaG1hcC5oYXMobG9va3VwSWQpKSB7XG4gICAgICAgICAgICAgICAgdGhpcy50ZXh0dXJlU291cmNlSGFzaG1hcC5zZXQobG9va3VwSWQsIHRleHR1cmVTb3VyY2UpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2MoKSB7XG4gICAgICAgIHRoaXMuZnJlZVVudXNlZFRleHR1cmVTb3VyY2VzKCk7XG4gICAgfVxuICAgIFxuICAgIGZyZWVVbnVzZWRUZXh0dXJlU291cmNlcygpIHtcbiAgICAgICAgbGV0IHJlbWFpbmluZ1RleHR1cmVTb3VyY2VzID0gW107XG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fdXBsb2FkZWRUZXh0dXJlU291cmNlcy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGxldCB0cyA9IHRoaXMuX3VwbG9hZGVkVGV4dHVyZVNvdXJjZXNbaV07XG4gICAgICAgICAgICBpZiAodHMuYWxsb3dDbGVhbnVwKCkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9mcmVlTWFuYWdlZFRleHR1cmVTb3VyY2UodHMpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZW1haW5pbmdUZXh0dXJlU291cmNlcy5wdXNoKHRzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHRoaXM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iAgICAgICAgLyoqXG4gICAgICAgICAqIFRyYWNrIHdoZXRoZXIgb3Igbm90IHRoZXJlIGlzIGFuIGFscGhhIGNoYW5uZWwgaW4gdGhpcyBzb3VyY2VcbiAgICAgICAgICogQHR5cGUge2Jvb2xlYW59XG4gICAgICAgICAqIEBwcml2YXRlXG4gICAgICAgICAqL1xuICAgICAgICAgdGhpcy5faGFzQWxwaGEgPSBmYWxzZTtcbiAgICB9XG5cbiAgICBnZXQgaGFzQWxwaGEoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9oYXNBbHBoYTtcbiAgICB9XG5cbiAgICBnZXQgbG9hZEVycm9yKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbG9hZEVycm9yO1xuICAgIH1cblxuICAgIGFkZFRleHR1cmUodikge1xuICAgICAgICBpZiAoIXRoaXMudGV4dHVyZXMuaGFzKHYpKSB7XG4gICAgICAgICAgICB0aGlzLnRleHR1cmVzLmFkZCh2KTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJlbW92ZVRleHR1cmUodikge1xuICAgICAgICB0aGlzLnRleHR1cmVzLmRlbGV0ZSh2KTtcbiAgICB9XG5cbiAgICBpbmNBY3RpdmVUZXh0dXJlQ291bnQoKSB7XG4gICAgICAgIHRoaXMuX2FjdGl2ZVRleHR1cmVDb3VudCsrO1xuICAgICAgICBpZiAodGhpcy5fYWN0aXZlVGV4dHVyZUNvdW50ID09PSAxKSB7XG4gICAgICAgICAgICB0aGlzLmJlY29tZXNVc2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBkZWNBY3RpdmVUZXh0dXJlQ291bnQoKSB7XG4gICAgICAgIHRoaXMuX2FjdGl2ZVRleHR1cmVDb3VudC0tO1xuICAgICAgICBpZiAodGhpcy5fYWN0aXZlVGV4dHVyZUNvdW50ID09PSAwKSB7XG4gICAgICAgICAgICB0aGlzLmJlY29tZXNVbnVzZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBpc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gICAgICAgLy8gRnJvbSB0aGUgbW9tZW50IG9mIGxvYWRpbmcgKHdoZW4gYSB0ZXh0dXJlIHNvdXJjZSBiZWNvbWVzIHVzZWQgYnkgYWN0aXZlIGVsZW1lbnRzKVxuICAgICAgICBpZiAodGhpcy5pc1Jlc3VsdFRleHR1cmUpIHtcbiAgICAgICAgICAgIC8vIEVsZW1lbnQgcmVzdWx0IHRleHR1cmUgc291cmNlLCBmb3Igd2hpY2ggdGhlIGxvYWRpbmcgaXMgbWFuYWdlZCBieSB0aGUgY29yZS5cbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICghdGhpcy5fbmF0aXZlVGV4dHVyZSAmJiAhdGhpcy5pc0xvYWRpbmcoKSkge1xuICAgICAgICAgICAgdGhpcy5sb2FkaW5nU2luY2UgPSAobmV3IERhdGUoKSkuZ2V0VGltZSgpO1xuICAgICAgICAgICAgdGhpcy5fY2FuY2VsQ2IgPSB0aGlzLmxvYWRlcigoZXJyLCBvcHRpb25zKSA9PiB7XG4gICAgICAgICAgICAgICAgLy8gSWdub3JlIGxvYWRzIHRoYXQgY29tZSBpbiBhZnRlciBhIGNhbmNlbC5cbiAgICAgICAgICAgICAgICBpZiAodGhpcy5pc0xvYWRpbmcoKSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBDbGVhciBjYWxsYmFjayB0byBhdm9pZCBtZW1vcnkgbGVha3MuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2NhbmNlbENiID0gbnVsbDtcblxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5tYW5hZ2VyLnN0YWdlLmRlc3Ryb3llZCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gSWdub3JlIGFzeW5jIGxvYWQgd2hlbiBzdGFnZSBpcyBkZXN0cm95ZWQuXG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgaWYgKGVycikge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gRW1pdCB0eEVycm9yLlxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5vbkVycm9yKGVycik7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3B0aW9ucyAmJiBvcHRpb25zLnNvdXJjZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCF0aGlzLnN0YWdlLmlzVXBkYXRpbmdGcmFtZSgpICYmICFmb3JjZVN5bmMgJiYgKG9wdGlvbnMudGhyb3R0bGUgIT09IGZhbHNlKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IHRleHR1cmVUaHJvdHRsZXIgPSB0aGlzLnN0YWdlLnRleHR1cmVUaHJvdHRsZXI7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fY2FuY2VsQ2IgPSB0ZXh0dXJlVGhyb3R0bGVyLmdlbmVyaWNDYW5jZWxDYjtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0ZXh0dXJlVGhyb3R0bGVyLmFkZCh0aGlzLCBvcHRpb25zKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5wcm9jZXNzTG9hZGVkU291cmNlKG9wdGlvbnMpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSwgdGhpcyk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBwcm9jZXNzTG9hZGVkU291cmNlKG9wdGlvbnMpIHtcbiAgICAgICAgdGhpcy5sb2FkaW5nU2luY2UgPSAwO1xuICAgICAgICB0aGlzLnNldFNvdXJjZShvcHRpb25zKTtcbiAgICB9XG5cbiAgICBzZXRTb3VyY2Uob3B0aW9ucykge1xuICAgICAgICBjb25zdCBzb3VyY2UgPSBvcHRpb25zL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biAgICAgICAgcmV0dXJuIHR5cGVvZiB2YWx1ZSA9PT0gJ3N0cmluZyc7XG4gICAgfVxuXG4gICAgc3RhdGljIGNsb25lKHYpIHtcbiAgICAgICAgaWYgKFV0aWxzLmlzT2JqZWN0TGl0ZXJhbCh2KSB8fCBBcnJheS5pc0FycmF5KHYpKSB7XG4gICAgICAgICAgICByZXR1cm4gVXRpbHMuZ2V0RGVlcENsb25lKHYpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgLy8gQ29weSBieSB2YWx1ZS5cbiAgICAgICAgICAgIHJldHVybiB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGNsb25lT2JqU2hhbGxvdyhvYmopIHtcbiAgICAgICAgbGV0IGtleXMgPSBPYmplY3Qua2V5cyhvYmopO1xuICAgICAgICBsZXQgY2xvbmUgPSB7fVxuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGtleXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgIGNsb25lW2tleXNbaV1dID0gb2JqW2tleXNbaV1dO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBjbG9uZTtcbiAgICB9XG5cbiAgICBzdGF0aWMgbWVyZ2Uob2JqMSwgb2JqMikge1xuICAgICAgICBsZXQga2V5cyA9IE9iamVjdC5rZXlzKG9iajIpO1xuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGtleXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgIG9iajFba2V5c1tpXV0gPSBvYmoyW2tleXNbaV1dO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBvYmoxO1xuICAgIH1cblxuICAgIHN0YXRpYyBpc09iamVjdCh2YWx1ZSkge1xuICAgICAgICBsZXQgdHlwZSA9IHR5cGVvZiB2YWx1ZTtcbiAgICAgICAgcmV0dXJuICEhdmFsdWUgJiYgKHR5cGUgPT09ICdvYmplY3QnIHx8IHR5cGUgPT09ICdmdW5jdGlvbicpO1xuICAgIH1cblxuICAgIHN0YXRpYyBpc1BsYWluT2JqZWN0KHZhbHVlKSB7XG4gICAgICAgIGxldCB0eXBlID0gdHlwZW9mIHZhbHVlO1xuICAgICAgICByZXR1cm4gISF2YWx1ZSAmJiAodHlwZSA9PT0gJ29iamVjdCcpO1xuICAgIH1cblxuICAgIHN0YXRpYyBpc09iamVjdExpdGVyYWwodmFsdWUpe1xuICAgICAgICByZXR1cm4gdHlwZW9mIHZhbHVlID09PSAnb2JqZWN0JyAmJiB2YWx1ZSAmJiB2YWx1ZS5jb25zdHJ1Y3RvciA9PT0gT2JqZWN0O1xuICAgIH1cblxuICAgIHN0YXRpYyBnZXRBcnJheUluZGV4KGluZGV4LCBhcnIpIHtcbiAgICAgICAgcmV0dXJuIFV0aWxzLmdldE1vZHVsb0luZGV4KGluZGV4LCBhcnIubGVuZ3RoKTtcbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0TW9kdWxvSW5kZXgoaW5kZXgsIGxlbikge1xuICAgICAgICBpZiAobGVuID09PSAwKSByZXR1cm4gaW5kZXg7XG4gICAgICAgIHdoaWxlIChpbmRleCA8IDApIHtcbiAgICAgICAgICAgIGluZGV4ICs9IE1hdGguY2VpbCgtaW5kZXggLyBsZW4pICogbGVuO1xuICAgICAgICB9XG4gICAgICAgIGluZGV4ID0gaW5kZXggJSBsZW47XG4gICAgICAgIHJldHVybiBpbmRleDtcbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0RGVlcENsb25lKG9iaikge1xuICAgICAgICBsZXQgaSwgYztcbiAgICAgICAgaWYgKFV0aWxzLmlzRnVuY3Rpb24ob2JqKSkge1xuICAgICAgICAgICAgLy8gQ29weSBmdW5jdGlvbnMgYnkgcmVmZXJlbmNlLlxuICAgICAgICAgICAgcmV0dXJuIG9iajtcbiAgICAgICAgfVxuICAgICAgICBpZiAoQXJyYXkuaXNBcnJheShvYmopKSB7XG4gICAgICAgICAgICBjID0gW107XG4gICAgICAgICAgICBsZXQga2V5cyA9IE9iamVjdC5rZXlzKG9iaik7XG4gICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwga2V5cy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgICAgIGNba2V5c1tpXV0gPSBVdGlscy5nZXREZWVwQ2xvbmUob2JqW2tleXNbaV1dKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiBjO1xuICAgICAgICB9IGVsc2UgaWYgKFV0aWxzLmlzT2JqZWN0KG9iaikpIHtcbiAgICAgICAgICAgIGMgPSB7fVxuICAgICAgICAgICAgbGV0IGtleXMgPSBPYmplY3Qua2V5cyhvYmopO1xuICAgICAgICAgICAgZm9yIChpID0gMDsgaSA8IGtleXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgICAgICBjW2tleXNbaV1dID0gVXRpbHMuZ2V0RGVlcENsb25lKG9ialtrZXlzW2ldXSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gYztcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiBvYmo7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgZXF1YWxWYWx1ZXModjEsIHYyKSB7XG4gICAgICAgIGlmICgodHlwZW9mIHYxKSAhPT0gKHR5cGVvZiB2MikpIHJldHVybiBmYWxzZTtcbiAgICAgICAgaWYgKFV0aWxzLmlzT2JqZWN0TGl0ZXJhbCh2MSkpIHtcbiAgICAgICAgICAgIHJldHVybiBVdGlscy5pc09iamVjdExpdGVyYWwodjIpICYmIFV0aWxzLmVxdWFsT2JqZWN0TGl0ZXJhbHModjEsIHYyKTtcbiAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KHYxKSkge1xuICAgICAgICAgICAgcmV0dXJuIEFycmF5LmlzQXJyYXkodjIpICYmIFV0aWxzLmVxdWFsQXJyYXlzKHYxLCB2Mik7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdjEgPT09IHYyO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGVxdWFsT2JqZWN0TGl0ZXJhbHMob2JqMSwgb2JqMikge1xuICAgICAgICBsZXQga2V5czEgPSBPYmplY3Qua2V5cyhvYmoxKTtcbiAgICAgICAgbGV0IGtleXMyID0gT2JqZWN0LmtleXMob2JqMik7XG4gICAgICAgIGlmIChrZXlzMS5sZW5ndGggIT09IGtleXMyLmxlbmd0aCkge1xuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG5cbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBrZXlzMS5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGNvbnN0IGsxID0ga2V5czFbaV07XG4gICAgICAgICAgICBjb25zdCBrMiA9IGtleXMyW2ldO1xuICAgICAgICAgICAgaWYgKGsxICE9PSBrMikge1xuICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgY29uc3QgdjEgPSBvYmoxW2sxXTtcbiAgICAgICAgICAgIGNvbnN0IHYyID0gb2JqMltrMl07XG5cbiAgICAgICAgICAgIGlmICghVXRpbHMuZXF1YWxWYWx1ZXModjEsIHYyKSkge1xuICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiB0cnVlO1xuICAgIH1cblxuICAgIHN0YXRpYyBlcXVhbEFycmF5cyh2MSwgdjIpIHtcbiAgICAgICAgaWYgKHYxLmxlbmd0aCAhPT0gdjIubGVuZ3RoKSB7XG4gICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgIH1cbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB2MS5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5lcXVhbFZhbHVlcyh2MVtpXSwgdjJbaV0pKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgfVxuXG4gICAgc3RhdGljIHNldFRvQXJyYXkocykge1xuICAgICAgICBsZXQgcmVzdWx0ID0gW107XG4gICAgICAgIHMuZm9yRWFjaChmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgICAgIHJlc3VsdC5wdXNoKHZhbHVlKTtcbiAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgfVxuXG4gICAgc3RhdGljIGl0ZXJhdG9yVG9BcnJheShpdGVyYXRvcikge1xuICAgICAgICBsZXQgcmVzdWx0ID0gW107XG4gICAgICAgIGxldCBpdGVyYXRvclJlc3VsdCA9IGl0ZXJhdG9yLm5leHQoKTtcbiAgICAgICAgd2hpbGUgKCFpdGVyYXRvclJlc3VsdC5kb25lKSB7XG4gICAgICAgICAgICByZXN1bHQucHVzaChpdGVyYXRvclJlc3VsdC52YWx1ZSk7XG4gICAgICAgICAgICBpdGVyYXRvclJlc3VsdCA9IGl0ZXJhdG9yLm5leHQoKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gcmVzdWx0O1xuICAgIH1cblxuICAgIHN0YXRpYyBpc1VjQ2hhcihjaGFyY29kZSkge1xuICAgICAgICByZXR1cm4gY2hhcmNvZGUgPj0gNjUgJiYgY2hhcmNvZGUgPD0gOTA7XG4gICAgfVxuXG59XG5cblV0aWxzLmlzV2ViID0gKHR5cGVvZiB3aW5kb3cgIT09IFwidW5kZWZpbmVkXCIpICYmICh0eXBlb2Ygc3BhcmtzY2VuZSA9PT0gXCJ1bmRlZmluZWRcIik7XG5VdGlscy5pc1dQRSA9IFV0aWxzLmlzV2ViICYmIChuYXZpZ2F0b3IudXNlckFnZW50LmluZGV4T2YoXCJXUEVcIikgIT09IC0xKTtcblV0aWxzLmlzU3BhcmsgPSAodHlwZW9mIHNwYXJ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zbyB0aGUgc2FtZS5cbiAgICAgICAgICAgIC8vIFByZXZlbnQgYW55IHNoYWRlciB1c2FnZSB0byBzYXZlIHBlcmZvcm1hbmNlLlxuXG4gICAgICAgICAgICB0aGlzLl9yZWFsU2hhZGVyID0gc2hhZGVyO1xuXG4gICAgICAgICAgICBpZiAoc2hhZGVyLnVzZURlZmF1bHQoKSkge1xuICAgICAgICAgICAgICAgIC8vIFVzZSB0aGUgZGVmYXVsdCBzaGFkZXIgd2hlbiBwb3NzaWJsZSB0byBwcmV2ZW50IHVubmVjZXNzYXJ5IHByb2dyYW0gY2hhbmdlcy5cbiAgICAgICAgICAgICAgICBzaGFkZXIgPSB0aGlzLmRlZmF1bHRTaGFkZXI7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy5fc2hhZGVyICE9PSBzaGFkZXIgfHwgdGhpcy5fc2hhZGVyT3duZXIgIT09IG93bmVyKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fc2hhZGVyID0gc2hhZGVyO1xuICAgICAgICAgICAgICAgIHRoaXMuX3NoYWRlck93bmVyID0gb3duZXI7XG4gICAgICAgICAgICAgICAgdGhpcy5fY2hlY2sgPSB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHJlbmRlclRleHR1cmVJbmZvKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcmVuZGVyVGV4dHVyZUluZm87XG4gICAgfVxuXG4gICAgc2V0U2Npc3NvcihhcmVhKSB7XG4gICAgICAgIGlmICh0aGlzLl9zY2lzc29yICE9PSBhcmVhKSB7XG4gICAgICAgICAgICBpZiAoYXJlYSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3NjaXNzb3IgPSBhcmVhO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9zY2lzc29yID0gbnVsbDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX2NoZW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AgICAgIC8vIEVsZW1lbnQgaXMgcmVuZGVyZWQgb24gYW5vdGhlciB0ZXh0dXJlLlxuICAgICAgICB0aGlzLl9yZW5kZXJUb1RleHR1cmVFbmFibGVkID0gZmFsc2U7XG5cbiAgICAgICAgdGhpcy5fdGV4dHVyaXplciA9IG51bGw7XG5cbiAgICAgICAgdGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlID0gZmFsc2U7XG5cbiAgICAgICAgdGhpcy5fYm91bmRzTWFyZ2luID0gbnVsbDtcblxuICAgICAgICB0aGlzLl9yZWNCb3VuZHNNYXJnaW4gPSBudWxsO1xuXG4gICAgICAgIHRoaXMuX3dpdGhpbkJvdW5kc01hcmdpbiA9IGZhbHNlO1xuXG4gICAgICAgIHRoaXMuX3ZpZXdwb3J0ID0gbnVsbDtcblxuICAgICAgICB0aGlzLl9jbGlwYm94ID0gdHJ1ZTtcblxuICAgICAgICB0aGlzLnJlbmRlciA9IHRoaXMuX3JlbmRlclNpbXBsZTtcblxuICAgICAgICB0aGlzLl9sYXlvdXQgPSBudWxsO1xuICAgIH1cblxuICAgIGdldCBvZmZzZXRYKCkge1xuICAgICAgICBpZiAodGhpcy5fZnVuY1gpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9mdW5jWDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh0aGlzLmhhc0ZsZXhMYXlvdXQoKSkge1xuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLl9sYXlvdXQub3JpZ2luYWxYO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5feDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHNldCBvZmZzZXRYKHYpIHtcbiAgICAgICAgaWYgKFV0aWxzLmlzRnVuY3Rpb24odikpIHtcbiAgICAgICAgICAgIHRoaXMuZnVuY1ggPSB2O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fZGlzYWJsZUZ1bmNYKCk7XG4gICAgICAgICAgICBpZiAodGhpcy5oYXNGbGV4TGF5b3V0KCkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLnggKz0gKHYgLSB0aGlzLl9sYXlvdXQub3JpZ2luYWxYKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9sYXlvdXQuc2V0T3JpZ2luYWxYV2l0aG91dFVwZGF0aW5nTGF5b3V0KHYpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLnggPSB2O1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl94O1xuICAgIH1cblxuICAgIHNldCB4KHYpIHtcbiAgICAgICAgaWYgKHYgIT09IHRoaXMuX3gpIHtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUxvY2FsVHJhbnNsYXRlRGVsdGEodiAtIHRoaXMuX3gsIDApO1xuICAgICAgICAgICAgdGhpcy5feCA9IHY7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgZnVuY1goKSB7XG4gICAgICAgIHJldHVybiAodGhpcy5fb3B0RmxhZ3MgJiAxID8gdGhpcy5fZnVuY1ggOiBudWxsKTtcbiAgICB9XG5cbiAgICBzZXQgZnVuY1godikge1xuICAgICAgICBpZiAodGhpcy5fZnVuY1ggIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX29wdEZsYWdzIHw9IDE7XG4gICAgICAgICAgICB0aGlzLl9mdW5jWCA9IHY7XG4gICAgICAgICAgICBpZiAodGhpcy5oYXNGbGV4TGF5b3V0KCkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9sYXlvdXQuc2V0T3JpZ2luYWxYV2l0aG91dFVwZGF0aW5nTGF5b3V0KDApO1xuICAgICAgICAgICAgICAgIHRoaXMubGF5b3V0LmZvcmNlTGF5b3V0KCk7XG4gICAgICAgIC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ICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy55ID0gdjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCB5KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5feTtcbiAgICB9XG5cbiAgICBzZXQgeSh2KSB7XG4gICAgICAgIGlmICh2ICE9PSB0aGlzLl95KSB7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVMb2NhbFRyYW5zbGF0ZURlbHRhKDAsIHYgLSB0aGlzLl95KTtcbiAgICAgICAgICAgIHRoaXMuX3kgPSB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGZ1bmNZKCkge1xuICAgICAgICByZXR1cm4gKHRoaXMuX29wdEZsYWdzICYgMiA/IHRoaXMuX2Z1bmNZIDogbnVsbCk7XG4gICAgfVxuXG4gICAgc2V0IGZ1bmNZKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX2Z1bmNZICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9vcHRGbGFncyB8PSAyO1xuICAgICAgICAgICAgdGhpcy5fZnVuY1kgPSB2O1xuICAgICAgICAgICAgaWYgKHRoaXMuaGFzRmxleExheW91dCgpKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fbGF5b3V0LnNldE9yaWdpbmFsWVdpdGhvdXRVcGRhdGluZ0xheW91dCgwKTtcbiAgICAgICAgICAgICAgICB0aGlzLmxheW91dC5mb3JjZUxheW91dCgpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl95ID0gMDtcbiAgICAgICAgICAgICAgICB0aGlzLl90cmlnZ2VyUmVjYWxjVHJhbnNsYXRlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZGlzYWJsZUZ1bmNZKCkge1xuICAgICAgICB0aGlzLl9vcHRGbGFncyA9IHRoaXMuX29wdEZsYWdzICYgKDB4RkZGRiAtIDIpO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2Z1bmNIID0gdjtcbiAgICAgICAgICAgIGlmICh0aGlzLmhhc0ZsZXhMYXlvdXQoKSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2xheW91dC5fb3JpZ2luYWxIZWlnaHQgPSAwO1xuICAgICAgICAgICAgICAgIHRoaXMubGF5b3V0LmNoYW5nZWREaW1lbnNpb25zKGZhbHNlLCB0cnVlKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5faCA9IDA7XG4gICAgICAgICAgICAgICAgdGhpcy5fdHJpZ2dlclJlY2FsY1RyYW5zbGF0ZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZGlzYWJsZUZ1bmNIKCkge1xuICAgICAgICB0aGlzLl9vcHRGbGFncyA9IHRoaXMuX29wdEZsYWdzICYgKDB4RkZGRiAtIDgpO1xuICAgICAgICB0aGlzLl9mdW5jSCA9IG51bGw7XG4gICAgfVxuXG4gICAgZ2V0IHcoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl93O1xuICAgIH1cblxuICAgIGdldFJlbmRlcldpZHRoKCkge1xuICAgICAgICBpZiAodGhpcy5oYXNGbGV4TGF5b3V0KCkpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9sYXlvdXQub3JpZ2luYWxXaWR0aDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl93O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9oO1xuICAgIH1cblxuICAgIGdldFJlbmRlckhlaWdodCgpIHtcbiAgICAgICAgaWYgKHRoaXMuaGFzRmxleExheW91dCgpKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fbGF5b3V0Lm9yaWdpbmFsSGVpZ2h0O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2g7XG4g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W50WSAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fbW91bnRZID0gdjtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUxvY2FsVHJhbnNsYXRlKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgbW91bnQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9tb3VudFg7XG4gICAgfVxuXG4gICAgc2V0IG1vdW50KHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX21vdW50WCAhPT0gdiB8fCB0aGlzLl9tb3VudFkgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX21vdW50WCA9IHY7XG4gICAgICAgICAgICB0aGlzLl9tb3VudFkgPSB2O1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlTG9jYWxUcmFuc2xhdGUoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCByb3RhdGlvbigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JvdGF0aW9uO1xuICAgIH1cblxuICAgIHNldCByb3RhdGlvbih2KSB7XG4gICAgICAgIGlmICh0aGlzLl9yb3RhdGlvbiAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fcm90YXRpb24gPSB2O1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlTG9jYWxUcmFuc2Zvcm0oKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBhbHBoYSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2FscGhhO1xuICAgIH1cblxuICAgIHNldCBhbHBoYSh2KSB7XG4gICAgICAgIC8vIEFjY291bnQgZm9yIHJvdW5kaW5nIGVycm9ycy5cbiAgICAgICAgdiA9ICh2ID4gMSA/IDEgOiAodiA8IDFlLTE0ID8gMCA6IHYpKTtcbiAgICAgICAgaWYgKHRoaXMuX2FscGhhICE9PSB2KSB7XG4gICAgICAgICAgICBsZXQgcHJldiA9IHRoaXMuX2FscGhhO1xuICAgICAgICAgICAgdGhpcy5fYWxwaGEgPS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aW9uKTtcbiAgICAgICAgICAgIGxldCBfY3IgPSBNYXRoLmNvcyh0aGlzLl9yb3RhdGlvbik7XG5cbiAgICAgICAgICAgIHRoaXMuX3NldExvY2FsVHJhbnNmb3JtKFxuICAgICAgICAgICAgICAgIF9jciAqIHRoaXMuX3NjYWxlWCxcbiAgICAgICAgICAgICAgICAtX3NyICogdGhpcy5fc2NhbGVZLFxuICAgICAgICAgICAgICAgIF9zciAqIHRoaXMuX3NjYWxlWCxcbiAgICAgICAgICAgICAgICBfY3IgKiB0aGlzLl9zY2FsZVlcbiAgICAgICAgICAgICk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9zZXRMb2NhbFRyYW5zZm9ybShcbiAgICAgICAgICAgICAgICB0aGlzLl9zY2FsZVgsXG4gICAgICAgICAgICAgICAgMCxcbiAgICAgICAgICAgICAgICAwLFxuICAgICAgICAgICAgICAgIHRoaXMuX3NjYWxlWVxuICAgICAgICAgICAgKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl91cGRhdGVMb2NhbFRyYW5zbGF0ZSgpO1xuICAgIH07XG5cbiAgICBfdXBkYXRlTG9jYWxUcmFuc2xhdGUoKSB7XG4gICAgICAgIHRoaXMuX3JlY2FsY0xvY2FsVHJhbnNsYXRlKCk7XG4gICAgICAgIHRoaXMuX3RyaWdnZXJSZWNhbGNUcmFuc2xhdGUoKTtcbiAgICB9O1xuXG4gICAgX3JlY2FsY0xvY2FsVHJhbnNsYXRlKCkge1xuICAgICAgICBsZXQgcGl2b3RYTXVsID0gdGhpcy5fcGl2b3RYICogdGhpcy5fdztcbiAgICAgICAgbGV0IHBpdm90WU11bCA9IHRoaXMuX3Bpdm90WSAqIHRoaXMuX2g7XG4gICAgICAgIGxldCBweCA9IHRoaXMuX3ggLSAocGl2b3RYTXVsICogdGhpcy5fbG9jYWxUYSArIHBpdm90WU11bCAqIHRoaXMuX2xvY2FsVGIpICsgcGl2b3RYTXVsO1xuICAgICAgICBsZ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AgfVxuXG4gICAgc2V0UGFyZW50KHBhcmVudCkge1xuICAgICAgICBpZiAocGFyZW50ICE9PSB0aGlzLl9wYXJlbnQpIHtcbiAgICAgICAgICAgIGxldCBwcmV2SXNaQ29udGV4dCA9IHRoaXMuaXNaQ29udGV4dCgpO1xuICAgICAgICAgICAgbGV0IHByZXZQYXJlbnQgPSB0aGlzLl9wYXJlbnQ7XG4gICAgICAgICAgICB0aGlzLl9wYXJlbnQgPSBwYXJlbnQ7XG5cbiAgICAgICAgICAgIC8vIE5vdGlmeSBmbGV4IGxheW91dCBlbmdpbmUuXG4gICAgICAgICAgICBpZiAodGhpcy5fbGF5b3V0IHx8IChwYXJlbnQgJiYgcGFyZW50LmlzRmxleENvbnRhaW5lcigpKSkge1xuICAgICAgICAgICAgICAgIHRoaXMubGF5b3V0LnNldFBhcmVudChwcmV2UGFyZW50LCBwYXJlbnQpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAocHJldlBhcmVudCkge1xuICAgICAgICAgICAgICAgIC8vIFdoZW4gZWxlbWVudHMgYXJlIGRlbGV0ZWQsIHRoZSByZW5kZXIgdGV4dHVyZSBtdXN0IGJlIHJlLXJlbmRlcmVkLlxuICAgICAgICAgICAgICAgIHByZXZQYXJlbnQuc2V0SGFzUmVuZGVyVXBkYXRlcygzKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdGhpcy5fc2V0UmVjYWxjKDEgKyAyICsgNCk7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9wYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAvLyBGb3JjZSBwYXJlbnQgdG8gcHJvcGFnYXRlIGhhc1VwZGF0ZXMgZmxhZy5cbiAgICAgICAgICAgICAgICB0aGlzLl9wYXJlbnQuX3NldEhhc1VwZGF0ZXMoKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX3pJbmRleCA9PT0gMCkge1xuICAgICAgICAgICAgICAgIHRoaXMuc2V0WlBhcmVudChwYXJlbnQpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLnNldFpQYXJlbnQocGFyZW50ID8gcGFyZW50LmZpbmRaQ29udGV4dCgpIDogbnVsbCk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChwcmV2SXNaQ29udGV4dCAhPT0gdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNaQ29udGV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZGlzYWJsZVpDb250ZXh0KCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbmFibGVaQ29udGV4dChwcmV2UGFyZW50LmZpbmRaQ29udGV4dCgpKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIFRyZWUgb3JkZXIgZGlkIGNoYW5nZTogZXZlbiBpZiB6UGFyZW50IHN0YXlzIHRoZSBzYW1lLCB3ZSBtdXN0IHJlc29ydC5cbiAgICAgICAgICAgIHRoaXMuX3pJbmRleFJlc29ydCA9IHRydWU7XG4gICAgICAgICAgICBpZiAodGhpcy5felBhcmVudCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZW5hYmxlWlNvcnQoKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKCF0aGlzLl9zaGFkZXIpIHtcbiAgICAgICAgICAgICAgICBsZXQgbmV3U2hhZGVyT3duZXIgPSBwYXJlbnQgJiYgIXBhcmVudC5fcmVuZGVyVG9UZXh0dXJlRW5hYmxlZCA/IHBhcmVudC5fc2hhZGVyT3duZXIgOiBudWxsO1xuICAgICAgICAgICAgICAgIGlmIChuZXdTaGFkZXJPd25lciAhPT0gdGhpcy5fc2hhZGVyT3duZXIpIHtcbiAgICAgICAgICAgICAgICAgICAgdGh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ZW5baW5kZXhdLnNldFBhcmVudChudWxsKTtcbiAgICAgICAgdGhpcy5fY2hpbGRyZW5baW5kZXhdID0gY2hpbGQ7XG4gICAgICAgIGNoaWxkLnNldFBhcmVudCh0aGlzKTtcbiAgICB9XG5cbiAgICByZW1vdmVDaGlsZEF0KGluZGV4KSB7XG4gICAgICAgIGxldCBjaGlsZCA9IHRoaXMuX2NoaWxkcmVuW2luZGV4XTtcbiAgICAgICAgdGhpcy5fY2hpbGRyZW4uc3BsaWNlKGluZGV4LCAxKTtcbiAgICAgICAgY2hpbGQuc2V0UGFyZW50KG51bGwpO1xuICAgIH07XG5cbiAgICByZW1vdmVDaGlsZHJlbigpIHtcbiAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLnNldFBhcmVudChudWxsKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW4uc3BsaWNlKDApO1xuXG4gICAgICAgICAgICBpZiAodGhpcy5fekluZGV4ZWRDaGlsZHJlbikge1xuICAgICAgICAgICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4uc3BsaWNlKDApO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfTtcblxuICAgIHN5bmNDaGlsZHJlbihyZW1vdmVkLCBhZGRlZCwgb3JkZXIpIHtcbiAgICAgICAgdGhpcy5fY2hpbGRyZW4gPSBvcmRlcjtcbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSByZW1vdmVkLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgcmVtb3ZlZFtpXS5zZXRQYXJlbnQobnVsbCk7XG4gICAgICAgIH1cbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBh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gdGhpcztcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9wYXJlbnQuZmluZFpDb250ZXh0KCk7XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgc2V0WlBhcmVudChuZXdaUGFyZW50KSB7XG4gICAgICAgIGlmICh0aGlzLl96UGFyZW50ICE9PSBuZXdaUGFyZW50KSB7XG4gICAgICAgICAgICBpZiAodGhpcy5felBhcmVudCAhPT0gbnVsbCkge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl96SW5kZXggIT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5felBhcmVudC5kZWNaQ29udGV4dFVzYWdlKCk7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgLy8gV2UgbXVzdCBmaWx0ZXIgb3V0IHRoaXMgaXRlbSB1cG9uIHRoZSBuZXh0IHJlc29ydC5cbiAgICAgICAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChuZXdaUGFyZW50ICE9PSBudWxsKSB7XG4gICAgICAgICAgICAgICAgbGV0IGhhZFpDb250ZXh0VXNhZ2UgPSAobmV3WlBhcmVudC5fekNvbnRleHRVc2FnZSA+IDApO1xuXG4gICAgICAgICAgICAgICAgLy8gQHByZTogbmV3IHBhcmVudCdzIGNoaWxkcmVuIGFycmF5IGhhcyBhbHJlYWR5IGJlZW4gbW9kaWZpZWQuXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3pJbmRleCAhPT0gMCkge1xuICAgICAgICAgICAgICAgICAgICBuZXdaUGFyZW50LmluY1pDb250ZXh0VXNhZ2UoKTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAobmV3WlBhcmVudC5fekNvbnRleHRVc2FnZSA+IDApIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFoYWRaQ29udGV4dFVzYWdlICYmICh0aGlzLl9wYXJlbnQgPT09IG5ld1pQYXJlbnQpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBUaGlzIGNoaWxkIHdhcyBhbHJlYWR5IGluIHRoZSBjaGlsZHJlbiBsaXN0LlxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gRG8gbm90IGFkZCBkb3VibGUuXG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBBZGQgbmV3IGNoaWxkIHRvIGFycmF5LlxuICAgICAgICAgICAgICAgICAgICAgICAgbmV3WlBhcmVudC5fekluZGV4ZWRDaGlsZHJlbi5wdXNoKHRoaXMpO1xuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgLy8gT3JkZXIgc2hvdWxkIGJlIGNoZWNrZWQuXG4gICAgICAgICAgICAgICAgICAgIG5ld1pQYXJlbnQuZW5hYmxlWlNvcnQoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQgPSBuZXdaUGFyZW50O1xuXG4gICAgICAgICAgICAvLyBOZXdseSBhZGRlZCBlbGVtZW50IG11c3QgYmUgbWFya2VkIGZvciByZXNvcnQuXG4gICAgICAgICAgICB0aGlzLl96SW5kZXhSZXNvcnQgPSB0cnVlO1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIGluY1pDb250ZXh0VXNhZ2UoKSB7XG4gICAgICAgIHRoaXMuX3pDb250ZXh0VXNhZ2UrKztcbiAgICAgICAgaWYgKHRoaXMuX3pDb250ZXh0VXNhZ2UgPT09IDEpIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5fekluZGV4ZWRDaGlsZHJlbikge1xuICAgICAgICAgICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4gPSBbXTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgICAgICAgIC8vIENvcHkuXG4gICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9jaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fekluZGV4ZWRDaGlsZHJlbi5wdXNoKHRoaXMuX2NoaWxkcmVuW2ldKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgLy8gSW5pdGlhbGx5LCBjaGlsZHJlbiBhcmUgYWxyZWFkeSBzb3J0ZWQgcHJvcGVybHkgKHRyZWUgb3JkZXIpLlxuICAgICAgICAgICAgICAgIHRoaXMuX3pTb3J0ID0gZmFsc2U7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgZGVjWkNvbnRleHRVc2FnZSgpIHtcbiAgICAgICAgdGhpcy5fekNvbnRleHRVc2FnZS0tO1xuICAgICAgICBpZiAodGhpcy5fekNvbnRleHRVc2FnZSA9PT0gMCkge1xuICAgICAgICAgICAgdGhpcy5felNvcnQgPSBmYWxzZTtcbiAgICAgICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4uc3BsaWNlKDApO1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIGdldCB6SW5kZXgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl96SW5kZXg7XG4gICAgfVxuXG4gICAgc2V0IHpJbmRleCh6SW5kZXgpIHtcbiAgICAgICAgaWYgKHRoaXMuX3pJbmRleCAhPT0gekluZGV4KSB7XG4gICAgICAgICAgICB0aGlzLnNldEhhc1JlbmRlclVwZGF0ZXMoMSk7XG5cbiAgICAgICAgICAgIGxldCBuZXdaUGFyZW50ID0gdGhpcy5felBhcmVudDtcblxuICAgICAgICAgICAgbGV0IHByZXZJc1pDb250ZXh0ID0gdGhpcy5pc1pDb250ZXh0KCk7XG4gICAgICAgICAgICBpZiAoekluZGV4ID09PSAwICYmIHRoaXMuX3pJbmRleCAhPT0gMCkge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9wYXJlbnQgPT09IHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZGVjWkNvbnRleHRVc2FnZSgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgbmV3WlBhcmVudCA9IHRoaXMuX3BhcmVudDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHpJbmRleCAhPT0gMCAmJiB0aGlzLl96SW5kZXggPT09IDApIHtcbiAgICAgICAgICAgICAgICBuZXdaUGFyZW50ID0gdGhpcy5fcGFyZW50ID8gdGhpcy5fcGFyZW50LmZpbmRaQ29udGV4dCgpIDogbnVsbDtcbiAgICAgICAgICAgICAgICBpZiAobmV3WlBhcmVudCA9PT0gdGhpcy5felBhcmVudCkge1xuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5felBhcmVudCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5felBhcmVudC5pbmNaQ29udGV4dFVzYWdlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHpJbmRleCAhPT0gdGhpcy5fekluZGV4KSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQgJiYgdGhpcy5felBhcmVudC5fekNvbnRleHRVc2FnZSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAobmV3WlBhcmVudCAhPT0gdGhpcy5felBhcmVudCkge1xuICAgICAgICAgICAgICAgIHRoaXMuc2V0WlBhcmVudChudWxsKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdGhpcy5fekluZGV4ID0gekluZGV4O1xuXG4gICAgICAgICAgICBpZiAobmV3WlBhcmVudCAhPT0gdGhpcy5felBhcmVudCkge1xuICAgICAgICAgICAgICAgIHRoaXMuc2V0WlBhcmVudChuZXdaUGFyZW50KTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHByZXZJc1pDb250ZXh0ICE9PSB0aGlzLmlzWkNvbnRleHQoKSkge1xuICAgICAgICAgICAgICAgIGlmICghdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5kaXNhYmxlWkNvbnRleHQoKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmVuYWJsZVpDb250ZXh0KHRoaXMuX3BhcmVudC5maW5kWkNvbnRleHQoKSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBNYWtlIHN1cmUgdGhhdCByZXNvcnQgaXMgZG9uZS5cbiAgICAgICAgICAgIHRoaXMuX3pJbmRleFJlc29ydCA9IHRydWU7XG4gICAgICAgICAgICBpZiAodGhpcy5felBhcmVudCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZW5hYmxlWlNvcnQoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBnZXQgZm9yY2VaSW5kZXhDb250ZXh0KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fZm9yY2VaSW5kZXhDb250ZXh0O1xuICAgIH1cblxuICAgIHNldCBmb3JjZVpJbmRleENvbnRleHQodikge1xuICAgICAgICB0aGlzLnNldEhhc1JlbmRlclVwZGF0ZXMoMSk7XG5cbiAgICAgICAgbGV0IHByZXZJc1pDb250ZXh0ID0gdGhpcy5pc1pDb250ZXh0KCk7XG4gICAgICAgIHRoaXMuX2ZvcmNlWkluZGV4Q29udGV4dCA9IHY7XG5cbiAgICAgICAgaWYgKHByZXZJc1pDb250ZXh0ICE9PSB0aGlzLmlzWkNvbnRleHQoKSkge1xuICAgICAgICAgICAgaWYgKCF0aGlzLmlzWkNvbnRleHQoKSkge1xuICAgICAgICAgICAgICAgIHRoaXMuZGlzYWJsZVpDb250ZXh0KCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuZW5hYmxlWkNvbnRleHQodGhpcy5fcGFyZW50LmZpbmRaQ29udGV4dCgpKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBlbmFibGVaQ29udGV4dChwcmV2WkNvbnRleHQpIHtcbiAgICAgICAgaWYgKHByZXZaQ29udGV4dCAmJiBwcmV2WkNvbnRleHQuX3pDb250ZXh0VXNhZ2UgPiAwKSB7XG4gICAgICAgICAgICAvLyBUcmFuc2ZlciBmcm9tIHVwcGVyIHogY29udGV4dCB0byB0aGlzIHogY29udGV4dC5cbiAgICAgICAgICAgIGNvbnN0IHJlc3VsdHMgPSB0aGlzLl9nZXRaSW5kZXhlZERlc2NzKCk7XG4gICAgICAgICAgICByZXN1bHRzLmZvckVhY2goKGMpID0+IHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5pc0FuY2VzdG9yT2YoYykgJiYgYy5fekluZGV4ICE9PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIGMuc2V0WlBhcmVudCh0aGlzKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9nZXRaSW5kZXhlZERlc2NzKCkge1xuICAgICAgICBjb25zdCByZXN1bHRzID0gW107XG4gICAgICAgIGlmICh0aGlzL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3pTb3J0KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5zb3J0WkluZGV4ZWRDaGlsZHJlbigpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuLnNsaWNlKCkuZm9yRWFjaChmdW5jdGlvbiAoYykge1xuICAgICAgICAgICAgICAgIGlmIChjLl96SW5kZXggIT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgYy5zZXRaUGFyZW50KG5ld1pQYXJlbnQpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIGdldCBjb2xvclVsKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fY29sb3JVbDtcbiAgICB9XG5cbiAgICBzZXQgY29sb3JVbChjb2xvcikge1xuICAgICAgICBpZiAodGhpcy5fY29sb3JVbCAhPT0gY29sb3IpIHtcbiAgICAgICAgICAgIHRoaXMuc2V0SGFzUmVuZGVyVXBkYXRlcyh0aGlzLl9kaXNwbGF5ZWRUZXh0dXJlU291cmNlID8gMyA6IDEpO1xuICAgICAgICAgICAgdGhpcy5fY29sb3JVbCA9IGNvbG9yO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGNvbG9yVXIoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9jb2xvclVyO1xuICAgIH1cblxuICAgIHNldCBjb2xvclVyKGNvbG9yKSB7XG4gICAgICAgIGlmICh0aGlzLl9jb2xvclVyICE9PSBjb2xvcikge1xuICAgICAgICAgICAgdGhpcy5zZXRIYXNSZW5kZXJVcGRhdGVzKHRoaXMuX2Rpc3BsYXllZFRleHR1cmVTb3VyY2UgPyAzIDogMSk7XG4gICAgICAgICAgICB0aGlzLl9jb2xvclVyID0gY29sb3I7XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgZ2V0IGNvbG9yQmwoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9jb2xvckJsO1xuICAg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l9jaGlsZHJlbltpXTtcbiAgICAgICAgICAgICAgICBpZiAoIWMuX3NoYWRlcikge1xuICAgICAgICAgICAgICAgICAgICBjLl9zZXRTaGFkZXJPd25lclJlY3Vyc2l2ZShlbGVtZW50Q29yZSk7XG4gICAgICAgICAgICAgICAgICAgIGMuX2hhc1JlbmRlclVwZGF0ZXMgPSAzO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBfc2V0U2hhZGVyT3duZXJDaGlsZHJlblJlY3Vyc2l2ZShlbGVtZW50Q29yZSkge1xuICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgbGV0IGMgPSB0aGlzLl9jaGlsZHJlbltpXTtcbiAgICAgICAgICAgICAgICBpZiAoIWMuX3NoYWRlcikge1xuICAgICAgICAgICAgICAgICAgICBjLl9zZXRTaGFkZXJPd25lclJlY3Vyc2l2ZShlbGVtZW50Q29yZSk7XG4gICAgICAgICAgICAgICAgICAgIGMuX2hhc1JlbmRlclVwZGF0ZXMgPSAzO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBfaGFzUmVuZGVyQ29udGV4dCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JlbmRlckNvbnRleHQgIT09IHRoaXMuX3dvcmxkQ29udGV4dDtcbiAgICB9XG5cbiAgICBnZXQgcmVuZGVyQ29udGV4dCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgfVxuXG4gICAgdXBkYXRlUmVuZGVyVG9UZXh0dXJlRW5hYmxlZCgpIHtcbiAgICAgICAgLy8gRW5mb3JjZSB0ZXh0dXJpemVyIGlu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GEgPCAxZS0xNCkge1xuICAgICAgICAgICAgICAgICAgICAvLyBUaW55IHJvdW5kaW5nIGVycm9ycyBtYXkgY2F1c2UgZmFpbGluZyB2aXNpYmlsaXR5IHRlc3RzLlxuICAgICAgICAgICAgICAgICAgICB3LmFscGhhID0gMDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChyZWNhbGMgJiA2KSB7XG4gICAgICAgICAgICAgICAgdy5weCA9IHB3LnB4ICsgdGhpcy5fbG9jYWxQeCAqIHB3LnRhO1xuICAgICAgICAgICAgICAgIHcucHkgPSBwdy5weSArIHRoaXMuX2xvY2FsUHkgKiBwdy50ZDtcbiAgICAgICAgICAgICAgICBpZiAocHcudGIgIT09IDApIHcucHggKz0gdGhpcy5fbG9jYWxQeSAqIHB3LnRiO1xuICAgICAgICAgICAgICAgIGlmIChwdy50YyAhPT0gMCkgdy5weSArPSB0aGlzLl9sb2NhbFB4ICogcHcudGM7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChyZWNhbGMgJiA0KSB7XG4gICAgICAgICAgICAgICAgdy50YSA9IHRoaXMuX2xvY2FsVGEgKiBwdy50YTtcbiAgICAgICAgICAgICAgICB3LnRiID0gdGhpcy5fbG9jYWxUZCAqIHB3LnRiO1xuICAgICAgICAgICAgICAgIHcudGMgPSB0aGlzLl9sb2NhbFRhICogcHcudGM7XG4gICAgICAgICAgICAgICAgdy50ZCA9IHRoaXMuX2xvY2FsVGQgKiBwdy50ZDtcblxuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9pc0NvbXBsZXgpIHtcbiAgICAgICAgICAgICAgICAgICAgdy50YSArPSB0aGlzLl9sb2NhbFRjICogcHcudGI7XG4gICAgICAgICAgICAgICAgICAgIHcudGIgKz0gdGhpcy5fbG9jYWxUYiAqIHB3LnRhO1xuICAgICAgICAgICAgICAgICAgICB3LnRjICs9IHRoaXMuX2xvY2FsVGMgKiBwdy50ZDtcbiAgICAgICAgICAgICAgICAgICAgdy50ZCArPSB0aGlzLl9sb2NhbFRiICogcHcudGM7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBVcGRhdGUgcmVuZGVyIGNvb3Jkcy9hbHBoYS5cbiAgICAgICAgICAgIGNvbnN0IHByID0gdGhpcy5fcGFyZW50Ll9yZW5kZXJDb250ZXh0O1xuICAgICAgICAgICAgaWYgKHRoaXMuX3BhcmVudC5faGFzUmVuZGVyQ29udGV4dCgpKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgaW5pdCA9IHRoaXMuX3JlbmRlckNvbnRleHQgPT09IHRoaXMuX3dvcmxkQ29udGV4dDtcbiAgICAgICAgICAgICAgICBpZiAoaW5pdCkge1xuICAgICAgICAgICAgICAgICAgICAvLyBGaXJzdCByZW5kZXIgY29udGV4dCBidWlsZDogbWFrZSBzdXJlIHRoYXQgaXQgaXMgZnVsbHkgaW5pdGlhbGl6ZWQgY29ycmVjdGx5LlxuICAgICAgICAgICAgICAgICAgICAvLyBPdGhlcndpc2UsIGlmIHdlIGdldCBpbnRvIGJvdW5kcyBsYXRlciwgdGhlIHJlbmRlciBjb250ZXh0IHdvdWxkIG5vdCBiZSBpbml0aWFsaXplZCBjb3JyZWN0bHkuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSBuZXcgRWxlbWVudENvcmVDb250ZXh0KCk7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgY29uc3QgciA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG5cbiAgICAgICAgICAgICAgICAvLyBVcGRhdGUgd29ybGQgY29vcmRzL2FscGhhLlxuICAgICAgICAgICAgICAgIGlmIChpbml0IHx8IChyZWNhbGMgJiAxKSkge1xuICAgICAgICAgICAgICAgICAgICByLmFscGhhID0gcHIuYWxwaGEgKiB0aGlzLl9sb2NhbEFscGhhO1xuXG4gICAgICAgICAgICAgICAgICAgIGlmIChyLmFscGhhIDwgMWUtMTQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHIuYWxwaGEgPSAwO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaWYgKGluaXQgfHwgKHJlY2FsYyAmIDYpKSB7XG4gICAgICAgICAgICAgICAgICAgIHIucHggPSBwci5weCArIHRoaXMuX2xvY2FsUHggKiBwci50YTtcbiAgICAgICAgICAgICAgICAgICAgci5weSA9IHByLnB5ICsgdGhpcy5fbG9jYWxQeSAqIHByLnRkO1xuICAgICAgICAgICAgICAgICAgICBpZiAocHIudGIgIT09IDApIHIucHggKz0gdGhpcy5fbG9jYWxQeSAqIHByLnRiO1xuICAgICAgICAgICAgICAgICAgICBpZiAocHIudGMgIT09IDApIHIucHkgKz0gdGhpcy5fbG9jYWxQeCAqIHByLnRjO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmIChpbml0KSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFdlIHNldCB0aGUgcmVjYWxjIHRvZ2dsZSwgYmVjYXVzZSB3ZSBtdXN0IG1ha2Ugc3VyZSB0aGF0IHRoZSBzY2lzc29yIGlzIHVwZGF0ZWQuXG4gICAgICAgICAgICAgICAgICAgIHJlY2FsYyB8PSAyO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmIChpbml0IHx8IChyZWNhbGMgJiA0KSkge1xuICAgICAgICAgICAgICAgICAgICByLnRhID0gdGhpcy5fbG9jYWxUYSAqIHByLnRhO1xuICAgICAgICAgICAgICAgICAgICByLnRiID0gdGhpcy5fbG9jYWxUZCAqIHByLnRiO1xuICAgICAgICAgICAgICAgICAgICByLnRjID0gdGhpcy5fbG9jYWxUYSAqIHByLnRjO1xuICAgICAgICAgICAgICAgICAgICByLnRkID0gdGhpcy5fbG9jYWxUZCAqIHByLnRkO1xuXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9pc0NvbXBsZXgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHIudGEgKz0gdGhpcy5fbG9jYWxUYyAqIHByLnRiO1xuICAgICAgICAgICAgICAgICAgICAgICAgci50YiArPSB0aGlzLl9sb2NhbFRiICogcHIudGE7XG4gICAgICAgICAgICAgICAgICAgICAgICByLnRjICs9IHRoaXMuX2xvY2FsVGMgKiBwci50ZDtcbiAgICAgICAgICAgICAgICAgICAgICAgIHIudGQgKz0gdGhpcy5fbG9jYWxUYiAqIHByLnRjO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gdGhpcy5fd29ybGRDb250ZXh0O1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAodGhpcy5jdHgudXBkYXRlVHJlZU9yZGVyID09PSAtMSkge1xuICAgICAgICAgICAgICAgIHRoaXMuY3R4LnVwZGF0ZVRyZWVPcmRlciA9IHRoaXMuX3VwZGF0ZVRyZWVPcmRlciArIDE7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVRyZWVPcmRlciA9IHRoaXMuY3R4LnVwZGF0ZVRyZWVPcmRlcisrO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBEZXRlcm1pbmUgd2hldGhlciB3ZSBtdXN0IHVzZSBhICdyZW5kZXJUZXh0dXJlJy5cbiAgICAgICAgICAgIGNvbnN0IHVzZVJlbmRlclRvVGV4dHVyZSA9IHRoaXMuX3JlbmRlclRvVGV4dHVyZUVuYWJsZWQgJiYgdGhpcy5fdGV4dHVyaXplci5tdXN0UmVuZGVyVG9UZXh0dXJlKCk7XG4gICAgICAgICAgICBpZiAodGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlICE9PSB1c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICAgICAgICAvLyBDb29yZHMgbXVzdCBiZSBjaGFuZ2VkLlxuICAgICAgICAgICAgICAgIHRoaXMuX3JlY2FsYyB8PSAyICsgNDtcblxuICAgICAgICAgICAgICAgIC8vIFNjaXNzb3IgbWF5IGNoYW5nZTogZm9yY2UgdXBkYXRlLlxuICAgICAgICAgICAgICAgIHJlY2FsYyB8PSAyO1xuXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gV2UgbXVzdCByZWxlYXNlIHRoZSB0ZXh0dXJlLlxuICAgICAgICAgICAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLnJlbGVhc2UoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUgPSB1c2VSZW5kZXJUb1RleHR1cmU7XG5cbiAgICAgICAgICAgIGNvbnN0IHIgPSB0aGlzLl9yZW5kZXJDb250ZXh0O1xuXG4gICAgICAgICAgICBjb25zdCBiYm94VyA9IHRoaXMuX2RpbXNVbmtub3duID8gMjA0OCA6IHRoaXMuX3c7XG4gICAgICAgICAgICBjb25zdCBiYm94SCA9IHRoaXMuX2RpbXNVbmtub3duID8gMjA0OCA6IHRoaXMuX2g7XG5cbiAgICAgICAgICAgIC8vIENhbGN1bGF0ZSBhIGJib3ggZm9yIHRoaXMgZWxlbWVudC5cbiAgICAgICAgICAgIGxldCBzeCwgc3ksIGV4LCBleTtcbiAgICAgICAgICAgIGNvbnN0IHJDb21wbGV4ID0gKHIudGIgIT09IDApIHx8IChyLnRjICE9PSAwKSB8fCAoci50YSA8IDApIHx8IChyLnRkIDwgMCk7XG4gICAgICAgICAgICBpZiAockNvbXBsZXgpIHtcbiAgICAgICAgICAgICAgICBzeCA9IE1hdGgubWluKDAsIGJib3hXICogci50YSwgYmJveFcgKiByLnRhICsgYmJveEggKiByLnRiLCBiYm94SCAqIHIudGIpICsgci5weDtcbiAgICAgICAgICAgICAgICBleCA9IE1hdGgubWF4KDAsIGJib3hXICogci50YSwgYmJveFcgKiByLnRhICsgYmJveEggKiByLnRiLCBiYm94SCAqIHIudGIpICsgci5weDtcbiAgICAgICAgICAgICAgICBzeSA9IE1hdGgubWluKDAsIGJib3hXICogci50YywgYmJveFcgKiByLnRjICsgYmJveEggKiByLnRkLCBiYm94SCAqIHIudGQpICsgci5weTtcbiAgICAgICAgICAgICAgICBleSA9IE1hdGgubWF4KDAsIGJib3hXICogci50YywgYmJveFcgKiByLnRjICsgYmJveEggKiByLnRkLCBiYm94SCAqIHIudGQpICsgci5weTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgc3ggPSByLnB4O1xuICAgICAgICAgICAgICAgIGV4ID0gci5weCArIHIudGEgKiBiYm94VztcbiAgICAgICAgICAgICAgICBzeSA9IHIucHk7XG4gICAgICAgICAgICAgICAgZXkgPSByLnB5ICsgci50ZCAqIGJib3hIO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAodGhpcy5fZGltc1Vua25vd24gJiYgKHJDb21wbGV4IHx8IHRoaXMuX2xvY2FsVGEgPCAxIHx8IHRoaXMuX2xvY2FsVGIgPCAxKSkge1xuICAgICAgICAgICAgICAgIC8vIElmIHdlIGFyZSBkZWFsaW5nIHdpdGggYSBub24taWRlbnRpdHkgbWF0cml4LCB3ZSBtdXN0IGV4dGVuZCB0aGUgYmJveCBzbyB0aGF0IHdpdGhpbkJvdW5kcyBhbmRcbiAgICAgICAgICAgICAgICAvLyAgc2Npc3NvcnMgd2lsbCBpbmNsdWRlIHRoZSBjb21wbGV0ZSByYW5nZSBvZiAocG9zaXRpdmUpIGRpbWVuc2lvbnMgdXAgdG8gLGxoLlxuICAgICAgICAgICAgICAgIGNvbnN0IG54ID0gdGhpcy5feCAqIHByLnRhICsgdGhpcy5feSAqIHByLnRiICsgcHIucHg7XG4gICAgICAgICAgICAgICAgY29uc3QgbnkgPSB0aGlzLl94ICogcHIudGMgKyB0aGlzLl95ICogcHIudGQgKyBwci5weTtcbiAgICAgICAgICAgICAgICBpZiAobnggPCBzeCkgc3ggPSBueDtcbiAgICAgICAgICAgICAgICBpZiAobnkgPCBzeSkgc3kgPSBueTtcbiAgICAgICAgICAgICAgICBpZiAobnggPiBleCkgZXggPSBueDtcbiAgICAgICAgICAgICAgICBpZiAobnkgPiBleSkgZXkgPSBueTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHJlY2FsYyAmIDYgfHwgIXRoaXMuX3NjaXNzb3IgLyogaW5pdGlhbCAqLykge1xuICAgICAgICAgICAgICAgIC8vIERldGVybWluZSB3aGV0aGVyIHdlIG11c3QgJ2NsaXAnLlxuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9jbGlwcGluZyAmJiByLmlzU3F1YXJlKCkpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gSWYgdGhlIHBhcmVudCByZW5kZXJzIHRvIGEgdGV4dHVyZSwgaXQncyBzY2lzc29yIHNob3VsZCBiZSBpZ25vcmVkO1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBhcmVhID0gdGhpcy5fcGFyZW50Ll91c2VSZW5kZXJUb1RleHR1cmUgPyB0aGlzLl9wYXJlbnQuX3ZpZXdwb3J0IDogdGhpcy5fcGFyZW50Ll9zY2lzc29yO1xuICAgICAgICAgICAgICAgICAgICBpZiAoYXJlYSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gTWVyZ2Ugc2Npc3NvciBhcmVhcy5cbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGx4ID0gTWF0aC5tYXgoYXJlYVswXSwgc3gpO1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgbHkgPSBNYXRoLm1heChhcmVhWzFdLCBzeSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9zY2lzc29yID0gW1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGx4LFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGx5LFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIE1hdGgubWluKGFyZWFbMl0gKyBhcmVhWzBdLCBleCkgLSBseCxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBNYXRoLm1pbihhcmVhWzNdICsgYXJlYVsxXSwgZXkpIC0gbHlcbiAgICAgICAgICAgICAgICAgICAgICAgIF07XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9zY2lzc29yID0gW3N4LCBzeSwgZXggLSBzeCwgZXkgLSBzeV07XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAvLyBObyBjbGlwcGluZzogcmV1c2UgcGFyZW50IHNjaXNzb3IuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3NjaXNzb3IgPSB0aGlzLl9wYXJlbnQuX3VzZVJlbmRlclRvVGV4dHVyZSA/IHRoaXMuX3BhcmVudC5fdmlld3BvcnQgOiB0aGlzLl9wYXJlbnQuX3NjaXNzb3I7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBDYWxjdWxhdGUgdGhlIG91dE9mQm91bmRzIG1hcmdpbi5cbiAgICAgICAgICAgIGlmICh0aGlzLl9ib3VuZHNNYXJnaW4pIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9yZWNCb3VuZHNNYXJnaW4gPSB0aGlzLl9ib3VuZHNNYXJnaW47XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX3JlY0JvdW5kc01hcmdpbiA9IHRoaXMuX3BhcmVudC5fcmVjQm91bmRzTWFyZ2luO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAodGhpcy5fb25BZnRlckNhbGNzKSB7XG4gICAgICAgICAgICAgICAgLy8gQWZ0ZXIgY2FsY3MgbWF5IGNoYW5nZSByZW5kZXIgY29vcmRzLCBzY2lzc29yIGFuZC9vciByZWNCb3VuZHNNYXJnaW4uXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX29uQWZ0ZXJDYWxjcyh0aGlzLmVsZW1lbnQpKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFJlY2FsY3VsYXRlIGJib3guXG4gICAgICAgICAgICAgICAgICAgIGlmIChyQ29tcGxleCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3ggPSBNYXRoLm1pbigwLCBiYm94VyAqIHIudGEsIGJib3hXICogci50YSArIGJib3hIICogci50YiwgYmJveEggKiByLnRiKSArIHIucHg7XG4gICAgICAgICAgICAgICAgICAgICAgICBleCA9IE1hdGgubWF4KDAsIGJib3hXICogci50YSwgYmJveFcgKiByLnRhICsgYmJveEggKiByLnRiLCBiYm94SCAqIHIudGIpICsgci5weDtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN5ID0gTWF0aC5taW4oMCwgYmJveFcgKiByLnRjLCBiYm94VyAqIHIudGMgKyBiYm94SCAqIHIudGQsIGJib3hIICogci50ZCkgKyByLnB5O1xuICAgICAgICAgICAgICAgICAgICAgICAgZXkgPSBNYXRoLm1heCgwLCBiYm94VyAqIHIudGMsIGJib3hXICogci50YyArIGJib3hIICogci50ZCwgYmJveEggKiByLnRkKSArIHIucHk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzeCA9IHIucHg7XG4gICAgICAgICAgICAgICAgICAgICAgICBleCA9IHIucHggKyByLnRhICogYmJveFc7XG4gICAgICAgICAgICAgICAgICAgICAgICBzeSA9IHIucHk7XG4gICAgICAgICAgICAgICAgICAgICAgICBleSA9IHIucHkgKyByLnRkICogYmJveEg7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fZGltc1Vua25vd24gJiYgKHJDb21wbGV4IHx8IHRoaXMuX2xvY2FsVGEgPCAxIHx8IHRoaXMuX2xvY2FsVGIgPCAxKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgbnggPSB0aGlzLl94ICogcHIudGEgKyB0aGlzLl95ICogcHIudGIgKyBwci5weDtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IG55ID0gdGhpcy5feCAqIHByLnRjICsgdGhpcy5feSAqIHByLnRkICsgcHIucHk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAobnggPCBzeCkgc3ggPSBueDtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChueSA8IHN5KSBzeSA9IG55O1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG54ID4gZXgpIGV4ID0gbng7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAobnkgPiBleSkgZXkgPSBueTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX3BhcmVudC5fb3V0T2ZCb3VuZHMgPT09IDIpIHtcbiAgICAgICAgICAgICAgICAvLyBJbmhlcml0IHBhcmVudCBvdXQgb2YgYm91bmRzbmVzcy5cbiAgICAgICAgICAgICAgICB0aGlzLl9vdXRPZkJvdW5kcyA9IDI7XG5cbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fd2l0aGluQm91bmRzTWFyZ2luKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3dpdGhpbkJvdW5kc01hcmdpbiA9IGZhbHNlO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmVsZW1lbnQuX2Rpc2FibGVXaXRoaW5Cb3VuZHNNYXJnaW4oKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGlmIChyZWNhbGMgJiA2KSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFJlY2hlY2sgaWYgZWxlbWVudCBpcyBvdXQtb2YtYm91bmRzIChhbGwgc2V0dGluZ3MgdGhhdCBhZmZlY3QgdGhpcyBzaG91bGQgZW5hYmxlIHJlY2FsYyBiaXQgMiBvciA0KS5cbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fb3V0T2ZCb3VuZHMgPSAwO1xuICAgICAgICAgICAgICAgICAgICBsZXQgd2l0aGluTWFyZ2luID0gdHJ1ZTtcblxuICAgICAgICAgICAgICAgICAgICAvLyBPZmZzY3JlZW5zIGFyZSBhbHdheXMgcmVuZGVyZWQgYXMgbG9uZyBhcyB0aGUgcGFyZW50IGlzIHdpdGhpbiBib3VuZHMuXG4gICAgICAgICAgICAgICAgICAgIGlmICghdGhpcy5fcmVuZGVyVG9UZXh0dXJlRW5hYmxlZCB8fCAhdGhpcy5fdGV4dHVyaXplciB8fCAhdGhpcy5fdGV4dHVyaXplci5yZW5kZXJPZmZzY3JlZW4pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9zY2lzc29yICYmICh0aGlzLl9zY2lzc29yWzJdIDw9IDAgfHwgdGhpcy5fc2Npc3NvclszXSA8PSAwKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIEVtcHR5IHNjaXNzb3IgYXJlYS5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9vdXRPZkJvdW5kcyA9IDI7XG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIFVzZSBiYm94IHRvIGNoZWNrIG91dC1vZi1ib3VuZG5lc3MuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCh0aGlzLl9zY2lzc29yWzBdID4gZXgpIHx8XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICh0aGlzLl9zY2lzc29yWzFdID4gZXkpIHx8XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChzeCA+ICh0aGlzLl9zY2lzc29yWzBdICsgdGhpcy5fc2Npc3NvclsyXSkpIHx8XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChzeSA+ICh0aGlzLl9zY2lzc29yWzFdICsgdGhpcy5fc2Npc3NvclszXSkpXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fb3V0T2ZCb3VuZHMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX2NsaXBwaW5nIHx8IHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSB8fCAodGhpcy5fY2xpcGJveCAmJiAoYmJveFcgJiYgYmJveEgpKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fb3V0T2ZCb3VuZHMgPSAyO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgICAgICB3aXRoaW5NYXJnaW4gPSAodGhpcy5fb3V0T2ZCb3VuZHMgPT09IDApO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCF3aXRoaW5NYXJnaW4pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBSZS10ZXN0LCBub3cgd2l0aCBtYXJnaW5zLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9yZWNCb3VuZHNNYXJnaW4pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgd2l0aGluTWFyZ2luID0gISgoZXggPCB0aGlzLl9zY2lzc29yWzBdIC0gdGhpcy5fcmVjQm91bmRzTWFyZ2luWzJdKSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGV5IDwgdGhpcy5fc2Npc3NvclsxXSAtIHRoaXMuX3JlY0JvdW5kc01hcmdpblszXSkgfHxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChzeCA+IHRoaXMuX3NjaXNzb3JbMF0gKyB0aGlzLl9zY2lzc29yWzJdICsgdGhpcy5fcmVjQm91bmRzTWFyZ2luWzBdKSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHN5ID4gdGhpcy5fc2Npc3NvclsxXSArIHRoaXMuX3NjaXNzb3JbM10gKyB0aGlzLl9yZWNCb3VuZHNNYXJnaW5bMV0pKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3aXRoaW5NYXJnaW4gPSAhKChleCA8IHRoaXMuX3NjaXNzb3JbMF0gLSAxMDApIHx8XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoZXkgPCB0aGlzLl9zY2lzc29yWzFdIC0gMTAwKSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHN4ID4gdGhpcy5fc2Npc3NvclswXSArIHRoaXMuX3NjaXNzb3JbMl0gKyAxMDApIHx8XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoc3kgPiB0aGlzLl9zY2lzc29yWzFdICsgdGhpcy5fc2Npc3NvclszXSArIDEwMCkpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod2l0aGluTWFyZ2luICYmIHRoaXMuX291dE9mQm91bmRzID09PSAyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIENoaWxkcmVuIG11c3QgYmUgdmlzaXRlZCBiZWNhdXNlIHRoZXkgbWF5IGNvbnRhaW4gZWxlbWVudHMgdGhhdCBhcmUgd2l0aGluIG1hcmdpbiwgc28gbXVzdCBiZSB2aXNpYmxlLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9vdXRPZkJvdW5kcyA9IDE7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX3dpdGhpbkJvdW5kc01hcmdpbiAhPT0gd2l0aGluTWFyZ2luKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4gPSB3aXRoaW5NYXJnaW47XG5cbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBUaGlzIG1heSB1cGRhdGUgdGhpbmdzICh0eExvYWRlZCBldmVudHMpIGluIHRoZSBlbGVtZW50IGl0c2VsZiwgYnV0IGFsc28gaW4gZGVzY2VuZGFudHMgYW5kIGFuY2VzdG9ycy5cblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIENoYW5nZXMgaW4gYW5jZXN0b3JzIHNob3VsZCBiZSBleGVjdXRlZCBkdXJpbmcgdGhlIG5leHQgY2FsbCBvZiB0aGUgc3RhZ2UgdXBkYXRlLiBCdXQgd2UgbXVzdFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIHRha2UgY2FyZSB0aGF0IHRoZSBfcmVjYWxjIGFuZCBfaGFzVXBkYXRlcyBmbGFncyBhcmUgcHJvcGVybHkgcmVnaXN0ZXJlZC4gVGhhdCdzIHdoeSB3ZSBjbGVhclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIGJvdGggYmVmb3JlIGVudGVyaW5nIHRoZSBjaGlsZHJlbiwgYW5kIHVzZSBfcFJlY2FsYyB0byB0cmFuc2ZlciBpbmhlcml0ZWQgdXBkYXRlcyBpbnN0ZWFkIG9mXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gX3JlY2FsYyBkaXJlY3RseS5cblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIENoYW5nZXMgaW4gZGVzY2VuZGFudHMgYXJlIGF1dG9tYXRpY2FsbHkgZXhlY3V0ZWQgd2l0aGluIHRoZSBjdXJyZW50IHVwZGF0ZSBsb29wLCB0aG91Z2ggd2UgbXVzdFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIHRha2UgY2FyZSB0byBub3QgdXBkYXRlIHRoZSBoYXNVcGRhdGVzIGZsYWcgdW5uZWNlc3NhcmlseSBpbiBhbmNlc3RvcnMuIFdlIGFjaGlldmUgdGhpcyBieSBtYWtpbmdcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBzdXJlIHRoYXQgdGhlIGhhc1VwZGF0ZXMgZmxhZyBvZiB0aGlzIGVsZW1lbnQgaXMgdHVybmVkIG9uLCB3aGljaCBibG9ja3MgaXQgZm9yIGFuY2VzdG9ycy5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9oYXNVcGRhdGVzID0gdHJ1ZTtcblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IHJlY2FsYyA9IHRoaXMuX3JlY2FsYztcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZWNhbGMgPSAwO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZWxlbWVudC5fZW5hYmxlV2l0aGluQm91bmRzTWFyZ2luKCk7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fcmVjYWxjKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIFRoaXMgZWxlbWVudCBuZWVkcyB0byBiZSByZS11cGRhdGVkIG5vdywgYmVjYXVzZSB3ZSB3YW50IHRoZSBkaW1lbnNpb25zIChhbmQgb3RoZXIgY2hhbmdlcykgdG8gYmUgdXBkYXRlZC5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMudXBkYXRlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcmVjYWxjID0gcmVjYWxjO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVsZW1lbnQuX2Rpc2FibGVXaXRoaW5Cb3VuZHNNYXJnaW4oKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgICAgICAgIC8vIFNldCB2aWV3cG9ydCBuZWNlc3NhcnkgZm9yIGNoaWxkcmVuIHNjaXNzb3IgY2FsY3VsYXRpb24uXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3ZpZXdwb3J0KSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3ZpZXdwb3J0WzJdID0gYmJveFc7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3ZpZXdwb3J0WzNdID0gYmJveEg7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fdmlld3BvcnQgPSBbMCwgMCwgYmJveFcsIGJib3hIXTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIEZpbHRlciBvdXQgYml0cyB0aGF0IHNob3VsZCBub3QgYmUgY29waWVkIHRvIHRoZSBjaGlsZHJlbiAoY3VycmVudGx5IGFsbCBhcmUpLlxuICAgICAgICAgICAgdGhpcy5fcFJlY2FsYyA9ICh0aGlzLl9yZWNhbGMgJiAxMzUpO1xuXG4gICAgICAgICAgICAvLyBDbGVhciBmbGFncyBzbyB0aGF0IGZ1dHVyZSB1cGRhdGVzIGFyZSBwcm9wZXJseSBkZXRlY3RlZC5cbiAgICAgICAgICAgIHRoaXMuX3JlY2FsYyA9IDA7XG4gICAgICAgICAgICB0aGlzLl9oYXNVcGRhdGVzID0gZmFsc2U7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9vdXRPZkJvdW5kcyA8IDIpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl93b3JsZENvbnRleHQuaXNJZGVudGl0eSgpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBPcHRpbWl6YXRpb24uXG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBUaGUgd29ybGQgY29udGV4dCBpcyBhbHJlYWR5IGlkZW50aXR5OiB1c2UgdGhlIHdvcmxkIGNvbnRleHQgYXMgcmVuZGVyIGNvbnRleHQgdG8gcHJldmVudHMgdGhlXG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBhbmNlc3RvcnMgZnJvbSBoYXZpbmcgdG8gdXBkYXRlIHRoZSByZW5kZXIgY29udGV4dC5cbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSB0aGlzLl93b3JsZENvbnRleHQ7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBUZW1wb3JhcmlseSByZXBsYWNlIHRoZSByZW5kZXIgY29vcmQgYXR0cmlicyBieSB0aGUgaWRlbnRpdHkgbWF0cml4LlxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gVGhpcyBhbGxvd3MgdGhlIGNoaWxkcmVuIHRvIGNhbGN1bGF0ZSB0aGUgcmVuZGVyIGNvbnRleHQuXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gRWxlbWVudENvcmVDb250ZXh0LklERU5USVRZO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuKSB7XG4gICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS51cGRhdGUoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IHI7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9jaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbltpXS5faGFzVXBkYXRlcykge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLnVwZGF0ZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBNYWtlIHN1cmUgd2UgZG9uJ3QgbG9zZSB0aGUgJ2luaGVyaXRlZCcgdXBkYXRlcy5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS5fcmVjYWxjIHw9IHRoaXMuX3BSZWNhbGM7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0udXBkYXRlT3V0T2ZCb3VuZHMoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX29uQWZ0ZXJVcGRhdGUpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9vbkFmdGVyVXBkYXRlKHRoaXMuZWxlbWVudCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodGhpcy5jdHgudXBkYXRlVHJlZU9yZGVyID09PSAtMSB8fCB0aGlzLl91cGRhdGVUcmVlT3JkZXIgPj0gdGhpcy5jdHgudXBkYXRlVHJlZU9yZGVyKSB7XG4gICAgICAgICAgICAgICAgLy8gSWYgbmV3IHRyZWUgb3JkZXIgZG9lcyBub3QgaW50ZXJmZXJlIHdpdGggdGhlIGN1cnJlbnQgKGdhcHMgYWxsb3dlZCkgdGhlcmUncyBubyBuZWVkIHRvIHRyYXZlcnNlIHRoZSBicmFuY2guXG4gICAgICAgICAgICAgICAgdGhpcy5jdHgudXBkYXRlVHJlZU9yZGVyID0gLTE7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMudXBkYXRlVHJlZU9yZGVyKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfYXBwbHlSZWxhdGl2ZURpbUZ1bmNzKCkge1xuICAgICAgICBpZiAodGhpcy5fb3B0RmxhZ3MgJiAxKSB7XG4gICAgICAgICAgICBjb25zdCB4ID0gdGhpcy5fZnVuY1godGhpcy5fcGFyZW50LncpO1xuICAgICAgICAgICAgaWYgKHggIT09IHRoaXMuX3gpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9sb2NhbFB4ICs9ICh4IC0gdGhpcy5feCk7XG4gICAgICAgICAgICAgICAgdGhpcy5feCA9IHg7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX29wdEZsYWdzICYgMikge1xuICAgICAgICAgICAgY29uc3QgeSA9IHRoaXMuX2Z1bmNZKHRoaXMuX3BhcmVudC5oKTtcbiAgICAgICAgICAgIGlmICh5ICE9PSB0aGlzLl95KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fbG9jYWxQeSArPSAoeSAtIHRoaXMuX3kpO1xuICAgICAgICAgICAgICAgIHRoaXMuX3kgPSB5O1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgbGV0IGNoYW5nZWREaW1zID0gZmFsc2U7XG4gICAgICAgIGlmICh0aGlzLl9vcHRGbGFncyAmIDQpIHtcbiAgICAgICAgICAgIGNvbnN0IHcgPSB0aGlzLl9mdW5jVyh0aGlzLl9wYXJlbnQudyk7XG4gICAgICAgICAgICBpZiAodyAhPT0gdGhpcy5fdykge1xuICAgICAgICAgICAgICAgIHRoaXMuX3cgPSB3O1xuICAgICAgICAgICAgICAgIGNoYW5nZWREaW1zID0gdHJ1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fb3B0RmxhZ3MgJiA4KSB7XG4gICAgICAgICAgICBjb25zdCBoID0gdGhpcy5fZnVuY0godGhpcy5fcGFyZW50LmgpO1xuICAgICAgICAgICAgaWYgKGggIT09IHRoaXMuX2gpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9oID0gaDtcbiAgICAgICAgICAgICAgICBjaGFuZ2VkRGltcyA9IHRydWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoY2hhbmdlZERpbXMpIHtcbiAgICAgICAgICAgIC8vIFJlY2FsYyBtb3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3RpdmVTaGFkZXIsIHRoaXMuX3NoYWRlck93bmVyKTtcbiAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRTY2lzc29yKHRoaXMuX3NjaXNzb3IpO1xuICAgICAgICAgICAgICAgIHRoaXMucmVuZGVyU3RhdGUuYWRkUXVhZCh0aGlzKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gQWxzbyBhZGQgY2hpbGRyZW4gdG8gdGhlIFZCTy5cbiAgICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl96Q29udGV4dFVzYWdlKSB7XG4gICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fekluZGV4ZWRDaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW5baV0ucmVuZGVyKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuW2ldLl96SW5kZXggPT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBJZiB6SW5kZXggaXMgc2V0LCB0aGlzIGl0ZW0gYWxyZWFkeSBiZWxvbmdzIHRvIGEgekluZGV4ZWRDaGlsZHJlbiBhcnJheSBpbiBvbmUgb2YgdGhlIGFuY2VzdG9ycy5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS5yZW5kZXIoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgIC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oaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl93ID09PSAwIHx8IHRoaXMuX2ggPT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gSWdub3JlIHRoaXMgYnJhbmNoIGFuZCBkb24ndCBkcmF3IGFueXRoaW5nLlxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICghdGhpcy5fdGV4dHVyaXplci5oYXNSZW5kZXJUZXh0dXJlKCkgfHwgKGhhc1JlbmRlclVwZGF0ZXMgPj0gMykpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gVGVsbCB0aGUgcmVuZGVyZXIgd2UncmUgcmVuZGVyaW5nIGEgcmVuZGVyVG9UZXh0dXJlIGVsZW1lbnQgaW4gdGhpcyBmcmFtZVxuICAgICAgICAgICAgICAgICAgICB0aGlzLmN0eC5yZW5kZXJUb1RleHR1cmVDb3VudCsrO1xuICAgICAgICAgICAgICAgICAgICAvLyBTd2l0Y2ggdG8gZGVmYXVsdCBzaGFkZXIgZm9yIGJ1aWxkaW5nIHVwIHRoZSByZW5kZXIgdGV4dHVyZS5cbiAgICAgICAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0U2hhZGVyKHJlbmRlclN0YXRlLmRlZmF1bHRTaGFkZXIsIHRoaXMpO1xuXG4gICAgICAgICAgICAgICAgICAgIHByZXZSZW5kZXJUZXh0dXJlSW5mbyA9IHJlbmRlclN0YXRlLnJlbmRlclRleHR1cmVJbmZvO1xuXG4gICAgICAgICAgICAgICAgICAgIHJlbmRlclRleHR1cmVJbmZvID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgbmF0aXZlVGV4dHVyZTogbnVsbCxcbiAgICAgICAgICAgICAgICAgICAgICAgIG9mZnNldDogMCwgIC8vIFNldCBieSBDb3JlUmVuZGVyU3RhdGUuXG4gICAgICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLl93LFxuICAgICAgICAgICAgICAgICAgICAgICAgaDogdGhpcy5faCxcbiAgICAgICAgICAgICAgICAgICAgICAgIGVtcHR5OiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICAgICAgY2xlYXJlZDogZmFsc2UsXG4gICAgICAgICAgICAgICAgICAgICAgICBpZ25vcmU6IGZhbHNlLFxuICAgICAgICAgICAgICAgICAgICAgICAgY2FjaGU6IGZhbHNlXG4gICAgICAgICAgICAgICAgICAgIH07XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX3RleHR1cml6ZXIuaGFzUmVzdWx0VGV4dHVyZSgpIHx8ICghcmVuZGVyU3RhdGUuaXNDYWNoaW5nVGV4dHVyaXplciAmJiAoaGFzUmVuZGVyVXBkYXRlcyA8IDMpKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLyoqXG4gICAgICAgICAgICAgICAgICAgICAgICAgKiBXZSBkb24ndCBhbHdheXMgY2FjaGUgcmVuZGVyIHRleHR1cmVzLlxuICAgICAgICAgICAgICAgICAgICAgICAgICpcbiAgICAgICAgICAgICAgICAgICAgICAgICAqIFRoZSBydWxlIGlzLCB0aGF0IGNhY2hpbmcgZm9yIGEgc3BlY2lmaWMgcmVuZGVyIHRleHR1cmUgaXMgb25seSBlbmFibGVkIGlmOlxuICAgICAgICAgICAgICAgICAgICAgICAgICogLSBUaGVyZSBpcyBhIHJlc3VsdCB0ZXh0dXJlIHRvIGJlIHVwZGF0ZWQuXG4gICAgICAgICAgICAgICAgICAgICAgICAgKiAtIFRoZXJlIHdlcmUgbm8gcmVuZGVyIHVwZGF0ZXMgLXdpdGhpbiB0aGUgY29udGVudHMtIHNpbmNlIGxhc3QgZnJhbWUgKEVsZW1lbnRDb3JlLmhhc1JlbmRlclVwZGF0ZXMgPCAzKVxuICAgICAgICAgICAgICAgICAgICAgICAgICogLSBBTkQgdGhlcmUgYXJlIG5vIGFuY2VzdG9ycyB0aGF0IGFyZSBiZWluZyBjYWNoZWQgZHVyaW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vLmNhY2hlID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlbmRlclN0YXRlLmlzQ2FjaGluZ1RleHR1cml6ZXIgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKCF0aGlzLl90ZXh0dXJpemVyLmhhc1Jlc3VsdFRleHR1cmUoKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gV2UgY2FuIGFscmVhZHkgcmVsZWFzZSB0aGUgY3VycmVudCB0ZXh0dXJlIHRvIHRoZSBwb29sLCBhcyBpdCB3aWxsIGJlIHJlYnVpbGQgYW55d2F5LlxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gSW4gY2FzZSBvZiBtdWx0aXBsZSBsYXllcnMgb2YgJ2ZpbHRlcmluZycsIHRoaXMgbWF5IHNhdmUgdXMgZnJvbSBoYXZpbmcgdG8gY3JlYXRlIG9uZVxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gIHJlbmRlci10by10ZXh0dXJlIGxheWVyLlxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gTm90aWNlIHRoYXQgd2UgZG9uJ3QgZG8gdGhpcyB3aGVuIHRoZXJlIGlzIGEgcmVzdWx0IHRleHR1cmUsIGFzIGFueSBvdGhlciBlbGVtZW50IG1heSByZWx5IG9uXG4gICAgICAgICAgICAgICAgICAgICAgICAvLyAgdGhhdCByZXN1bHQgdGV4dHVyZSBiZWluZyBmaWxsZWQuXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLnJlbGVhc2VSZW5kZXJUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRSZW5kZXJUZXh0dXJlSW5mbyhyZW5kZXJUZXh0dXJlSW5mbyk7XG4gICAgICAgICAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFNjaXNzb3IobnVsbCk7XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX2Rpc3BsYXllZFRleHR1cmVTb3VyY2UpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxldCByID0gdGhpcy5fcmVuZGVyQ29udGV4dDtcblxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gVXNlIGFuIGlkZW50aXR5IGNvbnRleHQgZm9yIGRyYXdpbmcgdGhlIGRpc3BsYXllZCB0ZXh0dXJlIHRvIHRoZSByZW5kZXIgdGV4dHVyZS5cbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSBFbGVtZW50Q29yZUNvbnRleHQuSURFTlRJVFk7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEFkZCBkaXNwbGF5ZWQgdGV4dHVyZSBzb3VyY2UgaW4gbG9jYWwgY29vcmRpbmF0ZXMuXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnJlbmRlclN0YXRlLmFkZFF1YWQodGhpcyk7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSByO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgbXVzdFJlbmRlckNoaWxkcmVuID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZiAoKHRoaXMuX291dE9mQm91bmRzID09PSAwKSAmJiB0aGlzLl9kaXNwbGF5ZWRUZXh0dXJlU291cmNlKSB7XG4gICAgICAgICAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFNoYWRlcih0aGlzLmFjdGl2ZVNoYWRlciwgdGhpcy5fc2hhZGVyT3duZXIpO1xuICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRTY2lzc29yKHRoaXMuX3NjaXNzb3IpO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnJlbmRlclN0YXRlLmFkZFF1YWQodGhpcyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBBbHNvIGFkZCBjaGlsZHJlbiB0byB0aGUgVkJPLlxuICAgICAgICAgICAgaWYgKG11c3RSZW5kZXJDaGlsZHJlbiAmJiB0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl96Q29udGV4dFVzYWdlKSB7XG4gICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fekluZGV4ZWRDaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW5baV0ucmVuZGVyKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuW2ldLl96SW5kZXggPT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBJZiB6SW5kZXggaXMgc2V0LCB0aGlzIGl0ZW0gYWxyZWFkeSBiZWxvbmdzIHRvIGEgekluZGV4ZWRDaGlsZHJlbiBhcnJheSBpbiBvbmUgb2YgdGhlIGFuY2VzdG9ycy5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS5yZW5kZXIoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgICAgICAgIGxldCB1cGRhdGVSZXN1bHRUZXh0dXJlID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgaWYgKG11c3RSZW5kZXJDaGlsZHJlbikge1xuICAgICAgICAgICAgICAgICAgICAvLyBGaW5pc2hlZCByZWZyZXNoaW5nIHJlbmRlclRleHR1cmUuXG4gICAgICAgICAgICAgICAgICAgIHJlbmRlclN0YXRlLmZpbmlzaGVkUmVuZGVyVGV4dHVyZSgpO1xuXG4gICAgICAgICAgICAgICAgICAgIC8vIElmIG5vdGhpbmcgd2FzIHJlbmRlcmVkLCB3ZSBzdG9yZSBhIGZsYWcgaW4gdGhlIHRleHR1cml6ZXIgYW5kIHByZXZlbnQgdW5uZWNlc3NhcnlcbiAgICAgICAgICAgICAgICAgICAgLy8gIHJlbmRlci10by10ZXh0dXJlIGFuZCBmaWx0ZXJpbmcuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3RleHR1cml6ZXIuZW1wdHkgPSByZW5kZXJUZXh0dXJlSW5mby5lbXB0eTtcblxuICAgICAgICAgICAgICAgICAgICBpZiAocmVuZGVyVGV4dHVyZUluZm8uZW1wdHkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFdlIGlnbm9yZSBlbXB0eSByZW5kZXIgdGV4dHVyZXMgYW5kIGRvIG5vdCBkcmF3IHRoZSBmaW5hbCBxdWFkLlxuXG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBUaGUgZm9sbG93aW5nIGNsZWFucyB1cCBtZW1vcnkgYW5kIGVuZm9yY2VzIHRoYXQgdGhlIHJlc3VsdCB0ZXh0dXJlIGlzIGFsc28gY2xlYXJlZC5cbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3RleHR1cml6ZXIucmVsZWFzZVJlbmRlclRleHR1cmUoKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChyZW5kZXJUZXh0dXJlSW5mby5uYXRpdmVUZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBJZiBuYXRpdmVUZXh0dXJlIGlzIHNldCwgd2UgY2FuIHJldXNlIHRoYXQgZGlyZWN0bHkgaW5zdGVhZCBvZiBjcmVhdGluZyBhIG5ldyByZW5kZXIgdGV4dHVyZS5cbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3RleHR1cml6ZXIucmV1c2VUZXh0dXJlQXNSZW5kZXJUZXh0dXJlKHJlbmRlclRleHR1cmVJbmZvLm5hdGl2ZVRleHR1cmUpO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICByZW5kZXJUZXh0dXJlSW5mby5pZ25vcmUgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX3RleHR1cml6ZXIucmVuZGVyVGV4dHVyZVJldXNlZCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIFF1YWQgb3BlcmF0aW9ucyBtdXN0IGJlIHdyaXR0ZW4gdG8gYSByZW5kZXIgdGV4dHVyZSBhY3R1YWxseSBvd25lZC5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLnJlbGVhc2VSZW5kZXJUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBKdXN0IGNyZWF0ZSB0aGUgcmVuZGVyIHRleHR1cmUuXG4gICAgICAgICAgICAgICAgICAgICAgICByZW5kZXJUZXh0dXJlSW5mby5uYXRpdmVUZXh0dXJlID0gdGhpcy5fdGV4dHVyaXplci5nZXRSZW5kZXJUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICAvLyBSZXN0b3JlIHRoZSBwYXJlbnQncyByZW5kZXIgdGV4dHVyZS5cbiAgICAgICAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0UmVuZGVyVGV4dHVyZUluZm8ocHJldlJlbmRlclRleHR1cmVJbmZvKTtcblxuICAgICAgICAgICAgICAgICAgICB1cGRhdGVSZXN1bHRUZXh0dXJlID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuX3RleHR1cml6ZXIuZW1wdHkpIHtcbiAgICAgICAgICAgICAgICAgICAgbGV0IHJlc3VsdFRleHR1cmUgPSB0aGlzLl90ZXh0dXJpemVyLmdldFJlc3VsdFRleHR1cmUoKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHVwZGF0ZVJlc3VsdFRleHR1cmUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZXN1bHRUZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gTG9nZ2luZyB0aGUgdXBkYXRlIGZyYW1lIGNhbiBiZSBoYW5keSBmb3IgdXNlcmxhbmQuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0VGV4dHVyZS51cGRhdGUgPSByZW5kZXJTdGF0ZS5zdGFnZS5mcmFtZUNvdW50ZXI7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLnVwZGF0ZVJlc3VsdFRleHR1cmUoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIGlmICghdGhpcy5fdGV4dHVyaXplci5yZW5kZXJPZmZzY3JlZW4pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFJlbmRlciByZXN1bHQgdGV4dHVyZSB0byB0aGUgYWN0dWFsIHJlbmRlciB0YXJnZXQuXG4gICAgICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRTaGFkZXIodGhpcy5hY3RpdmVTaGFkZXIsIHRoaXMuX3NoYWRlck93bmVyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFNjaXNzb3IodGhpcy5fc2Npc3Nvcik7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIElmIG5vIHJlbmRlciB0ZXh0dXJlIGluZm8gaXMgc2V0LCB0aGUgY2FjaGUgY2FuIGJlIHJldXNlZC5cbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGNhY2hlID0gIXJlbmRlclRleHR1cmVJbmZvIHx8IHJlbmRlclRleHR1cmVJbmZvLmNhY2hlO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRUZXh0dXJpemVyKHRoaXMuX3RleHR1cml6ZXIsIGNhY2hlKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3N0YXNoVGV4Q29vcmRzKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXRoaXMuX3RleHR1cml6ZXIuY29sb3JpemUpIHRoaXMuX3N0YXNoQ29sb3JzKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnJlbmRlclN0YXRlLmFkZFF1YWQodGhpcywgdHJ1ZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXRoaXMuX3RleHR1cml6ZXIuY29sb3JpemUpIHRoaXMuX3Vuc3Rhc2hDb2xvcnMoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3Vuc3Rhc2hUZXhDb29yZHMoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFRleHR1cml6ZXIobnVsbCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChyZW5kZXJUZXh0dXJlSW5mbyAmJiByZW5kZXJUZXh0dXJlSW5mby5jYWNoZSkge1xuICAgICAgICAgICAgICAgIC8vIEFsbG93IHNpYmxpbmdzIHRvIGNhY2hlLlxuIC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xlbmd0aDtcbiAgICAgICAgbGV0IHB0ciA9IDA7XG4gICAgICAgIGNvbnN0IGEgPSB0aGlzLl96SW5kZXhlZENoaWxkcmVuO1xuXG4gICAgICAgIC8vIE5vdGljZSB0aGF0IGl0ZW1zIG1heSBvY2N1ciBtdWx0aXBsZSB0aW1lcyBkdWUgdG8gei1pbmRleCBjaGFuZ2luZy5cbiAgICAgICAgY29uc3QgYiA9IFtdO1xuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgaWYgKGFbaV0uX3pQYXJlbnQgPT09IHRoaXMpIHtcbiAgICAgICAgICAgICAgICBpZiAoYVtpXS5fekluZGV4UmVzb3J0KSB7XG4gICAgICAgICAgICAgICAgICAgIGIucHVzaChhW2ldKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBpZiAocHRyICE9PSBpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBhW3B0cl0gPSBhW2ldO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHB0cisrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGNvbnN0IG0gPSBiLmxlbmd0aDtcbiAgICAgICAgaWYgKG0pIHtcbiAgICAgICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgbTsgaisrKSB7XG4gICAgICAgICAgICAgICAgYltqXS5fekluZGV4UmVzb3J0ID0gZmFsc2U7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGIuc29ydChFbGVtZW50Q29yZS5zb3J0WkluZGV4ZWRDaGlsZHJlbik7XG4gICAgICAgICAgICBjb25zdCBuID0gcHRyO1xuICAgICAgICAgICAgaWYgKCFuKSB7XG4gICAgICAgICAgICAgICAgcHRyID0gMDtcbiAgICAgICAgICAgICAgICBsZXQgaiA9IDA7XG4gICAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgICAgICBhW3B0cisrXSA9IGJbaisrXTtcbiAgICAgICAgICAgICAgICB9IHdoaWxlIChqIDwgbSk7XG5cbiAgICAgICAgICAgICAgICBpZiAoYS5sZW5ndGggPiBwdHIpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gU2xpY2Ugb2xkICh1bm5lY2Vzc2FyeSkgcGFydCBvZmYgYXJyYXkuXG4gICAgICAgICAgICAgICAgICAgIGEuc3BsaWNlKHB0cik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBhLnNwbGljZShuKTsgLy8gUmVtb3ZlIGl0ZW1zIHRoYXQgd2VyZSBzb3J0ZWQgaW4gYiBhcnJheSwgc28gdGhhdCB3ZSBjYW4gc29ydCBhXG4rICAgICAgICAgICAgICAgLy8gQmV3YXJlIHRoYXQgdGhlIGZ1bmN0aW9uIHBhc3NlZCBoZXJlIHRvIEFycmF5LnNvcnQgbXVzdCBiZSBzdGFibGVcbisgICAgICAgICAgICAgICBhLnNvcnQoRWxlbWVudENvcmUuc29ydFpJbmRleGVkQ2hpbGRyZW4pOyAvLyBOZWVkZWQgYmVjYXVzZSBpdGVtcyB3aXRoIHNhbWUgX3pJbmRleCBtYXkgbm90IGJlIG9yZGVyZWQgYnkgX3VwZGF0ZVRyZWVPcmRlclxuICAgICAgICAgICAgICAgIC8vIE1lcmdlLXNvcnQgYXJyYXlzO1xuICAgICAgICAgICAgICAgIHB0ciA9IDA7XG4gICAgICAgICAgICAgICAgbGV0IGkgPSAwO1xuICAgICAgICAgICAgICAgIGxldCBqID0gMDtcbiAgICAgICAgICAgICAgICBjb25zdCBtZXJnZVJlc3VsdCA9IFtdO1xuICAgICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgdiA9IChhW2ldLl96SW5kZXggPT09IGJbal0uX3pJbmRleCA/IGFbaV0uX3VwZGF0ZVRyZWVPcmRlciAtIGJbal0uX3VwZGF0ZVRyZWVPcmRlciA6IGFbaV0uX3pJbmRleCAtIGJbal0uX3pJbmRleCk7XG5cbiAgICAgICAgICAgICAgICAgICAgY29uc3QgYWRkID0gdiA+IDAgPyBiW2orK10gOiBhW2krK107XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHB0ciA9PT0gMCB8fCAobWVyZ2VSZXN1bHRbcHRyIC0gMV0gIT09IGFkZCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIG1lcmdlUmVzdWx0W3B0cisrXSA9IGFkZDtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIGlmIChpID49IG4pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBhZGQgPSBiW2orK107XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHB0ciA9PT0gMCB8fCAobWVyZ2VSZXN1bHRbcHRyIC0gMV0gIT09IGFkZCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbWVyZ2VSZXN1bHRbcHRyKytdID0gYWRkO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGogPCBtKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGogPj0gbSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGFkZCA9IGFbaSsrXTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocHRyID09PSAwIHx8IChtZXJnZVJlc3VsdFtwdHIgLSAxXSAhPT0gYWRkKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtZXJnZVJlc3VsdFtwdHIrK10gPSBhZGQ7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoaSA8IG4pO1xuICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IHdoaWxlICh0cnVlKTtcblxuICAgICAgICAgICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4gPSBtZXJnZVJlc3VsdDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChhLmxlbmd0aCA+IHB0cikge1xuICAgICAgICAgICAgICAgIC8vIFNsaWNlIG9sZCAodW5uZWNlc3NhcnkpIHBhcnQgb2ZmIGFycmF5LlxuICAgICAgICAgICAgICAgIGEuc3BsaWNlKHB0cik7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICB0aGlzLl96U29ydCA9IGZhbHNlO1xuICAgIH07XG5cbiAgICBnZXQgbG9jYWxUYSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2xvY2FsVGE7XG4gICAgfTtcblxuICAgIGdldCBsb2NhbFRiKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbG9jYWxUYjtcbiAgICB9O1xuXG4gICAgZ2V0IGxvY2FsVGMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9sb2NhbFRjO1xuICAgIH07XG5cbiAgICBnZXQgbG9jYWxUZCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2xvY2FsVGQ7XG4gICAgfTtcblxuICAgIGdldCBlbGVtZW50KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fZWxlbWVudDtcbiAgICB9XG5cbiAgICBnZXQgcmVuZGVyVXBkYXRlcygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2hhc1JlbmRlclVwZGF0ZXM7XG4gICAgfVxuXG4gICAgZ2V0IHRleHR1cml6ZXIoKSB7XG4gICAgICAgIGlmICghdGhpcy5fdGV4dHVyaXplcikge1xuICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplciA9IG5ldyBFbGVtZW50VGV4dHVyaXplcih0aGlzKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdGhpcy5fdGV4dHVyaXplcjtcbiAgICB9XG5cbiAgICBnZXRDb3JuZXJQb2ludHMoKSB7XG4gICAgICAgIGxldCB3ID0gdGhpcy5fd29ybGRDb250ZXh0O1xuXG4gICAgICAgIHJldHVybiBbXG4gICAgICAgICAgICB3LnB4LFxuICAgICAgICAgICAgdy5weSxcbiAgICAgICAgICAgIHcucHggKyB0aGlzLl93ICogdy50YSxcbiAgICAgICAgICAgIHcucHkgKyB0aGlzLl93ICogdy50YyxcbiAgICAgICAgICAgIHcucHggKyB0aGlzLl93ICogdy50YSArIHRoaXMuX2ggKiB3LnRiLFxuICAgICAgICAgICAgdy5weSArIHRoaXMuX3cgKiB3LnRjICsgdGhpcy5faCAqIHcudGQsXG4gICAgICAgICAgICB3LnB4ICsgdGhpcy5faCAqIHcudGIsXG4gICAgICAgICAgICB3LnB5ICsgdGhpcy5faCAqIHcudGRcbiAgICAgICAgXTtcbiAgICB9O1xuXG4gICAgZ2V0UmVuZGVyVGV4dHVyZUNvb3JkcyhyZWxYLCByZWxZKSB7XG4gICAgICAgIGxldCByID0gdGhpcy5fcmVuZGVyQ29udGV4dDtcbiAgICAgICAgcmV0dXJuIFtcbiAgICAgICAgICAgIHIucHggKyByLnRhICogcmVsWCArIHIudGIgKiByZWxZLFxuICAgICAgICAgICAgci5weSArIHIudGMgKiByZWxYICsgci50ZCAqIHJlbFlcbiAgICAgICAgXTtcbiAgICB9XG5cbiAgICBnZXRBYnNvbHV0ZUNvb3JkcyhyZWxYLCByZWxZKSB7XG4gICAgICAgIGxldCB3ID0gdGhpcy5fcmVuZGVyQ29udGV4dDtcbiAgICAgICAgcmV0dXJuIFtcbiAgICAgICAgICAgIHcucHggKyB3LnRhICogcmVsWCArIHcudGIgKiByZWxZLFxuICAgICAgICAgICAgdy5weSArIHcudGMgKiByZWxYICsgdy50ZCAqIHJlbFlcbiAgICAgICAgXTtcbiAgICB9XG5cbiAgICBjb2xsZWN0QXRDb29yZCh4LCB5LCBjaGlsZHJlbikge1xuICAgICAgICAvLyByZXR1cm4gd2hlbiBicmFuY2ggaXMgaGlkZGVuXG4gICAgICAgIGlmICh0aGlzLl9yZW5kZXJDb250ZXh0LmFscGhhID09PSAwKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5pbkJvdW5kKHgsIHkpKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fc2Npc3Nvcikge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLmluU2Npc3NvcigpKSB7XG4gICAgICAgICAgICAgICAgICAgIGNoaWxkcmVuLnB1c2godGhpcyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjaGlsZHJlbi5wdXNoKHRoaXMpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuKSB7XG4gICAgICAgICAgICBjb25zdCBqID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoO1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBqOyBpKyspIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS5jb2xsZWN0QXRDb29yZCh4LCB5LCBjaGlsZHJlbik7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gY2hpbGRyZW4uc29ydChFbGVtZW50Q29yZS5zb3J0WkluZGV4ZWRDaGlsZHJlbik7XG4gICAgfVxuXG4gICAgaW5Cb3VuZCh0eCwgdHkpIHtcbiAgICAgICAgY29uc3QgYyA9IHRoaXMuZ2V0Q29ybmVyUG9pbnRzKCk7XG4gICAgICAgIHJldHVybiB0eC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cGVvZiBwaHJhc2UgPT09ICdzdHJpbmcnICYmIHBocmFzZS5sZW5ndGgpIHtcbiAgICAgICAgICAvLyBTcGVhayBpdFxuICAgICAgICAgIGNvbnN0IHRvdGFsUmV0cmllcyA9IDNcbiAgICAgICAgICBsZXQgcmV0cmllc0xlZnQgPSB0b3RhbFJldHJpZXNcbiAgICAgICAgICB3aGlsZSAoYWN0aXZlICYmIHJldHJpZXNMZWZ0ID4gMCkge1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgYXdhaXQgc3BlYWsocGhyYXNlLCB1dHRlcmFuY2VzLCBsYW5nKVxuICAgICAgICAgICAgICByZXRyaWVzTGVmdCA9IDBcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgICAgLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIG5vLXVuZGVmXG4gICAgICAgICAgICAgIGlmIChlIGluc3RhbmNlb2YgU3BlZWNoU3ludGhlc2lzRXJyb3JFdmVudCkge1xuICAgICAgICAgICAgICAgIGlmIChlLmVycm9yID09PSAnbmV0d29yaycpIHtcbiAgICAgICAgICAgICAgICAgIHJldHJpZXNMZWZ0LS1cbiAgICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybihgU3BlZWNoIHN5bnRoZXNpcyBuZXR3b3JrIGVycm9yLiBSZXRyaWVzIGxlZnQ6ICR7cmV0cmllc0xlZnR9YClcbiAgICAgICAgICAgICAgICAgIGF3YWl0IGRlbGF5KDUwMCAqICh0b3RhbFJldHJpZXMgLSByZXRyaWVzTGVmdCkpXG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChlLmVycm9yID09PSAnY2FuY2VsZWQnIHx8IGUuZXJyb3IgPT09ICdpbnRlcnJ1cHRlZCcpIHtcbiAgICAgICAgICAgICAgICAgIC8vIENhbmNlbCBvciBpbnRlcnJ1cHQgZXJyb3IgKGlnbm9yZSlcbiAgICAgICAgICAgICAgICAgIHJldHJpZXNMZWZ0ID0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cmVzdCBvZiB0aGUgYmVhY29ucyBmb3IgdGhpcyBldmVudClcbiAgICAgICAgICAvLyBub3RlOiBmb3IgZmV0Y2ggZmFpbGVkIGh0dHAgcmVzcG9uc2VzIGRvbid0IHRocm93IGFuIEVycm9yIDopXG4gICAgICAgICAgLnRoZW4ocmVzcG9uc2UgPT4ge1xuICAgICAgICAgICAgaWYgKHJlc3BvbnNlLnN0YXR1cyA9PT0gMjAwKSB7XG4gICAgICAgICAgICAgIGZpcmVPbkNvbnN1bWVyKCdCZWFjb24nICsgZXZlbnQgKyAnU2VudCcpXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBmaXJlT25Db25zdW1lcignQmVhY29uJyArIGV2ZW50ICsgJ0ZhaWxlZCcgKyByZXNwb25zZS5zdGF0dXMpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBQcm9taXNlLnJlc29sdmUobnVsbClcbiAgICAgICAgICB9KVxuICAgICAgICAgIC5jYXRjaCgoKSA9PiB7XG4gICAgICAgICAgICBQcm9taXNlLnJlc29sdmUobnVsbClcbiAgICAgICAgICB9KVxuICAgICAgKVxuICAgIH0sIFByb21pc2UucmVzb2x2ZShudWxsKSlcbiAgfSBlbHNlIHtcbiAgICBMb2cuaW5mbygnQWQnLCAnTm8gY2FsbGJhY2sgZm91bmQgZm9yICcgKyBldmVudClcbiAgfVxufVxuXG5jb25zdCBmaXJlT25Db25zdW1lciA9IChldmVudCwgYXJncykgPT4ge1xuICBpZiAoY29uc3VtZXIpIHtcbiAgICBjb25zdW1lci5maXJlKCckYWQnICsgZXZlbnQsIGFyZ3MpXG4gICAgY29uc3VtZXIuZmlyZSgnJGFkRXZlbnQnLCBldmVudCwgYXJncylcbiAgfVxufVxuXG5leHBvcnQgZGVmYXVsdCB7XG4gIGdldChjb25maWcsIHZpZGVvUGxheWVyQ29uc3VtZXIpIHtcbiAgICBpZiAoY29uZmlnLmVuYWJsZWQgPT09IGZhbHNlKSB7XG4gICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKHtcbiAgICAgICAgcHJlcm9sbHMoKSB7XG4gICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSgpXG4gICAgICAgIH0sXG4gICAgICB9KVxuICAgIH1cbiAgICBjb25zdW1lciA9IHZpZGVvUGxheWVyQ29uc3VtZXJcblxuICAgIHJldHVybiBuZXcgUHJvbWlzZShyZXNvbHZlID0+IHtcbiAgICAgIExvZy5pbmZvKCdBZCcsICdTdGFydGluZyBzZXNzaW9uJylcbiAgICAgIGdldEFkcyhjb25maWcpLnRoZW4oYWRzID0+IHtcbiAgICAgICAgTG9nLmluZm8oJ0FkJywgJ0FQSSByZXN1bHQnLCBhZHMpXG4gICAgICAgIHJlc29sdmUoe1xuICAgICAgICAgIHByZXJvbGxzKCkge1xuICAgICAgICAgICAgaWYgKGFkcy5wcmVyb2xsKSB7XG4gICAgICAgICAgICAgIHN0YXRlLmFjdGl2ZSA9IHRydWVcbiAgICAgICAgICAgICAgZmlyZU9uQ29uc3VtZXIoJ1ByZXJvbGxTbG90SW1wcmVzc2lvbicsIGFkcylcbiAgICAgICAgICAgICAgc2VuZEJlYWNvbihhZHMucHJlcm9sbC5jYWxsYmFja3MsICdzbG90SW1wcmVzc2lvbicpXG4gICAgICAgICAgICAgIHJldHVybiBwbGF5U2xvdChhZHMucHJlcm9sbC5hZHMpLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgICAgIGZpcmVPbkNvbnN1bWVyKCdQcmVyb2xsU2xvdEVuZCcsIGFkcylcbiAgICAgICAgICAgICAgICBzZW5kQmVhY29uKGFkcy5wcmVyb2xsLmNhbGxiYWNrcywgJ3Nsb3RFbmQnKVxuICAgICAgICAgICAgICAgIHN0YXRlLmFjdGl2ZSA9IGZhbHNlXG4gICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKClcbiAgICAgICAgICB9LFxuICAgICAgICA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YShBcHBJbnN0YW5jZSlcblxuICAgICAgICAgIHRoaXMuX3JlZm9jdXMoKVxuXG4gICAgICAgICAgTG9nLmluZm8oJ0FwcCB2ZXJzaW9uJywgdGhpcy5jb25maWcudmVyc2lvbilcbiAgICAgICAgICBMb2cuaW5mbygnU0RLIHZlcnNpb24nLCBwYWNrYWdlSW5mby52ZXJzaW9uKVxuXG4gICAgICAgICAgaWYgKHBsYXRmb3JtU2V0dGluZ3Muc2hvd1ZlcnNpb24pIHtcbiAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmEoe1xuICAgICAgICAgICAgICByZWY6ICdWZXJzaW9uTGFiZWwnLFxuICAgICAgICAgICAgICB0eXBlOiBWZXJzaW9uTGFiZWwsXG4gICAgICAgICAgICAgIHZlcnNpb246IHRoaXMuY29uZmlnLnZlcnNpb24sXG4gICAgICAgICAgICAgIHNka1ZlcnNpb246IHBhY2thZ2VJbmZvLnZlcnNpb24sXG4gICAgICAgICAgICAgIHpJbmRleDogMSxcbiAgICAgICAgICAgIH0pXG4gICAgICAgICAgfVxuXG4gICAgICAgICAgaWYgKHBsYXRmb3JtU2V0dGluZ3Muc2hvd0Zwcykge1xuICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QuYSh7XG4gICAgICAgICAgICAgIHJlZjogJ0Zwc0NvdW50ZXInLFxuICAgICAgICAgICAgICB0eXBlOiBGcHNDb3VudGVyLFxuICAgICAgICAgICAgICB6SW5kZXg6IDEsXG4gICAgICAgICAgICB9KVxuICAgICAgICAgIH1cblxuICAgICAgICAgIHN1cGVyLl9zZXR1cCgpXG4gICAgICAgIH0pXG4gICAgICAgIC5jYXRjaChjb25zb2xlLmVycm9yKVxuICAgIH1cblxuICAgIF9oYW5kbGVCYWNrKCkge1xuICAgICAgdGhpcy5jbG9zZUFwcCgpXG4gICAgfVxuXG4gICAgX2hhbmRsZUV4aXQoKSB7XG4gICAgICB0aGlzLmNsb3NlQXBwKClcbiAgICB9XG5cbiAgICBjbG9zZUFwc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cbiAgICAgICAgaWYgKFNldHRpbmdzLmdldCgnYXBwJywgJ2hscycpKSB7XG4gICAgICAgICAgaWYgKCF3aW5kb3cuSGxzKSB7XG4gICAgICAgICAgICB3aW5kb3cuSGxzID0gY2xhc3MgSGxzIHtcbiAgICAgICAgICAgICAgc3RhdGljIGlzU3VwcG9ydGVkKCkge1xuICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybignaGxzLWxpZ2h0IG5vdCBpbmNsdWRlZCcpXG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlXG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHdpbmRvdy5IbHMuaXNTdXBwb3J0ZWQoKSkge1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9obHMpIHRoaXMuX2hscyA9IG5ldyB3aW5kb3cuSGxzKHsgbGl2ZUR1cmF0aW9uSW5maW5pdHk6IHRydWUgfSlcbiAgICAgICAgICAgIHRoaXMuX2hscy5sb2FkU291cmNlKHNldHRpbmdzLnN0cmVhbS5zcmMpXG4gICAgICAgICAgICB0aGlzLl9obHMuYXR0YWNoTWVkaWEodGhpcy52aWRlb0VsKVxuICAgICAgICAgICAgdGhpcy52aWRlb0VsLnN0eWxlLmRpc3BsYXkgPSAnYmxvY2snXG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMub3BlbihzZXR0aW5ncy5zdHJlYW0uc3JjKVxuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICB0aGlzLmNsb3NlKClcbiAgICAgIH1cbiAgICAgIHRoaXMuX3N0cmVhbSA9IHNldHRpbmdzLnN0cmVhbVxuICAgIH1cblxuICAgIHRoaXMuX3NldEhpZGUoc2V0dGluZ3MuaGlkZSlcbiAgICB0aGlzLl9zZXRWaWRlb0FyZWEoc2V0dGluZ3MudmlkZW9Qb3MpXG4gIH1cblxuICBfc2V0SGlkZShoaWRlKSB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ci5qcydcbmltcG9ydCB7IGlzQm9vbGVhbiB9IGZyb20gJy4vdXRpbHMvaGVscGVycydcblxuZXhwb3J0IGNsYXNzIFJvdXRlZEFwcCBleHRlbmRzIExpZ2h0bmluZy5Db21wb25lbnQge1xuICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgIHJldHVybiB7XG4gICAgICBQYWdlczoge1xuICAgICAgICBmb3JjZVpJbmRleENvbnRleHQ6IHRydWUsXG4gICAgICB9LFxuICAgICAgLyoqXG4gICAgICAgKiBUaGlzIGlzIGEgZGVmYXVsdCBMb2FkaW5nIHBhZ2UgdGhhdCB3aWxsIGJlIG1hZGUgdmlzaWJsZVxuICAgICAgICogZHVyaW5nIGRhdGEtcHJvdmlkZXIgb24oKSB5b3UgQ0FOIG92ZXJyaWRlIGluIGNoaWxkLWNsYXNzXG4gICAgICAgKi9cbiAgICAgIExvYWRpbmc6IHtcbiAgICAgICAgcmVjdDogdHJ1ZSxcbiAgICAgICAgdzogMTkyMCxcbiAgICAgICAgaDogMTA4MCxcbiAgICAgICAgY29sb3I6IDB4ZmYwMDAwMDAsXG4gICAgICAgIHZpc2libGU6IGZhbHNlLFxuICAgICAgICB6SW5kZXg6IDk5LFxuICAgICAgICBMYWJlbDoge1xuICAgICAgICAgIG1vdW50OiAwLjUsXG4gICAgICAgICAgeDogOTYwLFxuICAgICAgICAgIHk6IDU0MCxcbiAgICAgICAgICB0ZXh0OiB7XG4gICAgICAgICAgICB0ZXh0OiAnTG9hZGluZy4uJyxcbiAgICAgICAgICB9LFxuICAgICAgICB9LFxuICAgICAgfSxcbiAgICB9XG4gIH1cblxuICBzdGF0aWMgX3N0YXRlcygpIHtcbiAgICByZXR1cm4gW1xuICAgICAgY2xhc3MgTG9hZGluZyBleHRlbmRzIHRoaXMge1xuICAgICAgICAkZW50ZXIoKSB7XG4gICAgICAgICAgdGhpcy50YWcoJ0xvYWRpbmcnKS52aXNpYmxlID0gdHJ1ZVxuICAgICAgICB9XG5cbiAgICAg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AgICB0cnkge1xuICAgICAgICB2YXIgaSA9IG5bYV0oYyksIHUgPSBpLnZhbHVlO1xuICAgIH0gY2F0Y2ggKG4pIHtcbiAgICAgICAgcmV0dXJuIHZvaWQgZShuKTtcbiAgICB9XG4gICAgaS5kb25lID8gdCh1KSA6IFByb21pc2UucmVzb2x2ZSh1KS50aGVuKHIsIG8pO1xufVxuXG5mdW5jdGlvbiBfYXN5bmNUb0dlbmVyYXRvcihuKSB7XG4gICAgcmV0dXJuIGZ1bmN0aW9uKCkge1xuICAgICAgICB2YXIgdCA9IHRoaXMsIGUgPSBhcmd1bWVudHM7XG4gICAgICAgIHJldHVybiBuZXcgUHJvbWlzZSgoZnVuY3Rpb24ociwgbykge1xuICAgICAgICAgICAgdmFyIGEgPSBuLmFwcGx5KHQsIGUpO1xuICAgICAgICAgICAgZnVuY3Rpb24gX25leHQobikge1xuICAgICAgICAgICAgICAgIGFzeW5jR2VuZXJhdG9yU3RlcChhLCByLCBvLCBfbmV4dCwgX3Rocm93LCBcIm5leHRcIiwgbik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBmdW5jdGlvbiBfdGhyb3cobikge1xuICAgICAgICAgICAgICAgIGFzeW5jR2VuZXJhdG9yU3RlcChhLCByLCBvLCBfbmV4dCwgX3Rocm93LCBcInRocm93XCIsIG4pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgX25leHQodm9pZCAwKTtcbiAgICAgICAgfSkpO1xuICAgIH07XG59XG5cbmZ1bmN0aW9uIG93bktleXMoZSwgcikge1xuICAgIHZhciB0ID0gT2JqZWN0LmtleXMoZSk7XG4gICAgaWYgKE9iamVjdC5nZXRPd25Qcm9wZXJ0eVN5bWJvbHMpIHtcbiAgICAgICAgdmFyIG8gPSBPYmplY3QuZ2V0T3duUHJvcGVydHlTeW1ib2xzKGUpO1xuICAgICAgICByICYmIChvID0gby5maWx0ZXIoKGZ1bmN0aW9uKHIpIHtcbiAgICAgICAgICAgIHJldHVybiBPYmplY3QuZ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ldyBBcnJheShfbGVuMiksIF9rZXkyID0gMDsgX2tleTIgPCBfbGVuMjsgX2tleTIrKykge1xuICAgICAgICAgICAgYXJnc1tfa2V5Ml0gPSBhcmd1bWVudHNbX2tleTJdO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9sb2dDYWxsYmFjaykge1xuICAgICAgICAgICAgdGhpcy5fbG9nQ2FsbGJhY2soe1xuICAgICAgICAgICAgICAgIGxldmVsOiBcImluZm9cIixcbiAgICAgICAgICAgICAgICBwYXlsb2FkOiBhcmdzXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5kZWJ1Zykge1xuICAgICAgICAgICAgY29uc29sZS5pbmZvKHRoaXMuX3ByZWZpeCwgLi4uYXJncyk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgd2FybigpIHtcbiAgICAgICAgZm9yICh2YXIgX2xlbjMgPSBhcmd1bWVudHMubGVuZ3RoLCBhcmdzID0gbmV3IEFycmF5KF9sZW4zKSwgX2tleTMgPSAwOyBfa2V5MyA8IF9sZW4zOyBfa2V5MysrKSB7XG4gICAgICAgICAgICBhcmdzW19rZXkzXSA9IGFyZ3VtZW50c1tfa2V5M107XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX2xvZ0NhbGxiYWNrKSB7XG4gICAgICAgICAgICB0aGlzLl9sb2dDYWxsYmFjayh7XG4gICAgICAgICAgICAgICAgbGV2ZWw6IFwid2FyblwiLFxuICAgICAgICAgICAgICAgIHBheWxvYWQ6IGFyZ3NcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLmRlYnVnKSB7XG4gICAgICAgICAgICBjb25zb2xlLndhcm4odGhpcy5fcHJlZml4LCAuLi5hcmdzKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBlcnJvcigpIHtcbiAgICAgICAgZm9yICh2YXIgX2xlbjQgPSBhcmd1bWVudHMubGVuZ3RoLCBhcmdzID0gbmV3IEFycmF5KF9sZW40KSwgX2tleTQgPSAwOyBfa2V5NCA8IF9sZW40OyBfa2V5NCsrKSB7XG4gICAgICAgICAgICBhcmdzW19rZXk0XSA9IGFyZ3VtZW50c1tfa2V5NF07XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX2xvZ0NhbGxiYWNrKSB7XG4gICAgICAgICAgICB0aGlzLl9sb2dDYWxsYmFjayh7XG4gICAgICAgICAgICAgICAgbGV2ZWw6IFwiZXJyb3JcIixcbiAgICAgICAgICAgICAgICBwYXlsb2FkOiBhcmdzXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5kZWJ1Zykge1xuICAgICAgICAgICAgY29uc29sZS5lcnJvcih0aGlzLl9wcmVmaXgsIC4uLmFyZ3MpO1xuICAgICAgICB9XG4gICAgfVxufVxuXG52YXIgbG9nZ2VySW5zdGFuY2UgPSBuZXcgTG9nZ2VyO1xuXG5mdW5jdGlvbiBkZWJvdW5jZShmdW5jLCB3YWl0LCBpbW1lZGlhdGUpIHtcbiAgICB2YXIgdGltZW91dCwgYXJncywgY29udGV4dCwgdGltZXN0YW1wLCByZXN1bHQ7XG4gICAgaWYgKG51bGwgPT0gd2FpdCkgd2FpdCA9IDEwMDtcbiAgICBmdW5jdGlvbiBsYXRlcigpIHtcbiAgICAgICAgdmFyIGxhc3QgPSBEYXRlLm5vdygpIC0gdGltZXN0YW1wO1xuICAgICAgICBpZiAobGFzdCA8IHdhaXQgJiYgbGFzdCA+PSAwKSB7XG4gICAgICAgICAgICB0aW1lb3V0ID0gc2V0VGltZW91dChsYXRlciwgd2FpdCAtIGxhc3QpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGltZW91dCA9IG51bGw7XG4gICAgICAgICAgICBpZiAoIWltbWVkaWF0ZSkge1xuICAgICAgICAgICAgICAgIHJlc3VsdCA9IGZ1bmMuYXBwbHkoY29udGV4dCwgYXJncyk7XG4gICAgICAgICAgICAgICAgY29udGV4dCA9IGFyZ3MgPSBudWxsO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuICAgIHZhciBkZWJvdW5jZWQgPSBmdW5jdGlvbiBkZWJvdW5jZWQoKSB7XG4gICAgICAgIGNvbnRleHQgPSB0aGlzO1xuICAgICAgICBhcmdzID0gYXJndW1lbnRzO1xuICAgICAgICB0aW1lc3RhbXAgPSBEYXRlLm5vdygpO1xuICAgICAgICB2YXIgY2FsbE5vdyA9IGltbWVkaWF0ZSAmJiAhdGltZW91dDtcbiAgICAgICAgaWYgKCF0aW1lb3V0KSB0aW1lb3V0ID0gc2V0VGltZW91dChsYXRlciwgd2FpdCk7XG4gICAgICAgIGlmIChjYWxsTm93KSB7XG4gICAgICAgICAgICByZXN1bHQgPSBmdW5jLmFwcGx5KGNvbnRleHQsIGFyZ3MpO1xuICAgICAgICAgICAgY29udGV4dCA9IGFyZ3MgPSBudWxsO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgfTtcbiAgICBkZWJvdW5jZWQuY2xlYXIgPSBmdW5jdGlvbigpIHtcbiAgICAgICAgaWYgKHRpbWVvdXQpIHtcbiAgICAgICAgICAgIGNsZWFyVGltZW91dCh0aW1lb3V0KTtcbiAgICAgICAgICAgIHRpbWVvdXQgPSBudWxsO1xuICAgICAgICB9XG4gICAgfTtcbiAgICBkZWJvdW5jZWQuZmx1c2ggPSBmdW5jdGlvbigpIHtcbiAgICAgICAgaWYgKHRpbWVvdXQpIHtcbiAgICAgICAgICAgIHJlc3VsdCA9IGZ1bmMuYXBwbHkoY29udGV4dCwgYXJncyk7XG4gICAgICAgICAgICBjb250ZXh0ID0gYXJncyA9IG51bGw7XG4gICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZW91dCk7XG4gICAgICAgICAgICB0aW1lb3V0ID0gbnVsbDtcbiAgICAgICAgfVxuICAgIH07XG4gICAgcmV0dXJuIGRlYm91bmNlZDtcbn1cblxu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ltZW5zaW9ucyh0aGVtZSwgcmF0aW9YLCByYXRpb1ksIHVwQ291bnQpO1xuICAgIH0gZWxzZSBpZiAoaCAmJiB1cENvdW50KSB7XG4gICAgICAgIGRpbWVuc2lvbnMgPSB7XG4gICAgICAgICAgICB3OiBNYXRoLnJvdW5kKGdldFdpZHRoQnlVcENvdW50KHRoZW1lLCB1cENvdW50KSksXG4gICAgICAgICAgICBoOiBoXG4gICAgICAgIH07XG4gICAgfSBlbHNlIGlmIChoKSB7XG4gICAgICAgIGRpbWVuc2lvbnMgPSB7XG4gICAgICAgICAgICB3OiBmYWxsYmFja1csXG4gICAgICAgICAgICBoOiBoXG4gICAgICAgIH07XG4gICAgfSBlbHNlIGlmICh3KSB7XG4gICAgICAgIGRpbWVuc2lvbnMgPSB7XG4gICAgICAgICAgICB3OiB3LFxuICAgICAgICAgICAgaDogZmFsbGJhY2tIXG4gICAgICAgIH07XG4gICAgfSBlbHNlIHtcbiAgICAgICAgZGltZW5zaW9ucyA9IHtcbiAgICAgICAgICAgIHc6IGZhbGxiYWNrVyxcbiAgICAgICAgICAgIGg6IGZhbGxiYWNrSFxuICAgICAgICB9O1xuICAgIH1cbiAgICBkaW1lbnNpb25zID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBkaW1lbnNpb25zKSwge30sIHtcbiAgICAgICAgcmF0aW9YOiByYXRpb1gsXG4gICAgICAgIHJhdGlvWTogcmF0aW9ZLFxuICAgICAgICB1cENvdW50OiB1cENvdW50XG4gICAgfSk7XG4gICAgcmV0dXJuIGRpbWVuc2lvbnM7XG59XG5cbmZ1bmN0aW9uIGdldEl0ZW1SYXRpb0RpbWVuc2lvbnModGhlbWUsIHJhdGlvWCwgcmF0aW9ZLCB1cENvdW50KSB7XG4gICAgdmFyIHcsIGg7XG4gICAgaWYgKHJhdGlvWCAmJiByYXRpb1kgJiYgdXBDb3VudCkge1xuICAgICAgICB3ID0gTWF0aC5yb3VuZChnZXRXaWR0aEJ5VXBD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4Q29sb3IoaGV4KSB7XG4gICAgdmFyIGFscGhhID0gYXJndW1lbnRzLmxlbmd0aCA+IDEgJiYgYXJndW1lbnRzWzFdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMV0gOiAxO1xuICAgIGlmICghaGV4KSB7XG4gICAgICAgIHJldHVybiAwO1xuICAgIH1cbiAgICBpZiAodHlwZW9mIGhleCA9PT0gXCJudW1iZXJcIikge1xuICAgICAgICBoZXggPSBoZXgudG9TdHJpbmcoMTYpLnNsaWNlKDIpO1xuICAgIH1cbiAgICBoZXggPSBoZXgucmVwbGFjZShcIiNcIiwgXCJcIik7XG4gICAgdmFyIGhleEFscGhhID0gTWF0aC5yb3VuZChhbHBoYSAqIDI1NSkudG9TdHJpbmcoMTYpO1xuICAgIHZhciBzdHIgPSBcIjB4XCIuY29uY2F0KGhleEFscGhhKS5jb25jYXQoaGV4KTtcbiAgICByZXR1cm4gTnVtYmVyKHN0cik7XG59XG5cbmZ1bmN0aW9uIGdldFZhbGlkQ29sb3IoY29sb3IpIHtcbiAgICBpZiAodHlwZW9mIGNvbG9yID09PSBcInN0cmluZ1wiIHx8IHR5cGVvZiBjb2xvciA9PT0gXCJudW1iZXJcIikge1xuICAgICAgICBpZiAoL14weFswLTlhLWZBLUZdezh9L2cudGVzdChjb2xvcikpIHtcbiAgICAgICAgICAgIHJldHVybiBOdW1iZXIoY29sb3IpO1xuICAgICAgICB9IGVsc2UgaWYgKC9eI1swLTlhLWZBLUZdezZ9L2cudGVzdChjb2xvcikpIHtcbiAgICAgICAgICAgIHJldHVybiBnZXRIZXhDb2xvcihjb2xvci5zdWJzdHIoMSwgNikpO1xuICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBjb2xvciA9PT0gXCJzdHJpbmdcIiAmJiAvXlswLTldezgsMTB9L2cudGVzdChjb2xvcikpIHtcbiAgICAgICAgICAgIHJldHVybiBwYXJzZUludChjb2xvcik7XG4gICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIGN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G4gICAgICAgICAgICAgICAgICAgIGZvcm1hdHRlZEl0ZW0gPSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aXRsZTogaWNvblsxXSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGljb246IGljb25bMl0gfHwgaWNvblsxXVxuICAgICAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAobmV3bGluZSkge1xuICAgICAgICAgICAgICAgICAgICBmb3JtYXR0ZWRJdGVtID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgbmV3bGluZTogdHJ1ZVxuICAgICAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodGV4dCAmJiB0ZXh0WzFdKSB7XG4gICAgICAgICAgICAgICAgICAgIGZvcm1hdHRlZEl0ZW0gPSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0OiB0ZXh0WzFdLFxuICAgICAgICAgICAgICAgICAgICAgICAgc3R5bGU6IHRleHRbMl1cbiAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgY29udGVudC5wdXNoKGZvcm1hdHRlZEl0ZW0pO1xuICAgICAgICAgICAgfSkpO1xuICAgICAgICB9XG4gICAgfVxuICAgIHJldHVybiBjb250ZW50O1xufVxuXG5mdW5jdGlvbiBtYXgoKSB7XG4gICAgaWYgKCFhcmd1bWVudHMpIHtcbiAgICAgICAgcmV0dXJuO1xuICAgIH1cbiAgICB2YXIgYXJncyA9IEFycmF5LmZyb20oYXJndW1lbnRzKS5maWx0ZXIoKGFyZyA9PiAhaXNOYU4oYXJnKSAmJiBhcmcgIT0gbnVsbCkpO1xuICAgIGlmICghYXJncy5sZW5ndGgpIHtcbiAgICAgICAgcmV0dXJuO1xuICAgIH1cbiAgICByZXR1cm4gTWF0aC5tYXgoLi4uYXJncyk7XG59XG5cbmZ1bmN0aW9uIGNyZWF0ZUNvbmRpdGlvbmFsWk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YWxzZTtcbiAgICAgICAgd2F0Y2hQcm9wcy5mb3JFYWNoKChwcm9wID0+IHtcbiAgICAgICAgICAgIGlmIChlbGVtZW50LnRyYW5zaXRpb24ocHJvcCkgJiYgZWxlbWVudC50cmFuc2l0aW9uKHByb3ApLmlzUnVubmluZygpKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdmFyIHByZXZWYWx1ZUtleSA9IFwiX193YXRjaFByZXZcIi5jb25jYXQocHJvcCk7XG4gICAgICAgICAgICB2YXIgbmV4dFZhbHVlID0gZWxlbWVudFtwcm9wXTtcbiAgICAgICAgICAgIGlmIChuZXh0VmFsdWUgIT09IGVsZW1lbnRbcHJldlZhbHVlS2V5XSkge1xuICAgICAgICAgICAgICAgIGVsZW1lbnRbcHJldlZhbHVlS2V5XSA9IG5leHRWYWx1ZTtcbiAgICAgICAgICAgICAgICBoYXNDaGFuZ2VkID0gdHJ1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSkpO1xuICAgICAgICBpZiAoaGFzQ2hhbmdlZCkge1xuICAgICAgICAgICAgc2lkZUVmZmVjdCgpO1xuICAgICAgICB9XG4gICAgICAgIGlmIChpbml0aWFsT25BZnRlclVwZGF0ZSkge1xuICAgICAgICAgICAgaW5pdGlhbE9uQWZ0ZXJVcGRhdGUoZWxlbWVudCk7XG4gICAgICAgIH1cbiAgICB9LmJpbmQodGhpcyk7XG4gICAgcmV0dXJuIGVsZW1lbnQ7XG59XG5cbmZ1bmN0aW9uIGNvbnZlcnRUZXh0QWxpZ25Ub0ZsZXhKdXN0aWZ5KGFsaWduKSB7XG4gICAgc3dpdGNoIChhbGlnbikge1xuICAgICAgY2FzZSBcImxlZnRcIjpcbiAgICAgICAgcmV0dXJuIFwiZmxleC1zdGFydFwiO1xuXG4gICAgICBjYXNlIFwiY2VudGVyXCI6XG4gICAgICAgIHJldHVybiBcImNlbnRlclwiO1xuXG4gICAgICBjYXNlIFwic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BhbHBoYToge1xuICAgICAgICBwcmltYXJ5OiAxLFxuICAgICAgICBzZWNvbmRhcnk6IC43LFxuICAgICAgICB0ZXJ0aWFyeTogLjEsXG4gICAgICAgIGluYWN0aXZlOiAuNSxcbiAgICAgICAgZnVsbDogMSxcbiAgICAgICAgbm9uZTogMCxcbiAgICAgICAgYWxwaGExOiAuMSxcbiAgICAgICAgYWxwaGEyOiAuMyxcbiAgICAgICAgYWxwaGEzOiAuNSxcbiAgICAgICAgYWxwaGE0OiAuNyxcbiAgICAgICAgYWxwaGE1OiAuOVxuICAgIH0sXG4gICAgYW5pbWF0aW9uOiB7XG4gICAgICAgIGR1cmF0aW9uOiB7XG4gICAgICAgICAgICBub25lOiAwLFxuICAgICAgICAgICAgeGZhc3Q6IC4xLFxuICAgICAgICAgICAgZmFzdDogLjI1LFxuICAgICAgICAgICAgbm9ybWFsOiAuNSxcbiAgICAgICAgICAgIHNsb3c6IC43NSxcbiAgICAgICAgICAgIHhzbG93OiAuOVxuICAgICAgICB9LFxuICAgICAgICBkZWxheToge1xuICAgICAgICAgICAgbm9uZTogMCxcbiAgICAgICAgICAgIHhmYXN0OiAuMDEsXG4gICAgICAgICAgICBmYXN0OiAuMDI1LFxuICAgICAgICAgICAgbm9ybWFsOiAuMDUsXG4gICAgICAgICAgICBzbG93OiAuMDc1LFxuICAgICAgICAgICAgeHNsb3c6IC4wOVxuICAgICAgICB9LFxuICAgICAgICBleHByZXNzaXZlOiB7XG4gICAgICAgICAgICB0aW1pbmdGdW5jdGlvbjogXCJjdWJpYy1iZXppZXIoMCwgMCwgMSwgMSlcIixcbiAgICAgICAgICAgIGRlbGF5OiAwLFxuICAgICAgICAgICAgZHVyYXRpb246IC4yNVxuICAgICAgICB9LFxuICAgICAgICBleHByZXNzaXZlRW50cmFuY2U6IHtcbiAgICAgICAgICAgIHRpbWluZ0Z1bmN0aW9uOiBcImN1YmljLWJlemllcigwLCAwLCAxLCAxKVwiLFxuICAgICAgICAgICAgZGVsYXk6IDAsXG4gICAgICAgICAgICBkdXJhdGlvbjogLjI1XG4gICAgICAgIH0sXG4gICAgICAgIGV4cHJlc3NpdmVFeGl0OiB7XG4gICAgICAgICAgICB0aW1pbmdGdW5jdGlvbjogXCJjdWJpYy1iZXppZXIoMCwgMCwgMSwgMSlcIixcbiAgICAgICAgICAgIGRlbGF5OiAwLFxuICAgICAgICAgICAgZHVyYXRpb246IC4yNVxuICAgICAgICB9LFxuICAgICAgICBzdGFuZGFyZDoge1xuICAgICAgICAgICAgdGltaW5nRnVuY3Rpb246IFwiY3ViaWMtYmV6aWVyKDAsIDAsIDEsIDEpXCIsXG4gICAgICAgICAgICBkZWxheTogMCxcbiAgICAgICAgICAgIGR1cmF0aW9uOiAuMjVcbiAgICAgICAgfSxcbiAgICAgICAgc3RhbmRhcmRFbnRyYW5jZToge1xuICAgICAgICAgICAgdGltaW5nRnVuY3Rpb246IFwiY3ViaWMtYmV6aWVyKDAsIDAsIDEsIDEpXCIsXG4gICAgICAgICAgICBkZWxheTogMCxcbiAgICAgICAgICAgIGR1cmF0aW9uOiAuMjVcbiAgICAgICAgfSxcbiAgICAgICAgc3RhbmRhcmRFeGl0OiB7XG4gICAgICAgICAgICB0aW1pbmdGdW5jdGlvbjogXCJjdWJpYy1iZXppZXIoMCwgMCwgMSwgMSlcIixcbiAgICAgICAgICAgIGRlbGF5OiAwLFxuICAgICAgICAgICAgZHVyYXRpb246IC4yNVxuICAgICAgICB9LFxuICAgICAgICB1dGlsaXR5OiB7XG4gICAgICAgICAgICB0aW1pbmdGdW5jdGlvbjogXCJjdWJpYy1iZXppZXIoMCwgMCwgMSwgMSlcIixcbiAgICAgICAgICAgIGRlbGF5OiAwLFxuICAgICAgICAgICAgZHVyYXRpb246IC4yNVxuICAgICAgICB9LFxuICAgICAgICB1dGlsaXR5RW50cmFuY2U6IHtcbiAgICAgICAgICAgIHRpbWluZ0Z1bmN0aW9uOiBcImN1YmljLWJlemllcigwLCAwLCAxLCAxKVwiLFxuICAgICA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ZTogNTAsXG4gICAgICAgIHNjcmVlblc6IDE5MjAsXG4gICAgICAgIHNjcmVlbkg6IDEwODBcbiAgICB9LFxuICAgIHJhZGl1czoge1xuICAgICAgICBub25lOiAwLFxuICAgICAgICB4czogMixcbiAgICAgICAgc206IDQsXG4gICAgICAgIG1kOiA4LFxuICAgICAgICBsZzogMTYsXG4gICAgICAgIHhsOiAyNFxuICAgIH0sXG4gICAgc3BhY2VyOiB7XG4gICAgICAgIG5vbmU6IDAsXG4gICAgICAgIHh4czogMixcbiAgICAgICAgeHM6IDQsXG4gICAgICAgIHNtOiA4LFxuICAgICAgICBtZDogMTAsXG4gICAgICAgIGxnOiAyMCxcbiAgICAgICAgeGw6IDMwLFxuICAgICAgICB4eGw6IDQwLFxuICAgICAgICB4eHhsOiA1MFxuICAgIH0sXG4gICAgc3Ryb2tlOiB7XG4gICAgICAgIG5vbmU6IDAsXG4gICAgICAgIHNtOiAyLFxuICAgICAgICBtZDogNCxcbiAgICAgICAgbGc6IDYsXG4gICAgICAgIHhsOiA4XG4gICAgfSxcbiAgICB0eXBvZ3JhcGh5OiB7XG4gICAgICAgIGRpc3BsYXkxOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogNzUsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiA4NSxcbiAgICAgICAgICAgIGZvbnRTdHlsZTogXCI1MDBcIixcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgZGlzcGxheTI6IHtcbiAgICAgICAgICAgIGZvbnRGYW1pbHk6IFwiQXJpYWxcIixcbiAgICAgICAgICAgIGZvbnRTaXplOiA1MCxcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDYwLFxuICAgICAgICAgICAgZm9udFN0eWxlOiBcIjUwMFwiLFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogXCJtaWRkbGVcIixcbiAgICAgICAgICAgIHRleHRCYXNlbGluZTogXCJib3R0b21cIlxuICAgICAgICB9LFxuICAgICAgICBoZWFkbGluZTE6IHtcbiAgICAgICAgICAgIGZvbnRGYW1pbHk6IFwiQXJpYWxcIixcbiAgICAgICAgICAgIGZvbnRTaXplOiAzNSxcbiAgICAgICAgICAgIGZvbnRTdHlsZTogXCI1MDBcIixcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDQ4LFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogXCJtaWRkbGVcIixcbiAgICAgICAgICAgIHRleHRCYXNlbGluZTogXCJib3R0b21cIlxuICAgICAgICB9LFxuICAgICAgICBoZWFkbGluZTI6IHtcbiAgICAgICAgICAgIGZvbnRGYW1pbHk6IFwiQXJpYWxcIixcbiAgICAgICAgICAgIGZvbnRTaXplOiAzMCxcbiAgICAgICAgICAgIGZvbnRTdHlsZTogXCI1MDBcIixcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDQwLFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogXCJtaWRkbGVcIixcbiAgICAgICAgICAgIHRleHRCYXNlbGluZTogXCJib3R0b21cIlxuICAgICAgICB9LFxuICAgICAgICBoZWFkbGluZTM6IHtcbiAgICAgICAgICAgIGZvbnRGYW1pbHk6IFwiQXJpYWxcIixcbiAgICAgICAgICAgIGZvbnRTaXplOiAyNSxcbiAgICAgICAgICAgIGZvbnRTdHlsZTogXCI1MDBcIixcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDM2LFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogXCJtaWRkbGVcIixcbiAgICAgICAgICAgIHRleHRCYXNlbGluZTogXCJib3R0b21cIlxuICAgICAgICB9LFxuICAgICAgICBib2R5MToge1xuICAgICAgICAgICAgZm9udEZhbWlseTogXCJBcmlhbFwiLFxuICAgICAgICAgICAgZm9udFNpemU6IDI1LFxuICAgICAgICAgICAgZm9udFN0eWxlOiBcIjMwMFwiLFxuICAgICAgICAgICAgbGluZUhlaWdodDogNDAsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiBcIm1pZGRsZVwiLFxuICAgICAgICAgICAgdGV4dEJhc2VsaW5lOiBcImJvdHRvbVwiXG4gICAgICAgIH0sXG4gICAgICAgIGJvZHkyOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogMjIsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiMzAwXCIsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiAzMixcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgYm9keTM6IHtcbiAgICAgICAgICAgIGZvbnRGYW1pbHk6IFwiQXJpYWxcIixcbiAgICAgICAgICAgIGZvbnRTaXplOiAyMCxcbiAgICAgICAgICAgIGZvbnRTdHlsZTogXCIzMDBcIixcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDMyLFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogXCJtaWRkbGVcIixcbiAgICAgICAgICAgIHRleHRCYXNlbGluZTogXCJib3R0b21cIlxuICAgICAgICB9LFxuICAgICAgICBidXR0b24xOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogMjUsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiNTAwXCIsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiAzMixcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgYnV0dG9uMjoge1xuICAgICAgICAgICAgZm9udEZhbWlseTogXCJBcmlhbFwiLFxuICAgICAgICAgICAgZm9udFNpemU6IDIwLFxuICAgICAgICAgICAgZm9udFN0eWxlOiBcIjUwMFwiLFxuICAgICAgICAgICAgbGluZUhlaWdodDogMzIsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiBcIm1pZGRsZVwiLFxuICAgICAgICAgICAgdGV4dEJhc2VsaW5lOiBcImJvdHRvbVwiXG4gICAgICAgIH0sXG4gICAgICAgIGNhbGxvdXQxOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogMjAsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiNTAwXCIsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiAzMixcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgY2FwdGlvbjE6IHtcbiAgICAgICAgICAgIGZvbnRGYW1pbHk6IFwiQXJpYWxcIixcbiAgICAgICAgICAgIGZvbnRTaXplOiAxNSxcbiAgICAgICAgICAgIGZvbnRTdHlsZTogXCI1MDBcIixcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDI0LFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogXCJtaWRkbGVcIixcbiAgICAgICAgICAgIHRleHRCYXNlbGluZTogXCJib3R0b21cIlxuICAgICAgICB9LFxuICAgICAgICB0YWcxOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogMjAsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiNTAwXCIsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiAyNCxcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWl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LmFkZChmb250RmFjZSk7XG4gICAgICAgIHByb21pc2VzLnB1c2gobmV3IFByb21pc2UoKHJlc29sdmUgPT4ge1xuICAgICAgICAgICAgZm9udEZhY2UubG9hZCgpLnRoZW4oKCgpID0+IHtcbiAgICAgICAgICAgICAgICBjdXN0b21Gb250RmFjZXMucHVzaChmb250RmFjZSk7XG4gICAgICAgICAgICAgICAgcmVzb2x2ZShmYW1pbHkpO1xuICAgICAgICAgICAgfSkpLmNhdGNoKChlcnIgPT4ge1xuICAgICAgICAgICAgICAgIHJlc29sdmUobmV3IEVycm9yKFwiXCIuY29uY2F0KGZhbWlseSwgXCI6IFwiKS5jb25jYXQoZXJyLm1lc3NhZ2UpKSk7XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgIH0pKSk7XG4gICAgfTtcbiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGZvbnRzLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgIF9sb29wKCk7XG4gICAgfVxuICAgIHJldHVybiBQcm9taXNlLmFsbChwcm9taXNlcykudGhlbigoZm9udHNMb2FkZWQgPT4ge1xuICAgICAgICB2YXIgbG9hZGVkID0gZm9udHNMb2FkZWQuZmlsdGVyKChmb250ID0+ICEoZm9udCBpbnN0YW5jZW9mIEVycm9yKSkpLmpvaW4oXCIsIFwiKTtcbiAgICAgICAgaWYgKGxvYWRlZCkge1xuICAgICAgICAgICAgbG9nZ2VySW5zdGFuY2UubG9nKFwiRm9udHMgbG9hZGVkOiBcIi5jb25jYXQobG9hZGVkKSk7XG4gICAgICAgIH1cbiAgICAgICAgdmFyIGZhaWxlZCA9IGZvbnRzTG9hZGVkLmZpbHRlcigoZm9udCA9PiBmb250IGluc3RhbmNlb2YgRXJyb3IpKS5tYXAoKGl0ZW0gPT4gaXRlbS5tZXNzYWdlKSkuam9pbihcIiwgXCIpO1xuICAgICAgICBpZiAoZmFpbGVkKSB7XG4gICAgICAgICAgICBsb2dnZXJJbnN0YW5jZS5lcnJvcihcIlVuYWJsZSB0byBsb2FkIGZvbnRzOiBcIi5jb25jYXQoZmFpbGVkKSk7XG4gICAgICAgIH1cbiAgICB9KSk7XG59O1xuXG52YXIgY2xlYW51cEZvbnRzID0gZnVuY3Rpb24oKSB7XG4gICAgdmFyIF9yZWYzID0gX2FzeW5jVG9HZW5lcmF0b3IoKGZ1bmN0aW9uKihmb250cykge1xuICAgICAgICBpZiAoZG9jdW1lbnQuZm9udHMgJiYgXCJkZWxldGVcIiBpbiBkb2N1bWVudC5mb250cykge1xuICAgICAgICAgICAgaWYgKCFjdXN0b21Gb250RmFjZXMubGVuZ3RoKSByZXR1cm47XG4gICAgICAgICAgICBjdXN0b21Gb250RmFjZXMgPSBjdXN0b21Gb250RmFjZXMuZmlsdGVyKChmb250RmFjZSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKCFmb250cy5maW5kKChmb250ID0+IGZvbnQuZmFtaWx5ID09PSBmb250RmFjZS5mYW1pbHkpKSkge1xuICAgICAgICAgICAgICAgICAgICBsb2dnZXJJbnN0YW5jZS5pbmZvKFwiUmVtb3ZpbmcgZm9udFwiLCBmb250RmFjZS5mYW1pbHkpO1xuICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5mb250cy5kZWxldGUoZm9udEZhY2UpO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZvbnRGYWNlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGxvZ2dlckluc3RhbmNlLmluZm8oXCJVbmFibGUgdG8gcmVtb3ZlIG1hbnVhbGx5LWFkZGVkIGZvbnRzXCIpO1xuICAgICAgICB9XG4gICAgfSkpO1xuICAgIHJldHVybiBmdW5jdGlvbiBjbGVhbnVwRm9udHMoX3gpIHtcbiAgICAgICAgcmV0dXJuIF9yZWYzLmFw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B2YXIgcmVwbGFjZW1lbnQgPSBvcmlnaW5hbFZhbHVlO1xuICAgICAgICAgICAgICAgIGZvciAodmFyIGsgaW4gdmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKE9iamVjdC5oYXNPd25Qcm9wZXJ0eS5jYWxsKHZhbHVlLCBrKSAmJiBUSEVNRV9LRVlfUkVQTEFDRVJba10pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlcGxhY2VtZW50W2sgJiYgVEhFTUVfS0VZX1JFUExBQ0VSW2tdXSA9IHZhbHVlW2tdO1xuICAgICAgICAgICAgICAgICAgICAgICAgZGVsZXRlIHJlcGxhY2VtZW50W2tdO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHZhbHVlID0gcmVwbGFjZW1lbnQ7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIge2lzSW1hZ2U6IGlzSW1hZ2UsIG1pbWVUeXBlOiBtaW1lVHlwZX0gPSBjaGVja0Jhc2U2NEVuY29kZWRJbWFnZSh2YWx1ZSk7XG4gICAgICAgICAgICBpZiAod2luZG93LlVSTCAmJiB0eXBlb2Ygd2luZG93LlVSTC5jcmVhdGVPYmplY3RVUkwgPT09IFwiZnVuY3Rpb25cIiAmJiBpc0ltYWdlKSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIGJsb2JVUkwgPSBiYXNlNjRUb0Jsb2JVUkwodmFsdWUsIG1pbWVUeXBlKTtcbiAgICAgICAgICAgICAgICAgICAgYmFzZTY0Q2FjaGUucHVzaChibG9iVVJMKTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGJsb2JVUkw7XG4gICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyb3IpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHZhbHVlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1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uge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdmFsdWU7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB2YXIgdmFsaWRDb2xvciA9IGdldFZhbGlkQ29sb3IodmFsdWUpO1xuICAgICAgICAgICAgICAgIGlmICh2YWxpZENvbG9yKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB2YWxpZENvbG9yO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4gdmFsdWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pKTtcbiAgICAgICAgcmV0dXJuIF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBKU09OLnBhcnNlKHRoZW1lU3RyaW5nKSksIHRoZW1lRnVuY3Rpb25zKSwge30sIHtcbiAgICAgICAgICAgIGV4dGVuc2lvbnM6IGV4dGVuc2lvbnNcbiAgICAgICAgfSk7XG4gICAgfVxufVxuXG52YXIgdGhlbWVNYW5hZ2VySW5zdGFuY2UgPSBuZXcgVGhlbWVNYW5hZ2VyO1xuXG5jbGFzcyBDb250ZXh0IHtcbiAgICBnZXQgdGhlbWUoKSB7XG4gICAgICAgIHJldHVybiB0aGVtZU1hbmFnZXJJbnN0YW5jZS5nZXRUaGVtZSgpO1xuICAgIH1cbiAgICBzZXQgdGhlbWUodmFsdWUpIHtcbiAgICAgICAgbG9nZ2VySW5zdGFuY2Uud2FybihcIkNvbnRleHQudGhlbWUgbXVzdCBiZSBzZXQgdXNpbmcgY29udGV4dC5zZXRUaGVtZSBvciBjb250ZXh0LnVwZGF0ZVRoZW1lXCIpO1xuICAgIH1cbiAgICBnZXQga2V5TWV0cmljc0NhbGxiYWNrKCkge1xuICAgICAgICByZXR1cm4gbWV0cmljc0luc3RhbmNlLmtleU1ldHJpY3NDYWxsYmFjaztcbiAgICB9XG4gICAgc2V0IGtleU1ldHJpY3ND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21HZXR0ZXIgPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICAgICAgICAgIHZhciBfdGhpcyRfX2NvbXBvbmVudENvbmYsIF90aGlzJF9fY29tcG9uZW50Q29uZjI7XG4gICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gY3VzdG9tR2V0dGVyLmNhbGwodGhpcywgdGhpc1trZXldKTtcbiAgICAgICAgICAgICAgICB0aGlzW2tleV0gPSB2YWx1ZSB8fCAoKF90aGlzJF9fY29tcG9uZW50Q29uZiA9IHRoaXMuX19jb21wb25lbnRDb25maWdQcm9wcykgPT09IG51bGwgfHwgX3RoaXMkX19jb21wb25lbnRDb25mID09PSB2b2lkIDAgPyB2b2lkIDAgOiBfdGhpcyRfX2NvbXBvbmVudENvbmZbbmFtZV0pO1xuICAgICAgICAgICAgICAgIHJldHVybiBtZXJnZVByb3BzKChfdGhpcyRfX2NvbXBvbmVudENvbmYyID0gdGhpcy5fX2NvbXBvbmVudENvbmZpZ1Byb3BzKSA9PT0gbnVsbCB8fCBfdGhpcyRfX2NvbXBvbmVudENvbmYyID09PSB2b2lkIDAgPyB2b2lkIDAgOiBfdGhpcyRfX2NvbXBvbmVudENvbmYyW25hbWVdLCB2YWx1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gbWVyZ2VQcm9wcygoX3RoaXMkX19jb21wb25lbnRDb25mMyA9IHRoaXMuX19jb21wb25lbnRDb25maWdQcm9wcykgPT09IG51bGwgfHwgX3RoaXMkX19jb21wb25lbnRDb25mMyA9PT0gdm9pZCAwID8gdm9pZCAwIDogX3RoaXMkX19jb21wb25lbnRDb25mM1tuYW1lXSwgdGhpc1trZXldKTtcbiAgICAgICAgfSxcbiAgICAgICAgc2V0KHZhbHVlKSB7XG4gICAgICAgICAgICB2YXIgb2xkVmFsdWUgPSB0aGlzW2tleV07XG4gICAgICAgICAgICBpZiAodmFsdWUgIT09IG9sZFZhbHVlKSB7XG4gICAgICAgICAgICAgICAgdmFyIG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BhbmQgd2lsbCBiZSByZW1vdmVkIGluIGEgZnV0dXJlIHJlbGVhc2UuIFBsZWFzZSB1c2UgXCInKS5jb25jYXQoY3VyciwgJ1wiIGluc3RlYWQuJyk7XG4gICAgcmV0dXJuIHtcbiAgICAgICAgZ2V0KCkge1xuICAgICAgICAgICAgY29uc29sZS53YXJuKGRlcHJlY2F0aW9uV2FybmluZyk7XG4gICAgICAgICAgICByZXR1cm4gdGhpc1tjdXJyXTtcbiAgICAgICAgfSxcbiAgICAgICAgc2V0KHZhbHVlKSB7XG4gICAgICAgICAgICBjb25zb2xlLndhcm4oZGVwcmVjYXRpb25XYXJuaW5nKTtcbiAgICAgICAgICAgIHRoaXNbY3Vycl0gPSB2YWx1ZTtcbiAgICAgICAgfVxuICAgIH07XG59XG5cbmZ1bmN0aW9uIHdpdGhVcGRhdGVzKEJhc2UpIHtcbiAgICByZXR1cm4gY2xhc3MgZXh0ZW5kcyBCYXNlIHtcbiAgICAgICAgc3RhdGljIGdldCBuYW1lKCkge1xuICAgICAgICAgICAgcmV0dXJuIEJhc2UubmFtZTtcbiAgICAgICAgfVxuICAgICAgICBfY29uc3RydWN0KCkge1xuICAgICAgICAgICAgdmFyIHByb3RvdHlwZSA9IE9iamVjdC5nZXRQcm90b3R5cGVPZih0aGlzKTtcbiAgICAgICAgICAgIGlmICghcHJvdG90eXBlLl93aXRoVXBkYXRlc0luaXRpYWxpemVkKSB7XG4gICAgICAgICAgICAgICAgdmFyIHByb3BzID0gdGhpcy5jb25zdHJ1Y3Rvci5wcm9wZXJ0aWVzIHx8IFtdO1xuICAgICAgICAgICAgICAgIHByb3BzLmZvckVhY2goKG5hbWUgPT4ge1xuICAgICAgICAgICAgICAgICAgICB2YXIga2V5ID0gXCJfXCIgKyBuYW1lO1xuICAgICAgICAgICAgICAgICAgICB2YXIgZGVzY3JpcHRvciA9IGdldFByb3BlcnR5RGVzY3JpcHRvciQxKG5hbWUsIGtleSk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChkZXNjcmlwdG9yICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShwcm90b3R5cGUsIG5hbWUsIGRlc2NyaXB0b3IpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgICAgIHZhciBhbGlhc1Byb3BzID0gdGhpcy5jb25zdHJ1Y3Rvci5hbGlhc1Byb3BlcnRpZXMgfHwgW107XG4gICAgICAgICAgICAgICAgYWxpYXNQcm9wcy5mb3JFYWNoKChhbGlhcyA9PiB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChhbGlhcyAmJiB0eXBlb2YgYWxpYXMucHJldiA9PT0gXCJzdHJpbmdcIiAmJiB0eXBlb2YgYWxpYXMuY3VyciA9PT0gXCJzdHJpbmdcIikge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGRlc2NyaXB0b3IgPSBnZXRBbGlhc1Byb3BlcnR5RGVzY3JpcHRvcihhbGlhcy5wcmV2LCBhbGlhcy5jdXJyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkZXNjcmlwdG9yICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkocHJvdG90eXBlLCBhbGlhcy5wcmV2LCBkZXNjcmlwdG9yKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICBwcm90b3R5cGUuX3dpdGhVcGRhdGVzSW5pdGlhbGl6ZWQgPSB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fd2hlbkVuYWJsZWQgPSBuZXcgUHJvbWlzZSgocmVzb2x2ZSA9PiB7XG4gICAgICAgICAgICAgICAgdGhpcy5fd2hlbkVuYWJsZW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gICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIF9kZXRhY2goKSB7XG4gICAgICAgICAgICBzdXBlci5fZGV0YWNoKCk7XG4gICAgICAgICAgICB1cGRhdGVNYW5hZ2VyLmRlbGV0ZVJlcXVlc3RVcGRhdGUodGhpcyk7XG4gICAgICAgIH1cbiAgICAgICAgcmVxdWVzdFVwZGF0ZSgpIHtcbiAgICAgICAgICAgIHZhciBmb3JjZSA9IGFyZ3VtZW50cy5sZW5ndGggPiAwICYmIGFyZ3VtZW50c1swXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzBdIDogZmFsc2U7XG4gICAgICAgICAgICBpZiAodGhpcy5fcmVhZHlGb3JVcGRhdGVzIHx8IGZvcmNlKSB7XG4gICAgICAgICAgICAgICAgdmFyIHJlc3VsdCA9IHRoaXMuX3VwZGF0ZSgpO1xuICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgcmVzdWx0ID09PSBcIm9iamVjdFwiICYmIHJlc3VsdCAhPT0gbnVsbCAmJiByZXN1bHQuY2F0Y2gpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0LmNhdGNoKChlID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRleHRJbnN0YW5jZS5lcnJvcihcImFzeW5jcm9ub3VzIF91cGRhdGUoKSBlcnJvciBpbiAnXCIuY29uY2F0KHRoaXMuY29uc3RydWN0b3IuX19jb21wb25lbnROYW1lLCBcIidcIiksIHRoaXMsIGUpO1xuICAgICAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGxvZ1Byb3BUYWJsZSgpIHtcbiAgICAgICAgICAgIGNvbnNvbGUudGFibGUodGhpcy5fcHJvcFRhYmxlKTtcbiAgICAgICAgfVxuICAgICAgICBnZXQgX3Byb3BUYWJsZSgpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLmNvbnN0cnVjdG9yLnByb3BlcnRpZXMucmVkdWNlKCgoYWNjLCBwcm9wKSA9PiB7XG4gICAgICAgICAgICAgICAgYWNjW3Byb3BdID0gdGhpc1twcm9wXTtcbiAgICAgICAgICAgICAgICByZXR1cm4gYWNjO1xuICAgICAgICAgICAgfSksIHt9KTtcbiAgICAgICAgfVxuICAgIH07XG59XG5cbmZ1bmN0aW9uIGdldFByb3BlcnR5RGVzY3JpcHRvcihwYXRoKSB7XG4gICAgcmV0dXJuIHtcbiAgICAgICAgZ2V0KCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMudGFnKHBhdGgpO1xuICAgICAgICB9LFxuICAgICAgICBjb25maWd1cmFibGU6IHRydWUsXG4gICAgICAgIGVudW1lcmFibGU6IHRydWVcbiAgICB9O1xufVxuXG5mdW5jdGlvbiB3aXRoVGFncyhCYXNlKSB7XG4gICAgcmV0dXJuIGNsYXNzIGV4dGVuZHMgQmFzZSB7XG4gICAgICAgIHN0YXRpYyBnZXQgbmFtZSgpIHtcbiAgICAgICAgICAgIHJldHVybiBCYXNlLm5hbWU7XG4gICAgICAgIH1cbiAgICAgICAgX2NvbnN0cnVjdCgpIHtcbiAgICAgICAgICAgIHZhciBwcm90b3R5cGUgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2YodGhpcyk7XG4gICAgICAgICAgICBpZiAoIXByb3RvdHlwZS5fd2l0aFRhZ3NJbml0aWFsaXplZCkge1xuICAgICAgICAgICAgICAgIHZhciB0YWdzID0gdGhpcy5jb25zdHJ1Y3Rvci50YWdzIHx8IFtdO1xuICAgICAgICAgICAgICAgIHRhZ3MuZm9yRWFjaCgodGFnID0+IHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHR5cGVvZiB0YWcgPT09IFwib2JqZWN0XCIpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciB7bmFtZTogbmFtZSwgcGF0aDogcGF0aH0gPSB0YWc7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgbmFtZSA9IHRhZztcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBwYXRoID0gdGFnO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHZhciBrZXkgPSBcIl9cIiArIG5hbWU7XG4gICAgICAgICAgICAgICAgICAgIHZhciBkZXNjcmlwdG9yID0gZ2V0UHJvcGVydHlEZXNjcmlwdG9yKHBhdGgpO1xuICAgICAgICAgICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkocHJvdG90eXBlLCBrZXksIGRlc2NyaXB0b3IpO1xuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICBwcm90b3R5cGUuX3dpdGhUYWdzSW5pdGlhbGl6ZWQgPSB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCAmJiBzdXBlci5fY29uc3RydWN0KCk7XG4gICAgICAgIH1cbiAgICB9O1xufVxuXG5mdW5jdGlvbiB3aXRoSGFuZGxlS2V5KEJhc2UpIHtcbiAgICByZXR1cm4gY2xhc3MgZXh0ZW5kcyBCYXNlIHtcbiAgICAgICAgc3RhdGljIGdldCBuYW1lKCkge1xuICAgICAgICAgICAgcmV0dXJuIEJhc2UubmFtZTtcbiAgICAgICAgfVxuICAgICAgICBfaGFuZGxlS2V5KGtleUV2ZW50KSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fcHJvY2Vzc0V2ZW50KGtleUV2ZW50KTtcbiAgICAgICAgfVxuICAgICAgICBfaGFuZGxlS2V5UmVsZWFzZShrZXlFdmVudCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3Byb2Nlc3NFdmVudChrZXlFdmVudCwgXCJSZWxlYXNlXCIpO1xuICAgICAgICB9XG4gICAgICAgIF9wcm9jZXNzRXZlbnQoa2V5RXZlbnQpIHtcbiAgICAgICAgICAgIHZhciBzdWZ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GhMYXlvdXQoQmFzZSkge1xuICAgIHJldHVybiBjbGFzcyBleHRlbmRzIEJhc2Uge1xuICAgICAgICBfY29uc3RydWN0KCkge1xuICAgICAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCAmJiBzdXBlci5fY29uc3RydWN0KCk7XG4gICAgICAgICAgICB0aGlzLl9wcmV2aW91c0RpbWVuc2lvbkRhdGEgPSBudWxsO1xuICAgICAgICB9XG4gICAgICAgIGdldCBpdGVtTGF5b3V0KCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2l0ZW1MYXlvdXQ7XG4gICAgICAgIH1cbiAgICAgICAgc2V0IGl0ZW1MYXlvdXQodikge1xuICAgICAgICAgICAgdmFyIGNvbXBvbmVudE5hbWUgPSB0aGlzLmNvbnN0cnVjdG9yLl9jb21wb25lbnROYW1lIHx8IHRoaXMuY29uc3RydWN0b3IubmFtZTtcbiAgICAgICAgICAgIHZhciBpdGVtTGF5b3V0O1xuICAgICAgICAgICAgaWYgKHYpIHtcbiAgICAgICAgICAgICAgICBpdGVtTGF5b3V0ID0gSlNPTi5wYXJzZShKU09OLnN0cmluZ2lmeSh2LCAoKGssIHYpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGsgIT09IFwiY2lyY2xlXCIgJiYgdiA8IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRleHRJbnN0YW5jZS5lcnJvcihcIml0ZW1MYXlvdXQgZm9yIFwiLmNvbmNhdChjb21wb25lbnROYW1lLCBcIiByZWNlaXZlZCBhbiBpbnZhbGlkIHZhbHVlIG9mIFwiKS5jb25jYXQodiwgXCIgZm9yIFwiKS5jb25jYXQoaykpO1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGsgPT09IFwiY2lyY2xlXCIpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBCb29sZWFuKHYpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB2O1xuICAgICAgICAgICAgICAgIH0pKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoIXN0cmluZ2lmeUNvbXBhcmUodGhpcy5faXRlbUxheW91dCwgaXRlbUxheW91dCkpIHtcbiAgICAgICAgICAgICAgICBpZiAoaXRlbUxheW91dCAmJiAhaXRlbUxheW91dC51cENvdW50KSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX29yaWdpbmFsVyA9IHRoaXMudztcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fb3JpZ2luYWxIID0gdGhpcy5oO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9pdGVtTGF5b3V0ID0gX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLl9vcmlnaW5hbFcsXG4gICAgICAgICAgICAgICAgICAgICAgICBoOiB0aGlzLl9vcmlnaW5hbEhcbiAgICAgICAgICAgICAgICAgICAgfSwgaXRlbUxheW91dCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5faXRlbUxheW91dCA9IGl0ZW1MYXlvdXQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUl0ZW1MYXlvdXQoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBfYWxsb3dVcGRhdGUoKSB7XG4gICAgICAgICAgICB2YXIge3c6IHcgPSBcIlwiLCBoOiBoID0gXCJcIiwgY2lyY2xlOiBjaXJjbGUgPSBcIlwiLCByYXRpb1g6IHJhdGlvWCA9IFwiXCIsIHJhdGlvWTogcmF0aW9ZID0gXCJcIiwgdXBDb3VudDogdXBDb3VudCA9IFwiXCJ9ID0gdGhpcy5faXRlbUxheW91dCB8fCB7fTtcbiAgICAgICAgICAgIHZhciBsYXlvdXRTdHJpbmcgPSBPYmplY3QudmFsdWVzKGNvbnRleHRJbnN0YW5jZS50aGVtZS5sYXlvdXQpLmpvaW4oXCJcIikgKyBcIlwiLmNvbmNhdCh3KS5jb25jYXQoaCkuY29uY2F0KGNpcmNsZSA/IDEgOiAwKS5jb25jYXQocmF0aW9YKS5jb25jYXQocmF0aW9ZKS5jb25jYXQodXBDb3VudCk7XG4gICAgICAgICAgICBpZiAobGF5b3V0U3RyaW5nICE9PSB0aGlzLl9wcmV2aW91c0RpbWVuc2lvbkRhdGEpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9wcmV2aW91c0RpbWVuc2lvbkRhdGEgPSBsYXlvdXRTdHJpbmc7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgIH1cbiAgICAgICAgX3VwZGF0ZUl0ZW1MYXlvdXQoKSB7XG4gICAgICAgICAgICBpZiAoIXRoaXMuX2FsbG93VXBkYXRlKCkpIHJldHVybjtcbiAgICAgICAgICAgIHZhciB7dzogdywgaDogaH0gPSBnZXREaW1lbnNpb25zKHRoaXMudGhlbWUsIHRoaXMuX2l0ZW1MYXlvdXQpO1xuICAgICAgICAgICAgaWYgKGggfHwgdykge1xuICAgICAgICAgICAgICAgIHZhciB3aWR0aCA9IGNvbnRleHRJbnN0YW5jZS50aGVtZS5sYXlvdXQuc2NyZWVuVztcbiAgICAgICAgICAgICAgICB2YXIgaGVpZ2h0ID0gY29udGV4dEluc3RhbmNlLnRoZW1lLmxheW91dC5zY3JlZW5IO1xuICAgICAgICAgICAgICAgIHZhciBjYWxjdWxhdGVkV2lkdGggPSB3IHx8IGggKiAod2lkdGggLyBoZWlnaHQpO1xuICAgICAgICAgICAgICAgIHZhciBjYWxjdWxhdGVkSGVpZ2h0ID0gaCB8fCB3ICogKGhlaWdodCAvIHdpZHRoKTtcbiAgICAgICAgICAgICAgICB0aGlzLncgPSB0aGlzLl9pdGVtTGF5b3V0ICYmIHRoaXMuX2l0ZW1MYXlvdXQuY2lyY2xlID8gY2FsY3VsYXRlZEhlaWdodCA6IGNhbGN1bGF0ZWRXaWR0aDtcbiAgICAgICAgICAgICAgICB0aGlzLmggPSBjYWxjdWxhdGVkSGVpZ2h0O1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9pdGVtTGF5b3V0ICYmIHRoaXMuX2l0ZW1MYXlvdXQuY2lyY2xlICYmIHRoaXMuc3R5bGUucmFkaXVzKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2NpcmNsZVNldCA9IHRydWU7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX29yaWdpbmFsUmFkaXVzID0gdGhpcy5zdHlsZS5yYWRpdXM7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc3R5bGUgPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmFkaXVzOiBjYWxjdWxhdGVkSGVpZ2h0IC8gMlxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2NpcmNsZVNldCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnN0eWxlID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJhZGl1czogdGhpcy5fb3JpZ2luYWxSYWRpdXNcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX29yaWdpbmFsUmFkaXVzID0gdW5kZWZpbmVkO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9jaXJjbGVTZXQgPSBmYWxzZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdGhpcy5xdWV1ZVJlcXVlc3RVcGRhdGUgJiYgd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HJlbW92ZUVtcHR5T2JqZWN0cyhvYmopIHtcbiAgICBmb3IgKHZhciBrZXkgaW4gb2JqKSB7XG4gICAgICAgIGlmIChvYmouaGFzT3duUHJvcGVydHkoa2V5KSAmJiBpc1BsYWluT2JqZWN0KG9ialtrZXldKSkge1xuICAgICAgICAgICAgcmVtb3ZlRW1wdHlPYmplY3RzKG9ialtrZXldKTtcbiAgICAgICAgICAgIGlmIChPYmplY3Qua2V5cyhvYmpba2V5XSkubGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgICAgICAgZGVsZXRlIG9ialtrZXldO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuICAgIHJldHVybiBvYmo7XG59XG5cbmZ1bmN0aW9uIGNyZWF0ZVNoYXJlZFJlZmVyZW5jZXMoKSB7XG4gICAgdmFyIG9iaiA9IGFyZ3VtZW50cy5sZW5ndGggPiAwICYmIGFyZ3VtZW50c1swXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzBdIDoge307XG4gICAgdmFyIHNlZW5PYmplY3RzID0gbmV3IE1hcDtcbiAgICBmdW5jdGlvbiBoYXNoKG9iamVjdCkge1xuICAgICAgICByZXR1cm4gSlNPTi5zdHJpbmdpZnkob2JqZWN0LCBPYmplY3Qua2V5cyhvYmplY3QpLnNvcnQoKSk7XG4gICAgfVxuICAgIGZ1bmN0aW9uIHByb2Nlc3MoY3VycmVudE9iaikge1xuICAgICAgICBmb3IgKHZhciBrZXkgaW4gY3VycmVudE9iaikge1xuICAgICAgICAgICAgaWYgKGN1cnJlbnRPYmouaGFzT3duUHJvcGVydHkoa2V5KSkge1xuICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IGN1cnJlbnRPYmpba2V5XTtcbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIHZhbHVlID09PSBcIm9iamVjdFwiICYmIHZhbHVlICE9PSBudWxsKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciB2YWx1ZUhhc2ggPSBoYXNo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zID0gW107XG4gICAgZnVuY3Rpb24gc2VhcmNoTmVzdGVkS2V5cyhvYmopIHtcbiAgICAgICAgaWYgKHR5cGVvZiBvYmogPT09IFwib2JqZWN0XCIgJiYgb2JqICE9PSBudWxsKSB7XG4gICAgICAgICAgICBmb3IgKHZhciBrZXkgaW4gb2JqKSB7XG4gICAgICAgICAgICAgICAgaWYgKG9iai5oYXNPd25Qcm9wZXJ0eShrZXkpKSB7XG4gICAgICAgICAgICAgICAgICAgIG5lc3RlZEtleXMucHVzaChrZXkpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbiAgICBmdW5jdGlvbiBzZWFyY2hGb3JLZXkob2JqKSB7XG4gICAgICAgIGlmICh0eXBlb2Ygb2JqID09PSBcIm9iamVjdFwiICYmIG9iaiAhPT0gbnVsbCkge1xuICAgICAgICAgICAgZm9yICh2YXIga2V5IGluIG9iaikge1xuICAgICAgICAgICAgICAgIGlmIChvYmouaGFzT3duUHJvcGVydHkoa2V5KSkge1xuICAgICAgICAgICAgICAgICAgICBpZiAoa2V5ID09PSBrZXlUb0ZpbmQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHNlYXJjaE5lc3RlZEtleXMob2JqW2tleV0pO1xuICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgc2VhcmNoRm9yS2V5KG9ialtrZXldKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgc2VhcmNoRm9yS2V5KG9iaik7XG4gICAgcmV0dXJuIG5lc3RlZEtleXM7XG59XG5cbnZhciBnZW5lcmF0ZVNvbHV0aW9uID0gZnVuY3Rpb24gZ2VuZXJhdGVTb2x1dGlvbihfcmVmNykge1xuICAgIHZhciB7YmFzZTogYmFzZSA9IHt9LCB0b25lOiB0b25lID0ge30sIG1vZGU6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bGVDaGFpbi5tYXAoKF9yZWY4ID0+IHtcbiAgICAgICAgdmFyIHtzdHlsZTogc3R5bGV9ID0gX3JlZjg7XG4gICAgICAgIGlmICh0eXBlb2Ygc3R5bGUgPT09IFwib2JqZWN0XCIgJiYgIXN0eWxlLmJhc2UgJiYgIXN0eWxlLm1vZGUgJiYgIXN0eWxlLnRvbmUgJiYgIXN0eWxlLmRlZmF1bHQpIHtcbiAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgYmFzZTogc3R5bGVcbiAgICAgICAgICAgIH07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB2YXIge2Jhc2U6IF9iYXNlID0ge30sIG1vZGU6IF9tb2RlID0ge30sIHRvbmU6IF90b25lID0ge319ID0gc3R5bGU7XG4gICAgICAgICAgICB2YXIgY29tcG9uZW50Q29uZmlnRGVmYXVsdFN0eWxlO1xuICAgICAgICAgICAgaWYgKHN0eWxlKSB7XG4gICAgICAgICAgICAgICAgdmFyIGRlZmF1bHRTdHlsZSA9IEpTT04ucGFyc2UoSlNPTi5zdHJpbmdpZnkoc3R5bGUpKTtcbiAgICAgICAgICAgICAgICBkZWxldGUgZGVmYXVsdFN0eWxlLmJhc2U7XG4gICAgICAgICAgICAgICAgZGVsZXRlIGRlZmF1bHRTdHlsZS50b25lO1xuICAgICAgICAgICAgICAgIGRlbGV0ZSBkZWZhdWx0U3R5bGUubW9kZTtcbiAgICAgICAgICAgICAgICBjb21wb25lbnRDb25maWdEZWZhdWx0U3R5bGUgPSBkZWZhdWx0U3R5bGU7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgIGRlZmF1bHRTdHlsZTogY29tcG9uZW50Q29uZmlnRGVmYXVsdFN0eWxlIHx8IHt9LFxuICAgICAgICAgICAgICAgIGJhc2U6IF9iYXNlLFxuICAgICAgICAgICAgICAgIG1vZGU6IF9tb2RlLFxuICAgICAgICAgICAgICAgIHRvbmU6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IGRvIHtcbiAgICAgICAgdmFyIF9wcm90bztcbiAgICAgICAgcHJvdG8gPSAhcHJvdG8gPyBjb21wb25lbnRPYmogOiBPYmplY3QuZ2V0UHJvdG90eXBlT2YocHJvdG8pO1xuICAgICAgICBpZiAoKChfcHJvdG8gPSBwcm90bykgPT09IG51bGwgfHwgX3Byb3RvID09PSB2b2lkIDAgPyB2b2lkIDAgOiBfcHJvdG8uY29uc3RydWN0b3IpID09PSBPYmplY3QpIGJyZWFrO1xuICAgICAgICBpZiAocHJvdG8gJiYgdHlwZW9mIHByb3RvID09PSBcIm9iamVjdFwiICYmIHByb3RvLmhhc093blByb3BlcnR5KFwiY29uc3RydWN0b3JcIikpIHtcbiAgICAgICAgICAgIHZhciB7c3R5bGU6IGNvbXBvbmVudENvbmZpZ1N0eWxlfSA9IGdldENvbXBvbmVudENvbmZpZyhwcm90byk7XG4gICAgICAgICAgICBpZiAoT2JqZWN0LmtleXMoY29tcG9uZW50Q29uZmlnU3R5bGUgfHwge30pLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgIGlmICghc3R5bGVNYXAuaGFzKGNvbXBvbmVudENvbmZpZ1N0eWxlKSkge1xuICAgICAgICAgICAgICAgICAgICBzdHlsZU1hcC5zZXQoY29tcG9uZW50Q29uZmlnU3R5bGUsIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0eWxlOiBjb21wb25lbnRDb25maWdTdHlsZVxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgdGhlbWVTdHlsZSA9IHByb3RvLmNvbnN0cnVjdG9yLmhhc093blByb3BlcnR5KFwiX190aGVtZVN0eWxlXCIpICYmIHByb3RvLmNvbnN0cnVjdG9yLl9fdGhlbWVTdHlsZTtcbiAgICAgICAgICAgIGlmIChPYmplY3Qua2V5cyh0aGVtZVN0eWxlIHx8IHt9KS5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICBpZiAoIXN0eWxlTWFwLmhhcyh0aGVtZVN0eWxlKSkge1xuICAgICAgICAgICAgICAgICAgICBzdHlsZU1hcC5zZXQodGhlbWVTdHlsZSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3R5bGU6IF9vYmplY3RTcHJlYWQoe30sIHRoZW1lU3R5bGUpXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHRoZW1lU3R5bGUgPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICAgICAgICAgIGlmICghc3R5bGVNYXAuaGFzKHRoZW1lU3R5bGUpKSB7XG4gICAgICAgICAgICAgICAgICAgIHN0eWxlTWFwLnNldCh0aGVtZVN0eWxlLCB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzdHlsZTogdGhlbWVTdHlsZVxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgbWl4aW5TdHlsZSA9IHByb3RvLmNvbnN0cnVjdG9yLmhhc093blByb3BlcnR5KFwiX19taXhpblN0eWxlXCIpICYmIHByb3RvLmNvbnN0cnVjdG9yLl9fbWl4aW5TdHlsZTtcbiAgICAgICAgICAgIGlmIChPYmplY3Qua2V5cyhtaXhpblN0eWxlIHx8IHt9KS5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICBpZiAoIXN0eWxlTWFwLmhhcyhtaXhpblN0eWxlKSkge1xuICAgICAgICAgICAgICAgICAgICBzdHlsZU1hcC5zZXQobWl4aW5TdHlsZSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3R5bGU6IG1peGluU3R5bGVcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfSB3aGlsZSAocHJvdG8pO1xuICAgIHZhciB1bmlxdWVTdHlsZXMgP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X19pZCk7XG4gICAgICAgICAgICBpZiAocmVtb3ZlSW5kZXggPiAtMSAmJiBpZHMubGVuZ3RoID4gMSkge1xuICAgICAgICAgICAgICAgIGNhY2hlLnNldChuYW1lLCB7XG4gICAgICAgICAgICAgICAgICAgIGlkczogaWRzLnNsaWNlKDAsIHJlbW92ZUluZGV4KS5jb25jYXQoaWRzLnNsaWNlKHJlbW92ZUluZGV4ICsgMSkpLFxuICAgICAgICAgICAgICAgICAgICBwYXlsb2FkOiBwYXlsb2FkXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHJlbW92ZUluZGV4ID4gLTEpIHtcbiAgICAgICAgICAgICAgICBjYWNoZS5kZWxldGUobmFtZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pKTtcbiAgICB9XG4gICAgX3JlbW92ZUNhY2hlKG5hbWUpIHtcbiAgICAgICAgY2FjaGUuZGVsZXRlKG5hbWUpO1xuICAgIH1cbiAgICBfZ2V0Q2FjaGUobmFtZSkge1xuICAgICAgICB2YXIga2V5ID0gdGhpcy5fZ2VuZXJhdGVDYWNoZUtleShuYW1lKTtcbiAgICAgICAgcmV0dXJuIGNhY2hlLmdldChrZXkpO1xuICAgIH1cbiAgICB1cGRhdGUoKSB7XG4gICAgICAgIGlmICghdGhpcy5jb21wb25lbnQpIHJldHVybjtcbiAgICAgICAgdmFyIHttb2RlOiBtb2RlLCB0b25lOiB0b25lfSA9IHRoaXMuY29tcG9uZW50O1xuICAgICAgICB0cnkge1xuICAgICAgICAgICAgdmFyIF90aGlzJF9nZXRDYWNoZSwgX3RoaXMkX2dldENhY2hlMjtcbiAgICAgICAgICAgIHZhciBzdHlsZVNvdXJjZSA9IChfdGhpcyRfZ2V0Q2FjaGUgPSB0aGlzLl9nZXRDYWNoZShcInN0eWxlU291cmNlXCIpKSA9PT0gbnVsbCB8fCBfdGhpcyRfZ2V0Q2FjaGUgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJF9nZXRDYWNoZS5wYXlsb2FkO1xuICAgICAgICAgICAgaWYgKCFzdHlsZVNvdXJjZSkge1xuICAgICAgICAgICAgICAgIHN0eWxlU291cmNlID0gZ2VuZXJhdGVDb21wb25lbnRTdHlsZVNvdXJjZSh7XG4gICAgICAgICAgICAgICAgICAgIGFsaWFzOiB0aGlzLmNvbXBvbmVudC5jb25zdHJ1Y3Rvci5hbGlhc1N0eWxlcyxcbiAgICAgICAgICAgICAgICAgICAgaW5saW5lU3R5bGU6IHRoaXMuY29tcG9uZW50Ll9jb21wb25lbnRMZXZlbFN0eWxlLFxuICAgICAgICAgICAgICAgICAgICBzdHlsZUNoYWluOiBnZXRTdHlsZUNoYWluTWVtb2l6ZWQodGhpcy5jb21wb25lbnQpLFxuICAgICAgICAgICAgICAgICAgICB0aGVtZTogdGhpcy5jb21wb25lbnQudGhlbWVcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB0aGlzLl9hZGRDYWNoZShcInN0eWxlU291cmNlXCIsIHN0eWxlU291cmNlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBzdHlsZSA9IChfdGhpcyRfZ2V0Q2FjaGUyID0gdGhpcy5fZ2V0Q2FjaGUoXCJzdHlsZV9cIi5jb25jYXQobW9kZSwgXCJfXCIpLmNvbmNhdCh0b25lKSkpID09PSBudWxsIHx8IF90aGlzJF9nZXRDYWNoZTIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJF9nZXRDYWNoZTIucGF5bG9hZDtcbiAgICAgICAgICAgIGlmICghc3R5bGUpIHtcbiAgICAgICAgICAgICAgICBzdHlsZSA9IGdlbmVyYXRlU3R5bGUodGhpcy5jb21wb25lbnQsIHN0eWxlU291cmNlKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9hZGRDYWNoZShcInN0eWxlX1wiLmNvbmNhdChtb2RlLCBcIl9cIikuY29uY2F0KHRvbmUpLCBzdHlsZSk7XG4gICAgICAgICAgIC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ICAgICAgICAgYWxsS2V5cy5mb3JFYWNoKChrZXkgPT4ge1xuICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgZmlyc3RPYmpba2V5XSA9PT0gXCJvYmplY3RcIiAmJiBmaXJzdE9ialtrZXldICE9PSBudWxsKSB7XG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdFtrZXldID0gbWVyZ2VPYmplY3RzV2l0aFNlY29uZERvbWluYW50KGZpcnN0T2JqW2tleV0sIHNlY29uZE9ialtrZXldIHx8IHt9KTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBzZWNvbmRPYmpba2V5XSA9PT0gXCJvYmplY3RcIiAmJiBzZWNvbmRPYmpba2V5XSAhPT0gbnVsbCkge1xuICAgICAgICAgICAgICAgICAgICByZXN1bHRba2V5XSA9IG1lcmdlT2JqZWN0c1dpdGhTZWNvbmREb21pbmFudChmaXJzdE9ialtrZXldIHx8IHt9LCBzZWNvbmRPYmpba2V5XSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0W2tleV0gPSBzZWNvbmRPYmouaGFzT3duUHJvcGVydHkoa2V5KSA/IHNlY29uZE9ialtrZXldIDogdW5kZWZpbmVkO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgICAgIH1cbiAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gZmlyc3RPYmo7XG4gICAgfVxufVxuXG5mdW5jdGlvbiB3aXRoVGhlbWVTdHlsZXMoQmFzZSkge1xuICAgIHZhciBtaXhpblN0eWxlID0gYXJndW1lbnRzLmxlbmd0aCA+IDEgJiYgYXJndW1lbnRzWzFdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMV0gOiB7fTtcbiAgICByZXR1cm4gY2xhc3MgZXh0ZW5kcyBCYXNlIHtcbiAgICAgICAgX2NvbnN0cnV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gIHVwZGF0ZU1hbmFnZXIuYWRkVXBkYXRlVGhlbWUodGhpcyk7XG4gICAgICAgIH1cbiAgICAgICAgc3RhdGljIGdldCBuYW1lKCkge1xuICAgICAgICAgICAgcmV0dXJuIEJhc2UubmFtZTtcbiAgICAgICAgfVxuICAgICAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgICAgIGlmICghc3VwZXIuX19jb21wb25lbnROYW1lKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiQSB2YWxpZCBzdGF0aWMgX19jb21wb25lbnROYW1lIHByb3BlcnR5IGlzIHJlcXVpcmVkIGZvciB0aGVtaW5nIHRvIHdvcmsgcHJvcGVybHkuIFBsZWFzZSBhZGQgdGhpcyB0byB0aGUgXCIuY29uY2F0KHRoaXMuY29uc3RydWN0b3IubmFtZSwgXCIgY2xhc3MuXCIpKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiBzdXBlci5fX2NvbXBvbmVudE5hbWU7XG4gICAgICAgIH1cbiAgICAgICAgc3RhdGljIGdldCBfX21peGluU3R5bGUoKSB7XG4gICAgICAgICAgICByZXR1cm4gbWl4aW5TdHlsZTtcbiAgICAgICAgfVxuICAgICAgICBnZXQgdGhlbWUoKSB7XG4gICAgICAgICAgICB2YXIgc3ViVGhlbWUgPSB0aGlzLl90YXJnZXRTdWJUaGVtZSAmJiBjb250ZXh0SW5zdGFuY2UuZ2V0U3ViVGhlbWUodGhpcy5fdGFyZ2V0U3ViVGhlbWUpO1xuICAgICAgICAgICAgcmV0dXJuIHN1YlRoZW1lIHx8IGNvbnRleHRJbnN0YW5jZS50aGVtZTtcbiAgICAgICAgfVxuICAgICAgICBzZXQgc3R5bGUodikge1xuICAgICAgICAgICAgaWYgKE9iamVjdC5wcm90b3R5cGUudG9TdHJpbmcuY2FsbCh2KSAhPT0gXCJbb2JqZWN0IE9iamVjdF1cIikge1xuICAgICAgICAgICAgICAgIGNvbnRleHRJbnN0YW5jZS5lcnJvcihcInN0eWxlIG11c3QgYmUgYW4gb2JqZWN0XCIpO1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX2NvbXBvbmVudExldmVsU3R5bGUgPSB2O1xuICAgICAgICAgICAgdGhpcy5fc3R5bGVNYW5hZ2VyLmNsZWFyU3R5bGVDYWNoZSgpO1xuICAgICAgICAgICAgdGhpcy5fc3R5bGVNYW5hZ2VyLnVwZGF0ZSgpO1xuICAgICAgICB9XG4gICAgICAgIGdldCBzdHlsZSgpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9zdHlsZTtcbiAgICAgICAgfVxuICAgICAgICBnZXQgX2NvbXBvbmVudFN0eWxlKCkge1xuICAgICAgICAgICAgY29udGV4dEluc3RhbmNlLmluZm8oXCJfY29tcG9uZW50U3R5bGUgd2lsbCBzb29uIGJlIGRlcHJlY2F0ZWQuIFBsZWFzZSB1c2UgQ29tcG9uZW50LnN0eWxlXCIpO1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3N0eWxlO1xuICAgICAgICB9XG4gICAgICAgIHNldCBzdHlsZUNvbmZpZyh2KSB7XG4gICAgICAgICAgICBjb250ZXh0SW5zdGFuY2UuaW5mbyhcInN0eWxlIGNvbmZpZyBpcyBkZXByZWNhdGVkLiBQbGVhc2UgdXNlIHN0eWxlID0geyBiYXNlOiB7fSwgdG9uZToge30sIG1vZGU6IHt9IH1cIik7XG4gICAgICAgICAgICB0aGlzLl9zdHlsZUNvbmZpZyA9IHY7XG4gICAgICAgICAgICB0aGlzLl9zdHlsZU1hbmFnZXIudXBkYXRlKCk7XG4gICAgICAgIH1cbiAgICAgICAgZ2V0IHN0eWxlQ29uZmlnKCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3N0eWxlQ29uZmlnO1xuICAgICAgICB9XG4gICAgICAgIGdldCBfY29tcG9uZW50Q29uZmlnKCkge1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HByb3RvdHlwZUNoYWluID0gbmV3IFNldDtcbiAgICAgICAgICAgIHZhciBwcm90byA9IHRoaXM7XG4gICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgcHJvdG8gPSBPYmplY3QuZ2V0UHJvdG90eXBlT2YocHJvdG8pO1xuICAgICAgICAgICAgICAgIGlmIChudWxsICE9PSBwcm90byAmJiB0eXBlb2YgcHJvdG8gPT09IFwib2JqZWN0XCIpIHtcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwcm90by5jb25zdHJ1Y3Rvci5fX2NvbXBvbmVudE5hbWUpIHByb3RvdHlwZUNoYWluLmFkZChwcm90by5jb25zdHJ1Y3Rvci5fX2NvbXBvbmVudE5hbWUpO1xuICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlcnJvcikge31cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IHdoaWxlIChwcm90byk7XG4gICAgICAgICAgICB0aGlzLl9fcHJvdG90eXBlQ2hhaW4gPSBwcm90b3R5cGVDaGFpbjtcbiAgICAgICAgICAgIHJldHVybiBwcm90b3R5cGVDaGFpbjtcbiAgICAgICAgfVxuICAgICAgICBnZXQgX2V4dGVuc2lvbnMoKSB7XG4gICAgICAgICAgICB2YXIgZXh0ZW5zaW9ucyA9IGNvbnRleHRJbnN0YW5jZSAmJiBjb250ZXh0SW5zdGFuY2UudGhlbWUgJiYgY29udGV4dEluc3RhbmNlLnRoZW1lLmV4dGVuc2lvbnM7XG4gICAgICAgICAgICBpZiAoIWV4dGVuc2lvbnMgfHwgIUFycmF5LmlzQXJyYXkoZXh0ZW5zaW9ucykgfHwgQXJyYXkuaXNBcnJheShleHRlbnNpb25zKSAmJiAhZXh0ZW5zaW9ucy5sZW5ndGgpIHJldHVybiBbXTtcbiAgICAgICAgICAgIHJldHVybiBleHRlbnNpb25zLmZpbHRlcigoX3JlZjExID0+IHtcbiAgICAgICAgICAgICAgICB2YXIge3RhcmdldENvbXBvbmVudDogdGFyZ2V0Q29tcG9uZW50LCBleHRlbnNpb246IGV4dGVuc2lvbn0gPSBfcmVmMTE7XG4gICAgICAgICAgICAgICAgcmV0dXJuICh0eXBlb2YgdGFyZ2V0Q29tcG9uZW50ID09PSBcInN0cmluZ1wiIHx8IEFycmF5LmlzQXJyYXkodGFyZ2V0Q29tcG9uZW50KSkgJiYgdHlwZW9mIGV4dGVuc2lvbiA9PT0gXCJmdW5jdGlvblwiO1xuICAgICAgICAgICAgfSkpLnNsaWNlKCkucmV2ZXJzZSgpIHx8IFtdO1xuICAgICAgICB9XG4gICAgICAgIGdldCBfY29tcG9uZW50RXh0ZW5zaW9ucygpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9leHRlbnNpb25zLmZpbHRlcigoX3JlZjEyID0+IHtcbiAgICAgICAgICAgICAgICB2YXIge3RhcmdldENvbXBvbmVudDogdGFyZ2V0Q29tcG9uZW50fSA9IF9yZWYxMjtcbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIHRhcmdldENvbXBvbmVudCA9PT0gXCJzdHJpbmdcIikge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGFyZ2V0Q29tcG9uZW50ID09PSB0aGlzLmNvbnN0cnVjdG9yLl9fY29tcG9uZW50TmFtZSB8fCB0aGlzLl9wcm90b3R5cGVDaGFpbi5oYXModGFyZ2V0Q29tcG9uZW50KTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKEFycmF5LmlzQXJyYXkodGFyZ2V0Q29tcG9uZW50KSkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGFyZ2V0Q29tcG9uZW50LmZpbmQoKHBhdHRlcm4gPT4ge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBhdHRlcm4uc3RhcnRzV2l0aChcIi9cIikgJiYgcGF0dGVybi5lbmRzV2l0aChcIi9cIikpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgQ29tcG9uZW50UmVnRXhwID0gbmV3IFJlZ0V4cChwYXR0ZXJuLnNsaWNlKDEsIC0xKSk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIEFycmF5LmZyb20odGhpcy5fcHJvdG90eXBlQ2hhaW4pLnNvbWUoKG5hbWUgPT4gQ29tcG9uZW50UmVnRXhwLnRlc3QobmFtZSkpKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3Byb3RvdHlwZUNoYWluLmhhcyhwYXR0ZXJuKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICB9KSkucmVkdWNlKCgoYWNjLCBfcmVmMTMpID0+IHtcbiAgICAgICAgICAgICAgICB2YXIge2V4dGVuc2lvbjogZXh0ZW5zaW9ufSA9IF9yZWYxMztcbiAgICAgICAgICAgICAgICBhY2MucHVzaChleHRlbnNpb24pO1xuICAgICAgICAgICAgICAgIHJldHVybiBhY2M7XG4gICAgICAgICAgICB9KSwgW10pO1xuICAgICAgICB9XG4gICAgICAgIGdldCBfZXh0ZW5zaW9uQXBwbGllZCgpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9jdXJyZW50Q29tcG9uZW50RXh0ZW5zaW9uTGVuZ3RoID09PSB0aGlzLl9hcHBsaWVkRXh0ZW5zaW9uTGVuZ3RoO1xuICAgICAgICB9XG4gICAgICAgIF9jb25zdHJ1Y3QoKSB7XG4gICAgICAgICAgICB0aGlzLl9hcHBsaWVkRXh0ZW5zaW9uTGVuZ3RoID0gMDtcbiAgICAgICAgICAgIHRoaXMuX2V4dGVuZGVkTGlzdCA9IHt9O1xuICAgICAgICAgICAgdGhpcy5fZXh0ZW5zaW9uSW5zdGFuY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Xh0ZW5kZWRMaXN0KSB8fCBbXSkuZm9yRWFjaCgocHJvcCA9PiB7XG4gICAgICAgICAgICAgICAgZGVsZXRlIHRoaXNbcHJvcF07XG4gICAgICAgICAgICAgICAgZGVsZXRlIHRoaXNbcHJvcCArIFNVRkZJWF07XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICB0aGlzLl9leHRlbnNpb25JbnN0YW5jZSA9IHt9O1xuICAgICAgICAgICAgdGhpcy5fZXh0ZW5kZWRMaXN0ID0ge307XG4gICAgICAgIH1cbiAgICAgICAgX2NhbGN1bGF0ZUNvbXBvbmVudEV4dGVuc2lvbkxlbmd0aCgpIHtcbiAgICAgICAgICAgIHZhciBleHRlbnNpb25MZW5ndGggPSB0aGlzLl9jb21wb25lbnRFeHRlbnNpb25zLnJlZHVjZSgoKGFjYywgZXh0ZW5zaW9uTWl4aW4pID0+IHtcbiAgICAgICAgICAgICAgICBhY2MgKz0gZXh0ZW5zaW9uTWl4aW4udG9TdHJpbmcoKS5sZW5ndGg7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgICAgIH0pLCAwKTtcbiAgICAgICAgICAgIHJldHVybiBleHRlbnNpb25MZW5ndGg7XG4gICAgICAgIH1cbiAgICAgICAgX2NyZWF0ZUV4dGVuc2lvbigpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9leHRlbnNpb25BcHBsaWVkKSByZXR1cm47XG4gICAgICAgICAgICB0aGlzLl9yZXNldENvbXBvbmVudCgpO1xuICAgICAgICAgICAgdmFyIEV4dGVuZGVkQ2xhc3MgPSB0aGlzLl9jcmVhdGVFeHRlbnNpb25DbGFzcygpO1xuICAgICAgICAgICAgdmFyIGluc3RhbmNlID0gbmV3IEV4dGVuZGVkQ2xhc3M7XG4gICAgICAgICAgICB0aGlzLl9leHRlbmRlZExpc3QgPSB0aGlzLl9jcmVhdGVFeHRlbnNpb25BbGlhc2VzKGluc3RhbmNlKTtcbiAgICAgICAgICAgIHRoa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V3IGV4dGVuc2lvbihjbGFzcyBGYWtlQ2xhc3Mge30pO1xuICAgICAgICAgICAgICAgIHZhciBpbnN0YW5jZSA9IG5ldyBleHRlbnNpb25DbGFzcztcbiAgICAgICAgICAgICAgICB2YXIgb3JpZ2luYWxDb21wb25lbnREZXNjcmlwdG9ycyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eURlc2NyaXB0b3JzKE9iamVjdC5nZXRQcm90b3R5cGVPZihpbnN0YW5jZSkpO1xuICAgICAgICAgICAgICAgIE9iamVjdC5rZXlzKG9yaWdpbmFsQ29tcG9uZW50RGVzY3JpcHRvcnMpLmZvckVhY2goKHByb3AgPT4ge1xuICAgICAgICAgICAgICAgICAgICBpZiAoWyBcImNvbnN0cnVjdG9yXCIgXS5pbmNsdWRlcyhwcm9wKSkgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICBpZiAob3JpZ2luYWxDb21wb25lbnREZXNjcmlwdG9yc1twcm9wXS5nZXQgfHwgb3JpZ2luYWxDb21wb25lbnREZXNjcmlwdG9yc1twcm9wXS5zZXQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGV4dGVuZGVkW3Byb3BdID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFwiYWNjZXNzb3JcIlxuICAgICAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGFjY1twcm9wXSA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBnZXQ6IGZ1bmN0aW9uIGdldCgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoaXNbcHJvcCArIFNVRkZJWF07XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZXQ6IGZ1bmN0aW9uIHNldCh2KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXNbcHJvcCArIFNVRkZJWF0gPSB2O1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZXh0ZW5kZWRbcHJvcF0gPSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBcIm1ldGhvZFwiXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgICAgIGFjY1twcm9wXSA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiB2YWx1ZSgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzW3Byb3AgKyBTVUZGSVhdICYmIHRoaXNbcHJvcCArIFNVRkZJWF0oKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgICAgIH0pLCB7fSk7XG4gICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydGllcyhiYXNlUHJvdG8sIGV4dGVuc2lvbk92ZXJyaWRlcyk7XG4gICAgICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYmFzZVByb3RvLCB0aGlzKTtcbiAgICAgICAgICAgIHJldHVybiBleHRlbmRlZDtcbiAgICAgICAgfVxuICAgICAgICBfc2V0Q29tcG9uZW50QWxpYXNlcyhhbGlhc09iaikge1xuICAgICAgICAgICAgT2JqZWN0LmtleXMoYWxpYXNPYmopLmZvckVhY2goKHByb3AgPT4ge1xuICAgICAgICAgICAgICAgIHRoaXNbcHJvcCArIFNVRkZJWF0gPSB0aGlzW3Byb3BdO1xuICAgICAgICAgICAgICAgIGlmIChhbGlhc09ialtwcm9wXS50eXBlID09PSBcIm1ldGhvZFwiKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXNbcHJvcF0gPSB0aGlzLl9leHRlbnNpb25JbnN0YW5jZVtwcm9wXTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGFsaWFzT2JqW3Byb3BdLnR5cGUgPT09IFwiYWNjZXNzb3JcIikge1xuICAgICAgICAgICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgcHJvcCwge1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICAgICAgZ2V0KCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLl9leHRlbnNpb25JbnN0YW5jZVtwcm9wXTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgICAgICBzZXQodikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2V4dGVuc2lvbkluc3RhbmNlW3Byb3BdID0gdjtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSkpO1xuICAgICAgICB9XG4gICAgfTtcbn1cblxuY2xhc3MgQmFzZSBleHRlbmRzIGxuZy5Db21wb25lbnQge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJCYXNlXCI7XG4gICAgfVxuICAgIF9jb25zdHJ1Y3QoKSB7XG4gICAgICAgIHRoaXMuY29uc3RydWN0b3IuX19jb21wb25lbnROYW1lO1xuICAgICAgICB0aGlzLnNraXBQbGlua28gPSBmYWxzZTtcbiAgICAgICAgdGhpcy5jZW50ZXJJblBhcmVudCA9IGZhbHNlO1xuICAgICAgICBpZiAoIXRoaXMubG9hZGVkKSB0aGlzLmxvYWRlZCA9IFByb21pc2UucmVzb2x2ZSgpO1xuICAgIH1cbiAgICBfaW5pdCgpIH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ltYWdlIGxvYWQgZXJyb3JcIik7XG4gICAgICAgIH1cbiAgICB9O1xuICAgIGltYWdlLm9ubG9hZCA9IGZ1bmN0aW9uKCkge1xuICAgICAgICBjYihudWxsLCB7XG4gICAgICAgICAgICBzb3VyY2U6IGltYWdlLFxuICAgICAgICAgICAgcmVuZGVySW5mbzoge1xuICAgICAgICAgICAgICAgIHNyYzogc3JjLFxuICAgICAgICAgICAgICAgIGNvbXByZXNzZWQ6IGZhbHNlXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgaGFzQWxwaGE6IHRydWVcbiAgICAgICAgfSk7XG4gICAgfTtcbiAgICBpbWFnZS5zcmMgPSBzcmM7XG4gICAgcmV0dXJuIGZ1bmN0aW9uKCkge1xuICAgICAgICBpbWFnZS5vbmVycm9yID0gbnVsbDtcbiAgICAgICAgaW1hZ2Uub25sb2FkID0gbnVsbDtcbiAgICAgICAgaW1hZ2UucmVtb3ZlQXR0cmlidXRlKFwic3JjXCIpO1xuICAgIH07XG59XG5cbmNsYXNzIEN1c3RvbUltYWdlVGV4dHVyZSBleHRlbmRzIGxuZy5UZXh0dXJlIHtcbiAgICBjb25zdHJ1Y3RvcihzdGFnZSkge1xuICAgICAgICBzdXBlcihzdGFnZSk7XG4gICAgICAgIHRoaXMuX3NyYyA9IHVuZGVmaW5lZDtcbiAgICAgICAgdGhpcy5faGFzQWxwaGEgPSBmYWxzZTtcbiAgICB9XG4gICAgZ2V0IHNyYygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3NyYztcbiAgICB9XG4gICAgc2V0IHNyYyh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9zcmMgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX3NyYyA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgZ2V0IGhhc0FscGhhKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faGFzQWxwaGE7XG4gICAgfVxuICAgIHNldCBoYXNBbHBoYSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNBbHBoYSAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5faGFzQWxwaGEgPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuICAgIGdldCB3KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdztcbiAgICB9XG4gICAgc2V0IHcobCkge1xuICAgICAgICB0aGlzLl93ID0gbDtcbiAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgIH1cbiAgICBnZXQgaCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2g7XG4gICAgfVxuICAgIHNldCBoKGwpIHtcbiAgICAgICAgdGhpcy5faCA9IGw7XG4gICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICB9XG4gICAgX2dldElzVmFsaWQoKSB7XG4gICAgICAgIHJldHVybiAhIXRoaXMuX3NyYztcbiAgICB9XG4gICAgX2dldExvb2t1cElkKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fc3JjO1xuICAgIH1cbiAgICBfZ2V0U291cmNlTG9hZGVyKCkge1xuICAgICAgICB2YXIgdyA9IHRoaXMuX3c7XG4gICAgICAgIHZhciBoID0gdGhpcy5faDtcbiAgICAgICAgdmFyIHNyYyA9IHRoaXMuX3NyYztcbiAgICAgICAgdmFyIGhhc0FscGhhID0gdGhpcy5faGFzQWxwaGE7XG4gICAgICAgIGlmICh0aGlzLnN0YWdlLmdldE9wdGlvbihcInNyY0Jhc2VQYXRoXCIpKSB7XG4gICAgICAgICAgICB2YXIgZmMgPSBzcmMuY2hhckNvZGVBdCgwKTtcbiAgICAgICAgICAgIGlmIChzcmMuaW5kZXhPZihcIi8vXCIpID09PSAtMSAmJiAoZmMgPj0gNjUgJiYgZmMgPD0gOTAgfHwgZmMgPj0gOTcgJiYgZmMgPD0gMTIyIHx8IGZjID09IDQ2KSkge1xuICAgICAgICAgICAgICAgIHNyYyA9IHRoaXMuc3RhZ2UuZ2V0T3B0aW9uKFwic3JjQmFzZVBhdGhcIikgKyBzcmM7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGNiID0+IHtcbiAgICAgICAgICAgIHZhciBmaWxlVHlwZSA9IGNoZWNrRmlsZVR5cGUoc3JjKTtcbiAgICAgICAgICAgIHN3aXRjaCAoZmlsZVR5cGUpIHtcbiAgICAgICAgICAgICAgY2FzZSBcIlNWR1wiOlxuICAgICAgICAgICAgICAgIHJldHVybiBjcmVhdGVTdmcoY2IsIHRoaXMuc3RhZ2UsIFwiZGF0YTppbWFnZS9zdmcreG1sLFwiLmNvbmNhdChlbmNvZGVVUklDb21wb25lbnQoc3JjKSksIHcsIGgpO1xuXG4gICAgICAgICAgICAgIGNhc2UgXCJCbG9iXCI6XG4gICAgICAgICAgICAgICAgcmV0dXJuIGltYWdlTG9hZGVyKHtcbiAgICAgICAgICAgICAgICAgICAgc3JjOiBzcmNcbiAgICAgICAgICAgICAgICB9LCBjYik7XG5cbiAgICAgICAgICAgICAgZGVmYXVsdDpcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5zdGFnZS5wbGF0Zm9ybS5sb2FkU3JjVGV4dHVyZSh7XG4gICAgICAgICAgICAgICAgICAgIHNyYzogc3JjLFxuICAgICAgICAgICAgICAgICAgICBoYXNBbHBoYTogaGFzQWxwaGFcbiAgICAgICAgICAgICAgICB9LCBjYik7XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIGdldE5vbkRlZmF1bHRzKCkge1xuICAgICAgICB2YXIgb2JqID0gc3VwZXIuZ2V0Tm9uRGVmYXVsdHMoKTtcbiAgICAgICAgaWYgKHRoaXMuX3NyYykge1xuICAgICAgICAgICAgb2JqLnNyYyA9IHRoaXMuX3NyYztcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gb2JqO1xuICAgIH1cbn1cblxuY2xhc3MgQXJ0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GlzLnNyY0NhbGxiYWNrICYmIHR5cGVvZiB0aGlzLnNyY0NhbGxiYWNrID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgIHNyYyA9IHRoaXMuc3JjQ2FsbGJhY2soe1xuICAgICAgICAgICAgICAgIGNsb3Nlc3RBc3BlY3RSYXRpbzogdGhpcy5fY2xvc2VzdFN1cHBvcnRlZEFzcGVjdFJhdGlvLFxuICAgICAgICAgICAgICAgIGFzcGVjdFJhdGlvOiB0aGlzLl9hY3R1YWxBc3BlY3RSYXRpbyxcbiAgICAgICAgICAgICAgICBzcmM6IHRoaXMuc3JjLFxuICAgICAgICAgICAgICAgIHc6IHRoaXMudyxcbiAgICAgICAgICAgICAgICBoOiB0aGlzLmhcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBzcmMgJiYgc3JjLnRoZW4gPyBzcmMgOiBQcm9taXNlLnJlc29sdmUoc3JjKTtcbiAgICB9XG4gICAgZ2V0IF9ncmFkaWVudFBhdGNoKCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgYWxwaGE6ICF0aGlzLl9HcmFkaWVudCAmJiB0aGlzLnNob3VsZFNtb290aCA/IC4wMDEgOiAxLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICBncmFkaWVudENvbG9yOiBnZXRWYWxpZENvbG9yKHRoaXMuc3R5bGUuZ3JhZGllbnRDb2xvcilcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBoOiB0aGlzLmggKyA0LFxuICAgICAgICAgICAgdHlwZTogR3JhZGllbnQsXG4gICAgICAgICAgICB3OiB0aGlzLncgKyA0LFxuICAgICAgICAgICAgeDogLTIsXG4gICAgICAgICAgICB5OiAtMixcbiAgICAgICAgICAgIHpJbmRleDogdGhpcy5jb3JlLmZpbmRaQ29udGV4dCgpLnpJbmRleCArIHRoaXMuc3R5bGUuekluZGV4U2V0LmdyYWRpZW50XG4gICAgICAg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gICBfdGhpczUuX3VwZGF0ZUdyYWRpZW50KCk7XG4gICAgICAgICAgICB5aWVsZCBfdGhpczUuX3VwZGF0ZUltYWdlKCk7XG4gICAgICAgICAgICBfdGhpczUuX3VwZGF0ZUZpbGxDb2xvcigpO1xuICAgICAgICAgICAgX3RoaXM1Ll91cGRhdGVGb3JlZ3JvdW5kSW1hZ2UoKTtcbiAgICAgICAgICAgIGlmICghX3RoaXM1LnNyYykge1xuICAgICAgICAgICAgICAgIF90aGlzNS5fc2hvd0NvbXBvbmVudCgpO1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgeWllbGQgX3RoaXM1Ll9jb21wb25lbnRTcmMuY29tcGxldGU7XG4gICAgICAgICAgICAgICAgeWllbGQgX3RoaXM1Ll91cGRhdGVDZW50ZXJJbWFnZSgpO1xuICAgICAgICAgICAgICAgIF90aGlzNS5fdXBkYXRlQmx1cigpO1xuICAgICAgICAgICAgICAgIF90aGlzNS5fc2hvd0NvbXBvbmVudCgpO1xuICAgICAgICAgICAgICAgIF90aGlzNS5fdXBkYXRlU2NhbGUoKTtcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgICAgICBfdGhpczUuX2hhbmRsZUltYWdlTG9hZEVycm9yKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoX3RoaXM1LnNob3VsZFNtb290aCA9PT0gdW5kZWZpbmVkKSBfdGhpczUuc2hvdWxkU21vb3RoID0gdHJ1ZTtcbiAgICAgICAgfSkpKCk7XG4gICAgfVxuICAgIF91cGRhdGVTY2FsZSgpIHtcbiAgICAgICAgaWYgKHRoaXMuc2hvdWxkU2NhbGUpIHtcbiAgICAgICAgICAgIHZhciBpbWFnZVNjYWxlO1xuICAgICAgICAgICAgc3dpdGNoICh0eXBlb2YgdGhpcy5zdHlsZS5pbWFnZVNjYWxlKSB7XG4gICAgICAgICAgICAgIGNhc2UgXCJmdW5jdGlvblwiOlxuICAgICAgICAgICAgICAgIGltYWdlU2NhbGUgPSB0aGlzLnN0eWxlLmltYWdlU2NhbGUodGhpcy53KTtcbiAgICAgICAgICAgICAgICBicmVhaztcblxuICAgICAgICAgICAgICBjYXNlIFwibnVtYmVyXCI6XG4gICAgICAgICAgICAgICAgaW1hZ2VTY2FsZSA9IHRoaXMuc3R5bGUuaW1hZ2VTY2FsZTtcbiAgICAgICAgICAgICAgICBicmVhaztcblxuICAgICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgIGltYWdlU2NhbGUgPSAxO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fSW1hZ2Uuc21vb3RoID0ge1xuICAgICAgICAgICAgICAgIHBpdm90WDogdGhpcy5zdHlsZS5pbWFnZVNjYWxlUGl2b3RYLFxuICAgICAgICAgICAgICAgIHBpdm90WTogdGhpcy5zdHlsZS5pbWFnZVNjYWxlUGl2b3RZLFxuICAgICAgICAgICAgICAgIHNjYWxlOiBbIGltYWdlU2NhbGUsIHRoaXMuX0ltYWdlLnNjYWxlIDwgaW1hZ2VTY2FsZSA/IHRoaXMuc3R5bGUuYW5pbWF0aW9uSW1hZ2VTY2FsZUVudHJhbmNlIDogdGhpcy5zdHlsZS5hbmltYXRpb25JbWFnZVNjYWxlRXhpdCBdXG4gICAgICAgICAgICB9O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdmFyIHNjYWxlID0gMTtcbiAgICAgICAgICAgIHRoaXMuX0ltYWdlLnNtb290aCA9IHtcbiAgICAgICAgICAgICAgICBzY2FsZTogWyBzY2FsZSwgdGhpcy5zdHlsZS5hbmltYXRpb25JbWFnZVNjYWxlRXhpdCBdXG4gICAgICAgICAgICB9O1xuICAgICAgICB9XG4gICAgfVxuICAgIF9oYW5kbGVJbWFnZUxvYWRFcnJvcigpIHtcbiAgICAgICAgaWYgKHRoaXMuc3JjID09PSB0aGlzLmZhbGxiYWNrU3JjKSByZXR1cm47XG4gICAgICAgIGNvbnRleHRJbnN0YW5jZS5lcnJvcihcIkltYWdlIFwiLmNvbmNhdCh0aGlzLl9zcmMsIFwiIGZhaWxlZCB0byBsb2FkXCIpKTtcbiAgICAgICAgaWYgKHRoaXMuZmFsbGJhY2tTcmMgJiYgdGhpcy5mYWxsYmFja1NyYyAhPT0gdGhpcy5zcmMpIHtcbiAgICAgICAgICAgIHRoaXMuc3JjID0gdGhpcy5mYWxsYmFja1NyYztcbiAgICAgICAgfVxuICAgIH1cbiAgICBfc2hvd0NvbXBvbmVudCgpIHtcbiAgICAgICAgdGhpcy5zbW9vdGggPSB7XG4gICAgICAgICAgICBhbHBoYTogWyAxLCB0aGlzLnN0eWxlLmFuaW1hdGlvbkNvbXBvbmVudEVudHJhbmNlIF1cbiAgICAgICAgfTtcbiAgICB9XG4gICAgX3VwZGF0ZUZvcmVncm91bmRJbWFnZSgpIHtcbiAgICAgICAgdmFyIF90aGlzNiA9IHRoaXM7XG4gICAgICAgIHJldHVybiBfYXN5bmNUb0dlbmVyYXRvcigoZnVuY3Rpb24qKCkge1xuICAgICAgICAgICAgaWYgKCFfdGhpczYuX2ZvcmVncm91bmRTcmMpIHtcbiAgICAgICAgICAgICAgICBpZiAoX3RoaXM2Ll9Gb3JlZ3JvdW5kSW1hZ2UpIHtcbiAgICAgICAgICAgICAgICAgICAgX3RoaXM2LnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgICAgIEZvcmVncm91bmRJbWFnZTogdW5kZWZpbmVkXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgZm9yZWdyb3VuZEltYWdlUGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgbW91bnQ6IC41LFxuICAgICAgICAgICAgICAgIHg6IF90aGlzNi53IC8gMixcbiAgICAgICAgICAgICAgICB5OiBfdGhpczYuaCAvIDIsXG4gICAgICAgICAgICAgICAgekluZGV4OiBfdGhpczYuY29yZS5maW5kWkNvbnRleHQoKS56SW5kZXggKyBfdGhpczYuc3R5bGUuekluZGV4U2V0LmZvcmVncm91bmQsXG4gICAgICAgICAgICAgICAgdGV4dHVyZToge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBDdXN0b21JbWFnZVRleHR1cmUsXG4gICAgICAgICAgICAgICAgICAgIHNyYzogX3RoaXM2Ll9mb3JlZ3JvdW5kU3JjLFxuICAgICAgICAgICAgICAgICAgICBoYXNBbHBoYTogdHJ1ZVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICBpZiAoX3RoaXM2LmZvcmVncm91bmRXaWR0aCAmJiBfdGhpczYuZm9yZWdyb3VuZEhlaWdodCkge1xuICAgICAgICAgICAgICAgIGZvcmVncm91bmRJbWFnZVBhdGNoLmggPSBfdGhpczYuZm9yZWdyb3VuZEhlaWdodDtcbiAgICAgICAgICAgICAgICBmb3JlZ3JvdW5kSW1hZ2VQYXRjaC53ID0gX3RoaXM2LmZvcmVncm91bmRXaWR0aDtcbiAgICAgICAgICAgICAgICBfdGhpczYucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICBGb3JlZ3JvdW5kSW1hZ2U6IGZvcmVncm91bmRJbWFnZVBhdGNoXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKF90aGlzNi5mb3JlZ3JvdW5kV2lkdGggfHwgX3RoaXM2LmZvcmVncm91bmRIZWlnaHQpIHtcbiAgICAgICAgICAgICAgICBfdGhpczYucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICBGb3JlZ3JvdW5kSW1hZ2U6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgZm9yZWdyb3VuZEltYWdlUGF0Y2gpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgYWxwaGE6IC4wMDFcbiAgICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICBfdGhpczYuX0ZvcmVncm91bmRJbWFnZS5vbmNlKFwidHhMb2FkZWRcIiwgKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIGltYWdlVyA9IF90aGlzNi5fRm9yZWdyb3VuZEltYWdlLnRleHR1cmUuZ2V0UmVuZGVyV2lkdGgoKTtcbiAgICAgICAgICAgICAgICAgICAgdmFyIGltYWdlSCA9IF90aGlzNi5fRm9yZWdyb3VuZEltYWdlLnRleHR1cmUuZ2V0UmVuZGVySGVpZ2h0KCk7XG4gICAgICAgICAgICAgICAgICAgIF90aGlzNi5fRm9yZWdyb3VuZEltYWdlLnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGFscGhhOiAxLFxuICAgICAgICAgICAgICAgICAgICAgICAgdzogX3RoaXM2LmZvcmVncm91bmRIZWlnaHQgPyBfdGhpczYuZm9yZWdyb3VuZEhlaWdodCAqIChpbWFnZVcgLyBpbWFnZUgpIDogX3RoaXM2LmZvcmVncm91bmRXaWR0aCxcbiAgICAgICAgICAgICAgICAgICAgICAgIGg6IF90aGlzNi5mb3JlZ3JvdW5kV2lkdGggPyBfdGhpczYuZm9yZWdyb3VuZFdpZHRoICogKGltYWdlSCAvIGltYWdlVykgOiBfdGhpczYuZm9yZWdyb3VuZEhlaWdodFxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBfdGhpczYucGF0Y2goe1xuICAgICAgICAgICAgICAgIEZvcmVncm91bmRJbWFnZTogZm9yZWdyb3VuZEltYWdlUGF0Y2hcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KSkoKTtcbiAgICB9XG4gICAgX3VwZGF0ZUJsdXIoKSB7XG4gICAgICAgIGlmICgoIXRoaXMuX3Nob3VsZEJsdXIgfHwgdGhpcy5fSW1hZ2UgJiYgdGhpcy5fSW1hZ2UudGV4dHVyZSAmJiB0aGlzLl9JbWFnZS50ZXh0dXJlLnNyYyA9PT0gdGhpcy5mYWxsYmFja1NyYykgJiYgdGhpcy5fQmx1cikge1xuICAgICAgICAgICAgaWYgKHRoaXMuc2hvdWxkU21vb3RoKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fQmx1ci5fZ2V0VHJhbnNpdGlvbihcImFscGhhXCIpLm9uY2UoXCJmaW5pc2hcIiwgKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgICAgICBCbHVyOiB1bmRlZmluZWRcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgICAgIHRoaXMuX0JsdXIuc21vb3RoID0ge1xuICAgICAgICAgICAgICAgICAgICBhbHBoYTogWyAwLCB0aGlzLnN0eWxlLmFuaW1hdGlvbkJsdXJFeGl0IF1cbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgQmx1cjogdW5kZWZpbmVkXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLl9zcmNGYWlsZWQgJiYgdGhpcy5fc2hvdWxkQmx1cikge1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgQmx1cjoge1xuICAgICAgICAgICAgICAgICAgICBhbHBoYTogIXRoaXMuX0JsdXIgJiYgdGhpcy5zaG91bGRTbW9vdGggPyAuMDAxIDogMSxcbiAgICAgICAgICAgICAgICAgICAgYW1vdW50OiB0aGlzLnN0eWxlLmJsdXIsXG4gICAgICAgICAgICAgICAgICAgIHpJbmRleDogdGhpcy5jb3JlLmZpbmRaQ29udGV4dCgpLnpJbmRleCArIHRoaXMuc3R5bGUuekluZGV4U2V0LmJsdXIsXG4gICAgICAgICAgICAgICAgICAgIGNvbnRlbnQ6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIEltYWdlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaDogdGhpcy5oLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRleHR1cmU6IHRoaXMuX0ltYWdlLmdldFRleHR1cmUoKSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLndcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgaDogdGhpcy5oLFxuICAgICAgICAgICAgICAgICAgICBydHQ6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IGxuZy5jb21wb25lbnRzLkZhc3RCbHVyQ29tcG9uZW50LFxuICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLndcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIGlmICh0aGlzLl9CbHVyLmFscGhhIDwgMSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX0JsdXIuc21vb3RoID0ge1xuICAgICAgICAgICAgICAgICAgICBhbHBoYTogWyAxLCB0aGlzLnN0eWxlLmFuaW1hdGlvbkJsdXJFbnRyYW5jZSBdXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlQ2VudGVySW1hZ2UoKSB7XG4gICAgICAgIGlmICh0aGlzLmZvcm1hdCA9PT0gXCJjb250YWluXCIpIHtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUZvcm1hdENvbnRhaW4oKTtcbiAgICAgICAgfSBlbHNlIGlmICh0aGlzLmZvcm1hdCA9PT0gXCJjaXJjbGVcIiB8fCB0aGlzLmZvcm1hdCA9PT0gXCJzcXVhcmVcIikge1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlRm9ybWF0U3F1YXJlQ2lyY2xlKCk7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5fQ2VudGVySW1hZ2UpIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIENlbnRlckltYWdlOiB1bmRlZmluZWRcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVGb3JtYXRDb250YWluKCkge1xuICAgICAgICB2YXIgX3RoaXM3ID0gdGhpcztcbiAgICAgICAgcmV0dXJuIF9hc3luY1RvR2VuZXJhdG9yKChmdW5jdGlvbiooKSB7XG4gICAgICAgICAgICBpZiAoX3RoaXM3Ll9DZW50ZXJJbWFnZSAmJiBfdGhpczcuX0NlbnRlckltYWdlLm1vZGUgIT09IF90aGlzNy5mb3JtYXQgfHwgX3RoaXM3LnNyYyA9PT0gX3RoaXM3LmZhbGxiYWNrU3JjIHx8IF90aGlzNy5fYXNwZWN0UmF0aW9FcXVhbCkge1xuICAgICAgICAgICAgICAgIF90aGlzNy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIENlbnRlckltYWdlOiB1bmRlZmluZWRcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICBpZiAoX3RoaXM3LnNyYyA9PT0gX3RoaXM3LmZhbGxiYWNrU3JjIHx8IF90aGlzNy5fYXNwZWN0UmF0aW9FcXVhbCkge1xuICAgICAgICAgICAgICAgICAgICBfdGhpczcuX0ltYWdlLmFscGhhID0gMTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBpbWFnZVc7XG4gICAgICAgICAgICB2YXIgaW1hZ2VIO1xuICAgICAgICAgICAgdmFyIHJhdGlvVyA9IE1hdGguYWJzKF90aGlzNy5fSW1hZ2UudGV4dHVyZS5zb3VyY2UudyAvIF90aGlzNy5fSW1hZ2UudGV4dHVyZS5zb3VyY2UuaCk7XG4gICAgICAgICAgICB2YXIgcmF0aW9IID0gTWF0aC5hYnMoX3RoaXM3Ll9JbWFnZS50ZXh0dXJlLnNvdXJjZS5oIC8gX3RoaXM3Ll9JbWFnZS50ZXh0dXJlLnNvdXJjZS53KTtcbiAgICAgICAgICAgIGlmIChfdGhpczcuX0ltYWdlLnRleHR1cmUuc291cmNlLncgPCBfdGhpczcuX0ltYWdlLnRleHR1cmUuc291cmNlLmgpIHtcbiAgICAgICAgICAgICAgICBpZiAoX3RoaXM3LmggKiByYXRpb1cgPCBfdGhpczcudykge1xuICAgICAgICAgICAgICAgICAgICBpbWFnZVcgPSBfdGhpczcuaCAqIHJhdGlvVztcbiAgICAgICAgICAgICAgICAgICAgaW1hZ2VIID0gX3RoaXM3Lmg7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgaW1hZ2VXID0gX3RoaXM3Lnc7XG4gICAgICAgICAgICAgICAgICAgIGltYWdlSCA9IF90aGlzNy53ICogcmF0aW9IO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAoX3RoaXM3Ll9JbWFnZS50ZXh0dXJlLnNvdXJjZS53ID4gX3RoaXM3Ll9JbWFnZS50ZXh0dXJlLnNvdXJjZS5oKSB7XG4gICAgICAgICAgICAgICAgaWYgKF90aGlzNy53ICogcmF0aW9IIDwgX3RoaXM3LmgpIHtcbiAgICAgICAgICAgICAgICAgICAgaW1hZ2VXID0gX3RoaXM3Lnc7XG4gICAgICAgICAgICAgICAgICAgIGltYWdlSCA9IF90aGlzNy53ICogcmF0aW9IO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGltYWdlVyA9IF90aGlzNy5oICogcmF0aW9XO1xuICAgICAgICAgICAgICAgICAgICBpbWFnZUggPSBfdGhpczcuaDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGltYWdlVyA9IE1hdGgubWluKF90aGlzNy53LCBfdGhpczcuaCk7XG4gICAgICAgICAgICAgICAgaW1hZ2VIID0gaW1hZ2VXO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdmFyIHNyYyA9IHlpZWxkIF90aGlzNy5fcHJvY2Vzc2VkSW1hZ2VTcmM7XG4gICAgICAgICAgICBfdGhpczcucGF0Y2goe1xuICAgICAgICAgICAgICAgIENlbnRlckltYWdlOiB7XG4gICAgICAgICAgICAgICAgICAgIGZvcm1hdDogX3RoaXM3LmZvcm1hdCxcbiAgICAgICAgICAgICAgICAgICAgbW91bnQ6IC41LFxuICAgICAgICAgICAgICAgICAgICB3OiBpbWFnZVcsXG4gICAgICAgICAgICAgICAgICAgIGg6IGltYWdlSCxcbiAgICAgICAgICAgICAgICAgICAgeDogX3RoaXM3LncgLyAyLFxuICAgICAgICAgICAgICAgICAgICB5OiBfdGhpczcuaCAvIDIsXG4gICAgICAgICAgICAgICAgICAgIHpJbmRleDogX3RoaXM3LmNvcmUuZmluZFpDb250ZXh0KCkuekluZGV4ICsgX3RoaXM3LnN0eWxlLnpJbmRleFNldC5jZW50ZXJJbWFnZSxcbiAgICAgICAgICAgICAgICAgICAgdGV4dHVyZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3JjOiBzcmMsXG4gICAgICAgICAgICAgICAgICAgICAgICByZXNpemVNb2RlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaDogaW1hZ2VILFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFwiY292ZXJcIixcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB3OiBpbWFnZVdcbiAgICAgICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBDdXN0b21JbWFnZVRleHR1cmVcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KSkoKTtcbiAgICB9XG4gICAgX3VwZGF0ZUZvcm1hdFNxdWFyZUNpcmNsZSgpIHtcbiAgICAgICAgaWYgKHRoaXMuX0NlbnRlckltYWdlICYmIHRoaXMuX0NlbnRlckltYWdlLm1vZGUgIT09IHRoaXMuZm9ybWF0IHx8IHRoaXMuc3JjID09PSB0aGlzLmZhbGxiYWNrU3JjKSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBDZW50ZXJJbWFnZTogdW5kZWZpbmVkXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIGlmICh0aGlzLnNyYyA9PT0gdGhpcy5mYWxsYmFja1NyYykgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHZhciBpbWFnZVNpemUgPSBNYXRoLm1pbih0aGlzLncsIHRoaXMuaCkgLSB0aGlzLnN0eWxlLnBhZGRpbmcgKiAyO1xuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIENlbnRlckltYWdlOiB7XG4gICAgICAgICAgICAgICAgZm9ybWF0OiB0aGlzLmZvcm1hdCxcbiAgICAgICAgICAgICAgICBoOiBpbWFnZVNpemUsXG4gICAgICAgICAgICAgICAgc2hhZGVyOiB7XG4gICAgICAgICAgICAgICAgICAgIHJhZGl1czogXCJjaXJjbGVcIiA9PT0gdGhpcy5mb3JtYXQgPyBpbWFnZVNpemUgLyAyIDogdGhpcy5zdHlsZS5jZW50ZXJJbWFnZVJhZGl1cyxcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogbG5nLnNoYWRlcnMuUm91bmRlZFJlY3RhbmdsZVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgdzogaW1hZ2VTaXplLFxuICAgICAgICAgICAgICAgIHpJbmRleDogdGhpcy5jb3JlLmZpbmRaQ29udGV4dCgpLnpJbmRleCArIHRoaXMuc3R5bGUuekluZGV4U2V0LmNlbnRlckltYWdlLFxuICAgICAgICAgICAgICAgIEltYWdlOiB7XG4gICAgICAgICAgICAgICAgICAgIGg6IGltYWdlU2l6ZSxcbiAgICAgICAgICAgICAgICAgICAgbW91bnQ6IC41LFxuICAgICAgICAgICAgICAgICAgICBydHQ6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHc6IGltYWdlU2l6ZSxcbiAgICAgICAgICAgICAgICAgICAgeDogdGhpcy53IC8gMixcbiAgICAgICAgICAgICAgICAgICAgeTogdGhpcy5oIC8gMixcbiAgICAgICAgICAgICAgICAgICAgdGV4dHVyZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3JjOiB0aGlzLl9JbWFnZS50ZXh0dXJlLnNyYyxcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc2l6ZU1vZGU6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBoOiBpbWFnZVNpemUsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogXCJjb3ZlclwiLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHc6IGltYWdlU2l6ZVxuICAgICAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IEN1c3RvbUltYWdlVGV4dHVyZVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZUdyYWRpZW50KCkge1xuICAgICAgICBpZiAoIXRoaXMuZ3JhZGllbnQpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9HcmFkaWVudCkge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLnNob3VsZFNtb290aCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9HcmFkaWVudC5fZ2V0VHJhbnNpdGlvbihcImFscGhhXCIpLm9uY2UoXCJmaW5pc2hcIiwgKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciB0cmFuc2l0aW9uID0gdGhpcy5fR3JhZGllbnQgJiYgdGhpcy5fR3JhZGllbnQuX2dldFRyYW5zaXRpb24oXCJhbHBoYVwiKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghdGhpcy5ncmFkaWVudCAmJiB0cmFuc2l0aW9uICYmIHRyYW5zaXRpb24ucCA9PT0gMSkgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgR3JhZGllbnQ6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fR3JhZGllbnQucGF0Y2godGhpcy5fZ3JhZGllbnRQYXRjaCk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX0dyYWRpZW50LnNtb290aCA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGFscGhhOiBbIDAsIHRoaXMuc3R5bGUuYW5pbWF0aW9uR3JhZGllbnRFeGl0IF1cbiAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgICAgIEdyYWRpZW50OiB1bmRlZmluZWRcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX2NyZWF0ZUdyYWRpZW50KCk7XG4gICAgfVxuICAgIF9jcmVhdGVHcmFkaWVudCgpIHtcbiAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICBHcmFkaWVudDogdGhpcy5fZ3JhZGllbnRQYXRjaFxuICAgICAgICB9KTtcbiAgICAgICAgaWYgKHRoaXMuc2hvdWxkU21vb3RoKSB7XG4gICAgICAgICAgICB0aGlzLmFwcGx5U21vb3RoKHRoaXMuX0dyYWRpZW50LCB7XG4gICAgICAgICAgICAgICAgYWxwaGE6IFsgMSwgdGhpcy5zdHlsZS5hbmltYXRpb25HcmFkaWVudEVudHJhbmNlIF1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVJbWFnZSgpIHtcbiAgICAgICAgdmFyIF90aGlzOCA9IHRoaXM7XG4gICAgICAgIHJldHVybiBfYXN5bmNUb0dlbmVyYXRvcigoZnVuY3Rpb24qKCkge1xuICAgICAgICAgICAgX3RoaXM4Ll9hc3BlY3RSYXRpb0VxdWFsID0gZmFsc2U7XG4gICAgICAgICAgICBpZiAoIV90aGlzOC5fcHJvY2Vzc2VkSW1hZ2VTcmMpIHtcbiAgICAgICAgICAgICAgICBpZiAoX3RoaXM4Ll9JbWFnZSkge1xuICAgICAgICAgICAgICAgICAgICBfdGhpczguX0ltYWdlLnRleHR1cmUgPSB1bmRlZmluZWQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBzcmMgPSB5aWVsZCBfdGhpczguX3Byb2Nlc3NlZEltYWdlU3JjO1xuICAgICAgICAgICAgX3RoaXM4Ll9JbWFnZS5wYXRjaCh7XG4gICAgICAgICAgICAgICAgYWxwaGE6IF90aGlzOC5zcmMgIT09IF90aGlzOC5mYWxsYmFja1NyYyAmJiAoX3RoaXM4Ll9ibHVyIHx8IF90aGlzOC5faGFzQ2VudGVySW1hZ2UpID8gLjAwMSA6IDEsXG4gICAgICAgICAgICAgICAgaDogX3RoaXM4LmgsXG4gICAgICAgICAgICAgICAgdGV4dHVyZToge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBDdXN0b21JbWFnZVRleHR1cmUsXG4gICAgICAgICAgICAgICAgICAgIHNyYzogc3JjLFxuICAgICAgICAgICAgICAgICAgICByZXNpemVNb2RlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBcImNvdmVyXCIsXG4gICAgICAgICAgICAgICAgICAgICAgICB3OiBfdGhpczgudyxcbiAgICAgICAgICAgICAgICAgICAgICAgIGg6IF90aGlzOC5oXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIHc6IF90aGlzOC53LFxuICAgICAgICAgICAgICAgIHpJbmRleDogX3RoaXM4LmNvcmUuZmluZFpDb250ZXh0KCkuekluZGV4ICsgX3RoaXM4LnN0eWxlLnpJbmRleFNldC5pbWFnZVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pKSgpO1xuICAgIH1cbiAgICBfdXBkYXRlRmlsbENvbG9yKCkge1xuICAgICAgICBpZiAoIXRoaXMuZmlsbCkge1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgRmlsbENvbG9yOiB1bmRlZmluZWRcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgRmlsbENvbG9yOiB7XG4gICAgICAgICAgICAgICAgICAgIHJlY3Q6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHc6IHRoaXMudyxcbiAgICAgICAgICAgICAgICAgICAgaDogdGhpcy5oLFxuICAgICAgICAgICAgICAgICAgICBjb2xvcjogdGhpcy5zdHlsZS5maWxsQ29sb3IsXG4gICAgICAgICAgICAgICAgICAgIHpJbmRleDogNVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVSYWRpdXMoKSB7XG4gICAgICAgIHRoaXMucGF0Y2godGhpcy5zdHlsZS5yYWRpdXMgPyB7XG4gICAgICAgICAgICBzaGFkZXI6IHtcbiAgICAgICAgICAgICAgICB0eXBlOiBsbmcuc2hhZGVycy5Sb3VuZGVkUmVjdGFuZ2xlLFxuICAgICAgICAgICAgICAgIHJhZGl1czogZ2V0TWF4Um91bmRSYWRpdXModGhpcy5zdHlsZS5yYWRpdXMsIHRoaXMudywgdGhpcy5oKVxuICAgICAgICAgICAgfVxuICAgICAgICB9IDoge1xuICAgICAgICAgICAgc2hhZGVyOiB1bmRlZmluZWRcbiAgICAgICAgfSk7XG4gICAgfVxufVxuXG52YXIgdG9uZSRvID0gdGhlbWUgPT4gKHtcbiAgICBuZXV0cmFsOiB7XG4gICAgICAgIGNvbG9yOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbFxuICAgIH0sXG4gICAgaW52ZXJzZToge1xuICAgICAgICBjb2xvcjogdGhlbWUuY29sb3IuZmlsbEludmVyc2VcbiAgICB9LFxuICAgIGJyYW5kOiB7XG4gICAgICAgIGNvbG9yOiB0aGVtZS5jb2xvci5maWxsQnJhbmRcbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyRRID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIHRvbmU6IHRvbmUkb1xufSk7XG5cbmNsYXNzIEljb24gZXh0ZW5kcyBCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJJY29uXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJFE7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJpY29uXCIsIFwiZml4ZWRcIiwgXCJjb2xvclwiIF07XG4gICAgfVxuICAgIF9pbml0KCkge1xuICAgICAgICB0aGlzLm9uKFwidHhMb2FkZWRcIiwgKCgpID0+IHtcbiAgICAgICAgICAgIGlmICghdGhpcy5maXhlZCkge1xuICAgICAgICAg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cbiAgICAgICAgcmV0dXJuIF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgdGV4dHVyZTogdGV4dHVyZSxcbiAgICAgICAgICAgIHNoYWRlcjogc2hhZGVyXG4gICAgICAgIH0sIGNvbG9yID8ge1xuICAgICAgICAgICAgY29sb3JVbDogY29sb3IsXG4gICAgICAgICAgICBjb2xvclVyOiBjb2xvcixcbiAgICAgICAgICAgIGNvbG9yQmw6IGNvbG9yLFxuICAgICAgICAgICAgY29sb3JCcjogY29sb3JcbiAgICAgICAgfSA6IHt9KTtcbiAgICB9XG59XG5cbnZhciBiYXNlJFAgPSB0aGVtZSA9PiAoe1xuICAgIGNvbnRlbnRTcGFjaW5nOiB0aGVtZS5zcGFjZXIueHMsXG4gICAgb2Zmc2V0WTogMSxcbiAgICBwYWRkaW5nWDogdGhlbWUuc3BhY2VyLm1kLFxuICAgIHBhZGRpbmdZOiB0aGVtZS5zcGFjZXIueHMsXG4gICAgcmFkaXVzOiB0aGVtZS5yYWRpdXMuc20sXG4gICAgc3Ryb2tlV2lkdGg6IHRoZW1lLnN0cm9rZS5zbSxcbiAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhlbWUudHlwb2dyYXBoeS50YWcxKSwge30sIHtcbiAgICAgICAgdGV4dEFsaWduOiBcImNlbnRlclwiXG4gICAgfSlcbn0pO1xuXG52YXIgdG9uZSRuID0gdGhlbWUgPT4gKHtcbiAgICBuZXV0cmFsOiB7XG4gICAgICAgIGJhY2tncm91bmRDb2xvcjogdGhlbWUuY29sb3IuZmlsbEludmVyc2VTZWNvbmRhcnksXG4gICAgICAgIGljb25Db2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWwsXG4gICAgICAgIHRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICB9LFxuICAgICAgICBzdHJva2VDb2xvcjogdG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gICAgICAgIHR5cGU6IEljb24sXG4gICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIGl0ZW1DaGFuZ2VkOiBcIl91cGRhdGVMYXlvdXRcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIHJldHVybiBcIkJhZGdlXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJFA7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJ0aXRsZVwiLCBcImljb25cIiwgXCJpY29uQWxpZ25cIiwgXCJpY29uV2lkdGhcIiwgXCJpY29uSGVpZ2h0XCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCB0YWdzKCkge1xuICAgICAgICByZXR1cm4gWyBcIkJhY2tncm91bmRcIiwgXCJUZXh0XCIsIFwiSWNvblwiIF07XG4gICAgfVxuICAgIF9pbml0KCkge1xuICAgICAgICB0aGlzLl9UZXh0Lm9uKFwidHhMb2FkZWRcIiwgdGhpcy5fdXBkYXRlTGF5b3V0LmJpbmQodGhpcykpO1xuICAgICAgICBzdXBlci5faW5pdCgpO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVUZXh0KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUljb24oKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlTGF5b3V0KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVZpc2liaWxpdHkoKTtcbiAgICB9XG4gICAgX3VwZGF0ZVZpc2liaWxpdHkoKSB7XG4gICAgICAgIHRoaXMuYWxwaGEgPSB0aGlz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xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZUljb24oKSB7XG4gICAgICAgIHRoaXMuX0ljb24ucGF0Y2goe1xuICAgICAgICAgICAgaWNvbjogdGhpcy5pY29uLFxuICAgICAgICAgICAgdzogdGhpcy5pY29uV2lkdGgsXG4gICAgICAgICAgICBoOiB0aGlzLmljb25IZWlnaHQsXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIGNvbG9yOiBnZXRIZXhDb2xvcih0aGlzLnN0eWxlLmljb25Db2xvcilcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVXaWR0aCgpIHtcbiAgICAgICAgdmFyIHdpZHRoID0gMDtcbiAgICAgICAgaWYgKHRoaXMudGl0bGUgJiYgdGhpcy5pY29uKSB7XG4gICAgICAgICAgICB3aWR0aCA9IHRoaXMuX1RleHQucmVuZGVyV2lkdGggKyB0aGlzLl9JY29uLmZpbmFsVyArIHRoaXMuc3R5bGUuY29udGVudFNwYWNpbmcgKyB0aGlzLnN0eWxlLnBhZGRpbmdYICogMjtcbiAgICAgICAgfSBlbHNlIGlmICh0aGlzLnRpdGxlKSB7XG4gICAgICAgICAgICB3aWR0aCA9IHRoaXMuX1RleHQucmVuZGVyV2lkdGggKyB0aGlzLnN0eWxlLnBhZGRpbmdYICogMjtcbiAgICAgICAgfSBlbHNlIGlmICh0aGlzLmljb24pIHtcbiAgICAgICAgICAgIHdpZHRoID0gdGhpcy5fSWNvbi5maW5hbFcgKyB0aGlzLnN0eWxlLnBhZGRpbmdYICogMjtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLncgPSB3aWR0aDtcbiAgICB9XG4gICAgX3VwZGF0ZVBvc2l0aW9ucygpIHtcbiAgICAgICAgdGhpcy5fSWNvbi55ID0gdGhpcy5oIC8gMjtcbiAgICAgICAgaWYgKHRoaXMuaWNvbkFsaWduID09PSBcImxlZnRcIiAmJiB0a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HtcbiAgICAgICAgICAgICAgICBhY2MucHVzaChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGl0ZW0pLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBvcmlnaW5hbElkeDogaWR4XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgfSksIFtdKS5zaGlmdCgpO1xuICAgICAgICByZXR1cm4gZmlyc3RJdGVtLm9yaWdpbmFsSWR4O1xuICAgIH1cbiAgICBfbGFzdEZvY3VzYWJsZUluZGV4KCkge1xuICAgICAgICBpZiAoIXRoaXMuaXRlbXMubGVuZ3RoKSByZXR1cm4gMDtcbiAgICAgICAgdmFyIGxhc3RJdGVtID0gdGhpcy5pdGVtcy5yZWR1Y2UoKChhY2MsIGl0ZW0sIGlkeCkgPT4ge1xuICAgICAgICAgICAgaWYgKCFpdGVtLnNraXBGb2N1cykge1xuICAgICAgICAgICAgICAgIGFjYy5wdXNoKF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgaXRlbSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIG9yaWdpbmFsSWR4OiBpZHhcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gYWNjO1xuICAgICAgICB9KSwgW10pLnBvcCgpO1xuICAgICAgICByZXR1cm4gbGFzdEl0ZW0ub3JpZ2luYWxJZHg7XG4gICAgfVxuICAgIHNlbGVjdFByZXZpb3VzKCkge1xuICAgICAgICB0aGlzLnNob3VsZFNtb290aCA9IHRydWU7XG4gICAgICAgIHZhciBoYXNGb2N1c2FibGUgPSAhISh0aGlzLml0ZW1zIHx8IFtdKS5maWx0ZXIoKGkgPT4gIWkuc2tpcEZvY3VzKSkubGVuZ3RoO1xuICAgICAgICBpZiAodGhpcy5zZWxlY3RlZEluZGV4ID09PSAwICYmICF0aGlzLndyYXBTZW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gICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9sYXN0U2Nyb2xsSW5kZXggPSBsYXN0U2Nyb2xsSW5kZXg7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX2xhc3RTY3JvbGxJbmRleCA+IHRoaXMuaXRlbXMubGVuZ3RoKSB7XG4gICAgICAgICAgICB0aGlzLl9sYXN0U2Nyb2xsSW5kZXggPSB0aGlzLml0ZW1zLmxlbmd0aCAtIDE7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX2NhbGNDcm9zc0RpbWVuc2lvblNpemUoY29tcCkge1xuICAgICAgICBpZiAodGhpcy5faXNSb3cpIHtcbiAgICAgICAgICAgIHJldHVybiBnZXRIKGNvbXApO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9pc0NvbHVtbikge1xuICAgICAgICAgICAgcmV0dXJuIGdldFcoY29tcCk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX2NhbGNBeGlzUG9zaXRpb24oY29tcCkge1xuICAgICAgICBpZiAodGhpcy5faXNSb3cpIHtcbiAgICAgICAgICAgIHJldHVybiBnZXRYKGNvbXApO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9pc0NvbHVtbikge1xuICAgICAgICAgICAgcmV0dXJuIGdldFkoY29tcCk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3RyYW5zaXRpb25MaXN0ZW5lcigpIHtcbiAgICAgICAgdGhpcy5zaG91bGRTbW9vdGggPSBmYWxzZTtcbiAgICAgICAgdGhpcy50cmFuc2l0aW9uRG9uZSgpO1xuICAgIH1cbiAgICBfd2l0aEFmdGVyVXBkYXRlKGVsZW1lbnQpIHtcbiAgICAgICAgcmV0dXJuIHdhdGNoRm9yVXBkYXRlcyh7XG4gICAgICAgICAgICBlbGVtZW50OiBlbGVtZW50LFxuICAgICAgICA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iAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRKO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IGFsaWFzU3R5bGVzKCkge1xuICAgICAgICByZXR1cm4gWyB7XG4gICAgICAgICAgICBwcmV2OiBcImljb25IXCIsXG4gICAgICAgICAgICBjdXJyOiBcImljb25IZWlnaHRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBwcmV2OiBcImljb25XXCIsXG4gICAgICAgICAgICBjdXJyOiBcImljb25XaWR0aFwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgX2NvbnN0cnVjdCgpIHtcbiAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCgpO1xuICAgICAgICB0aGlzLl9tYXhMaW5lc1N1ZmZpeCA9IFwiLi5cIjtcbiAgICB9XG4gICAgX3VwZGF0ZSgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlQ29udGVudCgpO1xuICAgICAgICB0aGlzLl93YWl0Rm9yQ29tcG9uZW50TG9hZCgpO1xuICAgIH1cbiAgICBfdXBkYXRlQ29udGVudCgpIHtcbiAgICAgICAgdGhpcy5jaGlsZExpc3QuY2xlYXIoKTtcbiAgICAgICAgaWYgKHRoaXMuX3Nob3VsZFRydW5jYXRlKSB7XG4gICAgICAgICAgICB0aGlzLmFscGhhID0gLjAwMTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fcGFyc2VkQ29udGVudCAmJiB0aGlzLl9wYXJzZWRDb250ZW50Lmxlbmd0aCkge1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgZmxleDoge1xuICAgICAgICAgICAgICAgICAgICBkaXJlY3Rpb246IFwicm93XCIsXG4gICAgICAgICAgICAgICAgICAgIHdyYXA6ICEhdGhpcy5jb250ZW50V3JhcCxcbiAgICAgICAgICAgICAgICAgICAganVzdGlmeUNvbnRlbnQ6IHRoaXMuanVzdGlmeSAhPSB1bmRlZmluZWQgPyB0aGlzLmp1c3RpZnkgOiB0aGlzLnN0eWxlLmp1c3RpZnlcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHRoaXMuX3BhcnNlZENvbnRlbnQuZm9yRWFjaCgoKGl0ZW0sIGluZGV4KSA9PiB7XG4gICAgICAgICAgICAgICAgdmFyIGlzTGFzdCA9IGluZGV4ID09PSB0aGlzLl9wYXJzZWRDb250ZW50Lmxlbmd0aCAtIDE7XG4gICAgICAgICAgICAgICAgdmFyIGJhc2UgPSB7XG4gICAgICAgICAgICAgICAgICAgIGZsZXhJdGVtOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuY29udGVudFByb3BlcnRpZXMpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgbWFyZ2luQm90dG9tOiBpc0xhc3QgPyAwIDogdGhpcy5fbWFyZ2luQm90dG9tLFxuICAgICAgICAgICAgICAgICAgICAgICAgbWFyZ2luUmlnaHQ6IGlzTGFzdCA/IDAgOiB0aGlzLmNvbnRlbnRQcm9wZXJ0aWVzLm1hcmdpblJpZ2h0IHx8IHRoaXMuc3R5bGUuY29udGVudFNwYWNpbmdcbiAgICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgIGlmIChpc1RleHQoaXRlbSkpIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIG5leHRJdGVtID0gdGhpcy5fcGFyc2VkQ29udGVudFtpbmRleCArIDFdO1xuICAgICAgICAgICAgICAgICAgICBpZiAobmV4dEl0ZW0gJiYgaXNUZXh0KG5leHRJdGVtKSB8fCB0aGlzLmNvbnRlbnRXcmFwICYmIG5leHRJdGVtICYmIG5leHRJdGVtLm5ld2xpbmUgJiYgdGhpcy5fcGFyc2VkQ29udGVudFtpbmRleCArIDJdICYmIGlzVGV4dCh0aGlzLl9wYXJzZWRDb250ZW50W2luZGV4ICsgMl0pKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBiYXNlLmZsZXhJdGVtLm1hcmdpblJpZ2h0ID0gMDtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB0aGlzLmNoaWxkTGlzdC5hKHRoaXMuX2NyZWF0ZVRleHQoYmFzZSwgaXRlbSkpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoaXNJY29uKGl0ZW0pKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmEodGhpcy5fY3JlYXRlSWNvbihiYXNlLCBpdGVtKSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChpc0JhZGdlKGl0ZW0pKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmEodGhpcy5fY3JlYXRlQmFkZ2UoYmFzZSwgaXRlbS5iYWRnZSkpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoaXRlbS5uZXdsaW5lICYmIHRoaXMuY29udGVudFdyYXApIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QuYSh7XG4gICAgICAgICAgICAgICAgICAgICAgICBoOiAwLFxuICAgICAgICAgICAgICAgICAgICAgICAgdzogdGhpcy53XG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfd2FpdEZvckNvbXBvbmVudExvYWQoKSB7XG4gICAgICAgIGlmICh0aGlzLmNoaWxkcmVuLmxlbmd0aCkge1xuICAgICAgICAgICAgUHJvbWlzZS5hbGwodGhpcy5jaGlsZHJlbi5tYXAoKGNoaWxkID0+IG5ldyBQcm9taXNlKChyZXNvbHZlID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoY2hpbGQuaCA9PT0gMCAmJiBjaGlsZC53ID09PSB0aGlzLncpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzb2x2ZSgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNoaWxkLm9uKFwidHhMb2FkZWRcIiwgcmVzb2x2ZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSkpKSkpLmZpbmFsbHkoKCgpID0+IHRoaXMuX2NvbnRlbnRMb2FkZWQoKSkpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5oID0gMDtcbiAgICAgICAgICAgIHRoaXMuX2NvbnRlbnRMb2FkZWQoKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfbm90aWZ5QW5jZXN0b3JzKCkge1xuICAgICAgICB0aGlzLmZpcmVBbmNlc3RvcnMoXCIkbG9hZGVkSW5saW5lQ29udGVudFwiLCB0aGlzKTtcbiAgICAgICAgdGhpcy5zaWduYWwoXCJsb2FkZWRJbmxpbmVDb250ZW50XCIsIHRoaXMuZmluYWxXLCB0aGlzLm11bHRpTGluZUhlaWdodCk7XG4gICAgfVxuICAgIF9jb250ZW50TG9hZGVkKCkge1xuICAgICAgICBpZiAodGhpcy5jaGlsZHJlbi5sZW5ndGgpIHtcbiAgICAgICAgICAgIHNldFRpbWVvdXQoKCgpID0+IHtcbiAgICAgICAgICAgICAgICB0aGlzLm11bHRpTGluZUhlaWdodCA9IHRoaXMuZmluYWxIO1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLmZsZXggJiYgdGhpcy5mbGV4Ll9sYXlvdXQgJiYgdGhpcy5mbGV4Ll9sYXlvdXQuX2xpbmVMYXlvdXRlciAmJiB0aGlzLmZsZXguX2xheW91dC5fbGluZUxheW91dGVyLl9saW5lcykge1xuICAgICAgICAgICAgICAgICAgICB2YXIgdG90YWxIZWlnaHQgPSAwO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmZsZXguX2xheW91dC5fbGluZUxheW91dGVyLl9saW5lcy5mb3JFYWNoKChsaW5lID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRvdGFsSGVpZ2h0ICs9IE9iamVjdC5lbnRyaWVzKGxpbmUuaXRlbXMpLnNsaWNlKGxpbmUuc3RhcnRJbmRleCwgbGluZS5lbmRJbmRleCArIDEpLnNvcnQoKChhLCBiKSA9PiBiWzFdLmggLSBhWzFdLmgpKVswXVsxXS5oO1xuICAgICAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMubXVsdGlMaW5lSGVpZ2h0ID0gdG90YWxIZWlnaHQ7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9zaG91bGRUcnVuY2F0ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcmVuZGVyTWF4TGluZXMoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB0aGlzLl9ub3RpZnlBbmNlc3RvcnMoKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9jb250ZW50TG9hZGVkKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSksIDEwKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX25vdGlmeUFuY2VzdG9ycygpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9yZW5kZXJNYXhMaW5lcygpIHtcbiAgICAgICAgdmFyIGNoaWxkcmVuRGltZW5zaW9ucyA9IHRoaXMuX2NhbGNDaGlsZHJlbkRpbWVuc2lvbnMoKTtcbiAgICAgICAgdGhpcy5jaGlsZExpc3QuY2xlYXIoKTtcbiAgICAgICAgdmFyIHJlbmRlcmVkTGFzdEVsZW1lbnQgPSBmYWxzZTtcbiAgICAgICAgY2hpbGRyZW5EaW1lbnNpb25zLmZvckVhY2goKChjaGlsZCwgaW5kZXgpID0+IHtcbiAgICAgICAgICAgIGlmIChyZW5kZXJlZExhc3RFbGVtZW50KSB7XG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y5fYWRkU3VmZml4KGNoaWxkKSk7XG4gICAgICAgICAgICAgICAgICAgIHJlbmRlcmVkTGFzdEVsZW1lbnQgPSB0cnVlO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmFkZChjaGlsZC5jb21wb25lbnQpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSkpO1xuICAgICAgICB0aGlzLmFscGhhID0gMTtcbiAgICB9XG4gICAgX2NhbGNDaGlsZHJlbkRpbWVuc2lvbnMoKSB7XG4gICAgICAgIHZhciBzdWZmaXhXID0gbWVhc3VyZVRleHRXaWR0aChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUudGV4dFN0eWxlKSwge30sIHtcbiAgICAgICAgICAgIHRleHQ6IHRoaXMubWF4TGluZXNTdWZmaXhcbiAgICAgICAgfSkpO1xuICAgICAgICB2YXIgY29udGVudEVuZFggPSAwO1xuICAgICAgICB2YXIgbGluZSA9IDE7XG4gICAgICAgIHJldHVybiB0aGlzLmNoaWxkcmVuLnJlZHVjZSgoKGFjYywgY2hpbGQpID0+IHtcbiAgICAgICAgICAgIHZhciBjb21wb25lbnQgPSBjaGlsZDtcbiAgICAgICAgICAgIHZhciB0eXBlLCBjb250ZW50LCB3O1xuICAgICAgICAgICAgdmFyIGlzTmV3TGluZUVsZW1lbnQgPSBjaGlsZC53ID09IHRoaXMudyAmJiBjaGlsZC5oID09PSAwO1xuICAgICAgICAgICAgaWYgKGlzTmV3TGluZUVsZW1lbnQpIHtcbiAgICAgICAgICAgICAgICBsaW5lKys7XG4gICAgICAgICAgICAgICAgY29udGVudEVuZFggPSAwO1xuICAgICAgICAgICAgICAgIHZhciBfZGF0YSA9IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogXCJsaW5lYnJlYWtcIixcbiAgICAgICAgICAgICAgICAgICAgY29tcG9uZW50OiBjb21wb25lbnQsXG4gICAgICAgICAgICAgICAgICAgIGNvbnRlbnQ6IGNvbnRlbnQsXG4gICAgICAgICAgICAgICAgICAgIGxpbmU6IGxpbmUsXG4gICAgICAgICAgICAgICAgICAgIGhhc1NwYWNlRm9yU3VmZml4OiB0cnVlXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICBhY2MucHVzaChfZGF0YSk7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChpc1RleHQoY2hpbGQpKSB7XG4gICAgICAgICAgICAgICAgdHlwZSA9IFwidGV4dFwiO1xuICAgICAgICAgICAgICAgIGNvbnRlbnQgPSBjaGlsZC50ZXh0LnRleHQ7XG4gICAgICAgICAgICAgICAgdyA9IGNoaWxkLnRleHR1cmUuZ2V0UmVuZGVyV2lkdGgoKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoaXNJY29uKGNoaWxkKSkge1xuICAgICAgICAgICAgICAgIHR5cGUgPSBcImljb25cIjtcbiAgICAgICAgICAgICAgICB3ID0gY2hpbGQudztcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoY2hpbGQuY29uc3RydWN0b3IuX19jb21wb25lbnROYW1lID09PSBcIkJhZGdlXCIpIHtcbiAgICAgICAgICAgICAgICB0eXBlID0gXCJiYWRnZVwiO1xuICAgICAgICAgICAgICAgIHcgPSBjaGlsZC53O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY29udGVudEVuZFggKz0gdztcbiAgICAgICAgICAgIGNvbnRlbnRFbmRYICs9IGNoaWxkLmZsZXhJdGVtLm1hcmdpblJpZ2h0O1xuICAgICAgICAgICAgaWYgKE1hdGguY2VpbChjb250ZW50RW5kWCkgPj0gdGhpcy53KSB7XG4gICAgICAgICAgICAgICAgbGluZSsrO1xuICAgICAgICAgICAgICAgIGNvbnRlbnRFbmRYID0gdztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBoYXNTcGFjZUZvclN1ZmZpeCA9IE1hdGguY2VpbChjb250ZW50RW5kWCkgKyBzdWZmaXhXIDw9IHRoaXMudztcbiAgICAgICAgICAgIHZhciBkYXRhID0ge1xuICAgICAgICAgICAgICAgIHR5cGU6IHR5cGUsXG4gICAgICAgICAgICAgICAgY29tcG9uZW50OiBjb21wb25lbnQsXG4gICAgICAgICAgICAgICAgY29udGVudDogY29udGVudCxcbiAgICAgICAgICAgICAgICBsaW5lOiBsaW5lLFxuICAgICAgICAgICAgICAgIGhhc1NwYWNlRm9yU3VmZml4OiBoYXNTcGFjZUZvclN1ZmZpeFxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGFjYy5wdXNoKGRhdGEpO1xuICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgfSksIFtdKTtcbiAgICB9XG4gICAgX2FkZFN1ZmZpeChfcmVmMTYpIHtcbiAgICAgICAgdmFyIHt0eXBlOiB0eXBlLCBjb21wb25lbnQ6IGNvbXBvbmVudCwgY29udGVudDogY29udGVudH0gPSBfcmVmMTY7XG4gICAgICAgIHZhciBuZWdhdGVkUmlnaHRNYXJnaW4gPSBjb21wb25lbnQuZmxleEl0ZW0ubWFyZ2luUmlnaHQgKiAtMTtcbiAgICAgICAgdmFyIHN1ZmZpeDtcbiAgICAgICAgaWYgKHR5cGUgPT09IFwidGV4dFwiKSB7XG4gICAgICAgICAgICB2YXIge2ZvbnRGYWNlOiBmb250RmFjZSwgZm9udFNpemU6IGZvbnRTaXplLCBmb250U3R5bGU6IGZvbnRTdHlsZSwgbGluZUhlaWdodDogbGluZUhlaWdodCwgdmVydGljYWxBbGlnbjogdmVydGljYWxBbGlnbn0gPSBjb21wb25lbnQudGV4dDtcbiAgICAgICAgICAgIHN1ZmZpeCA9IHRoaXMuX2NyZWF0ZVRleHQoe1xuICAgICAgICAgICAgICAgIGZsZXhJdGVtOiB0aGlzLmNvbnRlbnRQcm9wZXJ0aWVzXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGV4dDogXCJcIi5jb25jYXQoY29udGVudC50cmltKCkpLmNvbmNhdCh0aGlzLm1heExpbmVzU3VmZml4KSxcbiAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICBmb250RmFjZTogZm9udEZhY2UsXG4gICAgICAgICAgICAgICAgICAgIGZvbnRTaXplOiBmb250U2l6ZSxcbiAgICAgICAgICAgICAgICAgICAgZm9udFN0eWxlOiBmb250U3R5bGUsXG4gICAgICAgICAgICAgICAgICAgIGxpbmVIZWlnaHQ6IGxpbmVIZWlnaHQsXG4gICAgICAgICAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IHZlcnRpY2FsQWxpZ25cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmFkZChjb21wb25lbnQpO1xuICAgICAgICAgICAgc3VmZml4ID0gdGhpcy5fY3JlYXRlVGV4dCh7XG4gICAgICAgICAgICAgICAgZmxleEl0ZW06IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5jb250ZW50UHJvcGVydGllcyksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIG1hcmdpbkxlZnQ6IG5lZ2F0ZWRSaWdodE1hcmdpblxuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9LCB0aGlzLm1heExpbmVzU3VmZml4KTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gc3VmZml4O1xuICAgIH1cbiAgICBfY3JlYXRlSWNvbihiYXNlLCBpY29uUHJvcHMpIHtcbiAgICAgICAgdmFyIHkgPSAodGhpcy50ZXh0SGVpZ2h0ID4gdGhpcy5zdHlsZS50ZXh0U3R5bGUubGluZUhlaWdodCA/IHRoaXMudGV4dEhlaWdodCA6IHRoaXMuc3R5bGUudGV4dFN0eWxlLmxpbmVIZWlnaHQ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8IHRoaXMuc3R5bGUudGV4dFN0eWxlLnRleHRDb2xvcixcbiAgICAgICAgICAgICAgICBoOiB0ZXh0Q29tcG9uZW50LmggKiB0aGlzLnN0eWxlLnN0cmlrZXRocm91Z2hSYXRpbyxcbiAgICAgICAgICAgICAgICB5OiB0ZXh0Q29tcG9uZW50LmggLyAyLFxuICAgICAgICAgICAgICAgIG1vdW50WTogMVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgdHlwZTogbG5nLkNvbXBvbmVudCxcbiAgICAgICAgICAgICAgICB3OiB0ZXh0V2lkdGggKyB0ZXh0Q29tcG9uZW50LmZsZXhJdGVtLm1hcmdpblJpZ2h0LFxuICAgICAgICAgICAgICAgIGg6IHRleHRDb21wb25lbnQuaCxcbiAgICAgICAgICAgICAgICBjaGlsZHJlbjogWyBfb2JqZWN0U3ByZWFkKHt9LCB0ZXh0Q29tcG9uZW50KSwgX29iamVjdFNwcmVhZCh7fSwgc3RyaWtldGhyb3VnaExpbmUpIF1cbiAgICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRleHRDb21wb25lbnQ7XG4gICAgfVxuICAgIF9jcmVhdGVCYWRnZShiYXNlLCBiYWRnZSkge1xuICAgICAgICByZXR1cm4gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGJhc2UpLCB7fSwge1xuICAgICAgICAgICAgeTogdGhpcy5iYWRnZVkgfHwgMFxuICAgICAgICB9LCB0aGlzLmJhZGdlUHJvcGVydGllcyksIHt9LCB7XG4gICAgICAgICAgICB0eXBlOiBCYWRnZSxcbiAgICAgICAgICAgIHRpdGxlOiBiYWRnZSxcbiAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICBsb2FkZWRCYWRnZTogXCJfbG9hZGVkQmFkZ2VcIlxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZUljb25Qb3NpdGlvbihpY29uKSB7XG4gICAgICAgIGljb24ueSA9IHRoaXMuc3R5bGUudGV4dFN0eWxlLmxpbmVIZWlnaHQgLSBpY29uLmg7XG4gICAgfVxuICAgIF9sb2FkZWRCYWRnZShiYWRnZSkge1xuICAgICAgICBpZiAodGhpcy5iYWRnZVkgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgYmFkZ2UueSA9IHRoaXMuc3R5bGUudGV4dFN0eWxlLmxpbmVIZWlnaHQgLSBiYWRnZS5oO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9mb3JtYXRTcGFjZXMocGFyc2VkQ29udGVudCkge1xuICAgICAgICB2YXIgd2hpdGVzcGFjZSA9IC8oLis/XFxzKykvO1xuICAgICAgICByZXR1cm4gZmxhdHRlbigocGFyc2VkQ29udGVudCB8fCBbXSkucmVkdWNlKCgoYWNjLCBpdGVtKSA9PiB7XG4gICAgICAgICAgICB2YXIgcGFyc2VkID0gaXRlbTtcbiAgICAgICAgICAgIGlmIChpc1RleHQoaXRlbSkpIHtcbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIGl0ZW0gPT09IFwib2JqZWN0XCIpIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIGZvcm1hdHRlZFdvcmRzID0gaXRlbS50ZXh0LnNwbGl0KHdoaXRlc3BhY2UpLm1hcCgod29yZCA9PiB3b3JkICYmIF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgaXRlbSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0OiB3b3JkXG4gICAgICAgICAgICAgICAgICAgIH0pKSk7XG4gICAgICAgICAgICAgICAgICAgIGFjYy5wdXNoKC4uLmZvcm1hdHRlZFdvcmRzKTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcGFyc2VkID0gaXRlbS5zcGxpdCh3aGl0ZXNwYWNlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGFjYy5wdXNoKHBhcnNlZCk7XG4gICAgICAgICAgICByZXR1cm4gYWNjO1xuICAgICAgICB9KSwgW10pKS5tYXAoKChpdGVtLCBpbmRleCwgYXJyKSA9PiB7XG4gICAgICAgICAgICBpZiAoaXRlbSA9PT0gXCIgXCIpIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgIGlmIChhcnJbaW5kZXggKyAxXSA9PT0gXCIgXCIpIHJldHVybiBpdGVtICsgXCIgXCI7XG4gICAgICAgICAgICByZXR1cm4gaXRlbTtcbiAgICAgICAgfSkpLmZpbHRlcihCb29sZWFuKTtcbiAgICB9XG4gICAgX3NldENvbnRlbnQoY29udGVudCkge1xuICAgICAgICBpZiAoY29udGVudCAhPT0gdGhpcy5fY29udGVudCkge1xuICAgICAgICAgICAgdGhpcy5fY29udGVudCA9IGNvbnRlbnQ7XG4gICAgICAgICAgICB2YXIgcGFyc2VkQ29udGVudCA9IHRoaXMuX2NvbnRlbnQ7XG4gICAgICAgICAgICBpZiAoY29udGVudCAmJiAhQXJyYXkuaXNBcnJheShjb250ZW50KSkge1xuICAgICAgICAgICAgICAgIHBhcnNlZENvbnRlbnQgPSBwYXJzZUlubGluZUNvbnRlbnQoY29udGVudCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9wYXJzZWRDb250ZW50ID0gdGhpcy5fZm9ybWF0U3BhY2VzKHBhcnNlZENvbnRlbnQpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBjb250ZW50O1xuICAgIH1cbiAgICBfc2V0QmFkZ2VQcm9wZXJ0aWVzKGJhZGdlUHJvcGVydGllcykge1xuICAgICAgICBpZiAodHlwZW9mIGJhZGdlUHJvcGVydGllcyA9PT0gXCJvYmplY3RcIikge1xuICAgICAgICAgICAgcmV0dXJuIGJhZGdlUHJvcGVydGllcztcbiAgICAgICAgfVxuICAgIH1cbiAgICBfZ2V0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bnRlbnRQcm9wZXJ0aWVzLm1hcmdpbkJvdHRvbSAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5jb250ZW50UHJvcGVydGllcy5tYXJnaW5Cb3R0b207XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuc3R5bGUubWFyZ2luQm90dG9tKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5zdHlsZS5tYXJnaW5Cb3R0b207XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIDA7XG4gICAgfVxuICAgIGdldCBfc2hvdWxkVHJ1bmNhdGUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLmNvbnRlbnRXcmFwICYmIHRoaXMubWF4TGluZXM7XG4gICAgfVxuICAgIHNldCBhbm5vdW5jZShhbm5vdW5jZSkge1xuICAgICAgICBzdXBlci5hbm5vdW5jZSA9IGFubm91bmNlO1xuICAgIH1cbiAgICBnZXQgYW5ub3VuY2UoKSB7XG4gICAgICAgIGlmICh0aGlzLl9hbm5vdW5jZSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2Fubm91bmNlO1xuICAgICAgICB9XG4gICAgICAgIHZhciBhbm5vdW5jZSA9IHRoaXMuX3BhcnNlZENvbnRlbnQgJiYgdGhpcy5fcGFyc2VkQ29udGVudC5yZWR1Y2UoKChhbm5vdW5jZSwgaXRlbSkgPT4ge1xuICAgICAgICAgICAgaWYgKHR5cGVvZiBpdGVtID09PSBcInN0cmluZ1wiKSB7XG4gICAgICAgICAgICAgICAgYW5ub3VuY2UgKz0gaXRlbTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoaXRlbS5hbm5vdW5jZSkge1xuICAgICAgICAgICAgICAgIGFubm91bmNlICs9IGl0ZW0uYW5ub3VuY2U7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGl0ZW0udGV4dCkge1xuICAgICAgICAgICAgICAgIHZhciBfaXRlbSRzdHlsZTtcbiAgICAgICAgICAgICA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ICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiTWFycXVlZVwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRJO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIFwiQ29udGVudENsaXBwZXJcIiwge1xuICAgICAgICAgICAgbmFtZTogXCJDb250ZW50Qm94XCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRlbnRDbGlwcGVyLkNvbnRlbnRCb3hcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIkNvbnRlbnRcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGVudENsaXBwZXIuQ29udGVudEJveC5Db250ZW50XCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJDb250ZW50TG9vcFRleHR1cmVcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGVudENsaXBwZXIuQ29udGVudEJveC5Db250ZW50TG9vcFRleHR1cmVcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJhdXRvU3RhcnRcIiwgXCJ0aXRsZVwiLCBcImNvbnRlbnRUZXh0dXJlXCIsIFwiY29sb3JcIiwgXCJjZW50ZXJBbGlnblwiLCBcImRlbGF5XCIsIFwicmVwZWF0XCIsIFwib3ZlcnJpZGVMb29wWFwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgYWxpYXNTdHlsZXMoKSB7XG4gICAgICAgIHJldHVybiBbIHtcbiAgICAgICAgICAgIHByZXY6IFwiZmFkZVdcIixcbiAgICAgICAgICAgIGN1cnI6IFwiZmFkZVdpZHRoXCJcbiAgICAgIC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gICAgICAgfSBlbHNlIGlmICh0aGlzLnRpdGxlKSB7XG4gICAgICAgICAgICBjb250ZW50LnRleHQgPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS50ZXh0U3R5bGUpLCB0aGlzLnRpdGxlKSwge30sIHtcbiAgICAgICAgICAgICAgICB0ZXh0OiB0aGlzLnRleHRDb250ZW50XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIENvbnRlbnRDbGlwcGVyOiB7XG4gICAgICAgICAgICAgICAgdzogdGhpcy53ICsgMTQsXG4gICAgICAgICAgICAgICAgQ29udGVudEJveDoge1xuICAgICAgICAgICAgICAgICAgICBDb250ZW50OiBjb250ZW50LFxuICAgICAgICAgICAgICAgICAgICBDb250ZW50TG9vcFRleHR1cmU6IHt9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgdGhpcy5zaWduYWwoXCJtYXJxdWVlQ29udGVudExvYWRlZFwiKTtcbiAgICB9XG4gICAgX3VwZGF0ZVNoYWRlcigpIHtcbiAgICAgICAgdGhpcy5fQ29udGVudENsaXBwZXIucGF0Y2goe1xuICAgICAgICAgICAgdzogdGhpcy53ID4gMCA/IHRoaXMudyArIHRoaXMuc3R5bGUuZmFkZVdpZHRoIC8gMiA6IDAsXG4gICAgICAgICAgICBzaGFkZXI6IHtcbiAgICAgICAgICAgICAgICB0eXBlOiBGYWRlU2hhZGVyLFxuICAgICAgICAgICAgICAgIHBvc2l0aW9uTGVmdDogMCxcbiAgICAgICAgICAgICAgICBwb3NpdGlvblJpZ2h0OiB0aGlzLnN0eWxlLmZhZGVXaWR0aFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIHJ0dDogdHJ1ZVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZUFuaW1hdGlvbigpIHtcbiAgICAgICAgdGhpcy5fc2Nyb2xsQW5pbWF0aW9uICYmIHRoaXMuX3Njcm9sbEFuaW1hdGlvbi5zdG9wTm93KCk7XG4gICAgICAgIHRoaXMuX3Njcm9sbEFuaW1hdGlvbiA9IHRoaXMuYW5pbWF0aW9uKHtcbiAgICAgICAgICAgIGR1cmF0aW9uOiB0aGlzLl9sb29wV2lkdGggLyA1MCxcbiAgICAgICAgICAgIGRlbGF5OiBpc05hTih0aGlzLmRlbGF5KSA/IDEuNSA6IHRoaXMuZGVsYXksXG4gICAgICAgICAgICByZXBlYXQ6IGlzTmFOKHRoaXMucmVwZWF0KSA/IC0xIDogdGhpcy5yZXBlYXQsXG4gICAgICAgICAgICBhY3Rpb25zOiBbIHtcbiAgICAgICAgICAgICAgICB0OiBcIkNvbnRlbnRCb3hcIixcbiAgICAgICAgICAgICAgICBwOiBcInhcIixcbiAgICAgICAgICAgICAgICB2OiB7XG4gICAgICAgICAgICAgICAgICAgIHNtOiAwLFxuICAgICAgICAgICAgICAgICAgICAwOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2OiAwXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIC41OiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2OiAtKHRoaXMuX2xvb3BXaWR0aCArIHRoaXMuc3R5bGUub2Zmc2V0KVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHQ6IFwiQ29udGVudENsaXBwZXJcIixcbiAgICAgICAgICAgICAgICBwOiBcInNoYWRlci5wb3NpdGlvbkxlZnRcIixcbiAgICAgICAgICAgICAgICB2OiB7XG4gICAgICAgICAgICAgICAgICAgIHNtOiAwLFxuICAgICAgICAgICAgICAgICAgICAwOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2OiAwXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIC4xOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2OiB0aGlzLnN0eWxlLmZhZGVXaWR0aFxuICAgICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgICAuNDoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdjogdGhpcy5zdHlsZS5mYWRlV2lkdGhcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgLjU6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHY6IDBcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gXVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3Bvc2l0aW9uVGV4dHVyZSgpIHtcbiAgICAgICAgdmFyIHggPSB0aGlzLl9zaG91bGRDZW50ZXIoKSA/ICh0aGlzLncgLSB0aGlzLl90ZXh0UmVuZGVyZWRXKSAvIDIgOiAwO1xuICAgICAgICBpZiAodGhpcy5zdHlsZS5zaG91bGRTbW9vdGgpIHtcbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnRCb3guc21vb3RoID0ge1xuICAgICAgICAgICAgICAgIHg6IHhcbiAgICAgICAgICAgIH07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50Qm94LnggPSB4O1xuICAgICAgICB9XG4gICAgfVxuICAgIHN0YXJ0U2Nyb2xsaW5nKCkge1xuICAgICAgICB0aGlzLl9Db250ZW50Lm9mZihcInR4TG9hZGVkXCIsIHRoaXMuc3RhcnRTY3JvbGxpbmcuYmluZCh0aGlzKSk7XG4gICAgICAgIHRoaXMuX3Nob3VsZFRyeVNjcm9sbGluZyA9IHRydWU7XG4gICAgICAgIGlmICh0aGlzLl90ZXh0UmVuZGVyZWRXID09PSAwKSB7XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50Lm9uKFwidHhMb2FkZWRcIiwgdGhpcy5zdGFydFNjcm9sbGlu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mb2FkICYmIHRoaXMuYWxwaGEgPCAxKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5hbHBoYSA9IDE7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9ub3RpZnlBbmNlc3RvcnMoKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfc2V0Q29udGVudChjb250ZW50KSB7XG4gICAgICAgIHRoaXMuX2lzSW5saW5lQ29udGVudCA9IGZhbHNlO1xuICAgICAgICBpZiAoQXJyYXkuaXNBcnJheShjb250ZW50KSB8fCB1dGlscyQxLmlzTWFya3VwU3RyaW5nKGNvbnRlbnQpKSB7XG4gICAgICAgICAgICB0aGlzLl9pc0lubGluZUNvbnRlbnQgPSB0cnVlO1xuICAgICAgICB9XG4gICAgICAgIGlmIChcInN0cmluZ1wiICE9PSB0eXBlb2YgY29udGVudCAmJiAhdGhpcy5faXNJbmxpbmVDb250ZW50KSB7XG4gICAgICAgICAgICByZXR1cm4gXCJcIjtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gY29udGVudDtcbiAgICB9XG4gICAgZ2V0IHRpdGxlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fY29udGVudDtcbiAgICB9XG4gICAgX25vdGlmeUFuY2VzdG9ycygpIHtcbiAgICAgICAgdmFyIHcgPSBhcmd1bWVudHMubGVuZ3RoID4gMCAmJiBhcmd1bWVudHNbMF0gIT09IHVuZGVmaW5lZCA/IGFyZ3VtZW50c1swXSA6IHRoaXMudztcbiAgICAgICAgdmFyIGggPSBhcmd1bWVudHMubGVuZ3RoID4gMSAmJiBhcmd1bWVudHNbMV0gIT09IHVuZGVmaW5lZCA/IGFyZ3VtZW50c1sxXSA6IHRoaXMuaDtcbiAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKFwiJGl0ZW1DaGFuZ2VkXCIpO1xuICAgICAgICB0aGlzLnNpZ25hbChcInRleHRCb3hDaGFuZ2VkXCIsIHtcbiAgICAgICAgICAgIHc6IHcsXG4gICAgICAgICAgICBoOiBoXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfY29uc3RydWN0KCkge1xuICAgICAgICBzdXBlci5fY29uc3RydWN0KCk7XG4gICAgICAgIHRoaXMuX21hcnF1ZWVDb250ZW50TGlzdGVuZXJBdHRhY2hlZCA9IGZhbHNlO1xuICAgICAgICB0aGlzLl9tYXJxdWVlT3ZlcnJpZGVMb29wWCA9IHVuZGVmaW5lZDtcbiAgICAgICAgdGhpcy5fcmVzZXRNYXJxdWVlUHJvbWlzZSgpO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICBpZiAoIXRoaXMuY29udGVudCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX1RleHQgfHwgdGhpcy5fSW5saW5lQ29udGVudCkge1xuICAgICAgICAgICAgICAgIHRoaXMudyA9IHRoaXMuaCA9IDA7XG4gICAgICAgICAgICAgICAgdGhpcy5fbm90aWZ5QW5jZXN0b3JzKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fdXBkYXRlTWFycXVlZSgpO1xuICAgICAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICBUZXh0OiB1bmRlZmluZWQsXG4gICAgICAgICAgICAgICAgICAgIElubGluZUNvbnRlbnQ6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX2lzSW5saW5lQ29udGVudCA/IHRoaXMuX3VwZGF0ZUlubGluZUNvbnRlbnQoKSA6IHRoaXMuX3VwZGF0ZVRleHQoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlTWFycXVlZSgpO1xuICAgIH1cbiAgICBfdXBkYXRlSW5saW5lQ29udGVudCgpIHtcbiAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICBUZXh0OiB1bmRlZmluZWRcbiAgICAgICAgfSk7XG4gICAgICAgIHZhciBpbmxpbmVDb250ZW50UGF0Y2ggPSBJbmxpbmVDb250ZW50LnByb3BlcnRpZXMucmVkdWNlKCgoYWNjLCBwcm9wKSA9PiB7XG4gICAgICAgICAgICBpZiAodGhpc1twcm9wXSAhPSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBhY2NbcHJvcF0gPSB0aGlzW3Byb3BdO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgfSksIHtcbiAgICAgICAgICAgIHN0eWxlOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgIHRleHRTdHlsZTogdGhpcy5fdGV4dFN0eWxlU2V0XG4gICAgICAgICAgICB9KVxuICAgICAgICB9KTtcbiAgICAgICAgaWYgKHRoaXMuX3RleHRTdHlsZVNldC53b3JkV3JhcFdpZHRoKSB7XG4gICAgICAgICAgICBpbmxpbmVDb250ZW50UGF0Y2gudyA9IHRoaXMuX3RleHRTdHlsZVNldC53b3JkV3JhcFdpZHRoO1xuICAgICAgICAgICAgaW5saW5lQ29udGVudFBhdGNoLnJ0dCA9IHRydWU7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX3RleHRTdHlsZVNldC5tYXhMaW5lcykge1xuICAgICAgICAgICAgaW5saW5lQ29udGVudFBhdGNoLm1heExpbmVzID0gdGhpcy5fdGV4dFN0eWxlU2V0Lm1heExpbmVzO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl90ZXh0U3R5bGVTZXQubWF4TGluZXNTdWZmaXgpIHtcbiAgICAgICAgICAgIGlubGluZUNvbnRlbnRQYXRjaC5tYXhMaW5lc1N1ZmZpeCA9IHRoaXMuX3RleHRTdHlsZVNldC5tYXhMaW5lc1N1ZmZpeDtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIGFscGhhOiAxLFxuICAgICAgICAgICAgSW5saW5lQ29udGVudDogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICB0eXBlOiBJbmxpbmVDb250ZW50LFxuICAgICAgICAgICAgICAgIHc6IHRoaXMud1xuICAgICAgICAgICAgfSwgaW5saW5lQ29udGVudFBhdGNoKSwge30sIHtcbiAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIGxvYWRlZElubGluZUNvbnRlbnQ6IFwiX3NldERpbWVuc2lvbnNcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlVGV4dCgpIHtcbiAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICBJbmxpbmVDb250ZW50OiB1bmRlZmluZWRcbiAgICAgICAgfSk7XG4gICAgICAgIGlmICghdGhpcy5fVGV4dCkge1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgVGV4dDoge31cbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgdGhpcy5fVGV4dC5vbihcInR4TG9hZGVkXCIsIHRoaXMuX3NldERpbWVuc2lvbnMuYmluZCh0aGlzKSk7XG4gICAgICAgIH1cbiAgICAgICAgdmFyIGZvbnRTdHlsZSA9IHRoaXMuX3RleHRTdHlsZVNldDtcbiAgICAgICAgaWYgKHRoaXMuX1RleHQpIHtcbiAgICAgICAgICAgIHRoaXMuX1RleHQucGF0Y2goe1xuICAgICAgICAgICAgICAgIHk6IHRoaXMuc3R5bGUub2Zmc2V0WSxcbiAgICAgICAgICAgICAgICB4OiB0aGlzLnN0eWxlLm9mZnNldFgsXG4gICAgICAgICAgICAgICAgdGV4dDogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBsaWdodG5pbmdUZXh0RGVmYXVsdHMpLCBmb250U3R5bGUpXG4gICAgICAgICAgICB9KT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AgICAgICAgICAgIHRoaXMuX3Jlc2V0TWFycXVlZVByb21pc2UoKTtcbiAgICAgICAgICAgIHZhciBtYXJxdWVlUGF0Y2ggPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMubWFycXVlZVByb3BzKSwge30sIHtcbiAgICAgICAgICAgICAgICB3OiB0aGlzLl90ZXh0U3R5bGVTZXQud29yZFdyYXBXaWR0aCB8fCB0aGlzLncsXG4gICAgICAgICAgICAgICAgaDogdGhpcy5oLFxuICAgICAgICAgICAgICAgIHk6IHRoaXMuc3R5bGUub2Zmc2V0WSxcbiAgICAgICAgICAgICAgICB4OiB0aGlzLnN0eWxlLm9mZnNldFgsXG4gICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICBtYXJxdWVlQ29udGVudExvYWRlZDogXCJfbG9hZGVkTWFycXVlZUNvbnRlbnRcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9NYXJxdWVlKSB7XG4gICAgICAgICAgICAgICAgbWFycXVlZVBhdGNoLnR5cGUgPSBNYXJxdWVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRoaXMuX2lzSW5saW5lQ29udGVudCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX0lubGluZUNvbnRlbnQudyA9IDA7XG4gICAgICAgICAgICAgICAgbWFycXVlZVBhdGNoLnRpdGxlID0gdW5kZWZpbmVkO1xuICAgICAgICAgICAgICAgIG1hcnF1ZWVQYXRjaC5jb250ZW50VGV4dHVyZSA9IHRoaXMuX2NvbnRlbnRUYWcuZ2V0VGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgIG1hcnF1ZWVQYXRjaC53ID0gdGhpcy5fdGV4dFN0eWxlU2V0LndvcmRXcmFwV2lkdGggfHwgdGhpcy53O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBtYXJxdWVlUGF0Y2guY29udGVudFRleHR1cmUgPSB1bmRlZmluZWQ7XG4gICAgICAgICAgICAgICAgbWFycXVlZVBhdGNoLnRpdGxlID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dDogdGhpcy5fY29udGVudFRhZy50ZXh0LnRleHRcbiAgICAgICAgICAgICAgICB9LCB0aGlzLl90ZXh0U3R5bGVTZXQpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcFdpZHRoOiAwLFxuICAgICAgICAgICAgICAgICAgICBtYXhMaW5lczogMVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgTWFycXVlZTogbWFycXVlZVBhdGNoXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIGlmICghdGhpcy5fbWFycXVlZUNvbnRlbnRMaXN0ZW5lckF0dGFjaGVkKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fbWFycXVlZUNvbnRlbnRMaXN0ZW5lckF0dGFjaGVkID0gdHJ1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChcInVuZGVmaW5lZFwiICE9PSB0eXBlb2YgdGhpcy5fbWFycXVlZU92ZXJyaWRlTG9vcFgpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9hd2FpdE1hcnF1ZWVPdmVycmlkZVgudGhlbigoKCkgPT4ge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl90b2dnbGVNYXJxdWVlKHRoaXMuX2NvbnRlbnRUYWcpO1xuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fdG9nZ2xlTWFycXVlZSh0aGlzLl9jb250ZW50VGFnKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbiAgICBfZ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bnRlbnQgJiYgIXRoaXMuc3R5bGUudGV4dFN0eWxlLndvcmRXcmFwV2lkdGggJiYgdGhpcy5maXhlZCkge1xuICAgICAgICAgICAgZm9udFN0eWxlLndvcmRXcmFwV2lkdGggPSB0aGlzLnc7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGZvbnRTdHlsZTtcbiAgICB9XG4gICAgZ2V0IF9jb250ZW50VGFnKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faXNJbmxpbmVDb250ZW50ID8gdGhpcy5fSW5saW5lQ29udGVudCA6IHRoaXMuX1RleHQ7XG4gICAgfVxuICAgIF90b2dnbGVNYXJxdWVlKGNvbnRlbnRUYWcpIHtcbiAgICAgICAgaWYgKHRoaXMubWFycXVlZSkge1xuICAgICAgICAgICAgaWYgKGNvbnRlbnRUYWcpIHtcbiAgICAgICAgICAgICAgICBjb250ZW50VGFnLmFscGhhID0gLjAwMTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLl9NYXJxdWVlKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fTWFycXVlZS5hbHBoYSA9IDE7XG4gICAgICAgICAgICAgICAgdGhpcy5fTWFycXVlZS5zdGFydFNjcm9sbGluZygpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKGNvbnRlbnRUYWcpIHtcbiAgICAgICAgICAgICAgICBjb250ZW50VGFnLmFscGhhID0gMTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLl9NYXJxdWVlKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fTWFycXVlZS5hbHBoYSA9IC4wMDE7XG4gICAgICAgICAgICAgICAgdGhpcy5fTWFycXVlZS5zdG9wU2Nyb2xsaW5nKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgdG9nZ2xlTWFycXVlZSgpIHtcbiAgICAgICAgdGhpcy5fdG9nZ2xl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IsXG4gICAgICAgICAgICBjdXJyOiBcImNvbnRlbnRTcGFjaW5nXCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIC4uLnN1cGVyLnRhZ3MsIFwiQ29udGVudFwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIlRleHRXcmFwcGVyXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRlbnQuVGV4dFdyYXBwZXJcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlRpdGxlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRlbnQuVGV4dFdyYXBwZXIuVGl0bGVcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlByZWZpeFwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50LlByZWZpeFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiU3VmZml4XCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRlbnQuU3VmZml4XCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBzdXBlci5fdGVtcGxhdGUoKSksIHt9LCB7XG4gICAgICAgICAgICBDb250ZW50OiB7XG4gICAgICAgICAgICAgICAgbW91bnQ6IC41LFxuICAgICAgICAgICAgICAgIHg6IHcgPT4gdyAvIDIsXG4gICAgICAgICAgICAgICAgeTogaCA9PiBoIC8gMixcbiAgICAgICAgICAgICAgICB6SW5kZXg6IDJcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVByZWZpeCgpO1xuICAgICAgICB0aGlzLl91cGRhdGVUaXRsZSgpO1xuICAgICAg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XgueCA9IHRoaXMuX3N1ZmZpeFg7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVByZWZpeCgpIHtcbiAgICAgICAgdmFyIHByZWZpeFN0cmluZyA9IEpTT04uc3RyaW5naWZ5KHRoaXMucHJlZml4KTtcbiAgICAgICAgaWYgKHRoaXMucHJlZml4KSB7XG4gICAgICAgICAgICB2YXIgcHJlZml4UGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgaXRlbVNwYWNpbmc6IHRoaXMuc3R5bGUuaXRlbVNwYWNpbmdcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9QcmVmaXgpIHtcbiAgICAgICAgICAgICAgICBwcmVmaXhQYXRjaCA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5fcm93UHJvcHMpLCBwcmVmaXhQYXRjaCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBQcmVmaXg6IHByZWZpeFBhdGNoXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVByZWZpeFN1ZmZpeFN0eWxlcyhcInByZWZpeFwiKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgIFByZWZpeDogdW5kZWZpbmVkXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9wcmV2UHJlZml4ID0gcHJlZml4U3RyaW5nO1xuICAgIH1cbiAgICBfdXBkYXRlUHJlZml4U3VmZml4U3R5bGVzKCkge1xuICAgICAgICB2YXIgdHlwZSA9IGFyZ3VtZW50cy5sZW5ndGggPiAwICYmIGFyZ3VtZW50c1swXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzBdIDogXCJwcmVmaXhcIjtcbiAgICAgICAgdmFyIG1hcCA9IHtcbiAgICAgICAgICAgIHByZWZpeDoge1xuICAgICAgICAgICAgICAgIHRhZzogdGhpcy5fUHJlZml4LFxuICAgICAgICAgICAgICAgIHByb3A6IHRoaXMucHJlZml4LFxuICAgICAgICAgICAgICAgIHByZXZQcm9wOiB0aGlzLl9wcmV2UHJlZml4XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgc3VmZml4OiB7XG4gICAgICAgICAgICAgICAgdGFnOiB0aGlzLl9TdWZmaXgsXG4gICAgICAgICAgICAgICAgcHJvcDogdGhpcy5zdWZmaXgsXG4gICAgICAgICAgICAgICAgcHJldlByb3A6IHRoaXMuX3ByZXZTdWZmaXhcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgICAgdmFyIHt0YWc6IHRhZywgcHJvcDogcHJvcH0gPSBtYXBbdHlwZV07XG4gICAgICAgIHZhciB7cHJldlByb3A6IHByZXZQcm9wfSA9IG1hcFt0eXBlXTtcbiAgICAgICAgdmFyIHByb3BTdHJpbmcgPSBKU09OLnN0cmluZ2lmeShwcm9wKTtcbiAgICAgICAgaWYgKHByb3BTdHJpbmcgIT09IHByZXZQcm9wKSB7XG4gICAgICAgICAgICBwcmV2UHJvcCA9IHByb3BTdHJpbmc7XG4gICAgICAgICAgICB0YWcuaXRlbXMgPSB0aGlzLl9hZGRCdXR0b25Qcm9wcyhwcm9wKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRhZy5JdGVtcy5jaGlsZHJlbi5mb3JFYWNoKCgoaXRlbSwgaWR4KSA9PiB7XG4gICAgICAgICAgICAgICAgaXRlbS5jb2xvciA9IEFycmF5LmlzQXJyYXkocHJvcCkgPyBwcm9wW2lkeF0uY29sb3IgOiBwcm9wLmNvbG9yO1xuICAgICAgICAgICAgICAgIGl0ZW0uc3R5bGUgPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGl0ZW0uc3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBjb2xvcjogdGhpcy5zdHlsZS5jb250ZW50Q29sb3JcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlVGl0bGUoKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNUaXRsZSkge1xuICAgICAgICAgICAgdmFyIHRpdGxlUGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgY29udGVudDogdGhpcy50aXRsZSxcbiAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IHRoaXMuc3R5bGUudGV4dFN0eWxlXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmICghdGhpcy5fVGl0bGUpIHtcbiAgICAgICAgICAgICAgICB0aXRsZVBhdGNoID0gX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgICAgIG1vdW50WTogLjUsXG4gICAgICAgICAgICAgICAgICAgIHk6IGggPT4gaCAvIDIsXG4gICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRleHRCb3hDaGFuZ2VkOiBcIl9vblRpdGxlVGV4dEJveENoYW5nZWRcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSwgdGl0bGVQYXRjaCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBUZXh0V3JhcHBlcjoge1xuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgICAgICAgICBUaXRsZTogdGl0bGVQYXRjaFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgVGV4dFdyYXBwZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgVGl0bGU6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVTdWZmaXgoKSB7XG4gICAgICAgIGlmICh0aGlzLnN1ZmZpeCkge1xuICAgICAgICAgICAgdmFyIHN1ZmZpeFBhdGNoID0ge1xuICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIGl0ZW1TcGFjaW5nOiB0aGlzLnN0eWxlLml0ZW1TcGFjaW5nXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmICghdGhpcy5fU3VmZml4KSB7XG4gICAgICAgICAgICAgICAgc3VmZml4UGF0Y2ggPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuX3Jvd1Byb3BzKSwgc3VmZml4UGF0Y2gpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgU3VmZml4OiBzdWZmaXhQYXRjaFxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVQcmVmaXhTdWZmaXhTdHlsZXMoXCJzdWZmaXhcIik7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBTdWZmaXg6IHVuZGVmaW5lZFxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVRydW5jYXRpb24oKSB7XG4gICAgICAgIGlmICh0aGlzLl9UaXRsZSkge1xuICAgICAgICAgICAgdGhpcy5fVGl0bGUucGF0Y2goe1xuICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlLnRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdGhpcy5maXhlZCxcbiAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuZml4ZWQgPyB0aGlzLl9maXhlZFdvcmRXcmFwV2lkdGggOiAwXG4gICAgICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZUNvbnRlbnREaW1lbnNpb25zKCkge1xuICAgICAgICB2YXIgY29udGVudERpbWVuc2lvbnNQYXRjaCA9IHt9O1xuICAgICAgICB2YXIgeSA9IHRoaXMuaCAvIDI7XG4gICAgICAgIGlmICh0aGlzLl9Db250ZW50LnRyYW5zaXRpb24oXCJ3XCIpLnRhcmdldFZhbHVlICE9PSB0aGlzLl9jb250ZW50Vykge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC53ID0gdGhpcy5fY29udGVudFc7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX0NvbnRlbnQueSAhPT0geSkge1xuICAgICAgICAgICAgY29udGVudERpbWVuc2lvbnNQYXRjaC55ID0geTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoT2JqZWN0LmtleXMoY29udGVudERpbWVuc2lvbnNQYXRjaCkubGVuZ3RoID4gMCkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaChjb250ZW50RGltZW5zaW9uc1BhdGNoKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlQ29udGVudFBvc2l0aW9uKCkge1xuICAg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b3BzKGFycikge1xuICAgICAgICB2YXIgaXRlbXMgPSBBcnJheS5pc0FycmF5KGFycikgPyBhcnIgOiBbIGFyciBdO1xuICAgICAgICByZXR1cm4gaXRlbXMubWFwKChpdGVtID0+IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLl9idXR0b25Qcm9wcyksIGl0ZW0pLCB7fSwge1xuICAgICAgICAgICAgc3R5bGU6IF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgIGNvbG9yOiB0aGlzLnN0eWxlLmNvbnRlbnRDb2xvclxuICAgICAgICAgICAgfSwgaXRlbS5zdHlsZSlcbiAgICAgICAgfSkpKTtcbiAgICB9XG4gICAgX2dldEp1c3RpZnkoKSB7XG4gICAgICAgIHJldHVybiAhIXRoaXMuX2p1c3RpZnkgPyB0aGlzLl9qdXN0aWZ5IDogdGhpcy5zdHlsZS5qdXN0aWZ5O1xuICAgIH1cbiAgICBnZXQgX2NvbnRlbnRQcm9wcygpIHtcbiAgICAgICAgdmFyIG1vdW50WDtcbiAgICAgICAgdmFyIHg7XG4gICAgICAgIHN3aXRjaCAodGhpcy5qdXN0aWZ5KSB7XG4gICAgICAgICAgY2FzZSBcImxlZnRcIjpcbiAgICAgICAgICAgIG1vdW50WCA9IDA7XG4gICAgICAgICAgICB4ID0gdGhpcy5fcGFkZGluZ0xlZnQ7XG4gICAgICAgICAgICBicmVhaztcblxuICAgICAgICAgIGNhc2UgXCJyaWdodFwiOlxuICAgICAgICAgICAgbW91bnRYID0gMTtcbiAgICAgICAgICAgIHggPSB0aGlzLncgLSB0aGlzLl9wYWRkaW5nUmlnaHQ7XG4gICAgICAgICAgICBicmVhaztcblxuICAgICAgICAgIGNhc2UgXCJjZW50ZXJcIjpcbiAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgbW91bnRYID0gLjU7XG4gICAgICAgICAgICB4ID0gdGhpcy53IC8gMjtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBtb3VudFg6IG1vdW50WCxcbiAgICAgICAgICAgIHg6IHhcbiAgICAgICAgfTtcbiAgICB9XG4gICAgZ2V0IF9idXR0b25Qcm9wcygpIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIGNlbnRlckluUGFyZW50OiB0cnVlLFxuICAgICAgICAgICAgbW9kZTogdGhpcy5tb2RlXG4gICAgICAgIH07XG4gICAgfVxuICAgIGdldCBfaGFzUHJlZml4KCkge1xuICAgICAgICByZXR1cm4gISEodGhpcy5wcmVmaXggJiYgT2JqZWN0LmtleXModGhpcy5wcmVmaXgpLmxlbmd0aCk7XG4gICAgfVxuICAgIGdldCBfcHJlZml4VygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2hhc1ByZWZpeCAmJiB0aGlzLl9QcmVmaXggIT09IHVuZGVmaW5lZCA/IHRoaXMuX1ByZWZpeC53IDogMDtcbiAgICB9XG4gICAgZ2V0IF9wcmVmaXhYKCkge1xuICAgICAgICByZXR1cm4gMDtcbiAgICB9XG4gICAgZ2V0IF9oYXNUaXRsZSgpIHtcbiAgICAgICAgcmV0dXJuICEhdGhpcy50aXRsZTtcbiAgICB9XG4gICAgZ2V0IF90aXRsZVcoKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNUaXRsZSAmJiB0aGlzLl9UaXRsZSAmJiB0aGlzLl9UaXRsZS5fVGV4dCAmJiB0aGlzLl9UaXRsZS52aXNpYmxlKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fVGl0bGUudztcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gMDtcbiAgICB9XG4gICAgZ2V0IF90aXRsZVgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9oYXNQcmVmaXggPyB0aGlzLl9wcmVmaXhXICsgdGhpcy5zdHlsZS5jb250ZW50U3BhY2luZyA6IDA7XG4gICAgfVxuICAgIG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KCkge1xuICAgICAgICByZXR1cm4gWyAuLi5zdXBlci5wcm9wZXJ0aWVzLCBcImljb25XaWR0aFwiLCBcImljb25IZWlnaHRcIiwgXCJpY29uU3JjXCIgXTtcbiAgICB9XG4gICAgX3VwZGF0ZSgpIHtcbiAgICAgICAgc3VwZXIuX3VwZGF0ZSgpO1xuICAgICAgICB0aGlzLl91cGRhdGVJY29uKCk7XG4gICAgfVxuICAgIF91cGRhdGVJY29uKCkge1xuICAgICAgICB2YXIge2ljb25XaWR0aDogaWNvbldpZHRoLCBpY29uSGVpZ2h0OiBpY29uSGVpZ2h0fSA9IHRoaXMuc3R5bGU7XG4gICAgICAgIHZhciBpY29uT2JqZWN0ID0ge1xuICAgICAgICAgICAgdzogaWNvbldpZHRoLFxuICAgICAgICAgICAgaDogaWNvbkhlaWdodCxcbiAgICAgICAgICAgIGljb246IHRoaXMuaWNvblNyYyxcbiAgICAgICAgICAgIHg6IHRoaXMudyAtIGljb25XaWR0aCAtIHRoaXMuc3R5bGUucGFkZGluZ0hvcml6b250YWwsXG4gICAgICAgICAgICB5OiAodGhpcy5fVGl0bGUuc3R5bGUudGV4dFN0eWxlLmxpbmVIZWlnaHQgLSBpY29uSGVpZ2h0KSAvIDIgKyB0aGlzLnN0eWxlLnBhZGRpbmdWZXJ0aWNhbFxuICAgICAgICB9O1xuICAgICAgICBpZiAoIXRoaXMuX0ljb24pIHtcbiAgICAgICAgICAgIGljb25PYmplY3QudHlwZSA9IEljb247XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICBJY29uOiBpY29uT2JqZWN0XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfY2FsY3VsYXRlVGV4dFdpZHRoKCkge1xuICAgICAgICB2YXIgdGV4dFdpZHRoID0gdGhpcy53IC0gdGhpcy5zdHlsZS5wYWRkaW5nSG9yaXpvbnRhbCAqIDI7XG4gICAgICAgIHJldHVybiB0aGlzLmljb25TcmMgPyB0ZXh0V2l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IHcgLyAyLFxuICAgICAgICAgICAgeTogaCA9PiBoIC8gMlxuICAgICAgICB9O1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgQm9keTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICBydHQ6IHRydWVcbiAgICAgICAgICAgIH0sIGNlbnRlciksIHt9LCB7XG4gICAgICAgICAgICAgICAgQ2hlY2s6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEljb25cbiAgICAgICAgICAgICAgICB9LCBjZW50ZXIpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBhbHBoYTogMFxuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9KSxcbiAgICAgICAgICAgIFN0cm9rZTogY2VudGVyXG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJDaGVja1wiLCBcIkJvZHlcIiwgXCJTdHJva2VcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwiY2hlY2tlZFwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgYWxpYXNTdHlsZXMoKSB7XG4gICAgICAgIHJldHVybiBbIHtcbiAgICAgICAgICAgIHByZXY6IFwiY2hlY2tTcmNcIixcbiAgICAgICAgICAgIGN1cnI6IFwiaWNvblwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIHByZXY6IFwiY2hlY2tIXCIsXG4gICAgICAgICAgICBjdXJyOiBcImljb25IZWlnaHRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBwcmV2OiBcImNoZWNrV1wiLFxuICAgICAgICAgICAgY3VycjogXCJpY29uV2lkdGhcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBwcmV2OiBcImNoZWNrSGVpZ2h0XCIsXG4gICAgICAgICAgICBjdXJyOiBcImljb25IZWlnaHRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBwcmV2OiBcImNoZWNrV2lkdGhcIixcbiAgICAgICAgICAgIGN1cnI6IFwiaWNvbldpZHRoXCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVCb2R5KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVN0cm9rZSgpO1xuICAgICAgICB0aGlzLl91cGRhdGVDaGVjaygpO1xuICAgICAgICBpZiAodGhpcy5fY2hlY2tlZENoYW5nZWQpIHtcbiAgICAgICAgICAgIHRoaXMuZmlyZUFuY2VzdG9ycyhcIiRhbm5vdW5jZVwiLCB0aGlzLmFubm91bmNlKTtcbiAgICAgICAgICAgIHRoaXMuX2NoZWNrZWRDaGFuZ2VkID0gZmFsc2U7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fdXBkYXRlT3BhY2l0eSgpO1xuICAgIH1cbiAgICBfdXBkYXRlQ2hlY2soKSB7XG4gICAgICAgIHRoaXMuX0NoZWNrLnBhdGNoKHtcbiAgICAgICAgICAgIHc6IHRoaXMuc3R5bGUuaWNvbldpZHRoLFxuICAgICAgICAgICAgaDogdGhpcy5zdHlsZS5pY29uSGVpZ2h0LFxuICAgICAgICAgICAgaWNvbjogdGhpcy5zdHlsZS5pY29uLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICBjb2xvcjogdGhpcy5zdHlsZS5jaGVja0NvbG9yXG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgICB2YXIgYWxwaGFQYXRjaCA9IHtcbiAgICAgICAgICAgIGFscGhhOiB0aGlzLmNoZWNrZWQgPyAxIDogMFxuICAgICAgICB9O1xuICAgICAgICB0aGlzLmFwcGx5U21vb3RoKHRoaXMuX0NoZWNrLCBhbHBoYVBhdGNoKTtcbiAgICB9XG4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IG1vdW50WTogLjUsXG4gICAgICAgICAgICAgICAgbW91bnRYOiAuNSxcbiAgICAgICAgICAgICAgICB0ZXh0OiB7fVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiTGFiZWxcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkejtcbiAgICB9XG4gICAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gWyBcInRpdGxlXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCB0YWdzKCkge1xuICAgICAgICByZXR1cm4gWyBcIkJhY2tncm91bmRcIiwgXCJUZXh0XCIgXTtcbiAgICB9XG4gICAgX2luaXQoKSB7XG4gICAgICAgIHRoaXMuX1RleHQub24oXCJ0eExvYWRlZFwiLCB0aGlzLl91cGRhdGVCYWNrZ3JvdW5kLmJpbmQodGhpcykpO1xuICAgICAgICBzdXBlci5faW5pdCgpO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVCYWNrZ3JvdW5kKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVRleHQoKTtcbiAgICB9XG4gICAgX3VwZGF0ZVRleHQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9UZXh0KSB7XG4gICAgICAgICAgICB0aGlzLl9UZXh0LnBhdGNoKHtcbiAgICAgICAgICAgICAgICB0ZXh0OiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUudGV4dFN0eWxlKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dDogdGhpcy50aXRsZVxuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICB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AgICAgICB9XG4gICAgICAgIF9pbml0KCkge1xuICAgICAgICAgICAgc3VwZXIuX2luaXQoKTtcbiAgICAgICAgICAgIGlmICh0aGlzLl9zaG91bGRTeW5jKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fdXBkYXRlU2lnbmFscygpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIF91cGRhdGUoKSB7XG4gICAgICAgICAgICBzdXBlci5fdXBkYXRlKCk7XG4gICAgICAgICAgICBpZiAodGhpcy5fc2hvdWxkU3luYykge1xuICAgICAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVNpZ25hbHMoKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fY2xlYW51cFN5bmNWYWx1ZXMoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBfY2xlYW51cFN5bmNWYWx1ZXMoKSB7XG4gICAgICAgICAgICB0aGlzLnN5bmNBcnJheS5tYXAoKGNvbXBvbmVudCA9PiB7XG4gICAgICAgICAgICAgICAgY29tcG9uZW50Lm1hcnF1ZWVPdmVycmlkZUxvb3BYID0gdW5kZWZpbmVkO1xuICAgICAgICAgICAgICAgIGNvbXBvbmVudC5zaWduYWxzICYmIGNvbXBvbmVudC5zaWduYWxzLndpbGxNYXJxdWVlICYmIGRlbGV0ZSBjb21wb25lbnQuc2lnbmFscy53aWxsTWFycXVlZTtcbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgfVxuICAgICAgICBfdXBkYXRlU2lnbmFscygpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLnN5bmNBcnJheSkge1xuICAgICAgICAgICAgICAgIHRoaXMuc3luY0FycmF5Lm1hcCgoY29tcG9uZW50ID0+IHtcbiAgICAgICAgICAgICAgICAgICAgY29tcG9uZW50LnNpZ25hbHMgPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGNvbXBvbmVudC5zaWduYWxzKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHdpbGxNYXJxdWVlOiBcIl93aWxsTWFycXVlZVwiXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBfd2lsbE1hcnF1ZWUoY29tcFJlZikge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3Nob3VsZFN5bmMpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9sb25nZXN0TWFycXVlZVdpZHRoID0gTWF0aC5tYXgoY29tcFJlZi5fdGV4dFJlbmRlcmVkVyB8fCAwLCB0aGlzLl9sb25nZXN0TWFycXVlZVdpZHRoIHx8IDApO1xuICAgICAgICAgICAgICAgIHRoaXMuc3luY0FycmF5Lm1hcCgoY29tcG9uZW50ID0+IHtcbiAgICAgICAgICAgICAgICAgICAgY29tcG9uZW50Lm1hcnF1ZWVPdmVycmlkZUxvb3BYID0gdGhpcy5fbG9uZ2VzdE1hcnF1ZWVXaWR0aDtcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgZ2V0IF9zaG91bGRTeW5jKCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuc3R5bGUubWFycXVlZVN5bmMgPT09IGZhbHNlKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKCF0aGlzLnN5bmNBcnJheSkge1xuICAgICAgICAgICAgICAgIGxvZ2dlckluc3RhbmNlLndhcm4oXCJ3YXJuaW5nOiBjb21wb25lbnRzIHVzaW5nIE1hcnF1ZWVTeW5jIG11c3QgaGF2ZSBhIHN5bmNBcnJheSBnZXR0ZXIgZGVmaW5lZC5cIik7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgfSBlbHNlIGlmICghQXJyYXkuaXNBcnJheSh0aGl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6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBkZXRhaWxzVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgZGVzY3JpcHRpb25UZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfSxcbiAgICBpbnZlcnNlOiB7XG4gICAgICAgIHRpdGxlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHRJbnZlcnNlXG4gICAgICAgIH0sXG4gICAgICAgIHN1YnRpdGxlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHRJbnZlcnNlU2Vjb25kYXJ5XG4gICAgICAgIH0sXG4gICAgICAgIGRldGFpbHNUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dEludmVyc2VcbiAgICAgICAgfSxcbiAgICAgICAgZGVzY3JpcHRpb25UZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dEludmVyc2VTZWNvbmRhcnlcbiAgICAgICAgfSxcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZGlzYWJsZWQ6IHtcbiAgICAgICAgICAgICAgICB0aXRsZVRleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIHN1YnRpdGxlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH0sXG4gICAgYnJhbmQ6IHtcbiAgICAgICAgdGl0bGVUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxcbiAgICAgICAgfSxcbiAgICAgICAgc3VidGl0bGVUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxTZWNvbmRhcnlcbiAgICAgICAgfSxcbiAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICB9LFxuICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFNlY29uZGFyeVxuICAgICAgICB9LFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIHRpdGxlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbn0pO1xuXG52YXIgc3R5bGVzJHkgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSR5LFxuICAgIG1vZGU6IG1vZGUkOSxcbiAgICB0b25lOiB0b25lJGhcbn0pO1xuXG5jbGFzcyBNZXRhZGF0YUJhc2UgZXh0ZW5kcyBCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJNZXRhZGF0YUJhc2VcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkeTtcbiAgICB9XG4gICAgc3RhdGljIF90ZW1wbGF0ZSgpIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIFRleHQ6IHtcbiAgICAgICAgICAgICAgICBmbGV4OiB7XG4gICAgICAgICAgICAgICAgICAgIGRpcmVjdGlvbjogXCJjb2x1bW5cIixcbiAgICAgICAgICAgICAgICAgICAganVzdGlmeUNvbnRlbnQ6IFwiZmxleC1zdGFydFwiXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBEZXRhaWxzV3JhcHBlcjoge31cbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gWyBcImRlc2NyaXB0aW9uXCIsIFwibG9nb1wiLCBcImxvZ29IZWlnaHRcIiwgXCJsb2dvUG9zaXRpb25cIiwgXCJsb2dvVGl0bGVcIiwgXCJsb2dvV2lkdGhcIiwgXCJkZXRhaWxzXCIsIFwic3VidGl0bGVcIiwgXCJ0aXRsZVwiLCBcIm1hcnF1ZWVcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIFwiVGV4dFwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIlRpdGxlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHQuVGl0bGVcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlN1YnRpdGxlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHQuU3VidGl0bGVcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIkRldGFpbHNXcmFwcGVyXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHQuRGV0YWlsc1dyYXBwZXJcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIkRldGFpbHNcIixcbiAgICAgICAgICAgIHBhdGg6IFwiVGV4dC5EZXRhaWxzV3JhcHBlci5EZXRhaWxzXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJEZXNjcmlwdGlvblwiLFxuICAgICAgICAgICAgcGF0aDogXCJUZXh0LkRlc2NyaXB0aW9uXCJcbiAgICAgICAgfSwgXCJMb2dvXCIg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0aGlzLl9UaXRsZSkge1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIGlmICghdGhpcy5fVGl0bGUpIHtcbiAgICAgICAgICAgIHRoaXMuX1RleHQuY2hpbGRMaXN0LmFkZEF0KHtcbiAgICAgICAgICAgICAgICByZWY6IFwiVGl0bGVcIixcbiAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3RpdGxlTG9hZGVkXCJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LCAwKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9UaXRsZS5wYXRjaCh7XG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLnRpdGxlLFxuICAgICAgICAgICAgbWFycXVlZTogdGhpcy5tYXJxdWVlLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS50aXRsZVRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIG1heExpbmVzOiAxLFxuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogdGhpcy5fVGV4dC53XG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVTdWJ0aXRsZSgpIHtcbiAgICAgICAgaWYgKCF0aGlzLnN1YnRpdGxlICYmICF0aGlzLl9TdWJ0aXRsZSkge1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIGlmICghdGhpcy5fU3VidGl0bGUpIHtcbiAgICAgICAgICAgIHRoaXMuX1RleHQuY2hpbGRMaXN0LmFkZEF0KHtcbiAgICAgICAgICAgICAgICByZWY6IFwiU3VidGl0bGVcIixcbiAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3N1YnRpdGxlTG9hZGVkXCJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LCAxKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9TdWJ0aXRsZS5wYXRjaCh7XG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLnN1YnRpdGxlLFxuICAgICAgICAgICAgbWFycXVlZTogdGhpcy5tYXJxdWVlLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS5zdWJ0aXRsZVRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIG1heExpbmVzOiAxLFxuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogdGhpcy5fVGV4dC53XG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIHJlc2V0TWFycXVlZSgpIHtcbiAgICAgICAgaWYgKHRoaXMubWFycXVlZSkge1xuICAgICAgICAgICAgaWYgKHRoaXMudGl0bGUpIHtcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuX1RpdGxlKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVRpdGxlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHRoaXMuX1RpdGxlLnRvZ2dsZU1hcnF1ZWUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLmRlc2NyaXB0aW9uKSB7XG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLl9EZXNjcmlwdGlvbikge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVEZXNjcmlwdGlvbigpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0aGlzLl9EZXNjcmlwdGlvbi50b2dnbGVNYXJxdWVlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZURldGFpbHMoKSB7XG4gICAgICAgIGlmICghdGhpcy5kZXRhaWxzICYmICF0aGlzLl9EZXRhaWxzKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLl9EZXRhaWxzKSB7XG4gICAgICAgICAgICB0aGlzLl9EZXRhaWxzV3JhcHBlci5wYXRjaCh7XG4gICAgICAgICAgICAgICAgRGV0YWlsczoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0Qm94Q2hhbmdlZDogXCJfZGV0YWlsc0xvYWRlZFwiXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9EZXRhaWxzLnBhdGNoKHtcbiAgICAgICAgICAgIGNvbnRlbnQ6IHRoaXMuZGV0YWlscyxcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB0aGlzLnN0eWxlLmRldGFpbHNUZXh0U3R5bGVcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIGlmICh0aGlzLl9EZXRhaWxzLmZpbmFsVyA+IHRoaXMuX3RleHRXKCkpIHtcbiAgICAgICAgICAgIHRoaXMuX0RldGFpbHMucGF0Y2goe1xuICAgICAgICAgICAgICAgIHc6IHRoaXMuX3RleHRXKCkgKyB0aGlzLnN0eWxlLmZhZGVXaWR0aCAvIDIsXG4gICAgICAgICAgICAgICAgc2hhZGVyOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEZhZGVTaGFkZXIsXG4gICAgICAgICAgICAgICAgICAgIHBvc2l0aW9uTGVmdDogMCxcbiAgICAgICAgICAgICAgICAgICAgcG9zaXRpb25SaWdodDogdGhpcy5zdHlsZS5mYWRlV2lkdGhcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIHJ0dDogdHJ1ZVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9EZXRhaWxzV3JhcHBlci5zaGFkZXIgPSB1bmRlZmluZWQ7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fRGV0YWlsc1dyYXBwZXIudmlzaWJsZSA9IHRoaXMuZGV0YWlscyA/IHRydWUgOiBmYWxzZTtcbiAgICAgICAgdGhpcy5fRGV0YWlsc1dyYXBwZXIuYWxwaGEgPSB0aGlzLnN0eWxlLmFscGhhO1xuICAgIH1cbiAgICBfdXBkYXRlRGVzY3JpcHRpb24oKSB7XG4gICAgICAgIGlmICghdGhpcy5kZXNjcmlwdGlvbiAmJiAhdGhpcy5fRGVzY3JpcHRpb24pIHtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICBpZiAoIXRoaXMuX0Rlc2NyaXB0aW9uKSB7XG4gICAgICAgICAgICB0aGlzLl9UZXh0LmNoaWxkTGlzdC5hZGQoe1xuICAgICAgICAgICAgICAgIHJlZjogXCJEZXNjcmlwdGlvblwiLFxuICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Qm94Q2hhbmdlZDogXCJfZGVzY3JpcHRpb25Mb2FkZWRcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX0Rlc2NyaXB0aW9uLnBhdGNoKHtcbiAgICAgICAgICAgIGNvbnRlbnQ6IHRoaXMuZGVzY3JpcHRpb24sXG4gICAgICAgICAgICBtYXJxdWVlOiB0aGlzLm1hcnF1ZWUsXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlLmRlc2NyaXB0aW9uVGV4dFN0eWxlKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgbWF4TGluZXM6IDEsXG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcFdpZHRoOiB0aGlzLl9UZXh0LndcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZUxvZ28oKSB7XG4gICAgICAgIGlmICghdGhpcy5sb2dvICYmICF0aGlzLl9Mb2dvKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLl9Mb2dvKSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBMb2dvOiB7XG4gICAgICAgICAgICAgICAgICAgIGZsZXhJdGVtOiBmYWxzZSxcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogSWNvblxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMubG9nb1Bvc2l0aW9uID0gdGhpcy5sb2dvUG9zaXRpb24gfHwgXCJyaWdodFwiO1xuICAgICAgICB2YXIgc3VidGl0bGVIID0gdGhpcy5zdWJ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AgICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0SW52ZXJzZVNlY29uZGFyeVxuICAgICAgICB9LFxuICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0SW52ZXJzZVxuICAgICAgICB9LFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIGRldGFpbHNUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGJyYW5kOiB7XG4gICAgICAgIGRldGFpbHNUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxTZWNvbmRhcnlcbiAgICAgICAgfSxcbiAgICAgICAgZGVzY3JpcHRpb25UZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxcbiAgICAgICAgfSxcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZGlzYWJsZWQ6IHtcbiAgICAgICAgICAgICAgICBkZXRhaWxzVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgZGVzY3JpcHRpb25UZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMkeCA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJHgsXG4gICAgdG9uZTogdG9uZSRnXG59KTtcblxuY2xhc3MgTWV0YWRhdGFUaWxlIGV4dGVuZHMgTWV0YWRhdGFCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJNZXRhZGF0YVRpbGVcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkeDtcbiAgICB9XG4gICAgX3VwZGF0ZURldGFpbHMoKSB7XG4gICAgICAgIGlmICghdGhpcy5kZXRhaWxzICYmICF0aGlzLl9EZXRhaWxzKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuZGVzY3JpcHRpb24gJiYgdGhpcy5fRGV0YWlscykge1xuICAgICAgICAgICAgdGhpcy5fRGV0YWlscy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgY29udGVudDogXCJcIlxuICAgICAgICAgICAgfSk7XG4gICAgICA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gICAgIH1cbiAgICAgICAgfVxuICAgIH1cbn0pO1xuXG52YXIgbW9kZSQ4ID0gdGhlbWUgPT4gKHtcbiAgICBkaXNhYmxlZDoge1xuICAgICAgICBhbHBoYTogdGhlbWUuYWxwaGEuaW5hY3RpdmVcbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyR2ID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkdixcbiAgICBtb2RlOiBtb2RlJDgsXG4gICAgdG9uZTogdG9uZSRlXG59KTtcblxuY2xhc3MgVGlsZSBleHRlbmRzIFN1cmZhY2Uge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJUaWxlXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJHY7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHN1cGVyLl90ZW1wbGF0ZSgpKSwge30sIHtcbiAgICAgICAgICAgIFRpbGU6IHtcbiAgICAgICAgICAgICAgICBBcnR3b3JrOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEFydHdvcmssXG4gICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlTG9hZGVkOiBcIl9pbWFnZUxvYWRlZFwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIG1vdW50OiAuNVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgQ29udGVudDoge1xuICAgICAgICAgICAgICAgICAgICBtb3VudDogLjVcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwiYXJ0d29ya1wiLCBcImJhZGdlXCIsIFwiY2hlY2tib3hcIiwgXCJjaXJjbGVcIiwgXCJsYWJlbFwiLCBcImxvZ29cIiwgXCJtZXRhZGF0YVwiLCBcIm1ldGFkYXRhTG9jYXRpb25cIiwgXCJwZXJzaXN0ZW50TWV0YWRhdGFcIiwgXCJwcm9ncmVzc0JhclwiLCBcInNyY1wiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgYWxpYXNTdHlsZXMoKSB7XG4gICAgICAgIHJldHVybiBbIHtcbiAgICAgICAgICAgIHByZXY6IFwiaWNvbkhlaWdodFwiLFxuICAgICAgICAgICAgY3VycjogXCJsb2dvSGVpZ2h0XCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgcHJldjogXCJpY29uV2lkdGhcIixcbiAgICAgICAgICAgIGN1cnI6IFwibG9nb1dpZHRoXCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IGFsaWFzUHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsge1xuICAgICAgICAgICAgcHJldjogXCJpY29uU3JjXCIsXG4gICAgICAgICAgICBjdXJyOiBcImxvZ29cIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIudGFncywgXCJBcnR3b3JrXCIsIFwiQ29udGVudFwiLCBcIlRpbGVcIiwge1xuICAgICAgICAgICAgbmFtZTogXCJCYWRnZVwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50LkJhZGdlXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJDaGVja2JveFwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50LkNoZWNrYm94XCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmF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AgICAgIHJldHVybiBhY2M7XG4gICAgICAgIH0pLCB7fSkpO1xuICAgIH1cbiAgICBfdXBkYXRlTG9nbygpIHtcbiAgICAgICAgaWYgKCF0aGlzLmxvZ28pIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIExvZ286IHVuZGVmaW5lZFxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgdmFyIGxvZ29PYmplY3QgPSB7XG4gICAgICAgICAgICB3OiB0aGlzLnN0eWxlLmxvZ29XaWR0aCxcbiAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUubG9nb0hlaWdodCxcbiAgICAgICAgICAgIGljb246IHRoaXMubG9nbyxcbiAgICAgICAgICAgIGFscGhhOiB0aGlzLl9zaG91bGRTaG93TG9nbyA/IHRoaXMuc3R5bGUuYWxwaGEgOiAuMDAxLFxuICAgICAgICAgICAgeDogdGhpcy5zdHlsZS5wYWRkaW5nWCxcbiAgICAgICAgICAgIHk6IHRoaXMuX2NhbGN1bGF0ZUxvZ29ZUG9zaXRpb24oKVxuICAgICAgICB9O1xuICAgICAgICBpZiAoIXRoaXMuX0xvZ28pIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIExvZ286IF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IDFcbiAgICAgICAgICAgICAgICB9LCBsb2dvT2JqZWN0KVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmFwcGx5U21vb3RoKHRoaXMuX0xvZ28sIGxvZ29PYmplY3QpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9jYWxjdWxhdGVMb2dvWVBvc2l0aW9uKCkge1xuICAgICAgICBpZiAodGhpcy5faXNJbnNldE1ldGFkYXRhICY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aGlzLl9pc0NpcmNsZUxheW91dCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX0xhYmVsKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIExhYmVsOiB1bmRlZmluZWRcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICB2YXIgbGFiZWxQYXRjaCA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5sYWJlbCksIHt9LCB7XG4gICAgICAgICAgICBtb2RlOiB0aGlzLm1vZGUsXG4gICAgICAgICAgICB4OiB0aGlzLl93IC0gdGhpcy5zdHlsZS5wYWRkaW5nWCxcbiAgICAgICAgICAgIHk6IHRoaXMuc3R5bGUucGFkZGluZ1ksXG4gICAgICAgICAgICBhbHBoYTogdGhpcy5fc2hvdWxkU2hvd0JhZGdlTGFiZWwgPyAxIDogLjAwMVxuICAgICAgICB9KTtcbiAgICAgICAgaWYgKCF0aGlzLl9MYWJlbCkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgTGFiZWw6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IExhYmVsLFxuICAgICAgICAgICAgICAgICAgICBtb3VudFg6IDFcbiAgICAgICAgICAgICAgICB9LCBsYWJlbFBhdGNoKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgbG9hZGVkTGFiZWw6IFwiX3VwZGF0ZUxhYmVsXCJcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfSBlbHNlIHtcbiAgICA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Gl0IF1cbiAgICAgICAgfTtcbiAgICB9XG4gICAgX3VwZGF0ZUNoZWNrYm94KCkge1xuICAgICAgICB2YXIgX3RoaXMkY2hlY2tib3g7XG4gICAgICAgIGlmICghKHR5cGVvZiAoKF90aGlzJGNoZWNrYm94ID0gdGhpcy5jaGVja2JveCkgPT09IG51bGwgfHwgX3RoaXMkY2hlY2tib3ggPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJGNoZWNrYm94LmNoZWNrZWQpID09PSBcImJvb2xlYW5cIiAmJiB0aGlzLmNoZWNrYm94LmNoZWNrZWQpIHx8IHRoaXMuX2lzQ2lyY2xlTGF5b3V0KSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fQ2hlY2tib3gpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgQ2hlY2tib3g6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHZhciBjaGVja2JveFBhdGNoID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLmNoZWNrYm94KSwge30sIHtcbiAgICAgICAgICAgIG1vZGU6IHRoaXMubW9kZSxcbiAgICAgICAgICAgIHg6IHRoaXMuX3cgLSB0aGlzLnN0eWxlLnBhZGRpbmdYLFxuICAgICAgICAgICAgeTogdGhpcy5faCAtIHRoaXMuc3R5bGUucGFkZGluZ1lcbiAgICAgICAgfSk7XG4gICAgICAgIGlmICghdGhpcy5fQ2hlY2tib3gpIHtcbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgIENoZWNrYm94OiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGNoZWNrYm94UGF0Y2gpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOi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5pc2hcIiwgKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlbW92ZVByb2dyZXNzQmFyKCk7XG4gICAgICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fUHJvZ3Jlc3NCYXIuc21vb3RoID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgYWxwaGE6IDBcbiAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZW1vdmVQcm9ncmVzc0JhcigpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5wcm9ncmVzc0Jhci5wcm9ncmVzcyA+IDApIHtcbiAgICAgICAgICAgIHZhciBwcm9ncmVzc1BhdGNoID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnByb2dyZXNzQmFyKSwge30sIHtcbiAgICAgICAgICAgICAgICBtb2RlOiB0aGlzLm1vZGUsXG4gICAgICAgICAgICAgICAgdzogdGhpcy5fdyAtIHRoaXMuc3R5bGUucGFkZGluZ1ggKiAyLFxuICAgICAgICAgICAgICAgIHg6IHRoaXMuX3cgLyAyLFxuICAgICAgICAgICAgICAgIHk6IHRoaXMuX2ggLSB0aGlzLnN0eWxlLnBhZGRpbmdZUHJvZ3Jlc3NcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9Qcm9ncmVzc0Jhcikge1xuICAgICAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICBQcm9ncmVzc0JhcjogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBwcm9ncmVzc1BhdGNoKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFByb2dyZXNzQmFyLFxuICAgICAgICAgICAgICAgICAgICAgICAgbW91bnRYOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgICAgIG1vdW50WTogMSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGFscGhhOiB0aGlzLl9oYXNNZXRhZGF0YSAmJiB0aGlzLnNob3VsZFNtb290aCA/IC4wMDEgOiAxXG4gICAgICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuc2hvdWxkU21vb3RoKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX1Byb2dyZXNzQmFyLnNtb290aCA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGFscGhhOiBbIDEsIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWxheTogdGhpcy5zdHlsZS5hbmltYXRpb25FbnRyYW5jZS5kdXJhdGlvblxuICAgICAgICAgICAgICAgICAgICAgICAgfSBdXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuYXBwbHlTbW9vdGgodGhpcy5fUHJvZ3Jlc3NCYXIsIHByb2dyZXNzUGF0Y2gsIE9iamVjdC5rZXlzKHByb2dyZXNzUGF0Y2gpLnJlZHVjZSgoKGFjYywgcHJvcCkgPT4ge1xuICAgICAgICAgICAgICAgIGFjY1twcm9wXSA9IFsgcHJvZ3Jlc3NQYXRjaFtwcm9wXSwgdGhpcy5faXNGb2N1c2VkTW9kZSA/IHRoaXMuc3R5bGUuYW5pbWF0aW9uRW50cmFuY2UgOiB0aGlzLnN0eWxlLmFuaW1hdGlvbkV4aXQgXTtcbiAgICAgICAgICAgICAgICByZXR1cm4gYWNjO1xuICAgICAgICAgICAgfSksIHt9KSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3JlbW92ZV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AgICAgICAgICAgIG1vZGU6IHRoaXMubW9kZSxcbiAgICAgICAgICAgIG1vdW50WDogLjUsXG4gICAgICAgICAgICBtb3VudFk6IHRoaXMuX2lzSW5zZXRNZXRhZGF0YSA/IDEgOiAwLFxuICAgICAgICAgICAgbWFycXVlZTogdGhpcy5faXNGb2N1c2VkTW9kZVxuICAgICAgICB9LCB0aGlzLm1ldGFkYXRhIHx8IHt9KTtcbiAgICB9XG4gICAgX2dldE1ldGFkYXRhTG9jYXRpb24oKSB7XG4gICAgICAgIHZhciBfdGhpcyRfbWV0YWRhdGFMb2NhdGk7XG4gICAgICAgIHJldHVybiAoX3RoaXMkX21ldGFkYXRhTG9jYXRpID0gdGhpcy5fbWV0YWRhdGFMb2NhdGlvbikgIT09IG51bGwgJiYgX3RoaXMkX21ldGFkYXRhTG9jYXRpICE9PSB2b2lkIDAgPyBfdGhpcyRfbWV0YWRhdGFMb2NhdGkgOiB0aGlzLnN0eWxlLm1ldGFkYXRhTG9jYXRpb247XG4gICAgfVxuICAgIF91cGRhdGVNZXRhZGF0YSgpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9oYXNNZXRhZGF0YSkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgTWV0YWRhdGE6IHVuZGVmaW5lZFxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLl9NZXRhZGF0YSAmJiB0aGlzLl9oYXNNZXRhZGF0YSkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgTWV0YWRhdGE6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IE1ldGFkYXRhVGlsZSxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdX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IH1cbiAgICBnZXQgcHJvdmlkZXJzSGlkZGVuKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5wcm92aWRlcnMubGVuZ3RoIC0gdGhpcy5fdmlzaWJsZUNvdW50O1xuICAgIH1cbiAgICBfY29uc3RydWN0KCkge1xuICAgICAgICB0aGlzLl9wcm92aWRlcnMgPSBbXTtcbiAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCgpO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVQcm92aWRlcnMoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlQ291bnRlcigpO1xuICAgIH1cbiAgICBfdXBkYXRlUHJvdmlkZXJzKCkge1xuICAgICAgICB2YXIgcHJvdmlkZXJMaXN0ID0gW107XG4gICAgICAgIHRoaXMucHJvdmlkZXJzLnNsaWNlKDAsIHRoaXMudmlzaWJsZUNvdW50KS5mb3JFYWNoKChwcm92aWRlciA9PiB7XG4gICAgICAgICAgICB2YXIgcGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgY2VudGVySW5QYXJlbnQ6IHRydWUsXG4gICAgICAgICAgICAgICAgcmFkaXVzOiB0aGlzLmRpc2FibGVSYWRpdXMgPyAwIDogZ2V0TWF4Um91bmRSYWRpdXModGhpcy5zdHlsZS5yYWRpdXMsIHRoaXMuc3R5bGUuaXRlbVNpemUsIHRoaXMuc3R5bGUuaXRlbVNpemUpLFxuICAgICAgICAgICAgICAgIGFscGhhOiB0aGlzLnN0eWxlLmFscGhhLFxuICAgICAgICAgICAgICAgIHN0eWxlOiBwcm92aWRlci5zdHlsZSB8fCB7fVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmIChwcm92aWRlci50eXBlID09PSBJY29uICYmIHByb3ZpZGVyLmljb24gJiYgcHJvdmlkZXIudyAmJiBwcm92aWRlci5oKSB7XG4gICAgICAgICAgICAgICAgdmFyIHJhdGlvID0gcHJvdmlkZXIudyAvIHByb3ZpZGVyLmg7XG4gICAgICAgICAgICAgICAgcGF0Y2ggPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgICAgICBpY29uOiBwcm92aWRlci5pY29uXG4gICAgICAgICAgICAgICAgfSwgcHJvdmlkZXIpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLnN0eWxlLml0ZW1TaXplICogcmF0aW8sXG4gICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuaXRlbVNpemVcbiAgICAgICAgICAgICAgICB9LCBwYXRjaCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHBhdGNoID0gX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEljb24sXG4gICAgICAgICAgICAgICAgICAgIHc6IHRoaXMuc3R5bGUuaXRlbVNpemUsXG4gICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuaXRlbVNpemVcbiAgICAgICAgICAgICAgICB9LCBwYXRjaCk7XG4gICAgICAgICAgICAgICAgaWYgKHR5cGVvZiBwcm92aWRlciA9PT0gXCJvYmplY3RcIikge1xuICAgICAgICAgICAgICAgICAgICBwYXRjaCA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgcGF0Y2gpLCBwcm92aWRlcik7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcGF0Y2guaWNvbiA9IHByb3ZpZGVyO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHByb3ZpZGVyTGlzdC5wdXNoKHBhdGNoKTtcbiAgICAgICAgfSkpO1xuICAgICAgICB0aGlzLl9Sb3cucGF0Y2goe1xuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICBpdGVtU3BhY2luZzogdGhpcy5zdHlsZS5pdGVtU3BhY2luZ1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGl0ZW1zOiBwcm92aWRlckxpc3QsXG4gICAgICAgICAgICBoOiB0aGlzLnN0eWxlLml0ZW1TaXplXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlQ291bnRlcigpIHtcbiAgICAgICAgaWYgKHRoaXMucHJvdmlkZXJzLmxlbmd0aCA+IHRoaXMudmlzaWJsZUNvdW50KSB7XG4gICAgICAgICAgICB2YXIgcmVtYWluaW5nID0gdGhpcy5wcm92aWRlcnNIaWRkZW47XG4gICAgICAgICAgICB2YXIgY291bnRlciA9IHtcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCIrXCIuY29uY2F0KHJlbWFpbmluZyksXG4gICAgICAgICAgICAgICAgYWxwaGE6IHRoaXMuc3R5bGUuYWxwaGEsXG4gICAgICAgICAgICAgICAgdzogdGhpcy5zdHlsZS5pdGVtU2l6ZSxcbiAgICAgICAgICAgICAgICBoOiB0aGlzLnN0eWxlLml0ZW1TaXplLFxuICAgICAgICAgICAgICAgIGNlbnRlckluUGFyZW50OiB0cnVlLFxuICAgICAgICAgICAgICAgIEJhY2tncm91bmQ6IHtcbiAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5zdHlsZS5pdGVtU2l6ZSxcbiAgICAgICAgICAgICAgICAgICAgaDogdGhpcy5zdHlsZS5pdGVtU2l6ZSxcbiAgICAgICAgICAgICAgICAgICAgdGV4dHVyZTogbG5nLlRvb2xzLmdldFJvdW5kUmVjdCh0aGlzLnN0eWxlLml0ZW1TaXplLCB0aGlzLnN0eWxlLml0ZW1TaXplLCBnZXRNYXhSb3VuZFJhZGl1cyh0aGlzLnN0eWxlLnJhZGl1cywgdGhpcy5zdHlsZS5pdGVtU2l6ZSwgdGhpcy5zdHlsZS5pdGVtU2l6ZSksIDAsIG51bGwsIHRydWUsIHRoaXMuc3R5bGUuY291bnRlckJhY2tncm91bmRDb2xvcilcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIFRleHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgbW91bnRYOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgeDogdGhpcy5zdHlsZS5pdGVtU2l6ZSAvIDIsXG4gICAgICAgICAgICAgICAgICAgIHk6IHRoaXMuc3R5bGUuaXRlbVNpemUgLyAyLFxuICAgICAgICAgICAgICAgICAgICBjb250ZW50OiB0aGlzLmNvdW50ZXJUZXh0IHx8IFwiK1wiLmNvbmNhdChyZW1haW5pbmcpLFxuICAgICAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB0aGlzLnN0eWxlLmNvdW50ZXJUZXh0U3R5bGVcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICB0aGlzLl9Sb3cuYXBwZW5kSXRlbXMoWyBjb3VudGVyIF0pO1xuICAgICAgICB9XG4gICAgfVxuICAgICRpdGVtQ2hhbmdlZCgpIHtcbiAgICAgICAgdGhpcy5zaWduYWwoXCJwcm92aWRlckNoYW5nZWRcIik7XG4gICAgfVxuICAgIF9nZXRWaXNpYmxlQ291bnQoKSB7XG4gICAgICAgIHZhciBtaW4gPSAxO1xuICAgICAgICB2YXIgbWF4ID0gdGhpcy5wcm92aWRlcnMubGVuZ3RoO1xuICAgICAgICB2YXIgdmlzaWJsZUNvdW50ID0gTWF0aC5taW4oTWF0aC5tYXgobWluLCB0aGlzLl92aXNpYmxlQ291bnQpLCBtYXgpO1xuICAgICAgICBpZiAodGhpcy5fdmlzaWJsZUNvdW50IDwgbWluKSB7XG4gICAgICAgICAgICBjb25zb2xlLndhcm4oXCJXYXJuaW5nOiBUaGUgc3BlY2lmaWVkI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TGluZXM6IDNcbiAgICB9LFxuICAgIGRlc2NyaXB0aW9uRGV0YWlsc1N0eWxlOiB7XG4gICAgICAgIHBhZGRpbmdZOiA1XG4gICAgfSxcbiAgICBmYWRlV2lkdGg6IHRoZW1lLnNwYWNlci5tZCAqIHRoZW1lLnNwYWNlci5tZCxcbiAgICBwcm92aWRlcjoge1xuICAgICAgICBpdGVtU2l6ZTogdGhlbWUuc3BhY2VyLnh4eGwgKyB0aGVtZS5zcGFjZXIubWRcbiAgICB9XG59KTtcblxudmFyIHRvbmUkYyA9IHRoZW1lID0+ICh7XG4gICAgbmV1dHJhbDoge1xuICAgICAgICBkZXRhaWxzVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgICAgIH0sXG4gICAgICAgIG1vZGU6IHtcbiAgICAgICAgICAgIGRpc2FibGVkOiB7XG4gICAgICAgICAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0SW52ZXJzZVxuICAgICAgICB9LFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIGRldGFpbHNUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfSxcbiAgICBicmFuZDoge1xuICAgICAgICBkZXRhaWxzVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgICAgIH0sXG4gICAgICAgIG1vZGU6IHtcbiAgICAgICAgICAgIGRpc2FibGVkOiB7XG4gICAgICAgICAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyR0ID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkdCxcbiAgICB0b25lOiB0b25lJGNcbn0pO1xuXG5jbGFzcyBNZXRhZGF0YUNhcmRDb250ZW50IGV4dGVuZHMgTWV0YWRhdGFCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJNZXRhZGF0YUNhcmRDb250ZW50XCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJHQ7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBUZXh0OiB7XG4gICAgICAgICAgICAgICAgZmxleDoge1xuICAgICAgICAgICAgICAgICAgICBkaXJlY3Rpb246IFwiY29sdW1uXCIsXG4gICAgICAgICAgICAgICAgICAgIGp1c3RpZnlDb250ZW50OiBcImZsZXgtc3RhcnRcIlxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgVGl0bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgU3VidGl0bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgRGVzY3JpcHRpb246IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgRGVzY3JpcHRpb25EZXRhaWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3hcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgRGV0YWlsc1dyYXBwZXI6IHtcbiAgICAgICAgICAgICAgICBEZXRhaWxzRmFkZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgRGV0YWlsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3Jlc29sdmVEZXRhaWxzXCJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgUHJvdmlkZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgbW91bnQ6IDEsXG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IFByb3ZpZGVyLFxuICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBwcm92aWRlckNoYW5nZWQ6IFwiX3Jlc29sdmVQcm92aWRlclwiXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJkZXNjcmlwdGlvblwiLCBcImRlc2NyaXB0aW9uRGV0YWlsc1wiLCBcImRldGFpbHNcIiwgXCJwcm92aWRlclwiLCBcInN1YnRpdGxlXCIsIFwidGl0bGVcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIFwiVGV4dFwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIlRpdGxlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHQuVGl0bGVcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlN1YnRpdGxlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHQuU3VidGl0bGVcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIkRlc2NyaXB0aW9uXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHQuRGVzY3JpcHRpb25cIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIkRlc2NyaXB0aW9uRGV0YWlsc1wiLFxuICAgICAgICAgICAgcGF0aDogXCJUZXh0LkRlc2NyaXB0aW9uRGV0YWlsc1wiXG4gICAgICAgIH0sIFwiRGV0YWlsc1dyYXBwZXJcIiwge1xuICAgICAgICAgICAgbmFtZTogXCJEZXRhaWxzRmFkZXJcIixcbiAgICAgICAgICAgIHBhdGg6IFwiRGV0YWlsc1dyYXBwZXIuRGV0YWlsc0ZhZGVyXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJEZXRhaWxzXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkRldGFpbHNXcmFwcGVyLkRldGFpbHNGYWRlci5EZXRhaWxzXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJQcm92aWRlclwiLFxuICAgICAgICAgICAgcGF0aDogXCJEZXRhaWxzV3JhcHBlci5Qcm92aWRlclwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgX3NldERldGFpbHMoZGV0YWlscykge1xuICAgICAgICBpZiAoZGV0YWlscykge1xuICAgICAgICAgICAgdGhpcy5fZGV0YWlsc1Byb21pc2UgPSBuZXcgUHJvbWlzZSgocmVzb2x2ZSA9PiB7XG4gICAgICAgICAgICAgICAgdGhpcy5fZGV0YWlsc1Byb21pc2VSZXNvbHZlciA9IHJlc29sdmU7XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9kZXRhaWxzUHJvbWlzZSA9IHVuZGVmaW5lZDtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZGV0YWlscztcbiAgICB9XG4gICAgX3NldFByb3ZpZGVyKHByb3ZpZGVyKSB7XG4gICAgICAgIGlmIChwcm92aWRlcikge1xuICAgICAgICAgICAgdGhpcy5fcHJvdmlkZXJQcm9taXNlID0gbmV3IFByb21pc2UoKHJlc29sdmUgPT4ge1xuICAgICAgICAgICAgICAgIHRoaXMuX3Byb3ZpZGVyUHJvbWlzZVJlc29sdmVyID0gcmVzb2x2ZTtcbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX3Byb3ZpZGVyUHJvbWlzZSA9IHVuZGVmaW5lZDtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gcHJvdmlkZXI7XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIHZhciBfdGhpczkgPSB0aGlzO1xuICAgICAgICByZXR1cm4gX2FzeW5jVG9HZW5lcmF0b3IoKGZ1bmN0aW9uKigpIHtcbiAgICAgICAgICAgIF90aGlzOS5fdXBkYXRlTGluZXMoKTtcbiAgICAgICAgICAgIF90aGlzOS5fdXBkYXRlUHJvdmlkZXIoKTtcbiAgICAgICAgICAgIHlpZWxkIFByb21pc2UuYWxsKFsgX3RoaXM5Ll9kZXRhaWxzUHJvbWlzZSwgX3RoaXM5Ll9wcm92aWRlclByb21pc2UgXS5maWx0ZXIoQm9vbGVhbikpO1xuICAgICAgICAgICAgX3RoaXM5Ll91cGRhdGVQb3NpdGlvbnMoKTtcbiAgICAgICAgfSkpKCk7XG4gICAgfVxuICAgIF91cGRhdGVMaW5lcygpIHtcbiAgICAgICAgdGhpcy5fVGV4dC53ID0gdGhpcy53O1xuICAgICAgICB0aGlzLl91cGRhdGVUaXRsZSgpO1xuICAgICAgICB0aGlzLl91cGRhdGVTdWJ0aXRsZSgpO1xuICAgICAgICB0aGlzLl91cGRhdGVEZXNjcmlwdGlvbigpO1xuICAgICAgICB0aGlzLl91cGRhdGVEZXNjcmlwdGlvbkRldGFpbHMoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlRGV0YWlscygpO1xuICAgIH1cbiAgICBfdXBkYXRlU3VidGl0bGUoKSB7XG4gICAgICAgIGlmICghdGhpcy5zdWJ0aXRsZSAmJiAhdGhpcy5fU3VidGl0bGUpIHtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICBpZiAoIXRoaXMuX1N1YnRpdGxlKSB7XG4gICAgICAgICAgICB0aGlzLl9UZXh0LmNoaWxkTGlzdC5hZGRBdCh7XG4gICAgICAgICAgICAgICAgcmVmOiBcIlN1YnRpdGxlXCIsXG4gICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveFxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fU3VidGl0bGUucGF0Y2goe1xuICAgICAgICAgICAgY29udGVudDogdGhpcy5zdWJ0aXRsZSxcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUuc3VidGl0bGVUZXh0U3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBtYXhMaW5lczogMSxcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXA6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuX1RleHQud1xuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlRGVzY3JpcHRpb24oKSB7XG4gICAgICAgIHRoaXMuX0Rlc2NyaXB0aW9uLnBhdGNoKHtcbiAgICAgICAgICAgIGNvbnRlbnQ6IHRoaXMuZGVzY3JpcHRpb24sXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlLmRlc2NyaXB0aW9uVGV4dFN0eWxlKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXA6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuX1RleHQud1xuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlRGVzY3JpcHRpb25EZXRhaWxzKCkge1xuICAgICAgICB0aGlzLl9EZXNjcmlwdGlvbkRldGFpbHMucGF0Y2goe1xuICAgICAgICAgICAgY29udGVudDogdGhpcy5kZXNjcmlwdGlvbkRldGFpbHMsXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlLmRlc2NyaXB0aW9uRGV0YWlsc1RleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIG1heExpbmVzOiAxLFxuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogdGhpcy5fVGV4dC53XG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICB5OiB0aGlzLnN0eWxlLmRlc2NyaXB0aW9uRGV0YWlsc1N0eWxlLnBhZGRpbmdZXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlRGV0YWlscygpIHtcbiAgICAgICAgdmFyIG1heFdpZHRoID0gdGhpcy5fZGV0YWlsc01heFc7XG4gICAgICAgIHRoaXMuX0RldGFpbHMucGF0Y2goe1xuICAgICAgICAgICAgY29udGVudDogdGhpcy5kZXRhaWxzLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS5kZXRhaWxzVGV4dFN0eWxlKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXA6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIG1heExpbmVzOiAxLFxuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcFdpZHRoOiBtYXhXaWR0aCArIHRoaXMuc3R5bGUuZmFkZVdpZHRoIC8gMlxuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgICBpZiAodGhpcy5fRGV0YWlscy5maW5hbFcgPiBtYXhXaWR0aCkge1xuICAgICAgICAgICAgdGhpcy5fRGV0YWlsc0ZhZGVyLnBhdGNoKHtcbiAgICAgICAgICAgICAgICB3OiBtYXhXaWR0aCArIHRoaXMuc3R5bGUuZmFkZVdpZHRoIC8gMixcbiAgICAgICAgICAgICAgICBzaGFkZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogRmFkZVNoYWRlcixcbiAgICAgICAgICAgICAgICAgICAgcG9zaXRpb25MZWZ0OiAwLFxuICAgICAgICAgICAgICAgICAgICBwb3NpdGlvblJpZ2h0OiB0aGlzLnN0eWxlLmZhZ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em9udGFsXCIgPyBbIHJhZGl1c1swXSwgMCwgMCwgcmFkaXVzWzNdIF0gOiBbIHJhZGl1c1swXSwgcmFkaXVzWzFdLCAwLCAwIF07XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX29yaWVudGF0aW9uICE9PSBcImhvcml6b250YWxcIikge1xuICAgICAgICAgICAgdyA9IHRoaXMuc3R5bGUuZXhwYW5kZWRXaWR0aDtcbiAgICAgICAgICAgIGggPSB0aGlzLnN0eWxlLmltYWdlU2l6ZS5oO1xuICAgICAgICB9XG4gICAgICAgIHZhciB0aWxlID0gdGhpcy50aWxlO1xuICAgICAgICBpZiAodGhpcy5zcmMpIHtcbiAgICAgICAgICAgIHRpbGUgPSB1dGlscyQxLmNsb25lKHtcbiAgICAgICAgICAgICAgICBzcmM6IHRoaXMuc3JjXG4gICAgICAgICAgICB9LCB0aGlzLnRpbGUpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX1RpbGUucGF0Y2goX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgIHc6IHcsXG4gICAgICAgICAgICBoOiBoXG4gICAgICAgIH0sIHRpbGUpLCB7fSwge1xuICAgICAgICAgICAgc3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgKChfdGlsZSA9IHRpbGUpID09PSBudWxsIHx8IF90aWxlID09PSB2b2lkIDAgPyB2b2lkIDAgOiBfdGlsZS5zdHlsZSkgfHwge30pLCB7fSwge1xuICAgICAgICAgICAgICAgIHJhZGl1czogdGlsZVJhZGl1c1xuICAgICAgICAgICAgfSksXG4gICAgICAgICAgICBwZXJzaXN0ZW50TWV0YWRhdGE6IHRydWUsXG4gICAgICAgICAgICBhbHBoYTogdGhpcy5fc2hvdWxkU2hvd1RpbGUgPyAxIDogMFxuICAgICAgICB9KSk7XG4gICAgfVxuICAgIF91cGRhdGVNZXRhZGF0YSgpIHtcbiAgICAgICAgdmFyIG1ldGFkYXR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5zcGFjZXIubWQgKiA5LFxuICAgICAgICBwYWRkaW5nWDogcGFkZGluZ1gsXG4gICAgICAgIHBhZGRpbmdYTm9UaXRsZTogdGhlbWUuc3BhY2VyLm1kLFxuICAgICAgICBwcmVmaXhQYWRkaW5nOiB0aGVtZS5zcGFjZXIubWQsXG4gICAgICAgIHJhZGl1czogcmFkaXVzLFxuICAgICAgICBjb250ZW50U3BhY2luZzogdGhlbWUuc3BhY2VyLm1kXG4gICAgfTtcbn07XG5cbnZhciBzdHlsZXMkbSA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJG1cbn0pO1xuXG5jbGFzcyBDb250cm9sIGV4dGVuZHMgQnV0dG9uU21hbGwge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJDb250cm9sXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJG07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIucHJvcGVydGllcywgXCJpY29uXCIsIFwibG9nb1wiLCBcInNob3VsZENvbGxhcHNlXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBhbGlhc1N0eWxlcygpIHtcbiAgICAgICAgcmV0dXJuIFsge1xuICAgICAgICAgICAgcHJldjogXCJ0aXRsZVBhZGRpbmdcIixcbiAgICAgICAgICAgIGN1cnI6IFwiY29udGVudFNwYWNpbmdcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVByZWZpeFN0eWxlKCk7XG4gICAgICAgIHN1cGVyLl91cGRhdGVUaXRsZSgpO1xuICAgICAgICB0aGlzLl91cGRhdGVDb2xsYXBzZVN0YXR1cygpO1xuICAgICAgICBzdXBlci5fdXBkYXRlKCk7XG4gICAgfVxuICAgIF91cGRhdGVDb2xsYXBzZVN0YXR1cygpIHtcbiAgICAgICAgaWYgKHRoaXMuX1RpdGxlKSB7XG4gICAgICAgICAgICB0aGlzLl9UaXRsZS52aXNpYmxlID0gIXRoaXMuX2NvbGxhcHNlO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVQcmVmaXhTdHlsZSgpIHtcbiAgICAgICAgaWYgKHRoaXMuX3ByZWZpeCkge1xuICAgICAgICAgICAgaWYgKHRoaXMubG9nbykge1xuICAgICAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVByZWZpeE9iaih0aGlzLmxvZ28sIHtcbiAgICAgICAgICAgICAgICAgICAgc3R5bGU6IF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgICAgICAgICAgY29sb3I6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgICAgICB9LCB0aGlzLnN0eWxlLmxvZ29TdHlsZSlcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5pY29uKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fdXBkYXRlUHJlZml4T2JqKHRoaXMuaWNvbiwge1xuICAgICAgICAgICAgICAgICAgICBzdHlsZTogdGhpcy5zdHlsZS5pY29uU3R5bGVcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbiAgICBfcGF0Y2hUaXRsZSh4LCBtb3VudFgpIHtcbiAgICAgICAgdGhpcy5fVGl0bGUucGF0Y2goe1xuICAgICAgICAgICAgeDogeCxcbiAgICAgICAgICAgIG1vdW50WDogbW91bnRYXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlQ29udGVudFBvc2l0aW9uKCkge1xuICAgICAgICBpZiAodGhpcy5fcHJlZml4ICYmIHRoaXMuX1RpdGxlKSB7XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBtb3VudFg6IDAsXG4gICAgICAgICAgICAgICAgeDogdGhpcy5fcGFkZGluZ0xlZnRcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgc3dpdGNoICh0aGlzLl9qdXN0aWZ5KSB7XG4gICAgICAgICAgICAgIGNhc2UgXCJsZWZ0XCI6XG4gICAgICAgICAgICAgICAgdGhpcy5fcGF0Y2hUaXRsZSgwLCAwKTtcbiAgICAgICAgICAgICAgICBicmVhaztcblxuICAgICAgICAgICAgICBjYXNlIFwicmlnaHRcIjpcbiAgICAgICAgICAgICAgICBpZiAodGhpcy53IDwgdGhpcy5fUHJlZml4LncgKyB0aGlzLl9UaXRsZS53KSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3BhdGNoVGl0bGUoMCwgMCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIGxlZnRPdmVyU3BhY2UgPSB0aGlzLncgLSAodGhpcy5fcGFkZGluZ0xlZnQgKyB0aGlzLl9wYWRkaW5nUmlnaHQgKyB0aGlzLl9QcmVmaXgudyArIHRoaXMuc3R5bGUuY29udGVudFNwYWNpbmcpO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9wYXRjaFRpdGxlKGxlZnRPdmVyU3BhY2UsIDEpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBicmVhaztcblxuICAgICAgICAgICAgICBjYXNlIFwiY2VudGVyXCI6XG4gICAgICAgICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuZml4ZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMudyA8IHRoaXMuX1ByZWZpeC53ICsgdGhpcy5fVGl0bGUudykge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcGF0Y2hUaXRsZSgwLCAwKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBtaWRkbGUgPSAodGhpcy53IC0gKHRoaXMuX3BhZGRpbmdMZWZ0ICsgdGhpcy5fUHJlZml4LncgKyB0aGlzLl9wYWRkaW5nUmlnaHQpKSAvIDI7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9wYXRjaFRpdGxlKG1pZGRsZSwgLjUpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9QcmVmaXggIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgICAgICB2YXIgX21pZGRsZSA9ICh0aGlzLncgLSAodGhpcy5fcGFkZGluZ0xlZnQgKyB0aGlzLl9QcmVmaXgudyArIHRoaXMuc3R5bGUuY29udGVudFNwYWNpbmcgKyB0aGlzLl9wYWRkaW5nUmlnaHQpKSAvIDI7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3BhdGNoVGl0bGUoX21pZGRsZSwgLjUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHN1cGVyLl91cGRhdGVDb250ZW50UG9zaXRpb24oKTtcbiAgICAgICAgICAgIHRoaXMuX1RpdGxlICYmIHRoaXMuX3BhdGNoVGl0bGUoMCwgMCk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3NldFByZWZpeCgpIHtcbiAgICAgICAgcmV0dXJuO1xuICAgIH1cbiAgICBfc2V0U3VmZml4KCkge1xuICAgICAgICByZXR1cm47XG4gICAgfVxuICAgIF91cGRhdGVQcmVmaXhPYmooaWNvbikge1xuICAgICAgICB2YXIgcHJvcHMgPSBhcmd1bWVudHMubGVuZ3RoID4gMSAmJiBhcmd1bWVudHNbMV0gIT09IHVuZGVmaW5lZCA/IGFyZ3VtZW50c1sxXSA6IHt9O1xuICAgICAgICB0aGlzLl9wcmVmaXggPSBfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgIHR5cGU6IEljb24sXG4gICAgICAgICAgICBpY29uOiBpY29uXG4gICAgICAgIH0sIHByb3BzKTtcbiAgICB9XG4gICAgX3NldEljb24oaWNvbikge1xuICAgICAgICBpZiAoIXRoaXMubG9nbykge1xuICAgICAgICAgICAgaWYgKGljb24pIHtcbiAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVQcmVmaXhPYmooaWNvbiwge1xuICAgICAgICAgICAgICAgICAgICBzdHlsZTogdGhpcy5zdHlsZS5pY29uU3R5bGVcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcHJlZml4ID0gaWNvbjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gaWNvbjtcbiAgICB9XG4gICAgX3NldExvZ28obG9nbykge1xuICAgICAgICBpZiAobG9nbykge1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlUHJlZml4T2JqKGxvZ28sIHtcbiAgICAgICAgICAgICAgICBzdHlsZTogX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIGNvbG9yOiB1bmRlZmluZWRcbiAgICAgICAgICAgICAgICB9LCB0aGlzLnN0eWxlLmxvZ29TdHlsZSlcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2UgaWYgKHRoaXMuaWNvbikge1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlUHJlZml4T2JqKHRoaXMuaWNvbiwge1xuICAgICAgICAgICAgICAgIHN0eWxlOiB0aGlzLnN0eWxlLmljb25TdHlsZVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9wcmVmaXggPSBsb2dvO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBsb2dvO1xuICAgIH1cbiAgICBnZX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YXJnaW5Ub3BcIixcbiAgICAgICAgICAgIGN1cnI6IFwidGl0bGVNYXJnaW5Cb3R0b21cIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIF90aXRsZUxvYWRlZCgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlUm93KCk7XG4gICAgfVxuICAgIF9jb25zdHJ1Y3QoKSB7XG4gICAgICAgIHN1cGVyLl9jb25zdHJ1Y3QoKTtcbiAgICAgICAgdGhpcy5fYXV0b1Jlc2l6ZUhlaWdodCA9IHRydWU7XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIHN1cGVyLl91cGRhdGUoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGl0bGUoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlUm93KCk7XG4gICAgfVxuICAgIF9hdXRvUmVzaXplKCkge1xuICAgICAgICB0aGlzLncgPSB0aGlzLncgfHwgdGhpcy5zdHlsZS53O1xuICAgICAgICB0aGlzLmggPSB0aGlzLmF1dG9SZXNpemVIZWlnaHQgPyB0aGlzLkl0ZW1zLnkgKyB0aGlzLkl0ZW1zLmggOiB0aGlzLmg7XG4gICAgfVxuICAgIF91cGRhdGVUaXRsZSgpIHtcbiAgICAgICAgaWYgKCF0aGlzLnRpdGxlKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fVGl0bGUpIHtcbiAgICAgICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgVGl0bGU6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHZhciB0aXRsZVBhdGNoID0ge1xuICAgICAgICAgICAgeDogdGhpcy5zdHlsZS50aXRsZU1hcmdpbkxlZnQsXG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLnRpdGxlLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAg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y5wYXRjaCh7XG4gICAgICAgICAgICBzdGFydExhenlTY3JvbGxJbmRleDogdGhpcy5sZWZ0Q29udHJvbHMubGVuZ3RoLFxuICAgICAgICAgICAgc3RvcExhenlTY3JvbGxJbmRleDogdGhpcy5sZWZ0Q29udHJvbHMubGVuZ3RoICsgdGhpcy5pdGVtcy5sZW5ndGggLSAxXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBhZGRMZWZ0Q29udHJvbHNBdChjb250cm9scywgaW5kZXgpIHtcbiAgICAgICAgdmFyIGl0ZW1zVG9BZGQgPSB0aGlzLl9jcmVhdGVDb250cm9scyhjb250cm9scyk7XG4gICAgICAgIGlmIChpbmRleCA9PT0gdGhpcy5fbGFzdExlZnRDb250cm9sSW5kZXggKyAxKSB7XG4gICAgICAgICAgICB0aGlzLmFkZExlZnRDb250cm9scyhjb250cm9scyk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9hcHBlbmRJdGVtc0F0KGl0ZW1zVG9BZGQsIGluZGV4KTtcbiAgICAgICAgICAgIGlmICh0aGlzLmxlZnRDb250cm9scykge1xuICAgICAgICAgICAgICAgIHRoaXMuX2xlZnRDb250cm9scy5zcGxpY2UoaW5kZXgsIDAsIC4uLmNvbnRyb2xzKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9sYXN0TGVmdENvbnRyb2xJbmRleCA9IHRoaXMuX2xlZnRDb250cm9scy5sZW5ndGggLSAxO1xuICAgICAgICAgICAgICAgIHRoaXMuX2xhc3RJdGVtSW5kZXggKz0gY29udHJvbHMubGVuZ3RoO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgc3RhcnRMYXp5U2Nyb2xsSW5kZXg6IHRoaXMubGVmdENvbnRyb2xzLmxlbmd0aCxcbiAgICAgICAgICAgICAgICBzdG9wTGF6eVNjcm9sbEluZGV4OiB0aGlzLmxlZnRDb250cm9scy5sZW5ndGggKyB0a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gICAgICAgdGhpcy5fYXBwZW5kSXRlbXNBdCh0aGlzLl9jcmVhdGVDb250cm9scyhjb250cm9scyksIGFwcGVuZEluZGV4KTtcbiAgICB9XG4gICAgcmVtb3ZlUmlnaHRDb250cm9sQXQoaW5kZXgpIHtcbiAgICAgICAgdmFyIHJlbW92ZUluZGV4ID0gdGhpcy5sZWZ0Q29udHJvbHMubGVuZ3RoICsgdGhpcy5jb250ZW50SXRlbXMubGVuZ3RoICsgaW5kZXg7XG4gICAgICAgIHRoaXMucmVtb3ZlSXRlbUF0KHJlbW92ZUluZGV4KTtcbiAgICAgICAgaWYgKHRoaXMucmlnaHRDb250cm9scykge1xuICAgICAgICAgICAgdGhpcy5fcmlnaHRDb250cm9scy5zcGxpY2UoaW5kZXgsIDEpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9jcmVhdGVDb250cm9scyhjb250cm9scykge1xuICAgICAgICByZXR1cm4gY29udHJvbHMubWFwKChjb250cm9sUHJvcHMgPT4gX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICBiYWNrZ3JvdW5kVHlwZTogXCJmaWxsXCIsXG4gICAgICAgICAgICBjZW50ZXJJblBhcmVudDogdHJ1ZVxuICAgICAgICB9LCBjb250cm9sUHJvcHMpKSk7XG4gICAgfVxuICAgIF9jcmVhdGVDb250ZW50SXRlbXMoY29udGVudEl0ZW1zKSB7XG4gICAgICAgIHZhciBuZXdDb250ZW50SXRlbXMgPSBjb250ZW50SXRlbXMubWFwKChpdGVtUHJvcHMgPT4gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBpdGVtUHJvcHMpLCB7fSwge1xuICAgICAgICAgICAgY2VudGVySW5QYXJlbnQ6IHRydWVcbiAgICAgICAgfSkpKTtcbiAgICAgICAgcmV0dXJuIG5ld0NvbnRlbnRJdGVtcztcbiAgICB9XG4gICAgX3NldExlZnRDb250cm9scyhsZWZ0Q29udHJvbHMpIHtcbiAgICAgICAgdGhpcy5fbGVmdENvbnRy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bnRyb2xJbmRleCArIDEpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBbXTtcbiAgICB9XG4gICAgX2dldENvbnRlbnRJdGVtSXRlbXMoKSB7XG4gICAgICAgIGlmICh0aGlzLmNvbnRlbnRJdGVtcy5sZW5ndGgpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLml0ZW1zLnNsaWNlKHRoaXMuX2xhc3RMZWZ0Q29udHJvbEluZGV4ICsgMSwgdGhpcy5fbGFzdEl0ZW1JbmRleCArIDEpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBbXTtcbiAgICB9XG4gICAgX2dldFJpZ2h0Q29udHJvbEl0ZW1zKCkge1xuICAgICAgICBpZiAodGhpcy5yaWdodENvbnRyb2xzLmxlbmd0aCkge1xuICAgICAgICAgICAgdmFyIGxlZnRTaWJsaW5nSW5kZXggPSB0aGlzLl9sYXN0SXRlbUluZGV4IHx8IHRoaXMuX2xhc3RMZWZ0Q29udHJvbEluZGV4O1xuICAgICAgICAgICAgcmV0dXJuIGxlZnRTaWJsaW5nSW5kZXggPyB0aGlzLml0ZW1zLnNsaWNlKGxlZnRTaWJsaW5nSW5kZXggKyAxKSA6IHRoaXMuaXRlbXM7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIFtdO1xuICAgIH1cbiAgICBzZXQgbGVmdENvbnRyb2xzKGxlZnRDb250cm9scykge1xuICAgICAgICB0aGlzLl9zZXRMZWZ0Q29udHJvbHMobGVmdENvbnRyb2xzKTtcbiAgICB9XG4gICAgZ2V0IGxlZnRDb250cm9scygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2dldExlZnRDb250cm9scygpO1xuICAgIH1cbiAgICBzZXQgcmlnaHRDb250cm9scyhyaWdodENvbnRyb2xzKSB7XG4gICAgICAgIHRoaXMuX3NldFJpZ2h0Q29udHJvbHMocmlnaHRDb250cm9scyk7XG4gICAgfVxuICAgIGdldCByaWdodENvbnRyb2xzKCkge1xuICAgICAgICByZXR1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GF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiU3BhY2VyXCI7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBMaW5lOiB7XG4gICAgICAgICAgICAgICAgaDogU3BhY2VyLl9saW5lVGhpY2tuZXNzLFxuICAgICAgICAgICAgICAgIHJlY3Q6IHRydWUsXG4gICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICBUaWNrTGVmdDogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBTcGFjZXIuX3RpY2spLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICB4OiBTcGFjZXIuX2xpbmVUaGlja25lc3MgKiAtMVxuICAgICAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgICAgIFRpY2tSaWdodDogU3BhY2VyLl90aWNrXG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJsaW5lQ29sb3JcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIFwiTGluZVwiLCBcIlRpY2tMZWZ0XCIsIFwiVGlja1JpZ2h0XCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfbGluZVRoaWNrbmVzcygpIHtcbiAgICAgICAgcmV0dXJuIDM7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX3RpY2tMZW5ndGgoKSB7XG4gICAgICAgIHJldHVybiAyNTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfdGljaygpIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIHJlY3Q6IHRydWUsXG4gICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgdzogU3BhY2VyLl9saW5lVGhpY2tuZXNzLFxuICAgICAgICAgICAgaDogU3BhY2VyLl90aWNrTGVuZ3RoLFxuICAgICAgICAgICAgeTogU3BhY2VyLl9saW5lVGhpY2tuZXNzIC8gMlxuICAgICAgICB9O1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl9MaW5lLncgPSB0aGlzLnc7XG4gICAgICAgIHRoaXMuX1RpY2tSaWdodC54ID0gdGhpcy5fTGluZS53O1xuICAgICAgICBpZiAodGhpcy5saW5lQ29sb3IpIHtcbiAgICAgICAgICAgIHRoaXMuX0xpbmUuY29sb3IgPSB0aGlzLl9UaWNrTGVmdC5jb2xvciA9IHRoaXMuX1RpY2tSaWdodC5jb2xvciA9IHRoaXMubGluZUNvbG9yO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMucm90YXRpb24gPSB0aGlzLnZlcnRpY2FsID8gTWF0aC5QSSAvIDIgOiAwO1xuICAgICAgICB0aGlzLnNpZ25hbChcInNwYWNlckxvYWRlZFwiKTtcbiAgICB9XG59XG5cbmNsYXNzIEdyaWRPdmVybGF5IGV4dGVuZHMgQmFzZSQxIHtcbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiR3JpZE92ZXJsYXlcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkaTtcbiAgICB9XG4gICAgc3RhdGljIF90ZW1wbGF0ZSgpIHtcbiAgICAgICAgdmFyIHRleHRSb3cgPSB7XG4gICAgICAgICAgICB0eXBlOiBSb3csXG4gICAgICAgICAgICBhdXRvUmVzaXplSGVpZ2h0OiB0cnVlLFxuICAgICAgICAgICAgSXRlbXM6IHtcbiAgICAgICAgICAgICAgICBQcm9wZXJ0eToge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0Qm94Q2hhbmdlZDogXCJfdXBkYXRlXCJcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgVmFsdWU6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3VwZGF0ZVwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIGNlbnRlckluUGFyZW50OiB0cnVlXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgQ29sdW1uczoge1xuICAgICAgICAgICAgICAgIGFscGhhOiAuMDAxLFxuICAgICAgICAgICAgICAgIHR5cGU6IFJvd1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIE1hcmdpbnM6IHtcbiAgICAgICAgICAgICAgICBhbHBoYTogLjAwMSxcbiAgICAgICAgICAgICAgICBIb3Jpem9udGFsOiB7XG4gICAgICAgICAgICAgICAgICAgIExlZnQ6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFNwYWNlcixcbiAgICAgICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzcGFjZXJMb2FkZWQ6IFwiX3VwZGF0ZVwiXG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIFJpZ2h0OiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBTcGFjZXIsXG4gICAgICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgc3BhY2VyTG9hZGVkOiBcIl91cGRhdGVcIlxuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBWZXJ0aWNhbDoge1xuICAgICAgICAgICAgICAgICAgICBUb3A6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFNwYWNlcixcbiAgICAgICAgICAgICAgICAgICAgICAgIHZlcnRpY2FsOiB0cnVlXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgU2FmZToge1xuICAgICAgICAgICAgICAgIGFscGhhOiAuMDAxLFxuICAgICAgICAgICAgICAgIEhvcml6b250YWw6IHtcbiAgICAgICAgICAgICAgICAgICAgTGVmdDoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogU3BhY2VyLFxuICAgICAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNwYWNlckxvYWRlZDogXCJfdXBkYXRlXCJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgUmlnaHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFNwYWNlcixcbiAgICAgICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzcGFjZXJMb2FkZWQ6IFwiX3VwZGF0ZVwiXG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIFZlcnRpY2FsOiB7XG4gICAgICAgICAgICAgICAgICAgIFRvcDoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogU3BhY2VyLFxuICAgICAgICAgICAgICAgICAgICAgICAgdmVydGljYWw6IHRydWVcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgQm90dG9tOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBTcGFjZXIsXG4gICAgICAgICAgICAgICAgICAgICAgICB2ZXJ0aWNhbDogdHJ1ZVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIEd1dHRlcnM6IHtcbiAgICAgICAgICAgICAgICBhbHBoYTogLjAwMSxcbiAgICAgICAgICAgICAgICBIb3Jpem9udGFsOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IFNwYWNlcixcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3BhY2VyTG9hZGVkOiBcIl91cGRhdGVcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIFRleHRQYW5lbDoge1xuICAgICAgICAgICAgICAgIGFscGhhOiAuMDAxLFxuICAgICAgICAgICAgICAgIHR5cGU6IENvbHVtbixcbiAgICAgICAgICAgICAgICBhdXRvUmVzaXplSGVpZ2h0OiB0cnVlLFxuICAgICAgICAgICAgICAgIEl0ZW1zOiB7XG4gICAgICAgICAgICAgICAgICAgIFNjcmVlblc6IHRleHRSb3csXG4gICAgICAgICAgICAgICAgICAgIFNjcmVlbkg6IHRleHRSb3csXG4gICAgICAgICAgICAgICAgICAgIENvbHVtbkNvdW50OiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBNYXJnaW5YOiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBNYXJnaW5ZOiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBHdXR0ZXJYOiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBHdXR0ZXJZOiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBTYWZlOiB0ZXh0Um93XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwic2hvd0NvbHVtbnNcIiwgXCJzaG93TWFyZ2luc1wiLCBcInNob3dTYWZlXCIsIFwic2hvd0d1dHRlcnNcIiwgXCJzaG93VGV4dFwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJDb2x1bW5zXCIsIFwiTWFyZ2luc1wiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIk1hcmdpbkhvcml6b250YWxcIixcbiAgICAgICAgICAgIHBhdGg6IFwiTWFyZ2lucy5Ib3Jpem9udGFsXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJNYXJnaW5MZWZ0XCIsXG4gICAgICAgICAgICBwYXRoOiBcIk1hcmdpbnMuSG9yaXpvbnRhbC5MZWZ0XCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJNYXJnaW5SaWdodFwiLFxuICAgICAgICAgICAgcGF0aDogXCJNYXJnaW5zLkhvcml6b250YWwuUmlnaHRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIk1hcmdpblZlcnRpY2FsXCIsXG4gICAgICAgICAgICBwYXRoOiBcIk1hcmdpbnMuVmVydGljYWxcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIk1hcmdpblRvcFwiLFxuICAgICAgICAgICAgcGF0aDogXCJNYXJnaW5zLlZlcnRpY2FsLlRvcFwiXG4gICAgICAgIH0sIFwiU2FmZVwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIlNhZmVIb3Jpem9udGFsXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlNhZmUuSG9yaXpvbnRhbFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiU2FmZUxlZnRcIixcbiAgICAgICAgICAgIHBhdGg6IFwiU2FmZS5Ib3Jpem9udGFsLkxlZnRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlNhZmVSaWdodFwiLFxuICAgICAgICAgICAgcGF0aDogXCJTYWZlLkhvcml6b250YWwuUmlnaHRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlNhZmVWZXJ0aWNhbFwiLFxuICAgICAgICAgICAgcGF0aDogXCJTYWZlLlZlcnRpY2FsXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJTYWZlVG9wXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlNhZmUuVmVydGljYWwuVG9wXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJTYWZlQm90dG9tXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlNhZmUuVmVydGljYWwuQm90dG9tXCJcbiAgICAgICAgfSwgXCJHdXR0ZXJzXCIsIHtcbiAgICAgICAgICAgIG5hbWU6IFwiR3V0dGVySG9yaXpvbnRhbFwiLFxuICAgICAgICAgICAgcGF0aDogXCJHdXR0ZXJzLkhvcml6b250YWxcIlxuICAgICAgICB9LCBcIlRleHRQYW5lbFwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIlRleHRTY3JlZW5XXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHRQYW5lbC5JdGVtcy5TY3JlZW5XXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJUZXh0U2NyZWVuSFwiLFxuICAgICAgICAgICAgcGF0aDogXCJUZXh0UGFuZWwuSXRlbXMuU2NyZWVuSFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGV4dENvbHVtbkNvdW50XCIsXG4gICAgICAgICAgICBw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G4gICAgbWluV2lkdGg6IGdldFdpZHRoQnlVcENvdW50KHRoZW1lLCA0KSxcbiAgICBwYWRkaW5nWDogdGhlbWUuc3BhY2VyLnhsLFxuICAgIHBhZGRpbmdZOiB0aGVtZS5zcGFjZXIueGwsXG4gICAgYmFja2dyb3VuZENvbG9yOiB0aGVtZS5jb2xvci5pbnRlcmFjdGl2ZU5ldXRyYWxcbn0pO1xuXG52YXIgbW9kZSQ2ID0gdGhlbWUgPT4gKHtcbiAgICBkaXNhYmxlZDoge1xuICAgICAgICBleWVicm93VGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgfSxcbiAgICAgICAgaGVscFRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgIH1cbiAgICB9LFxuICAgIGZvY3VzZWQ6IHtcbiAgICAgICAgY3Vyc29yU3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dEludmVyc2VcbiAgICAgICAgfSxcbiAgICAgICAgZXllYnJvd1RleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICB9LFxuICAgICAgICBoZWxwVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsU2Vjb25kYXJ5XG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHRvbmUkYSA9IHRoZW1lID0+ICh7XG4gICAgaW52ZXJzZToge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBmb2N1c2VkOiB7XG4gICAgICAgICAgICAgICAgZXllYnJvd1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBoZWxwVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyRoID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkaCxcbiAgICBtb2RlOiBtb2RlJDYsXG4gICAgdG9uZTogdG9uZSRhXG59KTtcblxuY2xhc3MgSW5wdXQgZXh0ZW5kcyBCdXR0b24ge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJJbnB1dFwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRoO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBzdXBlci5fdGVtcGxhdGUoKSksIHt9LCB7XG4gICAgICAgICAgICBFeWVicm93OiB7XG4gICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIEhlbHBUZXh0OiB7XG4gICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveFxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gWyAuLi5zdXBlci5wcm9wZXJ0aWVzLCBcImFjdHVhbFRpdGxlXCIsIFwiY3Vyc29yXCIsIFwiZXllYnJvd1wiL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gICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlLnRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogZmFsc2VcbiAgICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlRXllYnJvdygpIHtcbiAgICAgICAgdGhpcy5fRXllYnJvdy5wYXRjaCh7XG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLmV5ZWJyb3csXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIHRleHRTdHlsZTogdGhpcy5zdHlsZS5leWVicm93VGV4dFN0eWxlXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgbW91bnRZOiAxLFxuICAgICAgICAgICAgeDogdGhpcy5zdHlsZS5wYWRkaW5nWCxcbiAgICAgICAgICAgIHk6IHRoaXMueSAtIHRoaXMuc3R5bGUucGFkZGluZ1lcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVIZWxwVGV4dCgpIHtcbiAgICAgICAgdGhpcy5fSGVscFRleHQucGF0Y2goe1xuICAgICAgICAgICAgY29udGVudDogdGhpcy5oZWxwVGV4dCxcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB0aGlzLnN0eWxlLmhlbHBUZXh0U3R5bGVcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICB4OiB0aGlzLnN0eWxlLnBhZGRpbmdYLFxuICAgICAgICAgICAgeTogdGhpcy55ICsgdGhpcy5pbm5lckggKyB0aGlzLnN0eWxlLnBhZGRpbmdZXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlVGV4dFdyYXBwZXIoKSB7XG4gICAgICAgIHRoaXMuX1RleHRXcmFwcGVyLmNsaXBwaW5nID0gdHJ1ZTtcbiAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIudyA9IHRoaXMuX3Zpc2libGVDb250ZW50V2lkdGg7XG4gICAgICAgIGlmICh0aGlzLl9UaXRsZSkge1xuICAgICAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIuaCA9IHRoaXMuX1RpdGxlLmg7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZUhpZGRlbkNvbnRlbnQoKSB7XG4gICAgICAgIGlmICghdGhpcy5fSGlkZGVuQ29udGVudCkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgSGlkZGVuQ29udGVudDoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyLFxuICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0Qm94Q2hhbmdlZDogXCJfb25IaWRkZW5UZXh0Qm94Q2hhbmdlZFwiXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICB2YXIge3RpdGxlOiB2YWx1ZSA9IFwiXCIsIHBvc2l0aW9uOiBwb3NpdGlvbiwgcGFzc3dvcmQ6IHBhc3N3b3JkLCBtYXNrOiBtYXNrfSA9IHRoaXM7XG4gICAgICAgIHZhciB0ZXh0QmVmb3JlQ3Vyc29yID0gcGFzc3dvcmQgPyBtYXNrLnJlcGVhdCh2YWx1ZS5sZW5ndGgpLnN1YnN0cmluZygwLCBwb3NpdGlvbikgOiB2YWx1ZS5zdWJzdHJpbmcoMCwgcG9zaXRpb24pO1xuICAgICAgICB0aGlzLl9IaWRkZW5Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB0aGlzLnN0eWxlLnRleHRTdHlsZVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGNvbnRlbnQ6IHRleHRCZWZvcmVDdXJzb3JcbiAgICAgICAgfSk7XG4gICAgICAgIHRoaXMuX0hpZGRlbkNvbnRlbnQuX1RleHQgJiYgdGhpcy5fSGlkZGVuQ29udGVudC5fVGV4dC5wYXRjaCh7XG4gICAgICAgICAgICBhbHBoYTogLjAwMVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZUN1cnNvcigpIHtcbiAgICAgICAgaWYgKHRoaXMuc3R5bGUuY3Vyc29yU3R5bGUgJiYgdGhpcy5zdHlsZS5jdXJzb3JTdHlsZS5ibGluaykge1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9DdXJzb3IpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgQ3Vyc29yOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZWN0OiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgdGhpcy5jdXJzb3JCbGluayA9IHRoaXMuX0N1cnNvci5hbmltYXRpb24oe1xuICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbjogMS41LFxuICAgICAgICAgICAgICAgICAgICByZXBlYXQ6IC0xLFxuICAgICAgICAgICAgICAgICAgICBhY3Rpb25zOiBbIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHA6IFwiYWxwaGFcIixcbiAgICAgICAgICAgICAgICAgICAgICAgIHY6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAwOiAwLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC41OiAxLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIDE6IDBcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSBdXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9DdXJzb3IucGF0Y2godGhpcy5zdHlsZS5jdXJzb3JTdHlsZSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZUN1cnNvckxpc3RlbmluZygpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9pc0Rpc2FibGVkTW9kZSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuY3Vyc29yQmxpbmsgJiYgIXRoaXMuY3Vyc29yQmxpbmsuaXNQbGF5aW5nKCkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmN1cnNvckJsaW5rLnN0YXJ0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodGhpcy5jdXJzb3JCbGluaykgdGhpcy5pc0N1cnNvckFjdGl2ZSA/IHRoaXMuY3Vyc29yQmxpbmsuc3RhcnQoKSA6IHRoaXMuY3Vyc29yQmxpbmsuc3RvcCgpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX0N1cnNvci5zbW9vdGggPSB7XG4gICAgICAgICAgICBjb2xvcjogdGhpcy5zdHlsZS5jdXJzb3JTdHlsZS50ZXh0Q29sb3JcbiAgICAgICAgfTtcbiAgICB9XG4gICAgX3VwZGF0ZUN1cnNvckJsaW5rKCkge1xuICAgICAgICBpZiAodGhpcy5jdXJzb3JCbGluaykge1xuICAgICAgICAgICAgaWYgKHRoaXMuaXNDdXJzb3JBY3RpdmUpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmN1cnNvckJsaW5rLnN0YXJ0KCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuY3Vyc29yQmxpbmsuc3Rvc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IHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLm9uUmlnaHQodGhpcyk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgfVxuICAgIG1vdmVMZWZ0KCkge1xuICAgICAgICB2YXIge3Bvc2l0aW9uOiBwb3NpdGlvbn0gPSB0aGlzO1xuICAgICAgICBpZiAocG9zaXRpb24gPj0gMCkge1xuICAgICAgICAgICAgdGhpcy5wb3NpdGlvbi0tO1xuICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cbiAgICBtb3ZlUmlnaHQoKSB7XG4gICAgICAgIHZhciB7cG9zaXRpb246IHBvc2l0aW9uLCB0aXRsZTogdGl0bGV9ID0gdGhpcztcbiAgICAgICAgaWYgKHBvc2l0aW9uIDwgdGl0bGUubGVuZ3RoKSB7XG4gICAgICAgICAgICB0aGlzLnBvc2l0aW9uKys7XG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuICAgIHNldCBhbm5vdW5jZShhbm5vdW5jZSkge1xuICAgICAgICBzdXBlci5hbm5vdW5jZSA9IGFubm91bmNlO1xuICAgIH1cbiAgICBnZXQgYW5ub3VuY2UoKSB7XG4gICAgICAgIGlmICh0aGlzLl9hbm5vdW5jZSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2Fubm91bmNlO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLnBhc3N3b3JkKSB7XG4gICAgICAgICAgICByZXR1cm4gWyB0aGlzLmV5ZWJyb3csIHRoaXMuaGVscFRleHQgXTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiBbIHRoaXMuZXllYnJvdywgXCJJbnB1dDogXCIgKyB0aGlzLnRpdGxlLCB0aGlzLmhlbHBUZXh0IF07XG4gICAgICAgIH1cbiAgICB9XG59XG5cbnZhciBiYXNlJGcgPSB0aGVtZSA9PiB7XG4gICAgdmFyIHRleHRTdHlsZSA9IHRoZW1lLnR5cG9ncmFwaHkuaGVhZGxpbmUyO1xuICAgIHJldHVybiB7XG4gICAgICAgIGhlaWdodDogdGhlbWUuc3BhY2VyLm1kICogOSxcbiAgICAgICAgbWluV2lkdGg6IHRoZW1lLnNwYWNlci5tZCAqIDcsXG4gICAgICAgIHBhZGRpbmdYOiB0aGVtZS5zcGFjZXIubWQsXG4gICAgICAgIHRleHRTdHlsZTogdGV4dFN0eWxlLFxuICAgICAgICBzaXplczoge1xuICAgICAgICAgICAgc206IDEsXG4gICAgICAgICAgICBtZDogMixcbiAgICAgICAgICAgIGxnOiAzLFxuICAgICAgICAgICAgeGw6IDQsXG4gICAgICAgICAgICB4eGw6IDVcbiAgICAgICAgfSxcbiAgICAgICAgYmFzZVdpZHRoOiB0aGVtZS5zcGFjZXIubWQgKiA3LFxuICAgICAgICBpY29uV2lkdGg6IHRleHRTdHlsZS5saW5lSGVpZ2h0LFxuICAgICAgICBpY29uSGVpZ2h0OiB0ZXh0U3R5bGUubGluZUhlaWdodFxuICAgIH07XG59O1xuXG52YXIgc3R5bGVzJGcgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSRnXG59KTtcblxudmFyIGlzVXBwZXJDYXNlID0gc3RyaW5nID0+IC9eW0EtWl0kLy50ZXN0KHN0cmluZyk7XG5cbnZhciBpc0FscGhhQ2hhciA9IHN0cmluZyA9PiAvXltBLVphLXpdJC8udGVzdChzdHJpbmcpO1xuXG52YXIgYWxwaGFOYXRvID0ge1xuICAgIGE6IFwiYWxwaGFcIixcbiAgICBiOiBcImJyYXZvXCIsXG4gICAgYzogXCJjaGFybGllXCIsXG4gICAgZDogXCJkZWx0YVwiLFxuICAgIGU6IFwiZWNob1wiLFxuICAgIGY6IFwiZm94dHJvdFwiLFxuICAgIGc6IFwiZ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cbiAgICBzdGF0aWMgZ2V0IGFsaWFzU3R5bGVzKCkge1xuICAgICAgICByZXR1cm4gWyB7XG4gICAgICAgICAgICBwcmV2OiBcImljb25IXCIsXG4gICAgICAgICAgICBjdXJyOiBcImljb25IZWlnaHRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBwcmV2OiBcImljb25XXCIsXG4gICAgICAgICAgICBjdXJyOiBcImljb25XaWR0aFwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgX2NvbnN0cnVjdCgpIHtcbiAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCgpO1xuICAgICAgICB0aGlzLl9zaXplID0gXCJzbVwiO1xuICAgICAgICB0aGlzLl9rZXlTcGFjaW5nID0gMDtcbiAgICB9XG4gICAgX3VwZGF0ZSgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlUHJlZml4U3R5bGUoKTtcbiAgICAgICAgc3VwZXIuX3VwZGF0ZSgpO1xuICAgIH1cbiAgICBfY2FsY0R5bmFtaWNXaWR0aCgpIHtcbiAgICAgICAgdmFyIHNpemVNdWx0aXBsaWVyID0gdGhpcy5zdHlsZS5zaXplc1t0aGlzLnNpemUgfHwgXCJzbVwiXTtcbiAgICAgICAgdmFyIGJhc2VTaXplID0gdGhpcy5zdHlsZS5iYXNlV2lkdGggKiBzaXplTXVsdGlwbGllcjtcbiAgICAgICAgdmFyIHBhZGRpbmcgPSB0aGlzLmtleVNwYWNpbmcgKiAoc2l6ZU11bHRpcGxpZXIgLSAxKTtcbiAgICAgICAgcmV0dXJuIGJhc2VTaXplICsgcGFkZGluZztcbiAgICB9XG4gICAgX3VwZGF0ZVByZWZpeFN0eWxlKCkge1xuICAgICAgICBpZiAodGhpcy5fcHJlZml4ICYmIHRoaXMuaWNvbikge1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlUHJlZml4T2JqKHRoaXMuaWNvbiwge1xuICAgICAgICAgICAgICAgIHN0eWxlOiB0aGlzLnN0eWxlLmljb25TdHlsZVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVByZWZpeE9iaihpY29uKSB7XG4gICAgICAgIHZhciBwcm9wcyA9IGFyZ3VtZW50cy5sZW5ndGggPiAxICYmIGFyZ3VtZW50c1sxXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzFdIDoge307XG4gICAgICAgIHRoaXMuX3ByZWZpeCA9IF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgdHlwZTogSWNvbixcbiAgICAgICAgICAgIGljb246IGljb24sXG4gICAgICAgICAgICB3OiB0aGlzLnN0eWxlLmljb25XaWR0aCxcbiAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuaWNvbkhlaWdodFxuICAgICAgICB9LCBwcm9wcyk7XG4gICAgfVxuICAgIF9zZXRJY29uKGljb24pIHtcbiAgICAgICAgaWYgKGljb24pIHtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVByZWZpeE9iaihpY29uLCB7XG4gICAgICAgICAgICAgICAgc3R5bGU6IHRoaXMuc3R5bGUuaWNvblN0eWxlXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX3ByZWZpeCA9IGljb247XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGljb247XG4gICAgfVxuICAgIHNldCBhbm5vdW5jZShhbm5vdW5jZSkge1xuICAgICAgICBzdXBlci5hbm5vdW5jZSA9IGFubm91bmNlO1xuICAgIH1cbiAgICBnZXQgYW5ub3VuY2UoKSB7XG4gICAgICAgIGlmICh0aGlzLl9hbm5vdW5jZSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2Fubm91bmNlO1xuICAgICAgICB9XG4gICAgICAgIGlmIChpc1VwcGVyQ2FzZSh0aGlzLnRpdGxlKSkge1xuICAgICAgICAgICAgcmV0dXJuIFwiQ2FwaXRhbCBcIi5jb25jYXQoZ2V0TmF0byh0aGlzLnR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2V5ID0+IHtcbiAgICAgICAgICAgIHZhciBmb3JtYXQgPSB0aGlzLmZvcm1hdHNba2V5XTtcbiAgICAgICAgICAgIGlmIChmb3JtYXQpIHtcbiAgICAgICAgICAgICAgICB2YXIga2V5Ym9hcmREYXRhID0gdGhpcy5fZm9ybWF0S2V5Ym9hcmREYXRhKGZvcm1hdCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fY3JlYXRlS2V5Ym9hcmQoa2V5LCB0aGlzLl9jcmVhdGVSb3dzKGtleWJvYXJkRGF0YSwga2V5KSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pKTtcbiAgICAgICAgdGhpcy5fZm9ybWF0c0NoYW5nZWQgPSBmYWxzZTtcbiAgICB9XG4gICAgX2NyZWF0ZUtleWJvYXJkKGtleSkge1xuICAgICAgICB2YXIgcm93cyA9IGFyZ3VtZW50cy5sZW5ndGggPiAxICYmIGFyZ3VtZW50c1sxXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzFdIDogW107XG4gICAgICAgIGtleSA9IGNhcGl0YWxpemUoa2V5KTtcbiAgICAgICAgaWYgKHJvd3MubGVuZ3RoID09PSAxKSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBba2V5XTogcm93c1swXVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBba2V5XToge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBDb2x1bW4sXG4gICAgICAgICAgICAgICAgICAgIHBsaW5rbzogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgaXRlbXM6IHJvd3MsXG4gICAgICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpdGVtU3BhY2luZzogdGhpcy5zdHlsZS5rZXlTcGFjaW5nXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIGF1dG9SZXNpemVXaWR0aDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgYXV0b1Jlc2l6ZUhlaWdodDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgbmV2ZXJTY3JvbGw6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIGFscGhhOiBrZXkgPT09IGNhcGl0YWxpemUodGhpcy5fY3VycmVudEZvcm1hdCkgPyAxIDogLjAwMVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9jcmVhdGVSb3dzKCkge1xuICAgICAgICB2YXIgcm93cyA9IGFyZ3VtZW50cy5sZW5ndGggPiAwICYmIGFyZ3VtZW50c1swXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzBdIDogW107XG4gICAgICAgIHZhciBrZXlib2FyZCA9IGFyZ3VtZW50cy5sZW5ndGggPiAxID8gYXJndW1lbnRzWzFdIDogdW5kZWZpbmVkO1xuICAgICAgICByZXR1cm4gcm93cy5tYXAoKGtleXMgPT4ge1xuICAgICAgICAgICAgdmFyIF90aGlzJF9jdXJyZW50S2V5Ym9hcjtcbiAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgdHlwZTogUm93LFxuICAgICAgICAgICAgICAgIGF1dG9SZXNpemVIZWlnaHQ6IHRydWUsXG4gICAgICAgICAgICAgICAgYXV0b1Jlc2l6ZVdpZHRoOiB0cnVlLFxuICAgICAgICAgICAgICAgIGNlbnRlckluUGFyZW50OiB0aGlzLmNlbnRlcktleXMsXG4gICAgICAgICAgICAgICAgbmV2ZXJTY3JvbGw6IHRydWUsXG4gICAgICAgICAgICAgICAgd3JhcFNlbGVjdGVkOiB0aGlzLnJvd1dyYXAgIT09IHVuZGVmaW5lZCA/IHRoaXMucm93V3JhcCA6IHRydWUsXG4gICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgaXRlbVNwYWNpbmc6IHRoaXMuc3R5bGUua2V5U3BhY2luZ1xuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgaXRlbXM6IHRoaXMuX2NyZWF0ZUtleXMoa2V5cywga2V5Ym9hcmQpLFxuICAgICAgICAgICAgICAgIHNlbGVjdGVkSW5kZXg6ICgoX3RoaXMkX2N1cnJlbnRLZXlib2FyID0gdGhpcy5fY3VycmVudEtleWJvYXJkKSA9PT0gbnVsbCB8fCBfdGhpcyRfY3VycmVudEtleWJvYXIgPT09IHZvaWQgMCB8fCAoX3RoaXMkX2N1cnJlbnRLZXlib2FyID0gX3RoaXMkX2N1cnJlbnRLZXlib2FyLnNlbGVjdGVkKSA9PT0gbnVsbCB8fCBfdGhpcyRfY3VycmVudEtleWJvYXIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJF9jdXJyZW50S2V5Ym9hci5zZWxlY3RlZEluZGV4KSB8fCAwXG4gICAgICAgICAgICB9O1xuICAgICAgICB9KSk7XG4gICAgfVxuICAgIF9jcmVhdGVLZXlzKCkge1xuICAgICAgICB2YXIga2V5cyA9IGFyZ3VtZW50cy5sZW5ndGggPiAwICYmIGFyZ3VtZW50c1swXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzBdIDogW107XG4gICAgICAgIHZhciBrZXlib2FyZCA9IGFyZ3VtZW50cy5sZW5ndGggPiAxID8gYXJndW1lbnRzWzFdIDogdW5kZWZpbmVkO1xuICAgICAgICByZXR1cm4ga2V5cy5tYXAoKGtleVByb3BzID0+IHtcbiAgICAgICAgICAgIGlmICgha2V5UHJvcHMpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiB0aGlzLmtleUNvbXBvbmVudCB8fCBLZXksXG4gICAgICAgICAgICAgICAgICAgIGtleVNwYWNpbmc6IHRoaXMuc3R5bGUua2V5U3BhY2luZyxcbiAgICAgICAgICAgICAgICAgICAgc2tpcEZvY3VzOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICBhbHBoYTogLjAxXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBrZXkgPSB7XG4gICAgICAgICAgICAgICAgdHlwZTogdGhpcy5rZXlDb21wb25lbnQgfHwgS2V5LFxuICAgICAgICAgICAgICAgIGtleVNwYWNpbmc6IHRoaXMuc3R5bGUua2V5U3BhY2luZ1xuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmICh0eXBlb2Yga2V5UHJvcHMgPT09IFwib2JqZWN0XCIpIHtcbiAgICAgICAgICAgICAgICB2YXIgX3RoaXMkc3R5bGUka2V5UHJvcHMsIF90aGlzJHN0eWxlJGtleVByb3BzMjtcbiAgICAgICAgICAgICAgICB2YXIga2V5TmFtZSA9IGtleVByb3BzLmtleUlkIHx8IGtleVByb3BzLnRpdGxlO1xuICAgICAgICAgICAgICAgIHZhciBrZXlPdmVycmlkZXMgPSAoKF90aGlzJHN0eWxlJGtleVByb3BzID0gdGhpcy5zdHlsZS5rZXlQcm9wcykgPT09IG51bGwgfHwgX3RoaXMkc3R5bGUka2V5UHJvcHMgPT09IHZvaWQgMCB8fCAoX3RoaXMkc3R5bGUka2V5UHJvcHMgPSBfdGhpcyRzdHlsZSRrZXlQcm9wc1trZXlib2FyZF0pID09PSBudWxsIHx8IF90aGlzJHN0eWxlJGtleVByb3BzID09PSB2b2lkIDAgPyB2b2lkIDAgOiBfdGhpcyRzdHlsZSRrZXlQcm9wc1trZXlOYW1lXSkgfHwgKChfdGhpcyRzdHlsZSRrZXlQcm9wczIgPSB0aGlzLnN0eWxlLmtleVByb3BzKSA9PT0gbnVsbCB8fCBfdGhpcyRzdHlsZSRrZXlQcm9wczIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJHN0eWxlJGtleVByb3BzMltrZXlOYW1lXSkgfHwge307XG4gICAgICAgICAgICAgICAgdmFyIGtleVBhdGNoID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGtleSksIGtleVByb3BzKSwga2V5T3ZlcnJpZGVzKTtcbiAgICAgICAgICAgICAgICBpZiAoa2V5T3ZlcnJpZGVzICE9PSBudWxsICYmIGtleU92ZXJyaWRlcyAhPT0gdm9pZCAwICYmIGtleU92ZXJyaWRlcy5pY29uKSB7XG4gICAgICAgICAgICAgICAgICAgIGtleVBhdGNoLnN0eWxlID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBrZXlPdmVycmlkZXMuc3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWNvblN0eWxlOiBfb2JqZWN0U3ByZWFkKHt9LCBrZXlPdmVycmlkZXMuaWNvblN0eWxlKVxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIGtleVBhdGNoO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwga2V5KSwge30sIHtcbiAgICAgICAgICAgICAgICB0aXRsZToga2V5UHJvcHNcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KSk7XG4gICAgfVxuICAgIF9mb3JtYXRLZXlib2FyZERhdGEoKSB7XG4gICAgICAgIHZhciBkYXRhID0gYXJndW1lbnRzLmxlbmd0aCA+IDAgJiYgYXJndW1lbnRzWzBdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMF0gOiBbXTtcbiAgICAgICAgaWYgKEFycmF5LmlzQXJyYXkoZGF0YSkgJiYgZGF0YS5sZW5ndGgpIHtcbiAgICAgICAgICAgIGlmICghQXJyYXkuaXNBcnJheShkYXRhWzBdKSAmJiAhdGhpcy5pbmxpbmUpIHtcbiAgICAgICAgICAgICAgICB2YXIga2V5Um93cyA9IFtdO1xuICAgICAgICAgICAgICAgIHZhciBpZHgsIGNvdW50ZXI7XG4gICAgICAgICAgICAgICAgZm9yIChpZHggPSAwLCBjb3VudGVyID0gLTE7IGlkeCA8IGRhdGEubGVuZ3RoOyBpZHgrKykge1xuICAgICAgICAgICAgICAgICAgICBpZiAoaWR4ICUgdGhpcy5jb2x1bW5Db3VudCA9PT0gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgY291bnRlcisrO1xuICAgICAgICAgICAgICAgICAgICAgICAga2V5Um93c1tjb3VudGVyXSA9IFtdO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGtleVJvd3NbY291bnRlcl0ucHVzaChkYXRhW2lkeF0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4ga2V5Um93cztcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5pbmxpbmUpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gWyBkYXRhIF07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gZGF0YTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfZm9ybWF0S2V5cygpIHtcbiAgICAgICAgT2JqZWN0LmtleXModGhpcy5mb3JtYXRzKS5mb3JFYWNoKChmb3JtYXQgPT4ge1xuICAgICAgICAgICAgdmFyIGVsZW1lbnQgPSB0aGlzLnRhZyhjYXBpdGFsaXplKGZvcm1hdCkpO1xuICAgICAgICAgICAgaWYgKGVsZW1lbnQpIHtcbiAgICAgICAgICAgICAgICBlbGVtZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgYWxwaGE6IGZvcm1hdCA9PT0gdGhpcy5fY3VycmVudEZvcm1hdCA/IDEgOiAuMDAxLFxuICAgICAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgaXRlbVNwYWNpbmc6IHRoaXMuc3R5bGUua2V5U3BhY2luZ1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgZWxlbWVudC5pdGVtcy5mb3JFYWNoKChyb3cgPT4ge1xuICAgICAgICAgICAgICAgICAgICByb3cucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpdGVtU3BhY2luZzogdGhpcy5zdHlsZS5rZXlTcGFjaW5nXG4gICAgICAgICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgICAgICAgY2VudGVySW5QYXJlbnQ6IHRoaXMuY2VudGVyS2V5cyxcbiAgICAgICAgICAgICAgICAgICAgICAgIHdyYXBTZWxlY3RlZDogdGhpcy5yb3dXcmFwICE9PSB1bmRlZmluZWQgPyB0aGlzLnJvd1dyYXAgOiB0cnVlXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICBlbGVtZW50LnF1ZXVlUmVxdWVzdFVwZGF0ZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KSk7XG4gICAgfVxuICAgICR0b2dnbGVLZXlib2FyZChuZXh0KSB7XG4gICAgICAgIHZhciBuZXh0S2V5Ym9hcmQgPSBjYXBpdGFsaXplKG5leHQpO1xuICAgICAgICBpZiAobmV4dCAhPT0gdGhpcy5fY3VycmVudEZvcm1hdCkge1xuICAgICAgICAgICAgdmFyIG5leHRLZXlib2FyZFRhZyA9IHRoaXMudGFnKG5leHRLZXlib2FyZCk7XG4gICAgICAgICAgICB0aGlzLnNlbGVjdEtleU9uKG5leHRLZXlib2FyZFRhZyk7XG4gICAgICAgICAgICB0aGlzLl9jdXJyZW50S2V5Ym9hcmQuYWxwaGEgPSAuMDAxO1xuICAgICAgICAgICAgbmV4dEtleWJvYXJkVGFnLmFscGhhID0gMTtcbiAgICAgICAgICAgIHRoaXMuX2N1cnJlbnRGb3JtYXQgPSBuZXh0O1xuICAgICAgICB9XG4gICAgfVxuICAgIHNlbGVjdEtleU9uKGtleWJvYXJkKSB7XG4gICAgICAgIHZhciB7cm93OiByb3csIGNvbHVtbjogY29sdW1ufSA9IGFyZ3VtZW50cy5sZW5ndGggPiAxICYmIGFyZ3VtZW50c1sxXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzFdIDogdGhpcy5nZXRTZWxlY3RlZEtleSgpO1xuICAgICAgICBpZiAoa2V5Ym9hcmQgJiYga2V5Ym9hcmQuY29uc3RydWN0b3IpIHtcbiAgICAgICAgICAgIHZhciB0eXBlID0ga2V5Ym9hcmQuY29uc3RydWN0b3IubmFtZTtcbiAgICAgICAgICAgIGlmICh0eXBlID09PSBcIlJvd1wiKSB7XG4gICAgICAgICAgICAgICAga2V5Ym9hcmQuc2VsZWN0ZWRJbmRleCA9IGNvbHVtbjtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAga2V5Ym9hcmQuc2VsZWN0ZWRJbmRleCA9IHJvdztcbiAgICAgICAgICAgICAgICBrZXlib2FyZC5zZWxlY3RlZC5zZWxlY3RlZEluZGV4ID0gY29sdW1uO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuICAgIGdldFNlbGVjdGVkS2V5KCkge1xuICAgICAgICB2YXIgcm93LCBjb2x1bW47XG4gICAgICAgIHZhciBrZXlib2FyZCA9IHRoaXMuX2N1cnJlbnRLZXlib2FyZDtcbiAgICAgICAgdmFyIHR5cGUgPSBrZXlib2FyZC5jb25zdHJ1Y3Rvci5uYW1lO1xuICAgICAgICBpZiAodHlwZSA9PT0gXCJSb3dcIikge1xuICAgICAgICAgICAgcm93ID0gMDtcbiAgICAgICAgICAgIGNvbHVtbiA9IGtleWJvYXJkLnNlbGVjdGVkSW5kZXg7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByb3cgPSBrZXlib2FyZC5zZWxlY3RlZEluZGV4O1xuICAgICAgICAgICAgY29sdW1uID0ga2V5Ym9hcmQuc2VsZWN0ZWQu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IFsgXCJRXCIsIFwiV1wiLCBcIkVcIiwgXCJSXCIsIFwiVFwiLCBcIllcIiwgXCJVXCIsIFwiSVwiLCBcIk9cIiwgXCJQXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIjQCFcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcInN5bWJvbHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzeW1ib2wgbW9kZSwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3ltYm9sc1wiXG4gICAgICAgICAgICB9IF0sIFsgXCJBXCIsIFwiU1wiLCBcIkRcIiwgXCJGXCIsIFwiR1wiLCBcIkhcIiwgXCJKXCIsIFwiS1wiLCBcIkxcIiwgXCJAXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCLDocO2w7tcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhY2NlbnRzLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJhY2NlbnRzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIlpcIiwgXCJYXCIsIFwiQ1wiLCBcIlZcIiwgXCJCXCIsIFwiTlwiLCBcIk1cIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiX1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInVuZGVyc2NvcmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImxvd2VyY2FzZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNoaWZ0IG9mZiwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic2hpZnRcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuY29tXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBjb21cIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIubmV0XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBuZXRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuZWR1XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBlZHVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIub3JnXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBvcmdcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuY29cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGNvXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLnVrXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCB1a1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJDbGVhclwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJjbGVhclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsZWFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlNwYWNlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNwYWNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic3BhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRG9uZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkb25lXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG9uZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSBdLFxuICAgICAgICAgICAgbG93ZXJjYXNlOiBbIFsgXCIxXCIsIFwiMlwiLCBcIjNcIiwgXCI0XCIsIFwiNVwiLCBcIjZcIiwgXCI3XCIsIFwiOFwiLCBcIjlcIiwgXCIwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEZWxldGVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGVsZXRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIFwicVwiLCBcIndcIiwgXCJlXCIsIFwiclwiLCBcInRcIiwgXCJ5XCIsIFwidVwiLCBcImlcIiwgXCJvXCIsIFwicFwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiI0AhXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJzeW1ib2xzXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic3ltYm9sIG1vZGUsIGJ1dHRvblwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInN5bWJvbHNcIlxuICAgICAgICAgICAgfSBdLCBbIFwiYVwiLCBcInNcIiwgXCJkXCIsIFwiZlwiLCBcImdcIiwgXCJoXCIsIFwialwiLCBcImtcIiwgXCJsXCIsIFwiQFwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiw6HDtsO7XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJhY2NlbnRzXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYWNjZW50cywgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiYWNjZW50c1wiXG4gICAgICAgICAgICB9IF0sIFsgXCJ6XCIsIFwieFwiLCBcImNcIiwgXCJ2XCIsIFwiYlwiLCBcIm5cIiwgXCJtXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJfXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwidW5kZXJzY29yZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwicGVyaW9kLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi1cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkYXNoLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcInNoaWZ0XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJ1cHBlcmNhc2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzaGlmdCBvbiwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic2hpZnRcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuY29tXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBjb21cIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIubmV0XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBuZXRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuZWR1XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBlZHVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIub3JnXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBvcmdcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuY29cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGNvXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLnVrXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCB1a1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJDbGVhclwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJjbGVhclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsZWFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlNwYWNlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNwYWNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic3BhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRG9uZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkb25lXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG9uZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSBdLFxuICAgICAgICAgICAgYWNjZW50czogWyBbIFwiMVwiLCBcIjJcIiwgXCIzXCIsIFwiNFwiLCBcIjVcIiwgXCI2XCIsIFwiN1wiLCBcIjhcIiwgXCI5XCIsIFwiMFwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRlbGV0ZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOkXCIsIFwiw6tcIiwgXCLDr1wiLCBcIsO2XCIsIFwiw7xcIiwgXCLDv1wiLCBcIsOgXCIsIFwiw6hcIiwgXCLDrFwiLCBcIsOyXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIjQCFcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcInN5bWJvbHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzeW1ib2wgbW9kZSwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3ltYm9sc1wiXG4gICAgICAgICAgICB9IF0sIFsgXCLDuVwiLCBcIsOhXCIsIFwiw6lcIiwgXCLDrVwiLCBcIsOzXCIsIFwiw7pcIiwgXCLDvVwiLCBcIsOiXCIsIFwiw6pcIiwgXCJAXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJhYmNcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImxvd2VyY2FzZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImFscGhhIG1vZGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0sIFsgXCLDrlwiLCBcIsO0XCIsIFwiw7tcIiwgXCLDo1wiLCBcIsOxXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJfXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwidW5kZXJzY29yZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwicGVyaW9kLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi1cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkYXNoLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcInNoaWZ0XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJhY2NlbnRzVXBwZXJcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzaGlmdCBvZmYsIGJ1dHRvblwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNoaWZ0XCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLmNvbVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgY29tXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLm5ldFwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgbmV0XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLmVkdVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgZWR1XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLm9yZ1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgb3JnXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLmNvXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBjb1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi51a1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgdWtcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiQ2xlYXJcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiY2xlYXJcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjbGVhciwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJTcGFjZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwieGxcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzcGFjZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNwYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRvbmVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZG9uZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvbmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0gXSxcbiAgICAgICAgICAgIGFjY2VudHNVcHBlcjogWyBbIFwiMVwiLCBcIjJcIiwgXCIzXCIsIFwiNFwiLCBcIjVcIiwgXCI2XCIsIFwiN1wiLCBcIjhcIiwgXCI5XCIsIFwiMFwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRlbGV0ZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOEXCIsIFwiw4tcIiwgXCLDj1wiLCBcIsOWXCIsIFwiw5xcIiwgXCLFuFwiLCBcIsOAXCIsIFwiw4hcIiwgXCLDjFwiLCBcIsOSXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIjQCFcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcInN5bWJvbHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzeW1ib2wgbW9kZSwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3ltYm9sc1wiXG4gICAgICAgICAgICB9IF0sIFsgXCLDmVwiLCBcIsOBXCIsIFwiw4lcIiwgXCLDjVwiLCBcIsOTXCIsIFwiw5pcIiwgXCLDnVwiLCBcIsOCXCIsIFwiw4pcIiwgXCJAXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJhYmNcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImxvd2VyY2FzZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImFscGhhIG1vZGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0sIFsgXCLDjlwiLCBcIsOUXCIsIFwiw5tcIiwgXCLDg1wiLCBcIsORXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwicGVyaW9kLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi1cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkYXNoLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcInNoaWZ0XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJhY2NlbnRzXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic2hpZnQgb2ZmLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzaGlmdFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5jb21cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGNvbVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5uZXRcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIG5ldFwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5lZHVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGVkdVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5vcmdcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIG9yZ1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5jb1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgY29cIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIudWtcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIHVrXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkNsZWFyXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImNsZWFyXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xlYXIsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiU3BhY2VcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3BhY2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzcGFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEb25lXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRvbmVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb25lLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdIF0sXG4gICAgICAgICAgICBzeW1ib2xzOiBbIFsgXCIxXCIsIFwiMlwiLCBcIjNcIiwgXCI0XCIsIFwiNVwiLCBcIjZcIiwgXCI3XCIsIFwiOFwiLCBcIjlcIiwgXCIwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEZWxldGVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGVsZXRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIhXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZXhjbGFtYXRpb24sIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCBcIkBcIiwgXCIjXCIsIFwiJFwiLCBcIiVcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjYXJldCBjaXJjdW1mbGV4LCBidXR0b25cIlxuICAgICAgICAgICAgfSwgXCImXCIsIFwiKlwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiKFwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcIm9wZW4gcGFyZW50aGVzaXMsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiKVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsb3NlIHBhcmVudGhlc2lzLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImFiY1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYWxwaGEgbW9kZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwie1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcIm9wZW4gYnJhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwifVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsb3NlIGJyYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIltcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJvcGVuIGJyYWNrZXQsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiXVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsb3NlIGJyYWNrZXQsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiO1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNlbWljb2xvbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogJ1wiJyxcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3VibGVxdW90ZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIsXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY29tbWEsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwifFwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInZlcnRpY2FsIGJhciwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJcXFxcXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYmFja3NsYXNoLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJmb3J3YXJkc2xhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiw6HDtsO7XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJhY2NlbnRzXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYWNjZW50cywgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiYWNjZW50c1wiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjxcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJsZXNzIHRoYW4sIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiPlwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImdyZWF0ZXIgdGhhbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCI/XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwicXVlc3Rpb24gbWFyaywgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCI9XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZXF1YWwgc2lnbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJgXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZ3JhdmUgYWNjZW50LCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIn5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ0aWxkZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJfXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwidW5kZXJzY29yZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCI6XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY29sb24sIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiK1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInBsdXMgc2lnbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLmNvbVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgY29tXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLm5ldFwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgbmV0XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLmVkdVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgZWR1XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLm9yZ1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgb3JnXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLmNvXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBjb1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi51a1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgdWtcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiQ2xlYXJcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiY2xlYXJcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjbGVhciwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJTcGFjZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwieGxcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzcGFjZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNwYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRvbmVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZG9uZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvbmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0gXVxuICAgICAgICB9O1xuICAgIH1cbn1cblxuY2xhc3MgS2V5Ym9hcmRGdWxsU2NyZWVuIGV4dGVuZHMgS2V5Ym9hcmQge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJLZXlib2FyZEZ1bGxTY3JlZW5cIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkZjtcbiAgICB9XG4gICAgX2NvbnN0cnVjdCgpIHtcbiAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCgpO1xuICAgICAgICB0aGlzLmZvcm1hdHMgPSB0aGlzLmZ1bGxzY3JlZW5Gb3JtYXQ7XG4gICAgfVxuICAgIGdldCBmdWxsc2NyZWVuRm9ybWF0KCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgbGV0dGVyczogWyBbIFwiXCIsIFwiXCIsIFwiXCIs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FsgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkFCQ1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibGV0dGVyc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNhcHMgb24sIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiU3BhY2VcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3BhY2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzcGFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEZWxldGVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGVsZXRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiBdLCBbIFwiMVwiLCBcIjJcIiwgXCIzXCIsIFwiNFwiLCBcIjVcIiwgXCI2XCIsIFwiN1wiLCBcIjhcIiwgXCI5XCIsIFwiMFwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiIVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImV4Y2xhbWF0aW9uLCBidXR0b25cIlxuICAgICAgICAgICAgfSwgXCJAXCIsIFwiI1wiLCBcIiRcIiwgXCIlXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJeXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2FyZXQgY2lyY3VtZmxleCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIFwiJlwiLCBcIipcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIihcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJvcGVuIHBhcmVudGhlc2lzLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIilcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjbG9zZSBwYXJlbnRoZXNpcywgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJgXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZ3JhdmUgYWNjZW50LCBidXR0b25cIlxuICAgICAgICAgICAgfSwgXCJ+XCIsIFwiX1wiLCBcIi5cIiwgXCItXCIsIFwiK1wiIF0gXVxuICAgICAgICB9O1xuICAgIH1cbn1cblxuY2xhc3MgS2V5Ym9hcmROdW1iZXJzIGV4dGVuZHMgS2V5Ym9hcmQge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJLZXlib2FyZE51bWJlcnNcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkZjtcbiAgICB9XG4gICAgX2NvbnN0cnVjdCgpIHtcbiAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCgpO1xuICAgICAgICB0aGlzLmZvcm1hdHMgPSB0aGlzLm51bWJlcnNGb3JtYXQ7XG4gICAgfVxuICAgIGdldCBudW1iZXJzRm9ybWF0KCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgbnVtYmVyczogWyBcIjFcIiwgXCIyXCIsIFwiM1wiLCBcIjRcIiwgXCI1XCIsIFwiNlwiLCBcIjdcI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IiwgXCIzXCIsIFwiNFwiLCBcIjVcIiwgXCI2XCIsIFwiN1wiLCBcIjhcIiwgXCI5XCIsIFwiMFwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRlbGV0ZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIlFcIiwgXCJXXCIsIFwiRVwiLCBcIlJcIiwgXCJUXCIsIFwiWVwiLCBcIlVcIiwgXCJJXCIsIFwiT1wiLCBcIlBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIkFcIiwgXCJTXCIsIFwiRFwiLCBcIkZcIiwgXCJHXCIsIFwiSFwiLCBcIkpcIiwgXCJLXCIsIFwiTFwiLCBcIkBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIsOhw7bDu1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwiYWNjZW50c1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImFjY2VudHMsIGJ1dHRvblwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImFjY2VudHNcIlxuICAgICAgICAgICAgfSBdLCBbIFwiWlwiLCBcIlhcIiwgXCJDXCIsIFwiVlwiLCBcIkJcIiwgXCJOXCIsIFwiTVwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiX1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInVuZGVyc2NvcmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLlwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInBlcmlvZCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCItXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGFzaCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJzaGlmdFwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic2hpZnQgb2ZmLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzaGlmdFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkNsZWFyXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImNsZWFyXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xlYXIsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiU3BhY2VcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3BhY2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzcGFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEb25lXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRvbmVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb25lLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdIF0sXG4gICAgICAgICAgICBsb3dlcmNhc2U6IFsgWyBcIjFcIiwgXCIyXCIsIFwiM1wiLCBcIjRcIiwgXCI1XCIsIFwiNlwiLCBcIjdcIiwgXCI4XCIsIFwiOVwiLCBcIjBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0sIFsgXCJxXCIsIFwid1wiLCBcImVcIiwgXCJyXCIsIFwidFwiLCBcInlcIiwgXCJ1XCIsIFwiaVwiLCBcIm9cIiwgXCJwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIjQCFcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcInN5bWJvbHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzeW1ib2wgbW9kZSwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3ltYm9sc1wiXG4gICAgICAgICAgICB9IF0sIFsgXCJhXCIsIFwic1wiLCBcImRcIiwgXCJmXCIsIFwiZ1wiLCBcImhcIiwgXCJqXCIsIFwia1wiLCBcImxcIiwgXCJAXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCLDocO2w7tcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhY2NlbnRzLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJhY2NlbnRzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcInpcIiwgXCJ4XCIsIFwiY1wiLCBcInZcIiwgXCJiXCIsIFwiblwiLCBcIm1cIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcInVwcGVyY2FzZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNoaWZ0IG9uLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzaGlmdFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkNsZWFyXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImNsZWFyXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xlYXIsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiU3BhY2VcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3BhY2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzcGFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEb25lXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRvbmVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb25lLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdIF0sXG4gICAgICAgICAgICBhY2NlbnRzOiBbIFsgXCIxXCIsIFwiMlwiLCBcIjNcIiwgXCI0XCIsIFwiNVwiLCBcIjZcIiwgXCI3XCIsIFwiOFwiLCBcIjlcIiwgXCIwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEZWxldGVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGVsZXRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIFwiw6RcIiwgXCLDq1wiLCBcIsOvXCIsIFwiw7ZcIiwgXCLDvFwiLCBcIsO/XCIsIFwiw6BcIiwgXCLDqFwiLCBcIsOsXCIsIFwiw7JcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsO5XCIsIFwiw6FcIiwgXCLDqVwiLCBcIsOtXCIsIFwiw7NcIiwgXCLDulwiLCBcIsO9XCIsIFwiw6JcIiwgXCLDqlwiLCBcIkBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImFiY1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYWxwaGEgbW9kZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOuXCIsIFwiw7RcIiwgXCLDu1wiLCBcIsOjXCIsIFwiw7FcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNVcHBlclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNoaWZ0IG9mZiwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic2hpZnRcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJDbGVhclwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJjbGVhclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsZWFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlNwYWNlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNwYWNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic3BhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRG9uZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkb25lXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG9uZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSBdLFxuICAgICAgICAgICAgYWNjZW50c1VwcGVyOiBbIFsgXCIxXCIsIFwiMlwiLCBcIjNcIiwgXCI0XCIsIFwiNVwiLCBcIjZcIiwgXCI3XCIsIFwiOFwiLCBcIjlcIiwgXCIwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEZWxldGVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGVsZXRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIFwiw4RcIiwgXCLDi1wiLCBcIsOPXCIsIFwiw5ZcIiwgXCLDnFwiLCBcIsW4XCIsIFwiw4BcIiwgXCLDiFwiLCBcIsOMXCIsIFwiw5JcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOZXCIsIFwiw4FcIiwgXCLDiVwiLCBcIsONXCIsIFwiw5NcIiwgXCLDmlwiLCBcIsOdXCIsIFwiw4JcIiwgXCLDilwiLCBcIkBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImFiY1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYWxwaGEgbW9kZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOOXCIsIFwiw5RcIiwgXCLDm1wiLCBcIsODXCIsIFwiw5FcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiX1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInVuZGVyc2NvcmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzaGlmdCBvZmYsIGJ1dHRvblwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNoaWZ0XCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiQ2xlYXJcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiY2xlYXJcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjbGVhciwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJTcGFjZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwieGxcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzcGFjZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNwYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRvbmVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZG9uZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvbmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0gXSxcbiAgICAgICAgICAgIHN5bWJvbHM6IFsgWyBcIjFcIiwgXCIyXCIsIFwiM1wiLCBcIjRcIiwgXCI1XCIsIFwiNlwiLCBcIjdcIiwgXCI4XCIsIFwiOVwiLCBcIjBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiFcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJleGNsYW1hdGlvbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIFwiQFwiLCBcIiNcIiwgXCIkXCIsIFwiJVwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiXlwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNhcmV0IGNpcmN1bWZsZXgsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCBcIiZcIiwgXCIqXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIoXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwib3BlbiBwYXJlbnRoZXNpcywgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIpXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xvc2UgcGFyZW50aGVzaXMsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiYWJjXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJsb3dlcmNhc2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhbHBoYSBtb2RlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJ7XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwib3BlbiBicmFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJ9XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xvc2UgYnJhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiW1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcIm9wZW4gYnJhY2tldCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJdXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xvc2UgYnJhY2tldCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCI7XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic2VtaWNvbG9uLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiAnXCInLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdWJsZXF1b3RlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIixcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjb21tYSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJ8XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwidmVydGljYWwgYmFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlxcXFxcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJiYWNrc2xhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiL1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImZvcndhcmRzbGFzaCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCLDocO2w7tcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhY2NlbnRzLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJhY2NlbnRzXCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiPFwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImxlc3MgdGhhbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCI+XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZ3JlYXRlciB0aGFuLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIj9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJxdWVzdGlvbiBtYXJrLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIj1cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJlcXVhbCBzaWduLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImBcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJncmF2ZSBhY2NlbnQsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiflwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInRpbGRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjpcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjb2xvbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCItXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGFzaCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIrXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwicGx1cyBzaWduLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJDbGVhclwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJjbGVhclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsZWFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlNwYWNlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNwYWNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic3BhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRG9uZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkb25lXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG9uZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSBdXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBLZXlib2FyZElucHV0IGV4dGVuZHMgQmFzZSQxIHtcbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiS2V5Ym9hcmRJbnB1dFwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwiY2VudGVyS2V5Ym9hcmRcIiwgXCJkZWZhdWx0Rm9ybWF0XCIsIFwiaW5wdXRcIiwgXCJrZXlib2FyZFR5cGVcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRmO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgV3JhcHBlcjoge1xuICAgICAgICAgICAgICAgIHR5cGU6IENvbHVtbixcbiAgICAgICAgICAgICAgICBuZXZlclNjcm9sbDogdHJ1ZSxcbiAgICAgICAgICAgICAgICB3OiB0aGlzLncsXG4gICAgICAgICAgICAgICAgaXRlbXM6IFsge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJbnB1dCxcbiAgICAgICAgICAgICAgICAgICAgcmVmOiBcIklucHV0XCJcbiAgICAgICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEtleWJvYXJkLFxuICAgICAgICAgICAgICAgICAgICByZWY6IFwiS2V5Ym9hcmRcIixcbiAgICAgICAgICAgICAgICAgICAgcGFzc1NpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGtleWJvYXJkV2lkdGhDaGFuZ2VkOiB0cnVlXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IF0sXG4gICAgICAgICAgICAgICAgc2VsZWN0ZWRJbmRleDogMSxcbiAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIGtleWJvYXJkV2lkdGhDaGFuZ2VkOiBcIl91cGRhdGVXaWR0aFwiXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIFwiV3JhcHBlclwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIklucHV0XCIsXG4gICAgICAgICAgICBwYXRoOiBcIldyYXBwZXIuSW5wdXRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIktleWJvYXJkXCIsXG4gICAgICAgICAgICBwYXRoOiBcIldyYXBwZXIuS2V5Ym9hcmRcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIHRoaXMuX1dyYXBwZXIuc3R5bGUuaXRlbVNwYWNpbmcgPSB0aGlzLnN0eWxlLmlucHV0U3BhY2luZztcbiAgICAgICAgdGhpcy5fdXBkYXRlS2V5Ym9hcmRUeXBlKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUlucHV0KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUtleWJvYXJkKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUNlbnRlcktleWJvYXJkKCk7XG4gICAgfVxuICAgIF91cGRhdGVLZXlib2FyZFR5cGUoKSB7XG4gICAgICAgIGlmICh0aGlzLl9LZXlib2FyZC5jb25zdHJ1Y3RvciAhPT0gdGhpcy5rZXlib2FyZFR5cGUpIHtcbiAgICAgICAgICAgIHRoaXMuX1dyYXBwZXIuX3Jlc2V0SXRlbXMoKTtcbiAgICAgICAgICAgIHRoaXMuX1dyYXBwZXIuaXRlbXMgPSBbIHtcbiAgICAgICAgICAgICAgICB0eXBlOiBJbnB1dCxcbiAgICAgICAgICAgICAgICByZWY6IFwiSW5wdXRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHR5cGU6IHRoaXMua2V5Ym9hcmRUeXBlLFxuICAgICAgICAgICAgICAgIHJlZjogXCJLZXlib2FyZFwiLFxuICAgICAgICAgICAgICAgIHBhc3NTaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIGtleWJvYXJkV2lkdGhDaGFuZ2VkOiB0cnVlXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBdO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVJbnB1dCgpIHtcbiAgICAgICAgdGhpcy5fSW5wdXQucGF0Y2goX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLmlucHV0KSwge30sIHtcbiAgICAgICAgICAgIGNlbnRlckluUGF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uICAgICAgICByZXR1cm4gc3R5bGVzJGY7XG4gICAgfVxuICAgIF9jb25zdHJ1Y3QoKSB7XG4gICAgICAgIHN1cGVyLl9jb25zdHJ1Y3QoKTtcbiAgICAgICAgdGhpcy5mb3JtYXRzID0gdGhpcy5zZWFyY2hGb3JtYXQ7XG4gICAgfVxuICAgIGdldCBzZWFyY2hGb3JtYXQoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICB1cHBlcmNhc2U6IFsgWyBcIkFcIiwgXCJCXCIsIFwiQ1wiLCBcIkRcIiwgXCJFXCIsIFwiRlwiIF0sIFsgXCJHXCIsIFwiSFwiLCBcIklcIiwgXCJKXCIsIFwiS1wiLCBcIkxcIiBdLCBbIFwiTVwiLCBcIk5cIiwgXCJPXCIsIFwiUFwiLCBcIlFcIiwgXCJSXCIgXSwgWyBcIlNcIiwgXCJUXCIsIFwiVVwiLCBcIlZcIiwgXCJXXCIsIFwiWFwiIF0sIFsgXCJZXCIsIFwiWlwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiMVwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcIm51bWJlclwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiMlwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcIm51bWJlclwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiM1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcIm51bWJlclwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiNFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcIm51bWJlclwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjVcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjZcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjhcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjlcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjBcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJTcGFjZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwieGxcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzcGFjZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNwYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0gXVxuICAgICAgICB9O1xuICAgIH1cbn1cblxudmFyIGJhc2UkZSA9IHRoZW1lID0+IHtcbiAgICB2YXIgc2l6ZSA9IHRoZW1lLnNwYWNlci5sZztcbiAgICByZXR1cm4ge1xuICAgICAgICB3aWR0aDogc2l6ZSxcbiAgICAgICAgaGVpZ2h0OiBzaXplLFxuICAgICAgICByYWRpdXM6IHNpemUgL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Swgc3VwZXIuX3RlbXBsYXRlKCkuQ29udGVudCksIHt9LCB7XG4gICAgICAgICAgICAgICAgVGV4dFdyYXBwZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgZmxleDoge1xuICAgICAgICAgICAgICAgICAgICAgICAgZGlyZWN0aW9uOiBcImNvbHVtblwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIFRpdGxlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRleHRCb3hDaGFuZ2VkOiBcIl9vblRleHRCb3hDaGFuZ2VkXCJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIC4uLnN1cGVyLnByb3BlcnRpZXMsIFwiZGVzY3JpcHRpb25cIiwgXCJwcmVmaXhMb2dvXCIsIFwic3VmZml4TG9nb1wiLCBcInNob3VsZENvbGxhcHNlXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBhbGlhc1N0eWxlcygpIHtcbiAgICAgICAgcmV0dXJuIFsge1xuICAgICAgICAgICAgcHJldjogXCJ0aXRsZVBhZGRpbmdcIixcbiAgICAgICAgICAgIGN1cnI6IFwiY29udGVudFNwYWNpbmdcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIudGFncywge1xuICAgICAgICAgICAgbmFtZTogXCJEZXNjcmlwdGlvblwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50LlRleHRXcmFwcGVyLkRlc2NyaXB0aW9uXCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBfb25UZXh0Qm94Q2hhbmdlZCgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGl0bGUoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlRGVzY3JpcHRpb24oKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlVHJ1bmNhdGlvbigpO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVQcmVmaXhMb2dvKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVN1ZmZpeExvZ28oKTtcbiAgICAgICAgc3VwZXIuX3VwZGF0ZSgpO1xuICAgICAgICB0aGlzLl91cGRhdGVEZXNjcmlwdGlvbigpO1xuICAgIH1cbiAgICBfdXBkYXRlVGl0bGUoKSB7XG4gICAgICAgIHRoaXMuX1RleHRXcmFwcGVyLnBhdGNoKHtcbiAgICAgICAgICAgIFRpdGxlOiB7XG4gICAgICAgICAgICAgICAgY29udGVudDogdGhpcy50aXRsZSxcbiAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IHRoaXMuc3R5bGUudGl0bGVUZXh0U3R5bGVcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlRGVzY3JpcHRpb24oKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNEZXNjcmlwdGlvbikge1xuICAgICAgICAgICAgdmFyIGRlc2NyaXB0aW9uUGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgY29udGVudDogdGhpcy5kZXNjcmlwdGlvbixcbiAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS5kZXNjcmlwdGlvblRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuX2ZpeGVkV29yZFdyYXBXaWR0aFxuICAgICAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgdmlzaWJsZTogIXRoaXMuX2NvbGxhcHNlXG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9EZXNjcmlwdGlvbikge1xuICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uUGF0Y2ggPSBfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX29uVGV4dEJveENoYW5nZWRcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSwgZGVzY3JpcHRpb25QYXRjaCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9UZXh0V3JhcHBlci5wYXRjaCh7XG4gICAgICAgICAgICAgICAgRGVzY3JpcHRpb246IGRlc2NyaXB0aW9uUGF0Y2hcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIucGF0Y2goe1xuICAgICAgICAgICAgICAgIERlc2NyaXB0aW9uOiB1bmRlZmluZWRcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVUcnVuY2F0aW9uKCkge1xuICAgICAgICBpZiAodGhpcy5fVGl0bGUpIHtcbiAgICAgICAgICAgIHRoaXMuX1RpdGxlLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS50aXRsZVRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdGhpcy5maXhlZCxcbiAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuZml4ZWQgPyB0aGlzLl9maXhlZFdvcmRXcmFwV2lkdGggOiAwXG4gICAgICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVByZWZpeExvZ28oKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNQcmVmaXhMb2dvKSB7XG4gICAgICAgICAgICB0aGlzLl9wcmVmaXggPSB0aGlzLl9hZGRMb2dvUHJvcHModGhpcy5fcHJlZml4TG9nbyk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVN1ZmZpeExvZ28oKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNTdWZmaXhMb2dvKSB7XG4gICAgICAgICAgICB0aGlzLl9zdWZmaXggPSB0aGlzLl9hZGRMb2dvUHJvcHModGhpcy5fc3VmZml4TG9nbyk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX2FkZExvZ29Qcm9wcyhpY29uKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgaWNvbjogaWNvbixcbiAgICAgICAgICAgIHN0eWxlOiBfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICBjb2xvcjogdW5kZWZpbmVkXG4gICAgICAgICAgICB9LCB0aGlzLnN0eWxlLmxvZ29TdHlsZSlcbiAgICAgICAgfTtcbiAgICB9XG4gICAgZ2V0IF9oYXNQcm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ICAgICByZXR1cm4gdGhpcy5fYW5ub3VuY2U7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRoaXMudGl0bGUgKyB0aGlzLmRlc2NyaXB0aW9uICsgXCIsIExpc3QgSXRlbVwiO1xuICAgIH1cbn1cblxudmFyIGJhc2UkYyA9ICgpID0+ICh7XG4gICAgc2hvd0Fycm93czogZmFsc2UsXG4gICAgc2hvd0tub2I6IGZhbHNlXG59KTtcblxudmFyIG1vZGUkNCA9ICgpID0+ICh7XG4gICAgZm9jdXNlZDoge1xuICAgICAgICBzaG93QXJyb3dzOiB0cnVlXG4gICAgfVxufSk7XG5cbnZhciB0b25lJDcgPSB0aGVtZSA9PiAoe1xuICAgIG5ldXRyYWw6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIGFycm93Q29sb3I6IHRoZW1lLmNvbG9yLmZpbGxJbnZlcnNlLFxuICAgICAgICAgICAgICAgIHByb2dyZXNzQmFyOiB7XG4gICAgICAgICAgICAgICAgICAgIGJhckNvbG9yOiB0aGVtZS5jb2xvci5maWxsSW52ZXJzZVRlcnRpYXJ5LFxuICAgICAgICAgICAgICAgICAgICBwcm9ncmVzc0NvbG9yOiB0aGVtZS5jb2xvci5maWxsSW52ZXJzZVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH0sXG4gICAgaW52ZXJzZToge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBmb2N1c2VkOiB7XG4gICAgICAgICAgICAgICAgYXJyb3dDb2xvcjogdGhlbWUuY29sb3IuZmlsbE5ldXRyYWwsXG4gICAgICAgICAgICAgICAgcHJvZ3Jlc3NCYXI6IHtcbiAgICAgICAgICAgICAgICAgICAgYmFyQ29sb3I6IHRoZW1lLmNvbG9yLmZpbGxOZXV0cmFsVGVydGlhcnksXG4gICAgICAgICAgICAgICAgICAgIHByb2dyZXNzQ29sb3I6IHRoZW1lLmNvbG9yLmZpbGxOZXV0cmFsXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfSxcbiAgICBicmFuZDoge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBmb2N1c2VkOiB7XG4gICAgICAgICAgICAgICAgYXJyb3dDb2xvcjogdGhlbWUuY29sb3IuZmlsbEludmVyc2UsXG4gICAgICAgICAgICAgICAgcHJvZ3Jlc3NCYXI6IHtcbiAgICAgICAgICAgICAgICAgICAgYmFyQ29sb3I6IHRoZW1lLmNvbG9yLmZpbGxCcmFuZFRlcnRpYXJ5LFxuICAgICAgICAgICAgICAgICAgICBwcm9ncmVzc0NvbG9yOiB0aGVtZS5jb2xvci5maWxsQnJhbmRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyRjID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkYyxcbiAgICBtb2RlOiBtb2RlJDQsXG4gICAgdG9uZTogdG9uZSQ3XG59KTtcblxudmFyIGJhc2UkYiA9IHRoZW1lID0+IHtcbiAgICB2YXIgc2l6ZSA9IHRoZW1lLnNwYWNlci5sZztcbiAgICByZXR1cm4ge1xuICAgICAgICBhcnJvd0FscGhhVmFsdWU6IHRoZW1lLmFscGhhLnByaW1hcnksXG4gICAgICAgIGFycm93QWxwaGFWYWx1ZUxpbWl0OiB0aGVtZS5hbHBoYS5zZWNvbmRhcnksXG4gICAgICAgIGFycm93SGVpZ2h0OiB0aGVtZS5zcGFjZXIueHhsLFxuICAgICAgICBhcnJvd1NwYWNpbmc6IHRoZW1lLnNwYWNlci5tZCxcbiAgICAgICAgYXJyb3dXaWR0aDogdGhlbWUuc3BhY2VyLnh4bCxcbiAgICAgICAgYXJyb3dDb2xvcjogdGhlbWUuY29sb3IuZmlsbE5ldX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AgICAgY2lyY2xlQ29sb3I6IHRoZW1lLmNvbG9yLmludGVyYWN0aXZlTmV1dHJhbEZvY3VzXG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMkYiA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJGIsXG4gICAgbW9kZTogbW9kZSQzLFxuICAgIHRvbmU6IHRvbmUkNlxufSk7XG5cbmNsYXNzIFNsaWRlciBleHRlbmRzIEJhc2UkMSB7XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIHJldHVybiBcIlNsaWRlclwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRiO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgQ29udGFpbmVyOiB7XG4gICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyLFxuICAgICAgICAgICAgICAgIEJhcjoge1xuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgICAgICAgICBTbGlkZXJCYXI6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFByb2dyZXNzQmFyLFxuICAgICAgICAgICAgICAgICAgICAgICAgcHJvZ3Jlc3M6IC41LFxuICAgICAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGFubm91bmNlOiBcIlwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIENpcmNsZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogS25vYixcbiAgICAgICAgICAgICAgICAgICAgICAgIHpJbmRleDogNVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBMZWZ0QXJyb3c6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogSWNvbixcbiAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgeTogaCA9PiBoIC8gMlxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgUmlnaHRBcnJvdzoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwibWF4XCIsIFwibWluXCIsIFwic3RlcFwiLCBcInZhbHVlXCIsIFwidmVydGljYWxcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIFwiQ29udGFpbmVyXCIsIHtcbiAgICAgICAgICAgIG5hbWU6IFwiQmFyXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRhaW5lci5CYXJcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlNsaWRlckJhclwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250YWluZXIuQmFyLlNsaWRlckJhclwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiQ2lyY2xlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRhaW5lci5CYXIuQ2lyY2xlXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJMZWZ0QXJyb3dcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGFpbmVyLkxlZnRBcnJvd1wiXG4gICAgICAgI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AgICAgICB9XG4gICAgICAgIHRoaXMuX2RlY3JlbWVudFZhbHVlKCk7XG4gICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbkxlZnQgPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMub25MZWZ0KHRoaXMpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0cnVlO1xuICAgIH1cbiAgICBfaGFuZGxlUmlnaHQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9pc0Rpc2FibGVkTW9kZSkge1xuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX2luY3JlbWVudFZhbHVlKCk7XG4gICAgICAgIGlmICh0eXBlb2YgdGhpcy5vblJpZ2h0ID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLm9uUmlnaHQodGhpcyk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgfVxuICAgIF91cGRhdGVEaXJlY3Rpb24oKSB7XG4gICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgcGl2b3RYOiAwLFxuICAgICAgICAgICAgcm90YXRpb246IHRoaXMudmVydGljYWwgPyBkZWdyZWVzVG9SYWRpYW5zKDkwKSA6IDAsXG4gICAgICAgICAgICBtb3VudFk6IHRoaXMudmVydGljYWwgPyAuNSA6IDBcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVTbGlkZXJMYXlvdXQoKSB7XG4gICAgICAgIHZhciB3ID0gdGhpcy53IHx8IHRoaXMuc3R5bGUubWluV2lkdGg7XG4gICAgICAgIHRoaXMuX0NvbnRhaW5lci5wYXRjaCh7XG4gICAgICAgICAgICBoOiB0aGlzLnN0eWxlLmNvbnRhaW5lckhlaWdodCxcbiAgICAgICAgICAgIHc6IHcsXG4gICAgICAgICAgICBCYXI6IHtcbiAgICAgICAgICAgICAgICB4OiB0aGlzLl9jYWxjdWxhdGVkU2xpZGVyWCxcbiAgICAgICAgICAgICAgICBTbGlkZXJCYXI6IHtcbiAgICAgICAgICAgICAgICAgICAgeTogdGhpcy5zdHlsZS5jb250YWluZXJIZWlnaHQgLyAyLFxuICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLl9jYWxjdWxhdGVkU2xpZGVyV2lkdGgsXG4gICAgICAgICAgICAgICAgICAgIHN0eWxlOiBfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uOiAwXG4gICAgICAgICAgICAgICAgICAgIH0sIHRoaXMuc3R5bGUucHJvZ3Jlc3NCYXIpXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgdGhpcy5oID0gTWF0aC5tYXgodGhpcy5zdHlsZS5jb250YWluZXJIZWlnaHQsIHRoaXMuc3R5bGUuYXJyb3dIZWlnaHQpO1xuICAgIH1cbiAgICBfY2hlY2tBbmRTaWduYWxTaXplQ2hhbmdlKCkge1xuICAgICAgICBpZiAodGhpcy5oICE9PSB0aGlzLnByZXZIIHx8IHRoaXMuX0NvbnRhaW5lci53ICE9PSB0aGlzLnByZXZXIHx8IHRoaXMucm90YXRpb24gIT09IHRoaXMucHJldlJvdGF0aW9uKSB7XG4gICAgICAgICAgICB0aGlzLnNpZ25hbChcIm9uU2l6ZUNoYW5nZVwiLCB0aGlzKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnByZXZIID0gdGhpcy5oO1xuICAgICAgICB0aGlzLnByZXZXID0gdGhpcy5fQ29udGFpbmVyLnc7XG4gICAgICAgIHRoaXMucHJldlJvdGF0aW9uID0gdGhpcy5yb3RhdGlvbjtcbiAgICB9XG4gICAgX3VwZGF0ZVBvc2l0aW9ucygpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlU2xpZGVyUHJvZ3Jlc3MoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlQ2lyY2xl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4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodGhpcy5taW4gPCAwIHx8IHRoaXMubWF4IDwgMCkge1xuICAgICAgICAgICAgICAgIHhDaXJjbGVQb3NpdGlvbiA9ICh0aGlzLnZhbHVlIC0gdGhpcy5taW4pIC8gKHRoaXMubWF4IC0gdGhpcy5taW4pICogdGhpcy5fY2FsY3VsYXRlZFNsaWRlcldpZHRoO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB4Q2lyY2xlUG9zaXRpb24gPSB0aGlzLnZhbHVlIC8gdGhpcy5tYXggKiB0aGlzLl9jYWxjdWxhdGVkU2xpZGVyV2lkdGg7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX0NpcmNsZSkge1xuICAgICAgICAgICAgdGhpcy5fQ2lyY2xlLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBtb2RlOiB0aGlzLm1vZGUsXG4gICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgcmFkaXVzOiB0aGlzLnN0eWxlLnJhZGl1cyxcbiAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5zdHlsZS53LFxuICAgICAgICAgICAgICAgICAgICBoOiB0aGlzLnN0eWxlLmgsXG4gICAgICAgICAgICAgICAgICAgIGNpcmNsZUNvbG9yOiB0aGlzLnN0eWxlLmNpcmNsZUNvbG9yXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICB5OiB0aGlzLl9TbGlkZXJCYXIueSArIDEsXG4gICAgICAgICAgICAgICAgYWxwaGE6IHRoaXMuX2lzRm9jdXNlZE1vZGUgJiYgdGhpcy5zdHlsZS5zaG93S25vYiA/IDEgOiAwXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIGlmICh0aGlzLnN0eWxlLmNpcmNsZUFuaW1hdGlvbiAmJiBPYmplY3Qua2V5cyh0aGlzLnN0eWxlLmNpcm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ICByaWdodEFscGhhID0gYWxwaGFMaW1pdDtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9MZWZ0QXJyb3cuc21vb3RoID0ge1xuICAgICAgICAgICAgYWxwaGE6IGxlZnRBbHBoYVxuICAgICAgICB9O1xuICAgICAgICB0aGlzLl9SaWdodEFycm93LnNtb290aCA9IHtcbiAgICAgICAgICAgIGFscGhhOiByaWdodEFscGhhXG4gICAgICAgIH07XG4gICAgfVxuICAgIF91cGRhdGVBcnJvd3MoKSB7XG4gICAgICAgIHZhciBhcnJvd1Byb3BzID0ge1xuICAgICAgICAgICAgdzogdGhpcy5zdHlsZS5hcnJvd1dpZHRoLFxuICAgICAgICAgICAgaDogdGhpcy5zdHlsZS5hcnJvd0hlaWdodCxcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgY29sb3I6IHRoaXMuc3R5bGUuYXJyb3dDb2xvclxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICB0aGlzLl9MZWZ0QXJyb3cucGF0Y2goX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBhcnJvd1Byb3BzKSwge30sIHtcbiAgICAgICAgICAgIGljb246IHRoaXMuc3R5bGUuaWNvbkxlZnRTcmNcbiAgICAgICAgfSkpO1xuICAgICAgICB0aGlzLl9SaWdodEFycm93LnBhdGNoKF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgYXJyb3dQcm9wcyksIHt9LCB7XG4gICAgICAgICAgICBpY29uOiB0aGlzLnN0eWxlLmljb25SaWdodFNyY1xuICAgICAgICB9KSk7XG4gICAgICAgIHRoaXMuX1JpZ2h0QXJyb3cuc21vb3RoID0ge1xuICAgICAgICAgICAgeDogdGhpcy5zdHlsZS5hcnJvd1NwYWNpbmcgKyB0aGlzLl9jYWxjdWxhdGVkU2xpZGVyV2lkdGggKyB0aGlzLl9CYXIueFxuICAgICAgICB9O1xuICAgIH1cbiAgICBfZGVjcmVtZW50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1bmRlZmluZWQgJiYgdGhpcy5fYW5ub3VuY2UgIT09IG51bGwpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9hbm5vdW5jZTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdGhpcy52YWx1ZS50b1N0cmluZygpO1xuICAgIH1cbiAgICBzdGF0aWMgX3N0YXRlcygpIHtcbiAgICAgICAgcmV0dXJuIFsgY2xhc3MgVmVydGljYWxTbGlkZXIgZXh0ZW5kcyh0aGlzKXtcbiAgICAgICAgICAgIF9oYW5kbGVMZWZ0KCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIF9oYW5kbGVSaWdodCgpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBfaGFuZGxlVXAoKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2lzRGlzYWJsZWRNb2RlKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdGhpcy5fZGVjcmVtZW50VmFsdWUoKTtcbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIHRoaXMub25VcCA9PT0gXCJmdW5jdGlvblwiKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLm9uVXAodGhpcyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgX2hhbmRsZURvd24oKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2lzRGlzYWJsZWRNb2RlKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdGhpcy5faW5jcmVtZW50VmFsdWUoKTtcbiAgICAgICAgICAgIC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GVtZS5jb2xvci50ZXh0SW52ZXJzZVNlY29uZGFyeVxuICAgICAgICB9XG4gICAgfVxufSk7XG5cbnZhciB0b25lJDUgPSB0aGVtZSA9PiAoe1xuICAgIG5ldXRyYWw6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIHZhbHVlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dEludmVyc2VTZWNvbmRhcnlcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIHZhbHVlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxTZWNvbmRhcnlcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGJyYW5kOiB7XG4gICAgICAgIG1vZGU6IHtcbiAgICAgICAgICAgIGZvY3VzZWQ6IHtcbiAgICAgICAgICAgICAgICB2YWx1ZVRleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHRJbnZlcnNlU2Vjb25kYXJ5XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMkYSA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJGEsXG4gICAgbW9kZTogbW9kZSQyLFxuICAgIHRvbmU6IHRvbmUkNVxufSk7XG5cbmNsYXNzIExpc3RJdGVtU2xpZGVyIGV4dGVuZHMgTGlzdEl0ZW0ge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJMaXN0SXRlbVNsaWRlclwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRhO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICB2YXIgdGVtcGxhdGUgPSBzdXBlci5fdGVtcGxhdGU7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRlbXBsYXRlKCkpLCB7fSwge1xuICAgICAgICAgICAgQ29udGVudDogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0ZW1wbGF0ZSgpLkNvbnRlbnQpLCB7fSwge1xuICAgICAgICAgICAgICAgIGZsZXg6IHtcbiAgICAgICAgICAgICAgICAgICAgZGlyZWN0aW9uOiBcImNvbHVtblwiXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBUZXh0V3JhcHBlcjogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0ZW1wbGF0ZSgpLkNvbnRlbnQuVGV4dFdyYXBwZXIpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IDAsXG4gICAgICAgICAgICAgICAgICAgIGZsZXg6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgICAgIFNsaWRlcjoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBOZXN0ZWRTbGlkZXIsXG4gICAgICAgICAgICAgICAgICAgIG1vdW50WDogLjUsXG4gICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIG9uQ2hhbmdlOiBcIl9vblNsaWRlckNoYW5nZWRcIlxuICAgICAgICAgICAgICAgICAgICB9X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gICAgICAgc3VwZXIuX29uVGV4dEJveENoYW5nZWQoKTtcbiAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIuaCA9IE1hdGgubWF4KHRoaXMuX1RpdGxlID8gdGhpcy5fVGl0bGUuaCA6IDAsIHRoaXMuX1ZhbHVlID8gdGhpcy5fVmFsdWUuaCA6IDApO1xuICAgIH1cbiAgICBfdXBkYXRlVmFsdWUoKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNWYWx1ZSkge1xuICAgICAgICAgICAgdmFyIHZhbHVlUGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgY29udGVudDogdGhpcy52YWx1ZS50b1N0cmluZygpLFxuICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS52YWx1ZVRleHRTdHlsZSlcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIG1vdW50WDogMSxcbiAgICAgICAgICAgICAgICB4OiB0aGlzLncgLSB0aGlzLl9wYWRkaW5nWFxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmICghdGhpcy5fVmFsdWUpIHtcbiAgICAgICAgICAgICAgICB2YWx1ZVBhdGNoID0gX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRleHRCb3hDaGFuZ2VkOiBcIl9vblRleHRCb3hDaGFuZ2VkXCJcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0sIHZhbHVlUGF0Y2gpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIucGF0Y2goe1xuICAgICAgICAgICAgICAgIFZhbHVlOiB2YWx1ZVBhdGNoXG4gICAgICAgICAgICB9KTt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Y2UoKSB7XG4gICAgICAgIGlmICh0aGlzLl9hbm5vdW5jZSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2Fubm91bmNlO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0aGlzLnRpdGxlICsgdGhpcy52YWx1ZSArIFwiLCBMaXN0IEl0ZW0gU2xpZGVyXCI7XG4gICAgfVxufVxuXG52YXIgYmFzZSQ5ID0gdGhlbWUgPT4gKHtcbiAgICBhcnJvd0FscGhhVmFsdWU6IHRoZW1lLmFscGhhLnByaW1hcnksXG4gICAgYXJyb3dBbHBoYVZhbHVlTGltaXQ6IHRoZW1lLmFscGhhLnNlY29uZGFyeSxcbiAgICBhcnJvd1dpZHRoOiB0aGVtZS5zcGFjZXIueHhsLFxuICAgIGFycm93SGVpZ2h0OiB0aGVtZS5zcGFjZXIueHhsLFxuICAgIGljb25MZWZ0U3JjOiB0aGVtZS5hc3NldC5hcnJvd0xlZnQsXG4gICAgaWNvblJpZ2h0U3JjOiB0aGVtZS5hc3NldC5hcnJvd1JpZ2h0XG59KTtcblxudmFyIHRvbmUkNCA9IHRoZW1lID0+ICh7XG4gICAgbmV1dHJhbDoge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBmb2N1c2VkOiB7XG4gICAgICAgICAgICAgICAgYXJyb3dDb2xvcjogdGhlbWUuY29sb3IuZmlsbEludmVyc2VcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH0sXG4gICAgaW52ZXJzZToge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBmb2N1c2VkOiB7XG4gICAgICAgICAgICAgICAgYXJyb3dDb2xvcjogdGhlbWUuY29sb3IuZmlsbE5ldXRyYWxcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH0sXG4gICAgYnJhbmQ6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIGFycm93Q29sb3I6IHRoZW1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ZXIuX29uVGV4dEJveENoYW5nZWQoKTtcbiAgICAgICAgdGhpcy5fYWxpZ25QaWNrZXIoKTtcbiAgICB9XG4gICAgX2NvbnN0cnVjdCgpIHtcbiAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCgpO1xuICAgICAgICB0aGlzLl9vcHRpb25zID0gW107XG4gICAgICAgIHRoaXMuX3NlbGVjdGVkSW5kZXggPSAwO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICBzdXBlci5fdXBkYXRlKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVBpY2tlcigpO1xuICAgICAgICB0aGlzLl91cGRhdGVBcnJvd3MoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlQXJyb3dzQWxwaGEoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlQWxpZ25tZW50KCk7XG4gICAgfVxuICAgIF91cGRhdGVBbGlnbm1lbnQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9pc0ZvY3VzZWRNb2RlKSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBqdXN0aWZ5OiBcImNlbnRlclwiXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIGp1c3RpZnk6IFwibGVmdFwiXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlQXJyb3dzKCkge1xuICAgICAgICBpZiAoIXRoaXMuX2lzRm9jdXNlZE1vZGUpIHtcbiAgICAgICAgICAgIHZhciBvZmZBbHBoYSA9IC4wMDE7XG4gICAgICAgICAgICBpZiAodGhpcy5fTGVmdEFycm93KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fTGVmdEFycm93LmFscGhhID0gb2ZmQWxwaGE7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy5fUmlnaHRBcnJvdykge1xuICAgICAgICAgICAgICAgIHRoaXMuX1JpZ2h0QXJyb3cuYWxwaGEgPSBvZmZBbHBoYTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICB2YXIgYXJyb3dQcm9wcyA9IHtcbiAgICAgICAgICAgIHc6IHRoaXMuc3R5bGUuYXJyb3dXaWR0aCxcbiAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuYXJyb3dIZWlnaHQsXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIGNvbG9yOiB0aGlzLnN0eWxlLmFycm93Q29sb3JcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBhbHBoYTogdGhpcy5zdHlsZS5hcnJvd0FscGhhVmFsdWVcbiAgICAgICAgfTtcbiAgICAgICAgaWYgKCF0aGlzLl9MZWZ0QXJyb3cpIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIExlZnRBcnJvdzoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fTGVmdEFycm93LnBhdGNoKF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgYXJyb3dQcm9wcyksIHt9LCB7XG4gICAgICAgICAgICBpY29uOiB0aGlzLnN0eWxlLmljb25MZWZ0U3JjXG4gICAgICAgIH0pKTtcbiAgICAgICAgdGhpcy5fTGVmdEFycm93LnNtb290aCA9IHtcbiAgICAgICAgICAgIHg6IHRoaXMuc3R5bGUucGFkZGluZ1hcbiAgICAgICAgfTtcbiAgICAgICAgaWYgKCF0aGlzLl9SaWdodEFycm93KSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBSaWdodEFycm93OiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEljb24sXG4gICAgICAgICAgICAgICAgICAgIG1vdW50WTogLjUsXG4gICAgICAgICAgICAgICAgICAgIG1vdW50WDogMSxcbiAgICAgICAgICAgICAgICAgICAgeTogaCA9PiBoIC8gMlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX1JpZ2h0QXJyb3cucGF0Y2goX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBhcnJvd1Byb3BzKSwge30sIHtcbiAgICAgICAgICAgIGljb246IHRoaXMuc3R5bGUuaWNvblJpZ2h0U3JjXG4gICAgICAgIH0pKTtcbiAgICAgICAgdGhpcy5fUmlnaHRBcnJvdy5zbW9vdGggPSB7XG4gICAgICAgICAgICB4OiB0aGlzLncgLSB0aGlzLnN0eWxlLnBhZGRpbmdYXG4gICAgICAgIH07XG4gICAgfVxuICAgIF91cGRhdGVQaWNrZXIoKSB7XG4gICAgICAgIHZhciB3ID0gdGhpcy53IC0gdGhpcy5fcGFkZGluZ1ggLSB0aGlzLnN0eWxlLmFycm93V2lkdGggKiAyO1xuICAgICAgICBpZiAoIXRoaXMuX1BpY2tlcikge1xuICAgICAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIucGF0Y2goe1xuICAgICAgICAgICAgICAgIFBpY2tlcjoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBSb3csXG4gICAgICAgICAgICAgICAgICAgIGNsaXBwaW5nOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICBhbHdheXNTY3JvbGw6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGVjdGVkQ2hhbmdlOiBcIl91cGRhdGVBcnJvd3NBbHBoYVwiXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9QaWNrZXIucGF0Y2goe1xuICAgICAgICAgICAgdmlzaWJsZTogIXRoaXMuX2NvbGxhcHNlLFxuICAgICAgICAgICAgaDogdGhpcy5zdHlsZS5kZXNjcmlwdGlvblRleHRTdHlsZS5saW5lSGVpZ2h0LFxuICAgICAgICAgICAgdzogdyxcbiAgICAgICAgICAgIGl0ZW1zOiB0aGlzLm9wdGlvbnMubWFwKChvcHRpb24gPT4gKHtcbiAgICAgICAgICAgICAgICB0eXBlOiBNYXJxdWVlLFxuICAgICAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuZGVzY3JpcHRpb25UZXh0U3R5bGUubGluZUhlaWdodCxcbiAgICAgICAgICAgICAgICB3OiB3LFxuICAgICAgICAgICAgICAgIGNlbnRlckFsaWduOiB0aGlzLl9pc0ZvY3VzZWRNb2RlLFxuICAgICAgICAgICAgICAgIHRpdGxlOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUuZGVzY3JpcHRpb25UZXh0U3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0OiBvcHRpb25cbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfSkpKSxcbiAgICAgICAgICAgIHNlbGVjdGVkSW5kZXg6IHRoaXMuc2VsZWN0ZWRJbmRleFxuICAgICAgICB9KTtcbiAgICAgICAgdGhpcy5fYWxpZ25QaWNrZXIoKTtcbiAgICB9XG4gICAgX2FsaWduUGlja2VyKCkge1xuICAgICAgICB0aGlzLl9QaWNrZXIucGF0Y2goe1xuICAgICAgICAgICAgbW91bnRYOiB0aGlzLl9pc0ZvY3VzZWRNb2RlID8gLjUgOiAwLFxuICAgICAgICAgICAgeDogdGhpcy5faXNGb2N1c2VkTW9kZSA/IHRoaXMuX1RpdGxlLncgLyAyIDogMFxuICAgICAgICB9KTtcbiAgICB9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IGNpcmNsZUFuaW1hdGlvbjogc2Nyb2xsXG4gICAgfTtcbn07XG5cbnZhciBzdHlsZXMkNyA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJDdcbn0pO1xuXG5jbGFzcyBTY3JvbGxTbGlkZXIgZXh0ZW5kcyBTbGlkZXIge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJTY3JvbGxTbGlkZXJcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkNztcbiAgICB9XG59XG5cbmNsYXNzIFNjcm9sbFdyYXBwZXIgZXh0ZW5kcyBCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJDg7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBjbGlwcGluZzogdHJ1ZSxcbiAgICAgICAgICAgIEZhZGVDb250YWluZXI6IHtcbiAgICAgICAgICAgICAgICBTY3JvbGxDb250YWluZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgdzogX3cgPT4gX3csXG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIFNsaWRlcjoge1xuICAgICAgICAgICAgICAgIHR5cGU6IFNjcm9sbFNsaWRlcixcbiAgICAgICAgICAgICAgICB2ZXJ0aWNhbDogdHJ1ZSxcbiAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIG9uU2l6ZUNoYW5nZTogXCJfdXBkYXRlU2Nyb2xsQ29udGFpbmVyU2l6ZVwiXG4gICAgICAgICAgICA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0gXCJjb2x1bW5cIjtcbiAgICAgICAgdGhpcy5fZmFkZUNvbnRlbnQgPSB0cnVlO1xuICAgICAgICB0aGlzLl9zbGlkZXJXaWR0aCA9IDA7XG4gICAgfVxuICAgIF9hZnRlclRleHRCb3hVcGRhdGUodGV4dEJveCkge1xuICAgICAgICBpZiAodGhpcy5fcHJldlcgIT09IHRleHRCb3guZmluYWxXIHx8IHRoaXMuX3ByZXZIICE9PSB0ZXh0Qm94LmZpbmFsSCkge1xuICAgICAgICAgICAgdGhpcy5fcHJldlcgPSB0ZXh0Qm94LmZpbmFsVztcbiAgICAgICAgICAgIHRoaXMuX3ByZXZIID0gdGV4dEJveC5maW5hbEg7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVTY3JvbGxXcmFwcGVyTGF5b3V0KCk7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVBbHBoYSgpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9yZXNldEZsZXhDb250YWluZXIoKSB7XG4gICAgICAgIHRoaXMuX0ZhZGVDb250YWluZXIucGF0Y2goe1xuICAgICAgICAgICAgU2Nyb2xsQ29udGFpbmVyOiB1bmRlZmluZWRcbiAgICAgICAgfSk7XG4gICAgICAgIHRoaXMuX0ZhZGVDb250YWluZXIucGF0Y2goe1xuICAgICAgICAgICAgU2Nyb2xsQ29udGFpbmVyOiB7XG4gICAgICAgICAgICAgICAgdzogX3cyID0+IF93MixcbiAgICAgICAgICAgICAgICB3b3JkV3JhcDogdHJ1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZSgpIHtcbiAgICAgICAgaWYgKHRoaXMuX2NvbnRlbnRDaGFuZ2VkKSB7XG4gICAgICAgICAgICB0aGlzLl9yZXNldEZsZXhDb250YWluZXIoKTtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUF1dG9TY3JvbGwoKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl91cGRhdGVTY3JvbGxDb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OiB0aGlzLl9jb250ZW50V2lkdGgsXG4gICAgICAgICAgICB5OiB0aGlzLnN0eWxlLmNvbnRlbnRNYXJnaW5Ub3AsXG4gICAgICAgICAgICB4OiB0aGlzLnN0eWxlLmNvbnRlbnRNYXJnaW5MZWZ0LFxuICAgICAgICAgICAgcnR0OiB0cnVlLFxuICAgICAgICAgICAgc2hhZGVyOiBzaG91bGRGYWRlID8ge1xuICAgICAgICAgICAgICAgIHR5cGU6IGxuZy5zaGFkZXJzLkZhZGVPdXQsXG4gICAgICAgICAgICAgICAgYm90dG9tOiB0aGlzLnN0eWxlLmZhZGVIZWlnaHRcbiAgICAgICAgICAgIH0gOiB1bmRlZmluZWRcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF9zY3JvbGxDb250YWluZXJMb2FkZWQoX3JlZjIzKSB7XG4gICAgICAgIHZhciB7aDogaH0gPSBfcmVmMjM7XG4gICAgICAgIHRoaXMuX1Njcm9sbENvbnRhaW5lci5oID0gaDtcbiAgICAgICAgdGhpcy5fdXBkYXRlU2Nyb2xsV3JhcHBlckxheW91dCgpO1xuICAgIH1cbiAgICBfdXBkYXRlU2Nyb2xsQ29udGFpbmVyKCkge1xuICAgICAgICBpZiAoIXRoaXMuY29udGVudCkgcmV0dXJuO1xuICAgICAgICBpZiAodHlwZW9mIHRoaXMuY29udGVudCA9PT0gXCJzdHJpbmdcIikge1xuICAgICAgICAgICAgdGhpcy5fU2Nyb2xsQ29udGFpbmVyLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBmbGV4OiB7XG4gICAgICAgICAgICAgICAgICAgIGRpcmVjdGlvbjogXCJjb2x1bW5cIlxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgU2Nyb2xsYWJsZVRleHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgaDogMCxcbiAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5fY29udGVudFdpZHRoLFxuICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICBjb250ZW50OiB0aGlzLmNvbnRlbnQsXG4gICAgICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS50ZXh0U3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuX2NvbnRlbnRXaWR0aFxuICAgICAgICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3Njcm9sbENvbnRhaW5lckxvYWRlZFwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIG9uQWZ0ZXJVcGRhdGU6IHRoaXMuX2FmdGVyVGV4dEJveFVwZGF0ZS5iaW5kKHRoaXMpXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSBpZiAoQXJyYXkuaXNBcnJheSh0aGlzLmNvbnRlbnQpKSB7XG4gICAgICAgICAgICB2YXIgY29udGVudCA9IHt9O1xuICAgICAgICAgICAgdGhpcy5jb250ZW50LmZvckVhY2goKChpdGVtLCBpbmRleCkgPT4ge1xuICAgICAgICAgICAgICAgIHZhciBpZCA9IFwiU2Nyb2xsVGV4dFwiLmNvbmNhdChpbmRleCk7XG4gICAgICAgICAgICAgICAgY29udGVudFtpZF0gPSBfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5fY29udGVudFdpZHRoXG4gICAgICAgICAgICAgICAgfSwgaXRlbSk7XG4gICAgICAgICAgICAgICAgaWYgKGl0ZW0udGV4dCkge1xuICAgICAgICAgICAgICAgICAgICBjb250ZW50W2lkXSA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgICAgICAgICBjb250ZW50OiBpdGVtLnRleHQsXG4gICAgICAgICAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUudGV4dFN0eWxlKSwgaXRlbS5zdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcFdpZHRoOiB0aGlzLl9jb250ZW50V2lkdGhcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgICAgIG9uQWZ0ZXJVcGRhdGU6IHRoaXMuX2FmdGVyVGV4dEJveFVwZGF0ZS5iaW5kKHRoaXMpXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgdGhpcy5fU2Nyb2xsQ29udGFpbmVyLnBhdGNoKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgIGZsZXg6IHtcbiAgICAgICAgICAgICAgICAgICAgZGlyZWN0aW9uOiB0aGlzLmZsZXhEaXJlY3Rpb24sXG4gICAgICAgICAgICAgICAgICAgIHdyYXA6IHRoaXMuc2hvdWxkV3JhcFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0sIGNvbnRlbnQpKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfc2Nyb2xsRG93bigp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ogKHRoaXMudyArIGV4dHJhQm91bmRzWCkgLyAyLFxuICAgICAgICAgICAgICAgIHk6ICh0aGlzLmggKyBleHRyYUJvdW5kc1kpIC8gMixcbiAgICAgICAgICAgICAgICBtb3VudDogLjUsXG4gICAgICAgICAgICAgICAgcnR0OiB0aGlzLm1hc2tTaGFkb3csXG4gICAgICAgICAgICAgICAgc2hhZGVyOiB0aGlzLm1hc2tTaGFkb3cgPyB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IGxuZy5zaGFkZXJzLkhvbGUsXG4gICAgICAgICAgICAgICAgICAgIHc6IHRoaXMudyAtIGhvbGVwdW5jaEVycm9yLFxuICAgICAgICAgICAgICAgICAgICBoOiB0aGlzLmggLSBob2xlcHVuY2hFcnJvcixcbiAgICAgICAgICAgICAgICAgICAgeDogc2hhZG93U2l6ZSArIGhvbGVwdW5jaEVycm9yIC8gMixcbiAgICAgICAgICAgICAgICAgICAgeTogc2hhZG93U2l6ZSArIGhvbGVwdW5jaEVycm9yIC8gMixcbiAgICAgICAgICAgICAgICAgICAgcmFkaXVzOiByYWRpdXNcbiAgICAgICAgICAgICAgICB9IDogdW5kZWZpbmVkLFxuICAgICAgICAgICAgICAgIFNoYWRvdzoge1xuICAgICAgICAgICAgICAgICAgICBjb2xvcjogdGhpcy5zdHlsZS5jb2xvcixcbiAgICAgICAgICAgICAgICAgICAgdGV4dHVyZTogbG5nLlRvb2xzLmdldFNoYWRvd1JlY3QodGhpcy53ICsgdGhpcy5zdHlsZS5zcHJlYWQgKiAyLCB0aGlzLmggKyB0aGlzLnN0eWxlLnNwcmVhZCAqIDIsIHJhZGl1cywgdGhpcy5zdHlsZS5ibHVyKVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIGlmICh0aGlzLnNob3VsZFNtb290aCA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICB0aGlzLnNob3VsZFNtb290aCA9IHRydWU7XG4gICAgIC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hdGUoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlU2VsZWN0ZWQoKTtcbiAgICB9XG4gICAgX3VwZGF0ZVNlbGVjdGVkKCkge1xuICAgICAgICBpZiAodGhpcy5fcHJldmVTZWxlY3RlZEluZGV4ICE9PSB0aGlzLnNlbGVjdGVkSW5kZXgpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9wcmV2ZVNlbGVjdGVkSW5kZXggIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIHZhciBwcmV2Q29udGVudCA9IHRoaXMudGFnKFwiQ29udGVudFwiLmNvbmNhdCh0aGlzLl9wcmV2ZVNlbGVjdGVkSW5kZXgpKTtcbiAgICAgICAgICAgICAgICBwcmV2Q29udGVudC5zbW9vdGggPSB7XG4gICAgICAgICAgICAgICAgICAgIGFscGhhOiAwXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5faGFzQ29udGVudCkge1xuICAgICAgICAgICAgICAgICAgICBwcmV2Q29udGVudC5fZ2V0VHJhbnNpdGlvbihcImFscGhhXCIpLm9uY2UoXCJmaW5pc2hcIiwgKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2ZhZGVJbkNvbnRlbnQoKTtcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5zZWxlY3RlZEluZGV4ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZmFkZUluQ29udGVudCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5faGFzQ29udGVudCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2ZhZGVJbkNvbnRlbnQoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX3ByZXZlU2VsZWN0ZWRJbmRleCA9IHRoaXMuc2VsZWN0ZWRJbmRleDtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfZmFkZUluQ29udGVudCgpIHtcbiAgICAgICAgdGhpcy5fc2VsZWN0ZWRDb250ZW50LnNtb290aCA9IHtcbiAgICAgICAgICAgIGFscGhhOiAxXG4gICAgICAgIH07XG4gICAgICAgIHRoaXMuX3NlbGVjdGVkQ29udGVudC5fZ2V0VHJhbnNpdGlvbihcImFscGhhXCIpLm9uY2UoXCJmaW5pc2hcIiwgKCgpID0+IHtcbiAgICAgICAgICAgIHRoaXMuaCA9IHRoaXMuX3NlbGVjdGVkQ29udGVudC5oO1xuICAgICAgICAgICAgdGhpcy5zaWduYWwoXCJjb250ZW50SGVpZ2h0Q2hhbmdlXCIsIHRoaXMuaCk7XG4gICAgICAgIH0pKTtcbiAgICB9XG4gICAgX3VwZGF0ZUNvbnRlbnQoKSB7XG4gICAgICAgIHZhciBhbGxDb250ZW50ID0gdGhpcy5jb250ZW50SXRlbXMucmVkdWNlKCgoYWNjLCBpdGVtLCBpZHgpID0+IHtcbiAgICAgICAgICAgIHZhciBjb21wb25lbnQ7XG4gICAgICAgICAgICB2YXIgdGFnTmFtZSA9IFwiQ29udGVudFwiLmNvbmNhdChpZHgpO1xuICAgICAgICAgICAgaWYgKHR5cGVvZiBpdGVtID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgICAgICB2YXIgY29tcG9uZW50TG9hZGVyID0gaXRlbSgpO1xuICAgICAgICAgICAgICAgIGlmIChjb21wb25lbnRMb2FkZXIudGhlbikge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9sb2FkQXN5bmNDb21wb25lbnQoY29tcG9uZW50TG9hZGVyLCBpZHgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbXBvbmVudCA9IGNvbXBvbmVudExvYWRlcjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGNvbXBvbmVudCA9IGl0ZW07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoY29tcG9uZW50KSB7XG4gICAgICAgICAgICAgICAgYWNjW3RhZ05hbWVdID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBjb21wb25lbnQpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBhbHBoYTogMFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgfSksIHt9KTtcbiAgICAgICAgdGhpcy5wYXRjaChhbGxDb250ZW50KTtcbiAgICB9XG4gICAgX2xvYWRBc3luY0NvbXBvbmVudChjb21wb25lbnRMb2FkZXIsIGlkeCkge1xuICAgICAgICBjb21wb25lbnRMb2FkZXIudGhlbigoY29tcG9uZW50ID0+IHtcbiAgICAgICAgICAgIHZhciB0YWdOYW1lID0gXCJDb250ZW50XCIuY29uY2F0KGlkeCk7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBbdGFnTmFtZV06IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgY29tcG9uZW50KSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgYWxwaGE6IDBcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pKTtcbiAgICB9XG4gICAgc2V0IGNvbnRlbnRJdGVtcyhjb250ZW50SXRlbXMpIHtcbiAgICAgICAgaWYgKCFzdHJpbmdpZnlDb21wYXJlKGNvbnRlbnRJdGVtcywgdGhpcy5fY29udGVudEl0ZW1zKSkge1xuICAgICAgICAgICAgdGhpcy5fY29udGVudEl0ZW1zID0gY29udGVudEl0ZW1zO1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlQ29udGVudCgpO1xuICAgICAgICB9XG4gICAgfVxuICAgIGdldCBjb250ZW50SXRlbXMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9jb250ZW50SXRlbXM7XG4gICAgfVxuICAgIGdldCBfaGFzQ29udGVudCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3NlbGVjdGVkQ29udGVudCAmJiB0aGlzLl9zZWxlY3RlZENvbnRlbnQuY2hpbGRyZW4ubGVuZ3RoID4gMDtcbiAgICB9XG4gICAgZ2V0IF9zZWxlY3RlZENvbnRlbnQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnRhZyhcIkNvbnRlbnRcIi5jb25jYXQodGhpcy5zZWxlY3RlZEluZGV4KSk7XG4gICAgfVxuICAgIF9nZXRGb2N1c2VkKCkge1xuICAgICAgICBpZiAodGhpcy5faGFzQ29udGVudCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3NlbGVjdGVkQ29udGVudDtcbiAgICAgICAgfVxuICAgIH1cbn1cblxudmFyIGJhc2UkNCA9IHRoZW1lID0+ICh7XG4gICAgdGFiU3BhY2luZzogdGhlbWUuc3BhY2VyLmxnLFxuICAgIHRhYnNNYXJnaW5Cb3R0b206IHRoZW1lLnNwYWNlci54eGxcbn0pO1xuXG52YXIgc3R5bGVzJDQgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSQ0XG59KTtcblxuY2xhc3MgVGFiQmFyIGV4dGVuZHMgQmFzZSQxIHtcbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgVGFiczoge1xuICAgICAgICAgICAgICAgIHR5cGU6IFJvdyxcbiAgICAgICAgICAgICAgICBhdXRvUmVzaXplSGVpZ2h0OiB0cnVlLFxuICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgc2VsZWN0ZWRDaGFuZ2U6IFwiX3NlbGVjdGVkVGFiQ2hhbmdlXCJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LFxuICAgICAgICA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4ge1xuICAgICAgICAgICAgICAgIHRhYi5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIGFscGhhOiAxXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9UYWJzLml0ZW1zLmZvckVhY2goKHRhYiA9PiB7XG4gICAgICAgICAgICAgICAgdGFiLnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgYWxwaGE6IHRhYiA9PT0gdGhpcy5fVGFicy5zZWxlY3RlZCA/IDEgOiAuM1xuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfSkpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVUYWJDb250ZW50KCkge1xuICAgICAgICB2YXIgbWFyZ2luID0gdGhpcy5zdHlsZS50YWJzTWFyZ2luQm90dG9tO1xuICAgICAgICB0aGlzLl9UYWJDb250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgIHk6IHRoaXMuX1RhYnMuaCArIG1hcmdpbixcbiAgICAgICAgICAgIGNvbnRlbnRJdGVtczogdGhpcy5fdGFiQ29udGVudCxcbiAgICAgICAgICAgIHNlbGVjdGVkSW5kZXg6IHRoaXMuX2lzRm9jdXNlZE1vZGUgPyB0aGlzLl9UYWJzLnNlbGVjdGVkSW5kZXggOiB1bmRlZmluZWRcbiAgICAgICAgfSk7XG4gICAgfVxuICAgICRpdGVtQ2hhbmdlZCgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGFiQmFySGVpZ2h0KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVRhYkNvbnRlbnQoKTtcbiAgICB9XG4gICAgX3VwZGF0ZVRhYkJhckhlaWdodCgpIHtcbiAgICAgICAgdmFyIGg7XG4gICAgICAgIGlmICh0aGlzLmNvbGxhcHNlKSB7XG4gICAgICAgICAgICBoID0gdGhpcy5faXNGb2N1c2VkTW9kZSAmJiB0aGlzLl90YWJDb250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WUuY29sb3IuZmlsbEludmVyc2UsXG4gICAgICAgIHRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0SW52ZXJzZVxuICAgICAgICB9XG4gICAgfSxcbiAgICBzZWxlY3RlZDoge1xuICAgICAgICBiYWNrZ3JvdW5kQ29sb3I6IHRoZW1lLmNvbG9yLmludGVyYWN0aXZlTmV1dHJhbEZvY3VzU29mdCxcbiAgICAgICAgY29udGVudENvbG9yOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbCxcbiAgICAgICAgdGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgICAgIH1cbiAgICB9LFxuICAgIGRpc2FibGVkOiB7XG4gICAgICAgIGJhY2tncm91bmRDb2xvcjogdGhlbWUuY29sb3IuZmlsbFRyYW5zcGFyZW50LFxuICAgICAgICBjb250ZW50Q29sb3I6IHRoZW1lLmNvbG9yLmZpbGxOZXV0cmFsRGlzYWJsZWQsXG4gICAgICAgIHRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHRvbmUkMiA9IHRoZW1lID0+ICh7XG4gICAgbmV1dHJhbDoge30sXG4gICAgaW52ZXJzZToge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBmb2N1c2VkOiB7XG4gICAgICAgICAgICAgICAgY29udGVudENvbG9yOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbCxcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH0sXG4gICAgYnJhbmQ6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIGNvbnRlbnRDb2xvcjogdGhlbWUuY29sb3IuZmlsbE5ldXRyYWwsXG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyQzID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkMyxcbiAgICBtb2RlOiBtb2RlLFxuICAgIHRvbmU6IHRvbmUkMlxufSk7XG5cbmNsYXNzIFRhYiBleHRlbmRzIFN1cmZhY2Uge1xuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHN1cGVyLl90ZW1wbGF0ZSgpKSwge30sIHtcbiAgICAgICAgICAgIENvbnRlbnQ6IHtcbiAgICAgICAgICAgICAgICBtb3VudDogLjUsXG4gICAgICAgICAgICAgICAgeDogdyA9PiB3IC8gMixcbiAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyLFxuICAgICAgICAgICAgICAgIFRleHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX29uVGV4dEJveENoYW5nZWRcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkMztcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIHJldHVybiBcIlRhYlwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwiaWNvblwiLCBcInRpdGxlXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCB0YWdzKCkge1xuICAgICAgICByZXR1cm4gWyAuLi5zdXBlci50YWdzLCBcIkNvbnRlbnRcIiwge1xuICAgICAgICAgICAgbmFtZTogXCJJY29uXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRlbnQuSWNvblwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGV4dFwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50LlRleHRcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgYWxpYXNTdHlsZXMoKSB7XG4gICAgICAgIHJldHVybiBbIHtcbiAgICAgICAgICAgIHByZXY6IFwibm9UaXRsZVBhZGRpbmdYXCIsXG4gICAgICAgICAgICBjdXJyOiBcInBhZGRpbmdYTm9UaXRsZVwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgX29uVGV4dEJveENoYW5nZWQoKSB7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUNvbnRlbnQoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGFiU2l6ZSgpO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICBzdXBlci5fdXBkYXRlKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUljb24oKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGV4dCgpO1xuICAgICAgICB0aGlzLl91cGRhdGVDb250ZW50KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVRhYlNpemUoKTtcbiAgICB9XG4gICAgX3VwZGF0ZUljb24oKSB7XG4gICAgICAgIGlmICghdGhpcy5pY29uKSB7XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBJY29uOiB1bmRlZmluZWRcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHZhciBpY29uUGF0Y2ggPSB7XG4gICAgICAgICAgICBpY29uOiB0aGlzLmljb24sXG4gICAgICAgICAgICB3OiB0aGlzLnN0eWxlLmljb25TaXplLFxuICAgICAgICAgICAgaDogdGhpcy5zdHlsZS5pY29uU2l6ZSxcbiAgICAgICAgICAgIHk6IHRoaXMuX0NvbnRlbnQuaCAvIDIsXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIGNvbG9yOiB0aGlzLnN0eWxlLmNvbnRlbnRDb2xvclxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICBpZiAodGhpcy50aXRsZSkge1xuICAgICAgICAgICAgaWNvblBhdGNoLnggPSAwO1xuICAgICAgICAgICAgaWNvblBhdGNoLm1vdW50WCA9IDA7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpY29uUGF0Y2gueCA9IHRoaXMuX0NvbnRlbnQudyAvIDI7XG4gICAgICAgICAgICBpY29uUGF0Y2gubW91bnRYID0gLjU7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX0ljb24pIHtcbiAgICAgICAgICAgIHRoaXMuX0ljb24ucGF0Y2goaWNvblBhdGNoKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgIEljb246IF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41XG4gICAgICAgICAgICAgICAgfSwgaWNvblBhdGNoKVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVRleHQoKSB7XG4gICAgICAgIHZhciB0ZXh0UGF0Y2ggPSB7XG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLnRpdGxlLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IHRoaXMuc3R5bGUudGV4dFN0eWxlXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgeTogdGhpcy5fQ29udGVudC5oIC8gMlxuICAgICAgICB9O1xuICAgICAgICBpZiAodGhpcy5pY29uKSB7XG4gICAgICAgICAgICB0ZXh0UGF0Y2gueCA9IHRoaXMuX2ljb25XICsgdGhpcy5zdHlsZS5pY29uTWFyZ2luUmlnaHQ7XG4gICAgICAgICAgICB0ZXh0UGF0Y2gubW91bnRYID0gMDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRleHRQYXRjaC54ID0gdGhpcy5fQ29udGVudC53IC8gMjtcbiAgICAgICAgICAgIHRleHRQYXRjaC5tb3VudFggPSAuNTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9UZXh0LnBhdGNoKHRleHRQYXRjaCk7XG4gICAgfVxuICAgIF91cGRhdGVDb250ZW50KCkge1xuICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgIHc6IHRoaXMuX2ljb25XICsgKHRoaXMudGl0bGUgPyB0aGlzLnN0eWxlLmljb25NYXJnaW5SaWdodCA6IDApICsgdGhpcy5fdGV4dFcsXG4gICAgICAgICAgICBoOiBNYXRoLm1heCh0aGlzLl9pY29uSCwgdGhpcy5fVGV4dC5oKVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZVRhYlNpemUoKSB7XG4gICAgICAgIGlmICh0aGlzLnRpdGxlIHx8IHRoaXMuaWNvbikge1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgdzogdGhpcy5fcGFkZGluZ1ggKiAyICsgdGhpcy5fQ29udGVudC53LFxuICAgICAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUucGFkZGluZ1kgKiAyICsgdGhpcy5fQ29udGVudC5oXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIHc6IDAsXG4gICAgICAgICAgICAgICAgaDogMFxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgZ2V0IF90ZXh0VygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMudGl0bGUgPyB0aGlzLl9UZXh0LncgOiAwO1xuICAgIH1cbiAgICBnZXQgX2ljb25XKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5pY29uICYmIHRoaXMuX0ljb24gIT09IHVuZGVmaW5lZCA/IHRoaXMuX0ljb24udyA6IDA7XG4gICAgfVxuICAgIGdldCBfaWNvbkgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLmljb24gJiYgdGhpcy5fSWNvbiAhPT0gdW5kZWZpbmVkID8gdGhpcy5fSWNvbi5oIDogMDtcbiAgICB9XG4gICAgZ2V0IF9wYWRkaW5nWCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMudGl0bGUgPyB0aGlzLnN0eWxlLnBhZGRpbmdYIDogdGhpcy5zdHlsZS5wYWRkaW5nWE5vVGl0bGU7XG4gICAgfVxuICAgIHNldCBhbm5vdW5jZShhbm5vdW5jZSkge1xuICAgICAgICBzdXBlci5hbm5vdW5jZSA9IGFubm91bmNlO1xuICAgIH1cbiAgICBnZXQgYW5ub3VuY2UoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9hbm5vdW5jZSB8fCB0aGlzLl9UZXh0ICYmIHRoaXMuX1RleHQuYW5ub3VuY2U7XG4gICAgfVxufVxuXG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VxufSk7XG5cbnZhciBzdHlsZXMkMiA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJDIsXG4gICAgdG9uZTogdG9uZSQxXG59KTtcblxuY2xhc3MgVG9nZ2xlIGV4dGVuZHMgQmFzZSQxIHtcbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiVG9nZ2xlXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJDI7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBDb250YWluZXI6IHtcbiAgICAgICAgICAgICAgICBTdHJva2U6IHt9LFxuICAgICAgICAgICAgICAgIEtub2I6IHt9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJDb250YWluZXJcIiwge1xuICAgICAgICAgICAgbmFtZTogXCJLbm9iXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRhaW5lci5Lbm9iXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJTdHJva2VcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGFpbmVyLlN0cm9rZVwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gWyBcImNoZWNrZWRcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IGFsaWFzU3R5bGVzKCkge1xuICAgICAgICByZXR1cm4gWyB7XG4gICAgICAgICAgICBwcmV2OiBcInN0cm9rZVdlaWdodFwiLFxuICAgICAgICAgICAgY3VycjogXCJzdHJva2VXaW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IHRoZW1lLmNvbG9yLmZpbGxJbnZlcnNlLFxuICAgICAgICB0ZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxcbiAgICAgICAgfVxuICAgIH0sXG4gICAgYnJhbmQ6IHtcbiAgICAgICAgYmFja2dyb3VuZENvbG9yOiB0aGVtZS5jb2xvci5maWxsQnJhbmQsXG4gICAgICAgIHRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICB9XG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSxcbiAgICB0b25lOiB0b25lXG59KTtcblxuY2xhc3MgVG9vbHRpcCBleHRlbmRzIEJhc2UkMSB7XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIHJldHVybiBcIlRvb2x0aXBcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXM7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBhbHBoYTogMCxcbiAgICAgICAgICAgIHNjYWxlOiAuNSxcbiAgICAgICAgICAgIG1vdW50WDogLjUsXG4gICAgICAgICAgICB4OiB3ID0+IHcgLyAyLFxuICAgICAgICAgICAgQmFja2dyb3VuZDoge1xuICAgICAgICAgICAgICAgIFRleHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3RleHRMb2FkZWRcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwidGl0bGVcIiwgXCJkZWxheVZpc2libGVcIiwgXCJ0aW1lVmlzaWJsZVwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJCYWNrZ3JvdW5kXCIsIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGV4dFwiLFxuICAgICAgICAgICAgcGF0aDogXCJCYWNrZ3JvdW5kLlRleHRcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgYWxpYXNTdHlsZXMoKSB7XG4gICAgICAgIHJldHVybiBbIHtcbiAgICAgICAgICAgIHByZXY6IFwicG9pbnRlckhcIixcbiAgICAgICAgICAgIGN1cnI6IFwicG9pbnRlckhlaWdodFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIHByZXY6IFwicG9pbnRlcldcIixcbiAgICAgICAgICAgIGN1cnI6IFwicG9pbnRlcldpZHRoXCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVUZXh0KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUJhY2tncm91bmQoKTtcbiAgICB9XG4gICAgX3VwZGF0ZVRleHQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9UZXh0KSB7XG4gICAgICAgICAgICB0aGlzLl9UZXh0LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBjb250ZW50OiB0aGlzLnRpdGxlLFxuICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogdGhpcy5zdHlsZS50ZXh0U3R5bGVcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdGV4dExvYWRlZCgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlQmFja2dyb3VuZEhlaWdodCgpO1xuICAgICAgICB0aGlzLl91cGRhdGVUZXh0UG9zaXRpb24oKTtcbiAgICB9XG4gICAgX3VwZGF0ZUJhY2tncm91bmQoKSB7XG4gICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgQmFja2dyb3VuZDoge1xuICAgICAgICAgICAgICAgIHRleHR1cmU6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogQnViYmxlLFxuICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLl9CYWNrZ3JvdW5kLncsXG4gICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuX0JhY2tncm91bmQuaCxcbiAgICAgICAgICAgICAgICAgICAgcmFkaXVzOiBnZXRNYXhSb3VuZFJhZGl1cyh0aGlzLnN0eWxlLnJhZGl1cywgdGhpcy5fQmFja2dyb3VuZC53IC0gdGhpcy5zdHlsZS5wb2ludGVySGVpZ2h0LCB0aGlzLl9CYWNrZ3JvdW5kLmggLSB0aGlzLnN0eWxlLnBvaW50ZXJIZWlnaHQpLFxuICAgICAgICAgICAgICAgICAgICBwb2ludGVyV2lkdGg6IHRoaXMuc3R5bGUucG9pbnRlcldpZHRoLFxuICAgICAgICAgICAgICAgICAgICBwb2ludGVySGVpZ2h0OiB0aGlzLnN0eWxlLnBvaW50ZXJIZWlnaHQsXG4gICAgICAgICAgICAgICAgICAgIGNvbG9yOiB0aGlzLnN0eWxlLmJhY2tncm91bmRDb2xvclxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVCYWNrZ3JvdW5kSGVpZ2h0KCkge1xuICAgICAgICB2YXIgYmFja2dyb3VuZEggPSB0aGlzLl9UZXh0LmZpbmFsSCArIHRoaXMuc3R5bGUucGFkZGluZ1kgKiAyICsgdGhpcy5zdHlsZS5wb2ludGVySGVpZ2h0O1xuICAgICAgICB2YXIgYmFja2dyb3VuZFcgPSB0aGlzLl9UZXh0LmZpbmFsVyArIHRoaXMuc3R5bGUucGFkZGluZ1ggKiAyO1xuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIHc6IGJhY2tncm91bmRXLFxuICAgICAgICAgICAgaDogYmFja2dyb3VuZEgsXG4gICAgICAgICAgICBtb3VudFk6IDEsXG4gICAgICAgICAgICB5OiAtdGhpcy5zdHlsZS5tYXJnaW5Cb3R0b20sXG4gICAgICAgICAgICBCYWNrZ3JvdW5kOiB7XG4gICAgICAgICAgICAgICAgdzogYmFja2dyb3VuZFcsXG4gICAgICAgICAgICAgICAgaDogYmFja2dyb3VuZEgsXG4gICAgICAgICAgICAgICAgdGV4dHVyZToge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBCdWJibGUsXG4gICAgICAgICAgICAgICAgICAgIHc6IGJhY2tncm91bmRXLFxuICAgICAgICAgICAgICAgICAgICBoOiBiYWNrZ3JvdW5kSFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVUZXh0UG9zaXRpb24oKSB7XG4gICAgICAgIGlmICh0aGlzLl9UZXh0KSB7XG4gICAgICAgICAgICB0aGlzLl9UZXh0LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBtb3VudDogLjUsXG4gICAgICAgICAgICAgICAgeDogdGhpcy5fQmFja2dyb3VuZC53IC8gMixcbiAgICAgICAgICAgICAgICB5OiAodGhpcy5fQmFja2dyb3VuZC5oIC0gdGhpcy5zdHlsZS5wb2ludGVySGVpZ2h0KSAvIDJcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9jbGVhclRpbWVycygpIHtcbiAgICAgICAgY2xlYXJUaW1lb3V0KHRoaXMuX2hpZGVUaW1lcik7XG4gICAgICAgIGNsZWFyVGltZW91dCh0aGlzLl9zaG93VGltZXIpO1xuICAgIH1cbiAgICBfdHJhbnNpdGlvbkluKCkge1xuICAgICAgICB2YXIgc21vb3RoID0ge1xuICAgICAgICAgICAgc21vb3RoOiB7XG4gICAgICAgICAgICAgICAgYWxwaGE6IFsgMSwgdGhpcy5zdHlsZS50cmFuc2l0aW9uIF0sXG4gICAgICAgICAgICAgICAgc2NhbGU6IFsgMSwgdGhpcy5zdHlsZS50cmFuc2l0aW9uIF1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgICAgaWYgKHRoaXMuZGVsYXlWaXNpYmxlKSB7XG4gICAgICAgICAgICB0aGlzLl9zaG93VGltZXIgPSBzZXRUaW1lb3V0KCgoKSA9PiB7XG4gICAgICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIHNtb290aDogc21vb3RoXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9KSwgdGhpcy5kZWxheVZpc2libGUpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fc2hvd1RpbWVyID0gdW5kZWZpbmVkO1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgc21vb3RoOiBzbW9vdGhcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX2hpZGVUaW1lciA9IHRoaXMudGltZVZpc2libGUgPyBzZXRUaW1lb3V0KCgoKSA9PiB7XG4gICAgICAgICAgICB0aGlzLl91bmZvY3VzKCk7XG4gICAgICAgIH0pLCB0aGlzLnRpbWVWaXNpYmxlICsgKHRoaXMuZGVsYXlWaXNpYmxlIHx8IDApKSA6IHVuZGVmaW5lZDtcbiAgICB9XG4gICAgX3RyYW5zaXRpb25PdXQoKSB7XG4gICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgc21vb3RoOiB7XG4gICAgICAgICAgICAgICAgYWxwaGE6IFsgM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ICAgICAgICBwYXVzZSA9IDA7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgeWllbGQgZGVsYXkocGF1c2UpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHBocmFzZSA9PT0gXCJzdHJpbmdcIiAmJiBwaHJhc2UubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciB0b3RhbFJldHJpZXMgPSAzO1xuICAgICAgICAgICAgICAgICAgICB2YXIgcmV0cmllc0xlZnQgPSB0b3RhbFJldHJpZXM7XG4gICAgICAgICAgICAgICAgICAgIHdoaWxlIChhY3RpdmUgJiYgcmV0cmllc0xlZnQgPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHlpZWxkIHNwZWFrKHBocmFzZSwgdXR0ZXJhbmNlcywgbGFuZyk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0cmllc0xlZnQgPSAwO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlIGluc3RhbmNlb2YgU3BlZWNoU3ludGhlc2lzRXJyb3JFdmVudCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZS5lcnJvciA9PT0gXCJuZXR3b3JrXCIpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHJpZXNMZWZ0LS07XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJTcGVlY2ggc3ludGhlc2lzIG5ldHdvcmsgZXJyb3IuIFJldHJpZXMgbGVmdDogXCIuY29uY2F0KHJldHJpZXNMZWZ0KSk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB5aWVsZCBkZWxheSg1MDAgKiAodG90YWxSZXRyaWVzIC0gcmV0cmllc0xlZnQpKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChlLmVycm9yID09PSBcImNhbmNlbGVkXCIgfHwgZS5lcnJvciA9PT0gXCJpbnRlcnJ1cHRlZFwiKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXRyaWVzTGVmdCA9IDA7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoXCJTcGVlY2hTeW50aGVzaXNFcnJvckV2ZW50OiBcIi5jb25jYXQoZS5lcnJvcikpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhyb3cgZTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBwaHJhc2UgPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICAgICAgICAgICAgICB2YXIgc2VyaWVzUmVzdWx0ID0gc3BlYWtTZXJpZXMocGhyYXNlKCksIGxhbmcsIGZhbHNlKTtcbiAgICAgICAgICAgICAgICAgICAgbmVzdGVkU2VyaWVzUmVzdWx0cy5wdXNoKHNlcmllc1Jlc3VsdCk7XG4gICAgICAgICAgICAgICAgICAgIHlpZWxkIHNlcmllc1Jlc3VsdC5zZXJpZXM7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KHBocmFzZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIF9zZXJpZXNSZXN1bHQgPSBzcGVha1NlcmllcyhwaHJhc2UsIGxhbmcsIGZhbHNlKTtcbiAgICAgICAgICAgICAgICAgICAgbmVzdGVkU2VyaWVzUmVzdWx0cy5wdXNoKF9zZXJpZXNSZXN1bHQpO1xuICAgICAgICAgICAgICAgICAgICB5aWVsZCBfc2VyaWVzUmVzdWx0LnNlcmllcztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZmluYWxseSB7XG4gICAgICAgICAgICBhY3RpdmUgPSBmYWxzZTtcbiAgICAgICAgfVxuICAgIH0pKSgpO1xuICAgIHJldHVybiB7XG4gICAgICAgIHNlcmllczogc2VyaWVzQ2hhaW4sXG4gICAgICAgIGdldCBhY3RpdmUoKSB7XG4gICAgICAgICAgICByZXR1cm4gYWN0aXZlO1xuICAgICAgICB9LFxuICAgICAgICBhcHBlbmQ6IHRvU3BlYWsgPT4ge1xuICAgICAgICAgICAgcmVtYWluaW5nUGhyYXNlcy5wdXNoKHRvU3BlYWspO1xuICAgICAgICB9LFxuICAgICAgICBjYW5jZWw6ICgpID0+IHtcbiAgICAgICAgICAgIGlmICghYWN0aXZlKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHJvb3QpIHtcbiAgICAgICAgICAgICAgICBzeW50aC5jYW5jZWwoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG5lc3RlZFNlcmllc1Jlc3VsdHMuZm9yRWFjaCgobmVzdGVkU2VyaWVzUmVzdWx0cyA9PiB7XG4gICAgICAgICAgICAgICAgbmVzdGVkU2VyaWVzUmVzdWx0cy5jYW5jZWwoKTtcbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgIGFjdGl2ZSA9IGZhbHNlO1xuICAgICAgICB9XG4gICAgfTtcbn1cblxudmFyIGN1cnJlbnRTZXJpZXM7XG5cbmZ1bmN0aW9uIFNwZWVjaCh0b1NwZWFrLCBsYW5nKSB7XG4gICAgY3VycmVudFNlcmllcyAmJiBjdXJyZW50U2VyaWVzLmN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HJ1Y3QoKSB7XG4gICAgICAgICAgICB0aGlzLl9hbm5vdW5jZUVuZGVkVGltZW91dDtcbiAgICAgICAgICAgIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nID0gXCJcIjtcbiAgICAgICAgICAgIHN1cGVyLl9jb25zdHJ1Y3QgJiYgc3VwZXIuX2NvbnN0cnVjdCgpO1xuICAgICAgICB9XG4gICAgICAgIF92b2ljZU91dCh0b0Fubm91bmNlKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fdm9pY2VPdXREaXNhYmxlZCkge1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciB0b1NwZWFrID0gdG9Bbm5vdW5jZTtcbiAgICAgICAgICAgIGlmIChhbm5vdW5jZXJPcHRpb25zLmFiYnJldmlhdGlvbnNDb25maWcuYWJicmV2aWF0aW9uc1BhdHRlcm4pIHtcbiAgICAgICAgICAgICAgICB0b1NwZWFrID0gQXJyYXkuaXNBcnJheSh0b0Fubm91bmNlKSA/IHRvQW5ub3VuY2UubWFwKChwaHJhc2UgPT4gdHJhbnNsYXRlQWJicmV2KHBocmFzZSwgYW5ub3VuY2VyT3B0aW9ucy5hYmJyZXZpYXRpb25zQ29uZmlnKSkpIDogdHJhbnNsYXRlQWJicmV2KHRvQW5ub3VuY2UsIGFubm91bmNlck9wdGlvbnMuYWJicmV2aWF0aW9uc0NvbmZpZyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgc3BlZWNoID0gc3BlYWsodG9TcGVhaywgb3B0aW9ucy5sYW5ndWFnZSk7XG4gICAgICAgICAgICBpZiAoc3BlZWNoICYmIHNwZWVjaC5zZXJpZXMpIHtcbiAgICAgICAgICAgICAgICBzcGVlY2guc2VyaWVzLnRoZW4oKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdGFnZS5lbWl0KFwiYW5ub3VuY2VFbmRlZFwiKTtcbiAgICAgICAgICAgICAgICB9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oZWxtLmFubm91bmNlKSB7XG4gICAgICAgICAgICAgICAgICAgIGFjYy5wdXNoKFsgZWxtTmFtZShlbG0pLCBcIkFubm91bmNlXCIsIGVsbS5hbm5vdW5jZSBdKTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGVsbS50aXRsZSkge1xuICAgICAgICAgICAgICAgICAgICBhY2MucHVzaChbIGVsbU5hbWUoZWxtKSwgXCJUaXRsZVwiLCBlbG0udGl0bGUgfHwgXCJcIiBdKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgICAgIH0pLCBbXSk7XG4gICAgICAgICAgICBmb2N1c0RpZmYucmV2ZXJzZSgpLnJlZHVjZSgoKGFjYywgZWxtKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKGVsbS5hbm5vdW5jZUNvbnRleHQpIHtcbiAgICAgICAgICAgICAgICAgICAgYWNjLnB1c2goWyBlbG1OYW1lKGVsbSksIFwiQ29udGV4dFwiLCBlbG0uYW5ub3VuY2VDb250ZXh0IF0pO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGFjYy5wdXNoKFsgZWxtTmFtZShlbG0pLCBcIk5vIENvbnRleHRcIiwgXCJcIiBdKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgICAgIH0pLCB0b0Fubm91bmNlKTtcbiAgICAgICAgICAgIGlmICh0aGlzLmRlYnVnKSB7XG4gICAgICAgICAgICAgICAgY29uc29sZS50YWJsZSh0b0Fubm91bmNlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRvQW5ub3VuY2UgPSB0b0Fubm91bmNlLnJlZHVjZSgoKGFjYywgYSkgPT4ge1xuICAgICAgICAgICAgICAgIHZhciB0eHQgPSBhWzJdO1xuICAgICAgICAgICAgICAgIHR4dCAmJiBhY2MucHVzaCh0eHQpO1xuICAgICAgICAgICAgICAgIHJldHVybiBhY2M7XG4gICAgICAgICAgICB9KSwgW10pO1xuICAgICAgICAgICAgaWYgKHRvQW5ub3VuY2UubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgdGhpcy4kYW5ub3VuY2VyQ2FuY2VsKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fY3VycmVudGx5U3BlYWtpbmcgPSB0aGlzLl92b2ljZU91dCh0b0Fubm91bmNlLnJlZHVjZSgoKGFjYywgdmFsKSA9PiBhY2MuY29uY2F0KHZhbCkpLCBbXSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgICRhbm5vdW5jZSh0b0Fubm91bmNlKSB7XG4gICAgICAgICAgICB2YXIge2FwcGVuZDogYXBwZW5kID0gZmFsc2UsIG5vdGlmaWNhdGlvbjogbm90aWZpY2F0aW9uID0gZmFsc2V9ID0gYXJndW1lbnRzLmxlbmd0aCA+IDEgJiYgYXJndW1lbnRzWzFdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMV0gOiB7fTtcbiAgICAgICAgICAgIGlmICghdG9Bbm5vdW5jZSB8fCAhdG9Bbm5vdW5jZS50cmltKCkubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRoaXMuYW5ub3VuY2VyRW5hYmxlZCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2RlYm91bmNlQW5ub3VuY2VGb2N1c0NoYW5nZXMuZmx1c2goKTtcbiAgICAgICAgICAgICAgICBpZiAoYXBwZW5kICYmIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nICYmIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nLmFjdGl2ZSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9jdXJyZW50bHlTcGVha2luZy5hcHBlbmQodG9Bbm5vdW5jZSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy4kYW5ub3VuY2VyQ2FuY2VsKCk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nID0gdGhpcy5fdm9pY2VPdXQodG9Bbm5vdW5jZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChub3RpZmljYXRpb24pIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fdm9pY2VPdXREaXNhYmxlZCA9IHRydWU7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nLnNlcmllcy5maW5hbGx5KCgoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl92b2ljZU91dERpc2FibGVkID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLiRhbm5vdW5jZXJSZWZyZXNoKCk7XG4gICAgICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgJGFubm91bmNlckNhbmNlbCgpIHtcbiAgICAgICAgICAgIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nICYmIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nLmNhbmNlbCgpO1xuICAgICAgICB9XG4gICAgICAgICRhbm5vdW5jZXJSZWZyZXNoKGRlcHRoKSB7XG4gICAgICAgICAgICBpZiAoZGVwdGgpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9sYXN0Rm9jdXNQYXRoID0gdGhpcy5fbGFzdEZvY3VzUGF0aC5zbGljZSgwLCBkZXB0aCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX2xhc3RGb2N1c1BhdGggPSB1bmRlZmluZWQ7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9yZXNldEZvY3VzVGltZXIoKTtcbiAgICAgICAgICAgIHRoaXMuX2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gICAgIH1cbiAgICAgICAgX3dhaXRGb3JUcmFuc2l0aW9uKGl0ZW0sIGF4aXMpIHtcbiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZSgocmVzb2x2ZSA9PiBpdGVtLl9nZXRUcmFuc2l0aW9uKGF4aXMpLm9uKFwiZmluaXNoXCIsIHJlc29sdmUpKSk7XG4gICAgICAgIH1cbiAgICAgICAgZ2V0IHNlbGVjdGVkSW5kZXgoKSB7XG4gICAgICAgICAgICByZXR1cm4gc3VwZXIuc2VsZWN0ZWRJbmRleDtcbiAgICAgICAgfVxuICAgICAgICBzZXQgc2VsZWN0ZWRJbmRleChpbmRleCkge1xuICAgICAgICAgICAgdmFyIF90aGlzMTAgPSB0aGlzO1xuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRWRpdGluZyB8fCB0aGlzLnNlbGVjdGVkSW5kZXggPj0gdGhpcy5pdGVtcy5sZW5ndGggLSAxICYmIGluZGV4ID4gdGhpcy5zZWxlY3RlZEluZGV4KSB7XG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzRWRpdGluZykge1xuICAgICAgICAgICAgICAgICAgICBzdXBlci5zZWxlY3RlZEluZGV4ID0gaW5kZXg7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBjdXJyZW50SXRlbSA9IHRoaXMuc2VsZWN0ZWQ7XG4gICAgICAgICAgICB0aGlzLnByZXZTZWxlY3RlZCA9IGN1cnJlbnRJdGVtO1xuICAgICAgICAgICAgdmFyIG5leHRJdGVtID0gdGhpcy5pdGVtc1tpbmRleF07XG4gICAgICAgICAgICB2YXIgcHJldmlvdXNJbmRleCA9IHRoaXMuc2VsZWN0ZWRJbmRleDtcbiAgICAgICAgICAgIHZhciBvbGRQb3MgPSB7XG4gICAgICAgICAgICAgICAgeDogdGhpcy5fZ2V0UG9zaXRpb25WYWx1ZShjdXJyZW50SXRlbSwgXCJ4XCIpLFxuICAgICAgICAgICAgICAgIHk6IHRoaXMuX2dldFBvc2l0aW9uVmFsdWUoY3VycmVudEl0ZW0sIFwieVwiKVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIHZhciBuZXdQb3MgPSB7XG4gICAgICAgICAgICAgICAgeDogdGhpcy5fZ2V0UG9zaXRpb25WYWx1ZShuZXh0SXRlbSwgXCJ4XCIpLFxuICAgICAgICAgICAgICAgIHk6IHRoaXMuX2dldFBvc2l0aW9uVmFsdWUobmV4dEl0ZW0sIFwieVwiKVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIHZhciBwcmV2aW91c0N1cnJlbnRJdGVtWkluZGV4ID0gY3VycmVudEl0ZW0uekluZGV4O1xuICAgICAgICAgICAgY3VycmVudEl0ZW0uekluZGV4ID0gcHJldmlvdXNDdXJyZW50SXRlbVpJbmRleCArIDE7XG4gICAgICAgICAgICB0aGlzLl9zd2FwSXRlbUFycmF5UG9zKHRoaXMuaXRlbXMsIGluZGV4LCBwcmV2aW91c0luZGV4KTtcbiAgICAgICAgICAgIGN1cnJlbnRJdGVtLnNldFNtb290aChcInhcIiwgbmV3UG9zLngpO1xuICAgICAgICAgICAgY3VycmVudEl0ZW0uc2V0U21vb3RoKFwieVwiLCBuZXdQb3MueSk7XG4gICAgICAgICAgICBuZXh0SXRlbS5zZXRTbW9vdGgoXCJ4XCIsIG9sZFBvcy54KTtcbiAgICAgICAgICAgIG5leHRJdGVtLnNldFNtb290aChcInlcIiwgb2xkUG9zLnkpO1xuICAgICAgICAgICAgX2FzeW5jVG9HZW5lcmF0b3IoKGZ1bmN0aW9uKigpIHtcbiAgICAgICAgICAgICAgICB2YXIgX3RoaXMxMCRJdGVtcyRjaGlsZHJlO1xuICAgICAgICAgICAgICAgIHlpZWxkIFByb21pc2UuYWxsKFsgX3RoaXMxMC5fd2FpdEZvclRyYW5zaXRpb24oY3VycmVudEl0ZW0sIFwieFwiKSwgX3RoaXMxMC5fd2FpdEZvcl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AgPSBoZWlnaHQ7XG4gICAgICAgIGJyZWFrO1xuXG4gICAgICBjYXNlIDU6XG4gICAgICAgIHkwID0gaGVpZ2h0IC8gMiArIGE7XG4gICAgICAgIGJyZWFrO1xuXG4gICAgICBjYXNlIDY6XG4gICAgICAgIHkwID0gaGVpZ2h0IC8gMiAtIGE7XG4gICAgICAgIGJyZWFrO1xuXG4gICAgICBjYXNlIDc6XG4gICAgICAgIHgwID0gd2lkdGggLyAyIC0gYTtcbiAgICAgICAgYnJlYWs7XG4gICAgfVxuICAgIGlmICh4MCA9PSAwKSB7XG4gICAgICAgIHgxID0gd2lkdGg7XG4gICAgICAgIHkxID0gaGVpZ2h0IC0geTA7XG4gICAgfVxuICAgIGlmICh5MCA9PSAwKSB7XG4gICAgICAgIHkxID0gaGVpZ2h0O1xuICAgICAgICB4MSA9IHdpZHRoIC0geDA7XG4gICAgfVxuICAgIGlmICh4MCA9PSB3aWR0aCkge1xuICAgICAgICB4MSA9IDA7XG4gICAgICAgIHkxID0gaGVpZ2h0IC0geTA7XG4gICAgfVxuICAgIGlmICh5MCA9PSBoZWlnaHQpIHtcbiAgICAgICAgeTEgPSAwO1xuICAgICAgICB4MSA9IHdpZHRoIC0geDA7XG4gICAgfVxuICAgIHJldHVybiB7XG4gICAgICAgIHgwOiB4MCxcbiAgICAgICAgeTA6IHkwLFxuICAgICAgICB4MTogeDEsXG4gICAgICAgIHkxOiB5MVxuICAgIH07XG59O1xuXG5jbGFzcyBMaW5lYXJHcmFkaWVudCBleHRlbmRzIGxuZy5UZXh0dXJlIHtcbiAgICBjb25zdHJ1Y3RvcihzdGFnZSkge1xuICAgICAgICBzdXBlcihzdGFnZSk7XG4gICAgICAgIHRoaXMuX3cgPSAwO1xuICAgICAgICB0aGlzLl9oID0gMDtcbiAgICAgICAgdGhpcy5fc3RlcHMgPSBbXTtcbiAgICAgICAgdGhpcy5fZGVncmVlcyA9IDA7XG4gICAgfVxuICAgIGdldCB3KCkge1xuICAgICAgICByZXR1c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gPSBkaXJlY3Rpb247XG4gICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICB9XG4gICAgX2dldExvb2t1cElkKCkge1xuICAgICAgICByZXR1cm4gXCJfX3RyaWFuZ2xlX1wiLmNvbmNhdCh0aGlzLl9kaXJlY3Rpb24sIFwiX1wiKS5jb25jYXQodGhpcy5fdywgXCJ4XCIpLmNvbmNhdCh0aGlzLl9oKTtcbiAgICB9XG4gICAgX2dldFNvdXJjZUxvYWRlcigpIHtcbiAgICAgICAgdmFyIGNvbG9yID0gdGhpcy5fY29sb3I7XG4gICAgICAgIHZhciB3ID0gdGhpcy5fdztcbiAgICAgICAgdmFyIGggPSB0aGlzLl9oO1xuICAgICAgICB2YXIgZGlyZWN0aW9uID0gdGhpcy5fZGlyZWN0aW9uO1xuICAgICAgICB2YXIgY2FudmFzID0gdGhpcy5zdGFnZS5wbGF0Zm9ybS5nZXREcmF3aW5nQ2FudmFzKCk7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbihjYikge1xuICAgICAgICAgICAgdmFyIGN0eCA9IGNhbnZhcy5nZXRDb250ZXh0KFwiMmRcIik7XG4gICAgICAgICAgICBjYW52YXMud2lkdGggPSB3O1xuICAgICAgICAgICAgY2FudmFzLmhlaWdodCA9IGg7XG4gICAgICAgICAgICBjdHguZmlsbFN0eWxlID0gY29sb3I7XG4gICAgICAgICAgICBjdHguc3Ryb2tlU3R5bGUgPSBjdHguZmlsbFN0eWxlO1xuICAgICAgICAgICAgY3R4LmxpbmVXaWR0aCA9IDI7XG4gICAgICAgICAgICBjdHgubGluZUNhcCA9IFwicm91bmRcIjtcbiAgICAgICAgICAgIGN0eC5saW5lSm9pbiA9IFwicm91bmRcIjtcbiAgICAgICAgICAgIHZhciBwID0gY3R4LmxpbmVXaWR0aCAvIDI7XG4gICAgICAgICAgICBjdHguYmVnaW5QYXRoKCk7XG4gICAgICAgICAgICBpZiAoZGlyZWN0aW9uID09PSBcInJpZ2h0XCIpIHtcbiAgICAgICAgICAgICAgICBjdHgubW92ZVRvKHAsIHApO1xuICAgICAgICAgICAgICAgIGN0eC5saW5lVG8ocCwgaCAtIHApO1xuICAgICAgICAgICAgICAgIGN0eC5saW5lVG8odyAtIHAsIGggLyAyKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoZGlyZWN0aW9uID09PSBcImRvd25cIikge1xuICAgICAgICAgICAgICAgIGN0eC5tb3ZlVG8ocCwgcCk7XG4gICAgICAgICAgICAgICAgY3R4LmxpbmVUbyh3IC0gcCwgcCk7XG4gICAgICAgICAgICAgICAgY3R4LmxpbmVUbyh3IC8gMiwgaCAtIHApO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjdHgubW92ZVRvKHAsIGggLyAyKTtcbiAgICAgICAgICAgICAgICBjdHgubGluZVRvKHcgLSBwLCBwKTtcbiAgICAgICAgICAgICAgICBjdHgubGluZVRvKHcgLSBwLCBoIC0gcCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjdHguY2xvc2VQYXRoKCk7XG4gICAgICAgICAgICBjdHguc3Ryb2tlKCk7XG4gICAgICAgICAgICBjdHguZmlsbCgpO1xuICAgICAgICAgICAgY2IobnVsbCwge1xuICAgICAgICAgICAgICAgIHNvdXJjZTogY2FudmFzLFxuICAgICAgICAgICAgICAgIHc6IHcsXG4gICAgICAgICAgICAgICAgaDogaCxcbiAgICAgICAgICAgICAgICBkaXJlY3Rpb246IGRpcmVjdGlvblxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBMaW5lIGV4dGVuZHMgbG5nLlRleHR1cmUge1xuICAgIGNvbnN0cnVjdG9yKHN0YWdlKSB7XG4gICAgICAgIHN1cGVyKHN0YWdlKTtcbiAgICAgICAgdGhpcy5fdyA9IDA7XG4gICAgICAgIHRoaXMuX2ggPSAwO1xuICAgICAgICB0aGlzLl9yb3VuZGVkID0gZmFsc2U7XG4gICAgfVxuICAgIGdldCB3KC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gaDtcbiAgICAgICAgICAgIGN0eC5saW5lV2lkdGggPSBoO1xuICAgICAgICAgICAgaWYgKHJvdW5kZWQpIHtcbiAgICAgICAgICAgICAgICBjdHgubGluZUNhcCA9IFwicm91bmRcIjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGN0eC5zdHJva2VTdHlsZSA9IFwid2hpdGVcIjtcbiAgICAgICAgICAgIGN0eC5iZWdpblBhdGgoKTtcbiAgICAgICAgICAgIGN0eC5tb3ZlVG8ocm91bmRlZCA/IDIgOiAwLCBoIC8gMik7XG4gICAgICAgICAgICBjdHgubGluZVRvKHJvdW5kZWQgPyB3IC0gMiA6IHcsIGggLyAyKTtcbiAgICAgICAgICAgIGN0eC5zdHJva2UoKTtcbiAgICAgICAgICAgIGNiKG51bGwsIHtcbiAgICAgICAgICAgICAgICBzb3VyY2U6IGNhbnZhcyxcbiAgICAgICAgICAgICAgICB3OiB3LFxuICAgICAgICAgICAgICAgIGg6IGgsXG4gICAgICAgICAgICAgICAgcm91bmRlZDogcm91bmRlZFxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBTaWduYWxCdXR0b24gZXh0ZW5kcyBCdXR0b24ge1xuICAgIG9uRW50ZXIoKSB7XG4gICAgICAgIHRoaXMuc2lnbmFsKHRoaXMuc2lnbmFsTmFtZSk7XG4gICAgfVxuICAgIHNldCBzaWduYWxOYW1lKHNpZ25hbE5hbWUpIHtcbiAgICAgICAgdGhpcy5fc2lnbmFsTmFtZSA9IHNpZ25hbE5hbWU7XG4gICAgfVxuICAgIGdldCBzaWduYWxOYW1lKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fc2lnbmFsTmFtZTtcbiAgICB9XG59XG5cbmV4cG9ydCB7IEFycm93LCBBcnR3b3JrLCBCYWRnZSwgQmFzZSQxIGFzIEJhc2UsIEJ1YmJsZSwgQnV0dG9uLCBCdXR0b25TbWFsbCwgQ2FyZCwgQ2FyZENvbnRlbnQ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ICByZWN0OiB0cnVlLFxuICAgICAgICBjb2xvcjogMHhkZDAwMDAwMCxcbiAgICAgICAgYWxwaGE6IDAuMDAwMDAxLFxuICAgICAgICBEaWFsb2c6IHtcbiAgICAgICAgICB3OiA2NDgsXG4gICAgICAgICAgaDogMzIwLFxuICAgICAgICAgIHk6IGggPT4gKGggLSAzMjApIC8gMixcbiAgICAgICAgICB4OiB3ID0+ICh3IC0gNjQ4KSAvIDIsXG4gICAgICAgICAgcmVjdDogdHJ1ZSxcbiAgICAgICAgICBjb2xvcjogMHhkZDMzMzMzMyxcbiAgICAgICAgICBzaGFkZXI6IHsgdHlwZTogTGlnaHRuaW5nLnNoYWRlcnMuUm91bmRlZFJlY3RhbmdsZSwgcmFkaXVzOiAxMCB9LFxuICAgICAgICAgIEluZm86IHtcbiAgICAgICAgICAgIHk6IDI0LFxuICAgICAgICAgICAgeDogNDgsXG4gICAgICAgICAgICB0ZXh0OiB7IHRleHQ6ICdQbGVhc2UgZW50ZXIgeW91ciBQSU4nLCBmb250U2l6ZTogMzIgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIE1zZzoge1xuICAgICAgICAgICAgeTogMjYwLFxuICAgICAgICAgICAgeDogNDgsXG4gICAgICAgICAgICB0ZXh0OiB7IHRleHQ6ICcnLCBmb250U2l6ZTogMjgsIHRleHRDb2xvcjogMHhmZmZmZmZmZiB9LFxuICAgICAgICAgIH0sXG4gICAgICAgICAgQ29kZToge1xuICAgICAgICAgICAgeDogNDgsXG4gICAgICAgICAgICB5OiA5NixcbiAgICAgICAgICB9LFxuICAgICAgICB9LFxuICAgICAgfVxuICAgIH1cblxuICAgIF9pbml0KCkge1xuICAgICAgY29uc3QgY2hpbGRyZW4gPSBbXVxuICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCA0OyBpKyspIHtcbiAgICAgICAgY2hpbGRyZW4ucHVzaCh7XG4gICAgICAgICAgdHlwZTogUGluSW5wdXQoKSxcbiAgICAgICAgICBpbmRleDogaSxcbiAgICAgICAgfSlcbiAgICAgIH1cblxuICAgICAgdGhpcy50YWcoJ0NvZGUnKS5jaGlsZHJlbiA9IGNoaWxkcmVuXG4gICAgfVxuXG4gICAgZ2V0IHBpbigpIHtcbiAgICAgIGlmICghdGhpcy5fcGluKSB0aGlzLl9waW4gPSAnJ1xuICAgICAgcmV0dXJuIHRoaXMuX3BpblxuICAgIH1cblxuICAgIHNldCBwaW4odikge1xuICAgICAgaWYgKHYubGVuZ3RoIDw9IDQpIHtcbiAgICAgICAgY29uc3QgbWFza2VkUGluID0gbmV3IEFycmF5KE1hdGgubWF4KHYubGVuZ3RoIC0gMSwgMCkpLmZpbGwoJyonLCAwLCB2Lmxlbmd0aCAtIDEpXG4gICAgICAgIHYubGVuZ3RoICYmIG1hc2tlZFBpbi5wdXNoKHYubGVuZ3RoID4gdGhpcy5fcGluLmxlbmd0aCA/IHYuc2xpY2UoLTEpIDogJyonKVxuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IDQ7IGkrKykge1xuICAgICAgICAgIHRoaXMudGFnKCdDb2RlJykuY2hpbGRyZW5baV0ubnIgPSBtYXNrZWRQaW5baV0gfHwgJydcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9waW4gPSB2XG4gICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IG1zZygpIHtcbiAgICAgIGlmICghdGhpcy5fbXNnKSB0aGlzLl9tc2cgPSAnJ1xuICAgICAgcmV0dXJuIHRoaXMuX21zZ1xuICAgIH1cblxuICAgIHNldCBtc2codikge1xuICAgICAgdGhpcy5fdGltZW91dCAmJiBjbGVhclRpbWVvdXQodGhpcy5fdGltZW91dClcblxuICAgICAgdGhpcy5fbXNnID0gdlxuICAgICAgaWYgKHRoaXMuX21zZykge1xuICAgICAgICB0aGlzLnRhZygnTXNnJykudGV4dCA9IHRoaXMuX21zZ1xuICAgICAgICB0aGlzLnRhZygnSW5mbycpLnNldFNtb290aCgnYWxwaGEnLCAwLjUpXG4gICAgICAgIHRoaXMud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0gY29udGV4dENoZWNrKGNvbnRleHQpXG4gICAgICAgIGlmIChjb250ZXh0KSB7XG4gICAgICAgICAgY2hlY2soY29udGV4dClcbiAgICAgICAgICAgIC50aGVuKHJlc29sdmUpXG4gICAgICAgICAgICAuY2F0Y2gocmVqZWN0KVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHJlamVjdCgnSW5jb3JyZWN0IENvbnRleHQgcHJvdmlkZWQnKVxuICAgICAgICB9XG4gICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgIHJlamVjdChlKVxuICAgICAgfVxuICAgIH0pXG4gIH0sXG4gIGxvY2tlZChjb250ZXh0KSB7XG4gICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgIHRyeSB7XG4gICAgICAgIGNvbnRleHQgPSBjb250ZXh0Q2hlY2soY29udGV4dClcbiAgICAgICAgaWYgKGNvbnRleHQpIHtcbiAgICAgICAgICBjaGVjayhjb250ZXh0KVxuICAgICAgICAgICAgLnRoZW4odW5sb2NrZWQgPT4gcmVzb2x2ZSghISF1bmxvY2tlZCkpXG4gICAgICAgICAgICAuY2F0Y2gocmVqZWN0KVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHJlamVjdCgnSW5jb3JyZWN0IENvbnRleHQgcHJvdmlkZWQnKVxuICAgICAgICB9XG4gICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgIHJlamVjdChlKVxuICAgICAgfVxuICAgIH0pXG4gIH0sXG59XG4iLCIvKlxuICogSWYgbm90IHN0YXRlZCBvdGhlcndpc2UgaW4gdGhpcyBmaWxlIG9yIHRoaXMgY29tcG9uZW50J3MgTElDRU5TRSBmaWxlIHRoZVxuICogZm9sbG93aW5nIGNvcHlyaWdodCBhbmQgbGljZW5zZXMgYXBwbHk6XG4gKlxuICogQ29weXJpZ2h0IDIwMjAgTWV0cm9sb2dpY2FsXG4gKlxuICogTGljZW5zZWQgdW5kZXIgdGhlIE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0dXJlLFxuICAgICAgICAgICAgaWRlbnRpZmllcjogU2V0dGluZ3MuZ2V0KCdhcHAnLCAnaWQnKSxcbiAgICAgICAgICAgIG5hbWU6IFNldHRpbmdzLmdldCgnYXBwJywgJ2lkJyksXG4gICAgICAgICAgICBob3VzZWhvbGQsXG4gICAgICAgICAgICBjb3VudHJ5LFxuICAgICAgICAgICAgb3BlcmF0b3IsXG4gICAgICAgICAgICBtYWMsXG4gICAgICAgICAgICB1aWQsXG4gICAgICAgICAgICB0eXBlLFxuICAgICAgICAgIH0pXG4gICAgICAgICAgICAudGhlbihyZXNvbHZlKVxuICAgICAgICAgICAgLmNhdGNoKHJlamVjdClcbiAgICAgICAgfSlcbiAgICAgICAgLmNhdGNoKHJlamVjdClcbiAgICB9KVxuICB9LFxuICBjb25maXJtKHRyYW5zYWN0aW9uSWQpIHtcbiAgICByZXR1cm4gbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgYmlsbGluZ1JlcXVlc3QoJy9jb25maXJtJywge1xuICAgICAgICB0cmFuc2FjdGlvbklkLFxuICAgICAgfSlcbiAgICAgICAgLnRoZW4ocmVzb2x2ZSlcbiAgICAgICAgLmNhdGNoKHJlamVjdClcbiAgICB9KVxuICB9LFxuICBidXkoYXNzZXRJZCwgdHlwZSkge1xuICAgIHJldHVybiBuZXcgUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICBsZXQgdHJhbnNhY3Rpb25JZFxuICAgICAgc2VxdWVuY2UoW1xuICAgICAgICAoKSA9PiB0aGlzLnNpZ25hdHVyZShhc3NldElkKSxcbiAgICAgICAgc2lnbmF0dXJlID0+IHRoaXMucGF5bWVudChzaWduYXR1cmUsIHR5cGUpLFxuICAgICAgICB0cmFuc2FjdGlvbiA9PiB7XG4gICAgICAgICAgdHJhbnNhY3Rpb25JZCA9IHRyYW5zYWN0aW9uLnRyYW5zYWN0aW9uSWRcbiAgICAgICAgICByZXR1cm4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0gdGhpcy52aWRlb0VsLmhlaWdodFxuICAgICAgICAgICAgICAgIGNvbnN0IGV4cGVjdGVkQXNwZWN0UmF0aW8gPSB0aGlzLnZpZGVvVmlldy53IC8gdGhpcy52aWRlb1ZpZXcuaFxuICAgICAgICAgICAgICAgIGNvbnN0IHJlYWxBc3BlY3RSYXRpbyA9IHRoaXMudmlkZW9FbC53aWR0aCAvIHRoaXMudmlkZW9FbC5oZWlnaHRcblxuICAgICAgICAgICAgICAgIGlmIChleHBlY3RlZEFzcGVjdFJhdGlvID4gcmVhbEFzcGVjdFJhdGlvKSB7XG4gICAgICAgICAgICAgICAgICB0aGlzLnZpZGVvVmlldy5zY2FsZVggPSByZWFsQXNwZWN0UmF0aW8gLyBleHBlY3RlZEFzcGVjdFJhdGlvXG4gICAgICAgICAgICAgICAgICB0aGlzLnZpZGVvVmlldy5zY2FsZVkgPSAxXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIHRoaXMudmlkZW9WaWV3LnNjYWxlWSA9IGV4cGVjdGVkQXNwZWN0UmF0aW8gLyByZWFsQXNwZWN0UmF0aW9cbiAgICAgICAgICAgICAgICAgIHRoaXMudmlkZW9WaWV3LnNjYWxlWCA9IDFcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgICAgICBMb2cuZXJyb3IoJ3RleEltYWdlMmQgdmlkZW8nLCBlKVxuICAgICAgICAgICAgICAgIHRoaXMuc3RvcCgpXG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgdGhpcy52aWRlb1RleHR1cmUuc291cmNlLmZvcmNlUmVuZGVyVXBkYXRlKClcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmICghdGhpcy5fdXBkYXRpbmdWaWRlb1RleHR1cmUpIHtcbiAgICAgICAgc3RhZ2Uub24oJ2ZyYW1lU3Rh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1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLm1vZGUgPSBleHBvcnRzLklORkxBVEU7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG5cbiAgICAgICAgLy8gZmFsbHRocm91Z2hcbiAgICAgICAgY2FzZSAxOlxuICAgICAgICAgIGlmIChuZXh0X2V4cGVjdGVkX2hlYWRlcl9ieXRlID09PSBudWxsKSB7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAodGhpcy5zdHJtLmlucHV0W25leHRfZXhwZWN0ZWRfaGVhZGVyX2J5dGVdID09PSBHWklQX0hFQURFUl9JRDIpIHtcbiAgICAgICAgICAgIHRoaXMuZ3ppcF9pZF9ieXRlc19yZWFkID0gMjtcbiAgICAgICAgICAgIHRoaXMubW9kZSA9IGV4cG9ydHMuR1VOWklQO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAvLyBUaGVyZSBpcyBubyBhY3R1YWwgZGlmZmVyZW5jZSBiZXR3ZWVuIElORkxBVEUgYW5kIElORkxBVEVSQVdcbiAgICAgICAgICAgIC8vIChhZnRlciBpbml0aWFsaXphdGlvbikuXG4gICAgICAgICAgICB0aGlzLm1vZGUgPSBleHBvcnRzLklORkxBVEU7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdpbnZhbGlkIG51bWJlciBvZiBnemlwIG1hZ2ljIG51bWJlciBieXRlcyByZWFkJyk7XG4gICAgICB9XG5cbiAgICAvLyBmYWxsdGhyb3VnaFxuICAgIGNhc2UgZXhwb3J0cy5JTkZMQVRFOlxuICAgIGNhc2UgZXhwb3J0cy5HVU5aSVA6XG4gICAgY2FzZSBleHBvcnRzLklORkxBVEVSQVc6XG4gICAgICB0aGlzLmVyciA9IHpsaWJfaW5mbGF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A9PT0gaTE4bi5hbVBtWzFdKSB7XG4gICAgICAgICAgICByZXR1cm4gMTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gbnVsbDtcbiAgICB9XG5dO1xudmFyIHRpbWV6b25lT2Zmc2V0ID0gW1xuICAgIFwidGltZXpvbmVPZmZzZXRcIixcbiAgICBcIlteXFxcXHNdKj9bXFxcXCtcXFxcLV1cXFxcZFxcXFxkOj9cXFxcZFxcXFxkfFteXFxcXHNdKj9aP1wiLFxuICAgIGZ1bmN0aW9uICh2KSB7XG4gICAgICAgIHZhciBwYXJ0cyA9ICh2ICsgXCJcIikubWF0Y2goLyhbKy1dfFxcZFxcZCkvZ2kpO1xuICAgICAgICBpZiAocGFydHMpIHtcbiAgICAgICAgICAgIHZhciBtaW51dGVzID0gK3BhcnRzWzFdICogNjAgKyBwYXJzZUludChwYXJ0c1syXSwgMTApO1xuICAgICAgICAgICAgcmV0dXJuIHBhcnRzWzBdID09PSBcIitcIiA/IG1pbnV0ZXMgOiAtbWludXRlcztcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gMDtcbiAgICB9XG5dO1xudmFyIHBhcnNlRmxhZ3MgPSB7XG4gICAgRDogW1wiZGF5XCIsIHR3b0RpZ2l0c09wdGlvbmFsXSxcbiAgICBERDogW1wiZGF5XCIsIHR3b0RpZ2l0c10sXG4gICAgRG86IFtcImRheVwiLCB0d29EaWdpdHNPcHRpb25hbCArIHdvcmQsIGZ1bmN0aW9uICh2KSB7IHJldHVybiBwYXJzZUludCh2LCAxMCk7IH1dLFxuICAgIE06IFtcIm1vbnRoXCIsIHR3b0RpZ2l0c09wdGlvbmFsLCBtb250aFBhcnNlXSxcbiAgICBNTTogW1wibW9udGhcIiwgdHdvRGlnaXRzLCBtb250aFBhcnNlXSxcbiAgICBZWTogW1xuICAgICAgICBcInllYXJcIixcbiAgICAgICAgdHdvRGlnaXRzLFxuICAgICAgICBmdW5jdGlvbiAodikge1xuICAgICAgICAgICAgdmFyIG5vdyA9I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0aGlzIGluc3RhbmNlb2YgYm91bmQpIHtcbiAgICAgICAgICAgIHZhciByZXN1bHQgPSB0YXJnZXQuYXBwbHkoXG4gICAgICAgICAgICAgICAgdGhpcyxcbiAgICAgICAgICAgICAgICBjb25jYXR0eShhcmdzLCBhcmd1bWVudHMpXG4gICAgICAgICAgICApO1xuICAgICAgICAgICAgaWYgKE9iamVjdChyZXN1bHQpID09PSByZXN1bHQpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gcmVzdWx0O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRhcmdldC5hcHBseShcbiAgICAgICAgICAgIHRoYXQsXG4gICAgICAgICAgICBjb25jYXR0eShhcmdzLCBhcmd1bWVudHMpXG4gICAgICAgICk7XG5cbiAgICB9O1xuXG4gICAgdmFyIGJvdW5kTGVuZ3RoID0gbWF4KDAsIHRhcmdldC5sZW5ndGggLSBhcmdzLmxlbmd0aCk7XG4gICAgdmFyIGJvdW5kQXJncyA9IFtdO1xuICAgIGZvciAodmFyIGkgPSAwOyBpIDwgYm91bmRMZW5ndGg7IGkrKykge1xuICAgICAgICBib3VuZEFyZ3NbaV0gPSAnJCcgKyBpO1xuICAgIH1cblxuICAgIGJvdW5kID0gRnVuY3Rpb24oJ2JpbmRlcicsICdyZXR1cm4gZnVuY3Rpb24gKCcgKyBqb2lueShib3VuZEFyZ3MsICcsJykgKyAnKXsgcmV0dXJuIGJpbmRlci5hcHBseSh0aGlzLGFyZ3VtZW50cyk7IH0nKShiaW5kZXIpO1xuXG4gICAgaWYgKHRhcmdldC5wcm90b3R5cGUpIHtcbiAgICAgICAgdmFyIEVtcHR5ID0gZnVuY3Rpb24gRW1wdHkoKSB7fTtcbiAgICAgICAgRW1wdHkucHJvdG90eXBlID0gdGFyZ2V0LnByb3RvdHlwZTtcbiAgICAgICAgYm91bmQucHJvdG90eXBlID0gbmV3IEVtcHR5KCk7XG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gIC8vIGJhc2UgMiwgYmFzZSA4LCBiYXNlIDE2XG5cbiAgICBpZiAoY2ggPT09ICdiJykge1xuICAgICAgLy8gYmFzZSAyXG4gICAgICBpbmRleCsrO1xuXG4gICAgICBmb3IgKDsgaW5kZXggPCBtYXg7IGluZGV4KyspIHtcbiAgICAgICAgY2ggPSBkYXRhW2luZGV4XTtcbiAgICAgICAgaWYgKGNoID09PSAnXycpIGNvbnRpbnVlO1xuICAgICAgICBpZiAoY2ggIT09ICcwJyAmJiBjaCAhPT0gJzEnKSByZXR1cm4gZmFsc2U7XG4gICAgICAgIGhhc0RpZ2l0cyA9IHRydWU7XG4gICAgICB9XG4gICAgICByZXR1cm4gaGFzRGlnaXRzICYmIGNoICE9PSAnXyc7XG4gICAgfVxuXG5cbiAgICBpZiAoY2ggPT09ICd4Jykge1xuICAgICAgLy8gYmFzZSAxNlxuICAgICAgaW5kZXgrKztcblxuICAgICAgZm9yICg7IGluZGV4IDwgbWF4OyBpbmRleCsrKSB7XG4gICAgICAgIGNoID0gZGF0YVtpbmRleF07XG4gICAgICAgIGlmIChjaCA9PT0gJ18nKSBjb250aW51ZTtcbiAgICAgICAgaWYgKCFpc0hleENvZGUoZGF0YS5jaGFyQ29kZUF0KGluZGV4KSkpIHJldHVybiBmYWxzZTtcbiAgICAgICAgaGFzRGlnaXRzID0gdHJ1ZTtcbiAgICAgIH1cbiAgICAgIHJldHVybiBoYXNEaWdpdHMgJiYgY2ggIT09ICdfJztcbiAgICB9XG5cblxuICAgIGlmIChjaCA9PT0gJ28nKSB7XG4gICAgICAvLyBiYXNlIDhcbiAgICAgIGluZGV4Kys7XG5cbiAgICAgIGZvciAoOyBpbmRleCA8IG1heDsgaW5kZXgrKykge1xuICAgICAgICBjaCA9IGRhdGFbaW5kZXhdO1xuICAgICAgICBpZiAoY2ggPT09ICdfJykgY29udGludWU7XG4gICAgICAgIGlmICghaXNPY3RDb2RlKGRhdGEuY2hhckNvZGVBdChpbmRleCkpKSByZXR1cm4g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ciBZQU1MX1RJTUVTVEFNUF9SRUdFWFAgPSBuZXcgUmVnRXhwKFxuICAnXihbMC05XVswLTldWzAtOV1bMC05XSknICAgICAgICAgICsgLy8gWzFdIHllYXJcbiAgJy0oWzAtOV1bMC05XT8pJyAgICAgICAgICAgICAgICAgICArIC8vIFsyXSBtb250aFxuICAnLShbMC05XVswLTldPyknICAgICAgICAgICAgICAgICAgICsgLy8gWzNdIGRheVxuICAnKD86W1R0XXxbIFxcXFx0XSspJyAgICAgICAgICAgICAgICAgKyAvLyAuLi5cbiAgJyhbMC05XVswLTldPyknICAgICAgICAgICAgICAgICAgICArIC8vIFs0XSBob3VyXG4gICc6KFswLTldWzAtOV0pJyAgICAgICAgICAgICAgICAgICAgKyAvLyBbNV0gbWludXRlXG4gICc6KFswLTldWzAtOV0pJyAgICAgICAgICAgICAgICAgICAgKyAvLyBbNl0gc2Vjb25kXG4gICcoPzpcXFxcLihbMC05XSopKT8nICAgICAgICAgICAgICAgICArIC8vIFs3XSBmcmFjdGlvblxuICAnKD86WyBcXFxcdF0qKFp8KFstK10pKFswLTldWzAtOV0/KScgKyAvLyBbOF0gdHogWzldIHR6X3NpZ24gWzEwXSB0el9ob3VyXG4gICcoPzo6KFswLTldWzAtOV0pKT8pKT8kJyk7ICAgICAgICAgICAvLyBbMTFdIHR6X21pbnV0ZVxuXG5mdW5jdGlvbiByZXNvbHZlWWFtbFRpbWVzdGFtcChkYXRhKSB7XG4gIGlmIChkYXRhID09PSBudWxsKSByZXR1cm4gZmFsc2U7XG4gIGlmIChZQU1MX0RBVEVfUkVHRVhQLmV4ZWMoZGF0YSkgIT09IG51bGwpIHJldHVybiB0cnVlO1xuICBpZiAoWUFNTF9USU1FU1RBTVBfUkVHRVhQLmV4ZWMoZGF0YSkgIT09IG51bGwpIHJldHVybiB0cnVlO1xuICByZXR1cm4gZmFsc2U7XG59XG5cbmZ1bmN0aW9uIGNvbnN0cnVjdFlhbWxUaW1lc3RhbXAoZGF0YSkge1xuICB2YX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pbmdDb250ZW50LFxuICAgICAgX2xpbmUsXG4gICAgICBfbGluZVN0YXJ0LFxuICAgICAgX2xpbmVJbmRlbnQsXG4gICAgICBfa2luZCA9IHN0YXRlLmtpbmQsXG4gICAgICBfcmVzdWx0ID0gc3RhdGUucmVzdWx0LFxuICAgICAgY2g7XG5cbiAgY2ggPSBzdGF0ZS5pbnB1dC5jaGFyQ29kZUF0KHN0YXRlLnBvc2l0aW9uKTtcblxuICBpZiAoaXNfV1NfT1JfRU9MKGNoKSAgICAgIHx8XG4gICAgICBpc19GTE9XX0lORElDQVRPUihjaCkgfHxcbiAgICAgIGNoID09PSAweDIzLyogIyAqLyAgICB8fFxuICAgICAgY2ggPT09IDB4MjYvKiAmICovICAgIHx8XG4gICAgICBjaCA9PT0gMHgyQS8qICogKi8gICAgfHxcbiAgICAgIGNoID09PSAweDIxLyogISAqLyAgICB8fFxuICAgICAgY2ggPT09IDB4N0MvKiB8ICovICAgIHx8XG4gICAgICBjaCA9PT0gMHgzRS8qID4gKi8gICAgfHxcbiAgICAgIGNoID09PSAweDI3LyogJyAqLyAgICB8fFxuICAgICAgY2ggPT09IDB4MjIvKiBcIiAqLyAgICB8fFxuICAgICAgY2ggPT09IDB4MjUvKiAlICovICAgIHx8XG4gICAgICBjaCA9PT0gMHg0MC8qIEAgKi8gICAgfHxcbiAgICAgIGNoID09PSAweDYwLyogYCAqLykge1xuICAgIHJldHVybiBmYWxzZTtcbiAgfVxuXG4gIGlmIChjaCA9PT0gMHgzRi8qID8gKi8gfHwgY2ggPT09IDB4MkQvKiAtICovKSB7XG4gICAgZm9sbG93aW5nID0gc3RhdGUuaW5wdXQuY2hhckNvZGVBdChzdGF0ZS5wb3NpdGlvbiArIDEpO1xuXG4gICAgaWYgKGlzX1dTX09SX0VPTChmb2xsb3dpbmcpIHx8XG4gICAgICAgIHdpdGhpbkZsb3dDb2xsZWN0aW9uICYmIGlzX0ZMT1dfSU5ESUNBVE9SKGZvbGxvd2luZykpIHtcbiAgICA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VjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7XG5cbnZhciBDSEFSX0JPTSAgICAgICAgICAgICAgICAgID0gMHhGRUZGO1xudmFyIENIQVJfVEFCICAgICAgICAgICAgICAgICAgPSAweDA5OyAvKiBUYWIgKi9cbnZhciBDSEFSX0xJTkVfRkVFRCAgICAgICAgICAgID0gMHgwQTsgLyogTEYgKi9cbnZhciBDSEFSX0NBUlJJQUdFX1JFVFVSTiAgICAgID0gMHgwRDsgLyogQ1IgKi9cbnZhciBDSEFSX1NQQUNFICAgICAgICAgICAgICAgID0gMHgyMDsgLyogU3BhY2UgKi9cbnZhciBDSEFSX0VYQ0xBTUFUSU9OICAgICAgICAgID0gMHgyMTsgLyogISAqL1xudmFyIENIQVJfRE9VQkxFX1FVT1RFICAgICAgICAgPSAweDIyOyAvKiBcIiAqL1xudmFyIENIQVJfU0hBUlAgICAgICAgICAgICAgICAgPSAweDIzOyAvKiAjICovXG52YXIgQ0hBUl9QRVJDRU5UICAgICAgICAgICAgICA9IDB4MjU7IC8qICUgKi9cbnZhciBDSEFSX0FNUEVSU0FORCAgICAgICAgICAgID0gMHgyNjsgLyogJiAqL1xudmFyIENIQVJfU0lOR0xFX1FVT1RFICAgICAgICAgPSAweDI3OyAvKiAnICovXG52YXIgQ0hBUl9BU1RFUklTSyAgICAgICAgICAgICA9IDB4MkE7IC8qICogKi9cbnZhciBDSEFSX0NPTU1BICAgICAgICAgICAgICAgID0gMHgyQzsgLyogLCAqL1xudmFyIENIQVJfTUlOVVMgICAgICAgICAgICAgICAgPSAweDJEOyAvKiAtICovXG52YXIgQ0hBUl9DT0xPTiAgICAgICAgICAgICAgICA9IDB4M0E7IC8qIDogKi9cbnZhciBDSEFSX0VRVUFMUyAgICAgICAgICAgICAgID0gMHgzRDsgLyogPSAqL1xudmFyIENIQVJfR1JFQVRFUl9USEFOICAgICAgICAgPSAweDNFOyAvKiA+ICovXG52YXIgQ0hBUl9RVUVTVElPTiAgICAgICAgICAgICA9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ZXksIG9iamVjdCwgc3RhY2spIDogY3VzdG9taXplcih2YWx1ZSk7XG4gICAgICB9XG4gICAgICBpZiAocmVzdWx0ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICAgIH1cbiAgICAgIGlmICghaXNPYmplY3QodmFsdWUpKSB7XG4gICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICAgIH1cbiAgICAgIHZhciBpc0FyciA9IGlzQXJyYXkodmFsdWUpO1xuICAgICAgaWYgKGlzQXJyKSB7XG4gICAgICAgIHJlc3VsdCA9IGluaXRDbG9uZUFycmF5KHZhbHVlKTtcbiAgICAgICAgaWYgKCFpc0RlZXApIHtcbiAgICAgICAgICByZXR1cm4gY29weUFycmF5KHZhbHVlLCByZXN1bHQpO1xuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICB2YXIgdGFnID0gZ2V0VGFnKHZhbHVlKSxcbiAgICAgICAgICAgIGlzRnVuYyA9IHRhZyA9PSBmdW5jVGFnIHx8IHRhZyA9PSBnZW5UYWc7XG5cbiAgICAgICAgaWYgKGlzQnVmZmVyKHZhbHVlKSkge1xuICAgICAgICAgIHJldHVybiBjbG9uZUJ1ZmZlcih2YWx1ZSwgaXNEZWVwKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGFnID09IG9iamVjdFRhZyB8fCB0YWcgPT0gYXJnc1RhZyB8fCAoaXNGdW5jICYmICFvYmplY3QpKSB7XG4gICAgICAgICAgcmVzdWx0ID0gKGlzRmxhdCB8fCBpc0Z1bmMpID8ge30gOiBpbml0Q2xvbmVPYmplY3QodmFsdWUpO1xuICAgICAgICAgIGlmICghaXNEZWVwKSB7XG4gICAgICAgICAgICByZXR1cm4gaXNGbGF0XG4gICAgICAgICAgICAgID8gY29weVN5bWJvbHNJbih2YWx1ZSwgYmFzZUFzc2lnbkluKHJlc3VsdCwgdmFsdWUpKVxuICAgICAgICAgICAgICA6IGNvcHlTeW1ib2xzKHZ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BhcnJheSA9IGFycmF5c1swXTtcblxuICAgICAgdmFyIGluZGV4ID0gLTEsXG4gICAgICAgICAgc2VlbiA9IGNhY2hlc1swXTtcblxuICAgICAgb3V0ZXI6XG4gICAgICB3aGlsZSAoKytpbmRleCA8IGxlbmd0aCAmJiByZXN1bHQubGVuZ3RoIDwgbWF4TGVuZ3RoKSB7XG4gICAgICAgIHZhciB2YWx1ZSA9IGFycmF5W2luZGV4XSxcbiAgICAgICAgICAgIGNvbXB1dGVkID0gaXRlcmF0ZWUgPyBpdGVyYXRlZSh2YWx1ZSkgOiB2YWx1ZTtcblxuICAgICAgICB2YWx1ZSA9IChjb21wYXJhdG9yIHx8IHZhbHVlICE9PSAwKSA/IHZhbHVlIDogMDtcbiAgICAgICAgaWYgKCEoc2VlblxuICAgICAgICAgICAgICA/IGNhY2hlSGFzKHNlZW4sIGNvbXB1dGVkKVxuICAgICAgICAgICAgICA6IGluY2x1ZGVzKHJlc3VsdCwgY29tcHV0ZWQsIGNvbXBhcmF0b3IpXG4gICAgICAgICAgICApKSB7XG4gICAgICAgICAgb3RoSW5kZXggPSBvdGhMZW5ndGg7XG4gICAgICAgICAgd2hpbGUgKC0tb3RoSW5kZXgpIHtcbiAgICAgICAgICAgIHZhciBjYWNoZSA9IGNhY2hlc1tvdGhJbmRleF07XG4gICAgICAgICAgICBpZiAoIShjYWNoZVxuICAgICAgICAgICAgICAgICAgPyBjYWNoZUhhcyhjYWNoZSwgY29tcHV0ZWQpXG4gICAgICAgICAgICAgICAgICA6IGluY2x1ZGVzKGFycmF5c1tvdGhJbmRleF0sIGNvbXB1dGVkLCBjb21wYXJhdG9yKSlcbiAgICAgICAgICAgICAgICApIHtcbiAgICAgICAgICAgICAgY29udGludWUgb3V0ZXI7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChzZWVuKSB7XG4gICAgICAgICAgICBzZWVuLnB1c2goY29tcHV0ZWQpO1xuICAgICAgICAgIH1cbiAgICAgICAg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ICAgfVxuXG4gICAgLyoqXG4gICAgICogVGhlIGJhc2UgaW1wbGVtZW50YXRpb24gb2YgYF8uaW52b2tlYCB3aXRob3V0IHN1cHBvcnQgZm9yIGluZGl2aWR1YWxcbiAgICAgKiBtZXRob2QgYXJndW1lbnRzLlxuICAgICAqXG4gICAgICogQHByaXZhdGVcbiAgICAgKiBAcGFyYW0ge09iamVjdH0gb2JqZWN0IFRoZSBvYmplY3QgdG8gcXVlcnkuXG4gICAgICogQHBhcmFtIHtBcnJheXxzdHJpbmd9IHBhdGggVGhlIHBhdGggb2YgdGhlIG1ldGhvZCB0byBpbnZva2UuXG4gICAgICogQHBhcmFtIHtBcnJheX0gYXJncyBUaGUgYXJndW1lbnRzIHRvIGludm9rZSB0aGUgbWV0aG9kIHdpdGguXG4gICAgICogQHJldHVybnMgeyp9IFJldHVybnMgdGhlIHJlc3VsdCBvZiB0aGUgaW52b2tlZCBtZXRob2QuXG4gICAgICovXG4gICAgZnVuY3Rpb24gYmFzZUludm9rZShvYmplY3QsIHBhdGgsIGFyZ3MpIHtcbiAgICAgIHBhdGggPSBjYXN0UGF0aChwYXRoLCBvYmplY3QpO1xuICAgICAgb2JqZWN0ID0gcGFyZW50KG9iamVjdCwgcGF0aCk7XG4gICAgICB2YXIgZnVuYyA9IG9iamVjdCA9PSBudWxsID8gb2JqZWN0IDogb2JqZWN0W3RvS2V5KGxhc3QocGF0aCkpXTtcbiAgICAgIHJldHVybiBmdW5jID09IG51bGwgPyB1bmRlZmluZWQgOiBhcHBseShmdW5jLCBvYmplY3QsIGFyZ3MpO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFRoZSBiYXNlIGltcGxlbWVudGF0aW9uIG9mIGBfLmlzQXJndW1lbnRzYC5cbiAgICAgKlxuICAgICAqIEBwcml2YXRlXG4gICAgICogQHBhcmFtIHsqfSB2YWx1ZSBUaGUgdmFsdWUgdG8gY2hlY2suXG4gICAgICogQHJldHVybnMge2Jvb2xlYW59IFJldHVybnMgYHR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5ndGgpIHtcbiAgICAgICAgZGF0YSA9IG1hdGNoRGF0YVtpbmRleF07XG4gICAgICAgIHZhciBrZXkgPSBkYXRhWzBdLFxuICAgICAgICAgICAgb2JqVmFsdWUgPSBvYmplY3Rba2V5XSxcbiAgICAgICAgICAgIHNyY1ZhbHVlID0gZGF0YVsxXTtcblxuICAgICAgICBpZiAobm9DdXN0b21pemVyICYmIGRhdGFbMl0pIHtcbiAgICAgICAgICBpZiAob2JqVmFsdWUgPT09IHVuZGVmaW5lZCAmJiAhKGtleSBpbiBvYmplY3QpKSB7XG4gICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHZhciBzdGFjayA9IG5ldyBTdGFjaztcbiAgICAgICAgICBpZiAoY3VzdG9taXplcikge1xuICAgICAgICAgICAgdmFyIHJlc3VsdCA9IGN1c3RvbWl6ZXIob2JqVmFsdWUsIHNyY1ZhbHVlLCBrZXksIG9iamVjdCwgc291cmNlLCBzdGFjayk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmICghKHJlc3VsdCA9PT0gdW5kZWZpbmVkXG4gICAgICAgICAgICAgICAgPyBiYXNlSXNFcXVhbChzcmNWYWx1ZSwgb2JqVmFsdWUsIENPTVBBUkVfUEFSVElBTF9GTEFHIHwgQ09NUEFSRV9VTk9SREVSRURfRkxBRywgY3VzdG9taXplciwgc3RhY2spXG4gICAgICAgICAgICAgICAgOiByZXN1bHRcbiAgICAgICAgICAgICAgKSkge1xuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIHRydWU7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogVGhlIGJhc2UgaW1wbGVtZW50YXRpb24gb2YgYF8uaXNOYXRpdmVgIHdpdGhvdXQgYmFkIHNoaW0gY2hlY2tzLlxuICAgICAqXG4gICAgICogQHByaXZhdGVc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ICAqIEByZXR1cm5zIHtBcnJheX0gUmV0dXJucyB0aGUgYXJyYXkgb2YgcHJvcGVydHkgbmFtZXMuXG4gICAgICovXG4gICAgZnVuY3Rpb24gYmFzZUtleXMob2JqZWN0KSB7XG4gICAgICBpZiAoIWlzUHJvdG90eXBlKG9iamVjdCkpIHtcbiAgICAgICAgcmV0dXJuIG5hdGl2ZUtleXMob2JqZWN0KTtcbiAgICAgIH1cbiAgICAgIHZhciByZXN1bHQgPSBbXTtcbiAgICAgIGZvciAodmFyIGtleSBpbiBPYmplY3Qob2JqZWN0KSkge1xuICAgICAgICBpZiAoaGFzT3duUHJvcGVydHkuY2FsbChvYmplY3QsIGtleSkgJiYga2V5ICE9ICdjb25zdHJ1Y3RvcicpIHtcbiAgICAgICAgICByZXN1bHQucHVzaChrZXkpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gcmVzdWx0O1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFRoZSBiYXNlIGltcGxlbWVudGF0aW9uIG9mIGBfLmtleXNJbmAgd2hpY2ggZG9lc24ndCB0cmVhdCBzcGFyc2UgYXJyYXlzIGFzIGRlbnNlLlxuICAgICAqXG4gICAgICogQHByaXZhdGVcbiAgICAgKiBAcGFyYW0ge09iamVjdH0gb2JqZWN0IFRoZSBvYmplY3QgdG8gcXVlcnkuXG4gICAgICogQHJldHVybnMge0FycmF5fSBSZXR1cm5zIHRoZSBhcnJheSBvZiBwcm9wZXJ0eSBuYW1lcy5cbiAgICAgKi9cbiAgICBmdW5jdGlvbiBiYXNlS2V5c0luKG9iamVjdCkge1xuICAgICAgaWYgKCFpc09iamVjdChvYmplY3QpKSB7XG4gICAgICAgIHJldHVybiBuYXRpdmVLZXlzSW4ob2JqZWN0KTtcbiAgICAgIH1cbiAgICAgIHZhciBpc1Byb3RvID0gaXNQcm90b3R5cGUob2JqZWN0KSxcbiAgICAgICAgICByZXN1bHQgPSBbXTtcblxuICAgICAgZm9yICh2YXIga2V5IGlu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uZ3RoIDogMCxcbiAgICAgICAgICBsYXN0SW5kZXggPSBsZW5ndGggLSAxO1xuXG4gICAgICB3aGlsZSAobGVuZ3RoLS0pIHtcbiAgICAgICAgdmFyIGluZGV4ID0gaW5kZXhlc1tsZW5ndGhdO1xuICAgICAgICBpZiAobGVuZ3RoID09IGxhc3RJbmRleCB8fCBpbmRleCAhPT0gcHJldmlvdXMpIHtcbiAgICAgICAgICB2YXIgcHJldmlvdXMgPSBpbmRleDtcbiAgICAgICAgICBpZiAoaXNJbmRleChpbmRleCkpIHtcbiAgICAgICAgICAgIHNwbGljZS5jYWxsKGFycmF5LCBpbmRleCwgMSk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGJhc2VVbnNldChhcnJheSwgaW5kZXgpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIGFycmF5O1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFRoZSBiYXNlIGltcGxlbWVudGF0aW9uIG9mIGBfLnJhbmRvbWAgd2l0aG91dCBzdXBwb3J0IGZvciByZXR1cm5pbmdcbiAgICAgKiBmbG9hdGluZy1wb2ludCBudW1iZXJzLlxuICAgICAqXG4gICAgICogQHByaXZhdGVcbiAgICAgKiBAcGFyYW0ge251bWJlcn0gbG93ZXIgVGhlIGxvd2VyIGJvdW5kLlxuICAgICAqIEBwYXJhbSB7bnVtYmVyfSB1cHBlciBUaGUgdXBwZXIgYm91bmQuXG4gICAgICogQHJldHVybnMge251bWJlcn0gUmV0dXJucyB0aGUgcmFuZG9tIG51bWJlci5cbiAgICAgKi9cbiAgICBmdW5jdGlvbiBiYXNlUmFuZG9tKGxvd2VyLCB1cHBlcikge1xuICAgICAgcmV0dXJuIGxvd2VyICsgbmF0aXZlRmxvb3IobmF0aXZlUmFuZG9tKCkgKiAodXBwZXIgLSBsb3dlciArIDEpKTtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBUaGUgYmFzZSBpbX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Y3Qob2JqZWN0KSkge1xuICAgICAgICByZXR1cm4gb2JqZWN0O1xuICAgICAgfVxuICAgICAgcGF0aCA9IGNhc3RQYXRoKHBhdGgsIG9iamVjdCk7XG5cbiAgICAgIHZhciBpbmRleCA9IC0xLFxuICAgICAgICAgIGxlbmd0aCA9IHBhdGgubGVuZ3RoLFxuICAgICAgICAgIGxhc3RJbmRleCA9IGxlbmd0aCAtIDEsXG4gICAgICAgICAgbmVzdGVkID0gb2JqZWN0O1xuXG4gICAgICB3aGlsZSAobmVzdGVkICE9IG51bGwgJiYgKytpbmRleCA8IGxlbmd0aCkge1xuICAgICAgICB2YXIga2V5ID0gdG9LZXkocGF0aFtpbmRleF0pLFxuICAgICAgICAgICAgbmV3VmFsdWUgPSB2YWx1ZTtcblxuICAgICAgICBpZiAoa2V5ID09PSAnX19wcm90b19fJyB8fCBrZXkgPT09ICdjb25zdHJ1Y3RvcicgfHwga2V5ID09PSAncHJvdG90eXBlJykge1xuICAgICAgICAgIHJldHVybiBvYmplY3Q7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoaW5kZXggIT0gbGFzdEluZGV4KSB7XG4gICAgICAgICAgdmFyIG9ialZhbHVlID0gbmVzdGVkW2tleV07XG4gICAgICAgICAgbmV3VmFsdWUgPSBjdXN0b21pemVyID8gY3VzdG9taXplcihvYmpWYWx1ZSwga2V5LCBuZXN0ZWQpIDogdW5kZWZpbmVkO1xuICAgICAgICAgIGlmIChuZXdWYWx1ZSA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICBuZXdWYWx1ZSA9IGlzT2JqZWN0KG9ialZhbHVlKVxuICAgICAgICAgICAgICA/IG9ialZhbHVlXG4gICAgICAgICAgICAgIDogKGlzSW5kZXgocGF0aFtpbmRleCArIDFdKSA/IFtdIDoge30pO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBhc3NpZ25WYWx1ZShuZXN0ZWQsIGtleSwgbmV3VmFsdWUpO1xuICAgICAgICBuZXN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dD17fV0gVGhlIG9iamVjdCB0byBjb3B5IHByb3BlcnRpZXMgdG8uXG4gICAgICogQHBhcmFtIHtGdW5jdGlvbn0gW2N1c3RvbWl6ZXJdIFRoZSBmdW5jdGlvbiB0byBjdXN0b21pemUgY29waWVkIHZhbHVlcy5cbiAgICAgKiBAcmV0dXJucyB7T2JqZWN0fSBSZXR1cm5zIGBvYmplY3RgLlxuICAgICAqL1xuICAgIGZ1bmN0aW9uIGNvcHlPYmplY3Qoc291cmNlLCBwcm9wcywgb2JqZWN0LCBjdXN0b21pemVyKSB7XG4gICAgICB2YXIgaXNOZXcgPSAhb2JqZWN0O1xuICAgICAgb2JqZWN0IHx8IChvYmplY3QgPSB7fSk7XG5cbiAgICAgIHZhciBpbmRleCA9IC0xLFxuICAgICAgICAgIGxlbmd0aCA9IHByb3BzLmxlbmd0aDtcblxuICAgICAgd2hpbGUgKCsraW5kZXggPCBsZW5ndGgpIHtcbiAgICAgICAgdmFyIGtleSA9IHByb3BzW2luZGV4XTtcblxuICAgICAgICB2YXIgbmV3VmFsdWUgPSBjdXN0b21pemVyXG4gICAgICAgICAgPyBjdXN0b21pemVyKG9iamVjdFtrZXldLCBzb3VyY2Vba2V5XSwga2V5LCBvYmplY3QsIHNvdXJjZSlcbiAgICAgICAgICA6IHVuZGVmaW5lZDtcblxuICAgICAgICBpZiAobmV3VmFsdWUgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgIG5ld1ZhbHVlID0gc291cmNlW2tleV07XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGlzTmV3KSB7XG4gICAgICAgICAgYmFzZUFzc2lnblZhbHVlKG9iamVjdCwga2V5LCBuZXdWYWx1ZSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgYXNzaWduVmFsdWUob2JqZWN0LCBrZXksIG5ld1ZhbHVlKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIG9iamVjdDtcbiAgICB9XG5cbiAgICAvKipcbiAgICA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SA6IHVuZGVmaW5lZDtcblxuICAgICAgICAgIGlmIChkYXRhICYmIGlzTGF6aWFibGUoZGF0YVswXSkgJiZcbiAgICAgICAgICAgICAgICBkYXRhWzFdID09IChXUkFQX0FSWV9GTEFHIHwgV1JBUF9DVVJSWV9GTEFHIHwgV1JBUF9QQVJUSUFMX0ZMQUcgfCBXUkFQX1JFQVJHX0ZMQUcpICYmXG4gICAgICAgICAgICAgICAgIWRhdGFbNF0ubGVuZ3RoICYmIGRhdGFbOV0gPT0gMVxuICAgICAgICAgICAgICApIHtcbiAgICAgICAgICAgIHdyYXBwZXIgPSB3cmFwcGVyW2dldEZ1bmNOYW1lKGRhdGFbMF0pXS5hcHBseSh3cmFwcGVyLCBkYXRhWzNdKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgd3JhcHBlciA9IChmdW5jLmxlbmd0aCA9PSAxICYmIGlzTGF6aWFibGUoZnVuYykpXG4gICAgICAgICAgICAgID8gd3JhcHBlcltmdW5jTmFtZV0oKVxuICAgICAgICAgICAgICA6IHdyYXBwZXIudGhydShmdW5jKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKCkge1xuICAgICAgICAgIHZhciBhcmdzID0gYXJndW1lbnRzLFxuICAgICAgICAgICAgICB2YWx1ZSA9IGFyZ3NbMF07XG5cbiAgICAgICAgICBpZiAod3JhcHBlciAmJiBhcmdzLmxlbmd0aCA9PSAxICYmIGlzQXJyYXkodmFsdWUpKSB7XG4gICAgICAgICAgICByZXR1cm4gd3JhcHBlci5wbGFudCh2YWx1ZSkudmFsdWUoKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgdmFyIGluZGV4ID0gMCxcbiAgICAgICAgICAgICAgcmVzdWx0ID0gbGVuZ3RoID8gZnVuY3NbaW5kZXhdLmFwcGx5KHRoaXMsIGFyZ3MpIDogdmFsdWU7XG5cbiAgICAgICAgICB3aGlsZSAoKytpbmRleCA8IGxl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gIC8vIElnbm9yZSBub24taW5kZXggcHJvcGVydGllcy5cbiAgICAgIHdoaWxlICgrK2luZGV4IDwgYXJyTGVuZ3RoKSB7XG4gICAgICAgIHZhciBhcnJWYWx1ZSA9IGFycmF5W2luZGV4XSxcbiAgICAgICAgICAgIG90aFZhbHVlID0gb3RoZXJbaW5kZXhdO1xuXG4gICAgICAgIGlmIChjdXN0b21pemVyKSB7XG4gICAgICAgICAgdmFyIGNvbXBhcmVkID0gaXNQYXJ0aWFsXG4gICAgICAgICAgICA/IGN1c3RvbWl6ZXIob3RoVmFsdWUsIGFyclZhbHVlLCBpbmRleCwgb3RoZXIsIGFycmF5LCBzdGFjaylcbiAgICAgICAgICAgIDogY3VzdG9taXplcihhcnJWYWx1ZSwgb3RoVmFsdWUsIGluZGV4LCBhcnJheSwgb3RoZXIsIHN0YWNrKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoY29tcGFyZWQgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgIGlmIChjb21wYXJlZCkge1xuICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJlc3VsdCA9IGZhbHNlO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIC8vIFJlY3Vyc2l2ZWx5IGNvbXBhcmUgYXJyYXlzIChzdXNjZXB0aWJsZSB0byBjYWxsIHN0YWNrIGxpbWl0cykuXG4gICAgICAgIGlmIChzZWVuKSB7XG4gICAgICAgICAgaWYgKCFhcnJheVNvbWUob3RoZXIsIGZ1bmN0aW9uKG90aFZhbHVlLCBvdGhJbmRleCkge1xuICAgICAgICAgICAgICAgIGlmICghY2FjaGVIYXMoc2Vlbiwgb3RoSW5kZXgpICYmXG4gICAgICAgICAgICAgICAgICAgIChhcnJWYWx1ZSA9PT0gb3RoVmFsdWUgfHwgZXF1YWxGdW5jKGFyclZhbHVlLCBvdGhWYWx1ZSwgYml0bWFzaywgY3VzdG9taXplciwgc3RhY2spKSkge1xuICAgICAgICAgICAgICAgICAgcmV0dXJuIHNlZW4ucHVzaChvdGhJbmRleCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9KSkge1xuICAgICAgICAgICAgcmVzdWx0ID0gZmFsc2U7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSBpZiAoIShcbiAgICAgICAgICAgICAgYXJyVmFsdWUgPT09IG90aFZhbHVlIHx8XG4gICAgICAgICAgICAgICAgZXF1YWxGdW5jKGFyclZhbHVlLCBvdGhWYWx1ZSwgYml0bWFzaywgY3VzdG9taXplciwgc3RhY2spXG4gICAgICAgICAgICApKSB7XG4gICAgICAgICAgcmVzdWx0ID0gZmFsc2U7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHN0YWNrWydkZWxldGUnXShhcnJheSk7XG4gICAgICBzdGFja1snZGVsZXRlJ10ob3RoZXIpO1xuICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBBIHNwZWNpYWxpemVkIHZlcnNpb24gb2YgYGJhc2VJc0VxdWFsRGVlcGAgZm9yIGNvbXBhcmluZyBvYmplY3RzIG9mXG4gICAgICogdGhlIHNhbWUgYHRvU3RyaW5nVGFnYC5cbiAgICAgKlxuICAgICAqICoqTm90ZToqKiBUaGlzIGZ1bmN0aW9uIG9ubHkgc3VwcG9ydHMgY29tcGFyaW5nIHZhbHVlcyB3aXRoIHRhZ3Mgb2ZcbiAgICAgKiBgQm9vbGVhbmAsIGBEYXRlYCwgYEVycm9yYCwgYE51bWJlcmAsIGBSZWdFeHBgLCBvciBgU3RyaW5nYC5cbiAgICAgKlxuICAgICAqIEBwcml2YXRlXG4gICAgICogQHBhcmFtIHtPYmplY3R9IG9iamVjdCBUaGUgb2JqZWN0IHRvIGNvbXBhcmUuXG4gICAgICogQHBhcmFtIHtPYmplY3R9IG90aGVyIFRoZSBvdGhl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sLm9yZy9lY21hLTI2Mi83LjAvI3NlYy1yZWdleHAucHJvdG90eXBlLnRvc3RyaW5nXG4gICAgICAgICAgLy8gZm9yIG1vcmUgZGV0YWlscy5cbiAgICAgICAgICByZXR1cm4gb2JqZWN0ID09IChvdGhlciArICcnKTtcblxuICAgICAgICBjYXNlIG1hcFRhZzpcbiAgICAgICAgICB2YXIgY29udmVydCA9IG1hcFRvQXJyYXk7XG5cbiAgICAgICAgY2FzZSBzZXRUYWc6XG4gICAgICAgICAgdmFyIGlzUGFydGlhbCA9IGJpdG1hc2sgJiBDT01QQVJFX1BBUlRJQUxfRkxBRztcbiAgICAgICAgICBjb252ZXJ0IHx8IChjb252ZXJ0ID0gc2V0VG9BcnJheSk7XG5cbiAgICAgICAgICBpZiAob2JqZWN0LnNpemUgIT0gb3RoZXIuc2l6ZSAmJiAhaXNQYXJ0aWFsKSB7XG4gICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vIEFzc3VtZSBjeWNsaWMgdmFsdWVzIGFyZSBlcXVhbC5cbiAgICAgICAgICB2YXIgc3RhY2tlZCA9IHN0YWNrLmdldChvYmplY3QpO1xuICAgICAgICAgIGlmIChzdGFja2VkKSB7XG4gICAgICAgICAgICByZXR1cm4gc3RhY2tlZCA9PSBvdGhlcjtcbiAgICAgICAgICB9XG4gICAgICAgICAgYml0bWFzayB8PSBDT01QQVJFX1VOT1JERVJFRF9GTEFHO1xuXG4gICAgICAgICAgLy8gUmVjdXJzaXZlbHkgY29tcGFyZSBvYmplY3RzIChzdXNjZXB0aWJsZSB0byBjYWxsIHN0YWNrIGxpbWl0cykuXG4gICAgICAgICAgc3RhY2suc2V0KG9iamVjdCwgb3RoZXIpO1xuICAgICAgICAgIHZhciByZXN1bHQgPSBlcXVhbEFycmF5cyhjb252ZXJ0KG9iamVjdCksIGNvbnZlcnQob3RoZXIpLCBiaXRtYXNrLCBjdXN0b21pemVyLCBlcXVhbEZ1bmMsIH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0YWNrLmdldChvdGhlcik7XG4gICAgICBpZiAob2JqU3RhY2tlZCAmJiBvdGhTdGFja2VkKSB7XG4gICAgICAgIHJldHVybiBvYmpTdGFja2VkID09IG90aGVyICYmIG90aFN0YWNrZWQgPT0gb2JqZWN0O1xuICAgICAgfVxuICAgICAgdmFyIHJlc3VsdCA9IHRydWU7XG4gICAgICBzdGFjay5zZXQob2JqZWN0LCBvdGhlcik7XG4gICAgICBzdGFjay5zZXQob3RoZXIsIG9iamVjdCk7XG5cbiAgICAgIHZhciBza2lwQ3RvciA9IGlzUGFydGlhbDtcbiAgICAgIHdoaWxlICgrK2luZGV4IDwgb2JqTGVuZ3RoKSB7XG4gICAgICAgIGtleSA9IG9ialByb3BzW2luZGV4XTtcbiAgICAgICAgdmFyIG9ialZhbHVlID0gb2JqZWN0W2tleV0sXG4gICAgICAgICAgICBvdGhWYWx1ZSA9IG90aGVyW2tleV07XG5cbiAgICAgICAgaWYgKGN1c3RvbWl6ZXIpIHtcbiAgICAgICAgICB2YXIgY29tcGFyZWQgPSBpc1BhcnRpYWxcbiAgICAgICAgICAgID8gY3VzdG9taXplcihvdGhWYWx1ZSwgb2JqVmFsdWUsIGtleSwgb3RoZXIsIG9iamVjdCwgc3RhY2spXG4gICAgICAgICAgICA6IGN1c3RvbWl6ZXIob2JqVmFsdWUsIG90aFZhbHVlLCBrZXksIG9iamVjdCwgb3RoZXIsIHN0YWNrKTtcbiAgICAgICAgfVxuICAgICAgICAvLyBSZWN1cnNpdmVseSBjb21wYXJlIG9iamVjdHMgKHN1c2NlcHRpYmxlIHRvIGNhbGwgc3RhY2sgbGltaXRzKS5cbiAgICAgICAgaWYgKCEoY29tcGFyZWQgPT09IHVuZGVmaW5lZFxuICAgICAgICAgICAgICA/IChvYmpWYWx1ZSA9PT0gb3RoVmFsdWUgfHwgZXF1YWxGdW5jKG9ialZhbHVlLCBvdGhWYWx1ZSwgYml0bWFzaywgY3VzdG9taXplciwgc3RhY2spKVxuICAgICAgICAgICA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gICAgKiBAZXhhbXBsZVxuICAgICAqXG4gICAgICogXy5zaXplKFsxLCAyLCAzXSk7XG4gICAgICogLy8gPT4gM1xuICAgICAqXG4gICAgICogXy5zaXplKHsgJ2EnOiAxLCAnYic6IDIgfSk7XG4gICAgICogLy8gPT4gMlxuICAgICAqXG4gICAgICogXy5zaXplKCdwZWJibGVzJyk7XG4gICAgICogLy8gPT4gN1xuICAgICAqL1xuICAgIGZ1bmN0aW9uIHNpemUoY29sbGVjdGlvbikge1xuICAgICAgaWYgKGNvbGxlY3Rpb24gPT0gbnVsbCkge1xuICAgICAgICByZXR1cm4gMDtcbiAgICAgIH1cbiAgICAgIGlmIChpc0FycmF5TGlrZShjb2xsZWN0aW9uKSkge1xuICAgICAgICByZXR1cm4gaXNTdHJpbmcoY29sbGVjdGlvbikgPyBzdHJpbmdTaXplKGNvbGxlY3Rpb24pIDogY29sbGVjdGlvbi5sZW5ndGg7XG4gICAgICB9XG4gICAgICB2YXIgdGFnID0gZ2V0VGFnKGNvbGxlY3Rpb24pO1xuICAgICAgaWYgKHRhZyA9PSBtYXBUYWcgfHwgdGFnID09IHNldFRhZykge1xuICAgICAgICByZXR1cm4gY29sbGVjdGlvbi5zaXplO1xuICAgICAgfVxuICAgICAgcmV0dXJuIGJhc2VLZXlzKGNvbGxlY3Rpb24pLmxlbmd0aDtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBDaGVja3MgaWYgYHByZWRpY2F0ZWAgcmV0dXJucyB0cnV0aHkgZm9yICoqYW55KiogZWxlbWVudCBvZiBgY29sbGVjdGlvbmAuXG4gICAgICogSXRlcmF0aW9uIGlzIHN0b3BwZWQgb25jZSBgcHJlZGljYXRlYCByZXR1cm5zIHRydXRoeS4gVGhlIHByZWRpY2F0ZSBpc1xuICAgICAqIGludm9rZWQgd2l0aCB0aHJlZSBhcmd1bWVudHM6ICh2YWx1ZSwgaW5kZXh8a2V5LCBjb2xsZWN0aW9uKS5cbiAgICAgKlxuICAgICAqIEBzdG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2FuY2VsKCkge1xuICAgICAgICBpZiAodGltZXJJZCAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgY2xlYXJUaW1lb3V0KHRpbWVySWQpO1xuICAgICAgICB9XG4gICAgICAgIGxhc3RJbnZva2VUaW1lID0gMDtcbiAgICAgICAgbGFzdEFyZ3MgPSBsYXN0Q2FsbFRpbWUgPSBsYXN0VGhpcyA9IHRpbWVySWQgPSB1bmRlZmluZWQ7XG4gICAgICB9XG5cbiAgICAgIGZ1bmN0aW9uIGZsdXNoKCkge1xuICAgICAgICByZXR1cm4gdGltZXJJZCA9PT0gdW5kZWZpbmVkID8gcmVzdWx0IDogdHJhaWxpbmdFZGdlKG5vdygpKTtcbiAgICAgIH1cblxuICAgICAgZnVuY3Rpb24gZGVib3VuY2VkKCkge1xuICAgICAgICB2YXIgdGltZSA9IG5vdygpLFxuICAgICAgICAgICAgaXNJbnZva2luZyA9IHNob3VsZEludm9rZSh0aW1lKTtcblxuICAgICAgICBsYXN0QXJncyA9IGFyZ3VtZW50cztcbiAgICAgICAgbGFzdFRoaXMgPSB0aGlzO1xuICAgICAgICBsYXN0Q2FsbFRpbWUgPSB0aW1lO1xuXG4gICAgICAgIGlmIChpc0ludm9raW5nKSB7XG4gICAgICAgICAgaWYgKHRpbWVySWQgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgcmV0dXJuIGxlYWRpbmdFZGdlKGxhc3RDYWxsVGltZSk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChtYXhpbmcpIHtcbiAgICAgICAgICAgIC8vIEhhbmRsZSBpbnZvY2F0aW9ucyBpbiBhIHRpZ2h0IGxvb3AuXG4gICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZXJJZCk7XG4gICAgICAgICAgICB0aW1lcklkID0gc2V0VGltZW91dCh0aW1lckV4cGlyZWQsIHdhaXQpO1xuICAgICAgICAgICAgcmV0dXJuIGludm9rZUZ1bmMobGFzdENhbGxUaW1lKTtcbiAgICAgIC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9XG5cbiAgICAvKipcbiAgICAgKiBDb252ZXJ0cyBgdmFsdWVgIHRvIGFuIGludGVnZXIuXG4gICAgICpcbiAgICAgKiAqKk5vdGU6KiogVGhpcyBtZXRob2QgaXMgbG9vc2VseSBiYXNlZCBvblxuICAgICAqIFtgVG9JbnRlZ2VyYF0oaHR0cDovL3d3dy5lY21hLWludGVybmF0aW9uYWwub3JnL2VjbWEtMjYyLzcuMC8jc2VjLXRvaW50ZWdlcikuXG4gICAgICpcbiAgICAgKiBAc3RhdGljXG4gICAgICogQG1lbWJlck9mIF9cbiAgICAgKiBAc2luY2UgNC4wLjBcbiAgICAgKiBAY2F0ZWdvcnkgTGFuZ1xuICAgICAqIEBwYXJhbSB7Kn0gdmFsdWUgVGhlIHZhbHVlIHRvIGNvbnZlcnQuXG4gICAgICogQHJldHVybnMge251bWJlcn0gUmV0dXJucyB0aGUgY29udmVydGVkIGludGVnZXIuXG4gICAgICogQGV4YW1wbGVcbiAgICAgKlxuICAgICAqIF8udG9JbnRlZ2VyKDMuMik7XG4gICAgICogLy8gPT4gM1xuICAgICAqXG4gICAgICogXy50b0ludGVnZXIoTnVtYmVyLk1JTl9WQUxVRSk7XG4gICAgICogLy8gPT4gMFxuICAgICAqXG4gICAgICogXy50b0ludGVnZXIoSW5maW5pdHkpO1xuICAgICAqIC8vID0+IDEuNzk3NjkzMTM0ODYyMzE1N2UrMzA4XG4gICAgICpcbiAgICAgKiBfLnRvSW50ZWdlcignMy4yJyk7XG4gICAgICogLy8gPT4gM1xuICAgICAqL1xuICAgIGZ1bmN0aW9uIHRvSW50ZWdlcih2YWx1ZSkge1xuICAgICAgdmFyIHJlc3VsdCA9IHRvRmluaXRlKHZhbHVlKSxcbiAgICAgICAgICByZW1haW5kZXIgPSByZXN1bHQgJSAxO1xuXG4gICAgICByZXR1cm4gcmVzdWx0ID09PSByZXN1bHQgPyAocmVtYWluZGVyID8gcmVzdWx0IC0gcmVtYWluZGVyIDogcmVzdWx0KSA6IDA7XG4g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3VhcmQgJiYgaXNJdGVyYXRlZUNhbGwoc291cmNlc1swXSwgc291cmNlc1sxXSwgZ3VhcmQpKSB7XG4gICAgICAgIGxlbmd0aCA9IDE7XG4gICAgICB9XG5cbiAgICAgIHdoaWxlICgrK2luZGV4IDwgbGVuZ3RoKSB7XG4gICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzW2luZGV4XTtcbiAgICAgICAgdmFyIHByb3BzID0ga2V5c0luKHNvdXJjZSk7XG4gICAgICAgIHZhciBwcm9wc0luZGV4ID0gLTE7XG4gICAgICAgIHZhciBwcm9wc0xlbmd0aCA9IHByb3BzLmxlbmd0aDtcblxuICAgICAgICB3aGlsZSAoKytwcm9wc0luZGV4IDwgcHJvcHNMZW5ndGgpIHtcbiAgICAgICAgICB2YXIga2V5ID0gcHJvcHNbcHJvcHNJbmRleF07XG4gICAgICAgICAgdmFyIHZhbHVlID0gb2JqZWN0W2tleV07XG5cbiAgICAgICAgICBpZiAodmFsdWUgPT09IHVuZGVmaW5lZCB8fFxuICAgICAgICAgICAgICAoZXEodmFsdWUsIG9iamVjdFByb3RvW2tleV0pICYmICFoYXNPd25Qcm9wZXJ0eS5jYWxsKG9iamVjdCwga2V5KSkpIHtcbiAgICAgICAgICAgIG9iamVjdFtrZXldID0gc291cmNlW2tleV07XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIHJldHVybiBvYmplY3Q7XG4gICAgfSk7XG5cbiAgICAvKipcbiAgICAgKiBUaGlzIG1ldGhvZCBpcyBsaWtlIGBfLmRlZmF1bHRzYCBleGNlcHQgdGhhdCBpdCByZWN1cnNpdmVseSBhc3NpZ25zXG4gICAgICogZGVmYXVsdCBwcm9wZXJ0aWVzLlxuICAgICAqXG4gICAgICogKipOb3RlOioqIFRoaXMgbWV0aG9kIG11dGF0ZXMgYG9iamVjdGAuXG4gICAgICpcbiAgICAgKiBAc3RhdGljXG4gICAgICogQG1lbWJlck9mIF9cbiAgICAgKiBAc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dG9taXplcikge1xuICAgICAgY3VzdG9taXplciA9IHR5cGVvZiBjdXN0b21pemVyID09ICdmdW5jdGlvbicgPyBjdXN0b21pemVyIDogdW5kZWZpbmVkO1xuICAgICAgcmV0dXJuIG9iamVjdCA9PSBudWxsID8gb2JqZWN0IDogYmFzZVVwZGF0ZShvYmplY3QsIHBhdGgsIGNhc3RGdW5jdGlvbih1cGRhdGVyKSwgY3VzdG9taXplcik7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogQ3JlYXRlcyBhbiBhcnJheSBvZiB0aGUgb3duIGVudW1lcmFibGUgc3RyaW5nIGtleWVkIHByb3BlcnR5IHZhbHVlcyBvZiBgb2JqZWN0YC5cbiAgICAgKlxuICAgICAqICoqTm90ZToqKiBOb24tb2JqZWN0IHZhbHVlcyBhcmUgY29lcmNlZCB0byBvYmplY3RzLlxuICAgICAqXG4gICAgICogQHN0YXRpY1xuICAgICAqIEBzaW5jZSAwLjEuMFxuICAgICAqIEBtZW1iZXJPZiBfXG4gICAgICogQGNhdGVnb3J5IE9iamVjdFxuICAgICAqIEBwYXJhbSB7T2JqZWN0fSBvYmplY3QgVGhlIG9iamVjdCB0byBxdWVyeS5cbiAgICAgKiBAcmV0dXJucyB7QXJyYXl9IFJldHVybnMgdGhlIGFycmF5IG9mIHByb3BlcnR5IHZhbHVlcy5cbiAgICAgKiBAZXhhbXBsZVxuICAgICAqXG4gICAgICogZnVuY3Rpb24gRm9vKCkge1xuICAgICAqICAgdGhpcy5hID0gMTtcbiAgICAgKiAgIHRoaXMuYiA9IDI7XG4gICAgICogfVxuICAgICAqXG4gICAgICogRm9vLnByb3RvdHlwZS5jID0gMztcbiAgICAgKlxuICAgICAqIF8udmFsdWVzKG5ldyBGb28pO1xuICAgICAqIC8vID0+IFsxLCAyXSAoaXRlcmF0aW9uIG9yZGVyIGlzIG5vdCBndWFyYW50ZWVkKVxuICAgICAqXG4gICAgICogXy52YWx1ZXMoJ2hpJyk7XG4gICAgICogLy8gPT4gWyd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0gMDtcbiAgICAgICAgdXBwZXIgPSAxO1xuICAgICAgfVxuICAgICAgZWxzZSB7XG4gICAgICAgIGxvd2VyID0gdG9GaW5pdGUobG93ZXIpO1xuICAgICAgICBpZiAodXBwZXIgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgIHVwcGVyID0gbG93ZXI7XG4gICAgICAgICAgbG93ZXIgPSAwO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHVwcGVyID0gdG9GaW5pdGUodXBwZXIpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpZiAobG93ZXIgPiB1cHBlcikge1xuICAgICAgICB2YXIgdGVtcCA9IGxvd2VyO1xuICAgICAgICBsb3dlciA9IHVwcGVyO1xuICAgICAgICB1cHBlciA9IHRlbXA7XG4gICAgICB9XG4gICAgICBpZiAoZmxvYXRpbmcgfHwgbG93ZXIgJSAxIHx8IHVwcGVyICUgMSkge1xuICAgICAgICB2YXIgcmFuZCA9IG5hdGl2ZVJhbmRvbSgpO1xuICAgICAgICByZXR1cm4gbmF0aXZlTWluKGxvd2VyICsgKHJhbmQgKiAodXBwZXIgLSBsb3dlciArIGZyZWVQYXJzZUZsb2F0KCcxZS0nICsgKChyYW5kICsgJycpLmxlbmd0aCAtIDEpKSkpLCB1cHBlcik7XG4gICAgICB9XG4gICAgICByZXR1cm4gYmFzZVJhbmRvbShsb3dlciwgdXBwZXIpO1xuICAgIH1cblxuICAgIC8qLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tKi9cblxuICAgIC8qKlxuICAgICAqIENvbnZlcnRzIGBzdHJpbmdgIHRvIFtjYW1lbCBjYXNlXShodHRwczovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9DYW1lbENhc2UpLlxuICAgICAqXG4gICAgICogQHN0YXRpY1xuICAgICAqIEBtZW1iZXJPZiBfXG4gICAgICogQHNpbmNl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biAgICAgICAgICAgOiAnJ1xuICAgICAgICApICtcbiAgICAgICAgKGlzRXZhbHVhdGluZ1xuICAgICAgICAgID8gJywgX19qID0gQXJyYXkucHJvdG90eXBlLmpvaW47XFxuJyArXG4gICAgICAgICAgICBcImZ1bmN0aW9uIHByaW50KCkgeyBfX3AgKz0gX19qLmNhbGwoYXJndW1lbnRzLCAnJykgfVxcblwiXG4gICAgICAgICAgOiAnO1xcbidcbiAgICAgICAgKSArXG4gICAgICAgIHNvdXJjZSArXG4gICAgICAgICdyZXR1cm4gX19wXFxufSc7XG5cbiAgICAgIHZhciByZXN1bHQgPSBhdHRlbXB0KGZ1bmN0aW9uKCkge1xuICAgICAgICByZXR1cm4gRnVuY3Rpb24oaW1wb3J0c0tleXMsIHNvdXJjZVVSTCArICdyZXR1cm4gJyArIHNvdXJjZSlcbiAgICAgICAgICAuYXBwbHkodW5kZWZpbmVkLCBpbXBvcnRzVmFsdWVzKTtcbiAgICAgIH0pO1xuXG4gICAgICAvLyBQcm92aWRlIHRoZSBjb21waWxlZCBmdW5jdGlvbidzIHNvdXJjZSBieSBpdHMgYHRvU3RyaW5nYCBtZXRob2Qgb3JcbiAgICAgIC8vIHRoZSBgc291cmNlYCBwcm9wZXJ0eSBhcyBhIGNvbnZlbmllbmNlIGZvciBpbmxpbmluZyBjb21waWxlZCB0ZW1wbGF0ZXMuXG4gICAgICByZXN1bHQuc291cmNlID0gc291cmNlO1xuICAgICAgaWYgKGlzRXJyb3IocmVzdWx0KSkge1xuICAgICAgICB0aHJvdyByZXN1bHQ7XG4gICAgICB9XG4gICAgICByZXR1cm4gcmVzdWx0O1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIENvbnZlcnRzIGBzdHJpbmdgLCBhcyBhIHdob2xlLCB0byBsb3dlciBjYXNlIGp1c3QgbGlrZVxuICAgICAqIFtTdHJpbmcjdG9Mb3dlckNhc2VdKGh0dHBzOi8vbWRuLmlvL3RvTG93ZXJDYXNlKS5cbiAgICAgKlxuIC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ICAgICpcbiAgICAgKiBfLnRyaW0oJy1fLWFiYy1fLScsICdfLScpO1xuICAgICAqIC8vID0+ICdhYmMnXG4gICAgICpcbiAgICAgKiBfLm1hcChbJyAgZm9vICAnLCAnICBiYXIgICddLCBfLnRyaW0pO1xuICAgICAqIC8vID0+IFsnZm9vJywgJ2JhciddXG4gICAgICovXG4gICAgZnVuY3Rpb24gdHJpbShzdHJpbmcsIGNoYXJzLCBndWFyZCkge1xuICAgICAgc3RyaW5nID0gdG9TdHJpbmcoc3RyaW5nKTtcbiAgICAgIGlmIChzdHJpbmcgJiYgKGd1YXJkIHx8IGNoYXJzID09PSB1bmRlZmluZWQpKSB7XG4gICAgICAgIHJldHVybiBiYXNlVHJpbShzdHJpbmcpO1xuICAgICAgfVxuICAgICAgaWYgKCFzdHJpbmcgfHwgIShjaGFycyA9IGJhc2VUb1N0cmluZyhjaGFycykpKSB7XG4gICAgICAgIHJldHVybiBzdHJpbmc7XG4gICAgICB9XG4gICAgICB2YXIgc3RyU3ltYm9scyA9IHN0cmluZ1RvQXJyYXkoc3RyaW5nKSxcbiAgICAgICAgICBjaHJTeW1ib2xzID0gc3RyaW5nVG9BcnJheShjaGFycyksXG4gICAgICAgICAgc3RhcnQgPSBjaGFyc1N0YXJ0SW5kZXgoc3RyU3ltYm9scywgY2hyU3ltYm9scyksXG4gICAgICAgICAgZW5kID0gY2hhcnNFbmRJbmRleChzdHJTeW1ib2xzLCBjaHJTeW1ib2xzKSArIDE7XG5cbiAgICAgIHJldHVybiBjYXN0U2xpY2Uoc3RyU3ltYm9scywgc3RhcnQsIGVuZCkuam9pbignJyk7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogUmVtb3ZlcyB0cmFpbGluZyB3aGl0ZXNwYWNlIG9yIHNwZWNpZmllZCBjaGFyYWN0ZXJzIGZyb20gYHN0cmluZ2AuXG4gICAgICpcbiAgICAgKiBAc3RhdGljXG4gICAgICogQG1lbWJlck9mIF9cbiAgICAgKiBAc2luY2UgNC4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AZXhhbXBsZVxuICAgICAqXG4gICAgICogZnVuY3Rpb24gdm93ZWxzKHN0cmluZykge1xuICAgICAqICAgcmV0dXJuIF8uZmlsdGVyKHN0cmluZywgZnVuY3Rpb24odikge1xuICAgICAqICAgICByZXR1cm4gL1thZWlvdV0vaS50ZXN0KHYpO1xuICAgICAqICAgfSk7XG4gICAgICogfVxuICAgICAqXG4gICAgICogXy5taXhpbih7ICd2b3dlbHMnOiB2b3dlbHMgfSk7XG4gICAgICogXy52b3dlbHMoJ2ZyZWQnKTtcbiAgICAgKiAvLyA9PiBbJ2UnXVxuICAgICAqXG4gICAgICogXygnZnJlZCcpLnZvd2VscygpLnZhbHVlKCk7XG4gICAgICogLy8gPT4gWydlJ11cbiAgICAgKlxuICAgICAqIF8ubWl4aW4oeyAndm93ZWxzJzogdm93ZWxzIH0sIHsgJ2NoYWluJzogZmFsc2UgfSk7XG4gICAgICogXygnZnJlZCcpLnZvd2VscygpO1xuICAgICAqIC8vID0+IFsnZSddXG4gICAgICovXG4gICAgZnVuY3Rpb24gbWl4aW4ob2JqZWN0LCBzb3VyY2UsIG9wdGlvbnMpIHtcbiAgICAgIHZhciBwcm9wcyA9IGtleXMoc291cmNlKSxcbiAgICAgICAgICBtZXRob2ROYW1lcyA9IGJhc2VGdW5jdGlvbnMoc291cmNlLCBwcm9wcyk7XG5cbiAgICAgIGlmIChvcHRpb25zID09IG51bGwgJiZcbiAgICAgICAgICAhKGlzT2JqZWN0KHNvdXJjZSkgJiYgKG1ldGhvZE5hbWVzLmxlbmd0aCB8fCAhcHJvcHMubGVuZ3RoKSkpIHtcbiAgICAgICAgb3B0aW9ucyA9IHNvdXJjZTtcbiAgICAgICAgc291cmNlID0gb2JqZWN0O1xuICAgICAgICBvYmplY3QgPSB0aGlzO1xuICAgICAgICBtZXRob2ROYW1lcyA9IGJhc2VGdW5jdGlvbnMoc291cmNlLCBrZXlzKHNvdXJjZSkpO1xuICAgICAgfVxuICAgICAgdmFyIGNoYWluID0gIShpc09iamVjdChvcHRpb25zKSAmJiAnY2hhaW4nIGluIG9wdGlvbnMpIHx8ICEhb3B0aW9ucy5jaGFpbixcbiAgICAgICAgICBpc0Z1bmMgPSBpc0Z1bmN0aW9uKG9iamVjdCk7XG5cbiAgICAgIGFycmF5RWFjaChtZXRob2ROYW1lcywgZnVuY3Rpb24obWV0aG9kTmFtZSkge1xuICAgICAgICB2YXIgZnVuYyA9IHNvdXJjZVttZXRob2ROYW1lXTtcbiAgICAgICAgb2JqZWN0W21ldGhvZE5hbWVdID0gZnVuYztcbiAgICAgICAgaWYgKGlzRnVuYykge1xuICAgICAgICAgIG9iamVjdC5wcm90b3R5cGVbbWV0aG9kTmFtZV0gPSBmdW5jdGlvbigpIHtcbiAgICAgICAgICAgIHZhciBjaGFpbkFsbCA9IHRoaXMuX19jaGFpbl9fO1xuICAgICAgICAgICAgaWYgKGNoYWluIHx8IGNoYWluQWxsKSB7XG4gICAgICAgICAgICAgIHZhciByZXN1bHQgPSBvYmplY3QodGhpcy5fX3dyYXBwZWRfXyksXG4gICAgICAgICAgICAgICAgICBhY3Rpb25zID0gcmVzdWx0Ll9fYWN0aW9uc19fID0gY29weUFycmF5KHRoaXMuX19hY3Rpb25zX18pO1xuXG4gICAgICAgICAgICAgIGFjdGlvbnMucHVzaCh7ICdmdW5jJzogZnVuYywgJ2FyZ3MnOiBhcmd1bWVudHMsICd0aGlzQXJnJzogb2JqZWN0IH0pO1xuICAgICAgICAgICAgICByZXN1bHQuX19jaGFpbl9fID0gY2hhaW5BbGw7XG4gICAgICAgICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gZnVuYy5hcHBseShvYmplY3QsIGFycmF5UHVzaChbdGhpcy52YWx1ZSgpXSwgYXJndW1lbnRzKSk7XG4gICAgICAgICAgfTtcbiAgICAgICAgfVxuICAgICAgfSk7XG5cbiAgICAgIHJldHVybiBvYmplY3Q7XG4gICAgfVxuXG4gICAgLyoqX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XSk7XG4gICAgICogLy8gPT4gZmFsc2VcbiAgICAgKi9cbiAgICBmdW5jdGlvbiBzdHViQXJyYXkoKSB7XG4gICAgICByZXR1cm4gW107XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogVGhpcyBtZXRob2QgcmV0dXJucyBgZmFsc2VgLlxuICAgICAqXG4gICAgICogQHN0YXRpY1xuICAgICAqIEBtZW1iZXJPZiBfXG4gICAgICogQHNpbmNlIDQuMTMuMFxuICAgICAqIEBjYXRlZ29yeSBVdGlsXG4gICAgICogQHJldHVybnMge2Jvb2xlYW59IFJldHVybnMgYGZhbHNlYC5cbiAgICAgKiBAZXhhbXBsZVxuICAgICAqXG4gICAgICogXy50aW1lcygyLCBfLnN0dWJGYWxzZSk7XG4gICAgICogLy8gPT4gW2ZhbHNlLCBmYWxzZV1cbiAgICAgKi9cbiAgICBmdW5jdGlvbiBzdHViRmFsc2UoKSB7XG4gICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogVGhpcyBtZXRob2QgcmV0dXJucyBhIG5ldyBlbXB0eSBvYmplY3QuXG4gICAgICpcbiAgICAgKiBAc3RhdGljXG4gICAgICogQG1lbWJlck9mIF9cbiAgICAgKiBAc2luY2UgNC4xMy4wXG4gICAgICogQGNhdGVnb3J5IFV0aWxcbiAgICAgKiBAcmV0dXJucyB7T2JqZWN0fSBSZXR1cm5zIHRoZSBuZXcgZW1wdHkgb2JqZWN0LlxuICAgICAqIEBleGFtcGxlXG4gICAgICpcbiAgICAgKiB2YXIgb2JqZWN0cyA9IF8udGltZXMoMiwgXy5zdHViT2JqZWN0KTtcbiAgICAgKlxuICAgICAqIGNvbnNvbGUubG9nKG9iamVjdHMpO1xuICAgICAqIC8vID0+IFt7fSwge31dXG4gICAgICpcbiAgICAgKiBjb25zb2xlLmxvZyhvYmplY3RzWzBdID09PSBvYmplY3RzWzFdKTtcbiAgICAgKiAvLyA9PiBmYWxzZVxuICAgICAqL1xuICAgIGZ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XBhcmF0b3IobnVtLCBzdHIpIHtcbiAgICBpZiAoXG4gICAgICAgIG51bSA9PT0gSW5maW5pdHlcbiAgICAgICAgfHwgbnVtID09PSAtSW5maW5pdHlcbiAgICAgICAgfHwgbnVtICE9PSBudW1cbiAgICAgICAgfHwgKG51bSAmJiBudW0gPiAtMTAwMCAmJiBudW0gPCAxMDAwKVxuICAgICAgICB8fCAkdGVzdC5jYWxsKC9lLywgc3RyKVxuICAgICkge1xuICAgICAgICByZXR1cm4gc3RyO1xuICAgIH1cbiAgICB2YXIgc2VwUmVnZXggPSAvWzAtOV0oPz0oPzpbMC05XXszfSkrKD8hWzAtOV0pKS9nO1xuICAgIGlmICh0eXBlb2YgbnVtID09PSAnbnVtYmVyJykge1xuICAgICAgICB2YXIgaW50ID0gbnVtIDwgMCA/IC0kZmxvb3IoLW51bSkgOiAkZmxvb3IobnVtKTsgLy8gdHJ1bmMobnVtKVxuICAgICAgICBpZiAoaW50ICE9PSBudW0pIHtcbiAgICAgICAgICAgIHZhciBpbnRTdHIgPSBTdHJpbmcoaW50KTtcbiAgICAgICAgICAgIHZhciBkZWMgPSAkc2xpY2UuY2FsbChzdHIsIGludFN0ci5sZW5ndGggKyAxKTtcbiAgICAgICAgICAgIHJldHVybiAkcmVwbGFjZS5jYWxsKGludFN0ciwgc2VwUmVnZXgsICckJl8nKSArICcuJyArICRyZXBsYWNlLmNhbGwoJHJlcGxhY2UuY2FsbChkZWMsIC8oWzAtOV17M30pL2csICckJl8nKSwgL18kLywgJycpO1xuICAgICAgICB9XG4gICAgfVxuICAgIHJldHVybiAkcmVwbGFjZS5jYWxsKHN0ciwgc2VwUmVnZXgsICckJl8nKTtcbn1cblxudmFyIHV0aWxJbnNwZWN0ID0gcmVxdWlyZSgnLi91dGlsLmluc3BlY3QnKTtcbnZhciBpbnNwZWN0Q3VzdG9tID0gdXRpbEluc3BlY3QuY3VzdG9tO1xudmFyIGluc3BlY3RTeW1ib2wgPSBpc1N5bWJvbChpbnNwZWN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d3JhcFF1b3RlcyhxdW90ZShhdHRyc1tpXS52YWx1ZSksICdkb3VibGUnLCBvcHRzKTtcbiAgICAgICAgfVxuICAgICAgICBzICs9ICc+JztcbiAgICAgICAgaWYgKG9iai5jaGlsZE5vZGVzICYmIG9iai5jaGlsZE5vZGVzLmxlbmd0aCkgeyBzICs9ICcuLi4nOyB9XG4gICAgICAgIHMgKz0gJzwvJyArICR0b0xvd2VyQ2FzZS5jYWxsKFN0cmluZyhvYmoubm9kZU5hbWUpKSArICc+JztcbiAgICAgICAgcmV0dXJuIHM7XG4gICAgfVxuICAgIGlmIChpc0FycmF5KG9iaikpIHtcbiAgICAgICAgaWYgKG9iai5sZW5ndGggPT09IDApIHsgcmV0dXJuICdbXSc7IH1cbiAgICAgICAgdmFyIHhzID0gYXJyT2JqS2V5cyhvYmosIGluc3BlY3QpO1xuICAgICAgICBpZiAoaW5kZW50ICYmICFzaW5nbGVMaW5lVmFsdWVzKHhzKSkge1xuICAgICAgICAgICAgcmV0dXJuICdbJyArIGluZGVudGVkSm9pbih4cywgaW5kZW50KSArICddJztcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gJ1sgJyArICRqb2luLmNhbGwoeHMsICcsICcpICsgJyBdJztcbiAgICB9XG4gICAgaWYgKGlzRXJyb3Iob2JqKSkge1xuICAgICAgICB2YXIgcGFydHMgPSBhcnJPYmpLZXlzKG9iaiwgaW5zcGVjdCk7XG4gICAgICAgIGlmICghKCdjYXVzZScgaW4gRXJyb3IucHJvdG90eXBlKSAmJiAnY2F1c2UnIGluIG9iaiAmJiAhaXNFbnVtZXJhYmxlLmNhbGwob2JqLCAnY2F1c2UnKSkge1xuICAgICAgICAgICAgcmV0dXJuICd7IFsnICsgU3RyaW5nKG9iaikgKyAnXSAnICsgJGpvaW4uY2FsbCgkY29uY2F0LmNhbGwoJ1tjYXVzZV06ICcgKyBpbnNwZWN0KG9iai5jYXVzZSksIHBhcnRzKSwgJywgJykgKyAnIH0nO1xuICAgICAgICB9XG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2VkIGZvciBzcGVjaWFsIGJ1dCBub3JtYWwgZXZlbnRzLlxuICAqL1xuICBaX09LOiAgICAgICAgICAgICAgIDAsXG4gIFpfU1RSRUFNX0VORDogICAgICAgMSxcbiAgWl9ORUVEX0RJQ1Q6ICAgICAgICAyLFxuICBaX0VSUk5POiAgICAgICAgICAgLTEsXG4gIFpfU1RSRUFNX0VSUk9SOiAgICAtMixcbiAgWl9EQVRBX0VSUk9SOiAgICAgIC0zLFxuICAvL1pfTUVNX0VSUk9SOiAgICAgLTQsXG4gIFpfQlVGX0VSUk9SOiAgICAgICAtNSxcbiAgLy9aX1ZFUlNJT05fRVJST1I6IC02LFxuXG4gIC8qIGNvbXByZXNzaW9uIGxldmVscyAqL1xuICBaX05PX0NPTVBSRVNTSU9OOiAgICAgICAgIDAsXG4gIFpfQkVTVF9TUEVFRDogICAgICAgICAgICAgMSxcbiAgWl9CRVNUX0NPTVBSRVNTSU9OOiAgICAgICA5LFxuICBaX0RFRkFVTFRfQ09NUFJFU1NJT046ICAgLTEsXG5cblxuICBaX0ZJTFRFUkVEOiAgICAgICAgICAgICAgIDEsXG4gIFpfSFVGRk1BTl9PTkxZOiAgICAgICAgICAgMixcbiAgWl9STEU6ICAgICAgICAgICAgICAgICAgICAzLFxuICBaX0ZJWEVEOiAgICAgICAgICAgICAgICAgIDQsXG4gIFpfREVGQVVMVF9TVFJBVEVHWTogICAgICAgMCxcblxuICAvKiBQb3NzaWJsZSB2YWx1ZXMgb2YgdGhlIGRhdGFfdHlwZSBmaWVsZCAodGhvdWdoIHNlZSBpbmZsYXRlKCkpICovXG4gIFpfQklOQVJZOiAgICAgICAgICAgICAgICAgMCxcbiAgWl9URVhUOiAgICAgICAgICAgICAgICAgICAxLFxuICAvL1pfQVNDSUk6ICAgICAgICAgICAgICAgIDEsIC8vID0gWl9URVhUIChkZXByZWNhdGVkKVxuICBaX1VOS05PV046ICAgICAgICAgICAgICAgIDIsXG5cbiAgLyogVGhlIGRlZmxhdGUgY29tc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VF9TUEVFRCAgICAgICAgICA9IDE7XG4vL3ZhciBaX0JFU1RfQ09NUFJFU1NJT04gICAgPSA5O1xudmFyIFpfREVGQVVMVF9DT01QUkVTU0lPTiA9IC0xO1xuXG5cbnZhciBaX0ZJTFRFUkVEICAgICAgICAgICAgPSAxO1xudmFyIFpfSFVGRk1BTl9PTkxZICAgICAgICA9IDI7XG52YXIgWl9STEUgICAgICAgICAgICAgICAgID0gMztcbnZhciBaX0ZJWEVEICAgICAgICAgICAgICAgPSA0O1xudmFyIFpfREVGQVVMVF9TVFJBVEVHWSAgICA9IDA7XG5cbi8qIFBvc3NpYmxlIHZhbHVlcyBvZiB0aGUgZGF0YV90eXBlIGZpZWxkICh0aG91Z2ggc2VlIGluZmxhdGUoKSkgKi9cbi8vdmFyIFpfQklOQVJZICAgICAgICAgICAgICA9IDA7XG4vL3ZhciBaX1RFWFQgICAgICAgICAgICAgICAgPSAxO1xuLy92YXIgWl9BU0NJSSAgICAgICAgICAgICAgID0gMTsgLy8gPSBaX1RFWFRcbnZhciBaX1VOS05PV04gICAgICAgICAgICAgPSAyO1xuXG5cbi8qIFRoZSBkZWZsYXRlIGNvbXByZXNzaW9uIG1ldGhvZCAqL1xudmFyIFpfREVGTEFURUQgID0gODtcblxuLyo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ki9cblxuXG52YXIgTUFYX01FTV9MRVZFTCA9IDk7XG4vKiBNYXhpbXVtIHZhbHVlIGZvciBtZW1MZXZlbCBpbiBkZWZsYXRlSW5pdDIgKi9cbnZhciBNQVhfV0JJVFMgPSAxNTtcbi8qIDMySyBMWjc3IHdpbmRvdyAqL1xudmFyIERFRl9NRU1fTEVWRUwgPSA4O1xuXG5cbnZhciBMRU5HVEhfQ09ERVMgID0gMjk7XG4vKiBudW1iZXIgb2YgbGVuZ3RoIGNvZGVzLCBub3QgY291bnRpbmcgdGhlIHNwZWNpYWwg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ICAqL1xuICAgIGlmIChzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCA+PSAocy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSkge1xuICAgICAgLyoqKiBGTFVTSF9CTE9DSyhzLCAwKTsgKioqL1xuICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7XG4gICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkge1xuICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFO1xuICAgICAgfVxuICAgICAgLyoqKi9cbiAgICB9XG4gIH1cblxuICBzLmluc2VydCA9IDA7XG5cbiAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkge1xuICAgIC8qKiogRkxVU0hfQkxPQ0socywgMSk7ICoqKi9cbiAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpO1xuICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7XG4gICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7XG4gICAgfVxuICAgIC8qKiovXG4gICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FO1xuICB9XG5cbiAgaWYgKHMuc3Ryc3RhcnQgPiBzLmJsb2NrX3N0YXJ0KSB7XG4gICAgLyoqKiBGTFVTSF9CTE9DSyhzLCAwKTsgKioqL1xuICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpO1xuICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7XG4gICAgICByZXR1cm4gQlNfTkVFRF9NT1JFO1xuICAgIH1cbiAgICAvKioqL1xuICB9XG5cbiAgcmV0dXJuIEJTX05FRURfTU9SRTtcbn1cblxuLyogPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09XG4gKiBDb21wcmVzcyBhcyBtdWNoIGFzIHBvc3NpYmxlIGZyb20gdGhlIGlucHV0IHN0cmVhbSwgcmV0dXJ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SBjdXJyZW50IGJsb2NrICovXG4gICAgfVxuXG4gICAgLyogU2VlIGhvdyBtYW55IHRpbWVzIHRoZSBwcmV2aW91cyBieXRlIHJlcGVhdHMgKi9cbiAgICBzLm1hdGNoX2xlbmd0aCA9IDA7XG4gICAgaWYgKHMubG9va2FoZWFkID49IE1JTl9NQVRDSCAmJiBzLnN0cnN0YXJ0ID4gMCkge1xuICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxO1xuICAgICAgcHJldiA9IF93aW5bc2Nhbl07XG4gICAgICBpZiAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0pIHtcbiAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDtcbiAgICAgICAgZG8ge1xuICAgICAgICAgIC8qanNoaW50IG5vZW1wdHk6ZmFsc2UqL1xuICAgICAgICB9IHdoaWxlIChwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmXG4gICAgICAgICAgICAgICAgIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiZcbiAgICAgICAgICAgICAgICAgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJlxuICAgICAgICAgICAgICAgICBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmXG4gICAgICAgICAgICAgICAgIHNjYW4gPCBzdHJlbmQpO1xuICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTtcbiAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID4gcy5sb29rYWhlYWQpIHtcbiAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IHMubG9va2FoZWFkO1xu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zLCA4KTtcbiAgICAgIGlmICghcy5nemhlYWQpIHsgLy8gcy0+Z3poZWFkID09IFpfTlVMTFxuICAgICAgICBwdXRfYnl0ZShzLCAwKTtcbiAgICAgICAgcHV0X2J5dGUocywgMCk7XG4gICAgICAgIHB1dF9ieXRlKHMsIDApO1xuICAgICAgICBwdXRfYnl0ZShzLCAwKTtcbiAgICAgICAgcHV0X2J5dGUocywgMCk7XG4gICAgICAgIHB1dF9ieXRlKHMsIHMubGV2ZWwgPT09IDkgPyAyIDpcbiAgICAgICAgICAgICAgICAgICAgKHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgP1xuICAgICAgICAgICAgICAgICAgICAgNCA6IDApKTtcbiAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7XG4gICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTtcbiAgICAgIH1cbiAgICAgIGVsc2Uge1xuICAgICAgICBwdXRfYnl0ZShzLCAocy5nemhlYWQudGV4dCA/IDEgOiAwKSArXG4gICAgICAgICAgICAgICAgICAgIChzLmd6aGVhZC5oY3JjID8gMiA6IDApICtcbiAgICAgICAgICAgICAgICAgICAgKCFzLmd6aGVhZC5leHRyYSA/IDAgOiA0KSArXG4gICAgICAgICAgICAgICAgICAgICghcy5nemhlYWQubmFtZSA/IDAgOiA4KSArXG4gICAgICAgICAgICAgICAgICAgICghcy5nemhlYWQuY29tbWVudCA/IDAgOiAxNilcbiAgICAgICAgKTtcbiAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDB4ZmYpO1xuICAgICAgICBwdXRfYnl0ZShzLCAocy5nemhlYWQudGltZSA+PiA4KSAmIDB4ZmYpO1xuICAgICAgICBwdXRfYnl0ZShzLCAocy5nemhlYWQudGltZSA+PiAxNikgJiAweGZmKTtcbiAgICAgICAgcHV0X2J5dGUocywgKHMuZ3poZWFkLnRpbWUgPj4gMjQpICYgMHhmZik7XG4gICAgICAg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Pj4gMTYpICYgMHhmZi8qaGVyZS5vcCovO1xuICAgICAgaWYgKG9wID09PSAwKSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBsaXRlcmFsICovXG4gICAgICAgIC8vVHJhY2V2digoc3RkZXJyLCBoZXJlLnZhbCA+PSAweDIwICYmIGhlcmUudmFsIDwgMHg3ZiA/XG4gICAgICAgIC8vICAgICAgICBcImluZmxhdGU6ICAgICAgICAgbGl0ZXJhbCAnJWMnXFxuXCIgOlxuICAgICAgICAvLyAgICAgICAgXCJpbmZsYXRlOiAgICAgICAgIGxpdGVyYWwgMHglMDJ4XFxuXCIsIGhlcmUudmFsKSk7XG4gICAgICAgIG91dHB1dFtfb3V0KytdID0gaGVyZSAmIDB4ZmZmZi8qaGVyZS52YWwqLztcbiAgICAgIH1cbiAgICAgIGVsc2UgaWYgKG9wICYgMTYpIHsgICAgICAgICAgICAgICAgICAgICAvKiBsZW5ndGggYmFzZSAqL1xuICAgICAgICBsZW4gPSBoZXJlICYgMHhmZmZmLypoZXJlLnZhbCovO1xuICAgICAgICBvcCAmPSAxNTsgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBudW1iZXIgb2YgZXh0cmEgYml0cyAqL1xuICAgICAgICBpZiAob3ApIHtcbiAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7XG4gICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzO1xuICAgICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgIH1cbiAgICAgICAgICBsZW4gKz0gaG9sZCAmICgoMSA8PCBvcCkgLSAxKTtcbiAgICAgICAgICBob2xkID4+Pj0gb3A7XG4gICAgICAgICAgYml0cyAtPSBvcDtcbiAgICAgICAgfVxuICAgICAgICAvL1RyYWNldnYoKHN0ZGVyciwgXCJpbmZsYXRlOiAgICAgICAgIGxlbmd0aCAldVxcblwiLCBsZW4pKTtcbiAgICAgICAgaWYgKGJpdHMgPCAxNSkge1xuICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7XG4gICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7XG4gICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICB9XG4gICAgICAgIGhlcmUgPSBkY29kZVtob2xkICYgZG1hc2tdO1xuXG4gICAgICAgIGRvZGlzdDpcbiAgICAgICAgZm9yICg7OykgeyAvLyBnb3RvIGVtdWxhdGlvblxuICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQvKmhlcmUuYml0cyovO1xuICAgICAgICAgIGhvbGQgPj4+PSBvcDtcbiAgICAgICAgICBiaXRzIC09IG9wO1xuICAgICAgICAgIG9wID0gKGhlcmUgPj4+IDE2KSAmIDB4ZmYvKmhlcmUub3AqLztcblxuICAgICAgICAgIGlmIChvcCAmIDE2KSB7ICAgICAgICAgICAgICAgICAgICAgIC8qIGRpc3RhbmNlIGJhc2UgKi9cbiAgICAgICAgICAgIGRpc3QgPSBoZXJlICYgMHhmZmZmLypoZXJlLnZhbCovO1xuICAgICAgICAgICAgb3AgJj0gMTU7ICAgICAgICAgICAgICAgICAgICAgICAvKiBudW1iZXIgb2YgZXh0cmEgYml0cyAqL1xuICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkge1xuICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzO1xuICAgICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHtcbiAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzO1xuICAgICAgICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZGlzdCArPSBob2xkICYgKCgxIDw8IG9wKSAtIDEpO1xuLy8jaWZkZWYgSU5GTEFURV9TVFJJQ1RcbiAgICAgICAgICAgIGlmIChkaXN0ID4gZG1heCkge1xuICAgICAgICAgICAgICBzdHJtLm1zZyA9ICdpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayc7XG4gICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7XG4gICAgICAgICAgICAgIGJyZWFrIHRvcDtcbiAgICAgICAgICAgIH1cbi8vI2VuZGlmXG4gICAgICAgICAgICBob2xkID4+Pj0gb3A7XG4gICAgICAgICAgICBiaXRzIC09IG9wO1xuICAgICAgICAgICAgLy9UcmFjZXZ2KChzdGRlcnIsIFwiaW5mbGF0ZTogICAgICAgICBkaXN0YW5jZSAldVxcblwiLCBkaXN0KSk7XG4gICAgICAgICAgICBvcCA9IF9vdXQgLSBiZWc7ICAgICAgICAgICAgICAgIC8qIG1heCBkaXN0YW5jZSBpbiBvdXRwdXQgKi9cbiAgICAgICAgICAgIGlmIChkaXN0ID4gb3ApIHsgICAgICAgICAgICAgICAgLyogc2VlIGlmIGNvcHkgZnJvbSB3aW5kb3cgKi9cbiAgICAgICAgICAgICAgb3AgPSBkaXN0IC0gb3A7ICAgICAgICAgICAgICAgLyogZGlzdGFuY2UgYmFjayBpbiB3aW5kb3cgKi9cbiAgICAgICAgICAgICAgaWYgKG9wID4gd2hhdmUpIHtcbiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuc2FuZSkge1xuICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAnaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2snO1xuICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDtcbiAgICAgICAgICAgICAgICB9XG5cbi8vICghKSBUaGlzIGJsb2NrIGlzIGRpc2FibGVkIGluIHpsaWIgZGVmYXVsdHMsXG4vLyBkb24ndCBlbmFibGUgaXQgZm9yIGJpbmFyeSBjb21wYXRpYmlsaXR5XG4vLyNpZmRlZiBJTkZMQVRFX0FMTE9XX0lOVkFMSURfRElTVEFOQ0VfVE9PRkFSX0FSUlJcbi8vICAgICAgICAgICAgICAgIGlmIChsZW4gPD0gb3AgLSB3aGF2ZSkge1xuLy8gICAgICAgICAgICAgICAgICBkbyB7XG4vLyAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSAwO1xuLy8gICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLWxlbik7XG4vLyAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIHRvcDtcbi8vICAgICAgICAgICAgICAgIH1cbi8vICAgICAgICAgICAgICAgIGxlbiAtPSBvcCAtIHdoYXZlO1xuLy8gICAgICAgICAgICAgICAgZG8ge1xuLy8gICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IDA7XG4vLyAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wID4gd2hhdmUpO1xuLy8gICAgICAgICAgICAgICAgaWYgKG9wID09PSAwKSB7XG4vLyAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDtcbi8vICAgICAgICAgICAgICAgICAgZG8ge1xuLy8gICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107XG4vLyAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tbGVuKTtcbi8vICAgICAgICAgICAgICAgICAgY29udGludWUgdG9wO1xuLy8gICAgICAgICAgICAgICAgfVxuLy8jZW5kaWZcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBmcm9tID0gMDsgLy8gd2luZG93IGluZGV4XG4gICAgICAgICAgICAgIGZyb21fc291cmNlID0gc193aW5kb3c7XG4gICAgICAgICAgICAgIGlmICh3bmV4dCA9PT0gMCkgeyAgICAgICAgICAgLyogdmVyeSBjb21tb24gY2FzZSAqL1xuICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgLSBvcDtcbiAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsgICAgICAgICAvKiBzb21lIGZyb20gd2luZG93ICovXG4gICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7XG4gICAgICAgICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApO1xuICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OyAgLyogcmVzdCBmcm9tIG91dHB1dCAqL1xuICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGVsc2UgaWYgKHduZXh0IDwgb3ApIHsgICAgICAvKiB3cmFwIGFyb3VuZCB3aW5kb3cgKi9cbiAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplICsgd25leHQgLSBvcDtcbiAgICAgICAgICAgICAgICBvcCAtPSB3bmV4dDtcbiAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsgICAgICAgICAvKiBzb21lIGZyb20gZW5kIG9mIHdpbmRvdyAqL1xuICAgICAgICAgICAgICAgICAgbGVuIC09IG9wO1xuICAgICAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107XG4gICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTtcbiAgICAgICAgICAgICAgICAgIGZyb20gPSAwO1xuICAgICAgICAgICAgICAgICAgaWYgKHduZXh0IDwgbGVuKSB7ICAvKiBzb21lIGZyb20gc3RhcnQgb2Ygd2luZG93ICovXG4gICAgICAgICAgICAgICAgICAgIG9wID0gd25leHQ7XG4gICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDtcbiAgICAgICAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7XG4gICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsgICAgICAvKiByZXN0IGZyb20gb3V0cHV0ICovXG4gICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0O1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBlbHNlIHsgICAgICAgICAgICAgICAgICAgICAgLyogY29udGlndW91cyBpbiB3aW5kb3cgKi9cbiAgICAgICAgICAgICAgICBmcm9tICs9IHduZXh0IC0gb3A7XG4gICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7ICAgICAgICAgLyogc29tZSBmcm9tIHdpbmRvdyAqL1xuICAgICAgICAgICAgICAgICAgbGVuIC09IG9wO1xuICAgICAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107XG4gICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTtcbiAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsgIC8qIHJlc3QgZnJvbSBvdXRwdXQgKi9cbiAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB3aGlsZSAobGVuID4gMikge1xuICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107XG4gICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdO1xuICAgICAgICAgICAgICAgIGxlbiAtPSAzO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGlmIChsZW4pIHtcbiAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107XG4gICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHtcbiAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7ICAgICAgICAgIC8qIGNvcHkgZGlyZWN0IGZyb20gb3V0cHV0ICovXG4gICAgICAgICAgICAgIGRvIHsgICAgICAgICAgICAgICAgICAgICAgICAvKiBtaW5pbXVtIGxlbmd0aCBpcyB0aHJlZSAqL1xuICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107XG4gICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdO1xuICAgICAgICAgICAgICAgIGxlbiAtPSAzO1xuICAgICAgICAgICAgICB9IHdoaWxlIChsZW4gPiAyKTtcbiAgICAgICAgICAgICAgaWYgKGxlbikge1xuICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107XG4gICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHtcbiAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgeyAgICAgICAgICAvKiAybmQgbGV2ZWwgZGlzdGFuY2UgY29kZSAqL1xuICAgICAgICAgICAgaGVyZSA9IGRjb2RlWyhoZXJlICYgMHhmZmZmKS8qaGVyZS52YWwqLyArIChob2xkICYgKCgxIDw8IG9wKSAtIDEpKV07XG4gICAgICAgICAgICBjb250aW51ZSBkb2Rpc3Q7XG4gICAgICAgICAgfVxuICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgc3RybS5tc2cgPSAnaW52YWxpZCBkaXN0YW5jZSBjb2RlJztcbiAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7XG4gICAgICAgICAgICBicmVhayB0b3A7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgYnJlYWs7IC8vIG5lZWQgdG8gZW11bGF0ZSBnb3RvIHZpYSBcImNvbnRpbnVlXCJcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7ICAgICAgICAgICAgICAvKiAybmQgbGV2ZWwgbGVuZ3RoIGNvZGUgKi9cbiAgICAgICAgaGVyZSA9IGxjb2RlWyhoZXJlICYgMHhmZmZmKS8qaGVyZS52YWwqLyArIChob2xkICYgKCgxIDw8IG9wKSAtIDEpKV07XG4gICAgICAgIGNvbnRpbnVlIGRvbGVuO1xuICAgICAgfVxuICAgICAgZWxzZSBpZiAob3AgJiAzMikgeyAgICAgICAgICAgICAgICAgICAgIC8qIGVuZC1vZi1ibG9jayAqL1xuICAgICAgICAvL1RyYWNldnYoKHN0ZGVyciwgXCJpbmZsYXRlOiAgICAgICAgIGVuZCBvZiBibG9ja1xcblwiKSk7XG4gICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFO1xuICAgICAgICBicmVhayB0b3A7XG4gICAgICB9XG4gICAgICBlbHNlIHtcbiAgICAgICAgc3RybS5tc2cgPSAnaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlJztcbiAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgYnJlYWs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AgICAgICAgICAgID0gMDtcbnZhciBaX1NUUkVBTV9FTkQgICAgPSAxO1xudmFyIFpfTkVFRF9ESUNUICAgICA9IDI7XG4vL3ZhciBaX0VSUk5PICAgICAgICAgPSAtMTtcbnZhciBaX1NUUkVBTV9FUlJPUiAgPSAtMjtcbnZhciBaX0RBVEFfRVJST1IgICAgPSAtMztcbnZhciBaX01FTV9FUlJPUiAgICAgPSAtNDtcbnZhciBaX0JVRl9FUlJPUiAgICAgPSAtNTtcbi8vdmFyIFpfVkVSU0lPTl9FUlJPUiA9IC02O1xuXG4vKiBUaGUgZGVmbGF0ZSBjb21wcmVzc2lvbiBtZXRob2QgKi9cbnZhciBaX0RFRkxBVEVEICA9IDg7XG5cblxuLyogU1RBVEVTID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ki9cbi8qID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PSovXG5cblxudmFyICAgIEhFQUQgPSAxOyAgICAgICAvKiBpOiB3YWl0aW5nIGZvciBtYWdpYyBoZWFkZXIgKi9cbnZhciAgICBGTEFHUyA9IDI7ICAgICAgLyogaTogd2FpdGluZyBmb3IgbWV0aG9kIGFuZCBmbGFncyAoZ3ppcCkgKi9cbnZhciAgICBUSU1FID0gMzsgICAgICAgLyogaTogd2FpdGluZyBmb3IgbW9kaWZpY2F0aW9uIHRpbWUgKGd6aXApICovXG52YXIgICAgT1MgPSA0OyAgICAgICAgIC8qIGk6IHdhaXRpbmcgZm9yIGV4dHJhIGZsYWdzIGFuZCBvcGVyYXRpbmcgc3lzdGVtIChnemlwKSAqL1xudmFyICAgIEVYTEVOID0gNTsgICAgICAvKiBpOiB3YWl0aW5nIGZvciBleHRyYSBsZW5ndGggKGd6aXApICovXG52YXIgICAgRVhUUkEgPSA2OyAgICAgIC8qIGk6IHdhaXRpbmcgZm9yIGV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ndGggKGd6aXApICovXG52YXIgICAgRE9ORSA9IDI5OyAgICAgIC8qIGZpbmlzaGVkIGNoZWNrLCBkb25lIC0tIHJlbWFpbiBoZXJlIHVudGlsIHJlc2V0ICovXG52YXIgICAgQkFEID0gMzA7ICAgICAgIC8qIGdvdCBhIGRhdGEgZXJyb3IgLS0gcmVtYWluIGhlcmUgdW50aWwgcmVzZXQgKi9cbnZhciAgICBNRU0gPSAzMTsgICAgICAgLyogZ290IGFuIGluZmxhdGUoKSBtZW1vcnkgZXJyb3IgLS0gcmVtYWluIGhlcmUgdW50aWwgcmVzZXQgKi9cbnZhciAgICBTWU5DID0gMzI7ICAgICAgLyogbG9va2luZyBmb3Igc3luY2hyb25pemF0aW9uIGJ5dGVzIHRvIHJlc3RhcnQgaW5mbGF0ZSgpICovXG5cbi8qID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PSovXG5cblxuXG52YXIgRU5PVUdIX0xFTlMgPSA4NTI7XG52YXIgRU5PVUdIX0RJU1RTID0gNTkyO1xuLy92YXIgRU5PVUdIID0gIChFTk9VR0hfTEVOUytFTk9VR0hfRElTVFMpO1xuXG52YXIgTUFYX1dCSVRTID0gMTU7XG4vKiAzMksgTFo3NyB3aW5kb3cgKi9cbnZhciBERUZfV0JJVFMgPSBNQVhfV0JJVFM7XG5cblxuZnVuY3Rpb24genN3YXAzMihxKSB7XG4gIHJldHVybiAgKCgocSA+Pj4gMjQpICYgMHhmZikgK1xuICAgICAgICAgICgocSA+Pj4gOCkgJiAweGZmMDApICtcbiAgICAgICAgICAoKHEgJiAweGZmMDApIDw8IDgpICtcbiAgICAgICAgICAoKHEgJiAweGZmKSA8PCAyNCkpO1xufVxuXG5cbmZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHtcbiAgdGhpcy5tb2RlID0gMDsgICAgICAgICAgICAgLyogY3VycmVudCBpbmZsYXRlIG1vZGUgKi9cbiAg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biA9IGhhdmU7XG4gIF9vdXQgPSBsZWZ0O1xuICByZXQgPSBaX09LO1xuXG4gIGluZl9sZWF2ZTogLy8gZ290byBlbXVsYXRpb25cbiAgZm9yICg7Oykge1xuICAgIHN3aXRjaCAoc3RhdGUubW9kZSkge1xuICAgICAgY2FzZSBIRUFEOlxuICAgICAgICBpZiAoc3RhdGUud3JhcCA9PT0gMCkge1xuICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgLy89PT0gTkVFREJJVFMoMTYpO1xuICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7XG4gICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzO1xuICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgfVxuICAgICAgICAvLz09PS8vXG4gICAgICAgIGlmICgoc3RhdGUud3JhcCAmIDIpICYmIGhvbGQgPT09IDB4OGIxZikgeyAgLyogZ3ppcCBoZWFkZXIgKi9cbiAgICAgICAgICBzdGF0ZS5jaGVjayA9IDAvKmNyYzMyKDBMLCBaX05VTEwsIDApKi87XG4gICAgICAgICAgLy89PT0gQ1JDMihzdGF0ZS5jaGVjaywgaG9sZCk7XG4gICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAweGZmO1xuICAgICAgICAgIGhidWZbMV0gPSAoaG9sZCA+Pj4gOCkgJiAweGZmO1xuICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApO1xuICAgICAgICAgIC8vPT09Ly9cblxuICAgICAgICAgIC8vPT09IElOSVRCSVRTKCk7XG4gICAgICAgICAgaG9sZCA9IDA7XG4gICAgICAgICAgYml0cyA9IDA7XG4gICAgICAgICAgLy89PT0vL1xuICAgICAgICAgIHN0YXRlLm1vZGUgPSBGTEFHUztcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICBzdGF0ZS5mbGFncyA9IDA7ICAgICAgICAgICAvKiBleHBlY3QgemxpYiBoZWFkZXIgKi9cbiAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHtcbiAgICAgICAgICBzdGF0ZS5oZWFkLmRvbmUgPSBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoIShzdGF0ZS53cmFwICYgMSkgfHwgICAvKiBjaGVjayBpZiB6bGliIGhlYWRlciBhbGxvd2VkICovXG4gICAgICAgICAgKCgoaG9sZCAmIDB4ZmYpLypCSVRTKDgpKi8gPDwgOCkgKyAoaG9sZCA+PiA4KSkgJSAzMSkge1xuICAgICAgICAgIHN0cm0ubXNnID0gJ2luY29ycmVjdCBoZWFkZXIgY2hlY2snO1xuICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKChob2xkICYgMHgwZikvKkJJVFMoNCkqLyAhPT0gWl9ERUZMQVRFRCkge1xuICAgICAgICAgIHN0cm0ubXNnID0gJ3Vua25vd24gY29tcHJlc3Npb24gbWV0aG9kJztcbiAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIC8vLS0tIERST1BCSVRTKDQpIC0tLS8vXG4gICAgICAgIGhvbGQgPj4+PSA0O1xuICAgICAgICBiaXRzIC09IDQ7XG4gICAgICAgIC8vLS0tLy9cbiAgICAgICAgbGVuID0gKGhvbGQgJiAweDBmKS8qQklUUyg0KSovICsgODtcbiAgICAgICAgaWYgKHN0YXRlLndiaXRzID09PSAwKSB7XG4gICAgICAgICAgc3RhdGUud2JpdHMgPSBsZW47XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAobGVuID4gc3Rhd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s7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMHhlMDAwKSB7XG4gICAgICAgICAgc3RybS5tc2cgPSAndW5rbm93biBoZWFkZXIgZmxhZ3Mgc2V0JztcbiAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7XG4gICAgICAgICAgc3RhdGUuaGVhZC50ZXh0ID0gKChob2xkID4+IDgpICYgMSk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMHgwMjAwKSB7XG4gICAgICAgICAgLy89PT0gQ1JDMihzdGF0ZS5jaGVjaywgaG9sZCk7XG4gICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAweGZmO1xuICAgICAgICAgIGhidWZbMV0gPSAoaG9sZCA+Pj4gOCkgJiAweGZmO1xuICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApO1xuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgfVxuICAgICAgICAvLz09PSBJTklUQklUUygpO1xuICAgICAgICBob2xkID0gMDtcbiAgICAgICAgYml0cyA9IDA7XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgc3RhdGUubW9kZSA9IFRJTUU7XG4gICAgICAgIC8qIGZhbGxzIHRocm91Z2ggKi9cbiAgICAgIGNhc2UgVElNRTpcbiAgICAgICAgLy89PT0gTkVFREJJVFMoMzIpOyAqL1xuICAgICAgICB3aGlsZSAoYml0cyA8IDMyKSB7XG4gICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzO1xuICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgfVxuICAgICAgICAvLz09PS8vXG4gICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7XG4gICAgICAgICAgc3RhdGUuaGVhZC50aW1lID0gaG9sZDtcbiAgICAgICAgfVxuICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAweDAyMDApIHtcbiAgICAgICAgICAvLz09PSBDUkM0KHN0YXRlLmNoZWNrLCBob2xkKVxuICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMHhmZjtcbiAgICAgICAgICBoYnVmWzFdID0gKGhvbGQgPj4+IDgpICYgMHhmZjtcbiAgICAgICAgICBoYnVmWzJdID0gKGhvbGQgPj4+IDE2KSAmIDB4ZmY7XG4gICAgICAgICAgaGJ1ZlszXSA9IChob2xkID4+PiAyNCkgJiAweGZmO1xuICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDQsIDApO1xuICAgICAgICAgIC8vPT09XG4gICAgICAgIH1cbiAgICAgICAgLy89PT0gSU5JVEJJVFMoKTtcbiAgICAgICAgaG9sZCA9IDA7XG4gICAgICAgIGJpdHMgPSAwO1xuICAgICAgICAvLz09PS8vXG4gICAgICAgIHN0YXRlLm1vZGUgPSBPUztcbiAgICAgICAgLyogZmFsbHMgdGhyb3VnaCAqL1xuICAgICAgY2FzZSBPUzpcbiAgICAgICAgLy89PT0gTkVFREJJVFMoMTYpOyAqL1xuICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7XG4gICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzO1xuICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgfVxuICAgICAgICAvLz09PS8vXG4gICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7XG4gICAgICAgICAgc3RhdGUuaGVhZC54ZmxhZ3MgPSAoaG9sZCAmIDB4ZmYpO1xuICAgICAgICAgIHN0YXRlLmhlYWQub3MgPSAoaG9sZCA+PiA4KTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAweDAyMDApIHtcbiAgICAgICAgICAvLz09PSBDUkMyKHN0YXRlLmNoZWNrLCBob2xkKTtcbiAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDB4ZmY7XG4gICAgICAgICAgaGJ1ZlsxXSA9IChob2xkID4+PiA4KSAmIDB4ZmY7XG4gICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7XG4gICAgICAgICAgLy89PT0vL1xuICAgICAgICB9XG4gICAgICAgIC8vPT09IElOSVRCSVRTKCk7XG4gICAgICAgIGhvbGQgPSAwO1xuICAgICAgICBiaXRzID0gMDtcbiAgICAgICAgLy89PT0vL1xuICAgICAgICBzdGF0ZS5tb2RlID0gRVhMRU47XG4gICAgICAgIC8qIGZhbGxzIHRocm91Z2ggKi9cbiAgICAgIGNhc2UgRVhMRU46XG4gICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDB4MDQwMCkge1xuICAgICAgICAgIC8vPT09IE5FRURCSVRTKDE2KTsgKi9cbiAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7XG4gICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICAgIGhhdmUtLTtcbiAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzO1xuICAgICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgIH1cbiAgICAgICAgICAvLz09PS8vXG4gICAgICAgICAgc3RhdGUubGVuZ3RoID0gaG9sZDtcbiAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkge1xuICAgICAgICAgICAgc3RhdGUuaGVhZC5leHRyYV9sZW4gPSBob2xkO1xuICA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W9yZSBjb252ZW5pZW50IHByb2Nlc3NpbmcgbGF0ZXJcbiAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhID0gbmV3IEFycmF5KHN0YXRlLmhlYWQuZXh0cmFfbGVuKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB1dGlscy5hcnJheVNldChcbiAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhLFxuICAgICAgICAgICAgICAgIGlucHV0LFxuICAgICAgICAgICAgICAgIG5leHQsXG4gICAgICAgICAgICAgICAgLy8gZXh0cmEgZmllbGQgaXMgbGltaXRlZCB0byA2NTUzNiBieXRlc1xuICAgICAgICAgICAgICAgIC8vIC0gbm8gbmVlZCBmb3IgYWRkaXRpb25hbCBzaXplIGNoZWNrXG4gICAgICAgICAgICAgICAgY29weSxcbiAgICAgICAgICAgICAgICAvKmxlbiArIGNvcHkgPiBzdGF0ZS5oZWFkLmV4dHJhX21heCAtIGxlbiA/IHN0YXRlLmhlYWQuZXh0cmFfbWF4IDogY29weSwqL1xuICAgICAgICAgICAgICAgIGxlblxuICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgICAvL3ptZW1jcHkoc3RhdGUuaGVhZC5leHRyYSArIGxlbiwgbmV4dCxcbiAgICAgICAgICAgICAgLy8gICAgICAgIGxlbiArIGNvcHkgPiBzdGF0ZS5oZWFkLmV4dHJhX21heCA/XG4gICAgICAgICAgICAgIC8vICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhX21heCAtIGxlbiA6IGNvcHkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMHgwMjAwKSB7XG4gICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGhhdmUgLT0gY29weTtcbiAgICAgICAgICAgIG5leHQgKz0gY29weT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ucHV0LCBjb3B5LCBuZXh0KTtcbiAgICAgICAgICB9XG4gICAgICAgICAgaGF2ZSAtPSBjb3B5O1xuICAgICAgICAgIG5leHQgKz0gY29weTtcbiAgICAgICAgICBpZiAobGVuKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICB9XG4gICAgICAgIGVsc2UgaWYgKHN0YXRlLmhlYWQpIHtcbiAgICAgICAgICBzdGF0ZS5oZWFkLmNvbW1lbnQgPSBudWxsO1xuICAgICAgICB9XG4gICAgICAgIHN0YXRlLm1vZGUgPSBIQ1JDO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIEhDUkM6XG4gICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDB4MDIwMCkge1xuICAgICAgICAgIC8vPT09IE5FRURCSVRTKDE2KTsgKi9cbiAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7XG4gICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICAgIGhhdmUtLTtcbiAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzO1xuICAgICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgIH1cbiAgICAgICAgICAvLz09PS8vXG4gICAgICAgICAgaWYgKGhvbGQgIT09IChzdGF0ZS5jaGVjayAmIDB4ZmZmZikpIHtcbiAgICAgICAgICAgIHN0cm0ubXNnID0gJ2hlYWRlciBjcmMgbWlzbWF0Y2gnO1xuICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIH1cbiAgICAgICAgICAvLz09PSBJTklUQklUUygpO1xuICAgICAgICAgIGhvbGQgPSAwO1xuICAgICAgICAgIGJpdHMgPSAwO1xuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgfVxuICAgICAgICBpZiAoc3RhdGUuaGVhZCkge1xuICAgICAgICAgIHN0YXRlLmhlYWQuaGNyYyA9ICgoc3RhdGUuZmxhZ3MgPj4gOSkgJiAxKTtcbiAgICAgICAgICBzdGF0ZS5oZWFkLmRvbmUgPSB0cnVlO1xuICAgICAgICB9XG4gICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDA7XG4gICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFO1xuICAgICAgICBicmVhaztcbiAgICAgIGNhc2UgRElDVElEOlxuICAgICAgICAvLz09PSBORUVEQklUUygzMik7ICovXG4gICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHtcbiAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICB9XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0genN3YXAzMihob2xkKTtcbiAgICAgICAgLy89PT0gSU5JVEJJVFMoKTtcbiAgICAgICAgaG9sZCA9IDA7XG4gICAgICAgIGJpdHMgPSAwO1xuICAgICAgICAvLz09PS8vXG4gICAgICAgIHN0YXRlLm1vZGUgPSBESUNUO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIERJQ1Q6XG4gICAgICAgIGlmIChzdGF0ZS5oYXZlZGljdCA9PT0gMCkge1xuICAgICAgICAgIC8vLS0tIFJFU1RPUkUoKSAtLS1cbiAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0O1xuICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gbGVmdDtcbiAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0O1xuICAgICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlO1xuICAgICAgICAgIHN0YXRlLmhvb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ST1BCSVRTKDEpIC0tLS8vXG4gICAgICAgIGhvbGQgPj4+PSAxO1xuICAgICAgICBiaXRzIC09IDE7XG4gICAgICAgIC8vLS0tLy9cblxuICAgICAgICBzd2l0Y2ggKChob2xkICYgMHgwMykvKkJJVFMoMikqLykge1xuICAgICAgICAgIGNhc2UgMDogICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIHN0b3JlZCBibG9jayAqL1xuICAgICAgICAgICAgLy9UcmFjZXYoKHN0ZGVyciwgXCJpbmZsYXRlOiAgICAgc3RvcmVkIGJsb2NrJXNcXG5cIixcbiAgICAgICAgICAgIC8vICAgICAgICBzdGF0ZS5sYXN0ID8gXCIgKGxhc3QpXCIgOiBcIlwiKSk7XG4gICAgICAgICAgICBzdGF0ZS5tb2RlID0gU1RPUkVEO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAxOiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLyogZml4ZWQgYmxvY2sgKi9cbiAgICAgICAgICAgIGZpeGVkdGFibGVzKHN0YXRlKTtcbiAgICAgICAgICAgIC8vVHJhY2V2KChzdGRlcnIsIFwiaW5mbGF0ZTogICAgIGZpeGVkIGNvZGVzIGJsb2NrJXNcXG5cIixcbiAgICAgICAgICAgIC8vICAgICAgICBzdGF0ZS5sYXN0ID8gXCIgKGxhc3QpXCIgOiBcIlwiKSk7XG4gICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsgICAgICAgICAgICAgLyogZGVjb2RlIGNvZGVzICovXG4gICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHtcbiAgICAgICAgICAgICAgLy8tLS0gRFJPUEJJVFMoMikgLS0tLy9cbiAgICAgICAgICAgICAgaG9sZCA+Pj49IDI7XG4gICAgICAgICAgICAgIGJpdHMgLT0gMjtcbiAgICAgICAgICAgICAgLy8tLS0vL1xuICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlIDI6ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBkeW5hbWljIGJsb2NrICovXG4gICAgICAgICAgICAvL1RyYWNldigoc3RkZXJyLCBcImluZmxhdGU6ICAgICBkeW5hbWljIGNvZGVzIGJsb2NrJXNcXG5cIixcbiAgICAgICAgICAgIC8vICAgICAgICBzdGF0ZS5sYXN0ID8gXCIgKGxhc3QpXCIgOiBcIlwiKSk7XG4gICAgICAgICAgICBzdGF0ZS5tb2RlID0gVEFCTEU7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlIDM6XG4gICAgICAgICAgICBzdHJtLm1zZyA9ICdpbnZhbGlkIGJsb2NrIHR5cGUnO1xuICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgfVxuICAgICAgICAvLy0tLSBEUk9QQklUUygyKSAtLS0vL1xuICAgICAgICBob2xkID4+Pj0gMjtcbiAgICAgICAgYml0cyAtPSAyO1xuICAgICAgICAvLy0tLS8vXG4gICAgICAgIGJyZWFrO1xuICAgICAgY2FzZSBTVE9SRUQ6XG4gICAgICAgIC8vLS0tIEJZVEVCSVRTKCkgLS0tLy8gLyogZ28gdG8gYnl0ZSBib3VuZGFyeSAqL1xuICAgICAgICBob2xkID4+Pj0gYml0cyAmIDc7XG4gICAgICAgIGJpdHMgLT0gYml0cyAmIDc7XG4gICAgICAgIC8vLS0tLy9cbiAgICAgICAgLy89PT0gTkVFREJJVFMoMzIpOyAqL1xuICAgICAgICB3aGlsZSAoYml0cyA8IDMyKSB7XG4gICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzO1xuICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgfVxuICAgICAgICAvLz09PS8vXG4g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4+Pj0gaGVyZV9iaXRzO1xuICAgICAgICAgICAgYml0cyAtPSBoZXJlX2JpdHM7XG4gICAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBoZXJlX3ZhbDtcbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICBpZiAoaGVyZV92YWwgPT09IDE2KSB7XG4gICAgICAgICAgICAgIC8vPT09IE5FRURCSVRTKGhlcmUuYml0cyArIDIpO1xuICAgICAgICAgICAgICBuID0gaGVyZV9iaXRzICsgMjtcbiAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7XG4gICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzO1xuICAgICAgICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAvLz09PS8vXG4gICAgICAgICAgICAgIC8vLS0tIERST1BCSVRTKGhlcmUuYml0cykgLS0tLy9cbiAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0cztcbiAgICAgICAgICAgICAgYml0cyAtPSBoZXJlX2JpdHM7XG4gICAgICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICAgICAgaWYgKHN0YXRlLmhhdmUgPT09IDApIHtcbiAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICdpbnZhbGlkIGJpdCBsZW5ndGggcmVwZWF0JztcbiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSAtIDFdO1xuICAgICAgICAgICAgICBjb3B5ID0gMyArIChob2xkICYgMHgwMyk7Ly9CSVRTKDIpO1xuICAgICAgICAgICAgICAvLy0tLSBEUk9QQklUUygyKSAtLS0vL1xuICAgICAgICAgICAgICBob2xkID4+Pj0gMjtcbiAgICAgICAgICAgICAgYml0cyAtPSAyO1xuICAgICAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIGlmIChoZXJlX3ZhbCA9PT0gMTcpIHtcbiAgICAgICAgICAgICAgLy89PT0gTkVFREJJVFMoaGVyZS5iaXRzICsgMyk7XG4gICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAzO1xuICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHtcbiAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICAgICAgLy8tLS0gRFJPUEJJVFMoaGVyZS5iaXRzKSAtLS0vL1xuICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzO1xuICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0cztcbiAgICAgICAgICAgICAgLy8tLS0vL1xuICAgICAgICAgICAgICBsZW4gPSAwO1xuICAgICAgICAgICAgICBjb3B5ID0gMyArIChob2xkICYgMHgwNyk7Ly9CSVRTKDMpO1xuICAgICAgICAgICAgICAvLy0tLSBEUk9QQklUUygzKSAtLS0vL1xuICAgICAgICAgICAgICBob2xkID4+Pj0gMztcbiAgICAgICAgICAgICAgYml0cyAtPSAzO1xuICAgICAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgLy89PT0gTkVFREJJVFMoaGVyZS5iaXRzICsgNyk7XG4gICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyA3O1xuICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHtcbiAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICAgICAgLy8tLS0gRFJPUEJJVFMoaGVyZS5iaXRzKSAtLS0vL1xuICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzO1xuICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0cztcbiAgICAgICAgICAgICAgLy8tLS0vL1xuICAgICAgICAgICAgICBsZW4gPSAwO1xuICAgICAgICAgICAgICBjb3B5ID0gMTEgKyAoaG9sZCAmIDB4N2YpOy8vQklUUyg3KTtcbiAgICAgICAgICAgICAgLy8tLS0gRFJPUEJJVFMoNykgLS0tLy9cbiAgICAgICAgICAgICAgaG9sZCA+Pj49IDc7XG4gICAgICAgICAgICAgIGJpdHMgLT0gNztcbiAgICAgICAgICAgICAgLy8tLS0vL1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHN0YXRlLmhhdmUgKyBjb3B5ID4gc3RhdGUubmxlbiArIHN0YXRlLm5kaXN0KSB7XG4gICAgICAgICAgICAgIHN0cm0ubXNnID0gJ2ludmFsaWQgYml0IGxlbmd0aCByZXBlYXQnO1xuICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHdoaWxlIChjb3B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A9IHN0YXRlLm5leHQ7XG5cbiAgICAgICAgaWYgKHJldCkge1xuICAgICAgICAgIHN0cm0ubXNnID0gJ2ludmFsaWQgZGlzdGFuY2VzIHNldCc7XG4gICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICAvL1RyYWNldigoc3RkZXJyLCAnaW5mbGF0ZTogICAgICAgY29kZXMgb2tcXG4nKSk7XG4gICAgICAgIHN0YXRlLm1vZGUgPSBMRU5fO1xuICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgIC8qIGZhbGxzIHRocm91Z2ggKi9cbiAgICAgIGNhc2UgTEVOXzpcbiAgICAgICAgc3RhdGUubW9kZSA9IExFTjtcbiAgICAgICAgLyogZmFsbHMgdGhyb3VnaCAqL1xuICAgICAgY2FzZSBMRU46XG4gICAgICAgIGlmIChoYXZlID49IDYgJiYgbGVmdCA+PSAyNTgpIHtcbiAgICAgICAgICAvLy0tLSBSRVNUT1JFKCkgLS0tXG4gICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDtcbiAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7XG4gICAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDtcbiAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTtcbiAgICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDtcbiAgICAgICAgICBzdGF0ZS5iaXRzID0gYml0cztcbiAgICAgICAgICAvLy0tLVxuICAgICAgICAgIGluZmxhdGVfZmFzdChzdHJtLCBfb3V0KTtcbiAgICAgICAgICAvLy0tLSBMT0FEKCkgLS0tXG4gICAgICAgICAgcHV0ID0gc3RybS5uZXh0X291dDtcbiAgICAgICAgICBvdXRwdXQgPSBzdHJtLm91dHB1dDtcbiAgICAgICAgICBsZWZ0ID0gc3RybS5hdmFpbF9vdXQ7XG4gIC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9iaXRzID0gaGVyZV9iaXRzO1xuICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wO1xuICAgICAgICAgIGxhc3RfdmFsID0gaGVyZV92YWw7XG4gICAgICAgICAgZm9yICg7Oykge1xuICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbbGFzdF92YWwgK1xuICAgICAgICAgICAgICAgICAgICAoKGhvbGQgJiAoKDEgPDwgKGxhc3RfYml0cyArIGxhc3Rfb3ApKSAtIDEpKS8qQklUUyhsYXN0LmJpdHMgKyBsYXN0Lm9wKSovID4+IGxhc3RfYml0cyldO1xuICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7XG4gICAgICAgICAgICBoZXJlX29wID0gKGhlcmUgPj4+IDE2KSAmIDB4ZmY7XG4gICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiAweGZmZmY7XG5cbiAgICAgICAgICAgIGlmICgobGFzdF9iaXRzICsgaGVyZV9iaXRzKSA8PSBiaXRzKSB7IGJyZWFrOyB9XG4gICAgICAgICAgICAvLy0tLSBQVUxMQllURSgpIC0tLS8vXG4gICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICAgIGhhdmUtLTtcbiAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzO1xuICAgICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgICAgLy8tLS0vL1xuICAgICAgICAgIH1cbiAgICAgICAgICAvLy0tLSBEUk9QQklUUyhsYXN0LmJpdHMpIC0tLS8vXG4gICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0cztcbiAgICAgICAgICBiaXRzIC09IGxhc3RfYml0cztcbiAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgc3RhdGUuYmFjayArPSBsYXN0X2JpdHM7XG4gICAgICAgIH1cbiAgICAgICAgLy8tLS0gRFJPUEJJVFMoaGVyZS5iaXRzKSAtLS0vL1xuICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzO1xuICAgICAgICBiaXRzIC09IGhlcmVfYml0cztcbiAgICAgICAgLy8tLS0vL1xuICAgICAgICBzdGF0ZS5iYWNrICs9IGhlcmVfYml0cztcbiAgICAgICAgc3RhdGUubGVuZ3RoID0gaGVyZV92YWw7XG4gICAgICAgIGlmIChoZXJlX29wID09PSAwKSB7XG4gICAgICAgICAgLy9UcmFjZXZ2KChzdGRlcnIsIGhlcmUudmFsID49IDB4MjAgJiYgaGVyZS52YWwgPCAweDdmID9cbiAgICAgICAgICAvLyAgICAgICAgXCJpbmZsYXRlOiAgICAgICAgIGxpdGVyYWwgJyVjJ1xcblwiIDpcbiAgICAgICAgICAvLyAgICAgICAgXCJpbmZsYXRlOiAgICAgICAgIGxpdGVyYWwgMHglMDJ4XFxuXCIsIGhlcmUudmFsKSk7XG4gICAgICAgICAgc3RhdGUubW9kZSA9IExJVDtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICBpZiAoaGVyZV9vcCAmIDMyKSB7XG4gICAgICAgICAgLy9UcmFjZXZ2KChzdGRlcnIsIFwiaW5mbGF0ZTogICAgICAgICBlbmQgb2YgYmxvY2tcXG5cIikpO1xuICAgICAgICAgIHN0YXRlLmJhY2sgPSAtMTtcbiAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7XG4gICAgICAgICAgc3RybS5tc2cgPSAnaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlJztcbiAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIHN0YXRlLmV4dHJhID0gaGVyZV9vcCAmIDE1O1xuICAgICAgICBzdGF0ZS5tb2RlID0gTEVORVhUO1xuICAgICAgICAvKi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DB4ZmZmZjtcblxuICAgICAgICAgICAgaWYgKChsYXN0X2JpdHMgKyBoZXJlX2JpdHMpIDw9IGJpdHMpIHsgYnJlYWs7IH1cbiAgICAgICAgICAgIC8vLS0tIFBVTExCWVRFKCkgLS0tLy9cbiAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgfVxuICAgICAgICAgIC8vLS0tIERST1BCSVRTKGxhc3QuYml0cykgLS0tLy9cbiAgICAgICAgICBob2xkID4+Pj0gbGFzdF9iaXRzO1xuICAgICAgICAgIGJpdHMgLT0gbGFzdF9iaXRzO1xuICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICBzdGF0ZS5iYWNrICs9IGxhc3RfYml0cztcbiAgICAgICAgfVxuICAgICAgICAvLy0tLSBEUk9QQklUUyhoZXJlLmJpdHMpIC0tLS8vXG4gICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7XG4gICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzO1xuICAgICAgICAvLy0tLS8vXG4gICAgICAgIHN0YXRlLmJhY2sgKz0gaGVyZV9iaXRzO1xuICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7XG4gICAgICAgICAgc3RybS5tc2cgPSAnaW52YWxpZCBkaXN0YW5jZSBjb2RlJztcbiAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIHN0YXRlLm9mZnNldCA9IGhlcmVfdmFsO1xuICAgICAgICBzdGF0ZS5leHRyYSA9IChoZXJlX29wKSAmIDE1O1xuICAgICAgICBzdGF0ZS5tb2RlID0gRElTVEVYVDtcbiAgICAgICAgLyogZmFsbHMgdGhyb3VnaCAqL1xuICAgICAgY2FzZSBESVNURVhUOlxuICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHtcbiAgICAgICAgICAvLz09PSBORUVEQklUUyhzdGF0ZS5leHRyYSk7XG4gICAgICAgICAgbiA9IHN0YXRlLmV4dHJhO1xuICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikge1xuICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgICB9XG4gICAgICAgICAgLy89PT0vL1xuICAgICAgICAgIHN0YXRlLm9mZnNldCArPSBob2xkICYgKCgxIDw8IHN0YXRlLmV4dHJhKSAtIDEpLypCSVRTKHN0YXRlLmV4dHJhKSovO1xuICAgICAgICAgIC8vLS0tIERST1BCSVRTKHN0YXRlLmV4dHJhKSAtLS0vL1xuICAgICAgICAgIGhvbGQgPj4+PSBzdGF0ZS5leHRyYTtcbiAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhO1xuICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhO1xuICAgICAgICB9XG4vLyNpZmRlZiBJTkZMQVRFX1NUUklDVFxuICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gc3RhdGUuZG1heCkge1xuICAgICAgICAgIHN0cm0ubXNnID0gJ2ludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrJztcbiAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4vLyNlbmRpZlxuICAgICAgICAvL1RyYWNldnYoKHN0ZGVyciwgXCJpbmZsYXRlOiAgICAgICAgIGRpc3RhbmNlICV1XFxuXCIsI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gIGxlZnQgLT0gY29weTtcbi8vICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5O1xuLy8gICAgICAgICAgZG8ge1xuLy8gICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gMDtcbi8vICAgICAgICAgIH0gd2hpbGUgKC0tY29weSk7XG4vLyAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoID09PSAwKSB7IHN0YXRlLm1vZGUgPSBMRU47IH1cbi8vICAgICAgICAgIGJyZWFrO1xuLy8jZW5kaWZcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS53bmV4dCkge1xuICAgICAgICAgICAgY29weSAtPSBzdGF0ZS53bmV4dDtcbiAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53c2l6ZSAtIGNvcHk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgZnJvbSA9IHN0YXRlLnduZXh0IC0gY29weTtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS5sZW5ndGgpIHsgY29weSA9IHN0YXRlLmxlbmd0aDsgfVxuICAgICAgICAgIGZyb21fc291cmNlID0gc3RhdGUud2luZG93O1xuICAgICAgICB9XG4gICAgICAgIGVsc2UgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIGNvcHkgZnJvbSBvdXRwdXQgKi9cbiAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDtcbiAgICAgICAgICBmcm9tID0gcHV0IC0gc3RhdGUub2Zmc2V0O1xuICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGNvcHkgPiBsZWZ0KSB7IGNvcHkgPSBsZWZ0OyB9XG4gICAgICAgIGxlZnQgLT0gY29weTtcbiAgICAgICAgc3RhdGUubGVuZ3RoIC09IGNvcHk7XG4gICAgICAgIGRvIHtcbiAgICAgICAgICBvdXRwdXRbcHV0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTtcbiAgICAgICAgfSB3aGlsZSAoLS1jb3B5KTtcbiAgICAgICAgaWYgKHN0YXRlLmxlbmd0aCA9PT0gMCkgeyBzdGF0ZS5tb2RlID0gTEVOOyB9XG4gICAgICAgIGJyZWFrO1xuICAgICAgY2FzZSBMSVQ6XG4gICAgICAgIGlmIChsZWZ0ID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICBvdXRwdXRbcHV0KytdID0gc3RhdGUubGVuZ3RoO1xuICAgICAgICBsZWZ0LS07XG4gICAgICAgIHN0YXRlLm1vZGUgPSBMRU47XG4gICAgICAgIGJyZWFrO1xuICAgICAgY2FzZSBDSEVDSzpcbiAgICAgICAgaWYgKHN0YXRlLndyYXApIHtcbiAgICAgICAgICAvLz09PSBORUVEQklUUygzMik7XG4gICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikge1xuICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgICAvLyBVc2UgJ3wnIGluc3RlYWQgb2YgJysnIHRvIG1ha2Ugc3VyZSB0aGF0IHJlc3VsdCBpcyBzaWduZWRcbiAgICAgICAgICAgIGhvbGQgfD0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzO1xuICAgICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgIH1cbiAgICAgICAgICAvLz09PS8vXG4gICAgICAgICAgX291dCAtPSBsZWZ0O1xuICAgICAgICAgIHN0cm0udG90YWxfb3V0ICs9IF9vdXQ7XG4gICAgICAgICAgc3RhdGUudG90YWwgKz0gX291dDtcbiAgICAgICAgICBpZiAoX291dCkge1xuICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID1cbiAgICAgICAgICAgICAgICAvKlVQREFURShzdGF0ZS5jaGVjaywgcHV0IC0gX291dCwgX291dCk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VxuICAgICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICBpZiAoaG9sZCAhPT0gKHN0YXRlLnRvdGFsICYgMHhmZmZmZmZmZikpIHtcbiAgICAgICAgICAgIHN0cm0ubXNnID0gJ2luY29ycmVjdCBsZW5ndGggY2hlY2snO1xuICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIH1cbiAgICAgICAgICAvLz09PSBJTklUQklUUygpO1xuICAgICAgICAgIGhvbGQgPSAwO1xuICAgICAgICAgIGJpdHMgPSAwO1xuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICAvL1RyYWNldigoc3RkZXJyLCBcImluZmxhdGU6ICAgbGVuZ3RoIG1hdGNoZXMgdHJhaWxlclxcblwiKSk7XG4gICAgICAgIH1cbiAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7XG4gICAgICAgIC8qIGZhbGxzIHRocm91Z2ggKi9cbiAgICAgIGNhc2UgRE9ORTpcbiAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EO1xuICAgICAgICBicmVhayBpbmZfbGVhdmU7XG4gICAgICBjYXNlIEJBRDpcbiAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SO1xuICAgICAgICBicmVhayBpbmZfbGVhdmU7XG4gICAgICBjYXNlIE1FTTpcbiAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SO1xuICAgICAgY2FzZSBTWU5DOlxuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBkZWZhdWx0OlxuICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7XG4gICAgfVxuICB9XG5cbiAgLy8gaW5mX2xlYXZlIDwtIGhlcmUgaXMgcmVhbCB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HJhX2luZGV4IC09IDI1NztcbiAgICBlbmQgPSAyNTY7XG5cbiAgfSBlbHNlIHsgICAgICAgICAgICAgICAgICAgIC8qIERJU1RTICovXG4gICAgYmFzZSA9IGRiYXNlO1xuICAgIGV4dHJhID0gZGV4dDtcbiAgICBlbmQgPSAtMTtcbiAgfVxuXG4gIC8qIGluaXRpYWxpemUgb3B0cyBmb3IgbG9vcCAqL1xuICBodWZmID0gMDsgICAgICAgICAgICAgICAgICAgLyogc3RhcnRpbmcgY29kZSAqL1xuICBzeW0gPSAwOyAgICAgICAgICAgICAgICAgICAgLyogc3RhcnRpbmcgY29kZSBzeW1ib2wgKi9cbiAgbGVuID0gbWluOyAgICAgICAgICAgICAgICAgIC8qIHN0YXJ0aW5nIGNvZGUgbGVuZ3RoICovXG4gIG5leHQgPSB0YWJsZV9pbmRleDsgICAgICAgICAgICAgIC8qIGN1cnJlbnQgdGFibGUgdG8gZmlsbCBpbiAqL1xuICBjdXJyID0gcm9vdDsgICAgICAgICAgICAgICAgLyogY3VycmVudCB0YWJsZSBpbmRleCBiaXRzICovXG4gIGRyb3AgPSAwOyAgICAgICAgICAgICAgICAgICAvKiBjdXJyZW50IGJpdHMgdG8gZHJvcCBmcm9tIGNvZGUgZm9yIGluZGV4ICovXG4gIGxvdyA9IC0xOyAgICAgICAgICAgICAgICAgICAvKiB0cmlnZ2VyIG5ldyBzdWItdGFibGUgd2hlbiBsZW4gPiByb290ICovXG4gIHVzZWQgPSAxIDw8IHJvb3Q7ICAgICAgICAgIC8qIHVzZSByb290IHRhYmxlIGVudHJpZXMgKi9cbiAgbWFzayA9IHVzZWQgLSAxOyAgICAgICAgICAgIC8qIG1hc2sgZm9yIGNvbXBhcmluZyBsb3cgKi9cblxuICAvKiBjaGVjayBhdmFpbGFibGUgdGFibGUgc3BhY2UgKi9cbiAgaWYgKCh0eXBlID09PSBMRU5TICYmIHVzZWQgPiBFTk9VR0hfTEVOUykgfHxcbiAgICAodHlwZSA9PT0gRElTVFMgJ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uLy92YXIgWl9STEUgICAgICAgICAgICAgICA9IDM7XG52YXIgWl9GSVhFRCAgICAgICAgICAgICAgID0gNDtcbi8vdmFyIFpfREVGQVVMVF9TVFJBVEVHWSAgPSAwO1xuXG4vKiBQb3NzaWJsZSB2YWx1ZXMgb2YgdGhlIGRhdGFfdHlwZSBmaWVsZCAodGhvdWdoIHNlZSBpbmZsYXRlKCkpICovXG52YXIgWl9CSU5BUlkgICAgICAgICAgICAgID0gMDtcbnZhciBaX1RFWFQgICAgICAgICAgICAgICAgPSAxO1xuLy92YXIgWl9BU0NJSSAgICAgICAgICAgICA9IDE7IC8vID0gWl9URVhUXG52YXIgWl9VTktOT1dOICAgICAgICAgICAgID0gMjtcblxuLyo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ki9cblxuXG5mdW5jdGlvbiB6ZXJvKGJ1ZikgeyB2YXIgbGVuID0gYnVmLmxlbmd0aDsgd2hpbGUgKC0tbGVuID49IDApIHsgYnVmW2xlbl0gPSAwOyB9IH1cblxuLy8gRnJvbSB6dXRpbC5oXG5cbnZhciBTVE9SRURfQkxPQ0sgPSAwO1xudmFyIFNUQVRJQ19UUkVFUyA9IDE7XG52YXIgRFlOX1RSRUVTICAgID0gMjtcbi8qIFRoZSB0aHJlZSBraW5kcyBvZiBibG9jayB0eXBlICovXG5cbnZhciBNSU5fTUFUQ0ggICAgPSAzO1xudmFyIE1BWF9NQVRDSCAgICA9IDI1ODtcbi8qIFRoZSBtaW5pbXVtIGFuZCBtYXhpbXVtIG1hdGNoIGxlbmd0aHMgKi9cblxuLy8gRnJvbSBkZWZsYXRlLmhcbi8qID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PVxuICogSW50ZXJuYWwgY29tcHJlc3Npb24gc3RhdGUuXG4gKi9cblxudmFyIExFTkdUSF9DT0RFU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yZmxvdyA+IDApO1xuXG4gIC8qIE5vdyByZWNvbXB1dGUgYWxsIGJpdCBsZW5ndGhzLCBzY2FubmluZyBpbiBpbmNyZWFzaW5nIGZyZXF1ZW5jeS5cbiAgICogaCBpcyBzdGlsbCBlcXVhbCB0byBIRUFQX1NJWkUuIChJdCBpcyBzaW1wbGVyIHRvIHJlY29uc3RydWN0IGFsbFxuICAgKiBsZW5ndGhzIGluc3RlYWQgb2YgZml4aW5nIG9ubHkgdGhlIHdyb25nIG9uZXMuIFRoaXMgaWRlYSBpcyB0YWtlblxuICAgKiBmcm9tICdhcicgd3JpdHRlbiBieSBIYXJ1aGlrbyBPa3VtdXJhLilcbiAgICovXG4gIGZvciAoYml0cyA9IG1heF9sZW5ndGg7IGJpdHMgIT09IDA7IGJpdHMtLSkge1xuICAgIG4gPSBzLmJsX2NvdW50W2JpdHNdO1xuICAgIHdoaWxlIChuICE9PSAwKSB7XG4gICAgICBtID0gcy5oZWFwWy0taF07XG4gICAgICBpZiAobSA+IG1heF9jb2RlKSB7IGNvbnRpbnVlOyB9XG4gICAgICBpZiAodHJlZVttICogMiArIDFdLyouTGVuKi8gIT09IGJpdHMpIHtcbiAgICAgICAgLy8gVHJhY2UoKHN0ZGVycixcImNvZGUgJWQgYml0cyAlZC0+JWRcXG5cIiwgbSwgdHJlZVttXS5MZW4sIGJpdHMpKTtcbiAgICAgICAgcy5vcHRfbGVuICs9IChiaXRzIC0gdHJlZVttICogMiArIDFdLyouTGVuKi8pICogdHJlZVttICogMl0vKi5GcmVxKi87XG4gICAgICAgIHRyZWVbbSAqIDIgKyAxXS8qLkxlbiovID0gYml0cztcbiAgICAgIH1cbiAgICAgIG4tLTtcbiAgICB9XG4gIH1cbn1cblxuXG4vKiA9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT1cbiAqIEdlbmVyYXRlIHRoZSBjb2RlcyBmb3IgYSBnaXZlbiB0cm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ICAgLyogdGhlIHRyZWUgdG8gYmUgc2Nhbm5lZCAqL1xuLy8gICAgaW50IG1heF9jb2RlOyAgICAvKiBhbmQgaXRzIGxhcmdlc3QgY29kZSBvZiBub24gemVybyBmcmVxdWVuY3kgKi9cbntcbiAgdmFyIG47ICAgICAgICAgICAgICAgICAgICAgLyogaXRlcmF0ZXMgb3ZlciBhbGwgdHJlZSBlbGVtZW50cyAqL1xuICB2YXIgcHJldmxlbiA9IC0xOyAgICAgICAgICAvKiBsYXN0IGVtaXR0ZWQgbGVuZ3RoICovXG4gIHZhciBjdXJsZW47ICAgICAgICAgICAgICAgIC8qIGxlbmd0aCBvZiBjdXJyZW50IGNvZGUgKi9cblxuICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXS8qLkxlbiovOyAvKiBsZW5ndGggb2YgbmV4dCBjb2RlICovXG5cbiAgdmFyIGNvdW50ID0gMDsgICAgICAgICAgICAgLyogcmVwZWF0IGNvdW50IG9mIHRoZSBjdXJyZW50IGNvZGUgKi9cbiAgdmFyIG1heF9jb3VudCA9IDc7ICAgICAgICAgLyogbWF4IHJlcGVhdCBjb3VudCAqL1xuICB2YXIgbWluX2NvdW50ID0gNDsgICAgICAgICAvKiBtaW4gcmVwZWF0IGNvdW50ICovXG5cbiAgaWYgKG5leHRsZW4gPT09IDApIHtcbiAgICBtYXhfY291bnQgPSAxMzg7XG4gICAgbWluX2NvdW50ID0gMztcbiAgfVxuICB0cmVlWyhtYXhfY29kZSArIDEpICogMiArIDFdLyouTGVuKi8gPSAweGZmZmY7IC8qIGd1YXJkICovXG5cbiAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7XG4gICAgY3VybGVuID0gbmV4dGxlbjtcbiAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdLyouTGVuKi87XG5cbiAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHtcbiAgICAgIGNvbnRpbnVlO1xuXG4gICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkge1xuICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdLyouRnJlcSovICs9IGNvdW50O1xuXG4gICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHtcblxuICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgeyBzLmJsX3RyZWVbY3VybGVuICogMl0vKi5GcmVxKi8rKzsgfVxuICAgICAgcy5ibF90cmVlW1JFUF8zXzYgKiAyXS8qLkZyZXEqLysrO1xuXG4gICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkge1xuICAgICAgcy5ibF90cmVlW1JFUFpfM18xMCAqIDJdLyouRnJlcSovKys7XG5cbiAgICB9IGVsc2Uge1xuICAgICAgcy5ibF90cmVlW1JFUFpfMTFfMTM4ICogMl0vKi5GcmVxKi8rKztcbiAgICB9XG5cbiAgICBjb3VudCA9IDA7XG4gICAgcHJldmxlbiA9IGN1cmxlbjtcblxuICAgIGlmIChuZXh0bGVuID09PSAwKSB7XG4gICAgICBtYXhfY291bnQgPSAxMzg7XG4gICAgICBtaW5fY291bnQgPSAzO1xuXG4gICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHtcbiAgICAgIG1heF9jb3VudCA9IDY7XG4gICAgICBtaW5fY291bnQgPSAzO1xuXG4gICAgfSBlbHNlIHtcbiAgICAgIG1heF9jb3VudCA9IDc7XG4gICAgICBtaW5fY291bnQgPSA0O1xuICAgIH1cbiAgfVxufVxuXG5cbi8qID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PVxuICogU2VuZCBhIGxpdGVyYWwgb3IgZGlzdGFuY2UgdHJlZSBpbiBjb21wcmVzc2VkIGZvcm0sIHVzaW5nIHRoZSBjb2RlcyBpblxuICogYmxfdHJlZS5cbiAqL1xuZnVuY3Rpb24gc2VuZF90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bHNlIGlmIChwYXJ0c1tpXSA9PT0gaXNvU2VudGluZWwpIHtcbiAgICAgICAgICAgICAgICAgICAgY2hhcnNldCA9ICdpc28tODg1OS0xJztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgc2tpcEluZGV4ID0gaTtcbiAgICAgICAgICAgICAgICBpID0gcGFydHMubGVuZ3RoOyAvLyBUaGUgZXNsaW50IHNldHRpbmdzIGRvIG5vdCBhbGxvdyBicmVhaztcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGZvciAoaSA9IDA7IGkgPCBwYXJ0cy5sZW5ndGg7ICsraSkge1xuICAgICAgICBpZiAoaSA9PT0gc2tpcEluZGV4KSB7XG4gICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgcGFydCA9IHBhcnRzW2ldO1xuXG4gICAgICAgIHZhciBicmFja2V0RXF1YWxzUG9zID0gcGFydC5pbmRleE9mKCddPScpO1xuICAgICAgICB2YXIgcG9zID0gYnJhY2tldEVxdWFsc1BvcyA9PT0gLTEgPyBwYXJ0LmluZGV4T2YoJz0nKSA6IGJyYWNrZXRFcXVhbHNQb3MgKyAxO1xuXG4gICAgICAgIHZhciBrZXksIHZhbDtcbiAgICAgICAgaWYgKHBvcyA9PT0gLTEpIHtcbiAgICAgICAgICAgIGtleSA9IG9wdGlvbnMuZGVjb2RlcihwYXJ0LCBkZWZhdWx0cy5kZWNvZGVyLCBjaGFyc2V0LCAna2V5Jyk7XG4gICAgICAgICAgICB2YWwgPSBvcHRpb25zLnN0cmljdE51bGxIYW5kbGluZyA/IG51bGwgOiAnJztcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGtleSA9IG9wdGlvbnMuZGVjb2RlcihwYXJ0LnNsaWNlKDAsIHBvcyksIGRlZmF1bHRzLmRlY29kZXIsIGNoYXJzZXQsICdrZXknKTtcbiAgICAgICAgICAgIHZhbCA9IHV0aWxzLm1heWJlTWFwKFxuICAgICAgICAgICAgICAgIHBhcnNlQXJyYXlWYWx1ZShwYXJ0LnNsaWNlKHBvcyArIDEpLCBvcHRpb25zKSxcbiAgICAgICAgICAgICAgICBmdW5jdGlvbiAoZW5jb2RlZFZhbCkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gb3B0aW9ucy5kZWNvZGVyKGVuY29kZWRWYWwsIGRlZmF1bHRzLmRlY29kZXIsIGNoYXJzZXQsICd2YWx1ZScpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodmFsICYmIG9wdGlvbnMuaW50ZXJwcmV0TnVtZXJpY0VudGl0aWVzICYmIGNoYXJzZXQgPT09ICdpc28tODg1OS0xJykge1xuICAgICAgICAgICAgdmFsID0gaW50ZXJwcmV0TnVtZXJpY0VudGl0aWVzKHZhbCk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAocGFydC5pbmRleE9mKCdbXT0nKSA+IC0xKSB7XG4gICAgICAgICAgICB2YWwgPSBpc0FycmF5KHZhbCkgPyBbdmFsXSA6IHZhbDtcbiAgICAgICAgfVxuXG4gICAgICAgIHZhciBleGlzdGluZyA9IGhhcy5jYWxsKG9iaiwga2V5KTtcbiAgICAgICAgaWYgKGV4aXN0aW5nICYmIG9wdGlvbnMuZHVwbGljYXRlcyA9PT0gJ2NvbWJpbmUnKSB7XG4gICAgICAgICAgICBvYmpba2V5XSA9IHV0aWxzLmNvbWJpbmUob2JqW2tleV0sIHZhbCk7XG4gICAgICAgIH0gZWxzZSBpZiAoIWV4aXN0aW5nIHx8IG9wdGlvbnMuZHVwbGljYXRlcyA9PT0gJ2xhc3QnKSB7XG4gICAgICAgICAgICBvYmpba2V5XSA9IHZhbDtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiBvYmo7XG59O1xuXG52YXIgcGFyc2VPYmplY3QgPSBmdW5jdGlvbiAoY2hhaW4sIHZhbCwgb3B0aW9ucywgdmFsdWVzUGFyc2VkKSB7XG4gICAgdmFyIGxlYWYgPSB2YWx1ZXNQYXJzZWQgPyB2YWwgOiBwYXJzZUFycmF5VmFsdWUodmFsLCBvcHRpb25zKTtcblxuICAgIGZvciAodmFyIGkgPSBjaGFpbi5sZW5ndGggLSAxOyBpID49IDA7IC0taSkge1xuICAgICAgICB2YXIgb2JqO1xuICAgICAgICB2YXIgcm9vdCA9IGNoYWluW2ldO1xuXG4gICAgICAgIGlmIChyb290ID09PSAnW10nICYmIG9wdGlvbnMucGFyc2VBcnJheXMpIHtcbiAgICAgICAgICAgIG9iaiA9IG9wdGlvbnMuYWxsb3dFbXB0eUFycmF5cyAmJiAobGVhZiA9PT0gJycgfHwgKG9wdGlvbnMuc3RyaWN0TnVsbEhhbmRsaW5nICYmIGxlYWYgPT09IG51bGwpKVxuICAgICAgICAgICAgICAgID8gW11cbiAgICAgICAgICAgICAgICA6IFtdLmNvbmNhdChsZWFmKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIG9iaiA9IG9wdGlvbnMucGxhaW5PYmplY3RzID8gT2JqZWN0LmNyZWF0ZShudWxsKSA6IHt9O1xuICAgICAgICAgICAgdmFyIGNsZWFuUm9vdCA9IHJvb3QuY2hhckF0KDApID09PSAnWycgJiYgcm9vdC5jaGFyQXQocm9vdC5sZW5ndGggLSAxKSA9PT0gJ10nID8gcm9vdC5zbGljZSgxLCAtMSkgOiByb290O1xuICAgICAgICAgICAgdmFyIGRlY29kZWRSb290ID0gb3B0aW9ucy5kZWNvZGVEb3RJbktleXMgPyBjbGVhblJvb3QucmVwbGFjZSgvJTJFL2csICcuJykgOiBjbGVhblJvb3Q7XG4gICAgICAgICAgICB2YXIgaW5kZXggPSBwYXJzZUludChkZWNvZGVkUm9vdCwgMTApO1xuICAgICAgICAgICAgaWYgKCFvcHRpb25zLnBhcnNlQXJyYXlzICYmIGRlY29kZWRSb290ID09PSAnJykge1xuICAgICAgICAgICAgICAgIG9iaiA9IHsgMDogbGVhZiB9O1xuICAgICAgICAgICAgfSBlbHNlIGlmIChcbiAgICAgICAgICAgICAgICAhaXNOYU4oaW5kZXgpXG4gICAgICAgICAgICAgICAgJiYgcm9vdCAhPT0gZGVjb2RlZFJvb3RcbiAgICAgICAgICAgICAgICAmJiBTdHJpbmcoaW5kZXgpID09PSBkZWNvZGVkUm9vdFxuICAgICAgICAgICAgICAgICYmIGluZGV4ID49IDBcbiAgICAgICAgICAgICAgICAmJiAob3B0aW9ucy5wYXJzZUFycmF5cyAmJiBpbmRleCA8PSBvcHRpb25zLmFycmF5TGltaXQpXG4gICAgICAgICAgICApIHtcbiAgICAgICAgICAgICAgICBvYmogPSBbXTtcbiAgICAgICAgICAgICAgICBvYmpbaW5kZXhdID0gbGVhZjtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoZGVjb2RlZFJvb3QgIT09ICdfX3Byb3RvX18nKSB7XG4gICAgICAgICAgICAgICAgb2JqW2RlY29kZWRSb290XSA9IGxlYWY7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBsZWFmID0gb2JqO1xuICAgIH1cblxuICAgIHJldHVybiBsZWFmO1xufTtcblxudmFyIHBhcnNlS2V5cyA9IGZ1bmN0aW9uIHBhcnNlUXVlcnlTdHJpbmdLZXlzKGdpdmVuS2V5LCB2YWwsIG9wdGlvbnMsIHZhbHVlc1BhcnNlZCkge1xuICAgIGlmICghZ2l2ZW5LZXkpIHtcbiAgICAgICAgcmV0dXJuO1xuICAgIH1cblxuICAgIC8vIFRyYW5zZm9ybSBkb3Qgbm90YXRpb24gdG8gYnJhY2tldCBub3RhdGlvblxuICAgIHZhciBrZXkgPSBvcHRpb25zLmFsbG93RG90cyA/IGdpdmVuS2V5LnJlcGxhY2UoL1xcLihbXi5bXSspL2csICdbJDFdJykgOiBnaXZlbktleTtcblxuICAgIC8vIFRoZSByZWdleCBjaHVua3NcblxuICAgIHZhciBicmFja2V0cyA9IC8oXFxbW15bXFxdXSpdKS87X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ICAgICAgaWYgKHR5cGVvZiB0bXBTYy5nZXQoc2VudGluZWwpID09PSAndW5kZWZpbmVkJykge1xuICAgICAgICAgICAgc3RlcCA9IDA7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBpZiAodHlwZW9mIGZpbHRlciA9PT0gJ2Z1bmN0aW9uJykge1xuICAgICAgICBvYmogPSBmaWx0ZXIocHJlZml4LCBvYmopO1xuICAgIH0gZWxzZSBpZiAob2JqIGluc3RhbmNlb2YgRGF0ZSkge1xuICAgICAgICBvYmogPSBzZXJpYWxpemVEYXRlKG9iaik7XG4gICAgfSBlbHNlIGlmIChnZW5lcmF0ZUFycmF5UHJlZml4ID09PSAnY29tbWEnICYmIGlzQXJyYXkob2JqKSkge1xuICAgICAgICBvYmogPSB1dGlscy5tYXliZU1hcChvYmosIGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgaWYgKHZhbHVlIGluc3RhbmNlb2YgRGF0ZSkge1xuICAgICAgICAgICAgICAgIHJldHVybiBzZXJpYWxpemVEYXRlKHZhbHVlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgaWYgKG9iaiA9PT0gbnVsbCkge1xuICAgICAgICBpZiAoc3RyaWN0TnVsbEhhbmRsaW5nKSB7XG4gICAgICAgICAgICByZXR1cm4gZW5jb2RlciAmJiAhZW5jb2RlVmFsdWVzT25seSA/IGVuY29kZXIocHJlZml4LCBkZWZhdWx0cy5lbmNvZGVyLCBjaGFyc2V0LCAna2V5JywgZm9ybWF0KSA6IHByZWZpeDtcbiAgICAgICAgfVxuXG4gICAgICAgIG9iaiA9ICcnO1xuICAgIH1cblxuICAgIGlmIChpc05vbk51bGxpc2hQcmltaXRpdmUob2JqKSB8fCB1dGlscy5pc0J1ZmZlcihvYmopKSB7XG4gICAgICAgIGlmIChlbmNvZGVyKSB7XG4gICAgICAgICAgICB2YXIga2V5VmFsdW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ZW5jb2RlZEtleSkgOiBhZGp1c3RlZFByZWZpeFxuICAgICAgICAgICAgOiBhZGp1c3RlZFByZWZpeCArIChhbGxvd0RvdHMgPyAnLicgKyBlbmNvZGVkS2V5IDogJ1snICsgZW5jb2RlZEtleSArICddJyk7XG5cbiAgICAgICAgc2lkZUNoYW5uZWwuc2V0KG9iamVjdCwgc3RlcCk7XG4gICAgICAgIHZhciB2YWx1ZVNpZGVDaGFubmVsID0gZ2V0U2lkZUNoYW5uZWwoKTtcbiAgICAgICAgdmFsdWVTaWRlQ2hhbm5lbC5zZXQoc2VudGluZWwsIHNpZGVDaGFubmVsKTtcbiAgICAgICAgcHVzaFRvQXJyYXkodmFsdWVzLCBzdHJpbmdpZnkoXG4gICAgICAgICAgICB2YWx1ZSxcbiAgICAgICAgICAgIGtleVByZWZpeCxcbiAgICAgICAgICAgIGdlbmVyYXRlQXJyYXlQcmVmaXgsXG4gICAgICAgICAgICBjb21tYVJvdW5kVHJpcCxcbiAgICAgICAgICAgIGFsbG93RW1wdHlBcnJheXMsXG4gICAgICAgICAgICBzdHJpY3ROdWxsSGFuZGxpbmcsXG4gICAgICAgICAgICBza2lwTnVsbHMsXG4gICAgICAgICAgICBlbmNvZGVEb3RJbktleXMsXG4gICAgICAgICAgICBnZW5lcmF0ZUFycmF5UHJlZml4ID09PSAnY29tbWEnICYmIGVuY29kZVZhbHVlc09ubHkgJiYgaXNBcnJheShvYmopID8gbnVsbCA6IGVuY29kZXIsXG4gICAgICAgICAgICBmaWx0ZXIsXG4gICAgICAgICAgICBzb3J0LFxuICAgICAgICAgICAgYWxsb3dEb3RzLFxuICAgICAgICAgICAgc2VyaWFsaXplRGF0ZSxcbiAgICAgICAgICAgIGZvcm1hdCxcbiAgICAgICAgICAgIGZvcm1hdHRlcixcbiAgICAgICAgICAgIGVuY29kZVZhbHVlc09ubHksXG4gICAgICAgICAgICBjaGFyc2V0LFxuICAgICAgICAgICAgdmFsdWVTaWRlQ2hhbm5lbFxuICAgICAgIC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PT09IG51bGwpIHtcbiAgICAgICAgcmV0dXJuICcnO1xuICAgIH1cblxuICAgIHZhciBnZW5lcmF0ZUFycmF5UHJlZml4ID0gYXJyYXlQcmVmaXhHZW5lcmF0b3JzW29wdGlvbnMuYXJyYXlGb3JtYXRdO1xuICAgIHZhciBjb21tYVJvdW5kVHJpcCA9IGdlbmVyYXRlQXJyYXlQcmVmaXggPT09ICdjb21tYScgJiYgb3B0aW9ucy5jb21tYVJvdW5kVHJpcDtcblxuICAgIGlmICghb2JqS2V5cykge1xuICAgICAgICBvYmpLZXlzID0gT2JqZWN0LmtleXMob2JqKTtcbiAgICB9XG5cbiAgICBpZiAob3B0aW9ucy5zb3J0KSB7XG4gICAgICAgIG9iaktleXMuc29ydChvcHRpb25zLnNvcnQpO1xuICAgIH1cblxuICAgIHZhciBzaWRlQ2hhbm5lbCA9IGdldFNpZGVDaGFubmVsKCk7XG4gICAgZm9yICh2YXIgaSA9IDA7IGkgPCBvYmpLZXlzLmxlbmd0aDsgKytpKSB7XG4gICAgICAgIHZhciBrZXkgPSBvYmpLZXlzW2ldO1xuXG4gICAgICAgIGlmIChvcHRpb25zLnNraXBOdWxscyAmJiBvYmpba2V5XSA9PT0gbnVsbCkge1xuICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgIH1cbiAgICAgICAgcHVzaFRvQXJyYXkoa2V5cywgc3RyaW5naWZ5KFxuICAgICAgICAgICAgb2JqW2tleV0sXG4gICAgICAgICAgICBrZXksXG4gICAgICAgICAgICBnZW5lcmF0ZUFycmF5UHJlZml4LFxuICAgICAgICAgICAgY29tbWFSb3VuZFRyaXAsXG4gICAgICAgICAgICBvcHRpb25zLmFsbG93RW1wdHlBcnJheXMsXG4gICAgICAgICAgICBvcHRpb25zLnN0cmljdE51bGxIYW5kbGluZyxcbiAgICAgICAgICAgIG9wdGlvbnMuc2tpcE51bGxzLFxuICAgICAgICAgICAgb3B0aW9ucy5lbmNvZGVEb3RJbktleXMsXG4gICAgICAgICAgICBvcHRpb25zLmVuY29kZSA/IG9wdGlvbnMuZW5jb2RlciA6IG51bGwsXG4gICAgICAgICAgICBvcHRpb25zLmZpbHRlcixcbiAgICAgICAgICAgIG9wdGlvbnMuc29ydCxcbiAgICAgICAgICAgIG9wdGlvbnMuYWxsb3dEb3RzLFxuICAgICAgICAgICAgb3B0aW9ucy5zZXJpYWxpemVEYXRlLFxuICAgICAgICAgICAgb3B0aW9ucy5mb3JtYXQsXG4gICAgICAgICAgICBvcHRpb25zLmZvcm1hdHRlcixcbiAgICAgICAgICAgIG9wdGlvbnMuZW5jb2RlVmFsdWVzT25seSxcbiAgICAgICAgICAgIG9wdGlvbnMuY2hhcnNldCxcbiAgICAgICAgICAgIHNpZGVDaGFubmVsXG4gICAgICAgICkpO1xuICAgIH1cblxuICAgIHZhciBqb2luZWQgPSBrZXlzLmpvaW4ob3B0aW9ucy5kZWxpbWl0ZXIpO1xuICAgIHZhciBwcmVmaXggPSBvcHRpb25zLmFkZFF1ZXJ5UHJlZml4ID09PSB0cnVlID8gJz8nIDogJyc7XG5cbiAgICBpZiAob3B0aW9ucy5jaGFyc2V0U2VudGluZWwpIHtcbiAgICAgICAgaWYgKG9wdGlvbnMuY2hhcnNldCA9PT0gJ2lzby04ODU5LTEnKSB7XG4gICAgICAgICAgICAvLyBlbmNvZGVVUklDb21wb25lbnQoJyYjMTAwMDM7JyksIHRoZSBcIm51bWVyaWMgZW50aXR5XCIgcmVwcmVzZW50YXRpb24gb2YgYSBjaGVja21hcmtcbiAgICAgICAgICAgIHByZWZpeCArPSAndXRmOD0lMjYlMjMxMDAwMyUzQiYnO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgLy8gZW5jb2RlVVJJQ29tcG9uZW50KCfinJMnKVxuICAgICAgICAgICAgcHJlZml4ICs9ICd1dGY4PSVFMiU5QyU5MyYnO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgcmV0dXJuIGpvaW5lZC5sZW5ndGggPiAwID8gcHJlZml4ICsgam9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0YXJnZXQsIHNvdXJjZV07XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gdGFyZ2V0O1xuICAgIH1cblxuICAgIGlmICghdGFyZ2V0IHx8IHR5cGVvZiB0YXJnZXQgIT09ICdvYmplY3QnKSB7XG4gICAgICAgIHJldHVybiBbdGFyZ2V0XS5jb25jYXQoc291cmNlKTtcbiAgICB9XG5cbiAgICB2YXIgbWVyZ2VUYXJnZXQgPSB0YXJnZXQ7XG4gICAgaWYgKGlzQXJyYXkodGFyZ2V0KSAmJiAhaXNBcnJheShzb3VyY2UpKSB7XG4gICAgICAgIG1lcmdlVGFyZ2V0ID0gYXJyYXlUb09iamVjdCh0YXJnZXQsIG9wdGlvbnMpO1xuICAgIH1cblxuICAgIGlmIChpc0FycmF5KHRhcmdldCkgJiYgaXNBcnJheShzb3VyY2UpKSB7XG4gICAgICAgIHNvdXJjZS5mb3JFYWNoKGZ1bmN0aW9uIChpdGVtLCBpKSB7XG4gICAgICAgICAgICBpZiAoaGFzLmNhbGwodGFyZ2V0LCBpKSkge1xuICAgICAgICAgICAgICAgIHZhciB0YXJnZXRJdGVtID0gdGFyZ2V0W2ldO1xuICAgICAgICAgICAgICAgIGlmICh0YXJnZXRJdGVtICYmIHR5cGVvZiB0YXJnZXRJdGVtID09PSAnb2JqZWN0JyAmJiBpdGVtICYmIHR5cGVvZiBpdGVtID09PSAnb2JqZWN0Jykge1xuICAgICAgICAgICAgICAgICAgICB0YXJnZXRbaV0gPSBtZXJnZSh0YXJnZXRJdGVtLCBpdGVtLCBvcHRpb25zKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0YXJnZXQucHVzaChpdGVtKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRhcmdldFtpXSA9IGl0ZW07XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgICByZXR1cm4gdGFyZ2V0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NsaWNlKDIpLCAxNikgKyAnJTNCJztcbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgdmFyIG91dCA9ICcnO1xuICAgIGZvciAodmFyIGogPSAwOyBqIDwgc3RyaW5nLmxlbmd0aDsgaiArPSBsaW1pdCkge1xuICAgICAgICB2YXIgc2VnbWVudCA9IHN0cmluZy5sZW5ndGggPj0gbGltaXQgPyBzdHJpbmcuc2xpY2UoaiwgaiArIGxpbWl0KSA6IHN0cmluZztcbiAgICAgICAgdmFyIGFyciA9IFtdO1xuXG4gICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgc2VnbWVudC5sZW5ndGg7ICsraSkge1xuICAgICAgICAgICAgdmFyIGMgPSBzZWdtZW50LmNoYXJDb2RlQXQoaSk7XG4gICAgICAgICAgICBpZiAoXG4gICAgICAgICAgICAgICAgYyA9PT0gMHgyRCAvLyAtXG4gICAgICAgICAgICAgICAgfHwgYyA9PT0gMHgyRSAvLyAuXG4gICAgICAgICAgICAgICAgfHwgYyA9PT0gMHg1RiAvLyBfXG4gICAgICAgICAgICAgICAgfHwgYyA9PT0gMHg3RSAvLyB+XG4gICAgICAgICAgICAgICAgfHwgKGMgPj0gMHgzMCAmJiBjIDw9IDB4MzkpIC8vIDAtOVxuICAgICAgICAgICAgICAgIHx8IChjID49IDB4NDEgJiYgYyA8PSAweDVBKSAvLyBhLXpcbiAgICAgICAgICAgICAgICB8fCAoYyA+PSAweDYxICYmIGMgPD0gMHg3QSkgLy8gQS1aXG4gICAgICAgICAgICAgICAgfHwgKGZvcm1hdCA9PT0gZm9ybWF0cy5SRkMxNzM4ICYmIChjID09PSAweDI4IHx8IGMgPT09IDB4MjkpKSAvLyAoIClcbiAgICAgICAgICAgICkge1xuICAgICAgICAgICAgICAgIGFyclthcnIubGVuZ3RoXSA9IHNlZ21lbnQuY2hhckF0KGkpO1xuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoYyA8IDB4ODApIHtcbiAgICAgICAgICAgICAgICBhcnJbYXJyLmxlbmd0aF0gPSBoZXhUYWJsZVtjXTtcbiAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGMgPCAweDgwMCkge1xuICAgICAgICAgICAgICAgIGFyclthcnIubGVuZ3RoXSA9IGhleFRhYmxlWzB4QzAgfCAoYyA+PiA2KV1cbiAgICAgICAgICAgICAgICAgICAgKyBoZXhUYWJsZVsweDgwIHwgKGMgJiAweDNGKV07XG4gICAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChjIDwgMHhEODAwIHx8IGMgPj0gMHhFMDAwKSB7XG4gICAgICAgICAgICAgICAgYXJyW2Fyci5sZW5ndGhdID0gaGV4VGFibGVbMHhFMCB8IChjID4+IDEyKV1cbiAgICAgICAgICAgICAgICAgICAgKyBoZXhUYWJsZVsweDgwIHwgKChjID4+IDYpICYgMHgzRildXG4gICAgICAgICAgICAgICAgICAgICsgaGV4VGFibGVbMHg4MCB8IChjICYgMHgzRildO1xuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpICs9IDE7XG4gICAgICAgICAgICBjID0gMHgxMDAwMCArICgoKGMgJiAweDNGRikgPDwgMTApIHwgKHNlZ21lbnQuY2hhckNvZGVBdChpKSAmIDB4M0ZGKSk7XG5cbiAgICAgICAgICAgIGFyclthcnIubGVuZ3RoXSA9IGhleFRhYmxlWzB4RjAgfCAoYyA+PiAxOCldXG4gICAgICAgICAgICAgICAgKyBoZXhUYWJsZVsweDgwIHwgKChjID4+IDEyKSAmIDB4M0YpXVxuICAgICAgICAgICAgICAgICsgaGV4VGFibGVbMHg4MCB8ICgoYyA+PiA2KSAmIDB4M0YpXVxuICAgICAgICAgICAgICAgICsgaGV4VGFibGVbMHg4MCB8IChjICYgMHgzRildO1xuICAgICAgIC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VyKSA9PT0gbnVsbCB8fCBfYSA9PT0gdm9pZCAwID8gdm9pZCAwIDogX2EubmV4dClcbiAgICAgICAgICAgID8gdGhpcy5vYnNlcnZlKG5leHRPck9ic2VydmVyKVxuICAgICAgICAgICAgOiB0aGlzLmRvKG5leHRPck9ic2VydmVyLCBlcnJvciwgY29tcGxldGUpO1xuICAgIH07XG4gICAgTm90aWZpY2F0aW9uLnByb3RvdHlwZS50b09ic2VydmFibGUgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgIHZhciBfYSA9IHRoaXMsIGtpbmQgPSBfYS5raW5kLCB2YWx1ZSA9IF9hLnZhbHVlLCBlcnJvciA9IF9hLmVycm9yO1xuICAgICAgICB2YXIgcmVzdWx0ID0ga2luZCA9PT0gJ04nXG4gICAgICAgICAgICA/XG4gICAgICAgICAgICAgICAgb2YodmFsdWUpXG4gICAgICAgICAgICA6XG4gICAgICAgICAgICAgICAga2luZCA9PT0gJ0UnXG4gICAgICAgICAgICAgICAgICAgID9cbiAgICAgICAgICAgICAgICAgICAgICAgIHRocm93RXJyb3IoZnVuY3Rpb24gKCkgeyByZXR1cm4gZXJyb3I7IH0pXG4gICAgICAgICAgICAgICAgICAgIDpcbiAgICAgICAgICAgICAgICAgICAgICAgIGtpbmQgPT09ICdDJ1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgID9cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRU1QVFlcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICA6XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDA7XG4gICAgICAgIGlmICghcmVzdWx0KSB7XG4gICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKFwiVW5leHBlY3RlZCBub3RpZmljYXRpb24ga2luZCBcIiArIGtpbmQpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgfTtcbiAgICBOb3RpZmljYXRpb24uY3JlYXRlTmV4dCA9IGZ1bmN0aW9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BTYWZlU3Vic2NyaWJlcihvYnNlcnZlck9yTmV4dCwgZXJyb3IsIGNvbXBsZXRlKTtcbiAgICAgICAgZXJyb3JDb250ZXh0KGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIHZhciBfYSA9IF90aGlzLCBvcGVyYXRvciA9IF9hLm9wZXJhdG9yLCBzb3VyY2UgPSBfYS5zb3VyY2U7XG4gICAgICAgICAgICBzdWJzY3JpYmVyLmFkZChvcGVyYXRvclxuICAgICAgICAgICAgICAgID9cbiAgICAgICAgICAgICAgICAgICAgb3BlcmF0b3IuY2FsbChzdWJzY3JpYmVyLCBzb3VyY2UpXG4gICAgICAgICAgICAgICAgOiBzb3VyY2VcbiAgICAgICAgICAgICAgICAgICAgP1xuICAgICAgICAgICAgICAgICAgICAgICAgX3RoaXMuX3N1YnNjcmliZShzdWJzY3JpYmVyKVxuICAgICAgICAgICAgICAgICAgICA6XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpcy5fdHJ5U3Vic2NyaWJlKHN1YnNjcmliZXIpKTtcbiAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiBzdWJzY3JpYmVyO1xuICAgIH07XG4gICAgT2JzZXJ2YWJsZS5wcm90b3R5cGUuX3RyeVN1YnNjcmliZSA9IGZ1bmN0aW9uIChzaW5rKSB7XG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fc3Vic2NyaWJlKHNpbmspO1xuICAgICAgICB9XG4gICAgICAgIGNhdGNoIChlcnIpIHtcbiAgICAgICAgICAgIHNpbmsuZXJyb3IoZXJyKTtcbiAgICAgICAgfVxuICAgIH07XG4gICAgT2JzZXJ2YWJsZS5wcm90b3R5cGUuZm9yRWFjaCA9IGZ1bmN0aW9uIChuZXh0LCBwcm9taXNlQ3Rvcikge1xuICAgICAgICB2YXIgX3RoaXMgPSB0aGlzO1xuICAgICAgICBwcm9taXNlQ3RvciA9IGdldFByb21pc2VDdG9yKHByb21pc2VDdG9yKTtcbiAgICAgICAgcmV0dXJuIG5ldyBwcm9taXNlQ3RvcihmdW5jdGlvbiAocmVzb2x2ZSwgcmVqZWN0KSB7XG4gICAgICAgICAgICB2YXIgc3Vic2NyaXB0aW9uO1xuICAgICAgICAgICAgc3Vic2NyaXB0aW9uID0gX3RoaXMuc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIG5leHQodmFsdWUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgIHJlamVjdChlcnIpO1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24gPT09IG51bGwgfHwgc3Vic2NyaXB0aW9uID09PSB2b2lkIDAgPyB2b2lkIDAgOiBzdWJzY3JpcHRpb24udW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LCByZWplY3QsIHJlc29sdmUpO1xuICAgICAgICB9KTtcbiAgICB9O1xuICAgIE9ic2VydmFibGUucHJvdG90eXBlLl9zdWJzY3JpYmUgPSBmdW5jdGlvbiAoc3Vic2NyaWJlcikge1xuICAgICAgICB2YXIgX2E7XG4gICAgICAgIHJldHVybiAoX2EgPSB0aGlzLnNvdXJjZSkgPT09IG51bGwgfHwgX2EgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF9hLnN1YnNjcmliZShzdWJzY3JpYmVyKTtcbiAgICB9O1xuICAgIE9ic2VydmFibGUucHJvdG90eXBlW1N5bWJvbF9vYnNlcnZhYmxlXSA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfTtcbiAgICBPYnNlcnZhYmxlLnByb3RvdHlwZS5waXBlID0gZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgb3BlcmF0aW9ucyA9IFtdO1xuICAgICAgICBmb3IgKHZhciBfaS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c3Vic2NyaWJlZEVycm9yKCk7XG4gICAgICAgIH1cbiAgICB9O1xuICAgIFN1YmplY3QucHJvdG90eXBlLm5leHQgPSBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgdmFyIF90aGlzID0gdGhpcztcbiAgICAgICAgZXJyb3JDb250ZXh0KGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIHZhciBlXzEsIF9hO1xuICAgICAgICAgICAgX3RoaXMuX3Rocm93SWZDbG9zZWQoKTtcbiAgICAgICAgICAgIGlmICghX3RoaXMuaXNTdG9wcGVkKSB7XG4gICAgICAgICAgICAgICAgdmFyIGNvcHkgPSBfdGhpcy5vYnNlcnZlcnMuc2xpY2UoKTtcbiAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBjb3B5XzEgPSBfX3ZhbHVlcyhjb3B5KSwgY29weV8xXzEgPSBjb3B5XzEubmV4dCgpOyAhY29weV8xXzEuZG9uZTsgY29weV8xXzEgPSBjb3B5XzEubmV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgb2JzZXJ2ZXIgPSBjb3B5XzFfMS52YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm5leHQodmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNhdGNoIChlXzFfMSkgeyBlXzEgPSB7IGVycm9yOiBlXzFfMSB9OyB9XG4gICAgICAgICAgICAgICAgZmluYWxseSB7XG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoY29weV8xXzEgJiYgIWNvcHlfMV8xLmRvbmUgJiYgKF9hID0gY29weV8xLnJldHVybikpIF9hLmNhbGwoY29weV8xKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBmaW5hbGx5IHsgaWYgKGVfMSkgdGhyb3cgZV8xLmVycm9yOyB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9O1xuICAgIFN1YmplY3QucHJvdG90eXBlLmVycm9yID0gZnVuY3Rpb24gKGVycikge1xuICAgICAgICB2YXIgX3RoaXMgPSB0aGlzO1xuICAgICAgICBlcnJvckNvbnRleHQoZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgX3RoaXMuX3Rocm93SWZDbG9zZWQoKTtcbiAgICAgICAgICAgIGlmICghX3RoaXMuaXNTdG9wcGVkKSB7XG4gICAgICAgICAgICAgICAgX3RoaXMuaGFzRXJyb3IgPSBfdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xuICAgICAgICAgICAgICAgIF90aGlzLnRocm93bkVycm9yID0gZXJyO1xuICAgICAgICAgICAgICAgIHZhciBvYnNlcnZlcnMgPSBfdGhpcy5vYnNlcnZlcnM7XG4gICAgICAgICAgICAgICAgd2hpbGUgKG9ic2VydmVycy5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXJzLnNoaWZ0KCkuZXJyb3IoZXJyKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH07XG4gICAgU3ViamVjdC5wcm90b3R5cGUuY29tcGxldGUgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgIHZhciBfdGhpcyA9IHRoaXM7XG4gICAgICAgIGVycm9yQ29udGV4dChmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICBfdGhpcy5fdGhyb3dJZkNsb3NlZCgpO1xuICAgICAgICAgICAgaWYgKCFfdGhpcy5pc1N0b3BwZWQpIHtcbiAgICAgICAgICAgICAgICBfdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xuICAgICAgICAgICAgICAgIHZhciBvYnNlcnZlcnMgPSBfdGhpcy5vYnNlcnZlcnM7XG4gICAgICAgICAgICAgICAgd2hpbGUgKG9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V0dXJuIF90aGlzLnVuc3Vic2NyaWJlKCk7IH07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICBjb250ZXh0XzEgPSBvYnNlcnZlck9yTmV4dDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG5leHQgPSBuZXh0ID09PSBudWxsIHx8IG5leHQgPT09IHZvaWQgMCA/IHZvaWQgMCA6IG5leHQuYmluZChjb250ZXh0XzEpO1xuICAgICAgICAgICAgZXJyb3IgPSBlcnJvciA9PT0gbnVsbCB8fCBlcnJvciA9PT0gdm9pZCAwID8gdm9pZCAwIDogZXJyb3IuYmluZChjb250ZXh0XzEpO1xuICAgICAgICAgICAgY29tcGxldGUgPSBjb21wbGV0ZSA9PT0gbnVsbCB8fCBjb21wbGV0ZSA9PT0gdm9pZCAwID8gdm9pZCAwIDogY29tcGxldGUuYmluZChjb250ZXh0XzEpO1xuICAgICAgICB9XG4gICAgICAgIF90aGlzLmRlc3RpbmF0aW9uID0ge1xuICAgICAgICAgICAgbmV4dDogbmV4dCA/IHdyYXBGb3JFcnJvckhhbmRsaW5nKG5leHQsIF90aGlzKSA6IG5vb3AsXG4gICAgICAgICAgICBlcnJvcjogd3JhcEZvckVycm9ySGFuZGxpbmcoZXJyb3IgIT09IG51bGwgJiYgZXJyb3IgIT09IHZvaWQgMCA/IGVycm9yIDogZGVmYXVsdEVycm9ySGFuZGxlciwgX3RoaXMpLFxuICAgICAgICAgICAgY29tcGxldGU6IGNvbXBsZXRlID8gd3JhcEZvckVycm9ySGFuZGxpbmcoY29tcGxldGUsIF90aGlzKSA6IG5vb3AsXG4gICAgICAgIH07XG4gICAgICAgIHJldHVybiBfdGhpcztcbiAgICB9XG4gICAgcmV0dXJuIFNhZmVTdWJzY3JpYmVyO1xufShTdWJzY3JpYmVyKSk7XG5leHBvcnQgeyBTYWZlU3Vic2NyaWJlciB9O1xuZnVuY3Rpb24gd3JhcEZvckVycm9ySGFuZGxpbmcoaGFuZGxlciwgaW5zdGFuY2UpIHtcbiAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgYXJncyA9IFtdO1xuICAgICAgICBmb3IgKHZhciBfaSA9IDA7IF9pIDwgYXJndW1lbnRzLmxlbmd0aDsgX2krKykge1xuICAgICAgICAgICAgYXJnc1tfaV0gPSBhcmd1bWVudHNbX2ldO1xuICAgICAgICB9XG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICBoYW5kbGVyLmFwcGx5KHZvaWQgMCwgX19zcHJlYWRBcnJheShbXSwgX19yZWFkKGFyZ3MpKSk7XG4gICAgICAgIH1cbiAgICAgICAgY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgaWYgKGNvbmZpZy51c2VEZXByZWNhdGVkU3luY2hyb25vdXNFcnJvckhhbmRsaW5nKSB7XG4gICAgICAgICAgICAgICAgY2FwdHVyZUVycm9yKGVycik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXBvcnRVbmhhbmRsZWRFcnJvcihlcnIpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfTtcbn1cbmZ1bmN0aW9uIGRlZmF1bHRFcnJvckhhbmRsZXIoZXJyKSB7XG4gICAgdGhyb3cgZXJyO1xufVxuZnVuY3Rpb24gaGFuZGxlU3RvcHBlZE5vdGlmaWNhdGlvbihub3RpZmljYXRpb24sIHN1YnNjcmliZXIpIHtcbiAgICB2YXIgb25TdG9wcGVkTm90aWZpY2F0aW9uID0gY29uZmlnLm9uU3RvcHBlZE5vdGlmaWNhdGlvbjtcbiAgICBvblN0b3BwZWROb3RpZmljYXRpb24gJiYgdGltZW91dFByb3ZpZGVyLnNldFRpbWVvdXQoZnVuY3Rpb24gKCkgeyByZXR1cm4gb25TdG9wcGVkTm90aWZpY2F0aW9uKG5vdGlmaWNhdGlvbiwgc3Vic2NyaWJlcik7IH0pO1xufVxuZXhwb3J0IHZhciBFTVBU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Z2U7XG4gICAgICAgICAgICBpZiAoX3BhcmVudGFnZSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3BhcmVudGFnZSA9IG51bGw7XG4gICAgICAgICAgICAgICAgaWYgKEFycmF5LmlzQXJyYXkoX3BhcmVudGFnZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAodmFyIF9wYXJlbnRhZ2VfMSA9IF9fdmFsdWVzKF9wYXJlbnRhZ2UpLCBfcGFyZW50YWdlXzFfMSA9IF9wYXJlbnRhZ2VfMS5uZXh0KCk7ICFfcGFyZW50YWdlXzFfMS5kb25lOyBfcGFyZW50YWdlXzFfMSA9IF9wYXJlbnRhZ2VfMS5uZXh0KCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgcGFyZW50XzEgPSBfcGFyZW50YWdlXzFfMS52YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRfMS5yZW1vdmUodGhpcyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgY2F0Y2ggKGVfMV8xKSB7IGVfMSA9IHsgZXJyb3I6IGVfMV8xIH07IH1cbiAgICAgICAgICAgICAgICAgICAgZmluYWxseSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChfcGFyZW50YWdlXzFfMSAmJiAhX3BhcmVudGFnZV8xXzEuZG9uZSAmJiAoX2EgPSBfcGFyZW50YWdlXzEucmV0dXJuKSkgX2EuY2FsbChfcGFyZW50YWdlXzEpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxseSB7IGlmIChlXzEpIHRocm93IGVfMS5lcnJvcjsgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBfcGFyZW50YWdlLnJlbW92ZSh0aGlzKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgaW5pdGlhbFRlYXJkb3duID0gdGhpcy5pbml0aWFsVGVhcmRvd247XG4gICAgICAgICAgICBpZiAoaXNGdW5jdGlvbihpbml0aWFsVGVhcmRvd24pKSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgaW5pdGlhbFRlYXJkb3duKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNhdGNoIChlKSB7XG4gICAgICAgICAgICAgICAgICAgIGVycm9ycyA9IGUgaW5zdGFuY2VvZiBVbnN1YnNjcmlwdGlvbkVycm9yID8gZS5lcnJvcnMgOiBbZV07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdmFyIF90ZWFyZG93bnMgPSB0aGlzLl90ZWFyZG93bnM7XG4gICAgICAgICAgICBpZiAoX3RlYXJkb3ducykge1xuICAgICAgICAgICAgICAgIHRoaXMuX3RlYXJkb3ducyA9IG51bGw7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgX3RlYXJkb3duc18xID0gX192YWx1ZXMoX3RlYXJkb3ducyksIF90ZWFyZG93bnNfMV8xID0gX3RlYXJkb3duc18xLm5leHQoKTsgIV90ZWFyZG93bnNfMV8xLmRvbmU7IF90ZWFyZG93bnNfMV8xID0gX3RlYXJkb3duc18xLm5leHQoKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHRlYXJkb3duXzEgPSBfdGVhcmRvd25zXzFfMS52YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZXhlY1RlYXJkb3duKHRlYXJkb3duXzEpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVycm9ycyA9IGVycm9ycyAhPT0gbnVsbCAmJiBlcnJvcnMgIT09IHZvaWQgMCA/IGVycm9ycyA6IFtdO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlcnIgaW5zdGFuY2VvZiBVbnN1YnNjcmlwdGlvbkVycm9yKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVycm9ycyA9IF9fc3ByZWFkQXJyYXkoX19zcHJlYWRBcnJheShbXSwgX19yZWFkKGVycm9ycykpLCBfX3JlYWQoZXJyLmVycm9ycykpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZXJyb3JzLnB1c2goZXJyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgY2F0Y2ggKGVfMl8xKSB7IGVfMiA9IHsgZXJyb3I6IGVfMl8xIH07IH1cbiAgICAgICAgICAgICAgICBmaW5hbGx5IHtcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChfdGVhcmRvd25zXzFfMSAmJiAhX3RlYXJkb3duc18xXzEuZG9uZSAmJiAoX2IgPSBfdGVhcmRvd25zXzEucmV0dXJuKSkgX2IuY2FsbChfdGVhcmRvd25zXzEpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGZpbmFsbHkgeyBpZiAoZV8yKSB0aHJvdyBlXzIuZXJyb3I7IH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoZXJyb3JzKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IFVuc3Vic2NyaXB0aW9uRXJyb3IoZXJyb3JzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG4gICAgU3Vic2NyaXB0aW9uLnByb3RvdHlwZS5hZGQgPSBmdW5jdGlvbiAodGVhcmRvd24pIHtcbiAgICAgICAgdmFyIF9hO1xuICAgICAgICBpZiAodGVhcmRvd24gJiYgdGVhcmRvd24gIT09IHRoaXMpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLmNsb3NlZCkge1xuICAgICAgICAgICAgICAgIGV4ZWNUZWFyZG93bih0ZWFyZG93bik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZiAodGVhcmRvd24gaW5zdGFuY2VvZiBTdWJzY3JpcHRpb24pIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRlYXJkb3duLmNsb3NlZCB8fCB0ZWFyZG93bi5faGFzUGFyZW50KHRoaXMpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgdGVhcmRvd24uX2FkZFBhcmVudCh0aGlzKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgKHRoaXMuX3RlYXJkb3ducyA9IChfYSA9IHRoaXMuX3RlYXJkb3ducykgIT09IG51bGwgJiYgX2EgIT09IHZvaWQgMCA/IF9hIDogW10pLnB1c2godGVhcmRvd24pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfTtcbiAgICBTdWJzY3JpcHRpb24ucHJvdG90eXBlLl9oYXNQYXJlbnQgPSBmdW5jdGlvbiAocGFyZW50KSB7XG4gICAgICAgIHZhciBfcGFyZW50YWdlID0gdGhpcy5fcGFyZW50Y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ICByZWplY3QobmV3IEVtcHR5RXJyb3IoKSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiAgICAgICAgfSk7XG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUoc3Vic2NyaWJlcik7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1maXJzdFZhbHVlRnJvbS5qcy5tYXAiLCJpbXBvcnQgeyBFbXB0eUVycm9yIH0gZnJvbSAnLi91dGlsL0VtcHR5RXJyb3InO1xuZXhwb3J0IGZ1bmN0aW9uIGxhc3RWYWx1ZUZyb20oc291cmNlLCBjb25maWcpIHtcbiAgICB2YXIgaGFzQ29uZmlnID0gdHlwZW9mIGNvbmZpZyA9PT0gJ29iamVjdCc7XG4gICAgcmV0dXJuIG5ldyBQcm9taXNlKGZ1bmN0aW9uIChyZXNvbHZlLCByZWplY3QpIHtcbiAgICAgICAgdmFyIF9oYXNWYWx1ZSA9IGZhbHNlO1xuICAgICAgICB2YXIgX3ZhbHVlO1xuICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKHtcbiAgICAgICAgICAgIG5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgIF92YWx1ZSA9IHZhbHVlO1xuICAgICAgICAgICAgICAgIF9oYXNWYWx1ZSA9IHRydWU7XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgZXJyb3I6IHJlamVjdCxcbiAgICAgICAgICAgIGNvbXBsZXRlOiBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgaWYgKF9oYXNWYWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICByZXNvbHZlKF92YWx1ZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2UgaWYgKGhhc0NvbmZpZykge1xuICAgICAgICAgICAgICAgICAgICByZXNvbHZlKGNvbmZpZy5kZWZhdWx0VmFsdWUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgIC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uZ3RoOyBfaSsrKSB7XG4gICAgICAgICAgICAgICAgYXJnc1tfaV0gPSBhcmd1bWVudHNbX2ldO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGJpbmRDYWxsYmFja0ludGVybmFscyhpc05vZGVTdHlsZSwgY2FsbGJhY2tGdW5jKVxuICAgICAgICAgICAgICAgIC5hcHBseSh0aGlzLCBhcmdzKVxuICAgICAgICAgICAgICAgIC5waXBlKHN1YnNjcmliZU9uKHNjaGVkdWxlciksIG9ic2VydmVPbihzY2hlZHVsZXIpKTtcbiAgICAgICAgfTtcbiAgICB9XG4gICAgcmV0dXJuIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgdmFyIF90aGlzID0gdGhpcztcbiAgICAgICAgdmFyIGFyZ3MgPSBbXTtcbiAgICAgICAgZm9yICh2YXIgX2kgPSAwOyBfaSA8IGFyZ3VtZW50cy5sZW5ndGg7IF9pKyspIHtcbiAgICAgICAgICAgIGFyZ3NbX2ldID0gYXJndW1lbnRzW19pXTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgc3ViamVjdCA9IG5ldyBBc3luY1N1YmplY3QoKTtcbiAgICAgICAgdmFyIHVuaW5pdGlhbGl6ZWQgPSB0cnVlO1xuICAgICAgICByZXR1cm4gbmV3IE9ic2VydmFibGUoZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcbiAgICAgICAgICAgIHZhciBzdWJzID0gc3ViamVjdC5zdWJzY3JpYmUoc3Vic2NyaWJlcik7XG4gICAgICAgICAgICBpZiAodW5pbml0aWFsaXplZCkge1xuICAgICAgICAgICAgICAgIHVuaW5pdGlhbGl6ZWQgPSBmYWxzZTtcbiAgICAgICAgICAgICAgICB2YXIgaXNBc3luY18xID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgdmFyIGlzQ29tcGxldGVfMSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIGNhbGxiYWNrRnVuYy5hcHBseShfdGhpcywgX19zcHJlYWRBcnJheShfX3NwcmVhZEFycmF5KFtdLCBfX3JlYWQoYXJncykpLCBbXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciByZXN1bHRzID0gW107XG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBfaSA9IDA7IF9pIDwgYXJndW1lbnRzLmxlbmd0aDsgX2krKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdHNbX2ldID0gYXJndW1lbnRzW19pXTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpc05vZGVTdHlsZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhciBlcnIgPSByZXN1bHRzLnNoaWZ0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGVyciAhPSBudWxsKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YmplY3QuZXJyb3IoZXJyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YmplY3QubmV4dCgxIDwgcmVzdWx0cy5sZW5ndGggPyByZXN1bHRzIDogcmVzdWx0c1swXSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpc0NvbXBsZXRlXzEgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzQXN5bmNfMSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YmplY3QuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBdKSk7XG4gICAgICAgICAgICAgICAgaWYgKGlzQ29tcGxldGVfMSkge1xuICAgICAgICAgICAgIC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ICAgICAgIHJlbWFpbmluZ0ZpcnN0VmFsdWVzLS07XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXJlbWFpbmluZ0ZpcnN0VmFsdWVzKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KHZhbHVlVHJhbnNmb3JtKHZhbHVlcy5zbGljZSgpKSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghLS1hY3RpdmUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICB9LCBzdWJzY3JpYmVyKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICAgICAgX2xvb3BfMShpKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSwgc3Vic2NyaWJlcik7XG4gICAgfTtcbn1cbmZ1bmN0aW9uIG1heWJlU2NoZWR1bGUoc2NoZWR1bGVyLCBleGVjdXRlLCBzdWJzY3JpcHRpb24pIHtcbiAgICBpZiAoc2NoZWR1bGVyKSB7XG4gICAgICAgIHN1YnNjcmlwdGlvbi5hZGQoc2NoZWR1bGVyLnNjaGVkdWxlKGV4ZWN1dGUpKTtcbiAgICB9XG4gICAgZWxzZSB7XG4gICAgICAgIGV4ZWN1dGUoKTtcbiAgICB9XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1jb21iaW5lTGF0ZXN0LmpzLm1hcCIsImltcG9ydCB7IGNvbmNhdEFsbCB9IGZyb20gJy4uL29wZXJhdG9ycy9jb25jYX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3IE9ic2VydmFibGUoZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcbiAgICAgICAgdmFyIGxlbmd0aCA9IHNvdXJjZXMubGVuZ3RoO1xuICAgICAgICBpZiAoIWxlbmd0aCkge1xuICAgICAgICAgICAgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHZhciB2YWx1ZXMgPSBuZXcgQXJyYXkobGVuZ3RoKTtcbiAgICAgICAgdmFyIHJlbWFpbmluZ0NvbXBsZXRpb25zID0gbGVuZ3RoO1xuICAgICAgICB2YXIgcmVtYWluaW5nRW1pc3Npb25zID0gbGVuZ3RoO1xuICAgICAgICB2YXIgX2xvb3BfMSA9IGZ1bmN0aW9uIChzb3VyY2VJbmRleCkge1xuICAgICAgICAgICAgdmFyIGhhc1ZhbHVlID0gZmFsc2U7XG4gICAgICAgICAgICBpbm5lckZyb20oc291cmNlc1tzb3VyY2VJbmRleF0pLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgIGlmICghaGFzVmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICByZW1haW5pbmdFbWlzc2lvbnMtLTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdmFsdWVzW3NvdXJjZUluZGV4XSA9IHZhbHVlO1xuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIGlmICghLS1yZW1haW5pbmdDb21wbGV0aW9ucyB8fCAhaGFzVmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFyZW1haW5pbmdFbWlzc2lvbnMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dChrZXlzID8gY3Jl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WJzY3JpYmVyLm5leHQodmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICBpZiAoc3Vic2NyaWJlci5jbG9zZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbMl07XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgX2IubGFiZWwgPSAzO1xuICAgICAgICAgICAgICAgIGNhc2UgMzogcmV0dXJuIFszLCAxXTtcbiAgICAgICAgICAgICAgICBjYXNlIDQ6IHJldHVybiBbMywgMTFdO1xuICAgICAgICAgICAgICAgIGNhc2UgNTpcbiAgICAgICAgICAgICAgICAgICAgZV8yXzEgPSBfYi5zZW50KCk7XG4gICAgICAgICAgICAgICAgICAgIGVfMiA9IHsgZXJyb3I6IGVfMl8xIH07XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBbMywgMTFdO1xuICAgICAgICAgICAgICAgIGNhc2UgNjpcbiAgICAgICAgICAgICAgICAgICAgX2IudHJ5cy5wdXNoKFs2LCAsIDksIDEwXSk7XG4gICAgICAgICAgICAgICAgICAgIGlmICghKGFzeW5jSXRlcmFibGVfMV8xICYmICFhc3luY0l0ZXJhYmxlXzFfMS5kb25lICYmIChfYSA9IGFzeW5jSXRlcmFibGVfMS5yZXR1cm4pKSkgcmV0dXJuIFszLCA4XTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFs0LCBfYS5jYWxsKGFzeW5jSXRlcmFibGVfMSldO1xuICAgICAgICAgICAgICAgIGNhc2UgNzpcbiAgICAgICAgICAgICAgICAgICAgX2Iuc2VudCgpO1xuICAgICAgICAgICAgICAgICAgICBfYi5sYWJlbCA9IDg7XG4gICAgICAgICAgICAgICAgY2FzZSA4OiByZXR1cm4gWzMsIDEwXTtcbiAgICAgICAgICAgICAgICBjYXNlIDk6XG4gICAgICAgICAgICAgICAgICAgIGlmIChlXzIpIHRocm93IGVfMi5lcnJvcjtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFs3XTtc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Y2hlZHVsZXIgPSBfYS5zY2hlZHVsZXIpO1xuICAgIH1cbiAgICBlbHNlIHtcbiAgICAgICAgaW5pdGlhbFN0YXRlID0gaW5pdGlhbFN0YXRlT3JPcHRpb25zO1xuICAgICAgICBpZiAoIXJlc3VsdFNlbGVjdG9yT3JTY2hlZHVsZXIgfHwgaXNTY2hlZHVsZXIocmVzdWx0U2VsZWN0b3JPclNjaGVkdWxlcikpIHtcbiAgICAgICAgICAgIHJlc3VsdFNlbGVjdG9yID0gaWRlbnRpdHk7XG4gICAgICAgICAgICBzY2hlZHVsZXIgPSByZXN1bHRTZWxlY3Rvck9yU2NoZWR1bGVyO1xuICAgICAgICB9XG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgcmVzdWx0U2VsZWN0b3IgPSByZXN1bHRTZWxlY3Rvck9yU2NoZWR1bGVyO1xuICAgICAgICB9XG4gICAgfVxuICAgIGZ1bmN0aW9uIGdlbigpIHtcbiAgICAgICAgdmFyIHN0YXRlO1xuICAgICAgICByZXR1cm4gX19nZW5lcmF0b3IodGhpcywgZnVuY3Rpb24gKF9hKSB7XG4gICAgICAgICAgICBzd2l0Y2ggKF9hLmxhYmVsKSB7XG4gICAgICAgICAgICAgICAgY2FzZSAwOlxuICAgICAgICAgICAgICAgICAgICBzdGF0ZSA9IGluaXRpYWxTdGF0ZTtcbiAgICAgICAgICAgICAgICAgICAgX2EubGFiZWwgPSAxO1xuICAgICAgICAgICAgICAgIGNhc2UgMTpcbiAgICAgICAgICAgICAgICAgICAgaWYgKCEoIWNvbmRpdGlvbiB8fCBjb25kaXRpb24oc3RhdGUpKSkgcmV0dXJuIFszLCA0XTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFs0LCByZXN1bHRTZWxlY3RvcihzdGF0ZSldO1xuICAgICAgICAgICAgICAgIGNhc2UgMjpcbiAgICAgICAgICAgICAgICAgICAgX2Euc2VudCgpO1xuICAgICAgICAgICAgICAgICAgICBfYS5sYWJlbCA9IDM7XG4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b24gKHN1YnNjcmliZXIpIHtcbiAgICAgICAgICAgICAgICB2YXIgbiA9IHN0YXJ0O1xuICAgICAgICAgICAgICAgIHJldHVybiBzY2hlZHVsZXIuc2NoZWR1bGUoZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICBpZiAobiA8IGVuZCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KG4rKyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnNjaGVkdWxlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgOlxuICAgICAgICAgICAgZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcbiAgICAgICAgICAgICAgICB2YXIgbiA9IHN0YXJ0O1xuICAgICAgICAgICAgICAgIHdoaWxlIChuIDwgZW5kICYmICFzdWJzY3JpYmVyLmNsb3NlZCkge1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQobisrKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1yYW5nZS5qcy5tYXAiLCJpbXBvcnQgeyBPYnNlcnZhYmxlIH0gZnJvbSAnLi4vT2JzZXJ2YWJsZSc7XG5pbXBvcnQgeyBpc0Z1bmN0aW9uIH0gZnJvbSAnLi4vdXRpbC9pc0Z1bmN0aW9uJztcbmV4cG9ydCBmdW5jdGlvbiB0aHJvd0Vycm9yKGVycm9yT3JFcnJvckZhY3RvcnksIHNjaGVkdWxlcikge1xuICAgIHZhciBlcnJvckZhY3Rvcnkg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cbiAgICAgICAgaWYgKGlzU2NoZWR1bGVyKGludGVydmFsT3JTY2hlZHVsZXIpKSB7XG4gICAgICAgICAgICBzY2hlZHVsZXIgPSBpbnRlcnZhbE9yU2NoZWR1bGVyO1xuICAgICAgICB9XG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgaW50ZXJ2YWxEdXJhdGlvbiA9IGludGVydmFsT3JTY2hlZHVsZXI7XG4gICAgICAgIH1cbiAgICB9XG4gICAgcmV0dXJuIG5ldyBPYnNlcnZhYmxlKGZ1bmN0aW9uIChzdWJzY3JpYmVyKSB7XG4gICAgICAgIHZhciBkdWUgPSBpc1ZhbGlkRGF0ZShkdWVUaW1lKSA/ICtkdWVUaW1lIC0gc2NoZWR1bGVyLm5vdygpIDogZHVlVGltZTtcbiAgICAgICAgaWYgKGR1ZSA8IDApIHtcbiAgICAgICAgICAgIGR1ZSA9IDA7XG4gICAgICAgIH1cbiAgICAgICAgdmFyIG4gPSAwO1xuICAgICAgICByZXR1cm4gc2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIGlmICghc3Vic2NyaWJlci5jbG9zZWQpIHtcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQobisrKTtcbiAgICAgICAgICAgICAgICBpZiAoMCA8PSBpbnRlcnZhbER1cmF0aW9uKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc2NoZWR1bGUodW5kZWZpbmVkLCBpbnRlcnZhbER1cmF0aW9uKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sIGR1ZSk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD10aW1lci5qcy5tYXAiLCJpbXBvcnQgeyBPYnNlcnZhYmx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gICAgICAgIGJ1ZmZlcnNbc291cmNlSW5kZXhdLnB1c2godmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICBpZiAoYnVmZmVycy5ldmVyeShmdW5jdGlvbiAoYnVmZmVyKSB7IHJldHVybiBidWZmZXIubGVuZ3RoOyB9KSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHJlc3VsdCA9IGJ1ZmZlcnMubWFwKGZ1bmN0aW9uIChidWZmZXIpIHsgcmV0dXJuIGJ1ZmZlci5zaGlmdCgpOyB9KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dChyZXN1bHRTZWxlY3RvciA/IHJlc3VsdFNlbGVjdG9yLmFwcGx5KHZvaWQgMCwgX19zcHJlYWRBcnJheShbXSwgX19yZWFkKHJlc3VsdCkpKSA6IHJlc3VsdCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoYnVmZmVycy5zb21lKGZ1bmN0aW9uIChidWZmZXIsIGkpIHsgcmV0dXJuICFidWZmZXIubGVuZ3RoICYmIGNvbXBsZXRlZFtpXTsgfSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbXBsZXRlZFtzb3VyY2VJbmRleF0gPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICAhYnVmZmVyc1tzb3VyY2VJbmRleF0ubGVuZ3RoICYmIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgZm9yICh2YXIgc291cmNlSW5kZXggPSAwOyAhc3Vic2NyaWJlci5jbG9zZWQgJiYgc291cmNlSW5kZXggPCBzb3VyY2VzLmxlbmd0aDsgc291cmNlSW5kZXgrKykge1xuICAgICAgICAgICAgICAgIF9sb29wXzEoc291cmNlSW5kZXgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICBidWZmZXJzID0gY29tcGxldGVkID0gbnVsbDtcbiAgICAgICAgICAgIH07XG4gICAgICAgIH0pXG4gICAgICAgIDogRU1QVFk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD16aXAuanMubWFwIiwiaW1wb3J0IHsgX19leHRlbmRzIH0gZnJvbSBcInRzbGliXCI7XG5pbXBvcnQgeyBTdWJzY3JpYmVyIH0gZnJvbSAnLi4vU3Vic2NyaWJlcic7XG52YXIgT3BlcmF0b3JTdWJzY3JpYmVyID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcbiAgICBfX2V4dGVuZHMoT3BlcmF0b3JTdWJzY3JpYmVyLCBfc3VwZXIpO1xuICAgIGZ1bmN0aW9uIE9wZXJhdG9yU3Vic2NyaWJlcihkZXN0aW5hdGlvbiwgb25OZXh0LCBvbkNvbXBsZXRlLCBvbkVycm9yLCBvbkZpbmFsaXplKSB7XG4gICAgICAgIHZhciBfdGhpcyA9IF9zdXBlci5jYWxsKHRoaXMsIGRlc3RpbmF0aW9uKSB8fCB0aGlzO1xuICAgICAgICBfdGhpcy5vbkZpbmFsaXplID0gb25GaW5hbGl6ZTtcbiAgICAgICAgX3RoaXMuX25leHQgPSBvbk5leHRcbiAgICAgICAgICAgID8gZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgb25OZXh0KHZhbHVlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICAgICAgICBkZXN0aW5hdGlvbi5lcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIDogX3N1cGVyLnByb3RvdHlwZS5fbmV4dDtcbiAgICAgICAgX3RoaXMuX2Vycm9yID0gb25FcnJvclxuICAgICAgICAgICAgPyBmdW5jdGlvbiAoZXJyKSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgb25FcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgIGRlc3RpbmF0aW9uLmVycm9yKGVycik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgOiBfc3VwZXIucHJvdG90eXBlLl9lcnJvcjtcbiAgICAgICAgX3RoaXMuX2NvbXBsZXRlID0gb25Db21wbGV0ZVxuICAgICAgICAgICAgPyBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgb25Db21wbGV0ZSgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgIGRlc3RpbmF0aW9uLmVycm9yKGVycik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgOiBfc3VwZXIucHJvdG90eXBlLl9jb21wbGV0ZTtcbiAgICAgICAgcmV0dXJuIF90aGlzO1xuICAgIH1cbiAgICBPcGVyYXRvclN1YnNjcmliZXIucHJvdG90eXBlLnVuc3Vic2NyaWJlID0gZnVuY3Rpb24g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mVyID09PSB2b2lkIDAgPyB2b2lkIDAgOiBkdXJhdGlvblN1YnNjcmliZXIudW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgIGR1cmF0aW9uU3Vic2NyaWJlciA9IG51bGw7XG4gICAgICAgICAgICBpZiAoaGFzVmFsdWUpIHtcbiAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IGxhc3RWYWx1ZTtcbiAgICAgICAgICAgICAgICBsYXN0VmFsdWUgPSBudWxsO1xuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dCh2YWx1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpc0NvbXBsZXRlICYmIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgfTtcbiAgICAgICAgdmFyIGNsZWFudXBEdXJhdGlvbiA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIGR1cmF0aW9uU3Vic2NyaWJlciA9IG51bGw7XG4gICAgICAgICAgICBpc0NvbXBsZXRlICYmIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgfTtcbiAgICAgICAgc291cmNlLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xuICAgICAgICAgICAgbGFzdFZhbHVlID0gdmFsdWU7XG4gICAgICAgICAgICBpZiAoIWR1cmF0aW9uU3Vic2NyaWJlcikge1xuICAgICAgICAgICAgICAgIGlubmVyRnJvbShkdXJhdGlvblNlbGVjdG9yKHZhbHVlKSkuc3Vic2NyaWJlKChkdXJhdGlvblN1YnNjcmliZXIgPSBuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGVuZER1cmF0aW9uLCBjbGVhbnVwRHVyYXRpb24pKSk7XG4gICAgICAgIC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AgIGlmIChidWZmZXJTaXplIDw9IGJ1ZmZlci5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRvRW1pdCA9IHRvRW1pdCAhPT0gbnVsbCAmJiB0b0VtaXQgIT09IHZvaWQgMCA/IHRvRW1pdCA6IFtdO1xuICAgICAgICAgICAgICAgICAgICAgICAgdG9FbWl0LnB1c2goYnVmZmVyKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGNhdGNoIChlXzFfMSkgeyBlXzEgPSB7IGVycm9yOiBlXzFfMSB9OyB9XG4gICAgICAgICAgICBmaW5hbGx5IHtcbiAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICBpZiAoYnVmZmVyc18xXzEgJiYgIWJ1ZmZlcnNfMV8xLmRvbmUgJiYgKF9hID0gYnVmZmVyc18xLnJldHVybikpIF9hLmNhbGwoYnVmZmVyc18xKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgZmluYWxseSB7IGlmIChlXzEpIHRocm93IGVfMS5lcnJvcjsgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRvRW1pdCkge1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIHRvRW1pdF8xID0gX192YWx1ZXModG9FbWl0KSwgdG9FbWl0XzFfMSA9IHRvRW1pdF8xLm5leHQoKTsgIXRvRW1pdF8xXzEuZG9uZTsgdG9FbWl0XzFfMSA9IHRvRW1pdF8xLm5leHQoKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGJ1ZmZlciA9IHRvRW1pdF8xXzEudmFsdWU7XG4gICAgICAgICAgICAgICAgICAgICAgICBhcnJSZW1vdmUoYnVmZmVycywgYnVmZmVyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dChidWZmZXIpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNhdGNoIChlXzJfMSkgeyBlXzIgPSB7IGVycm9yOiBlXzJfMSB9OyB9XG4gICAgICAgICAgICAgICAgZmluYWxseSB7XG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodG9FbWl0XzFfMSAmJiAhdG9FbWl0XzFfMS5kb25lICYmIChfYiA9IHRvRW1pdF8xLnJldHVybikpIF9iLmNhbGwodG9FbWl0XzEpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGZpbmFsbHkgeyBpZiAoZV8yKSB0aHJvdyBlXzIuZXJyb3I7IH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIHZhciBlXzMsIF9hO1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBidWZmZXJzXzIgPSBfX3ZhbHVlcyhidWZmZXJzKSwgYnVmZmVyc18yXzEgPSBidWZmZXJzXzIubmV4dCgpOyAhYnVmZmVyc18yXzEuZG9uZTsgYnVmZmVyc18yXzEgPSBidWZmZXJzXzIubmV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBidWZmZXIgPSBidWZmZXJzXzJfMS52YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KGJ1ZmZlcik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2F0Y2ggKGVfM18xKSB7IGVfMyA9IHsgZXJyb3I6IGVfM18xIH07IH1cbiAgICAgICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChidWZmZXJzXzJfMSAmJiAhYnVmZmV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2E7XG4gICAgICAgICAgICB2YXIgcmVjb3Jkc0NvcHkgPSBidWZmZXJSZWNvcmRzLnNsaWNlKCk7XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgIGZvciAodmFyIHJlY29yZHNDb3B5XzEgPSBfX3ZhbHVlcyhyZWNvcmRzQ29weSksIHJlY29yZHNDb3B5XzFfMSA9IHJlY29yZHNDb3B5XzEubmV4dCgpOyAhcmVjb3Jkc0NvcHlfMV8xLmRvbmU7IHJlY29yZHNDb3B5XzFfMSA9IHJlY29yZHNDb3B5XzEubmV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciByZWNvcmQgPSByZWNvcmRzQ29weV8xXzEudmFsdWU7XG4gICAgICAgICAgICAgICAgICAgIHZhciBidWZmZXIgPSByZWNvcmQuYnVmZmVyO1xuICAgICAgICAgICAgICAgICAgICBidWZmZXIucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgIG1heEJ1ZmZlclNpemUgPD0gYnVmZmVyLmxlbmd0aCAmJiBlbWl0KHJlY29yZCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2F0Y2ggKGVfMV8xKSB7IGVfMSA9IHsgZXJyb3I6IGVfMV8xIH07IH1cbiAgICAgICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChyZWNvcmRzQ29weV8xXzEgJiYgIXJlY29yZHNDb3B5XzFfMS5kb25lICYmIChfYSA9IHJlY29yZHNDb3B5XzEucmV0dXJuKSkgX2EuY2FsbChyZWNvcmRzQ29weV8xKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgZmluYWxseSB7IGlmIChlXzEpIHRocm93IGVfMS5lcnJvcjsgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICB3aGlsZSAoYnVmZmVy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b24gKHZhbHVlKSB7XG4gICAgICAgICAgICB2YXIgZV8xLCBfYTtcbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgZm9yICh2YXIgYnVmZmVyc18xID0gX192YWx1ZXMoYnVmZmVycyksIGJ1ZmZlcnNfMV8xID0gYnVmZmVyc18xLm5leHQoKTsgIWJ1ZmZlcnNfMV8xLmRvbmU7IGJ1ZmZlcnNfMV8xID0gYnVmZmVyc18xLm5leHQoKSkge1xuICAgICAgICAgICAgICAgICAgICB2YXIgYnVmZmVyID0gYnVmZmVyc18xXzEudmFsdWU7XG4gICAgICAgICAgICAgICAgICAgIGJ1ZmZlci5wdXNoKHZhbHVlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjYXRjaCAoZV8xXzEpIHsgZV8xID0geyBlcnJvcjogZV8xXzEgfTsgfVxuICAgICAgICAgICAgZmluYWxseSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGJ1ZmZlcnNfMV8xICYmICFidWZmZXJzXzFfMS5kb25lICYmIChfYSA9IGJ1ZmZlcnNfMS5yZXR1cm4pKSBfYS5jYWxsKGJ1ZmZlcnNfMSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkgeyBpZiAoZV8xKSB0aHJvdyBlXzEuZXJyb3I7IH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgd2hpbGUgKGJ1ZmZlcnMubGVuZ3RoID4gMCkge1xuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dChidWZmZXJzLnNoaWZ0KCkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICB9KSk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1idWZmZXJUb2dn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J0IGZ1bmN0aW9uIGRlYm91bmNlVGltZShkdWVUaW1lLCBzY2hlZHVsZXIpIHtcbiAgICBpZiAoc2NoZWR1bGVyID09PSB2b2lkIDApIHsgc2NoZWR1bGVyID0gYXN5bmNTY2hlZHVsZXI7IH1cbiAgICByZXR1cm4gb3BlcmF0ZShmdW5jdGlvbiAoc291cmNlLCBzdWJzY3JpYmVyKSB7XG4gICAgICAgIHZhciBhY3RpdmVUYXNrID0gbnVsbDtcbiAgICAgICAgdmFyIGxhc3RWYWx1ZSA9IG51bGw7XG4gICAgICAgIHZhciBsYXN0VGltZSA9IG51bGw7XG4gICAgICAgIHZhciBlbWl0ID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgaWYgKGFjdGl2ZVRhc2spIHtcbiAgICAgICAgICAgICAgICBhY3RpdmVUYXNrLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgYWN0aXZlVGFzayA9IG51bGw7XG4gICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gbGFzdFZhbHVlO1xuICAgICAgICAgICAgICAgIGxhc3RWYWx1ZSA9IG51bGw7XG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KHZhbHVlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgICAgZnVuY3Rpb24gZW1pdFdoZW5JZGxlKCkge1xuICAgICAgICAgICAgdmFyIHRhcmdldFRpbWUgPSBsYXN0VGltZSArIGR1ZVRpbWU7XG4gICAgICAgICAgICB2YXIgbm93ID0gc2NoZWR1bGVyLm5vdygpO1xuICAgICAgICAgICAgaWYgKG5vdyA8IHRhcmdldFRpbWUpIHtcbiAgICAgICAgICAgICAgICBhY3RpdmVUYXNrID0gdGhpcy5zY2hlZHVsZSh1bmRlZmluZWQsIHRhcmdldFRpbWUgLSBub3cpO1xuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIuYWRkKGFjdGl2ZVRhc2spO1xuICAgICAgICAgICAgICAgIHJldHVybjtc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YiA9IG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgdW5kZWZpbmVkLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIGlubmVyU3ViID0gbnVsbDtcbiAgICAgICAgICAgICAgICAgICAgaXNDb21wbGV0ZSAmJiBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgaW5uZXJGcm9tKHByb2plY3Qob3V0ZXJWYWx1ZSwgaW5kZXgrKykpLnN1YnNjcmliZShpbm5lclN1Yik7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIGlzQ29tcGxldGUgPSB0cnVlO1xuICAgICAgICAgICAgIWlubmVyU3ViICYmIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgfSkpO1xuICAgIH0pO1xufVxuLy8jIHNvdXJjZU1hcHBpbmdVUkw9ZXhoYXVzdE1hcC5qcy5tYXAiLCJpbXBvcnQgeyBvcGVyYXRlIH0gZnJvbSAnLi4vdXRpbC9saWZ0JztcbmltcG9ydCB7IG1lcmdlSW50ZXJuYWxzIH0gZnJvbSAnLi9tZXJnZUludGVybmFscyc7XG5leHBvcnQgZnVuY3Rpb24gZXhwYW5kKHByb2plY3QsIGNvbmN1cnJlbnQsIHNjaGVkdWxlcikge1xuICAgIGlmIChjb25jdXJyZW50ID09PSB2b2lkIDApIHsgY29uY3VycmVudCA9IEluZmluaXR5OyB9XG4gICAgY29uY3VycmVudCA9IChjb25jdXJyZW50IHx8IDApIDwgMSA/IEluZmluaXR5IDogY29uY3VycmVudDtcbiAgICByZXR1cm4gb3BlcmF0ZShmdW5jdGlvbiAoc291cmNlLCBzdWJzY3JpYmVyKSB7XG4gICAgICAgIHJldHVybiBtZXJnZUludGVybmFscyhzb3VyY2UsIHN1YnNjcmliZXIsIHByb2plY3QsIGNvbmN1cnJlbnQs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cbiAgICAgICAgICAgIChkdXJhdGlvbiA9IGVsZW1lbnRPck9wdGlvbnMuZHVyYXRpb24sIGVsZW1lbnQgPSBlbGVtZW50T3JPcHRpb25zLmVsZW1lbnQsIGNvbm5lY3RvciA9IGVsZW1lbnRPck9wdGlvbnMuY29ubmVjdG9yKTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgZ3JvdXBzID0gbmV3IE1hcCgpO1xuICAgICAgICB2YXIgbm90aWZ5ID0gZnVuY3Rpb24gKGNiKSB7XG4gICAgICAgICAgICBncm91cHMuZm9yRWFjaChjYik7XG4gICAgICAgICAgICBjYihzdWJzY3JpYmVyKTtcbiAgICAgICAgfTtcbiAgICAgICAgdmFyIGhhbmRsZUVycm9yID0gZnVuY3Rpb24gKGVycikgeyByZXR1cm4gbm90aWZ5KGZ1bmN0aW9uIChjb25zdW1lcikgeyByZXR1cm4gY29uc3VtZXIuZXJyb3IoZXJyKTsgfSk7IH07XG4gICAgICAgIHZhciBncm91cEJ5U291cmNlU3Vic2NyaWJlciA9IG5ldyBHcm91cEJ5U3Vic2NyaWJlcihzdWJzY3JpYmVyLCBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgdmFyIGtleV8xID0ga2V5U2VsZWN0b3IodmFsdWUpO1xuICAgICAgICAgICAgICAgIHZhciBncm91cF8xID0gZ3JvdXBzLmdldChrZXlfMSk7XG4gICAgICAgICAgICAgICAgaWYgKCFncm91cF8xKSB7XG4gICAgICAgICAgICAgICAgICAgIGdyb3Vwcy5zZXQoa2V5XzEsIChncm91cF8xID0gY29ubmVjdG9yID8gY29ubmVjdG9yKCkgOiBuZXcgU3ViamVjdCgpKSk7XG4gICAgICAgICAgICAgICAgICAgIHZhciBncm91cGVkID0gY3JlYXRlR3JvdXBlZE9ic2VydmFibGUoa2V5XzEsIGdyb3VwXzEpO1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQoZ3JvdXBlZCk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChkdXJhdGlvbikge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uU3Vic2NyaWJlcl8xID0gbmV3IE9wZXJhdG9yU3Vic2NyaWJlcihncm91cF8xLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXBfMS5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uU3Vic2NyaWJlcl8xID09PSBudWxsIHx8IGR1cmF0aW9uU3Vic2NyaWJlcl8xID09PSB2b2lkIDAgPyB2b2lkIDAgOiBkdXJhdGlvblN1YnNjcmliZXJfMS51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSwgdW5kZWZpbmVkLCB1bmRlZmluZWQsIGZ1bmN0aW9uICgpIHsgcmV0dXJuIGdyb3Vwcy5kZWxldGUoa2V5XzEpOyB9KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwQnlTb3VyY2VTdWJzY3JpYmVyLmFkZChpbm5lckZyb20oZHVyYXRpb24oZ3JvdXBlZCkpLnN1YnNjcmliZShkdXJhdGlvblN1YnNjcmliZXJfMSkpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGdyb3VwXzEubmV4dChlbGVtZW50ID8gZWxlbWVudCh2YWx1ZSkgOiB2YWx1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgaGFuZGxlRXJyb3IoZXJyKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSwgZnVuY3Rpb24gKCkgeyByZXR1cm4gbm90aWZ5KGZ1bmN0aW9uIChjb25zdW1lcikgeyByZXR1cm4gY29uc3VtZXIuY29tcGxldGUoKTsgfSk7IH0sIGhhbmRsZUVycm9yLCBmdW5jdGlvbiAoKSB7IHJldHVybiBncm91cHMuY2xlYXIoKTsgfSk7XG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUoZ3JvdXBCeVNvdXJjZVN1YnNjcmliZXIpO1xuICAgICAgICBmdW5jdGlvbiBjcmVhdGVHcm91cGVkT2JzZXJ2YWJsZShrZXksIGdyb3VwU3ViamVjdCkge1xuICAgICAgICAgICAgdmFyIHJlc3VsdCA9IG5ldyBPYnNlcnZhYmxlKGZ1bmN0aW9uIChncm91cFN1YnNjcmliZXIpIHtcbiAgICAgICAgICAgICAgICBncm91cEJ5U291cmNlU3Vic2NyaWJlci5hY3RpdmVHcm91cHMrKztcbiAgICAgICAgICAgICAgICB2YXIgaW5uZXJTdWIgPSBncm91cFN1YmplY3Quc3Vic2NyaWJlKGdyb3VwU3Vic2NyaWJlcik7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgaW5uZXJTdWIudW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgICAgICAgICAgLS1ncm91cEJ5U291cmNlU3Vic2NyaWJlci5hY3RpdmVHcm91cHMgPT09IDAgJiZcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwQnlTb3VyY2VTdWJzY3JpYmVyLnRlYXJkb3duQXR0ZW1wdGVkICYmXG4gICAgICAgICAgICAgICAgICAgICAgICBncm91cEJ5U291cmNlU3Vic2NyaWJlci51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHJlc3VsdC5rZXkgPSBrZXk7XG4gICAgICAgICAgICByZXR1cm4gcmVzdWx0O1xuICAgICAgICB9XG4gICAgfSk7XG59XG52YXIgR3JvdXBCeVN1YnNjcmliZXIgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xuICAgIF9fZXh0ZW5kcyhHcm91cEJ5U3Vic2NyaWJlciwgX3N1cGVyKTtcbiAgICB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ci5wdXNoKHZhbHVlKSk7IH07XG4gICAgdmFyIGRvSW5uZXJTdWIgPSBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgZXhwYW5kICYmIHN1YnNjcmliZXIubmV4dCh2YWx1ZSk7XG4gICAgICAgIGFjdGl2ZSsrO1xuICAgICAgICB2YXIgaW5uZXJDb21wbGV0ZSA9IGZhbHNlO1xuICAgICAgICBpbm5lckZyb20ocHJvamVjdCh2YWx1ZSwgaW5kZXgrKykpLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGZ1bmN0aW9uIChpbm5lclZhbHVlKSB7XG4gICAgICAgICAgICBvbkJlZm9yZU5leHQgPT09IG51bGwgfHwgb25CZWZvcmVOZXh0ID09PSB2b2lkIDAgPyB2b2lkIDAgOiBvbkJlZm9yZU5leHQoaW5uZXJWYWx1ZSk7XG4gICAgICAgICAgICBpZiAoZXhwYW5kKSB7XG4gICAgICAgICAgICAgICAgb3V0ZXJOZXh0KGlubmVyVmFsdWUpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KGlubmVyVmFsdWUpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICBpbm5lckNvbXBsZXRlID0gdHJ1ZTtcbiAgICAgICAgfSwgdW5kZWZpbmVkLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICBpZiAoaW5uZXJDb21wbGV0ZSkge1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIGFjdGl2ZS0tO1xuICAgICAgICAgICAgICAgICAgICB2YXIgX2xvb3BfMSA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBidWZmZXJlZFZhbHVlID0gYnVmZmVyLnNoaWZ0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpbm5lclN1YlNjaGVkdWxlciA/IHN1YnNjcmliZXIuYWRkKGlubmVyU3ViU2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHsgcmV0dXJuIGRvSW5uZXJTdWIoYnVmZmVyZWRWYWx1ZSk7IH0pKSA6IGRvSW5uZXJTdWIoYnVmZmVyZWRWYWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgICAgIHdoaWxlIChidWZmZXIubGVuZ3RoICYmIGFjdGl2ZSA8IGNvbmN1cnJlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIF9sb29wXzEoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBjaGVja0NvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNhdGNoIChlcnIpIHtcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5lcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSkpO1xuICAgIH07XG4gICAgc291cmNlLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIG91dGVyTmV4dCwgZnVuY3Rpb24gKCkge1xuICAgICAgICBpc0NvbXBsZXRlID0gdHJ1ZTtcbiAgICAgICAgY2hlY2tDb21wbGV0ZSgpO1xuICAgIH0pKTtcbiAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xuICAgICAgICBhZGRpdGlvbmFsVGVhcmRvd24gPT09IG51bGwgfHwgYWRkaXRpb25hbFRlYXJkb3duID09PSB2b2lkIDAgPyB2b2lkIDAgOiBhZGRpdGlvbmFsVGVhcmRvd24oKTtcbiAgICB9O1xufVxuLy8jIHNvdXJjZU1hcHBpbmdVUkw9bWVyZ2VJbnRlcm5hbHMuanMubWFwIiwiaW1wb3J0IHsgbWFwIH0gZnJvbSAnLi9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ICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVOZXh0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgdmFyIGlubmVyU3ViID0gbmV3IE9wZXJhdG9yU3Vic2NyaWJlcihzdWJzY3JpYmVyLCB1bmRlZmluZWQsIG5vb3AsIG5vb3ApO1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLmFkZChuZXh0U291cmNlLnN1YnNjcmliZShpbm5lclN1YikpO1xuICAgICAgICAgICAgICAgICAgICBpbm5lclN1Yi5hZGQoc3Vic2NyaWJlTmV4dCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICBzdWJzY3JpYmVOZXh0KCk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1vbkVycm9yUmVzdW1lTmV4dC5qcy5tYXAiLCJpbXBvcnQgeyBvcGVyYXRlIH0gZnJvbSAnLi4vdXRpbC9saWZ0JztcbmltcG9ydCB7IE9wZXJhdG9yU3Vic2NyaWJlciB9IGZyb20gJy4vT3BlcmF0b3JTdWJzY3JpYmVyJztcbmV4cG9ydCBmdW5jdGlvbiBwYWlyd2lzZSgpIHtcbiAgICByZXR1cm4gb3BlcmF0ZShmdW5jdGlvbiAoc291cmNlLCBzdWJzY3JpYmVyKSB7XG4gICAgICAgIHZhciBwcmV2O1xuICAgICAgICB2YXIgaGFzUHJldiA9IGZhbHNlO1xuICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic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ZShmdW5jdGlvbiAoc291cmNlLCBzdWJzY3JpYmVyKSB7XG4gICAgICAgICAgICB2YXIgc29GYXIgPSAwO1xuICAgICAgICAgICAgdmFyIGlubmVyU3ViO1xuICAgICAgICAgICAgdmFyIHN1YnNjcmliZUZvclJlcGVhdCA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICB2YXIgc3luY1Vuc3ViID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgaW5uZXJTdWIgPSBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgdW5kZWZpbmVkLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICgrK3NvRmFyIDwgY291bnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbm5lclN1Yikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyU3ViLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJTdWIgPSBudWxsO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZUZvclJlcGVhdCgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgc3luY1Vuc3ViID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICBpZiAoc3luY1Vuc3ViKSB7XG4gICAgICAgICAgICAgICAgICAgIGlubmVyU3ViLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICA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3QoKTtcbiAgICAgICAgICAgICAgICBub3RpZmllcihjb21wbGV0aW9ucyQpLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlubmVyU3ViKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVGb3JSZXBlYXRXaGVuKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzeW5jUmVzdWIgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICBpc05vdGlmaWVyQ29tcGxldGUgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICBjaGVja0NvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGNvbXBsZXRpb25zJDtcbiAgICAgICAgfTtcbiAgICAgICAgdmFyIHN1YnNjcmliZUZvclJlcGVhdFdoZW4gPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICBpc01haW5Db21wbGV0ZSA9IGZhbHNlO1xuICAgICAgICAgICAgaW5uZXJTdWIgPSBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgdW5kZWZpbmVkLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgaXNNYWluQ29tcGxldGUgPSB0cnVlO1xuICAgICAgICAgICAgICAgICFjaGVja0NvbXBsZXRlKCkgJiYgZ2V0Q29tcGxldGlvblN1YmplY3QoKS5uZXh0KCk7XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICBpZiAoc3luY1Jlc3ViKSB7XG4gICAgICAgICAgICAgICAgaW5uZXJTdWIudW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgICAgICBpbm5lclN1YiA9IG51bGw7XG4gICAgICAgICAgICAgICAgc3luY1Jlc3ViID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlRm9yUmVwZWF0V2hlbigpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICBzdWJzY3JpYmVGb3JSZXBlYXRXaGVuKCk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1yZXBlYXRXaGVuLmpzLm1hcCIsImltcG9ydCB7IG9wZXJhdGUgfSBmcm9tICcuLi91dGlsL2xpZnQnO1xuaW1wb3J0IHsgT3BlcmF0b3JTdWJzY3JpYmVyIH0gZnJvbSAnLi9PcGVyYXRvclN1YnNjcmliZXInO1xuaW1wb3J0IHsgaWRlbnRpdHkgfSBmcm9tICcuLi91dGlsL2lkZW50aXR5JztcbmV4cG9ydCBmdW5jdGlvbiByZXRyeShjb25maWdPckNvdW50KSB7XG4gICAgaWYgKGNvbmZpZ09yQ291bnQgPT09IHZvaWQgMCkgeyBjb25maWdPckNvdW50ID0gSW5maW5pdHk7IH1cbiAgICB2YXIgY29uZmlnO1xuICAgIGlmIChjb25maWdPckNvdW50ICYmIHR5cGVvZiBjb25maWdPckNvdW50ID09PSAnb2JqZWN0Jykge1xuICAgICAgICBjb25maWcgPSBjb25maWdPckNvdW50O1xuICAgIH1cbiAgICBlbHNlIHtcbiAgICAgICAgY29uZmlnID0ge1xuICAgICAgICAgICAgY291bnQ6IGNvbmZpZ09yQ291bnQsXG4gICAgICAgIH07XG4gICAgfVxuICAgIHZhciBjb3VudCA9IGNvbmZpZy5jb3VudCwgX2EgPSBjb25maWcucmVzZXRPblN1Y2Nlc3MsIHJlc2V0T25TdWNjZXNzID0gX2EgPT09IHZvaWQgMCA/IGZhbHNlIDogX2E7XG4gICAgcmV0dXJuIGNvdW50IDw9IDBcbiAgICAgICAgPyBpZGVudGl0eVxuICAgICAgICA6IG9wZXJhdGUoZnVuY3Rpb24gKHNvdXJjZSwgc3Vic2NyaWJlcikge1xuICAgICAgICAgICAgdmFyIHNvRmFyID0gMDtcbiAgICAgICAgICAgIHZhciBpbm5lclN1YjtcbiAgICAgICAgICAgIHZhciBzdWJzY3JpYmVGb3JSZXRyeSA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICB2YXIgc3luY1Vuc3ViID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgaW5uZXJTdWIgPSBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChyZXNldE9uU3VjY2Vzcykge1xuICAgICAgICAgICAgICAgICAgICAgICAgc29GYXIgPSAwO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgfSwgdW5kZWZpbmVkLCBmdW5jdGlvbiAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChzb0ZhcisrIDwgY291bnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbm5lclN1Yikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyU3ViLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJTdWIgPSBudWxsO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZUZvclJldHJ5KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzeW5jVW5zdWIgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5lcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgICAgIGlmIChzeW5jVW5zdWIpIHtcbiAgICAgICAgICAgICAgICAgICAgaW5uZXJTdWIudW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgICAgICAgICAgaW5uZXJTdWIgPSBudWxsO1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVGb3JSZXRyeSgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICBzdWJzY3JpYmVGb3JSZXRyeSgpO1xuICAgICAgICB9KTtcbn1cbi8vIyBzb3VyY2VNYXBwaW5nVVJMPXJldHJ5LmpzLm1hcCIsImltcG9ydCB7IFN1YmplY3QgfSBmcm9tICcuLi9TdWJqZWN0JztcbmltcG9ydCB7IG9wZXJhdGUgfSBmcm9tICcuLi91dGlsL2xpZnQnO1xuaW1wb3J0IHsgT3BlcmF0b3JTdWJzY3JpYmVyIH0gZnJvbSAnLi9PcGVyYXRvclN1YnNjcmliZXInO1xuZXhwb3J0IGZ1bmN0aW9uIHJldHJ5V2hlbihub3RpZmllcikge1xuICAgIHJldHVybiBvcGVyYXRlKGZ1bmN0aW9uIChzb3VyY2UsIHN1YnNjcmliZXIpIHtcbiAgICAgICAgdmFyIGlubmVyU3ViO1xuICAgICAgICB2YXIgc3luY1Jlc3ViID0gZmFsc2U7XG4gICAgICAgIHZhciBlcnJvcnMkO1xuICAgICAgICB2YXIgc3Vic2NyaWJlRm9yUmV0cnlXaGVuID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgaW5uZXJTdWIgPSBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgdW5kZWZpbmVkLCB1bmRlZmluZWQsIGZ1bmN0aW9uIChlcnIpIHtcbiAgICAgICAgICAgICAgICBpZiAoIWVycm9ycyQpIHtcbiAgICAgICAgICAgICAgICAgICAgZXJyb3JzJCA9IG5ldyBTdWJqZWN0KCk7XG4gICAgICAgICAgICAgICAgICAgIG5vdGlmaWVyKGVycm9ycyQpLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBpbm5lclN1YiA/IHN1YnNjcmliZUZvclJldHJ5V2hlbigpIDogKHN5bmNSZXN1YiA9IHRydWUpO1xuICAgICAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChlcnJvcnMkKSB7XG4gICAgICAgICAgICAgICAgICAgIGVycm9ycyQubmV4dChlcnIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgIGlmIChzeW5jUmVzdWIpIHtcbiAgICAgICAgICAgICAgICBpbm5lclN1Yi51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgICAgIGlubmVyU3ViID0gbnVsbDtcbiAgICAgICAgICAgICAgICBzeW5jUmVzdWIgPSBmYWxzZTtcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVGb3JSZXRyeVdoZW4oKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgICAgc3Vic2NyaWJlRm9yUmV0cnlXaGVuKCk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1yZXRyeVdoZW4uanMubWFwIiwiaW1wb3J0IHsgb3BlcmF0ZSB9IGZyb20gJy4uL3V0aWwvbGlmdCc7XG5pbXBvcnQgeyBub29wIH0gZnJvbSAnLi4vdXRpbC9ub29wJztcbmltcG9ydCB7IE9wZXJhdG9yU3Vic2NyaWJlciB9IGZyb20gJy4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ICAgICAgIHZhciBiU3RhdGUgPSBjcmVhdGVTdGF0ZSgpO1xuICAgICAgICB2YXIgZW1pdCA9IGZ1bmN0aW9uIChpc0VxdWFsKSB7XG4gICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQoaXNFcXVhbCk7XG4gICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgIH07XG4gICAgICAgIHZhciBjcmVhdGVTdWJzY3JpYmVyID0gZnVuY3Rpb24gKHNlbGZTdGF0ZSwgb3RoZXJTdGF0ZSkge1xuICAgICAgICAgICAgdmFyIHNlcXVlbmNlRXF1YWxTdWJzY3JpYmVyID0gbmV3IE9wZXJhdG9yU3Vic2NyaWJlcihzdWJzY3JpYmVyLCBmdW5jdGlvbiAoYSkge1xuICAgICAgICAgICAgICAgIHZhciBidWZmZXIgPSBvdGhlclN0YXRlLmJ1ZmZlciwgY29tcGxldGUgPSBvdGhlclN0YXRlLmNvbXBsZXRlO1xuICAgICAgICAgICAgICAgIGlmIChidWZmZXIubGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbXBsZXRlID8gZW1pdChmYWxzZSkgOiBzZWxmU3RhdGUuYnVmZmVyLnB1c2goYSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAhY29tcGFyYXRvcihhLCBidWZmZXIuc2hpZnQoKSkgJiYgZW1pdChmYWxzZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHNlbGZTdGF0ZS5jb21wbGV0ZSA9IHRydWU7XG4gICAgICAgICAgICAgICAgdmFyIGNvbXBsZXRlID0gb3RoZXJTdGF0ZS5jb21wbGV0ZSwgYnVmZmVyID0gb3RoZXJTdGF0ZS5idWZmZXI7XG4gICAgICAgICAgICAgICAgY29tcGxldGUgJiYgZW1pdChidWZmZXIubGV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KCkge1xuICAgICAgICAgICAgY2FuY2VsUmVzZXQoKTtcbiAgICAgICAgICAgIGNvbm5lY3Rpb24gPSBzdWJqZWN0ID0gbnVsbDtcbiAgICAgICAgICAgIGhhc0NvbXBsZXRlZCA9IGhhc0Vycm9yZWQgPSBmYWxzZTtcbiAgICAgICAgfTtcbiAgICAgICAgdmFyIHJlc2V0QW5kVW5zdWJzY3JpYmUgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICB2YXIgY29ubiA9IGNvbm5lY3Rpb247XG4gICAgICAgICAgICByZXNldCgpO1xuICAgICAgICAgICAgY29ubiA9PT0gbnVsbCB8fCBjb25uID09PSB2b2lkIDAgPyB2b2lkIDAgOiBjb25uLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgIH07XG4gICAgICAgIHJldHVybiBvcGVyYXRlKGZ1bmN0aW9uIChzb3VyY2UsIHN1YnNjcmliZXIpIHtcbiAgICAgICAgICAgIHJlZkNvdW50Kys7XG4gICAgICAgICAgICBpZiAoIWhhc0Vycm9yZWQgJiYgIWhhc0NvbXBsZXRlZCkge1xuICAgICAgICAgICAgICAgIGNhbmNlbFJlc2V0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgZGVzdCA9IChzdWJqZWN0ID0gc3ViamVjdCAhPT0gbnVsbCAmJiBzdWJqZWN0ICE9PSB2b2lkIDAgPyBzdWJqZWN0IDogY29ubmVjdG9yKCkpO1xuICAgICAgICAgICAgc3Vic2NyaWJlci5hZGQoZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHJlZkNvdW50LS07XG4gICAgICAgICAgICAgICAgaWYgKHJlZkNvdW50ID09PSAwICYmICFoYXNFcnJvcmVkICYmICFoYXNDb21wbGV0ZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzZXRDb25uZWN0aW9uID0gaGFuZGxlUmVzZXQocmVzZXRBbmRVbnN1YnNjcmliZSwgcmVzZXRPblJlZkNvdW50WmVybyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICBkZXN0LnN1YnNjcmliZShzdWJzY3JpYmVyKTtcbiAgICAgICAgICAgIGlmICghY29ubmVjdGlvbikge1xuICAgICAgICAgICAgICAgIGNvbm5lY3Rpb24gPSBuZXcgU2FmZVN1YnNjcmliZXIoe1xuICAgICAgICAgICAgICAgICAgICBuZXh0OiBmdW5jdGlvbiAodmFsdWUpIHsgcmV0dXJuIGRlc3QubmV4dCh2YWx1ZSk7IH0sXG4gICAgICAgICAgICAgICAgICAgIGVycm9yOiBmdW5jdGlvbiAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBoYXNFcnJvcmVkID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNhbmNlbFJlc2V0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXNldENvbm5lY3Rpb24gPSBoYW5kbGVSZXNldChyZXNldCwgcmVzZXRPbkVycm9yLCBlcnIpO1xuICAgICAgICAgICAgICAgICAgICAgICAgZGVzdC5lcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgICBjb21wbGV0ZTogZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaGFzQ29tcGxldGVkID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNhbmNlbFJlc2V0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXNldENvbm5lY3Rpb24gPSBoYW5kbGVSZXNldChyZXNldCwgcmVzZXRPbkNvbXBsZXRlKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlc3QuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICBmcm9tKHNvdXJjZSkuc3Vic2NyaWJlKGNvbm5lY3Rpb24pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KSh3cm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AgICB2YXIgdmFsdWVJbmRleCA9IHNlZW4rKztcbiAgICAgICAgICAgICAgICBpZiAodmFsdWVJbmRleCA8IHNraXBDb3VudCkge1xuICAgICAgICAgICAgICAgICAgICByaW5nW3ZhbHVlSW5kZXhdID0gdmFsdWU7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB2YXIgaW5kZXggPSB2YWx1ZUluZGV4ICUgc2tpcENvdW50O1xuICAgICAgICAgICAgICAgICAgICB2YXIgb2xkVmFsdWUgPSByaW5nW2luZGV4XTtcbiAgICAgICAgICAgICAgICAgICAgcmluZ1tpbmRleF0gPSB2YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KG9sZFZhbHVlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHJpbmcgPSBudWxsO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1za2lwTGFzdC5qcy5tYXAiLCJpbXBvcnQgeyBvcGVyYXRlIH0gZnJvbSAnLi4vdXRpbC9saWZ0JztcbmltcG9ydCB7IE9wZXJhdG9yU3Vic2NyaWJlciB9IGZyb20gJy4vT3BlcmF0b3JTdWJzY3JpYmVyJztcbmltcG9ydCB7IGlubmVyRnJvbSB9IGZyb20gJy4uL29ic2VydmFibGUvZnJvbSc7XG5pbXBvcnQgeyBub29wIH0gZnJvbSAnLi4vdXRpbC9ub29wJztcbmV4cG9ydCBmdW5jdGlvbiBza2lwVW50aWwobm90aWZpZXIpIHtcbiAgICByZXR1cm4gb3BlcmF0ZShmdW5jdGlvbiAoc291cmNlLCBzdWJzY3JpYmVyKSB7XG4gICAgICAgIHZhciB0YWtpbmcgPSBmYWxzZTtcbiAgICAgICAgdmFyIHNraXBTd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mYWxzZTtcbiAgICAgICAgdmFyIHNlbmRWYWx1ZSA9IG51bGw7XG4gICAgICAgIHZhciB0aHJvdHRsZWQgPSBudWxsO1xuICAgICAgICB2YXIgaXNDb21wbGV0ZSA9IGZhbHNlO1xuICAgICAgICB2YXIgZW5kVGhyb3R0bGluZyA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIHRocm90dGxlZCA9PT0gbnVsbCB8fCB0aHJvdHRsZWQgPT09IHZvaWQgMCA/IHZvaWQgMCA6IHRocm90dGxlZC51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgdGhyb3R0bGVkID0gbnVsbDtcbiAgICAgICAgICAgIGlmICh0cmFpbGluZykge1xuICAgICAgICAgICAgICAgIHNlbmQoKTtcbiAgICAgICAgICAgICAgICBpc0NvbXBsZXRlICYmIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgICAgdmFyIGNsZWFudXBUaHJvdHRsaW5nID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgdGhyb3R0bGVkID0gbnVsbDtcbiAgICAgICAgICAgIGlzQ29tcGxldGUgJiYgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICB9O1xuICAgICAgICB2YXIgc3RhcnRUaHJvdHRsZSA9IGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgcmV0dXJuICh0aHJvdHRsZWQgPSBpbm5lckZyb20oZHVyYXRpb25TZWxlY3Rvcih2YWx1ZSkpLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGVuZFRocm90dGxpbmcsIGNsZWFudXBUaHJvdHRsaW5nKSkpO1xuICAgICAgICB9O1xuICAgICAgICB2YXIgc2VuZCA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIGlmIChoYXNWYWx1ZSkge1xuICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gZm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yeSA6IHdpbmRvd1NpemU7XG4gICAgcmV0dXJuIG9wZXJhdGUoZnVuY3Rpb24gKHNvdXJjZSwgc3Vic2NyaWJlcikge1xuICAgICAgICB2YXIgd2luZG93cyA9IFtuZXcgU3ViamVjdCgpXTtcbiAgICAgICAgdmFyIHN0YXJ0cyA9IFtdO1xuICAgICAgICB2YXIgY291bnQgPSAwO1xuICAgICAgICBzdWJzY3JpYmVyLm5leHQod2luZG93c1swXS5hc09ic2VydmFibGUoKSk7XG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUobmV3IE9wZXJhdG9yU3Vic2NyaWJlcihzdWJzY3JpYmVyLCBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgICAgIHZhciBlXzEsIF9hO1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciB3aW5kb3dzXzEgPSBfX3ZhbHVlcyh3aW5kb3dzKSwgd2luZG93c18xXzEgPSB3aW5kb3dzXzEubmV4dCgpOyAhd2luZG93c18xXzEuZG9uZTsgd2luZG93c18xXzEgPSB3aW5kb3dzXzEubmV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciB3aW5kb3dfMSA9IHdpbmRvd3NfMV8xLnZhbHVlO1xuICAgICAgICAgICAgICAgICAgICB3aW5kb3dfMS5uZXh0KHZhbHVlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjYXRjaCAoZV8xXzEpIHsgZV8xID0geyBlcnJvcjogZV8xXzEgfTsgfVxuICAgICAgICAgICAgZmluYWxseSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHdpbmRvd3NfMV8xICYmICF3aW5kb3dzXzFfMS5kb25lICYmIChfYSA9IHdpbmRvd3NfMS5yZXR1cm4pKSBfYS5jYWxsKHdpbmRvd3NfMSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkgeyBpZiAoZV8xKSB0aHJvdyBlXzEuZXJyb3I7IH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBjID0gY291bnQgLSB3aW5kb3dTaXplICsgMTtcbiAgICAgICAgICAgIGlmIChjID49IDAgJiYgYyAlIHN0YXJ0RXZlcnkgPT09IDApIHtcbiAgICAgICAgICAgICAgICB3aW5kb3dzLnNoaWZ0KCkuY29tcGxldGUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICgrK2NvdW50ICUgc3RhcnRFdmVyeSA9PT0gMCkge1xuICAgICAgICAgICAgICAgIHZhciB3aW5kb3dfMiA9IG5ldyBTdWJqZWN0KCk7XG4gICAgICAgICAgICAgICAgd2luZG93cy5wdXNoKHdpbmRvd18yKTtcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQod2luZG93XzIuYXNPYnNlcnZhYmxlKCkpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICB3aGlsZSAod2luZG93cy5sZW5ndGggPiAwKSB7XG4gICAgICAgICAgICAgICAgd2luZG93cy5zaGlmdCgpLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgIH0sIGZ1bmN0aW9uIChlcnIpIHtcbiAgICAgICAgICAgIHdoaWxlICh3aW5kb3dzLmxlbmd0aCA+IDApIHtcbiAgICAgICAgICAgICAgICB3aW5kb3dzLnNoaWZ0KCkuZXJyb3IoZXJyKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHN1YnNjcmliZXIuZXJyb3IoZXJyKTtcbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgc3RhcnRzID0gbnVsbDtcbiAgICAgICAgICAgIHdpbmRvd3MgPSBudWxsO1xuICAgICAgICB9KSk7XG4gICAgfSk7XG59XG4vL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dHk7XG4gICAgcmV0dXJuIG9wZXJhdGUoZnVuY3Rpb24gKHNvdXJjZSwgc3Vic2NyaWJlcikge1xuICAgICAgICB2YXIgd2luZG93UmVjb3JkcyA9IFtdO1xuICAgICAgICB2YXIgcmVzdGFydE9uQ2xvc2UgPSBmYWxzZTtcbiAgICAgICAgdmFyIGNsb3NlV2luZG93ID0gZnVuY3Rpb24gKHJlY29yZCkge1xuICAgICAgICAgICAgdmFyIHdpbmRvdyA9IHJlY29yZC53aW5kb3csIHN1YnMgPSByZWNvcmQuc3VicztcbiAgICAgICAgICAgIHdpbmRvdy5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgc3Vicy51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgYXJyUmVtb3ZlKHdpbmRvd1JlY29yZHMsIHJlY29yZCk7XG4gICAgICAgICAgICByZXN0YXJ0T25DbG9zZSAmJiBzdGFydFdpbmRvdygpO1xuICAgICAgICB9O1xuICAgICAgICB2YXIgc3RhcnRXaW5kb3cgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICBpZiAod2luZG93UmVjb3Jkcykge1xuICAgICAgICAgICAgICAgIHZhciBzdWJzID0gbmV3IFN1YnNjcmlwdGlvbigpO1xuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIuYWRkKHN1YnMpO1xuICAgICAgICAgICAgICAgIHZhciB3aW5kb3dfMSA9IG5ldyBTdWJqZWN0KCk7XG4gICAgICAgICAgICAgICAgdmFyIHJlY29yZF8xID0ge1xuICAgICAgICAgICAgICAgICAgICB3aW5kb3c6IHdpbmRvd18xLFxuICAgICAgICAgICAgICAgICAgICBzdWJzOiBzdWJzLFxuICAgICAgICAgICAgICAgICAgICBzZWVuOiAwLFxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgd2luZG93UmVjb3Jkcy5wdXNoKHJlY29yZF8xKTtcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQod2luZG93XzEuYXNPYnNlcnZhYmxlKCkpO1xuICAgICAgICAgICAgICAgIHN1YnMuYWRkKHNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7IHJldHVybiBjbG9zZVdpbmRvdyhyZWNvcmRfMSk7IH0sIHdpbmRvd1RpbWVTcGFuKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIHdpbmRvd0NyZWF0aW9uSW50ZXJ2YWwgIT09IG51bGwgJiYgd2luZG93Q3JlYXRpb25JbnRlcnZhbCA+PSAwXG4gICAgICAgICAgICA/XG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlci5hZGQoc2NoZWR1bGVyLnNjaGVkdWxlKGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgc3RhcnRXaW5kb3coKTtcbiAgICAgICAgICAgICAgICAgICAgIXRoaXMuY2xvc2VkICYmIHN1YnNjcmliZXIuYWRkKHRoaXMuc2NoZWR1bGUobnVsbCwgd2luZG93Q3JlYXRpb25JbnRlcnZhbCkpO1xuICAgICAgICAgICAgICAgIH0sIHdpbmRvd0NyZWF0aW9uSW50ZXJ2YWwpKVxuICAgICAgICAgICAgOiAocmVzdGFydE9uQ2xvc2UgPSB0cnVlKTtcbiAgICAgICAgc3RhcnRXaW5kb3coKTtcbiAgICAgICAgdmFyIGxvb3AgPSBmdW5jdGlvbiAoY2IpIHsgcmV0dXJuIHdpbmRvd1JlY29yZHMuc2xpY2UoKS5mb3JFYWNoKGNiKTsgfTtcbiAgICAgICAgdmFyIHRlcm1pbmF0ZSA9IGZ1bmN0aW9uIChjYikge1xuICAgICAgICAgICAgbG9vcChmdW5jdGlvbiAoX2EpIHtcbiAgICAgICAgICAgICAgICB2YXIgd2luZG93ID0gX2Eud2luZG93O1xuICAgICAgICAgICAgICAgIHJldHVybiBjYih3aW5kb3cpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICBjYihzdWJzY3JpYmVyKTtcbiAgICAgICAgICAgIHN1YnNjcmliZXIudW5z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AgICAgICAgIGNsb3NpbmdTdWJzY3JpcHRpb24udW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICB2YXIgY2xvc2luZ05vdGlmaWVyO1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBjbG9zaW5nTm90aWZpZXIgPSBpbm5lckZyb20oY2xvc2luZ1NlbGVjdG9yKG9wZW5WYWx1ZSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICAgIGhhbmRsZUVycm9yKGVycik7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KHdpbmRvdy5hc09ic2VydmFibGUoKSk7XG4gICAgICAgICAgICBjbG9zaW5nU3Vic2NyaXB0aW9uLmFkZChjbG9zaW5nTm90aWZpZXIuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgY2xvc2VXaW5kb3csIG5vb3AsIGhhbmRsZUVycm9yKSkpO1xuICAgICAgICB9LCBub29wKSk7XG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUobmV3IE9wZXJhdG9yU3Vic2NyaWJlcihzdWJzY3JpYmVyLCBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgICAgIHZhciBlXzEsIF9hO1xuICAgICAgICAgICAgdmFyIHdpbmRvd3NDb3B5ID0gd2luZG93cy5zbGljZSgpO1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciB3aW5kb3dzQ29weV8xID0gX192YWx1ZXMod2luZG93c0NvcHkpLCB3aW5kb3dzQ29weV8xXzEgPSB3aW5kb3dzQ29weV8xLm5leHQoKTsgIXdpbmRvd3NDb3B5XzFfMS5kb25lOyB3aW5kb3dzQ29weV8xXzEgPSB3aW5kb3dzQ29weV8xLm5leHQoKSkge1xuICAgICAgICAgICAgICAgICAgICB2YXIgd2luZG93XzEgPSB3aW5kb3dzQ29weV8xXzEudmFsdWU7XG4gICAgICAgICAgICAgICAgICAgIHdpbmRvd18xLm5leHQodmFsdWUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGNhdGNoIChlXzFfMSkgeyBlXzEgPSB7IGVycm9yOiBlXzFfMSB9OyB9XG4gICAgICAgICAgICBmaW5hbGx5IHtcbiAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICBpZiAod2luZG93c0NvcHlfMV8xICYmICF3aW5kb3dzQ29weV8xXzEuZG9uZSAmJiAoX2EgPSB3aW5kb3dzQ29weV8xLnJldHVybikpIF9hLmNhbGwod2luZG93c0NvcHlfMSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkgeyBpZiAoZV8xKSB0aHJvdyBlXzEuZXJyb3I7IH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgd2hpbGUgKDAgPCB3aW5kb3dzLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgIHdpbmRvd3Muc2hpZnQoKS5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICB9LCBoYW5kbGVFcnJvciwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgd2hpbGUgKDAgPCB3aW5kb3dzLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgIHdpbmRvd3Muc2hpZnQoKS51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KSk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD13aW5kb3dUb2dnbGUuanMubWFwIiwiaW1wb3J0IHsgU3ViamVjdCB9IGZyb20gJy4uL1N1YmplY3QnO1xuaW1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IGlmICghaW5wdXQpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdJdGVyYWJsZSBjYW5ub3QgYmUgbnVsbCcpO1xuICAgIH1cbiAgICByZXR1cm4gbmV3IE9ic2VydmFibGUoZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcbiAgICAgICAgdmFyIHN1YiA9IG5ldyBTdWJzY3JpcHRpb24oKTtcbiAgICAgICAgc3ViLmFkZChzY2hlZHVsZXIuc2NoZWR1bGUoZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgdmFyIGl0ZXJhdG9yID0gaW5wdXRbU3ltYm9sLmFzeW5jSXRlcmF0b3JdKCk7XG4gICAgICAgICAgICBzdWIuYWRkKHNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgdmFyIF90aGlzID0gdGhpcztcbiAgICAgICAgICAgICAgICBpdGVyYXRvci5uZXh0KCkudGhlbihmdW5jdGlvbiAocmVzdWx0KSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChyZXN1bHQuZG9uZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KHJlc3VsdC52YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpcy5zY2hlZHVsZSgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgIH0pKTtcbiAgICAgICAgcmV0dXJuIHN1YjtcbiAgICB9KTtcbn1cbi8vIyBzb3VyY2VNYXBwaW5nVVJMPXNjaGVkdWxlQXN5bmNJdGVyYWJsZS5qcy5tYXAiLCJpbXBvcnQgeyBPYnNlcnZhYmxlIH0gZnJvbSAnLi4vT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XG4vLyMgc291cmNlTWFwcGluZ1VSTD1jcmVhdGVPYmplY3QuanMubWFwIiwiaW1wb3J0IHsgY29uZmlnIH0gZnJvbSAnLi4vY29uZmlnJztcbnZhciBjb250ZXh0ID0gbnVsbDtcbmV4cG9ydCBmdW5jdGlvbiBlcnJvckNvbnRleHQoY2IpIHtcbiAgICBpZiAoY29uZmlnLnVzZURlcHJlY2F0ZWRTeW5jaHJvbm91c0Vycm9ySGFuZGxpbmcpIHtcbiAgICAgICAgdmFyIGlzUm9vdCA9ICFjb250ZXh0O1xuICAgICAgICBpZiAoaXNSb290KSB7XG4gICAgICAgICAgICBjb250ZXh0ID0geyBlcnJvclRocm93bjogZmFsc2UsIGVycm9yOiBudWxsIH07XG4gICAgICAgIH1cbiAgICAgICAgY2IoKTtcbiAgICAgICAgaWYgKGlzUm9vdCkge1xuICAgICAgICAgICAgdmFyIF9hID0gY29udGV4dCwgZXJyb3JUaHJvd24gPSBfYS5lcnJvclRocm93biwgZXJyb3IgPSBfYS5lcnJvcjtcbiAgICAgICAgICAgIGNvbnRleHQgPSBudWxsO1xuICAgICAgICAgICAgaWYgKGVycm9yVGhyb3duKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgZXJyb3I7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgZWxzZSB7XG4gICAgICAgIGNiKCk7XG4gICAgfVxufVxuZXhwb3J0IGZ1bmN0aW9uIGNhcHR1cmVFcnJvcihlcnIpIHtcbiAgICBpZiAoY29uZmlnLnVzZURlcHJlY2F0ZWRTeW5jaHJvbm91c0Vycm9ySGFuZGxpbmcgJiYgY29udGV4dCkge1xuICAgICAgICBjb250ZXh0LmVycm9yVGhyb3duID0gdHJ1ZTtcbiAgICAgICAgY29udGV4dC5lcnJvciA9IGVycjtcbiAgICB9XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1lcnJvckNvbnRleHQuanMubWFwIiwiZXhwb3J0IGZ1bmN0aW9uIGlkZW50aXR5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gICAgICAgICAgICAgICAgICBpZiAoIXRydWUpIHJldHVybiBbMywgOF07XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBbNCwgX19hd2FpdChyZWFkZXIucmVhZCgpKV07XG4gICAgICAgICAgICAgICAgY2FzZSAzOlxuICAgICAgICAgICAgICAgICAgICBfYSA9IF9iLnNlbnQoKSwgdmFsdWUgPSBfYS52YWx1ZSwgZG9uZSA9IF9hLmRvbmU7XG4gICAgICAgICAgICAgICAgICAgIGlmICghZG9uZSkgcmV0dXJuIFszLCA1XTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFs0LCBfX2F3YWl0KHZvaWQgMCldO1xuICAgICAgICAgICAgICAgIGNhc2UgNDogcmV0dXJuIFsyLCBfYi5zZW50KCldO1xuICAgICAgICAgICAgICAgIGNhc2UgNTogcmV0dXJuIFs0LCBfX2F3YWl0KHZhbHVlKV07XG4gICAgICAgICAgICAgICAgY2FzZSA2OiByZXR1cm4gWzQsIF9iLnNlbnQoKV07XG4gICAgICAgICAgICAgICAgY2FzZSA3OlxuICAgICAgICAgICAgICAgICAgICBfYi5zZW50KCk7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBbMywgMl07XG4gICAgICAgICAgICAgICAgY2FzZSA4OiByZXR1cm4gWzMsIDEwXTtcbiAgICAgICAgICAgICAgICBjYXNlIDk6XG4gICAgICAgICAgICAgICAgICAgIHJlYWRlci5yZWxlYXNlTG9jaygpO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gWzddO1xuICAgICAgICAgICAgICAgIGNhc2UgMTA6IHJldHVybiBbMl07XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH0pO1xufVxuZXhwb3J0IGZ1bmN0aW9uIGlzUmVhZGFibGVTdHJlYW1MaWtlKG9iaikge1xuICAgIHJldHVybiBpc0Z1bmN0aW9uKG9iaiA9PT0gbnVsbCB8fCBvYmogPT09IHZvaWQgMCA/IHZvaWQgMCA6IG9iai5nZXRSZWFkZX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UpIHtcbiAgICAgIGNhc2UgJ3N0cmluZyc6XG4gICAgICAgIHJldHVybiBzdHJFc2NhcGUodmFsdWUpXG4gICAgICBjYXNlICdvYmplY3QnOiB7XG4gICAgICAgIGlmICh2YWx1ZSA9PT0gbnVsbCkge1xuICAgICAgICAgIHJldHVybiAnbnVsbCdcbiAgICAgICAgfVxuICAgICAgICBpZiAoc3RhY2suaW5kZXhPZih2YWx1ZSkgIT09IC0xKSB7XG4gICAgICAgICAgcmV0dXJuIGNpcmN1bGFyVmFsdWVcbiAgICAgICAgfVxuXG4gICAgICAgIGxldCByZXMgPSAnJ1xuICAgICAgICBsZXQgam9pbiA9ICcsJ1xuICAgICAgICBjb25zdCBvcmlnaW5hbEluZGVudGF0aW9uID0gaW5kZW50YXRpb25cblxuICAgICAgICBpZiAoQXJyYXkuaXNBcnJheSh2YWx1ZSkpIHtcbiAgICAgICAgICBpZiAodmFsdWUubGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgICByZXR1cm4gJ1tdJ1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAobWF4aW11bURlcHRoIDwgc3RhY2subGVuZ3RoICsgMSkge1xuICAgICAgICAgICAgcmV0dXJuICdcIltBcnJheV1cIidcbiAgICAgICAgICB9XG4gICAgICAgICAgc3RhY2sucHVzaCh2YWx1ZSlcbiAgICAgICAgICBpZiAoc3BhY2VyICE9PSAnJykge1xuICAgICAgICAgICAgaW5kZW50YXRpb24gKz0gc3BhY2VyXG4gICAgICAgICAgICByZXMgKz0gYFxcbiR7aW5kZW50YXRpb259YFxuICAgICAgICAgICAgam9pbiA9IGAsXFxuJHtpbmRlbnRhdGlvbn1gXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnN0IG1heGltdW1WYWx1ZXNUb1N0cmluZ2lmeSA9IE1hdGgubWluKHZhbHVlLmxlbmd0aCwgbWF4aW11bUJyZWFkdGgpXG4gICAgICAgICAgbGV0IGkgPSAwXG4gICAgICAgICAgZm9yICg7IGkgPCBtYXhpbXVtVmFsdWVzVG9TdHJpbmdpZnkgLSAxOyBpKyspIHtcbiAgICAgICAgICAgIGNvbnN0IHRtcCA9IHN0cmluZ2lmeUZuUmVwbGFjZXIoU3RyaW5nKGkpLCB2YWx1ZSwgc3RhY2ssIHJlcGxhY2VyLCBzcGFjZXIsIGluZGVudGF0aW9uKVxuICAgICAgICAgICAgcmVzICs9IHRtcCAhPT0gdW5kZWZpbmVkID8gdG1wIDogJ251bGwnXG4gICAgICAgICAgICByZXMgKz0gam9pblxuICAgICAgICAgIH1cbiAgICAgICAgICBjb25zdCB0bXAgPSBzdHJpbmdpZnlGblJlcGxhY2VyKFN0cmluZyhpKSwgdmFsdWUsIHN0YWNrLCByZXBsYWNlciwgc3BhY2VyLCBpbmRlbnRhdGlvbilcbiAgICAgICAgICByZXMgKz0gdG1wICE9PSB1bmRlZmluZWQgPyB0bXAgOiAnbnVsbCdcbiAgICAgICAgICBpZiAodmFsdWUubGVuZ3RoIC0gMSA+IG1heGltdW1CcmVhZHRoKSB7XG4gICAgICAgICAgICBjb25zdCByZW1vdmVkS2V5cyA9IHZhbHVlLmxlbmd0aCAtIG1heGltdW1CcmVhZHRoIC0gMVxuICAgICAgICAgICAgcmVzICs9IGAke2pvaW59XCIuLi4gJHtnZXRJdGVtQ291bnQocmVtb3ZlZEtleXMpfSBub3Qgc3RyaW5naWZpZWRcImBcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHNwYWNlciAhPT0gJycpIHtcbiAgICAgICAgICAgIHJlcyArPSBgXFxuJHtvcmlnaW5hbEluZGVudGF0aW9ufWBcbiAgICAgICAgICB9XG4gICAgICAgICAgc3RhY2sucG9wKClcbiAgICAgICAgICByZXR1cm4gYFske3Jlc31dYFxuICAgICAgICB9XG5cbiAgICAgICAgbGV0IGtleXMgPSBPYmplY3Qua2V5cyh2YWx1ZSlcbiAgICAgICAgY29uc3Qga2V5TGVuZ3RoID0ga2V5cy5sZW5ndGhcbiAgICAgICAgaWYgKGtleUxlbmd0aCA9PT0gMCkge1xuICAgICAgICAgIHJldHVybiAne30nXG4gICAgICAgIH1cbiAgICAgICAgaWYgKG1heGltdW1EZXB0aCA8IHN0YWNrLmxlbmd0aCArIDEpIHtcbiAgICAgICAgICByZXR1cm4gJ1wiW09iamVjdF1cIidcbiAgICAgICAgfVxuICAgICAgICBsZXQgd2hpdGVzcGFjZSA9ICcnXG4gICAgICAgIGxldCBzZXBhcmF0b3IgPSAnJ1xuICAgICAgICBpZiAoc3BhY2VyICE9PSAnJykge1xuICAgICAgICAgIGluZGVudGF0aW9uICs9IHNwYWNlclxuICAgICAgICAgIGpvaW4gPSBgLFxcbiR7aW5kZW50YXRpb259YFxuICAgICAgICAgIHdoaXRlc3BhY2UgPSAnICdcbiAgICAgICAgfVxuICAgICAgICBjb25zdCBtYXhpbXVtUHJvcGVydGllc1RvU3RyaW5naWZ5ID0gTWF0aC5taW4oa2V5TGVuZ3RoLCBtYXhpbXVtQnJlYWR0aClcbiAgICAgICAgaWYgKGRldGVybWluaXN0aWMgJiYgIWlzVHlwZWRBcnJheVdpdGhFbnRyaWVzKHZhbHVlKSkge1xuICAgICAgICAgIGtleXMgPSBzb3J0KGtleXMsIGNvbXBhcmF0b3IpXG4gICAgICAgIH1cbiAgICAgICAgc3RhY2sucHVzaCh2YWx1ZSlcbiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBtYXhpbXVtUHJvcGVydGllc1RvU3RyaW5naWZ5OyBpKyspIHtcbiAgICAgICAgICBjb25zdCBrZXkgPSBrZXlzW2ldXG4gICAgICAgICAgY29uc3QgdG1wID0gc3RyaW5naWZ5Rm5SZXBsYWNlcihrZXksIHZhbHVlLCBzdGFjaywgcmVwbGFjZXIsIHNwYWNlciwgaW5kZW50YXRpb24pXG4gICAgICAgICAgaWYgKHRtcCAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICByZXMgKz0gYCR7c2VwYXJhdG9yfSR7c3RyRXNjYXBlKGtleSl9OiR7d2hp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VybiAnXCJbQXJyYXldXCInXG4gICAgICAgICAgfVxuICAgICAgICAgIHN0YWNrLnB1c2godmFsdWUpXG4gICAgICAgICAgaWYgKHNwYWNlciAhPT0gJycpIHtcbiAgICAgICAgICAgIGluZGVudGF0aW9uICs9IHNwYWNlclxuICAgICAgICAgICAgcmVzICs9IGBcXG4ke2luZGVudGF0aW9ufWBcbiAgICAgICAgICAgIGpvaW4gPSBgLFxcbiR7aW5kZW50YXRpb259YFxuICAgICAgICAgIH1cbiAgICAgICAgICBjb25zdCBtYXhpbXVtVmFsdWVzVG9TdHJpbmdpZnkgPSBNYXRoLm1pbih2YWx1ZS5sZW5ndGgsIG1heGltdW1CcmVhZHRoKVxuICAgICAgICAgIGxldCBpID0gMFxuICAgICAgICAgIGZvciAoOyBpIDwgbWF4aW11bVZhbHVlc1RvU3RyaW5naWZ5IC0gMTsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCB0bXAgPSBzdHJpbmdpZnlBcnJheVJlcGxhY2VyKFN0cmluZyhpKSwgdmFsdWVbaV0sIHN0YWNrLCByZXBsYWNlciwgc3BhY2VyLCBpbmRlbnRhdGlvbilcbiAgICAgICAgICAgIHJlcyArPSB0bXAgIT09IHVuZGVmaW5lZCA/IHRtcCA6ICdudWxsJ1xuICAgICAgICAgICAgcmVzICs9IGpvaW5cbiAgICAgICAgICB9XG4gICAgICAgICAgY29uc3QgdG1wID0gc3RyaW5naWZ5QXJyYXlSZXBsYWNlcihTdHJpbmcoaSksIHZhbHVlW2ldLCBzdGFjaywgcmVwbGFjZXIsIHNwYWNlciwgaW5kZW50YXRpb24pXG4gICAgICAgICAgcmVzICs9IHRtcCAhPT0gdW5kZWZpbmVkID8gdG1wIDogJ251bGwnXG4gICAgICAgICAgaWYgKHZhbHVlLmxlbmd0aCAtIDEgPiBtYXhpbXVtQnJlYWR0aCkge1xuICAgICAgICAgICAgY29uc3QgcmVtb3ZlZEtleXMgPSB2YWx1ZS5sZW5ndGggLSBtYXhpbXVtQnJ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Y3Rpb24nKSB7XG4gICAgICAgICAgdmFsdWUgPSB2YWx1ZS50b0pTT04oa2V5KVxuICAgICAgICAgIC8vIFByZXZlbnQgY2FsbGluZyBgdG9KU09OYCBhZ2Fpbi5cbiAgICAgICAgICBpZiAodHlwZW9mIHZhbHVlICE9PSAnb2JqZWN0Jykge1xuICAgICAgICAgICAgcmV0dXJuIHN0cmluZ2lmeUluZGVudChrZXksIHZhbHVlLCBzdGFjaywgc3BhY2VyLCBpbmRlbnRhdGlvbilcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHZhbHVlID09PSBudWxsKSB7XG4gICAgICAgICAgICByZXR1cm4gJ251bGwnXG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmIChzdGFjay5pbmRleE9mKHZhbHVlKSAhPT0gLTEpIHtcbiAgICAgICAgICByZXR1cm4gY2lyY3VsYXJWYWx1ZVxuICAgICAgICB9XG4gICAgICAgIGNvbnN0IG9yaWdpbmFsSW5kZW50YXRpb24gPSBpbmRlbnRhdGlvblxuXG4gICAgICAgIGlmIChBcnJheS5pc0FycmF5KHZhbHVlKSkge1xuICAgICAgICAgIGlmICh2YWx1ZS5sZW5ndGggPT09IDApIHtcbiAgICAgICAgICAgIHJldHVybiAnW10nXG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChtYXhpbXVtRGVwdGggPCBzdGFjay5sZW5ndGggKyAxKSB7XG4gICAgICAgICAgICByZXR1cm4gJ1wiW0FycmF5XVwiJ1xuICAgICAgICAgIH1cbiAgICAgICAgICBzdGFjay5wdXNoKHZhbHVlKVxuICAgICAgICAgIGluZGVudGF0aW9uICs9IHNwYWNlclxuICAgICAgICAgIGxldCByZXMgPSBgXFxuJHtpbmRlbnRhdGlvbn1gXG4gICAgICAgICAgY29uc3Qgam9pbiA9IGAsXFxuJHtpbmRlbnRhdGlvbn1gXG4gICAgICAgICAgY29uc3QgbWF4aW11bVZhbHVlc1RvU3RyaW5naWZ5ID0gTWF0aC5taW4odmF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a2V5TGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgcmV0dXJuICd7fSdcbiAgICAgICAgfVxuICAgICAgICBpZiAobWF4aW11bURlcHRoIDwgc3RhY2subGVuZ3RoICsgMSkge1xuICAgICAgICAgIHJldHVybiAnXCJbT2JqZWN0XVwiJ1xuICAgICAgICB9XG4gICAgICAgIGluZGVudGF0aW9uICs9IHNwYWNlclxuICAgICAgICBjb25zdCBqb2luID0gYCxcXG4ke2luZGVudGF0aW9ufWBcbiAgICAgICAgbGV0IHJlcyA9ICcnXG4gICAgICAgIGxldCBzZXBhcmF0b3IgPSAnJ1xuICAgICAgICBsZXQgbWF4aW11bVByb3BlcnRpZXNUb1N0cmluZ2lmeSA9IE1hdGgubWluKGtleUxlbmd0aCwgbWF4aW11bUJyZWFkdGgpXG4gICAgICAgIGlmIChpc1R5cGVkQXJyYXlXaXRoRW50cmllcyh2YWx1ZSkpIHtcbiAgICAgICAgICByZXMgKz0gc3RyaW5naWZ5VHlwZWRBcnJheSh2YWx1ZSwgam9pbiwgbWF4aW11bUJyZWFkdGgpXG4gICAgICAgICAga2V5cyA9IGtleXMuc2xpY2UodmFsdWUubGVuZ3RoKVxuICAgICAgICAgIG1heGltdW1Qcm9wZXJ0aWVzVG9TdHJpbmdpZnkgLT0gdmFsdWUubGVuZ3RoXG4gICAgICAgICAgc2VwYXJhdG9yID0gam9pblxuICAgICAgICB9XG4gICAgICAgIGlmIChkZXRlcm1pbmlzdGljKSB7XG4gICAgICAgICAga2V5cyA9IHNvcnQoa2V5cywgY29tcGFyYXRvcilcbiAgICAgICAgfVxuICAgICAgICBzdGFjay5wdXNoKHZhbHVlKVxuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG1heGltdW1Qcm9wZXJ0aWVzVG9TdHJpbmdpZnk7IGkrKykge1xuICAgICAgICAgIGNvbnN0IGtleSA9IGtleXNbaV1cbiAgICAgICAgICBjb25zdCB0bXAgPSBzdHJpbmdpZnlJbmRlbnQoa2V5LCB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ICAgICAgaWYgKGJpZ2ludCkge1xuICAgICAgICAgIHJldHVybiBTdHJpbmcodmFsdWUpXG4gICAgICAgIH1cbiAgICAgICAgLy8gZmFsbHRocm91Z2hcbiAgICAgIGRlZmF1bHQ6XG4gICAgICAgIHJldHVybiBmYWlsID8gZmFpbCh2YWx1ZSkgOiB1bmRlZmluZWRcbiAgICB9XG4gIH1cblxuICBmdW5jdGlvbiBzdHJpbmdpZnlTaW1wbGUgKGtleSwgdmFsdWUsIHN0YWNrKSB7XG4gICAgc3dpdGNoICh0eXBlb2YgdmFsdWUpIHtcbiAgICAgIGNhc2UgJ3N0cmluZyc6XG4gICAgICAgIHJldHVybiBzdHJFc2NhcGUodmFsdWUpXG4gICAgICBjYXNlICdvYmplY3QnOiB7XG4gICAgICAgIGlmICh2YWx1ZSA9PT0gbnVsbCkge1xuICAgICAgICAgIHJldHVybiAnbnVsbCdcbiAgICAgICAgfVxuICAgICAgICBpZiAodHlwZW9mIHZhbHVlLnRvSlNPTiA9PT0gJ2Z1bmN0aW9uJykge1xuICAgICAgICAgIHZhbHVlID0gdmFsdWUudG9KU09OKGtleSlcbiAgICAgICAgICAvLyBQcmV2ZW50IGNhbGxpbmcgYHRvSlNPTmAgYWdhaW5cbiAgICAgICAgICBpZiAodHlwZW9mIHZhbHVlICE9PSAnb2JqZWN0Jykge1xuICAgICAgICAgICAgcmV0dXJuIHN0cmluZ2lmeVNpbXBsZShrZXksIHZhbHVlLCBzdGFjaylcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHZhbHVlID09PSBudWxsKSB7XG4gICAgICAgICAgICByZXR1cm4gJ251bGwnXG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmIChzdGFjay5pbmRleE9mKHZhbHVlKSAhPT0gLTEpIHtcbiAgICAgICAgICByZXR1cm4gY2lyY3VsYXJWYWx1ZVxuICAgICAgICB9XG5cbiAgICAgICAgbGV0IHJlcyA9ICcnXG5cbiAgICAgICAgY29uc3QgaGFzT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XROb2RlKHBhcnNlciwgJ29uY2xvc2VuYW1lc3BhY2UnLCB7IHByZWZpeDogcCwgdXJpOiBuIH0pXG4gICAgICAgIH0pXG4gICAgICB9XG4gICAgfVxuICAgIGlmICh0ID09PSAwKSBwYXJzZXIuY2xvc2VkUm9vdCA9IHRydWVcbiAgICBwYXJzZXIudGFnTmFtZSA9IHBhcnNlci5hdHRyaWJWYWx1ZSA9IHBhcnNlci5hdHRyaWJOYW1lID0gJydcbiAgICBwYXJzZXIuYXR0cmliTGlzdC5sZW5ndGggPSAwXG4gICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gIH1cblxuICBmdW5jdGlvbiBwYXJzZUVudGl0eSAocGFyc2VyKSB7XG4gICAgdmFyIGVudGl0eSA9IHBhcnNlci5lbnRpdHlcbiAgICB2YXIgZW50aXR5TEMgPSBlbnRpdHkudG9Mb3dlckNhc2UoKVxuICAgIHZhciBudW1cbiAgICB2YXIgbnVtU3RyID0gJydcblxuICAgIGlmIChwYXJzZXIuRU5USVRJRVNbZW50aXR5XSkge1xuICAgICAgcmV0dXJuIHBhcnNlci5FTlRJVElFU1tlbnRpdHldXG4gICAgfVxuICAgIGlmIChwYXJzZXIuRU5USVRJRVNbZW50aXR5TENdKSB7XG4gICAgICByZXR1cm4gcGFyc2VyLkVOVElUSUVTW2VudGl0eUxDXVxuICAgIH1cbiAgICBlbnRpdHkgPSBlbnRpdHlMQ1xuICAgIGlmIChlbnRpdHkuY2hhckF0KDApID09PSAnIycpIHtcbiAgICAgIGlmIChlbnRpdHkuY2hhckF0KDEpID09PSAneCcpIHtcbiAgICAgICAgZW50aXR5ID0gZW50aXR5LnNsaWNlKDIpXG4gICAgICAgIG51bSA9IHBhcnNlSW50KGVudGl0eSwgMTYpXG4gICAgICAgIG51bVN0ciA9IG51bS50b1N0cmluZygxNilcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGVudGl0eSA9IGVudGl0eS5zbGljZSgxKVxuICAgICAgICBudW0gPSBwYXJz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U1BBQ0VcbiAgICAgICAgICBpZiAoYyA9PT0gJ1xcdUZFRkYnKSB7XG4gICAgICAgICAgICBjb250aW51ZVxuICAgICAgICAgIH1cbiAgICAgICAgICBiZWdpbldoaXRlU3BhY2UocGFyc2VyLCBjKVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkJFR0lOX1dISVRFU1BBQ0U6XG4gICAgICAgICAgYmVnaW5XaGl0ZVNwYWNlKHBhcnNlciwgYylcbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5URVhUOlxuICAgICAgICAgIGlmIChwYXJzZXIuc2F3Um9vdCAmJiAhcGFyc2VyLmNsb3NlZFJvb3QpIHtcbiAgICAgICAgICAgIHZhciBzdGFydGkgPSBpIC0gMVxuICAgICAgICAgICAgd2hpbGUgKGMgJiYgYyAhPT0gJzwnICYmIGMgIT09ICcmJykge1xuICAgICAgICAgICAgICBjID0gY2hhckF0KGNodW5rLCBpKyspXG4gICAgICAgICAgICAgIGlmIChjICYmIHBhcnNlci50cmFja1Bvc2l0aW9uKSB7XG4gICAgICAgICAgICAgICAgcGFyc2VyLnBvc2l0aW9uKytcbiAgICAgICAgICAgICAgICBpZiAoYyA9PT0gJ1xcbicpIHtcbiAgICAgICAgICAgICAgICAgIHBhcnNlci5saW5lKytcbiAgICAgICAgICAgICAgICAgIHBhcnNlci5jb2x1bW4gPSAwXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIHBhcnNlci5jb2x1bW4rK1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcGFyc2VyLnRleHROb2RlICs9IGNodW5rLnN1YnN0cmluZyhzdGFydGksIGkgLSAxKVxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoYyA9PT0gJzwnICYmICEocGFyc2VyLnNhd1Jvb3QgJiYgcGFyc2VyLmNsb3NlZFJvb3QgJiYgIXBhcnNlci5zdHJpY3QpKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLk9QRU5fV0FLQVxuICAgICAgICAgICAgcGFyc2VyLnN0YXJ0VGFnUG9zaXRpb24gPSBwYXJzZXIucG9zaXRpb25cbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKCFpc1doaXRlc3BhY2UoYykgJiYgKCFwYXJzZXIuc2F3Um9vdCB8fCBwYXJzZXIuY2xvc2VkUm9vdCkpIHtcbiAgICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdUZXh0IGRhdGEgb3V0c2lkZSBvZiByb290IG5vZGUuJylcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChjID09PSAnJicpIHtcbiAgICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUX0VOVElUWVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgcGFyc2VyLnRleHROb2RlICs9IGNcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuU0NSSVBUOlxuICAgICAgICAgIC8vIG9ubHkgbm9uLXN0cmljdFxuICAgICAgICAgIGlmIChjID09PSAnPCcpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0NSSVBUX0VORElOR1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuc2NyaXB0ICs9IGNcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuU0NSSVBUX0VORElORzpcbiAgICAgICAgICBpZiAoYyA9PT0gJy8nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNMT1NFX1RBR1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuc2NyaXB0ICs9ICc8JyArIGNcbiAgICAgICAgICAgIH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l0aW9uICsgMSA8IHBhcnNlci5wb3NpdGlvbikge1xuICAgICAgICAgICAgICB2YXIgcGFkID0gcGFyc2VyLnBvc2l0aW9uIC0gcGFyc2VyLnN0YXJ0VGFnUG9zaXRpb25cbiAgICAgICAgICAgICAgYyA9IG5ldyBBcnJheShwYWQpLmpvaW4oJyAnKSArIGNcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHBhcnNlci50ZXh0Tm9kZSArPSAnPCcgKyBjXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlRFWFRcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuU0dNTF9ERUNMOlxuICAgICAgICAgIGlmIChwYXJzZXIuc2dtbERlY2wgKyBjID09PSAnLS0nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNPTU1FTlRcbiAgICAgICAgICAgIHBhcnNlci5jb21tZW50ID0gJydcbiAgICAgICAgICAgIHBhcnNlci5zZ21sRGVjbCA9ICcnXG4gICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAocGFyc2VyLmRvY3R5cGUgJiYgcGFyc2VyLmRvY3R5cGUgIT09IHRydWUgJiYgcGFyc2VyLnNnbWxEZWNsKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVfRFREXG4gICAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSAnPCEnICsgcGFyc2VyLnNnbWxEZWNsICsgY1xuICAgICAgICAgICAgcGFyc2VyLnNnbWxEZWNsID0gJydcbiAgICAgICAgICB9IGVsc2UgaWYgKChwYXJzZXIuc2dtbERlY2wgKyBjKS50b1VwcGVyQ2FzZSgpID09PSBDREFUQSkge1xuICAgICAgICAgICAgZW1pdE5vZGUocGFyc2VyLCAnb25vcGVuY2RhdGEnKVxuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DREFUQVxuICAgICAgICAgICAgcGFyc2VyLnNnbWxEZWNsID0gJydcbiAgICAgICAgICAgIHBhcnNlci5jZGF0YSA9ICcnXG4gICAgICAgICAgfSBlbHNlIGlmICgocGFyc2VyLnNnbWxEZWNsICsgYykudG9VcHBlckNhc2UoKSA9PT0gRE9DVFlQRSkge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5ET0NUWVBFXG4gICAgICAgICAgICBpZiAocGFyc2VyLmRvY3R5cGUgfHwgcGFyc2VyLnNhd1Jvb3QpIHtcbiAgICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsXG4gICAgICAgICAgICAgICAgJ0luYXBwcm9wcmlhdGVseSBsb2NhdGVkIGRvY3R5cGUgZGVjbGFyYXRpb24nKVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcGFyc2VyLmRvY3R5cGUgPSAnJ1xuICAgICAgICAgICAgcGFyc2VyLnNnbWxEZWNsID0gJydcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICc+Jykge1xuICAgICAgICAgICAgZW1pdE5vZGUocGFyc2VyLCAnb25zZ21sZGVjbGFyYXRpb24nLCBwYXJzZXIuc2dtbERlY2wpXG4gICAgICAgICAgICBwYXJzZXIuc2dtbERlY2wgPSAnJ1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgfSBlbHNlIGlmIChpc1F1b3RlKGMpKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlNHTUxfREVDTF9RVU9URURcbiAgICAgICAgICAgIHBhcnNlci5zZ21sRGVjbCArPSBjXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5zZ21sRGVjbCArPSBjXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLlNHTUxfREVDTF9RVU9URUQ6XG4gICAgICAgICAgaWYgKGMgPT09IHBhcnNlci5xKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlNHTUxfREVDTFxuICAgICAgICAgICAgcGFyc2VyLnEgPSAnJ1xuICAgICAgICAgIH1cbiAgICAgICAgICBwYXJzZXIuc2dtbERlY2wgKz0gY1xuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkRPQ1RZUEU6XG4gICAgICAgICAgaWYgKGMgPT09ICc+Jykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgICBlbWl0Tm9kZShwYXJzZXIsICdvbmRvY3R5cGUnLCBwYXJzZXIuZG9jdHlwZSlcbiAgICAgICAgICAgIHBhcnNlci5kb2N0eXBlID0gdHJ1ZSAvLyBqdXN0IHJlbWVtYmVyIHRoYXQgd2Ugc2F3IGl0LlxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgICAgICBpZiAoYyA9PT0gJ1snKSB7XG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuRE9DVFlQRV9EVERcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoaXNRdW90ZShjKSkge1xuICAgICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVfUVVPVEVEXG4gICAgICAgICAgICAgIHBhcnNlci5xID0gY1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5ET0NUWVBFX1FVT1RFRDpcbiAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgICAgaWYgKGMgPT09IHBhcnNlci5xKSB7XG4gICAgICAgICAgICBwYXJzZXIucSA9ICcnXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuRE9DVFlQRV9EVEQ6XG4gICAgICAgICAgaWYgKGMgPT09ICddJykge1xuICAgICAgICAgICAgcGFyc2VyLmRvY3R5cGUgKz0gY1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5ET0NUWVBFXG4gICAgICAgICAgfSBlbHNlIGlmIChjID09PSAnPCcpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuT1BFTl9XQUtBXG4gICAgICAgICAgICBwYXJzZXIuc3RhcnRUYWdQb3NpdGlvbiA9IHBhcnNlci5wb3NpdGlvblxuICAgICAgICAgIH0gZWxzZSBpZiAoaXNRdW90ZShjKSkge1xuICAgICAgICAgICAgcGFyc2VyLmRvY3R5cGUgKz0gY1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5ET0NUWVBFX0RURF9RVU9URURcbiAgICAgICAgICAgIHBhcnNlci5xID0gY1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkRPQ1RZUEVfRFREX1FVT1RFRDpcbiAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgICAgaWYgKGMgPT09IHBhcnNlci5xKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVfRFREXG4gICAgICAgICAgICBwYXJzZXIucSA9ICcnXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNPTU1FTlQ6XG4gICAgICAgICAgaWYgKGMgPT09ICctJykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DT01NRU5UX0VORElOR1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuY29tbWVudCArPSBjXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNPTU1FTlRfRU5ESU5HOlxuICAgICAgICAgIGlmIChjID09PSAnLScpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ09NTUVOVF9FTkRFRFxuICAgICAgICAgICAgcGFyc2VyLmNvbW1lbnQgPSB0ZXh0b3B0cyhwYXJzZXIub3B0LCBwYXJzZXIuY29tbWVudClcbiAgICAgICAgICAgIGlmIChwYXJzZXIuY29tbWVudCkge1xuICAgICAgICAgICAgICBlbWl0Tm9kZShwYXJzZXIsICdvbmNvbW1lbnQnLCBwYXJzZXIuY29tbWVudClcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHBhcnNlci5jb21tZW50ID0gJydcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcGFyc2VyLmNvbW1lbnQgKz0gJy0nICsgY1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DT01NRU5UXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNPTU1FTlRfRU5ERUQ6XG4gICAgICAgICAgaWYgKGMgIT09ICc+Jykge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdNYWxmb3JtZWQgY29tbWVudCcpXG4gICAgICAgICAgICAvLyBhbGxvdyA8IS0tIGJsYWggLS0gYmxvbyAtLT4gaW4gbm9uLXN0cmljdCBtb2RlLFxuICAgICAgICAgICAgLy8gd2hpY2ggaXMgYSBjb21tZW50IG9mIFwiIGJsYWggLS0gYmxvbyBcIlxuICAgICAgICAgICAgcGFyc2VyLmNvbW1lbnQgKz0gJy0tJyArIGNcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ09NTUVOVFxuICAgICAgICAgIH0gZWxzZSBpZiAocGFyc2VyLmRvY3R5cGUgJiYgcGFyc2VyLmRvY3R5cGUgIT09IHRydWUpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuRE9DVFlQRV9EVERcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNEQVRBOlxuICAgICAgICAgIGlmIChjID09PSAnXScpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ0RBVEFfRU5ESU5HXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5jZGF0YSArPSBjXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNEQVRBX0VORElORzpcbiAgICAgICAgICBpZiAoYyA9PT0gJ10nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNEQVRBX0VORElOR18yXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5jZGF0YSArPSAnXScgKyBjXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNEQVRBXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNEQVRBX0VORElOR18yOlxuICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIGlmIChwYXJzZXIuY2RhdGEpIHtcbiAgICAgICAgICAgICAgZW1pdE5vZGUocGFyc2VyLCAnb25jZGF0YScsIHBhcnNlci5jZGF0YSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVtaXROb2RlKHBhcnNlciwgJ29uY2xvc2VjZGF0YScpXG4gICAgICAgICAgICBwYXJzZXIuY2RhdGEgPSAnJ1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgfSBlbHNlIGlmIChjID09PSAnXScpIHtcbiAgICAgICAgICAgIHBhcnNlci5jZGF0YSArPSAnXSdcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcGFyc2VyLmNkYXRhICs9ICddXScgKyBjXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNEQVRBXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLlBST0NfSU5TVDpcbiAgICAgICAgICBpZiAoYyA9PT0gJz8nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlBST0NfSU5TVF9FTkRJTkdcbiAgICAgICAgICB9IGVsc2UgaWYgKGlzV2hpdGVzcGFjZShjKSkge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5QUk9DX0lOU1RfQk9EWVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIucHJvY0luc3ROYW1lICs9IGNcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuUFJPQ19JTlNUX0JPRFk6XG4gICAgICAgICAgaWYgKCFwYXJzZXIucHJvY0luc3RCb2R5ICYmIGlzV2hpdGVzcGFjZShjKSkge1xuICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICc/Jykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5QUk9DX0lOU1RfRU5ESU5HXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5wcm9jSW5zdEJvZHkgKz0gY1xuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5QUk9DX0lOU1RfRU5ESU5HOlxuICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIGVtaXROb2RlKHBhcnNlciwgJ29ucHJvY2Vzc2luZ2luc3RydWN0aW9uJywge1xuICAgICAgICAgICAgICBuYW1lOiBwYXJzZXIucHJvY0luc3ROYW1lLFxuICAgICAgICAgICAgICBib2R5OiBwYXJzZXIucHJvY0luc3RCb2R5XG4gICAgICAgICAgICB9KVxuICAgICAgICAgICAgcGFyc2VyLnByb2NJbnN0TmFtZSA9IHBhcnNlci5wcm9jSW5zdEJvZHkgPSAnJ1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5wcm9jSW5zdEJvZHkgKz0gJz8nICsgY1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5QUk9DX0lOU1RfQk9EWVxuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5PUEVOX1RBRzpcbiAgICAgICAgICBpZiAoaXNNYXRjaChuYW1lQm9keSwgYykpIHtcbiAgICAgICAgICAgIHBhcnNlci50YWdOYW1lICs9IGNcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbmV3VGFnKHBhcnNlcilcbiAgICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgICAgb3BlblRhZyhwYXJzZXIpXG4gICAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICcvJykge1xuICAgICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLk9QRU5fVEFHX1NMQVNIXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBpZiAoIWlzV2hpdGVzcGFjZShjKSkge1xuICAgICAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCBjaGFyYWN0ZXIgaW4gdGFnIG5hbWUnKVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLk9QRU5fVEFHX1NMQVNIOlxuICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIG9wZW5UYWcocGFyc2VyLCB0cnVlKVxuICAgICAgICAgICAgY2xvc2VUYWcocGFyc2VyKVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzdHJpY3RGYWlsKHBhcnNlciwgJ0ZvcndhcmQtc2xhc2ggaW4gb3BlbmluZyB0YWcgbm90IGZvbGxvd2VkIGJ5ID4nKVxuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuQVRUUklCOlxuICAgICAgICAgIC8vIGhhdmVuJ3QgcmVhZCB0aGUgYXR0cmlidXRlIG5hbWUgeWV0LlxuICAgICAgICAgIGlmIChpc1doaXRlc3BhY2UoYykpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfSBlbHNlIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIG9wZW5UYWcocGFyc2VyKVxuICAgICAgICAgIH0gZWxzZSBpZiAoYyA9PT0gJy8nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLk9QRU5fVEFHX1NMQVNIXG4gICAgICAgICAgfSBlbHNlIGlmIChpc01hdGNoKG5hbWVTdGFydCwgYykpIHtcbiAgICAgICAgICAgIHBhcnNlci5hdHRyaWJOYW1lID0gY1xuICAgICAgICAgICAgcGFyc2VyLmF0dHJpYlZhbHVlID0gJydcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX05BTUVcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdJbnZhbGlkIGF0dHJpYnV0ZSBuYW1lJylcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuQVRUUklCX05BTUU6XG4gICAgICAgICAgaWYgKGMgPT09ICc9Jykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJfVkFMVUVcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICc+Jykge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdBdHRyaWJ1dGUgd2l0aG91dCB2YWx1ZScpXG4gICAgICAgICAgICBwYXJzZXIuYXR0cmliVmFsdWUgPSBwYXJzZXIuYXR0cmliTmFtZVxuICAgICAgICAgICAgYXR0cmliKHBhcnNlcilcbiAgICAgICAgICAgIG9wZW5UYWcocGFyc2VyKVxuICAgICAgICAgIH0gZWxzZSBpZiAoaXNXaGl0ZXNwYWNlKGMpKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9OQU1FX1NBV19XSElURVxuICAgICAgICAgIH0gZWxzZSBpZiAoaXNNYXRjaChuYW1lQm9keSwgYykpIHtcbiAgICAgICAgICAgIHBhcnNlci5hdHRyaWJOYW1lICs9IGNcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdJbnZhbGlkIGF0dHJpYnV0ZSBuYW1lJylcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuQVRUUklCX05BTUVfU0FXX1dISVRFOlxuICAgICAgICAgIGlmIChjID09PSAnPScpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX1ZBTFVFXG4gICAgICAgICAgfSBlbHNlIGlmIChpc1doaXRlc3BhY2UoYykpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnQXR0cmlidXRlIHdpdGhvdXQgdmFsdWUnKVxuICAgICAgICAgICAgcGFyc2VyLnRhZy5hdHRyaWJ1dGVzW3BhcnNlci5hdHRyaWJOYW1lXSA9ICcnXG4gICAgICAgICAgICBwYXJzZXIuYXR0cmliVmFsdWUgPSAnJ1xuICAgICAgICAgICAgZW1pdE5vZGUocGFyc2VyLCAnb25hdHRyaWJ1dGUnLCB7XG4gICAgICAgICAgICAgIG5hbWU6IHBhcnNlci5hdHRyaWJOYW1lLFxuICAgICAgICAgICAgICB2YWx1ZTogJydcbiAgICAgICAgICAgIH0pXG4gICAgICAgICAgICBwYXJzZXIuYXR0cmliTmFtZSA9ICcnXG4gICAgICAgICAgICBpZiAoYyA9PT0gJz4nKSB7XG4gICAgICAgICAgICAgIG9wZW5UYWcocGFyc2VyKVxuICAgICAgICAgICAgfSBlbHNlIGlmIChpc01hdGNoKG5hbWVTdGFydCwgYykpIHtcbiAgICAgICAgICAgICAgcGFyc2VyLmF0dHJpYk5hbWUgPSBjXG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX05BTUVcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCBhdHRyaWJ1dGUgbmFtZScpXG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRTpcbiAgICAgICAgICBpZiAoaXNXaGl0ZXNwYWNlKGMpKSB7XG4gICAgICAgICAgICBjb250aW51ZVxuICAgICAgICAgIH0gZWxzZSBpZiAoaXNRdW90ZShjKSkge1xuICAgICAgICAgICAgcGFyc2VyLnEgPSBjXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9WQUxVRV9RVU9URURcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKCFwYXJzZXIub3B0LnVucXVvdGVkQXR0cmlidXRlVmFsdWVzKSB7XG4gICAgICAgICAgICAgIGVycm9yKHBhcnNlciwgJ1VucXVvdGVkIGF0dHJpYnV0ZSB2YWx1ZScpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9WQUxVRV9VTlFVT1RFRFxuICAgICAgICAgICAgcGFyc2VyLmF0dHJpYlZhbHVlID0gY1xuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5BVFRSSUJfVkFMVUVfUVVPVEVEOlxuICAgICAgICAgIGlmIChjICE9PSBwYXJzZXIucSkge1xuICAgICAgICAgICAgaWYgKGMgPT09ICcmJykge1xuICAgICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9WQUxVRV9FTlRJVFlfUVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgcGFyc2VyLmF0dHJpYlZhbHVlICs9IGNcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfVxuICAgICAgICAgIGF0dHJpYihwYXJzZXIpXG4gICAgICAgICAgcGFyc2VyLnEgPSAnJ1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX0NMT1NFRFxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9DTE9TRUQ6XG4gICAgICAgICAgaWYgKGlzV2hpdGVzcGFjZShjKSkge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICc+Jykge1xuICAgICAgICAgICAgb3BlblRhZyhwYXJzZXIpXG4gICAgICAgICAgfSBlbHNlIGlmIChjID09PSAnLycpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuT1BFTl9UQUdfU0xBU0hcbiAgICAgICAgICB9IGVsc2UgaWYgKGlzTWF0Y2gobmFtZVN0YXJ0LCBjKSkge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdObyB3aGl0ZXNwYWNlIGJldHdlZW4gYXR0cmlidXRlcycpXG4gICAgICAgICAgICBwYXJzZXIuYXR0cmliTmFtZSA9IGNcbiAgICAgICAgICAgIHBhcnNlci5hdHRyaWJWYWx1ZSA9ICcnXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9OQU1FXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCBhdHRyaWJ1dGUgbmFtZScpXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9VTlFVT1RFRDpcbiAgICAgICAgICBpZiAoIWlzQXR0cmliRW5kKGMpKSB7XG4gICAgICAgICAgICBpZiAoYyA9PT0gJyYnKSB7XG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX0VOVElUWV9VXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBwYXJzZXIuYXR0cmliVmFsdWUgKz0gY1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgICB9XG4gICAgICAgICAgYXR0cmliKHBhcnNlcilcbiAgICAgICAgICBpZiAoYyA9PT0gJz4nKSB7XG4gICAgICAgICAgICBvcGVuVGFnKHBhcnNlcilcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuQ0xPU0VfVEFHOlxuICAgICAgICAgIGlmICghcGFyc2VyLnRhZ05hbWUpIHtcbiAgICAgICAgICAgIGlmIChpc1doaXRlc3BhY2UoYykpIHtcbiAgICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgICAgIH0gZWxzZSBpZiAobm90TWF0Y2gobmFtZVN0YXJ0LCBjKSkge1xuICAgICAgICAgICAgICBpZiAocGFyc2VyLnNjcmlwdCkge1xuICAgICAgICAgICAgICAgIHBhcnNlci5zY3JpcHQgKz0gJzwvJyArIGNcbiAgICAgICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlNDUklQVFxuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCB0YWduYW1lIGluIGNsb3NpbmcgdGFnLicpXG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHBhcnNlci50YWdOYW1lID0gY1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAoYyA9PT0gJz4nKSB7XG4gICAgICAgICAgICBjbG9zZVRhZyhwYXJzZXIpXG4gICAgICAgICAgfSBlbHNlIGlmIChpc01hdGNoKG5hbWVCb2R5LCBjKSkge1xuICAgICAgICAgICAgcGFyc2VyLnRhZ05hbWUgKz0gY1xuICAgICAgICAgIH0gZWxzZSBpZiAocGFyc2VyLnNjcmlwdCkge1xuICAgICAgICAgICAgcGFyc2VyLnNjcmlwdCArPSAnPC8nICsgcGFyc2VyLnRhZ05hbWVcbiAgICAgICAgICAgIHBhcnNlci50YWdOYW1lID0gJydcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0NSSVBUXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICghaXNXaGl0ZXNwYWNlKGMpKSB7XG4gICAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCB0YWduYW1lIGluIGNsb3NpbmcgdGFnJylcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ0xPU0VfVEFHX1NBV19XSElURVxuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5DTE9TRV9UQUdfU0FXX1dISVRFOlxuICAgICAgICAgIGlmIChpc1doaXRlc3BhY2UoYykpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIGNsb3NlVGFnKHBhcnNlcilcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdJbnZhbGlkIGNoYXJhY3RlcnMgaW4gY2xvc2luZyB0YWcnKVxuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5URVhUX0VOVElUWTpcbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9FTlRJVFlfUTpcbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9FTlRJVFlfVTpcbiAgICAgICAgICB2YXIgcmV0dXJuU3RhdGVcbiAgICAgICAgICB2YXIgYnVmZmVyXG4gICAgICAgICAgc3dpdGNoIChwYXJzZXIuc3RhdGUpIHtcbiAgICAgICAgICAgIGNhc2UgUy5URVhUX0VOVElUWTpcbiAgICAgICAgICAgICAgcmV0dXJuU3RhdGUgPSBTLlRFWFRcbiAgICAgICAgICAgICAgYnVmZmVyID0gJ3RleHROb2RlJ1xuICAgICAgICAgICAgICBicmVha1xuXG4gICAgICAgICAgICBjYXNlIFMuQVRUUklCX1ZBTFVFX0VOVElUWV9ROlxuICAgICAgICAgICAgICByZXR1cm5TdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX1FVT1RFRFxuICAgICAgICAgICAgICBidWZmZXIgPSAnYXR0cmliVmFsdWUnXG4gICAgICAgICAgICAgIGJyZWFrXG5cbiAgICAgICAgICAgIGNhc2UgUy5BVFRSSUJfVkFMVUVfRU5USVRZX1U6XG4gICAgICAgICAgICAgIHJldHVyblN0YXRlID0gUy5BVFRSSUJfVkFMVUVfVU5RVU9URURcbiAgICAgICAgICAgICAgYnVmZmVyID0gJ2F0dHJpYlZhbHVlJ1xuICAgICAgICAgICAgICBicmVha1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChjID09PSAnOycpIHtcbiAgICAgICAgICAgIHZhciBwYXJzZWRFbnRpdHkgPSBwYXJzZUVudGl0eShwYXJzZXIpXG4gICAgICAgICAgICBpZiAocGFyc2VyLm9wdC51bnBhcnNlZEVudGl0aWVzICYmICFPYmplY3QudmFsdWVzKHNheC5YTUxfRU5USVRJRVMpLmluY2x1ZGVzKHBhcnNlZEVudGl0eSkpIHtcbiAgICAgICAgICAgICAgcGFyc2VyLmVudGl0eSA9ICcnXG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IHJldHVyblN0YXRlXG4gICAgICAgICAgICAgIHBhcnNlci53cml0ZShwYXJzZWRFbnRpdHkpXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBwYXJzZXJbYnVmZmVyXSArPSBwYXJzZWRFbnRpdHlcbiAgICAgICAgICAgICAgcGFyc2VyLmVudGl0eSA9ICcnXG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IHJldHVyblN0YXRlXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChpc01hdGNoKHBhcnNlci5lbnRpdHkubGVuZ3RoID8gZW50aXR5Qm9keSA6IGVudGl0eVN0YXJ0LCBjKSkge1xuICAgICAgICAgICAgcGFyc2VyLmVudGl0eSArPSBjXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCBjaGFyYWN0ZXIgaW4gZW50aXR5IG5hbWUnKVxuICAgICAgICAgICAgcGFyc2VyW2J1ZmZlcl0gKz0gJyYnICsgcGFyc2VyLmVudGl0eSArIGNcbiAgICAgICAgICAgIHBhcnNlci5lbnRpdHkgPSAnJ1xuICAgICAgICAgICAgcGFyc2VyL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ztcbiAgICAgICAgY2FzZSAxOlxuICAgICAgICAgICAgY2FsbGJhY2soYXJnc1swXSk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSAyOlxuICAgICAgICAgICAgY2FsbGJhY2soYXJnc1swXSwgYXJnc1sxXSk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSAzOlxuICAgICAgICAgICAgY2FsbGJhY2soYXJnc1swXSwgYXJnc1sxXSwgYXJnc1syXSk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgZGVmYXVsdDpcbiAgICAgICAgICAgIGNhbGxiYWNrLmFwcGx5KHVuZGVmaW5lZCwgYXJncyk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIHJ1bklmUHJlc2VudChoYW5kbGUpIHtcbiAgICAgICAgLy8gRnJvbSB0aGUgc3BlYzogXCJXYWl0IHVudGlsIGFueSBpbnZvY2F0aW9ucyBvZiB0aGlzIGFsZ29yaXRobSBzdGFydGVkIGJlZm9yZSB0aGlzIG9uZSBoYXZlIGNvbXBsZXRlZC5cIlxuICAgICAgICAvLyBTbyBpZiB3ZSdyZSBjdXJyZW50bHkgcnVubmluZyBhIHRhc2ssIHdlJ2xsIG5lZWQgdG8gZGVsYXkgdGhpcyBpbnZvY2F0aW9uLlxuICAgICAgICBpZiAoY3VycmVudGx5UnVubmluZ0FUYXNrKSB7XG4gICAgICAgICAgICAvLyBEZWxheSBieSBkb2luZyBhIHNldFRpbWVvdXQuIHNldEltbWVkaWF0ZSB3YXMgdHJpZWQgaW5zdGVhZCwgYnV0IGluIEZpcmVmb3ggNyBpdCBnZW5lcmF0ZWQgYVxuICAgICAgICAgICAgLy8gXCJ0b28gbXVjaCByZWN1cnNpb25cIiBlcnJvci5cbiAgICAgICAgICAgIHNldFRpbWVvdXQocnVuSWZQcmVzZW50LCAwLCBoYW5kbGUpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICA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G4gIHZhciBsaW5lcyA9IGVyci5zdGFjay5zcGxpdCgnXFxuJykuc2xpY2UoMSk7XG5cbiAgcmV0dXJuIGxpbmVzXG4gICAgLm1hcChmdW5jdGlvbihsaW5lKSB7XG4gICAgICBpZiAobGluZS5tYXRjaCgvXlxccypbLV17NCx9JC8pKSB7XG4gICAgICAgIHJldHVybiBzZWxmLl9jcmVhdGVQYXJzZWRDYWxsU2l0ZSh7XG4gICAgICAgICAgZmlsZU5hbWU6IGxpbmUsXG4gICAgICAgICAgbGluZU51bWJlcjogbnVsbCxcbiAgICAgICAgICBmdW5jdGlvbk5hbWU6IG51bGwsXG4gICAgICAgICAgdHlwZU5hbWU6IG51bGwsXG4gICAgICAgICAgbWV0aG9kTmFtZTogbnVsbCxcbiAgICAgICAgICBjb2x1bW5OdW1iZXI6IG51bGwsXG4gICAgICAgICAgJ25hdGl2ZSc6IG51bGwsXG4gICAgICAgIH0pO1xuICAgICAgfVxuXG4gICAgICB2YXIgbGluZU1hdGNoID0gbGluZS5tYXRjaCgvYXQgKD86KC4rKVxccytcXCgpPyg/OiguKz8pOihcXGQrKSg/OjooXFxkKykpP3woW14pXSspKVxcKT8vKTtcbiAgICAgIGlmICghbGluZU1hdGNoKSB7XG4gICAgICAgIHJldHVybjtcbiAgICAgIH1cblxuICAgICAgdmFyIG9iamVjdCA9IG51bGw7XG4gICAgICB2YXIgbWV0aG9kID0gbnVsbDtcbiAgICAgIHZhciBmdW5jdGlvbk5hbWUgPSBudWxsO1xuICAgICAgdmFyIHR5cGVOYW1lID0gbnVsbDtcbiAgICAgIHZhciBtZXRob2ROYW1lID0gbnVsbDtcbiAgICAgIHZhciBpc05hdGl2ZSA9IChsaW5lTWF0Y2hbNV0gPT09ICduYXRpdmUnKTtcblxuICAgICAgaWYgKGxpbmVNYXRjaFsxXSkge1xuICAgICAgICBmdW5jdGlvbk5hbWUgPSBsaW5lTWF0Y2hbMV07XG4gICAgICAgIHZhciBtZXRob2RTdGFydCA9IGZ1bmN0aW9uTmFtZS5sYXN0SW5kZXhPZignLicpO1xuICAgICAgICBpZiAoZnVuY3Rpb25OYW1lW21ldGhvZFN0YXJ0LTFdID09ICcuJylcbiAgICAgICAgICBtZXRob2RTdGFydC0tO1xuICAgICAgICBpZiAobWV0aG9kU3RhcnQgPiAwKSB7XG4gICAgICAgICAgb2JqZWN0ID0gZnVuY3Rpb25OYW1lLnN1YnN0cigwLCBtZXRob2RTdGFydCk7XG4gICAgICAgICAgbWV0aG9kID0gZnVuY3Rpb25OYW1lLnN1YnN0cihtZXRob2RTdGFydCArIDEpO1xuICAgICAgICAgIHZhciBvYmplY3RFbmQgPSBvYmplY3QuaW5kZXhPZignLk1vZHVsZScpO1xuICAgICAgICAgIGlmIChvYmplY3RFbmQgPiAwKSB7XG4gICAgICAgICAgICBmdW5jdGlvbk5hbWUgPSBmdW5jdGlvbk5hbWUuc3Vic3RyKG9iamVjdEVuZCArIDEpO1xuICAgICAgICAgICAgb2JqZWN0ID0gb2JqZWN0LnN1YnN0cigwLCBvYmplY3RFbmQpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB0eXBlTmFtZSA9IG51bGw7XG4gICAgICB9XG5cbiAgICAgIGlmIChtZXRob2QpIHtcbiAgICAgICAgdHlwZU5hbWUgPSBvYmplY3Q7XG4gICAgICAgIG1ldGhvZE5hbWUgPSBtZXRob2Q7XG4gICAgICB9XG5cbiAgICAgIGlmIChtZXRob2QgPT09ICc8YW5vbnltb3VzPicpIHtcbiAgICAgICAgbWV0aG9kTmFtZSA9IG51bGw7XG4gICAgICAgIGZ1bmN0aW9uTmFtZSA9IG51bGw7XG4gICAgICB9XG5cbiAgICAgIHZhciBwcm9wZXJ0aWVzID0ge1xuICAgICAgICBmaWxlTmFtZTogbGluZU1hdGNoWzJdIHx8IG51bGwsXG4gICAgICAgIGxpbmVOdW1iZXI6IHBhcnNlSW50KGxpbmVNYXRjaFszXSwgMTApIHx8IG51bGwsXG4gICAgICAgIGZ1bmN0a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W9uIHZlcmIobikgeyByZXR1cm4gZnVuY3Rpb24gKHYpIHsgcmV0dXJuIHN0ZXAoW24sIHZdKTsgfTsgfVxyXG4gICAgZnVuY3Rpb24gc3RlcChvcCkge1xyXG4gICAgICAgIGlmIChmKSB0aHJvdyBuZXcgVHlwZUVycm9yKFwiR2VuZXJhdG9yIGlzIGFscmVhZHkgZXhlY3V0aW5nLlwiKTtcclxuICAgICAgICB3aGlsZSAoXykgdHJ5IHtcclxuICAgICAgICAgICAgaWYgKGYgPSAxLCB5ICYmICh0ID0gb3BbMF0gJiAyID8geVtcInJldHVyblwiXSA6IG9wWzBdID8geVtcInRocm93XCJdIHx8ICgodCA9IHlbXCJyZXR1cm5cIl0pICYmIHQuY2FsbCh5KSwgMCkgOiB5Lm5leHQpICYmICEodCA9IHQuY2FsbCh5LCBvcFsxXSkpLmRvbmUpIHJldHVybiB0O1xyXG4gICAgICAgICAgICBpZiAoeSA9IDAsIHQpIG9wID0gW29wWzBdICYgMiwgdC52YWx1ZV07XHJcbiAgICAgICAgICAgIHN3aXRjaCAob3BbMF0pIHtcclxuICAgICAgICAgICAgICAgIGNhc2UgMDogY2FzZSAxOiB0ID0gb3A7IGJyZWFrO1xyXG4gICAgICAgICAgICAgICAgY2FzZSA0OiBfLmxhYmVsKys7IHJldHVybiB7IHZhbHVlOiBvcFsxXSwgZG9uZTogZmFsc2UgfTtcclxuICAgICAgICAgICAgICAgIGNhc2UgNTogXy5sYWJlbCsrOyB5ID0gb3BbMV07IG9wID0gWzBdOyBjb250aW51ZTtcclxuICAgICAgICAgICAgICAgIGNhc2UgNzogb3AgPSBfLm9wcy5wb3AoKTsgXy50cnlzLnBvcCgpOyBjb250aW51ZTtcclxuICAgICAgICAgICAgICAgIGRlZmF1bHQ6XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCEodCA9IF8udHJ5cywgdCA9IHQubGVuZ3RoID4gMCAmJiB0W3QubGVuZ3RoIC0gMV0pICYmIChvcFswXSA9PT0gNiB8f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vZiBob3N0bmFtZSBpcyBub3RcbiAgICAgICAgICAgICAgICogYnJva2VuIGJ5IHJlcGxhY2luZyBub24tQVNDSUkgYnkgbm90aGluZ1xuICAgICAgICAgICAgICAgKi9cbiAgICAgICAgICAgICAgbmV3cGFydCArPSAneCc7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBuZXdwYXJ0ICs9IHBhcnRbal07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vIHdlIHRlc3QgYWdhaW4gd2l0aCBBU0NJSSBjaGFyIG9ubHlcbiAgICAgICAgICBpZiAoIW5ld3BhcnQubWF0Y2goaG9zdG5hbWVQYXJ0UGF0dGVybikpIHtcbiAgICAgICAgICAgIHZhciB2YWxpZFBhcnRzID0gaG9zdHBhcnRzLnNsaWNlKDAsIGkpO1xuICAgICAgICAgICAgdmFyIG5vdEhvc3QgPSBob3N0cGFydHMuc2xpY2UoaSArIDEpO1xuICAgICAgICAgICAgdmFyIGJpdCA9IHBhcnQubWF0Y2goaG9zdG5hbWVQYXJ0U3RhcnQpO1xuICAgICAgICAgICAgaWYgKGJpdCkge1xuICAgICAgICAgICAgICB2YWxpZFBhcnRzLnB1c2goYml0WzFdKTtcbiAgICAgICAgICAgICAgbm90SG9zdC51bnNoaWZ0KGJpdFsyXSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAobm90SG9zdC5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgcmVzdCA9ICcvJyArIG5vdEhvc3Quam9pbignLicpICsgcmVzdDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuaG9zdG5hbWUgPSB2YWxpZFBhcnRzLmpvaW4oJy4nKTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cblxuICAgIGlmICh0aGlzLmhvc3RuYW1lLmxlbmd0aCA+IGhvc3RuYW1lTWF4TGVuKSB7X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ybjtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICghYnl0ZXMpIHtcbiAgICAgICAgICBpZiAoYnVmZikge1xuICAgICAgICAgICAgLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIGVxZXFlcVxuICAgICAgICAgICAgaWYgKG9wdGlvbnMuc3RhcnQgPT0gbnVsbCB8fCByb3cgPiBvcHRpb25zLnN0YXJ0KSB7XG4gICAgICAgICAgICAgIGlmICghaXRlcikge1xuICAgICAgICAgICAgICAgIHN0cmVhbS5lbWl0KCdsaW5lJywgYnVmZik7XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaXRlcihudWxsLCBidWZmKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcm93Kys7XG4gICAgICAgICAgICBidWZmID0gJyc7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybiBzZXRUaW1lb3V0KHJlYWQsIDEwMDApO1xuICAgICAgICB9XG5cbiAgICAgICAgbGV0IGRhdGEgPSBkZWNvZGUud3JpdGUoYnVmZmVyLnNsaWNlKDAsIGJ5dGVzKSk7XG4gICAgICAgIGlmICghaXRlcikge1xuICAgICAgICAgIHN0cmVhbS5lbWl0KCdkYXRhJywgZGF0YSk7XG4gICAgICAgIH1cblxuICAgICAgICBkYXRhID0gKGJ1ZmYgKyBkYXRhKS5zcGxpdCgvXFxuKy8pO1xuXG4gICAgICAgIGNvbnN0IGwgPSBkYXRhLmxlbmd0aCAtIDE7XG4gICAgICAgIGxldCBpID0gMDtcblxuICAgICAgICBmb3IgKDsgaSA8IGw7IGkrKykge1xuICAgICAgICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBlcWVxZXFcbiAgICAgICAgICBpZiAob3B0aW9ucy5zdGFydCA9PSBudWxsIHx8IHJvdyA+IG9wdGlvbnMuc3RhcnQpIHtcbiAgICAgICAgICAgIGlmICghaXRlcikge1xuICAgICAgICAgICAgICBzdH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gIH1cbiAgICBpZiAodGhpcy5fcm90YXRlKSB7XG4gICAgICB0aGlzLl9zdHJlYW0ub25jZSgncm90YXRlJywgKCkgPT4ge1xuICAgICAgICB0aGlzLl9yb3RhdGUgPSBmYWxzZTtcbiAgICAgICAgdGhpcy5sb2coaW5mbywgY2FsbGJhY2spO1xuICAgICAgfSk7XG4gICAgICByZXR1cm47XG4gICAgfVxuICAgIGlmICh0aGlzLmxhenkpIHtcbiAgICAgIGlmICghdGhpcy5fZmlsZUV4aXN0KSB7XG4gICAgICAgIGlmICghdGhpcy5fb3BlbmluZykge1xuICAgICAgICAgIHRoaXMub3BlbigpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMub25jZSgnb3BlbicsICgpID0+IHtcbiAgICAgICAgICB0aGlzLl9maWxlRXhpc3QgPSB0cnVlO1xuICAgICAgICAgIHRoaXMubG9nKGluZm8sIGNhbGxiYWNrKTtcbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH0pO1xuICAgICAgICByZXR1cm47XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5fbmVlZHNOZXdGaWxlKHRoaXMuX3BlbmRpbmdTaXplKSkge1xuICAgICAgICB0aGlzLl9kZXN0Lm9uY2UoJ2Nsb3NlJywgKCkgPT4ge1xuICAgICAgICAgIGlmICghdGhpcy5fb3BlbmluZykge1xuICAgICAgICAgICAgdGhpcy5vcGVuKCk7XG4gICAgICAgICAgfVxuICAgICAgICAgIHRoaXMub25jZSgnb3BlbicsICgpID0+IHtcbiAgICAgICAgICAgIHRoaXMubG9nKGluZm8sIGNhbGxiYWNrKTtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICB9KTtcbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH0pO1xuICAgICAgICByZXR1cm47XG4gICAgICB9XG4gICAgfVxuXG4gICAgLy8gR3JhYiB0aGUgcmF3IHN0cmluZyBhbmQgYXBwZW5kIHRoZSBleHBlY3RlZCBFT0wuXG4gICAgY29uc3Qgb3V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c2UnLCAoKSA9PiB7XG4gICAgICBpZiAoYnVmZikge1xuICAgICAgICBhZGQoYnVmZiwgdHJ1ZSk7XG4gICAgICB9XG4gICAgICBpZiAob3B0aW9ucy5vcmRlciA9PT0gJ2Rlc2MnKSB7XG4gICAgICAgIHJlc3VsdHMgPSByZXN1bHRzLnJldmVyc2UoKTtcbiAgICAgIH1cblxuICAgICAgLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIGNhbGxiYWNrLXJldHVyblxuICAgICAgaWYgKGNhbGxiYWNrKSBjYWxsYmFjayhudWxsLCByZXN1bHRzKTtcbiAgICB9KTtcblxuICAgIGZ1bmN0aW9uIGFkZChidWZmLCBhdHRlbXB0KSB7XG4gICAgICB0cnkge1xuICAgICAgICBjb25zdCBsb2cgPSBKU09OLnBhcnNlKGJ1ZmYpO1xuICAgICAgICBpZiAoY2hlY2sobG9nKSkge1xuICAgICAgICAgIHB1c2gobG9nKTtcbiAgICAgICAgfVxuICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICBpZiAoIWF0dGVtcHQpIHtcbiAgICAgICAgICBzdHJlYW0uZW1pdCgnZXJyb3InLCBlKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIHB1c2gobG9nKSB7XG4gICAgICBpZiAoXG4gICAgICAgIG9wdGlvbnMucm93cyAmJlxuICAgICAgICByZXN1bHRzLmxlbmd0aCA+PSBvcHRpb25zLnJvd3MgJiZcbiAgICAgICAgb3B0aW9ucy5vcmRlciAhPT0gJ2Rlc2MnXG4gICAgICApIHtcbiAgICAgICAgaWYgKHN0cmVhbS5yZWFkYWJsZSkge1xuICAgICAgICAgIHN0cmVhbS5kZXN0cm95KCk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuO1xuICAgICAgfVxuXG4gICAgICBpZiAob3B0aW9ucy5maWVsZHMpIHtcbiAgICAgICAgbG9nID0gb3B0aW9ucy5maWVsZHMucmVkdWNlKChvYmosIGtle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N0aW9uIGFzeW5jRWFjaE9mTGltaXQoZ2VuZXJhdG9yLCBsaW1pdCwgaXRlcmF0ZWUsIGNhbGxiYWNrKSB7XG4gICAgbGV0IGRvbmUgPSBmYWxzZTtcbiAgICBsZXQgY2FuY2VsZWQgPSBmYWxzZTtcbiAgICBsZXQgYXdhaXRpbmcgPSBmYWxzZTtcbiAgICBsZXQgcnVubmluZyA9IDA7XG4gICAgbGV0IGlkeCA9IDA7XG5cbiAgICBmdW5jdGlvbiByZXBsZW5pc2goKSB7XG4gICAgICAgIC8vY29uc29sZS5sb2coJ3JlcGxlbmlzaCcpXG4gICAgICAgIGlmIChydW5uaW5nID49IGxpbWl0IHx8IGF3YWl0aW5nIHx8IGRvbmUpIHJldHVybjtcbiAgICAgICAgLy9jb25zb2xlLmxvZygncmVwbGVuaXNoIGF3YWl0aW5nJylcbiAgICAgICAgYXdhaXRpbmcgPSB0cnVlO1xuICAgICAgICBnZW5lcmF0b3IubmV4dCgpLnRoZW4oKHsgdmFsdWUsIGRvbmU6IGl0ZXJEb25lIH0pID0+IHtcbiAgICAgICAgICAgIC8vY29uc29sZS5sb2coJ2dvdCB2YWx1ZScsIHZhbHVlKVxuICAgICAgICAgICAgaWYgKGNhbmNlbGVkIHx8IGRvbmUpIHJldHVybjtcbiAgICAgICAgICAgIGF3YWl0aW5nID0gZmFsc2U7XG4gICAgICAgICAgICBpZiAoaXRlckRvbmUpIHtcbiAgICAgICAgICAgICAgICBkb25lID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICBpZiAocnVubmluZyA8PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2coJ2RvbmUgbmV4dENiJylcbiAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2sobnVsbCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJ1bm5pbmcrKztcbiAgICAgICAgICAgIGl0ZXJhdG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sdCkob2JqW1N5bWJvbC5hc3luY0l0ZXJhdG9yXSgpLCBsaW1pdCwgaXRlcmF0ZWUsIGNhbGxiYWNrKTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgbmV4dEVsZW0gPSAoMCwgX2l0ZXJhdG9yMi5kZWZhdWx0KShvYmopO1xuICAgICAgICB2YXIgZG9uZSA9IGZhbHNlO1xuICAgICAgICB2YXIgY2FuY2VsZWQgPSBmYWxzZTtcbiAgICAgICAgdmFyIHJ1bm5pbmcgPSAwO1xuICAgICAgICB2YXIgbG9vcGluZyA9IGZhbHNlO1xuXG4gICAgICAgIGZ1bmN0aW9uIGl0ZXJhdGVlQ2FsbGJhY2soZXJyLCB2YWx1ZSkge1xuICAgICAgICAgICAgaWYgKGNhbmNlbGVkKSByZXR1cm47XG4gICAgICAgICAgICBydW5uaW5nIC09IDE7XG4gICAgICAgICAgICBpZiAoZXJyKSB7XG4gICAgICAgICAgICAgICAgZG9uZSA9IHRydWU7XG4gICAgICAgICAgICAgICAgY2FsbGJhY2soZXJyKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoZXJyID09PSBmYWxzZSkge1xuICAgICAgICAgICAgICAgIGRvbmUgPSB0cnVlO1xuICAgICAgICAgICAgICAgIGNhbmNlbGVkID0gdHJ1ZTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodmFsdWUgPT09IF9icmVha0xvb3AyLmRlZmF1bHQgfHwgZG9uZSAmJiBydW5uaW5nIDw9IDApIHtcbiAgICAgICAgICAgICAgICBkb25lID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICByZXR1cm4gY2FsbGJhY2sobnVsbCk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKCFsb29waW5nKSB7XG4gICAgICAgICAgICAgICAgcmVwbGVuaXNoKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBmdW5jdGlvbiByZXBsZW5pc2goKSB7XG4gICAgICAgICAgICBsb29waW5nID0gdHJ1ZTtcbiAgICAgICAgICAgIHdoaWxlIChydW5uaW5nIDwgbGltaXQgJiYgIWRvbmUpIHtcbiAgICAgICAgICAgICAgICB2YXIgZWxlbSA9IG5leHRFbGVtKCk7XG4gICAgICAgICAgICAgICAgaWYgKGVsZW0gPT09IG51bGwpIHtcbiAgICAgICAgICAgICAgICAgICAgZG9uZSA9IHRydWU7XG4gICAgICAgICAgICAgICAgICAgIGlmIChydW5uaW5nIDw9IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNhbGxiYWNrKG51bGwpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcnVubmluZyArPSAxO1xuICAgICAgICAgICAgICAgIGl0ZXJhdGVlKGVsZW0udmFsdWUsIGVsZW0ua2V5LCAoMCwgX29ubHlPbmNlMi5kZWZhdWx0KShpdGVyYXRlZUNhbGxiYWNrKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBsb29waW5nID0gZmFsc2U7XG4gICAgICAgIH1cblxuICAgICAgICByZXBsZW5pc2goKTtcbiAgICB9O1xufTtcblxubW9kdWxlLmV4cG9ydHMgPSBleHBvcnRzLmRlZmF1bHQ7IiwiXCJ1c2Ugc3RyaWN0XCI7XG5cbk9iamVjdC5kZWZpbmVQcm9wZXJ0eShleHBvcnRzLCBcIl9fZXNNb2R1bGVcIiwge1xuICAgIHZhbHVlOiB0cnVlXG59KTtcblxuZXhwb3J0cy5kZWZhdWx0ID0gZnVuY3Rpb24gKGNvbGwpIHtcbiAgICByZXR1cm4gY29sbFtTeW1ib2wuaXRlcmF0b3JdICYmIGNvbGxbU3ltYm9sLml0ZXJhdG9yXSgpO1xufTtcblxubW9kdWxlLmV4cG9ydHMgPSBleHBvcnRzLmRlZmF1bHQ7IiwiXCJ1c2Ugc3RyaWN0XCI7XG5cbk9iamVjdC5kZWZpbmVQcm9wZXJ0eShleHBvcnRzLCBc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nN0ZWFkIG9mIGFuIGFycmF5XG4gKiBhc3luYy5zZXJpZXMoe1xuICogICAgIG9uZTogZnVuY3Rpb24oY2FsbGJhY2spIHtcbiAqICAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbigpIHtcbiAqICAgICAgICAgICAgIC8vIGRvIHNvbWUgYXN5bmMgdGFza1xuICogICAgICAgICAgICAgY2FsbGJhY2sobnVsbCwgMSk7XG4gKiAgICAgICAgIH0sIDIwMCk7XG4gKiAgICAgfSxcbiAqICAgICB0d286IGZ1bmN0aW9uKGNhbGxiYWNrKSB7XG4gKiAgICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24oKSB7XG4gKiAgICAgICAgICAgICAvLyB0aGVuIGRvIGFub3RoZXIgYXN5bmMgdGFza1xuICogICAgICAgICAgICAgY2FsbGJhY2sobnVsbCwgMik7XG4gKiAgICAgICAgIH0sIDEwMCk7XG4gKiAgICAgfVxuICogfSkudGhlbihyZXN1bHRzID0+IHtcbiAqICAgICBjb25zb2xlLmxvZyhyZXN1bHRzKTtcbiAqICAgICAvLyByZXN1bHRzIGlzIGVxdWFsIHRvOiB7IG9uZTogMSwgdHdvOiAyIH1cbiAqIH0pLmNhdGNoKGVyciA9PiB7XG4gKiAgICAgY29uc29sZS5sb2coZXJyKTtcbiAqIH0pO1xuICpcbiAqIC8vVXNpbmcgYXN5bmMvYXdhaXRcbiAqIGFzeW5jICgpID0+IHtcbiAqICAgICB0cnkge1xuICogICAgICAgICBsZXQgcmVzdWx0cyA9IGF3YWl0IGFzeW5jLnNlcmllcyhbXG4gKiAgICAgICAgICAgICBmdW5jdGlvbihjYWxsYmFjaykge1xuICogICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24oKSB7XG4gKiAgICAgICAgICAgICAgICAgICAgIC8vIGRvIHNvbWUgYXN5bmMgdGFza1xuICogICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayhudWxsLCAnb25lJyk7XG4gKiAgICAgICAgICAgICAgICAgfSwgMjAwKTtcbiAqICAgICAgICAgICAgIH0sXG4gKiAgICAgICAgICAgICBmdW5jdGlvbihjYWxsYmFjaykge1xuICogICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24oKSB7XG4gKiAgICAgICAgICAgICAgICAgICAgIC8vIHRoZW4gZG8gYW5vdGhlciBhc3luYyB0YXNrXG4gKiAgICAgICAgICAgICAgICAgICAgIGNhbGxiYWNrKG51bGwsICd0d28nKTtcbiAqICAgICAgICAgICAgICAgICB9LCAxMDApO1xuICogICAgICAgICAgICAgfVxuICogICAgICAgICBdKTtcbiAqICAgICAgICAgY29uc29sZS5sb2cocmVzdWx0cyk7XG4gKiAgICAgICAgIC8vIHJlc3VsdHMgaXMgZXF1YWwgdG8gWydvbmUnLCd0d28nXVxuICogICAgIH1cbiAqICAgICBjYXRjaCAoZXJyKSB7XG4gKiAgICAgICAgIGNvbnNvbGUubG9nKGVycik7XG4gKiAgICAgfVxuICogfVxuICpcbiAqIC8vIGFuIGV4YW1wbGUgdXNpbmcgYW4gb2JqZWN0IGluc3RlYWQgb2YgYW4gYXJyYXlcbiAqIGFzeW5jICgpID0+IHtcbiAqICAgICB0cnkge1xuICogICAgICAgICBsZXQgcmVzdWx0cyA9IGF3YWl0IGFzeW5jLnBhcmFsbGVsKHtcbiAqICAgICAgICAgICAgIG9uZTogZnVuY3Rpb24oY2FsbGJhY2spIHtcbiAqICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KGZ1bmN0aW9uKCkge1xuICogICAgICAgICAgICAgICAgICAgICAvLyBkbyBzb21lIGFzeW5jIHRhc2tcbiAqICAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2sobnVsbCwgMSk7XG4gKiAgICAgICAgICAgICAgICAgfSwgMjAwKTtcbiAqICAgICAgICAgICAgIH0sXG4gKiAgICAgICAgICAgIHR3bzogZnVuY3Rpb24oY2FsbGJhY2spIHtcbiAqICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KGZ1bm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iAgICAgIHZhciByZXQgPSBCdWZmZXIuYWxsb2NVbnNhZmUobik7XG4gICAgICB2YXIgcCA9IHRoaXMuaGVhZDtcbiAgICAgIHZhciBjID0gMTtcbiAgICAgIHAuZGF0YS5jb3B5KHJldCk7XG4gICAgICBuIC09IHAuZGF0YS5sZW5ndGg7XG4gICAgICB3aGlsZSAocCA9IHAubmV4dCkge1xuICAgICAgICB2YXIgYnVmID0gcC5kYXRhO1xuICAgICAgICB2YXIgbmIgPSBuID4gYnVmLmxlbmd0aCA/IGJ1Zi5sZW5ndGggOiBuO1xuICAgICAgICBidWYuY29weShyZXQsIHJldC5sZW5ndGggLSBuLCAwLCBuYik7XG4gICAgICAgIG4gLT0gbmI7XG4gICAgICAgIGlmIChuID09PSAwKSB7XG4gICAgICAgICAgaWYgKG5iID09PSBidWYubGVuZ3RoKSB7XG4gICAgICAgICAgICArK2M7XG4gICAgICAgICAgICBpZiAocC5uZXh0KSB0aGlzLmhlYWQgPSBwLm5leHQ7ZWxzZSB0aGlzLmhlYWQgPSB0aGlzLnRhaWwgPSBudWxsO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmhlYWQgPSBwO1xuICAgICAgICAgICAgcC5kYXRhID0gYnVmLnNsaWNlKG5iKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgKytjO1xuICAgICAgfVxuICAgICAgdGhpcy5sZW5ndGggLT0gYztcbiAgICAgIHJldHVybiByZXQ7XG4gICAgfVxuXG4gICAgLy8gTWFrZSBzdXJlIHRoZSBsaW5rZWQgbGlzdCBvbmx5IHNob3dzIHRoZSBtaW5pbWFsIG5lY2Vzc2FyeSBpbmZvcm1hdGlvbi5cbiAgfSwge1xuICAgIGtleTogY3VzdG9tLFxuICAgIHZhbHVlOiBmdW5jdGlvbiB2YWx1ZShfLCBvcHRpb25zKSB7XG4gICAgICByZXR1cm4gaW5zcGVjdCh0aGlzLCBfb2Jq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EpICYmICh0aGlzLm9wdGlvbnMucm9vdE5hbWUgPT09IGRlZmF1bHRzWycwLjInXS5yb290TmFtZSkpIHtcbiAgICAgICAgcm9vdE5hbWUgPSBPYmplY3Qua2V5cyhyb290T2JqKVswXTtcbiAgICAgICAgcm9vdE9iaiA9IHJvb3RPYmpbcm9vdE5hbWVdO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcm9vdE5hbWUgPSB0aGlzLm9wdGlvbnMucm9vdE5hbWU7XG4gICAgICB9XG4gICAgICByZW5kZXIgPSAoZnVuY3Rpb24oX3RoaXMpIHtcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKGVsZW1lbnQsIG9iaikge1xuICAgICAgICAgIHZhciBhdHRyLCBjaGlsZCwgZW50cnksIGluZGV4LCBrZXksIHZhbHVlO1xuICAgICAgICAgIGlmICh0eXBlb2Ygb2JqICE9PSAnb2JqZWN0Jykge1xuICAgICAgICAgICAgaWYgKF90aGlzLm9wdGlvbnMuY2RhdGEgJiYgcmVxdWlyZXNDREFUQShvYmopKSB7XG4gICAgICAgICAgICAgIGVsZW1lbnQucmF3KHdyYXBDREFUQShvYmopKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIGVsZW1lbnQudHh0KG9iaik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KG9iaikpIHtcbiAgICAgICAgICAgIGZvciAoaW5kZXggaW4gb2JqKSB7XG4gICAgICAgICAgICAgIGlmICghaGFzUHJvcC5jYWxsKG9iaiwgaW5kZXgpKSBjb250aW51ZTtcbiAgICAgICAgICAgICAgY2hpbGQgPSBvYmpbaW5kZXhdO1xuICAgICAgICAgICAgICBmb3IgKGtleSBpbiBjaGlsZCkge1xuICAgICAgICAgICAgICAgIGVudHJ5ID0gY2hpbGRba2V5XTtcbiAgICAgICAgICAgICAgICBlbGVtZW50ID0gcmVuZGVyKGVsZW1lbnQuZWxlKGtleSksIGVudHJ5KS51cCgpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGZvciAoa2V5IGluIG9iaikge1xuICAgICAgICAgICAgICBpZiAoIWhhc1Byb3AuY2FsbChvYmosIGtleSkpIGNvbnRpbnVlO1xuICAgICAgICAgICAgICBjaGlsZCA9IG9ialtrZXldO1xuICAgICAgICAgICAgICBpZiAoa2V5ID09PSBhdHRya2V5KSB7XG4gICAgICAgICAgICAgICAgaWYgKHR5cGVvZiBjaGlsZCA9PT0gXCJvYmplY3RcIikge1xuICAgICAgICAgICAgICAgICAgZm9yIChhdHRyIGluIGNoaWxkKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhbHVlID0gY2hpbGRbYXR0cl07XG4gICAgICAgICAgICAgICAgICAgIGVsZW1lbnQgPSBlbGVtZW50LmF0dChhdHRyLCB2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9IGVsc2UgaWYgKGtleSA9PT0gY2hhcmtleSkge1xuICAgICAgICAgICAgICAgIGlmIChfdGhpcy5vcHRpb25zLmNkYXRhICYmIHJlcXVpcmVzQ0RBVEEoY2hpbGQpKSB7XG4gICAgICAgICAgICAgICAgICBlbGVtZW50ID0gZWxlbWVudC5yYXcod3JhcENEQVRBKGNoaWxkKSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIGVsZW1lbnQgPSBlbGVtZW50LnR4dChjaGlsZCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9IGVsc2UgaWYgKEFycmF5LmlzQXJyYXkoY2hpbGQpKSB7XG4gICAgICAgICAgICAgICAgZm9yIChpbmRleCBpbiBjaGlsZCkge1xuICAgICAgICAgICAgICAgICAgaWYgKCFoYXNQcm9wLmNhbGwoY2hpbGQsIGluZGV4KSkgY29udGludWU7XG4gICAgICAgICAgICAgICAgICBlbnRyeSA9IGNoaWxkW2luZGV4XTtcbiAgICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgZW50cnkgPT09ICdzdHJpbmcnKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChfdGhpcy5vcHRpb25zLmNkYXRhICYmIHJlcXVpcmVzQ0RBVEEoZW50cnkpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgZWxlbWVudCA9IGVsZW1lbnQuZWxlKGtleSkucmF3KHdyYXBDREFUQShlbnRyeSkpLnVwKCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgZWxlbWVudCA9IGVsZW1lbnQuZWxlKGtleSwgZW50cnkpLnVwKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGVsZW1lbnQgPSByZW5kZXIoZWxlbWVudC5lbGUoa2V5KSwgZW50cnkpLnVwKCk7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBjaGlsZCA9PT0gXCJvYmplY3RcIikge1xuICAgICAgICAgICAgICAgIGVsZW1lbnQgPSByZW5kZXIoZWxlbWVudC5lbGUoa2V5KSwgY2hpbGQpLnVwKCk7XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaWYgKHR5cGVvZiBjaGlsZCA9PT0gJ3N0cmluZycgJiYgX3RoaXMub3B0aW9ucy5jZGF0YSAmJiByZXF1aXJlc0NEQVRBKGNoaWxkKSkge1xuICAgICAgICAgICAgICAgICAgZWxlbWVudCA9IGVsZW1lbnQuZWxlKGtleSkucmF3KHdyYXBDREFUQShjaGlsZCkpLnVwKCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIGlmIChjaGlsZCA9PSBudWxsKSB7XG4gICAgICAgICAgICAgICAgICAgIGNoaWxkID0gJyc7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICBlbGVtZW50ID0gZWxlbWVudC5lbGUoa2V5LCBjaGlsZC50b1N0cmluZygpKS51cCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4gZWxlbWVudDtcbiAgICAgICAgfTtcbiAgICAgIH0pKHRoaXMpO1xuICAgICAgcm9vdEVsZW1lbnQgPSBidWlsZGVyLmNyZWF0ZShyb290TmFtZSwgdGhpcy5vcHRpb25zLnhtbGRlYywgdGhpcy5vcHRpb25zLmRvY3R5cGUsIHtcbiAgICAgICAgaGVhZGxlc3M6IHRoaXMub3B0aW9ucy5oZWFkbGVzcyxcbiAgICAgICAgYWxsb3dTdXJyb2dhdGVDaGFyczogdGhpcy5vcHRpb25zLmFsbG93U3Vycm9nYXRlQ2hhcnNcbiAgICAgIH0pO1xuICAgICAgcmV0dXJuIHJlbmRlcihyb290RWxlbWVudCwgcm9vdE9iaikuZW5kKHRoaXMub3B0aW9ucy5yZW5kZXJPcHRzKTtcbiAgICB9O1xuXG4gICAgcmV0dXJuIEJ1aWxkZXI7XG5cbiAgfSkoKTtcblxufSkuY2FsbCh0aGlzKTtcbiIsIi8vIEdlbmVyYXRlZCBieSBDb2ZmZWVTY3JpcHQgMS4xMi43XG4oZnVuY3Rpb24oKSB7XG4gIGV4cG9ydHMuZGVmYXVsdHMgPSB7XG4gICAgXCIwLjFcIjoge1xuICAgICAgZXhwbGljaXRDaGFya2V5OiBmYWxzZSxcbiAgICAgIHRyaW06IHRydWUsXG4gICAgICBub3JtYWxpemU6IHRydWUsXG4gICAgICBub3JtYWxpemVUYWdzOiBmYWxzZSxcbiAgICAgIGF0dHJrZXk6IFwiQFwiLFxuICAgICAgY2hhcmtleTogXCIjXCIsXG4gICAgICBleHBsaWNpdEF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m9wLmNhbGwocmVmLCBrZXkpKSBjb250aW51ZTtcbiAgICAgICAgdmFsdWUgPSByZWZba2V5XTtcbiAgICAgICAgdGhpcy5vcHRpb25zW2tleV0gPSB2YWx1ZTtcbiAgICAgIH1cbiAgICAgIGZvciAoa2V5IGluIG9wdHMpIHtcbiAgICAgICAgaWYgKCFoYXNQcm9wLmNhbGwob3B0cywga2V5KSkgY29udGludWU7XG4gICAgICAgIHZhbHVlID0gb3B0c1trZXldO1xuICAgICAgICB0aGlzLm9wdGlvbnNba2V5XSA9IHZhbHVlO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMub3B0aW9ucy54bWxucykge1xuICAgICAgICB0aGlzLm9wdGlvbnMueG1sbnNrZXkgPSB0aGlzLm9wdGlvbnMuYXR0cmtleSArIFwibnNcIjtcbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLm9wdGlvbnMubm9ybWFsaXplVGFncykge1xuICAgICAgICBpZiAoIXRoaXMub3B0aW9ucy50YWdOYW1lUHJvY2Vzc29ycykge1xuICAgICAgICAgIHRoaXMub3B0aW9ucy50YWdOYW1lUHJvY2Vzc29ycyA9IFtdO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMub3B0aW9ucy50YWdOYW1lUHJvY2Vzc29ycy51bnNoaWZ0KHByb2Nlc3NvcnMubm9ybWFsaXplKTtcbiAgICAgIH1cbiAgICAgIHRoaXMucmVzZXQoKTtcbiAgICB9XG5cbiAgICBQYXJzZXIucHJvdG90eXBlLnByb2Nlc3NBc3luYyA9IGZ1bmN0aW9uKCkge1xuICAgICAgdmFyIGNodW5rLCBlcnI7XG4gICAgICB0cnkge1xuICAgICAgICBpZiAodGhpcy5yZW1haW5pbmcubGVuZ3RoIDw9IHRoaXMub3B0aW9ucy5jaHVua1NpemUpIHtcbiAgICAgICAgICBjaHVuayA9IHRoaXMucmVtYWluaW5nO1xuICAgICAgICAgIHRoaXMucmVtYWluaW5nID0gJyc7XG4gICAgICAgICAgdGhpcy5zYXhQYXJ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ZWxzZSB7XG4gICAgICAgIGlmICghKG9ialtrZXldIGluc3RhbmNlb2YgQXJyYXkpKSB7XG4gICAgICAgICAgb2JqW2tleV0gPSBbb2JqW2tleV1dO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBvYmpba2V5XS5wdXNoKG5ld1ZhbHVlKTtcbiAgICAgIH1cbiAgICB9O1xuXG4gICAgUGFyc2VyLnByb3RvdHlwZS5yZXNldCA9IGZ1bmN0aW9uKCkge1xuICAgICAgdmFyIGF0dHJrZXksIGNoYXJrZXksIG9udGV4dCwgc3RhY2s7XG4gICAgICB0aGlzLnJlbW92ZUFsbExpc3RlbmVycygpO1xuICAgICAgdGhpcy5zYXhQYXJzZXIgPSBzYXgucGFyc2VyKHRoaXMub3B0aW9ucy5zdHJpY3QsIHtcbiAgICAgICAgdHJpbTogZmFsc2UsXG4gICAgICAgIG5vcm1hbGl6ZTogZmFsc2UsXG4gICAgICAgIHhtbG5zOiB0aGlzLm9wdGlvbnMueG1sbnNcbiAgICAgIH0pO1xuICAgICAgdGhpcy5zYXhQYXJzZXIuZXJyVGhyb3duID0gZmFsc2U7XG4gICAgICB0aGlzLnNheFBhcnNlci5vbmVycm9yID0gKGZ1bmN0aW9uKF90aGlzKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbihlcnJvcikge1xuICAgICAgICAgIF90aGlzLnNheFBhcnNlci5yZXN1bWUoKTtcbiAgICAgICAgICBpZiAoIV90aGlzLnNheFBhcnNlci5lcnJUaHJvd24pIHtcbiAgICAgICAgICAgIF90aGlzLnNheFBhcnNlci5lcnJUaHJvd24gPSB0cnVlO1xuICAgICAgICAgICAgcmV0dXJuIF90aGlzLmVtaXQoXCJlcnJvclwiLCBlcnJvcik7XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgfSkodGhpcyk7XG4gICAgICB0aGlzLnNheFBhcnNlci5vbmVuZCA9IChmdW5jdGlvbihfdGhpcykge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24oKSB7XG4gICAgICAgICAgaWYgKCFfdGhpcy5zYXhQYXJzZXIuZW5kZWQpIHtcbiAgICAgICAgICAgIF90aGlzLnNheFBhcnNlci5lbmRlZCA9IHRydWU7XG4gICAgICAgICAgICByZXR1cm4gX3RoaXMuZW1pdChcImVuZFwiLCBfdGhpcy5yZXN1bHRPYmplY3QpO1xuICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgIH0pKHRoaXMpO1xuICAgICAgdGhpcy5zYXhQYXJzZXIuZW5kZWQgPSBmYWxzZTtcbiAgICAgIHRoaXMuRVhQTElDSVRfQ0hBUktFWSA9IHRoaXMub3B0aW9ucy5leHBsaWNpdENoYXJrZXk7XG4gICAgICB0aGlzLnJlc3VsdE9iamVjdCA9IG51bGw7XG4gICAgICBzdGFjayA9IFtdO1xuICAgICAgYXR0cmtleSA9IHRoaXMub3B0aW9ucy5hdHRya2V5O1xuICAgICAgY2hhcmtleSA9IHRoaXMub3B0aW9ucy5jaGFya2V5O1xuICAgICAgdGhpcy5zYXhQYXJzZXIub25vcGVudGFnID0gKGZ1bmN0aW9uKF90aGlzKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbihub2RlKSB7XG4gICAgICAgICAgdmFyIGtleSwgbmV3VmFsdWUsIG9iaiwgcHJvY2Vzc2VkS2V5LCByZWY7XG4gICAgICAgICAgb2JqID0gT2JqZWN0LmNyZWF0ZShudWxsKTtcbiAgICAgICAgICBvYmpbY2hhcmtleV0gPSBcIlwiO1xuICAgICAgICAgIGlmICghX3RoaXMub3B0aW9ucy5pZ25vcmVBdHRycykge1xuICAgICAgICAgICAgcmVmID0gbm9kZS5hdHRyaWJ1dGVzO1xuICAgICAgICAgICAgZm9yIChrZXkgaW4gcmVmKSB7XG4gICAgICAgICAgICAgIGlmICghaGFzUHJvcC5jYWxsKHJlZiwga2V5KSkgY29udGludWU7XG4gICAgICAgICAgICAgIGlmICghKGF0dHJrZXkgaW4gb2JqKSAmJiAhX3RoaXMub3B0aW9ucy5tZXJnZUF0dHJzKSB7XG4gICAgICAgICAgICAgICAgb2JqW2F0dHJrZXldID0gT2JqZWN0LmNyZWF0ZShudWxsKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBuZXdWYWx1ZSA9IF90aGlzLm9wdGlvbnMuYXR0clZhbHVlUHJvY2Vzc29ycyA/IHByb2Nlc3NJdGVtKF90aGlzLm9wdGlvbnMuYXR0clZhbHVlUHJvY2Vzc29ycywgbm9kZS5hdHRyaWJ1dGVzW2tleV0sIGtleSkgOiBub2RlLmF0dHJpYnV0ZXNba2V5XTtcbiAgICAgICAgICAgICAgcHJvY2Vzc2VkS2V5ID0gX3RoaXMub3B0aW9ucy5hdHRyTmFtZVByb2Nlc3NvcnMgPyBwcm9jZXNzSXRlbShfdGhpcy5vcHRpb25zLmF0dHJOYW1lUHJvY2Vzc29ycywga2V5KSA6IGtleTtcbiAgICAgICAgICAgICAgaWYgKF90aGlzLm9wdGlvbnMubWVyZ2VBdHRycykge1xuICAgICAgICAgICAgICAgIF90aGlzLmFzc2lnbk9yUHVzaChvYmosIHByb2Nlc3NlZEtleSwgbmV3VmFsdWUpO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIG9ialthdHRya2V5XVtwcm9jZXNzZWRLZXldID0gbmV3VmFsdWU7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgb2JqW1wiI25hbWVcIl0gPSBfdGhpcy5vcHRpb25zLnRhZ05hbWVQcm9jZXNzb3JzID8gcHJvY2Vzc0l0ZW0oX3RoaXMub3B0aW9ucy50YWdOYW1lUHJvY2Vzc29ycywgbm9kZS5uYW1lKSA6IG5vZGUubmFtZTtcbiAgICAgICAgICBpZiAoX3RoaXMub3B0aW9ucy54bWxucykge1xuICAgICAgICAgICAgb2JqW190aGlzLm9wdGlvbnMueG1sbnNrZXldID0ge1xuICAgICAgICAgICAgICB1cmk6IG5vZGUudXJpLFxuICAgICAgICAgICAgICBsb2NhbDogbm9kZS5sb2NhbFxuICAgICAgICAgICAgfTtcbiAgICAgICAgICB9XG4gICAgICAgICAgcmV0dXJuIHN0YWNrLnB1c2gob2JqKTtcbiAgICAgICAgfTtcbiAgICAgIH0pKHRoaXMpO1xuICAgICAgdGhpcy5zYXhQYXJzZXIub25jbG9zZXRhZyA9IChmdW5jdGlvbihfdGhpcykge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24oKSB7XG4gICAgICAgICAgdmFyIGNkYXRhLCBlbXB0eVN0ciwga2V5LCBub2RlLCBub2RlTmFtZSwgb2JqLCBvYmpDbG9uZSwgb2xkLCBzLCB4cGF0aDtcbiAgICAgICAgICBvYmogPSBzdGFjay5wb3AoKTtcbiAgICAgICAgICBub2RlTmFtZSA9IG9ialtcIiNuYW1lXCJdO1xuICAgICAgICAgIGlmICghX3RoaXMub3B0aW9ucy5leHBsaWNpdENoaWxkcmVuIHx8ICFfdGhpcy5vcHRpb25zLnByZXNlcnZlQ2hpbGRyZW5PcmRlcikge1xuICAgICAgICAgICAgZGVsZXRlIG9ialtcIiNuYW1lXCJdO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAob2JqLmNkYXRhID09PSB0cnVlKSB7XG4gICAgICAgICAgICBjZGF0YSA9IG9iai5jZGF0YTtcbiAgICAgICAgICAgIGRlbGV0ZSBvYmouY2RhdGE7XG4gICAgICAgICAgfVxuICAgICAgICAgIHMgPSBzdGFja1tzdGFjay5sZW5ndGggLSAxXTtcbiAgICAgICAgICBpZiAob2JqW2NoYXJrZXldLm1hdGNoKC9eXFxzKiQvKSAmJiAhY2RhdGEpIHtcbiAgICAgICAgICAgIGVtcHR5U3RyID0gb2JqW2NoYXJrZXldO1xuICAgICAgICAgICAgZGVsZXRlIG9ialtjaGFya2V5XTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKF90aGlzLm9wdGlvbnMudHJpbSkge1xuICAgICAgICAgICAgICBvYmpbY2hhcmtleV0gPSBvYmpbY2hhcmtleV0udHJpbSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKF90aGlzLm9wdGlvbnMubm9ybWFsaXplKSB7XG4gICAgICAgICAgICAgIG9ialtjaGFya2V5XSA9IG9ialtjaGFya2V5XS5yZXBsYWNlKC9cXHN7Mix9L2csIFwiIFwiKS50cmltKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBvYmpbY2hhcmtleV0gPSBfdGhpcy5vcHRpb25zLnZhbHVlUHJvY2Vzc29ycyA/IHByb2Nlc3NJdGVtKF90aGlzLm9wdGlvbnMudmFsdWVQcm9jZXNzb3JzLCBvYmpbY2hhcmtleV0sIG5vZGVOYW1lKSA6IG9ialtjaGFya2V5XTtcbiAgICAgICAgICAgIGlmIChPYmplY3Qua2V5cyhvYmopLmxlbmd0aCA9PT0gMSAmJiBjaGFya2V5IGluIG9iaiAmJiAhX3RoaXMuRVhQTElDSVRfQ0hBUktFWSkge1xuICAgICAgICAgICAgICBvYmogPSBvYmpbY2hhcmtleV07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChpc0VtcHR5KG9iaikpIHtcbiAgICAgICAgICAgIGlmICh0eXBlb2YgX3RoaXMub3B0aW9ucy5lbXB0eVRhZyA9PT0gJ2Z1bmN0aW9uJykge1xuICAgICAgICAgICAgICBvYmogPSBfdGhpcy5vcHRpb25zLmVtcHR5VGFnKCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBvYmogPSBfdGhpcy5vcHRpb25zLmVtcHR5VGFnICE9PSAnJyA/IF90aGlzLm9wdGlvbnMuZW1wdHlUYWcgOiBlbXB0eVN0cjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKF90aGlzLm9wdGlvbnMudmFsaWRhdG9yICE9IG51bGwpIHtcbiAgICAgICAgICAgIHhwYXRoID0gXCIvXCIgKyAoKGZ1bmN0aW9uKCkge1xuICAgICAgICAgICAgICB2YXIgaSwgbGVuLCByZXN1bHRzO1xuICAgICAgICAgICAgICByZXN1bHRzID0gW107XG4gICAgICAgICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IHN0YWNrLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgbm9kZSA9IHN0YWNrW2ldO1xuICAgICAgICAgICAgICAgIHJlc3VsdHMucHVzaChub2RlW1wiI25hbWVcIl0pO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHJldHVybiByZXN1bHRzO1xuICAgICAgICAgICAgfSkoKSkuY29uY2F0KG5vZGVOYW1lKS5qb2luKFwiL1wiKTtcbiAgICAgICAgICAgIChmdW5jdGlvbigpIHtcbiAgICAgICAgICAgICAgdmFyIGVycjtcbiAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICByZXR1cm4gb2JqID0gX3RoaXMub3B0aW9ucy52YWxpZGF0b3IoeHBhdGgsIHMgJiYgc1tub2RlTmFtZV0sIG9iaik7XG4gICAgICAgICAgICAgIH0gY2F0Y2ggKGVycm9yMSkge1xuICAgICAgICAgICAgICAgIGVyciA9IGVycm9yMTtcbiAgICAgICAgICAgICAgICByZXR1cm4gX3RoaXMuZW1pdChcImVycm9yXCIsIGVycik7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pKCk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChfdGhpcy5vcHRpb25zLmV4cGxpY2l0Q2hpbGRyZW4gJiYgIV90aGlzLm9wdGlvbnMubWVyZ2VBdHRycyAmJiB0eXBlb2Ygb2JqID09PSAnb2JqZWN0Jykge1xuICAgICAgICAgICAgaWYgKCFfdGhpcy5vcHRpb25zLnByZXNlcnZlQ2hpbGRyZW5PcmRlcikge1xuICAgICAgICAgICAgICBub2RlID0gT2JqZWN0LmNyZWF0ZShudWxsKTtcbiAgICAgICAgICAgICAgaWYgKF90aGlzLm9wdGlvbnMuYXR0cmtleSBpbiBvYmopIHtcbiAgICAgICAgICAgICAgICBub2RlW190aGlzLm9wdGlvbnMuYXR0cmtleV0gPSBvYmpbX3RoaXMub3B0aW9ucy5hdHRya2V5XTtcbiAgICAgICAgICAgICAgICBkZWxldGUgb2JqW190aGlzLm9wdGlvbnMuYXR0cmtleV07XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgaWYgKCFfdGhpcy5vcHRpb25zLmNoYXJzQXNDaGlsZHJlbiAmJiBfdGhpcy5vcHRpb25zLmNoYXJrZXkgaW4gb2JqKSB7XG4gICAgICAgICAgICAgICAgbm9kZVtfdGhpcy5vcHRpb25zLmNoYXJrZXldID0gb2JqW190aGlzLm9wdGlvbnMuY2hhcmtleV07XG4gICAgICAgICAgICAgICAgZGVsZXRlIG9ialtfdGhpcy5vcHRpb25zLmNoYXJrZXldO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGlmIChPYmplY3QuZ2V0T3duUHJvcGVydHlOYW1lcyhvYmopLmxlbmd0aCA+IDApIHtcbiAgICAgICAgICAgICAgICBub2RlW190aGlzLm9wdGlvbnMuY2hpbGRrZXldID0gb2JqO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIG9iaiA9IG5vZGU7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHMpIHtcbiAgICAgICAgICAgICAgc1tfdGhpcy5vcHRpb25zLmNoaWxka2V5XSA9IHNbX3RoaXMub3B0aW9ucy5jaGlsZGtleV0gfHwgW107XG4gICAgICAgICAgICAgIG9iakNsb25lID0gT2JqZWN0LmNyZWF0ZShudWxsKTtcbiAgICAgICAgICAgICAgZm9yIChrZXkgaW4gb2JqKSB7XG4gICAgICAgICAgICAgICAgaWYgKCFoYXNQcm9wLmNhbGwob2JqLCBrZXkpKSBjb250aW51ZTtcbiAgICAgICAgICAgICAgICBvYmpDbG9uZVtrZXldID0gb2JqW2tleV07XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgc1tfdGhpcy5vcHRpb25zLmNoaWxka2V5XS5wdXNoKG9iakNsb25lKTtcbiAgICAgICAgICAgICAgZGVsZXRlIG9ialtcIiNuYW1lXCJdO1xuICAgICAgICAgICAgICBpZiAoT2JqZWN0LmtleXMob2JqKS5sZW5ndGggPT09IDEgJiYgY2hhcmtleSBpbiBvYmogJiYgIV90aGlzLkVYUExJQ0lUX0NIQVJLRVkpIHtcbiAgICAgICAgICAgICAgICBvYmogPSBvYmpbY2hhcmtleV07XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHN0YWNrLmxlbmd0aCA+IDApIHtcbiAgICAgICAgICAgIHJldHVybiBfdGhpcy5hc3NpZ25PclB1c2gocywgbm9kZU5hbWUsIG9iaik7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChfdGhpcy5vcHRpb25zLmV4cGxpY2l0Um9vdCkge1xuICAgICAgICAgICAgICBvbGQgPSBvYmo7XG4gICAgICAgICAgICAgIG9iaiA9IE9iamVjdC5jcmVhdGUobnVsbCk7XG4gICAgICAgICAgICAgIG9ialtub2RlTmFtZV0gPSBvbGQ7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBfdGhpcy5yZXN1bHRPYmplY3QgPSBvYmo7XG4gICAgICAgICAgICBfdGhpcy5zYXhQYXJzZXIuZW5kZWQgPSB0cnVlO1xuICAgICAgICAgICAgcmV0dXJuIF90aGlzLmVtaXQoXCJlbmRcIiwgX3RoaXMucmVzdWx0T2JqZWN0KTtcbiAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICB9KSh0aGlzKTtcbiAgICAgIG9udGV4dCA9IChmdW5jdGlvbihfdGhpcykge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24odGV4dCkge1xuICAgICAgICAgIHZhciBjaGFyQ2hpbGQsIHM7XG4gICAgICAgICAgcyA9IHN0YWNrW3N0YWNrLmxlbmd0aCAtIDFdO1xuICAgICAgICAgIGlmIChzKSB7XG4gICAgICAgICAgICBzW2NoYXJrZXldICs9IHRleHQ7XG4gICAgICAgICAgICBpZiAoX3RoaXMub3B0aW9ucy5leHBsaWNpdENoaWxkcmVuICYmIF90aGlzLm9wdGlvbnMucHJlc2VydmVDaGlsZHJlbk9yZGVyICYmIF90aGlzLm9wdGlvbnMuY2hhcnNBc0NoaWxkcmVuICYmIChfdGhpcy5vcHRpb25zLmluY2x1ZGVXaGl0ZUNoYXJzIHx8IHRleHQucmVwbGFjZSgvXFxcXG4vZywgJycpLnRyaW0oKSAhPT0gJycpKSB7XG4gICAgICAgICAgICAgIHNbX3RoaXMub3B0aW9ucy5jaGlsZGtleV0gPSBzW190aGlzLm9wdGlvbnMuY2hpbGRrZXldIHx8IFtdO1xuICAgICAgICAgICAgICBjaGFyQ2hpbGQgPSB7XG4gICAgICAgICAgICAgICAgJyNuYW1lJzogJ19fdGV4dF9fJ1xuICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICBjaGFyQ2hpbGRbY2hhcmtleV0gPSB0ZXh0O1xuICAgICAgICAgICAgICBpZiAoX3RoaXMub3B0aW9ucy5ub3JtYWxpemUpIHtcbiAgICAgICAgICAgICAgICBjaGFyQ2hpbGRbY2hhcmtleV0gPSBjaGFyQ2hpbGRbY2hhcmtleV0ucmVwbGFjZSgvXFxzezIsfS9nLCBcIiBcIikudHJpbSgpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHNbX3RoaXMub3B0aW9ucy5jaGlsZGtleV0ucHVzaChjaGFyQ2hpbGQpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIHM7XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgfSkodGhpcyk7XG4gICAgICB0aGlzLnNheFBhcnNlci5vbnRleHQgPSBvbnRleHQ7XG4gICAgICByZXR1cm4gdGhpcy5zYXhQYXJzZXIub25jZGF0YSA9IChmdW5jdGlvbihfdGhpcykge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24odGV4dCkge1xuICAgICAgICAgIHZhciBzO1xuICAgICAgICAgIHMgPSBvbnRleHQodGV4dCk7XG4gICAgICAgICAgaWYgKHMpIHtcbiAgICAgICAgICAgIHJldHVybiBzLmNkYXRhID0gdHJ1ZTtcbiAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICB9KSh0aGlzKTtcbiAgICB9O1xuXG4gICAgUGFyc2VyLnByb3RvdHlwZS5wYXJzZVN0cmluZyA9IGZ1bmN0aW9uKHN0ciwgY2IpIHtcbiAgICAgIHZhciBlcnI7XG4gICAgICBpZiAoKGNiICE9IG51bGwpICYmIHR5cGVvZiBjYiA9PT0gXCJmdW5jdGlvblwiKSB7XG4gICAgICAgIHRoaXMub24oXCJlbmRcIiwgZnVuY3Rpb24ocmVzdWx0KSB7XG4gICAgICAgICAgdGhpcy5yZXNldCgpO1xuICAgICAgICAgIHJldHVybiBjYihudWxsLCByZXN1bHQpO1xuICAgICAgICB9KTtcbiAgICAgICAgdGhpcy5vbihcImVycm9yXCIsIGZ1bmN0aW9uKGVycikge1xuICAgICAgICAgIHRoaXMucmVzZXQoKTtcbiAgICAgICAgICByZXR1cm4gY2IoZXJyKTtcbiAgICAgICAgfSk7XG4gICAgICB9XG4gICAgICB0cnkge1xuICAgICAgICBzdHIgPSBzdHIudG9TdHJpbmcoKTtcbiAgICAgICAgaWYgKHN0ci50cmltKCkgPT09ICcnKSB7XG4gICAgICAgICAgdGhpcy5lbWl0KFwiZW5kXCIsIG51bGwpO1xuICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG4gICAgICAgIHN0ciA9IGJvbS5zdHJpcEJPTShzdHIpO1xuICAgICAgICBpZiAodGhpcy5vcHRpb25zLmFzeW5jKSB7XG4gICAgICAgICAgdGhpcy5yZW1haW5pbmcgPSBzdHI7XG4gICAgICAgICAgc2V0SW1tZWRpYXRlKHRoaXMucHJvY2Vzc0FzeW5jKTtcbiAgICAgICAgICByZXR1cm4gdGhpcy5zYXhQYXJzZXI7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRoaXMuc2F4UGFyc2VyLndyaXRlKHN0cikuY2xvc2UoKTtcbiAgICAgIH0gY2F0Y2ggKGVycm9yMSkge1xuICAgICAgICBlcnIgPSBlcnJvcjE7XG4gICAgICAgIGlmICghKHRoaXMuc2F4UGFyc2VyLmVyclRocm93biB8fCB0aGlzLnNheFBhcnNlci5lbmRlZCkpIHtcbiAgICAgICAgICB0aGlzLmVtaXQoJ2Vycm9yJywgZXJyKTtcbiAgICAgICAgICByZXR1cm4gdGhpcy5zYXhQYXJzZXIuZXJyVGhyb3duID0gdHJ1ZTtcbiAgICAgICAgfSBlbHNlIGlmICh0aGlzLnNheFBhcnNlci5lbmRlZCkge1xuICAgICAgICAgIHRocm93IGVycjtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH07XG5cbiAgICBQYXJzZXIucHJvdG90eXBlLnBhcnNlU3RyaW5nUHJvbWlzZSA9IGZ1bmN0aW9uKHN0cikge1xuICAgICAgcmV0dXJuIG5ldyBQcm9taXNlKChmdW5jdGlvbihfdGhpcykge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24ocmVzb2x2ZSwgcmVqZWN0KSB7XG4gICAgICAgICAgcmV0dXJuIF90aGlzLnBhcnNlU3RyaW5nKHN0ciwgZnVuY3Rpb24oZXJyLCB2YWx1ZSkge1xuICAgICAgICAgICAgaWYgKGVycikge1xuICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGVycik7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICByZXR1cm4gcmVzb2x2ZSh2YWx1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSk7XG4gICAgICAgIH07XG4gICAgICB9KSh0aGlzKSk7XG4gICAgfTtcblxuICAgIHJldHVybiBQYXJzZXI7XG5cbiAgfSkoZXZlbnRzKTtcblxuICBleHBvcnRzLnBhcnNlU3R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TGV2ZWwpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBjaHVuayArPSAobm9kZS5jaGlsZHJlbiA/ICc+JyA6ICcvPicpICsgdGhpcy53cml0ZXIuZW5kbGluZShub2RlLCB0aGlzLndyaXRlck9wdGlvbnMsIHRoaXMuY3VycmVudExldmVsKTtcbiAgICAgICAgICB0aGlzLndyaXRlck9wdGlvbnMuc3RhdGUgPSBXcml0ZXJTdGF0ZS5JbnNpZGVUYWc7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhpcy53cml0ZXJPcHRpb25zLnN0YXRlID0gV3JpdGVyU3RhdGUuT3BlblRhZztcbiAgICAgICAgICBjaHVuayA9IHRoaXMud3JpdGVyLmluZGVudChub2RlLCB0aGlzLndyaXRlck9wdGlvbnMsIHRoaXMuY3VycmVudExldmVsKSArICc8IURPQ1RZUEUgJyArIG5vZGUucm9vdE5vZGVOYW1lO1xuICAgICAgICAgIGlmIChub2RlLnB1YklEICYmIG5vZGUuc3lzSUQpIHtcbiAgICAgICAgICAgIGNodW5rICs9ICcgUFVCTElDIFwiJyArIG5vZGUucHViSUQgKyAnXCIgXCInICsgbm9kZS5zeXNJRCArICdcIic7XG4gICAgICAgICAgfSBlbHNlIGlmIChub2RlLnN5c0lEKSB7XG4gICAgICAgICAgICBjaHVuayArPSAnIFNZU1RFTSBcIicgKyBub2RlLnN5c0lEICsgJ1wiJztcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKG5vZGUuY2hpbGRyZW4pIHtcbiAgICAgICAgICAgIGNodW5rICs9ICcgWyc7XG4gICAgICAgICAgICB0aGlzLndyaXRlck9wdGlvbnMuc3RhdGUgPSBXcml0ZXJTdGF0ZS5JbnNpZGVUYWc7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMud3JpdGVyT3B0aW9ucy5zdGF0ZSA9IFdyaXRlclN0YXRlLkNsb3NlVGFnO1xuICAgICAgICAgICAgY2h1bmsgKz0gJz4nO1x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VmMS5sZW5ndGg7IGogPCBsZW47IGorKykge1xuICAgICAgICAgICAgY2hpbGQgPSByZWYxW2pdO1xuICAgICAgICAgICAgaWYgKGNoaWxkLnR5cGUgPT09IE5vZGVUeXBlLkRvY1R5cGUpIHtcbiAgICAgICAgICAgICAgY2hpbGQubmFtZSA9IHRoaXMubmFtZTtcbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuXG4gICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KFhNTEVsZW1lbnQucHJvdG90eXBlLCAndGFnTmFtZScsIHtcbiAgICAgIGdldDogZnVuY3Rpb24oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLm5hbWU7XG4gICAgICB9XG4gICAgfSk7XG5cbiAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoWE1MRWxlbWVudC5wcm90b3R5cGUsICduYW1lc3BhY2VVUkknLCB7XG4gICAgICBnZXQ6IGZ1bmN0aW9uKCkge1xuICAgICAgICByZXR1cm4gJyc7XG4gICAgICB9XG4gICAgfSk7XG5cbiAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoWE1MRWxlbWVudC5wcm90b3R5cGUsICdwcmVmaXgnLCB7XG4gICAgICBnZXQ6IGZ1bmN0aW9uKCkge1xuICAgICAgICByZXR1cm4gJyc7XG4gICAgICB9XG4gICAgfSk7XG5cbiAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoWE1MRWxlbWVudC5wcm90b3R5cGUsICdsb2NhbE5hbWUnLCB7XG4gICAgICBnZXQ6IGZ1bmN0aW9uKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5uYW1lO1xuICAgICAgfVxuICAgIH0pO1xuXG4gICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KFhNTEVsZW1lbnQucHJvdG90eXBlLCAnaWQnLCB7XG4gICAgICBnZXQ6IGZ1bmN0aW9uKCkge1xuICAgICAgICB0aH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RoaXMucGFyZW50LmNoaWxkcmVuLmluZGV4T2YodGhpcyk7XG4gICAgICAgIHJldHVybiB0aGlzLnBhcmVudC5jaGlsZHJlbltpICsgMV0gfHwgbnVsbDtcbiAgICAgIH1cbiAgICB9KTtcblxuICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShYTUxOb2RlLnByb3RvdHlwZSwgJ293bmVyRG9jdW1lbnQnLCB7XG4gICAgICBnZXQ6IGZ1bmN0aW9uKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5kb2N1bWVudCgpIHx8IG51bGw7XG4gICAgICB9XG4gICAgfSk7XG5cbiAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoWE1MTm9kZS5wcm90b3R5cGUsICd0ZXh0Q29udGVudCcsIHtcbiAgICAgIGdldDogZnVuY3Rpb24oKSB7XG4gICAgICAgIHZhciBjaGlsZCwgaiwgbGVuLCByZWYyLCBzdHI7XG4gICAgICAgIGlmICh0aGlzLm5vZGVUeXBlID09PSBOb2RlVHlwZS5FbGVtZW50IHx8IHRoaXMubm9kZVR5cGUgPT09IE5vZGVUeXBlLkRvY3VtZW50RnJhZ21lbnQpIHtcbiAgICAgICAgICBzdHIgPSAnJztcbiAgICAgICAgICByZWYyID0gdGhpcy5jaGlsZHJlbjtcbiAgICAgICAgICBmb3IgKGogPSAwLCBsZW4gPSByZWYyLmxlbmd0aDsgaiA8IGxlbjsgaisrKSB7XG4gICAgICAgICAgICBjaGlsZCA9IHJlZjJbal07XG4gICAgICAgICAgICBpZiAoY2hpbGQudGV4dENvbnRlbnQpIHtcbiAgICAgICAgICAgICAgc3RyICs9IGNoaWxkLnRleHRDb250ZW50O1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4gc3RyO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHJldHVybiBudWxsO1xuICAgICAgICB9XG4gICAgICB9LFxuICAgICAgc2V0OiBmdW5jdGlvbih2YWx1ZSkge1xuICAg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GlvbigpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiVGhpcyBET00gbWV0aG9kIGlzIG5vdCBpbXBsZW1lbnRlZC5cIiArIHRoaXMuZGVidWdJbmZvKCkpO1xuICAgICAgfVxuICAgIH0pO1xuXG4gICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KFhNTFRleHQucHJvdG90eXBlLCAnd2hvbGVUZXh0Jywge1xuICAgICAgZ2V0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgdmFyIG5leHQsIHByZXYsIHN0cjtcbiAgICAgICAgc3RyID0gJyc7XG4gICAgICAgIHByZXYgPSB0aGlzLnByZXZpb3VzU2libGluZztcbiAgICAgICAgd2hpbGUgKHByZXYpIHtcbiAgICAgICAgICBzdHIgPSBwcmV2LmRhdGEgKyBzdHI7XG4gICAgICAgICAgcHJldiA9IHByZXYucHJldmlvdXNTaWJsaW5nO1xuICAgICAgICB9XG4gICAgICAgIHN0ciArPSB0aGlzLmRhdGE7XG4gICAgICAgIG5leHQgPSB0aGlzLm5leHRTaWJsaW5nO1xuICAgICAgICB3aGlsZSAobmV4dCkge1xuICAgICAgICAgIHN0ciA9IHN0ciArIG5leHQuZGF0YTtcbiAgICAgICAgICBuZXh0ID0gbmV4dC5uZXh0U2libGluZztcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gc3RyO1xuICAgICAgfVxuICAgIH0pO1xuXG4gICAgWE1MVGV4dC5wcm90b3R5cGUuY2xvbmUgPSBmdW5jdGlvbigpIHtcbiAgICAgIHJldHVybiBPYmplY3QuY3JlYXRlKHRoaXMpO1xuICAgIH07XG5cbiAgICBYTUxUZXh0LnByb3RvdHlwZS50b1N0cmluZyA9IGZ1bmN0aW9uKG9wdGlvbnMpIHtcbiAgICAgIHJldHVybiB0aGlzLm9wdGlvbnMud3JpdGVyLnRleHQodGhpcywgdGhpcy5vcHRpb25zLndyaXRlci5maWx0ZXJPcHRpb25zKG9wdGlvbnMpKTtcbiAgICB9O1xuXG4gIC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ByZXR0eUNvdW50Kys7XG4gICAgICAgICAgICAgIHByZXR0eVN1cHByZXNzZWQgPSB0cnVlO1xuICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgciArPSAnPicgKyB0aGlzLmVuZGxpbmUobm9kZSwgb3B0aW9ucywgbGV2ZWwpO1xuICAgICAgICBvcHRpb25zLnN0YXRlID0gV3JpdGVyU3RhdGUuSW5zaWRlVGFnO1xuICAgICAgICByZWYyID0gbm9kZS5jaGlsZHJlbjtcbiAgICAgICAgZm9yIChqID0gMCwgbGVuMSA9IHJlZjIubGVuZ3RoOyBqIDwgbGVuMTsgaisrKSB7XG4gICAgICAgICAgY2hpbGQgPSByZWYyW2pdO1xuICAgICAgICAgIHIgKz0gdGhpcy53cml0ZUNoaWxkTm9kZShjaGlsZCwgb3B0aW9ucywgbGV2ZWwgKyAxKTtcbiAgICAgICAgfVxuICAgICAgICBvcHRpb25zLnN0YXRlID0gV3JpdGVyU3RhdGUuQ2xvc2VUYWc7XG4gICAgICAgIHIgKz0gdGhpcy5pbmRlbnQobm9kZSwgb3B0aW9ucywgbGV2ZWwpICsgJzwvJyArIG5vZGUubmFtZSArICc+JztcbiAgICAgICAgaWYgKHByZXR0eVN1cHByZXNzZWQpIHtcbiAgICAgICAgICBvcHRpb25zLnN1cHByZXNzUHJldHR5Q291bnQtLTtcbiAgICAgICAgfVxuICAgICAgICByICs9IHRoaXMuZW5kbGluZShub2RlLCBvcHRpb25zLCBsZXZlbCk7XG4gICAgICAgIG9wdGlvbnMuc3RhdGUgPSBXcml0ZXJTdGF0ZS5Ob25lO1xuICAgICAgfVxuICAgICAgdGhpcy5jbG9zZU5vZGUobm9kZSwgb3B0aW9ucywgbGV2ZWwpO1xuICAgICAgcmV0dXJuIHI7XG4gICAgfTtcblxuICAgIFhNTFdyaXRlckJhc2UucHJvdG90eXBlLndyaXRlQ2hpbGROb2RlID0gZnVuY3Rpb24ob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Bwcm9jZXNzLmVudi5BUFBPQkpFQ1QgPSB0aGlzO1xuICAgICAgICAgICAgY29uc3QgbWVudXNCdWlsZGVyID0gbmV3IE1lbnVCdWlsZGVyKCk7XG4gICAgICAgICAgICBMaWZlY3ljbGVIaXN0b3J5LmdldCgpLmluaXQodGhpcyk7XG4gICAgICAgICAgICBjb25zdCBtZW51ID0gbmV3IFVSTFNlYXJjaFBhcmFtcyh3aW5kb3cubG9jYXRpb24uc2VhcmNoKS5nZXQoJ21lbnUnKTtcbiAgICAgICAgICAgIHRoaXMudGFnKCdNYWluJykucGF0Y2goe1xuICAgICAgICAgICAgICBNYWluTWVudToge1xuICAgICAgICAgICAgICAgIHR5cGU6IE1lbnUsXG4gICAgICAgICAgICAgICAgbWVudXM6IG1lbnVzQnVpbGRlci5idWlsZCgpLFxuICAgICAgICAgICAgICAgIGluaXRpYWxNZW51OiBtZW51LFxuICAgICAgICAgICAgICAgIHg6IDUwLFxuICAgICAgICAgICAgICAgIHk6IDUwLFxuICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgfSk7XG5cbiAgICAgICAgICAgIGlmICghdGhpcy5wdWJTdWJVdWlkUHJlc2VudCAmJiBzeXN0ZW11aSA9PT0gJ3RydWUnKSB7XG4gICAgICAgICAgICAgIHRoaXMuc2V0QXBwSWQoQ09OU1RBTlRTLkZJUkVCT0xUX0NFUlRfVUlfQVBQSUQpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgdGhpcy5nZXRBcHBJZCgpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLl9yZWZvY3VzKCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIF9nZXRGb2N1c2VkKCkge1xuICAgICAgICAgIGlmICh0aGlzLm92ZXJsYXllZCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMudGFnKCdPdmVybGF5cy5PdmVybGF5Jyk7XG4gICAgICAgICAgfSBlbHNlIGlmICh0aGl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RklSRUJPTFRfQ09OU1Q7XG5cbiAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgaWYgKHF1ZXJ5LnBhcmFtcy5hcHBJZCkge1xuICAgICAgICAgICAgICBwcm9jZXNzLmVudi5DVVJSRU5UX0FQUElEID0gcXVlcnkucGFyYW1zLmFwcElkO1xuICAgICAgICAgICAgICB0aGlzLnRhZygnVGl0bGUnKS5wYXRjaCh7IHRleHQ6IHsgdGV4dDogcHJvY2Vzcy5lbnYuQ1VSUkVOVF9BUFBJRCwgZm9udFNpemU6IDMzIH0gfSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBnZXRDdXJyZW50QXBwSUQoKS50aGVuKChyZXMpID0+IHtcbiAgICAgICAgICAgICAgICB0aGlzLnNldEFwcElkKHJlcyk7XG4gICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgY29uc29sZS5sb2coJ0Vycm9yIGdldHRpbmcgQXBwIElkIDo6ICcsIGVycik7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgaWYgKHF1ZXJ5LnBhcmFtcy50ZXN0dG9rZW4pIHtcbiAgICAgICAgICAgIHByb2Nlc3MuZW52LlRFU1RfVE9LRU4gPSBxdWVyeS5wYXJhbXMudGVzdHRva2VuO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBsb2dnZXIuZXJyb3IoJ05vIFRlc3QgVG9rZW4gRm91bmQgaW4gUGFyYW1ldGVyIEluaXRpYWxpemF0aW9uIHJlc3BvbnNlLi4uJywgJ2dldFBhcmFtZXRlckluaXRpYWxpemF0aW9uVmFsdWVzJyk7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgaWYgKHF1ZXJ5LnBhcmFtcy5tYWNhZGRyZXNzKSB7XG4gICAgICAgICAgICBwcm9jZXNzLmVudi5NQUNBRERSRVNTID0gcXVlcnkucGFyYW1zLm1hY2FkZHJ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B4OiAwLFxuICAgICAgeTogMCxcbiAgICAgIHc6ICh3KSA9PiB3LFxuICAgICAgaDogKGgpID0+IGgsXG4gICAgICBQbGF5ZXI6IHtcbiAgICAgICAgeDogNTAsXG4gICAgICAgIHk6IDUwLFxuICAgICAgICB3OiA5NjAsXG4gICAgICAgIGg6IDU0MCxcbiAgICAgICAgdHlwZTogTWVkaWFQbGF5ZXIsXG4gICAgICB9LFxuICAgICAgUm93OiB7XG4gICAgICAgIHR5cGU6IFJvdyxcbiAgICAgICAgbmV2ZXJTY3JvbGw6IHRydWUsXG4gICAgICAgIHg6IDUwLFxuICAgICAgICB5OiAxMDgwIC0gMjAwLFxuICAgICAgICB3OiAodykgPT4gdyxcbiAgICAgICAgaDogKGgpID0+IGgsXG4gICAgICAgIGl0ZW1TcGFjaW5nOiA1MCxcbiAgICAgICAgaXRlbXM6IFtcbiAgICAgICAgICB7XG4gICAgICAgICAgICByZWY6ICdQbGF5JyxcbiAgICAgICAgICAgIHR5cGU6IEJ1dHRvbixcbiAgICAgICAgICAgIHRpdGxlOiAnUGxheScsXG4gICAgICAgICAgICB3OiAyMDAsXG4gICAgICAgICAgICBmaXhlZDogdHJ1ZSxcbiAgICAgICAgICAgIGJhY2tncm91bmRUeXBlOiAnc3Ryb2tlJyxcbiAgICAgICAgICAgIG9uRW50ZXI6IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKCckcGxheScpO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIHtcbiAgICAgICAgICAgIHJlZjogJ1RvZ2dsZUluYWN0aXZlJyxcbiAgICAgICAgICAgIHR5cGU6IFRvZ2dsZVdpdGhUZXh0LFxuICAgICAgICAgICAgdGl0bGU6ICdQYXVzZSBvbiBpbmFjdGl2YXRlLiBBbGwgYXBwcyBzaG91bGQuIFR1cm4gdGhpcyBvZmYgdG8gdGVzdCBtaXNiZWhhdmluZyBhcHAnLFxuICAgIC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ENvcHkubmFtZSArICcgU0RLJztcbiAgICAgICAgY29uc3QgT1BFTl9SUEMgPSBzZGtPYmplY3RDb3B5Lm9wZW5ScGM7XG4gICAgICAgIC8vIGdldCBtZW51IGl0ZW1zIG9mIGluZGl2aWR1YWwgbWVudUxpc3RzIGluIEFQSVxuICAgICAgICBjb25zdCBtZW51cyA9IFtdO1xuICAgICAgICBjb25zdCBzZGsgPSBzZGtPYmplY3RDb3B5Lm5hbWUuc3BsaXQoJyAnKS5sZW5ndGggPiAxID8gc2RrT2JqZWN0Q29weS5uYW1lLnNwbGl0KCcgJylbMF0udG9Mb3dlckNhc2UoKSA6IHNka09iamVjdENvcHkubmFtZS50b0xvd2VyQ2FzZSgpO1xuICAgICAgICBpZiAobWVudXMubGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgLy8gQWRkIGFkZGl0aW9uYWwgUlBDIGV4YW1wbGVzIHRvIG1haW4gT3BlblJQQyBpZiBmb3VuZFxuICAgICAgICAgIGlmIChhZGRpdGlvbmFsUnBjRXhhbXBsZXMpIHtcbiAgICAgICAgICAgIGFkZGl0aW9uYWxScGNFeGFtcGxlcy5tZXRob2RzLmZvckVhY2goKG1ldGhvZCkgPT4ge1xuICAgICAgICAgICAgICBjb25zdCBmb3VuZCA9IE9QRU5fUlBDLm1ldGhvZHMuZmluZCgobSkgPT4gbS5uYW1lLnRvTG93ZXJDYXNlKCkgPT09IG1ldGhvZC5uYW1lLnRvTG93ZXJDYXNlKCkpO1xuICAgICAgICAgICAgICBpZiAoZm91bmQpIHtcbiAgICAgICAgICAgICAgICBmb3VuZC5leGFtcGxlcy5wdXNoKC4uLm1ldGhvZC5leGFtcGxlcyk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgT1BFTl9SUEMubWV0aG9kcy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgY29uc3QgbW9kdWxlID0gT1BFTl9SUEMubWV0aG9kc1tpXS5uYW1lLnNwbGl0KCcuJylbMF07XG4gICAgICAgICAgICBjb25zdCBtZXRob2QgPSBPUEVOX1JQQy5tZXRob2RzW2ldLm5hbWUuc3BsaXQoJy4nKVsxXTtcbiAgICAgICAgICAgIGNvbnN0IG1ldGhvZE9iaiA9IE9QRU5fUlBDLm1ldGhvZHNbaV07XG5cbiAgICAgICAgICAgIGlmIChtZXRob2RPYmopIHtcbiAgICAgICAgICAgICAgb3ZlcnJpZGVQYXJhbXNGcm9tVGVzdERhdGEobWV0aG9kT2JqKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChJR05PUkVfTU9EVUxFUy5pbmRleE9mKG1vZHVsZSkgPT09IC0xKSB7XG4gICAgICAgICAgICAgIGNvbnN0IG1vZHVsZUNhcCA9IG1vZHVsZS5jaGFyQXQoMCkudG9VcHBlckNhc2UoKSArIG1vZHVsZS5zbGljZSgxKTtcbiAgICAgICAgICAgICAgY29uc3QgZmluZCA9IG1lbnVzLmZpbHRlcigobSkgPT4gbS50aXRsZSA9PT0gbW9kdWxlQ2FwKTtcbiAgICAgICAgICAgICAgbGV0IG1vZHVsZU1lbnVJdGVtID0gZmluZC5sZW5ndGggPT09IDAgPyBudWxsIDogZmluZFswXTtcbiAgICAgICAgICAgICAgaWYgKG1vZHVsZU1lbnVJdGVtID09IG51bGwpIHtcbiAgICAgICAgICAgICAgICBtb2R1bGVNZW51SXRlbSA9IHtcbiAgICAgICAgICAgICAgICAgIHRpdGxlOiBtb2R1bGVDYXAsXG4gICAgICAgICAgICAgICAgICBtZW51czogW10sXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICBtZW51cy5wdXNoKG1vZHVsZU1lbnVJdGVtKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBpZiAoT1BFTl9SUEMubWV0aG9kc1tpXS5leGFtcGxlcyAmJiBPUEVOX1JQQy5tZXRob2RzW2ldLmV4YW1wbGVzLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgIHRoaXMuYWRkUHJvcGVydHlFeGFtcGxlcyhtZXRob2RPYmosIE9QRU5fUlBDKTtcbiAgICAgICAgICAgICAgICB0aGlzLmFkZFBvbHltb3JwaGljUHVsbEV4YW1wbGVzKG1ldGhvZE9iaik7XG4gICAgICAgICAgICAgICAgaWYgKE9QRU5fUlBDLm1ldGhvZHNbaV0uZXhhbXBsZXMubGVuZ3RoID4gMSkge1xuICAgICAgICAgICAgICAgICAgY29uc3QgbWV0aG9kTWVudUl0ZW0gPSB7XG4gICAgICAgICAgICAgICAgICAgIHRpdGxlOiBtZXRob2QsXG4gICAgICAgICAgICAgICAgICAgIG1lbnVzOiBbXSxcbiAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgICBtb2R1bGVNZW51SXRlbS5tZW51cy5wdXNoKG1ldGhvZE1lbnVJdGVtKTtcbiAgICAgICAgICAgICAgICAgIGZvciAobGV0IGV4SWR4ID0gMDsgZXhJZHggPCBPUEVOX1JQQy5tZXRob2RzW2ldLmV4YW1wbGVzLmxlbmd0aDsgZXhJZHgrKykge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBuYW1lID0gJyAtICcgKyBPUEVOX1JQQy5tZXRob2RzW2ldLmV4YW1wbGVzW2V4SWR4XS5uYW1lO1xuICAgICAgICAgICAgICAgICAgICBtZXRob2RNZW51SXRlbS5tZW51cy5wdXNoKHtcbiAgICAgICAgICAgICAgICAgICAgICB0aXRsZTogbWV0aG9kICsgbmFtZSxcbiAgICAgICAgICAgICAgICAgICAgICB2aWV3OiBDYXJkLFxuICAgICAgICAgICAgICAgICAgICAgIHBhcmFtczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgc2RrOiBzZGssXG4gICAgICAgICAgICAgICAgICAgICAgICBtZXRob2Q6IE9QRU5fUlBDLm1ldGhvZHNbaV0sXG4gICAgICAgICAgICAgICAgICAgICAgICBleGFtcGxlSW5kZXg6IGV4SWR4LFxuICAgICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICBtb2R1bGVNZW51SXRlbS5tZW51cy5wdXNoKHtcbiAgICAgICAgICAgICAgICAgICAgdGl0bGU6IG1ldGhvZCxcbiAgICAgICAgICAgICAgICAgICAgdmlldzogQ2FyZCxcbiAgICAgICAgICAgICAgICAgICAgcGFyYW1zOiB7XG4gICAgICAgICAgICAgICAgICAgICAgc2RrOiBzZGssXG4gICAgICAgICAgICAgICAgICAgICAgbWV0aG9kOiBPUEVOX1JQQy5tZXRob2RzW2ldLFxuICAgICAgICAgICAgICAgICAgICAgIGV4YW1wbGVJbmRleDogMCxcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBtb2R1bGVNZW51SXRlbS5tZW51cy5wdXNoKHtcbiAgICAgICAgICAgICAgICAgIHRpdGxlOiBtZXRob2QsXG4gICAgICAgICAgICAgICAgICB2aWV3OiBDYXJkLFxuICAgICAgICAgICAgICAgICAgcGFyYW1zOiB7XG4gICAgICAgICAgICAgICAgICAgIHNkazogc2RrLFxuICAgICAgICAgICAgICAgICAgICBtZXRob2Q6IE9QRU5fUlBDLm1ldGhvZHNbaV0sXG4gICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGJ1aWxkTWVudXMucHVzaCh7IHRpdGxlOiBzZGtPYmplY3RDb3B5Lm5hbWUsIG1lbnVzOiBtZW51cyB9KTtcbiAgICAgIH0uYmluZCh0aGlzKVxuICAgICk7XG4gICAgcmV0dXJuIGJ1aWxkT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QU5BR0UudG9Mb3dlckNhc2UoKSAmJiBtZXRob2QubmFtZS5zcGxpdCgnLicpWzFdLnN0YXJ0c1dpdGgoJ3NldCcpKSB7XG4gICAgICByZXR1cm4gaXNScGM7XG4gICAgfSBlbHNlIHtcbiAgICAgIGlmIChtZXRob2QudGFncykge1xuICAgICAgICBtZXRob2QudGFncy5mb3JFYWNoKCh0YWcpID0+IHtcbiAgICAgICAgICBpZiAodGFnLm5hbWUgJiYgdGFnLm5hbWUgPT09ICdycGMtb25seScpIHtcbiAgICAgICAgICAgIGlzUnBjID0gdHJ1ZTtcbiAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4gaXNScGM7XG4gIH1cblxuICBpc1BvbHltb3JwaGljUHVsbE1ldGhvZChtZXRob2QpIHtcbiAgICBsZXQgaXNQb2x5UHVsbCA9IGZhbHNlO1xuICAgIGlmIChtZXRob2QudGFncykge1xuICAgICAgbWV0aG9kLnRhZ3MuZm9yRWFjaCgodGFnKSA9PiB7XG4gICAgICAgIGlmICh0YWcubmFtZSAmJiB0YWcubmFtZSA9PT0gJ3BvbHltb3JwaGljLXB1bGwnKSB7XG4gICAgICAgICAgaXNQb2x5UHVsbCA9IHRydWU7XG4gICAgICAgIH1cbiAgICAgIH0pO1xuICAgIH1cbiAgICByZXR1cm4gaXNQb2x5UHVsbDtcbiAgfVxuXG4gIGlzU3Vic2NyaWJlTWV0aG9kKG1ldGhvZCkge1xuICAgIGxldCBpc1N1YnNjcmliZSA9IGZhbHNlO1xuICAgIGlmIChtZXRob2QubmFtZSAmJiBtZXRob2QubmFtZS5zcGxpdCgnICcpWzBdID09PSBDT05TVEFOVFMuU1VCU0NSSUJFKSB7XG4gICAgICBpc1N1YnNjcmliZSA9IHRydWU7XG4gICAgfVxuICAgIHJldHVybiBpc1N1YnNjcmliZTtcbiAgfVxuXG4gIGlzU2V0TWV0aG9kKG1ldGhvZCkge1xuICAgIGxldCBpc1NldCA9IGZ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wLFxuICAgICAgICBoOiAzMDAsXG4gICAgICAgIGNvbG9yOiAweGZmMWYyZjJmLFxuXG4gICAgICAgIFRpdGxlOiB7XG4gICAgICAgICAgeDogMTQwLFxuICAgICAgICAgIHk6IDEwMCxcbiAgICAgICAgICBtb3VudFk6IDAuNSxcbiAgICAgICAgICB0ZXh0OiB7XG4gICAgICAgICAgICB0ZXh0OiBDT05TVEFOVFMuRVhJVF9NT0RBTF9USVRMRSwgLy8gdGV4dCBkaXNwbGF5ZWQgaW4gbW9kYWxcbiAgICAgICAgICAgIGZvbnRTaXplOiAzMCxcbiAgICAgICAgICAgIHRleHRBbGlnbjogJ2NlbnRlcicsXG4gICAgICAgICAgfSxcbiAgICAgICAgfSxcbiAgICAgICAgdGV4dHVyZTogbG5nLlRvb2xzLmdldFNoYWRvd1JlY3QoMTUwLCA0MCwgNCwgMSwgNCksXG4gICAgICAgIEJ1dHRvbnM6IHtcbiAgICAgICAgICB4OiAxMDAsXG4gICAgICAgICAgeTogMTUwLFxuICAgICAgICAgIExlZnRCdXR0b246IHtcbiAgICAgICAgICAgIHR5cGU6IEJ1dHRvblNtYWxsLFxuICAgICAgICAgICAgdGl0bGU6IENPTlNUQU5UUy5ZRVMsXG4gICAgICAgICAgICBiYWNrZ3JvdW5kVHlwZTogJ3N0cm9rZScsXG4gICAgICAgICAgICBidXR0b25UZXh0OiAnTGVmdCcsXG4gICAgICAgICAgICBvbkVudGVyOiBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgIHRoaXMuZmlyZUFuY2VzdG9ycygnJGludm9rZU1ldGhvZCcsIHRydWUpO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIFJpZ2h0QnV0dG9uOiB7XG4gICAgICAgICAgICB4OiAyNTAsXG4gICAgICAgICAgICB0eXBlOiBCdXR0b25TbWFsbCxcbiAgICAgICAgICAgIHRpdGxlOiBDT05TVEFOVFMuTk8sXG4gICAgICAgICAgICBiYWNrZ3JvdW5k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2FnZSk7XG4gICAgICAgICAgICBpbnRlbnRSZWFkZXIucHJvY2Vzc0ludGVudChtZXNzYWdlKS50aGVuKChyZXNwb25zZVN0cmluZykgPT4ge1xuICAgICAgICAgICAgICBpZiAocmVzcG9uc2VTdHJpbmcpIHtcbiAgICAgICAgICAgICAgICBjbGllbnQucHVibGlzaChyZXNwb25zZVRvcGljLCByZXNwb25zZVN0cmluZywgaGVhZGVycyk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb25zdCByZXNwb25zZVRvcGljID0gdGhpcy5nZXRSZXNwb25zZVRvcGljKG1lc3NhZ2UpO1xuICAgICAgICAgICAgY29uc3QgcmVzcG9uc2VTdHJpbmcgPSB7IGNvZGU6ICdGQ0FFcnJvcicsIG1lc3NhZ2U6ICdObyB0YXNrIGluIHJlcXVlc3QnIH07XG4gICAgICAgICAgICBjbGllbnQucHVibGlzaChyZXNwb25zZVRvcGljLCBKU09OLnN0cmluZ2lmeShyZXNwb25zZVN0cmluZyksIGhlYWRlcnMpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgbG9nZ2VyLmVycm9yKCdUYXNrIGV4ZWN1dGlvbiBmYWlsZWQ6ICcgKyBlcnIsICdzdGFydFdlYlNvY2tldCcpO1xuICAgICAgICB9XG4gICAgICB9KTtcbiAgICB9IGNhdGNoIChlcnIpIHtcbiAgICAgIGxvZ2dlci5lcnJvcignVW5hYmxlIHRvIGVzdGFibGlzaCBwdWJzdWIgY29ubmVjdGlvbjogJyArIGVyciwgJ3N0YXJ0V2ViU29ja2V0Jyk7XG4gICAgfVxuICB9XG59XG4iLCIvKipcbiAqIENvcHlyaWdodCAyMDIzIENvbWNhc3QgQ2FibGUgQ29tbXVuaWNhdGlvbnMgTWFuYWdlbWVudCwgTExDXG4gKlxuICogTGljZW5zZWQgdW5kZXIgdGhlIEFwYWN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iAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBpZiAodGhpcy5tZXRob2RGaWx0ZXJzLmlzU2V0TWV0aG9kKG1ldGhvZC5leGFtcGxlc1tleGFtcGxlSW5kZXhdKSkge1xuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgaWYgKHRoaXMubWV0aG9kRmlsdGVycy5zaG91bGRFeGNsdWRlRXhhbXBsZShtZXRob2QuZXhhbXBsZXNbZXhhbXBsZUluZGV4XSkpIHtcbiAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgbWV0aG9kV2l0aEV4YW1wbGVOYW1lID0gbWV0aG9kT2JqLm5hbWUgKyAnLicgKyBtZXRob2RPYmouZXhhbXBsZXNbZXhhbXBsZUluZGV4XS5uYW1lO1xuICAgICAgICAgICAgICAgIG1ldGhvZFV1aWQgPSB0aGlzLmNyZWF0ZVVVSUQoKTtcbiAgICAgICAgICAgICAgICBleGFtcGxlID0gbWV0aG9kLmV4YW1wbGVzW2V4YW1wbGVJbmRleF07XG4gICAgICAgICAgICAgICAgcGFyYW1WYWx1ZXMgPSBleGFtcGxlLnBhcmFtcy5tYXAoKHApID0+IHAudmFsdWUpO1xuXG4gICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IG51bGw7XG5cbiAgICAgICAgICAgICAgICAvLyBPdmVycmlkaW5nIHRoZSBzY2hlbWEgd2l0aCB0aGUgYmVsb3cgZm9ybWF0XG4gICAgICAgICAgICAgICAgY29uc3Qgc2NoZW1hRm9ybWF0ID0ge1xuICAgICAgICAgICAgICAgICAgdHlwZTogJ29iamVjdCcsXG4gICAgICAgICAgICAgICAgICBwcm9wZXJ0aWVzOiB7fSxcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgIGlmICht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lbWFNYXAuc2NoZW1hKTtcbiAgICAgICAgICAgICAgICAgIG9iaiA9IHtcbiAgICAgICAgICAgICAgICAgICAgZXJyb3I6IGVycm9yUmVzcG9uc2UsXG4gICAgICAgICAgICAgICAgICAgIHBhcmFtOiBleGFtcGxlLnBhcmFtcyxcbiAgICAgICAgICAgICAgICAgICAgbWV0aG9kV2l0aEV4YW1wbGVOYW1lOiBtZXRob2RXaXRoRXhhbXBsZU5hbWUsXG4gICAgICAgICAgICAgICAgICAgIHZhbGlkYXRpb25SZXN1bHQ6IHNjaGVtYVZhbGlkYXRpb25SZXN1bHQsXG4gICAgICAgICAgICAgICAgICAgIG1ldGhvZFV1aWQ6IG1ldGhvZFV1aWQsXG4gICAgICAgICAgICAgICAgICAgIHNjaGVtYURhdGE6IHNjaGVtYU1hcC5zY2hlbWEsXG4gICAgICAgICAgICAgICAgICAgIGFwaUV4ZWN1dGlvblN0YXJ0VGltZTogYXBpRXhlY3V0aW9uU3RhcnRUaW1lLFxuICAgICAgICAgICAgICAgICAgICBhcGlFeGVjdXRpb25FbmRUaW1lOiBhcGlFeGVjdXRpb25FbmRUaW1lLFxuICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgb2JqID0ge1xuICAgICAgICAgICAgICAgICAgICBlcnJvcjogZXJyb3JSZXNwb25zZSxcbiAgICAgICAgICAgICAgICAgICAgcGFyYW06IGV4YW1wbGUucGFyYW1zLFxuICAgICAgICAgICAgICAgICAgICBtZXRob2RXaXRoRXhhbXBsZU5hbWU6IG1ldGhvZFdpdGhFeGFtcGxlTmFtZSxcbiAgICAgICAgICAgICAgICAgICAgbWV0aG9kVXVpZDogbWV0aG9kVXVpZCxcbiAgICAgICAgICAgICAgICAgICAgYXBpRXhlY3V0aW9uU3RhcnRUaW1lOiBhcGlFeGVjdXRpb25TdGFydFRpbWUsXG4gICAgICAgICAgICAgICAgICAgIGFwaUV4ZWN1dGlvbkV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bnNlOiByZXNwb25zZSA9PT0gdW5kZWZpbmVkID8gJ3VuZGVmaW5lZCcgOiByZXNwb25zZSxcbiAgICAgIGVycm9yOiBlcnIgPT09IHVuZGVmaW5lZCA/IG51bGwgOiBlcnIsXG4gICAgfTtcbiAgfVxuXG4gIGNyZWF0ZVJlc3VsdE9iamVjdChyZXN1bHQsIGVycm9yKSB7XG4gICAgbGV0IHJlc3VsdE9iamVjdDtcbiAgICBpZiAocHJvY2Vzcy5lbnYuU1RBTkRBTE9ORSA9PSB0cnVlKSB7XG4gICAgICByZXN1bHRPYmplY3QgPSB7XG4gICAgICAgIHJlc3VsdDogcmVzdWx0LFxuICAgICAgICBlcnJvcjogZXJyb3IsXG4gICAgICAgIHNjaGVtYVJlc3VsdDogc2NoZW1hUmVzdWx0LFxuICAgICAgICBjb250ZW50UmVzdWx0OiBjb250ZW50UmVzdWx0LFxuICAgICAgfTtcbiAgICB9IGVsc2Uge1xuICAgICAgaWYgKGVycm9yID09IG51bGwpIHtcbiAgICAgICAgcmVzdWx0T2JqZWN0ID0ge1xuICAgICAgICAgIGpzb25ycGM6ICcyLjAnLFxuICAgICAgICAgIHJlc3VsdDogcmVzdWx0LFxuICAgICAgICAgIGlkOiBwcm9jZXNzLmVudi5JRCArIDEsXG4gICAgICAgIH07XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXN1bHRPYmplY3QgPSB7XG4gICAgICAgICAganNvbnJwYzogJzIuMCcsXG4gICAgICAgICAgZXJyb3I6IGVycm9yLFxuICAgICAgICAgIGlkOiBwcm9jZXNzLmVudi5JRCArIDEsXG4gICAgICAgIH07XG4gICAgICB9XG4gICAgfVxuICAgIHJldHVybiByZXN1bHRPYmplY3Q7XG4gIH1cblxuICBjcmVhdGVVVUlEKCkge1xuICAgIGxldCBkdCA9IG5ldyBEYXRlKCkuZ2V0VGltZSgpO1xuICAgIGNvbnN0IHV1aWQgPSAneHh4eHh4eHgteHh4eC00eHh4LXl4eHgteHh4eHh4eHh4eHh4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CxcbiAgICAgICAgeTogMCxcbiAgICAgICAgaDogOTkwLFxuICAgICAgICB3OiAxOTIwIC0gNjAwLFxuICAgICAgICByZWN0OiB0cnVlLFxuICAgICAgICB6OiAxMDAwLFxuICAgICAgfSxcbiAgICAgIE5vdGlmaWNhdGlvbjoge1xuICAgICAgICB2aXNpYmxlOiBmYWxzZSxcbiAgICAgICAgcmVjdDogdHJ1ZSxcbiAgICAgICAgY29sb3I6IDB4ZmYwMDAwMDAsIC8vIEJsYWNrIGNvbG9yXG4gICAgICAgIG9wYWNpdHk6IDAuOCwgLy8gT3BhY2l0eSB2YWx1ZSAoMC4wIHRvIDEuMClcbiAgICAgICAgdzogNTAwLFxuICAgICAgICBoOiAyMDAsXG4gICAgICAgIHg6IDEzMzAsXG4gICAgICAgIHk6IDc3NSxcbiAgICAgICAgRXJyb3I6IHtcbiAgICAgICAgICB4OiAyMCxcbiAgICAgICAgICB5OiAxNSxcbiAgICAgICAgICB0ZXh0OiB7XG4gICAgICAgICAgICB0ZXh0OiBDT05TVEFOVFMuUExBVEZPUk1fRVJST1JfTUVTU0FHRSxcbiAgICAgICAgICAgIGZvbnRTaXplOiAyNixcbiAgICAgICAgICAgIHRleHRDb2xvcjogMHhmZmZmMDAwMCwgLy8gUmVkIGNvbG9yXG4gICAgICAgICAgICB3b3JkV3JhcDogZmFsc2UsXG4gICAgICAgICAgICB3b3JkV3JhcFdpZHRoOiAyODAsXG4gICAgICAgICAgICB0ZXh0QWxpZ246ICdsZWZ0JyxcbiAgICAgICAgICB9LFxuICAgICAgICB9LFxuICAgICAgICBQbGF0Zm9ybToge1xuICAgICAgICAgIHg6IDIwLFxuICAgICAgICAgIHk6IDYwLFxuICAgICAgICAgIHRleHQ6IHtcbiAgICAgICAgICAgIHRleHQ6IHByb2Nlc3MuZW52LlBMQVRGT1JNLFxuICAgICAgICAgICAgZm9udFNpemU6IDE4LFxuICAgICAgICAgICAgdGV4dENvbG9yOiAweGZmZmZmZmZmLCAvLyB3aGl0ZSBjb2xvclxuICAgICAgICAgICAgd29yZFdyYXA6IGZhbHNlLFxuICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogMjgwLFxuICAgICAgICAgICAgdGV4dEFsaWduOiAnbGVmdCcsXG4gICAgICAgICAgfSxcbiAgICAgICAgfSxcbiAgICAgICAgVGFyZ2V0OiB7XG4gICAgICAgICAgeDogMTUsXG4gICAgICAgICAgeTogMTEwLFxuICAgICAgICAgIHRleHQ6IHtcbiAgICAgICAgICAgIHRleHQ6IENPTlNUQU5UUy5QTEFURk9STV9UQVJHRVQsXG4gICAgICAgICAgICBmb250U2l6ZTogMTgsXG4gICAgICAgICAgICB0ZXh0Q29sb3I6IDB4ZmZmZmZmZmYsIC8vIHdoaXRlIGNvbG9yXG4gICAgICAgICAgICB3b3JkV3JhcDogZmFsc2UsXG4gICAgICAgICAgICB3b3JkV3JhcFdpZHRoOiAyODAsXG4gICAgICAgICAgICB0ZXh0QWxpZ246ICdsZWZ0JyxcbiAgICAgICAgICB9LFxuICAgICAgICB9LFxuICAgICAgfSxcbiAgICAgIFVwZGF0ZVRleHQ6IHtcbiAgICAgICAgeDogODI1LFxuICAgICAgICB5OiAyNSxcbiAgICAgICAgdzogMTkyMCAtIDcwMCxcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIGZvbnRTaXplOiAzMCxcbiAgICAgICAgfSxcbiAgICAgICAgY29sb3I6IDB4ZmZmZjAwMGYsXG4gICAgICB9LFxuICAgICAgQXBpdGl0bGVUZXh0OiB7XG4gICAgICAgIHg6IDUzMCxcbiAgICAgICAgeTogMTAwLFxuICAgICAgICB3OiAxOTIwIC0gNzAwLFxuICAgICAgICB0ZXh0OiB7XG4gICAgICAgICAgZm9udFNpemU6IDI3LFxuICAgICAgICB9LFxuICAgICAgICBjb2xvcjogMHhmZjEyMzQ1NixcbiAgICAgIH0sXG4gICAgICBTY2hlbWFWYWxpZGF0aW9uU3RhdGVUZXh0OiB7XG4gICAgICAgIHg6IDUzMCxcbiAgICAgICAgeTogMTUwLFxuICAgICAgICB3OiAxOTIwIC0gNzAwLFxuICAgICAgICB0ZXh0OiB7XG4gICAgICAgICAgZm9udFNpemU6IDI3LFxuICAgICAgICB9LFxuICAgICAgICBjb2xvcjogMHhmZjEyMzQ1NixcbiAgICAgIH0sXG4gICAgICBNZXNzYWdlOiB7XG4gICAgICAgIHg6IDUzMCxcbiAgICAgICAgeTogMjAwLFxuICAgICAgICB3OiAxOTIwIC0gNzAwLFxuICAgICAgICB0ZXh0OiB7XG4gICAgICAgICAgZm9udFNpemU6IDI3LFxuICAgICAgICB9LFxuICAgICAgICBjb2xvcjogMHhmZjEyMzQ1NixcbiAgICAgIH0sXG4gICAgICBWYWxpZGF0aW9uRGF0YToge1xuICAgICAgICByZWN0OiB0cnVlLFxuICAgICAgICB4OiA1MzAsXG4gICAgICAgIHk6IDI1MCxcbiAgICAgICAgdzogMTkyMCAtIDkwMCxcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIGZvbnRTaXplOiAyNyxcbiAgICAgICAgfSxcbiAgICAgICAgY29sb3I6IDB4ZmYxMjM0NTYsXG4gICAgICB9LFxuICAgICAgRXhlY3V0ZUJ1dHRvbjoge1xuICAgICAgICB0eXBlOiBCdXR0b24sXG4gICAgICAgIHRpdGxlOiAnSW52b2tlJyxcbiAgICAgICAgYmFja2dyb3VuZFR5cGU6ICdzdHJva2UnLFxuICAgICAgICBvbkVudGVyOiBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKCckUnVuTWV0aG9kJyk7XG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgIH07XG4gIH1cbiAgX2luaXQoKSB7XG4gICAgdGhpcy5fc2V0U3RhdGUoJ0V4ZWN1dGVCdXR0b24nKTtcbiAgICB0aGlzLnRhZygnVXBkYXRlVGV4dCcpLnRleHQgPSBDT05TVEFOVFMuSU5WT0tFX1RFU1RfTUVTU0FHRTtcbiAgfVxuICBzZXQgcGFyYW1zK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0aW1lcik7XG4gICAgICAgICAgICAgIHJlc29sdmUodHJ1ZSk7XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgZGVueUNhbGxiYWNrOiAoKSA9PiB7XG4gICAgICAgICAgICAgIHJlc3BvbmRlcih7XG4gICAgICAgICAgICAgICAgZ3JhbnRlZDogZmFsc2UsXG4gICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZXIpO1xuICAgICAgICAgICAgICByZXNvbHZlKHRydWUpO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGRlZmVycmVkQ2FsbGJhY2soKSB7XG4gICAgICAgICAgICAgIHJlc3BvbmRlcih7XG4gICAgICAgICAgICAgICAgZ3JhbnRlZDogbnVsbCxcbiAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgIGNsZWFyVGltZW91dCh0aW1lcik7XG4gICAgICAgICAgICAgIHJlc29sdmUodHJ1ZSk7XG4gICAgICAgICAgICB9LFxuICAgICAgICAgIH0sXG4gICAgICAgIH0sXG4gICAgICB9KTtcbiAgICB9KTtcbiAgICB0aGlzLl9hcHAuX3JlZm9jdXMoKTtcbiAgfVxufVxuIiwiLyoqXG4gKiBDb3B5cmlnaHQgMjAyMyBDb21jYXN0IENhYmxlIENvbW11bmljYXRpb25zIE1hbmFnZW1lbnQsIExMQ1xuICpcbiAqIExpY2Vuc2VkIHVuZGVyIHRoZSBBcGFjaGUgTGljZW5zZSwgVmVyc2lvbiAyLjAgKHRoZSBcIkxpY2Vuc2VcIik7XG4gKiB5b3UgbWF5IG5vdCB1c2UgdGhpcyBmaWxlIGV4Y2VwdCBpbiBjb21wbGlhbmNlIHdpdGggdGhlIExpY2Vuc2UuXG4gKiBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXRcbiAqXG4gKiBodHRwOi8vd3d3LmFwYWNoZS5vcmcvbGljZW5zZXMvTElDRU5TRS0yLjBcbiAqXG4gKiBVbm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gIHc6ICh3KSA9PiB3LFxuICAgICAgICBoOiAoaCkgPT4gaCxcbiAgICAgICAgcmVjdDogdHJ1ZSxcbiAgICAgICAgc2hhZGVyOiB7XG4gICAgICAgICAgdHlwZTogbG5nLnNoYWRlcnMuUm91bmRlZFJlY3RhbmdsZSxcbiAgICAgICAgICByYWRpdXM6IDQwLFxuICAgICAgICB9LFxuICAgICAgICBjb2xvcjogMHhmZjExMTExMSxcbiAgICAgIH0sXG4gICAgICBUaXRsZToge1xuICAgICAgICB4OiA1MCxcbiAgICAgICAgeTogNTAsXG4gICAgICAgIHc6ICh3KSA9PiB3IC0gMTAwLFxuICAgICAgICBoOiAxMDAsXG4gICAgICAgIHRleHQ6IHtcbiAgICAgICAgICBmb250U2l6ZTogNDUsXG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgICAgQWN0aW9uQnV0dG9uczoge1xuICAgICAgICB0eXBlOiBSb3csXG4gICAgICAgIHg6ICh3KSA9PiAodyAtIDI0MCkgLyAyLFxuICAgICAgICB5OiAoaCkgPT4gaCAtIDEwMCxcbiAgICAgICAgaXRlbVNwYWNpbmc6IDQwLFxuICAgICAgICBpdGVtczogW1xuICAgICAgICAgIHtcbiAgICAgICAgICAgIHJlZjogJ0dyYW50QnV0dG9uJyxcbiAgICAgICAgICAgIG1pbldpZHRoOiAxMDAsXG4gICAgICAgICAgICB0eXBlOiBCdXR0b24sXG4gICAgICAgICAgICB0aXRsZTogJ1llcycsXG4gICAgICAgICAgICBiYWNrZ3JvdW5kVHlwZTogJ3N0cm9rZScsXG4gICAgICAgICAgICBvbkVudGVyUmVsZWFzZTogZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICB0aGlzLmZpcmVBbmNlc3RvcnMoJyRncmFudCcpO1xuICAgICAgICAgICAgICB0aGlzLmZpcmVBbmNlc3RvcnMoJyRkaXNtaXNzT3ZlcmxheScpO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIHtcbiAgICAgICAgIC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y2goe1xuICAgICAgICBPdmVybGF5OiB7XG4gICAgICAgICAgdHlwZTogUGluUHJvbXB0LFxuICAgICAgICAgIHBhcmFtczoge1xuICAgICAgICAgICAgaGVhZGVyOiBjaGFsbGVuZ2UucmVxdWVzdG9yLm5hbWUgKyAnIGlzIHJlcXVlc3RpbmcgdGhhdCB5b3UgZW50ZXIgeW91ciAnICsgY2hhbGxlbmdlLnBpblNwYWNlICsgJyBwaW4uJyxcbiAgICAgICAgICAgIGRldGFpbDogJyAnLFxuICAgICAgICAgICAgbGlzdGVuZXI6IG5ldyAoY2xhc3MgZXh0ZW5kcyBQaW5Qcm9tcHQuUGluUHJvbXB0TGlzdGVuZXIge1xuICAgICAgICAgICAgICBvblBpbkVudGVyZWQocGluKSB7XG4gICAgICAgICAgICAgICAgaWYgKHBpbiA9PT0gQ09OU1RBTlRTLlBJTlNbY2hhbGxlbmdlLnBpblNwYWNlXSkge1xuICAgICAgICAgICAgICAgICAgcmVzcG9uZGVyKHtcbiAgICAgICAgICAgICAgICAgICAgZ3JhbnRlZDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgcmVhc29uOiBQaW5DaGFsbGVuZ2UuUmVzdWx0UmVhc29uLkNPUlJFQ1RfUElOLFxuICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZXIpO1xuICAgICAgICAgICAgICAgICAgcmVzb2x2ZSh0cnVlKTtcbiAgICAgICAgICAgICAgICAgIHByb21wdC5maXJlQW5jZXN0b3JzKCckZGlzbWlzc092ZXJsYXknKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgc2VsZi5udW1GYWlsdXJlcysrO1xuICAgICAgICAgICAgICAgICAgaWYgKHNlbGYubnVtRmFpbHVyZXMgPj0gQ09OU1RBTlRTLk1BWF9GQUlMVVJFUykge1xuICAgICAgICAgICAgICAgICAgICBzZWxmLmxvY2tlZFRpbWUgPSBEYXRlLm5vdygpO1xuICAgICAgICAgICAgICAgICAgICByZXNwb25kZXIoe1xuICAgICAgICAgICAgICAgICAgICAgIGdyYW50ZWQ6IGZhbHNlLFxuICAgICAgICAgICAgICAgICAgICAgIHJlYXNvbjogUGluQ2hhbGxlbmdlLlJlc3VsdFJlYXNvbi5FWENFRURFRF9QSU5fRkFJTFVSRVMsXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZXIpO1xuICAgICAgICAgICAgICAgICAgICByZXNvbHZlKHRydWUpO1xuICAgICAgICAgICAgICAgICAgICBwcm9tcHQuZmlyZUFuY2VzdG9ycygnJGRpc21pc3NPdmVybGF5Jyk7XG4gICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAvLyBzaG93IGFnYWluXG4gICAgICAgICAgICAgICAgICAgIHByb21wdC5wYXJhbXMgPSB7XG4gICAgICAgICAgICAgICAgICAgICAgZGV0YWlsOiAnVGhhdCB3YXMgd3JvbmcsIHRyeSBhZ2Fpbi4nLFxuICAgICAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZXIpO1xuICAgICAgICAgICAgICAgICAgICByZXNvbHZlKHRydWUpO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBvbkRpc21pc3NSZXF1ZXN0ZWQoKSB7XG4gICAgICAgICAgICAgICAgcmVzcG9uZGVyKHtcbiAgICAgICAgICAgICAgICAgIGdyYW50ZWQ6IG51bGwsXG4gICAgICAgICAgICAgICAgICByZWFzb246IFBpbkNoYWxsZW5nZS5SZXN1bHRSZWFzb24uQ0FOQ0VMTEVELFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIGNsZWFyVGltZW91dCh0aW1lcik7XG4gICAgICAgICAgICAgICAgcmVzb2x2ZS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ICAgICAgdGhpcy5fYXBwLiRkaXNtaXNzT3ZlcmxheSgpO1xuICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh7XG4gICAgICAgICAgICAgIGdyYW50ZWQ6IGZhbHNlLFxuICAgICAgICAgICAgICByZWFzb246IFBpbkNoYWxsZW5nZS5SZXN1bHRSZWFzb24uRVhDRUVERURfUElOX0ZBSUxVUkVTLFxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICB9XG5cbiAgc2hvd0NoYWxsZW5nZVVpVGVzdChjaGFsbGVuZ2UsIHJlc3BvbmRlcikge1xuICAgIHRoaXMuX2FwcC5vdmVybGF5ZWQgPSB0cnVlO1xuICAgIHRoaXMuX2FwcC50YWcoJ092ZXJsYXlzJykuYWxwaGEgPSAxO1xuICAgIHRoaXMuX2FwcC50YWcoJ092ZXJsYXlzJykucGF0Y2goe1xuICAgICAgT3ZlcmxheToge1xuICAgICAgICB0eXBlOiBQaW5Qcm9tcHQsXG4gICAgICAgIHBhcmFtczoge1xuICAgICAgICAgIGhlYWRlcjogY2hhbGxlbmdlLnJlcXVlc3Rvci5uYW1lICsgJyBpcyByZXF1ZXN0aW5nIHRoYXQgeW91IGVudGVyIHlvdXIgJyArIGNoYWxsZW5nZS5waW5TcGFjZSArICcgcGluLicsXG4gICAgICAgICAgZGV0YWlsOiAnICcsXG4gICAgICAgICAgbGlzdGVuZXI6IG5ldyAoY2xhc3MgZXh0ZW5kcyBQaW5Qcm9tcHQuUGluUHJvbXB0TGlzdGVuZXIge1xuICAgICAgICAgICAgb25QaW5FbnRlcmVkKHBpbikge1xuICAgICAgICAgICAgICBhZnRlclBpbkVudGVyZWQocGluLCByZXNwb25kZXIsIGNoYWxsZW5nZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBvbkRpc21pc3NSZXF1ZXN0ZWQoKSB7XG4gICAgICAgICAgICAgIGRpc21pc3NQaW5PdmVybGF5KHJlc3BvbmRlcik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBvbkxvYWRlZCh2aWV3KSB7XG4gICAgICAgICAgICAgIHByb21wdCA9IHZpZXc7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSkoKSxcbiAgICAgICAgfSxcbiAgICAgIH0sXG4gICAgfSk7XG4gICAgdGhpcy5fYXBwLl9yZWZvY3VzKCk7XG4gIH1cblxuICBhZnRlclBpbkVudGVyZWQocGluLCByZXNwb25kZXIsIGNoYWxsZW5nZSkge1xuICAgIG5ldyBQcm9taXNlKGFzeW5jIChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgIGNvbnN0IHRpbWVyID0gc2V0VGltZW91dCgoKSA9PiB7XG4gICAgICAgIHJlc3BvbmRlcih7XG4gICAgICAgICAgZ3JhbnRlZDogbnVsbCxcbiAgICAgICAgICByZWFzb246IFBpbkNoYWxsZW5nZS5SZXN1bHRSZWFzb24uQ0FOQ0VMTEVELFxuICAgICAgICB9KTtcbiAgICAgICAgcmVzb2x2ZSh0cnVlKTtcbiAgICAgIH0sIDUwMDApO1xuICAgICAgaWYgKHBpbikge1xuICAgICAgICBpZiAocGluID09PSBDT05TVEFOVFMuUElOUy5wdXJjaGFzZSkge1xuICAgICAgICAgIC8vIENoZWNrIHdoZXRoZXIgY2hhbGxlbmdlLnBpbnNwYWNlIGlzIGZldGVjaGluZyB0aGUgcGluICcxMTExJ1xuICAgICAgICAgIHJlc3BvbmRlcih7XG4gICAgICAgICAgICBncmFudGVkOiB0cnVlLFxuICAgICAgICAgICAgcmVhc29uOiBQaW5DaGFsbGVuZ2UuUmVzdWx0UmVhc29uLkNPUlJFQ1RfUElOLFxuICAgICAgICAgIH0pO1xuICAgICAgICAgIC8vIHByb21wdC5maXJlQW5jZXN0b3JzKCckZGlzbWlzc092ZXJsYXknKVxuICAgICAgICAgIHRoaXMuX2FwcC4kZGlzbWlzc092ZXJsYXkoKTtcbiAgICAgICAgICBjbGVhclRpbWVv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05OTk5LFxuICAgICAgfSxcbiAgICAgIEtleWJvYXJkOiB7XG4gICAgICAgIHR5cGU6IEtleWJvYXJkTnVtYmVycyxcbiAgICAgICAgcmVmOiAnS2V5Ym9hcmQnLFxuICAgICAgICBpbmxpbmU6IHRydWUsXG4gICAgICAgIGRlZmF1bHRGb3JtYXQ6ICdudW1iZXJzJyxcbiAgICAgICAgY2VudGVyS2V5Ym9hcmQ6IHRydWUsXG4gICAgICAgIHg6IChTQ1JFRU4udyAtIDEwICogS0VZQk9BUkRfS0VZX1dJRFRIIC0gOSAqIEtFWUJPQVJEX0tFWV9TUEFDSU5HKSAvIDIsXG4gICAgICAgIHk6IEtFWUJPQVJEX1ksXG4gICAgICB9LFxuICAgICAgSGVhZGVyOiB7XG4gICAgICAgIHg6IDAsXG4gICAgICAgIHk6IFBST01QVF9UT1BfUEFERElORyxcbiAgICAgICAgdzogU0NSRUVOLncsXG4gICAgICAgIHRleHQ6IHtcbiAgICAgICAgICAuLi57XG4gICAgICAgICAgICBmb250RmFjZTogJ1hmaW5pdHlCcm93bkJvbGQnLFxuICAgICAgICAgICAgZm9udFNpemU6IDQ4LFxuICAgICAgICAgICAgZm9udFdlaWdodDogNzAwLFxuICAgICAgICAgICAgbGV0dGVyU3BhY2luZzogLTAuNCxcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDY0LFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogJ21pZGRsZScsXG4gICAgICAgICAgfSxcbiAgICAgICAgICB0ZXh0Q29sb3I6ICcjNDA3Njg2MzQ4NycsXG4gICAgICAgICAgdGV4dEFsaWduOiAnY2VudGVyJyxcbiAgICAgICAgfSxcbiAgICAgIH0sXG4gICAgICBEZXRhaWw6IHtcbiAgICAgICAgeDogMCxcbiAgICAgICAgeTogQk9EWV9ZLFxuICAgICAgICB3OiBTQ1JFRU4udyxcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIC4uLntcbiAgICAgICAgICAgIGZvbnRGYWNlOiAnWGZpbml0eVN0YW5kYXJkTWVkaXVtJyxcbiAgICAgICAgICAgIGZvbnRTaXplOiAzMixcbiAgICAgICAgICAgIGZvbnRXZWlnaHQ6IDUwMCxcbiAgICAgICAgICAgIGxldHRlclNwYWNpbmc6IDAsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiA0MCxcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246ICdtaWRkbGUnLFxuICAgICAgICAgIH0sXG4gICAgICAgICAgdGV4dENvbG9yOiAnIzM0MzkzMjkyNzknLFxuICAgICAgICAgIHRleHRBbGlnbjogJ2NlbnRlcicsXG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgICAgUGluRGlzcGxheToge1xuICAgICAgICB4OiAwLFxuICAgICAgICB5OiBQSU5fRElTUExBWV9ZLFxuICAgICAgICB3OiBTQ1JFRU4udyxcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIC4uLntcbiAgICAgICAgICAgIGZvbnRGYWNlOiAnWGZpbml0eUJyb3duQm9sZCcsXG4gICAgICAgICAgICBmb250U2l6ZTogNTYsXG4gICAgICAgICAgICBmb250V2VpZ2h0OiA3MDAsXG4gICAgICAgICAgICBsZXR0ZXJTcGFjaW5nOiAtMC40LFxuICAgICAgICAgICAgbGluZUhlaWdodDogNzIsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiAnbWlkZGxlJyxcbiAgICAgICAgICB9LFxuICAgICAgICAgIGZvbnRTaXplOiA3MixcbiAgICAgICAgICB0ZXh0Q29sb3I6ICcjNDA3Njg2MzQ4NycsXG4gICAgICAgICAgdGV4dEFsaWduOiAnY2VudGVyJyxcbiAgICAgICAgfSxcbiAgICAgIH0sXG4gICAgfTtcbiAgfVxuXG4gIF9jb25zdHJ1Y3QoKSB7XG4gICAgdGhpcy5waW4gPSBbXTtcbiAgICB0aGlzLnNvZnRLZXlQZW5kaW5nID0gbnVsbDtcbiAgfVxuXG4gIF9nZXRGb2N1c2VkKCkge1xuICAgIHJldHVybi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udG9TdHJpbmcoJ3V0ZjgnKTtcbiAgICAgICAgICBhd2FpdCBuZXcgUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICAgICAgICBwYXJzZXIucGFyc2VTdHJpbmcoeG1sRGF0YSwgZnVuY3Rpb24gKGVyciwgcmVzdWx0KSB7XG4gICAgICAgICAgICAgIGlmIChlcnIpIHtcbiAgICAgICAgICAgICAgICBwYXJzaW5nU3VjY2Vzc2Z1bCA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIHJlc29sdmUoKTtcbiAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjb25zdCByZXMgPSByZXN1bHRbJ25zMjp4Y2FsLWF1dGgtbWVzc2FnZSddWydhdHRyaWJ1dGUnXTtcbiAgICAgICAgICAgICAgICBwYXJzaW5nU3VjY2Vzc2Z1bCA9IHRydWU7XG4gICAgICAgICAgICAgICAgZm9yIChjb25zdCByZXNJdGVtIG9mIHJlcykge1xuICAgICAgICAgICAgICAgICAgaWYgKHJlc0l0ZW0uJC5rZXkgPT09ICdkZXZpY2U6Y2NwUGtpOmVzdGJNYWMnKSB7XG4gICAgICAgICAgICAgICAgICAgIGxvZ2dlci5pbmZvKHJlc0l0ZW0uXywgJ3B1c2hSZXBvcnRUb1MzJyk7XG4gICAgICAgICAgICAgICAgICAgIG1hY0FkZHJlc3MgPSByZXNJdGVtLl87XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJlc29sdmUoKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIG1hY0FkZHJlc3MgPSBwcm9jZXNzLmVudi5NQUNBRERSRVNTO1xuICAgICAgICBwYXJzaW5nU3VjY2Vzc2Z1bCA9IHRydWU7XG4gICAgICB9XG5cbiAgICAgIG1hY0FkZ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lc3REYXRhSGFuZGxlcixcbiAgY2Vuc29yRGF0YSxcbiAgZmlsdGVyRXhhbXBsZXMsXG4gIGVycm9yU2NoZW1hQ2hlY2ssXG4gIHJlbW92ZVNldEluTWV0aG9kTmFtZSxcbiAgZ2V0Q3VycmVudEFwcElELFxuICBnZXRNZXRob2RFeGNsdWRlZExpc3RCYXNlZE9uTW9kZSxcbiAgZmluZFR5cGVJbk9uZU9GLFxuICBvdmVycmlkZVBhcmFtc0Zyb21UZXN0RGF0YSxcbiAgcGFyc2VYQUNULFxufTtcbiIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyJdLCJzb3VyY2VSb290IjoiIn0=
\ No newline at end of file
diff --git a/PR-247/startupScripts.bundle.0d5973f0b67a4f320f9f.js b/PR-247/startupScripts.bundle.a09a79a3daf0f6af3c74.js
similarity index 99%
rename from PR-247/startupScripts.bundle.0d5973f0b67a4f320f9f.js
rename to PR-247/startupScripts.bundle.a09a79a3daf0f6af3c74.js
index a34bec94..d320cbbb 100644
--- a/PR-247/startupScripts.bundle.0d5973f0b67a4f320f9f.js
+++ b/PR-247/startupScripts.bundle.a09a79a3daf0f6af3c74.js
@@ -170,4 +170,4 @@ module.exports = __webpack_require__(/*! ./plugins/startupScripts/index.js */"./
/***/ })
/******/ });
-//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAiLCJ3ZWJwYWNrOi8vLy4vcGx1Z2lucy9zdGFydHVwU2NyaXB0cy9hY3RpdmF0ZU1vY2tGaXJlYm9sdC5qcyIsIndlYnBhY2s6Ly8vLi9wbHVnaW5z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