diff --git a/PR-175/COMMITHASH b/PR-175/COMMITHASH
index eec0abb2..41ecd622 100644
--- a/PR-175/COMMITHASH
+++ b/PR-175/COMMITHASH
@@ -1 +1 @@
-7a5b5a02080de17311bf70ed79a7c73c874d1181
\ No newline at end of file
+c22472d6c38576d8b8c76550bdf772bba43478a6
\ No newline at end of file
diff --git a/PR-175/VERSION b/PR-175/VERSION
index a4325204..93f3fa9d 100644
--- a/PR-175/VERSION
+++ b/PR-175/VERSION
@@ -1 +1 @@
-7a5b5a0
\ No newline at end of file
+c22472d
\ No newline at end of file
diff --git a/PR-175/index.html b/PR-175/index.html
index 538e2b26..b937171a 100644
--- a/PR-175/index.html
+++ b/PR-175/index.html
@@ -8,7 +8,7 @@
1.2.0 - Firebolt Certification App - version 1.2.0
-
+
E7QUFDQTtBQUNBLFNBQVM7QUFDVDtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSxTQUFTO0FBQ1Q7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSxnRUFBZ0U7QUFDaEU7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ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XG4gICAgICAgIC5zb3J0KChhLCBiKSA9PiB7XG4gICAgICAgICAgLy8gTW9zdCBwZW9wbGUgd2lsbCBleHBlY3QgcmVmZXJlbmNlcyB0byBiZSBidW5kbGVkIGludG8gdGhlIHRoZSBcImRlZmluaXRpb25zXCIgcHJvcGVydHksXG4gICAgICAgICAgLy8gc28gd2UgYWx3YXlzIGNyYXdsIHRoYXQgcHJvcGVydHkgZmlyc3QsIGlmIGl0IGV4aXN0cy5cbiAgICAgICAgICBpZiAoYSA9PT0gXCJkZWZpbml0aW9uc1wiKSB7XG4gICAgICAgICAgICByZXR1cm4gLTE7XG4gICAgICAgICAgfVxuICAgICAgICAgIGVsc2UgaWYgKGIgPT09IFwiZGVmaW5pdGlvbnNcIikge1xuICAgICAgICAgICAgcmV0dXJuIDE7XG4gICAgICAgICAgfVxuICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgLy8gT3RoZXJ3aXNlLCBjcmF3bCB0aGUga2V5cyBiYXNlZCBvbiB0aGVpciBsZW5ndGguXG4gICAgICAgICAgICAvLyBUaGlzIHByb2R1Y2VzIHRoZSBzaG9ydGVzdCBwb3NzaWJsZSBidW5kbGVkIHJlZmVyZW5jZXNcbiAgICAgICAgICAgIHJldHVybiBhLmxlbmd0aCAtIGIubGVuZ3RoO1xuICAgICAgICAgIH1cbiAgICAgICAgfSk7XG5cbiAgICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBuby1zaGFkb3dcbiAgICAgIGZvciAobGV0IGtleSBvZiBrZXlzKSB7XG4gICAgICAgIGxldCBrZXlQYXRoID0gUG9pbnRlci5qb2luKHBhdGgsIGtleSk7XG4gICAgICAgIGxldCBrZXlQYXRoRnJvbVJvb3QgPSBQb2ludGVyLmpvaW4ocGF0aEZyb21Sb290LCBrZXkpO1xuICAgICAgICBsZXQgdmFsdWUgPSBvYmpba2V5XTtcblxuICAgICAgICBpZiAoJFJlZi5pc0FsbG93ZWQkUmVmKHZhbHVlKSkge1xuICA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KSkge1xuICAgICAgICAgIGxldCBrZXlQYXRoID0gUG9pbnRlci5qb2luKHBhdGgsIGtleSk7XG4gICAgICAgICAgbGV0IGtleVBhdGhGcm9tUm9vdCA9IFBvaW50ZXIuam9pbihwYXRoRnJvbVJvb3QsIGtleSk7XG5cbiAgICAgICAgICBpZiAoaXNFeGNsdWRlZFBhdGgoa2V5UGF0aEZyb21Sb290KSkge1xuICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgbGV0IHZhbHVlID0gb2JqW2tleV07XG4gICAgICAgICAgbGV0IGNpcmN1bGFyID0gZmFsc2U7XG5cbiAgICAgICAgICBpZiAoJFJlZi5pc0FsbG93ZWQkUmVmKHZhbHVlLCBvcHRpb25zKSkge1xuICAgICAgICAgICAgZGVyZWZlcmVuY2VkID0gZGVyZWZlcmVuY2UkUmVmKHZhbHVlLCBrZXlQYXRoLCBrZXlQYXRoRnJvbVJvb3QsIHBhcmVudHMsIHByb2Nlc3NlZE9iamVjdHMsIGRlcmVmZXJlbmNlZENhY2hlLCAkcmVmcywgb3B0aW9ucyk7XG4gICAgICAgICAgICBjaXJjdWxhciA9IGRlcmVmZXJlbmNlZC5jaXJjdWxhcjtcbiAgICAgICAgICAgIC8vIEF2b2lkIHBvaW50bGVzcyBtdXRhdGlvbnM7IGJyZWFrcyBmcm96ZW4gb2JqZWN0cyB0byBubyBwcm9maXRcbiAgICAgICAgICAgIGlmIChvYmpba2V5XSAhPT0gZGVyZWZlcmVuY2VkLnZhbHVlKSB7XG4gICAgICAgICAgICAgIG9ialtrZXldID0gZGVyZWZlcmVuY2VkLnZhbHVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgIGlmICghcGFyZW50cy5oYXModmFsdWUpKSB7XG4gICAgICAgICAgICAgIGRlcmVmZXJlbmNlZCA9IGNyYXdsKHZhbHVlLCBrZXlQYXRoLCBrZXlQYXRoRnJvbVJ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vbWlzZTxCdWZmZXI+fVxuICAgKi9cbiAgcmVhZCAoZmlsZSkge1xuICAgIHJldHVybiBuZXcgUHJvbWlzZSgoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgbGV0IHBhdGg7XG4gICAgICB0cnkge1xuICAgICAgICBwYXRoID0gdXJsLnRvRmlsZVN5c3RlbVBhdGgoZmlsZS51cmwpO1xuICAgICAgfVxuICAgICAgY2F0Y2ggKGVycikge1xuICAgICAgICByZWplY3QobmV3IFJlc29sdmVyRXJyb3Iob25vLnVyaShlcnIsIGBNYWxmb3JtZWQgVVJJOiAke2ZpbGUudXJsfWApLCBmaWxlLnVybCkpO1xuICAgICAgfVxuXG4gICAgICAvLyBjb25zb2xlLmxvZygnT3BlbmluZyBmaWxlOiAlcycsIHBhdGgpO1xuXG4gICAgICB0cnkge1xuICAgICAgICBmcy5yZWFkRmlsZShwYXRoLCAoZXJyLCBkYXRhKSA9PiB7XG4gICAgICAgICAgaWYgKGVycikge1xuICAgICAgICAgICAgcmVqZWN0KG5ldyBSZXNvbHZlckVycm9yKG9ubyhlcnIsIGBFcnJvciBvcGVuaW5nIGZpbGUgXCIke3BhdGh9XCJgKSwgcGF0aCkpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgIHJlc29sdmUoZGF0YSk7XG4gICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgIH1cbiAgICAgIGNhdGNoIChlcnIpIHtcbiAgICAgICAgcmVqZWN0KG5ldyBSZXNvbHZlckVycm9yKG9ubyhlcnIsIGBFcnJvciBvcGVuaW5nIGZpbGUgXCIke3BhdGh9XCJgKSwgcGF0aCkpO1xuICAgICAgfVxuICAgIH0pKTtcbiAgfVxufTtcbiIsIlwidXNlIHN0cmljdFwiO1xuXG5jb25zdCBodHRwID0gcmVxdWlyZShcImh0dHBcIik7XG5jb25zdCBodHRwcyA9IHJlcXVpcmUoXCJodHRwc1wiKTtcbmNvbnN0IHsgb25v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cbiAgICB2YXIgY2hhcnMgPSB0cmFwW2NdIHx8IFsnICddO1xuICAgIHZhciByYW5kID0gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogY2hhcnMubGVuZ3RoKTtcbiAgICBpZiAodHlwZW9mIHRyYXBbY10gIT09ICd1bmRlZmluZWQnKSB7XG4gICAgICByZXN1bHQgKz0gdHJhcFtjXVtyYW5kXTtcbiAgICB9IGVsc2Uge1xuICAgICAgcmVzdWx0ICs9IGM7XG4gICAgfVxuICB9KTtcbiAgcmV0dXJuIHJlc3VsdDtcbn07XG4iLCIvLyBwbGVhc2Ugbm9cbm1vZHVsZVsnZXhwb3J0cyddID0gZnVuY3Rpb24gemFsZ28odGV4dCwgb3B0aW9ucykge1xuICB0ZXh0ID0gdGV4dCB8fCAnICAgaGUgaXMgaGVyZSAgICc7XG4gIHZhciBzb3VsID0ge1xuICAgICd1cCc6IFtcbiAgICAgICfMjScsICfMjicsICfMhCcsICfMhScsXG4gICAgICAnzL8nLCAnzJEnLCAnzIYnLCAnzJAnLFxuICAgICAgJ82SJywgJ82XJywgJ82RJywgJ8yHJyxcbiAgICAgICfMiCcsICfMiicsICfNgicsICfMkycsXG4gICAgICAnzIgnLCAnzYonLCAnzYsnLCAnzYwnLFxuICAgICAgJ8yDJywgJ8yCJywgJ8yMJywgJ82QJyxcbiAgICAgICfMgCcsICfMgScsICfMiycsICfMjycsXG4gICAgICAnzJInLCAnzJMnLCAnzJQnLCAnzL0nLFxuICAgICAgJ8yJJywgJ82jJywgJ82kJywgJ82lJyxcbiAgICAgICfNpicsICfNpycsICfNqCcsICfNqScsXG4gICAgICAnzaonLCAnzasnLCAnzawnLCAnza0nLFxuICAgICAgJ82uJywgJ82vJywgJ8y+JywgJ82bJyxcbiAgICAgICfNhicsICfMmicsXG4gICAgXSxcbiAgICAnZG93bic6IFtcbiAgICAgICfMlicsICfMlycsICfMmCcsICfMmScsXG4gICAgICAnzJwnLCAnzJ0nLCAnzJ4nLCAnzJ8nLFxuICAgICAgJ8ygJywgJ8ykJywgJ8ylJywgJ8ymJyxcbiAgICAgICfMqScsICfMqicsICfMqycsICfMrCcsXG4gICAgICAnzK0nLCAnzK4nLCAnzK8nLCAnzLAnLFxuICAgICAgJ8yxJywgJ8yyJywgJ8yzJywgJ8y5JyxcbiAgICAgICfMuicsICfMuycsICfMvCcsICfNhScsXG4gICAgICAnzYcnLCAnzYgnLCAnzYknLCAnzY0nLFxuICAgICAgJ82OJywgJ82TJywgJ82UJywgJ82VJyxcbiAgICAgICfNlicsICfNmScsICfNmicsICfMoycsXG4gICAgXSxcbiAgICAnbWlkJzogW1xuICAgICAgJ8yVJywgJ8ybJywgJ8yAJywgJ8yBJyxcbiAgICAgICfNmCcsICfMoScsICfMoicsICfMpycsXG4gICAgICAnzKgnLCAnzLQnLCAnzLUnLCAnzLYnLFxuICAgICAgJ82cJywgJ82dJywgJ82eJyxcbiAgICAgICfNnycsICfNoCcsICfNoicsICfMuCcsXG4gICAgICAnzLcnLCAnzaEnLCAnINKJJyxcbiAgICBdLFxuICB9O1xuICB2YXIgYWxsID0gW10uY29uY2F0KHNvdWwudXAsIHNvdWwuZG93biwgc291bC5taWQpO1xuXG4gIGZ1bmN0aW9uIHJhbmRvbU51bWJlcihyYW5nZSkge1xuICAgIHZhciByID0gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogcmFuZ2UpO1xuICAgIHJldHVybiByO1xuICB9XG5cbiAgZnVuY3Rpb24gaXNDaGFyKGNoYXJhY3Rlcikge1xuICAgIHZhciBib29sID0gZmFsc2U7XG4gICAgYWxsLmZpbHRlcihmdW5jdGlvbihpKSB7XG4gICAgICBib29sID0gKGkgPT09IGNoYXJhY3Rlcik7XG4gICAgfSk7XG4gICAgcmV0dXJuIGJvb2w7XG4gIH1cblxuXG4gIGZ1bmN0aW9uIGhlQ29tZXModGV4dCwgb3B0aW9ucykge1xuICAgIHZhciByZXN1bHQgPSAnJztcbiAgICB2YXIgY291bnRzO1xuICAgIHZhci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cigxNikgKyAzO1xuICAgICAgICAgIGNvdW50cy5taWQgPSByYW5kb21OdW1iZXIoNCkgKyAxO1xuICAgICAgICAgIGNvdW50cy5kb3duID0gcmFuZG9tTnVtYmVyKDY0KSArIDM7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgY291bnRzLnVwID0gcmFuZG9tTnVtYmVyKDgpICsgMTtcbiAgICAgICAgICBjb3VudHMubWlkID0gcmFuZG9tTnVtYmVyKDYpIC8gMjtcbiAgICAgICAgICBjb3VudHMuZG93biA9IHJhbmRvbU51bWJlcig4KSArIDE7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICB9XG5cbiAgICAgIHZhciBhcnIgPSBbJ3VwJywgJ21pZCcsICdkb3duJ107XG4gICAgICBmb3IgKHZhciBkIGluIGFycikge1xuICAgICAgICB2YXIgaW5kZXggPSBhcnJbZF07XG4gICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDw9IGNvdW50c1tpbmRleF07IGkrKykge1xuICAgICAgICAgIGlmIChvcHRpb25zW2luZGV4XSkge1xuICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgc291bFtpbmRleF1bcmFuZG9tTnVtYmVyKHNvdWxbaW5kZXhdLmxlbmd0aCldO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4gcmVzdWx0O1xuICB9XG4gIC8vIGRvbid0IHN1bW1vbiBoaW1cbiAgcmV0dXJuIGhlQ29tZXModGV4dCwgb3B0aW9ucyk7XG59O1xuXG4iLCJtb2R1bGVbJ2V4cG9ydHMnXSA9IGZ1bmN0aW9uKGNvbG9ycykge1xuICByZXR1cm4gZnVuY3Rpb24obGV0dGVyLCBpLCBleHBsb2RlZCkge1xuICAgIGlmIChsZXR0ZXIgPT09ICcgJykgcmV0dXJuIGxldHRlcjtcbiAgICBzd2l0Y2ggKGklMykge1xuICAgICAgY2FzZSAwOiByZXR1cm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QpID0+IHtcbiAgICAgIGNvbnN0IGtleSA9IG1vZHVsZSArICcuJyArIGV2ZW50ICsgKGhhc0NvbnRleHQgPyBgLiR7Y29udGV4dEtleX1gIDogJycpXG5cbiAgICAgIGlmIChPYmplY3QudmFsdWVzKGxpc3RlbmVycy5nZXQoa2V5KSkubGVuZ3RoID09PSAwKSB7XG4gICAgICAgIGNvbnN0IGFyZ3MgPSBPYmplY3QuYXNzaWduKHsgbGlzdGVuOiB0cnVlIH0sIGNvbnRleHQpXG4gICAgICAgIGNvbnN0IHsgaWQsIHByb21pc2UgfSA9IFRyYW5zcG9ydC5saXN0ZW4oXG4gICAgICAgICAgbW9kdWxlLFxuICAgICAgICAgICdvbicgKyBldmVudFswXS50b1VwcGVyQ2FzZSgpICsgZXZlbnQuc3Vic3RyaW5nKDEpLFxuICAgICAgICAgIGFyZ3MsXG4gICAgICAgIClcbiAgICAgICAga2V5c1tpZF0gPSBrZXlcbiAgICAgICAgcHJvbWlzZXMucHVzaChwcm9taXNlKVxuICAgICAgfVxuXG4gICAgICBjb25zdCBzZXR0ZXIgPSBpbnRlcm5hbCA/IGxpc3RlbmVycy5zZXRJbnRlcm5hbCA6IGxpc3RlbmVycy5zZXRcblxuICAgICAgaWYgKHdpbGRjYXJkKSB7XG4gICAgICAgIHNldHRlcihrZXksICcnICsgbGlzdGVuZXJJZCwgKHZhbHVlKSA9PiBjYWxsYmFjayhldmVudCwgdmFsdWUpKVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgc2V0dGVyKGtleSwgJycgKyBsaXN0ZW5lcklkLCBjYWxsYmFjaylcbiAgICAgIH1cbiAgICB9KVxuXG4gICAgbGV0IHJlc29sdmUsIHJlamVjdFxuICAgIGxldCBwID0gbmV3IFByb21pc2UoKHJlcywgcmVqKSA9PiB7XG4gICAgICByZXNvbHZlID0gcmVzXG4gICAgICByZWplY3QgPSByZWpcbiAgICB9KVxuXG4gICAgaWYgKHByb21pc2VzLmxlbmd0aCkge1xuICAgICAgUH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lzdGVuZXJzLmZpbmQoc2VhcmNoSWQpXG5cbiAgICBpZiAoa2V5KSB7XG4gICAgICBsaXN0ZW5lcnMucmVtb3ZlKHNlYXJjaElkKVxuICAgICAgaWYgKGxpc3RlbmVycy5jb3VudChrZXkpID09PSAwKSB7XG4gICAgICAgIHVuc3Vic2NyaWJlKGtleSlcbiAgICAgIH1cbiAgICAgIHJldHVybiB0cnVlXG4gICAgfVxuICAgIHJldHVybiBmYWxzZVxuICB9IGVsc2Uge1xuICAgIGlmICghbW9kdWxlT3JJZCAmJiAhZXZlbnQpIHtcbiAgICAgIGxpc3RlbmVycy5rZXlzKCkuZm9yRWFjaCgoa2V5KSA9PiB7XG4gICAgICAgIGxpc3RlbmVycy5yZW1vdmVLZXkoa2V5KVxuICAgICAgICB1bnN1YnNjcmliZShrZXkpXG4gICAgICB9KVxuICAgIH0gZWxzZSBpZiAoIWV2ZW50KSB7XG4gICAgICBsaXN0ZW5lcnMua2V5cygpLmZvckVhY2goKGtleSkgPT4ge1xuICAgICAgICBpZiAoa2V5LmluZGV4T2YobW9kdWxlT3JJZC50b0xvd2VyQ2FzZSgpKSA9PT0gMCkge1xuICAgICAgICAgIGxpc3RlbmVycy5yZW1vdmVLZXkoa2V5KVxuICAgICAgICAgIHVuc3Vic2NyaWJlKGtleSlcbiAgICAgICAgfVxuICAgICAgfSlcbiAgICB9IGVsc2Uge1xuICAgICAgY29uc3QgaGFzQ29udGV4dCA9IE9iamVjdC52YWx1ZXMoY29udGV4dCkubGVuZ3RoID4gMFxuICAgICAgY29uc3QgY29udGV4dEtleSA9IE9iamVjdC5rZXlzKGNvbnRleHQpXG4gICAgICAgIC5zb3J0KClcbiAgICAgICAgLm1hcCgoa2V5KSA9PiBrZXkgKyAnPScgKyBKU09OLnN0cmluZ2lmeShjb250ZXh0W2tleV0pKVxuICAgICAgICAuam9pbignJicpXG4gICAgICBjb25zdCBrZXkgPVxuICAgICAgICBtb2R1bGVPcklkICsgJy4nICsgZXZlbnQgKyA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ICAgICAgICAgbW9kdWxlLFxuICAgICAgICAgICdvbicgKyBldmVudFswXS50b1VwcGVyQ2FzZSgpICsgZXZlbnQuc3Vic3RyaW5nKDEpLFxuICAgICAgICAgIGFyZ3MsXG4gICAgICAgIClcbiAgICAgICAga2V5c1tpZF0gPSBrZXlcbiAgICAgICAgcHJvbWlzZXMucHVzaChwcm9taXNlKVxuICAgICAgfVxuXG4gICAgICBjb25zdCBzZXR0ZXIgPSBpbnRlcm5hbCA/IGxpc3RlbmVycy5zZXRJbnRlcm5hbCA6IGxpc3RlbmVycy5zZXRcblxuICAgICAgaWYgKHdpbGRjYXJkKSB7XG4gICAgICAgIHNldHRlcihrZXksICcnICsgbGlzdGVuZXJJZCwgKHZhbHVlKSA9PiBjYWxsYmFjayhldmVudCwgdmFsdWUpKVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgc2V0dGVyKGtleSwgJycgKyBsaXN0ZW5lcklkLCBjYWxsYmFjaylcbiAgICAgIH1cbiAgICB9KVxuXG4gICAgbGV0IHJlc29sdmUsIHJlamVjdFxuICAgIGxldCBwID0gbmV3IFByb21pc2UoKHJlcywgcmVqKSA9PiB7XG4gICAgICByZXNvbHZlID0gcmVzXG4gICAgICByZWplY3QgPSByZWpcbiAgICB9KVxuXG4gICAgaWYgKHByb21pc2VzLmxlbmd0aCkge1xuICAgICAgUHJvbWlzZS5hbGwocHJvbWlzZXMpXG4gICAgICAgIC50aGVuKChyZXNwb25zZXMpID0+IHtcbiAgICAgICAgICByZXNvbHZlKGxpc3RlbmVySWQpXG4gICAgICAgIH0pXG4gICAgICAgIC5jYXRjaCgoZXJyb3IpID0+IHtcbiAgICAgICAgICAvLyBQcm9taXNlLmFsbCByZWplY3RzIGlmIGF0IGxlYXN0IG9uZSBwcm9taXNlIHJlamVjdHMuLi4gd2UgZG9uJ3Qgd2FudCB0aGF0IGJlaGF2aW9yIGhlcmVcbiAgICAgICAgICAvLyBUT0RPOiBEbyBzb21ldGhpbmcgYmV0dGVyIH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m9yRWFjaCgoa2V5KSA9PiB7XG4gICAgICAgIGxpc3RlbmVycy5yZW1vdmVLZXkoa2V5KVxuICAgICAgICB1bnN1YnNjcmliZShrZXkpXG4gICAgICB9KVxuICAgIH0gZWxzZSBpZiAoIWV2ZW50KSB7XG4gICAgICBsaXN0ZW5lcnMua2V5cygpLmZvckVhY2goKGtleSkgPT4ge1xuICAgICAgICBpZiAoa2V5LmluZGV4T2YobW9kdWxlT3JJZC50b0xvd2VyQ2FzZSgpKSA9PT0gMCkge1xuICAgICAgICAgIGxpc3RlbmVycy5yZW1vdmVLZXkoa2V5KVxuICAgICAgICAgIHVuc3Vic2NyaWJlKGtleSlcbiAgICAgICAgfVxuICAgICAgfSlcbiAgICB9IGVsc2Uge1xuICAgICAgY29uc3QgaGFzQ29udGV4dCA9IE9iamVjdC52YWx1ZXMoY29udGV4dCkubGVuZ3RoID4gMFxuICAgICAgY29uc3QgY29udGV4dEtleSA9IE9iamVjdC5rZXlzKGNvbnRleHQpXG4gICAgICAgIC5zb3J0KClcbiAgICAgICAgLm1hcCgoa2V5KSA9PiBrZXkgKyAnPScgKyBKU09OLnN0cmluZ2lmeShjb250ZXh0W2tleV0pKVxuICAgICAgICAuam9pbignJicpXG4gICAgICBjb25zdCBrZXkgPVxuICAgICAgICBtb2R1bGVPcklkICsgJy4nICsgZXZlbnQgKyAoaGFzQ29udGV4dCA/IGAuJHtjb250ZXh0S2V5fWAgOiAnJylcblxuICAgICAgbGlzdGVuZXJzLnJlbW92ZUtleShrZXkpXG4gICAgICB1bnN1YnNjcmliZShrZXksIGNvbnRleHQpXG4gICAgfVxuICB9XG59XG5cbmNvbnN0IGluaXQgPSAoKSA9PiB7XG4gIGlmICghdHJhbnNwb3J0SW5pdGlhbGl6ZWQpIHtcbiAgICBUcmFuc3BvcnQuYWRkRXZlbnRFbWl0dGVyKGVtaXQpXG4gICAgc2V0TW9ja0xpc3RlbmVyKGxpc3RlbilcbiAgICB0cmFuc3BvcnRJbml0aWFsaXpl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ucyB1bmRlciB0aGUgTGljZW5zZS5cbiAqXG4gKiBTUERYLUxpY2Vuc2UtSWRlbnRpZmllcjogQXBhY2hlLTIuMFxuICovXG5pbXBvcnQgTW9ja1Byb3BzIGZyb20gJy4uL1Byb3AvTW9ja1Byb3BzLm1qcydcblxuZXhwb3J0IGRlZmF1bHQge1xuICBhbGxvd1Jlc3VtZVBvaW50czogZnVuY3Rpb24gKHBhcmFtcykge1xuICAgIHJldHVybiBNb2NrUHJvcHMubW9jayhcbiAgICAgICdQcml2YWN5JyxcbiAgICAgICdhbGxvd1Jlc3VtZVBvaW50cycsXG4gICAgICBwYXJhbXMsXG4gICAgICB1bmRlZmluZWQsXG4gICAgICAwLFxuICAgICAgdHJ1ZSxcbiAgICApXG4gIH0sXG4gIGFsbG93VW5lbnRpdGxlZFJlc3VtZVBvaW50czogZnVuY3Rpb24gKHBhcmFtcykge1xuICAgIHJldHVybiBNb2NrUHJvcHMubW9jayhcbiAgICAgICdQcml2YWN5JyxcbiAgICAgICdhbGxvd1VuZW50aXRsZWRSZXN1bWVQb2ludHMnLFxuICAgICAgcGFyYW1zLFxuICAgICAgdW5kZWZpbmVkLFxuICAgICAgMCxcbiAgICAgIHRydWUsXG4gICAgKVxuICB9LFxuICBhbGxvd1dhdGNoSGlzdG9yeTogZnVuY3Rpb24gKHBhcmFtcykge1xuICAgIHJldHVybiBNb2NrUHJvcHMubW9jayhcbiAgICAgICdQcml2YWN5JyxcbiAgICAgICdhbGxvd1dhdGNoSGlzdG9yeScsXG4gICAgICBwYXJhbXMsXG4gICAgICB1bmRlZmluZWQsXG4gICAgICAwLFxuICAgICAgdHJ1ZSxcbiAgICApXG4gIH0sXG4gIGFsbG93UHJvZHVjdEFuYWx5dGljczogZnVuY3Rpb24gKHBhcmFtcykge1xuICAgIHJldHVybiBNb2NrUHJvcHMubW9jayhcbiAgICAgICdQcml2YWN5JyxcbiAgICAgICdhbGxvd1Byb2R1Y3RBbmFseXRpY3MnLFxuICAgICAgcGFy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XG4gICAgICB0cnVlLFxuICAgIClcbiAgfSxcbiAgYWxsb3dQcmltYXJ5QnJvd3NlQWRUYXJnZXRpbmc6IGZ1bmN0aW9uIChwYXJhbXMpIHtcbiAgICByZXR1cm4gTW9ja1Byb3BzLm1vY2soXG4gICAgICAnUHJpdmFjeScsXG4gICAgICAnYWxsb3dQcmltYXJ5QnJvd3NlQWRUYXJnZXRpbmcnLFxuICAgICAgcGFyYW1zLFxuICAgICAgdW5kZWZpbmVkLFxuICAgICAgMCxcbiAgICAgIHRydWUsXG4gICAgKVxuICB9LFxuICBhbGxvd0FwcENvbnRlbnRBZFRhcmdldGluZzogZnVuY3Rpb24gKHBhcmFtcykge1xuICAgIHJldHVybiBNb2NrUHJvcHMubW9jayhcbiAgICAgICdQcml2YWN5JyxcbiAgICAgICdhbGxvd0FwcENvbnRlbnRBZFRhcmdldGluZycsXG4gICAgICBwYXJhbXMsXG4gICAgICB1bmRlZmluZWQsXG4gICAgICAwLFxuICAgICAgdHJ1ZSxcbiAgICApXG4gIH0sXG4gIGFsbG93QUNSQ29sbGVjdGlvbjogZnVuY3Rpb24gKHBhcmFtcykge1xuICAgIHJldHVybiBNb2NrUHJvcHMubW9jayhcbiAgICAgICdQcml2YWN5JyxcbiAgICAgICdhbGxvd0FDUkNvbGxlY3Rpb24nLFxuICAgICAgcGFyYW1zLFxuICAgICAgdW5kZWZpbmVkLFxuICAgICAgMCxcbiAgICAgIHRydWUsXG4gICAgKVxuICB9LFxuICBhbGxvd0NhbWVyYUFuYWx5dGljczogZnVuY3Rpb24gKHBhcmFtcykge1xuICAgIHJldHVybiBNb2NrUHJvcHMubW9jayhcbiAgICAgICdQcml2YWN5JyxcbiAgICAgICdhbGxvd0NhbWVyYUFuYWx5dGljcycsXG4gICAgICBwYXJhbXMsXG4gICAgICB1bmRlZmluZWQsXG4gICAgICAwLFxuICAgICAgdHJ1ZSxcbiAgICApXG4gIH0sXG4gIHNldHRpbmdzOiB7XG4gICAgYWxsb3dBQ1JD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vbklkOiAoKSA9PiB7XG4gICAgICAgICAgICByZXR1cm4gcmVxdWVzdC5jb3JyZWxhdGlvbklkXG4gICAgICAgICAgfSxcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIG9ubHkgcGFzcyBpbiB0aGUgZm9jdXMgaGFuZHNoYWtlIGlmIG5lZWRlZFxuICAgICAgICBpZiAoaW1ldGhvZC5mb2N1cykge1xuICAgICAgICAgIHNlc3Npb24uZm9jdXMgPSAoKSA9PiB7XG4gICAgICAgICAgICBUcmFuc3BvcnQuc2VuZChtb2R1bGUsIGAke21ldGhvZH1Gb2N1c2AsIHtcbiAgICAgICAgICAgICAgY29ycmVsYXRpb25JZDogcmVxdWVzdC5jb3JyZWxhdGlvbklkLFxuICAgICAgICAgICAgfSlcbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBwcm92aWRlckNhbGxBcmdzLnB1c2goc2Vzc2lvbilcblxuICAgICAgICBjb25zdCByZXNwb25zZSA9IHtcbiAgICAgICAgICBjb3JyZWxhdGlvbklkOiByZXF1ZXN0LmNvcnJlbGF0aW9uSWQsXG4gICAgICAgIH1cbiAgICAgICAgbGV0IGhhbmRsZUVycm9yID0gKGVycm9yKSA9PiB7XG4gICAgICAgICAgcmVzcG9uc2UuZXJyb3IgPSB7XG4gICAgICAgICAgICBjb2RlOiBlcnJvci5jb2RlIHx8IDEwMDAsIC8vIHRvZG86IHNob3VsZCBiZSBzb21lIHJlc2VydmVkIGNvZGUgZm9yIFwiVW5rbm93blwiXG4gICAgICAgICAgICBtZXNzYWdlOlxuICAgICAgICAgICAgICBlcnJvci5tZXNzYWdlIHx8XG4gICAgICAgICAgICAgIGBBbiBlcnJvciBvY2N1cmVkIHdoaWxlIGNhbGxpbmcgcHJvdmlkZWQgJHttZXRob2R9IG1ldGhvZC5gLFxuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChlcnJvci5kYXRhKSB7XG4gICAgICAgICAgICByZXNwb25zZS5lcnJvci5kYXRhID0gSlNPTi5wYXJzZShKU09OLnN0cmluZ2lmeShlcnJvci5kYXRhKSlcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBUcmFuc3BvcnQuc2VuZChtb2R1bGUsIGAke21ldGhvZH1FcnJvcmAsIHJlc3BvbnNlKVxuICAgICAgICB9XG5cbiAgICAgICAgdHJ5IHtcbiAgICAgICAgICBjb25zdCByZXN1bHQgPSBwcm92aWRlclttZXRob2RdLmFwcGx5KHByb3ZpZGVyLCBwcm92aWRlckNhbGxBcmdzKVxuXG4gICAgICAgICAgaWYgKCEocmVzdWx0IGluc3RhbmNlb2YgUHJvbWlzZSkpIHtcbiAgICAgICAgICAgIHRocm93IGBQcm92aWRlciBtZXRob2QgJHttZXRob2R9IGRpZCBub3QgcmV0dXJuIGEgUHJvbWlzZS5gXG4gICAgICAgICAgfVxuXG4gICAgICAgICAgcmVzdWx0XG4gICAgICAgICAgICAudGhlbigocmVzdWx0KSA9PiB7XG4gICAgICAgICAgICAgIGlmIChpbWV0aG9kLnJlc3BvbnNlKSB7XG4gICAgICAgICAgICAgICAgcmVzcG9uc2UucmVzdWx0ID0gcmVzdWx0XG4gICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICBUcmFuc3BvcnQuc2VuZChtb2R1bGUsIGAke21ldGhvZH1SZXNwb25zZWAsIHJlc3BvbnNlKVxuICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIC5jYXRjaCgoZXJyKSA9PiBoYW5kbGVFcnJvcihlcnIpKVxuICAgICAgICB9IGNhdGNoIChlcnJvcikge1xuICAgICAgICAgIGhhbmRsZUVycm9yKGVycm9yKVxuICAgICAgICB9XG4gICAgICB9LFxuICAgIClcbiAgfSlcbn1cblxuZXhwb3J0IGRlZmF1bHQge1xuICBwcm92aWRlLFxufVxuIiwiaW1wb3J0IFRyYW5zcG9ydCBmcm9tICcuLi9UcmFuc3BvcnQvaW5kZXgubWpzJ1xuXG4vKlxubWV0aG9kcyA9IE1hcDxzdHJpbmcsIHtcbiAgIC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1bWVudHNbMF0gPT09ICdmdW5jdGlvbicpIHtcbiAgICBpZiAoZW50aXR5SW5mb0hhc0NhbGxiYWNrKSB7XG4gICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoJ0Nhbm5vdCByZWdpc3RlciBtb3JlIHRoYW4gb25lIGVudGl0eUluZm8gaGFuZGxlci4nKVxuICAgIH1cblxuICAgIGNvbnN0IGNhbGxiYWNrID0gYXJndW1lbnRzWzBdXG4gICAgZW50aXR5SW5mb0hhc0NhbGxiYWNrID0gdHJ1ZVxuICAgIHJldHVybiBFdmVudHMubGlzdGVuKCdEaXNjb3ZlcnknLCAncHVsbEVudGl0eUluZm8nLCAocmVxdWVzdCkgPT4ge1xuICAgICAgaWYgKHR5cGVvZiByZXF1ZXN0ID09PSAnYm9vbGVhbicpIHJldHVyblxuXG4gICAgICB0cnkge1xuICAgICAgICBjb25zdCByZXN1bHQgPSBjYWxsYmFjayhyZXF1ZXN0LnBhcmFtZXRlcnMpXG4gICAgICAgICAgLnRoZW4oKHJlc3VsdCkgPT4ge1xuICAgICAgICAgICAgY29uc3QgcGFyYW1zID0ge1xuICAgICAgICAgICAgICBjb3JyZWxhdGlvbklkOiByZXF1ZXN0LmNvcnJlbGF0aW9uSWQsXG4gICAgICAgICAgICAgIHJlc3VsdDogcmVzdWx0LFxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgVHJhbnNwb3J0LnNlbmQoJ0Rpc2NvdmVyeScsICdlbnRpdHlJbmZvJywgcGFyYW1zKS5jYXRjaCgoZXJyb3IpID0+IHtcbiAgICAgICAgICAgICAgY29uc3QgbXNnID1cbiAgICAgICAgICAgICAgICB0eXBlb2YgZXJyb3IgPT09ICdzdHJpbmcnXG4gICAgICAgICAgICAgICAgICA/IGVycm9yXG4gICAgICAgICAgICAgICAgICA6IGVycm9yLm1lc3NhZ2UgfHwgJ1Vua25vd24gRXJyb3InXG4gICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoXG4gICAgICAgICAgICAgICA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udEhhc0NhbGxiYWNrKSB7XG4gICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoXG4gICAgICAgICdDYW5ub3QgcmVnaXN0ZXIgbW9yZSB0aGFuIG9uZSBwdXJjaGFzZWRDb250ZW50IGhhbmRsZXIuJyxcbiAgICAgIClcbiAgICB9XG5cbiAgICBjb25zdCBjYWxsYmFjayA9IGFyZ3VtZW50c1swXVxuICAgIHB1cmNoYXNlZENvbnRlbnRIYXNDYWxsYmFjayA9IHRydWVcbiAgICByZXR1cm4gRXZlbnRzLmxpc3RlbignRGlzY292ZXJ5JywgJ3B1bGxQdXJjaGFzZWRDb250ZW50JywgKHJlcXVlc3QpID0+IHtcbiAgICAgIGlmICh0eXBlb2YgcmVxdWVzdCA9PT0gJ2Jvb2xlYW4nKSByZXR1cm5cblxuICAgICAgdHJ5IHtcbiAgICAgICAgY29uc3QgcmVzdWx0ID0gY2FsbGJhY2socmVxdWVzdC5wYXJhbWV0ZXJzKVxuICAgICAgICAgIC50aGVuKChyZXN1bHQpID0+IHtcbiAgICAgICAgICAgIGNvbnN0IHBhcmFtcyA9IHtcbiAgICAgICAgICAgICAgY29ycmVsYXRpb25JZDogcmVxdWVzdC5jb3JyZWxhdGlvbklkLFxuICAgICAgICAgICAgICByZXN1bHQ6IHJlc3VsdCxcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIFRyYW5zcG9ydC5zZW5kKCdEaXNjb3ZlcnknLCAncHVyY2hhc2VkQ29udGVudCcsIHBhcmFtcykuY2F0Y2goXG4gICAgICAgICAgICAgIChlcnJvcikgPT4ge1xuICAgICAgICAgICAgICAgIGNvbnN0IG1zZyA9XG4gICAgICAgICAgICAgICAgICB0eXBlb2YgZXJyb3IgPT09ICdzdHJpbmcnXG4gICAgICAgICAgICAgICAgICAgID8gZXJyb3JcbiAgICAgICAgICAgICAgICAgICAgOiBlcnJvci5tZXNzYWdlIHx8ICdVbmtub3duIEVycm9yJ1xuICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoXG4gICAgICAgICAgICAgICAgICBgRmFpbGVkIHRvIHNlbmQgcHVyY2hhc2VkQ29udGVudCBwdWxsIHJlc3BvbnNlIHRocm91Z2ggVHJhbnNwb3J0IExheWVyOiAke21zZ31gLFxuICAgICAgICAgICAgICAgIClcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIClcbiAgICAgICAgICB9KVxuICAgICAgICAgIC5jYXRjaCgoZXJyb3IpID0+IHtcbiAgICAgICAgICAgIGNvbnN0IG1zZyA9XG4gICAgICAgICAgICAgIHR5cGVvZiBlcnJvciA9PT0gJ3N0cmluZydcbiAgICAgICAgICAgICAgICA/IGVycm9yXG4gICAgICAgICAgICAgICAgOiBlcnJvci5tZXNzYWdlIHx8ICdVbmtub3duIEVycm9yJ1xuICAgICAgICAgICAgY29uc29sZS5lcnJvcihgQXBwICdwdXJjaGFzZWRDb250ZW50JyBjYWxsYmFjayBmYWlsZWQ6ICR7bXNnfWApXG4gICAgICAgICAgfSlcbiAgICAgIH0gY2F0Y2ggKGVycm9yKSB7XG4gICAgICAgIGNvbnN0IG1zZyA9XG4gICAgICAgICAgdHlwZW9mIGVycm9yID09PSAnc3RyaW5nJyA/IGVycm9yIDogZXJyb3IubWVzc2FnZSB8fCAnVW5rbm93biBFcnJvcidcbiAgICAgICAgY29uc29sZS5lcnJvcihgQXBwICdwdXJjaGFzZWRDb250ZW50JyBjYWxsYmFjayBmYWlsZWQ6ICR7bXNnfWApXG4gICAgICB9XG4gICAgfSlcbiAgfSBlbHNlIHtcbiAgICByZXR1cm4gVHJhbnNwb3J0LnNlbmQoJ0Rpc2NvdmVyeScsICdwdXJjaGFzZWRDb250ZW50Jywge1xuICAgICAgY29ycmVsYXRpb25JZDogbnVsbCxcbiAgICAgIHJlc3VsdDogZGF0YSxcbiAgICB9KVxuICB9XG59XG5cbmltcG9ydCB7IHNpZ25JbiBhcyBsb2dTaWduSW4gfSBmcm9tICcuLi9NZXRyaWNzL2luZGV4Lm1qc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bnRcbiAgaWYgKG1ldGhvZC5tYXRjaCgvXm9uW0EtWl0vKSkge1xuICAgIGlmIChqc29uLnBhcmFtcy5saXN0ZW4pIHtcbiAgICAgIGV2ZW50TWFwW2pzb24uaWRdID1cbiAgICAgICAgbW9kdWxlLnRvTG93ZXJDYXNlKCkgKyAnLicgKyBtZXRob2RbMl0udG9Mb3dlckNhc2UoKSArIG1ldGhvZC5zdWJzdHIoMylcbiAgICB9IGVsc2Uge1xuICAgICAgT2JqZWN0LmtleXMoZXZlbnRNYXApLmZvckVhY2goKGtleSkgPT4ge1xuICAgICAgICBpZiAoXG4gICAgICAgICAgZXZlbnRNYXBba2V5XSA9PT1cbiAgICAgICAgICBtb2R1bGUudG9Mb3dlckNhc2UoKSArXG4gICAgICAgICAgICAnLicgK1xuICAgICAgICAgICAgbWV0aG9kWzJdLnRvTG93ZXJDYXNlKCkgK1xuICAgICAgICAgICAgbWV0aG9kLnN1YnN0cigzKVxuICAgICAgICApIHtcbiAgICAgICAgICBkZWxldGUgZXZlbnRNYXBba2V5XVxuICAgICAgICB9XG4gICAgICB9KVxuICAgIH1cbiAgfVxuXG4gIGlmIChtb2NrKSBoYW5kbGUoanNvbilcbiAgZWxzZSBwZW5kaW5nLnB1c2goanNvbilcbn1cblxuZnVuY3Rpb24gaGFuZGxlKGpzb24pIHtcbiAgbGV0IHJlc3VsdFxuICB0cnkge1xuICAgIHJlc3VsdCA9IGdldFJlc3VsdChqc29uLm1ldGhvZCwganNvbi5wYXJhbXMpXG4gIH0gY2F0Y2ggKGVycm9yKSB7XG4gICAgc2V0VGltZW91dCgoKSA9PlxuICAgICAgY2FsbGJhY2soXG4gICAgICAgIEpTT04uc3RyaW5naWZ5KHtcbiAgICAgICAgICBqc29ucnBjOiAnMi4wJyxcbiAgICAgICAgICBlcnJvcjoge1xuICAgICAgICAgICAgY29kZTogLTMyNjAyLFxuICAgICAgICAgICAgbWVzc2FnZTpcbiAgICAgICAgICAgICAgJ0ludmFsaWQgcGFyYW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ICAgbGV0IHhhID0gMSAtIHhjIC0geGI7XG4gICAgbGV0IHljID0gMyAqIGI7XG4gICAgbGV0IHliID0gMyAqIChkIC0gYikgLSB5YztcbiAgICBsZXQgeWEgPSAxIC0geWMgLSB5YjtcbiAgICByZXR1cm4gZnVuY3Rpb24odGltZSkge1xuICAgICAgaWYgKHRpbWUgPj0gMSkge1xuICAgICAgICByZXR1cm4gMTtcbiAgICAgIH1cbiAgICAgIGlmICh0aW1lIDw9IDApIHtcbiAgICAgICAgcmV0dXJuIDA7XG4gICAgICB9XG4gICAgICBsZXQgdCA9IDAuNSwgY2J4LCBjYnhkLCBkeDtcbiAgICAgIGZvciAobGV0IGl0ID0gMDsgaXQgPCAyMDsgaXQrKykge1xuICAgICAgICBjYnggPSB0ICogKHQgKiAodCAqIHhhICsgeGIpICsgeGMpO1xuICAgICAgICBkeCA9IHRpbWUgLSBjYng7XG4gICAgICAgIGlmIChkeCA+IC0xZS04ICYmIGR4IDwgMWUtOCkge1xuICAgICAgICAgIHJldHVybiB0ICogKHQgKiAodCAqIHlhICsgeWIpICsgeWMpO1xuICAgICAgICB9XG4gICAgICAgIGNieGQgPSB0ICogKHQgKiAoMyAqIHhhKSArIDIgKiB4YikgKyB4YztcbiAgICAgICAgaWYgKGNieGQgPiAxZS0xMCAmJiBjYnhkIDwgMWUtMTApIHtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICB0ICs9IGR4IC8gY2J4ZDtcbiAgICAgIH1cbiAgICAgIGxldCBtaW5UID0gMDtcbiAgICAgIGxldCBtYXhUID0gMTtcbiAgICAgIGZvciAobGV0IGl0ID0gMDsgaXQgPCAyMDsgaXQrKykge1xuICAgICAgICB0ID0gMC41ICogKG1pblQgKyBtYXhUKTtcbiAgICAgICAgY2J4ID0gdCAqICh0ICogKHQgKiB4YSArIHhiKSArIHhjKTtcbiAgICAgICAgZHggPSB0aW1lIC0gY2J4O1xuICAgICAgICBpZiAoZHggPiAtMWUtOCAmJiBke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ybiB0aW1lID09PSAxID8gMSA6IDA7XG4gICAgICAgIH07XG4gICAgICBkZWZhdWx0OlxuICAgICAgICBsZXQgcyA9IFwiY3ViaWMtYmV6aWVyKFwiO1xuICAgICAgICBpZiAoc3RyICYmIHN0ci5pbmRleE9mKHMpID09PSAwKSB7XG4gICAgICAgICAgbGV0IHBhcnRzID0gc3RyLnN1YnN0cihzLmxlbmd0aCwgc3RyLmxlbmd0aCAtIHMubGVuZ3RoIC0gMSkuc3BsaXQoXCIsXCIpO1xuICAgICAgICAgIGlmIChwYXJ0cy5sZW5ndGggIT09IDQpIHtcbiAgICAgICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIFVua25vd24gdGltaW5nIGZ1bmN0aW9uOiBcIiArIHN0cik7XG4gICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24odGltZSkge1xuICAgICAgICAgICAgICByZXR1cm4gdGltZTtcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgfVxuICAgICAgICAgIGxldCBhID0gcGFyc2VGbG9hdChwYXJ0c1swXSk7XG4gICAgICAgICAgbGV0IGIgPSBwYXJzZUZsb2F0KHBhcnRzWzFdKTtcbiAgICAgICAgICBsZXQgYyA9IHBhcnNlRmxvYXQocGFydHNbMl0pO1xuICAgICAgICAgIGxldCBkID0gcGFyc2VGbG9hdChwYXJ0c1szXSk7XG4gICAgICAgICAgaWYgKGlzTmFOKGEpIHx8IGlzTmFOKGIpIHx8IGlzTmFOKGMpIHx8IGlzTmFOKGQpKSB7XG4gICAgICAgICAgICBjb25zb2xlLndhcm4oXCJbTGlnaHRuaW5nXSBVbmtub3duIHRpbWluZyBmdW5jdGlvbjogXCIgKyBzdHIpO1xuICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKHRpbWUpIHtcbiAgICAgICAgICAgICAgcmV0dXJuIHRpbWU7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4gU3RhZ2VVdGlscy5nZXRUaW1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aCk7XG4gIH1cbiAgc3RhdGljIGdldE1vZHVsb0luZGV4KGluZGV4LCBsZW4pIHtcbiAgICBpZiAobGVuID09PSAwKVxuICAgICAgcmV0dXJuIGluZGV4O1xuICAgIHdoaWxlIChpbmRleCA8IDApIHtcbiAgICAgIGluZGV4ICs9IE1hdGguY2VpbCgtaW5kZXggLyBsZW4pICogbGVuO1xuICAgIH1cbiAgICBpbmRleCA9IGluZGV4ICUgbGVuO1xuICAgIHJldHVybiBpbmRleDtcbiAgfVxuICBzdGF0aWMgZ2V0RGVlcENsb25lKG9iaikge1xuICAgIGxldCBpLCBjO1xuICAgIGlmIChVdGlscyQxLmlzRnVuY3Rpb24ob2JqKSkge1xuICAgICAgcmV0dXJuIG9iajtcbiAgICB9XG4gICAgaWYgKEFycmF5LmlzQXJyYXkob2JqKSkge1xuICAgICAgYyA9IFtdO1xuICAgICAgbGV0IGtleXMgPSBPYmplY3Qua2V5cyhvYmopO1xuICAgICAgZm9yIChpID0gMDsgaSA8IGtleXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgY1trZXlzW2ldXSA9IFV0aWxzJDEuZ2V0RGVlcENsb25lKG9ialtrZXlzW2ldXSk7XG4gICAgICB9XG4gICAgICByZXR1cm4gYztcbiAgICB9IGVsc2UgaWYgKFV0aWxzJDEuaXNPYmplY3Qob2JqKSkge1xuICAgICAgYyA9IHt9O1xuICAgICAgbGV0IGtleXMgPSBPYmplY3Qua2V5cyhvYmopO1xuICAgICAgZm9yIChpID0gMDsgaSA8IGtleXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgY1trZXlzW2ldXSA9IFV0aWxzJDEuZ2V0RGVlcENsb25lKG9ialtrZXlzW2ldXSk7XG4gICAgICB9XG4gICAgICByZXR1cm4gYztcbiAgICB9IGVsc2Uge1xuICAgICAgcmV0dXJuIG9iajtcbiAgICB9XG4gIH1cbiAgc3RhdGljIGVxdWFsVmFsdWVzKHYxLCB2Mikge1xuICAgIGlmICh0eXBlb2YgdjE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hyaW5rYWJsZUl0ZW0gPSBzaHJpbmtBbW91bnQgPiAwO1xuICAgICAgICAgIGlmIChpc1Nocmlua2FibGVJdGVtKSB7XG4gICAgICAgICAgICBsZXQgc2hyaW5rID0gc2hyaW5rQW1vdW50ICogYW1vdW50UGVyU2hyaW5rO1xuICAgICAgICAgICAgY29uc3QgbWluU2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc01pblNpemUoKTtcbiAgICAgICAgICAgIGNvbnN0IHNpemUgPSBmbGV4SXRlbS5fZ2V0TWFpbkF4aXNMYXlvdXRTaXplKCk7XG4gICAgICAgICAgICBpZiAoc2l6ZSA+IG1pblNpemUpIHtcbiAgICAgICAgICAgICAgY29uc3QgbWF4U2hyaW5rID0gc2l6ZSAtIG1pblNpemU7XG4gICAgICAgICAgICAgIGNvbnN0IGlzRnVsbHlTaHJ1bmsgPSBzaHJpbmsgPj0gbWF4U2hyaW5rO1xuICAgICAgICAgICAgICBpZiAoaXNGdWxseVNocnVuaykge1xuICAgICAgICAgICAgICAgIHNocmluayA9IG1heFNocmluaztcbiAgICAgICAgICAgICAgICB0b3RhbFNocmlua0Ftb3VudCAtPSBzaHJpbmtBbW91bnQ7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgY29uc3QgZmluYWxTaXplID0gc2l6ZSAtIHNocmluaztcbiAgICAgICAgICAgICAgZmxleEl0ZW0uX3Jlc2l6ZU1haW5BeGlzKGZpbmFsU2l6ZSk7XG4gICAgICAgICAgICAgIHRoaXMuX3NocnVua1NpemUgKz0gc2hyaW5rO1xuICAgICAgICAgICAgICB0aGlzLl9hbW91bnRSZW1haW5pbmcgLT0gc2hyaW5rO1xuICAgICAgICAgICAgICBpZiAoTWF0aC5hYnModGhpcy5fYW1vdW50UmVtYWluaW5nKSA8IDFlLTUpIHtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH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YXhHcm93ID0gbWF4U2l6ZSAtIHNpemU7XG4gICAgICAgICAgICAgICAgY29uc3QgaXNGdWxseUdyb3duID0gZ3JvdyA+PSBtYXhHcm93O1xuICAgICAgICAgICAgICAgIGlmIChpc0Z1bGx5R3Jvd24pIHtcbiAgICAgICAgICAgICAgICAgIGdyb3cgPSBtYXhHcm93O1xuICAgICAgICAgICAgICAgICAgdG90YWxHcm93QW1vdW50IC09IGdyb3dBbW91bnQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoZ3JvdyA+IDApIHtcbiAgICAgICAgICAgICAgY29uc3QgZmluYWxTaXplID0gc2l6ZSArIGdyb3c7XG4gICAgICAgICAgICAgIGZsZXhJdGVtLl9yZXNpemVNYWluQXhpcyhmaW5hbFNpemUpO1xuICAgICAgICAgICAgICB0aGlzLl9ncm93blNpemUgKz0gZ3JvdztcbiAgICAgICAgICAgICAgdGhpcy5fYW1vdW50UmVtYWluaW5nIC09IGdyb3c7XG4gICAgICAgICAgICAgIGlmIChNYXRoLmFicyh0aGlzLl9hbW91bnRSZW1haW5pbmcpIDwgMWUtNSkge1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfSB3aGlsZSAodG90YWxHcm93QW1vdW50ICYmIE1hdGguYWJzKHRoaXMuX2Ftb3VudFJlbWFpbmluZykgPiAxZS01KTtcbiAgICB9XG4gIH1cbiAgX2dldFRvdGFsR3Jvd0Ftb3VudCgpIHtcbiAgICBsZXQgdG90YWwgPSAwO1xuICAgIGNvbnN0IGl0ZW1zID0gdGhpcy5fbGluZS5pdGVtcztcbiAgICBmb3IgKGxldCBpID0gdGhpcy5fbGluZS5zdGFydEluZGV4OyBpIDw9IHRoaXMuX2xpbmUuZW5kSW5kZXg7IGkrKykge1xuICAgICAgY29uc3QgaXR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TtcbiAgICB0aGlzLl9wYXJlbnQuX3NjaXNzb3IgPSB0aGlzLl9wYXJlbnQuX3ZpZXdwb3J0O1xuICAgIHRoaXMuX3BhcmVudC5fcmVjQm91bmRzTWFyZ2luID0gbnVsbDtcbiAgICB0aGlzLl9zZXRSZWNhbGMoMSArIDIgKyA0KTtcbiAgfVxuICBpc0FuY2VzdG9yT2YoYykge1xuICAgIGxldCBwID0gYztcbiAgICB3aGlsZSAocCA9IHAuX3BhcmVudCkge1xuICAgICAgaWYgKHRoaXMgPT09IHApIHtcbiAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICB9XG4gICAgfVxuICAgIHJldHVybiBmYWxzZTtcbiAgfVxuICBpc1pDb250ZXh0KCkge1xuICAgIHJldHVybiB0aGlzLl9mb3JjZVpJbmRleENvbnRleHQgfHwgdGhpcy5fcmVuZGVyVG9UZXh0dXJlRW5hYmxlZCB8fCB0aGlzLl96SW5kZXggIT09IDAgfHwgdGhpcy5faXNSb290IHx8ICF0aGlzLl9wYXJlbnQ7XG4gIH1cbiAgZmluZFpDb250ZXh0KCkge1xuICAgIGlmICh0aGlzLmlzWkNvbnRleHQoKSkge1xuICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfSBlbHNlIHtcbiAgICAgIHJldHVybiB0aGlzLl9wYXJlbnQuZmluZFpDb250ZXh0KCk7XG4gICAgfVxuICB9XG4gIHNldFpQYXJlbnQobmV3WlBhcmVudCkge1xuICAgIGlmICh0aGlzLl96UGFyZW50ICE9PSBuZXdaUGFyZW50KSB7XG4gICAgICBpZiAodGhpcy5felBhcmVudCAhPT0gbnVsbCkge1xuICAgICAgICBpZiAodGhpcy5fekluZGV4ICE9PSAwKSB7XG4gICAgICAgICAgdGhpcy5felBhcmVudC5kZWNaQ29udGV4dFVzYWdlKCk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5felBhcmVudC5lbmFibGVaU29ydCgpO1xuICAgICAgfVxuICAgICAgaWYgKG5ld1pQYXJlbnQgIT09I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VsbDtcbiAgICAgICAgaWYgKG5ld1pQYXJlbnQgPT09IHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICBpZiAodGhpcy5felBhcmVudCkge1xuICAgICAgICAgICAgdGhpcy5felBhcmVudC5pbmNaQ29udGV4dFVzYWdlKCk7XG4gICAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9IGVsc2UgaWYgKHpJbmRleCAhPT0gdGhpcy5fekluZGV4KSB7XG4gICAgICAgIGlmICh0aGlzLl96UGFyZW50ICYmIHRoaXMuX3pQYXJlbnQuX3pDb250ZXh0VXNhZ2UpIHtcbiAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmIChuZXdaUGFyZW50ICE9PSB0aGlzLl96UGFyZW50KSB7XG4gICAgICAgIHRoaXMuc2V0WlBhcmVudChudWxsKTtcbiAgICAgIH1cbiAgICAgIHRoaXMuX3pJbmRleCA9IHpJbmRleDtcbiAgICAgIGlmIChuZXdaUGFyZW50ICE9PSB0aGlzLl96UGFyZW50KSB7XG4gICAgICAgIHRoaXMuc2V0WlBhcmVudChuZXdaUGFyZW50KTtcbiAgICAgIH1cbiAgICAgIGlmIChwcmV2SXNaQ29udGV4dCAhPT0gdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgaWYgKCF0aGlzLmlzWkNvbnRleHQoKSkge1xuICAgICAgICAgIHRoaXMuZGlzYWJsZVpDb250ZXh0KCk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhpcy5lbmFibGVaQ29udGV4dCh0aGlzLl9wYXJlbnQuZmluZFpDb250ZXh0KCkpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICB0aGlzLl96SW5kZXhSZXNvcnQgPSB0cnVlO1xuICAgICAgaWYgKHRoaXMuX3pQYXJlbnQpIHt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250ZXh0O1xuICAgICAgICBpZiAoaW5pdCB8fCByZWNhbGMgJiAxKSB7XG4gICAgICAgICAgcjIuYWxwaGEgPSBwci5hbHBoYSAqIHRoaXMuX2xvY2FsQWxwaGE7XG4gICAgICAgICAgaWYgKHIyLmFscGhhIDwgMWUtMTQpIHtcbiAgICAgICAgICAgIHIyLmFscGhhID0gMDtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGluaXQgfHwgcmVjYWxjICYgNikge1xuICAgICAgICAgIHIyLnB4ID0gcHIucHggKyB0aGlzLl9sb2NhbFB4ICogcHIudGE7XG4gICAgICAgICAgcjIucHkgPSBwci5weSArIHRoaXMuX2xvY2FsUHkgKiBwci50ZDtcbiAgICAgICAgICBpZiAocHIudGIgIT09IDApXG4gICAgICAgICAgICByMi5weCArPSB0aGlzLl9sb2NhbFB5ICogcHIudGI7XG4gICAgICAgICAgaWYgKHByLnRjICE9PSAwKVxuICAgICAgICAgICAgcjIucHkgKz0gdGhpcy5fbG9jYWxQeCAqIHByLnRjO1xuICAgICAgICB9XG4gICAgICAgIGlmIChpbml0KSB7XG4gICAgICAgICAgcmVjYWxjIHw9IDI7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGluaXQgfHwgcmVjYWxjICYgNCkge1xuICAgICAgICAgIHIyLnRhID0gdGhpcy5fbG9jYWxUYSAqIHByLnRhO1xuICAgICAgICAgIHIyLnRiID0gdGhpcy5fbG9jYWxUZCAqIHByLnRiO1xuICAgICAgICAgIHIyLnRjID0gdGhpcy5fbG9jYWxUYSAqIHByLnRjO1xuICAgICAgICAgIHIyLnRkID0gdGhpcy5fbG9jYWxUZCAqIHByLnRkO1xuICAgICAgICAgIGlmICh0aGlzLl9pc0NvbXBsZXgpIHtcbiAgICAgICAgICAgIHIyLnRhICs9IHRoaXMuX2xvY2FsVGMgKiBwci50YjtcbiAgICAgICAgICAgIHIyLnRiICs9IHRoaXMuX2xvY2FsVGIgKiBwci50YTtcbiAgICAgICA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DIwNDggOiB0aGlzLl93O1xuICAgICAgY29uc3QgYmJveEggPSB0aGlzLl9kaW1zVW5rbm93biA/IDIwNDggOiB0aGlzLl9oO1xuICAgICAgbGV0IHN4LCBzeSwgZXgsIGV5O1xuICAgICAgY29uc3QgckNvbXBsZXggPSByLnRiICE9PSAwIHx8IHIudGMgIT09IDAgfHwgci50YSA8IDAgfHwgci50ZCA8IDA7XG4gICAgICBpZiAockNvbXBsZXgpIHtcbiAgICAgICAgc3ggPSBNYXRoLm1pbigwLCBiYm94VyAqIHIudGEsIGJib3hXICogci50YSArIGJib3hIICogci50YiwgYmJveEggKiByLnRiKSArIHIucHg7XG4gICAgICAgIGV4ID0gTWF0aC5tYXgoMCwgYmJveFcgKiByLnRhLCBiYm94VyAqIHIudGEgKyBiYm94SCAqIHIudGIsIGJib3hIICogci50YikgKyByLnB4O1xuICAgICAgICBzeSA9IE1hdGgubWluKDAsIGJib3hXICogci50YywgYmJveFcgKiByLnRjICsgYmJveEggKiByLnRkLCBiYm94SCAqIHIudGQpICsgci5weTtcbiAgICAgICAgZXkgPSBNYXRoLm1heCgwLCBiYm94VyAqIHIudGMsIGJib3hXICogci50YyArIGJib3hIICogci50ZCwgYmJveEggKiByLnRkKSArIHIucHk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBzeCA9IHIucHg7XG4gICAgICAgIGV4ID0gci5weCArIHIudGEgKiBiYm94VztcbiAgICAgICAgc3kgPSByLnB5O1xuICAgICAgICBleSA9IHIucHkgKyByLnRkICogYmJveEg7XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5fZGltc1Vua25vd24gJiYgKHJDb21wbGV4IHx8IHRoaXMuX2xvY2FsVGEgPCAxIHx8IHRoaXMuX2xvY2FsVGIgPCAxKSkge1xuICAgICAgICBjb25zdCBueCA9IHRoaXMuX3ggKiBwci50YSArIHRoaXMuX3kgKiBwci50YiArIHByLnB4O1xuICAgICAgICBjb25zdCBueSA9IHRoaXMuX3ggKiBwci50YyArIHRoaXMuX3kgKiBwci50ZCArIHByLnB5O1xuICAgICAgICBpZiAobnggPCBzeClcbiAgICAgICAgICBzeCA9IG54O1xuICAgICAgICBpZiAobnkgPCBzeSlcbiAgICAgICAgICBzeSA9IG55O1xuICAgICAgICBpZiAobnggPiBleClcbiAgICAgICAgICBleCA9IG54O1xuICAgICAgICBpZiAobnkgPiBleSlcbiAgICAgICAgICBleSA9IG55O1xuICAgICAgfVxuICAgICAgaWYgKHJlY2FsYyAmIDYgfHwgIXRoaXMuX3NjaXNzb3IpIHtcbiAgICAgICAgaWYgKHRoaXMuX2NsaXBwaW5nICYmIHIuaXNTcXVhcmUoKSkge1xuICAgICAgICAgIGNvbnN0IGFyZWEgPSB0aGlzLl9wYXJlbnQuX3VzZVJlbmRlclRvVGV4dHVyZSA/IHRoaXMuX3BhcmVudC5fdmlld3BvcnQgOiB0aGlzLl9wYXJlbnQuX3NjaXNzb3I7XG4gICAgICAgICAgaWYgKGFyZWEpIHtcbiAgICAgICAgICAgIGNvbnN0IGx4ID0gTWF0aC5tYXgoYXJlYVswXSwgc3gpO1xuICAgICAgICAgICAgY29uc3QgbHkgPSBNYXRoLm1heChhcmVhWzFdLCBzeSk7XG4gICAgICAgICAgICB0aGlzLl9zY2lzc29yID0gW1xuICAgICAgICAgICAgICBseCxcbiAgICAgICAgICAgICAgbHksXG4gICAgICAgICAgICAgIE1hdGgubWluKGFyZWFbMl0gKyBhcmVhWzBdLCBleCkgLSBseCxcbiAgICAgICAgICAgICAgTWF0aC5taW4oYXJlYVszXSArIGFyZWFbMV0sIGV5KSAtIGx5XG4gICAgICAgICAgICBdO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9zY2lzc29yID0gW3N4LCBzeSwgZXggLSBzeCwgZXkgLSBzeV07XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuX3NjaXNzb3IgPSB0aGlzLl9wYXJlbnQuX3VzZVJlbmRlclRvVGV4dHVyZSA/IHRoaXMuX3BhcmVudC5fdmlld3BvcnQgOiB0aGlzLl9wYXJlbnQuX3NjaXNzb3I7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl9ib3VuZHNNYXJnaW4pIHtcbiAgICAgICAgdGhpcy5fcmVjQm91bmRzTWFyZ2luID0gdGhpcy5fYm91bmRzTWFyZ2luO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgdGhpcy5fcmVjQm91bmRzTWFyZ2luID0gdGhpcy5fcGFyZW50Ll9yZWNCb3VuZHNNYXJnaW47XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5fb25BZnRlckNhbGNzKSB7XG4gICAgICAgIGlmICh0aGlzLl9vbkFmdGVyQ2FsY3ModGhpcy5lbGVtZW50KSkge1xuICAgICAgICAgIGlmIChyQ29tcGxleCkge1xuICAgICAgICAgICAgc3ggPSBNYXRoLm1pbigwLCBiYm94VyAqIHIudGEsIGJib3hXICogci50YSArIGJib3hIICogci50YiwgYmJveEggKiByLnRiKSArIHIucHg7XG4gICAgICAgICAgICBleCA9IE1hdGgubWF4KDAsIGJib3hXICogci50YSwgYmJveFcgKiByLnRhICsgYmJveEggKiByLnRiLCBiYm94SCAqIHIudGIpICsgci5weDtcbiAgICAgICAgICAgIHN5ID0gTWF0aC5taW4oMCwgYmJveFcgKiByLnRjLCBiYm94VyAqIHIudGMgKyBiYm94SCAqIHIudGQsIGJib3hIICogci50ZCkgKyByLnB5O1xuICAgICAgICAgICAgZXkgPSBNYXRoLm1heCgwLCBiYm94VyAqIHIudGMsIGJib3hXICogci50YyArIGJib3hIICogci50ZCwgYmJveEggKiByLnRkKSArIHIucHk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHN4ID0gci5weDtcbiAgICAgICAgICAgIGV4ID0gci5weCArIHIudGEgKiBiYm94VztcbiAgICAgICAgICAgIHN5ID0gci5weTtcbiAgICAgICAgICAgIGV5ID0gci5weSArIHIudGQgKiBiYm94SDtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHRoaXMuX2RpbXNVbmtub3duICYmIChyQ29tcGxleCB8fCB0aGlzLl9sb2NhbFRhIDwgMSB8fCB0aGlzLl9sb2NhbFRiIDwgMSkpIHtcbiAgICAgICAgICAgIGNvbnN0IG54ID0gdGhpcy5feCAqIHByLnRhICsgdGhpcy5feSAqIHByLnRiICsgcHIucHg7XG4gICAgICAgICAgICBjb25zdCBueSA9IHRoaXMuX3ggKiBwci50YyArIHRoaXMuX3kgKiBwci50ZCArIHByLnB5O1xuICAgICAgICAgICAgaWYgKG54IDwgc3gpXG4gICAgICAgICAgICAgIHN4ID0gbng7XG4gICAgICAgICAgICBpZiAobnkgPCBzeSlcbiAgICAgICAgICAgICAgc3kgPSBueTtcbiAgICAgICAgICAgIGlmIChueCA+IGV4KVxuICAgICAgICAgICAgICBleCA9IG54O1xuICAgICAgICAgICAgaWYgKG55ID4gZXkpXG4gICAgICAgICAgICAgIGV5ID0gbnk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5fcGFyZW50Ll9vdXRPZkJvdW5kcyA9PT0gMikge1xuICAgICAgICB0aGlzLl9vdXRPZkJvdW5kcyA9IDI7XG4gICAgICAgIGlmICh0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4pIHtcbiAgICAgICAgICB0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4gPSBmYWxzZTtcbiAgICAgICAgICB0aGlzLmVsZW1lbnQuX2Rpc2FibGVXaXRoaW5Cb3VuZHNNYXJnaW4oKTtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKHJlY2FsYyAmIDYpIHtcbiAgICAgICAgICB0aGlzLl9vdXRPZkJvdW5kcyA9IDA7XG4gICAgICAgICAgbGV0IHdpdGhpbk1hcmdpbiA9IHRydWU7XG4gICAgICAgICAgaWYgKCF0aGlzLl9yZW5kZXJUb1RleHR1cmVFbmFibGVkIHx8ICF0aGlzLl90ZXh0dXJpemVyIHx8ICF0aGlzLl90ZXh0dXJpemVyLnJlbmRlck9mZnNjcmVlbikge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3NjaXNzb3IgJiYgKHRoaXMuX3NjaXNzb3JbMl0gPD0gMCB8fCB0aGlzLl9zY2lzc29yWzNdIDw9IDApKSB7XG4gICAgICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMjtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIGlmICh0aGlzLl9zY2lzc29yWzBdID4gZXggfHwgdGhpcy5fc2Npc3NvclsxXSA+IGV5IHx8IHN4ID4gdGhpcy5fc2Npc3NvclswXSArIHRoaXMuX3NjaXNzb3JbMl0gfHwgc3kgPiB0aGlzLl9zY2lzc29yWzFdICsgdGhpcy5fc2Npc3NvclszXSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBpZiAodGhpcy5fb3V0T2ZCb3VuZHMpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fY2xpcHBpbmcgfHwgdGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlIHx8IHRoaXMuX2NsaXBib3ggJiYgKGJib3hXICYmIGJib3hIKSkge1xuICAgICAgICAgICAgICAgICAgdGhpcy5fb3V0T2ZCb3VuZHMgPSAyO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgd2l0aGluTWFyZ2luID0gdGhpcy5fb3V0T2ZCb3VuZHMgPT09IDA7XG4gICAgICAgICAgICBpZiAoIXdpdGhpbk1hcmdpbikge1xuICAgICAgICAgICAgICBpZiAodGhpcy5fcmVjQm91bmRzTWFyZ2luKSB7XG4gICAgICAgICAgICAgICAgd2l0aGluTWFyZ2luID0gIShleCA8IHRoaXMuX3NjaXNzb3JbMF0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PSB0aGlzLl9yZWNhbGM7XG4gICAgICAgICAgICAgIHRoaXMuX3JlY2FsYyA9IDA7XG4gICAgICAgICAgICAgIHRoaXMuZWxlbWVudC5fZW5hYmxlV2l0aGluQm91bmRzTWFyZ2luKCk7XG4gICAgICAgICAgICAgIGlmICh0aGlzLl9yZWNhbGMpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy51cGRhdGUoKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB0aGlzLl9yZWNhbGMgPSByZWNhbGMyO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgdGhpcy5lbGVtZW50Ll9kaXNhYmxlV2l0aGluQm91bmRzTWFyZ2luKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlKSB7XG4gICAgICAgIGlmICh0aGlzLl92aWV3cG9ydCkge1xuICAgICAgICAgIHRoaXMuX3ZpZXdwb3J0WzJdID0gYmJveFc7XG4gICAgICAgICAgdGhpcy5fdmlld3BvcnRbM10gPSBiYm94SDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB0aGlzLl92aWV3cG9ydCA9IFswLCAwLCBiYm94VywgYmJveEhdO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICB0aGlzLl9wUmVjYWxjID0gdGhpcy5fcmVjYWxjICYgMTM1O1xuICAgICAgdGhpcy5fcmVjYWxjID0gMDtcbiAgICAgIHRoaXMuX2hhc1VwZGF0ZXMgPSBmYWxzZTtcbiAgICAgIGlmICh0aGlzLl9vdXRPZkJvdW5kcyA8IDIpIHtcbiAgICAgICAgaWYgKHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgIGlmICh0aGlzLl93b3JsZENvbnRleHQuaXNJZGVudGl0eSgpKSB7XG4gICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gdGhpcy5fd29ybGRDb250ZXh0O1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gRWxlbWVudENvcmVDb250ZXh0LklERU5USVRZO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0udXBkYXRlKCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gcjtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuKSB7XG4gICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9jaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbltpXS5faGFzVXBkYXRlcykge1xuICAgICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS51cGRhdGUoKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLl9yZWNhbGMgfD0gdGhpcy5fcFJlY2FsYztcbiAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0udXBkYXRlT3V0T2ZCb3VuZHMoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl9vbkFmdGVyVXBkYXRlKSB7XG4gICAgICAgIHRoaXMuX29uQWZ0ZXJVcGRhdGUodGhpcy5l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0gdGhpcy5fekluZGV4ZWRDaGlsZHJlbjtcbiAgICBjb25zdCBiID0gW107XG4gICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgIGlmIChhW2ldLl96UGFyZW50ID09PSB0aGlzKSB7XG4gICAgICAgIGlmIChhW2ldLl96SW5kZXhSZXNvcnQpIHtcbiAgICAgICAgICBiLnB1c2goYVtpXSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHB0ciAhPT0gaSkge1xuICAgICAgICAgICAgYVtwdHJdID0gYVtpXTtcbiAgICAgICAgICB9XG4gICAgICAgICAgcHRyKys7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgY29uc3QgbSA9IGIubGVuZ3RoO1xuICAgIGlmIChtKSB7XG4gICAgICBmb3IgKGxldCBqID0gMDsgaiA8IG07IGorKykge1xuICAgICAgICBiW2pdLl96SW5kZXhSZXNvcnQgPSBmYWxzZTtcbiAgICAgIH1cbiAgICAgIGIuc29ydChFbGVtZW50Q29yZS5zb3J0WkluZGV4ZWRDaGlsZHJlbik7XG4gICAgICBjb25zdCBuMiA9IHB0cjtcbiAgICAgIGlmICghbjIpIHtcbiAgICAgICAgcHRyID0gMDtcbiAgICAgICAgbGV0IGogPSAwO1xuICAgICAgICBkbyB7XG4gICAgICAgICAgYVtwdHIrK10gPSBiW2orK107XG4gICAgICAgIH0gd2hpbGUgKGogPCBtKTtcbiAgICAgICAgaWYgKGEubGVuZ3RoID4gcHRyKSB7XG4gICAgICAgICAgYS5zcGxpY2UocHRyKTtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcHRyID0gMDtcbiAgICAgICAgbGV0IGkgPSAwO1xuICAgICAgICBsZXQgaiA9IDA7XG4gICAgICAgIGNvbnN0IG1lcmdlUmVzdWx0ID0gW107XG4gICAgICAgIGRvIHtcbiAgICAgICAgICBjb25zdCB2ID0gYVtpXS5fekluZGV4ID09PSBiW2pdLl96SW5kZXggPyBhW2ldLl91cGRhdGVUcmVlT3JkZXIgLSBiW2pdLl91cGRhdGVUcmVlT3JkZXIgOiBhW2ldLl96SW5kZXggLSBiW2pdLl96SW5kZXg7XG4gICAgICAgICAgY29uc3QgYWRkID0gdiA+IDAgPyBiW2orK10gOiBhW2krK107XG4gICAgICAgICAgaWYgKHB0ciA9PT0gMCB8fCBtZXJnZVJlc3VsdFtwdHIgLSAxXSAhPT0gYWRkKSB7XG4gICAgICAgICAgICBtZXJnZVJlc3VsdFtwdHIrK10gPSBhZGQ7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChpID49IG4yKSB7XG4gICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgIGNvbnN0IGFkZDIgPSBiW2orK107XG4gICAgICAgICAgICAgIGlmIChwdHIgPT09IDAgfHwgbWVyZ2VSZXN1bHRbcHRyIC0gMV0gIT09IGFkZDIpIHtcbiAgICAgICAgICAgICAgICBtZXJnZVJlc3VsdFtwdHIrK10gPSBhZGQyO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IHdoaWxlIChqIDwgbSk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9IGVsc2UgaWYgKGogPj0gbSkge1xuICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICBjb25zdCBhZGQyID0gYVtpKytdO1xuICAgICAgICAgICAgICBpZiAocHRyID09PSAwIHx8IG1lcmdlUmVzdWx0W3B0ciAtIDFdICE9PSBhZGQyKSB7XG4gICAgICAgICAgICAgICAgbWVyZ2VSZXN1bHRbcHRyKytdID0gYWRkMjtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSB3aGlsZSAoaSA8IG4yKTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIH1cbiAgICAgICAgfSB3aGlsZSAodHJ1ZSk7XG4gICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4gPSBtZXJnZVJlc3VsdDtcbiAgICAgIH1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hpcy5fdyAqIHcudGMgKyB0aGlzLl9oICogdy50ZCxcbiAgICAgIHcucHggKyB0aGlzLl9oICogdy50YixcbiAgICAgIHcucHkgKyB0aGlzLl9oICogdy50ZFxuICAgIF07XG4gIH1cbiAgZ2V0UmVuZGVyVGV4dHVyZUNvb3JkcyhyZWxYLCByZWxZKSB7XG4gICAgbGV0IHIgPSB0aGlzLl9yZW5kZXJDb250ZXh0O1xuICAgIHJldHVybiBbXG4gICAgICByLnB4ICsgci50YSAqIHJlbFggKyByLnRiICogcmVsWSxcbiAgICAgIHIucHkgKyByLnRjICogcmVsWCArIHIudGQgKiByZWxZXG4gICAgXTtcbiAgfVxuICBnZXRBYnNvbHV0ZUNvb3JkcyhyZWxYLCByZWxZKSB7XG4gICAgbGV0IHcgPSB0aGlzLl9yZW5kZXJDb250ZXh0O1xuICAgIHJldHVybiBbXG4gICAgICB3LnB4ICsgdy50YSAqIHJlbFggKyB3LnRiICogcmVsWSxcbiAgICAgIHcucHkgKyB3LnRjICogcmVsWCArIHcudGQgKiByZWxZXG4gICAgXTtcbiAgfVxuICBjb2xsZWN0QXRDb29yZCh4LCB5LCBjaGlsZHJlbikge1xuICAgIGlmICh0aGlzLl9yZW5kZXJDb250ZXh0LmFscGhhID09PSAwKSB7XG4gICAgICByZXR1cm47XG4gICAgfVxuICAgIGlmICh0aGlzLmluQm91bmQoeCwgeSkpIHtcbiAgICAgIGlmICh0aGlzLl9zY2lzc29yKSB7XG4gICAgICAgIGlmICh0aGlzLmluU2Npc3NvcigpKSB7XG4gICAgICAgICAgY2hpbGRyZW4ucHVzaCh0aGlzKTtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgY2hpbGRyZW4ucHVzaCh0aGlzKTtcbiAgICAgIH1cbiAgICB9XG4gICAgaWYgKHRoaXMuX2NoaWxkcmVuKSB7XG4gICAgICBjb25zdCBqID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoO1xuICAgICAgZm9yIChsZXQgaS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hbWVdO1xuICAgICAgICAgIGZvciAoY29uc3QgbCBvZiBsaXN0ZW5lcnMpIHtcbiAgICAgICAgICAgIGlmIChsID09PSBsaXN0ZW5lciB8fCBsLl9fb3JpZ2luYWxGdW5jID09IGxpc3RlbmVyKSB7XG4gICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdID09PSBsaXN0ZW5lciB8fCB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdLl9fb3JpZ2luYWxGdW5jID09PSBsaXN0ZW5lcikge1xuICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIHJldHVybiBmYWxzZTtcbiAgfVxuICBvZmYobmFtZSwgbGlzdGVuZXIpIHtcbiAgICBpZiAodGhpcy5faGFzRXZlbnRMaXN0ZW5lcnMpIHtcbiAgICAgIGNvbnN0IGN1cnJlbnQgPSB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdO1xuICAgICAgaWYgKGN1cnJlbnQpIHtcbiAgICAgICAgaWYgKGN1cnJlbnQgPT09IEV2ZW50RW1pdHRlci5jb21iaW5lcikge1xuICAgICAgICAgIGNvbnN0IGxpc3RlbmVycyA9IHRoaXMuX2V2ZW50TGlzdGVuZXJzW25hbWVdO1xuICAgICAgICAgIGxldCBpbmRleCA9IGxpc3RlbmVycy5pbmRleE9mKGxpc3RlbmVyKTtcbiAgICAgICAgICBpZiAoaW5kZXggPj0gMCkge1xuICAgICAgICAgICAgbGlzdGVuZXJzLnNwbGljZShpbmRleCwgMSk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGluZGV4ID0gbGlzdGVuZXJzLm1hcCgobCkgPT4gbC5fX29yaWdpbmFsRnVuYykuaW5kZXhPZihsaXN0ZW5lcik7XG4gICAgICAgICAgaWYgKGluZGV4ID49IDApIHtcbiAg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NvdXJjZTtcbiAgICBpZiAodGhpcy5lbGVtZW50cy5zaXplKSB7XG4gICAgICBpZiAob2xkU291cmNlKSB7XG4gICAgICAgIGlmICh0aGlzLl9hY3RpdmVDb3VudCkge1xuICAgICAgICAgIG9sZFNvdXJjZS5kZWNBY3RpdmVUZXh0dXJlQ291bnQoKTtcbiAgICAgICAgfVxuICAgICAgICBvbGRTb3VyY2UucmVtb3ZlVGV4dHVyZSh0aGlzKTtcbiAgICAgICAgaWYgKHRoaXNbXCJ0ZXh0XCJdICYmICFvbGRTb3VyY2UuaXNVc2VkKCkpIHtcbiAgICAgICAgICB0aGlzLm1hbmFnZXIuZnJlZVRleHR1cmVTb3VyY2Uob2xkU291cmNlKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgaWYgKG5ld1NvdXJjZSkge1xuICAgICAgICBuZXdTb3VyY2UuYWRkVGV4dHVyZSh0aGlzKTtcbiAgICAgICAgaWYgKHRoaXMuX2FjdGl2ZUNvdW50KSB7XG4gICAgICAgICAgbmV3U291cmNlLmluY0FjdGl2ZVRleHR1cmVDb3VudCgpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIGlmICh0aGlzLmlzVXNlZCgpKSB7XG4gICAgICBpZiAobmV3U291cmNlKSB7XG4gICAgICAgIGlmIChuZXdTb3VyY2UuaXNMb2FkZWQoKSkge1xuICAgICAgICAgIGlmICh0aGlzLl9yZXNpemVNb2RlKSB7XG4gICAgICAgICAgICB0aGlzLl9hcHBseVJlc2l6ZU1vZGUoKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgdGhpcy5lbGVtZW50cy5mb3JFYWNoKChlbGVtZW50KSA9PiB7XG4gICAgICAgICAgICBpZiAoZWxlbWVudC5hY3RpdmUpIHtcbiAgICAgICAgICAgICAgZWxlbWVudC5fc2V0RGlzcGxheWVkVGV4dHVyZSh0aGlzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbi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udGV4dCkpIHtcbiAgICAgICAgICByZXR1cm4gZG9jdW1lbnQuZm9udHMubG9hZChmb250U2V0dGluZywgdGhpcy5fc2V0dGluZ3MudGV4dCkuY2F0Y2goKGVycikgPT4ge1xuICAgICAgICAgICAgY29uc29sZS53YXJuKFwiW0xpZ2h0bmluZ10gRm9udCBsb2FkIGVycm9yXCIsIGVyciwgZm9udFNldHRpbmcpO1xuICAgICAgICAgIH0pLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5mb250cy5jaGVjayhmb250U2V0dGluZywgdGhpcy5fc2V0dGluZ3MudGV4dCkpIHtcbiAgICAgICAgICAgICAgY29uc29sZS53YXJuKFwiW0xpZ2h0bmluZ10gRm9udCBub3QgZm91bmRcIiwgZm9udFNldHRpbmcpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIENhbid0IGNoZWNrIGZvbnQgbG9hZGluZyBmb3IgXCIgKyBmb250U2V0dGluZyk7XG4gICAgICB9XG4gICAgfVxuICB9XG4gIGRyYXcoKSB7XG4gICAgY29uc3QgbG9hZFByb21pc2UgPSB0aGlzLl9sb2FkKCk7XG4gICAgaWYgKCFsb2FkUHJvbWlzZSkge1xuICAgICAgcmV0dXJuIFV0aWxzJDEuaXNTcGFyayA/IHRoaXMuX3N0YWdlLnBsYXRmb3JtLmRyYXdUZXh0KHRoaXMpIDogdGhpcy5fZHJhdygpO1xuICAgIH0gZWxzZSB7XG4gICAgICByZXR1cm4gbG9hZFByb21pc2UudGhlbigoKSA9PiB7XG4gICAgICAgIHJldHVybiBVdGlscyQxLmlzU3BhcmsgPyB0aGlzLl9zdGFnZS5wbGF0Zm9ybS5kcmF3VGV4dCh0aGlzKSA6IHRoaXMuX2RyYXcoKTtcbiAgICAgIH0pO1xuICAgIH1cbiAgfVxuICBfY2FsY3V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ubGluZXNbaV0gPSB7XG4gICAgICAgIHdpZHRoOiAwLFxuICAgICAgICB4OiAwLFxuICAgICAgICB5OiByZW5kZXJJbmZvLmxpbmVIZWlnaHQgKiBpICsgdmFPZmZzZXQsXG4gICAgICAgIHRleHQ6IFtdXG4gICAgICB9O1xuICAgIH1cbiAgICBmb3IgKGxldCB0IG9mIHRleHQpIHtcbiAgICAgIHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnRleHQucHVzaCh0KTtcbiAgICB9XG4gICAgZm9yIChjb25zdCBsIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgIGlmIChsLnRleHQubGVuZ3RoID09IDApIHtcbiAgICAgICAgY29udGludWU7XG4gICAgICB9XG4gICAgICBjb25zdCBmaXJzdFdvcmQgPSBsLnRleHRbMF0udGV4dDtcbiAgICAgIGNvbnN0IGxhc3RXb3JkID0gbC50ZXh0W2wudGV4dC5sZW5ndGggLSAxXS50ZXh0O1xuICAgICAgaWYgKGZpcnN0V29yZCA9PSBcIlxcblwiKSB7XG4gICAgICAgIGwudGV4dC5zaGlmdCgpO1xuICAgICAgfVxuICAgICAgaWYgKGlzU3BhY2UobGFzdFdvcmQpIHx8IGxhc3RXb3JkID09IFwiXFxuXCIpIHtcbiAgICAgICAgbC50ZXh0LnBvcCgpO1xuICAgICAgfVxuICAgIH1cbiAgICBmb3IgKGxldCBsIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgIGwud2lkdGggPSBsLnRleHQucmVkdWNlKChhY2MsIHQpID0+IGFjYyArIHQud2lkdGgsIDApO1xuICAgIH1cbiAgICByZW5kZXJJbmZvLndpZHRoID0gdGhpcy5fc2V0dGluZ3MudyAhPSAwID8gdGhpcy5fc2V0dGluZ3MudyAqIHByZWNpc2lvbiA6IE1hdGgubWF4KC4uLnJlbmRlckluZm8ubGluZXMubWFwKChsKSA9PiBsLndpZHRoKSkgKyBwYWRkaW5nUmlnaHQ7XG4gICAgcmVuZGVySW5mby53ID0g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bGFzdExpbmVUZXh0LnJlZHVjZSgoYWNjLCB0KSA9PiBhY2MgKyB0LndpZHRoLCAwKTtcbiAgICAgICAgaWYgKGxhc3RMaW5lVGV4dC5sZW5ndGggPCBzcGwpIHtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgdGhpcy5hbGlnbkxpbmUobGFzdExpbmVUZXh0LCBsYXN0TGluZVRleHRbMF0ueCk7XG4gICAgICByZW5kZXJJbmZvLmxpbmVzW2luZGV4XS50ZXh0ID0gbGFzdExpbmVUZXh0O1xuICAgICAgcmVuZGVySW5mby5saW5lc1tpbmRleF0ud2lkdGggPSBfdztcbiAgICB9XG4gICAgaWYgKHJlbmRlckluZm8udGV4dEFsaWduID09IFwiY2VudGVyXCIpIHtcbiAgICAgIGZvciAobGV0IGwgb2YgcmVuZGVySW5mby5saW5lcykge1xuICAgICAgICBsLnggPSAocmVuZGVySW5mby53aWR0aCAtIGwud2lkdGggLSBwYWRkaW5nTGVmdCkgLyAyO1xuICAgICAgfVxuICAgIH0gZWxzZSBpZiAocmVuZGVySW5mby50ZXh0QWxpZ24gPT0gXCJyaWdodFwiKSB7XG4gICAgICBmb3IgKGxldCBsIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgICAgbC54ID0gcmVuZGVySW5mby53aWR0aCAtIGwud2lkdGggLSBwYWRkaW5nTGVmdDtcbiAgICAgIH1cbiAgICB9XG4gICAgcmV0dXJuIHJlbmRlckluZm87XG4gIH1cbiAgX2RyYXcoKSB7XG4gICAgY29uc3QgcmVuZGVySW5mbyA9IHRoaXMuX2NhbGN1bGF0ZVJlbmRlckluZm8oKTtcbiAgICBjb25zdCBwcmVjaXNpb24gPSB0aGlzLmdldFByZWNpc2lvbigpO1xuICAgIGNvbnN0IHBhZGRpbmdMZWZ0ID0gcmVuZGVySW5mby5wYWRkaW5nTGVmdCAqIHByZWNpc2lvbjtcbiAgICBsZXQgY2FudmFzV2lkdGggPSByZW5kZXJJ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GxldCBjdXJyZW50Q29sb3IgPSBkZWZhdWx0Q29sb3I7XG4gICAgdGhpcy5fY29udGV4dC5maWxsU3R5bGUgPSBkZWZhdWx0Q29sb3I7XG4gICAgZm9yIChjb25zdCBsaW5lIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgIGZvciAoY29uc3QgdCBvZiBsaW5lLnRleHQpIHtcbiAgICAgICAgbGV0IGx4ID0gMDtcbiAgICAgICAgaWYgKHQudGV4dCA9PSBcIlxcblwiKSB7XG4gICAgICAgICAgY29udGludWU7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHJlbmRlckluZm8ubWF4TGluZXMgJiYgdC5saW5lTm8gPj0gcmVuZGVySW5mby5tYXhMaW5lcykge1xuICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0LmNvbG9yICE9IGN1cnJlbnRDb2xvcikge1xuICAgICAgICAgIGN1cnJlbnRDb2xvciA9IHQuY29sb3I7XG4gICAgICAgICAgdGhpcy5fY29udGV4dC5maWxsU3R5bGUgPSBjdXJyZW50Q29sb3I7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fY29udGV4dC5mb250ID0gdC5mb250U3R5bGU7XG4gICAgICAgIGlmICh0LmxldHRlcnMpIHtcbiAgICAgICAgICBmb3IgKGxldCBsIG9mIHQubGV0dGVycykge1xuICAgICAgICAgICAgY29uc3QgX3ggPSByZW5kZXJJbmZvLmxpbmVzW3QubGluZU5vXS54ICsgdC54ICsgbHg7XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LmZpbGxUZXh0KGwudGV4dCwgX3gsIHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnkgKyByZW5kZXJJbmZvLmZvbnRTaXplKTtcbiAgICAgICAgICAgIGx4ICs9IGwud2lkdGg7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGNvbnN0IF94ID0gcmVuZGVySW5mby5saW5lc1t0LmxpbmV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HQodGhpcy5fY29udGV4dCwgd29yZCwgc3BhY2UpO1xuICB9XG4gIHRva2VuaXplKHRleHQpIHtcbiAgICByZXR1cm4gdG9rZW5pemVTdHJpbmcoLyB8XFx1MjAwQnxcXG58PGk+fDxcXC9pPnw8Yj58PFxcL2I+fDxjb2xvcj0wW3hYXVswLTlhLWZBLUZdezh9Pnw8XFwvY29sb3I+L2csIHRleHQpO1xuICB9XG4gIHBhcnNlKHRva2Vucykge1xuICAgIGxldCBpdGFsaWMgPSAwO1xuICAgIGxldCBib2xkID0gMDtcbiAgICBsZXQgY29sb3JTdGFjayA9IFtTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcodGhpcy5fc2V0dGluZ3MudGV4dENvbG9yKV07XG4gICAgbGV0IGNvbG9yID0gMDtcbiAgICBjb25zdCBjb2xvclJlZ2V4cCA9IC88Y29sb3I9KDBbeFhdWzAtOWEtZkEtRl17OH0pPi87XG4gICAgcmV0dXJuIHRva2Vucy5tYXAoKHQpID0+IHtcbiAgICAgIGlmICh0ID09IFwiPGk+XCIpIHtcbiAgICAgICAgaXRhbGljICs9IDE7XG4gICAgICAgIHQgPSBcIlwiO1xuICAgICAgfSBlbHNlIGlmICh0ID09IFwiPC9pPlwiICYmIGl0YWxpYyA+IDApIHtcbiAgICAgICAgaXRhbGljIC09IDE7XG4gICAgICAgIHQgPSBcIlwiO1xuICAgICAgfSBlbHNlIGlmICh0ID09IFwiPGI+XCIpIHtcbiAgICAgICAgYm9sZCArPSAxO1xuICAgICAgICB0ID0gXCJcIjtcbiAgICAgIH0gZWxzZSBpZiAodCA9PSBcIjwvYj5cIiAmJiBib2xkID4gMCkge1xuICAgICAgICBib2xkIC09IDE7XG4gICAgICAgIHQgPSBcIlwiO1xuICAgICAgfSBlbHNlIGlmICh0ID09IFwiPC9jb2xvcj5cIikge1xuICAgICAgICBpZiAoY29sb3JTdGFjay5sZW5ndGggPiAxKSB7XG4gICAgICAgICAgY29sb3IgLT0gMTtcbiAgICAgICAgICB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ZXJzID0gW107XG4gICAgICBsZXQgYnJlYWtJbmRleCA9IDA7XG4gICAgICBmb3IgKGNvbnN0IGwgb2Ygd29yZC5sZXR0ZXJzKSB7XG4gICAgICAgIGlmICh0b3RhbFdpZHRoICsgbC53aWR0aCA+PSB3aWR0aCkge1xuICAgICAgICAgIHBhcnRzLnB1c2goeyAuLi53b3JkIH0pO1xuICAgICAgICAgIHBhcnRzW3BhcnRzLmxlbmd0aCAtIDFdLnRleHQgPSB0ZXh0LnNsaWNlKDAsIGJyZWFrSW5kZXgpO1xuICAgICAgICAgIHBhcnRzW3BhcnRzLmxlbmd0aCAtIDFdLndpZHRoID0gdG90YWxXaWR0aDtcbiAgICAgICAgICBwYXJ0c1twYXJ0cy5sZW5ndGggLSAxXS5sZXR0ZXJzID0gbGV0dGVycztcbiAgICAgICAgICB0ZXh0ID0gdGV4dC5zbGljZShicmVha0luZGV4KTtcbiAgICAgICAgICB0b3RhbFdpZHRoID0gMDtcbiAgICAgICAgICBsZXR0ZXJzID0gW107XG4gICAgICAgICAgYnJlYWtJbmRleCA9IDA7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgYnJlYWtJbmRleCArPSAxO1xuICAgICAgICAgIGxldHRlcnMucHVzaChsKTtcbiAgICAgICAgICB0b3RhbFdpZHRoICs9IGwud2lkdGg7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmICh0b3RhbFdpZHRoID4gMCkge1xuICAgICAgICBwYXJ0cy5wdXNoKHsgLi4ud29yZCB9KTtcbiAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0udGV4dCA9IHRleHQuc2xpY2UoMCwgYnJlYWtJbmRleCk7XG4gICAgICAgIHBhcnRzW3BhcnRzLmxlbmd0aCAtIDFdLndpZHRoID0gdG90YWxXaWR0aDtcbiAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ubGV0dGVycyA9IGxldHRlcnM7XG4gICAgICB9XG4gICAgfVxuICAgIHJldHV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l0ZW0pO1xuICAgICAgaWYgKGN1cnJlbnRJbmRleCAhPSAtMSkge1xuICAgICAgICBpZiAoY3VycmVudEluZGV4ICE9PSBpbmRleCkge1xuICAgICAgICAgIGNvbnN0IGZyb21JbmRleCA9IGN1cnJlbnRJbmRleDtcbiAgICAgICAgICBpZiAoZnJvbUluZGV4ICE9PSBpbmRleCkge1xuICAgICAgICAgICAgdGhpcy5faXRlbXMuc3BsaWNlKGZyb21JbmRleCwgMSk7XG4gICAgICAgICAgICB0aGlzLl9pdGVtcy5zcGxpY2UoaW5kZXgsIDAsIGl0ZW0pO1xuICAgICAgICAgICAgdGhpcy5vbk1vdmUoaXRlbSwgZnJvbUluZGV4LCBpbmRleCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBpZiAoaW5kZXggPCB0aGlzLl9pdGVtcy5sZW5ndGgpIHtcbiAgICAgICAgICBpZiAodGhpcy5faXRlbXNbaW5kZXhdLnJlZikge1xuICAgICAgICAgICAgdGhpcy5fcmVmc1t0aGlzLl9pdGVtc1tpbmRleF0ucmVmXSA9IHZvaWQgMDtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgY29uc3QgcHJldkl0ZW0gPSB0aGlzLl9pdGVtc1tpbmRleF07XG4gICAgICAgIHRoaXMuX2l0ZW1zW2luZGV4XSA9IGl0ZW07XG4gICAgICAgIGlmIChpdGVtLnJlZikge1xuICAgICAgICAgIHRoaXMuX3JlZnNbaXRlbS5yZWZdID0gaXRlbTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLm9uU2V0KGl0ZW0sIGluZGV4LCBwcmV2SXRlbSk7XG4gICAgICB9XG4gICAgfSBlbHNlIHtcbiAgICAgIHRocm93IG5ldyBFcnJvcihcInNldEF0OiBUaGUgaW5kZXggXCIgKyBpbmRleCArIFwiIGlzIG91dCBvZiBib3VuZHMgXCIgKyB0aGlzLl9pdGVtcy5sZW5ndGgpO1xuICAgIH1cbi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NvdXJjZS5nZXRSZW5kZXJXaWR0aCgpO1xuICAgICAgICBsZXQgaCA9IGRpc3BsYXllZFRleHR1cmVTb3VyY2UuZ2V0UmVuZGVySGVpZ2h0KCk7XG4gICAgICAgIGxldCBpdywgaWgsIHJ3LCByaDtcbiAgICAgICAgaXcgPSAxIC8gdztcbiAgICAgICAgaWggPSAxIC8gaDtcbiAgICAgICAgaWYgKGRpc3BsYXllZFRleHR1cmUucHcpIHtcbiAgICAgICAgICBydyA9IGRpc3BsYXllZFRleHR1cmUucHcgKiBpdztcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBydyA9ICh3IC0gZGlzcGxheWVkVGV4dHVyZS5weCkgKiBpdztcbiAgICAgICAgfVxuICAgICAgICBpZiAoZGlzcGxheWVkVGV4dHVyZS5waCkge1xuICAgICAgICAgIHJoID0gZGlzcGxheWVkVGV4dHVyZS5waCAqIGloO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHJoID0gKGggLSBkaXNwbGF5ZWRUZXh0dXJlLnB5KSAqIGloO1xuICAgICAgICB9XG4gICAgICAgIGl3ICo9IGRpc3BsYXllZFRleHR1cmUucHg7XG4gICAgICAgIGloICo9IGRpc3BsYXllZFRleHR1cmUucHk7XG4gICAgICAgIHR4MSA9IGl3O1xuICAgICAgICB0eTEgPSBpaDtcbiAgICAgICAgdHgyID0gdHgyICogcncgKyBpdztcbiAgICAgICAgdHkyID0gdHkyICogcmggKyBpaDtcbiAgICAgICAgdHgxID0gTWF0aC5tYXgoMCwgdHgxKTtcbiAgICAgICAgdHkxID0gTWF0aC5tYXgoMCwgdHkxKTtcbiAgICAgICAgdHgyID0gTWF0aC5taW4oMSwgdHgyKTtcbiAgICAgICAgdHkyID0gTWF0aC5taW4oMSwgdHkyKTtcbiAgICAgIH1cbiAgICAgIGlmIChkaXNwbGF5ZWRUZXh0dXJlU291cmNlLl9mbGlwVGV4dHVyZVkpIHtcbiAgICAgICAgbGV0IHRlbXB0eSA9IHR5MjtcbiAgICAgICAgdHkyID0gdHkxO1xuICAgICAgICB0eTEgPSB0ZW1wdHk7XG4gICAgICB9XG4gICAgICB0aGlzLl9fY29yZS5zZXRUZXh0dXJlQ29vcmRzKHR4MSwgdHkxLCB0eDIsIHR5Mik7XG4gICAgfVxuICB9XG4gIGdldENvcm5lclBvaW50cygpIHtcbiAgICByZXR1cm4gdGhpcy5fX2NvcmUuZ2V0Q29ybmVyUG9pbnRzKCk7XG4gIH1cbiAgX3Vuc2V0VGFnc1BhcmVudCgpIHtcbiAgICBpZiAodGhpcy5fX3RhZ3MpIHtcbiAgICAgIHRoaXMuX190YWdzLmZvckVhY2goKHRhZykgPT4ge1xuICAgICAgICBsZXQgcCA9IHRoaXM7XG4gICAgICAgIHdoaWxlIChwID0gcC5fX3BhcmVudCkge1xuICAgICAgICAgIGxldCBwYXJlbnRUcmVlVGFncyA9IHAuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgICAgICBwYXJlbnRUcmVlVGFncy5kZWxldGUodGhpcyk7XG4gICAgICAgICAgaWYgKHAuX190YWdSb290KSB7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH0pO1xuICAgIH1cbiAgICBsZXQgdGFncyA9IG51bGw7XG4gICAgbGV0IG4gPSAwO1xuICAgIGlmICh0aGlzLl9fdHJlZVRhZ3MpIHtcbiAgICAgIGlmICghdGhpcy5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgdGFncyA9IFV0aWxzJDEuaXRlcmF0b3JUb0FycmF5KHRoaXMuX190cmVlVGFncy5rZXlzKCkpO1xuICAgICAgICBuID0gdGFncy5sZW5ndGg7XG4gICAgICAgIGlmIChuID4gMCkge1xuICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBsZXQgdGFnU2V0ID0gdGhpcy5fX3RyZWVUYWdzLmdldCh0YWdzW2ldKTtcbiAgICAgICAgICAgIGxldCBwID0gdGhpcztcbiAgICAgICAgICAgIHdoaWxlIChwID0gcC5fX3BhcmVudCkge1xuICAgICAgICAgICAgICBsZXQgcGFyZW50VHJlZVRhZ3MgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZ3NbaV0pO1xuICAgICAgICAgICAgICB0YWdTZXQuZm9yRWFjaChmdW5jdGlvbihjb21wKSB7XG4gICAgICAgICAgICAgICAgcGFyZW50VHJlZVRhZ3MuZGVsZXRlKGNvbXApO1xuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgaWYgKHAuX190YWdSb290KSB7XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gIH1cbiAgX3NldFRhZ3NQYXJlbnQoKSB7XG4gICAgaWYgKHRoaXMuX190YWdzKSB7XG4gICAgICB0aGlzLl9fdGFncy5mb3JFYWNoKCh0YWcpID0+IHtcbiAgICAgICAgbGV0IHAgPSB0aGlzO1xuICAgICAgICB3aGlsZSAocCA9IHAuX19wYXJlbnQpIHtcbiAgICAgICAgICBpZiAoIXAuX190cmVlVGFncykge1xuICAgICAgICAgICAgcC5fX3RyZWVUYWdzID0gLyogQF9fUFVSRV9fICovIG5ldyBNYXAoKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgbGV0IHMgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgaWYgKCFzKSB7XG4gICAgICAgICAgICBzID0gLyogQF9fUFVSRV9fICovIG5ldyBTZXQoKTtcbiAgICAgICAgICAgIHAuX190cmVlVGFncy5zZXQodGFnLCBzKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgcy5hZGQodGhpcyk7XG4gICAgICAgICAgaWYgKHAuX190YWdSb290KSB7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH0pO1xuICAgIH1cbiAgICBpZiAodGhpcy5fX3RyZWVUYWdzICYmIHRoaXMuX190cmVlVGFncy5zaXplKSB7XG4gICAgICBpZiAoIXRoaXMuX190YWdSb290KSB7XG4gICAgICAgIHRoaXMuX190cmVlVGFncy5mb3JFYWNoKCh0YWdTZXQsIHRhZykgPT4ge1xuICAgICAgICAgIGxldCBwID0gdGhpcztcbiAgICAgICAgICB3aGlsZSAoIXAuX190YWdSb290ICYmIChwID0gcC5fX3BhcmVudCkpIHtcbiAgICAgICAgICAgIGlmIChwLl9fdGFnUm9vdClcbiAgICAgICAgICAgICAgO1xuICAgICAgICAgICAgaWYgKCFwLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICAgICAgcC5fX3RyZWVUYWdzID0gLyogQF9fUFVSRV9fICovIG5ldyBNYXAoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGxldCBzID0gcC5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgICAgICAgaWYgKCFzKSB7XG4gICAgICAgICAgICAgIHMgPSAvKiBAX19QVVJFX18gKi8gbmV3IFNldCgpO1xuICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3Muc2V0KHRhZywgcyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0YWdTZXQuZm9yRWFjaChmdW5jdGlvbihjb21wKSB7XG4gICAgICAgICAgICAgIHMuYWRkKGNvbXApO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgIH1cbiAgICB9XG4gIH1cbiAgX2dldEJ5VGFnKHRhZykge1xuICAgIGlmICghdGhpcy5fX3RyZWVUYWdzKSB7XG4gICAgICByZXR1cm4gW107XG4gICAgfVxuICAgIGxldCB0ID0gdGhpcy5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgIHJldHVybiB0ID8gVXRpbHMkMS5zZXRUb0FycmF5KHQpIDogW107XG4gIH1cbiAgZ2V0VGFncygpIHtcbiAgICByZXR1cm4gdGhp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ldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgQmFzZS5wYXRjaE9iamVjdCh0W2ldLCBzZXR0aW5ncyk7XG4gICAgfVxuICB9XG4gIGdldCB0YWdSb290KCkge1xuICAgIHJldHVybiB0aGlzLl9fdGFnUm9vdDtcbiAgfVxuICBzZXQgdGFnUm9vdCh2KSB7XG4gICAgaWYgKHRoaXMuX190YWdSb290ICE9PSB2KSB7XG4gICAgICBpZiAoIXYpIHtcbiAgICAgICAgdGhpcy5fc2V0VGFnc1BhcmVudCgpO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgdGhpcy5fdW5zZXRUYWdzUGFyZW50KCk7XG4gICAgICB9XG4gICAgICB0aGlzLl9fdGFnUm9vdCA9IHY7XG4gICAgfVxuICB9XG4gIHNlbChwYXRoKSB7XG4gICAgY29uc3QgcmVzdWx0cyA9IHRoaXMuc2VsZWN0KHBhdGgpO1xuICAgIGlmIChyZXN1bHRzLmxlbmd0aCkge1xuICAgICAgcmV0dXJuIHJlc3VsdHNbMF07XG4gICAgfSBlbHNlIHtcbiAgICAgIHJldHVybiB2b2lkIDA7XG4gICAgfVxuICB9XG4gIHNlbGVjdChwYXRoKSB7XG4gICAgaWYgKHBhdGguaW5kZXhPZihcIixcIikgIT09IC0xKSB7XG4gICAgICBsZXQgc2VsZWN0b3JzID0gcGF0aC5zcGxpdChcIixcIik7XG4gICAgICBsZXQgcmVzID0gW107XG4gICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHNlbGVjdG9ycy5sZW5ndGg7IGkrKykge1xuICAgICAgICByZXMgPSByZXMuY29uY2F0KHRoaXMuX3NlbGVjdChzZWxlY3RvcnNbaV0pKTtcbiAgICAgIH1cbiAgICAgIHJldHVybiByZXM7XG4gICAgfSBlbHNlIHtcbiAgICAgIHJldHVybiB0aGlzLl9zZWxlY3QocGF0aCk7XG4gICAgfVxuICB9XG4gIF9zZWxlY3QocGF0aCkge1xuICAgIGlmIChwYXRoID09PSBcIlwiKVxuICA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lzc2luZyA9IGZhbHNlO1xuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgIGNoaWxkQXJyYXkucHVzaChjaGlsZHJlbltpXS5nZXRTZXR0aW5ncygpKTtcbiAgICAgICAgICBtaXNzaW5nID0gbWlzc2luZyB8fCAhY2hpbGRyZW5baV0ucmVmO1xuICAgICAgICB9XG4gICAgICAgIGlmICghbWlzc2luZykge1xuICAgICAgICAgIHNldHRpbmdzLmNoaWxkcmVuID0ge307XG4gICAgICAgICAgY2hpbGRBcnJheS5mb3JFYWNoKChjaGlsZCkgPT4ge1xuICAgICAgICAgICAgc2V0dGluZ3MuY2hpbGRyZW5bY2hpbGQucmVmXSA9IGNoaWxkO1xuICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHNldHRpbmdzLmNoaWxkcmVuID0gY2hpbGRBcnJheTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBzZXR0aW5ncy5pZCA9IHRoaXMuaWQ7XG4gICAgcmV0dXJuIHNldHRpbmdzO1xuICB9XG4gIGdldE5vbkRlZmF1bHRzKCkge1xuICAgIGxldCBzZXR0aW5ncyA9IHt9O1xuICAgIGlmICh0aGlzLmNvbnN0cnVjdG9yICE9PSBFbGVtZW50KSB7XG4gICAgICBzZXR0aW5ncy50eXBlID0gdGhpcy5jb25zdHJ1Y3Rvci5uYW1lO1xuICAgIH1cbiAgICBpZiAodGhpcy5fX3JlZikge1xuICAgICAgc2V0dGluZ3MucmVmID0gdGhpcy5fX3JlZjtcbiAgICB9XG4gICAgaWYgKHRoaXMuX190YWdzICYmIHRoaXMuX190YWdzLmxlbmd0aCkge1xuICAgICAgc2V0dGluZ3MudGFncyA9IHRoaXMuX190YWdzO1xuICAgIH1cbiAgICBpZiAodGhpcy54ICE9PSAwKVxuICAgICAgc2V0dGluZ3MueCA9IHRoaXMueDtcbiAgICBpZiAodGhpcy55ICE9PSAwKVxuICAgICAgc2V0dGluZ3MueSA9IHRoaXMueTtcbiAgICBpZiAodGhpcy53ICE9PSAwKVxuICAgICAgc2V0dGluZ3MudyA9IHRoaXMudztcbiAgICBpZiAodGhpcy5oICE9PSAwKVxuICAgICAgc2V0dGluZ3MuaCA9IHRoaXMuaDtcbiAgICBpZiAodGhpcy5zY2FsZVggPT09IHRoaXMuc2NhbGVZKSB7XG4gICAgICBpZiAodGhpcy5zY2FsZVggIT09IDEpXG4gICAgICAgIHNldHRpbmdzLnNjYWxlID0gdGhpcy5zY2FsZVg7XG4gICAgfSBlbHNlIHtcbiAgICAgIGlmICh0aGlzLnNjYWxlWCAhPT0gMSlcbiAgICAgICAgc2V0dGluZ3Muc2NhbGVYID0gdGhpcy5zY2FsZVg7XG4gICAgICBpZiAodGhpcy5zY2FsZVkgIT09IDEpXG4gICAgICAgIHNldHRpbmdzLnNjYWxlWSA9IHRoaXMuc2NhbGVZO1xuICAgIH1cbiAgICBpZiAodGhpcy5waXZvdFggPT09IHRoaXMucGl2b3RZKSB7XG4gICAgICBpZiAodGhpcy5waXZvdFggIT09IDAuNSlcbiAgICAgICAgc2V0dGluZ3MucGl2b3QgPSB0aGlzLnBpdm90WDtcbiAgICB9IGVsc2Uge1xuICAgICAgaWYgKHRoaXMucGl2b3RYICE9PSAwLjUpXG4gICAgICAgIHNldHRpbmdzLnBpdm90WCA9IHRoaXMucGl2b3RYO1xuICAgICAgaWYgKHRoaXMucGl2b3RZICE9PSAwLjUpXG4gICAgICAgIHNldHRpbmdzLnBpdm90WSA9IHRoaXMucGl2b3RZO1xuICAgIH1cbiAgICBpZiAodGhpcy5tb3VudFggPT09IHRoaXMubW91bnRZKSB7XG4gICAgICBpZiAodGhpcy5tb3VudFggIT09IDApXG4gICAgICAgIHNldHRpbmdzLm1vdW50ID0gdGhpcy5tb3VudFg7XG4gICAgfSBlbHNlIHtcbiAgICAgIGlmICh0aGlzLm1vdW50WCAhPT0gMClcbiAgICAgICAgc2V0dGluZ3MubW91bnRY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YpKSB7XG4gICAgICAgICAgICAgIGMgPSB2O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKGMuaXNFbGVtZW50KSB7XG4gICAgICAgICAgICAgIGMucmVmID0gcGF0aDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmEoYyk7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGlmICh2ID09PSB2b2lkIDApIHtcbiAgICAgICAgICAgIGlmIChjaGlsZC5wYXJlbnQpIHtcbiAgICAgICAgICAgICAgY2hpbGQucGFyZW50LmNoaWxkTGlzdC5yZW1vdmUoY2hpbGQpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMkMS5pc09iamVjdExpdGVyYWwodikpIHtcbiAgICAgICAgICAgIGNoaWxkLnBhdGNoKHYpO1xuICAgICAgICAgIH0gZWxzZSBpZiAodi5pc0VsZW1lbnQpIHtcbiAgICAgICAgICAgIHYucmVmID0gcGF0aDtcbiAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LnJlcGxhY2UodiwgY2hpbGQpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl90aHJvd0Vycm9yKFwiVW5leHBlY3RlZCB2YWx1ZSBmb3IgcGF0aDogXCIgKyBwYXRoKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIEJhc2UucGF0Y2hPYmplY3RQcm9wZXJ0eSh0aGlzLCBwYXRoLCB2KTtcbiAgICAgIH1cbiAgICB9XG4gIH1cbiAgX3Rocm93RXJyb3IobWVzc2FnZSkge1xuICAgIHRocm93IG5ldyBFcnJvcih0aGlzLmNvbnN0cnVjdG9yLm5hbWUgKyBcIiAoXCIgKyB0aGlzLmdldExvY2F0aW9uU3RyaW5nKCkgKyBcIik6IFwiICsgbWVzc2FnZSk7XG4gIH1cbiAgYW5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gICBvYmogPSB7IHY6IG9iaiB9O1xuICAgICAgICB9XG4gICAgICAgIGxldCBwID0gcGFyc2VGbG9hdChrZXkpO1xuICAgICAgICBpZiAoa2V5ID09PSBcInNtXCIpIHtcbiAgICAgICAgICBkZWZhdWx0U21vb3RobmVzcyA9IG9iai52O1xuICAgICAgICB9IGVsc2UgaWYgKCFpc05hTihwKSAmJiBwID49IDAgJiYgcCA8PSAyKSB7XG4gICAgICAgICAgb2JqLnAgPSBwO1xuICAgICAgICAgIG9iai5mID0gVXRpbHMkMS5pc0Z1bmN0aW9uKG9iai52KTtcbiAgICAgICAgICBvYmoubHYgPSBvYmouZiA/IG9iai52KDAsIDApIDogb2JqLnY7XG4gICAgICAgICAgaXRlbXMucHVzaChvYmopO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIGl0ZW1zID0gaXRlbXMuc29ydChmdW5jdGlvbihhLCBiKSB7XG4gICAgICByZXR1cm4gYS5wIC0gYi5wO1xuICAgIH0pO1xuICAgIG4gPSBpdGVtcy5sZW5ndGg7XG4gICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgbGV0IGxhc3QgPSBpID09PSBuIC0gMTtcbiAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoXCJwZVwiKSkge1xuICAgICAgICBpdGVtc1tpXS5wZSA9IGxhc3QgPyBpdGVtc1tpXS5wIDw9IDEgPyAxIDogMiA6IGl0ZW1zW2kgKyAxXS5wO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgY29uc3QgbWF4ID0gaSA8IG4gLSAxID8gaXRlbXNbaSArIDFdLnAgOiAxO1xuICAgICAgICBpZiAoaXRlbXNbaV0ucGUgPiBtYXgpIHtcbiAgICAgICAgICBpdGVtc1tpXS5wZSA9IG1heDtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgaWYgKGl0ZW1zW2ldLnBlID09PSBpdGVtc1tpXS5wKSB7XG4gICAgICAgIGl0ZW1zW2ld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FxuICAgICAgICAgICAgICAgIGQgKiAobmNbMV0gLSBwY1sxXSksXG4gICAgICAgICAgICAgICAgZCAqIChuY1syXSAtIHBjWzJdKSxcbiAgICAgICAgICAgICAgICBkICogKG5jWzNdIC0gcGNbM10pXG4gICAgICAgICAgICAgIF07XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBpdGVtc1tpXS5zID0gKG5pLmx2IC0gcGkubHYpIC8gKG5pLnAgLSBwaS5wKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgZm9yIChpID0gMDsgaSA8IG4gLSAxOyBpKyspIHtcbiAgICAgIGlmICghaXRlbXNbaV0uZikge1xuICAgICAgICBsZXQgbGFzdCA9IGkgPT09IG4gLSAxO1xuICAgICAgICBpZiAoIWl0ZW1zW2ldLmhhc093blByb3BlcnR5KFwidmVcIikpIHtcbiAgICAgICAgICBpdGVtc1tpXS52ZSA9IGxhc3QgPyBpdGVtc1tpXS5sdiA6IGl0ZW1zW2kgKyAxXS5sdjtcbiAgICAgICAgfVxuICAgICAgICBpZiAoVXRpbHMkMS5pc051bWJlcihpdGVtc1tpXS52KSAmJiBVdGlscyQxLmlzTnVtYmVyKGl0ZW1zW2ldLmx2KSkge1xuICAgICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoXCJzbWVcIikpIHtcbiAgICAgICAgICAgIGl0ZW1zW2ldLnNtZSA9IGxhc3QgPyBkZWZhdWx0U21vb3RobmVzcyA6IGl0ZW1zW2kgKyAxXS5zbTtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKCFpdGVtc1tpXS5oYXNPd25Qcm9wZXJ0eShcInNlXCIpKSB7XG4gICAgICAgICAgICBpdGVtc1tpXS5zZSA9IGxhc3QgPyByZ2JhID8gWzAsIDAsIDAsIDBdIDogMCA6IGl0ZW1zW2kgKyAxXS5zO1xuICAgICAgICAgIH1cbiAgICAgIC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mlba2V5XSA9PT0gdm9pZCAwKSB7XG4gICAgICAgIGJpW2tleV0gPSAtMTtcbiAgICAgIH1cbiAgICB9XG4gICAgY29uc3QgYWtzbCA9IGFrcy5sZW5ndGg7XG4gICAgY29uc3QgcmVzdWx0ID0ge307XG4gICAgZm9yIChsZXQgaSA9IDAsIG4gPSBia3MubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICBjb25zdCBrZXkgPSBia3NbaV07XG4gICAgICBjb25zdCBhSW5kZXggPSBhaVtrZXldO1xuICAgICAgbGV0IGN1ckluZGV4MiA9IGFJbmRleDtcbiAgICAgIHdoaWxlICgtLWN1ckluZGV4MiA+PSAwKSB7XG4gICAgICAgIGNvbnN0IGFrZXkgPSBha3NbY3VySW5kZXgyXTtcbiAgICAgICAgaWYgKGJpW2FrZXldICE9PSAtMSkge1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICB3aGlsZSAoKytjdXJJbmRleDIgPCBhSW5kZXgpIHtcbiAgICAgICAgY29uc3QgYWtleSA9IGFrc1tjdXJJbmRleDJdO1xuICAgICAgICByZXN1bHRbYWtleV0gPSBhW2FrZXldO1xuICAgICAgfVxuICAgICAgY29uc3QgYnYgPSBiW2tleV07XG4gICAgICBjb25zdCBhdiA9IGFba2V5XTtcbiAgICAgIGxldCByO1xuICAgICAgaWYgKHRoaXMuaXNNZihidikpIHtcbiAgICAgICAgciA9IGJ2KGF2KTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGlmICghVXRpbHMkMS5pc09iamVjdExpdGVyYWwoYXYpIHx8ICFVdGlscyQxLmlzT2JqZWN0TGl0ZXJhbChidikpIHtcbiAgICAgICAgICByID0gYnY7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgciA9IE9iak1lcmdlci5tZXJnZShhdiwgYnYpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpZiAociAhPT0gdm9pZCAwKSB7XG4gICAgICAgIHJlc3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AoKDEuMCAtIGEpICogdGV4dHVyZTJEKHVTYW1wbGVyLCB2VGV4dHVyZUNvb3JkKSArIChhICogdGV4dHVyZTJEKHVTYW1wbGVyMiwgdlRleHR1cmVDb29yZCkpKSAqIHZDb2xvcjtcbiAgICAgICAgfVxuICAgIH1cbmA7XG5jbGFzcyBCbG9vbUNvbXBvbmVudCBleHRlbmRzIENvbXBvbmVudCB7XG4gIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgY29uc3Qgb25VcGRhdGUgPSBmdW5jdGlvbihlbGVtZW50LCBlbGVtZW50Q29yZSkge1xuICAgICAgaWYgKGVsZW1lbnRDb3JlLl9yZWNhbGMgJiAyICsgMTI4KSB7XG4gICAgICAgIGNvbnN0IHcgPSBlbGVtZW50Q29yZS53O1xuICAgICAgICBjb25zdCBoID0gZWxlbWVudENvcmUuaDtcbiAgICAgICAgbGV0IGN1ciA9IGVsZW1lbnRDb3JlO1xuICAgICAgICBkbyB7XG4gICAgICAgICAgY3VyID0gY3VyLl9jaGlsZHJlblswXTtcbiAgICAgICAgICBjdXIuX2VsZW1lbnQudyA9IHc7XG4gICAgICAgICAgY3VyLl9lbGVtZW50LmggPSBoO1xuICAgICAgICB9IHdoaWxlIChjdXIuX2NoaWxkcmVuKTtcbiAgICAgIH1cbiAgICB9O1xuICAgIHJldHVybiB7XG4gICAgICBUZXh0d3JhcDoge1xuICAgICAgICBydHQ6IHRydWUsXG4gICAgICAgIGZvcmNlWkluZGV4Q29udGV4dDogdHJ1ZSxcbiAgICAgICAgcmVuZGVyT2Zmc2NyZWVuOiB0cnVlLFxuICAgICAgICBCbG9vbUJhc2U6IHtcbiAgICAgICAgICBzaGFkZXI6IHsgdHlwZTogQmxvb21CYXNlU2hhZGVyIH0sXG4gICAgICAgICAgQ29udGVudDoge31cbiAgICAgICAgfVxuICAgICAgfSxcbiAgICAgIExheWVyczoge1xuICAgICAgICBMMDogeyBydHQ6IHRydWUsIG9uVXBkYXRlLCBzY2FsZTogMiw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ZW50V2lkdGgoaSkgLyB0aGlzLl9ub2lzZVRleHR1cmUuZ2V0UmVuZGVyV2lkdGgoKTtcbiAgICAgIGxldCBicnkgPSBvcGVyYXRpb24uZ2V0RWxlbWVudEhlaWdodChpKSAvIHRoaXMuX25vaXNlVGV4dHVyZS5nZXRSZW5kZXJIZWlnaHQoKTtcbiAgICAgIGxldCB1bHggPSAwO1xuICAgICAgbGV0IHVseSA9IDA7XG4gICAgICBpZiAodGhpcy5fcmFuZG9tKSB7XG4gICAgICAgIHVseCA9IE1hdGgucmFuZG9tKCk7XG4gICAgICAgIHVseSA9IE1hdGgucmFuZG9tKCk7XG4gICAgICAgIGJyeCArPSB1bHg7XG4gICAgICAgIGJyeSArPSB1bHk7XG4gICAgICAgIGlmIChNYXRoLnJhbmRvbSgpIDwgMC41KSB7XG4gICAgICAgICAgY29uc3QgdCA9IHVseDtcbiAgICAgICAgICB1bHggPSBicng7XG4gICAgICAgICAgYnJ4ID0gdDtcbiAgICAgICAgfVxuICAgICAgICBpZiAoTWF0aC5yYW5kb20oKSA8IDAuNSkge1xuICAgICAgICAgIGNvbnN0IHQgPSB1bHk7XG4gICAgICAgICAgdWx5ID0gYnJ5O1xuICAgICAgICAgIGJyeSA9IHQ7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGZsb2F0c1tvZmZzZXRdID0gdWx4O1xuICAgICAgZmxvYXRzW29mZnNldCArIDFdID0gdWx5O1xuICAgICAgZmxvYXRzW29mZnNldCArIDJdID0gYnJ4O1xuICAgICAgZmxvYXRzW29mZnNldCArIDNdID0gdWx5O1xuICAgICAgZmxvYXRzW29mZnNldCArIDRdID0gYnJ4O1xuICAgICAgZmxvYXRzW29mZnNldCArIDVdID0gYnJ5O1xuICAgICAgZmxvYXRzW29mZnNldCArIDZdID0gdWx4O1xuICAgICAgZmxvYXRzW29mZnNldCArIDddID0gYnJ5O1xuICAgICAgb2Zmc2V0ICs9IDg7XG4gICAgfVxuICB9XG4gIGJlZm9yZURyYX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8gZG90KGQsIGQpO1xuICAgICAgICAgICAgdCA9IHNtb290aHN0ZXAoMC4wLCAxLjAsIGNsYW1wKGMsIDAuMCwgMS4wKSk7XG4gICAgICAgICAgICBjb2xvciA9IG1peCh2ZWM0KDAuMCksIGNvbG9yLCB0KTtcbiAgICAgICAgfVxuICAgICAgICBcbiAgICAgICAgaWYoZmFkZVsxXSA+IDAuMCkge1xuICAgICAgICAgICAgdmVjMiBwb3MxID0gdmVjMihwb2ludC54IC0gcmVzb2x1dGlvbi54IC0gZmFkZVsxXSwgdlRleHR1cmVDb29yZC55KTtcbiAgICAgICAgICAgIHZlYzIgcG9zMiA9IHZlYzIocG9pbnQueCAtIHJlc29sdXRpb24ueCwgdlRleHR1cmVDb29yZC55KTtcbiAgICAgICAgICAgIGQgPSBwb3MxIC0gcG9zMjtcbiAgICAgICAgICAgIGMgPSBkb3QocG9zMiwgZCkgLyBkb3QoZCwgZCk7XG4gICAgICAgICAgICB0ID0gc21vb3Roc3RlcCgwLjAsIDEuMCwgY2xhbXAoYywgMC4wLCAxLjApKTtcbiAgICAgICAgICAgIGNvbG9yID0gbWl4KHZlYzQoMC4wKSwgY29sb3IsIHQpO1xuICAgICAgICB9XG4gICAgICAgIFxuICAgICAgICBpZihmYWRlWzJdID4gMC4wKSB7XG4gICAgICAgICAgICB2ZWMyIHBvczEgPSB2ZWMyKHZUZXh0dXJlQ29vcmQueCwgcG9pbnQueSAtIHJlc29sdXRpb24ueSAtIGZhZGVbMl0pO1xuICAgICAgICAgICAgdmVjMiBwb3MyID0gdmVjMih2VGV4dHVyZUNvb3JkLngsIHBvaW50LnkgLSByZXNvbHV0aW9uLnkpO1xuICAgICAgICAgICAgZCA9IHBvczEgLSBwb3MyO1xuICAgICAgICAgICAgYyA9IGRvdChwb3MyLCBkKSAvIGRvdChkLCBkKTtcbiAgICAgICAgICAgIHQgPSBzbW9vdGhzdGVwKDAuMCwgMS4wLCBjbGFtcChjLCAwLjAsIDEuMCkpO1xuICAgICAgICA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geWMgLSB5YjtcbiAgICAgIHJldHVybiBmdW5jdGlvbih0aW1lKSB7XG4gICAgICAgIGlmICh0aW1lID49IDEpIHtcbiAgICAgICAgICByZXR1cm4gMTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGltZSA8PSAwKSB7XG4gICAgICAgICAgcmV0dXJuIDA7XG4gICAgICAgIH1cbiAgICAgICAgbGV0IHQgPSAwLjUsIGNieCwgY2J4ZCwgZHg7XG4gICAgICAgIGZvciAobGV0IGl0ID0gMDsgaXQgPCAyMDsgaXQrKykge1xuICAgICAgICAgIGNieCA9IHQgKiAodCAqICh0ICogeGEgKyB4YikgKyB4Yyk7XG4gICAgICAgICAgZHggPSB0aW1lIC0gY2J4O1xuICAgICAgICAgIGlmIChkeCA+IC0xZS04ICYmIGR4IDwgMWUtOCkge1xuICAgICAgICAgICAgcmV0dXJuIHQgKiAodCAqICh0ICogeWEgKyB5YikgKyB5Yyk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGNieGQgPSB0ICogKHQgKiAoMyAqIHhhKSArIDIgKiB4YikgKyB4YztcbiAgICAgICAgICBpZiAoY2J4ZCA+IDFlLTEwICYmIGNieGQgPCAxZS0xMCkge1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgfVxuICAgICAgICAgIHQgKz0gZHggLyBjYnhkO1xuICAgICAgICB9XG4gICAgICAgIGxldCBtaW5UID0gMDtcbiAgICAgICAgbGV0IG1heFQgPSAxO1xuICAgICAgICBmb3IgKGxldCBpdCA9IDA7IGl0IDwgMjA7IGl0KyspIHtcbiAgICAgICAgICB0ID0gMC41ICogKG1pblQgKyBtYXhUKTtcbiAgICAgICAgICBjYnggPSB0ICogKHQgKiAodCAqIHhhICsgeGIpICsgeGMpO1xuICAgICAgICAgIGR4ID0gdGltZSAtIGNieDtcbiAgICAgICAgICBpZiAoZHggPiAtMWUtOCAmJiBkeCA8IDFlLTgpIHtcbiAgICAgICAgICAgIHJldHVybiB0ICogKHQgKiAodCAqIHlhICsgeWIpICsgeWMpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoZHggPCAwKSB7XG4gICAgICAgICAgICBtYXhUID0gdDtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbWluVCA9IHQ7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0VGltaW5nRnVuY3Rpb24oc3RyKSB7XG4gICAgICBzd2l0Y2ggKHN0cikge1xuICAgICAgICBjYXNlIFwibGluZWFyXCI6XG4gICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKHRpbWUpIHtcbiAgICAgICAgICAgIHJldHVybiB0aW1lO1xuICAgICAgICAgIH07XG4gICAgICAgIGNhc2UgXCJlYXNlXCI6XG4gICAgICAgICAgcmV0dXJuIFN0YWdlVXRpbHMuZ2V0VGltaW5nQmV6aWVyKDAuMjUsIDAuMSwgMC4yNSwgMSk7XG4gICAgICAgIGNhc2UgXCJlYXNlLWluXCI6XG4gICAgICAgICAgcmV0dXJuIFN0YWdlVXRpbHMuZ2V0VGltaW5nQmV6aWVyKDAuNDIsIDAsIDEsIDEpO1xuICAgICAgICBjYXNlIFwiZWFzZS1vdXRcIjpcbiAgICAgICAgICByZXR1cm4gU3RhZ2VVdGlscy5nZXRUaW1pbmdCZXppZXIoMCwgMCwgMC41OCwgMSk7XG4gICAgICAgIGNhc2UgXCJlYXNlLWluLW91dFwiOlxuICAgICAgICAgIHJldHVybiBTdGFnZVV0aWxzLmdldFRpbWluZ0JlemllcigwLjQyLCAwLCAwLjU4LCAxKTtcbiAgICAgICAgY2FzZSBcInN0ZXAtc3RhcnRcIjpcbiAgICAgICAgICByZXR1cm4gZnVuY3Rpb24oKSB7XG4gICAgICAgICAgICByZXR1cm4gMTtcbiAgICAgICAgICB9O1xuICAgICAgICBjYXNlIFwic3RlcC1lbmRcIjpcbiAgICAgICAgICByZXR1cm4gZnVuY3Rpb24odGltZSkge1xuICAgICAgICAgICAgcmV0dXJuIHRpbWUgPT09IDEgPyAxIDogMDtcbiAgICAgICAgICB9O1xuICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgIGxldCBzID0gXCJjdWJpYy1iZXppZXIoXCI7XG4gICAgICAgICAgaWYgKHN0ciAmJiBzdHIuaW5kZXhPZihzKSA9PT0gMCkge1xuICAgICAgICAgICAgbGV0IHBhcnRzID0gc3RyLnN1YnN0cihzLmxlbmd0aCwgc3RyLmxlbmd0aCAtIHMubGVuZ3RoIC0gMSkuc3BsaXQoXCIsXCIpO1xuICAgICAgICAgICAgaWYgKHBhcnRzLmxlbmd0aCAhPT0gNCkge1xuICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJbTGlnaHRuaW5nXSBVbmtub3duIHRpbWluZyBmdW5jdGlvbjogXCIgKyBzdHIpO1xuICAgICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24odGltZSkge1xuICAgICAgICAgICAgICAgIHJldHVybiB0aW1lO1xuICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgbGV0IGEgPSBwYXJzZUZsb2F0KHBhcnRzWzBdKTtcbiAgICAgICAgICAgIGxldCBiID0gcGFyc2VGbG9hdChwYXJ0c1sxXSk7XG4gICAgICAgICAgICBsZXQgYyA9IHBhcnNlRmxvYXQocGFydHNbMl0pO1xuICAgICAgICAgICAgbGV0IGQgPSBwYXJzZUZsb2F0KHBhcnRzWzNdKTtcbiAgICAgICAgICAgIGlmIChpc05hTihhKSB8fCBpc05hTihiKSB8fCBpc05hTihjKSB8fCBpc05hTihkKSkge1xuICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJbTGlnaHRuaW5nXSBVbmtub3duIHRpbWluZyBmdW5jdGlvbjogXCIgKyBzdHIpO1xuICAgICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24odGltZSkge1xuICAgICAgICAgICAgICAgIHJldHVybiB0aW1lO1xuICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfVx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UuY29uc3RydWN0b3IgPT09IE9iamVjdDtcbiAgICB9XG4gICAgc3RhdGljIGdldEFycmF5SW5kZXgoaW5kZXgsIGFycikge1xuICAgICAgcmV0dXJuIFV0aWxzJDEuZ2V0TW9kdWxvSW5kZXgoaW5kZXgsIGFyci5sZW5ndGgpO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0TW9kdWxvSW5kZXgoaW5kZXgsIGxlbikge1xuICAgICAgaWYgKGxlbiA9PT0gMClcbiAgICAgICAgcmV0dXJuIGluZGV4O1xuICAgICAgd2hpbGUgKGluZGV4IDwgMCkge1xuICAgICAgICBpbmRleCArPSBNYXRoLmNlaWwoLWluZGV4IC8gbGVuKSAqIGxlbjtcbiAgICAgIH1cbiAgICAgIGluZGV4ID0gaW5kZXggJSBsZW47XG4gICAgICByZXR1cm4gaW5kZXg7XG4gICAgfVxuICAgIHN0YXRpYyBnZXREZWVwQ2xvbmUob2JqKSB7XG4gICAgICBsZXQgaSwgYztcbiAgICAgIGlmIChVdGlscyQxLmlzRnVuY3Rpb24ob2JqKSkge1xuICAgICAgICByZXR1cm4gb2JqO1xuICAgICAgfVxuICAgICAgaWYgKEFycmF5LmlzQXJyYXkob2JqKSkge1xuICAgICAgICBjID0gW107XG4gICAgICAgIGxldCBrZXlzID0gT2JqZWN0LmtleXMob2JqKTtcbiAgICAgICAgZm9yIChpID0gMDsgaSA8IGtleXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICBjW2tleXNbaV1dID0gVXRpbHMkMS5nZXREZWVwQ2xvbmUob2JqW2tleXNbaV1dKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gYztcbiAgICAgIH0gZWxzZSBpZiAoVXRpbHMkMS5pc09iamVjdChvYmopKSB7XG4gICAgICAgIGMgPSB7fTtcbiAgICAgICAgbGV0IGtleXMgPSBPYmplY3Qua2V5cyhvYmopO1xuICAgICAgICBmb3IgKGkgPSAwOyBpIDwga2V5cy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgIGNba2V5c1tpXV0gPSBVdGlscyQxLmdldERlZXBDbG9uZShvYmpba2V5c1tpXV0pO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBjO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIG9iajtcbiAgICAgIH1cbiAgICB9XG4gICAgc3RhdGljIGVxdWFsVmFsdWVzKHYxLCB2Mikge1xuICAgICAgaWYgKHR5cGVvZiB2MSAhPT0gdHlwZW9mIHYyKVxuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICBpZiAoVXRpbHMkMS5pc09iamVjdExpdGVyYWwodjEpKSB7XG4gICAgICAgIHJldHVybiBVdGlscyQxLmlzT2JqZWN0TGl0ZXJhbCh2MikgJiYgVXRpbHMkMS5lcXVhbE9iamVjdExpdGVyYWxzKHYxLCB2Mik7XG4gICAgICB9IGVsc2UgaWYgKEFycmF5LmlzQXJyYXkodjEpKSB7XG4gICAgICAgIHJldHVybiBBcnJheS5pc0FycmF5KHYyKSAmJiBVdGlscyQxLmVxdWFsQXJyYXlzKHYxLCB2Mik7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gdjEgPT09IHYyO1xuICAgICAgfVxuICAgIH1cbiAgICBzdGF0aWMgZXF1YWxPYmplY3RMaXRlcmFscyhvYmoxLCBvYmoyKSB7XG4gICAgICBsZXQga2V5czEgPSBPYmplY3Qua2V5cyhvYmoxKTtcbiAgICAgIGxldCBrZXlzMiA9IE9iamVjdC5rZXlzKG9iajIpO1xuICAgICAgaWYgKGtleXMxLmxlbmd0aCAhPT0ga2V5czIubGVuZ3RoKSB7XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgIH1cbiAgICAgIGZvciAobGV0IGkgPSAwLCBuID0ga2V5czEubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgIGNvbnN0IGsxID0ga2V5czFbaV07XG4gICAgICAgIGNvbnN0IGsyID0ga2V5czJbaV07XG4gICAgICAgIGlmICh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GFjZSkgLyBpdGVtR2FwcztcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSBcInNwYWNlLWFyb3VuZFwiOlxuICAgICAgICAgIGlmIChyZW1haW5pbmdTcGFjZSA8IDApIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLmdldFNwYWNpbmcoXCJjZW50ZXJcIiwgbnVtYmVyT2ZJdGVtcywgcmVtYWluaW5nU3BhY2UpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzcGFjZVBlckdhcCA9IHJlbWFpbmluZ1NwYWNlIC8gKGl0ZW1HYXBzICsgMSk7XG4gICAgICAgICAgICBzcGFjaW5nQmVmb3JlID0gMC41ICogc3BhY2VQZXJHYXA7XG4gICAgICAgICAgICBzcGFjaW5nQmV0d2VlbiA9IHNwYWNlUGVyR2FwO1xuICAgICAgICAgIH1cbiAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSBcInNwYWNlLWV2ZW5seVwiOlxuICAgICAgICAgIGlmIChyZW1haW5pbmdTcGFjZSA8IDApIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLmdldFNwYWNpbmcoXCJjZW50ZXJcIiwgbnVtYmVyT2ZJdGVtcywgcmVtYWluaW5nU3BhY2UpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzcGFjZVBlckdhcCA9IHJlbWFpbmluZ1NwYWNlIC8gKGl0ZW1HYXBzICsgMik7XG4gICAgICAgICAgICBzcGFjaW5nQmVmb3JlID0gc3BhY2VQZXJHYXA7XG4gICAgICAgICAgICBzcGFjaW5nQmV0d2VlbiA9IHNwYWNlUGVyR2FwO1xuICAgICAgICAgIH1cbiAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSBcInN0cmV0Y2hcIjpcbiAgICAgICAgICBzcGFjaW5nQmVmb3JlID0gMDtcbiAgICAgICAgICBzcGFjaW5nQmV0d2VlbiA9IDA7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIG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XNTaHJpbmthYmxlSXRlbSkge1xuICAgICAgICAgICAgICBsZXQgc2hyaW5rID0gc2hyaW5rQW1vdW50ICogYW1vdW50UGVyU2hyaW5rO1xuICAgICAgICAgICAgICBjb25zdCBtaW5TaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTWluU2l6ZSgpO1xuICAgICAgICAgICAgICBjb25zdCBzaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTGF5b3V0U2l6ZSgpO1xuICAgICAgICAgICAgICBpZiAoc2l6ZSA+IG1pblNpemUpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBtYXhTaHJpbmsgPSBzaXplIC0gbWluU2l6ZTtcbiAgICAgICAgICAgICAgICBjb25zdCBpc0Z1bGx5U2hydW5rID0gc2hyaW5rID49IG1heFNocmluaztcbiAgICAgICAgICAgICAgICBpZiAoaXNGdWxseVNocnVuaykge1xuICAgICAgICAgICAgICAgICAgc2hyaW5rID0gbWF4U2hyaW5rO1xuICAgICAgICAgICAgICAgICAgdG90YWxTaHJpbmtBbW91bnQgLT0gc2hyaW5rQW1vdW50O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjb25zdCBmaW5hbFNpemUgPSBzaXplIC0gc2hyaW5rO1xuICAgICAgICAgICAgICAgIGZsZXhJdGVtLl9yZXNpemVNYWluQXhpcyhmaW5hbFNpemUpO1xuICAgICAgICAgICAgICAgIHRoaXMuX3NocnVua1NpemUgKz0gc2hyaW5rO1xuICAgICAgICAgICAgICAgIHRoaXMuX2Ftb3VudFJlbWFpbmluZyAtPSBzaHJpbms7XG4gICAgICAgICAgICAgICAgaWYgKE1hdGguYWJzKHRoaXMuX2Ftb3VudFJlbWFpbmluZykgPCAxZS01KSB7XG4gICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9IHdoaWxlICh0b3RhbFNocmlua0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DA7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIGNvbnN0IG1heEdyb3cgPSBtYXhTaXplIC0gc2l6ZTtcbiAgICAgICAgICAgICAgICAgIGNvbnN0IGlzRnVsbHlHcm93biA9IGdyb3cgPj0gbWF4R3JvdztcbiAgICAgICAgICAgICAgICAgIGlmIChpc0Z1bGx5R3Jvd24pIHtcbiAgICAgICAgICAgICAgICAgICAgZ3JvdyA9IG1heEdyb3c7XG4gICAgICAgICAgICAgICAgICAgIHRvdGFsR3Jvd0Ftb3VudCAtPSBncm93QW1vdW50O1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBpZiAoZ3JvdyA+IDApIHtcbiAgICAgICAgICAgICAgICBjb25zdCBmaW5hbFNpemUgPSBzaXplICsgZ3JvdztcbiAgICAgICAgICAgICAgICBmbGV4SXRlbS5fcmVzaXplTWFpbkF4aXMoZmluYWxTaXplKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9ncm93blNpemUgKz0gZ3JvdztcbiAgICAgICAgICAgICAgICB0aGlzLl9hbW91bnRSZW1haW5pbmcgLT0gZ3JvdztcbiAgICAgICAgICAgICAgICBpZiAoTWF0aC5hYnModGhpcy5fYW1vdW50UmVtYWluaW5nKSA8IDFlLTUpIHtcbiAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH0gd2hpbGUgKHRvdGFsR3Jvd0Ftb3VudCAmJiBNYXRoLmFicyh0aGlzLl9hbW91bnRSZW1haW5pbmcpID4gMWUtNSk7XG4gICAgICB9XG4gICAgfVxuICAgIF9nZXRUb3RhbEdyb3dBbW91bnQoKSB7XG4gICAgICBsZXQgdG90YWwgPSAwO1xuICAgICAgY29uc3QgaXRlbXMgPSB0aGlzLl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IHRoaXMuX2xheW91dE1haW5BeGlzKCk7XG4gICAgICB0aGlzLl9sYXlvdXRDcm9zc0F4aXMoKTtcbiAgICB9XG4gICAgX2xheW91dE1haW5BeGlzKCkge1xuICAgICAgdGhpcy5fbGF5b3V0TGluZXMoKTtcbiAgICAgIHRoaXMuX2ZpdE1haW5BeGlzU2l6ZVRvQ29udGVudHMoKTtcbiAgICB9XG4gICAgX2xheW91dExpbmVzKCkge1xuICAgICAgdGhpcy5fbGluZUxheW91dGVyLmxheW91dExpbmVzKCk7XG4gICAgfVxuICAgIGdldCBfbGluZXMoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fbGluZUxheW91dGVyLmxpbmVzO1xuICAgIH1cbiAgICBfZml0TWFpbkF4aXNTaXplVG9Db250ZW50cygpIHtcbiAgICAgIGlmICghdGhpcy5fcmVzaXppbmdNYWluQXhpcykge1xuICAgICAgICBpZiAodGhpcy5pc01haW5BeGlzRml0VG9Db250ZW50cygpKSB7XG4gICAgICAgICAgdGhpcy5tYWluQXhpc1NpemUgPSB0aGlzLl9saW5lTGF5b3V0ZXIubWFpbkF4aXNDb250ZW50U2l6ZTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBfbGF5b3V0Q3Jvc3NBeGlzKCkge1xuICAgICAgY29uc3QgYWxpZ25lciA9IG5ldyBDb250ZW50QWxpZ25lcih0aGlzKTtcbiAgICAgIGFsaWduZXIuaW5pdCgpO1xuICAgICAgdGhpcy5fdG90YWxDcm9zc0F4aXNTaXplID0gYWxpZ25lci50b3RhbENyb3NzQXhpc1NpemU7XG4gICAgICB0aGlzLl9maXRDcm9zc0F4aXNTaXplVG9Db250ZW50cygpO1xuICAgICAgYWxpZ25lci5hbGlnbigpO1xuICAgIH1cbiAgICBfZml0Q3Jvc3NBeGlzU2l6ZVRvQ29udGVudHMoKSB7XG4gICAgICBpZiAoIXRoaXMuX3Jlc2l6aW5nQ3Jvc3NBeGlzKSB7XG4gICAgICAgIGlmICh0aGlzL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gICAgaWYgKHRoaXMuX2FsaWduSXRlbXMgPT09IHYpXG4gICAgICAgIHJldHVybjtcbiAgICAgIGlmIChGbGV4Q29udGFpbmVyLkFMSUdOX0lURU1TLmluZGV4T2YodikgPT09IC0xKSB7XG4gICAgICAgIHRocm93IG5ldyBFcnJvcihcIlVua25vd24gYWxpZ25JdGVtcywgb3B0aW9uczogXCIgKyBGbGV4Q29udGFpbmVyLkFMSUdOX0lURU1TLmpvaW4oXCIsXCIpKTtcbiAgICAgIH1cbiAgICAgIHRoaXMuX2FsaWduSXRlbXMgPSB2O1xuICAgICAgdGhpcy5fY2hhbmdlZENvbnRlbnRzKCk7XG4gICAgfVxuICAgIGdldCBhbGlnbkNvbnRlbnQoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fYWxpZ25Db250ZW50O1xuICAgIH1cbiAgICBzZXQgYWxpZ25Db250ZW50KHYpIHtcbiAgICAgIGlmICh0aGlzLl9hbGlnbkNvbnRlbnQgPT09IHYpXG4gICAgICAgIHJldHVybjtcbiAgICAgIGlmIChGbGV4Q29udGFpbmVyLkFMSUdOX0NPTlRFTlQuaW5kZXhPZih2KSA9PT0gLTEpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiVW5rbm93biBhbGlnbkNvbnRlbnQsIG9wdGlvbnM6IFwiICsgRmxleENvbnRhaW5lci5BTElHTl9DT05URU5ULmpvaW4oXCIsXCIpKTtcbiAgICAgIH1cbiAgICAgIHRoaXMuX2FsaWduQ29udGVudCA9IHY7XG4gICAgICB0aGlzLl9jaGFuZ2VkQ29udGVudHMoKTtcbiAgICB9XG4gICAgZ2V0IGp1c3RpZnlDb250ZW50KCkge1xuICAgICAgcmV0dXJuIHRoaXMuX2p1c3RpZnlDb250ZW50O1xuICAgIH1cbiAgICBzZXQganVzdGlmeUNvbnRlbnQodikge1xuICAgICAgaWYgKHRoaXMuX2p1c3RpZnlDb250ZW50ID09PSB2KVxuICAgICAgICByZXR1cm47XG4gICAgICBpZiAoRmx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gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gMDtcbiAgICAgIH1cbiAgICB9XG4gICAgc2V0IHNocmluayh2KSB7XG4gICAgICBpZiAodGhpcy5fc2hyaW5rID09PSB2KVxuICAgICAgICByZXR1cm47XG4gICAgICB0aGlzLl9zaHJpbmsgPSBwYXJzZUludCh2KSB8fCAwO1xuICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgIH1cbiAgICBnZXQgYWxpZ25TZWxmKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX2FsaWduU2VsZjtcbiAgICB9XG4gICAgc2V0IGFsaWduU2VsZih2KSB7XG4gICAgICBpZiAodGhpcy5fYWxpZ25TZWxmID09PSB2KVxuICAgICAgICByZXR1cm47XG4gICAgICBpZiAodiA9PT0gdm9pZCAwKSB7XG4gICAgICAgIHRoaXMuX2FsaWduU2VsZiA9IHZvaWQgMDtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGlmIChGbGV4Q29udGFpbmVyLkFMSUdOX0lURU1TLmluZGV4T2YodikgPT09IC0xKSB7XG4gICAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiVW5rbm93biBhbGlnblNlbGYsIG9wdGlvbnM6IFwiICsgRmxleENvbnRhaW5lci5BTElHTl9JVEVNUy5qb2luKFwiLFwiKSk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fYWxpZ25TZWxmID0gdjtcbiAgICAgIH1cbiAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICB9XG4gICAgZ2V0IG1pbldpZHRoKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX21pbldpZHRoO1xuICAgIH1cbiAgICBzZXQgbWluV2lkdGgodikge1xuICAgICAgdGhpcy5fbWluV2lkdGggPSBNYXRoLm1heCgwLCB2KTtcbiAgICAgIHRoaXMuX2l0ZW0uY2hhbmdlZERpbWVuc2lvbnModHJ1ZSwgZmFsc2UpO1xuICAgIH1cbiAgICBnZXQgbWluSGVpZ2h0KCkge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FJlY2FsYygxICsgMiArIDQpO1xuICAgICAgICBpZiAodGhpcy5fcGFyZW50KSB7XG4gICAgICAgICAgdGhpcy5fcGFyZW50Ll9zZXRIYXNVcGRhdGVzKCk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX3pJbmRleCA9PT0gMCkge1xuICAgICAgICAgIHRoaXMuc2V0WlBhcmVudChwYXJlbnQpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuc2V0WlBhcmVudChwYXJlbnQgPyBwYXJlbnQuZmluZFpDb250ZXh0KCkgOiBudWxsKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAocHJldklzWkNvbnRleHQgIT09IHRoaXMuaXNaQ29udGV4dCgpKSB7XG4gICAgICAgICAgaWYgKCF0aGlzLmlzWkNvbnRleHQoKSkge1xuICAgICAgICAgICAgdGhpcy5kaXNhYmxlWkNvbnRleHQoKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5lbmFibGVaQ29udGV4dChwcmV2UGFyZW50LmZpbmRaQ29udGV4dCgpKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fekluZGV4UmVzb3J0ID0gdHJ1ZTtcbiAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLl9zaGFkZXIpIHtcbiAgICAgICAgICBsZXQgbmV3U2hhZGVyT3duZXIgPSBwYXJlbnQgJiYgIXBhcmVudC5fcmVuZGVyVG9UZXh0dXJlRW5hYmxlZCA/IHBhcmVudC5fc2hhZGVyT3duZXIgOiBudWxsO1xuICAgICAgICAgIGlmIChuZXdTaGFkZXJPd25lciAhPT0gdGhpcy5fc2hhZGVyT3duZXIpIHtcbiAgICAgICAgICAgIHRoaXMuc2V0SGFzUmVuZGVyVXBkYXRlcygx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XJlbnQpIHtcbiAgICAgICAgaWYgKHRoaXMgPT09IHApIHtcbiAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cbiAgICBpc1pDb250ZXh0KCkge1xuICAgICAgcmV0dXJuIHRoaXMuX2ZvcmNlWkluZGV4Q29udGV4dCB8fCB0aGlzLl9yZW5kZXJUb1RleHR1cmVFbmFibGVkIHx8IHRoaXMuX3pJbmRleCAhPT0gMCB8fCB0aGlzLl9pc1Jvb3QgfHwgIXRoaXMuX3BhcmVudDtcbiAgICB9XG4gICAgZmluZFpDb250ZXh0KCkge1xuICAgICAgaWYgKHRoaXMuaXNaQ29udGV4dCgpKSB7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3BhcmVudC5maW5kWkNvbnRleHQoKTtcbiAgICAgIH1cbiAgICB9XG4gICAgc2V0WlBhcmVudChuZXdaUGFyZW50KSB7XG4gICAgICBpZiAodGhpcy5felBhcmVudCAhPT0gbmV3WlBhcmVudCkge1xuICAgICAgICBpZiAodGhpcy5felBhcmVudCAhPT0gbnVsbCkge1xuICAgICAgICAgIGlmICh0aGlzLl96SW5kZXggIT09IDApIHtcbiAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZGVjWkNvbnRleHRVc2FnZSgpO1xuICAgICAgICAgIH1cbiAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKG5ld1pQYXJlbnQgIT09IG51bGwpIHtcbiAgICAgICAgICBsZXQgaGFkWkNvbnRleHRVc2FnZSA9IG5ld1pQYXJlbnQuX3pDb250ZXh0VXNhZ2UgPiAwO1xuICAgICAgICAgIGlmICh0aGlzLl96SW5kZXggIT09IDApIHtcbiAgICAgICAgICAgIG5ld1pQYXJlbnQuaW5jWkNvbnRleHRVc2FnZSgpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAobmV3WlBhcmVudC5fekNvbnRleHRVc2FnZSA+IDApIHtcbiAgICAgICAgICAgIGlmICghaGFkWkNvbnRleHRVc2FnZSAmJiB0aGlzLl9wYXJlbnQgPT09IG5ld1pQYXJlbnQpXG4gICAgICAgICAgICAgIDtcbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICBuZXdaUGFyZW50Ll96SW5kZXhlZENoaWxkcmVuLnB1c2godGhpcyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBuZXdaUGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHRoaXMuX3pQYXJlbnQgPSBuZXdaUGFyZW50O1xuICAgICAgICB0aGlzLl96SW5kZXhSZXNvcnQgPSB0cnVlO1xuICAgICAgfVxuICAgIH1cbiAgICBpbmNaQ29udGV4dFVzYWdlKCkge1xuICAgICAgdGhpcy5fekNvbnRleHRVc2FnZSsrO1xuICAgICAgaWYgKHRoaXMuX3pDb250ZXh0VXNhZ2UgPT09IDEpIHtcbiAgICAgICAgaWYgKCF0aGlzLl96SW5kZXhlZENoaWxkcmVuKSB7XG4gICAgICAgICAgdGhpcy5fekluZGV4ZWRDaGlsZHJlbiA9IFtdO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuLnB1c2godGhpcy5fY2hpbGRyZW5baV0pO1xuICAgICAgICAgIH1cbiAgICAgICAgICB0aGlzLl96U29ydCA9IGZhbHNlO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIGRlY1pDb250ZXh0VXNhZ2UoKSB7XG4gICAgICB0aGlzLl96Q29udGV4dFVzYWdlLS07XG4gICAgICBpZiAodGhpcy5fekNvbnRleHRVc2FnZSA9PT0gMCkge1xuICAgICAgICB0aGlzLl96U29ydCA9IGZhbHNlO1xuICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuLnNwbGljZSgwKTtcbiAgICAgIH1cbiAgICB9XG4gICAgZ2V0IHpJbmRleCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl96SW5kZXg7XG4gICAgfVxuICAgIHNldCB6SW5kZXgoekluZGV4KSB7XG4gICAgICBpZiAodGhpcy5fekluZGV4ICE9PSB6SW5kZXgpIHtcbiAgICAgICAgdGhpcy5zZXRIYXNSZW5kZXJVcGRhdGVzKDEpO1xuICAgICAgICBsZXQgbmV3WlBhcmVudCA9IHRoaXMuX3pQYXJlbnQ7XG4gICAgICAgIGxldCBwcmV2SXNaQ29udGV4dCA9IHRoaXMuaXNaQ29udGV4dCgpO1xuICAgICAgICBpZiAoekluZGV4ID09PSAwICYmIHRoaXMuX3pJbmRleCAhPT0gMCkge1xuICAgICAgICAgIGlmICh0aGlzLl9wYXJlbnQgPT09IHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl96UGFyZW50KSB7XG4gICAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZGVjWkNvbnRleHRVc2FnZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBuZXdaUGFyZW50ID0gdGhpcy5fcGFyZW50O1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIGlmICh6SW5kZXggIT09IDAgJiYgdGhpcy5fekluZGV4ID09PSAwKSB7XG4gICAgICAgICAgbmV3WlBhcmVudCA9IHRoaXMuX3BhcmVudCA/IHRoaXMuX3BhcmVudC5maW5kWkNvbnRleHQoKSA6IG51bGw7XG4gICAgICAgICAgaWYgKG5ld1pQYXJlbnQgPT09IHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl96UGFyZW50KSB7XG4gICAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuaW5jWkNvbnRleHRVc2FnZSgpO1xuICAgICAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHpJbmRleCAhPT0gdGhpcy5fekluZGV4KSB7XG4gICAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQgJiYgdGhpcy5felBhcmVudC5fekNvbnRleHRVc2FnZSkge1xuICAgICAgICAgICAgdGhpcy5felBhcmVudC5lbmFibGVaU29ydCgpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAobmV3WlBhcmVudCAhPT0gdGhpcy5felBhcmVudCkge1xuICAgICAgICAgIHRoaXMuc2V0WlBhcmVudChudWxsKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl96SW5kZXggPSB6SW5kZXg7XG4gICAgICAgIGlmIChuZXdaUGFyZW50ICE9PSB0aGlzLl96UGFyZW50KSB7XG4gICAgICAgICAgdGhpcy5zZXRaUGFyZW50KG5ld1pQYXJlbnQpO1xuICAgICAgICB9XG4gICAgICAgIGlmIChwcmV2SXNaQ29udGV4dCAhPT0gdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgICBpZiAoIXRoaXMuaXNaQ29udGV4dCgpKSB7XG4gICAgICAgICAgICB0aGlzLmRpc2FibGVaQ29udGV4dCgpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmVuYWJsZVpDb250ZXh0KHRoaXMuX3BhcmVudC5maW5kWkNvbnRleHQoKSk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHRoaXMuX3pJbmRleFJlc29ydCA9IHRydWU7XG4gICAgICAgIGlmICh0aGlzLl96UGFyZW50KSB7XG4gICAgICAgICAgdGhpcy5felBhcmVudC5l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Zpc2libGUgfHwgdy5hbHBoYSAmJiAhdmlzaWJsZSkge1xuICAgICAgICBsZXQgcmVjYWxjID0gdGhpcy5fcmVjYWxjO1xuICAgICAgICBpZiAocmVjYWxjICYgMSkge1xuICAgICAgICAgIGlmICghdy5hbHBoYSAmJiB2aXNpYmxlKSB7XG4gICAgICAgICAgICB0aGlzLl9oYXNSZW5kZXJVcGRhdGVzID0gMztcbiAgICAgICAgICB9XG4gICAgICAgICAgdy5hbHBoYSA9IHB3LmFscGhhICogdGhpcy5fbG9jYWxBbHBoYTtcbiAgICAgICAgICBpZiAody5hbHBoYSA8IDFlLTE0KSB7XG4gICAgICAgICAgICB3LmFscGhhID0gMDtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHJlY2FsYyAmIDYpIHtcbiAgICAgICAgICB3LnB4ID0gcHcucHggKyB0aGlzLl9sb2NhbFB4ICogcHcudGE7XG4gICAgICAgICAgdy5weSA9IHB3LnB5ICsgdGhpcy5fbG9jYWxQeSAqIHB3LnRkO1xuICAgICAgICAgIGlmIChwdy50YiAhPT0gMClcbiAgICAgICAgICAgIHcucHggKz0gdGhpcy5fbG9jYWxQeSAqIHB3LnRiO1xuICAgICAgICAgIGlmIChwdy50YyAhPT0gMClcbiAgICAgICAgICAgIHcucHkgKz0gdGhpcy5fbG9jYWxQeCAqIHB3LnRjO1xuICAgICAgICB9XG4gICAgICAgIGlmIChyZWNhbGMgJiA0KSB7XG4gICAgICAgICAgdy50YSA9IHRoaXMuX2xvY2FsVGEgKiBwdy50YTtcbiAgICAgICAgICB3LnRiID0gdGhpcy5fbG9jYWxUZCAqIHB3LnRiO1xuICAgICAgICAgIHcudGMgPSB0aGlzLl9sb2NhbFRhICogcHcudGM7XG4gICAgICAgICAgdy50ZCA9IHRoaXMuX2xvY2FsVGQgKiBwdy50ZDtcbiAgICAgICAgICBpZiAodGhpcy5faXNDb21wbGV4KSB7XG4gICAgICAgICAgICB3LnRhICs9IHRoaXMuX2xvY2FsVGMgKiBwdy50YjtcbiAgICAgICAgICAgIHcudGIgKz0gdGhpcy5fbG9jYWxUYiAqIHB3LnRhO1xuICAgICAgICAgICAgdy50YyArPSB0aGlzLl9sb2NhbFRjICogcHcudGQ7XG4gICAgICAgICAgICB3LnRkICs9IHRoaXMuX2xvY2FsVGIgKiBwdy50YztcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgY29uc3QgcHIgPSB0aGlzLl9wYXJlbnQuX3JlbmRlckNvbnRleHQ7XG4gICAgICAgIGlmICh0aGlzLl9wYXJlbnQuX2hhc1JlbmRlckNvbnRleHQoKSkge1xuICAgICAgICAgIGNvbnN0IGluaXQgPSB0aGlzLl9yZW5kZXJDb250ZXh0ID09PSB0aGlzLl93b3JsZENvbnRleHQ7XG4gICAgICAgICAgaWYgKGluaXQpIHtcbiAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSBuZXcgRWxlbWVudENvcmVDb250ZXh0KCk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnN0IHIyID0gdGhpcy5fcmVuZGVyQ29udGV4dDtcbiAgICAgICAgICBpZiAoaW5pdCB8fCByZWNhbGMgJiAxKSB7XG4gICAgICAgICAgICByMi5hbHBoYSA9IHByLmFscGhhICogdGhpcy5fbG9jYWxBbHBoYTtcbiAgICAgICAgICAgIGlmIChyMi5hbHBoYSA8IDFlLTE0KSB7XG4gICAgICAgICAgICAgIHIyLmFscGhhID0gMDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKGluaXQgfHwgcmVjYWxjICYgNikge1xuICAgICAgICAgICAgcjIucHggPSBwci5weCArIHRoaXMuX2xvY2FsUHggKiBwci50YTtcbiAgICAgICAgICAgIHIyLnB5ID0gcHIucHkgKyB0aGlzLl9sb2NhbFB5ICogcHIudGQ7XG4gICAgICAgICAgICBpZiAocHIudGIgIT09IDApXG4gICAgICAgICAgICAgIHIyLnB4ICs9IHRoaXMuX2xvY2FsUHkgKiBwci50YjtcbiAgICAgICAgICAgIGlmIChwci50YyAhPT0gMClcbiAgICAgICAgICAgICAgcjIucHkgKz0gdGhpcy5fbG9jYWxQeCAqIHByLnRjO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoaW5pdCkge1xuICAgICAgICAgICAgcmVjYWxjIHw9IDI7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChpbml0IHx8IHJlY2FsYyAmIDQpIHtcbiAgICAgICAgICAgIHIyLnRhID0gdGhpcy5fbG9jYWxUYSAqIHByLnRhO1xuICAgICAgICAgICAgcjIudGIgPSB0aGlzLl9sb2NhbFRkICogcHIudGI7XG4gICAgICAgICAgICByMi50YyA9IHRoaXMuX2xvY2FsVGEgKiBwci50YztcbiAgICAgICAgICAgIHIyLnRkID0gdGhpcy5fbG9jYWxUZCAqIHByLnRkO1xuICAgICAgICAgICAgaWYgKHRoaXMuX2lzQ29tcGxleCkge1xuICAgICAgICAgICAgICByMi50YSArPSB0aGlzLl9sb2NhbFRjICogcHIudGI7XG4gICAgICAgICAgICAgIHIyLnRiICs9IHRoaXMuX2xvY2FsVGIgKiBwci50YTtcbiAgICAgICAgICAgICAgcjIudGMgKz0gdGhpcy5fbG9jYWxUYyAqIHByLnRkO1xuICAgICAgICAgICAgICByMi50ZCArPSB0aGlzLl9sb2NhbFRiICogcHIudGM7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSB0aGlzLl93b3JsZENvbnRleHQ7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuY3R4LnVwZGF0ZVRyZWVPcmRlciA9PT0gLTEpIHtcbiAgICAgICAgICB0aGlzLmN0eC51cGRhdGVUcmVlT3JkZXIgPSB0aGlzLl91cGRhdGVUcmVlT3JkZXIgKyAxO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuX3VwZGF0ZVRyZWVPcmRlciA9IHRoaXMuY3R4LnVwZGF0ZVRyZWVPcmRlcisrO1xuICAgICAgICB9XG4gICAgICAgIGNvbnN0IHVzZVJlbmRlclRvVGV4dHVyZSA9IHRoaXMuX3JlbmRlclRvVGV4dHVyZUVuYWJsZWQgJiYgdGhpcy5fdGV4dHVyaXplci5tdXN0UmVuZGVyVG9UZXh0dXJlKCk7XG4gICAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUgIT09IHVzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgIHRoaXMuX3JlY2FsYyB8PSAyICsgNDtcbiAgICAgICAgICByZWNhbGMgfD0gMjtcbiAgICAgICAgICBpZiAoIXRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci5yZWxlYXNlKCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSA9IHVzZVJlbmRlclRvVGV4dHVyZTtcbiAgICAgICAgY29uc3QgciA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgICAgIGNvbnN0IGJib3hXID0gdGhpcy5fZGltc1Vua25vd24gPyAyMDQ4IDogdGhpcy5fdztcbiAgICAgICAgY29uc3QgYmJveEggPSB0aGlzLl9kaW1zVW5rbm93biA/IDIwNDggOiB0aGlzLl9oO1xuICAgICAgICBsZXQgc3gsIHN5LCBleCwgZXk7XG4gICAgICAgIGNvbnN0IHJDb21wbGV4ID0gci50YiAhPT0gMCB8fCByLnRjICE9PSAwIHx8IHIudGEgPCAwIHx8IHIudGQgPCAwO1xuICAgICAgICBpZiAockNvbXBsZXgpIHtcbiAgICAgICAgICBzeCA9IE1hdGgubWluKDAsIGJib3hXICogci50YSwgYmJveFcgKiByLnRhICsgYmJveEggKiByLnRiLCBiYm94SCAqIHIudGIpICsgci5weDtcbiAgICAgICAgICBleCA9IE1hdGgubWF4KDAsIGJib3hXICogci50YSwgYmJveFcgKiByLnRhICsgYmJveEggKiByLnRiLCBiYm94SCAqIHIudGIpICsgci5weDtcbiAgICAgICAgICBzeSA9IE1hdGgubWluKDAsIGJib3hXICogci50YywgYmJveFcgKiByLnRjICsgYmJveEggKiByLnRkLCBiYm94SCAqIHIudGQpICsgci5weTtcbiAgICAgICAgICBleSA9IE1hdGgubWF4KDAsIGJib3hXICogci50YywgYmJveFcgKiByLnRjICsgYmJveEggKiByLnRkLCBiYm94SCAqIHIudGQpICsgci5weTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBzeCA9IHIucHg7XG4gICAgICAgICAgZXggPSByLnB4ICsgci50YSAqIGJib3hXO1xuICAgICAgICAgIHN5ID0gci5weTtcbiAgICAgICAgICBleSA9IHIucHkgKyByLnRkICogYmJveEg7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX2RpbXNVbmtub3duICYmIChyQ29tcGxleCB8fCB0aGlzLl9sb2NhbFRhIDwgMSB8fCB0aGlzLl9sb2NhbFRiIDwgMSkpIHtcbiAgICAgICAgICBjb25zdCBueCA9IHRoaXMuX3ggKiBwci50YSArIHRoaXMuX3kgKiBwci50YiArIHByLnB4O1xuICAgICAgICAgIGNvbnN0IG55ID0gdGhpcy5feCAqIHByLnRjICsgdGhpcy5feSAqIHByLnRkICsgcHIucHk7XG4gICAgICAgICAgaWYgKG54IDwgc3gpXG4gICAgICAgICAgICBzeCA9IG54O1xuICAgICAgICAgIGlmIChueSA8IHN5KVxuICAgICAgICAgICAgc3kgPSBueTtcbiAgICAgICAgICBpZiAobnggPiBleClcbiAgICAgICAgICAgIGV4ID0gbng7XG4gICAgICAgICAgaWYgKG55ID4gZXkpXG4gICAgICAgICAgICBleSA9IG55O1xuICAgICAgICB9XG4gICAgICAgIGlmIChyZWNhbGMgJiA2IHx8ICF0aGlzLl9zY2lzc29yKSB7XG4gICAgICAgICAgaWYgKHRoaXMuX2NsaXBwaW5nICYmIHIuaXNTcXVhcmUoKSkge1xuICAgICAgICAgICAgY29uc3QgYXJlYSA9IHRoaXMuX3BhcmVudC5fdXNlUmVuZGVyVG9UZXh0dXJlID8gdGhpcy5fcGFyZW50Ll92aWV3cG9ydCA6IHRoaXMuX3BhcmVudC5fc2Npc3NvcjtcbiAgICAgICAgICAgIGlmIChhcmVhKSB7XG4gICAgICAgICAgICAgIGNvbnN0IGx4ID0gTWF0aC5tYXgoYXJlYVswXSwgc3gpO1xuICAgICAgICAgICAgICBjb25zdCBseSA9IE1hdGgubWF4KGFyZWFbMV0sIHN5KTtcbiAgICAgICAgICAgICAgdGhpcy5fc2Npc3NvciA9IFtcbiAgICAgICAgICAgICAgICBseCxcbiAgICAgICAgICAgICAgICBseSxcbiAgICAgICAgICAgICAgICBNYXRoLm1pbihhcmVhWzJdICsgYXJlYVswXSwgZXgpIC0gbHgsXG4gICAgICAgICAgICAgICAgTWF0aC5taW4oYXJlYVszXSArIGFyZWFbMV0sIGV5KSAtIGx5XG4gICAgICAgICAgICAgIF07XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICB0aGlzLl9zY2lzc29yID0gW3N4LCBzeSwgZXggLSBzeCwgZXkgLSBzeV07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX3NjaXNzb3IgPSB0aGlzLl9wYXJlbnQuX3VzZVJlbmRlclRvVGV4dHVyZSA/IHRoaXMuX3BhcmVudC5fdmlld3BvcnQgOiB0aGlzLl9wYXJlbnQuX3NjaXNzb3I7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9ib3VuZHNNYXJnaW4pIHtcbiAgICAgICAgICB0aGlzLl9yZWNCb3VuZHNNYXJnaW4gPSB0aGlzLl9ib3VuZHNNYXJnaW47XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhpcy5fcmVjQm91bmRzTWFyZ2luID0gdGhpcy5fcGFyZW50Ll9yZWNCb3VuZHNNYXJnaW47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX29uQWZ0ZXJDYWxjcykge1xuICAgICAgICAgIGlmICh0aGlzLl9vbkFmdGVyQ2FsY3ModGhpcy5lbGVtZW50KSkge1xuICAgICAgICAgICAgaWYgKHJDb21wbGV4KSB7XG4gICAgICAgICAgICAgIHN4ID0gTWF0aC5taW4oMCwgYmJveFcgKiByLnRhLCBiYm94VyAqIHIudGEgKyBiYm94SCAqIHIudGIsIGJib3hIICogci50YikgKyByLnB4O1xuICAgICAgICAgICAgICBleCA9IE1hdGgubWF4KDAsIGJib3hXICogci50YSwgYmJveFcgKiByLnRhICsgYmJveEggKiByLnRiLCBiYm94SCAqIHIudGIpICsgci5weDtcbiAgICAgICAgICAgICAgc3kgPSBNYXRoLm1pbigwLCBiYm94VyAqIHIudGMsIGJib3hXICogci50YyArIGJib3hIICogci50ZCwgYmJveEggKiByLnRkKSArIHIucHk7XG4gICAgICAgICAgICAgIGV5ID0gTWF0aC5tYXgoMCwgYmJveFcgKiByLnRjLCBiYm94VyAqIHIudGMgKyBiYm94SCAqIHIudGQsIGJib3hIICogci50ZCkgKyByLnB5O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgc3ggPSByLnB4O1xuICAgICAgICAgICAgICBleCA9IHIucHggKyByLnRhICogYmJveFc7XG4gICAgICAgICAgICAgIHN5ID0gci5weTtcbiAgICAgICAgICAgICAgZXkgPSByLnB5ICsgci50ZCAqIGJib3hIO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRoaXMuX2RpbXNVbmtub3duICYmIChyQ29tcGxleCB8fCB0aGlzLl9sb2NhbFRhIDwgMSB8fCB0aGlzLl9sb2NhbFRiIDwgMSkpIHtcbiAgICAgICAgICAgICAgY29uc3QgbnggPSB0aGlzLl94ICogcHIudGEgKyB0aGlzLl95ICogcHIudGIgKyBwci5weDtcbiAgICAgICAgICAgICAgY29uc3QgbnkgPSB0aGlzLl94ICogcHIudGMgKyB0aGlzLl95ICogcHIudGQgKyBwci5weTtcbiAgICAgICAgICAgICAgaWYgKG54IDwgc3gpXG4gICAgICAgICAgICAgICAgc3ggPSBueDtcbiAgICAgICAgICAgICAgaWYgKG55IDwgc3kpXG4gICAgICAgICAgICAgICAgc3kgPSBueTtcbiAgICAgICAgICAgICAgaWYgKG54ID4gZXgpXG4gICAgICAgICAgICAgICAgZXggPSBueDtcbiAgICAgICAgICAgICAgaWYgKG55ID4gZXkpXG4gICAgICAgICAgICAgICAgZXkgPSBueTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX3BhcmVudC5fb3V0T2ZCb3VuZHMgPT09IDIpIHtcbiAgICAgICAgICB0aGlzLl9vdXRPZkJvdW5kcyA9IDI7XG4gICAgICAgICAgaWYgKHRoaXMuX3dpdGhpbkJvdW5kc01hcmdpbikge1xuICAgICAgICAgICAgdGhpcy5fd2l0aGluQm91bmRzTWFyZ2luID0gZmFsc2U7XG4gICAgICAgICAgICB0aGlzLmVsZW1lbnQuX2Rpc2FibGVXaXRoaW5Cb3VuZHNNYXJnaW4oKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHJlY2FsYyAmIDYpIHtcbiAgICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMDtcbiAgICAgICAgICAgIGxldCB3aXRoaW5NYXJnaW4gPSB0cnVlO1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9yZW5kZXJUb1RleHR1cmVFbmFibGVkIHx8ICF0aGlzLl90ZXh0dXJpemVyIHx8ICF0aGlzLl90ZXh0dXJpemVyLnJlbmRlck9mZnNjcmVlbikge1xuICAgICAgICAgICAgICBpZiAodGhpcy5fc2Npc3NvciAmJiAodGhpcy5fc2Npc3NvclsyXSA8PSAwIHx8IHRoaXMuX3NjaXNzb3JbM10gPD0gMCk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c2Npc3NvclsyXSArIHRoaXMuX3JlY0JvdW5kc01hcmdpblswXSB8fCBzeSA+IHRoaXMuX3NjaXNzb3JbMV0gKyB0aGlzLl9zY2lzc29yWzNdICsgdGhpcy5fcmVjQm91bmRzTWFyZ2luWzFdKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgd2l0aGluTWFyZ2luID0gIShleCA8IHRoaXMuX3NjaXNzb3JbMF0gLSAxMDAgfHwgZXkgPCB0aGlzLl9zY2lzc29yWzFdIC0gMTAwIHx8IHN4ID4gdGhpcy5fc2Npc3NvclswXSArIHRoaXMuX3NjaXNzb3JbMl0gKyAxMDAgfHwgc3kgPiB0aGlzLl9zY2lzc29yWzFdICsgdGhpcy5fc2Npc3NvclszXSArIDEwMCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmICh3aXRoaW5NYXJnaW4gJiYgdGhpcy5fb3V0T2ZCb3VuZHMgPT09IDIpIHtcbiAgICAgICAgICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4gIT09IHdpdGhpbk1hcmdpbikge1xuICAgICAgICAgICAgICB0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4gPSB3aXRoaW5NYXJnaW47XG4gICAgICAgICAgICAgIGlmICh0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4pIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9oYXNVcGRhdGVzID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICBjb25zdCByZWNhbGMyID0gdGhpcy5fcmVjYWxjO1xuICAgICAgICAgICAgICAgIHRoaXMuX3JlY2FsYyA9IDA7XG4gICAgICAgICAgICAgICAgdGhpcy5lbGVtZW50Ll9lbmFibGVXaXRoaW5Cb3VuZHNNYXJnaW4oKTtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fcmVjYWxjKSB7XG4gICAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy51cGRhdGUoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdGhpcy5fcmVjYWxjID0gcmVjYWxjMjtcbiAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLmVsZW1lbnQuX2Rpc2FibGVXaXRoaW5Cb3VuZHNNYXJnaW4oKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlKSB7XG4gICAgICAgICAgaWYgKHRoaXMuX3ZpZXdwb3J0KSB7XG4gICAgICAgICAgICB0aGlzLl92aWV3cG9ydFsyXSA9IGJib3hXO1xuICAgICAgICAgICAgdGhpcy5fdmlld3BvcnRbM10gPSBiYm94SDtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fdmlld3BvcnQgPSBbMCwgMCwgYmJveFcsIGJib3hIXTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fcFJlY2FsYyA9IHRoaXMuX3JlY2FsYyAmIDEzNTtcbiAgICAgICAgdGhpcy5fcmVjYWxjID0gMDtcbiAgICAgICAgdGhpcy5faGFzVXBkYXRlcyA9IGZhbHNlO1xuICAgICAgICBpZiAodGhpcy5fb3V0T2ZCb3VuZHMgPCAyKSB7XG4gICAgICAgICAgaWYgKHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3dvcmxkQ29udGV4dC5pc0lkZW50aXR5KCkpIHtcbiAgICAgICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IHRoaXMuX3dvcmxkQ29udGV4dDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSBFbGVtZW50Q29yZUNvbnRleHQuSURFTlRJVFk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9jaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0udXBkYXRlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSByO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbltpXS5faGFzVXBkYXRlcykge1xuICAgICAgICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLnVwZGF0ZSgpO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLl9yZWNhbGMgfD0gdGhpcy5fcFJlY2FsYztcbiAgICAgICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS51cGRhdGVPdXRPZkJvdW5kcygpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9vbkFmdGVyVXBkYXRlKSB7XG4gICAgICAgICAgdGhpcy5fb25BZnRlclVwZGF0ZSh0aGlzLmVs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zKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICBpZiAodGhpcy5fekNvbnRleHRVc2FnZSkge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl96SW5kZXhlZENoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuW2ldLnJlbmRlcigpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW5baV0uX3pJbmRleCA9PT0gMCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLnJlbmRlcigpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIF9yZW5kZXJBZHZhbmNlZCgpIHtcbiAgICAgIGNvbnN0IGhhc1JlbmRlclVwZGF0ZXMgPSB0aGlzLl9oYXNSZW5kZXJVcGRhdGVzO1xuICAgICAgdGhpcy5faGFzUmVuZGVyVXBkYXRlcyA9IDA7XG4gICAgICBpZiAodGhpcy5felNvcnQpIHtcbiAgICAgICAgdGhpcy5zb3J0WkluZGV4ZWRDaGlsZHJlbigpO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMuX291dE9mQm91bmRzIDwgMiAmJiB0aGlzLl9yZW5kZXJDb250ZXh0LmFscGhhKSB7XG4gICAgICAgIGxldCByZW5kZXJTdGF0ZSA9IHRoaXMucmVuZGVyU3RhdGU7XG4gICAgICAgIGxldCBtdXN0UmVuZGVyQ2hpbGRyZW4gPSB0cnVlO1xuICAgICAgICBsZXQgcmVuZGVyVGV4dHVyZUluZm87XG4gICAgICAgIGxldCBwcmV2UmVuZGVyVGV4dHVyZUluZm87XG4gICAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICBpZiAodGhpcy5fdyA9PT0gMCB8fCB0aGlzLl9oID09PSAwKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgfSBlbHNlIGlmICghdGhpcy5fdGV4dHVyaXplci5oYXNSZW5kZXJUZXh0dXJlKCkgfHwgaGFzUmVuZGVyVXBkYXRlcyA+PSAzKSB7XG4gICAgICAgICAgICB0aGlzLmN0eC5yZW5kZXJUb1RleHR1cmVDb3VudCsrO1xuICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0U2hhZGVyKHJlbmRlclN0YXRlLmRlZmF1bHRTaGFkZXIsIHRoaXMpO1xuICAgICAgICAgICAgcHJldlJlbmRlclRleHR1cmVJbmZvID0gcmVuZGVyU3RhdGUucmVuZGVyVGV4dHVyZUluZm87XG4gICAgICAgICAgICByZW5kZXJUZXh0dXJlSW5mbyA9IHtcbiAgICAgICAgICAgICAgbmF0aXZlVGV4dHVyZTogbnVsbCxcbiAgICAgICAgICAgICAgb2Zmc2V0OiAwLFxuICAgICAgICAgICAgICB3OiB0aGlzLl93LFxuICAgICAgICAgICAgICBoOiB0aGlzLl9oLFxuICAgICAgICAgICAgICBlbXB0eTogdHJ1ZSxcbiAgICAgICAgICAgICAgY2xlYXJlZDogZmFsc2UsXG4gICAgICAgICAgICAgIGlnbm9yZTogZmFsc2UsXG4gICAgICAgICAgICAgIGNhY2hlOiBmYWxzZVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmICh0aGlzLl90ZXh0dXJpemVyLmhhc1Jlc3VsdFRleHR1cmUoKSB8fCAhcmVuZGVyU3RhdGUuaXNDYWNoaW5nVGV4dHVyaXplciAmJiBoYXNSZW5kZXJVcGRhdGVzIDwgMykge1xuICAgICAgICAgICAgICByZW5kZXJUZXh0dXJlSW5mby5jYWNoZSA9IHRydWU7XG4gICAgICAgICAgICAgIHJlbmRlclN0YXRlLmlzQ2FjaGluZ1RleHR1cml6ZXIgPSB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKCF0aGlzLl90ZXh0dXJpemVyLmhhc1Jlc3VsdFRleHR1cmUoKSkge1xuICAgICAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLnJlbGVhc2VSZW5kZXJUZXh0dXJlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRSZW5kZXJUZXh0dXJlSW5mbyhyZW5kZXJUZXh0dXJlSW5mbyk7XG4gICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRTY2lzc29yKG51bGwpO1xuICAgICAgICAgICAgaWYgKHRoaXMuX2Rpc3BsYXllZFRleHR1cmVTb3VyY2UpIHtcbiAgICAgICAgICAgICAgbGV0IHIgPSB0aGlzLl9yZW5kZXJDb250ZXh0O1xuICAgICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gRWxlbWVudENvcmVDb250ZXh0LklERU5USVRZO1xuICAgICAgICAgICAgICB0aGlzLnJlbmRlclN0YXRlLmFkZFF1YWQodGhpcyk7XG4gICAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSByO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBtdXN0UmVuZGVyQ2hpbGRyZW4gPSBmYWxzZTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHRoaXMuX291dE9mQm91bmRzID09PSAwICYmIHRoaXMuX2Rpc3BsYXllZFRleHR1cmVTb3VyY2UpIHtcbiAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFNoYWRlcih0aGlzLmFjdGl2ZVNoYWRlciwgdGhpcy5fc2hhZGVyT3duZXIpO1xuICAgICAgICAgICAgcmVuZGVyU3Rhd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luZm8uZW1wdHkpIHtcbiAgICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci5yZWxlYXNlUmVuZGVyVGV4dHVyZSgpO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChyZW5kZXJUZXh0dXJlSW5mby5uYXRpdmVUZXh0dXJlKSB7XG4gICAgICAgICAgICAgIHRoaXMuX3RleHR1cml6ZXIucmV1c2VUZXh0dXJlQXNSZW5kZXJUZXh0dXJlKHJlbmRlclRleHR1cmVJbmZvLm5hdGl2ZVRleHR1cmUpO1xuICAgICAgICAgICAgICByZW5kZXJUZXh0dXJlSW5mby5pZ25vcmUgPSB0cnVlO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgaWYgKHRoaXMuX3RleHR1cml6ZXIucmVuZGVyVGV4dHVyZVJldXNlZCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3RleHR1cml6ZXIucmVsZWFzZVJlbmRlclRleHR1cmUoKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICByZW5kZXJUZXh0dXJlSW5mby5uYXRpdmVUZXh0dXJlID0gdGhpcy5fdGV4dHVyaXplci5nZXRSZW5kZXJUZXh0dXJlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRSZW5kZXJUZXh0dXJlSW5mbyhwcmV2UmVuZGVyVGV4dHVyZUluZm8pO1xuICAgICAgICAgICAgdXBkYXRlUmVzdWx0VGV4dHVyZSA9IHRydWU7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmICghdGhpcy5fdGV4dHVyaXplci5lbXB0eSkge1xuICAgICAgICAgICAgbGV0IHJlc3VsdFRleHR1cmUgPSB0aGlzLl90ZXh0dXJpemVyLmdldFJlc3VsdFRleHR1cmUoKTtcbiAgICAgICAgICAgIGlmICh1cGRhdGVSZXN1bHRUZXh0dXJlKSB7XG4gICAgICAgICAgICAgIGlmIChyZXN1bHRUZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgcmVzdWx0VGV4dHVyZS51cGRhdGUgPSByZW5kZXJTdGF0ZS5zdGFnZS5mcmFtZUNvdW50ZXI7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci51cGRhdGVSZXN1bHRUZXh0dXJlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoIXRoaXMuX3RleHR1cml6ZXIucmVuZGVyT2Zmc2NyZWVuKSB7XG4gICAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFNoYWRlcih0aGlzLmFjdGl2ZVNoYWRlciwgdGhpcy5fc2hhZGVyT3duZXIpO1xuICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRTY2lzc29yKHRoaXMuX3NjaXNzb3IpO1xuICAgICAgICAgICAgICBjb25zdCBjYWNoZSA9ICFyZW5kZXJUZXh0dXJlSW5mbyB8fCByZW5kZXJUZXh0dXJlSW5mby5jYWNoZTtcbiAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0VGV4dHVyaXplcih0aGlzLl90ZXh0dXJpemVyLCBjYWNoZSk7XG4gICAgICAgICAgICAgIHRoaXMuX3N0YXNoVGV4Q29vcmRzKCk7XG4gICAgICAgICAgICAgIGlmICghdGhpcy5fdGV4dHVyaXplci5jb2xvcml6ZSlcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGFzaENvbG9ycygpO1xuICAgICAgICAgICAgICB0aGlzLnJlbmRlclN0YXRlLmFkZFF1YWQodGhpcywgdHJ1ZSk7XG4gICAgICAgICAgICAgIGlmICghdGhpcy5fdGV4dHVyaXplci5jb2xvcml6ZSlcbiAgICAgICAgICAgICAgICB0aGlzLl91bnN0YXNoQ29sb3JzKCk7XG4gICAgICAgICAgICAgIHRoaXMuX3Vuc3Rhc2hUZXhDb29yZHMoKTtcbiAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0VGV4dHVyaXplcihudWxsKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHJlbmRlclRleHR1cmVJbmZvICYmIHJlbmRlclRleHR1cmVJbmZvLmNhY2hlKSB7XG4gICAgICAgICAgcmVuZGVyU3RhdGUuaXNDYWNoaW5nVGV4dHVyaXplciA9IGZhbHNlO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIGdldCB6U29ydCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl96U29ydDtcbiAgICB9XG4gICAgc29ydFpJbmRleGVkQ2hpbGRyZW4oKSB7XG4gICAgICBjb25zdCBuID0gdGhpcy5fekluZGV4ZWRDaGlsZHJlbi5sZW5ndGg7XG4gICAgICBsZXQgcHRyID0gMDtcbiAgICAgIGNvbnN0IGEgPSB0aGlzLl96SW5kZXhlZENoaWxkcmVuO1xuICAgICAgY29uc3QgYiA9IFtdO1xuICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgaWYgKGFbaV0uX3pQYXJlbnQgPT09IHRoaXMpIHtcbiAgICAgICAgICBpZiAoYVtpXS5fekluZGV4UmVzb3J0KSB7XG4gICAgICAgICAgICBiLnB1c2goYVtpXSk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChwdHIgIT09IGkpIHtcbiAgICAgICAgICAgICAgYVtwdHJdID0gYVtpXTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHB0cisrO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgY29uc3QgbSA9IGIubGVuZ3RoO1xuICAgICAgaWYgKG0pIHtcbiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBtOyBqKyspIHtcbiAgICAgICAgICBiW2pdLl96SW5kZXhSZXNvcnQgPSBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgICBiLnNvcnQoRWxlbWVudENvcmUuc29ydFpJbmRleGVkQ2hpbGRyZW4pO1xuICAgICAgICBjb25zdCBuMiA9IHB0cjtcbiAgICAgICAgaWYgKCFuMikge1xuICAgICAgICAgIHB0ciA9IDA7XG4gICAgICAgICAgbGV0IGogPSAwO1xuICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgIGFbcHRyKytdID0gYltqKytdO1xuICAgICAgICAgIH0gd2hpbGUgKGogPCBtKTtcbiAgICAgICAgICBpZiAoYS5sZW5ndGggPiBwdHIpIHtcbiAgICAgICAgICAgIGEuc3BsaWNlKHB0cik7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHB0ciA9IDA7XG4gICAgICAgICAgbGV0IGkgPSAwO1xuICAgICAgICAgIGxldCBqID0gMDtcbiAgICAgICAgICBjb25zdCBtZXJnZVJlc3VsdCA9IFtdO1xuICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgIGNvbnN0IHYgPSBhW2ldLl96SW5kZXggPT09IGJbal0uX3pJbmRleCA/IGFbaV0uX3VwZGF0ZVRyZWVPcmRlciAtIGJbal0uX3VwZGF0ZVRyZWVPcmRlciA6IGFbaV0uX3pJbmRleCAtIGJbal0uX3pJbmRleDtcbiAgICAgICAgICAgIGNvbnN0IGFkZCA9IHYgPiAwID8gYltqKytdIDogYVtpKytdO1xuICAgICAgICAgICAgaWYgKHB0ciA9PT0gMCB8fCBtZXJnZVJlc3VsdFtwdHIgLSAxXSAhPT0gYWRkKSB7XG4gICAgICAgICAgICAgIG1lcmdlUmVzdWx0W3B0cisrXSA9IGFkZDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChpID49IG4yKSB7XG4gICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICBjb25zdCBhZGQyID0gYltqKytdO1xuICAgICAgICAgICAgICAgIGlmIChwdHIgPT09IDAgfHwgbWVyZ2VSZXN1bHRbcHRyIC0gMV0gIT09IGFkZDIpIHtcbiAgICAgICAgICAgICAgICAgIG1lcmdlUmVzdWx0W3B0cisrXSA9IGFkZDI7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9IHdoaWxlIChqIDwgbSk7XG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChqID49IG0pIHtcbiAgICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgIGNvbnN0IGFkZDIgPSBhW2krK107XG4gICAgICAgICAgICAgICAgaWYgKHB0ciA9PT0gMCB8fCBtZXJnZVJlc3VsdFtwdHIgLSAxXSAhPT0gYWRkMikge1xuICAgICAgICAgICAgICAgICAgbWVyZ2VSZXN1bHRbcHRyKytdID0gYWRkMjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH0gd2hpbGUgKGkgPCBuMik7XG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gd2hpbGUgKHRydWUpO1xuICAgICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4gPSBtZXJnZVJlc3VsdDtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKGEubGVuZ3RoID4gcHRyKSB7XG4gICAgICAgICAgYS5zcGxpY2UocHRyKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgdGhpcy5felNvcnQgPSBmYWxzZTtcbiAgICB9XG4gICAgZ2V0IGxvY2FsVGEoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fbG9jYWxUYTtcbiAgICB9XG4gICAgZ2V0IGxvY2FsVGIoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fbG9jYWxUYjtcbiAgICB9XG4gICAgZ2V0IGxvY2FsVGMoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fbG9jYWxUYztcbiAgICB9XG4gICAgZ2V0IGxvY2FsVGQoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fbG9jYWxUZDtcbiAgICB9XG4gICAgZ2V0IGVsZW1lbnQoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fZWxlbWVudDtcbiAgICB9XG4gICAgZ2V0IHJlbmRlclVwZGF0ZXMoKSB7XG4gICAgICByZXR1cm4gdGhpcy5faGFzUmVuZGVyVXBkYXRlcztcbiAgICB9XG4gICAgZ2V0IHRleHR1cml6ZXIoKSB7XG4gICAgICBpZiAoIXRoaXMuX3RleHR1cml6ZXIpIHtcbiAgICAgICAgdGhpcy5fdGV4dHVyaXplciA9IG5ldyBFbGVtZW50VGV4dHVyaXplcih0aGlzKTtcbiAgICAgIH1cbiAgICAgIHJldHVybiB0aGlzLl90ZXh0dXJpemVyO1xuICAgIH1cbiAgICBnZXRDb3JuZXJQb2ludHMoKSB7XG4gICAgICBsZXQgdyA9IHRoaXMuX3dvcmxkQ29udGV4dDtcbiAgICAgIHJldHVybiBbXG4gICAgICAgIHcucHgsXG4gICAgICAgIHcucHksXG4gICAgICAgIHcucHggKyB0aGlzLl93ICogdy50YSxcbiAgICAgICAgdy5weSArIHRoaXMuX3cgKiB3LnRjLFxuICAgICAgICB3LnB4ICsgdGhpcy5fdyAqIHcudGEgKyB0aGlzLl9oICogdy50YixcbiAgICAgICAgdy5weSArIHRoaXMuX3cgKiB3LnRjICsgdGhpcy5faCAqIHcudGQsXG4gICAgICAgIHcucHggKyB0aGlzLl9oICogdy50YixcbiAgICAgICAgdy5weSArIHRoaXMuX2ggKiB3LnRkXG4gICAgICBdO1xuICAgIH1cbiAgICBnZXRSZW5kZXJUZXh0dXJlQ29vcmRzKHJlbFgsIHJlbFkpIHtcbiAgICAgIGxldCByID0gdGhpcy5fcmVuZGVyQ29udGV4dDtcbiAgICAgIHJldHVybiBbXG4gICAgICAgIHIucHggKyByLnRhICogcmVsWCArIHIudGIgKiByZWxZLFxuICAgICAgICByLnB5ICsgci50YyAqIHJlbFggKyByLnRkICogcmVsWVxuICAgICAgXTtcbiAgICB9XG4gICAgZ2V0QWJzb2x1dGVDb29yZHMocmVsWCwgcmVsWSkge1xuICAgICAgbGV0IHcgPSB0aGlzLl9yZW5kZXJD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ByZXR1cm4gdHJ1ZTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXSA9PT0gbGlzdGVuZXIgfHwgdGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXS5fX29yaWdpbmFsRnVuYyA9PT0gbGlzdGVuZXIpIHtcbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cbiAgICBvZmYobmFtZSwgbGlzdGVuZXIpIHtcbiAgICAgIGlmICh0aGlzLl9oYXNFdmVudExpc3RlbmVycykge1xuICAgICAgICBjb25zdCBjdXJyZW50ID0gdGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXTtcbiAgICAgICAgaWYgKGN1cnJlbnQpIHtcbiAgICAgICAgICBpZiAoY3VycmVudCA9PT0gRXZlbnRFbWl0dGVyLmNvbWJpbmVyKSB7XG4gICAgICAgICAgICBjb25zdCBsaXN0ZW5lcnMgPSB0aGlzLl9ldmVudExpc3RlbmVyc1tuYW1lXTtcbiAgICAgICAgICAgIGxldCBpbmRleCA9IGxpc3RlbmVycy5pbmRleE9mKGxpc3RlbmVyKTtcbiAgICAgICAgICAgIGlmIChpbmRleCA+PSAwKSB7XG4gICAgICAgICAgICAgIGxpc3RlbmVycy5zcGxpY2UoaW5kZXgsIDEpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaW5kZXggPSBsaXN0ZW5lcnMubWFwKChsKSA9PiBsLl9fb3JpZ2luYWxGdW5jKS5pbmRleE9mKGxpc3RlbmVyKTtcbiAgICAgICAgICAgIGlmIChpbmRleCA+PSAwKSB7XG4gICAgICAgICAgICAgIGxpc3RlbmVycy5zcGxpY2UoaW5kZXgsIDEpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKGxpc3RlbmVycy5sZW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gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHJldHVybiBzb3VyY2U7XG4gICAgfVxuICAgIF9nZXRSZXVzYWJsZVRleHR1cmVTb3VyY2UobG9va3VwSWQgPSB0aGlzLl9nZXRMb29rdXBJZCgpKSB7XG4gICAgICBpZiAodGhpcy5fZ2V0SXNWYWxpZCgpKSB7XG4gICAgICAgIGlmIChsb29rdXBJZCkge1xuICAgICAgICAgIHJldHVybiB0aGlzLm1hbmFnZXIuZ2V0UmV1c2FibGVUZXh0dXJlU291cmNlKGxvb2t1cElkKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIG51bGw7XG4gICAgfVxuICAgIF9yZXBsYWNlVGV4dHVyZVNvdXJjZShuZXdTb3VyY2UgPSBudWxsKSB7XG4gICAgICBsZXQgb2xkU291cmNlID0gdGhpcy5fc291cmNlO1xuICAgICAgdGhpcy5fc291cmNlID0gbmV3U291cmNlO1xuICAgICAgaWYgKHRoaXMuZWxlbWVudHMuc2l6ZSkge1xuICAgICAgICBpZiAob2xkU291cmNlKSB7XG4gICAgICAgICAgaWYgKHRoaXMuX2FjdGl2ZUNvdW50KSB7XG4gICAgICAgICAgICBvbGRTb3VyY2UuZGVjQWN0aXZlVGV4dHVyZUNvdW50KCk7XG4gICAgICAgICAgfVxuICAgICAgICAgIG9sZFNvdXJjZS5yZW1vdmVUZXh0dXJlKHRoaXMpO1xuICAgICAgICAgIGlmICh0aGlzW1widGV4dFwiXSAmJiAhb2xkU291cmNlLmlzVXNlZCgpKSB7XG4gICAgICAgICAgICB0aGlzLm1hbmFnZXIuZnJlZVRleHR1cmVTb3VyY2Uob2xkU291cmNlKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKG5ld1NvdXJjZSkge1xuICAgICAgICAgIG5ld1NvdXJjZS5hZGRUZXh0dXJlKHRoaXMpO1xuICAgICAgICAgIGlmICh0aGlzLl9hY3RpdmVDb3VudCkge1xuICAgICAgICAgICAgbmV3U291cmNlLmluY0FjdGl2ZVRleHR1cmVDb3VudCgpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgaWYgKHRoaXMuaXNVc2VkKCkpIHtcbiAgICAgICAgaWYgKG5ld1NvdXJjZSkge1xuICAgICAgICAgIGlmIChuZXdTb3VyY2UuaXNMb2FkZWQoKSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3Jlc2l6ZU1vZGUpIHtcbiAgICAgICAgICAgICAgdGhpcy5fYXBwbHlSZXNpemVNb2RlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLmVsZW1lbnRzLmZvckVhY2goKGVsZW1lbnQpID0+IHtcbiAgICAgICAgICAgICAgaWYgKGVsZW1lbnQuYWN0aXZlKSB7XG4gICAgICAgICAgICAgICAgZWxlbWVudC5fc2V0RGlzcGxheWVkVGV4dHVyZSh0aGlzKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGNvbnN0IGxvYWRFcnJvciA9IG5ld1NvdXJjZS5sb2FkRXJyb3I7XG4gICAgICAgICAgICBpZiAobG9hZEVycm9yKSB7XG4gICAgICAgICAgICAgIHRoaXMuZWxlbWVudHMuZm9yRWFjaCgoZWxlbWVudCkgPT4ge1xuICAgICAgICAgICAgICAgIGlmIChlbGVtZW50LmFjdGl2ZSkge1xuICAgICAgICAgICAgICAgICAgZWxlbWVudC5vblRleHR1cmVTb3VyY2VMb2FkRXJyb3IobG9hZEVycm9yKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB0aGlzLmVsZW1lbnRzLmZvckVhY2goKGVsZW1lbnQpID0+IHtcbiAgICAgICAgICAgIGlmIChlbGVtZW50LmFjdGl2ZSkge1xuICAgICAgICAgICAgICB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uZWxlbWVudHMuZm9yRWFjaChmdW5jdGlvbihlbGVtZW50KSB7XG4gICAgICAgIGlmIChlbGVtZW50LmRpc3BsYXllZFRleHR1cmUgPT09IHNlbGYyKSB7XG4gICAgICAgICAgZWxlbWVudC5vblByZWNpc2lvbkNoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgICAgfSk7XG4gICAgfVxuICAgIGdldE5vbkRlZmF1bHRzKCkge1xuICAgICAgbGV0IG5vbkRlZmF1bHRzID0ge307XG4gICAgICBub25EZWZhdWx0c1tcInR5cGVcIl0gPSB0aGlzLmNvbnN0cnVjdG9yLm5hbWU7XG4gICAgICBpZiAodGhpcy54ICE9PSAwKVxuICAgICAgICBub25EZWZhdWx0c1tcInhcIl0gPSB0aGlzLng7XG4gICAgICBpZiAodGhpcy55ICE9PSAwKVxuICAgICAgICBub25EZWZhdWx0c1tcInlcIl0gPSB0aGlzLnk7XG4gICAgICBpZiAodGhpcy53ICE9PSAwKVxuICAgICAgICBub25EZWZhdWx0c1tcIndcIl0gPSB0aGlzLnc7XG4gICAgICBpZiAodGhpcy5oICE9PSAwKVxuICAgICAgICBub25EZWZhdWx0c1tcImhcIl0gPSB0aGlzLmg7XG4gICAgICBpZiAodGhpcy5wcmVjaXNpb24gIT09IDEpXG4gICAgICAgIG5vbkRlZmF1bHRzW1wicHJlY2lzaW9uXCJdID0gdGhpcy5wcmVjaXNpb247XG4gICAgICByZXR1cm4gbm9uRGVmYXVsdHM7XG4gICAgfVxuICAgIGdldCBweCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl94O1xuICAgIH1cbiAgICBnZXQgcHkoKSB7XG4gICAgICByZXR1cm4gdGhpcy5feTtcbiAgICB9XG4gICAgZ2V0IHB3KCkge1xuICAgICAgcmV0dXJuIHRoaXMuX3c7XG4gICAgfVxuICAgIGdldCBwaCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl9oO1xuICAgIH1cbiAgICBnZXQgeCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl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R0aW5ncy5mb250U2l6ZSxcbiAgICAgICAgICB0aGlzLmdldFByZWNpc2lvbigpLFxuICAgICAgICAgIHRoaXMuX3N0YWdlLmdldE9wdGlvbihcImRlZmF1bHRGb250RmFjZVwiKVxuICAgICAgICApO1xuICAgICAgICB0cnkge1xuICAgICAgICAgIGlmICghZG9jdW1lbnQuZm9udHMuY2hlY2soZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpKSB7XG4gICAgICAgICAgICByZXR1cm4gZG9jdW1lbnQuZm9udHMubG9hZChmb250U2V0dGluZywgdGhpcy5fc2V0dGluZ3MudGV4dCkuY2F0Y2goKGVycikgPT4ge1xuICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJbTGlnaHRuaW5nXSBGb250IGxvYWQgZXJyb3JcIiwgZXJyLCBmb250U2V0dGluZyk7XG4gICAgICAgICAgICB9KS50aGVuKCgpID0+IHtcbiAgICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5mb250cy5jaGVjayhmb250U2V0dGluZywgdGhpcy5fc2V0dGluZ3MudGV4dCkpIHtcbiAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJbTGlnaHRuaW5nXSBGb250IG5vdCBmb3VuZFwiLCBmb250U2V0dGluZyk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIENhbid0IGNoZWNrIGZvbnQgbG9hZGluZyBmb3IgXCIgKyBmb250U2V0dGluZyk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgZHJhdygpIHtcbiAgICAgIGNvbnN0IGxvYWRQcm9taXNlID0gdGhpcy5fbG9hZCgpO1xuICAgICAgaWYgKCFsb2FkUHJvbWlzZSkge1xuICAgICAgICByZXR1cm4gVXRpbHMkMS5pc1NwYXJrID8gdGhpcy5fc3RhZ2UucGx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tICYmIGxpbmVzSW5mby5uW2kgKyAxXSkge1xuICAgICAgICAgICAgaisrO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZW5kZXJJbmZvLnJlbWFpbmluZ1RleHQgPSBvdGhlckxpbmVzLmpvaW4oXCJcXG5cIik7XG4gICAgICAgIHJlbmRlckluZm8ubW9yZVRleHRMaW5lcyA9IHRydWU7XG4gICAgICAgIGxpbmVzID0gdXNlZExpbmVzO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcmVuZGVySW5mby5tb3JlVGV4dExpbmVzID0gZmFsc2U7XG4gICAgICAgIHJlbmRlckluZm8ucmVtYWluaW5nVGV4dCA9IFwiXCI7XG4gICAgICB9XG4gICAgICBsZXQgbWF4TGluZVdpZHRoID0gMDtcbiAgICAgIGxldCBsaW5lV2lkdGhzID0gW107XG4gICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxpbmVzLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgIGxldCBsaW5lV2lkdGggPSB0aGlzLm1lYXN1cmVUZXh0KGxpbmVzW2ldLCBsZXR0ZXJTcGFjaW5nKSArIChpID09PSAwID8gdGV4dEluZGVudCA6IDApO1xuICAgICAgICBsaW5lV2lkdGhzLnB1c2gobGluZVdpZHRoKTtcbiAgICAgICAgbWF4TGluZVdpZHRoID0gTWF0aC5tYXgobWF4TGluZVdpZHRoLCBsaW5lV2lkdGgpO1xuICAgICAgfVxuICAgICAgcmVuZGVySW5mby5saW5lV2lkdGhzID0gbGluZVdpZHRocztcbiAgICAgIGlmICghdykge1xuICAgICAgICB3aWR0aCA9IG1heExpbmVXaWR0aCArIHBhZGRpbmdMZWZ0ICsgcGFkZGluZ1JpZ2h0O1xuICAgICAgICBpbm5lcldpZHRoID0gbWF4TGluZVdpZHRoO1xuICAgICAgfVxuICAgICAgbGluZUhlaWdodCA9IGxpbmVIZWlnaHQgfHwgZm9udFNpemU7XG4gICAgICBsZXQgaGVpZ2h0O1xuICAgICAgaWYg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3VyZSh0ZXh0LCBsZXR0ZXJTcGFjaW5nLCByZW5kZXJJbmZvLmJhc2VGb250KTtcbiAgICAgIGlmIChyZW5kZXJJbmZvLnRleHRJbmRlbnQpIHtcbiAgICAgICAgdGV4dCA9IHRoaXMuaW5kZW50KHRleHQsIHJlbmRlckluZm8udGV4dEluZGVudCk7XG4gICAgICB9XG4gICAgICBpZiAocmVuZGVySW5mby53b3JkQnJlYWspIHtcbiAgICAgICAgdGV4dCA9IHRleHQucmVkdWNlKChhY2MsIHQpID0+IGFjYy5jb25jYXQodGhpcy53b3JkQnJlYWsodCwgd3JhcFdpZHRoLCByZW5kZXJJbmZvLmJhc2VGb250KSksIFtdKTtcbiAgICAgICAgdGhpcy5yZXNldEZvbnRTdHlsZSgpO1xuICAgICAgfVxuICAgICAgbGV0IHggPSBwYWRkaW5nTGVmdDtcbiAgICAgIGxldCBsaW5lTm8gPSAwO1xuICAgICAgZm9yIChjb25zdCB0IG9mIHRleHQpIHtcbiAgICAgICAgaWYgKHJlbmRlckluZm8ud29yZFdyYXAgJiYgeCArIHQud2lkdGggPiB3cmFwV2lkdGggfHwgdC50ZXh0ID09IFwiXFxuXCIpIHtcbiAgICAgICAgICB4ID0gcGFkZGluZ0xlZnQ7XG4gICAgICAgICAgbGluZU5vICs9IDE7XG4gICAgICAgIH1cbiAgICAgICAgdC5saW5lTm8gPSBsaW5lTm87XG4gICAgICAgIGlmICh0LnRleHQgPT0gXCJcXG5cIikge1xuICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICB9XG4gICAgICAgIHQueCA9IHg7XG4gICAgICAgIHggKz0gdC53aWR0aDtcbiAgICAgIH1cbiAgICAgIHJlbmRlckluZm8ubGluZU51bSA9IGxpbmVObyArIDE7XG4gICAgICBpZiAodGhpcy5fc2V0dGluZ3MuaCkge1xuICAgICAgICByZW5kZXJJbmZvLmggPSB0aGlzLl9zZXR0aW5ncy5oO1xuICAgICAgfSBlbHNlIGlmIChyZW5kZXJJbmZvLm1heExp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wgcmVuZGVySW5mby5saW5lTnVtOyBpKyspIHtcbiAgICAgICAgcmVuZGVySW5mby5saW5lc1tpXSA9IHtcbiAgICAgICAgICB3aWR0aDogMCxcbiAgICAgICAgICB4OiAwLFxuICAgICAgICAgIHk6IHJlbmRlckluZm8ubGluZUhlaWdodCAqIGkgKyB2YU9mZnNldCxcbiAgICAgICAgICB0ZXh0OiBbXVxuICAgICAgICB9O1xuICAgICAgfVxuICAgICAgZm9yIChsZXQgdCBvZiB0ZXh0KSB7XG4gICAgICAgIHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnRleHQucHVzaCh0KTtcbiAgICAgIH1cbiAgICAgIGZvciAoY29uc3QgbCBvZiByZW5kZXJJbmZvLmxpbmVzKSB7XG4gICAgICAgIGlmIChsLnRleHQubGVuZ3RoID09IDApIHtcbiAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgfVxuICAgICAgICBjb25zdCBmaXJzdFdvcmQgPSBsLnRleHRbMF0udGV4dDtcbiAgICAgICAgY29uc3QgbGFzdFdvcmQgPSBsLnRleHRbbC50ZXh0Lmxlbmd0aCAtIDFdLnRleHQ7XG4gICAgICAgIGlmIChmaXJzdFdvcmQgPT0gXCJcXG5cIikge1xuICAgICAgICAgIGwudGV4dC5zaGlmdCgpO1xuICAgICAgICB9XG4gICAgICAgIGlmIChpc1NwYWNlKGxhc3RXb3JkKSB8fCBsYXN0V29yZCA9PSBcIlxcblwiKSB7XG4gICAgICAgICAgbC50ZXh0LnBvcCgpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICBmb3IgKGxldCBsIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgICAgbC53aWR0aCA9IGwudGV4dC5yZWR1Y2UoKGFjYywgdCkgPT4gYWNjICsgdC53aWR0aCwgMCk7XG4gICAgICB9XG4gICAgICByZW5kZXJJbmZvLndpZHRoID0gdGhpcy5fc2V0dGluZ3MudyAhPSAwID8gdGhpcy5fc2V0dGluZ3MudyAqIHByZWN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GluZVRleHRbbGFzdExpbmVUZXh0Lmxlbmd0aCAtIHNwbF0udGV4dCkpIHtcbiAgICAgICAgICBsYXN0TGluZVRleHQuc3BsaWNlKGxhc3RMaW5lVGV4dC5sZW5ndGggLSBzcGwsIDEpO1xuICAgICAgICAgIF93ID0gbGFzdExpbmVUZXh0LnJlZHVjZSgoYWNjLCB0KSA9PiBhY2MgKyB0LndpZHRoLCAwKTtcbiAgICAgICAgICBpZiAobGFzdExpbmVUZXh0Lmxlbmd0aCA8IHNwbCkge1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHRoaXMuYWxpZ25MaW5lKGxhc3RMaW5lVGV4dCwgbGFzdExpbmVUZXh0WzBdLngpO1xuICAgICAgICByZW5kZXJJbmZvLmxpbmVzW2luZGV4XS50ZXh0ID0gbGFzdExpbmVUZXh0O1xuICAgICAgICByZW5kZXJJbmZvLmxpbmVzW2luZGV4XS53aWR0aCA9IF93O1xuICAgICAgfVxuICAgICAgaWYgKHJlbmRlckluZm8udGV4dEFsaWduID09IFwiY2VudGVyXCIpIHtcbiAgICAgICAgZm9yIChsZXQgbCBvZiByZW5kZXJJbmZvLmxpbmVzKSB7XG4gICAgICAgICAgbC54ID0gKHJlbmRlckluZm8ud2lkdGggLSBsLndpZHRoIC0gcGFkZGluZ0xlZnQpIC8gMjtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChyZW5kZXJJbmZvLnRleHRBbGlnbiA9PSBcInJpZ2h0XCIpIHtcbiAgICAgICAgZm9yIChsZXQgbCBvZiByZW5kZXJJbmZvLmxpbmVzKSB7XG4gICAgICAgICAgbC54ID0gcmVuZGVySW5mby53aWR0aCAtIGwud2lkdGggLSBwYWRkaW5nTGVmdDtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgcmV0dXJuIHJlbmRlckluZm87XG4gICAgfVxuICAgIF9kcmF3KCkge1xuICAgICAgY29uc3QgcmVuZGVySW5mbyA9IH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YWRvd09mZnNldFkgPSB0aGlzLl9zZXR0aW5ncy5zaGFkb3dPZmZzZXRZICogcHJlY2lzaW9uO1xuICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd0JsdXIgPSB0aGlzLl9zZXR0aW5ncy5zaGFkb3dCbHVyICogcHJlY2lzaW9uO1xuICAgICAgfVxuICAgICAgY29uc3QgZGVmYXVsdENvbG9yID0gU3RhZ2VVdGlscy5nZXRSZ2JhU3RyaW5nKHRoaXMuX3NldHRpbmdzLnRleHRDb2xvcik7XG4gICAgICBsZXQgY3VycmVudENvbG9yID0gZGVmYXVsdENvbG9yO1xuICAgICAgdGhpcy5fY29udGV4dC5maWxsU3R5bGUgPSBkZWZhdWx0Q29sb3I7XG4gICAgICBmb3IgKGNvbnN0IGxpbmUgb2YgcmVuZGVySW5mby5saW5lcykge1xuICAgICAgICBmb3IgKGNvbnN0IHQgb2YgbGluZS50ZXh0KSB7XG4gICAgICAgICAgbGV0IGx4ID0gMDtcbiAgICAgICAgICBpZiAodC50ZXh0ID09IFwiXFxuXCIpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAocmVuZGVySW5mby5tYXhMaW5lcyAmJiB0LmxpbmVObyA+PSByZW5kZXJJbmZvLm1heExpbmVzKSB7XG4gICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHQuY29sb3IgIT0gY3VycmVudENvbG9yKSB7XG4gICAgICAgICAgICBjdXJyZW50Q29sb3IgPSB0LmNvbG9yO1xuICAgICAgICAgICAgdGhpcy5fY29udGV4dC5maWxsU3R5bGUgPSBjdXJyZW50Q29sb3I7XG4gICAgICAgICAgfVxuICAgICAgICAgIHRoaXMuX2NvbnRleHQuZm9udCA9IHQuZm9udFN0eWxlO1xuICAgICAgICAgIGlmICh0LmxldHRlcnMpIHtcbiAgICAgICAgICAgIGZvciAobGV0IGwgb2YgdC5sZXR0ZXJzKSB7XG4gICAgICAgICAgICAgIGNvbnN0IF94ID0gcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10ueCArIHQueCArIGx4O1xuICAgICAgICAgICAgICB0aGlzLl9jb250ZXh0LmZpbGxUZXh0KGwudGV4dCwgX3gsIHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnkgKyByZW5kZXJJbmZvLmZvbnRTaXplKTtcbiAgICAgICAgICAgICAgbHggKz0gbC53aWR0aDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29uc3QgX3ggPSByZW5kZXJJbmZvLmxpbmVzW3QubGluZU5vXS54ICsgdC54O1xuICAgICAgICAgICAgdGhpcy5fY29udGV4dC5maWxsVGV4dCh0LnRleHQsIF94LCByZW5kZXJJbmZvLmxpbmVzW3QubGluZU5vXS55ICsgcmVuZGVySW5mby5mb250U2l6ZSk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpZiAocHJldlNoYWRvd1NldHRpbmdzKSB7XG4gICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93Q29sb3IgPSBwcmV2U2hhZG93U2V0dGluZ3NbMF07XG4gICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93T2Zmc2V0WCA9IHByZXZTaGFkb3dTZXR0aW5nc1sxXTtcbiAgICAgICAgdGhpcy5fY29udGV4dC5zaGFkb3dPZmZzZXRZID0gcHJldlNoYWRvd1NldHRpbmdzWzJdO1xuICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd0JsdXIgPSBwcmV2U2hhZG93U2V0dGluZ3NbM107XG4gICAgICB9XG4gICAgICBpZiAocmVuZGVySW5mby5jdXRTeCB8fCByZW5kZXJJbmZvLmN1dFN5KSB7XG4gICAgICAgIHRoaXMuX2NvbnRleHQudHJhbnNsYXRlKHJlbmRlckluZm8uY3V0U3gsIHJlbmRlckluZm8uY3V0U3kpO1xuICAgICAgfVxuICAgICAgcmVuZGVySW5mby5saW5lcyA9IHJlbmRlckluZm8ubGluZXMubWFwKChsKSA9PiBsLnRleHQucmVkdWNlKChhY2MsIHYpID0+IGFjYyArIHYudGV4dCwgXCJcIikpO1xuICAgICAgaWYgKHJlbmRlckluZm8ubWF4TGluZXMpIHtcbiAgICAgICAgcmVuZGVySW5mby5saW5lcyA9IHJlbmRlckluZm8ubGluZXMuc2xpY2UoMCwgcmVuZGVySW5mby5tYXhMaW5lcyk7XG4gICAgICB9XG4gICAgICB0aGlzLnJlbmRlckluZm8gPSByZW5kZXJJbmZvO1xuICAgIH1cbiAgICBtZWFzdXJlVGV4dCh3b3JkLCBzcGFjZSA9IDApIHtcbiAgICAgIHJldHVybiBtZWFzdXJlVGV4dCh0aGlzLl9jb250ZXh0LCB3b3JkLCBzcGFjZSk7XG4gICAgfVxuICAgIHRva2VuaXplKHRleHQpIHtcbiAgICAgIHJldHVybiB0b2tlbml6ZVN0cmluZygvIHxcXHUyMDBCfFxcbnw8aT58PFxcL2k+fDxiPnw8XFwvYj58PGNvbG9yPTBbeFhdWzAtOWEtZkEtRl17OH0+fDxcXC9jb2xvcj4vZywgdGV4dCk7XG4gICAgfVxuICAgIHBhcnNlKHRva2Vucykge1xuICAgICAgbGV0IGl0YWxpYyA9IDA7XG4gICAgICBsZXQgYm9sZCA9IDA7XG4gICAgICBsZXQgY29sb3JTdGFjayA9IFtTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcodGhpcy5fc2V0dGluZ3MudGV4dENvbG9yKV07XG4gICAgICBsZXQgY29sb3IgPSAwO1xuICAgICAgY29uc3QgY29sb3JSZWdleHAgPSAvPGNvbG9yPSgwW3hYXVswLTlhLWZBLUZdezh9KT4vO1xuICAgICAgcmV0dXJuIHRva2Vucy5tYXAoKHQpID0+IHtcbiAgICAgICAgaWYgKHQgPT0gXCI8aT5cIikge1xuICAgICAgICAgIGl0YWxpYyArPSAxO1xuICAgICAgICAgIHQgPSBcIlwiO1xuICAgICAgICB9IGVsc2UgaWYgKHQgPT0gXCI8L2k+XCIgJiYgaXRhbGljID4gMCkge1xuICAgICAgICAgIGl0YWxpYyAtPSAxO1xuICAgICAgICAgIHQgPSBcIlwiO1xuICAgICAgICB9IGVsc2UgaWYgKHQgPT0gXCI8Yj5cIikge1xuICAgICAgICAgIGJvbGQgKz0gMTtcbiAgICAgICAgICB0ID0gXCJcIjtcbiAgICAgICAgfSBlbHNlIGlmICh0ID09IFwiPC9iPlwiICYmIGJvbGQgPiAwKSB7XG4gICAgICAgICAgYm9sZCAtPSAxO1xuICAgICAgICAgIHQgPSBcIlwiO1xuICAgICAgICB9IGVsc2UgaWYgKHQgPT0gXCI8L2NvbG9yPlwiKSB7XG4gICAgICAgICAgaWYgKGNvbG9yU3RhY2subGVuZ3RoID4gMSkge1xuICAgICAgICAgICAgY29sb3IgLT0gMTtcbiAgICAgICAgICAgIGNvbG9yU3RhY2sucG9wKCk7XG4gICAgICAgICAgfVxuICAgICAgICAgIHQgPSBcIlwiO1xuICAgICAgICB9IGVsc2UgaWYgKGNvbG9yUmVnZXhwLnRlc3QodCkpIHtcbiAgICAgICAgICBjb25zdCBtYXRjaGVkID0gY29sb3JSZWdleHAuZXhlYyh0KTtcbiAgICAgICAgICBjb2xvclN0YWNrLnB1c2goXG4gICAgICAgICAgICBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcocGFyc2VJbnQobWF0Y2hlZFsxXSkpXG4gICAgICAgICAgKTtcbiAgICAgICAgICBjb2xvciArPSAxO1xuICAgICAgICAgIHQgPSBcIlwiO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgdGV4dDogdCxcbiAgICAgICAgICBpdGFsaWMsXG4gICAgICAgICAgYm9sZCxcbiAgICAgICAgICBjb2xvcjogY29sb3JTdGFja1tjb2xvcl1cbiAgICAgICAgfTtcbiAgICAgIH0pLmZpbHRlcigobykgPT4gby50ZXh0ICE9IFwiXCIpO1xuICAgIH1cbiAgICBhcHBseUZvbnRTdHlsZSh3b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5nKDAsIGJyZWFrSW5kZXgpKTtcbiAgICAgIGlmICh0cnVuY1dvcmRXaWR0aCA+IHdpZHRoKSB7XG4gICAgICAgIHdoaWxlIChicmVha0luZGV4ID4gMCkge1xuICAgICAgICAgIHRydW5jV29yZFdpZHRoID0gdGhpcy5tZWFzdXJlVGV4dCh3b3JkLnN1YnN0cmluZygwLCBicmVha0luZGV4KSk7XG4gICAgICAgICAgaWYgKHRydW5jV29yZFdpZHRoID4gd2lkdGgpIHtcbiAgICAgICAgICAgIGJyZWFrSW5kZXggLT0gMTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICB3aGlsZSAoYnJlYWtJbmRleCA8IHdvcmRMZW4pIHtcbiAgICAgICAgICB0cnVuY1dvcmRXaWR0aCA9IHRoaXMubWVhc3VyZVRleHQod29yZC5zdWJzdHJpbmcoMCwgYnJlYWtJbmRleCkpO1xuICAgICAgICAgIGlmICh0cnVuY1dvcmRXaWR0aCA8IHdpZHRoKSB7XG4gICAgICAgICAgICBicmVha0luZGV4ICs9IDE7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGJyZWFrSW5kZXggLT0gMTtcbiAgICAgICAgICAgIHRydW5jV29yZFdpZHRoID0gdGhpcy5tZWFzdXJlVGV4dCh3b3JkLnN1YnN0cmluZygwLCBicmVha0luZGV4KSk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHJldHVybiB7IGJyZWFrSW5kZXgsIHRydW5jV29yZFdpZHRoIH07XG4gICAgfVxuICAgIHdvcmRCcmVhayh3b3JkLCB3aWR0aCwgYmFzZUZvbnQpIHtcbiAgICAgIGlmICghd29yZC50ZXh0KSB7XG4gICAgICAgIHJldHVybiB3b3JkO1xuICAgICAgfVxuICAgICAgdGhpcy5hcHBseUZvbn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uZ3RoIC0gMV0ud2lkdGggPSB0b3RhbFdpZHRoO1xuICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ubGV0dGVycyA9IGxldHRlcnM7XG4gICAgICAgICAgICB0ZXh0ID0gdGV4dC5zbGljZShicmVha0luZGV4KTtcbiAgICAgICAgICAgIHRvdGFsV2lkdGggPSAwO1xuICAgICAgICAgICAgbGV0dGVycyA9IFtdO1xuICAgICAgICAgICAgYnJlYWtJbmRleCA9IDA7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGJyZWFrSW5kZXggKz0gMTtcbiAgICAgICAgICAgIGxldHRlcnMucHVzaChsKTtcbiAgICAgICAgICAgIHRvdGFsV2lkdGggKz0gbC53aWR0aDtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRvdGFsV2lkdGggPiAwKSB7XG4gICAgICAgICAgcGFydHMucHVzaCh7IC4uLndvcmQgfSk7XG4gICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0udGV4dCA9IHRleHQuc2xpY2UoMCwgYnJlYWtJbmRleCk7XG4gICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ud2lkdGggPSB0b3RhbFdpZHRoO1xuICAgICAgICAgIHBhcnRzW3BhcnRzLmxlbmd0aCAtIDFdLmxldHRlcnMgPSBsZXR0ZXJzO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gcGFydHM7XG4gICAgfVxuICAgIGFsaWduTGluZShwYXJzZWQsIGluaXRpYWxYID0gMCkge1xuICAgICAgbGV0IHByZXZXaWR0aCA9IDA7XG4gICAgICBsZXQgcHJldlggPSBpbml0aWFsWDtcbiAgICAgIGZvciAoY29uc3Qgd29yZCBvZiBwYXJzZWQpIHtcbiAgICAgICAgaWYgKHdvcmQudGV4dCA9PSBcIlxcblwiKSB7XG4gICAgICAgICAgY29udGludWU7XG4gICAgICAgIH1cbiAgICAgICAgd29yZC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gICAgcmV0dXJuIHN1cGVyLnByZWNpc2lvbjtcbiAgICB9XG4gICAgc2V0IHByZWNpc2lvbih2KSB7XG4gICAgICBpZiAodGhpcy5wcmVjaXNpb24gIT09IHYpIHtcbiAgICAgICAgc3VwZXIucHJlY2lzaW9uID0gdjtcbiAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgfVxuICAgIH1cbiAgICBfZ2V0SXNWYWxpZCgpIHtcbiAgICAgIHJldHVybiAhIXRoaXMudGV4dDtcbiAgICB9XG4gICAgX2dldExvb2t1cElkKCkge1xuICAgICAgbGV0IHBhcnRzID0gW107XG4gICAgICBpZiAodGhpcy53ICE9PSAwKVxuICAgICAgICBwYXJ0cy5wdXNoKFwidyBcIiArIHRoaXMudyk7XG4gICAgICBpZiAodGhpcy5oICE9PSAwKVxuICAgICAgICBwYXJ0cy5wdXNoKFwiaCBcIiArIHRoaXMuaCk7XG4gICAgICBpZiAodGhpcy5mb250U3R5bGUgIT09IFwibm9ybWFsXCIpXG4gICAgICAgIHBhcnRzLnB1c2goXCJmU1wiICsgdGhpcy5mb250U3R5bGUpO1xuICAgICAgaWYgKHRoaXMuZm9udFNpemUgIT09IDQwKVxuICAgICAgICBwYXJ0cy5wdXNoKFwiZnNcIiArIHRoaXMuZm9udFNpemUpO1xuICAgICAgaWYgKHRoaXMuZm9udEJhc2VsaW5lUmF0aW8gIT09IDApXG4gICAgICAgIHBhcnRzLnB1c2goXCJmYlwiICsgdGhpcy5mb250QmFzZWxpbmVSYXRpbyk7XG4gICAgICBpZiAodGhpcy5mb250RmFjZSAhPT0gbnVsbClcbiAgICAgICAgcGFydHMucHVzaChcImZmXCIgKyAoQXJyYXkuaXNBcnJheSh0aGlzLmZvbnRGYWNlKSA/IHRoaXMuZm9udEZhY2Uuam9pbihcIixcIikgOiB0aGlzLmZvbnRGYWNlKSk7XG4gICAgICBpZiAodGhpcy53b3JkV3JhcCAhPT0gdHJ1ZSlcbiAgICAgICAgcGFydHMucHVzaChcIndyXCIgKyAodGhpcy53b3JkV3JhcCA/IDEgOiAwKSk7XG4gICAgICBpZiAodGhpcy53b3JkV3JhcFdpZHRoICE9PSAwKVxuICAgICAgICBwYXJ0cy5wdXNoKFwid3dcIiArIHRoaXMud29yZFdyYXBXaWR0aCk7XG4gICAgICBpZiAodGhpcy53b3JkQnJlYWsgIT09IGZhbHNlKVxuICAgICAgICBwYXJ0cy5wdXNoKFwid2JcIiArIHRoaXMud29yZEJyZWFrID8gMSA6IDApO1xuICAgICAgaWYgKHRoaXMudGV4dE92ZXJmbG93ICE9IFwiXCIpXG4gICAgICAgIHBhcnRzLnB1c2goXCJ0b1wiICsgdGhpcy50ZXh0T3ZlcmZsb3cpO1xuICAgICAgaWYgKHRoaXMubGluZUhlaWdodCAhPT0gbnVsbClcbiAgICAgICAgcGFydHMucHVzaChcImxoXCIgKyB0aGlzLmxpbmVIZWlnaHQpO1xuICAgICAgaWYgKHRoaXMudGV4dEJhc2VsaW5lICE9PSBcImFscGhhYmV0aWNcIilcbiAgICAgICAgcGFydHMucHVzaChcInRiXCIgKyB0aGlzLnRleHRCYXNlbGluZSk7XG4gICAgICBpZiAodGhpcy50ZXh0QWxpZ24gIT09IFwibGVmdFwiKVxuICAgICAgICBwYXJ0cy5wdXNoKFwidGFcIiArIHRoaXMudGV4dEFsaWduKTtcbiAgICAgIGlmICh0aGlzLnZlcnRpY2FsQWxpZ24gIT09IFwidG9wXCIpXG4gICAgICAgIHBhcnRzLnB1c2goXCJ2YVwiICsgdGhpcy52ZXJ0aWNhbEFsaWduKTtcbiAgICAgIGlmICh0aGlzLm9mZnNldFkgIT09IG51bGwpXG4gICAgICAgIHBhcnRzLnB1c2goXCJveVwiICsgdGhpcy5vZmZzZXRZKTtcbiAgICAgIGlmICh0aGlzLm1heExpbmVzICE9PSAwKVxuICAgICAgICBwYXJ0cy5wdXNoKFwibWxcIiArIHRoaXMubWF4TGluZXMpO1xuICAgICAgaWYgKHRoaXMubWF4TGluZXNTdWZmaXgg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VwbGFjZShpdGVtLCBwcmV2SXRlbSkge1xuICAgICAgY29uc3QgaW5kZXggPSB0aGlzLmdldEluZGV4KHByZXZJdGVtKTtcbiAgICAgIGlmIChpbmRleCA9PT0gLTEpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwicmVwbGFjZTogVGhlIHByZXZpb3VzIGl0ZW0gZG9lcyBub3QgZXhpc3RcIik7XG4gICAgICB9XG4gICAgICB0aGlzLnNldEF0KGl0ZW0sIGluZGV4KTtcbiAgICB9XG4gICAgc2V0QXQoaXRlbSwgaW5kZXgpIHtcbiAgICAgIGlmIChpbmRleCA+PSAwICYmIGluZGV4IDwgdGhpcy5faXRlbXMubGVuZ3RoKSB7XG4gICAgICAgIGlmIChVdGlscyQxLmlzT2JqZWN0TGl0ZXJhbChpdGVtKSkge1xuICAgICAgICAgIGNvbnN0IG8gPSBpdGVtO1xuICAgICAgICAgIGl0ZW0gPSB0aGlzLmNyZWF0ZUl0ZW0obyk7XG4gICAgICAgICAgaXRlbS5wYXRjaChvKTtcbiAgICAgICAgfVxuICAgICAgICBsZXQgY3VycmVudEluZGV4ID0gdGhpcy5faXRlbXMuaW5kZXhPZihpdGVtKTtcbiAgICAgICAgaWYgKGN1cnJlbnRJbmRleCAhPSAtMSkge1xuICAgICAgICAgIGlmIChjdXJyZW50SW5kZXggIT09IGluZGV4KSB7XG4gICAgICAgICAgICBjb25zdCBmcm9tSW5kZXggPSBjdXJyZW50SW5kZXg7XG4gICAgICAgICAgICBpZiAoZnJvbUluZGV4ICE9PSBpbmRleCkge1xuICAgICAgICAgICAgICB0aGlzLl9pdGVtcy5zcGxpY2UoZnJvbUluZGV4LCAxKTtcbiAgICAgICAgICAgICAgdGhpcy5faXRlbXMuc3BsaWNlKGluZGV4LCAwLCBpdGVtKTtcbiAgICAgICAgICAgICAgdGhpcy5vbk1vdmUoaXRlbSwgZnJvbUluZGV4LCBpbmRleCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgIC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G4gICAgICAgIGxldCBjcmVmID0gY3JlZnNbaV07XG4gICAgICAgIGxldCBzID0gc2V0dGluZ3NbY3JlZl07XG4gICAgICAgIGxldCBjID0gcmVmc1tjcmVmXTtcbiAgICAgICAgaWYgKCFjKSB7XG4gICAgICAgICAgaWYgKHRoaXMuaXNJdGVtKHMpKSB7XG4gICAgICAgICAgICBzLnJlZiA9IGNyZWY7XG4gICAgICAgICAgICB0aGlzLmFkZChzKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYyA9IHRoaXMuY3JlYXRlSXRlbShzKTtcbiAgICAgICAgICAgIGMucmVmID0gY3JlZjtcbiAgICAgICAgICAgIGMucGF0Y2gocyk7XG4gICAgICAgICAgICB0aGlzLmFkZChjKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHRoaXMuaXNJdGVtKHMpKSB7XG4gICAgICAgICAgICBpZiAoYyAhPT0gcykge1xuICAgICAgICAgICAgICBsZXQgaWR4ID0gdGhpcy5nZXRJbmRleChjKTtcbiAgICAgICAgICAgICAgcy5yZWYgPSBjcmVmO1xuICAgICAgICAgICAgICB0aGlzLnNldEF0KHMsIGlkeCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGMucGF0Y2gocyk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIF9lcXVhbHNBcnJheShhcnJheSkge1xuICAgICAgbGV0IHNhbWUgPSB0cnVlO1xuICAgICAgaWYgKGFycmF5Lmxlbmd0aCA9PT0gdGhpcy5faXRlbXMubGVuZ3RoKSB7XG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5faXRlbXMubGVuZ3RoOyBpIDwgbiAmJiBzYW1lOyBpKyspIHtcbiAgICAgICAgICBzYW1lID0gc2FtZSAmJiB0aGlzLl9pdGVtc1tpXSA9PT0gYXJyYXlbaV07XG4gICAgICAgIH1cbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHNhbWUgPSBmYWxzZTtcbiAgICAgIH1cbiAgICAgIHJldHVybiBzYW1lO1xuICAgIH1cbiAgICBfc2V0QnlBcnJheShhcnJheSkge1xuICAgICAgaWYgKHRoaXMuX2VxdWFsc0FycmF5KGFycmF5KSkge1xuICAgICAgICByZXR1cm47XG4gICAgICB9XG4gICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2l0ZW1zLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICB0aGlzLl9pdGVtc1tpXS5tYXJrZXIgPSB0cnVlO1xuICAgICAgfVxuICAgICAgbGV0IHJlZnM7XG4gICAgICBsZXQgbmV3SXRlbXMgPSBbXTtcbiAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gYXJyYXkubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgIGxldCBzID0gYXJyYXlbaV07XG4gICAgICAgIGlmICh0aGlzLmlzSXRlbShzKSkge1xuICAgICAgICAgIHMubWFya2VyID0gZmFsc2U7XG4gICAgICAgICAgbmV3SXRlbXMucHVzaChzKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBsZXQgY3JlZiA9IHMucmVmO1xuICAgICAgICAgIGxldCBjO1xuICAgICAgICAgIGlmIChjcmVmKSB7XG4gICAgICAgICAgICBpZiAoIXJlZnMpXG4gICAgICAgICAgICAgIHJlZnMgPSB0aGlzLl9nZXRSZWZzKCk7XG4gICAgICAgICAgICBjID0gcmVmc1tjcmVmXTtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKCFjKSB7XG4gICAgICAgICAgICBjID0gdGhpcy5jcmVhdGVJdGVtKHMpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjLm1hcmtlciA9IGZhbHNlO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoVXRpbHMkMS5pc09iamVjdExpdGVyYWwocykpIHtcbiAg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ge1xuICAgICAgICAgIHRoaXMuX29uQXR0YWNoKCk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhpcy5fb25EZXRhY2goKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlRW5hYmxlZEZsYWcoKSB7XG4gICAgICBsZXQgbmV3RW5hYmxlZCA9IHRoaXMuX2lzRW5hYmxlZCgpO1xuICAgICAgaWYgKHRoaXMuX19lbmFibGVkICE9PSBuZXdFbmFibGVkKSB7XG4gICAgICAgIGlmIChuZXdFbmFibGVkKSB7XG4gICAgICAgICAgdGhpcy5fb25FbmFibGVkKCk7XG4gICAgICAgICAgdGhpcy5fc2V0RW5hYmxlZEZsYWcoKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB0aGlzLl9vbkRpc2FibGVkKCk7XG4gICAgICAgICAgdGhpcy5fdW5zZXRFbmFibGVkRmxhZygpO1xuICAgICAgICB9XG4gICAgICAgIGxldCBjaGlsZHJlbiA9IHRoaXMuX2NoaWxkcmVuLmdldCgpO1xuICAgICAgICBpZiAoY2hpbGRyZW4pIHtcbiAgICAgICAgICBsZXQgbSA9IGNoaWxkcmVuLmxlbmd0aDtcbiAgICAgICAgICBpZiAobSA+IDApIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbTsgaSsrKSB7XG4gICAgICAgICAgICAgIGNoaWxkcmVuW2ldLl91cGRhdGVFbmFibGVkRmxhZygpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBfc2V0RW5hYmxlZEZsYWcoKSB7XG4gICAgICB0aGlzLl9fZW5hYmxlZCA9IHRydWU7XG4gICAgICB0aGlzLl91cGRhdGVEaW1lbnNpb25zKCk7XG4gICAgICB0aGlzLl91cGRhdGVUZXh0dXJlQ29vcmRzKCk7XG4gICAgICBpZiAodGhpcy5fX3RleHR1cmUpIHtcbiAgICAgICA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W5nKSB7XG4gICAgICAgICAgbGV0IHcgPSBkaXNwbGF5ZWRUZXh0dXJlU291cmNlLmdldFJlbmRlcldpZHRoKCk7XG4gICAgICAgICAgbGV0IGggPSBkaXNwbGF5ZWRUZXh0dXJlU291cmNlLmdldFJlbmRlckhlaWdodCgpO1xuICAgICAgICAgIGxldCBpdywgaWgsIHJ3LCByaDtcbiAgICAgICAgICBpdyA9IDEgLyB3O1xuICAgICAgICAgIGloID0gMSAvIGg7XG4gICAgICAgICAgaWYgKGRpc3BsYXllZFRleHR1cmUucHcpIHtcbiAgICAgICAgICAgIHJ3ID0gZGlzcGxheWVkVGV4dHVyZS5wdyAqIGl3O1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBydyA9ICh3IC0gZGlzcGxheWVkVGV4dHVyZS5weCkgKiBpdztcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKGRpc3BsYXllZFRleHR1cmUucGgpIHtcbiAgICAgICAgICAgIHJoID0gZGlzcGxheWVkVGV4dHVyZS5waCAqIGloO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByaCA9IChoIC0gZGlzcGxheWVkVGV4dHVyZS5weSkgKiBpaDtcbiAgICAgICAgICB9XG4gICAgICAgICAgaXcgKj0gZGlzcGxheWVkVGV4dHVyZS5weDtcbiAgICAgICAgICBpaCAqPSBkaXNwbGF5ZWRUZXh0dXJlLnB5O1xuICAgICAgICAgIHR4MSA9IGl3O1xuICAgICAgICAgIHR5MSA9IGloO1xuICAgICAgICAgIHR4MiA9IHR4MiAqIHJ3ICsgaXc7XG4gICAgICAgICAgdHkyID0gdHkyICogcmggKyBpaDtcbiAgICAgICAgICB0eDEgPSBNYXRoLm1heCgwLCB0eDEpO1xuICAgICAgICAgIHR5MSA9IE1hdGgubWF4KDAsIHR5MSk7XG4gICAgICAgICAgdHgyID0gTWF0aC5taW4oMSwgdHgyKTtcbiAgICAgICAgICB0eTIgPSBNYXRoLm1pbigxLCB0eTIpO1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gbiA9IHRhZ3MubGVuZ3RoO1xuICAgICAgICAgIGlmIChuID4gMCkge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgbGV0IHRhZ1NldCA9IHRoaXMuX190cmVlVGFncy5nZXQodGFnc1tpXSk7XG4gICAgICAgICAgICAgIGxldCBwID0gdGhpcztcbiAgICAgICAgICAgICAgd2hpbGUgKHAgPSBwLl9fcGFyZW50KSB7XG4gICAgICAgICAgICAgICAgbGV0IHBhcmVudFRyZWVUYWdzID0gcC5fX3RyZWVUYWdzLmdldCh0YWdzW2ldKTtcbiAgICAgICAgICAgICAgICB0YWdTZXQuZm9yRWFjaChmdW5jdGlvbihjb21wKSB7XG4gICAgICAgICAgICAgICAgICBwYXJlbnRUcmVlVGFncy5kZWxldGUoY29tcCk7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgaWYgKHAuX190YWdSb290KSB7XG4gICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgX3NldFRhZ3NQYXJlbnQoKSB7XG4gICAgICBpZiAodGhpcy5fX3RhZ3MpIHtcbiAgICAgICAgdGhpcy5fX3RhZ3MuZm9yRWFjaCgodGFnKSA9PiB7XG4gICAgICAgICAgbGV0IHAgPSB0aGlzO1xuICAgICAgICAgIHdoaWxlIChwID0gcC5fX3BhcmVudCkge1xuICAgICAgICAgICAgaWYgKCFwLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICAgICAgcC5fX3RyZWVUYWdzID0gLyogQF9fUFVSRV9fICovIG5ldyBNYXAoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGxldCBzID0gcC5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgICAgICAgaWYgKCFzKSB7XG4gICAgICAgICAgICAgIHMgPSAvKiBAX19QVVJFX18gKi8gbmV3IFNldCgpO1xuICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3Muc2V0KHRhZywgcyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBzLmFkZCh0aGlzKTtcbiAgICAgICAgICAgIGlmIChwLl9fdGFnUm9vdCkge1xuICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMuX190cmVlVGFncyAmJiB0aGlzLl9fdHJlZVRhZ3Muc2l6ZSkge1xuICAgICAgICBpZiAoIXRoaXMuX190YWdSb290KSB7XG4gICAgICAgICAgdGhpcy5fX3RyZWVUYWdzLmZvckVhY2goKHRhZ1NldCwgdGFnKSA9PiB7XG4gICAgICAgICAgICBsZXQgcCA9IHRoaXM7XG4gICAgICAgICAgICB3aGlsZSAoIXAuX190YWdSb290ICYmIChwID0gcC5fX3BhcmVudCkpIHtcbiAgICAgICAgICAgICAgaWYgKHAuX190YWdSb290KVxuICAgICAgICAgICAgICAgIDtcbiAgICAgICAgICAgICAgaWYgKCFwLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3MgPSAvKiBAX19QVVJFX18gKi8gbmV3IE1hcCgpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGxldCBzID0gcC5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgICAgICAgICBpZiAoIXMpIHtcbiAgICAgICAgICAgICAgICBzID0gLyogQF9fUFVSRV9fICovIG5ldyBTZXQoKTtcbiAgICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3Muc2V0KHRhZywgcyk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgdGFnU2V0LmZvckVhY2goZnVuY3Rpb24oY29tcCkge1xuICAgICAgICAgICAgICAgIHMuYWRkKGNvbXApO1xuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICBfZ2V0QnlUYWcodGFnKSB7XG4gICAgICBpZiAoIXRoaXMuX190cmVlVGFncykge1xuICAgICAgICByZXR1cm4gW107XG4gICAgICB9XG4gICAgICBsZXQgdCA9IHRoaXMuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgIHJldHVybiB0ID8gVXRpbHMkMS5zZXRUb0FycmF5KHQpIDogW107XG4gICAgfVxuICAgIGdldFRhZ3MoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fX3RhZ3MgPyB0aGlzLl9fdGFncyA6IFtdO1xuICAgIH1cbiAgICBzZXRUYWdzKHRhZ3MpIHtcbiAgICAgIHRhZ3MgPSB0YWdzLnJlZHVjZSgoYWNjLCB0YWcpID0+IHtcbiAgICAgICAgcmV0dXJuIGFjYy5jb25jYXQodGFnLnNwbGl0KFwiIFwiKSk7XG4gICAgICB9LCBbXSk7XG4gICAgICBpZiAodGhpcy5fX3JlZikge1xuICAgICAgICB0YWdzLnB1c2godGhpcy5fX3JlZik7XG4gICAgICB9XG4gICAgICBsZXQgaSwgbiA9IHRhZ3MubGVuZ3RoO1xuICAgICAgbGV0IHJlbW92ZXMgPSBbXTtcbiAgICAgIGxldCBhZGRzID0gW107XG4gICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgIGlmICghdGhpcy5oYXNUYWcodGFnc1tpXSkpIHtcbiAgICAgICAgICBhZGRzLnB1c2godGFnc1tpXSk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGxldCBjdXJyZW50VGFncyA9IHRoaXMudGFncyB8fCBbXTtcbiAgICAgIG4gPSBjdXJyZW50VGFncy5sZW5ndGg7XG4gICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgIGlmICh0YWdzLmluZGV4T2YoY3VycmVudF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fVxuICAgICAgfVxuICAgIH1cbiAgICBfYWRkVGFnKHRhZykge1xuICAgICAgaWYgKCF0aGlzLl9fdGFncykge1xuICAgICAgICB0aGlzLl9fdGFncyA9IFtdO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMuX190YWdzLmluZGV4T2YodGFnKSA9PT0gLTEpIHtcbiAgICAgICAgdGhpcy5fX3RhZ3MucHVzaCh0YWcpO1xuICAgICAgICBsZXQgcCA9IHRoaXMuX19wYXJlbnQ7XG4gICAgICAgIGlmIChwKSB7XG4gICAgICAgICAgZG8ge1xuICAgICAgICAgICAgaWYgKCFwLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICAgICAgcC5fX3RyZWVUYWdzID0gLyogQF9fUFVSRV9fICovIG5ldyBNYXAoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGxldCBzID0gcC5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgICAgICAgaWYgKCFzKSB7XG4gICAgICAgICAgICAgIHMgPSAvKiBAX19QVVJFX18gKi8gbmV3IFNldCgpO1xuICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3Muc2V0KHRhZywgcyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBzLmFkZCh0aGlzKTtcbiAgICAgICAgICB9IHdoaWxlICghcC5fX3RhZ1Jvb3QgJiYgKHAgPSBwLl9fcGFyZW50KSk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgcmVtb3ZlVGFnKHRhZykge1xuICAgICAgbGV0IGkgPSB0aGlzLl9fdGFncy5pbmRleE9mKHRhZyk7XG4gICAgICBpZiAoaSAhPT0gLTEpIHtcbiAgICAgICAgdGhpcy5fX3RhZ3Muc3BsaWNlKGksIDEpO1xuICAgICAgICBsZXQgcCA9IHRoaXMuX19wYXJlbnQ7XG4gICAgICAgIGlmIChwKSB7XG4gICAgICAgICAgZG8ge1xuICAgICAgICAgICAgbGV0IGxpc3QgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICBpZiAobGlzdCkge1xuICAgICAgICAgICAgICBsaXN0LmRlbGV0ZSh0aGlzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IHdoaWxlICghcC5fX3RhZ1Jvb3QgJiYgKHAgPSBwLl9fcGFyZW50KSk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgaGFzVGFnKHRhZykge1xuICAgICAgcmV0dXJuIHRoaXMuX190YWdzICYmIHRoaXMuX190YWdzLmluZGV4T2YodGFnKSAhPT0gLTE7XG4gICAgfVxuICAgIF90YWcodGFnKSB7XG4gICAgICBpZiAodGFnLmluZGV4T2YoXCIuXCIpICE9PSAtMSkge1xuICAgICAgICByZXR1cm4gdGhpcy5tdGFnKHRhZylbMF07XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBpZiAodGhpcy5fX3RyZWVUYWdzKSB7XG4gICAgICAgICAgbGV0IHQgPSB0aGlzLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgaWYgKHQpIHtcbiAgICAgICAgICAgIGNvbnN0IGl0ZW0gPSB0LnZhbHVlcygpLm5leHQoKTtcbiAgICAgICAgICAgIHJldHVybiBpdGVtID8gaXRlbS52YWx1ZSA6IHZvaWQgMDtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgZ2V0IHRhZygpIHtcbiAgICAgIHJldHVybiB0aGlzLl90YWc7XG4gICAgfVxuICAgIHNldCB0YWcodCkge1xuICAgICAgdGhpcy50YWdzID0gdDtcbiAgICB9XG4gICAgbXRhZyh0YWcpIHtcbiAgICAgIGxldCBpZHggPSB0YWcuaW5kZXhPZihcIi5cIik7XG4gICAgICBpZiAoaWR4ID49IDApIHtcbiAgICAgICAgbGV0IHBhcnRzID0gdGFnLnNwbGl0KFwiLlwiKTtcbiAgICAgICAgbGV0IHJlcyA9IHRoaXMuX2dldEJ5VGFnKHBhcnRzWzBdKTtcbiAgICAgICAgbGV0IGxldmVsID0gMTtcbiAgICAgICAgbGV0IGMgPSBwYXJ0cy5sZW5ndGg7XG4gICAgICAgIHdoaWxlIChyZXMubGVuZ3RoICYmIGxldmVsIDwgYykge1xuICAgICAgICAgIGxldCByZXNuID0gW107XG4gICAgICAgICAgZm9yIChsZXQgaiA9IDAsIG4gPSByZXMubGVuZ3RoOyBqIDwgbjsgaisrKSB7XG4gICAgICAgICAgICByZXNuID0gcmVzbi5jb25jYXQocmVzW2pdLl9nZXRCeVRhZyhwYXJ0c1tsZXZlbF0pKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgcmVzID0gcmVzbjtcbiAgICAgICAgICBsZXZlbCsrO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiByZXM7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gdGhpcy5fZ2V0QnlUYWcodGFnKTtcbiAgICAgIH1cbiAgICB9XG4gICAgc3RhZyh0YWcsIHNldHRpbmdzKSB7XG4gICAgICBsZXQgdCA9IHRoaXMubXRhZyh0YWcpO1xuICAgICAgbGV0IG4gPSB0Lmxlbmd0aDtcbiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgIEJhc2UucGF0Y2hPYmplY3QodFtpXSwgc2V0dGluZ3MpO1xuICAgICAgfVxuICAgIH1cbiAgICBnZXQgdGFnUm9vdCgpIHtcbiAgICAgIHJldHVybiB0aGlzLl9fdGFnUm9vdDtcbiAgICB9XG4gICAgc2V0IHRhZ1Jvb3Qodikge1xuICAgICAgaWYgKHRoaXMuX190YWdSb290ICE9PSB2KSB7XG4gICAgICAgIGlmICghdikge1xuICAgICAgICAgIHRoaXMuX3NldFRhZ3NQYXJlbnQoKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB0aGlzLl91bnNldFRhZ3NQYXJlbnQoKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9fdGFnUm9vdCA9IHY7XG4gICAgICB9XG4gICAgfVxuICAgIHNlbChwYXRoKSB7XG4gICAgICBjb25zdCByZXN1bHRzID0gdGhpcy5zZWxlY3QocGF0aCk7XG4gICAgICBpZiAocmVzdWx0cy5sZW5ndGgpIHtcbiAgICAgICAgcmV0dXJuIHJlc3VsdHNbMF07XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gdm9pZCAwO1xuICAgICAgfVxuICAgIH1cbiAgICBzZWxlY3QocGF0aCkge1xuICAgICAgaWYgKHBhdGguaW5kZXhPZihcIixcIikgIT09IC0xKSB7XG4gICAgICAgIGxldCBzZWxlY3RvcnMgPSBwYXRoLnNwbGl0KFwiLFwiKTtcbiAgICAgICAgbGV0IHJlcyA9IFtdO1xuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHNlbGVjdG9ycy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgIHJlcyA9IHJlcy5jb25jYXQodGhpcy5fc2VsZWN0KHNlbGVjdG9yc1tpXSkpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiByZXM7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gdGhpcy5fc2VsZWN0KHBhdGgpO1xuICAgICAgfVxuICAgIH1cbiAgICBfc2VsZWN0KHBhdGgpIHtcbiAgICAgIGlmIChwYXRoID09PSBcIlwiKVxuICAgICAgICByZXR1cm4gW3RoaXNdO1xuICAgICAgbGV0IHBvaW50SWR4ID0gcGF0aC5pbmRleE9mKFwiLlwiKTtcbiAgICAgIGxldCBhcnJvd0lkeCA9IHBhdGguaW5kZXhPZihcIj5cIik7XG4gICAgICBpZiAocG9pbnRJZHggPT09IC0xICYmIGFycm93SWR4ID09PSAtMSkge1xuICAgICAgICByZXR1cm4gdGhpcy5tdGFnKHBhdGgpO1xuICAgICAgfVxuICAgICAgbGV0IGlzUmVmO1xuICAgICAgaWYgKGFycm93SWR4ID09PSAwKSB7XG4gICAgICAgIGlzUmVmID0gdHJ1ZTtcbiAgICAgIC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RoaXMubXRhZyhzdHIpO1xuICAgICAgICB9XG4gICAgICAgIGxldCB0b3RhbCA9IFtdO1xuICAgICAgICBjb25zdCBzdWJQYXRoID0gcGF0aC5zdWJzdHIocG9pbnRJZHggKyAxKTtcbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBuZXh0Lmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgIHRvdGFsID0gdG90YWwuY29uY2F0KG5leHRbaV0uX3NlbGVjdENoaWxkcyhzdWJQYXRoLCBmYWxzZSkpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0b3RhbDtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGxldCBuZXh0O1xuICAgICAgICBjb25zdCBzdHIgPSBwYXRoLnN1YnN0cigwLCBhcnJvd0lkeCk7XG4gICAgICAgIGlmIChpc1JlZikge1xuICAgICAgICAgIGNvbnN0IHJlZiA9IHRoaXMuZ2V0QnlSZWYoc3RyKTtcbiAgICAgICAgICBuZXh0ID0gcmVmID8gW3JlZl0gOiBbXTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBuZXh0ID0gdGhpcy5tdGFnKHN0cik7XG4gICAgICAgIH1cbiAgICAgICAgbGV0IHRvdGFsID0gW107XG4gICAgICAgIGNvbnN0IHN1YlBhdGggPSBwYXRoLnN1YnN0cihhcnJvd0lkeCArIDEpO1xuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IG5leHQubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgdG90YWwgPSB0b3RhbC5jb25jYXQobmV4dFtpXS5fc2VsZWN0Q2hpbGRzKHN1YlBhdGgsIHRydWUpKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdG90YWw7XG4gICAgICB9XG4gICAgfVxuICAgIGdldEJ5UmVmKHJlZikge1xuICAgICAgcmV0dXJuIHRoaXMuY2hpbGRMaXN0LmdldEJ5UmVmKHJlZik7XG4gICAgfVxuICAgIGdld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W5baV0uZ2V0U2V0dGluZ3MoKSk7XG4gICAgICAgICAgICBtaXNzaW5nID0gbWlzc2luZyB8fCAhY2hpbGRyZW5baV0ucmVmO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoIW1pc3NpbmcpIHtcbiAgICAgICAgICAgIHNldHRpbmdzLmNoaWxkcmVuID0ge307XG4gICAgICAgICAgICBjaGlsZEFycmF5LmZvckVhY2goKGNoaWxkKSA9PiB7XG4gICAgICAgICAgICAgIHNldHRpbmdzLmNoaWxkcmVuW2NoaWxkLnJlZl0gPSBjaGlsZDtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzZXR0aW5ncy5jaGlsZHJlbiA9IGNoaWxkQXJyYXk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBzZXR0aW5ncy5pZCA9IHRoaXMuaWQ7XG4gICAgICByZXR1cm4gc2V0dGluZ3M7XG4gICAgfVxuICAgIGdldE5vbkRlZmF1bHRzKCkge1xuICAgICAgbGV0IHNldHRpbmdzID0ge307XG4gICAgICBpZiAodGhpcy5jb25zdHJ1Y3RvciAhPT0gRWxlbWVudCkge1xuICAgICAgICBzZXR0aW5ncy50eXBlID0gdGhpcy5jb25zdHJ1Y3Rvci5uYW1lO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMuX19yZWYpIHtcbiAgICAgICAgc2V0dGluZ3MucmVmID0gdGhpcy5fX3JlZjtcbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLl9fdGFncyAmJiB0aGlzLl9fdGFncy5sZW5ndGgpIHtcbiAgICAgICAgc2V0dGluZ3MudGFncyA9IHRoaXMuX190YWdzO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMueCAhPT0gMClcbiAgICAgICAgc2V0dGluZ3MueCA9IHRoaXMueDtcbiAgICAgIGlmICh0aGlzLnkgIT09IDApXG4gICAgICAgIHNldHRpbmdzLnkgPSB0aGlzLnk7XG4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50b1N0cmluZygxNik7XG4gICAgICAgIGlmICh0aGlzLmNvbG9yQnIgIT09IDQyOTQ5NjcyOTUpXG4gICAgICAgICAgc2V0dGluZ3MuY29sb3JCciA9IHRoaXMuY29sb3JCci50b1N0cmluZygxNik7XG4gICAgICB9XG4gICAgICBpZiAodGhpcy56SW5kZXgpXG4gICAgICAgIHNldHRpbmdzLnpJbmRleCA9IHRoaXMuekluZGV4O1xuICAgICAgaWYgKHRoaXMuZm9yY2VaSW5kZXhDb250ZXh0KVxuICAgICAgICBzZXR0aW5ncy5mb3JjZVpJbmRleENvbnRleHQgPSB0cnVlO1xuICAgICAgaWYgKHRoaXMuY2xpcHBpbmcpXG4gICAgICAgIHNldHRpbmdzLmNsaXBwaW5nID0gdGhpcy5jbGlwcGluZztcbiAgICAgIGlmICghdGhpcy5jbGlwYm94KVxuICAgICAgICBzZXR0aW5ncy5jbGlwYm94ID0gdGhpcy5jbGlwYm94O1xuICAgICAgaWYgKHRoaXMuX190ZXh0dXJlKSB7XG4gICAgICAgIGxldCB0bmQgPSB0aGlzLl9fdGV4dHVyZS5nZXROb25EZWZhdWx0cygpO1xuICAgICAgICBpZiAoT2JqZWN0LmtleXModG5kKS5sZW5ndGgpIHtcbiAgICAgICAgICBzZXR0aW5ncy50ZXh0dXJlID0gdG5kO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5zaGFkZXIgJiYgVXRpbHMkMS5pc0Z1bmN0aW9uKHRoaXMuc2hhZGVyLmdldE5vbkRlZmF1bHRzKSkge1xuICAgICAgICBsZXQgdG5kID0gdGhpcy5zaGFkZXIuZ2V0Tm9uRGVmYXVsdHMoKTtcbiAgICAgICAgaWYgKE9iamVjdC5rZXlzKHRuZCkubGVuZ3RoKSB7XG4gICAgICAgICAgc2V0dGluZ3Muc2hhZGVyID0gdG5kO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpZiAodGhpcy5faGFzVGV4dHVyaXplcigpKSB7XG4gICAgICAgIGlm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Fg7XG4gICAgfVxuICAgIHNldCBwaXZvdFgodikge1xuICAgICAgdGhpcy5fX2NvcmUucGl2b3RYID0gdjtcbiAgICB9XG4gICAgZ2V0IHBpdm90WSgpIHtcbiAgICAgIHJldHVybiB0aGlzLl9fY29yZS5waXZvdFk7XG4gICAgfVxuICAgIHNldCBwaXZvdFkodikge1xuICAgICAgdGhpcy5fX2NvcmUucGl2b3RZID0gdjtcbiAgICB9XG4gICAgZ2V0IHBpdm90KCkge1xuICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLnBpdm90O1xuICAgIH1cbiAgICBzZXQgcGl2b3Qodikge1xuICAgICAgdGhpcy5fX2NvcmUucGl2b3QgPSB2O1xuICAgIH1cbiAgICBnZXQgbW91bnRYKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLm1vdW50WDtcbiAgICB9XG4gICAgc2V0IG1vdW50WCh2KSB7XG4gICAgICB0aGlzLl9fY29yZS5tb3VudFggPSB2O1xuICAgIH1cbiAgICBnZXQgbW91bnRZKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLm1vdW50WTtcbiAgICB9XG4gICAgc2V0IG1vdW50WSh2KSB7XG4gICAgICB0aGlzLl9fY29yZS5tb3VudFkgPSB2O1xuICAgIH1cbiAgICBnZXQgbW91bnQoKSB7XG4gICAgICByZXR1cm4gdGhpcy5fX2NvcmUubW91bnQ7XG4gICAgfVxuICAgIHNldCBtb3VudCh2KSB7XG4gICAgICB0aGlzLl9fY29yZS5tb3VudCA9IHY7XG4gICAgfVxuICAgIGdldCByb3RhdGlvbigpIHtcbiAgICAgIHJldHVybiB0aGlzLl9fY29yZS5yb3RhdGlvbjtcbiAgICB9XG4gICAgc2V0IHJvdGF0aW9uKHYpIHtcbiAgICAgIHRoaXMuX19jb3JlLnJvdGF0aW9uID0gdjtcbiAgICB9XG4gICAgZ2V0IGFscGhhKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLmFscGhhO1xuICAgIH1cbi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AgICAgICAgICAgIGMucGF0Y2godik7XG4gICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMkMS5pc09iamVjdCh2KSkge1xuICAgICAgICAgICAgICAgIGMgPSB2O1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGlmIChjLmlzRWxlbWVudCkge1xuICAgICAgICAgICAgICAgIGMucmVmID0gcGF0aDtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB0aGlzLmNoaWxkTGlzdC5hKGMpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodiA9PT0gdm9pZCAwKSB7XG4gICAgICAgICAgICAgIGlmIChjaGlsZC5wYXJlbnQpIHtcbiAgICAgICAgICAgICAgICBjaGlsZC5wYXJlbnQuY2hpbGRMaXN0LnJlbW92ZShjaGlsZCk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMkMS5pc09iamVjdExpdGVyYWwodikpIHtcbiAgICAgICAgICAgICAgY2hpbGQucGF0Y2godik7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHYuaXNFbGVtZW50KSB7XG4gICAgICAgICAgICAgIHYucmVmID0gcGF0aDtcbiAgICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QucmVwbGFjZSh2LCBjaGlsZCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICB0aGlzLl90aHJvd0Vycm9yKFwiVW5leHBlY3RlZCB2YWx1ZSBmb3IgcGF0aDogXCIgKyBwYXRoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgQmFzZS5wYXRjaE9iamVjdFByb3BlcnR5KHRoaXMsIHBhdGgsIHYpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIF90aHJvd0Vycm9yKG1lc3NhZ2UpIHtcbiAgICAgIHRocm93IG5ld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oaWxkTGlzdFxuICAgICAgICAgICk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgc3RhdGljIGdldFByb3BlcnRpZXMoZWxlbWVudCkge1xuICAgICAgY29uc3QgcHJvcHMgPSB7fTtcbiAgICAgIGNvbnN0IGxpc3QgPSBbXG4gICAgICAgIFwiYWxwaGFcIixcbiAgICAgICAgXCJhY3RpdmVcIixcbiAgICAgICAgXCJhdHRhY2hlZFwiLFxuICAgICAgICBcImJvdW5kc01hcmdpblwiLFxuICAgICAgICBcImNvbG9yXCIsXG4gICAgICAgIFwiY2xpcHBpbmdcIixcbiAgICAgICAgXCJlbmFibGVkXCIsXG4gICAgICAgIFwiaFwiLFxuICAgICAgICBcImlkXCIsXG4gICAgICAgIFwiaXNDb21wb25lbnRcIixcbiAgICAgICAgXCJtb3VudFwiLFxuICAgICAgICBcIm1vdW50WVwiLFxuICAgICAgICBcIm1vdW50WFwiLFxuICAgICAgICBcInBpdm90XCIsXG4gICAgICAgIFwicGl2b3RYXCIsXG4gICAgICAgIFwicGl2b3RZXCIsXG4gICAgICAgIFwicmVmXCIsXG4gICAgICAgIFwicmVuZGVyT2Zmc2NyZWVuXCIsXG4gICAgICAgIFwicmVuZGVyVG9UZXh0dXJlXCIsXG4gICAgICAgIFwic2NhbGVcIixcbiAgICAgICAgXCJzY2FsZVhcIixcbiAgICAgICAgXCJzY2FsZVlcIixcbiAgICAgICAgXCJzdGF0ZVwiLFxuICAgICAgICBcInRhZ1wiLFxuICAgICAgICBcInZpc2libGVcIixcbiAgICAgICAgXCJ3XCIsXG4gICAgICAgIFwieFwiLFxuICAgICAgICBcInlcIixcbiAgICAgICAgXCJ6SW5kZXhcIixcbiAgICAgICAgXCIhIWZsZXhcIixcbiAgICAgICAgXCIhIWZsZXhJdGVtXCIsXG4gICAgICAgIFwiaGFzRm9jdXMoKVwiLFxuICAgICAgICBcImhhc0ZpbmFsRm9jdXMoKVwiXG4gICAgICBdO1xuICAgICAgbGV0IG4g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AgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fX3NldFN0YXRlKG5ld1N0YXRlKTtcbiAgICAgICAgaWYgKHRoaXMuX2NoYW5nZWRTdGF0ZSkge1xuICAgICAgICAgIGNvbnN0IGNvbnRleHQgPSB7XG4gICAgICAgICAgICBuZXdTdGF0ZTogbmV3U3RhdGUuX19wYXRoLFxuICAgICAgICAgICAgcHJldlN0YXRlOiBwcmV2U3RhdGUuX19wYXRoXG4gICAgICAgICAgfTtcbiAgICAgICAgICBpZiAoYXJncykge1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZFN0YXRlKGNvbnRleHQsIC4uLmFyZ3MpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkU3RhdGUoY29udGV4dCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9vblN0YXRlQ2hhbmdlKSB7XG4gICAgICAgICAgY29uc3QgY29udGV4dCA9IHtcbiAgICAgICAgICAgIG5ld1N0YXRlOiBuZXdTdGF0ZS5fX3BhdGgsXG4gICAgICAgICAgICBwcmV2U3RhdGU6IHByZXZTdGF0ZS5fX3BhdGhcbiAgICAgICAgICB9O1xuICAgICAgICAgIHRoaXMuX29uU3RhdGVDaGFuZ2UoY29udGV4dCk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgX2NhbGxFbnRlcihzdGF0ZSwgYXJncyA9IFtdLCBjb250ZXh0KSB7XG4gICAgICBjb25zdCBoYXNQYXJlbnQgPSAhIXN0YXRlLl9fcGFyZW50O1xuICAgICAgaWYgKHN0YXRlLnByb3RvdHlwZS4kZW50ZXIpIHtcbiAgICAgICAgaWYgKCFoYXNQYXJlbnQgfHwgc3RhdGUuX19wYXJlbnQucHJvdG90eXBlLiRlbnRlciAhPT0gc3RhdGUucHJvdG90eXBlLiRlbnRlcikge1xuICAgICAgICAgIHN0YXRlL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WYgKGRlc2NyaXB0b3IpIHtcbiAgICAgICAgICBjb25zdCBkZXNjVHlwZSA9IHRoaXMuX2dldERlc2NyaXB0b3JUeXBlKGRlc2NyaXB0b3IpO1xuICAgICAgICAgIGlmICh0eXBlICYmIHR5cGUgIT09IGRlc2NUeXBlKSB7XG4gICAgICAgICAgICBjb25zb2xlLndhcm4oYFtMaWdodG5pbmddIE1lbWJlciAke21lbWJlcn0gaW4gJHt0aGlzLl90eXBlLm5hbWV9IGhhcyBpbmNvbnNpc3RlbnQgdHlwZXMuYCk7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgfVxuICAgICAgICAgIHR5cGUgPSBkZXNjVHlwZTtcbiAgICAgICAgfVxuICAgICAgfSk7XG4gICAgICBzd2l0Y2ggKHR5cGUpIHtcbiAgICAgICAgY2FzZSBcIm1ldGhvZFwiOlxuICAgICAgICAgIHRoaXMuX2FkZE1ldGhvZFJvdXRlcihtZW1iZXIsIGRlc2NyaXB0b3JzLCBhbGlhc2VzKTtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSBcImdldHRlclwiOlxuICAgICAgICAgIHRoaXMuX2FkZEdldHRlclNldHRlclJvdXRlcnMobWVtYmVyKTtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSBcInByb3BlcnR5XCI6XG4gICAgICAgICAgY29uc29sZS53YXJuKFwiW0xpZ2h0bmluZ10gRml4ZWQgcHJvcGVydGllcyBhcmUgbm90IHN1cHBvcnRlZDsgcGxlYXNlIHVzZSBhIGdldHRlciBpbnN0ZWFkIVwiKTtcbiAgICAgICAgICBicmVhaztcbiAgICAgIH1cbiAgICB9XG4gICAgX2dldERlc2NyaXB0b3Ioc3RhdGUsIG1lbWJlciwgaXNWYWxpZCA9ICgpID0+IHRydWUpIHtcbiAgICAgIGxldCB0eXBlID0gc3RhdGU7XG4gICAgICBsZXQgY3VyU3RhdGUgPSBzdGF0ZTtcbiAgICAgIGRvIHtcbiAgICAgICAgY29uc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O1xuICAgICAgICAgICAgbG9jLnB1c2goYHZhciAke3Byb3BLZXl9ID0gJHtjdXJzb3J9LmVuYWJsZVRleHRUZXh0dXJlKClgKTtcbiAgICAgICAgICAgIGlmICh2YWx1ZS5fX3Byb3BlcnR5QmluZGluZyA9PT0gdHJ1ZSkge1xuICAgICAgICAgICAgICBzdG9yZS5wdXNoKHZhbHVlKTtcbiAgICAgICAgICAgICAgbG9jLnB1c2goYGVsZW1lbnQuX19iaW5kUHJvcGVydHkoc3RvcmVbJHtzdG9yZS5sZW5ndGggLSAxfV0sICR7Y3Vyc29yfSwgXCIke2tleX1cIilgKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHRoaXMucGFyc2VUZW1wbGF0ZVByb3BSZWModmFsdWUsIGNvbnRleHQsIHByb3BLZXkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAoa2V5ID09PSBcInNoYWRlclwiICYmIFV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKHZhbHVlKSkge1xuICAgICAgICAgICAgY29uc3Qgc2hhZGVyQ3Vyc29yID0gYCR7Y3Vyc29yfVtcInNoYWRlclwiXWA7XG4gICAgICAgICAgICBzdG9yZS5wdXNoKHZhbHVlKTtcbiAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn1bXCIke2tleX1cIl0gPSBzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XWApO1xuICAgICAgICAgICAgdGhpcy5wYXJzZVByb3BlcnR5QmluZGluZ3ModmFsdWUsIGNvbnRleHQsIHNoYWRlckN1cnNvcik7XG4gICAgICAgICAgfSBlbHNlIGlmIChrZXkgPT09IFwidGV4dHVyZVwiICYmIFV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKHZhbHVlKSkge1xuICAgICAgICAgICAgY29uc3QgcHJvcEtleSA9IGN1cnNvciArIFwiX190ZXh0dXJlXCI7XG4gICAgICAgICAgICBjb25zdCB0eXBlID0gdmFsdW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cG9uZW50KSB7XG4gICAgICAgIGFuY2VzdG9yID0gYW5jZXN0b3IucGFyZW50O1xuICAgICAgfVxuICAgICAgcmV0dXJuIGFuY2VzdG9yO1xuICAgIH1cbiAgICBnZXQgc2lnbmFscygpIHtcbiAgICAgIHJldHVybiB0aGlzLl9fc2lnbmFscztcbiAgICB9XG4gICAgc2V0IHNpZ25hbHModikge1xuICAgICAgaWYgKCFVdGlscyQxLmlzT2JqZWN0TGl0ZXJhbCh2KSkge1xuICAgICAgICB0aGlzLl90aHJvd0Vycm9yKFwiU2lnbmFsczogc3BlY2lmeSBhbiBvYmplY3Qgd2l0aCBzaWduYWwtdG8tZmlyZSBtYXBwaW5nc1wiKTtcbiAgICAgIH1cbiAgICAgIHRoaXMuX19zaWduYWxzID0gdjtcbiAgICB9XG4gICAgc2V0IGFsdGVyU2lnbmFscyh2KSB7XG4gICAgICBpZiAoIVV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKHYpKSB7XG4gICAgICAgIHRoaXMuX3Rocm93RXJyb3IoXCJTaWduYWxzOiBzcGVjaWZ5IGFuIG9iamVjdCB3aXRoIHNpZ25hbC10by1maXJlIG1hcHBpbmdzXCIpO1xuICAgICAgfVxuICAgICAgaWYgKCF0aGlzLl9fc2lnbmFscykge1xuICAgICAgICB0aGlzLl9fc2lnbmFscyA9IHt9O1xuICAgICAgfVxuICAgICAgZm9yIChsZXQga2V5IGluIHYpIHtcbiAgICAgICAgY29uc3QgZCA9IHZba2V5XTtcbiAgICAgICAgaWYgKGQgPT09IHZvaWQgMCkge1xuICAgICAgICAgIGRlbGV0ZSB0aGlzLl9fc2lnbmFsc1trZXldO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMuX19zaWduYWxzW2tleV0gPSB2O1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIGdldCBwYXNzU2lnbmFscygpIHtcbiAgICAgIHJldHVybiB0aGlzLl9fcGFzc1NpZ25hbHMgfHwge307XG4gICAgfVxuICAgIHNldCBwYXNzU2lnbmFscyh2KSB7XG4gICAgICB0aGlzLl9fcGFzc1NpZ25hbHMgPSBPYmplY3QuYXNzaWduKHRoaXMuX19wYXNzU2lnbmFscyB8fCB7fSwgdik7XG4gICAgfVxuICAgIHNldCBhbHRlclBhc3NTaWduYWxzKHYpIHtcbiAgICAgIGlmICghVXRpbHMkMS5pc09iamVjdExpdGVyYWwodikpIHtcbiAgICAgICAgdGhpcy5fdGhyb3dFcnJvcihcIlNpZ25hbHM6IHNwZWNpZnkgYW4gb2JqZWN0IHdpdGggc2lnbmFsLXRvLWZpcmUgbWFwcGluZ3NcIik7XG4gICAgICB9XG4gICAgICBpZiAoIXRoaXMuX19wYXNzU2lnbmFscykge1xuICAgICAgICB0aGlzLl9fcGFzc1NpZ25hbHMgPSB7fTtcbiAgICAgIH1cbiAgICAgIGZvciAobGV0IGtleSBpbiB2KSB7XG4gICAgICAgIGNvbnN0IGQgPSB2W2tleV07XG4gICAgICAgIGlmIChkID09PSB2b2lkIDApIHtcbiAgICAgICAgICBkZWxldGUgdGhpcy5fX3Bhc3NTaWduYWxzW2tleV07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdGhpcy5fX3Bhc3NTaWduYWxzW2tleV0gPSB2O1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIHNpZ25hbChldmVudCwgLi4uYXJncykge1xuICAgICAgcmV0dXJuIHRoaXMuX3NpZ25hbChldmVudCwgYXJncyk7XG4gICAgfVxuICAgIF9zaWduYWwoZXZlbnQsIGFyZ3MpIHtcbiAgICAgIGNvbnN0IHNpZ25hbFBhcmVudCA9IHRoaXMuX2dldFBhcmVudFNpZ25hbEhhbmRsZXIoKTtcbiAgICAgIGlmIChzaWduYWxQYXJlbnQpIHtcbiAgICAgICAgaWYgKHRoaXMuX19zaWduYWxzKSB7XG4gICAgICAgICAgbGV0IGZpcmVFdmVudCA9IHRoaXMuX19zaWduYWxzW2V2ZW50XTtcbiAgICAgICAgICBpZiAoZmlyZUV2ZW50ID09PSBmYWxzZSkge1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoZmlyZUV2ZW50KSB7XG4gICAgICAgICAgICBpZiAoZmlyZUV2ZW50ID09PSB0cnVlKSB7XG4gICAgICAgICAgICAgIGZpcmVFdmVudCA9IGV2ZW50O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKFV0aWxzJDEuaXNGdW5jdGlvbihmaXJlRXZlbnQpKSB7XG4gICAgICAgICAgICAgIHJldHVybiBmaXJlRXZlbnQoLi4uYXJncyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoc2lnbmFsUGFyZW50Ll9oYXNNZXRob2QoZmlyZUV2ZW50KSkge1xuICAgICAgICAgICAgICByZXR1cm4gc2lnbmFsUGFyZW50W2ZpcmVFdmVudF0oLi4uYXJncyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGxldCBwYXNzU2lnbmFsID0gdGhpcy5fX3Bhc3NTaWduYWxzICYmIHRoaXMuX19wYXNzU2lnbmFsc1tldmVudF07XG4gICAgICAgIGlmIChwYXNzU2lnbmFsKSB7XG4gICAgICAgICAgaWYgKHBhc3NTaWduYWwgJiYgcGFzc1NpZ25hbCAhPT0gdHJ1ZSkge1xuICAgICAgICAgICAgZXZlbnQgPSBwYXNzU2lnbmFsO1xuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4gc2lnbmFsUGFyZW50Ll9zaWduYWwoZXZlbnQsIGFyZ3MpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICAgIF9nZXRQYXJlbnRTaWduYWxIYW5kbGVyKCkge1xuICAgICAgcmV0dXJuIHRoaXMuY3BhcmVudCA/IHRoaXMuY3BhcmVudC5fZ2V0U2lnbmFsSGFuZGxlcigpIDogbnVsbDtcbiAgICB9XG4gICAgX2dldFNpZ25hbEhhbmRsZXIoK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2xsZWN0U3ViQ29tcG9uZW50cyhzdWJzLCBlbGVtZW50KSB7XG4gICAgICBpZiAoZWxlbWVudC5oYXNDaGlsZHJlbigpKSB7XG4gICAgICAgIGNvbnN0IGNoaWxkTGlzdCA9IGVsZW1lbnQuX19jaGlsZExpc3Q7XG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gY2hpbGRMaXN0Lmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgIGNvbnN0IGNoaWxkID0gY2hpbGRMaXN0LmdldEF0KGkpO1xuICAgICAgICAgIGlmIChjaGlsZC5pc0NvbXBvbmVudCkge1xuICAgICAgICAgICAgc3Vicy5wdXNoKGNoaWxkKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgQ29tcG9uZW50LmNvbGxlY3RTdWJDb21wb25lbnRzKHN1YnMsIGNoaWxkKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gICAgc3RhdGljIGdldENvbXBvbmVudChlbGVtZW50KSB7XG4gICAgICBsZXQgcGFyZW50ID0gZWxlbWVudDtcbiAgICAgIHdoaWxlIChwYXJlbnQgJiYgIXBhcmVudC5pc0NvbXBvbmVudCkge1xuICAgICAgICBwYXJlbnQgPSBwYXJlbnQucGFyZW50O1xuICAgICAgfVxuICAgICAgcmV0dXJuIHBhcmVudDtcbiAgICB9XG4gICAgc3RhdGljIGdldFBhcmVudChlbGVtZW50KSB7XG4gICAgICByZXR1cm4gQ29tcG9uZW50LmdldENvbXBvbmVudChlbGVtZW50LnBhcmVudCk7XG4gICAgfVxuICB9XG4gIENvbXBvbmVudC5wcm90b3R5cGUuaXNDb21wb25lbnQgPSB0cnVlO1xuICBjbGFzcyBDb3JlUXVhZExpc3Qge1xuICAgIGNvbnN0cnVjdG9yKGN0eCkge1xuICAgICAgdGhpcy5jdHggPSBjdHg7XG4gICAgICB0aGlzLnF1YWRUZXh0dXJlcyA9IFtdO1xuICAgICAgdGhpcy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rXSA9IGVsZW1lbnRDb3JlLl91bHk7XG4gICAgICAgIHVpbnRzW29mZnNldCsrXSA9IG1jYShlbGVtZW50Q29yZS5fY29sb3JVciwgci5hbHBoYSk7XG4gICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSByLnB4ICsgZWxlbWVudENvcmUuX3cgKiByLnRhICsgZWxlbWVudENvcmUuX2ggKiByLnRiO1xuICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weSArIGVsZW1lbnRDb3JlLl93ICogci50YyArIGVsZW1lbnRDb3JlLl9oICogci50ZDtcbiAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl9icng7XG4gICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ5O1xuICAgICAgICB1aW50c1tvZmZzZXQrK10gPSBtY2EoZWxlbWVudENvcmUuX2NvbG9yQnIsIHIuYWxwaGEpO1xuICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weCArIGVsZW1lbnRDb3JlLl9oICogci50YjtcbiAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHkgKyBlbGVtZW50Q29yZS5faCAqIHIudGQ7XG4gICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fdWx4O1xuICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX2JyeTtcbiAgICAgICAgdWludHNbb2Zmc2V0XSA9IG1jYShlbGVtZW50Q29yZS5fY29sb3JCbCwgci5hbHBoYSk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBsZXQgY3ggPSByLnB4ICsgZWxlbWVudENvcmUuX3cgKiByLnRhO1xuICAgICAgICBsZXQgY3kgPSByLnB5ICsgZWxlbWVudENvcmUuX2ggKiByLnRkO1xuICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weDtcbiAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHk7X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WxheSkge1xuICAgICAgICB0aGlzLl9pZGxlTG9vcENvdW50ZXIrKztcbiAgICAgICAgcmV0dXJuO1xuICAgICAgfVxuICAgICAgaWYgKCF0aGlzLnN0YWdlLmN0eC5oYXNSZW5kZXJVcGRhdGVzKCkpIHtcbiAgICAgICAgdGhpcy5zdG9wTG9vcCgpO1xuICAgICAgICB0aGlzLl9sb29wSGFuZGxlciA9IHNldEludGVydmFsKCgpID0+IHtcbiAgICAgICAgICB0aGlzLnN0YWdlLnVwZGF0ZUZyYW1lKCk7XG4gICAgICAgICAgdGhpcy5zdGFnZS5pZGxlRnJhbWUoKTtcbiAgICAgICAgICBpZiAodGhpcy5zdGFnZS5jdHguaGFzUmVuZGVyVXBkYXRlcygpKSB7XG4gICAgICAgICAgICBjbGVhckludGVydmFsKHRoaXMuX2xvb3BIYW5kbGVyKTtcbiAgICAgICAgICAgIHRoaXMuc3RhcnRMb29wKCk7XG4gICAgICAgICAgfVxuICAgICAgICB9LCAxZTMgLyA2MCk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICB0aGlzLl9pZGxlTG9vcENvdW50ZXIgPSAwO1xuICAgICAgfVxuICAgIH1cbiAgICBsb29wKCkge1xuICAgICAgbGV0IHNlbGYyID0gdGhpcztcbiAgICAgIGxldCBscCA9IGZ1bmN0aW9uKCkge1xuICAgICAgICBzZWxmMi5fYXdhaXRpbmdMb29wID0gZmFsc2U7XG4gICAgICAgIGlmIChzZWxmMi5fbG9vcGluZykge1xuICAgICAgICAgIHNlbGYyLnN0YWdlLnVwZGF0ZUZyYW1lKCk7XG4gICAgICAgICAgaWYgKHNlbGYyLnN0YWdlLmdldE9wdGlvbihcInBhdXNlUmFmTG9vcE9uSWRsZVwiKSkge1xuICAgICAgICAgICAgc2VsZjIuc3dpdGNoTG9vcCgpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBzZWxmMi5zdGFnZS5yZW5kZXJGcmFtZSgpO1xuICAgICAgICAgIHJlcXVlc3RBbmltYXRpb25Gc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IGdsSW50ZXJuYWxGb3JtYXQ6IHZpZXcuZ2V0VWludDMyKDI4LCBsaXR0bGVFbmRpYW4pLFxuICAgICAgICAgIGdsQmFzZUludGVybmFsRm9ybWF0OiB2aWV3LmdldFVpbnQzMigzMiwgbGl0dGxlRW5kaWFuKSxcbiAgICAgICAgICBwaXhlbFdpZHRoOiB2aWV3LmdldFVpbnQzMigzNiwgbGl0dGxlRW5kaWFuKSxcbiAgICAgICAgICBwaXhlbEhlaWdodDogdmlldy5nZXRVaW50MzIoNDAsIGxpdHRsZUVuZGlhbiksXG4gICAgICAgICAgcGl4ZWxEZXB0aDogdmlldy5nZXRVaW50MzIoNDQsIGxpdHRsZUVuZGlhbiksXG4gICAgICAgICAgbnVtYmVyT2ZBcnJheUVsZW1lbnRzOiB2aWV3LmdldFVpbnQzMig0OCwgbGl0dGxlRW5kaWFuKSxcbiAgICAgICAgICBudW1iZXJPZkZhY2VzOiB2aWV3LmdldFVpbnQzMig1MiwgbGl0dGxlRW5kaWFuKSxcbiAgICAgICAgICBudW1iZXJPZk1pcG1hcExldmVsczogdmlldy5nZXRVaW50MzIoNTYsIGxpdHRsZUVuZGlhbiksXG4gICAgICAgICAgYnl0ZXNPZktleVZhbHVlRGF0YTogdmlldy5nZXRVaW50MzIoNjAsIGxpdHRsZUVuZGlhbiksXG4gICAgICAgICAga3ZwczogW10sXG4gICAgICAgICAgbWlwbWFwczogW10sXG4gICAgICAgICAgZ2V0IHdpZHRoKCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMucGl4ZWxXaWR0aDtcbiAgICAgICAgICB9LFxuICAgICAgICAgIGdldCBoZWlnaHQoKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5waXhlbEhlaWdodDtcbiAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIGNvbnN0IHByb3BzID0gKG9iaikgPT4ge1xuICAgICAgICAgIGNvbnN0IHAgPSBbXTtcbiAgICAgICAgICBmb3IgKGxldCB2IGluIG9ia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AgICAgICBtaXBtYXBzOiBbXSxcbiAgICAgICAgICBwdnI6IHRydWUsXG4gICAgICAgICAgZ2V0IHdpZHRoKCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMucGl4ZWxXaWR0aDtcbiAgICAgICAgICB9LFxuICAgICAgICAgIGdldCBoZWlnaHQoKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5waXhlbEhlaWdodDtcbiAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIGxldCBvZmZzZXQgPSAwO1xuICAgICAgICBsZXQgd2lkdGggPSBkYXRhLnBpeGVsV2lkdGg7XG4gICAgICAgIGxldCBoZWlnaHQgPSBkYXRhLnBpeGVsSGVpZ2h0O1xuICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGRhdGEubnVtYmVyT2ZNaXBtYXBMZXZlbHM7IGkrKykge1xuICAgICAgICAgIGNvbnN0IGxldmVsID0gKHdpZHRoICsgMyA+PiAyKSAqIChoZWlnaHQgKyAzID4+IDIpICogODtcbiAgICAgICAgICBjb25zdCB2aWV3ID0gbmV3IFVpbnQ4QXJyYXkoYXJyYXlCdWZmZXIsIHB2cnRjRGF0YS5ieXRlT2Zmc2V0ICsgb2Zmc2V0LCBsZXZlbCk7XG4gICAgICAgICAgZGF0YS5taXBtYXBzLnB1c2godmlldyk7XG4gICAgICAgICAgb2Zmc2V0ICs9IGxldmVsO1xuICAgICAgICAgIHdpZHRoID0gd2lkdGggPj4gMTtcbiAgICAgICAgICBoZWlnaHQgPSBoZWlnaHQgPj4gMTtcbiAgICAgICAgfVxuICAgICAgICBjYihudWxsLCB7XG4gICAgICAgICAgc291cmNlOiBkYXRhLFxuICAgICAgICAgIHJlbmRlckluZm86IHsgc3JjLCBjb21wcmVzc2VkOiB0cnVlIH1cbiAgICAgICAgfSk7XG4gICAgICB9O1xuICAgIH1cbiAgICBsb2FkU3JjVGV4dHVyZSh7IHNyYywgaGFzQWxwaGEgfSwgY2IpIHtcbiAgICAgIGxld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W1hZ2Uub25Mb2FkID0gZnVuY3Rpb24oeyBpbWFnZUJpdG1hcCwgaGFzQWxwaGFDaGFubmVsIH0pIHtcbiAgICAgICAgICBjYihudWxsLCB7XG4gICAgICAgICAgICBzb3VyY2U6IGltYWdlQml0bWFwLFxuICAgICAgICAgICAgcmVuZGVySW5mbzogeyBzcmMsIGNvbXByZXNzZWQ6IGZhbHNlIH0sXG4gICAgICAgICAgICBoYXNBbHBoYTogaGFzQWxwaGFDaGFubmVsLFxuICAgICAgICAgICAgcHJlbXVsdGlwbHlBbHBoYTogdHJ1ZVxuICAgICAgICAgIH0pO1xuICAgICAgICB9O1xuICAgICAgICBjYW5jZWxDYiA9IGZ1bmN0aW9uKCkge1xuICAgICAgICAgIGltYWdlLmNhbmNlbCgpO1xuICAgICAgICB9O1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgbGV0IGltYWdlID0gbmV3IEltYWdlKCk7XG4gICAgICAgIGlmICghKHNyYy5zdWJzdHIoMCwgNSkgPT0gXCJkYXRhOlwiKSAmJiAhVXRpbHMkMS5pc1BTNCkge1xuICAgICAgICAgIGltYWdlLmNyb3NzT3JpZ2luID0gXCJBbm9ueW1vdXNcIjtcbiAgICAgICAgfVxuICAgICAgICBpbWFnZS5vbmVycm9yID0gZnVuY3Rpb24oZXJyKSB7XG4gICAgICAgICAgaWYgKGltYWdlLnNyYykge1xuICAgICAgICAgICAgcmV0dXJuIGNiKFwiSW1hZ2UgbG9hZCBlcnJvclwiKTtcbiAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIGltYWdlLm9ubG9hZCA9IGZ1bmN0aW9uKCkge1xuICAgICAgICAgIGNiKG51bGwsIHtcbiAgICAgICAgICAgIHNvdXJjZTogaW1hZ2UsXG4gICAgICAgICAgICByZW5kZXJJbmZvOiB7IHNyYywgY29tcHJlc3NlZDogZmFsc2UgfSxcbiAgICAgICAgICAgIGhhc0FscGhhOiBpc1BuZyB8fCBoYXNBbHBoYVxuICAgICAgICAgI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V0dXJuIFV0aWxzLmdldE1vZHVsb0luZGV4KGluZGV4LCBhcnIubGVuZ3RoKTtcbiAgICB9XG4gICAgc3RhdGljIGVxdWFsVmFsdWVzKHYxLCB2Mikge1xuICAgICAgaWYgKHR5cGVvZiB2MSAhPT0gdHlwZW9mIHYyKVxuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKHYxKSkge1xuICAgICAgICByZXR1cm4gVXRpbHMuaXNPYmplY3RMaXRlcmFsKHYyKSAmJiBVdGlscy5lcXVhbE9iamVjdExpdGVyYWxzKHYxLCB2Mik7XG4gICAgICB9IGVsc2UgaWYgKEFycmF5LmlzQXJyYXkodjEpKSB7XG4gICAgICAgIHJldHVybiBBcnJheS5pc0FycmF5KHYyKSAmJiBVdGlscy5lcXVhbEFycmF5cyh2MSwgdjIpO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIHYxID09PSB2MjtcbiAgICAgIH1cbiAgICB9XG4gICAgc3RhdGljIGVxdWFsT2JqZWN0TGl0ZXJhbHMob2JqMSwgb2JqMikge1xuICAgICAgbGV0IGtleXMxID0gT2JqZWN0LmtleXMob2JqMSk7XG4gICAgICBsZXQga2V5czIgPSBPYmplY3Qua2V5cyhvYmoyKTtcbiAgICAgIGlmIChrZXlzMS5sZW5ndGggIT09IGtleXMyLmxlbmd0aCkge1xuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICB9XG4gICAgICBmb3IgKGxldCBpID0gMCwgbiA9IGtleXMxLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICBjb25zdCBrMSA9IGtleXMxW2ldO1xuICAgICAgICBjb25zdCBrMiA9IGtleXMyW2ldO1xuICAgICAgICBpZiAoazEgIT09IGsyKSB7XG4gICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIGNvbnN0IHYxID0gb2JqMVtrMV07XG4gICAgICAgIGNvbnN0I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gIGNvbnN0cnVjdG9yKCkge1xuICAgICAgdGhpcy5fY2xlYXIoKTtcbiAgICB9XG4gICAgX2NsZWFyKCkge1xuICAgICAgdGhpcy5fcCA9IFtdO1xuICAgICAgdGhpcy5fcGUgPSBbXTtcbiAgICAgIHRoaXMuX2lkcCA9IFtdO1xuICAgICAgdGhpcy5fZiA9IFtdO1xuICAgICAgdGhpcy5fdiA9IFtdO1xuICAgICAgdGhpcy5fbHYgPSBbXTtcbiAgICAgIHRoaXMuX3NtID0gW107XG4gICAgICB0aGlzLl9zID0gW107XG4gICAgICB0aGlzLl92ZSA9IFtdO1xuICAgICAgdGhpcy5fc21lID0gW107XG4gICAgICB0aGlzLl9zZSA9IFtdO1xuICAgICAgdGhpcy5fbGVuZ3RoID0gMDtcbiAgICB9XG4gICAgcGFyc2UocmdiYSwgZGVmKSB7XG4gICAgICBsZXQgaSwgbjtcbiAgICAgIGlmICghVXRpbHMkMS5pc09iamVjdExpdGVyYWwoZGVmKSkge1xuICAgICAgICBkZWYgPSB7IDA6IGRlZiB9O1xuICAgICAgfVxuICAgICAgbGV0IGRlZmF1bHRTbW9vdGhuZXNzID0gMC41O1xuICAgICAgbGV0IGl0ZW1zID0gW107XG4gICAgICBmb3IgKGxldCBrZXkgaW4gZGVmKSB7XG4gICAgICAgIGlmIChkZWYuaGFzT3duUHJvcGVydHkoa2V5KSkge1xuICAgICAgICAgIGxldCBvYmogPSBkZWZba2V5XTtcbiAgICAgICAgICBpZiAoIVV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKG9iaikpIHtcbiAgICAgICAgICAgIG9iaiA9IHsgdjogb2JqIH07XG4gICAgICAgICAgfVxuICAgICAgICAgIGxldCBwID0gcGFyc2VGbG9hdChrZXkpO1xuICAgICAgICAgIGlmIChrZXkgPT09IFwic21cIikge1xuICAgICAgICAgICAgZGVmYXVsdFNtb290aG5lc3MgPSBvYmoudjtcbiAgICAgICAgICB9IGVsc2UgaWYgKCFpc05hTihwKSAmJiBwID49IDAgJiYgcCA8PSAyKSB7XG4gICAgICAgICAgICBvYmoucCA9IHA7XG4gICAgICAgICAgICBvYmouZiA9IFV0aWxzJDEuaXNGdW5jdGlvbihvYmoudik7XG4gICAgICAgICAgICBvYmoubHYgPSBvYmouZiA/IG9iai52KDAsIDApIDogb2JqLnY7XG4gICAgICAgICAgICBpdGVtcy5wdXNoKG9iaik7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBpdGVtcyA9IGl0ZW1zLnNvcnQoZnVuY3Rpb24oYSwgYikge1xuICAgICAgICByZXR1cm4gYS5wIC0gYi5wO1xuICAgICAgfSk7XG4gICAgICBuID0gaXRlbXMubGVuZ3RoO1xuICAgICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICBsZXQgbGFzdCA9IGkgPT09IG4gLSAxO1xuICAgICAgICBpZiAoIWl0ZW1zW2ldLmhhc093blByb3BlcnR5KFwicGVcIikpIHtcbiAgICAgICAgICBpdGVtc1tpXS5wZSA9IGxhc3QgPyBpdGVtc1tpXS5wIDw9IDEgPyAxIDogMiA6IGl0ZW1zW2kgKyAxXS5wO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGNvbnN0IG1heCA9IGkgPCBuIC0gMSA/IGl0ZW1zW2kgKyAxXS5wIDogMTtcbiAgICAgICAgICBpZiAoaXRlbXNbaV0ucGUgPiBtYXgpIHtcbiAgICAgICAgICAgIGl0ZW1zW2ldLnBlID0gbWF4O1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAoaXRlbXNbaV0ucGUgPT09IGl0ZW1zW2ldLnApIHtcbiAgICAgICAgICBpdGVtc1tpXS5pZHAgPSAwO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGl0ZW1zW2ldLmlkcCA9IDEgLyAoaXRlbXNbaV0ucGUgLSBpdGVtc1tpXS5wKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICBpZiAoIWl0ZW1zW2ldLmhhc093blByb3BlcnR5KFwic21cIikpIHtcbiAgICAgICAgICBpdGVtc1tpXS5zbSA9IGRlZmF1bHRTbW9vdGhuZXNzO1xuICAgICAgICB9XG4gICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoXCJzXCIpKSB7XG4gICAgICAgICAgaWYgKGkgPT09IDAgfHwgaSA9PT0gbiAtIDEgfHwgaXRlbXNbaV0ucCA9PT0gMSkge1xuICAgICAgICAgICAgaXRlbXNbaV0ucyA9IHJnYmEgPyBbMCwgMCwgMCwgMF0gOiAwO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb25zdCBwaSA9IGl0ZW1zW2kgLSAxXTtcbiAgICAgICAgICAgIGNvbnN0IG5pID0gaXRlbXNbaSArIDFdO1xuICAgICAgICAgICAgaWYgKHBpLnAgPT09IG5pLnApIHtcbiAgICAgICAgICAgICAgaXRlbXNbaV0ucyA9IHJnYmEgPyBbMCwgMCwgMCwgMF0gOiAwO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgaWYgKHJnYmEpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBuYyA9IE11bHRpU3BsaW5lLmdldFJnYmFDb21wb25lbnRzKG5pLmx2KTtcbiAgICAgICAgICAgICAgICBjb25zdCBwYyA9IE11bHRpU3BsaW5lLmdldFJnYmFDb21wb25lbnRzKHBpLmx2KTtcbiAgICAgICAgICAgICAgICBjb25zdCBkID0gMSAvIChuaS5wIC0gcGkucCk7XG4gICAgICAgICAgICAgICAgaXRlbXNbaV0ucyA9IFtcbiAgICAgICAgICAgICAgICAgIGQgKiAobmNbMF0gLSBwY1swXSksXG4gICAgICAgICAgICAgICAgICBkICogKG5jWzFdIC0gcGNbMV0pLFxuICAgICAgICAgICAgICAgICAgZCAqIChuY1syXSAtIHBjWzJdKSxcbiAgICAgICAgICAgICAgICAgIGQgKiAobmNbM10gLSBwY1szXSlcbiAgICAgICAgICAgICAgICBdO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGl0ZW1zW2ldLnMgPSAobmkubHYgLSBwaS5sdikgLyAobmkucCAtIHBpLnApO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBmb3IgKGkgPSAwOyBpIDwgbiAtIDE7IGkrKykge1xuICAgICAgICBpZiAoIWl0ZW1zW2ldLmYpIHtcbiAgICAgICAgICBsZXQgbGFzdCA9IGkgPT09IG4gLSAxO1xuICAgICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoXCJ2ZVwiKSkge1xuICAgICAgICAgICAgaXRlbXNbaV0udmUgPSBsYXN0ID8gaXRlbXNbaV0ubHYgOiBpdGVtc1tpICsgMV0ubHY7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChVdGlscyQxLmlzTnVtYmVyKGl0ZW1zW2ldLnYpICYmIFV0aWxzJDEuaXNOdW1iZXIoaXRlbXNbaV0ubHYpKSB7XG4gICAgICAgICAgICBpZiAoIWl0ZW1zW2ldLmhhc093blByb3BlcnR5KFwic21lXCIpKSB7XG4gICAgICAgICAgICAgIGl0ZW1zW2ldLnNtZSA9IGxhc3QgPyBkZWZhdWx0U21vb3RobmVzcyA6IGl0ZW1zW2kgKyAxXS5zbTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoXCJzZVwiKSkge1xuICAgICAgICAgICAgICBpdGVtc1tpXS5zZSA9IGxhc3QgPyByZ2JhID8gWzAsIDAsIDAsIDBdIDogMCA6IGl0ZW1zW2kgKyAxXS5zO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHJnYmEpIHtcbiAgICAgICAgICAgICAgaXRlbXNbaV0udiA9IE11bHRpU3BsaW5lLmdldFNw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gICB0aGlzLl9zbS5wdXNoKGl0ZW0uc20gfHwgMCk7XG4gICAgICB0aGlzLl9zLnB1c2goaXRlbS5zIHx8IDApO1xuICAgICAgdGhpcy5fdmUucHVzaChpdGVtLnZlIHx8IDApO1xuICAgICAgdGhpcy5fc21lLnB1c2goaXRlbS5zbWUgfHwgMCk7XG4gICAgICB0aGlzLl9zZS5wdXNoKGl0ZW0uc2UgfHwgMCk7XG4gICAgICB0aGlzLl9sZW5ndGgrKztcbiAgICB9XG4gICAgX2dldEl0ZW0ocCkge1xuICAgICAgY29uc3QgbiA9IHRoaXMuX2xlbmd0aDtcbiAgICAgIGlmICghbikge1xuICAgICAgICByZXR1cm4gLTE7XG4gICAgICB9XG4gICAgICBpZiAocCA8IHRoaXMuX3BbMF0pIHtcbiAgICAgICAgcmV0dXJuIDA7XG4gICAgICB9XG4gICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICBpZiAodGhpcy5fcFtpXSA8PSBwICYmIHAgPCB0aGlzLl9wZVtpXSkge1xuICAgICAgICAgIHJldHVybiBpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gbiAtIDE7XG4gICAgfVxuICAgIGdldFZhbHVlKHApIHtcbiAgICAgIGNvbnN0IGkgPSB0aGlzLl9nZXRJdGVtKHApO1xuICAgICAgaWYgKGkgPT09IC0xKSB7XG4gICAgICAgIHJldHVybiB2b2lkIDA7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBpZiAodGhpcy5fZltpXSkge1xuICAgICAgICAgIGNvbnN0IG8gPSBNYXRoLm1pbigxLCBNYXRoLm1heCgwLCAocCAtIHRoaXMuX3BbaV0pICogdGhpcy5faWRwW2ldKSk7XG4gICAgICAgICAgcmV0dXJuIHRoaXMuX3ZbaV0obyk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgcmV0dXJuIHRoaXMuX3ZbaV07XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gIC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IChwID09PSAwKVxuICAgICAgICAgICAgcmV0dXJuIHYxO1xuICAgICAgICAgIGlmIChwID09PSAxKVxuICAgICAgICAgICAgcmV0dXJuIHYyO1xuICAgICAgICAgIHJldHVybiBNdWx0aVNwbGluZS5tZXJnZUNvbG9ycyh2MiwgdjEsIHApO1xuICAgICAgICB9O1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKHApIHtcbiAgICAgICAgICBpZiAocCA9PT0gMClcbiAgICAgICAgICAgIHJldHVybiB2MTtcbiAgICAgICAgICBpZiAocCA9PT0gMSlcbiAgICAgICAgICAgIHJldHVybiB2MjtcbiAgICAgICAgICByZXR1cm4gTXVsdGlTcGxpbmUuZ2V0QXJnYk51bWJlcihbXG4gICAgICAgICAgICBNYXRoLm1pbigyNTUsIE11bHRpU3BsaW5lLmNhbGN1bGF0ZVNwbGluZShoZWxwZXJzWzBdLCBwKSksXG4gICAgICAgICAgICBNYXRoLm1pbigyNTUsIE11bHRpU3BsaW5lLmNhbGN1bGF0ZVNwbGluZShoZWxwZXJzWzFdLCBwKSksXG4gICAgICAgICAgICBNYXRoLm1pbigyNTUsIE11bHRpU3BsaW5lLmNhbGN1bGF0ZVNwbGluZShoZWxwZXJzWzJdLCBwKSksXG4gICAgICAgICAgICBNYXRoLm1pbigyNTUsIE11bHRpU3BsaW5lLmNhbGN1bGF0ZVNwbGluZShoZWxwZXJzWzNdLCBwKSlcbiAgICAgICAgICBdKTtcbiAgICAgICAgfTtcbiAgICAgIH1cbiAgICB9XG4gICAgc3RhdGljIGdldFNwbGluZUhlbHBlcnModjEsIHYyLCBvMSwgaTIsIHMxLCBzMikge1xuICAgICAgaWYgKCFvMSAmJiAhaTIpIHtcbiAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICB9XG4gICAgICBsZXQgY3N4ID0gbzE7XG4gICAgICBsZXQgY3N5ID0gdjEgKyBzMSAqIG8xO1xuICAgICAgbGV0IGNleCA9IDEgLSBpMjt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IHQgKiAodCAqICh0ICogeWEgKyB5YikgKyB5YykgKyB5ZDtcbiAgICAgICAgfVxuICAgICAgICBsZXQgY2J4ZCA9IHQgKiAodCAqICgzICogeGEpICsgMiAqIHhiKSArIHhjO1xuICAgICAgICBpZiAoY2J4ZCA+IDFlLTEwICYmIGNieGQgPCAxZS0xMCkge1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIHQgKz0gZHggLyBjYnhkO1xuICAgICAgfVxuICAgICAgbGV0IG1pblQgPSAwO1xuICAgICAgbGV0IG1heFQgPSAxO1xuICAgICAgZm9yIChsZXQgaXQgPSAwOyBpdCA8IDIwOyBpdCsrKSB7XG4gICAgICAgIHQgPSAwLjUgKiAobWluVCArIG1heFQpO1xuICAgICAgICBjYnggPSB0ICogKHQgKiAodCAqIHhhICsgeGIpICsgeGMpO1xuICAgICAgICBkeCA9IHAgLSBjYng7XG4gICAgICAgIGlmIChkeCA+IC0xZS04ICYmIGR4IDwgMWUtOCkge1xuICAgICAgICAgIHJldHVybiB0ICogKHQgKiAodCAqIHlhICsgeWIpICsgeWMpICsgeWQ7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGR4IDwgMCkge1xuICAgICAgICAgIG1heFQgPSB0O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIG1pblQgPSB0O1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gdDtcbiAgICB9XG4gICAgc3RhdGljIG1lcmdlQ29sb3JzKGMxLCBjMiwgcCkge1xuICAgICAgbGV0IHIxID0gKGMxIC8gNjU1MzYgfCAwKSAlIDI1NjtcbiAgICAgIGxldCBnMSA9IChjMSAvIDI1NiB8IDApICUgMjU2O1xuICAgICAgbGV0IGIxID0gYzEgJSAyNTY7XG4gICAgICBsZXQgYTEgPSBjMSAvIDE2Nzc3MjE2IHwgMDtcbiAgICAgIGxldCByMiA9IChjMiAvIDY1NTM2IHwgMCkgJSAyNTY7XG4gICAgICBsZXQgZzIgP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IE9iamVjdC5rZXlzKGEpO1xuICAgICAgY29uc3QgYmtzID0gT2JqZWN0LmtleXMoYik7XG4gICAgICBpZiAoIWJrcy5sZW5ndGgpIHtcbiAgICAgICAgcmV0dXJuIGE7XG4gICAgICB9XG4gICAgICBjb25zdCBhaSA9IHt9O1xuICAgICAgY29uc3QgYmkgPSB7fTtcbiAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gYmtzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICBjb25zdCBrZXkgPSBia3NbaV07XG4gICAgICAgIGFpW2tleV0gPSAtMTtcbiAgICAgICAgYmlba2V5XSA9IGk7XG4gICAgICB9XG4gICAgICBmb3IgKGxldCBpID0gMCwgbiA9IGFrcy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgY29uc3Qga2V5ID0gYWtzW2ldO1xuICAgICAgICBhaVtrZXldID0gaTtcbiAgICAgICAgaWYgKGJpW2tleV0gPT09IHZvaWQgMCkge1xuICAgICAgICAgIGJpW2tleV0gPSAtMTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgY29uc3QgYWtzbCA9IGFrcy5sZW5ndGg7XG4gICAgICBjb25zdCByZXN1bHQgPSB7fTtcbiAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gYmtzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICBjb25zdCBrZXkgPSBia3NbaV07XG4gICAgICAgIGNvbnN0IGFJbmRleCA9IGFpW2tleV07XG4gICAgICAgIGxldCBjdXJJbmRleDIgPSBhSW5kZXg7XG4gICAgICAgIHdoaWxlICgtLWN1ckluZGV4MiA+PSAwKSB7XG4gICAgICAgICAgY29uc3QgYWtleSA9IGFrc1tjdXJJbmRleDJdO1xuICAgICAgICAgIGlmIChiaVtha2V5XSAhPT0gLTEpIHtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB3aGlsZSAoKytjdXJJbmRleDIgPCBhSW5kZXgpIHtcbiAgICAgICAgICBjb25zdCBha2V5ID0gYWtzW2N1ckluZGV4Ml07XG4gICAgICAgICAgcmVzdWx0W2FrZXldID0gYVtha2V5XTtcbiAgICAgICAgfVxuICAgICAgICBjb25zdCBidiA9IGJba2V5XTtcbiAgICAgICAgY29uc3QgYXYgPSBhW2tleV07XG4gICAgICAgIGxldCByO1xuICAgICAgICBpZiAodGhpcy5pc01mKGJ2KSkge1xuICAgICAgICAgIHIgPSBidihhdik7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKCFVdGlscyQxLmlzT2JqZWN0TGl0ZXJhbChhdikgfHwgIVV0aWxzJDEuaXNPYmplY3RMaXRlcmFsKGJ2KSkge1xuICAgICAgICAgICAgciA9IGJ2O1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByID0gT2JqTWVyZ2VyLm1lcmdlKGF2LCBidik7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmIChyICE9PSB2b2lkIDApIHtcbiAgICAgICAgICByZXN1bHRba2V5XSA9IHI7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGxldCBjdXJJbmRleCA9IGFrc2w7XG4gICAgICB3aGlsZSAoLS1jdXJJbmRleCA+PSAwKSB7XG4gICAgICAgIGNvbnN0IGFrZXkgPSBha3NbY3VySW5kZXhdO1xuICAgICAgICBpZiAoYmlbYWtleV0gIT09IC0xKSB7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHdoaWxlICgrK2N1ckluZGV4IDwgYWtzbCkge1xuICAgICAgICBjb25zdCBha2V5ID0gYWtzW2N1ckluZGV4XTtcbiAgICAgICAgcmVzdWx0W2FrZXldID0gYVtha2V5XTtcbiAgICAgIH1cbiAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgfVxuICB9XG4gIGNsYXNzIE9iamVjdExpc3RQcm94eSBleHRlbmRzIE9iamVjdExpc3Qge1xu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GlmIChlID49IG5FbGVtZW50cykge1xuICAgICAgICAgIGUgPSBuRWxlbWVudHMgLSAxO1xuICAgICAgICAgIHBlID0gMTtcbiAgICAgICAgfVxuICAgICAgICBpZiAocyA+PSBuRWxlbWVudHMpIHtcbiAgICAgICAgICBzID0gbkVsZW1lbnRzIC0gMTtcbiAgICAgICAgICBwcyA9IDE7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGUgPD0gLTEpIHtcbiAgICAgICAgICBlID0gMDtcbiAgICAgICAgICBwZSA9IDE7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHMgPD0gLTEpIHtcbiAgICAgICAgICBzID0gMDtcbiAgICAgICAgICBwcyA9IDE7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGxldCBvZmZzZXQgPSAtZGlyZWN0aW9uICogcyAqIHRoaXMuX2l0ZW1TaXplO1xuICAgICAgbGV0IGl0ZW07XG4gICAgICBmb3IgKGxldCBpbmRleCA9IHM7IGRpcmVjdGlvbiA9PSAtMSA/IGluZGV4IDw9IGUgOiBpbmRleCA+PSBlOyBkaXJlY3Rpb24gPT0gLTEgPyBpbmRleCsrIDogaW5kZXgtLSkge1xuICAgICAgICBsZXQgcmVhbEluZGV4ID0gVXRpbHMkMS5nZXRNb2R1bG9JbmRleChpbmRleCwgbkVsZW1lbnRzKTtcbiAgICAgICAgbGV0IGVsZW1lbnQgPSB0aGlzLmdldEVsZW1lbnQocmVhbEluZGV4KTtcbiAgICAgICAgaXRlbSA9IGVsZW1lbnQucGFyZW50O1xuICAgICAgICB0aGlzLl92aXNpYmxlSXRlbXMuZGVsZXRlKGl0ZW0pO1xuICAgICAgICBpZiAodGhpcy5faG9yaXpvbnRhbCkge1xuICAgICAgICAgIGl0ZW0ueCA9IG9mZnNldCArIHNjcm9sbERlbHRhO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGl0ZW0ueSA9IG9mZnNldCArIHNjcm9sbERlbHRhO1xuICAgICAgICB9XG4gICAgICAg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AgICAgcmV0dXJuIHRoaXMuX3JvbGxNYXg7XG4gICAgfVxuICAgIHNldCByb2xsTWF4KHYpIHtcbiAgICAgIHRoaXMuX3JvbGxNYXggPSB2O1xuICAgICAgdGhpcy51cGRhdGUoKTtcbiAgICB9XG4gICAgZ2V0IGludmVydERpcmVjdGlvbigpIHtcbiAgICAgIHJldHVybiB0aGlzLl9pbnZlcnREaXJlY3Rpb247XG4gICAgfVxuICAgIHNldCBpbnZlcnREaXJlY3Rpb24odikge1xuICAgICAgaWYgKCF0aGlzLl9zdGFydGVkKSB7XG4gICAgICAgIHRoaXMuX2ludmVydERpcmVjdGlvbiA9IHY7XG4gICAgICB9XG4gICAgfVxuICAgIGdldCBob3Jpem9udGFsKCkge1xuICAgICAgcmV0dXJuIHRoaXMuX2hvcml6b250YWw7XG4gICAgfVxuICAgIHNldCBob3Jpem9udGFsKHYpIHtcbiAgICAgIGlmICh2ICE9PSB0aGlzLl9ob3Jpem9udGFsKSB7XG4gICAgICAgIGlmICghdGhpcy5fc3RhcnRlZCkge1xuICAgICAgICAgIHRoaXMuX2hvcml6b250YWwgPSB2O1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuICB9XG4gIGNsYXNzIExpc3RJdGVtcyBleHRlbmRzIE9iamVjdExpc3RXcmFwcGVyIHtcbiAgICBjb25zdHJ1Y3RvcihsaXN0KSB7XG4gICAgICBsZXQgd3JhcCA9IChpdGVtKSA9PiB7XG4gICAgICAgIGxldCBwYXJlbnQgPSBpdGVtLnN0YWdlLmNyZWF0ZUVsZW1lbnQoKTtcbiAgICAgICAgcGFyZW50LmFkZChpdGVtKTtcbiAgICAgICAgcGFyZW50LnZpc2libGUgPSBmYWxzZTtcbiAgICAgICAgcmV0dXJuIHBhcmVudDtcbiAgICAgIH07XG4gICAgICBzdXBlcihsaXN0Ll93cmFwcGVyLl9jaGlsZHJlbiwgd3JhcCk7XG4gICAgICB0aGlzLmxpc3QgPSBsaXN0O1xuICAgIH1cbiAgICBvbkFkZChpdGVtLCBpbmRleCkge1xuICAgICAgc3VwZXIub25BZGQoaXRlbSwgaW5kZXgpO1xuICAgICAgdGhpcy5jaGVja1N0YXJ0ZWQoaW5kZXgpO1xuICAgIH1cbiAgICBjaGVja1N0YXJ0ZWQoaW5kZXgpIHtcbiAgICAgIHRoaXMubGlzdC5fcmVsb2FkVmlzaWJsZUVsZW1lbnRzID0gdHJ1ZTtcbiAgICAgIGlmICghdGhpcy5saXN0Ll9zdGFydGVkKSB7XG4gICAgICAgIHRoaXMubGlzdC5zdGFydCgpO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKHRoaXMubGlzdC5sZW5ndGggPT09IDEpIHtcbiAgICAgICAgICB0aGlzLmxpc3Quc2V0SW5kZXgoMCwgdHJ1ZSwgdHJ1ZSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgaWYgKHRoaXMubGlzdC5faW5kZXggPj0gdGhpcy5saXN0Lmxlbmd0aCkge1xuICAgICAgICAgICAgdGhpcy5saXN0LnNldEluZGV4KDApO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB0aGlzLmxpc3QudXBkYXRlKCk7XG4gICAgICB9XG4gICAgfVxuICAgIG9uUmVtb3ZlKGl0ZW0sIGluZGV4KSB7XG4gICAgICBzdXBlci5vblJlbW92ZShpdGVtLCBpbmRleCk7XG4gICAgICBsZXQgcmkgPSB0aGlzLmxpc3QucmVhbEluZGV4O1xuICAgICAgaWYgKHJpID09PSBpbmRleCkge1xuICAgICAgICBpZiAocmkgPT09IHRoaXMubGlzdC5sZW5ndGgpIHtcbiAgICAgICAgICByaS0tO1xuICAgICAgICB9XG4gICAgICAgIGlmIChyaSA+PSAwKSB7XG4gICAgICAgICAgdGhpcy5saXN0LnNldEluZGV4KHJpKTtcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIGlmIChyaSA+IGluZGV4KSB7XG4gICAgICAgIHRoaXMubGlzdC5zZXRJbmRleChyaSAtIDEpO1xuICA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IDI7XG4gICAgICBsZXQgZmggPSBoICsgcGFkZGluZ1kgKiAyO1xuICAgICAgdGhpcy5fdGV4dHdyYXAudyA9IGZ3O1xuICAgICAgdGhpcy5fd3JhcHBlci54ID0gcGFkZGluZ1g7XG4gICAgICB0aGlzLmdldExheWVyKDApLncgPSB0aGlzLmdldExheWVyQ29udGVudHMoMCkudyA9IGZ3IC8gMjtcbiAgICAgIHRoaXMuZ2V0TGF5ZXIoMSkudyA9IHRoaXMuZ2V0TGF5ZXJDb250ZW50cygxKS53ID0gZncgLyA0O1xuICAgICAgdGhpcy5nZXRMYXllcigyKS53ID0gdGhpcy5nZXRMYXllckNvbnRlbnRzKDIpLncgPSBmdyAvIDg7XG4gICAgICB0aGlzLmdldExheWVyKDMpLncgPSB0aGlzLmdldExheWVyQ29udGVudHMoMykudyA9IGZ3IC8gMTY7XG4gICAgICB0aGlzLl90ZXh0d3JhcC54ID0gLXBhZGRpbmdYO1xuICAgICAgdGhpcy5fdGV4dHdyYXAuaCA9IGZoO1xuICAgICAgdGhpcy5fd3JhcHBlci55ID0gcGFkZGluZ1k7XG4gICAgICB0aGlzLmdldExheWVyKDApLmggPSB0aGlzLmdldExheWVyQ29udGVudHMoMCkuaCA9IGZoIC8gMjtcbiAgICAgIHRoaXMuZ2V0TGF5ZXIoMSkuaCA9IHRoaXMuZ2V0TGF5ZXJDb250ZW50cygxKS5oID0gZmggLyA0O1xuICAgICAgdGhpcy5nZXRMYXllcigyKS5oID0gdGhpcy5nZXRMYXllckNvbnRlbnRzKDIpLmggPSBmaCAvIDg7XG4gICAgICB0aGlzLmdldExheWVyKDMpLmggPSB0aGlzLmdldExheWVyQ29udGVudHMoMykuaCA9IGZoIC8gMTY7XG4gICAgICB0aGlzLl90ZXh0d3JhcC55ID0gLXBhZGRpbmdZO1xuICAgICAgdGhpcy53ID0gdztcbiAgICAgIHRoaXMuaCA9IGg7XG4gICAgfVxuICAgIHNldCBhbW91bnQodikge1xuICAgICAgdGhpcy5fYW1vd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dmVjMiBwb3MxO1xuICAgICAgICB2ZWMyIHBvczI7XG4gICAgICAgIHZlYzIgZDtcbiAgICAgICAgZmxvYXQgYztcbiAgICAgICAgZmxvYXQgdCA9IDAuMDtcbiAgICAgICAgICAgICBcbiAgICAgICAgaWYoZmFkZVswXSA+IDAuMCkge1xuICAgICAgICAgICAgcG9zMSA9IHZlYzIocG9pbnQueCwgcG9pbnQueSk7XG4gICAgICAgICAgICBwb3MyID0gdmVjMihwb2ludC54LCBwb2ludC55ICsgZmFkZVswXSk7XG4gICAgICAgICAgICBkID0gcG9zMiAtIHBvczE7XG4gICAgICAgICAgICBjID0gZG90KHBvczEsIGQpIC8gZG90KGQsIGQpO1xuICAgICAgICAgICAgdCA9IHNtb290aHN0ZXAoMC4wLCAxLjAsIGNsYW1wKGMsIDAuMCwgMS4wKSk7XG4gICAgICAgICAgICBjb2xvciA9IG1peCh2ZWM0KDAuMCksIGNvbG9yLCB0KTtcbiAgICAgICAgfVxuICAgICAgICBcbiAgICAgICAgaWYoZmFkZVsxXSA+IDAuMCkge1xuICAgICAgICAgICAgdmVjMiBwb3MxID0gdmVjMihwb2ludC54IC0gcmVzb2x1dGlvbi54IC0gZmFkZVsxXSwgdlRleHR1cmVDb29yZC55KTtcbiAgICAgICAgICAgIHZlYzIgcG9zMiA9IHZlYzIocG9pbnQueCAtIHJlc29sdXRpb24ueCwgdlRleHR1cmVDb29yZC55KTtcbiAgICAgICAgICAgIGQgPSBwb3MxIC0gcG9zMjtcbiAgICAgICAgICAgIGMgPSBkb3QocG9zMiwgZCkgLyBkb3QoZCwgZCk7XG4gICAgICAgICAgICB0ID0gc21vb3Roc3RlcCgwLjAsIDEuMCwgY2xhbXAoYywgMC4wLCAxLjApKTtcbiAgICAgICAgICAgIGNvbG9yID0gbWl4KHZlYzQoMC4wKSwgY29sb3IsIHQpO1xuICAgICAgICB9XG4gICAgICAgIFxuICAgICAgICBpZihmYWRlWzJdID4gMC4wKSB7XG4gICAgICAgICAgICB2ZWM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AgIGlmICh4MSA8IHgyKSB7XG4gICAgICAgICAgICBpZiAoYSA+IHgxICYmIGEgPCB4Mikge1xuICAgICAgICAgICAgICAgIGZsb2F0IHZhbCA9ICgxLjAgLSAoeDIgLSBhKSAvIGFuZ2xlKSAqIHNtb290aHN0ZXAoMC4wLCAzLiAqIHNtb290aCwgKHgyIC0gYSkpO1xuICAgICAgICAgICAgICAgIGZyYWdDb2xvciA9IG1peChiYWNrZ3JvdW5kQ29sb3IsIGNvbG9yLCB2YWwpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBmcmFnQ29sb3IgPSBiYWNrZ3JvdW5kQ29sb3I7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAoYSA8IHgyKSB7XG4gICAgICAgICAgICAgICAgZmxvYXQgdmFsID0gKDEuMCAtICh4MiAtIGEpIC8gYW5nbGUpICogc21vb3Roc3RlcCgwLjAsIDMuICogc21vb3RoLCAoeDIgLSBhKSk7XG4gICAgICAgICAgICAgICAgZnJhZ0NvbG9yID0gbWl4KGJhY2tncm91bmRDb2xvciwgY29sb3IsIHZhbCk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGEgPiB4MSkge1xuICAgICAgICAgICAgICAgIGZsb2F0IHZhbCA9ICgxLjAgLSAoMS4wICsgeDIgLSBhKSAvIGFuZ2xlKSAqIHNtb290aHN0ZXAoMC4wLCAzLiAqIHNtb290aCwgKDEuMCArIHgyIC0gYSkpO1xuICAgICAgICAgICAgICAgIGZyYWdDb2xvciA9IG1peChiYWNrZ3JvdW5kQ29sb3IsIGNvbG9yLCB2YWwpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBmcmFnQ29sb3IgPSBiYWNrZ3JvdW5kQ29sb3I7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBmbG9hdCBzID0gc21vb3Roc3RlcChpbm5lciwgaW5uZXIgKy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9zIC09IHBpdm90O1xuICAgICAgICBcbiAgICAgICAgLy8gVW5kbyBYWSByb3RhdGlvblxuICAgICAgICBtYXQyIGlSb3RYeSA9IG1hdDIoIGNvcyhyb3QueiksIHNpbihyb3QueiksIFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgLXNpbihyb3QueiksIGNvcyhyb3QueikpO1xuICAgICAgICBwb3MueHkgPSBpUm90WHkgKiBwb3MueHk7XG4gICAgICAgIFxuICAgICAgICAvLyBQZXJmb3JtIDNkIHJvdGF0aW9uc1xuICAgICAgICBnbF9Qb3NpdGlvbi54ID0gY29zKHJvdC54KSAqIHBvcy54IC0gc2luKHJvdC54KSAqIHBvcy56O1xuICAgICAgICBnbF9Qb3NpdGlvbi55ID0gcG9zLnk7XG4gICAgICAgIGdsX1Bvc2l0aW9uLnogPSBzaW4ocm90LngpICogcG9zLnggKyBjb3Mocm90LngpICogcG9zLno7XG4gICAgICAgIFxuICAgICAgICBwb3MueCA9IGdsX1Bvc2l0aW9uLng7XG4gICAgICAgIHBvcy55ID0gY29zKHJvdC55KSAqIGdsX1Bvc2l0aW9uLnkgLSBzaW4ocm90LnkpICogZ2xfUG9zaXRpb24uejtcbiAgICAgICAgcG9zLnogPSBzaW4ocm90LnkpICogZ2xfUG9zaXRpb24ueSArIGNvcyhyb3QueSkgKiBnbF9Qb3NpdGlvbi56O1xuICAgICAgICBcbiAgICAgICAgLy8gUmVkbyBYWSByb3RhdGlvblxuICAgICAgICBpUm90WHlbMF1bMV0gPSAtaVJvdFh5WzBdWzFdO1xuICAgICAgICBpUm90WHlbMV1bMF0gPSAtaVJvdFh5WzFdWzBdO1xuICAgICAgICBwb3MueHkgPSBpUm90WHkgKiBwb3MueHk7IFxuXG4gICAgICAgIC8vIFVuZG8gdHJhbnNsYXRlIHRvIHBpdm90IHBvc2l0aW9uXG4gICAgICAgIHBvcy54eXogKz0gcGl2b3Q7XG5cbiAgICAgICAgcG9zID0gdmVjMyhwb3MueCAqIHByb2plY3Rpb24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b3MgLT0gcGl2b3Q7XG4gICAgICAgIFxuICAgICAgICAvLyBVbmRvIFhZIHJvdGF0aW9uXG4gICAgICAgIG1hdDIgaVJvdFh5ID0gbWF0MiggY29zKHJvdC56KSwgc2luKHJvdC56KSwgXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAtc2luKHJvdC56KSwgY29zKHJvdC56KSk7XG4gICAgICAgIHBvcy54eSA9IGlSb3RYeSAqIHBvcy54eTtcbiAgICAgICAgXG4gICAgICAgIC8vIFBlcmZvcm0gM2Qgcm90YXRpb25zXG4gICAgICAgIGdsX1Bvc2l0aW9uLnggPSBjb3Mocm90LngpICogcG9zLnggLSBzaW4ocm90LngpICogcG9zLno7XG4gICAgICAgIGdsX1Bvc2l0aW9uLnkgPSBwb3MueTtcbiAgICAgICAgZ2xfUG9zaXRpb24ueiA9IHNpbihyb3QueCkgKiBwb3MueCArIGNvcyhyb3QueCkgKiBwb3MuejtcbiAgICAgICAgXG4gICAgICAgIHBvcy54ID0gZ2xfUG9zaXRpb24ueDtcbiAgICAgICAgcG9zLnkgPSBjb3Mocm90LnkpICogZ2xfUG9zaXRpb24ueSAtIHNpbihyb3QueSkgKiBnbF9Qb3NpdGlvbi56O1xuICAgICAgICBwb3MueiA9IHNpbihyb3QueSkgKiBnbF9Qb3NpdGlvbi55ICsgY29zKHJvdC55KSAqIGdsX1Bvc2l0aW9uLno7XG4gICAgICAgIFxuICAgICAgICAvLyBSZWRvIFhZIHJvdGF0aW9uXG4gICAgICAgIGlSb3RYeVswXVsxXSA9IC1pUm90WHlbMF1bMV07XG4gICAgICAgIGlSb3RYeVsxXVswXSA9IC1pUm90WHlbMV1bMF07XG4gICAgICAgIHBvcy54eSA9IGlSb3RYeSAqIHBvcy54eTsgXG5cbiAgICAgICAgLy8gVW5kbyB0cmFuc2xhdGUgdG8gcGl2b3QgcG9zaXRpb25cbiAgICAgICAgcG9zLnh5eiArPSBwaXZvdDtcblxuICAgICAgICBwb3MgPSB2ZWMzKHBvcy54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1xuICAgICAgICAgICAgbGlzdGVuZXIoYXJnMSwgYXJnMiwgYXJnMyk7XG4gICAgICAgICAgICB0aGlzLm9mZihuYW1lLCB3cmFwcGVyKTtcbiAgICAgICAgfVxuICAgICAgICB3cmFwcGVyLl9fb3JpZ2luYWxGdW5jID0gbGlzdGVuZXI7XG4gICAgICAgIHRoaXMub24obmFtZSwgd3JhcHBlcik7XG4gICAgfVxuXG4gICAgaGFzKG5hbWUsIGxpc3RlbmVyKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNFdmVudExpc3RlbmVycykge1xuICAgICAgICAgICAgY29uc3QgY3VycmVudCA9IHRoaXMuX2V2ZW50RnVuY3Rpb25bbmFtZV07XG4gICAgICAgICAgICBpZiAoY3VycmVudCkge1xuICAgICAgICAgICAgICAgIGlmIChjdXJyZW50ID09PSBFdmVudEVtaXR0ZXIuY29tYmluZXIpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgbGlzdGVuZXJzID0gdGhpcy5fZXZlbnRMaXN0ZW5lcnNbbmFtZV07XG4gICAgICAgICAgICAgICAgICAgIGZvciAoY29uc3QgbCBvZiBsaXN0ZW5lcnMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsID09PSBsaXN0ZW5lciB8fCBsLl9fb3JpZ2luYWxGdW5jID09IGxpc3RlbmVyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2V2ZW50RnVuY3Rpb25bbmFtZV0gPT09IGxpc3RlbmVyIHx8IHRoaXMuX2V2ZW50RnVuY3Rpb25bbmFtZV0uX19vcmlnaW5hbEZ1bmMgPT09IGxpc3RlbmVyKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuXG4gICAgb2ZmKG5hbWUsIGxpc3RlbmVyKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNFdmVudExpc3RlbmVycykge1xuICAgICAgICAgICAgY29uc3QgY3VycmVudCA9IHRoaXMuX2V2ZW50RnVuY3Rpb25bbmFtZV07XG4gICAgICAgICAgICBpZiAoY3VycmVudCkge1xuICAgICAgICAgICAgICAgIGlmIChjdXJyZW50ID09PSBFdmVudEVtaXR0ZXIuY29tYmluZXIpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgbGlzdGVuZXJzID0gdGhpcy5fZXZlbnRMaXN0ZW5lcnNbbmFtZV07XG4gICAgICAgICAgICAgICAgICAgIGxldCBpbmRleCA9IGxpc3RlbmVycy5pbmRleE9mKGxpc3RlbmVyKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGluZGV4ID49IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxpc3RlbmVycy5zcGxpY2UoaW5kZXgsIDEpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGluZGV4ID0gbGlzdGVuZXJzLm1hcCgobCkgPT4gbC5fX29yaWdpbmFsRnVuYykuaW5kZXhPZihsaXN0ZW5lcik7XG4gICAgICAgICAgICAgICAgICAgIGlmIChpbmRleCA+PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBsaXN0ZW5lcnMuc3BsaWNlKGluZGV4LCAxKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBpZiAobGlzdGVuZXJzLmxlbmd0aCA9PT0gMSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXSA9IGxpc3RlbmVyc1swXTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2V2ZW50TGlzdGVuZXJzW25hbWVdID0gdW5kZWZpbmVkO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdID09PSBsaXN0ZW5lciB8fCB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdLl9fb3JpZ2luYWxGdW5jID09PSBsaXN0ZW5lcikge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9ldmVudEZ1bmN0aW9uW25hbWVdID0gdW5kZWZpbmVkO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJlbW92ZUxpc3RlbmVyKG5hbWUsIGxpc3RlbmVyKSB7XG4gICAgICAgIHRoaXMub2ZmKG5hbWUsIGxpc3RlbmVyKTtcbiAgICB9XG5cbiAgICBlbWl0KG5hbWUsIGFyZzEsIGFyZzIsIGFyZzMpIHtcbiAgICAgICAgaWYgKHRoaXMuX2hhc0V2ZW50TGlzdGVuZXJzKSB7XG4gICAgICAgICAgICBjb25zdCBmdW5jID0gdGhpcy5fZXZlbnRGdW5jdGlvbltuYW1lXTtcbiAgICAgICAgICAgIGlmIChmdW5jKSB7XG4gICAgICAgICAgICAgICAgaWYgKGZ1bmMgPT09IEV2ZW50RW1pdHRlci5jb21iaW5lcikge1xuICAgICAgICAgICAgICAgICAgICBmdW5jKHRoaXMsIG5hbWUsIGFyZzEsIGFyZzIsIGFyZzMpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGZ1bmMoYXJnMSwgYXJnMiwgYXJnMyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgbGlzdGVuZXJDb3VudChuYW1lKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNFdmVudExpc3RlbmVycykge1xuICAgICAgICAgICAgY29uc3QgZnVuYyA9IHRoaXMuX2V2ZW50RnVu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1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuX2RlbGF5TGVmdCA+IDApIHtcbiAgICAgICAgICAgIHRoaXMuX2RlbGF5TGVmdCAtPSBkdDtcblxuICAgICAgICAgICAgaWYgKHRoaXMuX2RlbGF5TGVmdCA8IDApIHtcbiAgICAgICAgICAgICAgICBkdCA9IC10aGlzLl9kZWxheUxlZnQ7XG4gICAgICAgICAgICAgICAgdGhpcy5fZGVsYXlMZWZ0ID0gMDtcblxuICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgnZGVsYXlFbmQnKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuc2V0dGluZ3MuZHVyYXRpb24gPT09IDApIHtcbiAgICAgICAgICAgIHRoaXMuX3AgPSAxO1xuICAgICAgICB9IGVsc2UgaWYgKHRoaXMuc2V0dGluZ3MuZHVyYXRpb24gPiAwKSB7XG4gICAgICAgICAgICB0aGlzLl9wICs9IGR0IC8gdGhpcy5zZXR0aW5ncy5kdXJhdGlvbjtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fcCA+PSAxKSB7XG4gICAgICAgICAgICAvLyBGaW5pc2hlZCE7XG4gICAgICAgICAgICBpZiAodGhpcy5zZXR0aW5ncy5yZXBlYXQgPT0gLTEgfHwgdGhpcy5fcmVwZWF0c0xlZnQgPiAwKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3JlcGVhdHNMZWZ0ID4gMCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZXBlYXRzTGVmdC0tO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0aGlzLl9wID0gdGhpcy5zZXR0aW5ncy5yZXBlYXRPZmZzZXQ7XG4gICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdwcm9ncmVzcycsIHRoaXMuX3ApO1xuICAgICAgICAgICAgICAgIFxuICAgICAgICAgICAgICAgIGlmICh0aGlzLnNldHRpbmdzLnJlcGVhdERlbGF5KSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2RlbGF5TGVmdCA9IHRoaXMuc2V0dGluZ3MucmVwZWF0RGVsYXk7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdyZXBlYXQnLCB0aGlzLl9yZXBlYXRzTGVmdCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX3AgPSAxO1xuICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgncHJvZ3Jlc3MnLCB0aGlzLl9wKTtcbiAgICAgICAgICAgICAgICBcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IEFuaW1hdGlvbi5TVEFURVMuRklOSVNIRUQ7XG4gICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdmaW5pc2gnKTtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5zZXR0aW5ncy5hdXRvc3RvcCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnN0b3AoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmVtaXQoJ3Byb2dyZXNzJywgdGhpcy5fcCk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgXG4gICAgX3N0b3BQcm9ncmVzcyhkdCkge1xuICAgICAgICBsZXQgZHVyYXRpb24gPSB0aGlzLl9nZXRTdG9wRHVyYXRpb24oKTtcblxuICAgICAgICBpZiAodGhpcy5fc3RvcERlbGF5TGVmdCA+IDApIHtcbiAgICAgICAgICAgIHRoaXMuX3N0b3BEZWxheUxlZnQgLT0gZHQ7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9zdG9wRGVsYXlMZWZ0IDwgMCkge1xuICAgICAgICAgICAgICAgIGR0ID0gLXRoaXMuX3N0b3BEZWxheUxlZnQ7XG4gICAgICAgICAgICAgICAgdGhpcy5fc3RvcERlbGF5TGVmdCA9IDA7XG5cbiAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3N0b3BEZWxheUVuZCcpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuc2V0dGluZ3Muc3RvcE1ldGhvZCA9PSBBbmltYXRpb25TZXR0aW5ncy5TVE9QX01FVEhPRFMuSU1NRURJQVRFKSB7XG4gICAgICAgICAgICB0aGlzLl9zdGF0ZSA9IEFuaW1hdGlvbi5TVEFURVMuU1RPUFBFRDtcbiAgICAgICAgICAgIHRoaXMuZW1pdCgnc3RvcEZpbmlzaCcpO1xuICAgICAgICB9IGVsc2UgaWYgKHRoaXMuc2V0dGluZ3Muc3RvcE1ldGhvZCA9PSBBbmltYXRpb25TZXR0aW5ncy5TVE9QX01FVEhPRFMuUkVWRVJTRSkge1xuICAgICAgICAgICAgaWYgKGR1cmF0aW9uID09PSAwKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcCA9IDA7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGR1cmF0aW9uID4gMCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3AgLT0gZHQgLyBkdXJhdGlvbjtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX3AgPD0gMCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3AgPSAwO1xuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gQW5pbWF0aW9uLlNUQVRFUy5TVE9QUEVEO1xuICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgnc3RvcEZpbmlzaCcpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHRoaXMuc2V0dGluZ3Muc3RvcE1ldGhvZCA9PSBBbmltYXRpb25TZXR0aW5ncy5TVE9QX01FVEhPRFMuRkFERSkge1xuICAgICAgICAgICAgdGhpcy5fcHJvZ3Jlc3NTdG9wVHJhbnNpdGlvbihkdCk7XG4gICAgICAgICAgICBpZiAodGhpcy5fc3RvcFAgPj0gMSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3AgPSAwO1xuICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gQW5pbWF0aW9uLlNUQVRFUy5TVE9QUEVEO1xuICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgnc3RvcEZpbmlzaCcpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHRoaXMuc2V0dGluZ3Muc3RvcE1ldGhvZCA9PSBBbmltYXRpb25TZXR0aW5ncy5TVE9QX01FVEhPRFMuT05FVE9UV08pIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9wIDwgMikge1xuICAgICAgICAgICAgICAgIGlmIChkdXJhdGlvbiA9PT0gMCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9wID0gMjtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGR1cmF0aW9uID4gMCkge1xuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fcCA8IDEpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3AgKz0gZHQgLyB0aGlzLnNldHRpbmdzLmR1cmF0aW9uO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcCArPSBkdCAvIGR1cmF0aW9uO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9wID49IDIpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fcCA9IDI7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gQW5pbWF0aW9uLlNUQVRFUy5TVE9QUEVEO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3N0b3BGaW5pc2gnKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3Byb2dyZXNzJywgdGhpcy5fcCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHRoaXMuc2V0dGluZ3Muc3RvcE1ldGhvZCA9PSBBbmltYXRpb25TZXR0aW5ncy5TVE9QX01FVEhPRFMuRk9SV0FSRCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3AgPCAxKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuc2V0dGluZ3MuZHVyYXRpb24gPT0gMCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9wID0gMTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9wICs9IGR0IC8gdGhpcy5zZXR0aW5ncy5kdXJhdGlvbjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3AgPj0gMSkge1xuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5zZXR0aW5ncy5zdG9wTWV0aG9kID09IEFuaW1hdGlvblNldHRpbmdzLlNUT1BfTUVUSE9EUy5GT1JXQVJEKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9wID0gMTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3N0YXRlID0gQW5pbWF0aW9uLlNUQVRFUy5TVE9QUEVEO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdzdG9wRmluaXNoJyk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fcmVwZWF0c0xlZnQgPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcmVwZWF0c0xlZnQtLTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9wID0gMDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3JlcGVhdCcsIHRoaXMuX3JlcGVhdHNMZWZ0KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcCA9IDE7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fc3RhdGUgPSBBbmltYXRpb24uU1RBVEVTLlNUT1BQRUQ7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdzdG9wRmluaXNoJyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3Byb2dyZXNzJywgdGhpcy5fcCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIFxuICAgIH1cbiAgICBcbiAgICBfcHJvZ3Jlc3NTdG9wVHJhbnNpdGlvbihkdCkge1xuICAgICAgICBpZiAodGhpcy5fc3RvcFAgPCAxKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fc3RvcERlbGF5TGVmdCA+IDApIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9zdG9wRGVsYXlMZWZ0IC09IGR0O1xuXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3N0b3BEZWxheUxlZnQgPCAwKSB7XG4gICAgICAgICAgICAgICAgICAgIGR0ID0gLXRoaXMuX3N0b3BEZWxheUxlZnQ7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3N0b3BEZWxheUxlZnQgPSAwO1xuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgnZGVsYXlFbmQnKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgXG4gICAgICAgICAgICBjb25zdCBkdXJhdGlvbiA9IHRoaXMuX2dldFN0b3BEdXJhdGlvbigpO1xuXG4gICAgICAgICAgICBpZiAoZHVyYXRpb24gPT0gMCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3N0b3BQID0gMTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fc3RvcFAgKz0gZHQgLyBkdXJhdGlvbjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLl9zdG9wUCA+PSAxKSB7XG4gICAgICAgICAgICAgICAgLy8gRmluaXNoZWQhO1xuICAgICAgICAgICAgICAgIHRoaXMuX3N0b3BQID0gMTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9nZXRTdG9wRHVyYXRpb24oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnNldHRpbmdzLnN0b3BEdXJhdGlvbiB8fCB0aGlzLnNldHRpbmdzLmR1cmF0aW9uO1xuICAgIH1cblxuICAgIGFwcGx5KCkge1xuICAgICAgICBpZiAodGhpcy5fc3RhdGUgPT09IEFuaW1hdGlvbi5TVEFURVMuU1RPUFBFRCkge1xuICAgICAgICAgICAgdGhpcy5yZXNldCgpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbGV0IGZhY3RvciA9IDE7XG4gICAgICAgICAgICBpZiAodGhpcy5fc3RhdGUgPT09IEFuaW1hdGlvbi5TVEFURVMuU1RPUFBJTkcgJiYgdGhpcy5zZXR0aW5ncy5zdG9wTWV0aG9kID09PSBBbmltYXRpb25TZXR0aW5ncy5TVE9QX01FVEhPRFMuRkFERSkge1xuICAgICAgICAgICAgICAgIGZhY3RvciA9ICgxI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pbmdzO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBUaGUgc2VsZWN0b3IgdGhhdCBzZWxlY3RzIHRoZSBlbGVtZW50cy5cbiAgICAgICAgICogQHR5cGUge3N0cmluZ31cbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX3NlbGVjdG9yID0gXCJcIjtcblxuICAgICAgICAvKipcbiAgICAgICAgICogVGhlIHZhbHVlIGl0ZW1zLCBvcmRlcmVkIGJ5IHByb2dyZXNzIG9mZnNldC5cbiAgICAgICAgICogQHR5cGUge011bHRpU3BsaW5lfVxuICAgICAgICAgKiBAcHJpdmF0ZTtcbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX2l0ZW1zID0gbmV3IE11bHRpU3BsaW5lKCk7XG5cbiAgICAgICAgLyoqXG4gICAgICAgICAqIFRoZSBhZmZlY3RlZCBwcm9wZXJ0aWVzIChwYXRocykuXG4gICAgICAgICAqIEBwcml2YXRlO1xuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5fcHJvcHMgPSBbXTtcblxuICAgICAgICAvKipcbiAgICAgICAgICogUHJvcGVydHkgc2V0dGVycywgaW5kZXhlZCBhY2NvcmRpbmcgdG8gcHJvcHMuXG4gICAgICAgICAqIEBwcml2YXRlO1xuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5fcHJvcFNldHRlcnMgPSBbXTtcblxuICAgICAgICB0aGlzLl9yZXNldFZhbHVlID0gdW5kZWZpbmVkO1xuICAgICAgICB0aGlzLl9oYXNSZXNldFZhbHVlID0gZmFsc2U7XG5cbiAgICAgICAgdGhpcy5faGFzQ29sb3JQcm9wZXJ0eSA9IHVuZGVmaW5lZDtcbiAgICB9XG5cbiAgICBnZXRSZXNldFZhbHVlKCkge1xuICAgICAgICBpZiAodGhpcy5faGFzUmVzZXRWYWx1ZSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3Jlc2V0VmFsdWU7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZ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9yIChsZXQgaiA9IDA7IGogPCBtOyBqKyspIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcHJvcFNldHRlcnNbaV0oZWxlbWVudHNbal0sIHYpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuICAgIFxuICAgIGdldEFuaW1hdGVkRWxlbWVudHMoZWxlbWVudCkge1xuICAgICAgICByZXR1cm4gZWxlbWVudC5zZWxlY3QodGhpcy5fc2VsZWN0b3IpO1xuICAgIH1cblxuICAgIHJlc2V0KGVsZW1lbnQpIHtcbiAgICAgICAgY29uc3QgZWxlbWVudHMgPSB0aGlzLmdldEFuaW1hdGVkRWxlbWVudHMoZWxlbWVudCk7XG5cbiAgICAgICAgbGV0IHYgPSB0aGlzLmdldFJlc2V0VmFsdWUoKTtcblxuICAgICAgICBpZiAodiA9PT0gdW5kZWZpbmVkIHx8ICFlbGVtZW50cy5sZW5ndGgpIHtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEFwcGx5IHRyYW5zZm9ybWF0aW9uIHRvIGFsbCBjb21wb25lbnRzLlxuICAgICAgICBjb25zdCBuID0gdGhpcy5fcHJvcFNldHRlcnMubGVuZ3RoO1xuXG4gICAgICAgIGNvbnN0IG0gPSBlbGVtZW50cy5sZW5ndGg7XG4gICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgbTsgaisrKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIHRoaXMuX3Byb3BTZXR0ZXJzW2ldKGVsZW1lbnRzW2pdLCB2KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbiAgICBcbiAgICBzZXQgc2VsZWN0b3Iodikge1xuICAgICAgICB0aGlzLl9zZWxlY3RvciA9IHY7XG4gICAgfVxuXG4gICAgc2V0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hdGlvbnMgb24gYXR0YWNoZWQgc3ViamVjdHMuXG4gICAgICAgICAqIEB0eXBlIHtTZXQ8QW5pbWF0aW9uPn1cbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuYWN0aXZlID0gbmV3IFNldCgpO1xuICAgIH1cblxuICAgIHByb2dyZXNzKCkge1xuICAgICAgICBpZiAodGhpcy5hY3RpdmUuc2l6ZSkge1xuICAgICAgICAgICAgbGV0IGR0ID0gdGhpcy5zdGFnZS5kdDtcblxuICAgICAgICAgICAgbGV0IGZpbHRlciA9IGZhbHNlO1xuICAgICAgICAgICAgdGhpcy5hY3RpdmUuZm9yRWFjaChmdW5jdGlvbihhKSB7XG4gICAgICAgICAgICAgICAgaWYgKGEuaXNBY3RpdmUoKSkge1xuICAgICAgICAgICAgICAgICAgICBhLnByb2dyZXNzKGR0KTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBmaWx0ZXIgPSB0cnVlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuXG4gICAgICAgICAgICBpZiAoZmlsdGVyKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5hY3RpdmUgPSBuZXcgU2V0KFsuLi50aGlzLmFjdGl2ZV0uZmlsdGVyKHQgPT4gdC5pc0FjdGl2ZSgpKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBjcmVhdGVBbmltYXRpb24oZWxlbWVudCwgc2V0dGluZ3MpIHtcbiAgICAgICAgaWYgKFV0aWxzLmlzT2JqZWN0TGl0ZXJhbChzZXR0aW5ncykpIHtcbiAgICAgICAgICAgIC8vIENvbnZlcnQgcGxhaW4gb2JqZWN0IHRvIHByb3BlciBzZXR0aW5ncyBvYmplY3QuXG4gICAgICAgICAgICBzZXR0aW5ncyA9IHRoaXMuY3JlYXRlU2V0dGluZ3Moc2V0dGluZ3MpO1xuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIG5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1xuICAgICAgICAgICAgaWYgKHRoaXMuZGVsYXlMZWZ0ID4gMCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2RlbGF5TGVmdCAtPSBkdDtcblxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmRlbGF5TGVmdCA8IDApIHtcbiAgICAgICAgICAgICAgICAgICAgZHQgPSAtdGhpcy5kZWxheUxlZnQ7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2RlbGF5TGVmdCA9IDA7XG5cbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdkZWxheUVuZCcpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9zZXR0aW5ncy5kdXJhdGlvbiA9PSAwKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcCA9IDE7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX3AgKz0gZHQgLyB0aGlzLl9zZXR0aW5ncy5kdXJhdGlvbjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLl9wID49IDEpIHtcbiAgICAgICAgICAgICAgICAvLyBGaW5pc2hlZCE7XG4gICAgICAgICAgICAgICAgdGhpcy5fcCA9IDE7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICB0aGlzLl91cGRhdGVEcmF3VmFsdWUoKTtcblxuICAgICAgICB0aGlzLmludm9rZUxpc3RlbmVycygpO1xuICAgIH1cblxuICAgIGludm9rZUxpc3RlbmVycygpIHtcbiAgICAgICAgdGhpcy5lbWl0KCdwcm9ncmVzcycsIHRoaXMucCk7XG4gICAgICAgIGlmICh0aGlzLnAgPT09IDEpIHtcbiAgICAgICAgICAgIHRoaXMuZW1pdCgnZmluaXNoJyk7XG4gICAgICAgIH1cbiAgICB9XG5cb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ICB9KTtcblxuICAgICAgICAgICAgdGhpcy5zdGFnZS5wbGF0Zm9ybS5yZWdpc3RlckhvdmVySGFuZGxlcigoZSkgPT4ge1xuICAgICAgICAgICAgICAgIHRoaXMuX3JlY2VpdmVIb3ZlcihlKTtcbiAgICAgICAgICAgIH0pO1xuXG4gICAgICAgICAgICB0aGlzLnN0YWdlLnBsYXRmb3JtLnJlZ2lzdGVyU2Nyb2xsV2hlZWxIYW5kbGVyKChlKSA9PiB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcmVjaWV2ZVNjcm9sbFdoZWVsKGUpO1xuICAgICAgICAgICAgfSk7XG5cbiAgICAgICAgICAgIHRoaXMuY3Vyc29yID0gJ2RlZmF1bHQnO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0T3B0aW9uKG5hbWUpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19vcHRpb25zW25hbWVdO1xuICAgIH1cblxuICAgIF9zZXRPcHRpb25zKG8pIHtcbiAgICAgICAgdGhpcy5fX29wdGlvbnMgPSB7fTtcblxuICAgICAgICBsZXQgb3B0ID0gKG5hbWUsIGRlZikgPT4ge1xuICAgICAgICAgICAgbGV0IHZhbHVlID0gb1tuYW1lXTtcblxuICAgICAgICAgICAgaWYgKHZhbHVlID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9fb3B0aW9uc1tuYW1lXSA9IGRlZjtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fX29wdGlvbnNbbmFtZV0gPSB2YWx1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIG9wdCgnZGVidWcnLCBmYWxzZSk7XG4gICAgICAgIG9wdCgna2V5cycsIHtcbiAgICAgICAgICAgIDM4OiBcIlVwXCIsXG4gICAgICAgICAgICA0MDogXCJEb3duXCIsXG4gICAgICAgICAgICAzNzogXCJMZWZ0XCIsXG4gICAgICAgICAgICAzOT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uX191cGRhdGVGb2N1c0lkICE9PSB1cGRhdGVGb2N1c0lkKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZvY3VzT3ZlcnJpZGRlbikge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgLy8gRm9jdXMgZXZlbnRzLlxuICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSBpbmRleCwgbiA9IG5ld0ZvY3VzUGF0aC5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZm9jdXNQYXRoLnB1c2gobmV3Rm9jdXNQYXRoW2ldKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZm9jdXNQYXRoW2ldLl9mb2N1cyhuZXdGb2N1c2VkQ29tcG9uZW50LCBwcmV2Rm9jdXNlZENvbXBvbmVudCk7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGZvY3VzT3ZlcnJpZGRlbiA9ICh0aGlzLl9fdXBkYXRlRm9jdXNJZCAhPT0gdXBkYXRlRm9jdXNJZCk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChmb2N1c092ZXJyaWRkZW4pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIC8vIEZvY3VzIGNoYW5nZWQgZXZlbnRzLlxuICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgaW5kZXg7IGkrKykge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9mb2N1c1BhdGhbaV0uX2ZvY3VzQ2hhbmdlKG5ld0ZvY3VzZWRDb21wb25lbnQsIHByZXZGb2N1c2VkQ29tcG9uZW50KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAg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gICAgICBwYXRoLnB1c2gobmV4dEZvY3VzKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gTm90IGFuIGltbWVkaWF0ZSBjaGlsZDogaW5jbHVkZSBmdWxsIHBhdGggdG8gZGVzY2VuZGFudC5cbiAgICAgICAgICAgICAgICBjb25zdCBuZXdQYXJ0cyA9IFtuZXh0Rm9jdXNdO1xuICAgICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFwdHIpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGN1cnJlbnQuX3Rocm93RXJyb3IoXCJSZXR1cm4gdmFsdWUgZm9yIF9nZXRGb2N1c2VkIG11c3QgYmUgYW4gYXR0YWNoZWQgZGVzY2VuZGFudCBjb21wb25lbnQgYnV0IGl0cyAnXCIgKyBuZXh0Rm9jdXMuZ2V0TG9jYXRpb25TdHJpbmcoKSArIFwiJ1wiKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBuZXdQYXJ0cy5wdXNoKHB0cik7XG4gICAgICAgICAgICAgICAgICAgIHB0ciA9IHB0ci5jcGFyZW50O1xuICAgICAgICAgICAgICAgIH0gd2hpbGUgKHB0ciAhPT0gY3VycmVudCk7XG5cbiAgICAgICAgICAgICAgICAvLyBBZGQgdGhlbSByZXZlcnNlZC5cbiAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IG5ld1BhcnRzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICBwYXRoLnB1c2gobmV3UGFydHNbbiAtIGkgLSAxXSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBjdXJyZW50ID0gbmV4dEZvY3VzO1xuICAgICAgICB9IHdoaWxlICh0cnVlKTtcblxuICAgICAgICByZXR1cm4gcGF0aDtcbiAgICB9XG5cbiAgICBnZXQgZm9jdXNQYXRoKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fZm9jdXNQYXRoO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIEluamVjdHMgYW4gZXZlbnQgaW4gdGhlIHN0YXRlIG1hY2hpbmVzLCB0b3AtZG93biBmcm9tIGFwcGxpY2F0aW9uIHRvIGZvY3VzZWQgY29tcG9uZW50LlxuICAgICAqL1xuICAgIGZvY3VzVG9wRG93bkV2ZW50KGV2ZW50cywgLi4uYXJncykge1xuICAgICAgICBjb25zdCBwYXRoID0gdGhpcy5mb2N1c1BhdGg7XG4gICAgICAgIGNvbnN0IG4gPSBwYXRoLmxlbmd0aDtcblxuICAgICAgICAvLyBNdWx0aXBsZSBldmVudHMuXG4gICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCBldmVudCA9IHBhdGhbaV0uX2dldE1vc3RTcGVjaWZpY0hhbmRsZWRNZW1iZXIoZXZlbnRzKTtcbiAgICAgICAgICAgIGlmIChldmVudCAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgcmV0dXJuVmFsdWUgPSBwYXRoW2ldW2V2ZW50XSguLi5hcmdzKTtcbiAgICAgICAgICAgICAgICBpZiAocmV0dXJuVmFsdWUgIT09IGZhbHNlKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBJbmplY3RzIGFuIGV2ZW50IGluIHRoZSBzdGF0ZSBtYWNoaW5lcywgYm90dG9tLXVwIGZyb20gZm9jdXNlZCBjb21wb25lbnQgdG8gYXBwbGljYXRpb24uXG4gICAgICovXG4gICAgZm9jdXNCb3R0b21VcEV2ZW50KGV2ZW50cywgLi4uYXJncykge1xuICAgICAgICBjb25zdCBwYXRoID0gdGhpcy5mb2N1c1BhdGg7XG4gICAgICAgIGNvbnN0IG4gPSBwYXRoLmxlbmd0aDtcblxuICAgICAgICAvLyBNdWx0aXBsZSBldmVudHMuXG4gICAgICAgIGZvciAobGV0IGkgPSBuIC0gMTsgaSA+PSAwOyBpLS0pIHtcbiAgICAgICAgICAgIGNvbnN0IGV2ZW50ID0gcGF0aFtpXS5fZ2V0TW9zdFNwZWNpZmljSGFuZGxlZE1lbWJlcihldmVudHMpO1xuICAgICAgICAgICAgaWYgKGV2ZW50ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBjb25zdCByZXR1cm5WYWx1ZSA9IHBhdGhbaV1bZXZlbnRdKC4uLmFyZ3MpO1xuICAgICAgICAgICAgICAgIGlmIChyZXR1cm5WYWx1ZSAhPT0gZmFsc2UpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cblxuICAgIF9yZWNlaXZlS2V5ZG93bihlKSB7XG4gICAgICAgIGNvbnN0IG9iaiA9IGU7XG4gICAgICAgIGNvbnN0IGtleSA9IHRoaXMuX19rZXltYXBbZS5rZXlDb2RlXTtcbiAgICAgICAgY29uc3QgcGF0aCA9IHRoaXMuZm9jdXNQYXRoO1xuXG4gICAgICAgIGxldCBrZXlzO1xuICAgICAgICBpZiAoa2V5KSB7XG4gICAgICAgICAgICBrZXlzID0gQXJyYXkuaXNBcnJheShrZXkpID8ga2V5IDogW2tleV07XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoa2V5cykge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBrZXlzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIGNvbnN0IGhhc1RpbWVyID0gdGhpcy5fX2tleXByZXNzVGltZXJzLmhhcyhrZXlzW2ld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G9tVXBFdmVudChbYF9oYW5kbGUke2tleXNbaV19UmVsZWFzZWAsIFwiX2hhbmRsZUtleVJlbGVhc2VcIl0sIG9iaik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKCF0aGlzLnN0YWdlLmFwcGxpY2F0aW9uLmZvY3VzVG9wRG93bkV2ZW50KFtcIl9jYXB0dXJlS2V5UmVsZWFzZVwiXSwgb2JqKSkge1xuICAgICAgICAgICAgICAgIHRoaXMuc3RhZ2UuYXBwbGljYXRpb24uZm9jdXNCb3R0b21VcEV2ZW50KFtcIl9oYW5kbGVLZXlSZWxlYXNlXCJdLCBvYmopO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgdGhpcy51cGRhdGVGb2N1c1BhdGgoKTtcblxuICAgICAgICBpZiAoa2V5cykge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBrZXlzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9fa2V5cHJlc3NUaW1lcnMuaGFzKGtleXNbaV0pKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIGtleXVwIGhhcyBmaXJlZCBiZWZvcmUgZW5kIG9mIHRpbWVvdXQgc28gd2UgY2xlYXIgaXRcbiAgICAgICAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHRoaXMuX19rZXlwcmVzc1RpbWVycy5nZXQoa2V5c1tpXSkpO1xuICAgICAgICAgICAgICAgICAgICAvLyBkZWxldGUgc28gd2UgY2FuIHJlZ2lzdGVyIGl0IGFnYWluXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX19rZXlwcmVzc1RpbWVycy5kZWxldGUoa2V5c1tpXSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogUmVnaXN0ZXJ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AgICAgIGlmIChjaGlsZCAmJiBjaGlsZFtcIl9oYW5kbGVDbGlja1wiXSkge1xuICAgICAgICAgICAgICAgIGNvbnN0IHsgcHgsIHB5IH0gPSBjaGlsZC5jb3JlLl93b3JsZENvbnRleHQ7XG4gICAgICAgICAgICAgICAgY29uc3QgY3ggPSBweCAqIHByZWNpc2lvbjtcbiAgICAgICAgICAgICAgICBjb25zdCBjeSA9IHB5ICogcHJlY2lzaW9uO1xuXG4gICAgICAgICAgICAgICAgY29uc3QgbG9jYWxDb29yZHMgPSB7XG4gICAgICAgICAgICAgICAgICAgIHg6IGNsaWVudFggLSBjeCxcbiAgICAgICAgICAgICAgICAgICAgeTogY2xpZW50WSAtIGN5XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgY29uc3QgcmV0dXJuVmFsdWUgPSBjaGlsZC5faGFuZGxlQ2xpY2sodGFyZ2V0LCBsb2NhbENvb3Jkcyk7XG4gICAgICAgICAgICAgICAgaWYgKHJldHVyblZhbHVlICE9PSBmYWxzZSkge1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjaGlsZCA9IGNoaWxkLnBhcmVudDtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9yZWNlaXZlSG92ZXIoZSkge1xuICAgICAgICBjb25zdCBvYmogPSBlO1xuICAgICAgICBjb25zdCB7IGNsaWVudFgsIGNsaWVudFkgfSA9IG9iajtcblxuICAgICAgICBpZiAoY2xpZW50WCA8PSB0aGlzLnN0YWdlLncgJiYgY2xpZW50WSA8PSB0aGlzLnN0YWdlLmgpIHtcbiAgICAgICAgICAgIHRoaXMuc3RhZ2UuYXBwbGljYXRpb24uZmlyZUJvdHRvbVVwSG92ZXJIYW5kbGVyKG9iaik7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBmaXJlQm90dG9tVXBIb3ZlckhhbmRsZXIob2JqKSB7XG4gICAgICAg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JlZW4gaG92ZXJlZFxuICAgICAgICAgICAgLy8gYmFjayBmcm9tIGl0cyBjaGlsZFxuICAgICAgICAgICAgaWYgKGRpZmZCcmFuY2gubGVuZ3RoID09PSAwICYmIHRhcmdldCkge1xuICAgICAgICAgICAgICAgIGNvbnN0IGMgPSBDb21wb25lbnQuZ2V0Q29tcG9uZW50KHRhcmdldCk7XG4gICAgICAgICAgICAgICAgaWYgKGNbXCJfaGFuZGxlSG92ZXJcIl0pIHtcbiAgICAgICAgICAgICAgICAgICAgYy5faGFuZGxlSG92ZXIodGFyZ2V0KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZ2V0VGFyZ2V0Q2hpbGQoY2xpZW50WCwgY2xpZW50WSkge1xuICAgICAgICBsZXQgY2hpbGRyZW4gPSB0aGlzLnN0YWdlLmFwcGxpY2F0aW9uLmNoaWxkcmVuO1xuICAgICAgICBsZXQgYWZmZWN0ZWQgPSB0aGlzLl9maW5kQ2hpbGRyZW4oW10sIGNoaWxkcmVuKTtcbiAgICAgICAgbGV0IGhvdmVyYWJsZUNoaWxkcmVuID0gdGhpcy5fd2l0aGluQ2xpY2thYmxlUmFuZ2UoYWZmZWN0ZWQsIGNsaWVudFgsIGNsaWVudFkpO1xuXG4gICAgICAgIGhvdmVyYWJsZUNoaWxkcmVuLnNvcnQoKGEsIGIpID0+IHtcbiAgICAgICAgICAgIC8vIFNvcnQgYnkgekluZGV4IGFuZCB0aGVuIGlkXG4gICAgICAgICAgICBpZiAoYS56SW5kZXggPiBiLnpJbmRleCkge1xuICAgICAgICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChhLnpJbmRleCA8IGIuekluZGV4KSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIC0xO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gYS5pZCA+IGIuaWQgPyAxIDogLTE7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuXG4gICAgICAgIGlmIChob3ZlcmFibGVDaGlsZHJlbi5sZW5ndGgpIHtcbiAgICAgICAgICAgIC8vIEFzc3VtZSB0YXJnZXQgaGFzIGhpZ2hlc3QgekluZGV4IChpZCB3aGVuIHpJbmRleCBlcXVhbClcbiAgICAgICAgICAgIHJldHVybiBob3ZlcmFibGVDaGlsZHJlbi5zbGljZSgtMSlbMF07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gbnVsbDtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9maW5kQ2hpbGRyZW4oYnVja2V0LCBjaGlsZHJlbikge1xuICAgICAgICBsZXQgbiA9IGNoaWxkcmVuLmxlbmd0aDtcbiAgICAgICAgd2hpbGUgKG4tLSkge1xuICAgICAgICAgICAgY29uc3QgY2hpbGQgPSBjaGlsZHJlbltuXTtcbiAgICAgICAgICAgIC8vIG9ubHkgYWRkIGFjdGl2ZSBjaGlsZHJlblxuICAgICAgICAgICAgaWYgKGNoaWxkLl9fYWN0aXZlICYmIGNoaWxkLmNvbGxpc2lvbikge1xuICAgICAgICAgICAgICAgIGlmIChjaGlsZC5jb2xsaXNpb24gPT09IHRydWUpIHtcbiAgICAgICAgICAgICAgICAgICAgYnVja2V0LnB1c2goY2hpbGQpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAoY2hpbGQuaGFzQ2hpbGRyZW4oKSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9maW5kQ2hpbGRyZW4oYnVja2V0LCBjaGlsZC5jaGlsZHJlbik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBidWNrZXQ7XG4gICAgfVxuXG4gICAgX3dpdGhpbkNsaWNrYWJsZVJhbmdlKGFmZmVjdGVkQ2hpbGRyZW4sIGN1cnNvclgsIGN1cnNvclkpIHtcbiA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xuICAgICAgICAgICAgICAgIGlmICghdGhpcy5fdGVzdENvbGxpc2lvbihjdXJzb3JYLCBjdXJzb3JZLCAuLi5zY2lzc29yKSlcbiAgICAgICAgICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX3Rlc3RDb2xsaXNpb24oY3Vyc29yWCwgY3Vyc29yWSwgY3gsIGN5LCBjdywgY2gpKSB7XG4gICAgICAgICAgICAgICAgY2FuZGlkYXRlcy5wdXNoKGNoaWxkKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gY2FuZGlkYXRlcztcbiAgICB9XG5cbiAgICBfdGVzdENvbGxpc2lvbihweCwgcHksIGN4LCBjeSwgY3csIGNoKSB7XG4gICAgICAgIGlmIChweCA+PSBjeCAmJlxuICAgICAgICAgICAgcHggPD0gY3ggKyBjdyAmJlxuICAgICAgICAgICAgcHkgPj0gY3kgJiZcbiAgICAgICAgICAgIHB5IDw9IGN5ICsgY2gpIHtcbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9XG5cbiAgICBkZXN0cm95KCkge1xuICAgICAgICBpZiAoIXRoaXMuX2Rlc3Ryb3llZCkge1xuICAgICAgICAgICAgdGhpcy5fZGVzdHJveSgpO1xuICAgICAgICAgICAgdGhpcy5zdGFnZS5kZXN0cm95KCk7XG4gICAgICAgICAgICB0aGlzLl9kZXN0cm95ZWQgPSB0cnVlO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2Rlc3Ryb3koKSB7XG4gICAgICAgIC8vIFRoaXMgZm9yY2VzIHRoZSBfZGV0YWNoLCBfZGlzYWJsZWQgYW5kIF9hY3RpdmUgZXZlbnRzIHRvIGJlIGNhbGxlZC5cbiAgICAgICAgdGhpcy5zdGFnZS5zZXRBcHBsaWNhdGlvbih1bmRlZmluZWQpO1xuICAgICAgICB0aGl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uYyA/IHByb3BPYmouX19mdW5jIDogKGNvbnRleHQpID0+IGNvbnRleHRbcHJvcE5hbWVdO1xuXG4gICAgICAgICAgICBpZiAoIXRoaXMuaGFzT3duUHJvcGVydHkocHJvcE5hbWUpKSB7XG4gICAgICAgICAgICAgICAgdGhpc1tgX19wcm9wX2JpbmRpbmdzXyR7cHJvcE5hbWV9YF0gPSBbe19fb2JqOiBvYmosIF9fcHJvcDogcHJvcCwgX19mdW5jOiBmdW5jfV07XG4gICAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsIHByb3BOYW1lLCB7XG4gICAgICAgICAgICAgICAgICAgIHNldDogKHZhbHVlKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzW2BfX3Byb3BfJHtwcm9wTmFtZX1gXSA9IHZhbHVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChjb25zdCB7X19vYmosIF9fcHJvcCwgX19mdW5jfSBvZiB0aGlzW2BfX3Byb3BfYmluZGluZ3NfJHtwcm9wTmFtZX1gXSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fb2JqW19fcHJvcF0gPSBfX2Z1bmModGhpcyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIGdldDogKCkgPT4gdGhpc1tgX19wcm9wXyR7cHJvcE5hbWV9YF1cbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpc1tgX19wcm9wX2JpbmRpbmdzXyR7cHJvcE5hbWV9YF0ucHVzaCh7X19vYmo6IG9iaiwgX19wcm9wOiBwcm9wLCBfX2Z1bmM6IGZ1bmN9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFJldHVybnMgYSBoaWdoLXBlcmZvcm1hbmNlIHRlbXB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MgcGFyc2VUZW1wbGF0ZVJlYyhvYmosIGNvbnRleHQsIGN1cnNvcikge1xuICAgICAgICBjb25zdCBzdG9yZSA9IGNvbnRleHQuc3RvcmU7XG4gICAgICAgIGNvbnN0IGxvYyA9IGNvbnRleHQubG9jO1xuICAgICAgICBjb25zdCBrZXlzID0gT2JqZWN0LmtleXMob2JqKTtcbiAgICAgICAga2V5cy5mb3JFYWNoKGtleSA9PiB7XG4gICAgICAgICAgICBsZXQgdmFsdWUgPSBvYmpba2V5XTtcbiAgICAgICAgICAgIGlmIChVdGlscy5pc1VjQ2hhcihrZXkuY2hhckNvZGVBdCgwKSkpIHtcbiAgICAgICAgICAgICAgICAvLyBWYWx1ZSBtdXN0IGJlIGV4cGFuZGVkIGFzIHdlbGwuXG4gICAgICAgICAgICAgICAgaWYgKFV0aWxzLmlzT2JqZWN0TGl0ZXJhbCh2YWx1ZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gUmVmLlxuICAgICAgICAgICAgICAgICAgICBjb25zdCBjaGlsZEN1cnNvciA9IGByJHtrZXkucmVwbGFjZSgvW15hLXowLTldL2dpLCBcIlwiKSArIGNvbnRleHQucmlkfWA7XG4gICAgICAgICAgICAgICAgICAgIGxldCB0eXBlID0gdmFsdWUudHlwZSA/IHZhbHVlLnR5cGUgOiBFbGVtZW50O1xuICAgICAgICAgICAgICAgICAgICBpZiAodHlwZSA9PT0gRWxlbWVudCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYHZhciAke2NoaWxkQ3Vyc29yfSA9IGVsZW1lbnQuc3RhZ2UuY3JlYXRlRWxlbWVudCgpYCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzdG9yZS5wdXNoKHR5cGUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYHZhciAke2NoaWxkQ3Vyc29yfSA9IG5ldyBzdG9yZVske3N0b3JlLmxlbmd0aCAtIDF9XSgke2N1cnNvcn0uc3RhZ2UpYCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYCR7Y2hpbGRDdXJzb3J9LnJlZiA9IFwiJHtrZXl9XCJgKTtcbiAgICAgICAgICAgICAgICAgICAgY29udGV4dC5yaWQrKztcblxuICAgICAgICAgICAgICAgICAgICAvLyBFbnRlciBzdWIuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucGFyc2VUZW1wbGF0ZVJlYyh2YWx1ZSwgY29udGV4dCwgY2hpbGRDdXJzb3IpO1xuXG4gICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn0uY2hpbGRMaXN0LmFkZCgke2NoaWxkQ3Vyc29yfSlgKTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKFV0aWxzLmlzT2JqZWN0KHZhbHVlKSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBEeW5hbWljIGFzc2lnbm1lbnQuXG4gICAgICAgICAgICAgICAgICAgIHN0b3JlLnB1c2godmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtjdXJzb3J9LmNoaWxkTGlzdC5hZGQoc3RvcmVbJHtzdG9yZS5sZW5ndGggLSAxfV0pYCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZiAoa2V5ID09PSBcInRleHRcIikge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBwcm9wS2V5ID0gY3Vyc29yICsgXCJfX3RleHRcIjtcbiAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYHZhciAke3Byb3BLZXl9ID0gJHtjdXJzb3J9LmVuYWJsZVRleHRUZXh0dXJlKClgKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHZhbHVlLl9fcHJvcGVydHlCaW5kaW5nID09PSB0cnVlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBBbGxvdyBiaW5kaW5nIGVudGlyZSBvYmplY3RzIHRvIHRleHQgcHJvcGVydHlcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0b3JlLnB1c2godmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYGVsZW1lbnQuX19iaW5kUHJvcGVydHkoc3RvcmVbJHtzdG9yZS5sZW5ndGggLSAxfV0sICR7Y3Vyc29yfSwgXCIke2tleX1cIilgKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucGFyc2VUZW1wbGF0ZVByb3BSZWModmFsdWUsIGNvbnRleHQsIHByb3BLZXkpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChrZXkgPT09IFwic2hhZGVyXCIgJiYgVXRpbHMuaXNPYmplY3RMaXRlcmFsKHZhbHVlKSkge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBzaGFkZXJDdXJzb3IgPSBgJHtjdXJzb3J9W1wic2hhZGVyXCJdYFxuICAgICAgICAgICAgICAgICAgICBzdG9yZS5wdXNoKHZhbHVlKTtcbiAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYCR7Y3Vyc29yfVtcIiR7a2V5fVwiXSA9IHN0b3JlWyR7c3RvcmUubGVuZ3RoIC0gMX1dYCk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMucGFyc2VQcm9wZXJ0eUJpbmRpbmdzKHZhbHVlLCBjb250ZXh0LCBzaGFkZXJDdXJzb3IpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoa2V5ID09PSBcInRleHR1cmVcIiAmJiBVdGlscy5pc09iamVjdExpdGVyYWwodmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHByb3BLZXkgPSBjdXJzb3IgKyBcIl9fdGV4dHVyZVwiO1xuICAgICAgICAgICAgICAgICAgICBjb25zdCB0eXBlID0gdmFsdWUudHlwZTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHR5cGUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0b3JlLnB1c2godHlwZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgdmFyICR7cHJvcEtleX0gPSBuZXcgc3RvcmVbJHtzdG9yZS5sZW5ndGggLSAxfV0oJHtjdXJzb3J9LnN0YWdlKWApO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5wYXJzZVRlbXBsYXRlUHJvcFJlYyh2YWx1ZSwgY29udGV4dCwgcHJvcEtleSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtjdXJzb3J9W1wiJHtrZXl9XCJdID0gJHtwcm9wS2V5fWApO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYCR7cHJvcEtleX0gPSAke2N1cnNvcn0udGV4dHVyZWApO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5wYXJzZVRlbXBsYXRlUHJvcFJlYyh2YWx1ZSwgY29udGV4dCwgcHJvcEtleSk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKFV0aWxzLmlzT2JqZWN0TGl0ZXJhbCh2YWx1ZSkgJiYgdmFsdWUuX19wcm9wZXJ0eUJpbmRpbmcgPT09IHRydWUpIHtcbiAgICAgICAgICAgICAgICAgICAgc3RvcmUucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGBlbGVtZW50Ll9fYmluZFByb3BlcnR5KHN0b3JlWyR7c3RvcmUubGVuZ3RoIC0gMX1dLCAke2N1cnNvcn0sIFwiJHtrZXl9XCIpYCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gUHJvcGVydHk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChVdGlscy5pc051bWJlcih2YWx1ZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn1bXCIke2tleX1cIl0gPSAke3ZhbHVlfWApO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKFV0aWxzLmlzQm9vbGVhbih2YWx1ZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxvYy5wdXNoKGAke2N1cnNvcn1bXCIke2tleX1cIl0gPSAke3ZhbHVlID8gXCJ0cnVlXCIgOiBcImZhbHNlXCJ9YCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoVXRpbHMuaXNPYmplY3QodmFsdWUpIHx8IEFycmF5LmlzQXJyYXkodmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBEeW5hbWljIGFzc2lnbm1lbnQuXG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBCZWNhdXNlIGxpdGVyYWwgb2JqZWN0cyBtYXkgY29udGFpbiBkeW5hbWljcywgd2Ugc3RvcmUgdGhlIGZ1bGwgb2JqZWN0LlxuICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmUucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtjdXJzb3J9W1wiJHtrZXl9XCJdID0gc3RvcmVbJHtzdG9yZS5sZW5ndGggLSAxfV1gKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFN0cmluZyBldGMuXG4gICAgICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtjdXJzb3J9W1wiJHtrZXl9XCJdID0gJHtKU09OLnN0cmluZ2lmeSh2YWx1ZSl9YCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgI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1xuICAgICAgICAgICAgICAgICAgICAvLyBEeW5hbWljIGFzc2lnbm1lbnQuXG4gICAgICAgICAgICAgICAgICAgIC8vIEJlY2F1c2UgbGl0ZXJhbCBvYmplY3RzIG1heSBjb250YWluIGR5bmFtaWNzLCB3ZSBzdG9yZSB0aGUgZnVsbCBvYmplY3QuXG4gICAgICAgICAgICAgICAgICAgIHN0b3JlLnB1c2godmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtjdXJzb3J9W1wiJHtrZXl9XCJdID0gc3RvcmVbJHtzdG9yZS5sZW5ndGggLSAxfV1gKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAvLyBTdHJpbmcgZXRjLlxuICAgICAgICAgICAgICAgICAgICBsb2MucHVzaChgJHtjdXJzb3J9W1wiJHtrZXl9XCJdID0gJHtKU09OLnN0cmluZ2lmeSh2YWx1ZSl9YCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBzdGF0aWMgcGFyc2VQcm9wZXJ0eUJpbmRpbmdzKG9iaiwgY29udGV4dCwgY3Vyc29yKSB7XG4gICAgICAgIGNvbnN0IHN0b3JlID0gY29udGV4dC5zdG9yZTtcbiAgICAgICAgY29uc3QgbG9jID0gY29udGV4dC5sb2M7XG4gICAgICAgIGNvbnN0IGtleXMgPSBPYmplY3Qua2V5cyhvYmopO1xuICAgICAgICBrZXlzLmZvckVhY2goa2V5ID0+IHtcbiAgICAgICAgICAgIGlmIChrZXkgIT09IFwidHlwZVwiKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgdmFsdWUgPSBvYmpba2V5XTtcbiAgICAgICAgICAgICAgICBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKHZhbHVlKSAmJiB2YWx1ZS5fX3Byb3BlcnR5QmluZGluZyA9PT0gdHJ1ZSkge1xuICAgICAgICAgICAgICAgICAgICBzdG9yZS5wdXNoKHZhbHVlKTtcbiAgICAgICAgICAgICAgICAgICAgbG9jLnB1c2goYGVsZW1lbnQuX19iaW5kUHJvcGVydHkoc3RvcmVbJHtzdG9yZS5sZW5ndGggLSAxfV0sICR7Y3Vyc29yfSwgXCIke2tleX1cIilgKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIF9vblNldHVwKCkge1xuICAgICAgICBpZiAoIXRoaXMuX19pbml0aWFsaXplZCkge1xuICAgICAgICAgICAgdGhpcy5fc2V0dXAoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9zZXR1cCgpIHtcbiAgICB9XG5cbiAgICBfb25BdHRhY2goKSB7XG4gICAgICAgIGlmICghdGhpcy5fX2luaXRpYWxpemVkKSB7XG4gICAgICAgICAgICB0aGlzLl9faW5pdCgpO1xuICAgICAgICAgICAgdGhpcy5fX2luaXRpYWxpemVkID0gdHJ1ZTtcbiAgICAgICAgfVxuXG4gICAgICAgIHRoaXMuX2F0dGFjaCgpO1xuICAgIH1cblxuICAgIF9hdHRhY2goKSB7XG4gICAgfVxuXG4gICAgX29uRGV0YWNoKCkge1xuICAgICAgICB0aGlzLl9kZXRhY2goKTtcbiAgICB9XG5cbiAgICBfZGV0YWNoKCkge1xuICAgIH1cblxuICAgIF9vbkVuYWJsZWQoKSB7XG4gICAgICAgIGlmICghdGhpcy5fX2ZpcnN0RW5hYmxlKSB7XG4gICAgICAgICAgICB0aGlzLl9maXJzdEVuYWJsZSgpO1xuICAgICAgICAgICAgdGhpcy5fX2ZpcnN0RW5hYmxlID0gdHJ1ZTtcbiAgICAgICAgfVxuXG4gICAgICAgIHRoaXMuX2VuYWJsZSgpO1xuICAgIH1cblxuICAgIF9maXJzdEVuYWJsZSgpIHtcbiAgICB9XG5cbiAgICBfZW5hYmxlKCkge1xuICAgIH1cblxuICAgIF9vbkRpc2FibGVkKCkge1xuICAgICAgICB0aGlzLl9kaXN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ICAgICAgICBmb3IgKGxldCBrZXkgaW4gdikge1xuICAgICAgICAgICAgY29uc3QgZCA9IHZba2V5XTtcbiAgICAgICAgICAgIGlmIChkID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBkZWxldGUgdGhpcy5fX3NpZ25hbHNba2V5XTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fX3NpZ25hbHNba2V5XSA9IHY7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgcGFzc1NpZ25hbHMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fcGFzc1NpZ25hbHMgfHwge307XG4gICAgfVxuXG4gICAgc2V0IHBhc3NTaWduYWxzKHYpIHtcbiAgICAgICAgdGhpcy5fX3Bhc3NTaWduYWxzID0gT2JqZWN0LmFzc2lnbih0aGlzLl9fcGFzc1NpZ25hbHMgfHwge30sIHYpO1xuICAgIH1cblxuICAgIHNldCBhbHRlclBhc3NTaWduYWxzKHYpIHtcbiAgICAgICAgaWYgKCFVdGlscy5pc09iamVjdExpdGVyYWwodikpIHtcbiAgICAgICAgICAgIHRoaXMuX3Rocm93RXJyb3IoXCJTaWduYWxzOiBzcGVjaWZ5IGFuIG9iamVjdCB3aXRoIHNpZ25hbC10by1maXJlIG1hcHBpbmdzXCIpO1xuICAgICAgICB9XG4gICAgICAgIGlmICghdGhpcy5fX3Bhc3NTaWduYWxzKSB7XG4gICAgICAgICAgICB0aGlzLl9fcGFzc1NpZ25hbHMgPSB7fTtcbiAgICAgICAgfVxuICAgICAgICBmb3IgKGxldCBrZXkgaW4gdikge1xuICAgICAgICAgICAgY29uc3QgZCA9IHZba2V5XTtcbiAgICAgICAgICAgIGlmIChkID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICBkZWxldGUgdGhpcy5fX3Bhc3NTaWduYWxzW2tleV07XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX19wYXNzU2lnbmFsc1trZXldID0gdjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFNpZ25hbHMgdGhlIHBhcmVudCBvZiB0aGUgc3BlY2lmaWVkIGV2ZW50LlxuICAgICAqIEEgcGFyZW50L2FuY2VzdG9yIHRoYXQgd2lzaGVzIHRvIGhhbmRsZSB0aGUgc2lnbmFsIHNob3VsZCBzZXQgdGhlICdzaWduYWxzJyBwcm9wZXJ0eSBvbiB0aGlzIGNvbXBvbmVudC5cbiAgICAgKiBAcGFyYW0ge3N0cmluZ30gZXZlbnRcbiAgICAgKiBAcGFyYW0gey4uLip9IGFyZ3NcbiAgICAgKi9cbiAgICBzaWduYWwoZXZlbnQsIC4uLmFyZ3MpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3NpZ25hbChldmVudCwgYXJncyk7XG4gICAgfVxuXG4gICAgX3NpZ25hbChldmVudCwgYXJncykge1xuICAgICAgICBjb25zdCBzaWduYWxQYXJlbnQgPSB0aGlzLl9nZXRQYXJlbnRTaWduYWxIYW5kbGVyKCk7XG4gICAgICAgIGlmIChzaWduYWxQYXJlbnQpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9fc2lnbmFscykge1xuICAgICAgICAgICAgICAgIGxldCBmaXJlRXZlbnQgPSB0aGlzLl9fc2lnbmFsc1tldmVudF07XG4gICAgICAgICAgICAgICAgaWYgKGZpcmVFdmVudCA9PT0gZmFsc2UpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gSWdub3JlIGV2ZW50LlxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChmaXJlRXZlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZpcmVFdmVudCA9PT0gdHJ1ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgZmlyZUV2ZW50ID0gZXZlbnQ7XG4gICAgICAgICAgICAgICAgICAgIH1cbiBcbiAgICAgICAgICAgICAgICAgICAgaWYgKFV0aWxzLmlzRnVuY3Rpb24oZmlyZUV2ZW50KSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZpcmVFdmVudCguLi5hcmdzKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIGlmIChzaWduYWxQYXJlbnQuX2hhc01ldGhvZChmaXJlRXZlbnQpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gc2lnbmFsUGFyZW50W2ZpcmVFdmVudF0oLi4uYXJncyk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGxldCBwYXNzU2lnbmFsID0gKHRoaXMuX19wYXNzU2lnbmFscyAmJiB0aGlzLl9fcGFzc1NpZ25hbHNbZXZlbnRdKTtcbiAgICAgICAgICAgIGlmIChwYXNzU2lnbmFsKSB7XG4gICAgICAgICAgICAgICAgLy8gQnViYmxlIHVwLlxuICAgICAgICAgICAgICAgIGlmIChwYXNzU2lnbmFsICYmIHBhc3NTaWduYWwgIT09IHRydWUpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gUmVwbGFjZSBzaWduYWwgbmFtZS5cbiAgICAgICAgICAgICAgICAgICAgZXZlbnQgPSBwYXNzU2lnbmFsO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIHJldHVybiBzaWduYWxQYXJlbnQuX3NpZ25hbChldmVudCwgYXJncyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZ2V0UGFyZW50U2lnbmFsSGFuZGxlcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuY3BhcmVudCA/IHRoaXMuY3BhcmVudC5fZ2V0U2lnbmFsSGFuZGxlcigpIDogbnVsbDtcbiAgICB9XG5cbiAgICBfZ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fZG9GaXJlQW5jZXN0b3JzKG5hbWUsIGFyZ3MpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGNvbGxlY3RTdWJDb21wb25lbnRzKHN1YnMsIGVsZW1lbnQpIHtcbiAgICAgICAgaWYgKGVsZW1lbnQuaGFzQ2hpbGRyZW4oKSkge1xuICAgICAgICAgICAgY29uc3QgY2hpbGRMaXN0ID0gZWxlbWVudC5fX2NoaWxkTGlzdDtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gY2hpbGRMaXN0Lmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIGNvbnN0IGNoaWxkID0gY2hpbGRMaXN0LmdldEF0KGkpO1xuICAgICAgICAgICAgICAgIGlmIChjaGlsZC5pc0NvbXBvbmVudCkge1xuICAgICAgICAgICAgICAgICAgICBzdWJzLnB1c2goY2hpbGQpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIENvbXBvbmVudC5jb2xsZWN0U3ViQ29tcG9uZW50cyhzdWJzLCBjaGlsZCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGdldENvbXBvbmVudChlbGVtZW50KSB7XG4gICAgICAgIGxldCBwYXJlbnQgPSBlbGVtZW50O1xuICAgICAgICB3aGlsZSAocGFyZW50ICYmICFwYXJlbnQuaXNDb21wb25lbnQpIHtcbiAgICAgICAgICAgIHBhcmVudCA9IHBhcmVudC5wYXJlbnQ7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHBhcmVudDtcbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0UGFyZW50KGVsZW1lbnQpIHtcbiAgICAgICAgcmV0dXJuIENvbXBvbmVudC5nZXRDb21wb25lbnQoZWxlbWVudC5wYXJlbnQpO1xuICAgIH1cbn1cblxuQ29tcG9uZW50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9O1xuICAgICAgICAgICAgICAgIGNvbnN0IHNoYXJlZExldmVsID0gc2hhcmVkU3RhdGUuX19sZXZlbDtcblxuICAgICAgICAgICAgICAgIGlmIChoYXNEaWZmZXJlbnRFeGl0TWV0aG9kKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGV4aXRTdGF0ZXMgPSBTdGF0ZU1hY2hpbmUuX2dldFN0YXRlc1VudGlsTGV2ZWwodGhpcy5fc3RhdGUsIHNoYXJlZExldmVsKTtcbiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBleGl0U3RhdGVzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fX3NldFN0YXRlKGV4aXRTdGF0ZXNbaV0pO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fY2FsbEV4aXQodGhpcy5fc3RhdGUsIGFyZ3MsIGNvbnRleHQpO1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc3RhdGVDaGFuZ2VPdmVycmlkZGVuID0gKHRoaXMuX3NldFN0YXRlSWQgIT09IHNldFN0YXRlSWQpO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlQ2hhbmdlT3ZlcnJpZGRlbikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmIChoYXNEaWZmZXJlbnRFbnRlck1ldGhvZCkge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBlbnRlclN0YXRlcyA9IFN0YXRlTWFjaGluZS5fZ2V0U3RhdGVzVW50aWxMZXZlbChuZXdTdGF0ZSwgc2hhcmVkTGV2ZWwpLnJldmVyc2UoKTtcbiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBlbnRlclN0YXRlcy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX19zZXRTdGF0ZShlbnRlclN0YXRlc1tpXSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9jYWxsRW50ZXIodGhpcy5fc3RhdGUsIGFyZ3MsIGNvbnRleHQpO1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc3RhdGVDaGFuZ2VPdmVycmlkZGVuID0gKHRoaXMuX3NldFN0YXRlSWQgIT09IHNldFN0YXRlSWQpO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlQ2hhbmdlT3ZlcnJpZGRlbikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLl9fc2V0U3RhdGUobmV3U3RhdGUpO1xuXG4gICAgICAgICAgICBpZiAodGhpcy5fY2hhbmdlZFN0YXRlKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgY29udGV4dCA9IHtcbiAgICAgICAgICAgICAgICAgICAgbmV3U3RhdGU6IG5ld1N0YXRlLl9fcGF0aCxcbiAgICAgICAgICAgICAgICAgICAgcHJldlN0YXRlOiBwcmV2U3RhdGUuX19wYXRoXG4gICAgICAgICAgICAgICAgfTtcblxuICAgICAgICAgICAgICAgIGlmIChhcmdzKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2NoYW5nZWRTdGF0ZShjb250ZXh0LCAuLi5hcmdzKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9jaGFuZ2VkU3RhdGUoY29udGV4dCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAodGhpcy5fb25TdGF0ZUNoYW5nZSkge1xuICAgICAgICAgICAgICAgIGNvbnN0IGNvbnRleHQgPSB7XG4gICAgICAgICAgICAgICAgICAgIG5ld1N0YXRlOiBuZXdTdGF0ZS5fX3BhdGgsXG4gICAgICAgICAgICAgICAgICAgIHByZXZTdGF0ZTogcHJldlN0YXRlLl9fcGF0aFxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgdGhpcy5fb25TdGF0ZUNoYW5nZShjb250ZXh0KTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2NhbGxFbnRlcihzdGF0ZSwgYXJncyA9IFtdLCBjb250ZXh0KSB7XG4gICAgICAgIGNvbnN0IGhhc1BhcmVudCA9ICEhc3RhdGUuX19wYXJlbnQ7XG4gICAgICAgIGlmIChzdGF0ZS5wcm90b3R5cGUuJGVudGVyKSB7XG4gICAgICAgICAgICBpZiAoIWhhc1BhcmVudCB8fCAoc3RhdGUuX19wYXJlbnQucHJvdG90eXBlLiRlbnRlciAhPT0gc3RhdGUucHJvdG90eXBlLiRlbnRlcikpIHtcbiAgICAgICAgICAgICAgICBzdGF0ZS5wcm90b3R5cGUuJGVudGVyLmFwcGx5KHRoaXMsIFtjb250ZXh0LCAuLi5hcmdzXSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfY2FsbEV4aXQoc3RhdGUsIGFyZ3MgPSBbXSwgY29udGV4dCkge1xuICAgICAgICBjb25zdCBoYXNQYXJlbnQgPSAhIXN0YXRlLl9fcGFyZW50O1xuICAgICAgICBpZiAoc3RhdGUucHJvdG90eXBlLiRleGl0KSB7XG4gICAgICAgICAgICBpZiAoIWhhc1BhcmVudCB8fCAoc3RhdGUuX19wYXJlbnQucHJvdG90eXBlLiRleGl0ICE9PSBzdGF0ZS5wcm90b3R5cGUuJGV4aXQpKSB7XG4gICAgICAgICAgICAgICAgc3RhdGUucHJvdG90eXBlLiRleGl0Lm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BhcnJheSBpcyByZXR1cm5lZC5cbiAgICAgKiBAcGFyYW0ge3N0cmluZ1tdfSBtZW1iZXJOYW1lc1xuICAgICAqIEByZXR1cm5zIHtzdHJpbmd8dW5kZWZpbmVkfVxuICAgICAqIEBwcm90ZWN0ZWRcbiAgICAgKi9cbiAgICBfZ2V0TW9zdFNwZWNpZmljSGFuZGxlZE1lbWJlcihtZW1iZXJOYW1lcykge1xuICAgICAgICBsZXQgY3VyID0gdGhpcy5fc3RhdGU7XG4gICAgICAgIGRvIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gbWVtYmVyTmFtZXMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgbWVtYmVyTmFtZSA9IG1lbWJlck5hbWVzW2ldO1xuICAgICAgICAgICAgICAgIGlmICghY3VyLl9fcGFyZW50KSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChjdXIucHJvdG90eXBlW21lbWJlck5hbWVdKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gbWVtYmVyTmFtZTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGFsaWFzID0gU3RhdGVNYWNoaW5lVHlwZS5nZXRTdGF0ZU1lbWJlckFsaWFzKGN1ci5fX3BhdGgsIG1lbWJlck5hbWUpO1xuICAgICAgICAgICAgICAgICAgICBpZiAodGhpc1thbGlhc10pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBtZW1iZXJOYW1lO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY3VyID0gY3VyLl9fcGFyZW50O1xuICAgICAgICB9IHdoaWxlIChjdXIpO1xuICAgIH1cblxuICAgIHN0YXRpYyBfZ2V0U3RhdGVzVW50aWxMZXZlbChzdGF0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IoLi4uYXJndW1lbnRzKTtcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuY29uc3RydWN0b3IuaGFzT3duUHJvcGVydHkoJ19pc1JvdXRlcicpKSB7XG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihgWW91IG5lZWQgdG8gZXh0ZW5kICR7dHlwZS5uYW1lfS5vcmlnaW5hbCBpbnN0ZWFkIG9mICR7dHlwZS5uYW1lfS5gKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIHJvdXRlci5faXNSb3V0ZXIgPSB0cnVlO1xuICAgICAgICByb3V0ZXIucHJvdG90eXBlLl9yb3V0ZWRUeXBlID0gdHlwZTtcbiAgICAgICAgcm91dGVyLm9yaWdpbmFsID0gdHlwZTtcblxuICAgICAgICB0aGlzLl9taXhpblN0YXRlTWFjaGluZU1ldGhvZHMocm91dGVyKTtcblxuICAgICAgICByZXR1cm4gcm91dGVyO1xuICAgIH1cblxuICAgIF9taXhpblN0YXRlTWFjaGluZU1ldGhvZHMocm91dGVyKSB7XG4gICAgICAgIC8vIE1peGluIHRoZSBzdGF0ZSBtYWNoaW5lIG1ldGhvZHMsIHNvIHRoYXQgd2UgcmV1c2UgdGhlIG1ldGhvZHMgaW5zdGVhZCBvZiByZS1jcmVhdGluZyB0aGVtLlxuICAgICAgICBjb25zdCBuYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzKFN0YXRlTWFjaGluZS5wcm90b3R5cGUpO1xuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IG5hbWVzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgY29uc3QgbmFtZSA9IG5hbWVzW2ldO1xuICAgICAgICAgICAgaWYgKG5hbWUgIT09IFwiY29uc3RydWN0b3JcIikge1xuICAgICAgICAgICAgICAgIGNvbnN0IGRlc2NyaXB0b3IgPSBPYmplY3QuZ2V0T3duUHJvc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b3JzW2luZGV4XSA9IGRlc2NyaXB0b3I7XG5cbiAgICAgICAgICAgICAgICAvLyBBZGQgdG8gcHJvdG90eXBlLlxuICAgICAgICAgICAgICAgIGNvbnN0IGFsaWFzID0gU3RhdGVNYWNoaW5lVHlwZS5nZXRTdGF0ZU1lbWJlckFsaWFzKGRlc2NyaXB0b3IuX3NvdXJjZS5fX3BhdGgsIG1lbWJlcik7XG4gICAgICAgICAgICAgICAgYWxpYXNlc1tpbmRleF0gPSBhbGlhcztcblxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5fcm91dGVyLnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eShhbGlhcykpIHtcbiAgICAgICAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMuX3JvdXRlci5wcm90b3R5cGUsIGFsaWFzLCBkZXNjcmlwdG9yKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGRlc2NyaXB0b3JzW2luZGV4XSA9IG51bGw7XG4gICAgICAgICAgICAgICAgYWxpYXNlc1tpbmRleF0gPSBudWxsO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcblxuICAgICAgICBsZXQgdHlwZSA9IHVuZGVmaW5lZDtcbiAgICAgICAgZGVzY3JpcHRvcnMuZm9yRWFjaChkZXNjcmlwdG9yID0+IHtcbiAgICAgICAgICAgIGlmIChkZXNjcmlwdG9yKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgZGVzY1R5cGUgPSB0aGlzLl9nZXREZXNjcmlwdG9yVHlwZShkZXNjcmlwdG9yKTtcbiAgICAgICAgICAgICAgICBpZiAodHlwZSAmJiAodHlwZSAhPT0gZGVzY1R5cGUpKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybihgW0xpZ2h0bmluZ10gTWVtYmVyICR7bWVtYmVyfSBpbiAke3RoaXMuX3R5cGUubmFtZX0gaGFzIGluY29uc2lzdGVudCB0eXBlcy5gKTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0eXBlID0gZGVzY1R5cGU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuXG4gICAgICAgIHN3aXRjaCh0eXBlKSB7XG4gICAgICAgICAgICBjYXNlIFwibWV0aG9kXCI6XG4gICAgICAgICAgICAgICAgdGhpcy5fYWRkTWV0aG9kUm91dGVyKG1lbWJlciwgZGVzY3JpcHRvcnMsIGFsaWFzZXMpO1xuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgY2FzZSBcImdldHRlclwiOlxuICAgICAgICAgICAgICAgIHRoaXMuX2FkZEdldHRlclNldHRlclJvdXRlcnMobWVtYmVyKTtcbiAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIGNhc2UgXCJwcm9wZXJ0eVwiOlxuICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIEZpeGVkIHByb3BlcnRpZXMgYXJlIG5vdCBzdXBwb3J0ZWQ7IHBsZWFzZSB1c2UgYSBnZXR0ZXIgaW5zdGVhZCFcIilcbiAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9nZXREZXNjcmlwdG9yKHN0YXRlLCBtZW1iZXIsIGlzVmFsaWQgPSAoKSA9PiB0cnVlKSB7XG4gICAgICAgIGxldCB0eXBlID0gc3RhdGU7XG4gICAgICAgIGxldCBjdXJTdGF0ZSA9IHN0YXRlO1xuXG4gICAgICAgIGRvIHtcbiAgICAgICAgICAgIGNvbnN0IGRlc2NyaXB0b3IgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yKHR5cGUucHJvdG90eXBlLCBtZW1iZXIpO1xuICAgICAgICAgICAgaWYgKGRlc2NyaXB0b3IpIHtcbiAgICAgICAgICAgICAgICBpZiAoaXNWYWxpZChkZXNjcmlwdG9yKSkge1xuICAgICAgICAgICAgICAgICAgICBkZXNjcmlwdG9yLl9zb3VyY2UgPSBjdXJTdGF0ZTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRlc2NyaXB0b3I7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdHlwZSA9IE9iamVjdC5nZXRQcm90b3R5cGVPZih0eXBlKTtcbiAgICAgICAgICAgIGlmICh0eXBlICYmIHR5cGUuaGFzT3duUHJvcGVydHkoJ19fc3RhdGUnKSkge1xuICAgICAgICAgICAgICAgIGN1clN0YXRlID0gdHlwZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSB3aGlsZSh0eXBlICYmIHR5cGUucHJvdG90eXBlKTtcbiAgICAgICAgcmV0dXJuIHVuZGVmaW5lZDtcbiAgICB9XG5cbiAgICBfZ2V0RGVzY3JpcHRvclR5cGUoZGVzY3JpcHRvcikge1xuICAgICAgICBpZiAoZGVzY3JpcHRvci5nZXQgfHwgZGVzY3JpcHRvci5zZXQpIHtcbiAgICAgICAgICAgIHJldHVybiAnZ2V0dGVyJztcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh0eXBlb2YgZGVzY3JpcHRvci52YWx1ZSA9PT0gXCJmdW5jdGlvblwiKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuICdtZXRob2QnO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gJ3Byb3BlcnR5JztcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHN0YXRpYyBfc3VwcG9ydHNTcHJlYWQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9fc3VwcG9ydHNTcHJlYWQgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgdGhpcy5fX3N1cHBvcnRzU3ByZWFkID0gZmFsc2U7XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICA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pIDwgJHtpfSkgcmV0dXJuIHRoaXNbXCIke2N1cn1cIl0oLi4uYXJndW1lbnRzKTsgZWxzZWApO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgY29kZS5wdXNoKGBpZiAoaSA8ICR7aX0pIHJldHVybiB0aGlzW1wiJHtjdXJ9XCJdLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7IGVsc2VgKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNvZGUucHVzaChgaWYgKGkgPCAke2l9KSByZXR1cm4gOyBlbHNlYCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY3VyID0gYWxpYXM7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGN1cikge1xuICAgICAgICAgICAgaWYgKHN1cHBvcnRzU3ByZWFkKSB7XG4gICAgICAgICAgICAgICAgY29kZS5wdXNoKGByZXR1cm4gdGhpc1tcIiR7Y3VyfVwiXSguLi5hcmd1bWVudHMpO2ApO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjb2RlLnB1c2goYHJldHVybiB0aGlzW1wiJHtjdXJ9XCJdLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7YCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb2RlLnB1c2goYDtgKTtcbiAgICAgICAgfVxuICAgICAgICBjb25zdCBmdW5jdGlvbkJvZHkgPSBjb2RlLmpvaW4oXCJcXG5cIik7XG4gICAgICAgIGNvbnN0IHJvdXRlciA9IG5ldyBGdW5jdGlvbihbXSwgZnVuY3Rpb25Cb2R5KTtcblxuICAgICAgICBjb25zdCBkZXNjcmlwdG9yID0ge3ZhbHVlOiByb3V0ZXJ9O1xuICAgICAgICBPYmplY3QuZGVmaW5lUHJv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gICAgIC8vIEFkZCB0byBwcm90b3R5cGUuXG4gICAgICAgICAgICAgICAgY29uc3QgYWxpYXMgPSBTdGF0ZU1hY2hpbmVUeXBlLmdldFN0YXRlTWVtYmVyQWxpYXMoZGVzY3JpcHRvci5fc291cmNlLl9fcGF0aCwgbWVtYmVyKTtcbiAgICAgICAgICAgICAgICBhbGlhc2VzW2luZGV4XSA9IGFsaWFzO1xuXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLl9yb3V0ZXIucHJvdG90eXBlLmhhc093blByb3BlcnR5KGFsaWFzKSkge1xuICAgICAgICAgICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcy5fcm91dGVyLnByb3RvdHlwZSwgYWxpYXMsIGRlc2NyaXB0b3IpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgZGVzY3JpcHRvcnNbaW5kZXhdID0gbnVsbDtcbiAgICAgICAgICAgICAgICBhbGlhc2VzW2luZGV4XSA9IG51bGw7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuXG4gICAgICAgIGNvbnN0IGNvZGUgPSBbXG4gICAgICAgICAgICAvLyBUaGUgbGluZSBlbnN1cmVzIHRoYXQsIHdoaWxlIGRlYnVnZ2luZywgeW91ciBJREUgd29uJ3Qgb3BlbiBtYW55IHRhYnMuXG4gICAgICAgICAgICBcIi8vQCBzb3VyY2VVUkw9U3RhdGVNYWNoaW5lUm91dGVyLmpzXCIsXG4gICAgICAgICAgICBcInZhciBpID0gdGhpcy5fc3RhdGVJbmRleDtcIlxuICAgICAgICBdO1xuICAgICAgICBsZXQgY3VyID0gYWxpYXNlc1swXTtcbiAgICAgICAgZm9yIChsZXQgaSA9IDEsIG4gPSBhbGlhc2VzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgY29uc3QgYWxpYXMgPSBhbGlhc2VzW2ldO1xuICAgICAgICAgICAgaWYgKGFsaWFzICE9PSBjdXIpIHtcbiAgICAgICAgICAgICAgICBpZiAoY3VyKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvZGUucHVzaChgaWYgKGkgPCAke2l9KSByZXR1cm4gdGhpc1tcIiR7Y3VyfVwiXTsgZWxzZWApO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNvZGUucHVzaChgaWYgKGkgPCAke2l9KSByZXR1cm4gOyBlbHNlYCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY3VyID0gYWxpYXM7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGN1cikge1xuICAgICAgICAgICAgY29kZS5wdXNoKGByZXR1cm4gdGhpc1tcIiR7Y3VyfVwiXTtgKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGNvZGUucHVzaChgO2ApO1xuICAgICAgICB9XG4gICAgICAgIGNvbnN0IGZ1bmN0aW9uQm9keSA9IGNvZGUuam9pbihcIlxcblwiKTtcbiAgICAgICAgY29uc3Qgcm91dGVyID0gbmV3IEZ1bmN0aW9uKFtdLCBmdW5jdGlvbkJvZHkpO1xuICAgICAgICByZXR1cm4gcm91dGVyO1xuICAgIH1cblxuICAgIF9nZXRTZXR0ZXJSb3V0ZXIobWVtYmVyKSB7XG4gICAgICAgIGNvbnN0IHN0YXRlUGF0aHMgPSBPYmplY3Qua2V5cyh0aGlzLl9zdGF0ZU1hcCk7XG4gICAgICAgIGNvbnN0IGRlc2NyaXB0b3JzID0gW107XG4gICAgICAgIGNvbnN0IGFsaWFzZXMgPSBbXTtcbiAgICAgICAgc3RhdGVQYXRocy5mb3JFYWNoKChzdGF0ZVBhdGgsIGluZGV4KSA9PiB7XG4gICAgICAgICAgICBjb25zdCBzdGF0ZSA9IHRoaXMuX3N0YXRlTWFwW3N0YXRlUGF0aF07XG4gICAgICAgICAgICBjb25zdCBkZXNjcmlwdG9yID0gdGhpcy5fZ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ZUluZGV4O1wiXG4gICAgICAgIF07XG4gICAgICAgIGxldCBjdXIgPSBhbGlhc2VzWzBdO1xuICAgICAgICBmb3IgKGxldCBpID0gMSwgbiA9IGFsaWFzZXMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCBhbGlhcyA9IGFsaWFzZXNbaV07XG4gICAgICAgICAgICBpZiAoYWxpYXMgIT09IGN1cikge1xuICAgICAgICAgICAgICAgIGlmIChjdXIpIHtcbiAgICAgICAgICAgICAgICAgICAgY29kZS5wdXNoKGBpZiAoaSA8ICR7aX0pIHRoaXNbXCIke2N1cn1cIl0gPSBhcmc7IGVsc2VgKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBjb2RlLnB1c2goYGlmIChpIDwgJHtpfSkgOyBlbHNlYCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY3VyID0gYWxpYXM7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGN1cikge1xuICAgICAgICAgICAgY29kZS5wdXNoKGB0aGlzW1wiJHtjdXJ9XCJdID0gYXJnO2ApO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29kZS5wdXNoKGA7YCk7XG4gICAgICAgIH1cbiAgICAgICAgY29uc3QgZnVuY3Rpb25Cb2R5ID0gY29kZS5qb2luKFwiXFxuXCIpO1xuICAgICAgICBjb25zdCByb3V0ZXIgPSBuZXcgRnVuY3Rpb24oW1wiYXJnXCJdLCBmdW5jdGlvbkJvZHkpO1xuICAgICAgICByZXR1cm4gcm91dGVyO1xuICAgIH1cblxuICAgIHN0YXRpYyBnZXRTdGF0ZU1lbWJlckFsaWFzKHBhdGgsIG1lbWJlcikge1xuICAgICAgICByZXR1cm4gXCIkXCIgKyAocGF0aCA/IHBhdGggKyBcIi5cIiA6IFwiXCIpICsgbWVtYmVyO1xuICAgIH1cblxuICAgIF9nZXRBbGxNZW1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vcnQgRGVmYXVsdFNoYWRlciBmcm9tIFwiLi4vcmVuZGVyZXIvd2ViZ2wvc2hhZGVycy9EZWZhdWx0U2hhZGVyLm1qc1wiO1xuXG5leHBvcnQgZGVmYXVsdCBjbGFzcyBCbG9vbUNvbXBvbmVudCBleHRlbmRzIENvbXBvbmVudCB7XG5cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICBjb25zdCBvblVwZGF0ZSA9IGZ1bmN0aW9uKGVsZW1lbnQsIGVsZW1lbnRDb3JlKSB7XG4gICAgICAgICAgICBpZiAoKGVsZW1lbnRDb3JlLl9yZWNhbGMgJiAoMiArIDEyOCkpKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgdyA9IGVsZW1lbnRDb3JlLnc7XG4gICAgICAgICAgICAgICAgY29uc3QgaCA9IGVsZW1lbnRDb3JlLmg7XG4gICAgICAgICAgICAgICAgbGV0IGN1ciA9IGVsZW1lbnRDb3JlO1xuICAgICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICAgICAgY3VyID0gY3VyLl9jaGlsZHJlblswXTtcbiAgICAgICAgICAgICAgICAgICAgY3VyLl9lbGVtZW50LncgPSB3O1xuICAgICAgICAgICAgICAgICAgICBjdXIuX2VsZW1lbnQuaCA9IGg7XG4gICAgICAgICAgICAgICAgfSB3aGlsZShjdXIuX2NoaWxkcmVuKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcblxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgVGV4dHdyYXA6IHtydHQ6IHRydWUsIGZvcmNlWkluZGV4Q29udGV4dDogdHJ1ZSwgcmVuZGVyT2Zmc2NyZWVuOiB0cnVlLFxuICAgICAgICAgICAgICAgIEJsb29tQmFzZToge3NoYWRlcjoge3R5cGU6IEJsb29tQmFzZVNoYWRlcn0sXG4gICAgICAgICAgICAgICAgICAgIENvbnRlbnQ6IHt9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiA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gPSBwYWRkaW5nWTtcbiAgICAgICAgdGhpcy5nZXRMYXllcigwKS5oID0gdGhpcy5nZXRMYXllckNvbnRlbnRzKDApLmggPSBmaCAvIDI7XG4gICAgICAgIHRoaXMuZ2V0TGF5ZXIoMSkuaCA9IHRoaXMuZ2V0TGF5ZXJDb250ZW50cygxKS5oID0gZmggLyA0O1xuICAgICAgICB0aGlzLmdldExheWVyKDIpLmggPSB0aGlzLmdldExheWVyQ29udGVudHMoMikuaCA9IGZoIC8gODtcbiAgICAgICAgdGhpcy5nZXRMYXllcigzKS5oID0gdGhpcy5nZXRMYXllckNvbnRlbnRzKDMpLmggPSBmaCAvIDE2O1xuICAgICAgICB0aGlzLl9vdXRwdXQueSA9IC1wYWRkaW5nWTtcbiAgICAgICAgdGhpcy5fdGV4dHdyYXAueSA9IC1wYWRkaW5nWTtcbiAgICAgICAgdGhpcy5fb3V0cHV0LmggPSBmaDtcblxuICAgICAgICB0aGlzLncgPSB3O1xuICAgICAgICB0aGlzLmggPSBoO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFNldHMgdGhlIGFtb3VudCBvZiBibHVyLiBBIHZhbHVlIGJldHdlZW4gMCBhbmQgNC4gR29lcyB1cCBleHBvbmVudGlhbGx5IGZvciBibHVyLlxuICAgICAqIEJlc3QgcmVzdWx0cyBmb3Igbm9uLWZyYWN0aW9uYWwgdmFsdWVzLlxuICAgICAqIEBwYXJhbSB2O1xuICAgICAqL1xuICAgIHNldCBhbW91bnQodikge1xuICAgICAgICB0aGlzLl9hbW91bnQgPSB2O1xuICAgICAgICB0aGlzLl91cGRhdGUoKTtcbiAgICB9XG5cbiAgICBnZXQgYW1vdW50KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fYW1vdW50O1xuICAgIH1cblxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIGxldCB2ID0gTWF0aC5taW4oNCwgTWF0aC5tYXgoMCwgdGhpcy5fYW1vdW50KSk7XG4gICAgICAgIGlmICh2ID09PSAwKSB7XG4gICAgICAgICAgICB0aGlzLl90ZXh0d3JhcC5yZW5kZXJUb1RleHR1cmUgPSBmYWxzZTtcbiAgICAgICAgICAgIHRoaXMuX291dHB1dC5zaGFkZXIub3RoZXJUZXh0dXJlU291cmNlID0gbnVsbDtcbiAgICAgICAgICAgIHRoaXMuX291dHB1dC52aXNpYmxlID0gZmFsc2U7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl90ZXh0d3JhcC5yZW5kZXJUb1RleHR1cmUgPSB0cnVlO1xuICAgICAgICAgICAgdGhpcy5fb3V0cHV0LnZpc2libGUgPSB0cnVlO1xuXG4gICAgICAgICAgICB0aGlzLmdldExheWVyKDApLnZpc2libGUgPSAodiA+IDApO1xuICAgICAgICAgICAgdGhpcy5nZXRMYXllcigxKS52aXNpYmxlID0gKHYgPiAxKTtcbiAgICAgICAgICAgIHRoaXMuZ2V0TGF5ZXIoMikudmlzaWJsZSA9ICh2ID4gMik7XG4gICAgICAgICAgICB0aGlzLmdldExheWVyKDMpLnZpc2libGUgPSAodiA+IDMpO1xuXG4gICAgICAgICAgICBpZiAodiA8PSAxKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0cHV0LnRleHR1cmUgPSB0aGlzLl90ZXh0d3JhcC5nZXRUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0cHV0LnNoYWRlci5vdGhlclRleHR1cmVTb3VyY2UgPSB0aGlzLmdldExheWVyKDApLmdldFRleHR1cmUoKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9vdXRwdXQuc2hhZGVyLmEgPSB2O1xuICAgICAgICAgICAgfSBlbHNlIGlmICh2IDw9IDIpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9vdXRwdXQudGV4dHVyZSA9IHRoaXMuZ2V0TGF5ZXIoMCkuZ2V0VGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgIHRoaXMuX291dHB1dC5zaGFkZXIub3RoZXJUZXh0dXJlU291cmNlID0gdGhpcy5nZXRMYXllcigxKS5nZXRUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0cHV0LnNoYWRlci5hID0gdiAtIDE7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHYgPD0gMykge1xuICAgICAgICAgICAgICAgIHRoaXMuX291dHB1dC50ZXh0dXJlID0gdGhpcy5nZXRMYXllcigxKS5nZXRUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0cHV0LnNoYWRlci5vdGhlclRleHR1cmVTb3VyY2UgPSB0aGlzLmdldExheWVyKDIpLmdldFRleHR1cmUoKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9vdXRwdXQuc2hhZGVyLmEgPSB2IC0gMjtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodiA8PSA0KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0cHV0LnRleHR1cmUgPSB0aGlzLmdldExheWVyKDIpLmdldFRleHR1cmUoKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9vdXRwdXQuc2hhZGVyLm90aGVyVGV4dHVyZVNvdXJjZSA9IHRoaXMuZ2V0TGF5ZXIoMykuZ2V0VGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgIHRoaXMuX291dHB1dC5zaGFkZXIuYSA9IHYgLSAzO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2V0IHNoYWRlcihzKSB7XG4gICAgICAgIHN1cGVyLnNoYWRlciA9IHM7XG4gICAgICAgIGlmICghdGhpcy5yZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICAgIGNvbnNvbGUud2FybihcIltMaWdodG5pbmddIFBsZWFzZSBlbmFibGUgcmVuZGVyVG9UZXh0dXJlIHRvIHVzZSB3aXRoIGEgc2hhZGVyLlwiKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9maXJzdEFjdGl2ZSgpIHtcbiAgICAgICAgdGhpcy5fY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RvIHN0YXJ0LCBvciBzaG91bGQgaXQgYmUgY29udGludW91cywgbGlrZSBhIGNhcnJvdXNlbD9cbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX3JvbGwgPSBmYWxzZTtcblxuICAgICAgICAvKipcbiAgICAgICAgICogQWxsb3dzIHJlc3RyaWN0aW5nIHRoZSBzdGFydCBzY3JvbGwgcG9zaXRpb24uXG4gICAgICAgICAqL1xuICAgICAgICB0aGlzLl9yb2xsTWluID0gMDtcblxuICAgICAgICAvKipcbiAgICAgICAgICogQWxsb3dzIHJlc3RyaWN0aW5nIHRoZSBlbmQgc2Nyb2xsIHBvc2l0aW9uLlxuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5fcm9sbE1heCA9IDA7XG5cbiAgICAgICAgLyoqXG4gICAgICAgICAqIERlZmluaXRpb24gZm9yIGEgY3VzdG9tIGFuaW1hdGlvbiB0aGF0IGlzIGFwcGxpZWQgd2hlbiBhbiBpdGVtIGlzIChwYXJ0aWFsbHkpIHNlbGVjdGVkLlxuICAgICAgICAgKiBAdHlwZSBBbmltYXRpb25TZXR0aW5nc1xuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5fcHJvZ3Jlc3NBbmltYXRpb24gPSBudWxsO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBJbnZlcnRzIHRoZSBzY3JvbGxpbmcgZGlyZWN0aW9uLlxuICAgICAgICAgKiBAdHlwZSB7Ym9vbGVhbn1cbiAgICAgICAgICogQHByaXZhdGVcbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX2ludmVydERpcmVjdGlvbiA9IGZhbHNlO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBMYXlvdXQgdGhlIGl0ZW1zIGhvcml6b250YWxseSBvciB2ZXJ0aWNhbGx5P1xuICAgICAgICAgKiBAdHlwZSB7Ym9vbGVhbn1cbiAgICAgICAgICogQHByaXZhdGVcbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX2hvcml6b250YWw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leCAqIHRoaXMuX2l0ZW1TaXplO1xuXG4gICAgICAgIGlmICh0aGlzLl9yb2xsKSB7XG4gICAgICAgICAgICBsZXQgbWluLCBtYXgsIHNjcm9sbERlbHRhO1xuICAgICAgICAgICAgaWYgKGRpcmVjdGlvbiA9PSAxKSB7XG4gICAgICAgICAgICAgICAgbWF4ID0gKG5FbGVtZW50cyAtIDEpICogdGhpcy5faXRlbVNpemU7XG4gICAgICAgICAgICAgICAgc2Nyb2xsRGVsdGEgPSB0aGlzLl92aWV3cG9ydFNjcm9sbE9mZnNldCAqIHRoaXMudmlld3BvcnRTaXplIC0gdGhpcy5faXRlbVNjcm9sbE9mZnNldCAqIHRoaXMuX2l0ZW1TaXplO1xuXG4gICAgICAgICAgICAgICAgbWF4IC09IHNjcm9sbERlbHRhO1xuXG4gICAgICAgICAgICAgICAgbWluID0gdGhpcy52aWV3cG9ydFNpemUgLSAodGhpcy5faXRlbVNpemUgKyBzY3JvbGxEZWx0YSk7XG5cbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fcm9sbE1pbikgbWluIC09IHRoaXMuX3JvbGxNaW47XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3JvbGxNYXgpIG1heCArPSB0aGlzLl9yb2xsTWF4O1xuXG4gICAgICAgICAgICAgICAgdmFsdWUgPSBNYXRoLm1heChNYXRoLm1pbih2YWx1ZSwgbWF4KSwgbWluKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgbWF4ID0gKG5FbGVtZW50cyAqIHRoaXMuX2l0ZW1TaXplIC0gdGhpcy52aWV3cG9ydFNpemUpO1xuICAgICAgICAgICAgICAgIHNjcm9sbERlbHRhID0gdGhpcy5fdmlld3BvcnRTY3JvbGxPZmZzZXQgKiB0aGlzLnZpZXdwb3J0U2l6ZSAtIHRoaXMuX2l0ZW1TY3JvbGxPZmZzZXQgKiB0aGlzLl9pdGVtU2l6ZTtcblxuICAgICAgICAgICAgICAgIG1heCArPSBzY3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NYXRoLmNlaWwodiAvIHRoaXMuX2l0ZW1TaXplKTtcbiAgICAgICAgICAgIHBzID0gMSArICh2IC8gdGhpcy5faXRlbVNpemUpIC0gcztcbiAgICAgICAgICAgIGUgPSBNYXRoLmNlaWwoKHYgLSB2aWV3cG9ydFNpemUpIC8gdGhpcy5faXRlbVNpemUpO1xuICAgICAgICAgICAgcGUgPSBlIC0gKCh2IC0gdmlld3BvcnRTaXplKSAvIHRoaXMuX2l0ZW1TaXplKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fcm9sbCB8fCAodmlld3BvcnRTaXplID4gdGhpcy5faXRlbVNpemUgKiBuRWxlbWVudHMpKSB7XG4gICAgICAgICAgICAvLyBEb24ndCBzaG93IGFkZGl0aW9uYWwgaXRlbXMuXG4gICAgICAgICAgICBpZiAoZSA+PSBuRWxlbWVudHMpIHtcbiAgICAgICAgICAgICAgICBlID0gbkVsZW1lbnRzIC0gMTtcbiAgICAgICAgICAgICAgICBwZSA9IDE7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAocyA+PSBuRWxlbWVudHMpIHtcbiAgICAgICAgICAgICAgICBzID0gbkVsZW1lbnRzIC0gMTtcbiAgICAgICAgICAgICAgICBwcyA9IDE7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoZSA8PSAtMSkge1xuICAgICAgICAgICAgICAgIGUgPSAwO1xuICAgICAgICAgICAgICAgIHBlID0gMTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChzIDw9IC0xKSB7XG4gICAgICAgICAgICAgICAgcyA9IDA7XG4gICAgICAgICAgICAgICAgcHMgPSAxO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgbGV0IG9mZnNldCA9IC1kaXJlY3Rpb24gKiBzICogdGhpcy5faXRlbVNpemU7XG5cbiAgICAgICAgbGV0IGl0ZW07XG4gICAgICAgIGZvciAobGV0IGluZGV4ID0gczsgKGRpcmVjdGlvbiA9PSAtMSA/IGluZGV4IDw9IGUgOiBpbmRleCA+PSBlKTsgKGRpcmVjdGlvbiA9PSAtMSA/IGluZGV4KysgOiBpbmRleC0tKSkge1xuICAgICAgICAgICAgbGV0IHJlYWxJbmRleCA9IFV0aWxzLmdldE1vZHVsb0luZGV4KGluZGV4LCBuRWxlbWVudHMpO1xuXG4gICAgICAgICAgICBsZXQgZWxlbWVudCA9IHRoaXMuZ2V0RWxlbWVudChyZWFsSW5kZXgpO1xuICAgICAgICAgICAgaXRlbSA9IGVsZW1lbnQucGFyZW50O1xuICAgICAgICAgICAgdGhpcy5fdmlzaWJsZUl0ZW1zLmRlbGV0ZShpdGVtKTtcbiAgICAgICAgICAgIGlmICh0aGlzLl9ob3Jpem9udGFsKSB7XG4gICAgICAgICAgICAgICAgaXRlbS54ID0gb2Zmc2V0ICsgc2Nyb2xsRGVsdGE7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGl0ZW0ueSA9IG9mZnNldCArIHNjcm9sbERlbHRhO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBsZXQgd2FzVmlzaWJsZSA9IGl0ZW0udmlzaWJsZTtcbiAgICAgICAgICAgIGl0ZW0udmlzaWJsZSA9IHRydWU7XG5cbiAgICAgICAgICAgIGlmICghd2FzVmlzaWJsZSB8fCB0aGlzLl9yZWxvYWRWaXNpYmxlRWxlbWVudHMpIHtcbiAgICAgICAgICAgICAgICAvLyBUdXJuZWQgdmlzaWJsZS5cbiAgICAgICAgICAgICAgICB0aGlzLmVtaXQoJ3Zpc2libGUnLCBpbmRleCwgcmVhbEluZGV4KTtcbiAgICAgICAgICAgIH1cblxuXG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9wcm9ncmVzc0FuaW1hdGlvbikge1xuICAgICAgICAgICAgICAgIGxldCBwID0gMTtcbiAgICAgICAgICAgICAgICBpZiAoaW5kZXggPT0gcykge1xuICAgICAgICAgICAgICAgICAgICBwID0gcHM7XG4gICAgICA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cblxuICAgIHNldCByb2xsTWF4KHYpIHtcbiAgICAgICAgdGhpcy5fcm9sbE1heCA9IHY7XG4gICAgICAgIHRoaXMudXBkYXRlKCk7XG4gICAgfVxuXG4gICAgZ2V0IGludmVydERpcmVjdGlvbigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2ludmVydERpcmVjdGlvbjtcbiAgICB9XG5cbiAgICBzZXQgaW52ZXJ0RGlyZWN0aW9uKHYpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9zdGFydGVkKSB7XG4gICAgICAgICAgICB0aGlzLl9pbnZlcnREaXJlY3Rpb24gPSB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGhvcml6b250YWwoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9ob3Jpem9udGFsO1xuICAgIH1cblxuICAgIHNldCBob3Jpem9udGFsKHYpIHtcbiAgICAgICAgaWYgKHYgIT09IHRoaXMuX2hvcml6b250YWwpIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5fc3RhcnRlZCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2hvcml6b250YWwgPSB2O1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG59XG5cbmltcG9ydCBPYmplY3RMaXN0V3JhcHBlciBmcm9tIFwiLi4vdG9vbHMvT2JqZWN0TGlzdFdyYXBwZXIubWpzXCI7XG5jbGFzcyBMaXN0SXRlbXMgZXh0ZW5kcyBPYmplY3RMaXN0V3JhcHBlciB7XG4gICAgY29uc3RydWN0b3IobGlzdCkge1xuICAgICAgICBsZXQgd3JhcCA9IChpdGVtID0+IHtcbiAgICAgICAgICAgIGxldCBwYXJlbnQgPSBpdGVtLnN0YWdlLmNyZWF0ZUVsZW1lbnQoKTtcbiAgICAgICAgICAgIHBhcmVudC5hZGQoaXRlbSk7XG4gICAgICAgICAgICBwYXJlbnQudmlzaWJsZSA9IGZhbHNlO1xuICAgICAgICAgICAgcmV0dXJuIHBhcmVudDtcbiAg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2lvbnMsXG4gICAgICAgICAgICAgICAgQ29udGVudDoge31cbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBTY2FsZToge3Zpc2libGU6IGZhbHNlfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgY29uc3RydWN0b3Ioc3RhZ2UpIHtcbiAgICAgICAgc3VwZXIoc3RhZ2UpO1xuXG4gICAgICAgIHRoaXMuX3Ntb290aFNjYWxlID0gMTtcbiAgICAgICAgdGhpcy5faXRlcmF0aW9ucyA9IDA7XG4gICAgfVxuXG4gICAgZ2V0IGNvbnRlbnQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnRhZygnQ29udGVudCcpO1xuICAgIH1cblxuICAgIHNldCBjb250ZW50KHYpIHtcbiAgICAgICAgdGhpcy50YWcoJ0NvbnRlbnQnKS5wYXRjaCh2LCB0cnVlKTtcbiAgICB9XG5cbiAgICBnZXQgc21vb3RoU2NhbGUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9zbW9vdGhTY2FsZTtcbiAgICB9XG5cbiAgICBzZXQgc21vb3RoU2NhbGUodikge1xuICAgICAgICBpZiAodGhpcy5fc21vb3RoU2NhbGUgIT09IHYpIHtcbiAgICAgICAgICAgIGxldCBpdHMgPSAwO1xuICAgICAgICAgICAgd2hpbGUodiA8IDAuNSAmJiBpdHMgPCAxMikge1xuICAgICAgICAgICAgICAgIGl0cysrO1xuICAgICAgICAgICAgICAgIHYgPSB2ICogMjtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdGhpcy5zY2FsZSA9IHY7XG4gICAgICAgICAgICB0aGlzLl9zZXRJdGVyYXRpb25zKGl0cyk7XG5cbiAgICAgICAgICAgIHRoaXMuX3Ntb290aFNjYWxlID0gdjtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9zZXRJdGVyYXRpb25zKGl0cykge1xuICAgICAgICBpZiAodGhpcy5faXRlcmF0aW9ucyAhPT0gaXRzKSB7XG4gICAgICAgICAgICBjb25zdCBzY2FsZXJzID0gdGhpcy5zZWwoXCJTY2FsZVwiKS5jaGlsZExpc3Q7XG4gICAgICAgICAgICBjb25zdCBjb250ZW50ID0gdGhpcy5zZWwoXCJDb250ZW50V3JhcFwiKTtcbiAgICAgICAgICAgIHdoaWxlIChzY2FsZXJzLmxlbmd0aCA8IGl0cykge1xuICAgICAgICAgICAgICAgIGNvbnN0IGZpcnN0ID0gc2NhbGVycy5sZW5ndGggPT09IDA7XG4gICAgICAgICAgICAgICAgY29uc3QgdGV4dHVyZSA9IChmaXJzdCA/IGNvbnRlbnQuZ2V0VGV4dHVyZSgpIDogc2NhbGVycy5sYXN0LmdldFRleHR1cmUoKSk7XG4gICAgICAgICAgICAgICAgc2NhbGVycy5hKHtydHQ6IHRydWUsIHJlbmRlck9mZnNjcmVlbjogdHJ1ZSwgdGV4dHVyZTogdGV4dHVyZX0pO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBTbW9vdGhTY2FsZUNvbXBvbmVudC5fdXBkYXRlRGltZW5zaW9ucyh0aGlzLnRhZyhcIkNvbnRlbnRXcmFwXCIpLCB0cnVlKTtcblxuICAgICAgICAgICAgY29uc3QgdXNlU2NhbGVycyA9IChpdHMgPiAwKTtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIENvbnRlbnRXcmFwOiB7cmVuZGVyVG9UZXh0dXJlOiB1c2VTY2FsZXJzfSxcbiAgICAgICAgICAgICAgICBTY2FsZToge3Zpc2libGU6IHVzZVNjYWxlcnN9XG4gICAgICAgICAgICB9KTtcblxuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBzY2FsZXJzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIHNjYWxlcnMuZ2V0QXQoaSkucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICB2aXNpYmxlOiBpIDwgaXRzLFxuICAgICAgICAgICAgICAgICAgICByZW5kZXJPZmZzY3JlZW46IGkgIT09IGl0cyAtIDFcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX2l0ZXJhdGlvbnMgPSBpdHM7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgX3VwZGF0ZURpbWVuc2lvbnMoY29udGVudFdyYXAsIGZvcmNlKSB7XG4gICAgICAgIGNvbnN0IGNvbnRlbnQgPSBjb250ZW50V3JhcC5jaGlsZHJlblswXTtcbiAgICAgICAgbGV0IHcgPSBjb250ZW50LnJlbmRlcldpZHRoO1xuICAgICAgICBsZXQgaCA9IGNvbnRlbnQucmVuZGVySGVpZ2h0O1xuICAgICAgICBpZiAodyAhPT0gY29udGVudFdyYXAudyB8fCBoICE9PSBjb250ZW50V3JhcC5oIHx8IGZvcmNlKSB7XG4gICAgICAgICAgICBjb250ZW50V3JhcC53ID0gdztcbiAgICAgICAgICAgIGNvbnRlbnRXcmFwLmggPSBoO1xuXG4gICAgICAgICAgICBjb25zdCBzY2FsZXJzID0gY29udGVudFdyYXAucGFyZW50LnRhZyhcIlNjYWxlXCIpLmNoaWxkcmVuO1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBzY2FsZXJzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIHcgPSB3ICogMC41O1xuICAgICAgICAgICAgICAgIGggPSBoICogMC41O1xuICAgICAgICAgICAgICAgIHNjYWxlcnNbaV0udyA9IHc7XG4gICAgICAgICAgICAgICAgc2NhbGVyc1tpXS5oID0gaDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBfc2lnbmFsUHJveHkoKSB7XG4gICAgICAgIHJldHVybiB0cnVlO1xuICAgIH1cblxufVxuIiwiLypcbiAqIElmIG5vdCBzdGF0ZWQgb3RoZXJ3aXNlIGluIHRoaXMgZmlsZSBvciB0aGlzIGNvbXBvbmVudCdzIExJQ0VOU0UgZmlsZSB0aG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AgICAgICAgaWYgKHRoaXMuX2FsaWduQ29udGVudCA9PT0gdikgcmV0dXJuO1xuICAgICAgICBpZiAoRmxleENvbnRhaW5lci5BTElHTl9DT05URU5ULmluZGV4T2YodikgPT09IC0xKSB7XG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoXCJVbmtub3duIGFsaWduQ29udGVudCwgb3B0aW9uczogXCIgKyBGbGV4Q29udGFpbmVyLkFMSUdOX0NPTlRFTlQuam9pbihcIixcIikpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX2FsaWduQ29udGVudCA9IHY7XG5cbiAgICAgICAgdGhpcy5fY2hhbmdlZENvbnRlbnRzKCk7XG4gICAgfVxuXG4gICAgZ2V0IGp1c3RpZnlDb250ZW50KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fanVzdGlmeUNvbnRlbnQ7XG4gICAgfVxuXG4gICAgc2V0IGp1c3RpZnlDb250ZW50KHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX2p1c3RpZnlDb250ZW50ID09PSB2KSByZXR1cm47XG5cbiAgICAgICAgaWYgKEZsZXhDb250YWluZXIuSlVTVElGWV9DT05URU5ULmluZGV4T2YodikgPT09IC0xKSB7XG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoXCJVbmtub3duIGp1c3RpZnlDb250ZW50LCBvcHRpb25zOiBcIiArIEZsZXhDb250YWluZXIuSlVTVElGWV9DT05URU5ULmpvaW4oXCIsXCIpKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9qdXN0aWZ5Q29udGVudCA9IHY7XG5cbiAgICAgICAgdGhpcy5fY2hhbmdlZENvbnRlbnRzKCk7XG4gICAgfVxuXG4gICAgc2V0IHBhZGRpbmcodikge1xuICAgICAgICB0aGlzLnBhZGRpbmdMZWZ0ID0gdjtcbiAgICAgICAgdGhpcy5wYWRkaW5nVG9wID0gdjtcbiAgICAgICAgdGhpcy5wYWRkaW5nUmlnaHQgPSB2O1xuICAgICAgICB0aGl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gICAgfVxuXG4gICAgc2V0IHNocmluayh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9zaHJpbmsgPT09IHYpIHJldHVybjtcblxuICAgICAgICB0aGlzLl9zaHJpbmsgPSBwYXJzZUludCh2KSB8fCAwO1xuXG4gICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICB9XG5cbiAgICBnZXQgYWxpZ25TZWxmKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fYWxpZ25TZWxmO1xuICAgIH1cblxuICAgIHNldCBhbGlnblNlbGYodikge1xuICAgICAgICBpZiAodGhpcy5fYWxpZ25TZWxmID09PSB2KSByZXR1cm47XG5cbiAgICAgICAgaWYgKHYgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgdGhpcy5fYWxpZ25TZWxmID0gdW5kZWZpbmVkO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKEZsZXhDb250YWluZXIuQUxJR05fSVRFTVMuaW5kZXhPZih2KSA9PT0gLTEpIHtcbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoXCJVbmtub3duIGFsaWduU2VsZiwgb3B0aW9uczogXCIgKyBGbGV4Q29udGFpbmVyLkFMSUdOX0lURU1TLmpvaW4oXCIsXCIpKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX2FsaWduU2VsZiA9IHY7XG4gICAgICAgIH1cblxuICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgfVxuXG4gICAgZ2V0IG1pbldpZHRoKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbWluV2lkdGg7XG4gICAgfVxuXG4gICAgc2V0IG1pbldpZHRoKHYpIHtcbiAgICAgICAgdGhpcy5fbWluV2lkdGggPSBNYXRoLm1heCgwLCB2KTtcbiAgICAgICAgdGhpcy5faXRlbS5jaGFuZ2VkRGltZW5zaW9ucyh0cnVlLCBmYWxzZSk7XG4gICAgfVxuXG4gICAgZ2V0IG1pbk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gICAgICAgICAgIHJldHVybiB0aGlzLl9taW5XaWR0aDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9taW5IZWlnaHQ7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZ2V0TWF4U2l6ZVNldHRpbmcoaG9yaXpvbnRhbCkge1xuICAgICAgICBpZiAoaG9yaXpvbnRhbCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX21heFdpZHRoO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX21heEhlaWdodDtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9nZXRNYWluQXhpc01pblNpemUoKSB7XG4gICAgICAgIHJldHVybiBGbGV4VXRpbHMuZ2V0QXhpc01pblNpemUodGhpcy5pdGVtLCB0aGlzLmN0ci5faG9yaXpvbnRhbCk7XG4gICAgfVxuXG4gICAgX2dldENyb3NzQXhpc01pblNpemUoKSB7XG4gICAgICAgIHJldHVybiBGbGV4VXRpbHMuZ2V0QXhpc01pblNpemUodGhpcy5pdGVtLCAhdGhpcy5jdHIuX2hvcml6b250YWwpO1xuICAgIH1cblxuICAgIF9nZXRNYWluQXhpc0xheW91dFNpemUoKSB7XG4gICAgICAgIHJldHVybiBGbGV4VXRpbHMuZ2V0QXhpc0xheW91dFNpemUodGhpcy5pdGVtLCB0aGlzLmN0ci5faG9yaXpvbnRhbCk7XG4gICAgfVxuXG4gICAgX2dldE1haW5BeGlzTGF5b3V0UG9zKCkge1xuICAgICAgICByZXR1cm4gRmxleFV0aWxzLmdldEF4aXNMYXlvdXRQb3ModGhpcy5pdGVtLCB0aGlzLmN0ci5faG9yaXpvbnRhbCk7XG4gICAgfVxuXG4gICAgX3NldE1haW5BeGlzTGF5b3V0UG9zKHBvcykge1xuICAgICAgICByZXR1cm4gRmxleFV0aWxzLnNldEF4aXNMYXlvdXRQb3ModGhpcy5pdGVtLCB0aGlzLmN0ci5faG9yaXpv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3RhcmdldDtcbiAgICB9XG5cbiAgICBnZXQgZmxleCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2ZsZXg7XG4gICAgfVxuXG4gICAgc2V0IGZsZXgodikge1xuICAgICAgICBpZiAoIXYpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLmlzRmxleEVuYWJsZWQoKSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2Rpc2FibGVGbGV4KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNGbGV4RW5hYmxlZCgpKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fZW5hYmxlRmxleCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fZmxleC5wYXRjaCh2KTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBmbGV4SXRlbSgpIHtcbiAgICAgICAgaWYgKHRoaXMuX2ZsZXhJdGVtRGlzYWJsZWQpIHtcbiAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9lbnN1cmVGbGV4SXRlbSgpO1xuICAgICAgICByZXR1cm4gdGhpcy5fZmxleEl0ZW07XG4gICAgfVxuXG4gICAgc2V0IGZsZXhJdGVtKHYpIHtcbiAgICAgICAgaWYgKHYgPT09IGZhbHNlKSB7XG4gICAgICAgICAgICBpZiAoIXRoaXMuX2ZsZXhJdGVtRGlzYWJsZWQpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBwYXJlbnQgPSB0aGlzLmZsZXhQYXJlbnQ7XG4gICAgICAgICAgICAgICAgdGhpcy5fZmxleEl0ZW1EaXNhYmxlZCA9IHRydWU7XG4gICAgICAgICAgICAgICAgdGhpcy5fY2hlY2tFbmFibGVkKCk7XG4gICAgICAgICAgICAgICAgaWYgKHBhcmVudCkge1xuICAgICAgICAgICAgICAgICAgICBwYXJlbnQuX2NsZWFyRmxleEl0ZW1zQ2FjaGUoKTtcbiAgICAgICAgICAgICAgICAgICAgcGFyZW50LmNoYW5nZWRDb250ZW50cygpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX2Vuc3VyZUZsZXhJdGVtKCk7XG5cbiAgICAgICAgICAgIHRoaXMuX2ZsZXhJdGVtLnBhdGNoKHYpO1xuXG4gICAgICAgICAgICBpZiAodGhpcy5fZmxleEl0ZW1EaXNhYmxlZCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2ZsZXhJdGVtRGlzYWJsZWQgPSBmYWxzZTtcbiAgICAgICAgICAgICAgICB0aGlzLl9jaGVja0VuYWJsZWQoKTtcbiAgICAgICAgICAgICAgICBjb25zdCBwYXJlbnQgPSB0aGlzLmZsZXhQYXJlbnQ7XG4gICAgICAgICAgICAgICAgaWYgKHBhcmVudCkge1xuICAgICAgICAgICAgICAgICAgICBwYXJlbnQuX2NsZWFyRmxleEl0ZW1zQ2FjaGUoKTtcbiAgICAgICAgICAgICAgICAgICAgcGFyZW50LmNoYW5nZWRDb250ZW50cygpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9lbmFibGVGbGV4KCkge1xuICAgICAgICB0aGlzLl9mbGV4ID0gbmV3IEZsZXhDb250YWluZXIodGhpcyk7XG4gICAgICAgIHRoaXMuX2NoZWNrRW5hYmxlZCgpO1xuICAgICAgICB0aGlzLmNoYW5nZWREaW1lbnNpb25zKCk7XG4gICAgICAgIHRoaXMuX2VuYWJsZUNoaWxkcmVuQXNGbGV4SXRlbXMoKTtcbiAgICB9XG5cbiAgICBfZGlzYWJsZUZsZXgoKSB7XG4gICAgICAgIHRoaXMuY2hhbmdlZERpbWVuc2lvbnMoKTtcbiAgICAgICAgdGhpcy5fZmxleCA9IG51bGw7XG4gICAgICAgIHRoaXMuX2NoZWNrRW5hYmxlZCgp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xleFBhcmVudDtcbiAgICAgICAgaWYgKHBhcmVudCkge1xuICAgICAgICAgICAgcGFyZW50Ll9jaGFuZ2VkQ2hpbGRyZW4oKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBpdGVtcygpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9pdGVtcykge1xuICAgICAgICAgICAgdGhpcy5faXRlbXMgPSB0aGlzLl9nZXRGbGV4SXRlbXMoKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdGhpcy5faXRlbXM7XG4gICAgfVxuXG4gICAgX2dldEZsZXhJdGVtcygpIHtcbiAgICAgICAgY29uc3QgaXRlbXMgPSBbXTtcbiAgICAgICAgY29uc3QgY2hpbGRyZW4gPSB0aGlzLl90YXJnZXQuX2NoaWxkcmVuO1xuICAgICAgICBpZiAoY2hpbGRyZW4pIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgaXRlbSA9IGNoaWxkcmVuW2ldO1xuICAgICAgICAgICAgICAgIGlmIChpdGVtLnZpc2libGUpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGl0ZW0uaXNGbGV4SXRlbSgpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpdGVtcy5wdXNoKGl0ZW0ubGF5b3V0KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gaXRlbXM7XG4gICAgfVxuXG4gICAgX2NoYW5nZWRDaGlsZHJlbigpIHtcbiAgICAgICAgdGhpcy5fY2xlYXJGbGV4SXRlbXNDYWNoZSgpO1xuICAgICAgICB0aGlzLmNoYW5nZWRDb250ZW50cygpO1xuICAgIH1cblxuICAgIF9jbGVhckZsZXhJdGVtc0NhY2hlKCkge1xuICAgICAgICB0aGlzL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gICAgICAgICAgICAgIGlmIChjcm9zc0F4aXNJc0ZpdFRvQ29udGVudHMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFNwZWNpYWwgY2FzZTogZHVlIHRvIHdyYXBwaW5nLCB0aGUgY3Jvc3MgYXhpcyBzaXplIG1heSBiZSBjaGFuZ2VkLlxuICAgICAgICAgICAgICAgICAgICAgICAgY2hpbGRSZWNhbGMgKz0gY3Jvc3NBeGlzUmVjYWxjRmxhZztcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBpc1dpZHRoRHluYW1pYyA9IGxheW91dC5pc0F4aXNGaXRUb0NvbnRlbnRzKHRydWUpO1xuICAgICAgICBsZXQgaXNIZWlnaHREeW5hbWljID0gbGF5b3V0LmlzQXhpc0ZpdFRvQ29udGVudHMoZmFsc2UpO1xuXG4gICAgICAgIGlmIChsYXlvdXQuc2hydW5rKSB7XG4gICAgICAgICAgICAvLyBJZiBkdXJpbmcgcHJldmlvdXMgbGF5b3V0IHRoaXMgY29udGFpbmVyIHdhcyAnc2hydW5rJywgYW55IGNoYW5nZXMgbWF5IGNoYW5nZSB0aGUgJ21pbiBheGlzIHNpemUnIG9mIHRoZVxuICAgICAgICAgICAgLy8gY29udGVudHMsIGxlYWRpbmcgdG8gYSBkaWZmZXJlbnQgYXhpcyBzaXplIG9uIHRoaXMgY29udGFpbmVyIGV2ZW4gd2hlbiBpdCB3YXMgbm90ICdmaXQgdG8gY29udGVudHMnLlxuICAgICAgICAgICAgaWYgKGxheW91dC5faG9yaXpvbnRhbCkge1xuICAgICAgICAgICAgICAgIGlzV2lkdGhEeW5hbWljID0gdHJ1ZTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaXNIZWlnaHREeW5hbWljID0gdHJ1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgI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JlbnQ7XG4gICAgICAgICAgICBpZiAoZmxleFBhcmVudCkge1xuICAgICAgICAgICAgICAgIC8vIFVzZSBwZW5kaW5nIGxheW91dCBzaXplLlxuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLmdldEF4aXNMYXlvdXRTaXplKGZsZXhQYXJlbnQsIGhvcml6b250YWwpICsgdGhpcy5nZXRUb3RhbFBhZGRpbmcoZmxleFBhcmVudCwgaG9yaXpvbnRhbCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIFVzZSAnYWJzb2x1dGUnIHNpemUuXG4gICAgICAgICAgICAgICAgcmV0dXJuIGhvcml6b250YWwgPyBwYXJlbnQudyA6IHBhcmVudC5oO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGdldFJlbEF4aXNTaXplKGl0ZW0sIGhvcml6b250YWwpIHtcbiAgICAgICAgaWYgKGhvcml6b250YWwpIHtcbiAgICAgICAgICAgIGlmIChpdGVtLmZ1bmNXKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2FsbG93UmVsQXhpc1NpemVGdW5jdGlvbihpdGVtLCB0cnVlKSkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaXRlbS5mdW5jVyh0aGlzLmdldFBhcmVudEF4aXNTaXplV2l0aFBhZGRpbmcoaXRlbSwgdHJ1ZSkpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGl0ZW0ub3JpZ2luYWxXaWR0aDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChpdGVtLmZ1bmNIKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2FsbG93UmVsQXhpc1NpemV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iYgIWl0ZW0uZnVuY0g7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgZ2V0QXhpc0xheW91dFBvcyhpdGVtLCBob3Jpem9udGFsKSB7XG4gICAgICAgIHJldHVybiBob3Jpem9udGFsID8gaXRlbS54IDogaXRlbS55O1xuICAgIH1cblxuICAgIHN0YXRpYyBnZXRBeGlzTGF5b3V0U2l6ZShpdGVtLCBob3Jpem9udGFsKSB7XG4gICAgICAgIHJldHVybiBob3Jpem9udGFsID8gaXRlbS53IDogaXRlbS5oO1xuICAgIH1cblxuICAgIHN0YXRpYyBzZXRBeGlzTGF5b3V0UG9zKGl0ZW0sIGhvcml6b250YWwsIHBvcykge1xuICAgICAgICBpZiAoaG9yaXpvbnRhbCkge1xuICAgICAgICAgICAgaXRlbS54ID0gcG9zO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaXRlbS55ID0gcG9zO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIHNldEF4aXNMYXlvdXRTaXplKGl0ZW0sIGhvcml6b250YWwsIHNpemUpIHtcbiAgICAgICAgaWYgKGhvcml6b250YWwpIHtcbiAgICAgICAgICAgIGl0ZW0udyA9IHNpemU7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpdGVtLmggPSBzaXplO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGdldEF4aXNNaW5TaXplKGl0ZW0sIGhvcml6b250YWwpIHtcbiAgICAgICAgbGV0IG1pblNpemUgPSB0aGlzLmdldFBsYWluQXhpc01pblNpemUoaXRlbSwgaG9yaXpvbnRhbCk7XG5cbiAgICAgICAgbGV0IGZsZXhJdGVtTWluU2l6ZSA9IDA7XG4gICAgICAgIGlmIChpdGVtLmlzRmxleEl0ZW1FbmFibGVkKCkpIHtcbiAgICAgICAgICAgIGZsZXhJdGVtTWluU2l6ZSA9IGl0ZW0uX2ZsZXhJdGVtLl9nZXRNaW5TaXplU2V0dGluZyhob3Jpem9udGFsKTtcbiAgICAgICAgfVxuXG4gICAgICAgIGNvbnN0IGhhc0xpbWl0ZWRNaW5TaXplID0gKGZsZXhJdGVtTWluU2l6ZSA+IDApO1xuICAgICAgICBpZiAoaGFzTGltaXRlZE1pblNpemUpIHtcbiAgICAgICAgICAgIG1pblNpemUgPSBNYXRoLm1heChtaW5TaXplLCBmbGV4SXRlbU1pblNpemUpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBtaW5TaXplO1xuICAgIH1cblxuICAgIHN0YXRpYyBnZXRQbGFpbkF4aXNNaW5TaXplKGl0ZW0sIGhvcml6b250YWwpIHtcbiAgICAgICAgaWYgKGl0ZW0uaXNGbGV4RW5hYmxlZCgpKSB7XG4gICAgICAgICAgICByZXR1cm4gaXRlbS5fZmxleC5fbGF5b3V0LmdldEF4aXNNaW5TaXplKGhvcml6b250YWwpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29uc3QgaXNTaHJpbmthYmxlID0gKGl0ZW0uZmxleEl0ZW0uc2hyaW5rICE9PSAwKTtcbiAgICAgICAgICAgIGlmIChpc1Nocmlua2FibGUpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gMDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuZ2V0UmVsQXhpc1NpemUoaXRlbSwgaG9yaXpvbnRhbCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBzdGF0aWMgcmVzaXplQXhpcyhpdGVtLCBob3Jpem9udGFsLCBzaXplKSB7XG4gICAgICAgIGlmIChpdGVtLmlzRmxleEVuYWJsZWQoKSkge1xuICAgICAgICAgICAgY29uc3QgaXNNYWluQXhpcyA9IChpdGVtLl9mbGV4Ll9ob3Jpem9udGFsID09PSBob3Jpem9udGFsKTtcbiAgICAgICAgICAgIGlmIChpc01haW5BeGlzKSB7XG4gICAgICAgICAgICAgICAgaXRlbS5fZmxleC5fbGF5b3V0LnJlc2l6ZU1haW5BeGlzKHNpemUpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBpdGVtLl9mbGV4Ll9sYXlvdXQucmVzaXplQ3Jvc3NBeGlzKHNpemUpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5zZXRBeGlzTGF5b3V0U2l6ZShpdGVtLCBob3Jpem9udGFsLCBzaXplKTtcbiAgICAgICAgfVxuICAgIH1cblxuXG4gICAgc3RhdGljIGdldFBhZGRpbmdPZmZzZXQoaXRlbSwgaG9yaXpvbnRhbCkge1xuICAgICAgICBpZiAoaXRlbS5pc0ZsZXhFbmFibGVkKCkpIHtcbiAgICAgICAgICAgIGNvbnN0IGZsZXggPSBpdGVtLl9mbGV4O1xuICAgICAgICAgICAgaWYgKGhvcml6b250YWwpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmxleC5wYWRkaW5nTGVmdDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZsZXgucGFkZGluZ1RvcDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGdldFRvdGFsUGFkZGluZyhpdGVtLCBob3Jpem9udGFsKSB7XG4gICAgICAgIGlmIChpdGVtLmlzRmxleEVuYWJsZWQoKSkge1xuICAgICAgICAgICAgY29uc3QgZmxleCA9IGl0ZW0uX2ZsZXg7XG4gICAgICAgICAgICBpZiAoaG9yaXpvbnRhbCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBmbGV4LnBhZGRpbmdSaWdodCArIGZsZXgucGFkZGluZ0xlZnQ7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJldHVybiBmbGV4LnBhZGRpbmdUb3AgKyBmbGV4LnBhZGRpbmdCb3R0b207XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gMDtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHN0YXRpYyBnZXRNYXJnaW5PZmZzZXQoaXRlbSwgaG9yaXpvbnRhbCkge1xuICAgICAgICBjb25zdCBmbGV4SXRlbSA9IGl0ZW0uZmxleEl0ZW07XG4gICAgICAgIGlmIChmbGV4SXRlbSkge1xuICAgICAgICAgICAgaWYgKGhvcml6b250YWwpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmxleEl0ZW0ubWFyZ2luTGVmdDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZsZXhJdGVtLm1hcmdpblRvcDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGdldFRvdGFsTWFyZ2luKGl0ZW0sIGhvcml6b250YWwpIHtcbiAgICAgICAgY29uc3QgZmxleEl0ZW0gPSBpdGVtLmZsZXhJdGVtO1xuICAgICAgICBpZiAoZmxleEl0ZW0pIHtcbiAgICAgICAgICAgIGlmIChob3Jpem9udGFsKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZsZXhJdGVtLm1hcmdpblJpZ2h0ICsgZmxleEl0ZW0ubWFyZ2luTGVmdDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZsZXhJdGVtLm1hcmdpblRvcCArIGZsZXhJdGVtLm1hcmdpbkJvdHRvbTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICB9XG4gICAgfVxuXG59XG4iLCIvKlxuICogSWYgbm90IHN0YXRlZCBvdGhlcndpc2UgaW4gdGhpcyBmaWxlIG9yIHRoaXMgY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gICAgIHRoaXMuX3NocnVuayA9IGZhbHNlO1xuICAgIH1cblxuICAgIF9sYXlvdXRBeGVzKCkge1xuICAgICAgICB0aGlzLl9sYXlvdXRNYWluQXhpcygpO1xuICAgICAgICB0aGlzLl9sYXlvdXRDcm9zc0F4aXMoKTtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBAcHJlIG1haW5BeGlzU2l6ZSBzaG91bGQgZXhjbHVkZSBwYWRkaW5nLlxuICAgICAqL1xuICAgIF9sYXlvdXRNYWluQXhpcygpIHtcbiAgICAgICAgdGhpcy5fbGF5b3V0TGluZXMoKTtcbiAgICAgICAgdGhpcy5fZml0TWFpbkF4aXNTaXplVG9Db250ZW50cygpO1xuICAgIH1cblxuICAgIF9sYXlvdXRMaW5lcygpIHtcbiAgICAgICAgdGhpcy5fbGluZUxheW91dGVyLmxheW91dExpbmVzKCk7XG4gICAgfVxuXG4gICAgZ2V0IF9saW5lcygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2xpbmVMYXlvdXRlci5saW5lcztcbiAgICB9XG5cbiAgICBfZml0TWFpbkF4aXNTaXplVG9Db250ZW50cygpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9yZXNpemluZ01haW5BeGlzKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5pc01haW5BeGlzRml0VG9Db250ZW50cygpKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5tYWluQXhpc1NpemUgPSB0aGlzLl9saW5lTGF5b3V0ZXIubWFpbkF4aXNDb250ZW50U2l6ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIC8qKlxuICAgICAqIEBwcmUgY3Jvc3NBeGlzU2l6ZSBzaG91bGQgZXhjbHVkZSBwYWRkaW5nLlxuICAgICAqL1xuICAgIF9sYXlvdXRDcm9zc0F4aXMoKSB7XG4gICAgICAgIGNvbnN0IGFsaWduZXIgPSBuZXcgQ29udGVudEFsaWduZXIodGhpcyk7XG4gICAgICAgIGF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AgICAgcmV0dXJuICF0aGlzLl9oYXNGaXhlZENyb3NzQXhpc0Jhc2lzKCk7XG4gICAgfVxuXG4gICAgX2hhc0ZpeGVkTWFpbkF4aXNCYXNpcygpIHtcbiAgICAgICAgcmV0dXJuICFGbGV4VXRpbHMuaXNaZXJvQXhpc1NpemUodGhpcy5pdGVtLCB0aGlzLl9ob3Jpem9udGFsKTtcbiAgICB9XG5cbiAgICBfaGFzRml4ZWRDcm9zc0F4aXNCYXNpcygpIHtcbiAgICAgICAgcmV0dXJuICFGbGV4VXRpbHMuaXNaZXJvQXhpc1NpemUodGhpcy5pdGVtLCAhdGhpcy5faG9yaXpvbnRhbCk7XG4gICAgfVxuXG4gICAgZ2V0QXhpc01pblNpemUoaG9yaXpvbnRhbCkge1xuICAgICAgICBpZiAodGhpcy5faG9yaXpvbnRhbCA9PT0gaG9yaXpvbnRhbCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2dldE1haW5BeGlzTWluU2l6ZSgpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2dldENyb3NzQXhpc01pblNpemUoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9nZXRNYWluQXhpc01pblNpemUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9saW5lTGF5b3V0ZXIubWFpbkF4aXNNaW5TaXplO1xuICAgIH1cblxuICAgIF9nZXRDcm9zc0F4aXNNaW5TaXplKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbGluZUxheW91dGVyLmNyb3NzQXhpc01pblNpemU7XG4gICAgfVxuXG4gICAgcmVzaXplTWFpbkF4aXMoc2l6ZSkge1xuICAgICAgICBpZiAodGhpcy5tYWluQXhpc1NpemUgIT09IHNpemUpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLnJlY2FsYyA+IDApIHtcbiAgICAgICAgICAgICAgICB0aGlzLnBlcmZvcm1SZXNpemVNYWluQXhpcyhzaXplKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2NoZWNrVmFsaWRDYWNoZU1haW5BeGlzUmVzaXplKCkpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5tYWluQXhpc1NpemUgPSBzaXplO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9maXRDcm9zc0F4aXNTaXplVG9Db250ZW50cygpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIENhY2hlIG1pc3MuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaXRlbS5lbmFibGVMb2NhbFJlY2FsY0ZsYWcoKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5wZXJmb3JtUmVzaXplTWFpbkF4aXMoc2l6ZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2NoZWNrVmFsaWRDYWNoZU1haW5BeGlzUmVzaXplKHNpemUpIHtcbiAgICAgICAgY29uc3QgaXNGaW5hbE1haW5BeGlzU2l6ZSA9IChzaXplID09PSB0aGlzLnRhcmdldE1haW5BeGlzU2l6ZSk7XG4gICAgICAgIGlmIChpc0ZpbmFsTWFpbkF4aXNTaXplKSB7XG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgICBjb25zdCBjYW5JZ25vcmVDYWNoZU1pc3MgPSAhdGhpcy5pc0Nyb3NzQXhpc0ZpdFRvQ29udGVudHMoKTtcbiAgICAgICAgaWYgKGNhbklnbm9yZUNhY2hlTWlzcykge1xuICAgICAgICAgICAgLy8gQWxsb3cgb3RoZXIgbWFpbiBheGlzIHJlc2l6ZXMgYW5kIGNoZWNrIGlmIGZpbmFsIHJlc2l6ZSBtYXRjaGVzIHRoZSB0YXJnZXQgbWFpbiBheGlzIHNpemVcbiAgICAgICAgICAgIC8vICAoSXRlbUNvb3JkaW5hdGVzVXBkYX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aXMuX21haW5BeGlzU2l6ZSk7XG4gICAgICAgICAgICAgICAgaWYgKGlzT3ZlcmZsb3dpbmcpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fbGF5b3V0TGluZShzdGFydEluZGV4LCBpIC0gMSk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2N1ck1haW5BeGlzUG9zID0gMDtcbiAgICAgICAgICAgICAgICAgICAgc3RhcnRJbmRleCA9IGk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLl9hZGRUb01haW5BeGlzUG9zKGl0ZW1NYWluQXhpc1NpemUpO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHN0YXJ0SW5kZXggPCBpKSB7XG4gICAgICAgICAgICB0aGlzLl9sYXlvdXRMaW5lKHN0YXJ0SW5kZXgsIGkgLSAxKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9sYXlvdXRGbGV4SXRlbShpdGVtKSB7XG4gICAgICAgIGlmIChpdGVtLmlzRmxleEVuYWJsZWQoKSkge1xuICAgICAgICAgICAgaXRlbS5mbGV4TGF5b3V0LnVwZGF0ZVRyZWVMYXlvdXQoKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGl0ZW0uZmxleEl0ZW0uX3Jlc2V0TGF5b3V0U2l6ZSgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX3NldHVwKCkge1xuICAgICAgICB0aGlzLl9tYWluQXhpc1NpemUgPSB0aGlzLl9sYXlvdXQubWFpbkF4aXNTaXplO1xuICAgICAgICB0aGlzLl9jdXJNYWluQXhpc1BvcyA9IDA7XG4gICAgICAgIHRoaXMuX21heE1haW5BeGlzUG9zID0gMDtcbiAgICAgICAgdGhpcy5fbGluZXMgPSBbXTtcblxuICAgICAgICB0aGlzLl9tYWluQXhpc01pblNpemUgPSAtMTtcbiAgICAgICAgdGhpcy5fY3Jvc3NBeGlzTWluU2l6ZSA9IC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ZGVyIHRoZSBMaWNlbnNlLlxuICovXG5cbmV4cG9ydCBkZWZhdWx0IGNsYXNzIFNwYWNpbmdDYWxjdWxhdG9yIHtcblxuICAgIHN0YXRpYyBnZXRTcGFjaW5nKG1vZGUsIG51bWJlck9mSXRlbXMsIHJlbWFpbmluZ1NwYWNlKSB7XG4gICAgICAgIGNvbnN0IGl0ZW1HYXBzID0gKG51bWJlck9mSXRlbXMgLSAxKTtcbiAgICAgICAgbGV0IHNwYWNlUGVyR2FwO1xuXG4gICAgICAgIGxldCBzcGFjaW5nQmVmb3JlLCBzcGFjaW5nQmV0d2VlbjtcblxuICAgICAgICBzd2l0Y2gobW9kZSkge1xuICAgICAgICAgICAgY2FzZSBcImZsZXgtc3RhcnRcIjpcbiAgICAgICAgICAgICAgICBzcGFjaW5nQmVmb3JlID0gMDtcbiAgICAgICAgICAgICAgICBzcGFjaW5nQmV0d2VlbiA9IDA7XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICBjYXNlIFwiZmxleC1lbmRcIjpcbiAgICAgICAgICAgICAgICBzcGFjaW5nQmVmb3JlID0gcmVtYWluaW5nU3BhY2U7XG4gICAgICAgICAgICAgICAgc3BhY2luZ0JldHdlZW4gPSAwO1xuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgY2FzZSBcImNlbnRlclwiOlxuICAgICAgICAgICAgICAgIHNwYWNpbmdCZWZvcmUgPSByZW1haW5pbmdTcGFjZSAvIDI7XG4gICAgICAgICAgICAgICAgc3BhY2luZ0JldHdlZW4gPSAwO1xuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgY2FzZSBcInNwYWNlLWJldHdlZW5cIjpcbiAgICAgICAgICAgICAgICBzcGFjaW5nQmVmb3JlID0gMDtcbiAgICAgICAgICAgICAgICBzcGFjaW5nQmV0d2VlbiA9IE1hdGgubWF4KDAsIHJlbWFpbmluZ1NwYWNlKSAvIGl0ZW1HYXBzO1xuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgY2FzZSBcInNwYWNlLWFyb3VuZFwiOlxuICAgICAgICAgICAgICAgIGlmIChyZW1haW5pbmdTcGFjZSA8IDApIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuZ2V0U3BhY2luZyhcImNlbnRlclwiLCBudW1iZXJPZkl0ZW1zLCByZW1haW5pbmdTcGFjZSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgc3BhY2VQZXJHYXAgPSByZW1haW5pbmdTcGFjZSAvIChpdGVtR2FwcyArIDEpO1xuICAgICAgICAgICAgICAgICAgICBzcGFjaW5nQmVmb3JlID0gMC41ICogc3BhY2VQZXJHYXA7XG4gICAgICAgICAgICAgICAgICAgIHNwYWNpbmdCZXR3ZWVuID0gc3BhY2VQZXJHYXA7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgY2FzZSBcInNwYWNlLWV2ZW5seVwiOlxuICAgICAgICAgICAgICAgIGlmIChyZW1haW5pbmdTcGFjZSA8IDApIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuZ2V0U3BhY2luZyhcImNlbnRlclwiLCBudW1iZXJPZkl0ZW1zLCByZW1haW5pbmdTcGFjZSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgc3BhY2VQZXJHYXAgPSByZW1haW5pbmdTcGFjZSAvIChpdGVtR2FwcyArIDIpO1xuICAgICAgICAgICAgICAgICAgICBzcGFjaW5nQmVmb3JlID0gc3BhY2VQZXJHYXA7XG4gICAgICAgICAgICAgICAgICAgIHNwYWNpbmdCZXR3ZWVuID0gc3BhY2VQZXJHYXA7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgY2FzZSBcInN0cmV0Y2hcIjpcbiAgICAgIC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nbmVyKCkge1xuICAgICAgICByZXR1cm4gbmV3IEl0ZW1BbGlnbmVyKHRoaXMpO1xuICAgIH1cblxuICAgIF9jYWxjTGF5b3V0SW5mbygpIHtcbiAgICAgICAgdGhpcy5fY2FsY0Nyb3NzQXhpc01heExheW91dFNpemUoKTtcbiAgICB9XG5cbiAgICBnZXRNYWluQXhpc01pblNpemUoKSB7XG4gICAgICAgIGxldCBtYWluQXhpc01pblNpemUgPSAwO1xuICAgICAgICBmb3IgKGxldCBpID0gdGhpcy5zdGFydEluZGV4OyBpIDw9IHRoaXMuZW5kSW5kZXg7IGkrKykge1xuICAgICAgICAgICAgY29uc3QgaXRlbSA9IHRoaXMuaXRlbXNbaV07XG4gICAgICAgICAgICBtYWluQXhpc01pblNpemUgKz0gaXRlbS5mbGV4SXRlbS5fZ2V0TWFpbkF4aXNNaW5TaXplV2l0aFBhZGRpbmdBbmRNYXJnaW4oKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gbWFpbkF4aXNNaW5TaXplO1xuICAgIH1cbiAgICBcbiAgICBnZXQgbnVtYmVyT2ZJdGVtcygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuZW5kSW5kZXggLSB0aGlzLnN0YXJ0SW5kZXggKyAxO1xuICAgIH1cblxuICAgIGdldCBjcm9zc0F4aXNMYXlvdXRTaXplKCkge1xuICAgICAgICBjb25zdCBub1NwZWNpZmllZENyb3NzQXhpc1NpemUgPSAodGhpcy5fbGF5b3V0LmlzQ3Jvc3NBeGlzRml0VG9Db250ZW50cygpICYmICF0aGlzLl9sYXlvdXQucmVzaXppbmdDcm9zc0F4aXMpO1xuICAgICAgICBjb25zdCBzaG91bGRGaXRUb0NvbnRlbnRzID0gKHRoaXMuX2xheW91dC5pc1dyYXBwaW5nKCkgfHwgbm9TcGVjaWZpZWRDcm9zc0F4aXNTaXplKTtcbiAgICAgICAgaWYgKHNob3VsZEZpdFRvQ29udGVudHMpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGl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RvdGFsR3Jvd0Ftb3VudCgpO1xuICAgICAgICBpZiAodG90YWxHcm93QW1vdW50KSB7XG4gICAgICAgICAgICBjb25zdCBpdGVtcyA9IHRoaXMuX2xpbmUuaXRlbXM7XG4gICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgbGV0IGFtb3VudFBlckdyb3cgPSB0aGlzLl9hbW91bnRSZW1haW5pbmcgLyB0b3RhbEdyb3dBbW91bnQ7XG4gICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IHRoaXMuX2xpbmUuc3RhcnRJbmRleDsgaSA8PSB0aGlzLl9saW5lLmVuZEluZGV4OyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgaXRlbSA9IGl0ZW1zW2ldO1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBmbGV4SXRlbSA9IGl0ZW0uZmxleEl0ZW07XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGdyb3dBbW91bnQgPSBmbGV4SXRlbS5ncm93O1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBpc0dyb3dhYmxlSXRlbSA9IChncm93QW1vdW50ID4gMCk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChpc0dyb3dhYmxlSXRlbSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGdyb3cgPSBncm93QW1vdW50ICogYW1vdW50UGVyR3JvdztcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IG1heFNpemUgPSBmbGV4SXRlbS5fZ2V0TWFpbkF4aXNNYXhTaXplU2V0dGluZygpO1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc0xheW91dFNpemUoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChtYXhTaXplID4gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzaXplID49IG1heFNpemUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gQWxyZWFkeSBmdWxseSBncm93bi5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdyA9IDA7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgbWF4R3JvdyA9IG1heFNpemUgLSBzaXplO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBpc0Z1bGx5R3Jvd24gPSAoZ3JvdyA+PSBtYXhHcm93KTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzRnVsbHlHcm93bikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdyA9IG1heEdyb3c7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIERlc3RyaWJ1dGUgcmVtYWluaW5nIGFtb3VudCBvdmVyIHRoZSBvdGhlciBmbGV4IGl0ZW1zLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdG90YWxHcm93QW1vdW50IC09IGdyb3dBbW91bnQ7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChncm93ID4gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGZpbmFsU2l6ZSA9IHNpemUgKyBncm93O1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZsZXhJdGVtLl9yZXNpemVNYWluQXhpcyhmaW5hbFNpemUpO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fZ3Jvd25TaXplICs9IGdyb3c7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fYW1vdW50UmVtYWluaW5nIC09IGdyb3c7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoTWF0aC5hYnModGhpcy5fYW1vdW50UmVtYWluaW5nKSA8IDEwZS02KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IHdoaWxlKHRvdGFsR3Jvd0Ftb3VudCAmJiAoTWF0aC5hYnModGhpcy5fYW1vdW50UmVtYWluaW5nKSA+IDEwZS02KSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZ2V0VG90YWxHcm93QW1vdW50KCkge1xuICAgICAgICBsZXQgdG90YWwgPSAwO1xuICAgICAgICBjb25zdCBpdGVtcyA9IHRoaXMuX2xpbmUuaXRlbXM7XG4gICAgICAgIGZvciAobGV0IGkgPSB0aGlzLl9saW5lLnN0YXJ0SW5kZXg7IGkgPD0gdGhpcy5fbGluZS5lbmRJbmRleDsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCBpdGVtID0gaXRlbXNbaV07XG4gICAgICAgICAgICBjb25zdCBmbGV4SXRlbSA9IGl0ZW0uZmxleEl0ZW07XG5cbiAgICAgICAgICAgIGlmIChmbGV4SXRlbS5ncm93KSB7XG4gICAgICAgICAgICAgICAgY29uc3QgbWF4U2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc01heFNpemVTZXR0aW5nKCk7XG4gICAgICAgICAgICAgICAgY29uc3Qgc2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc0xheW91dFNpemUoKTtcblxuICAgICAgICAgICAgICAgIC8vIEV4Y2x1ZGUgdGhvc2UgYWxyZWFkeSBmdWxseSBncm93bi5cbiAgICAgICAgICAgICAgICBpZiAobWF4U2l6ZSA9PT0gMCB8fCBzaXplIDwgbWF4U2l6ZSkge1xuICAgICAgICAgICAgICAgICAgIC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luaztcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgaXNTaHJpbmthYmxlSXRlbSA9IChzaHJpbmtBbW91bnQgPiAwKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlzU2hyaW5rYWJsZUl0ZW0pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBzaHJpbmsgPSBzaHJpbmtBbW91bnQgKiBhbW91bnRQZXJTaHJpbms7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBtaW5TaXplID0gZmxleEl0ZW0uX2dldE1haW5BeGlzTWluU2l6ZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc0xheW91dFNpemUoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzaXplID4gbWluU2l6ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IG1heFNocmluayA9IHNpemUgLSBtaW5TaXplO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGlzRnVsbHlTaHJ1bmsgPSAoc2hyaW5rID49IG1heFNocmluayk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzRnVsbHlTaHJ1bmspIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hyaW5rID0gbWF4U2hyaW5rO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIERlc3RyaWJ1dGUgcmVtYWluaW5nIGFtb3VudCBvdmVyIHRoZSBvdGhlciBmbGV4IGl0ZW1zLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0b3RhbFNocmlua0Ftb3VudCAtPSBzaHJpbmtBbW91bnQ7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgZmluYWxTaXplID0gc2l6ZSAtIHNocmluaztcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmbGV4SXRlbS5fcmVzaXplTWFpbkF4aXMoZmluYWxTaXplKTtcblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3NocnVua1NpemUgKz0gc2hyaW5rO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2Ftb3VudFJlbWFpbmluZyAtPSBzaHJpbms7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoTWF0aC5hYnModGhpcy5fYW1vdW50UmVtYWluaW5nKSA8IDEwZS02KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IHdoaWxlKHRvdGFsU2hyaW5rQW1vdW50ICYmIChNYXRoLmFicyh0aGlzLl9hbW91bnRSZW1haW5pbmcpID4gMTBlLTYpKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9nZXRUb3RhbFNocmlua0Ftb3VudCgpIHtcbiAgICAgICAgbGV0IHRvdGFsID0gMDtcbiAgICAgICAgY29uc3QgaXRlbXMgPSB0aGlzLl9saW5lLml0ZW1zO1xuICAgICAgICBmb3IgKGxldCBpID0gdGhpcy5fbGluZS5zdGFydEluZGV4OyBpIDw9IHRoaXMuX2xpbmUuZW5kSW5kZXg7IGkrKykge1xuICAgICAgICAgICAgY29uc3QgaXRlbSA9IGl0ZW1zW2ldO1xuICAgICAgICAgICAgY29uc3QgZmxleEl0ZW0gPSBpdGVtLmZsZXhJdGVtO1xuXG4gICAgICAgICAgICBpZiAoZmxleEl0ZW0uc2hyaW5rKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgbWluU2l6ZSA9IGZsZXhJdGVtLl9nZXRNYWluQXhpc01pblNpemUoKTtcbiAgICAgICAgICAgICAgICBjb25zdCBzaXplID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uICAgICAgICAgICAgICAgICAgICBpZiAoZS5kYXRhLnR5cGUgPT0gJ2RhdGEnKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmZpbmlzaChpdGVtLCBlLmRhdGEuaW5mbyk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVycm9yKGl0ZW0sIGUuZGF0YS5pbmZvKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGNyZWF0ZShzcmMpIHtcbiAgICAgICAgY29uc3QgaWQgPSArK3RoaXMuX2lkO1xuICAgICAgICBjb25zdCBpdGVtID0gbmV3IEltYWdlV29ya2VySW1hZ2UodGhpcywgaWQsIHNyYyk7XG4gICAgICAgIHRoaXMuX2l0ZW1zLnNldChpZCwgaXRlbSk7XG4gICAgICAgIHRoaXMuX3dvcmtlci5wb3N0TWVzc2FnZSh7dHlwZTogXCJhZGRcIiwgaWQ6IGlkLCBzcmM6IHNyY30pO1xuICAgICAgICByZXR1cm4gaXRlbTtcbiAgICB9XG5cbiAgICBjYW5jZWwoaW1hZ2UpIHtcbiAgICAgICAgdGhpcy5fd29ya2VyLnBvc3RNZXNzYWdlKHt0eXBlOiBcImNhbmNlbFwiLCBpZDogaW1hZ2UuaWR9KTtcbiAgICAgICAgdGhpcy5faXRlbXMuZGVsZXRlKGltYWdlLmlkKTtcbiAgICB9XG5cbiAgICBlcnJvcihpbWFnZSwgaW5mbykge1xuICAgICAgICBpbWFnZS5lcnJvcihpbmZvKTtcbiAgICAgICAgdGhpcy5faXRlbXMuZGVsZXRlKGltYWdlLmlkKTtcbiAgICB9XG5cbiAgICBmaW5pc2goaW1hZ2UsIGluZm8pIHtcbiAgICAgICAgaW1hZ2UubG9hZChpbmZvKTtcbiAgICAgICAgdGhpcy5faXRlbXMuZGVsZXRlKGltYWdlLml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XCJ9KTtcbiAgICAgICAgfTtcblxuICAgICAgICB0aGlzLl94aHIub25sb2FkID0gZnVuY3Rpb24ob0V2ZW50KSB7XG4gICAgICAgICAgICB2YXIgYmxvYiA9IHQuX3hoci5yZXNwb25zZTtcbiAgICAgICAgICAgIHQuX21pbWVUeXBlID0gYmxvYi50eXBlO1xuXG4gICAgICAgICAgICB0Ll9jcmVhdGVJbWFnZUJpdG1hcChibG9iKTtcbiAgICAgICAgfTtcblxuICAgICAgICB0aGlzLl94aHIuc2VuZCgpO1xuICAgIH07XG5cbiAgICBJbWFnZVdvcmtlclNlcnZlckl0ZW0ucHJvdG90eXBlLl9jcmVhdGVJbWFnZUJpdG1hcCA9IGZ1bmN0aW9uKGJsb2IpIHtcbiAgICAgICAgdmFyIHQgPSB0aGlzO1xuICAgICAgICBjcmVhdGVJbWFnZUJpdG1hcChibG9iLCB7cHJlbXVsdGlwbHlBbHBoYTogJ3ByZW11bHRpcGx5JywgY29sb3JTcGFjZUNvbnZlcnNpb246ICdub25lJywgaW1hZ2VPcmllbnRhdGlvbjogJ25vbmUnfSkudGhlbihmdW5jdGlvbihpbWFnZUJpdG1hcCkge1xuICAgICAgICAgICAgdC5maW5pc2goe1xuICAgICAgICAgICAgICAgIGltYWdlQml0bWFwLFxuICAgICAgICAgICAgICAgIGhhc0FscGhhQ2hhbm5lbDogdC5faGFzQWxwaGFDaGFubmVsKClcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KS5jYXRjaChmdW5jdGlvbihlKSB7XG4gICAgICAgICAgICB0LmVycm9yKHt0eXBlOiBcInBhcnNlXCIsIG1lc3NhZ2U6IFwiRXJyb3IgcGFyc2luZyBpbWFnZSBkYXRhXCJ9KTtcbiAgICAgICAgfSk7XG4gICAgfTtcblxuICAgIEltYWdlV29ya2VyU2VydmVySXRlbS5wcm90b3R5cGUuX2hhc0FscGhhQ2hhbm5lbCA9IGZ1bmN0aW9uKCkge1xuICAgICAgICBpZiAoSW1hZ2VXb3JrZXJT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biAgICAgICAgZGVsZXRlIHRoaXMuc3RhZ2U7XG4gICAgfVxuXG4gICAgc3RhcnRMb29wKCkge1xuICAgICAgICB0aGlzLl9sb29waW5nID0gdHJ1ZTtcbiAgICAgICAgaWYgKCF0aGlzLl9hd2FpdGluZ0xvb3ApIHtcbiAgICAgICAgICAgIHRoaXMubG9vcCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RvcExvb3AoKSB7XG4gICAgICAgIHRoaXMuX2xvb3BpbmcgPSBmYWxzZTtcbiAgICB9XG5cbiAgICBzd2l0Y2hMb29wKCkge1xuICAgICAgICBpZiAodGhpcy5fb25JZGxlID09PSBmYWxzZSkge1xuICAgICAgICAgICAgdGhpcy5fb25JZGxlID0gdHJ1ZTtcbiAgICAgICAgICAgIHRoaXMuc3RhZ2Uub25JZGxlKCk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5faWRsZUxvb3BDb3VudGVyIDwgdGhpcy5faWRsZUxvb3BEZWxheSkge1xuICAgICAgICAgICAgdGhpcy5faWRsZUxvb3BDb3VudGVyKys7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLnN0YWdlLmN0eC5oYXNSZW5kZXJVcGRhdGVzKCkpIHtcbiAgICAgICAgICAgIHRoaXMuc3RvcExvb3AoKTtcbiAgICAgICAgICAgIHRoaXMuX2xvb3BIYW5kbGVyID0gc2V0SW50ZXJ2YWwoKCkgPT4ge1xuICAgICAgICAgICAgICAgIHRoaXMuc3RhZ2UudXBkYXRlRnJhbWUoKTtcbiAgICAgICAgICAgICAgICB0aGlzLnN0YWdlLmlkbGVGcmFtZSgpO1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLnN0YWdlLmN0eC5oYXNSZW5kZXJVcGRhdGVzKCkpIHtcbiAgICAgICAgICAgICAgICAgICAgY2xlYXJJbnRlcnZhbCh0aGlzLl9sb29wSGFuZGxlcik7XG4gICAgICAgICAgICAgICAgICA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0bGVFbmRpYW4pLFxuICAgICAgICAgICAgICAgIG51bWJlck9mRmFjZXM6IHZpZXcuZ2V0VWludDMyKDUyLCBsaXR0bGVFbmRpYW4pLFxuICAgICAgICAgICAgICAgIG51bWJlck9mTWlwbWFwTGV2ZWxzOiB2aWV3LmdldFVpbnQzMig1NiwgbGl0dGxlRW5kaWFuKSxcbiAgICAgICAgICAgICAgICBieXRlc09mS2V5VmFsdWVEYXRhOiB2aWV3LmdldFVpbnQzMig2MCwgbGl0dGxlRW5kaWFuKSxcbiAgICAgICAgICAgICAgICBrdnBzOiBbXSxcbiAgICAgICAgICAgICAgICBtaXBtYXBzOiBbXSxcbiAgICAgICAgICAgICAgICBnZXQgd2lkdGgoKSB7IHJldHVybiB0aGlzLnBpeGVsV2lkdGggfSxcbiAgICAgICAgICAgICAgICBnZXQgaGVpZ2h0KCkgeyByZXR1cm4gdGhpcy5waXhlbEhlaWdodCB9LFxuICAgICAgICAgICAgfTtcblxuICAgICAgICAgICAgY29uc3QgcHJvcHMgPSAob2JqKSA9PiB7XG4gICAgICAgICAgICAgICAgY29uc3QgcCA9IFtdO1xuICAgICAgICAgICAgICAgIGZvciAobGV0IHYgaW4gb2JqKSB7XG4gICAgICAgICAgICAgICAgICAgIHAucHVzaChvYmpbdl0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4gcDtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgY29uc3QgZm9ybWF0cyA9IE9iamVjdC52YWx1ZXMoc2VsZi5zdGFnZS5yZW5kZXJlci5nZXRDb21wcmVzc2VkVGV4dHVyZUV4dGVuc2lvbnMoKSlcbiAgICAgICAgICAgICAgICAuZmlsdGVyKChvYmopID0+IG9iaiAhPSBudWxsKVxuICAgICAgICAgICAgICAgIC5tYXAoKG9iaikgPT4gcHJvcHMob2JqKSlcbiAgICAgICAgICAgICAgICAucmVkdWNlKChwcmV2LCBjdXJyZW50KSA9PiBwcmV2LmNvbmNhdChjd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gICAgcmVuZGVySW5mbzogeyBzcmM6IHNyYywgY29tcHJlc3NlZDogdHJ1ZSB9LFxuICAgICAgICAgICAgfSlcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGhhbmRsZVB2ckxvYWQoY2IsIHNyYykge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgLy8gcHZyIGhlYWRlciBsZW5ndGggaW4gMzIgYml0c1xuICAgICAgICAgICAgY29uc3QgcHZySGVhZGVyTGVuZ3RoID0gMTM7XG4gICAgICAgICAgICAvLyBmb3Igbm93IG9ubHkgd2Ugb25seSBzdXBwb3J0OiBDT01QUkVTU0VEX1JHQl9FVEMxX1dFQkdMXG4gICAgICAgICAgICBjb25zdCBwdnJGb3JtYXRFdGMxID0gMHg4RDY0O1xuICAgICAgICAgICAgY29uc3QgcHZyV2lkdGggPSA3O1xuICAgICAgICAgICAgY29uc3QgcHZySGVpZ2h0ID0gNjtcbiAgICAgICAgICAgIGNvbnN0IHB2ck1pcG1hcENvdW50ID0gMTE7XG4gICAgICAgICAgICBjb25zdCBwdnJNZXRhZGF0YSA9IDEyO1xuICAgICAgICAgICAgY29uc3QgYXJyYXlCdWZmZXIgPSB0aGlzLnJlc3BvbnNlO1xuICAgICAgICAgICAgY29uc3QgaGVhZGVyID0gbmV3IEludDMyQXJyYXkoYXJyYXlCdWZmZXIsIDAsIHB2ckhlYWRlckxlbmd0aCk7XG4gICAgICAgICAgICBjb25zdCBkYXRhT2Zmc2V0ID0gaGVhZGVyW3B2ck1ldGFkYXRhXSArIDUyO1xuICAgICAgICAgICAgY29uc3QgcHZydGNEYXRhID0gbmV3IFVpbnQ4QXJyYXkoYXJyYXlCdWZmZXIsIGRhdGFPZmZzZXQpO1xuXG4gICAgICAgICAgICB2YXIgZGF0YSA9IHtcbiAgICAgICAgICAgICAgICBnbEludGVybmFsRm9ybWF0OiBwdnJGb3JtYXRFdGMxLFxuICAgICAgICAgICAgICAgIHBpeGVsV2lkdGg6IGhlYWRlcltwdnJXaWR0aF0sXG4gICAgICAgICAgICAgICAgcGl4ZWxIZWlnaHQ6IGhlYWRlcltwdnJIZWlnaHRdLFxuICAgICAgICAgICAgICAgIG51bWJlck9mTWlwbWFwTGV2ZWxzOiBoZWFkZXJbcHZyTWlwbWFwQ291bnRdLFxuICAgICAgICAgICAgICAgIG1pcG1hcHM6IFtdLFxuICAgICAgICAgICAgICAgIHB2cjogdHJ1ZSxcbiAgICAgICAgICAgICAgICBnZXQgd2lkdGgoKSB7IHJldHVybiB0aGlzLnBpeGVsV2lkdGggfSxcbiAgICAgICAgICAgICAgICBnZXQgaGVpZ2h0KCkgeyByZXR1cm4gdGhpcy5waXhlbEhlaWdodCB9LFxuICAgICAgICAgICAgfTtcblxuICAgICAgICAgICAgbGV0IG9mZnNldCA9IDBcbiAgICAgICAgICAgIGxldCB3aWR0aCA9IGRhdGEucGl4ZWxXaWR0aDtcbiAgICAgICAgICAgIGxldCBoZWlnaHQgPSBkYXRhLnBpeGVsSGVpZ2h0O1xuXG4gICAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGRhdGEubnVtYmVyT2ZNaXBtYXBMZXZlbHM7IGkrKykge1xuICAgICAgICAgICAgICAgIGNvbnN0IGxldmVsID0gKCh3aWR0aCArIDMpID4+IDIpICogKChoZWlnaHQgKyAzKSA+PiAyKSAqIDg7XG4gICAgICAgICAgICAgICAgY29uc3QgdmlldyA9IG5ldyBVaW50OEFycmF5KGFycmF5QnVmZmVyLCBwdnJ0Y0RhdGEuYnl0ZU9mZnNldCArIG9mZnNldCwgbGV2ZWwpO1xuICAgICAgICAgICAgICAgIGRhdGEubWlwbWFwcy5wdXNoKHZpZXcpO1xuICAgICAgICAgICAgICAgIG9mZnNldCArPSBsZXZlbDtcbiAgICAgICAgICAgICAgICB3aWR0aCA9IHdpZHRoID4+IDE7XG4gICAgICAgICAgICAgICAgaGVpZ2h0ID0gaGVpZ2h0ID4+IDE7XG4gICAgICAgICAgICB9XG5c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ICAgICAgICByZXF1ZXN0LmFib3J0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5faW1hZ2VXb3JrZXIpIHtcbiAgICAgICAgICAgIC8vIFdQRS1zcGVjaWZpYyBpbWFnZSBwYXJzZXIuXG4gICAgICAgICAgICBjb25zdCBpbWFnZSA9IHRoaXMuX2ltYWdlV29ya2VyLmNyZWF0ZShzcmMpO1xuICAgICAgICAgICAgaW1hZ2Uub25FcnJvciA9IGZ1bmN0aW9uIChlcnIpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gY2IoXCJJbWFnZSBsb2FkIGVycm9yXCIpO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGltYWdlLm9uTG9hZCA9IGZ1bmN0aW9uICh7IGltYWdlQml0bWFwLCBoYXNBbHBoYUNoYW5uZWwgfSkge1xuICAgICAgICAgICAgICAgIGNiKG51bGwsIHtcbiAgICAgICAgICAgICAgICAgICAgc291cmNlOiBpbWFnZUJpdG1hcCxcbiAgICAgICAgICAgICAgICAgICAgcmVuZGVySW5mbzogeyBzcmM6IHNyYywgY29tcHJlc3NlZDogZmFsc2UgfSxcbiAgICAgICAgICAgICAgICAgICAgaGFzQWxwaGE6IGhhc0FscGhhQ2hhbm5lbCxcbiAgICAgICAgICAgICAgICAgICAgcHJlbXVsdGlwbHlBbHBoYTogdHJ1ZVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGNhbmNlbENiID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIGltYWdlLmNhbmNlbCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbGV0IGltYWdlID0gbmV3IEltYWdlKCk7XG5cbiAgICAgICAgICAgIC8vIE9uIHRoZSBQUzQgcGxhdGZvcm0gc2V0dGluZyB0aGUgYGNyb3NzT3JpZ2luYCBhdHRyaWJ1dGUgb25cbiAgICAgICAgICAgIC8vIGltYWdlcyBjYW4gY2F1c2UgQ09SUyBmYWlsdXJlcy5cbiAgICAgICAgICAgIGlmICghKHNyYy5zdWJzdHIoMCwgNSkgPT0gXCJkYXRhOlwiKSAmJiAhVXRpbHMuaXNQUzQpIHtcbiAgICAgICAgICAgICAgICAvLyBCYXNlNjQuXG4gICAgICAgICAgICAgICAgaW1hZ2UuY3Jvc3NPcmlnaW4gPSBcIkFub255bW91c1wiO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaW1hZ2Uub25lcnJvciA9IGZ1bmN0aW9uIChlcnIpIHtcbiAgICAgICAgICAgICAgICAvLyBJZ25vcmUgZXJyb3IgbWVzc2FnZSB3aGVuIGNhbmNlbGxlZC5cbiAgICAgICAgICAgICAgICBpZiAoaW1hZ2Uuc3JjKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjYihcIkltYWdlIGxvYWQgZXJyb3JcIik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGltYWdlLm9ubG9hZCA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICBjYihudWxsLCB7XG4gICAgICAgICAgICAgICAgICAgIHNvdXJjZTogaW1hZ2UsXG4gICAgICAgICAgICAgICAgICAgIHJlbmRlckluZm86IHsgc3JjOiBzcmMsIGNvbXByZXNzZWQ6IGZhbHNlIH0sXG4gICAgICAgICAgICAgICAgICAgIGhhc0FscGhhOiBpc1BuZyB8fCBoYXNBbHBoYVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGltYWdlLnNyYyA9IHNyYztcblxuICAgICAgICAgICAgY2FuY2VsQ2IgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgaW1hZ2Uub25lcnJvciA9IG51bGw7XG4gICAgICAgICAgICAgICAgaW1hZ2Uub25sb2FkID0gbnVsbDtcbiAgICAgICAgICAgICAgICBpbWFnZS5yZ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gICAgICAvLyBXZSBjYW4ndCByZXNldCBjbGlwcGluZyBhbG9uZSBzbyB3ZSBuZWVkIHRvIHJlc3RvcmUgdGhlIGZ1bGwgY29udGV4dC5cbiAgICAgICAgICAgIHRoaXMuX3Jlc3RvcmVDb250ZXh0KCk7XG5cbiAgICAgICAgICAgIGxldCBwcmVjaXNpb24gPSB0aGlzLmN0eC5zdGFnZS5nZXRSZW5kZXJQcmVjaXNpb24oKTtcbiAgICAgICAgICAgIGlmIChhcmVhKSB7XG4gICAgICAgICAgICAgICAgY3R4LmJlZ2luUGF0aCgpO1xuICAgICAgICAgICAgICAgIGN0eC5yZWN0KE1hdGgucm91bmQoYXJlYVswXSAqIHByZWNpc2lvbiksIE1hdGgucm91bmQoYXJlYVsxXSAqIHByZWNpc2lvbiksIE1hdGgucm91bmQoYXJlYVsyXSAqIHByZWNpc2lvbiksIE1hdGgucm91bmQoYXJlYVszXSAqIHByZWNpc2lvbikpO1xuICAgICAgICAgICAgICAgIGN0eC5jbG9zZVBhdGgoKTtcbiAgICAgICAgICAgICAgICBjdHguY2xpcCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY3R4Ll9zY2lzc29yID0gYXJlYTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHN0YXRpYyBfZXF1YWxTY2lzc29yQXJlYXMoY2FudmFzLCBhcmVhLCBjdXJyZW50KSB7XG4gICAgICAgIGlmICghYXJlYSkge1xuICAgICAgICAgICAgYXJlYSA9IFswLCAwLCBjYW52YXMud2lkdGgsIGNhbnZhcy5oZWlnaHRdXG4gICAgICAgIH1cbiAgICAgICAgaWYgKCFjdXJyZW50KSB7XG4gICAgICAgICAgICBjdXJyZW50ID0gWzAsIDAsIGNhbnZhcy53aWR0aCwgY2FudmFzLmhlaWdodF1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gVXRpbHMuZXF1YWxWYWx1ZXMoYXJlYSwgY3VycmVudClcbiAgICB9XG5cbn1cbiIsIi8qXG4gKiBJZiB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NoZS5tZW1vcnlVc2FnZTtcblxuICAgICAgICAgICAgLy8gRmluZCBibGFuY28gdGludCB0ZXh0dXJlLlxuICAgICAgICAgICAgbGV0IHRhcmdldCA9IGNhY2hlLnJldXNlVGV4dHVyZShmcmFtZSk7XG4gICAgICAgICAgICBpZiAodGFyZ2V0KSB7XG4gICAgICAgICAgICAgICAgdGFyZ2V0LmN0eC5jbGVhclJlY3QoMCwgMCwgdGFyZ2V0LndpZHRoLCB0YXJnZXQuaGVpZ2h0KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gQWxsb2NhdGUgbmV3LlxuICAgICAgICAgICAgICAgIHRhcmdldCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ2NhbnZhcycpO1xuICAgICAgICAgICAgICAgIHRhcmdldC53aWR0aCA9IG5hdGl2ZVRleHR1cmUudztcbiAgICAgICAgICAgICAgICB0YXJnZXQuaGVpZ2h0ID0gbmF0aXZlVGV4dHVyZS5oO1xuICAgICAgICAgICAgICAgIHRhcmdldC5jdHggPSB0YXJnZXQuZ2V0Q29udGV4dCgnMmQnKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdGhpcy5fdGludFRleHR1cmUodGFyZ2V0LCBuYXRpdmVUZXh0dXJlLCBjb2xvcik7XG4gICAgICAgICAgICBjYWNoZS5zZXQoY29sb3IsIHRhcmdldCwgZnJhbWUpO1xuXG4gICAgICAgICAgICBjb25zdCBhZnRlciA9IGNhY2hlLm1lbW9yeVVzYWdlO1xuXG4gICAgICAgICAgICBpZiAoYWZ0ZXIgIT09IGJlZm9yZSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2FkZE1lbW9yeVVzYWdlKGFmdGVyIC0gYmVmb3JlKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgcmV0dXJuIHRhcmdldDtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF90aW50VGV4dHVyZSh0YXJnZXQsIHNvdXJjZ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sIGl0ZW0pO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBpdGVtO1xuICAgIH1cblxuICAgIHNldChjb2xvciwgdGV4dHVyZSwgZnJhbWUpIHtcbiAgICAgICAgY29uc3QgaXRlbSA9IHRoaXMuZ2V0KGNvbG9yKTtcbiAgICAgICAgaXRlbS5sZiA9IGZyYW1lO1xuICAgICAgICBpdGVtLnR4ID0gdGV4dHVyZTtcbiAgICAgICAgaXRlbS51ID0gZnJhbWU7XG4gICAgICAgIHRoaXMuX21lbVRleHR1cmVzKys7XG4gICAgfVxuXG4gICAgY2xlYW51cChmcmFtZSkge1xuICAgICAgICAvLyBXZSBvbmx5IG5lZWQgdG8gY2xlYW4gdXAgb25jZSBwZXIgZnJhbWUuXG4gICAgICAgIGlmICh0aGlzLl9sYXN0Q2xlYW51cEZyYW1lICE9PSBmcmFtZSkge1xuXG4gICAgICAgICAgICAvLyBXZSBsaW1pdCBibGFuY28gdGV4dHVyZXMgcmV1c2UgdG8gb25lIGZyYW1lIG9ubHkgdG8gcHJldmVudCBtZW1vcnkgdXNhZ2UgZ3Jvd3RoLlxuICAgICAgICAgICAgdGhpcy5fYmxhbmNvVGV4dHVyZXMgPSBbXTtcblxuICAgICAgICAgICAgdGhpcy5fY29sb3JzLmZvckVhY2goKGl0ZW0sIGNvbG9yKSA9PiB7XG4gICAgICAgICAgICAgICAgLy8gQ2xlYW4gdXAgZW50cmllcyB0aGF0IHdlcmUgbm90IHVzZWQgbGFzdCBmcmFtZS5cbiAgICAgICAgICAgICAgICBpZiAoaXRlbS5sZiA8IGZyYW1lIC0gMSkge1xuICAgICAgICAgICAgICAgICAgICBpZiAoaXRlbS50eCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gS2VlcCBhcyByZXVzYWJsZSBibGFuY28gdGV4dHVyZS5cbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2JsYW5jb1RleHR1cmVzLnB1c2goaXRlbS50eCk7XG4gICAgICAgICAgICAgICAgIC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Yy5fdWx5ICogdHguaCk7XG4gICAgICAgICAgICAgICAgY29uc3Qgc291cmNlVyA9IChzdGMgPyAxIDogKHZjLl9icnggLSB2Yy5fdWx4KSkgKiB0eC53O1xuICAgICAgICAgICAgICAgIGNvbnN0IHNvdXJjZUggPSAoc3RjID8gMSA6ICh2Yy5fYnJ5IC0gdmMuX3VseSkpICogdHguaDtcblxuICAgICAgICAgICAgICAgIGxldCBjb2xvcml6ZSA9ICF3aGl0ZTtcbiAgICAgICAgICAgICAgICBpZiAoY29sb3JpemUpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gQHRvZG86IGNhY2hlIHRoZSB0aW50IHRleHR1cmUgZm9yIGJldHRlciBwZXJmb3JtYW5jZS5cblxuICAgICAgICAgICAgICAgICAgICAvLyBEcmF3IHRvIGludGVybWVkaWF0ZSB0ZXh0dXJlIHdpdGggYmFja2dyb3VuZCBjb2xvci9ncmFkaWVudC5cbiAgICAgICAgICAgICAgICAgICAgLy8gVGhpcyBwcmV2ZW50cyB1cyBmcm9tIGhhdmluZyB0byBjcmVhdGUgYSBsb3Qgb2YgcmVuZGVyIHRleHR1cmUgY2FudmFzZXMuXG5cbiAgICAgICAgICAgICAgICAgICAgLy8gTm90aWNlIHRoYXQgd2UgZG9uJ3Qgc3VwcG9ydCAobm9uLXJlY3QpIGdyYWRpZW50cywgb25seSBjb2xvciB0aW50aW5nIGZvciBjMmQuIFdlJ2xsIGp1c3QgdGFrZSB0aGUgYXZlcmFnZSBjb2xvci5cbiAgICAgICAgICAgICAgICAgICAgbGV0IGNvbG9yID0gdmMuX2NvbG9yVWw7XG4gICAgICAgICAgICAgICAgICAgIGlmICh2Yy5fY29sb3JVbCAhPT0gdmMuX2NvbG9yVXIgfHwgdmMuX2NvbG9yVXIgIT09IHZjLl9jb2xvckJsIHx8IHZjLl9jb2xvckJyICE9PSB2Yy5fY29sb3JCbCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgY29sb3IgPSBTdGFnZVV0aWxzLm1lcmdlTXVsdGlDb2xvcnNFcXVhbChbdmMuX2NvbG9yVWwsIHZjLl9jb2xvclVyLCB2Yy5fY29sb3JCbCwgdmMuX2NvbG9yQnJdKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGFscGhhID0gKChjb2xvciAvIDE2Nzc3MjE2KSB8IDApIC8gMjU1LjA7XG4gICAgICAgICAgICAgICAgICAgIGN0eC5nbG9iYWxBbHBoYSAqPSBhbHBoYTtcblxuICAgICAgICAgICAgICAgICAgICBjb25zdCByZ2IgPSBjb2xvciAmIDB4MDBGRkZGRkY7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHRpbnRUZXh0dXJlID0gdGhpcy5fdGludE1hbmFnZXIuZ2V0VGludFRleHR1cmUodHgsIHJnYik7XG5cbiAgICAgICAgICAgICAgICAgICAgLy8gQWN0dWFsbHkgZHJhdyByZXN1bHQuXG4gICAgICAgICAgICAgICAgICAgIGN0eC5maWxsU3R5bGUgPSAnd2hpdGUnO1xuICAgICAgICAgICAgICAgICAgICBjdHguZHJhd0ltYWdlKHRpbnRUZXh0dXJlLCBzb3VyY2VYLCBzb3VyY2VZLCBzb3VyY2VXLCBzb3VyY2VILCAwLCAwLCB2Yy53LCB2Yy5oKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBjdHguZmlsbFN0eWxlID0gJ3doaXRlJztcbiAgICAgICAgICAgICAgICAgICAgY3R4LmRyYXdJbWFnZSh0eCwgc291cmNlWCwgc291cmNlWSwgc291cmNlVywgc291cmNlSCwgMCwgMCwgdmMudywgdmMuaCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHRoaXMuX2FmdGVyRHJhd0VsKGluZm8pO1xuICAgICAgICAgICAgICAgIGN0eC5nbG9iYWxBbHBoYSA9IDEuMDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9zZXRDb2xvckdyYWRpZW50KGN0eCwgdmMsIHcgPSB2Yy53LCBoID0gdmMuaCwgdHJhbnNwYXJlbmN5ID0gdHJ1ZSkge1xuICAgICAgICBsZXQgY29sb3IgPSB2Yy5fY29sb3JVbDtcbiAgICAgICAgbGV0IGdyYWRpZW50O1xuICAgICAgICAvL0B0b2RvOiBxdWljayBzaW5nbGUgY29sb3IgY2hlY2suXG4gICAgICAgIC8vQHRvZG86IGNhY2hlIGdyYWRpZW50L2ZpbGwgc3R5bGUgKGlmIHBvc3NpYmxlLCBwcm9iYWJseSBjb250ZXh0LXNwZWNpZmljKS5cblxuICAgICAgICBpZiAodmMuX2NvbG9yVWwgPT09IHZjLl9jb2xvclVyKSB7XG4gICAgICAgICAgICBpZiAodmMuX2NvbG9yQmwgPT09IHZjLl9jb2xvckJyKSB7XG4gICAgICAgICAgICAgICAgaWYgKHZjLl9jb2xvclVsID09PSB2Yy5jb2xvckJsKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFNpbmdsZSBjb2xvci5cbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAvLyBWZXJ0aWNhbCBncmFkaWVudC5cbiAgICAgICAgICAgICAgICAgICAgZ3JhZGllbnQgPSBjdHguY3JlYXRlTGluZWFyR3JhZGllbnQoMCwgMCwgMCwgaCk7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0cmFuc3BhcmVuY3kpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyYWRpZW50LmFkZENvbG9yU3RvcCgwLCBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcodmMuX2NvbG9yVWwpKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyYWRpZW50LmFkZENvbG9yU3RvcCgxLCBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcodmMuX2NvbG9yQmwpKTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyYWRpZW50LmFkZENvbG9yU3RvcCgwLCBTdGFnZVV0aWxzLmdldFJnYlN0cmluZyh2Yy5fY29sb3JVbCkpO1xuICAgICAgICAgICAgICAgICAgICAgICAgZ3JhZGllbnQuYWRkQ29sb3JTdG9wKDEsIFN0YWdlVXRpbHMuZ2V0UmdiU3RyaW5nKHZjLl9jb2xvckJsKSk7XG5cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gTm90IHN1cHBvcnRlZCBncmFkaWVudC5cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh2Yy5fY29sb3JVbCA9PT0gdmMuX2NvbG9yQmwgJiYgdmMuX2NvbG9yVXIgPT09IHZjLl9jb2xvckJyKSB7XG4gICAgICAgICAgICAgICAgLy8gSG9yaXpvbnRhbCBncmFkaWVudC5cbiAgICAgICAgICAgICAgICBncmFkaWVudCA9IGN0eC5jcmVhdGVMaW5lYXJHcmFkaWVudCgwLCAwLCB3LCAwKTtcbiAgICAgICAgICAgICAgICBpZiAodHJhbnNwYXJlbmN5KSB7XG4gICAgICAgICAgICAgICAgICAgIGdyYWRpZW50LmFkZENvbG9yU3RvcCgwLCBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcodmMuX2NvbG9yVWwpKTtcbiAgICAgICAgICAgICAgICAgICAgZ3JhZGllbnQuYWRkQ29sb3JTdG9wKDEsIFN0YWdlVXRpbHMuZ2V0UmdiYVN0cmluZyh2Yy5fY29sb3JCcikpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGdyYWRpZW50LmFkZENvbG9yU3RvcCgwLCBTdGFnZVV0aWxzLmdldFJnYlN0cmluZyh2Yy5fY29sb3JVbCkpO1xuICAgICAgICAgICAgICAgICAgICBncmFkaWVudC5hZGRDb2xvclN0b3AoMSwgU3Rh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CB2Yy5fY29sb3JVbCwgdmMpO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgZ2wuYmluZFRleHR1cmUoZ2wuVEVYVFVSRV8yRCwgZ2xUZXh0dXJlKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGdsLmRyYXdFbGVtZW50cyhnbC5UUklBTkdMRVMsIDYgKiAoaSAtIHBvcyksIGdsLlVOU0lHTkVEX1NIT1JULCAocG9zICsgb3BlcmF0aW9uLmluZGV4KSAqIDYgKiAyKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBnbFRleHR1cmUgPSB0eDtcbiAgICAgICAgICAgICAgICAgICAgcG9zID0gaTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAocG9zIDwgbGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgaWYgKGdsVGV4dHVyZS5vcHRpb25zICYmIGdsVGV4dHVyZS5vcHRpb25zLmltYWdlUmVmKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHByZWNpc2lvbiA9IHRoaXMuY3R4LnN0YWdlLmdldE9wdGlvbigncHJlY2lzaW9uJyk7XG4gICAgICAgICAgICAgICAgICAgIGxldCB2YyA9IG9wZXJhdGlvbi5nZXRFbGVtZW50Q29yZShwb3MpO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmN0eC5zdGFnZS5wbGF0Zm9ybS5wYWludChnbCwgZ2xUZXh0dXJlLm9wdGlvbnMuaW1hZ2VSZWYsIHZjLl93b3JsZENvbnRleHQucHgqcHJlY2lzaW9uLCB2Yy5fd29ybGRDb250ZXh0LnB5KnByZWNpc2lvbiwgdmMuX2NvbG9yVWwsIHZjKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBnbC5iaW5kVGV4dHVyZShnbC5URVhUVVJFXzJELCBnbFRleHR1cmUp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hpcy5kYXRhID0gbmV3IEFycmF5QnVmZmVyKGJ5dGVTaXplKTtcbiAgICAgICAgdGhpcy5mbG9hdHMgPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuZGF0YSk7XG4gICAgICAgIHRoaXMudWludHMgPSBuZXcgVWludDMyQXJyYXkodGhpcy5kYXRhKTtcbiAgICB9XG5cbiAgICBnZXRBdHRyaWJzRGF0YUJ5dGVPZmZzZXQoaW5kZXgpIHtcbiAgICAgICAgLy8gV2hlcmUgdGhpcyBxdWFkIGNhbiBiZSBmb3VuZCBpbiB0aGUgYXR0cmlicyBidWZmZXIuXG4gICAgICAgIHJldHVybiBpbmRleCAqIDgwO1xuICAgIH1cblxuICAgIGdldFF1YWRDb250ZW50cygpIHtcbiAgICAgICAgLy8gRGVidWc6IGxvZyBjb250ZW50cyBvZiBxdWFkIGJ1ZmZlci5cbiAgICAgICAgbGV0IGZsb2F0cyA9IHRoaXMuZmxvYXRzO1xuICAgICAgICBsZXQgdWludHMgPSB0aGlzLnVpbnRzO1xuICAgICAgICBsZXQgbGluZXMgPSBbXTtcbiAgICAgICAgZm9yIChsZXQgaSA9IDE7IGkgPD0gdGhpcy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgbGV0IHN0ciA9ICdlbnRyeSAnICsgaSArICc6ICc7XG4gICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IDQ7IGorKykge1xuICAgICAgICAgICAgICAgIGxldCBiID0gaSAqIDIwICsgaiAqIDQ7XG4gICAgICAgICAgICAgICAgc3RyICs9IGZsb2F0c1tiXSArICcsJyArIGZsb2F0c1tiKzFdICsgJzonICsgZmxvYXRzW2IrMl0gKyAnLCcgKyBmbG9hdHNbYiszXSArICdbJyArIHVpbnRzW2IrNF0udG9TdHJpbmcoMTYpICsgJ10gJztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGxpbmVzLnB1c2goc3RyKTtcbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiBsaW5lczt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BQ0hNRU5UMCwgZ2wuVEVYVFVSRV8yRCwgZ2xUZXh0dXJlLCAwKTtcblxuICAgICAgICByZXR1cm4gZ2xUZXh0dXJlO1xuICAgIH1cblxuICAgIGZyZWVSZW5kZXJUZXh0dXJlKGdsVGV4dHVyZSkge1xuICAgICAgICBsZXQgZ2wgPSB0aGlzLnN0YWdlLmdsO1xuICAgICAgICBnbC5kZWxldGVGcmFtZWJ1ZmZlcihnbFRleHR1cmUuZnJhbWVidWZmZXIpO1xuICAgICAgICBnbC5kZWxldGVUZXh0dXJlKGdsVGV4dHVyZSk7XG4gICAgfVxuXG4gICAgX2dldEJ5dGVzUGVyUGl4ZWwoZm10LCB0eXBlKSB7XG4gICAgICAgIGNvbnN0IGdsID0gdGhpcy5zdGFnZS5nbDtcblxuICAgICAgICBpZiAoZm10ID09PSBnbC5SR0JBKSB7XG4gICAgICAgICAgICBzd2l0Y2ggKHR5cGUpIHtcbiAgICAgICAgICAgICAgICBjYXNlIGdsLlVOU0lHTkVEX0JZVEU6XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiA0O1xuXG4gICAgICAgICAgICAgICAgY2FzZSBnbC5VTlNJR05FRF9TSE9SVF80XzRfNF80OlxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gMjtcblxuICAgICAgICAgICAgICAgIGNhc2UgZ2wuVU5TSUdORURfU0hPUlRfNV81XzVfMTpcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDI7XG5cbiAgICAgICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ0ludmFsaWQgdHlwZSBzcGVjaWZpZWQgZm9yIEdMX1JHQkEgZm9ybWF0Jyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAoZm10ID09PSBnbC5SR0IpIHtcbiAgICAgICAgICAgIHN3aXRjaCAodHlwZSkge1xuICAgICAgICAgICAgICAgIGNhc2UgZ2wuVU5TSUdORURfQllURTpcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDM7XG5cbiAgICAgICAgICAgICAgICBjYXNlIGdsLlVOU0lHTkVEX0JZVEVfNV82XzU6XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiAyO1xuXG4gICAgICAgICAgICAgICAgZGVmYXVsdDpcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdJbnZhbGlkIHR5cGUgc3BlY2lmaWVkIGZvciBHTF9SR0IgZm9ybWF0Jyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ0ludmFsaWQgZm9ybWF0IHNwZWNpZmllZCBpbiBjYWxsIHRvIF9nZXRCeXRlc1BlclBpeGVsKCknKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHVwbG9hZFRleHR1cmVTb3VyY2UodGV4dHVyZVNvdXJjZSwgb3B0aW9ucykge1xuICAgICAgICBjb25zdCBnbCA9IHRoaXMuc3RhZ2UuZ2w7XG5cbiAgICAgICAgY29uc3Qgc291cmNlID0gb3B0aW9ucy5zb3VyY2U7XG4gICAgICAgIGxldCBjb21wcmVzc2VkID0gZmFsc2U7XG4gICAgICAgIGlmIChvcHRpb25zLnJlbmRlckluZm8pIHtcbiAgICAgICAgICAgIGNvbXByZXNzZWQgPSBvcHRpb25zLnJlbmRlckluZm8uY29tcHJlc3NlZCB8fCBmYWxzZVxuICAgICAgICB9XG5cbiAgICAgICAgY29uc3QgZm9ybWF0ID0ge1xuICAgICAgICAgICAgcHJlbXVsdGlwbHlBbHBoYTogdHJ1ZSxcbiAgICAgICAgICAgIGhhc0FscGhhOiB0cnVlXG4gICAgICAgIH07XG5cbiAgICAgICAgaWYgKG9wdGlvbnMgJiYgb3B0aW9ucy5oYXNPd25Qcm9wZXJ0eSgncHJlbXVsdGlwbHlBbHBoYScpKSB7XG4gICAgICAgICAgICBmb3J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V0ZVRleHR1cmUodGV4dHVyZVNvdXJjZS5uYXRpdmVUZXh0dXJlKTtcbiAgICB9XG5cbiAgICBhZGRRdWFkKHJlbmRlclN0YXRlLCBxdWFkcywgaW5kZXgpIHtcbiAgICAgICAgbGV0IG9mZnNldCA9IChpbmRleCAqIDIwKTtcbiAgICAgICAgY29uc3QgZWxlbWVudENvcmUgPSBxdWFkcy5xdWFkRWxlbWVudHNbaW5kZXhdO1xuXG4gICAgICAgIGxldCByID0gZWxlbWVudENvcmUuX3JlbmRlckNvbnRleHQ7XG5cbiAgICAgICAgbGV0IGZsb2F0cyA9IHJlbmRlclN0YXRlLnF1YWRzLmZsb2F0cztcbiAgICAgICAgbGV0IHVpbnRzID0gcmVuZGVyU3RhdGUucXVhZHMudWludHM7XG4gICAgICAgIGNvbnN0IG1jYSA9IFN0YWdlVXRpbHMubWVyZ2VDb2xvckFscGhhO1xuXG4gICAgICAgIGlmIChyLnRiICE9PSAwIHx8IHIudGMgIT09IDApIHtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSByLnB4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHk7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX3VseDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fdWx5O1xuICAgICAgICAgICAgdWludHNbb2Zmc2V0KytdID0gbWNhKGVsZW1lbnRDb3JlLl9jb2xvclVsLCByLmFscGhhKTtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSByLnB4ICsgZWxlbWVudENvcmUuX3cgKiByLnRhO1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHkgKyBlbGVtZW50Q29yZS5fdyAqIHIudGM7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX2JyeDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fdWx5O1xuICAgICAgICAgICAgdWludHNbb2Zmc2V0KytdID0gbWNhKGVsZW1lbnRDb3JlLl9jb2xvclVyLCByLmFscGhhKTtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSByLnB4ICsgZWxlbWVudENvcmUuX3cgKiByLnRhICsgZWxlbWVudENvcmUuX2ggKiByLnRiO1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHkgKyBlbGVtZW50Q29yZS5fdyAqIHIudGMgKyBlbGVtZW50Q29yZS5faCAqIHIudGQ7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX2JyeDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ5O1xuICAgICAgICAgICAgdWludHNbb2Zmc2V0KytdID0gbWNhKGVsZW1lbnRDb3JlLl9jb2xvckJyLCByLmFscGhhKTtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSByLnB4ICsgZWxlbWVudENvcmUuX2ggKiByLnRiO1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHkgKyBlbGVtZW50Q29yZS5faCAqIHIudGQ7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX3VseDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ5O1xuICAgICAgICAgICAgdWludHNbb2Zmc2V0XSA9IG1jYShlbGVtZW50Q29yZS5fY29sb3JCbCwgci5hbHBoYSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAvLyBTaW1wbGUuXG4gICAgICAgICAgICBsZXQgY3ggPSByLnB4ICsgZWxlbWVudENvcmUuX3cgKiByLnRhO1xuICAgICAgICAgICAgbGV0IGN5ID0gci5weSArIGVsZW1lbnRDb3JlLl9oICogci50ZDtcblxuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHg7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gci5weTtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fdWx4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl91bHk7XG4gICAgICAgICAgICB1aW50c1tvZmZzZXQrK10gPSBtY2EoZWxlbWVudENvcmUuX2NvbG9yVWwsIHIuYWxwaGEpO1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGN4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHk7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX2JyeDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fdWx5O1xuICAgICAgICAgICAgdWludHNbb2Zmc2V0KytdID0gbWNhKGVsZW1lbnRDb3JlLl9jb2xvclVyLCByLmFscGhhKTtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBjeDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBjeTtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IGVsZW1lbnRDb3JlLl9icnk7XG4gICAgICAgICAgICB1aW50c1tvZmZzZXQrK10gPSBtY2EoZWxlbWVudENvcmUuX2NvbG9yQnIsIHIuYWxwaGEpO1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCsrXSA9IHIucHg7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gY3k7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0KytdID0gZWxlbWVudENvcmUuX3VseDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQrK10gPSBlbGVtZW50Q29yZS5fYnJ5O1xuICAgICAgICAgICAgdWludHNbb2Zmc2V0XSA9IG1jYShlbGVtZW50Q29yZS5fY29sb3JCbCwgci5hbHBoYSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBpc1JlbmRlclRleHR1cmVSZXVzYWJsZShyZW5kZXJTdGF0ZSwgcmVuZGVyVGV4dHVyZUluZm8pIHtcbiAgICAgICAgbGV0IG9mZnNldCA9IChyZW5kZXJTdGF0ZS5fcmVuZGVyVGV4dHVyZUluZm8ub2Zmc2V0ICogODApIC8gNDtcbiAgICAgICAgbGV0IGZsb2F0cyA9IHJlbmRlclN0YXRlLnF1YWRzLmZsb2F0cztcbiAgICAgICAgbGV0IHVpbnRzID0gcmVuZGVyU3RhdGUucXVhZHMudWludHM7XG4gICAgICAgIHJldHVybiAoKGZsb2F0c1tvZmZzZXRdID09PSAwKSAmJlxuICAgICAgICAgICAgKGZsb2F0c1tvZmZzZXQgKyAxXSA9PT0gMCkgJiZcbiAgICAgICAgICAgIChmbG9hdHNbb2Zmc2V0ICsgMl0gPT09IDApICYmXG4gICAgICAgICAgICAoZmxvYXRzW29mZnNldCArIDNdID09PSAwKSAmJlxuICAgICAgICAgICAgKHVpbnRzW29mZnNldCArIDRdID09PSAweEZGRkZGRkZGKSAmJlxuICAgICAgICAgICAgKGZsb2F0c1tvZmZzZXQgKyA1XSA9PT0gcmVuZGVyVGV4dHVyZUluZm8udykgJiZcbiAgICAgICAgICAgIChmbG9hdHNbb2Zmc2V0ICsgNl0gPT09IDApICYmXG4gICAgICAgICAgICAoZmxvYXRzW29mZnNldCArIDddID09PSAxKSAmJlxuICAgICAgICAgICAgKGZsb2F0c1tvZmZzZXQgKyA4XSA9PT0gMCkgJiZcbiAgICAgICAgICAgICh1aW50c1tvZmZzZXQgKyA5XSA9PT0gMHhGRkZGRkZGRikgJiZcbiAgICA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ucXVhZHMuZmxvYXRzO1xuXG4gICAgICAgIGxldCBsZW5ndGggPSBvcGVyYXRpb24ubGVuZ3RoO1xuXG4gICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuZ3RoOyBpKyspIHtcblxuICAgICAgICAgICAgLy8gQ2FsY3VsYXRlIG5vaXNlIHRleHR1cmUgY29vcmRpbmF0ZXMgc28gdGhhdCBpdCBzcGFucyB0aGUgZnVsbCBlbGVtZW50LlxuICAgICAgICAgICAgbGV0IGJyeCA9IG9wZXJhdGlvbi5nZXRFbGVtZW50V2lkdGgoaSkgLyB0aGlzLl9ub2lzZVRleHR1cmUuZ2V0UmVuZGVyV2lkdGgoKTtcbiAgICAgICAgICAgIGxldCBicnkgPSBvcGVyYXRpb24uZ2V0RWxlbWVudEhlaWdodChpKSAvIHRoaXMuX25vaXNlVGV4dHVyZS5nZXRSZW5kZXJIZWlnaHQoKTtcblxuICAgICAgICAgICAgbGV0IHVseCA9IDA7XG4gICAgICAgICAgICBsZXQgdWx5ID0gMDtcbiAgICAgICAgICAgIGlmICh0aGlzLl9yYW5kb20pIHtcbiAgICAgICAgICAgICAgICB1bHggPSBNYXRoLnJhbmRvbSgpO1xuICAgICAgICAgICAgICAgIHVseSA9IE1hdGgucmFuZG9tKCk7XG5cbiAgICAgICAgICAgICAgICBicnggKz0gdWx4O1xuICAgICAgICAgICAgICAgIGJyeSArPSB1bHk7XG5cbiAgICAgICAgICAgICAgICBpZiAoTWF0aC5yYW5kb20oKSA8IDAuNSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBGbGlwIGZvciBtb3JlIHJhbmRvbW5lc3MuXG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHQgPSB1bHg7XG4gICAgICAgICAgICAgICAgICAgIHVseCA9IGJyeDtcbiAgICAgICAgICAgICAgICAgICAgYnJ4ID0gdDtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAoTWF0aC5yYW5kb20oKSA8IDAuNSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBGbGlwIGZvciBtb3JlIHJhbmRvbW5lc3MuXG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHQgPSB1bHk7XG4gICAgICAgICAgICAgICAgICAgIHVseSA9IGJyeTtcbiAgICAgICAgICAgICAgICAgICAgYnJ5ID0gdDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIFNwZWNpZnkgYWxsIGNvcm5lciBwb2ludHMuXG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0XSA9IHVseDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQgKyAxXSA9IHVseTtcblxuICAgICAgICAgICAgZmxvYXRzW29mZnNldCArIDJdID0gYnJ4O1xuICAgICAgICAgICAgZmxvYXRzW29mZnNldCArIDNdID0gdWx5O1xuXG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0ICsgNF0gPSBicng7XG4gICAgICAgICAgICBmbG9hdHNbb2Zmc2V0ICsgNV0gPSBicnk7XG5cbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQgKyA2XSA9IHVseDtcbiAgICAgICAgICAgIGZsb2F0c1tvZmZzZXQgKyA3XSA9IGJyeTtcblxuICAgICAgICAgICAgb2Zmc2V0ICs9IDg7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBiZWZvcmVEcmF3KG9wZXJhdGlvbikge1xuICAgICAgICBsZXQgZ2wgPSB0aGlzLmdsO1xuICAgICAgICBnbC52ZXJ0ZXhBdHRyaWJQb2ludGVyKHRoaXMuX2F0dHJpYihcImFOb2lzZVRleHR1cmVDb29yZFwiKSwgMiwgZ2wuRkxPQVQsIGZhbHNlLCA4LCB0aGlzLmdldFZlcnRleEF0dHJpYlBvaW50ZXJPZmZzZXQob3BlcmF0aW9uKSk7XG5cbiAgICAgICAgbGV0IGdsVGV4dHVyZSA9IHRoaXMuX25vaXNlVGV4dHVyZS5zb3VyY2UubmF0aXZ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G9yKGNvbnRleHQpIHtcbiAgICAgICAgc3VwZXIoY29udGV4dCk7XG4gICAgICAgIHRoaXMuX2ZhZGUgPSBbMCwgMCwgMCwgMF07XG4gICAgfVxuXG4gICAgc2V0IHRvcChudW0pIHtcbiAgICAgICAgdGhpcy5fZmFkZVswXSA9IG51bTtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgdG9wKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fZmFkZVswXTtcbiAgICB9XG5cbiAgICBzZXQgcmlnaHQobnVtKSB7XG4gICAgICAgIHRoaXMuX2ZhZGVbMV0gPSBudW07XG4gICAgICAgIHRoaXMucmVkcmF3KCk7XG4gICAgfVxuXG4gICAgZ2V0IHJpZ2h0KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fZmFkZVsxXTtcbiAgICB9XG5cbiAgICBzZXQgYm90dG9tKG51bSkge1xuICAgICAgICB0aGlzLl9mYWRlWzJdID0gbnVtO1xuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIGdldCBib3R0b20oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9mYWRlWzJdO1xuICAgIH1cblxuICAgIHNldCBsZWZ0KG51bSkge1xuICAgICAgICB0aGlzLl9mYWRlWzNdID0gbnVtO1xuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIGdldCBsZWZ0KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fZmFkZVszXTtcbiAgICB9XG5cbiAgICBzZXQgZmFkZSh2KSB7XG4gICAgICAgIGlmKEFycmF5LmlzQXJyYXkodikpIHtcbiAgICAgICAgICAgIGlmKHYubGVuZ3RoID09PSAyKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fZmFkZSA9IFt2WzBdLCB2WzFdLCB2WzBdLCB2WzFdXTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2UgaWYodi5sZW5ndGggPT09IDMpIHt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zIocG9pbnQueCwgcG9pbnQueSArIGZhZGVbMF0pO1xuICAgICAgICAgICAgZCA9IHBvczIgLSBwb3MxO1xuICAgICAgICAgICAgYyA9IGRvdChwb3MxLCBkKSAvIGRvdChkLCBkKTtcbiAgICAgICAgICAgIHQgPSBzbW9vdGhzdGVwKDAuMCwgMS4wLCBjbGFtcChjLCAwLjAsIDEuMCkpO1xuICAgICAgICAgICAgY29sb3IgPSBtaXgodmVjNCgwLjApLCBjb2xvciwgdCk7XG4gICAgICAgIH1cbiAgICAgICAgXG4gICAgICAgIGlmKGZhZGVbMV0gPiAwLjApIHtcbiAgICAgICAgICAgIHZlYzIgcG9zMSA9IHZlYzIocG9pbnQueCAtIHJlc29sdXRpb24ueCAtIGZhZGVbMV0sIHZUZXh0dXJlQ29vcmQueSk7XG4gICAgICAgICAgICB2ZWMyIHBvczIgPSB2ZWMyKHBvaW50LnggLSByZXNvbHV0aW9uLngsIHZUZXh0dXJlQ29vcmQueSk7XG4gICAgICAgICAgICBkID0gcG9zMSAtIHBvczI7XG4gICAgICAgICAgICBjID0gZG90KHBvczIsIGQpIC8gZG90KGQsIGQpO1xuICAgICAgICAgICAgdCA9IHNtb290aHN0ZXAoMC4wLCAxLjAsIGNsYW1wKGMsIDAuMCwgMS4wKSk7XG4gICAgICAgICAgICBjb2xvciA9IG1peCh2ZWM0KDAuMCksIGNvbG9yLCB0KTtcbiAgICAgICAgfVxuICAgICAgICBcbiAgICAgICAgaWYoZmFkZVsyXSA+IDAuMCkge1xuICAgICAgICAgICAgdmVjMiBwb3MxID0gdmVjMih2VGV4dHVyZUNvb3JkLngsIHBvaW50LnkgLSByZXNvbHV0aW9uLnkgLSBmYWRlWzJdKTtcbiAgICAgICAgICAgIHZlYzIgcG9zMiA9IHZlYzIodlRleHR1cmVDb29yZC54LCBwb2ludC55IC0gcmVzb2x1dGlvbi55KTtcbiAgICAgICAgICAgIGQgPSBwb3MxIC0gcG9zMjtcbiAgICAgICAgICAgIGMgPSBkb3QocG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iAgICBzZXQgY29sb3IoYXJnYikge1xuICAgICAgICB0aGlzLmlubmVyQ29sb3IgPSBhcmdiO1xuICAgIH1cblxuICAgIGdldCBjb2xvcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuaW5uZXJDb2xvcjtcbiAgICB9XG5cbiAgICBnZXQgb3V0ZXJDb2xvcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2ljO1xuICAgIH1cblxuICAgIHNldCB4KGYpIHtcbiAgICAgICAgdGhpcy5feCA9IGY7XG4gICAgICAgIHRoaXMucmVkcmF3KCk7XG4gICAgfVxuXG4gICAgc2V0IHkoZikge1xuICAgICAgICB0aGlzLl95ID0gZjtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBzZXQgcGl2b3Qodikge1xuICAgICAgICBpZihBcnJheS5pc0FycmF5KHYpICYmIHYubGVuZ3RoID09PSAyKSB7XG4gICAgICAgICAgICB0aGlzLl9waXZvdCA9IHY7XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZihBcnJheS5pc0FycmF5KHYpKSB7XG4gICAgICAgICAgICB0aGlzLl9waXZvdCA9IFt2WzBdLCB2WzFdIHx8IHZbMF1dO1xuICAgICAgICB9XG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fcGl2b3QgPSBbdiwgdl07XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgcGl2b3QoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9waXZvdFswXTtcbiAgICB9XG5cbiAgICBzZXQgcGl2b3RZKGYpIHtcbiAgICAgICAgdGhpcy5fcGl2b3RbMV0gPSBmO1xuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIGdldCBwaXZvdFkoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9waXZvdFsxXTtcbiAgICB9XG5cbiAgICBzZXQgcGl2b3RYKGY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zBdLCB2WzFdLCB2WzJdLCB0aGlzLl9yYWRpdXNbM11dO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSBpZiAodi5sZW5ndGggPT09IDQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9yYWRpdXMgPSB2O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcmFkaXVzID0gW3ZbMF0sIHZbMF0sIHZbMF0sIHZbMF1dO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fcmFkaXVzID0gW3YsIHYsIHYsIHZdO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMucmVkcmF3KCk7XG4gICAgfVxuXG4gICAgZ2V0IHJhZGl1cygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JhZGl1cztcbiAgICB9XG5cbiAgICBzZXQgdG9wTGVmdChudW0pIHtcbiAgICAgICAgdGhpcy5fcmFkaXVzWzBdID0gbnVtO1xuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIGdldCB0b3BMZWZ0KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcmFkaXVzWzBdO1xuICAgIH1cblxuICAgIHNldCB0b3BSaWdodChudW0pIHtcbiAgICAgICAgdGhpcy5fcmFkaXVzWzFdID0gbnVtO1xuICAgICAgICB0aGlzLnJlZHJhdygpO1xuICAgIH1cblxuICAgIGdldCB0b3BSaWdodCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JhZGl1c1sxXTtcbiAgICB9XG5cbiAgICBzZXQgYm90dG9tUmlnaHQobnVtKSB7XG4gICAgICAgIHRoaXMuX3JhZGl1c1syXSA9IG51bTtcbiAgICAgICAgdGhpcy5yZWRyYXcoKTtcbiAgICB9XG5cbiAgICBnZXQgYm90dG9tUmlnaHQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9yY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1heChkLCAwLjApKSAtIHJhZGl1cztcbiAgICB9XG4gICAgXG4gICAgZmxvYXQgZmlsbE1hc2soZmxvYXQgZGlzdCl7XG4gICAgICAgIHJldHVybiBjbGFtcCgtZGlzdCwgMC4wLCAxLjApO1xuICAgIH1cbiAgICBcbiAgICBmbG9hdCBpbm5lckJvcmRlck1hc2soZmxvYXQgZGlzdCwgZmxvYXQgd2lkdGgpe1xuICAgICAgICBmbG9hdCBhbHBoYTEgPSBjbGFtcChkaXN0ICsgd2lkdGgsIDAuMCwgMS4wKTtcbiAgICAgICAgZmxvYXQgYWxwaGEyID0gY2xhbXAoZGlzdCwgMC4wLCAxLjApO1xuICAgICAgICByZXR1cm4gYWxwaGExIC0gYWxwaGEyO1xuICAgIH1cblxuICAgIHZvaWQgbWFpbigpIHtcbiAgICAgICAgdmVjMiBoYWxmUmVzID0gMC41ICogcmVzb2x1dGlvbi54eTtcbiAgICAgICAgZmxvYXQgciA9IDAuMDtcbiAgICAgICAgaWYgKHZUZXh0dXJlQ29vcmQueCA8IDAuNSAmJiB2VGV4dHVyZUNvb3JkLnkgPCAwLjUpIHtcbiAgICAgICAgICAgIHIgPSByYWRpdXNbMF07XG4gICAgICAgIH0gZWxzZSBpZiAodlRleHR1cmVDb29yZC54ID49IDAuNSAmJiB2VGV4dHVyZUNvb3JkLnkgPCAwLjUpIHtcbiAgICAgICAgICAgIHIgPSByYWRpdXNbMV07XG4gICAgICAgIH0gZWxzZSBpZiAodlRleHR1cmVDb29yZC54ID49IDAuNSAmJiB2VGV4dHVyZUNvb3JkLnkgPj0gMC41KSB7XG4gICAgICAgICAgICByID0gcmFkaXVzWzJdO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgciA9IHJhZGl1c1szXTtcbiAgICAgICAgfVxuICAgICAgICBcbiAgICAgICAgZmxvYXQgYiA9IGJveERpc3QodlRleHR1cmVDb29yZC54eSAqIHJlc29sdXRpb24gLSBoYWxmUmVzLCBoYWxmUmVzIC0gMC4wM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ICBmbG9hdCB4MSA9IG1vZCh0LCAxLjApO1xuICAgICAgICBmbG9hdCB4MiA9IG1vZCh0ICsgYW5nbGUsIDEuMCk7XG5cbiAgICAgICAgaWYgKHgxIDwgeDIpIHtcbiAgICAgICAgICAgIGlmIChhID4geDEgJiYgYSA8IHgyKSB7XG4gICAgICAgICAgICAgICAgZmxvYXQgdmFsID0gKDEuMCAtICh4MiAtIGEpIC8gYW5nbGUpICogc21vb3Roc3RlcCgwLjAsIDMuICogc21vb3RoLCAoeDIgLSBhKSk7XG4gICAgICAgICAgICAgICAgZnJhZ0NvbG9yID0gbWl4KGJhY2tncm91bmRDb2xvciwgY29sb3IsIHZhbCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGZyYWdDb2xvciA9IGJhY2tncm91bmRDb2xvcjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmIChhIDwgeDIpIHtcbiAgICAgICAgICAgICAgICBmbG9hdCB2YWwgPSAoMS4wIC0gKHgyIC0gYSkgLyBhbmdsZSkgKiBzbW9vdGhzdGVwKDAuMCwgMy4gKiBzbW9vdGgsICh4MiAtIGEpKTtcbiAgICAgICAgICAgICAgICBmcmFnQ29sb3IgPSBtaXgoYmFja2dyb3VuZENvbG9yLCBjb2xvciwgdmFsKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoYSA+IHgxKSB7XG4gICAgICAgICAgICAgICAgZmxvYXQgdmFsID0gKDEuMCAtICgxLjAgKyB4MiAtIGEpIC8gYW5nbGUpICogc21vb3Roc3RlcCgwLjAsIDMuICogc21vb3RoLCAoMS4wICsgeDIgLSBhKSk7XG4gICAgICAgICAgICAgICAgZnJhZ0NvbG9yID0gbWl4KGJhY2tncm91bmRDb2xvciwgY29sb3IsIHZhbCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGZyYWdDb2xvciA9IGJhY2tncm91bmRDb2xvcjtc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BpbmNsdWRlIGh0bWwyY2FudmFzIChodHRwczovL2h0bWwyY2FudmFzLmhlcnR6ZW4uY29tLylcIikpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBjb25zdCBhcmVhID0gSHRtbFRleHR1cmUuZ2V0UHJlbG9hZEFyZWEoKTtcbiAgICAgICAgICAgIGFyZWEuYXBwZW5kQ2hpbGQoaHRtbEVsZW1lbnQpO1xuXG4gICAgICAgICAgICBodG1sMmNhbnZhcyhodG1sRWxlbWVudCwge2JhY2tncm91bmRDb2xvcjogbnVsbCwgc2NhbGU6IHNjYWxlfSkudGhlbihmdW5jdGlvbihjYW52YXMpIHtcbiAgICAgICAgICAgICAgICBhcmVhLnJlbW92ZUNoaWxkKGh0bWxFbGVtZW50KTtcbiAgICAgICAgICAgICAgICBpZiAoY2FudmFzLmhlaWdodCA9PT0gMCkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gY2IobmV3IEVycm9yKFwiQ2FudmFzIGhlaWdodCBpcyAwXCIpKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgY2IobnVsbCwge3NvdXJjZTogY2FudmFzLCB3aWR0aDogY2FudmFzLndpZHRoLCBoZWlnaHQ6IGNhbnZhcy5oZWlnaHR9KTtcbiAgICAgICAgICAgIH0pLmNhdGNoKGUgPT4ge1xuICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoJ1tMaWdodG5pbmddJywgZSk7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHN0YXRpYyBnZXRQcmVsb2FkQXJlYSgpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9wcmVsb2FkQXJlYSkge1xuICAgICAgICAgICAgLy8gUHJlbG9hZCBhcmVhIG11c3QgYmUgaW5jbHVkZWQgaW4gZG9jdW1lbnQgYm9keSBhbmQgbXVzdCBiZSB2aXNpYmxlIHRvIHRyaWdnZXIgaHRtbCBlbGVtZW50IHJlbmRlcmluZy5c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AgICBpZiAodGhpcy5hZHZhbmNlZFJlbmRlcmVyKSB7XG4gICAgICAgICAgICByZXR1cm4gbmV3IFRleHRUZXh0dXJlUmVuZGVyZXJBZHZhbmNlZChzdGFnZSwgY2FudmFzLCBzZXR0aW5ncyk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gbmV3IFRleHRUZXh0dXJlUmVuZGVyZXIoc3RhZ2UsIGNhbnZhcywgc2V0dGluZ3MpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHRleHQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl90ZXh0O1xuICAgIH1cblxuICAgIHNldCB0ZXh0KHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX3RleHQgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX3RleHQgPSBcIlwiICsgdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCB3KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdztcbiAgICB9XG5cbiAgICBzZXQgdyh2KSB7XG4gICAgICAgIGlmICh0aGlzLl93ICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl93ID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBoKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faDtcbiAgICB9XG5cbiAgICBzZXQgaCh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9oICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9oID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBmb250U3R5bGUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9mb250U3R5bGU7XG4gICAgfVxuXG4gICAgc2V0IGZvbnRTdHlsZSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9mb250U3R5bGUgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX2ZvbnRTdHlsZSA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgZm9udEJhc2VsaW5lUmF0aW8oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9mb250QmFzZWxpbmVSYXRpbztcbiAgICB9XG4gICAgXG4gICAgc2V0IGZvbnRCYXNlbGluZVJhdGlvKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX2ZvbnRCYXNlbGluZVJhdGlvICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9mb250QmFzZWxpbmVSYXRpbyA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgZm9udFNpemUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9mb250U2l6ZTtcbiAgICB9XG5cbiAgICBzZXQgZm9udFNpemUodikge1xuICAgICAgICBpZiAodGhpcy5fZm9udFNpemUgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX2ZvbnRTaXplID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBmb250RmFjZSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2ZvbnRGYWNlO1xuICAgIH1cblxuICAgIHNldCBmb250RmFjZSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9mb250RmFjZSAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fZm9udEZhY2UgPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHdvcmRXcmFwKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fd29yZFdyYXA7XG4gICAgfVxuXG4gICAgc2V0IH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AgICBnZXQgb2Zmc2V0WSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX29mZnNldFk7XG4gICAgfVxuXG4gICAgc2V0IG9mZnNldFkodikge1xuICAgICAgICBpZiAodGhpcy5fb2Zmc2V0WSAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fb2Zmc2V0WSA9IHY7XG4gICAgICAgICAgICB0aGlzLl9jaGFuZ2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgbWF4TGluZXMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9tYXhMaW5lcztcbiAgICB9XG5cbiAgICBzZXQgbWF4TGluZXModikge1xuICAgICAgICBpZiAodGhpcy5fbWF4TGluZXMgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX21heExpbmVzID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBtYXhMaW5lc1N1ZmZpeCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX21heExpbmVzU3VmZml4O1xuICAgIH1cblxuICAgIHNldCBtYXhMaW5lc1N1ZmZpeCh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9tYXhMaW5lc1N1ZmZpeCAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fbWF4TGluZXNTdWZmaXggPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHRleHRDb2xvcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3RleHRDb2xvcjtcbiAgICB9XG5cbiAgICBzZXQgdGV4dENvbG9yKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX3RleHRDb2xvciAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fdGV4dENvbG9yID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblx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xuICAgIGdldCBsZXR0ZXJTcGFjaW5nKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbGV0dGVyU3BhY2luZztcbiAgICB9XG5cbiAgICBzZXQgdGV4dEluZGVudCh2KSB7XG4gICAgICAgIGlmICh0aGlzLl90ZXh0SW5kZW50ICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl90ZXh0SW5kZW50ID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCB0ZXh0SW5kZW50KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdGV4dEluZGVudDtcbiAgICB9XG5cbiAgICBzZXQgcnRsKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX3J0bCAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fcnRsID0gdjtcbiAgICAgICAgICAgIHRoaXMuX2NoYW5nZWQoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBydGwoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9ydGw7XG4gICAgfVxuXG4gICAgZ2V0IHByZWNpc2lvbigpIHtcbiAgICAgICAgcmV0dXJuIHN1cGVyLnByZWNpc2lvbjtcbiAgICB9XG5cbiAgICBzZXQgcHJlY2lzaW9uKHYpIHtcbiAgICAgICAgLy8gV2UgYWN0dWFsbHkgZHJhdyBkaWZmZXJlbnRseSB3aGVuIHRoZSBwcmVjaXNpb24gY2hhbmdlcy5cbiAgICAgICAgaWYgKHRoaXMucHJlY2lzaW9uICE9PSB2KSB7XG4gICAgICAgICAgICBzdXBlci5wcmVjaXNpb24gPSB2O1xuICAgICAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2dldElzVmFsaWQoKSB7XG4gICAgICAgIHJldHVybiAhIXRoaXMudGV4dDtcbiAgICB9XG5cbiAgICBfZ2V0TG9va3VwSWQoKSB7XG4gICAgICAgIGxldCBwYXJ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JiYgYXJncy5mb250U2l6ZSA8PSBzaGFycENmZy5mb250U2l6ZTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGdsICYmIHNoYXJwZW4pIHtcbiAgICAgICAgICAgICAgICB0ZXhQYXJhbXNbZ2wuVEVYVFVSRV9NQUdfRklMVEVSXSA9IGdsLk5FQVJFU1Q7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChwKSB7XG4gICAgICAgICAgICAgICAgcC50aGVuKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgLyogRklYTUU6IG9uIHNvbWUgcGxhdGZvcm1zIChlLmcuIFJQSSksIHRocm90dGxpbmcgdGV4dCB0ZXh0dXJlcyBjYXVzZSBhcnRpZmFjdHMgKi9cbiAgICAgICAgICAgICAgICAgICAgY2IobnVsbCwgT2JqZWN0LmFzc2lnbih7XG4gICAgICAgICAgICAgICAgICAgICAgICByZW5kZXJJbmZvOiByZW5kZXJlci5yZW5kZXJJbmZvLFxuICAgICAgICAgICAgICAgICAgICAgICAgdGhyb3R0bGU6IGZhbHNlLFxuICAgICAgICAgICAgICAgICAgICAgICAgdGV4UGFyYW1zOiB0ZXhQYXJhbXMsXG4gICAgICAgICAgICAgICAgICAgIH0sIHRoaXMuc3RhZ2UucGxhdGZvcm0uZ2V0VGV4dHVyZU9wdGlvbnNGb3JEcmF3aW5nQ2FudmFzKGNhbnZhcykpKTtcbiAgICAgICAgICAgICAgICB9KS5jYXRjaCgoZXJyKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgIGNiKGVycik7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGNiKG51bGwsIE9iamVjdC5hc3NpZ24oe1xuICAgICAgICAgICAgICAgICAgICByZW5kZXJJbmZvOiByZW5kZXJlci5yZW5kZXJJbmZvLFxuICAgICAgICAgICAgICAgICAgICB0aHJvdHRsZTogZmFsc2UsXG4gICAgICAgICAgIC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ID0gdGhpcy5fY2FudmFzLmdldENvbnRleHQoJzJkJyk7XG4gICAgICAgIHRoaXMuX3NldHRpbmdzID0gc2V0dGluZ3M7XG4gICAgfVxuXG4gICAgZ2V0UHJlY2lzaW9uKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fc2V0dGluZ3MucHJlY2lzaW9uO1xuICAgIH07XG5cbiAgICBzZXRGb250UHJvcGVydGllcygpIHtcbiAgICAgICAgdGhpcy5fY29udGV4dC5mb250ID0gZ2V0Rm9udFNldHRpbmcoXG4gICAgICAgICAgICB0aGlzLl9zZXR0aW5ncy5mb250RmFjZSxcbiAgICAgICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRTdHlsZSxcbiAgICAgICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRTaXplLFxuICAgICAgICAgICAgdGhpcy5nZXRQcmVjaXNpb24oKSxcbiAgICAgICAgICAgIHRoaXMuX3N0YWdlLmdldE9wdGlvbignZGVmYXVsdEZvbnRGYWNlJyksXG4gICAgICAgICk7XG4gICAgICAgIHRoaXMuX2NvbnRleHQudGV4dEJhc2VsaW5lID0gdGhpcy5fc2V0dGluZ3MudGV4dEJhc2VsaW5lO1xuICAgICAgICB0aGlzLl9jb250ZXh0LmRpcmVjdGlvbiA9IHRoaXMuX3NldHRpbmdzLnJ0bCA/IFwicnRsXCIgOiBcImx0clwiO1xuICAgIH07XG5cbiAgICBfbG9hZCgpIHtcbiAgICAgICAgaWYgKFV0aWxzLmlzV2ViICYmIGRvY3VtZW50LmZvbnRzKSB7XG4gICAgICAgICAgICBjb25zdCBmb250U2V0dGluZyA9IGdldEZvbnRTZXR0aW5nKFxuICAgICAgICAgICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRGYWNlLFxuICAgICAgICAgICAgICAgIHRoaXMuX3NldHRpbmdzLmZvbnRTdHlsZSxcbiAgICAgICAgICAgICAgICB0aGlzLl9zZXR0aW5ncy5mb250U2l6ZSxcbiAgICAgICAgICAgICAgICB0aGlzLmdldFByZWNpc2lvbigpLFxuICAgICAgICAgICAgICAgIHRoaXMuX3N0YWdlLmdldE9wdGlvbignZGVmYXVsdEZvbnRGYWNlJylcbiAgICAgICAgICAgICk7XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgIGlmICghZG9jdW1lbnQuZm9udHMuY2hlY2soZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFVzZSBhIHByb21pc2UgdGhhdCB3YWl0cyBmb3IgbG9hZGluZy5cbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGRvY3VtZW50LmZvbnRzLmxvYWQoZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpLmNhdGNoKGVyciA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBKdXN0IGxvYWQgdGhlIGZhbGxiYWNrIGZvbnQuXG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oJ1tMaWdodG5pbmddIEZvbnQgbG9hZCBlcnJvcicsIGVyciwgZm9udFNldHRpbmcpO1xuICAgICAgICAgICAgICAgICAgICB9KS50aGVuKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghZG9jdW1lbnQuZm9udHMuY2hlY2soZm9udFNldHRpbmcsIHRoaXMuX3NldHRpbmdzLnRleHQpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS53YXJuKCdbTGlnaHRuaW5nXSBGb250IG5vdCBmb3VuZCcsIGZvbnRTZXR0aW5nKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBjYXRjaChlKSB7XG4gICAgICAgICAgICAgICAgY29uc29sZS53YXJuKFwiW0xpZ2h0bmluZ10gQ2FuJ3QgY2hlY2sgZm9udCBsb2FkaW5nIGZvciBcIi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fHwgdGhpcy5fc3RhZ2UuZ2V0T3B0aW9uKCd3Jyk7XG5cbiAgICAgICAgLy8gSW5uZXIgd2lkdGguXG4gICAgICAgIGxldCBpbm5lcldpZHRoID0gd2lkdGggLSAocGFkZGluZ0xlZnQpO1xuICAgICAgICBpZiAoaW5uZXJXaWR0aCA8IDEwKSB7XG4gICAgICAgICAgICB3aWR0aCArPSAoMTAgLSBpbm5lcldpZHRoKTtcbiAgICAgICAgICAgIGlubmVyV2lkdGggPSAxMDtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICghd29yZFdyYXBXaWR0aCkge1xuICAgICAgICAgICAgd29yZFdyYXBXaWR0aCA9IGlubmVyV2lkdGhcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIFRleHQgb3ZlcmZsb3dcbiAgICAgICAgaWYgKHRoaXMuX3NldHRpbmdzLnRleHRPdmVyZmxvdyAmJiAhdGhpcy5fc2V0dGluZ3Mud29yZFdyYXApIHtcbiAgICAgICAgICAgIGxldCBzdWZmaXg7XG4gICAgICAgICAgICBzd2l0Y2ggKHRoaXMuX3NldHRpbmdzLnRleHRPdmVyZmxvdykge1xuICAgICAgICAgICAgICAgIGNhc2UgJ2NsaXAnOlxuICAgICAgICAgICAgICAgICAgICBzdWZmaXggPSAnJztcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgY2FzZSAnZWxsaXBzaXMnOlxuICAgICAgICAgICAgICAgICAgICBzdWZmaXggPSB0aGlzLl9zZXR0aW5ncy5tYXhMaW5lc1N1ZmZpeDtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgZGVmYXVsdDpcbiAgICAgICAgICAgICAgICAgICAgc3VmZml4ID0gdGhpcy5fc2V0dGluZ3MudGV4dE92ZXJmbG93O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fc2V0dGluZ3MudGV4dCA9IHRoaXMud3JhcFdvcmQodGhpcy5fc2V0dG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kge1xuICAgICAgICAgICAgICAgICAgICBqKys7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICByZW5kZXJJbmZvLnJlbWFpbmluZ1RleHQgPSBvdGhlckxpbmVzLmpvaW4oXCJcXG5cIik7XG5cbiAgICAgICAgICAgIHJlbmRlckluZm8ubW9yZVRleHRMaW5lcyA9IHRydWU7XG5cbiAgICAgICAgICAgIGxpbmVzID0gdXNlZExpbmVzO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmVuZGVySW5mby5tb3JlVGV4dExpbmVzID0gZmFsc2U7XG4gICAgICAgICAgICByZW5kZXJJbmZvLnJlbWFpbmluZ1RleHQgPSBcIlwiO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gY2FsY3VsYXRlIHRleHQgd2lkdGhcbiAgICAgICAgbGV0IG1heExpbmVXaWR0aCA9IDA7XG4gICAgICAgIGxldCBsaW5lV2lkdGhzID0gW107XG4gICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGluZXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgIGxldCBsaW5lV2lkdGggPSB0aGlzLm1lYXN1cmVUZXh0KGxpbmVzW2ldLCBsZXR0ZXJTcGFjaW5nKSArIChpID09PSAwID8gdGV4dEluZGVudCA6IDApO1xuICAgICAgICAgICAgbGluZVdpZHRocy5wdXNoKGxpbmVXaWR0aCk7XG4gICAgICAgICAgICBtYXhMaW5lV2lkdGggPSBNYXRoLm1heChtYXhMaW5lV2lkdGgsIGxpbmVXaWR0aCk7XG4gICAgICAgIH1cblxuICAgICAgICByZW5kZXJJbmZvLmxpbmVXaWR0aHMgPSBsaW5lV2lkdGhzO1xuXG4gICAgICAgIGlmICghdykge1xuICAgICAgICAgICAgLy8gQXV0by1zZXQgd2lkdGggdG8gbWF4IHRleHQgbGVuZ3RoLlxuICAgICAgICAgICAgd2lkdGggPSBtYXhMaW5lV2lkdGggKyBwYWRkaW5nTGVmdCArIHBhZGRpbmdSaWdodDtcbiAgICAgICAgICAgIGlubmVyV2lkdGggPSBtYXhMaW5lV2lkdGg7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBjYWxjdWxhdGUgdGV4dCBoZWlnaHRcbiAgICAgICAgbGluZUhlaWdodCA9IGxpbmVIZWlnaHQgfHwgZm9udFNpemU7XG5cbiAgICAgICAgbGV0IGhlaWdodDtcbiAgICAgICAgaWYgKGgpIHtcbiAgICAgICAgICAgIGhlaWdodCA9IGg7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb25zdCBiYXNlbGluZU9mZnNldCA9ICh0aGlzLl9zZXR0aW5ncy50ZXh0QmFzZWxpbmUgIT0gJ2JvdHRvbScpID8gMC41ICogZm9udFNpemUgOiAwO1xuICAgICAgICAgICAgaGVpZ2h0ID0gbGluZUhlaWdodCAqIChsaW5lcy5sZW5ndGggLSAxKSArIGJhc2VsaW5lT2Zmc2V0ICsgTWF0aC5tYXgobGluZUhlaWdodCwgZm9udFNpemUpICsgb2Zmc2V0WTtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChvZmZzZXRZID09PSBudWxsKSB7XG4gICAgICAgICAgICBvZmZzZXRZID0gZm9udFNpemU7XG4gICAgICAgIH1cblxuICAgICAgICByZW5kZXJJbmZvLncgPSB3aWR0aDtcbiAgICAgICAgcmVuZGVySW5mby5oID0gaGVpZ2h0O1xuICAgICAgICByZW5kZXJJbmZvLmxpbmVzID0gbGluZXM7XG4gICAgICAgIHJlbmRlckluZm8ucHJlY2lzaW9uID0gcHJlY2lzaW9uO1xuXG4gICAgICAgIGlmICghd2lkdGgpIHtcbiAgICAgICAgICAgIC8vIFRvIHByZXZlbnQgY2FudmFzIGVycm9ycy5cbiAgICAgICAgICAgIHdpZHRoID0gMTtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICghaGVpZ2h0KSB7XG4gICAgICAgICAgICAvLyBUbyBwcmV2ZW50IGNhbnZhcyBlcnJvcnMuXG4g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cblxuICAgICAgICBpZiAocmVuZGVySW5mby5jdXRTeCB8fCByZW5kZXJJbmZvLmN1dFN5KSB7XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnRyYW5zbGF0ZSgtcmVuZGVySW5mby5jdXRTeCwgLXJlbmRlckluZm8uY3V0U3kpO1xuICAgICAgICB9XG5cbiAgICAgICAgbGV0IGxpbmVQb3NpdGlvblg7XG4gICAgICAgIGxldCBsaW5lUG9zaXRpb25ZO1xuXG4gICAgICAgIGxldCBkcmF3TGluZXMgPSBbXTtcblxuICAgICAgICAvLyBEcmF3IGxpbmVzIGxpbmUgYnkgbGluZS5cbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSByZW5kZXJJbmZvLmxpbmVzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgbGluZVBvc2l0aW9uWCA9IGkgPT09IDAgPyByZW5kZXJJbmZvLnRleHRJbmRlbnQgOiAwO1xuXG4gICAgICAgICAgICAvLyBCeSBkZWZhdWx0LCB0ZXh0IGlzIGFsaWduZWQgdG8gdG9wXG4gICAgICAgICAgICBsaW5lUG9zaXRpb25ZID0gKGkgKiByZW5kZXJJbmZvLmxpbmVIZWlnaHQpICsgcmVuZGVySW5mby5vZmZzZXRZO1xuXG4gICAgICAgICAgICBpZiAodGhpcy5fc2V0dGluZ3MudmVydGljYWxBbGlnbiA9PSAnbWlkZGxlJykge1xuICAgICAgICAgICAgICAgIGxpbmVQb3NpdGlvblkgKz0gKHJlbmRlckluZm8ubGluZUhlaWdodCAtIHJlbmRlckluZm8uZm9udFNpemUpIC8gMjtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fc2V0dGluZ3MudmVydGljYWxBbGlnbiA9PSAnYm90dG9tJykge1xuICAgICAgICAgICAgICAgIGxpbmVQb3NpdGlvblkgKz0gcmVuZGVySW5mby5saW5lSGVpZ2h0IC0gcmVuZGVySW5mby5mb250U2l6ZTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX3NldHRpbmdzLnRleHRBbGlnbiA9PT0gJ3JpZ2h0Jykge1xuICAgICAgICAgICAgICAgIGxpbmVQb3NpdGlvblggKz0gKHJlbmRlckluZm8uaW5uZXJXaWR0aCAtIHJlbmRlckluZm8ubGluZVdpZHRoc1tpXSk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX3NldHRpbmdzLnRleHRBbGlnbiA9PT0gJ2NlbnRlcicpIHtcbiAgICAgICAgICAgICAgICBsaW5lUG9zaXRpb25YICs9ICgocmVuZGVySW5mby5pbm5lcldpZHRoIC0gcmVuZGVySW5mby5saW5lV2lkdGhzW2ldKSAvIDIpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgbGluZVBvc2l0aW9uWCArPSByZW5kZXJJbmZvLnBhZGRpbmdMZWZ0O1xuICAgICAgICAgICAgaWYgKHRoaXMuX3NldHRpbmdzLnJ0bCkge1xuICAgICAgICAgICAgICAgIGxpbmVQb3NpdGlvblggKz0gcmVuZGVySW5mby5saW5lV2lkdGhzW2ldO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBkcmF3TGluZXMucHVzaCh7dGV4dDogcmVuZGVySW5mby5saW5lc1tpXSwgeDogbGluZVBvc2l0aW9uWCwgeTogbGluZVBvc2l0aW9uWSwgdzogcmVuZGVySW5mby5saW5lV2lkdGhzW2ldfSk7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBIaWdobGlnaHQuXG4gICAgICAgIGlmICh0aGlzLl9zZXR0aW5ncy5oaWdobGlnaHQpIHtcbiAgICAgICAgICAgIGxldCBjb2xvciA9IHRoaXMuX3NldHRpbmdzLmhpZ2hsaWdodENvbG9yIHx8IDB4MDAwMDAwMDA7XG5cbiAgICAgICAgICAgIGxldCBobEhlaWdodCA9ICh0aGlzLl9zZXR0aW5ncy5oaWdobGlnaHRIZWlnaHQgKiBwcmVjaXNpb24gfHwgcmVuZGVySW5mby5mb250U2l6ZSAqIDE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xUZXh0KGRyYXdMaW5lLnRleHQsIGRyYXdMaW5lLngsIGRyYXdMaW5lLnkpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjb25zdCB0ZXh0U3BsaXQgPSBkcmF3TGluZS50ZXh0LnNwbGl0KCcnKTtcbiAgICAgICAgICAgICAgICBsZXQgeCA9IGRyYXdMaW5lLng7XG4gICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIGogPSB0ZXh0U3BsaXQubGVuZ3RoOyBpIDwgajsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuZmlsbFRleHQodGV4dFNwbGl0W2ldLCB4LCBkcmF3TGluZS55KTtcbiAgICAgICAgICAgICAgICAgICAgeCArPSB0aGlzLm1lYXN1cmVUZXh0KHRleHRTcGxpdFtpXSwgcmVuZGVySW5mby5sZXR0ZXJTcGFjaW5nKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBpZiAocHJldlNoYWRvd1NldHRpbmdzKSB7XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd0NvbG9yID0gcHJldlNoYWRvd1NldHRpbmdzWzBdO1xuICAgICAgICAgICAgdGhpcy5fY29udGV4dC5zaGFkb3dPZmZzZXRYID0gcHJldlNoYWRvd1NldHRpbmdzWzFdO1xuICAgICAgICAgICAgdGhpcy5fY29udGV4dC5zaGFkb3dPZmZzZXRZID0gcHJldlNoYWRvd1NldHRpbmdzWzJdO1xuICAgICAgICAgICAgdGhpcy5fY29udGV4dC5zaGFkb3dCbHVyID0gcHJldlNoYWRvd1NldHRpbmdzWzNdO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHJlbmRlckluZm8uY3V0U3ggfHwgcmVuZGVySW5mby5jdXRTeSkge1xuICAgICAgICAgICAgdGhpcy5fY29udGV4dC50cmFuc2xhdGUocmVuZGVySW5mby5jdXRTeCwgcmVu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SB0aGlzLm1lYXN1cmVUZXh0KHdvcmQuc3Vic3RyaW5nKDAsIGN1dG9mZkluZGV4KSkgKyBzdWZmaXhXaWR0aDtcbiAgICAgICAgICAgICAgICBpZiAodHJ1bmNXb3JkV2lkdGggPiB3b3JkV3JhcFdpZHRoKSB7XG4gICAgICAgICAgICAgICAgICAgIGN1dG9mZkluZGV4IC09IDE7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgIC8qIEluIGNhc2UgZ3Vlc3Mgd2FzIHVuZGVyZXN0aW1hdGVkLCBleHRlbmQgaXQgbGV0dGVyIGJ5IGxldHRlci4gKi9cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHdoaWxlIChjdXRvZmZJbmRleCA8IHdvcmRMZW4pIHtcbiAgICAgICAgICAgICAgICB0cnVuY1dvcmRXaWR0aCA9IHRoaXMubWVhc3VyZVRleHQod29yZC5zdWJzdHJpbmcoMCwgY3V0b2ZmSW5kZXgpKSArIHN1ZmZpeFdpZHRoO1xuICAgICAgICAgICAgICAgIGlmICh0cnVuY1dvcmRXaWR0aCA8IHdvcmRXcmFwV2lkdGgpIHtcbiAgICAgICAgICAgICAgICAgICAgY3V0b2ZmSW5kZXggKz0gMTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAvLyBGaW5hbGx5LCB3aGVuIGJvdW5kIGlzIGNyb3NzZWQsIHJldHJhY3QgbGFzdCBsZXR0ZXIuXG4gICAgICAgICAgICAgICAgICAgIGN1dG9mZkluZGV4IC09MTtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgLyogSWYgd3JhcFdpZHRoIGlzIHRvbyBzaG9ydCB0byBldmVuIGNvbnRh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ICAgIGlmIChVdGlscy5pc1dlYiAmJiBkb2N1bWVudC5mb250cykge1xuICAgICAgICAgICAgY29uc3QgZm9udFNldHRpbmcgPSBnZXRGb250U2V0dGluZyhcbiAgICAgICAgICAgICAgICB0aGlzLl9zZXR0aW5ncy5mb250RmFjZSxcbiAgICAgICAgICAgICAgICB0aGlzLl9zZXR0aW5ncy5mb250U3R5bGUsXG4gICAgICAgICAgICAgICAgdGhpcy5fc2V0dGluZ3MuZm9udFNpemUsXG4gICAgICAgICAgICAgICAgdGhpcy5nZXRQcmVjaXNpb24oKSxcbiAgICAgICAgICAgICAgICB0aGlzLl9zdGFnZS5nZXRPcHRpb24oJ2RlZmF1bHRGb250RmFjZScpXG4gICAgICAgICAgICApO1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmZvbnRzLmNoZWNrKGZvbnRTZXR0aW5nLCB0aGlzLl9zZXR0aW5ncy50ZXh0KSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBVc2UgYSBwcm9taXNlIHRoYXQgd2FpdHMgZm9yIGxvYWRpbmcuXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBkb2N1bWVudC5mb250cy5sb2FkKGZvbnRTZXR0aW5nLCB0aGlzLl9zZXR0aW5ncy50ZXh0KS5jYXRjaChlcnIgPT4ge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gSnVzdCBsb2FkIHRoZSBmYWxsYmFjayBmb250LlxuICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS53YXJuKCdGb250IGxvYWQgZXJyb3InLCBlcnIsIGZvbnRTZXR0aW5nKTtcbiAgICAgICAgICAgICAgICAgICAgfSkudGhlbigoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmZvbnRzLmNoZWNrKGZvbnRTZXR0aW5nLCB0aGlzLl9zZXR0aW5ncy50ZXh0KSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybignRm9udCBub3QgZm91bmQnLCBmb250U2V0dGluZyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gY2F0Y2goZSkge1xuICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybihcIkNhbid0IGNoZWNrIGZvbnQgbG9hZGluZyBmb3IgXCIgKyBmb250U2V0dGluZyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBkcmF3KCkge1xuICAgICAgICAvLyBXZSBkbyBub3QgdXNlIGEgcHJvbWlzZSBzbyB0aGF0IGxvYWRpbmcgaXMgcGVyZm9ybWVkIHN5bmNyb25vdXMgd2hlbiBwb3NzaWJsZS5cbiAgICAgICAgY29uc3QgbG9hZFByb21pc2UgPSB0aGlzLl9sb2FkKCk7XG4gICAgICAgIGlmICghbG9hZFByb21pc2UpIHtcbiAgICAgICAgICAgIHJldHVybiBVdGlscy5pc1NwYXJrID8gdGhpcy5fc3RhZ2UucGxhdGZvcm0uZHJhd1RleHQodGhpcykgOiB0aGlzLl9kcmF3KCk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gbG9hZFByb21pc2UudGhlbigoKSA9PiB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIFV0aWxzLmlzU3BhcmsgPyB0aGlzLl9zdGFnZS5wbGF0Zm9ybS5kcmF3VGV4dCh0aGlzKSA6IHRoaXMuX2RyYXcoKTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2NhbGN1bGF0ZVJlbmRlckluZm8oKSB7XG4gICAgICAgIGxldCByZW5kZXJJbmZvID0ge307XG5cbiAgICAgICAgY29uc3QgcHJlY2lzaW9uID0gdGhpcy5nZXRQcmVjaXNpb24oKTtcblxuICAgICAgICBjb25zdCBwYWRkaW5nTGVmdCA9IHRoaX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ICAgY29uc3QgbGV0dGVyU3BhY2luZyA9IHRoaXMuX3NldHRpbmdzLmxldHRlclNwYWNpbmcgfHwgMDtcblxuICAgICAgICAvLyBTZXQgZm9udCBwcm9wZXJ0aWVzLlxuICAgICAgICByZW5kZXJJbmZvLmJhc2VGb250ID0gdGhpcy5zZXRGb250UHJvcGVydGllcygpO1xuXG4gICAgICAgIHJlbmRlckluZm8udyA9IHc7XG4gICAgICAgIHJlbmRlckluZm8ud2lkdGggPSB3O1xuICAgICAgICByZW5kZXJJbmZvLnRleHQgPSB0aGlzLl9zZXR0aW5ncy50ZXh0O1xuICAgICAgICByZW5kZXJJbmZvLnByZWNpc2lvbiA9IHByZWNpc2lvbjtcbiAgICAgICAgcmVuZGVySW5mby5mb250U2l6ZSA9IGZvbnRTaXplO1xuICAgICAgICByZW5kZXJJbmZvLmZvbnRCYXNlbGluZVJhdGlvID0gdGhpcy5fc2V0dGluZ3MuZm9udEJhc2VsaW5lUmF0aW87XG4gICAgICAgIHJlbmRlckluZm8ubGluZUhlaWdodCA9IGxpbmVIZWlnaHQ7XG4gICAgICAgIHJlbmRlckluZm8ubGV0dGVyU3BhY2luZyA9IGxldHRlclNwYWNpbmc7XG4gICAgICAgIHJlbmRlckluZm8udGV4dEFsaWduID0gdGhpcy5fc2V0dGluZ3MudGV4dEFsaWduO1xuICAgICAgICByZW5kZXJJbmZvLnRleHRDb2xvciA9IHRoaXMuX3NldHRpbmdzLnRleHRDb2xvcjtcbiAgICAgICAgcmVuZGVySW5mby52ZXJ0aWNhbEFsaWduID0gdGhpcy5fc2V0dGluZ3MudmVydGljYWxBbGlnbjtcbiAgICAgICAgcmVuZGVySW5mby5oaWdobGlnaHQgPSB0aGlzLl9zZXR0aW5ncy5oaWdobGlnaHQ7XG4gICAgICAgIHJlbmRlckluZm8uaGlnaGxpZ2h0Q29sb3IgPSB0aGlzLl9zZXR0aW5ncy5oaWdobGlnaHRDb2xvcjtcbiAgICAgICAgcmVuZGVySW5mby5oaWdobGl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CA9ICcnO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBjYXNlICdlbGxpcHNpcyc6XG4gICAgICAgICAgICAgICAgICAgIHN1ZmZpeCA9IHRoaXMuX3NldHRpbmdzLm1heExpbmVzU3VmZml4O1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgICAgICBzdWZmaXggPSB0aGlzLl9zZXR0aW5ncy50ZXh0T3ZlcmZsb3c7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0ZXh0ID0gdGhpcy53cmFwV29yZCh0ZXh0LCB3b3JkV3JhcFdpZHRoIHx8IHJlbmRlckluZm8udywgc3VmZml4KTtcbiAgICAgICAgfVxuXG4gICAgICAgIHRleHQgPSB0aGlzLnRva2VuaXplKHRleHQpO1xuICAgICAgICB0ZXh0ID0gdGhpcy5wYXJzZSh0ZXh0KTtcbiAgICAgICAgdGV4dCA9IHRoaXMubWVhc3VyZSh0ZXh0LCBsZXR0ZXJTcGFjaW5nLCByZW5kZXJJbmZvLmJhc2VGb250KTtcblxuICAgICAgICBpZiAocmVuZGVySW5mby50ZXh0SW5kZW50KSB7XG4gICAgICAgICAgICB0ZXh0ID0gdGhpcy5pbmRlbnQodGV4dCwgcmVuZGVySW5mby50ZXh0SW5kZW50KTtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChyZW5kZXJJbmZvLndvcmRCcmVhaykge1xuICAgICAgICAgICAgdGV4dCA9IHRleHQucmVkdWNlKChhY2MsIHQpID0+IGFjYy5jb25jYXQodGhpcy53b3JkQnJlYWsodCwgd3JhcFdpZHRoLCByZW5kZXJJbmZvLmJhc2VGb250KSksIFtdKVxuICAgICAgICAgICAgdGhpcy5yZXNldEZvbnRTdHlsZSgpXG4gICAgICAgIH1cblxuICAgICAgICAvLyBDYWxjdWxhdGUgZGV0YWlsZWQgZHJhd2luZyBpbmZvcm1hdGlvblxuICAgICAgICBsZXQgeCA9IHBhZGRpbmdMZWZ0O1xuICAgICAgICBsZXQgbGluZU5vID0gMDtcblxuICAgICAgICBmb3IgKGNvbnN0IHQgb2YgdGV4dCkge1xuICAgICAgICAgICAgLy8gV3JhcCB0ZXh0XG4gICAgICAgICAgICBpZiAocmVuZGVySW5mby53b3JkV3JhcCAmJiB4ICsgdC53aWR0aCA+IHdyYXBXaWR0aCB8fCB0LnRleHQgPT0gJ1xcbicpIHtcbiAgICAgICAgICAgICAgICB4ID0gcGFkZGluZ0xlZnQ7XG4gICAgICAgICAgICAgICAgbGluZU5vICs9IDE7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0LmxpbmVObyA9IGxpbmVObztcblxuICAgICAgICAgICAgaWYgKHQudGV4dCA9PSAnXFxuJykge1xuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0LnggPSB4O1xuICAgICAgICAgICAgeCArPSB0LndpZHRoO1xuICAgICAgICB9XG4gICAgICAgIHJlbmRlckluZm8ubGluZU51bSA9IGxpbmVObyArIDE7XG5cbiAgICAgICAgaWYgKHRoaXMuX3NldHRpbmdzLmgpIHtcbiAgICAgICAgICAgIHJlbmRlckluZm8uaCA9IHRoaXMuX3NldHRpbmdzLmg7XG4gICAgICAgIH0gZWxzZSBpZiAocmVuZGVySW5mby5tYXhMaW5lcyAmJiByZW5kZXJJbmZvLm1heExpbmVzIDwgcmVuZGVySW5mby5saW5lTnVtKSB7XG4gICAgICAgICAgICByZW5kZXJJbmZvLmggPSByZW5kZXJJbmZvLm1heExpbmVzICogcmVuZGVySW5mby5saW5lSGVpZ2h0ICsgZm9udFNpemUgLyAyO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmVuZGVySW5mby5oID0gcmVuZGVySW5mby5saW5lTnVtICogcmVuZGVySW5mby5saW5lSGVpZ2h0ICsgZm9udFNpemUgLyAyO1xuICAgICAgICB9XG5cbiAgICAgICAgL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plIC0gYmFzZWxpbmVPZmZzZXRJblB4KSAvIDI7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5fc2V0dGluZ3MudmVydGljYWxBbGlnbiA9PSAnYm90dG9tJykge1xuICAgICAgICAgICAgdmFPZmZzZXQgPSByZW5kZXJJbmZvLmxpbmVIZWlnaHQgLSByZW5kZXJJbmZvLmZvbnRTaXplO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gQ2FsY3VsYXRlIGxpbmVzIGluZm9ybWF0aW9uXG4gICAgICAgIHJlbmRlckluZm8ubGluZXMgPSBbXVxuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHJlbmRlckluZm8ubGluZU51bTsgaSsrKSB7XG4gICAgICAgICAgICByZW5kZXJJbmZvLmxpbmVzW2ldID0ge1xuICAgICAgICAgICAgICAgIHdpZHRoOiAwLFxuICAgICAgICAgICAgICAgIHg6IDAsXG4gICAgICAgICAgICAgICAgeTogcmVuZGVySW5mby5saW5lSGVpZ2h0ICogaSArIHZhT2Zmc2V0LFxuICAgICAgICAgICAgICAgIHRleHQ6IFtdLFxuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgZm9yIChsZXQgdCBvZiB0ZXh0KSB7XG4gICAgICAgICAgICByZW5kZXJJbmZvLmxpbmVzW3QubGluZU5vXS50ZXh0LnB1c2godCk7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBGaWx0ZXIgb3V0IHdoaXRlIHNwYWNlcyBhdCBiZWdpbm5pbmcgYW5kIGVuZCBvZiBlYWNoIGxpbmVcbiAgICAgICAgZm9yIChjb25zdCBsIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgICAgICAgIGlmIChsLnRleHQubGVuZ3RoID09IDApIHtcbiAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgY29uc3QgZmlyc3RXb3JkID0gbC50ZXh0WzBdLnRleHQ7XG4gICAgICAgICAgICBjb25zdCBsYXN0V29yZCA9IGwudGV4dFtsLnRleHQubGVuZ3RoIC0gMV0udGV4dDtcblxuICAgICAgICAgICAgaWYgKGZpcnN0V29yZCA9PSAnXFxuJykge1xuICAgICAgICAgICAgICAgIGwudGV4dC5zaGlmdCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKGlzU3BhY2UobGFzdFdvcmQpIHx8IGxhc3RXb3JkID09ICdcXG4nKSB7XG4gICAgICAgICAgICAgICAgbC50ZXh0LnBvcCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cblxuICAgICAgICAvLyBDYWxjdWxhdGUgbGluZSB3aWR0aFxuICAgICAgICBmb3IgKGxldCBsIG9mIHJlbmRlckluZm8ubGluZXMpIHtcbiAgICAgICAgICAgIGwud2lkdGggPSBsLnRleHQucmVkdWNlKChhY2MsIHQpID0+IGFjYyArIHQud2lkdGgsIDApO1xuICAgICAgICB9XG5cbiAgICAgICAgcmVuZGVySW5mby53aWR0aCA9IHRoaXMuX3NldHRpbmdzLncgIT0gMCA/IHRoaXMuX3NldHRpbmdzLncgKiBwcmVjaXNpb24gOiBNYXRoLm1heCguLi5yZW5kZXJJbmZvLmxpbmVzLm1hcCgobCkgPT4gbC53aWR0aCkpICsgcGFkZGluZ1JpZ2h0O1xuICAgICAgICByZW5kZXJJbmZvLncgPSByZW5kZXJJbmZvLndpZHRoO1xuXG4gICAgICAgIC8vIEFwcGx5IG1heExpbmVzU3VmZml4XG4gICAgICAgIGlmIChyZW5kZXJJbmZvLm1heExpbmVzICYmIHJlbmRlckluZm8ubGluZU51bSA+IHJlbmRlckluZm8ubWF4TGluZXMgJiYgcmVuZGVySW5mby5tYXhMaW5lc1N1ZmZpeCkge1xuICAgICAgICAgICAgY29uc3QgaW5kZXggPSByZW5kZXJJbmZvLm1heExpbmVzIC0gMTtcbiAgICAgICAgICAgIGxldCBsYXN0TGluZVRleHQgPSB0ZXh0LmZpbHRlcigodCkgPT4gdC5saW5lTm8gPT0gaW5kZXgpXG4gICAgICAgICAgICBsZXQgc3VmZml4ID0gcmVuZGVySW5mby5tYXhMaW5lc1N1ZmZpeDtcbiAgICAgICAgICAgIHN1ZmZpeCA9IHRoaXMudG9rZW5pemUoc3VmZml4KTtcbiAgICAgICAgICAgIHN1ZmZpeCA9IHRoaXMucGFyc2Uoc3VmZml4KTtcbiAgICAgICAgICAgIHN1ZmZpeCA9IHRoaXMubWVhc3VyZShzdWZmaXgsIHJlbmRlckluZm8ubGV0dGVyU3BhY2luZywgcmVuZGVySW5mby5iYXNlRm9udCk7XG4gICAgICAgICAgICBmb3IgKGNvbnN0IHMgb2Ygc3VmZml4KSB7XG4gICAgICAgICAgICAgICAgcy5saW5lTm8gPSBpbmRleDtcbiAgICAgICAgICAgICAgICBzLnggPSAwO1xuICAgICAgICAgICAgICAgIGxhc3RMaW5lVGV4dC5wdXNoKHMpXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGNvbnN0IHNwbCA9IHN1ZmZpeC5sZW5ndGggKyAxXG4gICAgICAgICAgICBsZXQgX3cgPSBsYXN0TGluZVRleHQucmVkdWNlKChhY2MsIHQpID0+IGFjYyArIHQud2lkdGgsIDApO1xuICAgICAgICAgICAgd2hpbGUgKF93ID4gcmVuZGVySW5mby53aWR0aCB8fCBpc1NwYWNlKGxhc3RMaW5lVGV4dFtsYXN0TGluZVRleHQubGVuZ3RoIC0gc3BsXS50ZXh0KSkge1xuICAgICAgICAgICAgICAgIGxhc3RMaW5lVGV4dC5zcGxpY2UobGFzdExpbmVUZXh0Lmxlbmd0aCAtIHNwbCwgMSk7XG4gICAgICAgICAgICAgICAgX3cgPSBsYXN0TGluZVRleHQucmVkdWNlKChhY2MsIHQpID0+IGFjYyArIHQud2lkdGgsIDApO1xuICAgICAgICAgICAgICAgIGlmIChsYXN0TGluZVRleHQubGVuZ3RoIDwgc3BsKSB7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAg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C5saW5lTm8gPj0gcmVuZGVySW5mby5tYXhMaW5lcykge1xuICAgICAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAodC5jb2xvciAhPSBjdXJyZW50Q29sb3IpIHtcbiAgICAgICAgICAgICAgICAgICAgY3VycmVudENvbG9yID0gdC5jb2xvcjtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fY29udGV4dC5maWxsU3R5bGUgPSBjdXJyZW50Q29sb3I7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgdGhpcy5fY29udGV4dC5mb250ID0gdC5mb250U3R5bGU7XG5cbiAgICAgICAgICAgICAgICAvLyBEcmF3IHdpdGggbGV0dGVyIHNwYWNpbmdcbiAgICAgICAgICAgICAgICBpZiAodC5sZXR0ZXJzKSB7XG4gICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGwgb2YgdC5sZXR0ZXJzKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBfeCA9IHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnggKyB0LnggKyBseDtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuZmlsbFRleHQobC50ZXh0LCBfeCwgcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10ueSArIHJlbmRlckluZm8uZm9udFNpemUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgbHggKz0gbC53aWR0aDtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIC8vIFN0YW5kYXJkIGRyYXdpbmdcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBfeCA9IHJlbmRlckluZm8ubGluZXNbdC5saW5lTm9dLnggKyB0Lng7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuZmlsbFRleHQodC50ZXh0LCBfeCwgcmVuZGVySW5mby5saW5lc1t0LmxpbmVOb10ueSArIHJlbmRlckluZm8uZm9udFNpemUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIC8vIFJlc2V0IHRleHQgc2hhZG93XG4gICAgICAgIGlmIChwcmV2U2hhZG93U2V0dGluZ3MpIHtcbiAgICAgICAgICAgIHRoaXMuX2NvbnRleHQuc2hhZG93Q29sb3IgPSBwcmV2U2hhZG93U2V0dGluZ3NbMF07XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd09mZnNldFggPSBwcmV2U2hhZG93U2V0dGluZ3NbMV07XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd09mZnNldFkgPSBwcmV2U2hhZG93U2V0dGluZ3NbMl07XG4gICAgICAgICAgICB0aGlzLl9jb250ZXh0LnNoYWRvd0JsdXIgPSBwcmV2U2hhZG93U2V0dGluZ3NbM107XG4gICAgICAgIH1cblxuICAgICAgICAvLyBSZXNldCBjdXQgdHJhbnNsYXRpb25cbiAgICAgICAgaWYgKHJlbmRlckluZm8uY3V0U3ggfHwgcmVuZGVySW5mby5jdXRTeSkge1xuICAgICAgICAgICAgdGhpcy5fY29udGV4dC50cmFuc2xhdGUocmVuZGVySW5mby5jdXRTeCwgcmVuZGVySW5mby5jdXRTeSk7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBQb3N0cHJvY2VzcyByZW5kZXJJbmZvLmxpbmVzIHRvIGJlIGNvbXBhdGlibGUgd2l0aCBzdGFuZGFyZCB2ZXJzaW9uXG4gICAgICAgIHJlbmRlckluZm8ubGluZXMgPSByZW5kZXJJbmZvLmxpbmVzLm1hcCgobCkgPT4gbC50ZXh0LnJlZHVjZSgoYWNjLCB2KSA9PiBhY2MgKyB2LnRleHQsICcnKSk7XG4gICAgICAgIGlmIChyZW5kZXJJbmZvLm1heExpbmVzKSB7XG4gICAgICAgICAgICByZW5kZXJJbmZvLmxpbmVzID0gcmVu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biAgICAgICAgICAgICAgICB0ID0gJyc7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHQgPT0gJzwvaT4nICYmIGl0YWxpYyA+IDApIHtcbiAgICAgICAgICAgICAgICBpdGFsaWMgLT0gMTtcbiAgICAgICAgICAgICAgICB0ID0gJyc7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHQgPT0gJzxiPicpIHtcbiAgICAgICAgICAgICAgICBib2xkICs9IDE7XG4gICAgICAgICAgICAgICAgdCA9ICcnO1xuICAgICAgICAgICAgfSBlbHNlIGlmICh0ID09ICc8L2I+JyAmJiBib2xkID4gMCkge1xuICAgICAgICAgICAgICAgIGJvbGQgLT0gMTtcbiAgICAgICAgICAgICAgICB0ID0gJyc7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHQgPT0gJzwvY29sb3I+Jykge1xuICAgICAgICAgICAgICAgIGlmIChjb2xvclN0YWNrLmxlbmd0aCA+IDEpIHtcbiAgICAgICAgICAgICAgICAgICAgY29sb3IgLT0gMTtcbiAgICAgICAgICAgICAgICAgICAgY29sb3JTdGFjay5wb3AoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdCA9ICcnO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChjb2xvclJlZ2V4cC50ZXN0KHQpKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgbWF0Y2hlZCA9IGNvbG9yUmVnZXhwLmV4ZWModCk7XG4gICAgICAgICAgICAgICAgY29sb3JTdGFjay5wdXNoKFxuICAgICAgICAgICAgICAgICAgICBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcocGFyc2VJbnQobWF0Y2hlZFsxXSkpXG4gICAgICAgICAgICAgICAgKTtcbiAgICAgICAgICAgICAgICBjb2xvciArPSAxO1xuICAgICAgICAgICAgICAgIHQgPSAnJztcblxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgIHRleHQ6IHQsXG4gICAgICAgICAgICAgICAgaXRhbGljOiBpdGFsaWMsXG4gICAgICAgICAgICAgICAgYm9sZDogYm9sZCxcbiAgICAgICAgICAgICAgICBjb2xvcjogY29sb3JTdGFja1tjb2xvcl0sXG4gICAgICAgICAgICB9XG4gICAgICAgIH0pXG4gICAgICAgIC5maWx0ZXIoKG8pID0+IG8udGV4dCAhPSAnJyk7XG4gICAgfVxuXG4gICAgYXBwbHlGb250U3R5bGUod29yZCwgYmFzZUZvbnQpIHtcbiAgICAgICAgbGV0IGZvbnQgPSBiYXNlRm9udDtcbiAgICAgICAgaWYgKHdvcmQuYm9sZCkge1xuICAgICAgICAgICAgZm9udCA9ICdib2xkICcgKyBmb250O1xuICAgICAgICB9XG4gICAgICAgIGlmICh3b3JkLml0YWxpYykge1xuICAgICAgICAgICAgZm9udCA9ICdpdGFsaWMgJyArIGZvbnQ7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fY29udGV4dC5mb250ID0gZm9udFxuICAgICAgICB3b3JkLmZvbnRTdHlsZSA9IGZvbnQ7XG4gICAgfVxuXG4gICAgcmVzZXRGb250U3R5bGUoYmFzZUZvbnQpIHtcbiAgICAgICAgdGhpcy5fY29udGV4dC5mb250ID0gYmFzZUZvbnQ7XG4gICAgfVxuXG4gICAgbWVhc3VyZShwYXJzZWQsIGxldHRlclNwYWNpbmcgPSAwLCBiYXNlRm9udCkge1xuICAgICAgICBmb3IgKGNvbnN0IHAgb2YgcGFyc2VkKSB7XG4gICAgICAgICAgICB0aGlzLmFwcGx5Rm9udFN0eWxlKHAsIGJhc2VGb250KTtcbiAgICAgICAgICAgIHAud2lkdGggPSB0aGlzLm1lYXN1cmVUZXh0KHAudGV4dCwgbGV0dGVyU3BhY2luZyk7XG5cbiAgICAgICAgICAgIC8vIExldHRlciBieSBsZXR0ZXIgZGV0YWlsIGZvciBsZXR0ZXIgc3BhY2luZ1xuICAgICAgICAgICAgaWYgKGxldHRlclNwYWNpbmcgPiAwKSB7XG4gICAgICAgICAgICAgICAg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J1bmNXb3JkV2lkdGggPCB3b3JkV3JhcFdpZHRoKSB7XG4gICAgICAgICAgICAgICAgICAgIGN1dG9mZkluZGV4ICs9IDE7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gRmluYWxseSwgd2hlbiBib3VuZCBpcyBjcm9zc2VkLCByZXRyYWN0IGxhc3QgbGV0dGVyLlxuICAgICAgICAgICAgICAgICAgICBjdXRvZmZJbmRleCAtPTE7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIC8qIElmIHdyYXBXaWR0aCBpcyB0b28gc2hvcnQgdG8gZXZlbiBjb250YWluIHN1ZmZpeCBhbG9uZSwgcmV0dXJuIGVtcHR5IHN0cmluZyAqL1xuICAgICAgICByZXR1cm4gd29yZC5zdWJzdHJpbmcoMCwgY3V0b2ZmSW5kZXgpICsgKHdvcmRXcmFwV2lkdGggPj0gc3VmZml4V2lkdGggPyBzdWZmaXggOiAnJylcbiAgICB9XG5cbiAgICBfZ2V0QnJlYWtJbmRleCh3b3JkLCB3aWR0aCkge1xuICAgICAgICBjb25zdCB3b3JkTGVuID0gd29yZC5sZW5ndGg7XG4gICAgICAgIGNvbnN0IHdvcmRXaWR0aCA9IHRoaXMubWVhc3VyZVRleHQod29yZCk7XG5cbiAgICAgICAgaWYgKHdvcmRXaWR0aCA8PSB3aWR0aCkge1xuICAgICAgICAgICAgcmV0dXJuIHticmVha0luZGV4OiB3b3JkLmxlbmd0aCwgdHJ1bmNXb3JkV2lkdGg6IHdvcmRXaWR0aH07XG4gICAgICAgIH1cblxuICAgICAgICBsZXQgYnJlYWtJbmRleCA9IE1hdGguZmxvb3IoKHdpZHRoICogd29yZExlbikgLyB3b3JkV2lkdGgpO1xuICAgICAgICBsZXQgdHJ1bmNXb3JkV2lkdGggPSB0aGlzLm1lYXN1cmVUZXh0KHdvcmQuc3Vic3RyaW5nKDAsIGJyZWFrSW5kZXgpKVxuXG4gICAgICAgIC8qIEluIGNhc2UgZ3Vlc3Mgd2FzIG92ZXJlc3RpbWF0ZWQsIHNocmluayBpdCBsZXR0ZXIgYnkgbGV0dGVyLiAqL1xuICAgICAgICBpZiAodHJ1bmNXb3JkV2lkdGggPiB3aWR0aCkge1xuICAgICAgICAgICAgd2hpbGUgKGJyZWFrSW5kZXggPiAwKSB7XG4gICAgICAgICAgICAgICAgdHJ1bmNXb3JkV2lkdGggPSB0aGlzLm1lYXN1cmVUZXh0KHdvcmQuc3Vic3RyaW5nKDAsIGJyZWFrSW5kZXgpKTtcbiAgICAgICAgICAgICAgICBpZiAodHJ1bmNXb3JkV2lkdGggPiB3aWR0aCkge1xuICAgICAgICAgICAgICAgICAgICBicmVha0luZGV4IC09IDE7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgIC8qIEluIGNhc2UgZ3Vlc3Mgd2FzIHVuZGVyZXN0aW1hdGVkLCBleHRlbmQgaXQgbGV0dGVyIGJ5IGxldHRlci4gKi9cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHdoaWxlIChicmVha0luZGV4IDwgd29yZExlbikge1xuICAgICAgICAgICAgICAgIHRydW5jV29yZFdpZHRoID0gdGhpcy5tZWFzdXJlVGV4dCh3b3JkLnN1YnN0cmluZygwLCBicmVha0luZGV4KSk7XG4gICAgICAgICAgICAgICAgaWYgKHRydW5jV29yZFdpZHRoIDwgd2lkdGgpIHtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWtJbmRleCArPSAxO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIEZpbmFsbHksIHdoZW4gYm91bmQgaXMgY3Jvc3NlZCwgcmV0cmFjdCBsYXN0IGxldHRlci5cbiAgICAgICAgICAgICAgICAgICAgYnJlYWtJbmRleCAtPTE7XG4gICAgICAgICAgICAgICAgICAgIHRydW5jV29yZFdpZHRoID0gdGhpcy5tZWFzdXJlVGV4dCh3b3JkLnN1YnN0cmluZygwLCBicmVha0luZGV4KSk7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4ge2JyZWFrSW5kZXgsIHRydW5jV29yZFdpZHRofTtcblxuICAgIH1cblxuICAgIHdvcmRCcmVhayh3b3JkLCB3aWR0aCwgYmFzZUZvbnQpIHtcbiAgICAgICAgaWYgKCF3b3JkLnRleHQpIHtcbiAgICAgICAgICAgIHJldHVybiB3b3JkXG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5hcHBseUZvbnRTdHlsZSh3b3JkLCBiYXNlRm9udClcbiAgICAgICAgY29uc3QgcGFydHMgPSBbXTtcbiAgICAgICAgbGV0IHRleHQgPSB3b3JkLnRleHQ7XG4gICAgICAgIGlmICghd29yZC5sZXR0ZXJzKSB7XG4gICAgICAgICAgICB3aGlsZSAodHJ1ZSkge1xuICAgICAgICAgICAgICAgIGNvbnN0IHticmVha0luZGV4LCB0cnVuY1dvcmRXaWR0aH0gPSB0aGlzLl9nZXRCcmVha0luZGV4KHRleHQsIHdpZHRoKTtcbiAgICAgICAgICAgICAgICBwYXJ0cy5wdXNoKHsuLi53b3JkfSk7XG4gICAgICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0udGV4dCA9IHRleHQuc2xpY2UoMCwgYnJlYWtJbmRleCk7XG4gICAgICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ud2lkdGggPSB0cnVuY1dvcmRXaWR0aDtcblxuICAgICAgICAgICAgICAgIGlmIChicmVha0luZGV4ID09PSB0ZXh0Lmxlbmd0aCkge1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICB0ZXh0ID0gdGV4dC5zbGljZShicmVha0luZGV4KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGxldCB0b3RhbFdpZHRoID0gMDtcbiAgICAgICAgICAgIGxldCBsZXR0ZXJzID0gW107XG4gICAgICAgICAgICBsZXQgYnJlYWtJbmRleCA9IDA7XG4gICAgICAgICAgICBmb3IgKGNvbnN0IGwgb2Ygd29yZC5sZXR0ZXJzKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRvdGFsV2lkdGggKyBsLndpZHRoID49IHdpZHRoKSB7XG4gICAgICAgICAgICAgICAgICAgIHBhcnRzLnB1c2goey4uLndvcmR9KTtcbiAgICAgICAgICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0udGV4dCA9IHRleHQuc2xpY2UoMCwgYnJlYWtJbmRleCk7XG4gICAgICAgICAgICAgICAgICAgIHBhcnRzW3BhcnRzLmxlbmd0aCAtIDFdLndpZHRoID0gdG90YWxXaWR0aDtcbiAgICAgICAgICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ubGV0dGVycyA9IGxldHRlcnM7XG4gICAgICAgICAgICAgICAgICAgIHRleHQgPSB0ZXh0LnNsaWNlKGJyZWFrSW5kZXgpO1xuICAgICAgICAgICAgICAgICAgICB0b3RhbFdpZHRoID0gMDtcbiAgICAgICAgICAgICAgICAgICAgbGV0dGVycyA9IFtdO1xuICAgICAgICAgICAgICAgICAgICBicmVha0luZGV4ID0gMDtcblxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrSW5kZXggKz0gMTtcbiAgICAgICAgICAgICAgICAgICAgbGV0dGVycy5wdXNoKGwpO1xuICAgICAgICAgICAgICAgICAgICB0b3RhbFdpZHRoICs9IGwud2lkdGg7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAodG90YWxXaWR0aCA+IDApIHtcbiAgICAgICAgICAgICAgICBwYXJ0cy5wdXNoKHsuLi53b3JkfSk7XG4gICAgICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0udGV4dCA9IHRleHQuc2xpY2UoMCwgYnJlYWtJbmRleCk7XG4gICAgICAgICAgICAgICAgcGFydHNbcGFydHMubGVuZ3RoIC0gMV0ud2lkdGggPSB0b3RhbFdpZHRoO1xuICAgICAgICAgICAgICAgIHBhcnRzW3BhcnRzLmxlbmd0aCAtIDFdLmxldHRlcnMgPSBsZXR0ZXJzO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIHBhcnRzO1xuICAgIH1cblxuICAgIGFsaWduTGluZShwYXJzZWQsIGluaXRpYWxYID0gMCkge1xuICAgICAgICBsZXQgcHJldldpZHRoID0gMDtcbiAgICAgICAgbGV0IHByZXZYID0gaW5pdGlhbFg7XG4gICAgICAgIGZvciAoY29uc3Qgd29yZCBvZiBwYXJzZWQpIHtcbiAgICAgICAgICAgIGlmICh3b3JkLnRleHQgPT0gJ1xcbicpIHtcbiAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHdvcmQueCA9IHByZXZYICsgcHJldldpZHRoO1xuICAgICAgICAgICAgcHJldlggPSB3b3JkLng7XG4gICAgICAgICAgICBwcmV2V2lkdGggPSB3b3JkLndpZHRoO1xuICAgICAgICB9XG5cbiAgICB9XG59IiwiLypcbiAqIElmIG5vdCBzdGF0ZWQgb3RoZXJ3aXNlIGluIHRoaXMgZmlsZSBvciB0aGlzIGNvbXBvbmVudCdzIExJQ0VOU0UgZmlsZSB0aGVcbiAqIGZvbGxvd2luZyBjb3B5cmlnaHQgYW5kIGxpY2Vuc2VzIGFwcGx5OlxuICpcbiAqIENvcHlyaWdodCAyMDIwIE1ldHJvbG9naWNhbFxuIC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dChjb250ZXh0LCBzcGFjZSwgbGV0dGVyU3BhY2luZyk7XG4gICAgICAgICAgICBpZiAoaiA9PT0gMCB8fCB3b3JkV2lkdGhXaXRoU3BhY2UgPiBzcGFjZUxlZnQpIHtcbiAgICAgICAgICAgICAgICAvLyBTa2lwIHByaW50aW5nIHRoZSBuZXdsaW5lIGlmIGl0J3MgdGhlIGZpcnN0IHdvcmQgb2YgdGhlIGxpbmUgdGhhdCBpcy5cbiAgICAgICAgICAgICAgICAvLyBncmVhdGVyIHRoYW4gdGhlIHdvcmQgd3JhcCB3aWR0aC5cbiAgICAgICAgICAgICAgICBpZiAoaiA+IDApIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0TGluZXMucHVzaChyZXN1bHQpO1xuICAgICAgICAgICAgICAgICAgICByZXN1bHQgPSAnJztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmVzdWx0ICs9IHdvcmQ7XG4gICAgICAgICAgICAgICAgc3BhY2VMZWZ0ID0gd29yZFdyYXBXaWR0aCAtIHdvcmRXaWR0aCAtIChqID09PSAwID8gaW5kZW50IDogMCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICBzcGFjZUxlZnQgLT0gd29yZFdpZHRoV2l0aFNwYWNlO1xuICAgICAgICAgICAgICAgIHJlc3VsdCArPSBzcGFjZSArIHdvcmQ7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmVzdWx0TGluZXMucHVzaChyZXN1bHQpO1xuICAgICAgICByZXN1bHQgPSAnJztcbiAgICAgICAgYWxsTGluZXMgPSBhbGxMaW5lcy5jb25jYXQocmVzdWx0TGluZXMpO1xuICAgICAgICBpZiAoaSA8IGxpbmVzLmxlbmd0aCAtIDEpIHtcbiAgICAgICAgICAgIHJlYWxOZXdsaW5lcy5wdXNoKGFsbExpbmVzLmxlbmd0aCk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgcmV0d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1bmRlciB0aGUgTGljZW5zZS5cbiAqL1xuXG5pbXBvcnQgVXRpbHMgZnJvbSBcIi4uL3RyZWUvVXRpbHMubWpzXCI7XG5cbmV4cG9ydCBkZWZhdWx0IGNsYXNzIE11bHRpU3BsaW5lIHtcblxuICAgIGNvbnN0cnVjdG9yKCkge1xuICAgICAgICB0aGlzLl9jbGVhcigpO1xuICAgIH1cblxuICAgIF9jbGVhcigpIHtcbiAgICAgICAgdGhpcy5fcCA9IFtdO1xuICAgICAgICB0aGlzLl9wZSA9IFtdO1xuICAgICAgICB0aGlzLl9pZHAgPSBbXTtcbiAgICAgICAgdGhpcy5fZiA9IFtdO1xuICAgICAgICB0aGlzLl92ID0gW107XG4gICAgICAgIHRoaXMuX2x2ID0gW107XG4gICAgICAgIHRoaXMuX3NtID0gW107XG4gICAgICAgIHRoaXMuX3MgPSBbXTtcbiAgICAgICAgdGhpcy5fdmUgPSBbXTtcbiAgICAgICAgdGhpcy5fc21lID0gW107XG4gICAgICAgIHRoaXMuX3NlID0gW107XG5cbiAgICAgICAgdGhpcy5fbGVuZ3RoID0gMDtcbiAgICB9XG5cbiAgICBwYXJzZShyZ2JhLCBkZWYpIHtcbiAgICAgICAgbGV0IGksIG47XG4gICAgICAgIGlmICghVXRpbHMuaXNPYmplY3RMaXRlcmFsKGRlZikpIHtcbiAgICAgICAgICAgIGRlZiA9IHswOiBkZWZ9XG4gICAgICAgIH1cblxuICAgICAgICBsZXQgZGVmYXVsdFNtb290aG5lc3MgPSAwLjU7XG5cbiAgICAgICAgbGV0IGl0ZW1zID0gW107XG4gICAgICAgIGZvciAobGV0IGtleSBpbiBkZWYpIHtcbiAgICAgICAgICAgIGlmIChkZWYuaGFzT3duUHJvcGVydHkoa2V5KSkge1xuICAgICAgICAgICAgICAgIGxldCBvYmogPSBkZWZba2V5XTtcbiAgICAgICAgICAgICAgICBpZiAoIVV0aWxzLmlzT2JqZWN0TGl0ZXJhbChvYmopKSB7XG4gICAgICAgICAgICAgICAgICAgIG9iaiA9IHt2OiBvYmp9XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgbGV0IHAgPSBwYXJzZUZsb2F0KGtleSk7XG5cbiAgICAgICAgICAgICAgICBpZiAoa2V5ID09PSBcInNtXCIpIHtcbiAgICAgICAgICAgICAgICAgICAgZGVmYXVsdFNtb290aG5lc3MgPSBvYmoudjtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKCFpc05hTihwKSAmJiBwID49IDAgJiYgcCA8PSAyKSB7XG4gICAgICAgICAgICAgICAgICAgIG9iai5wID0gcDtcblxuICAgICAgICAgICAgICAgICAgICBvYmouZiA9IFV0aWxzLmlzRnVuY3Rpb24ob2JqLnYpO1xuICAgICAgICAgICAgICAgICAgICBvYmoubHYgPSBvYmouZiA/IG9iai52KDAsIDApIDogb2JqLnY7XG5cbiAgICAgICAgICAgICAgICAgICAgaXRlbXMucHVzaChvYmopO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIC8vIFNvcnQgYnkgcHJvZ3Jlc3MgdmFsdWUuXG4gICAgICAgIGl0ZW1zID0gaXRlbXMuc29ydChmdW5jdGlvbihhLCBiKSB7cmV0dXJuIGEucCAtIGIucH0pO1xuXG4gICAgICAgIG4gPSBpdGVtcy5sZW5ndGg7XG5cbiAgICAgICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgbGV0IGxhc3QgPSAoaSA9PT0gbiAtIDEpO1xuICAgICAgICAgICAgaWYgKCFpdGVtc1tpXS5oYXNPd25Qcm9wZXJ0eSgncGUnKSkge1xuICAgICAgICAgICAgICAgIC8vIFByb2dyZXNzLlxuICAgICAgICAgICAgICAgIGl0ZW1zW2ldLnBlID0gbGFzdCA/IChpdGVtc1tpXS5wIDw9IDEgPyAxIDogMiAvKiBzdXBwb3J0IG9uZXRvdHdvIHN0b3AgKi8pIDogaXRlbXNbaSArIDFdLnA7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIFByZXZlbnQgbXVsdGlwbGUgaXRlbXMgYXQgdGhlIHNhbWUgdGltZS5cbiAgICAgICAgICAgICAgICBjb25zdCBtYXggPSBpIDwgbiAtIDEgPyBpdGVtc1tpICsgMV0ucCA6IDE7XG4gICAgICAgICAgICAgICAgaWYgKGl0ZW1zW2ldLnBlID4gbWF4KSB7XG4gICAgICAgICAgICAgICAgICAgIGl0ZW1zW2ldLnBlID0gbWF4O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChpdGVtc1tpXS5wZSA9PT0gaXRlbXNbaV0ucCkge1xuICAgICAgICAgICAgICAgIGl0ZW1zW2ldLmlkcCA9IDA7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGl0ZW1zW2ldLmlkcCA9IDEgLyAoaXRlbXNbaV0ucGUgLSBpdGVtc1tpXS5wKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIC8vIENvbG9yIG1lcmdlcjogd2UgbmVlZCB0byBzcGxpdC9jb21iaW5lIFJHQkEgY29tcG9uZW50cy5cblxuICAgICAgICAvLyBDYWxjdWxhdGUgYmV6aWVyIGhlbHBlciB2YWx1ZXMuO1xuICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBpZiAoIWl0ZW1zW2ldLmhhc093blByb3BlcnR5KCdzbScpKSB7XG4gICAgICAgICAgICAgICAgLy8gU21vb3RobmVzcy47XG4gICAgICAgICAgICAgICAgaXRlbXNbaV0uc20gPSBkZWZhdWx0U21vb3RobmVzcztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoJ3MnKSkge1xuICAgICAgICAgICAgICAgIC8vIFNsb3BlLjtcbiAgICAgICAgICAgICAgICBpZiAoaSA9PT0gMCB8fCBpID09PSBuIC0gMSB8fCAoaXRlbXNbaV0ucCA9PT0gMSAvKiBmb3Igb25ldG90d28gKi8pKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIEhvcml6b250YWwgc2xvcGUgYXQgc3RhcnQgYW5kIGVuZC47XG4gICAgICAgICAgICAgICAgICAgIGl0ZW1zW2ldLnMgPSByZ2JhID8gWzAsIDAsIDAsIDBdIDogMDtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBwaSA9IGl0ZW1zW2kgLSAxXTtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgbmkgPSBpdGVtc1tpICsgMV07XG4gICAgICAgICAgICAgICAgICAgIGlmIChwaS5wID09PSBuaS5wKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpdGVtc1tpXS5zID0gcmdiYSA/IFswLCAwLCAwLCAwXSA6IDA7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAocmdiYSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IG5jID0gTXVsdGlTcGxpbmUuZ2V0UmdiYUNvbXBvbmVudHMobmkubHYpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IHBjID0gTXVsdGlTcGxpbmUuZ2V0UmdiYUNvbXBvbmVudHMocGkubHYpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGQgPSAxIC8gKG5pLnAgLSBwaS5wKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpdGVtc1tpXS5zID0gW1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkICogKG5jWzBdIC0gcGNbMF0pLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkICogKG5jWzFdIC0gcGNbMV0pLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkICogKG5jWzJdIC0gcGNbMl0pLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkICogKG5jWzNdIC0gcGNbM10pXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgXTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaXRlbXNbaV0ucyA9IChuaS5sdiAtIHBpLmx2KSAvIChuaS5wIC0gcGkucCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbiAtIDE7IGkrKykge1xuICAgICAgICAgICAgLy8gQ2FsY3VsYXRlIHZhbHVlIGZ1bmN0aW9uLjtcbiAgICAgICAgICAgIGlmICghaXRlbXNbaV0uZikge1xuXG4gICAgICAgICAgICAgICAgbGV0IGxhc3QgPSAoaSA9PT0gbiAtIDEpO1xuICAgICAgICAgICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoJ3ZlJykpIHtcbiAgICAgICAgICAgICAgICAgICAgaXRlbXNbaV0udmUgPSBsYXN0ID8gaXRlbXNbaV0ubHYgOiBpdGVtc1tpICsgMV0ubHY7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgLy8gV2UgY2FuIG9ubHkgaW50ZXJwb2xhdGUgb24gbnVtZXJpYyB2YWx1ZXMuIE5vbi1udW1lcmljIHZhbHVlcyBhcmUgc2V0IGxpdGVyYWxseSB3aGVuIHJlYWNoZWQgdGltZS5cbiAgICAgICAgICAgICAgICBpZiAoVXRpbHMuaXNOdW1iZXIoaXRlbXNbaV0udikgJiYgVXRpbHMuaXNOdW1iZXIoaXRlbXNbaV0ubHYpKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICghaXRlbXNbaV0uaGFzT3duUHJvcGVydHkoJ3NtZScpKSB7XG4gICAgICAg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CA8IHRoaXMuX3BbMF0pIHtcbiAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICB9XG5cbiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9wW2ldIDw9IHAgJiYgcCA8IHRoaXMuX3BlW2ldKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gbiAtIDE7XG4gICAgfVxuXG4gICAgZ2V0VmFsdWUocCkge1xuICAgICAgICBjb25zdCBpID0gdGhpcy5fZ2V0SXRlbShwKTtcbiAgICAgICAgaWYgKGkgPT09IC0xKSB7XG4gICAgICAgICAgICByZXR1cm4gdW5kZWZpbmVkO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHRoaXMuX2ZbaV0pIHtcbiAgICAgICAgICAgICAgICBjb25zdCBvID0gTWF0aC5taW4oMSwgTWF0aC5tYXgoMCwgKHAgLSB0aGlzLl9wW2ldKSAqIHRoaXMuX2lkcFtpXSkpO1xuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLl92W2ldKG8pO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5fdltpXTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBsZW5ndGgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9sZW5ndGg7XG4gICAgfVxuXG4gICAgc3RhdGljIGdldFJnYmFDb21wb25lbnRzKGFyZ2IpIHtcbiAgICAgICAgbGV0IHIgPSAoKGFyZ2IgLyA2NTUzNikgfCAwKSAlIDI1NjtcbiAgICAgICAgbGV0IGcgPSAoKGFyZ2IgLyAyNTYpIHwgMCkgJSAyNTY7XG4gICAgICAgIGxldCBiID0gYXJnYiAlIDI1NjtcbiAgICAgICAgbGV0IGEgPSAoKGFyZ2IgLyAxNjc3NzIxNikgfCAwKTtcbiAgICAgICAgcmV0dXJuIFtyLCBnLCBiLCBhXTtcbiAgICB9O1xuXG4gICAgc3RhdGljIGdldFNwbGluZVZhbHVlRnVuY3Rpb24odjEsIHYyLCBwMSwgcDIsIG8xLCBpMiwgczEsIHMyKSB7XG4gICAgICAgIC8vIE5vcm1hbGl6ZSBzbG9wZXMgYmVjYXVzZSB3ZSB1c2UgYSBzcGxpbmUgdGhhdCBnb2VzIGZyb20gMCB0byAxLlxuICAgICAgICBsZXQgZHAgPSBwMiAtIHAxO1xuICAgICAgICBzMSAqPSBkcDtcbiAgICAgICAgczIgKj0gZHA7XG5cbiAgICAgICAgbGV0IGhlbHBlcnMgPSBNdWx0aVNwbGluZS5nZXRTcGxpbmVIZWxwZXJzKHYxLCB2MiwgbzEsIGkyLCBzMSwgczIpO1xuICAgICAgICBpZiAoIWhlbHBlcnMpIHtcbiAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbiAocCkge1xuICAgICAgICAgICAgICAgIGlmIChwID09PSAwKSByZXR1cm4gdjE7XG4gICAgICAgICAgICAgICAgaWYgKHAgPT09IDEpIHJldHVybiB2MjtcblxuICAgICAgICAgICAgICAgIHJldHVybiB2MiAqIHAgKyB2MSAqICgxIC0gcCk7XG4gICAgICAgICAgICB9O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIChwKSB7XG4gICAgICAgICAgICAgICAgaWYgKHAgPT09IDApIHJldHVybiB2MTtcbiAgICAgICAgICAgICAgICBpZiAocCA9PT0gMSkgcmV0dXJuIHYyO1xuICAgICAgICAgICAgICAgIHJldHVybiBNdWx0aVNwbGluZS5jYWxjdWxhdGVTcGxpbmUoaGVscGVycywgcCk7XG4gICAgICAgICAgICB9O1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIHN0YXRpYyBnZXRTcGxpbmVSZ2JhVmFsdWVGdW5jdGlvbih2MSwgdjIsIHAxLCBwMiwg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ICAgICAgICAgICAgICAvLyBMaW5lYXIuXG4gICAgICAgICAgICAgICAgaWYgKHAgPT09IDApIHJldHVybiB2MTtcbiAgICAgICAgICAgICAgICBpZiAocCA9PT0gMSkgcmV0dXJuIHYyO1xuXG4gICAgICAgICAgICAgICAgcmV0dXJuIE11bHRpU3BsaW5lLm1lcmdlQ29sb3JzKHYyLCB2MSwgcCk7XG4gICAgICAgICAgICB9O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIChwKSB7XG4gICAgICAgICAgICAgICAgaWYgKHAgPT09IDApIHJldHVybiB2MTtcbiAgICAgICAgICAgICAgICBpZiAocCA9PT0gMSkgcmV0dXJuIHYyO1xuXG4gICAgICAgICAgICAgICAgcmV0dXJuIE11bHRpU3BsaW5lLmdldEFyZ2JOdW1iZXIoW1xuICAgICAgICAgICAgICAgICAgICBNYXRoLm1pbigyNTUsIE11bHRpU3BsaW5lLmNhbGN1bGF0ZVNwbGluZShoZWxwZXJzWzBdLCBwKSksXG4gICAgICAgICAgICAgICAgICAgIE1hdGgubWluKDI1NSwgTXVsdGlTcGxpbmUuY2FsY3VsYXRlU3BsaW5lKGhlbHBlcnNbMV0sIHApKSxcbiAgICAgICAgICAgICAgICAgICAgTWF0aC5taW4oMjU1LCBNdWx0aVNwbGluZS5jYWxjdWxhdGVTcGxpbmUoaGVscGVyc1syXSwgcCkpLFxuICAgICAgICAgICAgICAgICAgICBNYXRoLm1pbigyNTUsIE11bHRpU3BsaW5lLmNhbGN1bGF0ZVNwbGluZShoZWxwZXJzWzNdLCBwKSlcbiAgICAgICAgICAgICAgICBdKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgIH1cblxuICAgIH07XG5cbiAgICAvKipcbiAgICAgKiBDcmVhdGVzIGhlbHBlcnMgdG8gYmUgdXNlZCBpbiB0aGUgc3BsaW5lIGZ1bmN0aW9uLlxuICAgICAqIEBwYXJhbSB7bnVtYmVyfSB2MVxuICAgICAqICA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cbiAgICAgICAgICAgIC8vIExpbmVhci5cbiAgICAgICAgICAgIHJldHVybiBwO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gRmluZCB0IGZvciBwLlxuICAgICAgICBsZXQgdCA9IDAuNSwgY2J4LCBkeDtcblxuICAgICAgICBmb3IgKGxldCBpdCA9IDA7IGl0IDwgMjA7IGl0KyspIHtcbiAgICAgICAgICAgIC8vIEN1YmljIGJlemllciBmdW5jdGlvbjogZih0KT10Kih0Kih0KmErYikrYykuXG4gICAgICAgICAgICBjYnggPSB0ICogKHQgKiAodCAqIHhhICsgeGIpICsgeGMpO1xuXG4gICAgICAgICAgICBkeCA9IHAgLSBjYng7XG4gICAgICAgICAgICBpZiAoZHggPiAtMWUtOCAmJiBkeCA8IDFlLTgpIHtcbiAgICAgICAgICAgICAgICAvLyBTb2x1dGlvbiBmb3VuZCFcbiAgICAgICAgICAgICAgICByZXR1cm4gdCAqICh0ICogKHQgKiB5YSArIHliKSArIHljKSArIHlkO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBDdWJpYyBiZXppZXIgZGVyaXZhdGl2ZSBmdW5jdGlvbjogZicodCk9dCoodCooMyphKSsyKmIpK2NcbiAgICAgICAgICAgIGxldCBjYnhkID0gdCAqICh0ICogKDMgKiB4YSkgKyAyICogeGIpICsgeGM7XG5cbiAgICAgICAgICAgIGlmIChjYnhkID4gMWUtMTAgJiYgY2J4ZCA8IDFlLTEwKSB7XG4gICAgICAgICAgICAgICAgLy8gUHJvYmxlbWF0aWMuIEZhbGwgYmFjayB0byBiaW5hcnkgc2VhcmNoIG1ldGhvZC5cbiAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdCArPSBkeCAvIGNieGQ7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBGYWxsYmFjazogYmluYXJ5IHNlYXJjaCBtZXRob2QuIFRoaXMgaXMgbW9yZSByZWxpYWJsZSB3aGVuIHRoZXJlIGFyZSBuZWFyLTAgc2xvcGVzLlxuICAgICAgICBsZXQgbWluVCA9IDA7XG4gICAgICAgIGxldCBtYXhUID0gMTtcbiAgICAgICAgZm9yIChsZXQgaXQgPSAwOyBpdCA8IDIwOyBpdCsrKSB7XG4gICAgICAgICAgICB0ID0gMC41ICogKG1pblQgKyBtYXhUKTtcblxuICAgICAgICAgICAgLy8gQ3ViaWMgYmV6aWVyIGZ1bmN0aW9uOiBmKHQpPXQqKHQqKHQqYStiKStjKStkLlxuICAgICAgICAgICAgY2J4ID0gdCAqICh0ICogKHQgKiB4YSArIHhiKSArIHhjKTtcblxuICAgICAgICAgICAgZHggPSBwIC0gY2J4O1xuICAgICAgICAgICAgaWYgKGR4ID4gLTFlLTggJiYgZHggPCAxZS04KSB7XG4gICAgICAgICAgICAgICAgLy8gU29sdXRpb24gZm91bmQhXG4gICAgICAgICAgICAgICAgcmV0dXJuIHQgKiAodCAqICh0ICogeWEgKyB5YikgKyB5YykgKyB5ZDtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGR4IDwgMCkge1xuICAgICAgICAgICAgICAgIG1heFQgPSB0O1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBtaW5UID0gdDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiB0O1xuICAgIH07XG5cbiAgICBzdGF0aWMgbWVyZ2VDb2xvcnMoYzEsIGMyLCBwKSB7XG4gICAgICAgIGxldCByMSA9ICgoYzEgLyA2NTUzNikgfCAwKSAlIDI1NjtcbiAgICAgICAgbGV0IGcxID0gKChjMSAvIDI1NikgfCAwKSAlIDI1NjtcbiAgICAgICAgbGV0IGIxID0gYzEgJSAyNTY7XG4gICAgICAgIGxldCBhMSA9ICgoYzEgLyAxNjc3NzIxNikgfCAwKTtcblxuICAgICAgICBsZXQgcjIgPSAoKGMyIC8gNjU1MzYpIHwgMCkgJSAyNTY7XG4gICAgICAgIGxldCBnMiA9IC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sdCBjbGFzcyBPYmpNZXJnZXIge1xuXG4gICAgc3RhdGljIGlzTWYoZikge1xuICAgICAgICByZXR1cm4gVXRpbHMuaXNGdW5jdGlvbihmKSAmJiBmLl9fbWY7XG4gICAgfVxuXG4gICAgc3RhdGljIG1mKGYpIHtcbiAgICAgICAgLy8gU2V0IGFzIG1lcmdlIGZ1bmN0aW9uLlxuICAgICAgICBmLl9fbWYgPSB0cnVlO1xuICAgICAgICByZXR1cm4gZjtcbiAgICB9XG5cbiAgICBzdGF0aWMgbWVyZ2UoYSwgYikge1xuICAgICAgICBjb25zdCBha3MgPSBPYmplY3Qua2V5cyhhKTtcbiAgICAgICAgY29uc3QgYmtzID0gT2JqZWN0LmtleXMoYik7XG5cbiAgICAgICAgaWYgKCFia3MubGVuZ3RoKSB7XG4gICAgICAgICAgICByZXR1cm4gYTtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIENyZWF0ZSBpbmRleCBhcnJheSBmb3IgYWxsIGVsZW1lbnRzLlxuICAgICAgICBjb25zdCBhaSA9IHt9O1xuICAgICAgICBjb25zdCBiaSA9IHt9O1xuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IGJrcy5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGNvbnN0IGtleSA9IGJrc1tpXTtcbiAgICAgICAgICAgIGFpW2tleV0gPSAtMTtcbiAgICAgICAgICAgIGJpW2tleV0gPSBpO1xuICAgICAgICB9XG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gYWtzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgY29uc3Qga2V5ID0gYWtzW2ldO1xuICAgICAgICAgICAgYWlba2V5XSA9IGk7XG4gICAgICAgICAgICBpZiAoYmlba2V5XSA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgYmlba2V5XSA9IC0xO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgY29uc3QgYWtzbCA9IGFrcy5sZW5ndGg7XG5cbiAgICAgICAgY29uc3QgcmVzdWx0ID0ge307XG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gYmtzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgY29uc3Qga2V5ID0gYmtzW2ldO1xuXG4gICAgICAgICAgICAvLyBQcmVwZW5kIGFsbCBpdGVtcyBpbiBhIHRoYXQgYXJlIG5vdCBpbiBiIC0gYmVmb3JlIHRoZSBub3cgYWRkZWQgYiBhdHRyaWJ1dGUuXG4gICAgICAgICAgICBjb25zdCBhSW5kZXggPSBhaVtrZXldO1xuICAgICAgICAgICAgbGV0IGN1ckluZGV4ID0gYUluZGV4O1xuICAgICAgICAgICAgd2hpbGUoLS1jdXJJbmRleCA+PSAwKSB7XG4gICAgICAgICAgICAgICAgY29uc3QgYWtleSA9IGFrc1tjdXJJbmRleF07XG4gICAgICAgICAgICAgICAgaWYgKGJpW2FrZXldICE9PSAtMSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBBbHJlYWR5IGZvdW5kPyBTdG9wIHByb2Nlc3NpbmcuXG4gICAgICAgICAgICAgICAgICAgIC8vIE5vdCB5ZXQgZm91bmQgYnV0IGV4aXN0cyBpbiBiPyBBbHNvIHN0b3AgcHJvY2Vzc2luZzogd2FpdCB1bnRpbCB3ZSBmaW5kIGl0IGluIGIuXG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHdoaWxlKCsrY3VySW5kZXggPCBhSW5kZXgpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBha2V5ID0gYWtzW2N1ckluZGV4XTtcbiAgICAgICAgICAgICAgICByZXN1bHRbYWtleV0gPSBhW2FrZXldO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBjb25zdCBidiA9IGJba2V5XTtcbiAgICAgICAgICAgIGNvbnN0IGF2ID0gYVtrZXldO1xuICAgICAgICAgICAgbGV0IHI7XG4gICAgICAgICAgICBpZiAodGhpcy5pc01mKGJ2KSkge1xuICAgICAgICAgICAgICAgIHIgPSBidihhdik7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGlmICghVXRpbHMuaXNPYmplY3RMaXRlcmFsKGF2KSB8fCAhVXRpbHMuaXNPYmplY3RMaXRlcmFsKGJ2KSkge1xuICAgICAgICAgICAgICAgICAgICByID0gYnY7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgciA9IE9iak1lcmdlci5tZXJnZShhdiwgYnYpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gV2hlbiBtYXJrZWQgYXMgdW5kZWZpbmVkLCBwcm9wZXJ0eSBpcyBkZWxldGVkLlxuICAgICAgICAgICAgaWYgKHIgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIHJlc3VsdFtrZXldID0gcjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIC8vIEFwcGVuZCByZW1haW5pbmcgZmluYWwgaXRlbXMgaW4gYS5cbiAgICAgICAgbGV0IGN1ckluZGV4ID0gYWtzbDtcbiAgICAgICAgd2hpbGUoLS1jdXJJbmRleCA+PSAwKSB7XG4gICAgICAgICAgICBjb25zdCBha2V5ID0gYWtzW2N1ckluZGV4XTtcbiAgICAgICAgICAgIGlmIChiaVtha2V5XSAhPT0gLTEpIHtcbiAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB3aGlsZSgrK2N1ckluZGV4IDwgYWtzbCkge1xuICAgICAgICAgICAgY29uc3QgYWtleSA9IGFrc1tjdXJJbmRleF07XG4gICAgICAgICAgICByZXN1bHRbYWtleV0gPSBhW2FrZXldO1xuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIHJlc3VsdDtcbiAg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NSAqIHN0cm9rZVdpZHRoICsgMTtcblxuICAgICAgICBjdHgubW92ZVRvKHggKyByYWRpdXNbMF0sIHkpO1xuICAgICAgICBjdHgubGluZVRvKHggKyB3IC0gcmFkaXVzWzFdLCB5KTtcbiAgICAgICAgY3R4LmFyY1RvKHggKyB3LCB5LCB4ICsgdywgeSArIHJhZGl1c1sxXSwgcmFkaXVzWzFdKTtcbiAgICAgICAgY3R4LmxpbmVUbyh4ICsgdywgeSArIGggLSByYWRpdXNbMl0pO1xuICAgICAgICBjdHguYXJjVG8oeCArIHcsIHkgKyBoLCB4ICsgdyAtIHJhZGl1c1syXSwgeSArIGgsIHJhZGl1c1syXSk7XG4gICAgICAgIGN0eC5saW5lVG8oeCArIHJhZGl1c1szXSwgeSArIGgpO1xuICAgICAgICBjdHguYXJjVG8oeCwgeSArIGgsIHgsIHkgKyBoIC0gcmFkaXVzWzNdLCByYWRpdXNbM10pO1xuICAgICAgICBjdHgubGluZVRvKHgsIHkgKyByYWRpdXNbMF0pO1xuICAgICAgICBjdHguYXJjVG8oeCwgeSwgeCArIHJhZGl1c1swXSwgeSwgcmFkaXVzWzBdKTtcbiAgICAgICAgY3R4LmNsb3NlUGF0aCgpO1xuXG4gICAgICAgIGlmIChmaWxsKSB7XG4gICAgICAgICAgICBpZiAoVXRpbHMuaXNOdW1iZXIoZmlsbENvbG9yKSkge1xuICAgICAgICAgICAgICAgIGN0eC5maWxsU3R5bGUgPSBTdGFnZVV0aWxzLmdldFJnYmFTdHJpbmcoZmlsbENvbG9yKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgY3R4LmZpbGxTdHlsZSA9IFwid2hpdGVcIjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGN0eC5maWxsKCk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoc3Ryb2tlV2lkdGgpIHtcbiAgICAgICAgICAgIGlmIChVdGlscy5pc051bWJlcihzdHJva2VDb2xvcikpIHtcbiAg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IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGNvbnN0IGsxID0ga2V5czFbaV07XG4gICAgICAgICAgICBjb25zdCBrMiA9IGtleXMyW2ldO1xuICAgICAgICAgICAgaWYgKGsxICE9PSBrMikge1xuICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBjb25zdCB2MSA9IG9iajFbazFdO1xuICAgICAgICAgICAgY29uc3QgdjIgPSBvYmoyW2syXTtcblxuICAgICAgICAgICAgaWYgKCFVdGlscy5lcXVhbFZhbHVlcyh2MSwgdjIpKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICB9XG5cbiAgICBzdGF0aWMgZXF1YWxBcnJheXModjEsIHYyKSB7XG4gICAgICAgIGlmICh2MS5sZW5ndGggIT09IHYyLmxlbmd0aCkge1xuICAgICAgICAgICAgcmV0dXJuIGZhbHNlXG4gICAgICAgIH1cbiAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB2MS5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5lcXVhbFZhbHVlcyh2MVtpXSwgdjJbaV0pKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gdHJ1ZVxuICAgIH1cblxufVxuXG4vKipcbiAqIE1haW50YWlucyB0aGUgc3RhdGUgb2YgYSBXZWJHTFJlbmRlcmluZ0NvbnRleHQuXG4gKi9cbmNsYXNzIFdlYkdMU3RhdGUge1xuXG4gICAgY29uc3RydWN0b3IoaWQsIGdsKSB7XG4gICAgICAgIHRoaXMuX2lkID0gaWQ7XG4gICAgICAgIHRoaXMuX2dsID0gZ2w7XG4gICAgICAgIHRoaXMuX3Byb2dyYW0gPS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iB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fdmVydGV4QXR0cmlic1tpbmRleF0gPSBbMCwgMCwgMCwgMCwgMCwgdHJ1ZV07XG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuXG4gICAgdmVydGV4QXR0cmliUG9pbnRlcihpbmRleCwgcHJvcHMpIHtcbiAgICAgICAgbGV0IHZhID0gdGhpcy5fdmVydGV4QXR0cmlic1tpbmRleF07XG4gICAgICAgIGxldCBlcXVhbCA9IGZhbHNlO1xuICAgICAgICBpZiAodmEpIHtcbiAgICAgICAgICAgIGVxdWFsID0gdmFbMF0gPT09IHByb3BzWzBdICYmXG4gICAgICAgICAgICAgICAgdmFbMV0gPT09IHByb3BzWzFdICYmXG4gICAgICAgICAgICAgICAgdmFbMl0gPT09IHByb3BzWzJdICYmXG4gICAgICAgICAgICAgICAgdmFbM10gPT09IHByb3BzWzNdICYmXG4gICAgICAgICAgICAgICAgdmFbNF0gPT09IHByb3BzWzRdO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKGVxdWFsKSB7XG4gICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwcm9wc1s1XSA9IHZhID8gdmFbNV0gOiBmYWxzZTtcbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2V0QWN0aXZlVGV4dHVyZSh0ZXh0dXJlKSB7XG4gICAgICAgIGNvbnN0IGNoYW5nZWQgPSB0aGlzLl9hY3RpdmVUZXh0dXJlICE9PSB0ZXh0dXJlO1xuICAgICAgICB0aGlzLl9hY3RpdmVUZXh0dXJlID0gdGV4dHVyZTtcbiAgICAgICAgcmV0dXJuIGNoYW5nZWQ7XG4gICAgfVxuXG4gICAgYmluZFRleHR1cmU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AgICAgICAgICAgICAgICAgICB0aGlzLl9nbC5fZGlzYWJsZVZlcnRleEF0dHJpYkFycmF5KGluZGV4KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcblxuICAgICAgICAgICAgcy5fdmVydGV4QXR0cmlicy5mb3JFYWNoKChhdHRyaWIsIGluZGV4KSA9PiB7XG4gICAgICAgICAgICAgICAgdGhpcy5fZ2wuX3ZlcnRleEF0dHJpYlBvaW50ZXIoaW5kZXgsIGF0dHJpYlswXSwgYXR0cmliWzFdLCBhdHRyaWJbMl0sIGF0dHJpYls0XSk7XG4gICAgICAgICAgICAgICAgaWYgKGF0dHJpYls1XSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9nbC5fZW5hYmxlVmVydGV4QXR0cmliQXJyYXkoaW5kZXgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2dsLl9kaXNhYmxlVmVydGV4QXR0cmliQXJyYXkoaW5kZXgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgLy8gV2hlbiBidWZmZXJzIGFyZSBjaGFuZ2VkLCBwcmV2aW91cyBhdHRyaWJ1dGVzIHdlcmUgcmVzZXQgYXV0b21hdGljYWxseS5cbiAgICAgICAgICAgIHMuX3ZlcnRleEF0dHJpYnMuZm9yRWFjaCgoYXR0cmliLCBpbmRleCkgPT4ge1xuICAgICAgICAgICAgICAgIGlmIChhdHRyaWJbMF0pIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gRG8gbm90IHNldCB2ZXJ0ZXggYXR0cmliIHBvaW50ZXIgd2hlbiBpdCB3YXMganVzdCB0aGUgZGVmYXVsdCB2YWx1ZS5cbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZ2wuX3ZlcnRleEF0dHJpYlBvaW50ZXIoaW5kZXgsIGF0dHJpYlswXSwgYXR0cmliWzFdLCBhdHRyaWJbMl0sIGF0dHJpYlszXSwgYXR0cmliWzRdKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaWYgKGF0dHJpYls1XSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9nbC5fZW5hYmxlVmVydGV4QXR0cmliQXJyYXkoaW5kZXgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgX21pZ3JhdGVTZXR0aW5ncyh0LCBzKSB7XG4gICAgICAgIGNvbnN0IGRlZmF1bHRzID0gdGhpcy5jb25zdHJ1Y3Rvci5nZXREZWZhdWx0U2V0dGluZ3MoKTtcbiAgICAgICAgdC5fc2V0dGluZ3MuZm9yRWFjaCgodmFsdWUsIGZ1bmMpID0+IHtcbiAgICAgICAgICAgIGNvbnN0IG5hbWUgPSBmdW5jLm5hbWUgfHwgZnVuYy54bmFtZTtcbiAgICAgICAgICAgIGlmICghcy5fc2V0dGluZ3MuaGFzKGZ1bmMpKSB7XG4gICAgICAgICAgICAgICAgbGV0IGFyZ3MgPSBkZWZhdWx0cy5nZXQobmFtZSk7XG4gICAgICAgICAgICAgICAgaWYgKFV0aWxzLmlzRnVuY3Rpb24oYXJncykpIHtcbiAgICAgICAgICAgICAgICAgICAgYXJncyA9IGFyZ3ModGhpcy5fZ2wpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAvLyBXZSBhcmUgYWN0dWFsbHkgc2V0dGluZyB0aGUgc2V0dGluZyBmb3Igb3B0aW1pemF0aW9uIHB1cnBvc2VzLlxuICAgICAgICAgICAgICAgIHMuX3NldHRpbmdzLnNldChmdW5jLCBhcmdzKTtcbiAgICAgICAgICAgICAgICBmdW5jLmFwcGx5KHRoaXMuX2dsLCBhcmdzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIHMuX3NldHRpbmdzLmZvckVhY2goKHZhbHVlLCBmdW5jKSA9PiB7XG4gICAgICAgICAgICBjb25zdCB0VmFsdWUgPSB0Ll9zZXR0aW5ncy5nZXQoZnVuYyk7XG4gICAgICAgICAgICBpZiAoIXRWYWx1ZSB8fCAhVXRpbHMuZXF1YWxWYWx1ZXModFZhbHVlLCB2YWx1ZSkpIHtcbiAgICAgICAgICAgICAgICBmdW5jLmFwcGx5KHRoaXMuX2dsLCB2YWx1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIF9taWdyYXRlRmxhZ3ModCwgcykge1xuICAgICAgICB0Ll9ub25EZWZhdWx0RmxhZ3MuZm9yRWFjaChzZXR0aW5nID0+IHtcbiAgICAgICAgICAgIGlmICghcy5fbm9uRGVmYXVsdEZsYWdzLmhhcyhzZXR0aW5nKSkge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9nZXREZWZhdWx0RmxhZyhzZXR0aW5nKSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9nbC5fZW5hYmxlKHNldHRpbmcpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2dsLl9kaXNhYmxlKHNldHRpbmcpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIHMuX25vbkRlZmF1bHRGbGFncy5mb3JFYWNoKHNldHRpbmcgPT4ge1xuICAgICAgICAgICAgaWYgKCF0Ll9ub25EZWZhdWx0RmxhZ3MuaGFzKHNldHRpbmcpKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2dldERlZmF1bHRGbGFnKHNldHRpbmcpKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2dsLl9kaXNhYmxlKHNldHRpbmcpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2dsLl9lbmFibGUoc2V0dGluZyk7XG4gICAgICAgICAg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3RvcmVpSW5kZXgocG5hbWUpIHtcbiAgICAgICAgc3dpdGNoKHBuYW1lKSB7XG4gICAgICAgICAgICBjYXNlIDB4MEQwNTpcbiAgICAgICAgICAgICAgICAvKiBQQUNLX0FMSUdOTUVOVCAqL1xuICAgICAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICAgICAgY2FzZSAweDBDRjU6XG4gICAgICAgICAgICAgICAgLyogVU5QQUNLX0FMSUdOTUVOVCAqL1xuICAgICAgICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICAgICAgY2FzZSAweDkyNDA6XG4gICAgICAgICAgICAgICAgLyogVU5QQUNLX0ZMSVBfWV9XRUJHTCAqL1xuICAgICAgICAgICAgICAgIHJldHVybiAyO1xuICAgICAgICAgICAgY2FzZSAweDkyNDE6XG4gICAgICAgICAgICAgICAgLyogVU5QQUNLX1BSRU1VTFRJUExZX0FMUEhBX1dFQkdMICovXG4gICAgICAgICAgICAgICAgcmV0dXJuIDM7XG4gICAgICAgICAgICBjYXNlIDB4OTI0MzpcbiAgICAgICAgICAgICAgICAvKiBVTlBBQ0tfQ09MT1JTUEFDRV9DT05WRVJTSU9OX1dFQkdMICovXG4gICAgICAgICAgICAgICAgcmV0dXJuIDQ7XG4gICAgICAgICAgICAgICAgLy9AdG9kbzogc3VwcG9ydCBXZWJHTDIgcHJvcGVydGllcywgc2VlIGh0dHBzOi8vZGV2ZWxvcGVyLm1vemlsbGEub3JnL2VuLVVTL2RvY3MvV2ViL0FQSS9XZWJHTFJlbmRlcmluZ0NvbnRleHQvcGl4ZWxTdG9yZWlcbiAgICAgICAgICAgIGNhc2UgMHg5MjQ1OlxuICAgICAgICAgICAgICAgIC8qIFVOUEFDS19GTElQX0JMVUVfUkVEICovXG4gICAgICAgICAgICAgICAgcmV0dXJuIDU7XG4gICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgIC8vIFNob3VsZG4ndCBoYXBwZW4uXG4gICAgICAgICAgICAgICAgdGhyb3cgbm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ZShnbCwgaWQgPSBcImRlZmF1bHRcIikge1xuICAgICAgICBjb25zdCBuYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzKFdlYkdMU3RhdGVNYW5hZ2VyLnByb3RvdHlwZSk7XG4gICAgICAgIGNvbnN0IFdlYkdMUmVuZGVyaW5nQ29udGV4dFByb3RvID0gZ2wuX19wcm90b19fO1xuICAgICAgICBuYW1lcy5mb3JFYWNoKG5hbWUgPT4ge1xuICAgICAgICAgICAgaWYgKG5hbWUgIT09IFwiY29uc3RydWN0b3JcIikge1xuICAgICAgICAgICAgICAgIGNvbnN0IG1ldGhvZCA9IFdlYkdMU3RhdGVNYW5hZ2VyLnByb3RvdHlwZVtuYW1lXTtcbiAgICAgICAgICAgICAgICBpZiAobmFtZS5jaGFyQXQoMCkgPT09IFwiJFwiKSB7XG4gICAgICAgICAgICAgICAgICAgIG5hbWUgPSBuYW1lLnN1YnN0cigxKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaWYgKGdsW25hbWVdICE9PSBtZXRob2QpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGdsW25hbWVdKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIWdsW25hbWVdLm5hbWUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBXZSBkbyB0aGlzIGZvciBjb21wYXRpYmlsaXR5IHdpdGggdGhlIENocm9tZSBXZWJHTCBJbnNwZWN0b3IgcGx1Z2luLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdsW25hbWVdLnhuYW1lID0gbmFtZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIGdsWydfJyArIG5hbWVdID0gZ2xbbmFtZV07XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZ2xbbmFtZV0gPSBtZXRob2Q7XG4gICAgICAgICAgICAgICAgfVxuICAgICA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7XG4gICAgICAgICAgICBpZiAoIVV0aWxzLmlzVWNDaGFyKGNoYXJjb2RlKSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3Rocm93RXJyb3IoXCJSZWYgbXVzdCBzdGFydCB3aXRoIGFuIHVwcGVyIGNhc2UgY2hhcmFjdGVyOiBcIiArIHJlZik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy5fX3JlZiAhPT0gbnVsbCkge1xuICAgICAgICAgICAgICAgIHRoaXMucmVtb3ZlVGFnKHRoaXMuX19yZWYpO1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9fcGFyZW50KSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX19wYXJlbnQuX19jaGlsZExpc3QuY2xlYXJSZWYodGhpcy5fX3JlZik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLl9fcmVmID0gcmVmO1xuXG4gICAgICAgICAgICBpZiAodGhpcy5fX3JlZikge1xuICAgICAgICAgICAgICAgIHRoaXMuX2FkZFRhZyh0aGlzLl9fcmVmKTtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fX3BhcmVudCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9fcGFyZW50Ll9fY2hpbGRMaXN0LnNldFJlZih0aGlzLl9fcmVmLCB0aGlzKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgcmVmKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX3JlZjtcbiAgICB9XG5cbiAgICBnZXQgY29yZSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlO1xuICAgIH1cblxuICAgIHNldEFzUm9vdCgpIHtcbiAgICAgICAgdGhpcy5fX2NvcmUuc2V0QXNSb290KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUF0dGFjaGVkRmxhZygpO1xuICAgICAgICB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7XG4gICAgICAgIGxldCBwID0gdGhpcztcbiAgICAgICAgd2hpbGUgKGwgPiAwICYmIHAuX19wYXJlbnQpIHtcbiAgICAgICAgICAgIHAgPSBwLl9fcGFyZW50O1xuICAgICAgICAgICAgbC0tO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBwO1xuICAgIH07XG5cbiAgICBnZXRBbmNlc3RvcnMoKSB7XG4gICAgICAgIGNvbnN0IGEgPSBbXTtcbiAgICAgICAgbGV0IHAgPSB0aGlzO1xuICAgICAgICB3aGlsZSAocCkge1xuICAgICAgICAgICAgYS5wdXNoKHApO1xuICAgICAgICAgICAgcCA9IHAuX19wYXJlbnQ7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGE7XG4gICAgfVxuXG4gICAgZ2V0QW5jZXN0b3JBdERlcHRoKGRlcHRoKSB7XG4gICAgICAgIGxldCBsZXZlbHMgPSB0aGlzLmdldERlcHRoKCkgLSBkZXB0aDtcbiAgICAgICAgaWYgKGxldmVscyA8IDApIHtcbiAgICAgICAgICAgIHJldHVybiBudWxsO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0aGlzLmdldEFuY2VzdG9yKGxldmVscyk7XG4gICAgfTtcblxuICAgIGlzQW5jZXN0b3JPZihjKSB7XG4gICAgICAgIGxldCBwID0gYztcbiAgICAgICAgd2hpbGUocCA9IHAucGFyZW50KSB7XG4gICAgICAgICAgICBpZiAodGhpcyA9PT0gcCkge1xuICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9O1xuXG4gICAgZ2V0U2hhcmVkQW5jZXN0b3IoYykge1xuICAgICAgICBsZXQgbzEgPSB0aGlzO1xuICAgICAgICBsZXQgbzIgPSBjO1xuICAgICAgICBsZXQgbDEgPSBvMS5nZXREZXB0aCgpO1xuICAgICAgICBsZXQgbDIgPSBvMi5nZXREZXB0aCgpO1xuICAgICAgIC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N0aXZlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faXNFbmFibGVkKCkgJiYgdGhpcy53aXRoaW5Cb3VuZHNNYXJnaW47XG4gICAgfTtcblxuICAgIC8qKlxuICAgICAqIFVwZGF0ZXMgdGhlICdhdHRhY2hlZCcgZmxhZyBmb3IgdGhpcyBicmFuY2guXG4gICAgICovXG4gICAgX3VwZGF0ZUF0dGFjaGVkRmxhZygpIHtcbiAgICAgICAgbGV0IG5ld0F0dGFjaGVkID0gdGhpcy5faXNBdHRhY2hlZCgpO1xuICAgICAgICBpZiAodGhpcy5fX2F0dGFjaGVkICE9PSBuZXdBdHRhY2hlZCkge1xuICAgICAgICAgICAgdGhpcy5fX2F0dGFjaGVkID0gbmV3QXR0YWNoZWQ7XG5cbiAgICAgICAgICAgIGlmIChuZXdBdHRhY2hlZCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX29uU2V0dXAoKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgbGV0IGNoaWxkcmVuID0gdGhpcy5fY2hpbGRyZW4uZ2V0KCk7XG4gICAgICAgICAgICBpZiAoY2hpbGRyZW4pIHtcbiAgICAgICAgICAgICAgICBsZXQgbSA9IGNoaWxkcmVuLmxlbmd0aDtcbiAgICAgICAgICAgICAgICBpZiAobSA+IDApIHtcbiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBtOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNoaWxkcmVuW2ldLl91cGRhdGVBdHRhY2hlZEZsYWcoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKG5ld0F0dGFjaGVkKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb25BdHRhY2goKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb25EZXRhY2goKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG5cbiAgICAvKipcbiAgICAgKiBVcGRhdGVzIHRoZSAnZW5hYmxlZCcgZmxhZyBmb3IgdGhpcyBicmFuY2guXG4gICAgICovXG4gICAgX3VwZGF0ZUVuYWJsZWRGbGFnKCkge1xuICAgICAgICBsZXQgbmV3RW5hYmxlZCA9IHRoaXMuX2lzRW5hYmxlZCgpO1xuICAgICAgICBpZiAodGhpcy5fX2VuYWJsZWQgIT09IG5ld0VuYWJsZWQpIHtcbiAgICAgICAgICAgIGlmIChuZXdFbmFibGVkKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb25FbmFibGVkKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fc2V0RW5hYmxlZEZsYWcoKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb25EaXNhYmxlZCgpO1xuICAgICAgICAgICAgICAgIHRoaXMuX3Vuc2V0RW5hYmxlZEZsYWcoKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgbGV0IGNoaWxkcmVuID0gdGhpcy5fY2hpbGRyZW4uZ2V0KCk7XG4gICAgICAgICAgICBpZiAoY2hpbGRyZW4pIHtcbiAgICAgICAgICAgICAgICBsZXQgbSA9IGNoaWxkcmVuLmxlbmd0aDtcbiAgICAgICAgICAgICAgICBpZiAobSA+IDApIHtcbiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBtOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNoaWxkcmVuW2ldLl91cGRhdGVFbmFibGVkRmxhZygpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfTtcblxuICAgIF9zZXRFbmFibGVkRmxhZygpIHtcbiAgICAgICAgdGhpcy5fX2VuYWJsZWQgPSB0cnVlO1xuXG4gICAgICAgIC8vIEZvcmNlIH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Aodi50eXBlKSB7XG4gICAgICAgICAgICAgICAgdGV4dHVyZSA9IG5ldyB2LnR5cGUodGhpcy5zdGFnZSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRleHR1cmUgPSB0aGlzLnRleHR1cmU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0ZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgQmFzZS5wYXRjaE9iamVjdCh0ZXh0dXJlLCB2KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIGlmICghdikge1xuICAgICAgICAgICAgdGV4dHVyZSA9IG51bGw7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodi5pc1RleHR1cmUpIHtcbiAgICAgICAgICAgICAgICB0ZXh0dXJlID0gdjtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodi5pc1RleHR1cmVTb3VyY2UpIHtcbiAgICAgICAgICAgICAgICB0ZXh0dXJlID0gbmV3IFNvdXJjZVRleHR1cmUodGhpcy5zdGFnZSk7XG4gICAgICAgICAgICAgICAgdGV4dHVyZS50ZXh0dXJlU291cmNlID0gdjtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihcIltMaWdodG5pbmddIFBsZWFzZSBzcGVjaWZ5IGEgdGV4dHVyZSB0eXBlLlwiKTtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBjb25zdCBwcmV2VGV4dHVyZSA9IHRoaXMuX190ZXh0dXJlO1xuICAgICAgICBpZiAodGV4dHVyZSAhPT0gcHJldlRleHR1cmUpIHtcbiAgICAgICAgICAgIHRoaXMuX190ZXh0dXJlID0gdGV4dHVyZTtcblxuICAgICAgICAgICAgaWYgKHRoaXMuX190ZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX19lbmFibGVkKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX190ZXh0dXJlLmFkZEVsZW1lbnQodGhpcyk7XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMud2l0aGluQm91bmRzTWFyZ2luKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fX3RleHR1cmUuaXNMb2FkZWQoKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3NldERpc3BsYXllZFRleHR1cmUodGhpcy5fX3RleHR1cmUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9lbmFibGVUZXh0dXJlRXJyb3IoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgLy8gTWFrZSBzdXJlIHRoYXQgY3VycmVudCB0ZXh0dXJlIGlzIGNsZWFyZWQgd2hlbiB0aGUgdGV4dHVyZSBpcyBleHBsaWNpdGx5IHNldCB0byBudWxsLlxuICAgICAgICAgICAgICAgIHRoaXMuX3NldERpc3BsYXllZFRleHR1cmUobnVsbCk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChwcmV2VGV4dHVyZSAmJiBwcmV2VGV4dHVyZSAhPT0gdGhpcy5fX2Rpc3BsYXllZFRleHR1cmUpIHtcbiAgICAgICAgICAgICAgICBwcmV2VGV4dHVyZS5yZW1vdmVFbGVtZW50KHRoaXMpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLl91cGRhdGVEaW1lbnNpb25zKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgZGlzcGxheWVkVGV4dHVyZSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19kaXNwbGF5ZWRUZXh0dXJlO1xuICA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SAmJiB0aGlzLl9fdGV4dHVyZSkge1xuICAgICAgICAgICAgICAgIC8vIFdlIHVzZSBhICdtYXggd2lkdGgnIHJlcGxhY2VtZW50IGluc3RlYWQgaW4gdGhlIEVsZW1lbnRDb3JlIGNhbGNzLlxuICAgICAgICAgICAgICAgIC8vIFRoaXMgbWFrZXMgc3VyZSB0aGF0IGl0IGlzIGFibGUgdG8gZGV0ZXJtaW5lIHdpdGhpbkJvdW5kcy5cbiAgICAgICAgICAgICAgICB3ID0gdyB8fCB0aGlzLl9fdGV4dHVyZS5tdztcbiAgICAgICAgICAgICAgICBoID0gaCB8fCB0aGlzLl9fdGV4dHVyZS5taDtcblxuICAgICAgICAgICAgICAgIGlmICgoIXcgfHwgIWgpICYmIHRoaXMuX190ZXh0dXJlLmlzQXV0b3NpemVUZXh0dXJlKCkpIHtcbiAgICAgICAgICAgICAgICAgICAgdW5rbm93blNpemUgPSB0cnVlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLl9fY29yZS5zZXREaW1lbnNpb25zKHcsIGgsIHVua25vd25TaXplKSkge1xuICAgICAgICAgICAgdGhpcy5fb25SZXNpemUoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF91cGRhdGVUZXh0dXJlQ29vcmRzKCkge1xuICAgICAgICBpZiAodGhpcy5kaXNwbGF5ZWRUZXh0dXJlICYmIHRoaXMuZGlzcGxheWVkVGV4dHVyZS5fc291cmNlKSB7XG4gICAgICAgICAgICBsZXQgZGlzcGxheWVkVGV4dHVyZSA9IHRoaXMuZGlzcGxheWVkVGV4dHVyZTtcbiAgICAgICAgICAgIGxldCBkaXNwbGF5ZWRUZXh0dXJlU291cmNlID0gdGhpcy5kaXNwbGF5ZWRUZXh0dXJlLl9zb3VyY2U7XG5cbiAgICAgICAgICAgIGxldCB0eDEgPSAwLCB0eTEgPSAwLCB0eDIgPSAxLjAsIHR5MiA9IDEuMDtcbiAgICAgICAgICAgIGlmIChkaXNwbGF5ZWRUZXh0dXJlLmNsaXBwaW5nKSB7XG4gICAgICAgICAgICAgICAgLy8gQXBwbHkgdGV4dHVyZSBjbGlwcGluZy5cbiAgICAgICAgICAgICAgICBsZXQgdyA9IGRpc3BsYXllZFRleHR1cmVTb3VyY2UuZ2V0UmVuZGVyV2lkdGgoKTtcbiAgICAgICAgICAgICAgICBsZXQgaCA9IGRpc3BsYXllZFRleHR1cmVTb3VyY2UuZ2V0UmVuZGVySGVpZ2h0KCk7XG4gICAgICAgICAgICAgICAgbGV0IGl3LCBpaCwgcncsIHJoO1xuICAgICAgICAgICAgICAgIGl3ID0gMSAvIHc7XG4gICAgICAgICAgICAgICAgaWggPSAxIC8gaDtcblxuICAgICAgICAgICAgICAgIGlmIChkaXNwbGF5ZWRUZXh0dXJlLnB3KSB7XG4gICAgICAgICAgICAgICAgICAgIHJ3ID0gKGRpc3BsYXllZFRleHR1cmUucHcpICogaXc7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcncgPSAodyAtIGRpc3BsYXllZFRleHR1cmUucHgpICogaXc7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaWYgKGRpc3BsYXllZFRleHR1cmUucGgpIHtcbiAgICAgICAgICAgICAgICAgICAgcmggPSBkaXNwbGF5ZWRUZXh0dXJlLnBoICogaWg7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmggPSAoaCAtIGRpc3BsYXllZFRleHR1cmUucHkpICogaWg7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaXcgKj0gKGRpc3BsYXllZFRleHR1cmUucHgpO1xuICAgICAgICAgICAgICAgIGloICo9IChkaXNwbGF5ZWRUZXh0dXJlLnB5KTtcblxuICAgICAgICAgICAgICAgIHR4MSA9IGl3O1xuICAgICAgICAgICAgICAgIHR5MSA9IGloO1xuICAgICAgICAgICAgICAgIHR4MiA9IHR4MiAqIHJ3ICsgaXc7XG4gICAgICAgICAgICAgICAgdHkyID0gdHkyICogcmggKyBpaDtcblxuICAgICAgICAgICAgICAgIHR4MSA9IE1hdGgubWF4KDAsIHR4MSk7XG4gICAgICAgICAgICAgICAgdHkxID0gTWF0aC5tYXgoMCwgdHkxKTtcbiAgICAgICAgICAgICAgICB0eDIgPSBNYXRoLm1pbigxLCB0eDIpO1xuICAgICAgICAgICAgICAgIHR5MiA9IE1hdGgubWluKDEsIHR5Mik7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChkaXNwbGF5ZWRUZXh0dXJlU291cmNlLl9mbGlwVGV4dHVyZVkpIHtcbiAgICAgICAgICAgICAgICBsZXQgdGVtcHR5ID0gdHkyO1xuICAgICAgICAgICAgICAgIHR5MiA9IHR5MTtcbiAgICAgICAgICAgICAgICB0eTEgPSB0ZW1wdHk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9fY29yZS5zZXRUZXh0dXJlQ29vcmRzKHR4MSwgdHkxLCB0eDIsIHR5Mik7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXRDb3JuZXJQb2ludHMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fY29yZS5nZXRDb3JuZXJQb2ludHMoKTtcbiAgICB9XG5cbiAgICBfdW5zZXRUYWdzUGFyZW50KCkge1xuICAgICAgICBpZiAodGhpcy5fX3RhZ3MpIHtcbiAgICAgICAgICAgIHRoaXMuX190YWdzLmZvckVhY2goKHRhZykgPT4ge1xuICAgICAgICAgICAgICAgIC8vIFJlbW92ZSBmcm9tIHRyZWVUYWdzLlxuICAgICAgICAgICAgICAgIGxldCBwID0gdGhpcztcbiAgICAgICAgICAgICAgICB3aGlsZSAocCA9IHAuX19wYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgbGV0IHBhcmVudFRyZWVUYWdzID0gcC5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgICAgICAgICAgICAgICBwYXJlbnRUcmVlVGFncy5kZWxldGUodGhpcyk7XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHAuX190YWdSb290KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG5cbiAgICAgICAgbGV0IHRhZ3MgPSBudWxsO1xuICAgICAgICBsZXQgbiA9IDA7XG4gICAgICAgIGlmICh0aGlzLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5fX3RhZ1Jvb3QpIHtcbiAgICAgICAgICAgICAgICB0YWdzID0gVXRpbHMuaXRlcmF0b3JUb0FycmF5KHRoaXMuX190cmVlVGFncy5rZXlzKCkpO1xuICAgICAgICAgICAgICAgIG4gPSB0YWdzLmxlbmd0aDtcblxuICAgICAgICAgICAgICAgIGlmIChuID4gMCkge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHRhZ1NldCA9IHRoaXMuX190cmVlVGFncy5nZXQodGFnc1tpXSk7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFJlbW92ZSBmcm9tIHRyZWVUYWdzLlxuICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHAgPSB0aGlzO1xuICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKChwID0gcC5fX3BhcmVudCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgcGFyZW50VHJlZVRhZ3MgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZ3NbaV0pO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGFnU2V0LmZvckVhY2goZnVuY3Rpb24gKGNvbXApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGFyZW50VHJlZVRhZ3MuZGVsZXRlKGNvbXApO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHAuX190YWdSb290KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBfc2V0VGFnc1BhcmVudCgpIHtcbiAgICAgICAgLy8gSnVzdCBjb3B5IG92ZXIgdGhlICdsb2NhbCcgdGFncy5cbiAgICAgICAgaWYgKHRoaXMuX190YWdzKSB7XG4gICAgICAgICAgICB0aGlzLl9fdGFncy5mb3JFYWNoKCh0YWcpID0+IHtcbiAgICAgICAgICAgICAgICBsZXQgcCA9IHRoaXM7XG4gICAgICAgICAgICAgICAgd2hpbGUgKHAgPSBwLl9fcGFyZW50KSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICghcC5fX3RyZWVUYWdzKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3MgPSBuZXcgTWFwKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICBsZXQgcyA9IHAuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFzKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzID0gbmV3IFNldCgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgcC5fX3RyZWVUYWdzLnNldCh0YWcsIHMpO1xuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgcy5hZGQodGhpcyk7XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHAuX190YWdSb290KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuX190cmVlVGFncyAmJiB0aGlzLl9fdHJlZVRhZ3Muc2l6ZSkge1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9fdGFnUm9vdCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX190cmVlVGFncy5mb3JFYWNoKCh0YWdTZXQsIHRhZykgPT4ge1xuICAgICAgICAgICAgICAgICAgICBsZXQgcCA9IHRoaXM7XG4gICAgICAgICAgICAgICAgICAgIHdoaWxlICghcC5fX3RhZ1Jvb3QgJiYgKHAgPSBwLl9fcGFyZW50KSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHAuX190YWdSb290KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gRG8gbm90IGNvcHkgYWxsIHN1YnMuXG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXAuX190cmVlVGFncykge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHAuX190cmVlVGFncyA9IG5ldyBNYXAoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHMgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzID0gbmV3IFNldCgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHAuX190cmVlVGFncy5zZXQodGFnLCBzKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICAgICAgdGFnU2V0LmZvckVhY2goZnVuY3Rpb24gKGNvbXApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzLmFkZChjb21wKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9O1xuXG5cbiAgICBfZ2V0QnlUYWcodGFnKSB7XG4gICAgICAgIGlmICghdGhpcy5fX3RyZWVUYWdzKSB7XG4gICAgICAgICAgICByZXR1cm4gW107XG4gICAgICAgIH1cbiAgICAgICAgbGV0IHQgPSB0aGlzLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgIHJldHVybiB0ID8gVXRpbHMuc2V0VG9BcnJheSh0KSA6IFtdO1xuICAgIH07XG5cbiAgICBnZXRUYWdzKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX3RhZ3MgPyB0aGlzLl9fdGFncyA6IFtdO1xuICAgIH07XG5cbiAgICBzZXRUYWdzKHRhZ3MpIHtcbiAgICAgICAgdGFncyA9IHRhZ3MucmVkdWNlKChhY2MsIHRhZykgPT4ge1xuICAgICAgICAgICAgcmV0dXJuIGFjYy5jb25jYXQodGFnLnNwbGl0KCcgJykpO1xuICAgICAgICB9LCBbXSk7XG5cbiAgICAgICAgaWYgKHRoaXMuX19yZWYpIHtcbiAgICAgICAgICAgIHRhZ3MucHVzaCh0aGlzLl9fcmVmKTtcbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBpLCBuID0gdGFncy5sZW5ndGg7XG4gICAgICAgIGxldCByZW1vdmVzID0gW107XG4gICAgICAgIGxldCBhZGRzID0gW107XG4gICAgICAgIGZvciAoaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5oYXNUYWcodGFnc1tpXSkpIHtcbiAgICAgICAgICAgICAgICBhZGRzLnB1c2godGFnc1tpXSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBsZXQgY3VycmVudFRhZ3MgPSB0aGlzLnRhZ3MgfHwgW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lzVWNDaGFyKHRhZy5jaGFyQ29kZUF0KDApKSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl90aHJvd0Vycm9yKFwiVGFnIG1heSBub3Qgc3RhcnQgd2l0aCBhbiB1cHBlciBjYXNlIGNoYXJhY3Rlci5cIik7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgdGhpcy5fYWRkVGFnKHRhZyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfYWRkVGFnKHRhZykge1xuICAgICAgICBpZiAoIXRoaXMuX190YWdzKSB7XG4gICAgICAgICAgICB0aGlzLl9fdGFncyA9IFtdO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9fdGFncy5pbmRleE9mKHRhZykgPT09IC0xKSB7XG4gICAgICAgICAgICB0aGlzLl9fdGFncy5wdXNoKHRhZyk7XG5cbiAgICAgICAgICAgIC8vIEFkZCB0byB0cmVlVGFncyBoaWVyYXJjaHkuXG4gICAgICAgICAgICBsZXQgcCA9IHRoaXMuX19wYXJlbnQ7XG4gICAgICAgICAgICBpZiAocCkge1xuICAgICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFwLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHAuX190cmVlVGFncyA9IG5ldyBNYXAoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIGxldCBzID0gcC5fX3RyZWVUYWdzLmdldCh0YWcpO1xuICAgICAgICAgICAgICAgICAgICBpZiAoIXMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHMgPSBuZXcgU2V0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBwLl9fdHJlZVRhZ3Muc2V0KHRhZywgcyk7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICBzLmFkZCh0aGlzKTtcblxuICAgICAgICAgICAgICAgIH0gd2hpbGUgKCFwLl9fdGFnUm9vdCAmJiAocCA9IHAuX19wYXJlbnQpKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJlbW92ZVRhZyh0YWcpIHtcbiAgICAgICAgbGV0IGkgPSB0aGlzLl9fdGFncy5pbmRleE9mKHRhZyk7XG4gICAgICAgIGlmIChpICE9PSAtMSkge1xuICAgICAgICAgICAgdGhpcy5fX3RhZ3Muc3BsaWNlKGksIDEpO1xuXG4gICAgICAgICAgICAvLyBSZW1vdmUgZnJvbSB0cmVlVGFncyBoaWVyYXJjaHkuXG4gICAgICAgICAgICBsZXQgcCA9IHRoaXMuX19wYXJlbnQ7XG4gICAgICAgICAgICBpZiAocCkge1xuICAgICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICAgICAgbGV0IGxpc3QgPSBwLl9fdHJlZVRhZ3MuZ2V0KHRhZyk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChsaXN0KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBsaXN0LmRlbGV0ZSh0aGlzKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gd2hpbGUgKCFwLl9fdGFnUm9vdCAmJiAocCA9IHAuX19wYXJlbnQpKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGhhc1RhZyh0YWcpIHtcbiAgICAgICAgcmV0dXJuICh0aGlzLl9fdGFncyAmJiAodGhpcy5fX3RhZ3MuaW5kZXhPZih0YWcpICE9PSAtMSkpO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFJldHVybnMgb25lIG9mIHRoZSBlbGVtZW50cyBmcm9tIHRoZSBzdWJ0cmVlIHRoYXQgaGF2ZSB0aGlzIHRhZy5cbiAgICAgKiBAcGFyYW0ge3N0cmluZ30gdGFnXG4gICAgICogQHJldHVybnMge0VsZW1lbnR9XG4gICAgICovXG4gICAgX3RhZyh0YWcpIHtcbiAgICAgICAgaWYgKHRhZy5pbmRleE9mKFwiLlwiKSAhPT0gLTEpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLm10YWcodGFnKVswXTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9fdHJlZVRhZ3MpIHtcbiAgICAgICAgICAgICAgICBsZXQgdCA9IHRoaXMuX190cmVlVGFncy5nZXQodGFnKTtcbiAgICAgICAgICAgICAgICBpZiAodCkge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBpdGVtID0gdC52YWx1ZXMoKS5uZXh0KCk7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBpdGVtID8gaXRlbS52YWx1ZSA6IHVuZGVmaW5lZDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgZ2V0IHRhZygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3RhZztcbiAgICB9XG5cbiAgICBzZXQgdGFnKHQpIHtcbiAgICAgICAgdGhpcy50YWdzID0gdDtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBSZXR1cm5zIGFsbCBlbGVtZW50cyBmcm9tIHRoZSBzdWJ0cmVlIHRoYXQgaGF2ZSB0aGlzIHRhZy5cbiAgICAgKiBAcGFyYW0ge3N0cmluZ30gdGFnXG4gICAgICogQHJldHVybnMge0VsZW1lbnRbXX1cbiAgICAgKi9cbiAgICBtdGFnKHRhZykge1xuICAgICAgICBsZXQgaWR4ID0gdGFnLmluZGV4T2YoXCIuXCIpO1xuICAgICAgICBpZiAoaWR4ID49IDApIHtcbiAgICAgICAgICAgIGxldCBwYXJ0cyA9IHRhZy5zcGxpdCgnLicpO1xuICAgICAgICAgICAgbGV0IHJlcyA9IHRoaXMuX2dldEJ5VGFnKHBhcnRzWzBdKTtcbiAgICAgICAgICAgIGxldCBsZXZlbCA9IDE7XG4gICAgICAgICAgICBsZXQgYyA9IHBhcnRzLmxlbmd0aDtcbiAgICAgICAgICAgIHdoaWxlIChyZXMubGVuZ3RoICYmIGxldmVsIDwgYykge1xuICAgICAgICAgICAgICAgIGxldCByZXNuID0gW107XG4gICAgICAgICAgICAgICAgZm9yIChsZXQgaiA9IDAsIG4gPSByZXMubGVuZ3RoOyBqIDwgbjsgaisrKSB7XG4gICAgICAgICAgICAgICAgICAgIHJlc24gPSByZXNuLmNvbmNhdChyZXNbal0uX2dldEJ5VGFnKHBhcnRzW2xldmVsXSkpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIHJlcyA9IHJlc247XG4gICAgICAgICAgICAgICAgbGV2ZWwrKztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiByZXM7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fZ2V0QnlUYWcodGFnKTtcbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBzdGFnKHRhZywgc2V0dGluZ3MpIHtcbiAgICAgICAgbGV0IHQgPSB0aGlzLm10YWcodGFnKTtcbiAgICAgICAgbGV0IG4gPSB0Lmxlbmd0aDtcbiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIEJhc2UucGF0Y2hPYmplY3QodFtpXSwgc2V0dGluZ3MpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHRhZ1Jvb3QoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fdGFnUm9vdDtcbiAgICB9XG5cbiAgICBzZXQgdGFnUm9vdCh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9fdGFnUm9vdCAhPT0gdikge1xuICAgICAgICAgICAgaWYgKCF2KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fc2V0VGFnc1BhcmVudCgpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl91bnNldFRhZ3NQYXJlbnQoKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdGhpcy5fX3RhZ1Jvb3QgPSB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2VsKHBhdGgpIHtcbiAgICAgICAgY29uc3QgcmVzdWx0cyA9IHRoaXMuc2VsZWN0KHBhdGgpO1xuICAgICAgICBpZiAocmVzdWx0cy5sZW5ndGgpIHtcbiAgICAgICAgICAgIHJldHVybiByZXN1bHRzWzBdO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHVuZGVmaW5lZDtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHNlbGVjdChwYXRoKSB7XG4gICAgICAgIGlmIChwYXRoLmluZGV4T2YoXCIsXCIpICE9PSAtMSkge1xuICAgICAgICAgICAgbGV0IHNlbGVjdG9ycyA9IHBhdGguc3BsaXQoJywnKTtcbiAgICAgICAgICAgIGxldCByZXMgPSBbXTtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc2VsZWN0b3JzLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICAgICAgcmVzID0gcmVzLmNvbmNhdCh0aGlzLl9zZWxlY3Qoc2VsZWN0b3JzW2ldKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gcmVzO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3NlbGVjdChwYXRoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9zZWxlY3QocGF0aCkge1xuICAgICAgICBpZiAocGF0aCA9PT0gXCJcIikgcmV0dXJuIFt0aGlzXTtcblxuXG4gICAgICAgIGxldCBwb2ludElkeCA9IHBhdGguaW5kZXhPZihcIi5cIik7XG4gICAgICAgIGxldCBhcnJvd0lkeCA9IHBhdGguaW5kZXhPZihcIj5cIik7XG4gICAgICAgIGlmIChwb2ludElkeCA9PT0gLTEgJiYgYXJyb3dJZHggPT09IC0xKSB7XG4gICAgICAgICAgICAvLyBRdWljayBjYXNlLlxuICAgICAgICAgICAgcmV0dXJuIHRoaXMubXRhZyhwYXRoKTtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIERldGVjdCBieSBmaXJzdCBjaGFyLlxuICAgICAgICBsZXQgaXNSZWY7XG4gICAgICAgIGlmIChhcnJvd0lkeCA9PT0gMCkge1xuICAgICAgICAgICAgaXNSZWYgPSB0cnVlO1xuICAgICAgICAgICAgcGF0aCA9IHBhdGguc3Vic3RyKDEpO1xuICAgICAgICB9IGVsc2UgaWYgKHBvaW50SWR4ID09PSAwKSB7XG4gICAgICAgICAgICBpc1JlZiA9IGZhbHNlO1xuICAgICAgICAgICAgcGF0aCA9IHBhdGguc3Vic3RyKDEpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaXNSZWYgPSBmYWxzZTtcbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiB0aGlzLl9zZWxlY3RDaGlsZHMocGF0aCwgaXNSZWYpO1xuICAgIH1cblxuICAgIF9zZWxlY3RDaGlsZHMocGF0aCwgaXNSZWYpIHtcbiAgICAgICAgY29uc3QgcG9pbnRJZHggPSBwYXRoLmluZGV4T2YoXCIuXCIpO1xuICAgICAgICBjb25zdCBhcnJvd0lkeCA9IHBhdGguaW5kZXhPZihcIj5cIik7XG5cbiAgICAgICAgaWYgKHBvaW50SWR4ID09PSAtMSAmJiBhcnJvd0lkeCA9PT0gLTEpIHtcbiAgICAgICAgICAgIGlmIChpc1JlZikge1xuICAgICAgICAgICAgICAgIGNvbnN0IHJlZiA9IHRoaXMuZ2V0QnlSZWYocGF0aCk7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHJlZiA/IFtyZWZdIDogW107XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLm10YWcocGF0aCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoKGFycm93SWR4ID09PSAtMSkgfHwgKHBvaW50SWR4ICE9PSAtMSAmJiBwb2ludElkeCA8IGFycm93SWR4KSkge1xuICAgICAgICAgICAgbGV0IG5leHQ7XG4gICAgICAgICAgICBjb25zdCBzdHIgPSBwYXRoLnN1YnN0cigwLCBwb2ludElkeCk7XG4gICAgICAgICAgICBpZiAoaXNSZWYpIHtcbiAgICAgICAgICAgICAgICBjb25zdCByZWYgPSB0aGlzLmdldEJ5UmVmKHN0cik7XG4gICAgICAgICAgICAgICAgbmV4dCA9IHJlZiA/IFtyZWZdIDogW107XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIG5leHQgPSB0aGlzLm10YWcoc3RyKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGxldCB0b3RhbCA9IFtdO1xuICAgICAgICAgICAgY29uc3Qgc3ViUGF0aCA9IHBhdGguc3Vic3RyKHBvaW50SWR4ICsgMSk7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IG5leHQubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgdG90YWwgPSB0b3RhbC5jb25jYXQobmV4dFtpXS5fc2VsZWN0Q2hpbGRzKHN1YlBhdGgsIGZhbHNlKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gdG90YWw7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBsZXQgbmV4dDtcbiAgICAgICAgICAgIGNvbnN0IHN0ciA9IHBhdGguc3Vic3RyKDAsIGFycm93SWR4KTtcbiAgICAgICAgICAgIGlmIChpc1JlZikge1xuICAgICAgICAgICAgICAgIGNvbnN0IHJlZiA9IHRoaXMuZ2V0QnlSZWYoc3RyKTtcbiAgICAgICAgICAgICAgICBuZXh0ID0gcmVmID8gW3JlZl0gOiBbXTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgbmV4dCA9IHRoaXMubXRhZyhzdHIpO1xuICAgICAgICAgICAgfVxu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LmlkO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBzdHI7XG4gICAgfVxuXG4gICAgdG9TdHJpbmcoKSB7XG4gICAgICAgIGxldCBvYmogPSB0aGlzLmdldFNldHRpbmdzKCk7XG4gICAgICAgIHJldHVybiBFbGVtZW50LmdldFByZXR0eVN0cmluZyhvYmosIFwiXCIpO1xuICAgIH07XG5cbiAgICBzdGF0aWMgZ2V0UHJldHR5U3RyaW5nKG9iaiwgaW5kZW50KSB7XG4gICAgICAgIGxldCBjaGlsZHJlbiA9IG9iai5jaGlsZHJlbjtcbiAgICAgICAgZGVsZXRlIG9iai5jaGlsZHJlbjtcblxuXG4gICAgICAgIC8vIENvbnZlcnQgc2luZ3VsYXIganNvbiBzZXR0aW5ncyBvYmplY3QuXG4gICAgICAgIGxldCBjb2xvcktleXMgPSBbXCJjb2xvclwiLCBcImNvbG9yVWxcIiwgXCJjb2xvclVyXCIsIFwiY29sb3JCbFwiLCBcImNvbG9yQnJcIl07XG4gICAgICAgIGxldCBzdHIgPSBKU09OLnN0cmluZ2lmeShvYmosIGZ1bmN0aW9uIChrLCB2KSB7XG4gICAgICAgICAgICBpZiAoY29sb3JLZXlzLmluZGV4T2YoaykgIT09IC0xKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIFwiQ09MT1JbXCIgKyB2LnRvU3RyaW5nKDE2KSArIFwiXVwiO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIHY7XG4gICAgICAgIH0pO1xuICAgICAgICBzdHIgPSBzdHIucmVwbGFjZSgvXCJDT0xPUlxcWyhbYS1mMC05XXsxLDh9KVxcXVwiL2csIFwiMHgkMVwiKTtcblxuICAgICAgICBpZiAoY2hpbGRyZW4pIHtcbiAgICAgICAgICAgIGxldCBjaGlsZFN0ciA9IFwiXCI7XG4gICAgICAgICAgICBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKGNoaWxkcmVuKSkge1xuICAgICAgICAgICAgICAgIGxldCByZWZzID0gT2JqZWN0LmtleXMoY2hpbGRyZW4pO1xuICAgICAgICAgICAgICAgIGNoaWxkU3RyID0gXCJcIjtcbiAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHJlZnMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgIGNoaWxkU3RyICs9IGBcXG4ke2luZGVudH0gIFwiJHtyZWZzW2ldfVwiOmBcbiAgICAgICAgICAgICAgICAgICAgZGVsZXRlIGNoaWxkcmVuW3JlZnNbaV1dLnJlZjtcbiAgICAgICAgICAgICAgICAgICAgY2hpbGRTdHIgKz0gRWxlbWVudC5nZXRQcmV0dHlTdHJpbmcoY2hpbGRyZW5bcmVmc1tpXV0sIGluZGVudCArIFwiICBcIikgKyAoaSA8IG4gLSAxID8gXCIsXCIgOiBcIlwiKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgbGV0IGlzRW1wdHkgPSAoc3RyID09PSBcInt9XCIpO1xuICAgICAgICAgICAgICAgIHN0ciA9IHN0ci5zdWJzdHIoMCwgc3RyLmxlbmd0aCAtIDEpICsgKGlzRW1wdHkgPyBcIlwiIDogXCIsXCIpICsgY2hpbGRTdHIgKyBcIlxcblwiICsgaW5kZW50ICsgXCJ9XCI7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGxldCBuID0gY2hpbGRyZW4ubGVuZ3RoO1xuICAgICAgICAgICAgICAgIGNoaWxkU3RyID0gXCJbXCI7XG4gICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgY2hpbGRTdHIgKz0gRWxlbWVudC5nZXRQcmV0dHlTdHJpbmcoY2hpbGRyZW5baV0sIGluZGVudCArIFwiICBcIikgKyAoaSA8IG4gLSAxID8gXCIsXCIgOiBcIlwiKSArIFwiXFxuXCI7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNoaWxkU3RyICs9IGluZGVudCArIFwiXX1cIjtcbiAgICAgICAgICAgICAgICBsZXQgaXNFbXB0eSA9IChzdHIgPT09IFwie31cIik7XG4gICAgICAgICAgICAgICAgc3RyID0gc3RyLnN1YnN0cigwLCBzdHIubGVuZ3RoIC0gMSkgKyAoaXNFbXB0eSA/IFwiXCIgOiBcIixcIikgKyBcIlxcXCJjaGlsZHJlblxcXCI6XFxuXCIgKyBpbmRlbnQgKyBjaGlsZFN0ciArIFwifVwiO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gc3RyO1xuICAgIH1cblxuICAgIGdldFNldHRpbmdzKCkge1xuICAgICAgICBsZXQgc2V0dGluZ3MgPSB0aGlzLmdldE5vbkRlZmF1bHRzKCk7XG5cbiAgICAgICAgbGV0IGNoaWxkcmVuID0gdGhpcy5fY2hpbGRyZW4uZ2V0KCk7XG4gICAgICAgIGlmIChjaGlsZHJlbikge1xuICAgICAgICAgICAgbGV0IG4gPSBjaGlsZHJlbi5sZW5ndGg7XG4gICAgICAgICAgICBpZiAobikge1xuICAgICAgICAgICAgICAgIGNvbnN0IGNoaWxkQXJyYXkgPSBbXTtcbiAgICAgICAgICAgICAgICBsZXQgbWlzc2luZyA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgIGNoaWxkQXJyYXkucHVzaChjaGlsZHJlbltpXS5nZXRTZXR0aW5ncygpKTtcbiAgICAgICAgICAgICAgICAgICAgbWlzc2luZyA9IG1pc3NpbmcgfHwgIWNoaWxkcmVuW2ldLnJlZjtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAoIW1pc3NpbmcpIHtcbiAgICAgICAgICAgICAgICAgICAgc2V0dGluZ3MuY2hpbGRyZW4gPSB7fVxuICAgICAgICAgICAgICAgICAgICBjaGlsZEFycmF5LmZvckVhY2goY2hpbGQgPT4ge1xuICAgICAgICAgICAgICAgICAgICAgICAgc2V0dGluZ3MuY2hpbGRyZW5bY2hpbGQucmVmXSA9IGNoaWxkO1xuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBzZXR0aW5ncy5jaGlsZHJlbiA9IGNoaWxkQXJyYXk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgc2V0dGluZ3MuaWQgPSB0aGlzLmlkO1xuXG4gICAgICAgIHJldHVybiBzZXR0aW5ncztcbiAgICB9XG5cbiAgICBnZXROb25EZWZhdWx0cygpIHtcbiAgICAgICAgbGV0IHNldHRpbmdzID0ge307XG5cbiAgICAgICAgaWYgKHRoaXMuY29uc3RydWN0b3IgIT09IEVsZW1lbnQpIHtcbiAgICAgICAgICAgIHNldHRpbmdzLnR5cGUgPSB0aGlzLmNvbnN0cnVjdG9yLm5hbWU7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5fX3JlZikge1xuICAgICAgICAgICAgc2V0dGluZ3MucmVmID0gdGhpcy5fX3JlZjtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLl9fdGFncyAmJiB0aGlzLl9fdGFncy5sZW5ndGgpIHtcbiAgICAgICAgICAgIHNldHRpbmdzLnRhZ3MgPSB0aGlzLl9fdGFncztcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLnggIT09IDApIHNldHRpbmdzLnggPSB0aGlzLng7XG4gICAgICAgIGlmICh0aGlzLnkgIT09IDApIHNldHRpbmdzLnkgPSB0aGlzLnk7XG4gICAgICAgIGlmICh0aGlzLncgIT09IDApIHNldHRpbmdzLncgPSB0aGlzLnc7XG4gICAgICAgIGlmICh0aGlzLmggIT09IDApIHNldHRpbmdzLmggPSB0aGlzLmg7XG5cbiAgICAgICAgaWYgKHRoaXMuc2NhbGVYID09PSB0aGlzLnNjYWxlWSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuc2NhbGVYICE9PSAxKSBzZXR0aW5ncy5zY2FsZSA9IHRoaXMuc2NhbGVYO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHRoaXMuc2NhbGVYICE9PSAxKSBzZXR0aW5ncy5zY2FsZVggPSB0aGlzLnNjYWxlWDtcbiAgICAgICAgICAgIGlmICh0aGlzLnNjYWxlWSAhPT0gMSkgc2V0dGluZ3Muc2NhbGVZID0gdGhpcy5zY2FsZVk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5waXZvdFggPT09IHRoaXMucGl2b3RZKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5waXZvdFggIT09IDAuNSkgc2V0dGluZ3MucGl2b3QgPSB0aGlzLnBpdm90WDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh0aGlzLnBpdm90WCAhPT0gMC41KSBzZXR0aW5ncy5waXZvdFggPSB0aGlzLnBpdm90WDtcbiAgICAgICAgICAgIGlmICh0aGlzLnBpdm90WSAhPT0gMC41KSBzZXR0aW5ncy5waXZvdFkgPSB0aGlzLnBpdm90WTtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLm1vdW50WCA9PT0gdGhpcy5tb3VudFkpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLm1vdW50WCAhPT0gMCkgc2V0dGluZ3MubW91bnQgPSB0aGlzLm1vdW50WDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh0aGlzLm1vdW50WCAhPT0gMCkgc2V0dGluZ3MubW91bnRYID0gdGhpcy5tb3VudFg7XG4gICAgICAgICAgICBpZiAodGhpcy5tb3VudFkgIT09IDApIHNldHRpbmdzLm1vdW50WSA9IHRoaXMubW91bnRZO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuYWxwaGEgIT09IDEpIHNldHRpbmdzLm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b250ZXh0KSBzZXR0aW5ncy5mb3JjZVpJbmRleENvbnRleHQgPSB0cnVlO1xuXG4gICAgICAgIGlmICh0aGlzLmNsaXBwaW5nKSBzZXR0aW5ncy5jbGlwcGluZyA9IHRoaXMuY2xpcHBpbmc7XG5cbiAgICAgICAgaWYgKCF0aGlzLmNsaXBib3gpIHNldHRpbmdzLmNsaXBib3ggPSB0aGlzLmNsaXBib3g7XG5cbiAgICAgICAgaWYgKHRoaXMuX190ZXh0dXJlKSB7XG4gICAgICAgICAgICBsZXQgdG5kID0gdGhpcy5fX3RleHR1cmUuZ2V0Tm9uRGVmYXVsdHMoKTtcbiAgICAgICAgICAgIGlmIChPYmplY3Qua2V5cyh0bmQpLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgIHNldHRpbmdzLnRleHR1cmUgPSB0bmQ7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBpZiAodGhpcy5zaGFkZXIgJiYgVXRpbHMuaXNGdW5jdGlvbih0aGlzLnNoYWRlci5nZXROb25EZWZhdWx0cykpIHtcbiAgICAgICAgICAgIGxldCB0bmQgPSB0aGlzLnNoYWRlci5nZXROb25EZWZhdWx0cygpO1xuICAgICAgICAgICAgaWYgKE9iamVjdC5rZXlzKHRuZCkubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgc2V0dGluZ3Muc2hhZGVyID0gdG5kO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuX2hhc1RleHR1cml6ZXIoKSkge1xuICAgICAgICAgICAgaWYgKHRoaXMudGV4dHVyaXplci5lbmFibGVkKSB7XG4gICAgICAgICAgICAgICAgc2V0dGluZ3MucmVuZGVyVG9UZXh0dXJlID0gdGhpcy50ZXh0dXJpemVyLmVuYWJsZWQ7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy50ZXh0dXJpemVyLmxhenkpIHtcbiAgICAgICAgICAgICAgICBzZXR0aW5ncy5yZW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Ym91bmRzTWFyZ2luID0gdjtcbiAgICB9XG5cbiAgICBnZXQgYm91bmRzTWFyZ2luKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUuYm91bmRzTWFyZ2luO1xuICAgIH1cblxuICAgIGdldCB4KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUub2Zmc2V0WDtcbiAgICB9XG5cbiAgICBzZXQgeCh2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLm9mZnNldFggPSB2O1xuICAgIH1cblxuICAgIGdldCB5KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUub2Zmc2V0WTtcbiAgICB9XG5cbiAgICBzZXQgeSh2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLm9mZnNldFkgPSB2O1xuICAgIH1cblxuICAgIGdldCB3KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdztcbiAgICB9XG5cbiAgICBzZXQgdyh2KSB7XG4gICAgICAgIGlmIChVdGlscy5pc0Z1bmN0aW9uKHYpKSB7XG4gICAgICAgICAgICB0aGlzLl93ID0gMDtcbiAgICAgICAgICAgIHRoaXMuX19jb3JlLmZ1bmNXID0gdjtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHYgPSBNYXRoLm1heCh2LCAwKTtcbiAgICAgICAgICAgIGlmICh0aGlzLl93ICE9PSB2KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fX2NvcmUuZGlzYWJsZUZ1bmNXKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fdyA9IHY7XG4gICAgICAgICAgICAgICAgdGhpcy5fdXBkYXRlRGltZW5zaW9ucygpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGgoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9oO1xuICAgIH1cblxuICAgIHNldCBoKHYpIHtcbiAgICAgICAgaWYgKFV0aWxzLmlzRnVuY3Rpb24odikpIHtcbiAgICAgICAgICAgIHRoaXMuX2ggPSAwO1xuICAgICAgICAgICAgdGhpcy5fX2NvcmUuZnVuY0ggPSB2O1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdiA9IE1hdGgubWF4KHYsIDApO1xuICAgICAgICAgICAgaWYgKHRoaXMuX2ggIT09IHYpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9fY29yZS5kaXNhYmxlRnVuY0goKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9oID0gdjtcbiAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVEaW1lbnNpb25zKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgY29sbGlzaW9uKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fY29sbGlzaW9uO1xuICAgIH1cblxuICAgIHNldCBjb2xsaXNpb24odikge1xuICAgICAgICB0aGlzLl9jb2xsaXNpb24gPSB2O1xuICAgIH1cblxuICAgIF91cGRhdGVDb2xsaXNpb24oKSB7XG4gICAgICAgIGlmICh0aGlzLmNvbGxpc2lvbiAmJiB0aGlzLl9fcGFyZW50ICYmIHRoaXMuX19wYXJlbnQuY29sbGlzaW9uID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIC8qKlxuICAgICAgICAgICAgICogTWFyayBjb2xsaXNpb24gYXMgMiB0byBpbmRpY2F0ZSBhdGxlYXN0IG9uZSBkZXNjZW5kYW50IGhhcyBjb2xsaXNpb24gZW5hYmxlZC5cbiAgICAgICAgICAgICAqIFRoaXMgbmFycm93cyBkb3duIHRoZSBzZWFyY2ggZm9yIGVsZW1lbnRzIHdpdGggYWN0aXZlIGNvbGxpc2lvbi5cbiAgICAgICAgICAgICovXG4gICAgICAgICAgICB0aGlzLl9fcGFyZW50LmNvbGxpc2lvbiA9IDI7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgc2NhbGVYKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUuc2NhbGV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XQgbW91bnRZKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUubW91bnRZO1xuICAgIH1cblxuICAgIHNldCBtb3VudFkodikge1xuICAgICAgICB0aGlzLl9fY29yZS5tb3VudFkgPSB2O1xuICAgIH1cblxuICAgIGdldCBtb3VudCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLm1vdW50O1xuICAgIH1cblxuICAgIHNldCBtb3VudCh2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLm1vdW50ID0gdjtcbiAgICB9XG5cbiAgICBnZXQgcm90YXRpb24oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fY29yZS5yb3RhdGlvbjtcbiAgICB9XG5cbiAgICBzZXQgcm90YXRpb24odikge1xuICAgICAgICB0aGlzLl9fY29yZS5yb3RhdGlvbiA9IHY7XG4gICAgfVxuXG4gICAgZ2V0IGFscGhhKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUuYWxwaGE7XG4gICAgfVxuXG4gICAgc2V0IGFscGhhKHYpIHtcbiAgICAgICAgdGhpcy5fX2NvcmUuYWxwaGEgPSB2O1xuICAgIH1cblxuICAgIGdldCB2aXNpYmxlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fX2NvcmUudmlzaWJsZTtcbiAgICB9XG5cbiAgICBzZXQgdmlzaWJsZSh2KSB7XG4gICAgICAgIHRoaXMuX19jb3JlLnZpc2libGUgPSB2O1xuICAgIH1cbiAgICBcbiAgICBnZXQgY29sb3JVbCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLmNvbG9yVWw7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yVWwodikge1xuICAgICAgICB0aGlzLl9fY29yZS5jb2xvclVsID0gdjtcbiAgICB9XG5cbiAgICBnZXQgY29sb3JVcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLmNvbG9yVXI7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yVXIodikge1xuICAgICAgICB0aGlzLl9fY29yZS5jb2xvclVyID0gdjtcbiAgICB9XG5cbiAgICBnZXQgY29sb3JCbCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLmNvbG9yQmw7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yQmwodikge1xuICAgICAgICB0aGlzLl9fY29yZS5jb2xvckJsID0gdjtcbiAgICB9XG5cbiAgICBnZXQgY29sb3JCcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLmNvbG9yQnI7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yQnIodikge1xuICAgICAgICB0aGlzLl9fY29yZS5jb2xvckJyID0gdjtcbiAgICB9XG5cbiAgICBnZXQgY29sb3IoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9fY29yZS5jb2xvclVsO1xuICAgIH1cblxuICAgIHNldCBjb2xvcih2KSB7XG4gICAgICAgIGlmICh0aGlzLmNvbG9yVWwgIT09IHYgfHwgdGhpcy5jb2xvclVyICE9PSB2IHx8IHRoaXMuY29sb3JCbCAhPT0gdiB8fCB0aGlzLmNvbG9yQnIgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuY29sb3JVbCA9IHY7XG4gICAgICAgICAgICB0aGlzLmNvbG9yVXIgPSB2O1xuICAgICAgICAgICAgdGhpcy5jb2xvckJsID0gdjtcbiAgICAgICAgICAgIHRoaXMuY29sb3JCciA9IHY7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgY29sb3JUb3AoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLmNvbG9yVWw7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yVG9wKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuY29sb3JVbCAhPT0gdiB8fCB0aGlzLmNvbG9yVXIgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuY29sb3JVbCA9IHY7XG4gICAgICAgICAgICB0aGlzLmNvbG9yVXIgPSB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGNvbG9yQm90dG9tKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5jb2xvckJsO1xuICAgIH1cblxuICAgIHNldCBjb2xvckJvdHRvbSh2KSB7XG4gICAgICAgIGlmICh0aGlzLmNvbG9yQmwgIT09IHYgfHwgdGhpcy5jb2xvckJyICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLmNvbG9yQmwgPSB2O1xuICAgICAgICAgICAgdGhpcy5jb2xvckJyID0gdjtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBjb2xvckxlZnQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLmNvbG9yVWw7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yTGVmdCh2KSB7XG4gICAgICAgIGlmICh0aGlzLmNvbG9yVWwgIT09IHYgfHwgdGhpcy5jb2xvckJsICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLmNvbG9yVWwgPSB2O1xuICAgICAgICAgICAgdGhpcy5jb2xvckJsID0gdjtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBjb2xvclJpZ2h0KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5jb2xvclVyO1xuICAgIH1cblxuICAgIHNldCBjb2xvclJpZ2h0KHYpIHtcbiAgICAgICAgaWYgKHRoaXMuY29sb3JVciAhPT0gdiB8fCB0aGlzLmNvbG9yQnIgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuY29sb3JVciA9IHY7XG4gICAgICAgICAgICB0aGlzLmNvbG9yQnIgPSB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHpJbmRleCgpIHtyZXR1cm4gdGhpcy5fX2NvcmUuekluZGV4fVxuICAgIHNldCB6SW5kZXgodikge1xuICAgICAgICB0aGlzLl9fY29yZS56SW5kZXggPSB2O1xuICAgIH1cblxuICAgIGdldCBmb3JjZVpJbmRleENvbnRleHQoKSB7cmV0dXJuIHRoaXMuX19jb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XG4gICAgZW5hYmxlVGV4dFRleHR1cmUoKSB7XG4gICAgICAgIGlmICghdGhpcy50ZXh0dXJlIHx8ICEodGhpcy50ZXh0dXJlIGluc3RhbmNlb2YgVGV4dFRleHR1cmUpKSB7XG4gICAgICAgICAgICB0aGlzLnRleHR1cmUgPSBuZXcgVGV4dFRleHR1cmUodGhpcy5zdGFnZSk7XG5cbiAgICAgICAgICAgIGlmICghdGhpcy50ZXh0dXJlLncgJiYgIXRoaXMudGV4dHVyZS5oKSB7XG4gICAgICAgICAgICAgICAgLy8gSW5oZXJpdCBkaW1lbnNpb25zIGZyb20gZWxlbWVudC5cbiAgICAgICAgICAgICAgICAvLyBUaGlzIGFsbG93cyB1c2VybGFuZCB0byBzZXQgZGltZW5zaW9ucyBvZiB0aGUgRWxlbWVudCBhbmQgdGhlbiBsYXRlciBzcGVjaWZ5IHRoZSB0ZXh0LlxuICAgICAgICAgICAgICAgIHRoaXMudGV4dHVyZS53ID0gdGhpcy53O1xuICAgICAgICAgICAgICAgIHRoaXMudGV4dHVyZS5oID0gdGhpcy5oO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0aGlzLnRleHR1cmU7XG4gICAgfVxuXG4gICAgZ2V0IHRleHQoKSB7XG4gICAgICAgIGlmICh0aGlzLnRleHR1cmUgJiYgKHRoaXMudGV4dHVyZSBpbnN0YW5jZW9mIFRleHRUZXh0dXJlKSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMudGV4dHVyZTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiBudWxsO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2V0IHRleHQodikge1xuICAgICAgICBpZiAoIXRoaXMudGV4dHVyZSB8fCAhKHRoaXMudGV4dHVyZSBpbnN0YW5jZW9mIFRleHRUZXh0dXJlKSkge1xuICAgICAgICAgICAgdGhpcy5lbmFibGVUZXh0VGV4dHVyZSgpO1xuICAgICAgICB9XG4gIC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yaXplci5sYXp5ID0gdjtcbiAgICB9XG5cbiAgICBnZXQgcmVuZGVyT2Zmc2NyZWVuKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faGFzVGV4dHVyaXplcigpICYmIHRoaXMudGV4dHVyaXplci5yZW5kZXJPZmZzY3JlZW47XG4gICAgfVxuXG4gICAgc2V0IHJlbmRlck9mZnNjcmVlbih2KSB7XG4gICAgICAgIHRoaXMudGV4dHVyaXplci5yZW5kZXJPZmZzY3JlZW4gPSB2O1xuICAgIH1cblxuICAgIGdldCBjb2xvcml6ZVJlc3VsdFRleHR1cmUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9oYXNUZXh0dXJpemVyKCkgJiYgdGhpcy50ZXh0dXJpemVyLmNvbG9yaXplO1xuICAgIH1cblxuICAgIHNldCBjb2xvcml6ZVJlc3VsdFRleHR1cmUodikge1xuICAgICAgICB0aGlzLnRleHR1cml6ZXIuY29sb3JpemUgPSB2O1xuICAgIH1cblxuICAgIGdldFRleHR1cmUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnRleHR1cml6ZXIuX2dldFRleHR1cmVTb3VyY2UoKTtcbiAgICB9XG5cbiAgICBnZXQgdGV4dHVyaXplcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX19jb3JlLnRleHR1cml6ZXI7XG4gICAgfVxuXG4gICAgcGF0Y2goc2V0dGluZ3MpIHtcbiAgICAgICAgbGV0IHBhdGhzID0gT2JqZWN0LmtleXMoc2V0dGluZ3MpO1xuXG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gcGF0aHMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBsZXQgcGF0aCA9IHBhdGhzW2ldO1xuICAgICAgICAgICAgY29uc3QgdiA9IHNldHRpbmdzW3BhdGhdO1xuXG4gICAgICAgICAgICBjb25zdCBmaXJzdENoYXJDb2RlID0gcGF0aC5jaGFyQ29kZUF0KDApO1xuICAgICAgICAgICAgaWYgKFV0aWxzLmlzVWNDaGFyKGZpcnN0Q2hhckNvZGUpKSB7XG4gICAgICAgICAgICAgICAgLy8gUmVmLlxuICAgICAgICAgICAgICAgIGNvbnN0IGNoaWxkID0gdGhpcy5nZXRCeVJlZihwYXRoKTtcbiAgICAgICAgICAgICAgICBpZiAoIWNoaWxkKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICh2ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEFkZCB0byBsaXN0IGltbWVkaWF0ZWx5LlxuICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGM7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKHYpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gQ2F0Y2ggdGhpcyBjYXNlIHRvIGNhcHR1cmUgY3JlYXRlTW9kZSBmbGFnLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGMgPSB0aGlzLmNoaWxkTGlzdC5jcmVhdGVJdGVtKHYpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGMucGF0Y2godik7XG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKFV0aWxzLmlzT2JqZWN0KHYpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgYyA9IHY7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoYy5pc0VsZW1lbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjLnJlZiA9IHBhdGg7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmEoYyk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBpZiAodiA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoY2hpbGQucGFyZW50KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hpbGQucGFyZW50LmNoaWxkTGlzdC5yZW1vdmUoY2hpbGQpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKFV0aWxzLmlzT2JqZWN0TGl0ZXJhbCh2KSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgY2hpbGQucGF0Y2godik7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodi5pc0VsZW1lbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFJlcGxhY2UgZWxlbWVudCBieSBuZXcgZWxlbWVudC5cbiAgICAgICAgICAgICAgICAgICAgICAgIHYucmVmID0gcGF0aDtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LnJlcGxhY2UodiwgY2hpbGQpO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fdGhyb3dFcnJvcihcIlVuZXhwZWN0ZWQgdmFsdWUgZm9yIHBhdGg6IFwiICsgcGF0aCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIFByb3BlcnR5LlxuICAgICAgICAgICAgICAgIEJhc2UucGF0Y2hPYmplY3RQcm9wZXJ0eSh0aGlzLCBwYXRoLCB2KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF90aHJvd0Vycm9yKG1lc3NhZ2UpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKHRoaXMuY29uc3RydWN0b3IubmFtZSArIFwiIChcIiArIHRoaXMuZ2V0TG9jYXRpb25TdHJpbmcoKSArIFwiKTogXCIgKyBtZXNzYWdlKTtcbiAgICB9XG5cbiAgICBhbmltYXRpb24oc2V0dGluZ3MpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuc3RhZ2UuYW5pbWF0aW9ucy5jcmVhdGVBbmltYXRpb24odGhpcywgc2V0dGluZ3MpO1xuICAgIH1cblxuICAgIHRyYW5zaXRpb24ocHJvcGVydHksIHNldHRpbmdzID0gbnVsbCkge1xuICAgICAgICBpZiAoc2V0dGluZ3MgPT09IG51bGwpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9nZXRUcmFuc2l0aW9uKHByb3BlcnR5KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX3NldFRyYW5zaXRpb24ocHJvcGVydHksIHNldHRpbmdzKTtcbiAgICAgICAgICAgIC8vIFdlIGRvIG5vdCBjcmVhdGUvcmV0dXJuIHRoZSB0cmFuc2l0aW9uLCBiZWNhdXNlIGl0IHdvdWxkIHVuZG8gdGhlICdsYXp5IHRyYW5zaXRpb24gY3JlYXRpb24nIG9wdGltaXphdGlvbi5cbiAgICAgICAgICAgIHJldHVybiBudWxsO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2V0IHRyYW5zaXRpb25zKG9iamVjdCkge1xuICAgICAgICBsZXQga2V5cyA9IE9iamVjdC5rZXlzKG9iamVjdCk7XG4gICAgICAgIGtleXMuZm9yRWFjaChwcm9wZXJ0eSA9PiB7XG4gICAgICAgICAgICB0aGlzLnRyYW5zaXRpb24ocHJvcGVydHksIG9iamVjdFtwcm9wZXJ0eV0pO1xuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBzZXQgc21vb3RoKG9iamVjdCkge1xuICAgICAgICBsZXQga2V5cyA9IE9iamVjdC5rZXlzKG9iamVjdCk7XG4gICAgICAgIGtleXMuZm9yRWFjaChwcm9wZXJ0eSA9PiB7XG4gICAgICAgICAgICBsZXQgdmFsdWUgPSBvYmplY3RbcHJvcGVydHldO1xuICAgICAgICAgICAgaWYgKEFycmF5LmlzQXJyYXkodmFsdWUpKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5zZXRTbW9vdGgocHJvcGVydHksIHZhbHVlWzBdLCB2YWx1ZVsxXSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuc2V0U21vb3RoKHByb3BlcnR5LCB2YWx1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIGZhc3RGb3J3YXJkKHByb3BlcnR5KSB7XG4gICAgICAgIGlmICh0aGlzLl90cmFuc2l0aW9ucykge1xuICAgICAgICAgICAgbGV0IHQgPSB0aGlzLl90cmFuc2l0aW9uc1twcm9wZXJ0eV07XG4gICAgICAgICAgICBpZiAodCAmJiB0LmlzVHJhbnNpdGlvbikge1xuICAgICAgICAgICAgICAgIHQuZmluaXNoKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZ2V0VHJhbnNpdGlvbihwcm9wZXJ0eSkge1xuICAgICAgICBpZiAoIXRoaXMuX3RyYW5zaXRpb25zKSB7XG4gICAgICAgICAgICB0aGlzLl90cmFuc2l0aW9ucyA9IHt9O1xuICAgICAgICB9XG4gICAgICAgIGxldCB0ID0gdGhpcy5fdHJhbnNpdGlvbnNbcHJvcGVydHldO1xuICAgICAgICBpZiAoIXQpIHtcbiAgICAgICAgICAgIC8vIENyZWF0ZSBkZWZhdWx0IHRyYW5zaXRpb24uXG4gICAgICAgICAgICB0ID0gbmV3IFRyYW5zaXRpb24odGhpcy5zdGFnZS50cmFuc2l0aW9ucywgdGhpcy5zdGFnZS50cmFuc2l0aW9ucy5kZWZhdWx0VHJhbnNpdGlvblNldHRpbmdzLCB0aGlzLCBwcm9wZXJ0eSk7XG4gICAgICAgIH0gZWxzZSBpZiAodC5pc1RyYW5zaXRpb25TZXR0aW5ncykge1xuICAgICAgICAgICAgLy8gVXBncmFkZSB0byAncmVhbCcgdHJhbnNpdGlvbi5cbiAgICAgICAgICAgIHQgPSBuZXcgVHJhbnNpdGlvbihcbiAgICAgICAgICAgICAgICB0aGlzLnN0YWdlLnRyYW5zaXRpb25zLFxuICAgICAgICAgICAgICAgIHQsXG4gICAgICAgICAgICAgICAgdGhpcyxcbiAgICAgICAgICAgICAgICBwcm9wZXJ0eVxuICAgICAgICAgICAgKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl90cmFuc2l0aW9uc1twcm9wZXJ0eV0gPSB0O1xuICAgICAgICByZXR1cm4gdDtcbiAgICB9XG5cbiAgICBfc2V0VHJhbnNpdGlvbihwcm9wZXJ0eSwgc2V0dGluZ3MpIHtcbiAgICAgICAgaWYgKCFzZXR0aW5ncykge1xuICAgICAgICAgICAgdGhpcy5fcmVtb3ZlVHJhbnNpdGlvbihwcm9wZXJ0eSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKHNldHRpbmdzKSkge1xuICAgICAgICAgICAgICAgIC8vIENvbnZlcnQgcGxhaW4gb2JqZWN0IHRvIHByb3BlciBzZXR0aW5ncyBvYmplY3QuXG4gICAgICAgICAgICAgICAgc2V0dGluZ3MgPSB0aGlzLnN0YWdlLnRyYW5zaXRpb25zLmNyZWF0ZVNldHRpbmdzKHNldHRpbmdzKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKCF0aGlzLl90cmFuc2l0aW9ucykge1xuICAgICAgICAgICAgICAgIHRoaXMuX3RyYW5zaXRpb25zID0ge307XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGxldCBjdXJyZW50ID0gdGhpcy5fdHJhbnNpdGlvbnNbcHJvcGVydHldO1xuICAgICAgICAgICAgaWYgKGN1cnJlbnQgJiYgY3VycmVudC5pc1RyYW5zaXRpb24pIHtcbiAgICAgICAgICAgICAgICAvLyBSdW50aW1lIHNldHRpbmdzIGNoYW5nZS5cbiAgICAgICAgICAgICAgICBjdXJyZW50LnNldHRpbmdzID0gc2V0dGluZ3M7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGN1cnJlbnQ7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIC8vIEluaXRpYWxseSwgb25seSBzZXQgdGhlIHNldHRpbmdzIGFuZCB1cGdyYWRlIHRvIGEgJ3JlYWwnIHRyYW5zaXRpb24gd2hlbiBpdCBpcyB1c2VkLlxuICAgICAgICAgICAgICAgIHRoaXMuX3RyYW5zaXRpb25zW3Byb3BlcnR5XSA9IHNldHRpbmdzO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgX3JlbW92ZVRyYW5zaXRpb24ocHJvcGVydHkpIHtcbiAgICAgICAgaWYgKHRoaXMuX3RyYW5zaXRpb25zKSB7XG4gICAgICAgICAgICBkZWxldGUgdGhpcy5fdHJhbnNpdGlvbnNbcHJvcGVydHldO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0U21vb3RoKHByb3BlcnR5LCB2KSB7XG4gICAgICAgIGxldCB0ID0gdGhpcy5fZ2V0VHJhbnNpdGlvbihwcm9wZXJ0eSk7XG4gICAgICAgIGlmICh0ICYmIHQuaXNBdHRhY2hlZCgpKSB7XG4gICAgICAgICAgICByZXR1cm4gdC50YXJnZXRWYWx1ZTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2V0U21vb3RoKHByb3BlcnR5LCB2LCBzZXR0aW5ncykge1xuICAgICAgICBpZiAoc2V0dGluZ3MpIHtcbiAgICAgICAgICAgIHRoaXMuX3NldFRyYW5zaXRpb24ocHJvcGVydHksIHNldHRpbmdzKTtcbiAgICAgICAgfVxuICAgICAgICBsZXQgdCA9IHRoaXMuX2dldFRyYW5zaXRpb24ocHJvcGVydHkpO1xuICAgICAgICB0LnN0YXJ0KHYpO1xuICAgICAgICByZXR1cm4gdDtcbiAgICB9XG5cbiAgICB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ImJvdW5kc01hcmdpblwiLCBcImNvbG9yXCIsIFwiY2xpcHBpbmdcIiwgXCJlbmFibGVkXCIsIFwiaFwiLCBcImlkXCIsIFwiaXNDb21wb25lbnRcIixcbiAgICAgICAgICAgIFwibW91bnRcIiwgXCJtb3VudFlcIiwgXCJtb3VudFhcIiwgXCJwaXZvdFwiLCBcInBpdm90WFwiLCBcInBpdm90WVwiLCBcInJlZlwiLCBcInJlbmRlck9mZnNjcmVlblwiLCBcInJlbmRlclRvVGV4dHVyZVwiLCBcInNjYWxlXCIsXG4gICAgICAgICAgICBcInNjYWxlWFwiLCBcInNjYWxlWVwiLCBcInN0YXRlXCIsIFwidGFnXCIsIFwidmlzaWJsZVwiLCBcIndcIiwgXCJ4XCIsIFwieVwiLCBcInpJbmRleFwiLFxuICAgICAgICAgICAgXCIhIWZsZXhcIiwgXCIhIWZsZXhJdGVtXCIsIFwiaGFzRm9jdXMoKVwiLCBcImhhc0ZpbmFsRm9jdXMoKVwiXG4gICAgICAgIF07XG4gICAgICAgIGxldCBuID0gbGlzdC5sZW5ndGg7XG5cbiAgICAgICAgd2hpbGUgKG4tLSkge1xuICAgICAgICAgICAgbGV0IGtleSA9IGxpc3Rbbl07XG4gICAgICAgICAgICBjb25zdCBnZXRCb29sZWFuID0gL14hezJ9LztcbiAgICAgICAgICAgIGNvbnN0IGlzRnVuY3Rpb24gPSAvXFwoXFwpJC87XG5cbiAgICAgICAgICAgIGlmIChnZXRCb29sZWFuLnRlc3Qoa2V5KSkge1xuICAgICAgICAgICAgICAgIGtleSA9IGtleS5zdWJzdHJpbmcoMiwga2V5Lmxlbmd0aCk7XG4gICAgICAgICAgICAgICAgcHJvcHNba2V5XSA9ICEhZWxlbWVudFtrZXldO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChpc0Z1bmN0aW9uLnRlc3Qoa2V5KSkge1xuICAgICAgICAgICAgICAgIGtleSA9IGtleS5zdWJzdHJpbmcoMCwga2V5Lmxlbmd0aCAtIDIpO1xuICA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nBhdGNoKG8pO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoY3VycmVudEluZGV4ICE9IC0xKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5zZXRBdChpdGVtLCBpbmRleCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGlmIChpdGVtLnJlZikge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZWZzW2l0ZW0ucmVmXSA9IGl0ZW07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHRoaXMuX2l0ZW1zLnNwbGljZShpbmRleCwgMCwgaXRlbSk7XG4gICAgICAgICAgICAgICAgdGhpcy5vbkFkZChpdGVtLCBpbmRleCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ2FkZEF0OiBUaGUgaW5kZXggJyArIGluZGV4ICsgJyBpcyBvdXQgb2YgYm91bmRzICcgKyB0aGlzLl9pdGVtcy5sZW5ndGgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgcmVwbGFjZUJ5UmVmKGl0ZW0pIHtcbiAgICAgICAgaWYgKGl0ZW0ucmVmKSB7XG4gICAgICAgICAgICBjb25zdCBleGlzdGluZ0l0ZW0gPSB0aGlzLmdldEJ5UmVmKGl0ZW0ucmVmKTtcbiAgICAgICAgICAgIGlmICghZXhpc3RpbmdJdGVtKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdyZXBsYWNlQnlSZWY6IG5vIGl0ZW0gZm91bmQgd2l0aCByZWZlcmVuY2U6ICcgKyBpdGVtLnJlZik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLnJlcGxhY2UoaXRlbSwgZXhpc3RpbmdJdGVtKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigncmVwbGFjZUJ5UmVmOiBubyByZWYgc3BlY2lmaWVkIGluIGl0ZW0nKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLmFkZEF0KGl0ZW0sIHRoaXMuX2l0ZW1zLmxlbmd0aCk7XG5cbiAgICB9XG5cbiAgICByZXBsYWNlKGl0ZW0sIHByZXZJdGVtKSB7XG4gICAgICAgIGNvbnN0IGluZGV4ID0gdGhpcy5nZXRJbmRleChwcmV2SXRlbSk7XG4gICAgICAgIGlmIChpbmRleCA9PT0gLTEpIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigncmVwbGFjZTogVGhlIHByZXZpb3VzIGl0ZW0gZG9lcyBub3QgZXhpc3QnKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnNldEF0KGl0ZW0sIGluZGV4KTtcbiAgICB9XG5cbiAgICBzZXRBdChpdGVtLCBpbmRleCkge1xuICAgICAgICBpZiAoaW5kZXggPj0gMCAmJiBpbmRleCA8PSB0aGlzLl9pdGVtcy5sZW5ndGgpIHtcblxuICAgICAgICAgICAgaWYgKFV0aWxzLmlzT2JqZWN0TGl0ZXJhbChpdGVtKSkge1xuICAgICAgICAgICAgICAgIGNvbnN0IG8gPSBpdGVtO1xuICAgICAgICAgICAgICAgIGl0ZW0gPSB0aGlzLmNyZWF0ZUl0ZW0obyk7XG4gICAgICAgICAgICAgICAgaXRlbS5wYXRjaChvKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgbGV0IGN1cnJlbnRJbmRleCA9IHRoaXMuX2l0ZW1zLmluZGV4T2YoaXRlbSk7XG4gICAgICAgICAgICBpZiAoY3VycmVudEluZGV4ICE9IC0xKSB7XG4gICAgICAgICAgICAgICAgaWYgKGN1cnJlbnRJbmRleCAhPT0gaW5kZXgpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgZnJvbUluZGV4ID0gY3VycmVudEluZGV4O1xuICAgICAgICAgICAgICAgICAgICBpZiAoZnJvbUluZGV4ICE9PSBpbmRleCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5faXRlbXMuc3BsaWNlKGZyb21JbmRleCwgMSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9pdGVtcy5zcGxpY2UoaW5kZXgsIDAsIGl0ZW0pO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5vbk1vdmUoaXRlbSwgZnJvbUluZGV4LCBpbmRleCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGlmKCBpbmRleCA8IHRoaXMuX2l0ZW1zLmxlbmd0aCl7XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX2l0ZW1zW2luZGV4XS5yZWYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlZnNbdGhpcy5faXRlbXNbaW5kZXhdLnJlZl0gPSB1bmRlZmluZWQ7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICBjb25zdCBwcmV2SXRlbSA9IHRoaXMuX2l0ZW1zW2luZGV4XTtcblxuICAgICAgICAgICAgICAgICAgICAvLyBEb2Vzbid0IGV4aXN0IHlldDogb3ZlcndyaXRlIGN1cnJlbnQuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2l0ZW1zW2luZGV4XSA9IGl0ZW07XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKGl0ZW0ucmVmKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZWZzW2l0ZW0ucmVmXSA9IGl0ZW07XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICB0aGlzLm9uU2V0KGl0ZW0sIGluZGV4LCBwcmV2SXRlbSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdzZXRBdDogVGhlIGluZGV4ICcgKyBpb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ICAgICAgcmV0dXJuIGl0ZW07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYHJlbW92ZUF0OiBUaGUgaW5kZXggJHtpbmRleH0gaXMgb3V0IG9mIGJvdW5kcyAke3RoaXMuX2l0ZW1zLmxlbmd0aCAtIDF9YCk7XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgY2xlYXIoKSB7XG4gICAgICAgIGxldCBuID0gdGhpcy5faXRlbXMubGVuZ3RoO1xuICAgICAgICBpZiAobikge1xuICAgICAgICAgICAgbGV0IHByZXYgPSB0aGlzLl9pdGVtcztcbiAgICAgICAgICAgIHRoaXMuX2l0ZW1zID0gW107XG4gICAgICAgICAgICB0aGlzLl9yZWZzID0ge31cbiAgICAgICAgICAgIHRoaXMub25TeW5jKHByZXYsIFtdLCBbXSk7XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgYShvKSB7XG4gICAgICAgIGlmIChVdGlscy5pc09iamVjdExpdGVyYWwobykpIHtcbiAgICAgICAgICAgIGxldCBjID0gdGhpcy5jcmVhdGVJdGVtKG8pO1xuICAgICAgICAgICAgYy5wYXRjaChvKTtcbiAgICAgICAgICAgIHRoaXMuYWRkKGMpO1xuICAgICAgICAgICAgcmV0dXJuIGM7XG4gICAgICAgIH0gZWxzZSBpZiAoQXJyYXkuaXNBcnJheShvKSkge1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSBvLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIHRoaXMuYShvW2ldKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiBudWxsO1xuICAgICAgICB9IGVsc2UgaWYgKHRoaXMuaXNJdGVtKG8pKSB7XG4gICAgICAgICAgICB0aGlzLmFkZChvKTtcbiAgICAgICAgICAgIHJldHVybiBvO1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIGdldCBsZW5ndGgoKSB7XG4gICAgICAgI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AgICAgICAgaWYgKCFjKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuaXNJdGVtKHMpKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFJlcGxhY2UgcHJldmlvdXMgaXRlbTtcbiAgICAgICAgICAgICAgICAgICAgcy5yZWYgPSBjcmVmO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmFkZChzKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAvLyBDcmVhdGUgbmV3IGl0ZW0uXG4gICAgICAgICAgICAgICAgICAgIGMgPSB0aGlzLmNyZWF0ZUl0ZW0ocyk7XG4gICAgICAgICAgICAgICAgICAgIGMucmVmID0gY3JlZjtcbiAgICAgICAgICAgICAgICAgICAgYy5wYXRjaChzKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5hZGQoYyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5pc0l0ZW0ocykpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGMgIT09IHMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFJlcGxhY2UgcHJldmlvdXMgaXRlbTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBpZHggPSB0aGlzLmdldEluZGV4KGMpO1xuICAgICAgICAgICAgICAgICAgICAgICAgcy5yZWYgPSBjcmVmO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5zZXRBdChzLCBpZHgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgYy5wYXRjaChzKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZXF1YWxzQXJyYXkoYXJyYXkpIHtcbiAgICAgICAgbGV0IHNhbWUgPSB0cnVlO1xuICAgICAgICBpZiAoYXJyYXkubGVuZ3RoID09PSB0aGlzLl9pdGVtcy5sZW5ndGgpIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5faXRlbXMubGVuZ3RoOyAoaSA8IG4pICYmIHNhbWU7IGkrKykge1xuICAgICAgICAgICAgICAgIHNhbWUgPSBzYW1lICYmICh0aGlzLl9pdGVtc1tpXSA9PT0gYXJyYXlbaV0pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc2FtZSA9IGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBzYW1lO1xuICAgIH1cblxuICAgIF9zZXRCeUFycmF5KGFycmF5KSB7XG4gICAgICAgIC8vIEZvciBwZXJmb3JtYW5jZSByZWFzb25zLCBmaXJzdCBjaGVjayBpZiB0aGUgYXJyYXlzIG1hdGNoIGV4YWN0bHkgYW5kIGJhaWwgb3V0IGlmIHRoZXkgZG8uXG4gICAgICAgIGlmICh0aGlzLl9lcXVhbHNBcnJheShhcnJheSkpIHtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuXG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5faXRlbXMubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICB0aGlzLl9pdGVtc1tpXS5tYXJrZXIgPSB0cnVlO1xuICAgICAgICB9XG5cbiAgICAgICAgbGV0IHJlZnM7XG4gICAgICAgIGxldCBuZXdJdGVtcyA9IFtdO1xuICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IGFycmF5Lmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgbGV0IHMgPSBhcnJheVtpXTtcbiAgICAgICAgICAgIGlmICh0aGlzLmlzSXRlbShzKSkge1xuICAgICAgICAgICAgICAgIHMubWFya2VyID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgbmV3SXRlbXMucHVzaChzKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgbGV0IGNyZWYgPSBzLnJlZjtcbiAgICAgICAgICAgICAgICBsZXQgYztcbiAgICAgICAgICAgICAgICBpZiAoY3JlZikge1xuICAgICAgICAgICAgICAgICAgICBpZiAoIXJlZnMpIHJlZnMgPSB0aGlzLl9nZXRSZWZzKCk7XG4gICAgICAgICAgICAgICAgICAgIGMgPSByZWZzW2NyZWZdO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmICghYykge1xuICAgICAgICAgICAgICAgICAgICAvLyBDcmVhdGUgbmV3IGl0ZW0uXG4gICAgICAgICAgICAgICAgICAgIGMgPSB0aGlzLmNyZWF0ZUl0ZW0ocyk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgYy5tYXJrZXIgPSBmYWxzZTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAoVXRpbHMuaXNPYmplY3RMaXRlcmFsKHMpKSB7XG4gICAgICAgICAgICAgICAgICAgIGMucGF0Y2gocyk7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgbmV3SXRlbXMucHVzaChjKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHRoaXMuX3NldEl0ZW1zKG5ld0l0ZW1zKTtcbiAgICB9XG5cbiAgICBfc2V0SXRlbXMobmV3SXRlbXMpIHtcbiAgICAgICAgbGV0IHByZXZJdGVtcyA9IHRoaXMuX2l0ZW1zO1xuICAgICAgICB0aGlzLl9pdGVtcyA9IG5ld0l0ZW1zO1xuXG4gICAgICAgIC8vIFJlbW92ZSB0aGUgaXRlbXMuXG4gICAgICAgIGxldCByZW1vdmVkID0gcHJldkl0ZW1zLmZpbHRlcihpdGVtID0+IHtsZXQgbSA9IGl0ZW0ubWFya2VyOyBkZWxldGUgaXRlbS5tYXJrZXI7IHJldHVybiBtfSk7XG4g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FkZXI7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChzaGFkZXIpIHtcbiAgICAgICAgICAgICAgICBCYXNlLnBhdGNoT2JqZWN0KHNoYWRlciwgdik7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSBpZiAodiA9PT0gbnVsbCkge1xuICAgICAgICAgICAgc2hhZGVyID0gc3RhZ2UuY3R4LnJlbmRlclN0YXRlLmRlZmF1bHRTaGFkZXI7XG4gICAgICAgIH0gZWxzZSBpZiAodiA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICBzaGFkZXIgPSBudWxsO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHYuaXNTaGFkZXIpIHtcbiAgICAgICAgICAgICAgICBpZiAoIXN0YWdlLnJlbmRlcmVyLmlzVmFsaWRTaGFkZXJUeXBlKHYuY29uc3RydWN0b3IpKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoXCJbTGlnaHRuaW5nXSBJbnZhbGlkIHNoYWRlciB0eXBlXCIpO1xuICAgICAgICAgICAgICAgICAgICB2ID0gbnVsbDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgc2hhZGVyID0gdjtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihcIltMaWdodG5pbmddIFBsZWFzZSBzcGVjaWZ5IGEgc2hhZGVyIHR5cGUuXCIpO1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiBzaGFkZXI7XG4gICAgfVxuXG4gICAgc3RhdGljIGdldFdlYkdMKCkge1xuICAgICAgICByZXR1cm4gdW5kZWZpbmVkO1xuICAgIH1cblxuICAgIHN0YXRpYyBnZXRDMmQoKSB7XG4gICAgICAgIHJldHVybiB1bmRlZmluZWQ7XG4gICAgfVxuXG4gICAgYWRk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Ghpcy5fbW9kZSA9IHRoaXMuZ2wgPyAwIDogMTtcblxuICAgICAgICAvLyBPdmVycmlkZSB3aWR0aCBhbmQgaGVpZ2h0LlxuICAgICAgICBpZiAodGhpcy5nZXRDYW52YXMoKSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuZ2V0T3B0aW9uKCdkZXZpY2VQaXhlbFJhdGlvJykgIT09IDEpIHtcbiAgICAgICAgICAgICAgICBjb25zdCByYXRpbyA9IHRoaXMuZ2V0T3B0aW9uKCdkZXZpY2VQaXhlbFJhdGlvJyk7XG4gICAgICAgICAgICAgICAgLy8gc2V0IGNvcnJlY3QgZGlzcGxheSBzaWVcbiAgICAgICAgICAgICAgICB0aGlzLmdldENhbnZhcygpLnN0eWxlLndpZHRoID0gdGhpcy5fb3B0aW9uc1sndyddIC8gcmF0aW8gICsgJ3B4JztcbiAgICAgICAgICAgICAgICB0aGlzLmdldENhbnZhcygpLnN0eWxlLmhlaWdodCA9IHRoaXMuX29wdGlvbnNbJ2gnXSAvIHJhdGlvICsgJ3B4JztcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gc2V0IGRpc3BsYXkgYnVmZmVyIHNpemVcbiAgICAgICAgICAgIHRoaXMuX29wdGlvbnMudyA9IHRoaXMuZ2V0Q2FudmFzKCkud2lkdGg7XG4gICAgICAgICAgICB0aGlzLl9vcHRpb25zLmggPSB0aGlzLmdldENhbnZhcygpLmhlaWdodDtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLl9tb2RlID09PSAwKSB7XG4gICAgICAgICAgICBpZiAoVXRpbHMuaXNTcGFyaykge1xuICAgICAgICAgICAgICAgIHRoaXMuX3JlbmRlcmVyID0gbmV3IFNwYXJrUmVuZGVyZXIodGhpcyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX3JlbmRlcmVyID0gbmV3IFdlYkdMUmVuZGVyZXIodGhpcyk7XG4gICAgICAgICAgICB9XG4gICA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gIHRoaXMuY3R4ID0gbmV3IENvcmVDb250ZXh0KHRoaXMpO1xuXG4gICAgICAgIHRoaXMuX3VwZGF0ZVNvdXJjZVRleHR1cmVzID0gbmV3IFNldCgpO1xuICAgIH1cblxuICAgIGdldCByZW5kZXJlcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JlbmRlcmVyO1xuICAgIH1cblxuICAgIHN0YXRpYyBpc1dlYmdsU3VwcG9ydGVkKCkge1xuICAgICAgICBpZiAoVXRpbHMuaXNOb2RlKSB7XG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuXG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICByZXR1cm4gISF3aW5kb3cuV2ViR0xSZW5kZXJpbmdDb250ZXh0O1xuICAgICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBSZXR1cm5zIHRoZSByZW5kZXJpbmcgbW9kZS5cbiAgICAgKiBAcmV0dXJucyB7bnVtYmVyfVxuICAgICAqICAwOiBXZWJHTFxuICAgICAqICAxOiBDYW52YXMyZFxuICAgICAqL1xuICAgIGdldCBtb2RlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbW9kZTtcbiAgICB9XG5cbiAgICBpc1dlYmdsKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5tb2RlID09PSAwO1xuICAgIH1cblxuICAgIGlzQzJkKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5tb2RlID09PSAxO1xuICAgIH1cblxuICAgIGdldE9wdGlvbihuYW1lKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9vcHRpb25zW25hbWVdO1xuICAgIH1cblxuICAgIF9zZXRPcHRpb25zKG8pIHtcbiAgICAgICAgdGhpcy5fb3B0aW9ucyA9IHt9O1xuXG4gICAgICAgIGxldCBvcHQgPSAobmFtZSwgZGVmKSA9PiB7XG4gICAgIC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NTY7XG4gICAgICAgIGxldCBnID0gKChjb2xvciAvIDI1NikgfCAwKSAlIDI1NjtcbiAgICAgICAgbGV0IGIgPSBjb2xvciAlIDI1NjtcbiAgICAgICAgcmV0dXJuICdyZ2IoJyArIHIgKyAnLCcgKyBnICsgJywnICsgYiArICcpJztcbiAgICB9O1xuXG4gICAgc3RhdGljIGdldFJnYmFTdHJpbmcoY29sb3IpIHtcbiAgICAgICAgbGV0IHIgPSAoKGNvbG9yIC8gNjU1MzYpIHwgMCkgJSAyNTY7XG4gICAgICAgIGxldCBnID0gKChjb2xvciAvIDI1NikgfCAwKSAlIDI1NjtcbiAgICAgICAgbGV0IGIgPSBjb2xvciAlIDI1NjtcbiAgICAgICAgbGV0IGEgPSAoKGNvbG9yIC8gMTY3NzcyMTYpIHwgMCkgLyAyNTU7XG4gICAgICAgIHJldHVybiAncmdiYSgnICsgciArICcsJyArIGcgKyAnLCcgKyBiICsgJywnICsgYS50b0ZpeGVkKDQpICsgJyknO1xuICAgIH07XG5cbiAgICBzdGF0aWMgZ2V0UmdiYVN0cmluZ0Zyb21BcnJheShjb2xvcikge1xuICAgICAgICBsZXQgciA9IE1hdGguZmxvb3IoY29sb3JbMF0gKiAyNTUpO1xuICAgICAgICBsZXQgZyA9IE1hdGguZmxvb3IoY29sb3JbMV0gKiAyNTUpO1xuICAgICAgICBsZXQgYiA9IE1hdGguZmxvb3IoY29sb3JbMl0gKiAyNTUpO1xuICAgICAgICBsZXQgYSA9IE1hdGguZmxvb3IoY29sb3JbM10gKiAyNTUpIC8gMjU1O1xuICAgICAgICByZXR1cm4gJ3JnYmEoJyArIHIgKyAnLCcgKyBnICsgJywnICsgYiArICcsJyArIGEudG9GaXhlZCg0KSArICcpJztcbiAgICB9O1xuXG4gICAgc3RhdGljIGdldFJnYmFDb21wb25lbnRzTm9ybWFsaXplZChhcmdiKSB7XG4gICAgICAgIGxldCByID0gKChhcmdiIC8gNjU1MzYpIHwgMCkgJSAyNTY7XG4gICAgICAgIGx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vIDY1NTM2KSB8IDApICUgMjU2O1xuICAgICAgICAgICAgbGV0IGcxID0gKChjW2ldIC8gMjU2KSB8IDApICUgMjU2O1xuICAgICAgICAgICAgbGV0IGIxID0gY1tpXSAlIDI1NjtcbiAgICAgICAgICAgIGxldCBhMSA9ICgoY1tpXSAvIDE2Nzc3MjE2KSB8IDApO1xuICAgICAgICAgICAgciArPSByMTtcbiAgICAgICAgICAgIGcgKz0gZzE7XG4gICAgICAgICAgICBiICs9IGIxO1xuICAgICAgICAgICAgYSArPSBhMTtcbiAgICAgICAgICAgIHQgKz0gMS4wO1xuICAgICAgICB9XG5cbiAgICAgICAgdCA9IDEgLyB0O1xuICAgICAgICByZXR1cm4gTWF0aC5yb3VuZChhICogdCkgKiAxNjc3NzIxNiArIE1hdGgucm91bmQociAqIHQpICogNjU1MzYgKyBNYXRoLnJvdW5kKGcgKiB0KSAqIDI1NiArIE1hdGgucm91bmQoYiAqIHQpO1xuICAgIH07XG5cbiAgICBzdGF0aWMgbWVyZ2VDb2xvckFscGhhKGMsIGFscGhhKSB7XG4gICAgICAgIGxldCBhID0gKChjIC8gMTY3NzcyMTYgfCAwKSAqIGFscGhhKSB8IDA7XG4gICAgICAgIHJldHVybiAoKCgoKGMgPj4gMTYpICYgMHhmZikgKiBhKSAvIDI1NSkgJiAweGZmKSArXG4gICAgICAgICAgICAoKCgoYyAmIDB4ZmYwMCkgKiBhKSAvIDI1NSkgJiAweGZmMDApICtcbiAgICAgICAgICAgICgoKCgoYyAmIDB4ZmYpIDw8IDE2KSAqIGEpIC8gMjU1KSAmIDB4ZmYwMDAwKSArXG4gICAgICAgICAgICAoYSA8PCAyNCk7XG4gICAgfTtcblxuICAgIHN0YXRpYyByYWQoZGVnKSB7XG4gICAgICAgIHJldHVybiBkZWcgKiAoTWF0aC5QSSAvIDE4MCk7XG4gICAgfTtcblxuICAgIHN0YXRpYyBnZXRUaW1pbmdCZXppZXIoYSwgYiwgYywgZCkge1xuICAgICAgICBsZXQgeGMgPSAzLjAgKiBhO1xuICAgICAgICBsZXQgeGIgPSAzLjAgKiAoYyAtIGEpIC0geGM7XG4gICAgICAgIGxldCB4YSA9IDEuMCAtIHhjIC0geGI7XG4gICAgICAgIGxldCB5YyA9IDMuMCAqIGI7XG4gICAgICAgIGxldCB5YiA9IDMuMCAqIChkIC0gYikgLSB5YztcbiAgICAgICAgbGV0IHlhID0gMS4wIC0geWMgLSB5YjtcblxuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKHRpbWUpIHtcbiAgICAgICAgICAgIGlmICh0aW1lID49IDEuMCkge1xuICAgICAgICAgICAgICAgIHJldHVybiAxO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRpbWUgPD0gMCkge1xuICAgICAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBsZXQgdCA9IDAuNSwgY2J4LCBjYnhkLCBkeDtcblxuICAgICAgICAgICAgZm9yIChsZXQgaXQgPSAwOyBpdCA8IDIwOyBpdCsrKSB7XG4gICAgICAgICAgICAgICAgY2J4ID0gdCAqICh0ICogKHQgKiB4YSArIHhiKSArIHhjKTtcbiAgICAgICAgICAgICAgICBkeCA9IHRpbWUgLSBjYng7XG4gICAgICAgICAgICAgICAgaWYgKGR4ID4gLTFlLTggJiYgZHggPCAxZS04KSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0ICogKHQgKiAodCAqIHlhICsgeWIpICsgeWMpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIC8vIEN1YmljIGJlemllciBkZXJpdmF0aXZlLlxuICAgICAgICAgICAgICAgIGNieGQgPSB0ICogKHQgKiAoMyAqIHhhKSArIDIgKiB4YikgKyB4YztcblxuICAgICAgICAgICAgICAgIGlmIChjYnhkID4gMWUtMTAgJiYgY2J4ZCA8IDFlLTEwKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFByb2JsZW1hdGljLiBGYWxsIGJhY2sgdG8gYmluYXJ5IHNlYXJjaCBtZXRob2QuXG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIHQgKz0gZHggLyBjYnhkO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBGYWxsYmFjazogYmluYXJ5IHNlYXJjaCBtZXRob2QuIFRoaXMgaXMgbW9yZSByZWxpYWJsZSB3aGVuIHRoZXJlIGFyZSBuZWFyLTAgc2xvcGVzLlxuICAgICAgICAgICAgbGV0IG1pblQgPSAwO1xuICAgICAgICAgICAgbGV0IG1heFQgPSAxO1xuICAgICAgICAgICAgZm9yIChsZXQgaXQgPSAwOyBpdCA8IDIwOyBpdCsrKSB7XG4gICAgICAgICAgICAgICAgdCA9IDAuNSAqIChtaW5UICsgbWF4VCk7XG5cbiAgICAgICAgICAgICAgICBjYnggPSB0ICogKHQgKiAodCAqIHhhICsgeGIpICsgeGMpO1xuXG4gICAgICAgICAgICAgICAgZHggPSB0aW1lIC0gY2J4O1xuICAgICAgICAgICAgICAgIGlmIChkeCA+IC0xZS04ICYmIGR4IDwgMWUtOCkge1xuICAgICAgICAgICAgICAgICAgICAvLyBTb2x1dGlvbiBmb3VuZCFcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHQgKiAodCAqICh0ICogeWEgKyB5YikgKyB5Yyk7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaWYgKGR4IDwgMCkge1xuICAgICAgICAgICAgICAgICAgICBtYXhUID0gdDtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBtaW5UID0gdDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgfTtcbiAgICB9O1xuXG4gICAgc3RhdGljIGdldFRpbWluZ0Z1bmN0aW9uKHN0cikge1xuICAgICAgICBzd2l0Y2ggKHN0cikge1xuICAgICAgICAgICAgY2FzZSBcImxpbmVhclwiOlxuICAgICAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbiAodGltZSkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGltZVxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICBjYXNlIFwiZWFzZVwiOlxuICAgICAgICAgICAgICAgIHJldHVybiBTdGFnZVV0aWxzLmdldFRpbWluZ0JlemllcigwLjI1LCAwLjEsIDAuMjUsIDEuMCk7XG4gICAgICAgICAgICBjYXNlIFwiZWFzZS1pblwiOlxuICAgICAgICAgICAgICAgIHJldHVybiBTdGFnZVV0aWxzLmdldFRpbWluZ0JlemllcigwLjQyLCAwLCAxLjAsIDEuMCk7XG4gICAgICAgICAgICBjYXNlIFwiZWFzZS1vdXRcIjpcbiAgICAgICAgICAgICAgICByZXR1cm4gU3RhZ2VVdGlscy5nZXRUaW1pbmdCZXppZXIoMCwgMCwgMC41OCwgMS4wKTtcbiAgICAgICAgICAgIGNhc2UgXCJlYXNlLWluLW91dFwiOlxuICAgICAgICAgICAgICAgIHJldHVybiBTdGFnZVV0aWxzLmdldFRpbWluZ0JlemllcigwLjQyLCAwLCAwLjU4LCAxLjApO1xuICAgICAgICAgICAgY2FzZSBcInN0ZXAtc3RhcnRcIjpcbiAgICAgICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gMVxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICBjYXNlIFwic3RlcC1lbmRcIjpcbiAgICAgICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24gKHRpbWUpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRpbWUgPT09IDEgPyAxIDogMDtcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgZGVmYXVsdDpcbiAgICAgICAgICAgICAgICBsZXQgcyA9IFwiY3ViaWMtYmV6aWVyKFwiO1xuICAgICAgICAgICAgICAgIGlmIChzdHIgJiYgc3RyLmluZGV4T2YocykgPT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgbGV0IHBhcnRzID0gc3RyLnN1YnN0cihzLmxlbmd0aCwgc3RyLmxlbmd0aCAtIHMubGVuZ3RoIC0gMSkuc3BsaXQoXCIsXCIpO1xuICAgICAgICAgICAgICAgICAgICBpZiAocGFydHMubGVuZ3RoICE9PSA0KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJbTGlnaHRuaW5nXSBVbmtub3duIHRpbWluZyBmdW5jdGlvbjogXCIgKyBzdHIpO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBGYWxsYmFjazogdXNlIGxpbmVhci5cbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbiAodGltZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB0aW1lXG4gICAgICAgICAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGxldCBhID0gcGFyc2VGbG9hdChwYXJ0c1swXSk7XG4gICAgICAgICAgICAgICAgICAgIGxldCBiID0gcGFyc2VGbG9hdChwYXJ0c1sxXSk7XG4gICAgICAgICAgICAgICAgICAgIGxldCBjID0gcGFyc2VGbG9hdChwYXJ0c1syXSk7XG4gICAgICAgICAgICAgICAgICAgIGxldCBkID0gcGFyc2VGbG9hdChwYXJ0c1szXSk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChpc05hTihhKSB8fCBpc05hTihiKSB8fCBpc05hTihjKSB8fCBpc05hTihkKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS53YXJuKFwiW0xpZ2h0bmluZ10gVW5rbm93biB0aW1pbmcgZnVuY3Rpb246IFwiICsgc3RyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEZhbGxiYWNrOiB1c2UgbGluZWFyLlxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICh0aW1lKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRpbWVcbiAgICAgICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gU3RhZ2VVdGlscy5nZXRUaW1pbmdCZXppZXIoYSwgYiwgYywgZCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS53YXJuKFwiW0xpZ2h0bmluZ10gVW5rbm93biB0aW1pbmcgZnVuY3Rpb246IFwiICsgc3RyKTtcbiAgICAgICAgICAgICAgICAgICAgLy8gRmFsbGJhY2s6IHVzZSBsaW5lYXIuXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbiAodGltZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRpbWVcbiAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9O1xuXG59XG4iLCIvKlxuICogSWYgbm90IHN0YXRlZCBvdGhlcndpc2UgaW4gdGhpcyBmaWxlIG9yIHRoaXMgY29tcG9uZW50J3MgTElDRU5TRSBmaWxlIHRoZVxuICogZm9sbG93aW5nIGNvcHlyaWdodCBhbmQgbGljZW5zZXMgYXBwbHk6XG4gKlxuICogQ29weXJpZ2h0IDIwMjAgTWV0cm9sb2dpY2FsXG4gKlxuICogTGljZW5zZWQgdW5kZXIgdGhlIEFwYWNoZSBMaWNlbnNlLCBWZXJzaW9uIDIuMCAodGhlIExpY2Vuc2UpO1xuICogeW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLlxuICogWW91IG1heSBvYnRhaW4gYSBjb3B5IG9mIHRoZSBMaWNlbnNlIGF0XG4gKlxuICogaHR0cDovL3d3dy5hcGFjaGUub3JnL2xpY2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HtudW1iZXJ9XG4gICAgICAgICAqL1xuICAgICAgICB0aGlzLl95ID0gMDtcblxuICAgICAgICAvKipcbiAgICAgICAgICogVGhlIHRleHR1cmUgY2xpcHBpbmcgd2lkdGguIElmIDAgdGhlbiBmdWxsIHdpZHRoLlxuICAgICAgICAgKiBAdHlwZSB7bnVtYmVyfVxuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5fdyA9IDA7XG5cbiAgICAgICAgLyoqXG4gICAgICAgICAqIFRoZSB0ZXh0dXJlIGNsaXBwaW5nIGhlaWdodC4gSWYgMCB0aGVuIGZ1bGwgaGVpZ2h0LlxuICAgICAgICAgKiBAdHlwZSB7bnVtYmVyfVxuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5faCA9IDA7XG5cbiAgICAgICAgLyoqXG4gICAgICAgICAqIFJlbmRlciBwcmVjaXNpb24gKDAuNSA9IGZ1enp5LCAxID0gbm9ybWFsLCAyID0gc2hhcnAgZXZlbiB3aGVuIHNjYWxlZCB0d2ljZSwgZXRjLikuXG4gICAgICAgICAqIEB0eXBlIHtudW1iZXJ9XG4gICAgICAgICAqIEBwcml2YXRlXG4gICAgICAgICAqL1xuICAgICAgICB0aGlzLl9wcmVjaXNpb24gPSAxO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBUaGUgKG1heGltdW0pIGV4cGVjdGVkIHRleHR1cmUgc291cmNlIHdpZHRoLiBVc2VkIGZvciB3aXRoaW4gYm91bmRzIGRldGVybWluYXRpb24gd2hpbGUgdGV4dHVyZSBpcyBub3QgeWV0IGxvYWRlZC5cbiAgICAgICAgICogSWYgbm90IHNldCwgMjA0OCBpcyB1c2VkIGJ5IEVsZW1lbnRDb3JlLnVwZGF0ZS5cbiAgICAgICAgICogQHR5cGUge251bWJlcn1cbiAgICAgICAgICovXG4gICAgICAgIHRoaXMubXcgPSAwO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBUaGUgKG1heGltdW0pIGV4cGVjdGVkIHRleHR1cmU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gICAgIGlmICghdGhpcy5lbGVtZW50cy5oYXModikpIHtcbiAgICAgICAgICAgIHRoaXMuZWxlbWVudHMuYWRkKHYpO1xuXG4gICAgICAgICAgICBpZiAodGhpcy5lbGVtZW50cy5zaXplID09PSAxKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3NvdXJjZSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9zb3VyY2UuYWRkVGV4dHVyZSh0aGlzKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh2LmFjdGl2ZSkge1xuICAgICAgICAgICAgICAgIHRoaXMuaW5jQWN0aXZlQ291bnQoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHJlbW92ZUVsZW1lbnQodikge1xuICAgICAgICBpZiAodGhpcy5lbGVtZW50cy5kZWxldGUodikpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLmVsZW1lbnRzLnNpemUgPT09IDApIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fc291cmNlKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3NvdXJjZS5yZW1vdmVUZXh0dXJlKHRoaXMpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHYuYWN0aXZlKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5kZWNBY3RpdmVDb3VudCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgaW5jQWN0aXZlQ291bnQoKSB7XG4gICAgICAgIC8vIEVuc3VyZSB0aGF0IHRleHR1cmUgc291cmNlJ3MgYWN0aXZlQ291bnQgaGFzIHRyYW5zZmVycmVkIG93bmVyc2hpcC5cbiAgICAgICAgY29uc3Qgc291cmNlID0gdGhpcy5zb3VyY2U7XG5cbiAgICAgICAgaWYgKHNvdXJjZSkge1xuICAgICAgICAgICAgdGhpcy5fY2hlY2tGb3JOZXdlclJldXNhYmxlVGV4dHVyZVNvdXJjZSgpO1xuICAgICAgICB9XG5cbiAgICAgICAgdGhpcy5fYWN0aXZlQ291bnQrKztcbiAgICAgICAgaWYgKHRoaXMuX2FjdGl2ZUNvdW50ID09PSAxKSB7XG4gICAgICAgICAgICB0aGlzLmJlY29tZXNVc2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBkZWNBY3RpdmVDb3VudCgpIHtcbiAgICAgICAgY29uc3Qgc291cmNlID0gdGhpcy5zb3VyY2U7IC8vIEZvcmNlIHVwZGF0aW5nIHRoZSBzb3VyY2UuXG4gICAgICAgIHRoaXMuX2FjdGl2ZUNvdW50LS07XG4gICAgICAgIGlmICghdGhpcy5fYWN0aXZlQ291bnQpIHtcbiAgICAgICAgICAgIHRoaXMuYmVjb21lc1VudXNlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgYmVjb21lc1VzZWQoKSB7XG4gICAgICAgIGlmICh0aGlzLnNvdXJjZSkge1xuICAgICAgICAgICAgdGhpcy5zb3VyY2UuaW5jQWN0aXZlVGV4dHVyZUNvdW50KCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBvbkxvYWQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9yZXNpemVNb2RlKSB7XG4gICAgICAgICAgICB0aGlzLl9hcHBseVJlc2l6ZU1vZGUoKTtcbiAgICAgICAgfVxuXG4gICAgICAgIHRoaXMuZWxlbWVudHMuZm9yRWFjaChlbGVtZW50ID0+IHtcbiAgICAgICAgICAgIGlmIChlbGVtZW50LmFjdGl2ZSkge1xuICAgICAgICAgICAgICAgIGVsZW1lbnQub25UZXh0dXJlU291cmNlTG9hZGVkKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIF9jaGVja0Zvck5ld2VyUmV1c2FibGVUZXh0dXJlU291cmNlKCkge1xuICAgICAgICAvLyBXaGVuIHRoaXMgc291cmNlIGJlY2FtZS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ZSgpO1xuICAgICAgICAgICAgdGhpcy5fcmVwbGFjZVRleHR1cmVTb3VyY2Uoc291cmNlKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9nZXRUZXh0dXJlU291cmNlKCkge1xuICAgICAgICBsZXQgc291cmNlID0gbnVsbDtcbiAgICAgICAgaWYgKHRoaXMuX2dldElzVmFsaWQoKSkge1xuICAgICAgICAgICAgY29uc3QgbG9va3VwSWQgPSB0aGlzLl9nZXRMb29rdXBJZCgpO1xuICAgICAgICAgICAgc291cmNlID0gdGhpcy5fZ2V0UmV1c2FibGVUZXh0dXJlU291cmNlKGxvb2t1cElkKTtcbiAgICAgICAgICAgIGlmICghc291cmNlKSB7XG4gICAgICAgICAgICAgICAgc291cmNlID0gdGhpcy5tYW5hZ2VyLmdldFRleHR1cmVTb3VyY2UodGhpcy5fZ2V0U291cmNlTG9hZGVyKCksIGxvb2t1cElkKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gc291cmNlO1xuICAgIH1cblxuICAgIF9nZXRSZXVzYWJsZVRleHR1cmVTb3VyY2UobG9va3VwSWQgPSB0aGlzLl9nZXRMb29rdXBJZCgpKSB7XG4gICAgICAgIGlmICh0aGlzLl9nZXRJc1ZhbGlkKCkpIHtcbiAgICAgICAgICAgIGlmIChsb29rdXBJZCkge1xuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLm1hbmFnZXIuZ2V0UmV1c2FibGVUZXh0dXJlU291cmNlKGxvb2t1cElkKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gbnVsbDtcbiAgICB9XG5cbiAgICBfcmVwbGFjZVRleHR1cmVTb3VyY2UobmV3U291cmNlID0gbnVsbCkge1xuICAgICAgICBsZXQgb2xkU291cmNlID0gdGhpcy5fc291cmNlO1xuXG4gICAgICAgIHRoaXMuX3NvdXJjZSA9IG5ld1NvdXJjZTtcblxuICAgICAgICBpZiAodGhpcy5lbGVtZW50cy5zaXplKSB7XG4gICAgICAgICAgICBpZiAob2xkU291cmNlKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2FjdGl2ZUNvdW50KSB7XG4gICAgICAgICAgICAgICAgICAgIG9sZFNvdXJjZS5kZWNBY3RpdmVUZXh0dXJlQ291bnQoKTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBvbGRTb3VyY2UucmVtb3ZlVGV4dHVyZSh0aGlzKTtcblxuICAgICAgICAgICAgICAgIC8vIGZyZWUgdXAgdW51c2VkIFRleHRUZXh0dXJlcyBpbW1lZGlhdGVseSBhcyB0aGV5IGFyZSBub3QgcmV1c2VkIGFueXdheVxuICAgICAgICAgICAgICAgIGlmKHRoaXNbJ3RleHQnXSAmJiAhb2xkU291cmNlLmlzVXNlZCgpKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMubWFuYWdlci5mcmVlVGV4dHVyZVNvdXJjZShvbGRTb3VyY2UpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKG5ld1NvdXJjZSkge1xuICAgICAgICAgICAgICAgIC8vIE11c3QgaGFwcGVuIGJlZm9yZSBzZXREaXNwbGF5ZWRUZXh0dXJlIHRvIGVuc3VyZSBzcHJpdGUgbWFwIHRleGNvb3JkcyBhcmUgdXNlZC5cbiAgICAgICAgICAgICAgICBuZXdTb3VyY2UuYWRkVGV4dHVyZSh0aGlzKTtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYWN0aXZlQ291bnQpIHtcbiAgICAgICAgICAgICAgICAgICAgbmV3U291cmNlLmluY0FjdGl2ZVRleHR1cmVDb3VudCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLmlzVXNlZCgpKSB7XG4gICAgICAgICAgICBpZiAobmV3U291cmNlKSB7XG4gICAgICAgICAgICAgICAgaWYgKG5ld1NvdXJjZS5pc0xvYWRlZCgpKSB7XG5cbiAgICAgICAgICAgICAgICAgICAgLy8gQXBwbHkgcmVzaXplTW9kZVxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fcmVzaXplTW9kZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fYXBwbHlSZXNpemVNb2RlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICB0aGlzLmVsZW1lbnRzLmZvckVhY2goZWxlbWVudCA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoZWxlbWVudC5hY3RpdmUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbGVtZW50Ll9zZXREaXNwbGF5ZWRUZXh0dXJlKHRoaXMpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCBsb2FkRXJyb3IgPSBuZXdTb3VyY2UubG9hZEVycm9yO1xuICAgICAgICAgICAgICAgICAgICBpZiAobG9hZEVycm9yKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVsZW1lbnRzLmZvckVhY2goZWxlbWVudCA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGVsZW1lbnQuYWN0aXZlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnQub25UZXh0dXJlU291cmNlTG9hZEVycm9yKGxvYWRFcnJvcik7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuZWxlbWVudHMuZm9yRWFjaChlbGVtZW50ID0+IHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGVsZW1lbnQuYWN0aXZlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBlbGVtZW50Ll9zZXREaXNwbGF5ZWRUZXh0dXJlKG51bGwpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBsb2FkKCkge1xuICAgICAgICAvLyBNYWtlIHN1cmUgdGhhdCBzb3VyY2UgaXMgdXAgdG8gZGF0ZS5cbiAgICAgICAgaWYgKHRoaXMuc291cmNlKSB7XG4gICAgICAgICAgICBpZiAoIXRoaXMuaXNMb2FkZWQoKSkge1xuICAgICAgICAgICAgICAgIHRoaXMuc291cmNlLmxvYWQodHJ1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBpc0xvYWRlZCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3NvdXJjZSAmJiB0aGlzLl9zb3VyY2UuaXNMb2FkZWQoKTtcbiAgICB9XG5cbiAgICBnZXQgbG9hZEVycm9yKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fc291cmNlICYmIHRoaXMuX3NvdXJjZS5sb2FkRXJyb3I7XG4gICAgfVxuXG4gICAgZnJlZSgpIHtcbiAgICAgICAgaWYgKHRoaXMuX3NvdXJjZSkge1xuICAgICAgICAgICAgdGhpcy5fc291cmNlLmZyZWUoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHNldCByZXNpemVNb2RlKHt0eXBlID0gXCJjb3ZlclwiLCB3ID0gMCwgaCA9IDAsIGNsaXBYID0gMC41LCBjbGlwWSA9IDAuNX0pIHtcbiAgICAgICAgdGhpcy5fcmVzaXplTW9kZSA9IHt0eXBlLCB3LCBoLCBjbGlwWCwgY2xpcFl9O1xuICAgICAgICBpZiAodGhpcy5pc0xvYWRlZCgpKSB7XG4gICAgICAgICAgICB0aGlzLl9hcHBseVJlc2l6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lzLl93IHx8IHRoaXMuX2gpO1xuXG4gICAgICAgIGxldCBzZWxmID0gdGhpcztcbiAgICAgICAgdGhpcy5lbGVtZW50cy5mb3JFYWNoKGZ1bmN0aW9uKGVsZW1lbnQpIHtcbiAgICAgICAgICAgIC8vIElnbm9yZSBpZiBub3QgdGhlIGN1cnJlbnRseSBkaXNwbGF5ZWQgdGV4dHVyZS5cbiAgICAgICAgICAgIGlmIChlbGVtZW50LmRpc3BsYXllZFRleHR1cmUgPT09IHNlbGYpIHtcbiAgICAgICAgICAgICAgICBlbGVtZW50Lm9uRGlzcGxheWVkVGV4dHVyZUNsaXBwaW5nQ2hhbmdlZCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBfdXBkYXRlUHJlY2lzaW9uKCkge1xuICAgICAgICBsZXQgc2VsZiA9IHRoaXM7XG4gICAgICAgIHRoaXMuZWxlbWVudHMuZm9yRWFjaChmdW5jdGlvbihlbGVtZW50KSB7XG4gICAgICAgICAgICAvLyBJZ25vcmUgaWYgbm90IHRoZSBjdXJyZW50bHkgZGlzcGxheWVkIHRleHR1cmUuXG4gICAgICAgICAgICBpZiAoZWxlbWVudC5kaXNwbGF5ZWRUZXh0dXJlID09PSBzZWxmKSB7XG4gICAgICAgICAgICAgICAgZWxlbWVudC5vblByZWNpc2lvbkNoYW5nZWQoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgZ2V0Tm9uRGVmYXVsdHMoKSB7XG4gICAgICAgIGxldCBub25EZWZhdWx0cyA9IHt9O1xuICAgICAgICBub25EZWZhdWx0c1sndHlwZSddID0gdGhpcy5jb25zdHJ1Y3Rvci5uYW1lO1xuICAgICAgICBpZiAodGhpcy54ICE9PSAwKSBub25EZWZhdWx0c1sneCddID0gdGhpcy54O1xuICAgICAgICBpZiAodGhpcy55ICE9PSAwKSBub25EZWZhdWx0c1sneSddID0gdGhpcy55O1xuICAgICAgICBpZiAodGhpcy53ICE9PSAwKSBub25EZWZhdWx0c1sndyddID0gdGhpcy53O1xuICAgICAgICBpZiAodGhpcy5oICE9PSAwKSBub25EZWZhdWx0c1snaCddID0gdGhpcy5oO1xuICAgICAgICBpZiAodGhpcy5wcmVjaXNpb24gIT09IDEpIG5vbkRlZmF1bHRzWydwcmVjaXNpb24nXSA9IHRoaXMucHJlY2lzaW9uO1xuICAgICAgICByZXR1cm4gbm9uRGVmYXVsdHM7XG4gICAgfVxuXG4gICAgZ2V0IHB4KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5feDtcbiAgICB9XG5cbiAgICBnZXQgcHkoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl95O1xuICAgIH1cblxuICAgIGdldCBwdygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3c7XG4gICAgfVxuXG4gICAgZ2V0IHBoKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faDtcbiAgICB9XG5cbiAgICBnZXQgeCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3ggLyB0aGlzLl9wcmVjaXNpb247XG4gICAgfVxuICAgIHNldCB4KHYpIHtcbiAgICAgICAgdGhpcy5fY2xlYXJSZXNpemVNb2RlKCk7XG4gICAgICAgIHYgPSB2ICogdGhpcy5fcHJlY2lzaW9uO1xuICAgICAgICBpZiAodGhpcy5feCAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5feCA9IHY7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVDbGlwcGluZygpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHkoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl95IC8gdGhpcy5fcHJlY2lzaW9uO1xuICAgIH1cbiAgICBzZXQgeSh2KSB7XG4gICAgICAgIHRoaXMuX2NsZWFyUmVzaXplTW9kZSgpO1xuICAgICAgICB2ID0gdiAqIHRoaXMuX3ByZWNpc2lvbjtcbiAgICAgICAgaWYgKHRoaXMuX3kgIT09IHYpIHtcbiAg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1aXJlZCBmb3IgU3BhcmsgcnVudGltZS5cbiAgICAgICAgICogQHR5cGUge29iamVjdH1cbiAgICAgICAgICogQHByaXZhdGVcbiAgICAgICAgICovXG4gICAgICAgIHRoaXMuX2ltYWdlUmVmID0gbnVsbDtcblxuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBUcmFjayB3aGV0aGVyIG9yIG5vdCB0aGVyZSBpcyBhbiBhbHBoYSBjaGFubmVsIGluIHRoaXMgc291cmNlXG4gICAgICAgICAqIEB0eXBlIHtib29sZWFufVxuICAgICAgICAgKiBAcHJpdmF0ZVxuICAgICAgICAgKi9cbiAgICAgICAgIHRoaXMuX2hhc0FscGhhID0gZmFsc2U7XG4gICAgfVxuXG4gICAgZ2V0IGhhc0FscGhhKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faGFzQWxwaGE7XG4gICAgfVxuXG4gICAgZ2V0IGxvYWRFcnJvcigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2xvYWRFcnJvcjtcbiAgICB9XG5cbiAgICBhZGRUZXh0dXJlKHYpIHtcbiAgICAgICAgaWYgKCF0aGlzLnRleHR1cmVzLmhhcyh2KSkge1xuICAgICAgICAgICAgdGhpcy50ZXh0dXJlcy5hZGQodik7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZW1vdmVUZXh0dXJlKHYpIHtcbiAgICAgICAgdGhpcy50ZXh0dXJlcy5kZWxldGUodik7XG4gICAgfVxuXG4gICAgaW5jQWN0aXZlVGV4dHVyZUNvdW50KCkge1xuICAgICAgICB0aGlzLl9hY3RpdmVUZXh0dXJlQ291bnQrKztcbiAgICAgICAgaWYgKHRoaXMuX2FjdGl2ZVRleHR1cmVDb3VudCA9PT0gMSkge1xuICAgICAgICAgICAgdGhpcy5iZWNvbWVzVXNlZCgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZGVjQWN0aXZlVGV4dHVyZUNvdW50KCkge1xuICAgICAgICB0aGlzLl9hY3RpdmVUZXh0dXJlQ291bnQtLTtcbiAgICAgICAgaWYgKHRoaXMuX2FjdGl2ZVRleHR1cmVDb3VudCA9PT0gMCkge1xuICAgICAgICAgICAgdGhpcy5iZWNvbWVzVW51c2VkKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgaXNSZXN1bHRUZXh0dXJlKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faXNSZXN1bHRUZXh0dXJlO1xuICAgIH1cblxuICAgIHNldCBpc1Jlc3VsdFRleHR1cmUodikge1xuICAgICAgICB0aGlzLl9pc1Jlc3VsdFRleHR1cmUgPSB2O1xuICAgIH1cblxuICAgIGZvckVhY2hFbmFibGVkRWxlbWVudChjYikge1xuICAgICAgICB0aGlzLnRleHR1cmVzLmZvckVhY2godGV4dHVyZSA9PiB7XG4gICAgICAgICAgICB0ZXh0dXJlLmVsZW1lbnRzLmZvckVhY2goY2IpO1xuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBoYXNFbmFibGVkRWxlbWVudHMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnRleHR1cmVzLnNpemUgPiAwO1xuICAgIH1cblxuICAgIGZvckVhY2hBY3RpdmVFbGVtZW50KGNiKSB7XG4gICAgICAgIHRoaXMudGV4dHVyZXMuZm9yRWFjaCh0ZXh0dXJlID0+IHtcbiAgICAgICAgICAgIHRleHR1cmUuZWxlbWVudHMuZm9yRWFjaChlbGVtZW50ID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoZWxlbWVudC5hY3RpdmUpIHtcbiAgICAgICAgICAgICAgICAgICAgY2IoZWxlbWVudCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIGdldFJlbmRlcldpZHRoKCkge1xuICAgICAgICByZXR1cm4gdGhpcy53O1xuICAgIH1cblxuICAgIGdldFJlbmRlckhlaWdodCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuaDtcbiAgICB9XG5cbiAgICB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ZSBhc3luYyBsb2FkIHdoZW4gc3RhZ2UgaXMgZGVzdHJveWVkLlxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGlmIChlcnIpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEVtaXQgdHhFcnJvci5cbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMub25FcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wdGlvbnMgJiYgb3B0aW9ucy5zb3VyY2UpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghdGhpcy5zdGFnZS5pc1VwZGF0aW5nRnJhbWUoKSAmJiAhZm9yY2VTeW5jICYmIChvcHRpb25zLnRocm90dGxlICE9PSBmYWxzZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCB0ZXh0dXJlVGhyb3R0bGVyID0gdGhpcy5zdGFnZS50ZXh0dXJlVGhyb3R0bGVyO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2NhbmNlbENiID0gdGV4dHVyZVRocm90dGxlci5nZW5lcmljQ2FuY2VsQ2I7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGV4dHVyZVRocm90dGxlci5hZGQodGhpcywgb3B0aW9ucyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucHJvY2Vzc0xvYWRlZFNvdXJjZShvcHRpb25zKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0sIHRoaXMpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgcHJvY2Vzc0xvYWRlZFNvdXJjZShvcHRpb25zKSB7XG4gICAgICAgIHRoaXMubG9hZGluZ1Npb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HkgZnVuY3Rpb25zIGJ5IHJlZmVyZW5jZS5cbiAgICAgICAgICAgIHJldHVybiBvYmo7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKEFycmF5LmlzQXJyYXkob2JqKSkge1xuICAgICAgICAgICAgYyA9IFtdO1xuICAgICAgICAgICAgbGV0IGtleXMgPSBPYmplY3Qua2V5cyhvYmopO1xuICAgICAgICAgICAgZm9yIChpID0gMDsgaSA8IGtleXMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgICAgICBjW2tleXNbaV1dID0gVXRpbHMuZ2V0RGVlcENsb25lKG9ialtrZXlzW2ldXSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gYztcbiAgICAgICAgfSBlbHNlIGlmIChVdGlscy5pc09iamVjdChvYmopKSB7XG4gICAgICAgICAgICBjID0ge31cbiAgICAgICAgICAgIGxldCBrZXlzID0gT2JqZWN0LmtleXMob2JqKTtcbiAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBrZXlzLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICAgICAgY1trZXlzW2ldXSA9IFV0aWxzLmdldERlZXBDbG9uZShvYmpba2V5c1tpXV0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGM7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gb2JqO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc3RhdGljIGVxdWFsVmFsdWVzKHYxLCB2Mikge1xuICAgICAgICBpZiAoKHR5cGVvZiB2MSkgIT09ICh0eXBlb2YgdjIpKSByZXR1cm4gZmFsc2U7XG4gICAgICAgIGlmIChVdGlscy5pc09iamVjdExpdGVyYWwodjEpKSB7XG4gICAgICAgICAgICByZXR1cm4gVXRpbHMuaXNPYmplY3RMaXRlcmFsKHYyKSAmJiBVdGlscy5lcXVhbE9iamVjdExpdGVyYWxzKHYxLCB2Mik7XG4gICAgICAgIH0gZWxzZSBpZiAoQXJyYXkuaXNBcnJheSh2MSkpIHtcbiAgICAgICAgICAgIHJldHVybiBBcnJheS5pc0FycmF5KHYyKSAmJiBVdGlscy5lcXVhbEFycmF5cyh2MSwgdjIpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcmV0dXJuIHYxID09PSB2MjtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHN0YXRpYyBlcXVhbE9iamVjdExpdGVyYWxzKG9iajEsIG9iajIpIHtcbiAgICAgICAgbGV0IGtleXMxID0gT2JqZWN0LmtleXMob2JqMSk7XG4gICAgICAgIGxldCBrZXlzMiA9IE9iamVjdC5rZXlzKG9iajIpO1xuICAgICAgICBpZiAoa2V5czEubGVuZ3RoICE9PSBrZXlzMi5sZW5ndGgpIHtcbiAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgfVxuXG4gICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0ga2V5czEubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCBrMSA9IGtleXMxW2ldO1xuICAgICAgICAgICAgY29uc3QgazIgPSBrZXlzMltpXTtcbiAgICAgICAgICAgIGlmIChrMSAhPT0gazIpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGNvbnN0IHYxID0gb2JqMVtrMV07XG4gICAgICAgICAgICBjb25zdCB2MiA9IG9iajJbazJdO1xuXG4gICAgICAgICAgICBpZiAoIVV0aWxzLmVxdWFsVmFsdWVzKHYxLCB2MikpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICB9XG5cbiAgICBzdGF0aWMgZXF1YWxBcnJheXModjEsIHYyKSB7XG4gICAgICAgIGlmICh2MS5sZW5ndGggIT09IHYyLmxlbmd0aCkge1xuICAgICAgICAgICA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yICE9PSBvd25lciB8fCB0aGlzLl9yZWFsU2hhZGVyICE9PSBzaGFkZXIpIHtcbiAgICAgICAgICAgIC8vIFNhbWUgc2hhZGVyIG93bmVyOiBhY3RpdmUgc2hhZGVyIGlzIGFsc28gdGhlIHNhbWUuXG4gICAgICAgICAgICAvLyBQcmV2ZW50IGFueSBzaGFkZXIgdXNhZ2UgdG8gc2F2ZSBwZXJmb3JtYW5jZS5cblxuICAgICAgICAgICAgdGhpcy5fcmVhbFNoYWRlciA9IHNoYWRlcjtcblxuICAgICAgICAgICAgaWYgKHNoYWRlci51c2VEZWZhdWx0KCkpIHtcbiAgICAgICAgICAgICAgICAvLyBVc2UgdGhlIGRlZmF1bHQgc2hhZGVyIHdoZW4gcG9zc2libGUgdG8gcHJldmVudCB1bm5lY2Vzc2FyeSBwcm9ncmFtIGNoYW5nZXMuXG4gICAgICAgICAgICAgICAgc2hhZGVyID0gdGhpcy5kZWZhdWx0U2hhZGVyO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRoaXMuX3NoYWRlciAhPT0gc2hhZGVyIHx8IHRoaXMuX3NoYWRlck93bmVyICE9PSBvd25lcikge1xuICAgICAgICAgICAgICAgIHRoaXMuX3NoYWRlciA9IHNoYWRlcjtcbiAgICAgICAgICAgICAgICB0aGlzLl9zaGFkZXJPd25lciA9IG93bmVyO1xuICAgICAgICAgICAgICAgIHRoaXMuX2NoZWNrID0gdHJ1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCByZW5kZXJUZXh0dXJlSW5mbygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JlbmRlclRleHR1cmVJbmZvO1xuICAgIH1cblxuICAgIHNldFNjaXNzb3IoYXJlYSkge1xuICAgICAgICBpZiAodGhpcy5fc2Npc3NvciAhPT0gYXJlYSkge1xuICAgICAgICAgICAgaWYgKGFyZWEpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9zY2lzc29yID0g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Nzb3JbM10gPiAwKSkpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gSWdub3JlIGVtcHR5IGNsaXBwaW5nIHJlZ2lvbnMuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMucXVhZE9wZXJhdGlvbnMucHVzaCh0aGlzLl9xdWFkT3BlcmF0aW9uKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl90ZW1wb3JhcnlUZXh0dXJpemVycy5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX3RlbXBvcmFyeVRleHR1cml6ZXJzLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICAvLyBXZSBjYW4gbm93IHJldXNlIHRoZXNlIHJlbmRlci10by10ZXh0dXJlcyBpbiBzdWJzZXF1ZW50IHN0YWdlcy5cbiAgICAgICAgICAgICAgICAgICAgLy8gSHVnZSBwZXJmb3JtYW5jZSBiZW5lZml0IHdoZW4gZmlsdGVyaW5nIChmYXN0IGJsdXIpLlxuICAgICAgICAgICAgICAgICAgICB0aGlzLl90ZW1wb3JhcnlUZXh0dXJpemVyc1tpXS5yZWxlYXNlUmVuZGVyVGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0aGlzLl90ZW1wb3JhcnlUZXh0dXJpemVycyA9IFtdO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLl9xdWFkT3BlcmF0aW9uID0gbnVsbDtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChjcmVhdGUpIHtcbiAgICAgICAgICAgIHRoaXMuX2NyZWF0ZVF1YWRPcGVyYXRpb24oKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9jcmVhdGVRdWFkT3BlcmF0aW9uKCkge1xuICAgICAgICB0aGlzLl9xdWFkT3BlcmF0aW9uID0gdGhpcy5yZW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Ghpcy5fZnVuY1ggPSBudWxsO1xuICAgICAgICB0aGlzLl9mdW5jWSA9IG51bGw7XG4gICAgICAgIHRoaXMuX2Z1bmNXID0gbnVsbDtcbiAgICAgICAgdGhpcy5fZnVuY0ggPSBudWxsO1xuXG4gICAgICAgIHRoaXMuX3NjYWxlWCA9IDE7XG4gICAgICAgIHRoaXMuX3NjYWxlWSA9IDE7XG4gICAgICAgIHRoaXMuX3Bpdm90WCA9IDAuNTtcbiAgICAgICAgdGhpcy5fcGl2b3RZID0gMC41O1xuICAgICAgICB0aGlzLl9tb3VudFggPSAwO1xuICAgICAgICB0aGlzLl9tb3VudFkgPSAwO1xuICAgICAgICB0aGlzLl9yb3RhdGlvbiA9IDA7XG5cbiAgICAgICAgdGhpcy5fYWxwaGEgPSAxO1xuICAgICAgICB0aGlzLl92aXNpYmxlID0gdHJ1ZTtcblxuICAgICAgICB0aGlzLl91bHggPSAwO1xuICAgICAgICB0aGlzLl91bHkgPSAwO1xuICAgICAgICB0aGlzLl9icnggPSAxO1xuICAgICAgICB0aGlzLl9icnkgPSAxO1xuXG4gICAgICAgIHRoaXMuX3pJbmRleCA9IDA7XG4gICAgICAgIHRoaXMuX2ZvcmNlWkluZGV4Q29udGV4dCA9IGZhbHNlO1xuICAgICAgICB0aGlzLl96UGFyZW50ID0gbnVsbDtcblxuICAgICAgICB0aGlzLl9pc1Jvb3QgPSBmYWxzZTtcblxuICAgICAgICAvKipcbiAgICAgICAgICogSWZmIHRydWUsIGR1cmluZyB6U29ydCwgdGhpcyBlbGVtZW50IHNob3VsZCBiZSAncmUtc29ydGVkJyBiZWNhdXNlIGVpdGhlcjpcbiAgICAgICAgICogLSB6SW5kZXggZGlkIGNoYW5nXG4gICAgICAgICAqIC0gelBhcmVudCBkaWQgY2hhbmdlXG4gICAgICAgICAqIC0gZWxlbWVudCB3YXMgbW92ZWQgaW4gdGhlIHJlbmRlciB0cmVlXG4gICAgICAgICAqIEB0eXBlIHtib29sZWFufVxuICAgICAgICA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SB7XG4gICAgICAgIGlmIChVdGlscy5pc0Z1bmN0aW9uKHYpKSB7XG4gICAgICAgICAgICB0aGlzLmZ1bmNYID0gdjtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX2Rpc2FibGVGdW5jWCgpO1xuICAgICAgICAgICAgaWYgKHRoaXMuaGFzRmxleExheW91dCgpKSB7XG4gICAgICAgICAgICAgICAgdGhpcy54ICs9ICh2IC0gdGhpcy5fbGF5b3V0Lm9yaWdpbmFsWCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fbGF5b3V0LnNldE9yaWdpbmFsWFdpdGhvdXRVcGRhdGluZ0xheW91dCh2KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy54ID0gdjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCB4KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5feDtcbiAgICB9XG5cbiAgICBzZXQgeCh2KSB7XG4gICAgICAgIGlmICh2ICE9PSB0aGlzLl94KSB7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVMb2NhbFRyYW5zbGF0ZURlbHRhKHYgLSB0aGlzLl94LCAwKTtcbiAgICAgICAgICAgIHRoaXMuX3ggPSB2O1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IGZ1bmNYKCkge1xuICAgICAgICByZXR1cm4gKHRoaXMuX29wdEZsYWdzICYgMSA/IHRoaXMuX2Z1bmNYIDogbnVsbCk7XG4gICAgfVxuXG4gICAgc2V0IGZ1bmNYKHYpIHtcbiAgICAgICAgaWYgKHRoaXMuX2Z1bmNYICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9vcHRGbGFncyB8PSAxO1xuICAgICAgICAgICAgdGhpcy5fZnVuY1ggPSB2O1xuICAgICAgICAgICAgaWYgKHRoaXMuaGFzRmxleExheW91dCgpKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fbGF5b3V0LnNldE9yaWdpbmFsWFdpdGhvdXRVcGRhdGluZ0xheW91dCgwKTtcbiAgICAgICAgICAgICAgICB0aGlzLmxheW91dC5mb3JjZUxheW91dCgpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl94ID0gMDtcbiAgICAgICAgICAgICAgICB0aGlzLl90cmlnZ2VyUmVjYWxjVHJhbnNsYXRlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZGlzYWJsZUZ1bmNYKCkge1xuICAgICAgICB0aGlzLl9vcHRGbGFncyA9IHRoaXMuX29wdEZsYWdzICYgKDB4RkZGRiAtIDEpO1xuICAgICAgICB0aGlzLl9mdW5jWCA9IG51bGw7XG4gICAgfVxuXG4gICAgZ2V0IG9mZnNldFkoKSB7XG4gICAgICAgIGlmICh0aGlzLl9mdW5jWSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2Z1bmNZO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHRoaXMuaGFzRmxleExheW91dCgpKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2xheW91dC5vcmlnaW5hbFk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLl95O1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2V0IG9mZnNldFkodikge1xuICAgICAgICBpZiAoVXRpbHMuaXNGdW5jdGlvbih2KSkge1xuICAgICAgICAgICAgdGhpcy5mdW5jWSA9IHY7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9kaXNhYmxlRnVuY1koKTtcbiAgICAgICAgICAgIGlmICh0aGlzLmhhc0ZsZXhMYXlvdXQoKSkge1xuICAgICAgICAgICAgICAgIHRoaXMueSArPSAodiAtIHRoaXMuX2xheW91dC5vcmlnaW5hbFkpO1xuICAgICAgICAgICAgICAgIHRoaXMuX2xheW91dC5zZXRPcmlnaW5hbFlXaXRob3V0VXBkYXRpbmdMYXlvdXQodik7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMueSA9IHY7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgeSgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3k7XG4gICAgfVxuXG4gICAgc2V0IHkodikge1xuICAgICAgICBpZiAodiAhPT0gdGhpcy5feSkge1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlTG9jYWxUcmFuc2xhdGVEZWx0YSgwLCB2IC0gdGhpcy5feSk7XG4gICAgICAgICAgICB0aGlzLl95ID0gdjtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBmdW5jWSgpIHtcbiAgICAgICAgcmV0dXJuICh0aGlzLl9vcHRGbGFncyAmIDIgPyB0aGlzLl9mdW5jWSA6IG51bGwpO1xuICAgIH1cblxuICAgIHNldCBmdW5jWSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9mdW5jWSAhPT0gdikge1xuICAgICAgICAgICAgdGhpcy5fb3B0RmxhZ3MgfD0gMjtcbiAgICAgICAgICAgIHRoaXMuX2Z1bmNZID0gdjtcbiAgICAgICAgICAgIGlmICh0aGlzLmhhc0ZsZXhMYXlvdXQoKSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2xheW91dC5zZXRPcmlnaW5hbFlXaXRob3V0VXBkYXRpbmdMYXlvdXQoMCk7XG4gICAgICAgICAgICAgICAgdGhpcy5sYXlvdXQuZm9yY2VMYXlvdXQoKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5feSA9IDA7XG4gICAgICAgICAgICAgICAgdGhpcy5fdHJpZ2dlclJlY2FsY1RyYW5zbGF0ZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2Rpc2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pcy5fZnVuY0ggIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX29wdEZsYWdzIHw9IDg7XG4gICAgICAgICAgICB0aGlzLl9mdW5jSCA9IHY7XG4gICAgICAgICAgICBpZiAodGhpcy5oYXNGbGV4TGF5b3V0KCkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9sYXlvdXQuX29yaWdpbmFsSGVpZ2h0ID0gMDtcbiAgICAgICAgICAgICAgICB0aGlzLmxheW91dC5jaGFuZ2VkRGltZW5zaW9ucyhmYWxzZSwgdHJ1ZSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX2ggPSAwO1xuICAgICAgICAgICAgICAgIHRoaXMuX3RyaWdnZXJSZWNhbGNUcmFuc2xhdGUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGRpc2FibGVGdW5jSCgpIHtcbiAgICAgICAgdGhpcy5fb3B0RmxhZ3MgPSB0aGlzLl9vcHRGbGFncyAmICgweEZGRkYgLSA4KTtcbiAgICAgICAgdGhpcy5fZnVuY0ggPSBudWxsO1xuICAgIH1cblxuICAgIGdldCB3KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdztcbiAgICB9XG5cbiAgICBnZXRSZW5kZXJXaWR0aCgpIHtcbiAgICAgICAgaWYgKHRoaXMuaGFzRmxleExheW91dCgpKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fbGF5b3V0Lm9yaWdpbmFsV2lkdGg7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fdztcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBoKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faDtcbiAgICB9XG5cbiAgICBnZXRSZW5kZXJIZWlnaHQoKSB7XG4gICAgICAgIGlmICh0aGlzLmhhc0ZsZXhMYXlvdXQoKSkge1xuICAgICAgICAgICAgcmV0dXJuIHRo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dFgodikge1xuICAgICAgICBpZiAodGhpcy5fcGl2b3RYICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9waXZvdFggPSB2O1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlTG9jYWxUcmFuc2xhdGUoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBwaXZvdFkoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9waXZvdFk7XG4gICAgfVxuXG4gICAgc2V0IHBpdm90WSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9waXZvdFkgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX3Bpdm90WSA9IHY7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVMb2NhbFRyYW5zbGF0ZSgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IHBpdm90KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcGl2b3RYO1xuICAgIH1cblxuICAgIHNldCBwaXZvdCh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9waXZvdFggIT09IHYgfHwgdGhpcy5fcGl2b3RZICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9waXZvdFggPSB2O1xuICAgICAgICAgICAgdGhpcy5fcGl2b3RZID0gdjtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUxvY2FsVHJhbnNsYXRlKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgbW91bnRYKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbW91bnRYO1xuICAgIH1cblxuICAgIHNldCBtb3VudFgodikge1xuICAgICAgICBpZiAodGhpcy5fbW91bnRYICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9tb3VudFggPSB2O1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlTG9jYWxUcmFuc2xhdGUoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBtb3VudFkoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9tb3VudFk7XG4gICAgfVxuXG4gICAgc2V0IG1vdW50WSh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9tb3VudFkgIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX21vdW50WSA9IHY7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVMb2NhbFRyYW5zbGF0ZSgpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgZ2V0IG1vdW50KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbW91bnRYO1xuICAgIH1cblxuICAgIHNldCBtb3VudCh2KSB7XG4gICAgICAgIGlmICh0aGlzLl9tb3VudFggIT09IHYgfHwgdGhpcy5fbW91bnRZICE9PSB2KSB7XG4gICAgICAgICAgICB0aGlzLl9tb3VudFggPSB2O1xuICAgICAgICAgICAgdGhpcy5fbW91bnRZID0gdjtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUxvY2FsVHJhbnNsYXRlKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgcm90YXRpb24oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9yb3RhdGlvbjtcbiAgICB9XG5cbiAgICBzZXQgcm90YXRpb24odikge1xuICAgICAgICBpZiAodGhpcy5fcm90YXRpb24gIT09IHYpIHtcbiAgICAgICAgICAgIHRoaXMuX3JvdGF0aW9uID0gdjtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUxvY2FsVHJhbnNmb3JtKCk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBnZXQgYWxwaGEoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9hbHBoYTtcbiAgICB9XG5cbiAgICBzZXQgYWxwaGEodikge1xuICAgICAgICAvLyBBY2NvdW50IGZvciByb3VuZGluZyBlcnJvcnMuXG4gICAgICAgIHYgPSAodiA+IDEgPyAxIDogKHYgPCAxZS0xNCA/IDAgOiB2KSk7XG4gICAgICAgIGlmICh0aGlzLl9hbHBoYSAhPT0gdikge1xuICAgICAgICAgICAgbGV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iAgICAgICAgICAgIGxldCBfc3IgPSBNYXRoLnNpbih0aGlzLl9yb3RhdGlvbik7XG4gICAgICAgICAgICBsZXQgX2NyID0gTWF0aC5jb3ModGhpcy5fcm90YXRpb24pO1xuXG4gICAgICAgICAgICB0aGlzLl9zZXRMb2NhbFRyYW5zZm9ybShcbiAgICAgICAgICAgICAgICBfY3IgKiB0aGlzLl9zY2FsZVgsXG4gICAgICAgICAgICAgICAgLV9zciAqIHRoaXMuX3NjYWxlWSxcbiAgICAgICAgICAgICAgICBfc3IgKiB0aGlzLl9zY2FsZVgsXG4gICAgICAgICAgICAgICAgX2NyICogdGhpcy5fc2NhbGVZXG4gICAgICAgICAgICApO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fc2V0TG9jYWxUcmFuc2Zvcm0oXG4gICAgICAgICAgICAgICAgdGhpcy5fc2NhbGVYLFxuICAgICAgICAgICAgICAgIDAsXG4gICAgICAgICAgICAgICAgMCxcbiAgICAgICAgICAgICAgICB0aGlzLl9zY2FsZVlcbiAgICAgICAgICAgICk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fdXBkYXRlTG9jYWxUcmFuc2xhdGUoKTtcbiAgICB9O1xuXG4gICAgX3VwZGF0ZUxvY2FsVHJhbnNsYXRlKCkge1xuICAgICAgICB0aGlzLl9yZWNhbGNMb2NhbFRyYW5zbGF0ZSgpO1xuICAgICAgICB0aGlzLl90cmlnZ2VyUmVjYWxjVHJhbnNsYXRlKCk7XG4gICAgfTtcblxuICAgIF9yZWNhbGNMb2NhbFRyYW5zbGF0ZSgpIHtcbiAgICAgICAgbGV0IHBpdm90WE11bCA9IHRoaXMuX3Bpdm90WCAqIHRoaXMuX3c7XG4gICAgICAgIGxldCBwaXZvdFlNdWwgPSB0aGlzLl9waXZvdFkgKiB0aGlzLl9oO1xuICAgICAgICBsZXQgcHggPSB0aGlzLl94IC0gKHBpdm90WE11bCAqIHRoaXMuX2xvY2FsVGEgKyBwaXZvdF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Z2V0UGFyZW50KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fcGFyZW50O1xuICAgIH1cblxuICAgIHNldFBhcmVudChwYXJlbnQpIHtcbiAgICAgICAgaWYgKHBhcmVudCAhPT0gdGhpcy5fcGFyZW50KSB7XG4gICAgICAgICAgICBsZXQgcHJldklzWkNvbnRleHQgPSB0aGlzLmlzWkNvbnRleHQoKTtcbiAgICAgICAgICAgIGxldCBwcmV2UGFyZW50ID0gdGhpcy5fcGFyZW50O1xuICAgICAgICAgICAgdGhpcy5fcGFyZW50ID0gcGFyZW50O1xuXG4gICAgICAgICAgICAvLyBOb3RpZnkgZmxleCBsYXlvdXQgZW5naW5lLlxuICAgICAgICAgICAgaWYgKHRoaXMuX2xheW91dCB8fCAocGFyZW50ICYmIHBhcmVudC5pc0ZsZXhDb250YWluZXIoKSkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmxheW91dC5zZXRQYXJlbnQocHJldlBhcmVudCwgcGFyZW50KTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHByZXZQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAvLyBXaGVuIGVsZW1lbnRzIGFyZSBkZWxldGVkLCB0aGUgcmVuZGVyIHRleHR1cmUgbXVzdCBiZSByZS1yZW5kZXJlZC5cbiAgICAgICAgICAgICAgICBwcmV2UGFyZW50LnNldEhhc1JlbmRlclVwZGF0ZXMoMyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRoaXMuX3NldFJlY2FsYygxICsgMiArIDQpO1xuXG4gICAgICAgICAgICBpZiAodGhpcy5fcGFyZW50KSB7XG4gICAgICAgICAgICAgICAgLy8gRm9yY2UgcGFyZW50IHRvIHByb3BhZ2F0ZSBoYXNVcGRhdGVzIGZsYWcuXG4gICAgICAgICAgICAgICAgdGhpcy5fcGFyZW50Ll9zZXRIYXNVcGRhdGVzKCk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl96SW5kZXggPT09IDApIHtcbiAgICAgICAgICAgICAgICB0aGlzLnNldFpQYXJlbnQocGFyZW50KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5zZXRaUGFyZW50KHBhcmVudCA/IHBhcmVudC5maW5kWkNvbnRleHQoKSA6IG51bGwpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAocHJldklzWkNvbnRleHQgIT09IHRoaXMuaXNaQ29udGV4dCgpKSB7XG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmlzWkNvbnRleHQoKSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmRpc2FibGVaQ29udGV4dCgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZW5hYmxlWkNvbnRleHQocHJldlBhcmVudC5maW5kWkNvbnRleHQoKSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBUcmVlIG9yZGVyIGRpZCBjaGFuZ2U6IGV2ZW4gaWYgelBhcmVudCBzdGF5cyB0aGUgc2FtZSwgd2UgbXVzdCByZXNvcnQuXG4gICAgICAgICAgICB0aGlzLl96SW5kZXhSZXNvcnQgPSB0cnVlO1xuICAgICAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICghdGhpcy5fc2hhZGVyKSB7XG4gICAgICAgICAgICAgICAgbGV0IG5ld1NoYWRlck93bmVyID0gcGFyZW50ICYmICFwYXJlbnQuX3JlbmRlclRvVGV4dHVyZUVuYWJsZWQgPyBwYXJlbnQuX3NoYWRlck93bmVyIDogbnVsbDtcbiAgICAgICAgICAgICAgICBpZiAobmV3U2hhZGVyT3duZXIgIT09IHRoaXMuX3NoYWRlck93bmVyKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc2V0SGFzUmVuZGVyVXBkYXRlcygxKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fc2V0U2hhZGVyT3duZXJSZWN1cnNpdmUobmV3U2hhZGVyT3duZXIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBlbmFibGVaU29ydChmb3JjZSA9IGZhbHNlKSB7XG4gICAgICAgIGlmICghdGhpcy5felNvcnQgJiYgdGhpcy5fekNvbnRleHRVc2FnZSA+IDApIHtcbiAgICAgICAgICAgIHRoaXMuX3pTb3J0ID0gdHJ1ZTtcbiAgICAgICAgICAgIGlmIChmb3JjZSkge1xuICAgICAgICAgICAgICAgIC8vIFpTb3J0IG11c3QgYmUgZG9uZSwgZXZlbiBpZiB0aGlzIGVsZW1lbnQgaXMgaW52aXNpYmxlLlxuICAgICAgICAgICAgICAgIC8vIFRoaXMgaXMgZG9uZSB0byBwcmV2ZW50IG1lbW9yeSBsZWFrcyB3aGVuIHJlbW92aW5nIGVsZW1lbnQgZnJvbSBpbmFjdGl2ZSByZW5kZXIgYnJhbmNoZXMuXG4gICAgICAgICAgICAgICAgdGhpcy5jdHguZm9yY2VaU29ydCh0aGlzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGFkZENoaWxkQXQoaW5kZXgsIGNoaWxkKSB7XG4gICAgICAgIGlmICghdGhpcy5fY2hpbGRyZW4pIHRoaXMuX2NoaWxkcmVuID0gW107XG4gICAgICAgIHRoaXMuX2NoaWxkcmVuLnNwbGljZShpbmRleCwgMCwgY2hpbGQpO1xuICAgICAgICBjaGlsZC5zZXRQYXJlbnQodGhpcyk7XG4gICAgfTtcblxuICAgIHNldENoaWxkQXQoaW5kZXgsIGNoaWxkKSB7XG4gICAgICAgIGlmICghdGhpcy5fY2hpbGRyZW4pIHRoaXMuX2NoaWxkcmVuID0gW107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dGltYXRlO1xuXG4gICAgICAgIGlmICh0aGlzLmhhc0ZsZXhMYXlvdXQoKSkge1xuICAgICAgICAgICAgdGhpcy5fbGF5b3V0Lm9yaWdpbmFsV2lkdGggPSB3O1xuICAgICAgICAgICAgdGhpcy5fbGF5b3V0Lm9yaWdpbmFsSGVpZ2h0ID0gaDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl93ICE9PSB3IHx8IHRoaXMuX2ggIT09IGgpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVEaW1lbnNpb25zKHcsIGgpO1xuICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9O1xuXG4gICAgX3VwZGF0ZURpbWVuc2lvbnModywgaCkge1xuICAgICAgICBpZiAodGhpcy5fdyAhPT0gdyB8fCB0aGlzLl9oICE9PSBoKSB7XG4gICAgICAgICAgICB0aGlzLl93ID0gdztcbiAgICAgICAgICAgIHRoaXMuX2ggPSBoO1xuXG4gICAgICAgICAgICB0aGlzLl90cmlnZ2VyUmVjYWxjVHJhbnNsYXRlKCk7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl90ZXh0dXJpemVyKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci5yZWxlYXNlUmVuZGVyVGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgIHRoaXMuX3RleHR1cml6ZXIudXBkYXRlUmVzdWx0VGV4dHVyZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgLy8gRHVlIHRvIHdpZHRoL2hlaWdodCBjaGFuZ2U6IHVwZGF0ZSB0aGUgdHJhbnNsYXRpb24gdmVjdG9yLlxuICAgICAgICAgICAgdGhpcy5fdXBkYXRlTG9jYWxUcmFuc2xhdGUoKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHNldFRleHR1cmVDb29yZH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kNvbnRleHQoKSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fcGFyZW50LmZpbmRaQ29udGV4dCgpO1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIHNldFpQYXJlbnQobmV3WlBhcmVudCkge1xuICAgICAgICBpZiAodGhpcy5felBhcmVudCAhPT0gbmV3WlBhcmVudCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQgIT09IG51bGwpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fekluZGV4ICE9PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuZGVjWkNvbnRleHRVc2FnZSgpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIC8vIFdlIG11c3QgZmlsdGVyIG91dCB0aGlzIGl0ZW0gdXBvbiB0aGUgbmV4dCByZXNvcnQuXG4gICAgICAgICAgICAgICAgdGhpcy5felBhcmVudC5lbmFibGVaU29ydCgpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAobmV3WlBhcmVudCAhPT0gbnVsbCkge1xuICAgICAgICAgICAgICAgIGxldCBoYWRaQ29udGV4dFVzYWdlID0gKG5ld1pQYXJlbnQuX3pDb250ZXh0VXNhZ2UgPiAwKTtcblxuICAgICAgICAgICAgICAgIC8vIEBwcmU6IG5ldyBwYXJlbnQncyBjaGlsZHJlbiBhcnJheSBoYXMgYWxyZWFkeSBiZWVuIG1vZGlmaWVkLlxuICAgICAgICAgICAgICAgIGlmICh0aGlzLl96SW5kZXggIT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgbmV3WlBhcmVudC5pbmNaQ29udGV4dFVzYWdlKCk7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaWYgKG5ld1pQYXJlbnQuX3pDb250ZXh0VXNhZ2UgPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICghaGFkWkNvbnRleHRVc2FnZSAmJiAodGhpcy5fcGFyZW50ID09PSBuZXdaUGFyZW50KSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gVGhpcyBjaGlsZCB3YXMgYWxyZWFkeSBpbiB0aGUgY2hpbGRyZW4gbGlzdC5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIERvIG5vdCBhZGQgZG91YmxlLlxuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gQWRkIG5ldyBjaGlsZCB0byBhcnJheS5cbiAgICAgICAgICAgICAgICAgICAgICAgIG5ld1pQYXJlbnQuX3pJbmRleGVkQ2hpbGRyZW4ucHVzaCh0aGlzKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIC8vIE9yZGVyIHNob3VsZCBiZSBjaGVja2VkLlxuICAgICAgICAgICAgICAgICAgICBuZXdaUGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0aGlzLl96UGFyZW50ID0gbmV3WlBhcmVudDtcblxuICAgICAgICAgICAgLy8gTmV3bHkgYWRkZWQgZWxlbWVudCBtdXN0IGJlIG1hcmtlZCBmb3IgcmVzb3J0LlxuICAgICAgICAgICAgdGhpcy5fekluZGV4UmVzb3J0ID0gdHJ1ZTtcbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBpbmNaQ29udGV4dFVzYWdlKCkge1xuICAgICAgICB0aGlzLl96Q29udGV4dFVzYWdlKys7XG4gICAgICAgIGlmICh0aGlzLl96Q29udGV4dFVzYWdlID09PSAxKSB7XG4gICAgICAgICAgICBpZiAoIXRoaXMuX3pJbmRleGVkQ2hpbGRyZW4pIHtcbiAgICAgICAgICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuID0gW107XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICAgICAgICAvLyBDb3B5LlxuICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4ucHVzaCh0aGlzLl9jaGlsZHJlbltpXSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIC8vIEluaXRpYWxseSwgY2hpbGRyZW4gYXJlIGFscmVhZHkgc29ydGVkIHByb3Blcmx5ICh0cmVlIG9yZGVyKS5cbiAgICAgICAgICAgICAgICB0aGlzLl96U29ydCA9IGZhbHNlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfTtcblxuICAgIGRlY1pDb250ZXh0VXNhZ2UoKSB7XG4gICAgICAgIHRoaXMuX3pDb250ZXh0VXNhZ2UtLTtcbiAgICAgICAgaWYgKHRoaXMuX3pDb250ZXh0VXNhZ2UgPT09IDApIHtcbiAgICAgICAgICAgIHRoaXMuX3pTb3J0ID0gZmFsc2U7XG4gICAgICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuLnNwbGljZSgwKTtcbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBnZXQgekluZGV4KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fekluZGV4O1xuICAgIH1cblxuICAgIHNldCB6SW5kZXgoekluZGV4KSB7XG4gICAgICAgIGlmICh0aGlzLl96SW5kZXggIT09IHpJbmRleCkge1xuICAgICAgICAgICAgdGhpcy5zZXRIYXNSZW5kZXJVcGRhdGVzKDEpO1xuXG4gICAgICAgICAgICBsZXQgbmV3WlBhcmVudCA9IHRoaXMuX3pQYXJlbnQ7XG5cbiAgICAgICAgICAgIGxldCBwcmV2SXNaQ29udGV4dCA9IHRoaXMuaXNaQ29udGV4dCgpO1xuICAgICAgICAgICAgaWYgKHpJbmRleCA9PT0gMCAmJiB0aGlzLl96SW5kZXggIT09IDApIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fcGFyZW50ID09PSB0aGlzLl96UGFyZW50KSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl96UGFyZW50KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl96UGFyZW50LmRlY1pDb250ZXh0VXNhZ2UoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIG5ld1pQYXJlbnQgPSB0aGlzLl9wYXJlbnQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmICh6SW5kZXggIT09IDAgJiYgdGhpcy5fekluZGV4ID09PSAwKSB7XG4gICAgICAgICAgICAgICAgbmV3WlBhcmVudCA9IHRoaXMuX3BhcmVudCA/IHRoaXMuX3BhcmVudC5maW5kWkNvbnRleHQoKSA6IG51bGw7XG4gICAgICAgICAgICAgICAgaWYgKG5ld1pQYXJlbnQgPT09IHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3pQYXJlbnQuaW5jWkNvbnRleHRVc2FnZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5felBhcmVudC5lbmFibGVaU29ydCgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmICh6SW5kZXggIT09IHRoaXMuX3pJbmRleCkge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl96UGFyZW50ICYmIHRoaXMuX3pQYXJlbnQuX3pDb250ZXh0VXNhZ2UpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5felBhcmVudC5lbmFibGVaU29ydCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKG5ld1pQYXJlbnQgIT09IHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLnNldFpQYXJlbnQobnVsbCk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRoaXMuX3pJbmRleCA9IHpJbmRleDtcblxuICAgICAgICAgICAgaWYgKG5ld1pQYXJlbnQgIT09IHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLnNldFpQYXJlbnQobmV3WlBhcmVudCk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChwcmV2SXNaQ29udGV4dCAhPT0gdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaXNaQ29udGV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZGlzYWJsZVpDb250ZXh0KCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbmFibGVaQ29udGV4dCh0aGlzLl9wYXJlbnQuZmluZFpDb250ZXh0KCkpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gTWFrZSBzdXJlIHRoYXQgcmVzb3J0IGlzIGRvbmUuXG4gICAgICAgICAgICB0aGlzLl96SW5kZXhSZXNvcnQgPSB0cnVlO1xuICAgICAgICAgICAgaWYgKHRoaXMuX3pQYXJlbnQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl96UGFyZW50LmVuYWJsZVpTb3J0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgZ2V0IGZvcmNlWkluZGV4Q29udGV4dCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2ZvcmNlWkluZGV4Q29udGV4dDtcbiAgICB9XG5cbiAgICBzZXQgZm9yY2VaSW5kZXhDb250ZXh0KHYpIHtcbiAgICAgICAgdGhpcy5zZXRIYXNSZW5kZXJVcGRhdGVzKDEpO1xuXG4gICAgICAgIGxldCBwcmV2SXNaQ29udGV4dCA9IHRoaXMuaXNaQ29udGV4dCgpO1xuICAgICAgICB0aGlzLl9mb3JjZVpJbmRleENvbnRleHQgPSB2O1xuXG4gICAgICAgIGlmIChwcmV2SXNaQ29udGV4dCAhPT0gdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5pc1pDb250ZXh0KCkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmRpc2FibGVaQ29udGV4dCgpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLmVuYWJsZVpDb250ZXh0KHRoaXMuX3BhcmVudC5maW5kWkNvbnRleHQoKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgZW5hYmxlWkNvbnRleHQocHJldlpDb250ZXh0KSB7XG4gICAgICAgIGlmIChwcmV2WkNvbnRleHQgJiYgcHJldlpDb250ZXh0Ll96Q29udGV4dFVzYWdlID4gMCkge1xuICAgICAgICAgICAgLy8gVHJhbnNmZXIgZnJvbSB1cHBlciB6IGNvbnRleHQgdG8gdGhpcyB6IGNvbnRleHQuXG4gICAgICAgICAgICBjb25zdCByZXN1bHRzID0gdGhpcy5fZ2V0WkluZGV4ZWREZXNjcygpO1xuICAgICAgICAgICAgcmVzdWx0cy5mb3JFYWNoKChjKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuaXNBbmNlc3Rvck9mKGMpICYmIGMuX3pJbmRleCAhPT0gMCkge1xuICAgICAgICAgICAgICAgICAgICBjLnNldFpQYXJlbnQodGhpcyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBfZ2V0WkluZGV4ZWREZXNjcygpIHtcbiAgICAgICAgY29uc3QgcmVzdWx0cyA9IFtdO1xuICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0uX2dldFpJbmRleGVkRGVzY3NSZWMocmVzdWx0cyk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHJlc3VsdHM7XG4gICAgfVxuXG4gICAgX2dldFpJbmRleGVkRGVzY3NSZWMocmVzdWx0cykge1xuICAgICAgICBpZiAodGhpcy5fekluZGV4KSB7XG4gICAgICAgICAgICByZXN1bHRzLnB1c2godGhpcyk7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5fY2hpbGRyZW4gJiYgIXRoaXMuaXNaQ29udGV4dCgpKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLl9nZXRaSW5kZXhlZERlc2NzUmVjKHJlc3VsdHMpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgZGlzYWJsZVpDb250ZXh0KCkge1xuICAgICAgICAvLyBUcmFuc2ZlciBmcm9tIHRoaXMgeiBjb250ZXh0IHRvIHVwcGVyIHogY29udGV4dC5cbiAgICAgICAgaWYgKHRoaXMuX3pDb250ZXh0VXNhZ2UgPiAwKSB7XG4gICAgICAgICAgICBsZXQgbmV3WlBhcmVudCA9IHRoaXMuX3BhcmVudC5maW5kWkNvbnRleHQoKTtcblxuICAgICAgICAgICAgLy8gTWFrZSBzdXJlIHRoYXQgei1pbmRleGVkIGNoaWxkcmVuIGFyZSB1cCB0byBkYXRlIChvbGQgb25lcyByZW1vdmVkKS5cbiAgICAgICAgICAgIGlmICh0aGlzLl96U29ydCkge1xuICAgICAgICAgICAgICAgIHRoaXMuc29ydFpJbmRleGVkQ2hpbGRyZW4oKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdGhpcy5fekluZGV4ZWRDaGlsZHJlbi5zbGljZSgpLmZvckVhY2goZnVuY3Rpb24gKGMpIHtcbiAgICAgICAgICAgICAgICBpZiAoYy5fekluZGV4ICE9PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIGMuc2V0WlBhcmVudChuZXdaUGFyZW50KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH07XG5cbiAgICBnZXQgY29sb3JVbCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2NvbG9yVWw7XG4gICAgfVxuXG4gICAgc2V0IGNvbG9yVWwoY29sb3IpIHtcbiAgICAgICAgaWYgKHRoaXMuX2NvbG9yVWwgIT09IGNvbG9yKSB7XG4gICAgICAgICAgICB0aGlzLnNldEhhc1JlbmRlclVwZGF0ZXModGhpcy5fZGlzcGxheWVkVGV4dHVyZVNvdXJjZSA/IDMgOiAxKTtcbiAgICAgICAgICAgIHRoaXMuX2NvbG9yVWwgPSBjb2xvcjtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBjb2xvclVyKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fY29sb3JVcjtcbiAgICB9XG5cbiAgICBzZXQgY29sb3JVcihjb2xvcikge1xuICAgICAgICBpZiAodGhpcy5fY29sb3JVciAhPT0gY29sb3IpIHtcbiAgICAgICAgICAgIHRoaXMuc2V0SGFzUmVuZGVyVXBkYXRlcyh0aGlzLl9kaXNwbGF5ZWRUZXh0dXJlU291cmNlID8gMyA6IDEpO1xuICAgICAgICAgICAgdGhpcy5fY29sb3JVciA9IGNvbG9yO1xuICAgICAgICB9XG4gICAgfTtcblxuICAgIGdldCBjb2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uLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIGxldCBjID0gdGhpcy5fY2hpbGRyZW5baV07XG4gICAgICAgICAgICAgICAgaWYgKCFjLl9zaGFkZXIpIHtcbiAgICAgICAgICAgICAgICAgICAgYy5fc2V0U2hhZGVyT3duZXJSZWN1cnNpdmUoZWxlbWVudENvcmUpO1xuICAgICAgICAgICAgICAgICAgICBjLl9oYXNSZW5kZXJVcGRhdGVzID0gMztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgX3NldFNoYWRlck93bmVyQ2hpbGRyZW5SZWN1cnNpdmUoZWxlbWVudENvcmUpIHtcbiAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgIGxldCBjID0gdGhpcy5fY2hpbGRyZW5baV07XG4gICAgICAgICAgICAgICAgaWYgKCFjLl9zaGFkZXIpIHtcbiAgICAgICAgICAgICAgICAgICAgYy5fc2V0U2hhZGVyT3duZXJSZWN1cnNpdmUoZWxlbWVudENvcmUpO1xuICAgICAgICAgICAgICAgICAgICBjLl9oYXNSZW5kZXJVcGRhdGVzID0gMztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9O1xuXG4gICAgX2hhc1JlbmRlckNvbnRleHQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9yZW5kZXJDb250ZXh0ICE9PSB0aGlzLl93b3JsZENvbnRleHQ7XG4gICAgfVxuXG4gICAgZ2V0IHJlbmRlckNvbnRleHQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9yZW5kZXJDb250ZXh0O1xuICAgIH1cblxuICAgIHVwZGF0ZVJlbmRlclRvVGV4dHVyZUVuYWJsZWQ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lKCkge1xuICAgICAgICByZXR1cm4gKHRoaXMuX2NvbG9yVWwgPT09IDB4RkZGRkZGRkYpICYmICh0aGlzLl9jb2xvclVyID09PSAweEZGRkZGRkZGKSAmJiAodGhpcy5fY29sb3JCbCA9PT0gMHhGRkZGRkZGRikgJiYgKHRoaXMuX2NvbG9yQnIgPT09IDB4RkZGRkZGRkYpO1xuICAgIH1cblxuICAgIGhhc1NpbXBsZVRleENvb3JkcygpIHtcbiAgICAgICAgcmV0dXJuICh0aGlzLl91bHggPT09IDApICYmICh0aGlzLl91bHkgPT09IDApICYmICh0aGlzLl9icnggPT09IDEpICYmICh0aGlzLl9icnkgPT09IDEpO1xuICAgIH1cblxuICAgIF9zdGFzaFRleENvb3JkcygpIHtcbiAgICAgICAgdGhpcy5fc3Rhc2hlZFRleENvb3JkcyA9IFt0aGlzLl91bHgsIHRoaXMuX3VseSwgdGhpcy5fYnJ4LCB0aGlzLl9icnldO1xuICAgICAgICB0aGlzLl91bHggPSAwO1xuICAgICAgICB0aGlzLl91bHkgPSAwO1xuICAgICAgICB0aGlzLl9icnggPSAxO1xuICAgICAgICB0aGlzLl9icnkgPSAxO1xuICAgIH1cblxuICAgIF91bnN0YXNoVGV4Q29vcmRzKCkge1xuICAgICAgICB0aGlzLl91bHggPSB0aGlzLl9zdGFzaGVkVGV4Q29vcmRzWzBdO1xuICAgICAgICB0aGlzLl91bHkgPSB0aGlzLl9zdGFzaGVkVGV4Q29vcmRzWzFdO1xuICAgICAgICB0aGlzLl9icnggPSB0aGlzLl9zdGFzaGVkVGV4Q29vcmRzWzJdO1xuICAgICAgICB0aGlzLl9icnkgPSB0aGlzLl9zdGFzaGVkVGV4Q29vcmRzWzNdO1xuICAgICAgICB0aGlzLl9zdGFzaGVkVGV4Q29vcmRzID0gbnVsbDtcbiAgICB9XG5cbiAgICBfc3Rhc2hDb2xvcnMoKSB7XG4gICAgICAgIHRoaXMuX3N0YXNoZWRDb2xvcnMgPSBbdGhpcy5fY29sb3JVbCw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RDb250ZXh0O1xuICAgICAgICBjb25zdCB2aXNpYmxlID0gKHB3LmFscGhhICYmIHRoaXMuX2xvY2FsQWxwaGEpO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBXZSBtdXN0IHVwZGF0ZSBpZjpcbiAgICAgICAgICogLSBicmFuY2ggY29udGFpbnMgdXBkYXRlcyAoZXZlbiB3aGVuIGludmlzaWJsZSBiZWNhdXNlIGl0IG1heSBjb250YWluIHotaW5kZXhlZCBkZXNjZW5kYW50cylcbiAgICAgICAgICogLSB0aGVyZSBhcmUgKGluaGVyaXRlZCkgdXBkYXRlcyBhbmQgdGhpcyBicmFuY2ggaXMgdmlzaWJsZVxuICAgICAgICAgKiAtIHRoaXMgYnJhbmNoIGJlY29tZXMgaW52aXNpYmxlIChkZXNjcyBtYXkgYmUgei1pbmRleGVkIHNvIHdlIG11c3QgdXBkYXRlIGFsbCBhbHBoYSB2YWx1ZXMpXG4gICAgICAgICAqL1xuICAgICAgICBpZiAodGhpcy5faGFzVXBkYXRlcyB8fCAodGhpcy5fcmVjYWxjICYmIHZpc2libGUpIHx8ICh3LmFscGhhICYmICF2aXNpYmxlKSkge1xuICAgICAgICAgICAgbGV0IHJlY2FsYyA9IHRoaXMuX3JlY2FsYztcblxuICAgICAgICAgICAgLy8gVXBkYXRlIHdvcmxkIGNvb3Jkcy9hbHBoYS5cbiAgICAgICAgICAgIGlmIChyZWNhbGMgJiAxKSB7XG4gICAgICAgICAgICAgICAgaWYgKCF3LmFscGhhICYmIHZpc2libGUpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gQmVjb21lcyB2aXNpYmxlLlxuICAgICAgICAgICAgICAgICAgICB0aGlzLl9oYXNSZW5kZXJVcGRhdGVzID0gMztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdy5hbHBoYSA9IHB3LmFscGhhICogdGhpcy5fbG9jYWxBbHBoYTtcblxuICAgICAgICAgICAgICAgIGlmICh3LmFscGhhIDwgMWUtMTQpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gVGlueSByb3VuZGluZyBlcnJvcnMgbWF5IGNhdXNlIGZhaWxpbmcgdmlzaWJpbGl0eSB0ZXN0cy5cbiAgICAgICAgICAgICAgICAgICAgdy5hbHBoYSA9IDA7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAocmVjYWxjICYgNikge1xuICAgICAgICAgICAgICAgIHcucHggPSBwdy5weCArIHRoaXMuX2xvY2FsUHggKiBwdy50YTtcbiAgICAgICAgICAgICAgICB3LnB5ID0gcHcucHkgKyB0aGlzLl9sb2NhbFB5ICogcHcudGQ7XG4gICAgICAgICAgICAgICAgaWYgKHB3LnRiICE9PSAwKSB3LnB4ICs9IHRoaXMuX2xvY2FsUHkgKiBwdy50YjtcbiAgICAgICAgICAgICAgICBpZiAocHcudGMgIT09IDApIHcucHkgKz0gdGhpcy5fbG9jYWxQeCAqIHB3LnRjO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAocmVjYWxjICYgNCkge1xuICAgICAgICAgICAgICAgIHcudGEgPSB0aGlzLl9sb2NhbFRhICogcHcudGE7XG4gICAgICAgICAgICAgICAgdy50YiA9IHRoaXMuX2xvY2FsVGQgKiBwdy50YjtcbiAgICAgICAgICAgICAgICB3LnRjID0gdGhpcy5fbG9jYWxUYSAqIHB3LnRjO1xuICAgICAgICAgICAgICAgIHcudGQgPSB0aGlzLl9sb2NhbFRkICogcHcudGQ7XG5cbiAgICAgICAgICAgICAgICBpZiAodGhpcy5faXNDb21wbGV4KSB7XG4gICAgICAgICAgICAgICAgICAgIHcudGEgKz0gdGhpcy5fbG9jYWxUYyAqIHB3LnRiO1xuICAgICAgICAgICAgICAgICAgICB3LnRiICs9IHRoaXMuX2xvY2FsVGIgKiBwdy50YTtcbiAgICAgICAgICAgICAgICAgICAgdy50YyArPSB0aGlzLl9sb2NhbFRjICogcHcudGQ7XG4gICAgICAgICAgICAgICAgICAgIHcudGQgKz0gdGhpcy5fbG9jYWxUYiAqIHB3LnRjO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gVXBkYXRlIHJlbmRlciBjb29yZHMvYWxwaGEuXG4gICAgICAgICAgICBjb25zdCBwciA9IHRoaXMuX3BhcmVudC5fcmVuZGVyQ29udGV4dDtcbiAgICAgICAgICAgIGlmICh0aGlzLl9wYXJlbnQuX2hhc1JlbmRlckNvbnRleHQoKSkge1xuICAgICAgICAgICAgICAgIGNvbnN0IGluaXQgPSB0aGlzLl9yZW5kZXJDb250ZXh0ID09PSB0aGlzLl93b3JsZENvbnRleHQ7XG4gICAgICAgICAgICAgICAgaWYgKGluaXQpIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gRmlyc3QgcmVuZGVyIGNvbnRleHQgYnVpbGQ6IG1ha2Ugc3VyZSB0aGF0IGl0IGlzIGZ1bGx5IGluaXRpYWxpemVkIGNvcnJlY3RseS5cbiAgICAgICAgICAgICAgICAgICAgLy8gT3RoZXJ3aXNlLCBpZiB3ZSBnZXQgaW50byBib3VuZHMgbGF0ZXIsIHRoZSByZW5kZXIgY29udGV4dCB3b3VsZCBub3QgYmUgaW5pdGlhbGl6ZWQgY29ycmVjdGx5LlxuICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gbmV3IEVsZW1lbnRDb3JlQ29udGV4dCgpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGNvbnN0IHIgPSB0aGlzLl9yZW5kZXJDb250ZXh0O1xuXG4gICAgICAgICAgICAgICAgLy8gVXBkYXRlIHdvcmxkIGNvb3Jkcy9hbHBoYS5cbiAgICAgICAgICAgICAgICBpZiAoaW5pdCB8fCAocmVjYWxjICYgMSkpIHtcbiAgICAgICAgICAgICAgICAgICAgci5hbHBoYSA9IHByLmFscGhhICogdGhpcy5fbG9jYWxBbHBoYTtcblxuICAgICAgICAgICAgICAgICAgICBpZiAoci5hbHBoYSA8IDFlLTE0KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByLmFscGhhID0gMDtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmIChpbml0IHx8IChyZWNhbGMgJiA2KSkge1xuICAgICAgICAgICAgICAgICAgICByLnB4ID0gcHIucHggKyB0aGlzLl9sb2NhbFB4ICogcHIudGE7XG4gICAgICAgICAgICAgICAgICAgIHIucHkgPSBwci5weSArIHRoaXMuX2xvY2FsUHkgKiBwci50ZDtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHByLnRiICE9PSAwKSByLnB4ICs9IHRoaXMuX2xvY2FsUHkgKiBwci50YjtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHByLnRjICE9PSAwKSByLnB5ICs9IHRoaXMuX2xvY2FsUHggKiBwci50YztcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAoaW5pdCkge1xuICAgICAgICAgICAgICAgICAgICAvLyBXZSBzZXQgdGhlIHJlY2FsYyB0b2dnbGUsIGJlY2F1c2Ugd2UgbXVzdCBtYWtlIHN1cmUgdGhhdCB0aGUgc2Npc3NvciBpcyB1cGRhdGVkLlxuICAgICAgICAgICAgICAgICAgICByZWNhbGMgfD0gMjtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAoaW5pdCB8fCAocmVjYWxjICYgNCkpIHtcbiAgICAgICAgICAgICAgICAgICAgci50YSA9IHRoaXMuX2xvY2FsVGEgKiBwci50YTtcbiAgICAgICAgICAgICAgICAgICAgci50YiA9IHRoaXMuX2xvY2FsVGQgKiBwci50YjtcbiAgICAgICAgICAgICAgICAgICAgci50YyA9IHRoaXMuX2xvY2FsVGEgKiBwci50YztcbiAgICAgICAgICAgICAgICAgICAgci50ZCA9IHRoaXMuX2xvY2FsVGQgKiBwci50ZDtcblxuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5faXNDb21wbGV4KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByLnRhICs9IHRoaXMuX2xvY2FsVGMgKiBwci50YjtcbiAgICAgICAgICAgICAgICAgICAgICAgIHIudGIgKz0gdGhpcy5fbG9jYWxUYiAqIHByLnRhO1xuICAgICAgICAgICAgICAgICAgICAgICAgci50YyArPSB0aGlzLl9sb2NhbFRjICogcHIudGQ7XG4gICAgICAgICAgICAgICAgICAgICAgICByLnRkICs9IHRoaXMuX2xvY2FsVGIgKiBwci50YztcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IHRoaXMuX3dvcmxkQ29udGV4dDtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuY3R4LnVwZGF0ZVRyZWVPcmRlciA9PT0gLTEpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmN0eC51cGRhdGVUcmVlT3JkZXIgPSB0aGlzLl91cGRhdGVUcmVlT3JkZXIgKyAxO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVUcmVlT3JkZXIgPSB0aGlzLmN0eC51cGRhdGVUcmVlT3JkZXIrKztcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gRGV0ZXJtaW5lIHdoZXRoZXIgd2UgbXVzdCB1c2UgYSAncmVuZGVyVGV4dHVyZScuXG4gICAgICAgICAgICBjb25zdCB1c2VSZW5kZXJUb1RleHR1cmUgPSB0aGlzLl9yZW5kZXJUb1RleHR1cmVFbmFibGVkICYmIHRoaXMuX3RleHR1cml6ZXIubXVzdFJlbmRlclRvVGV4dHVyZSgpO1xuICAgICAgICAgICAgaWYgKHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSAhPT0gdXNlUmVuZGVyVG9UZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgLy8gQ29vcmRzIG11c3QgYmUgY2hhbmdlZC5cbiAgICAgICAgICAgICAgICB0aGlzLl9yZWNhbGMgfD0gMiArIDQ7XG5cbiAgICAgICAgICAgICAgICAvLyBTY2lzc29yIG1heSBjaGFuZ2U6IGZvcmNlIHVwZGF0ZS5cbiAgICAgICAgICAgICAgICByZWNhbGMgfD0gMjtcblxuICAgICAgICAgICAgICAgIGlmICghdGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFdlIG11c3QgcmVsZWFzZSB0aGUgdGV4dHVyZS5cbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci5yZWxlYXNlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlID0gdXNlUmVuZGVyVG9UZXh0dXJlO1xuXG4gICAgICAgICAgICBjb25zdCByID0gdGhpcy5fcmVuZGVyQ29udGV4dDtcblxuICAgICAgICAgICAgY29uc3QgYmJveFcgPSB0aGlzLl9kaW1zVW5rbm93biA/IDIwNDggOiB0aGlzLl93O1xuICAgICAgICAgICAgY29uc3QgYmJveEggPSB0aGlzLl9kaW1zVW5rbm93biA/IDIwNDggOiB0aGlzLl9oO1xuXG4gICAgICAgICAgICAvLyBDYWxjdWxhdGUgYSBiYm94IGZvciB0aGlzIGVsZW1lbnQuXG4gICAgICAgICAgICBsZXQgc3gsIHN5LCBleCwgZXk7XG4gICAgICAgICAgICBjb25zdCByQ29tcGxleCA9IChyLnRiICE9PSAwKSB8fCAoci50YyAhPT0gMCkgfHwgKHIudGEgPCAwKSB8fCAoci50ZCA8IDApO1xuICAgICAgICAgICAgaWYgKHJDb21wbGV4KSB7XG4gICAgICAgICAgICAgICAgc3ggPSBNYXRoLm1pbigwLCBiYm94VyAqIHIudGEsIGJib3hXICogci50YSArIGJib3hIICogci50YiwgYmJveEggKiByLnRiKSArIHIucHg7XG4gICAgICAgICAgICAgICAgZXggPSBNYXRoLm1heCgwLCBiYm94VyAqIHIudGEsIGJib3hXICogci50YSArIGJib3hIICogci50YiwgYmJveEggKiByLnRiKSArIHIucHg7XG4gICAgICAgICAgICAgICAgc3kgPSBNYXRoLm1pbigwLCBiYm94VyAqIHIudGMsIGJib3hXICogci50YyArIGJib3hIICogci50ZCwgYmJveEggKiByLnRkKSArIHIucHk7XG4gICAgICAgICAgICAgICAgZXkgPSBNYXRoLm1heCgwLCBiYm94VyAqIHIudGMsIGJib3hXICogci50YyArIGJib3hIICogci50ZCwgYmJveEggKiByLnRkKSArIHIucHk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHN4ID0gci5weDtcbiAgICAgICAgICAgICAgICBleCA9IHIucHggKyByLnRhICogYmJveFc7XG4gICAgICAgICAgICAgICAgc3kgPSByLnB5O1xuICAgICAgICAgICAgICAgIGV5ID0gci5weSArIHIudGQgKiBiYm94SDtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX2RpbXNVbmtub3duICYmIChyQ29tcGxleCB8fCB0aGlzLl9sb2NhbFRhIDwgMSB8fCB0aGlzLl9sb2NhbFRiIDwgMSkpIHtcbiAgICAgICAgICAgICAgICAvLyBJZiB3ZSBhcmUgZGVhbGluZyB3aXRoIGEgbm9uLWlkZW50aXR5IG1hdHJpeCwgd2UgbXVzdCBleHRlbmQgdGhlIGJib3ggc28gdGhhdCB3aXRoaW5Cb3VuZHMgYW5kXG4gICAgICAgICAgICAgICAgLy8gIHNjaXNzb3JzIHdpbGwgaW5jbHVkZSB0aGUgY29tcGxldGUgcmFuZ2Ugb2YgKHBvc2l0aXZlKSBkaW1lbnNpb25zIHVwIHRvICxsaC5cbiAgICAgICAgICAgICAgICBjb25zdCBueCA9IHRoaXMuX3ggKiBwci50YSArIHRoaXMuX3kgKiBwci50YiArIHByLnB4O1xuICAgICAgICAgICAgICAgIGNvbnN0IG55ID0gdGhpcy5feCAqIHByLnRjICsgdGhpcy5feSAqIHByLnRkICsgcHIucHk7XG4gICAgICAgICAgICAgICAgaWYgKG54IDwgc3gpIHN4ID0gbng7XG4gICAgICAgICAgICAgICAgaWYgKG55IDwgc3kpIHN5ID0gbnk7XG4gICAgICAgICAgICAgICAgaWYgKG54ID4gZXgpIGV4ID0gbng7XG4gICAgICAgICAgICAgICAgaWYgKG55ID4gZXkpIGV5ID0gbnk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChyZWNhbGMgJiA2IHx8ICF0aGlzLl9zY2lzc29yIC8qIGluaXRpYWwgKi8pIHtcbiAgICAgICAgICAgICAgICAvLyBEZXRlcm1pbmUgd2hldGhlciB3ZSBtdXN0ICdjbGlwJy5cbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fY2xpcHBpbmcgJiYgci5pc1NxdWFyZSgpKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIElmIHRoZSBwYXJlbnQgcmVuZGVycyB0byBhIHRleHR1cmUsIGl0J3Mgc2Npc3NvciBzaG91bGQgYmUgaWdub3JlZDtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgYXJlYSA9IHRoaXMuX3BhcmVudC5fdXNlUmVuZGVyVG9UZXh0dXJlID8gdGhpcy5fcGFyZW50Ll92aWV3cG9ydCA6IHRoaXMuX3BhcmVudC5fc2Npc3NvcjtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGFyZWEpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIE1lcmdlIHNjaXNzb3IgYXJlYXMuXG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBseCA9IE1hdGgubWF4KGFyZWFbMF0sIHN4KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGx5ID0gTWF0aC5tYXgoYXJlYVsxXSwgc3kpO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fc2Npc3NvciA9IFtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBseCxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBseSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBNYXRoLm1pbihhcmVhWzJdICsgYXJlYVswXSwgZXgpIC0gbHgsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgTWF0aC5taW4oYXJlYVszXSArIGFyZWFbMV0sIGV5KSAtIGx5XG4gICAgICAgICAgICAgICAgICAgICAgICBdO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fc2Npc3NvciA9IFtzeCwgc3ksIGV4IC0gc3gsIGV5IC0gc3ldO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gTm8gY2xpcHBpbmc6IHJldXNlIHBhcmVudCBzY2lzc29yLlxuICAgICAgICAgICAgICAgICAgICB0aGlzLl9zY2lzc29yID0gdGhpcy5fcGFyZW50Ll91c2VSZW5kZXJUb1RleHR1cmUgPyB0aGlzLl9wYXJlbnQuX3ZpZXdwb3J0IDogdGhpcy5fcGFyZW50Ll9zY2lzc29yO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gQ2FsY3VsYXRlIHRoZSBvdXRPZkJvdW5kcyBtYXJnaW4uXG4gICAgICAgICAgICBpZiAodGhpcy5fYm91bmRzTWFyZ2luKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcmVjQm91bmRzTWFyZ2luID0gdGhpcy5fYm91bmRzTWFyZ2luO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9yZWNCb3VuZHNNYXJnaW4gPSB0aGlzLl9wYXJlbnQuX3JlY0JvdW5kc01hcmdpbjtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHRoaXMuX29uQWZ0ZXJDYWxjcykge1xuICAgICAgICAgICAgICAgIC8vIEFmdGVyIGNhbGNzIG1heSBjaGFuZ2UgcmVuZGVyIGNvb3Jkcywgc2Npc3NvciBhbmQvb3IgcmVjQm91bmRzTWFyZ2luLlxuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9vbkFmdGVyQ2FsY3ModGhpcy5lbGVtZW50KSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBSZWNhbGN1bGF0ZSBiYm94LlxuICAgICAgICAgICAgICAgICAgICBpZiAockNvbXBsZXgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN4ID0gTWF0aC5taW4oMCwgYmJveFcgKiByLnRhLCBiYm94VyAqIHIudGEgKyBiYm94SCAqIHIudGIsIGJib3hIICogci50YikgKyByLnB4O1xuICAgICAgICAgICAgICAgICAgICAgICAgZXggPSBNYXRoLm1heCgwLCBiYm94VyAqIHIudGEsIGJib3hXICogci50YSArIGJib3hIICogci50YiwgYmJveEggKiByLnRiKSArIHIucHg7XG4gICAgICAgICAgICAgICAgICAgICAgICBzeSA9IE1hdGgubWluKDAsIGJib3hXICogci50YywgYmJveFcgKiByLnRjICsgYmJveEggKiByLnRkLCBiYm94SCAqIHIudGQpICsgci5weTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGV5ID0gTWF0aC5tYXgoMCwgYmJveFcgKiByLnRjLCBiYm94VyAqIHIudGMgKyBiYm94SCAqIHIudGQsIGJib3hIICogci50ZCkgKyByLnB5O1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3ggPSByLnB4O1xuICAgICAgICAgICAgICAgICAgICAgICAgZXggPSByLnB4ICsgci50YSAqIGJib3hXO1xuICAgICAgICAgICAgICAgICAgICAgICAgc3kgPSByLnB5O1xuICAgICAgICAgICAgICAgICAgICAgICAgZXkgPSByLnB5ICsgci50ZCAqIGJib3hIO1xuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX2RpbXNVbmtub3duICYmIChyQ29tcGxleCB8fCB0aGlzLl9sb2NhbFRhIDwgMSB8fCB0aGlzLl9sb2NhbFRiIDwgMSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IG54ID0gdGhpcy5feCAqIHByLnRhICsgdGhpcy5feSAqIHByLnRiICsgcHIucHg7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBueSA9IHRoaXMuX3ggKiBwci50YyArIHRoaXMuX3kgKiBwci50ZCArIHByLnB5O1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG54IDwgc3gpIHN4ID0gbng7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAobnkgPCBzeSkgc3kgPSBueTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChueCA+IGV4KSBleCA9IG54O1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG55ID4gZXkpIGV5ID0gbnk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9wYXJlbnQuX291dE9mQm91bmRzID09PSAyKSB7XG4gICAgICAgICAgICAgICAgLy8gSW5oZXJpdCBwYXJlbnQgb3V0IG9mIGJvdW5kc25lc3MuXG4gICAgICAgICAgICAgICAgdGhpcy5fb3V0T2ZCb3VuZHMgPSAyO1xuXG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3dpdGhpbkJvdW5kc01hcmdpbikge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4gPSBmYWxzZTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5lbGVtZW50Ll9kaXNhYmxlV2l0aGluQm91bmRzTWFyZ2luKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZiAocmVjYWxjICYgNikge1xuICAgICAgICAgICAgICAgICAgICAvLyBSZWNoZWNrIGlmIGVsZW1lbnQgaXMgb3V0LW9mLWJvdW5kcyAoYWxsIHNldHRpbmdzIHRoYXQgYWZmZWN0IHRoaXMgc2hvdWxkIGVuYWJsZSByZWNhbGMgYml0IDIgb3IgNCkuXG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMDtcbiAgICAgICAgICAgICAgICAgICAgbGV0IHdpdGhpbk1hcmdpbiA9IHRydWU7XG5cbiAgICAgICAgICAgICAgICAgICAgLy8gT2Zmc2NyZWVucyBhcmUgYWx3YXlzIHJlbmRlcmVkIGFzIGxvbmcgYXMgdGhlIHBhcmVudCBpcyB3aXRoaW4gYm91bmRzLlxuICAgICAgICAgICAgICAgICAgICBpZiAoIXRoaXMuX3JlbmRlclRvVGV4dHVyZUVuYWJsZWQgfHwgIXRoaXMuX3RleHR1cml6ZXIgfHwgIXRoaXMuX3RleHR1cml6ZXIucmVuZGVyT2Zmc2NyZWVuKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fc2Npc3NvciAmJiAodGhpcy5fc2Npc3NvclsyXSA8PSAwIHx8IHRoaXMuX3NjaXNzb3JbM10gPD0gMCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBFbXB0eSBzY2lzc29yIGFyZWEuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fb3V0T2ZCb3VuZHMgPSAyO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBVc2UgYmJveCB0byBjaGVjayBvdXQtb2YtYm91bmRuZXNzLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICgodGhpcy5fc2Npc3NvclswXSA+IGV4KSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAodGhpcy5fc2Npc3NvclsxXSA+IGV5KSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoc3ggPiAodGhpcy5fc2Npc3NvclswXSArIHRoaXMuX3NjaXNzb3JbMl0pKSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoc3kgPiAodGhpcy5fc2Npc3NvclsxXSArIHRoaXMuX3NjaXNzb3JbM10pKVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9vdXRPZkJvdW5kcyA9IDE7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX291dE9mQm91bmRzKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9jbGlwcGluZyB8fCB0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUgfHwgKHRoaXMuX2NsaXBib3ggJiYgKGJib3hXICYmIGJib3hIKSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX291dE9mQm91bmRzID0gMjtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICAgICAgd2l0aGluTWFyZ2luID0gKHRoaXMuX291dE9mQm91bmRzID09PSAwKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghd2l0aGluTWFyZ2luKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gUmUtdGVzdCwgbm93IHdpdGggbWFyZ2lucy5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fcmVjQm91bmRzTWFyZ2luKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdpdGhpbk1hcmdpbiA9ICEoKGV4IDwgdGhpcy5fc2Npc3NvclswXSAtIHRoaXMuX3JlY0JvdW5kc01hcmdpblsyXSkgfHxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChleSA8IHRoaXMuX3NjaXNzb3JbMV0gLSB0aGlzLl9yZWNCb3VuZHNNYXJnaW5bM10pIHx8XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoc3ggPiB0aGlzLl9zY2lzc29yWzBdICsgdGhpcy5fc2Npc3NvclsyXSArIHRoaXMuX3JlY0JvdW5kc01hcmdpblswXSkgfHxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChzeSA+IHRoaXMuX3NjaXNzb3JbMV0gKyB0aGlzLl9zY2lzc29yWzNdICsgdGhpcy5fcmVjQm91bmRzTWFyZ2luWzFdKSk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgd2l0aGluTWFyZ2luID0gISgoZXggPCB0aGlzLl9zY2lzc29yWzBdIC0gMTAwKSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGV5IDwgdGhpcy5fc2Npc3NvclsxXSAtIDEwMCkgfHxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChzeCA+IHRoaXMuX3NjaXNzb3JbMF0gKyB0aGlzLl9zY2lzc29yWzJdICsgMTAwKSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHN5ID4gdGhpcy5fc2Npc3NvclsxXSArIHRoaXMuX3NjaXNzb3JbM10gKyAxMDApKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHdpdGhpbk1hcmdpbiAmJiB0aGlzLl9vdXRPZkJvdW5kcyA9PT0gMikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBDaGlsZHJlbiBtdXN0IGJlIHZpc2l0ZWQgYmVjYXVzZSB0aGV5IG1heSBjb250YWluIGVsZW1lbnRzIHRoYXQgYXJlIHdpdGhpbiBtYXJnaW4sIHNvIG11c3QgYmUgdmlzaWJsZS5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fb3V0T2ZCb3VuZHMgPSAxO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl93aXRoaW5Cb3VuZHNNYXJnaW4gIT09IHdpdGhpbk1hcmdpbikge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fd2l0aGluQm91bmRzTWFyZ2luID0gd2l0aGluTWFyZ2luO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fd2l0aGluQm91bmRzTWFyZ2luKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gVGhpcyBtYXkgdXBkYXRlIHRoaW5ncyAodHhMb2FkZWQgZXZlbnRzKSBpbiB0aGUgZWxlbWVudCBpdHNlbGYsIGJ1dCBhbHNvIGluIGRlc2NlbmRhbnRzIGFuZCBhbmNlc3RvcnMuXG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBDaGFuZ2VzIGluIGFuY2VzdG9ycyBzaG91bGQgYmUgZXhlY3V0ZWQgZHVyaW5nIHRoZSBuZXh0IGNhbGwgb2YgdGhlIHN0YWdlIHVwZGF0ZS4gQnV0IHdlIG11c3RcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyB0YWtlIGNhcmUgdGhhdCB0aGUgX3JlY2FsYyBhbmQgX2hhc1VwZGF0ZXMgZmxhZ3MgYXJlIHByb3Blcmx5IHJlZ2lzdGVyZWQuIFRoYXQncyB3aHkgd2UgY2xlYXJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBib3RoIGJlZm9yZSBlbnRlcmluZyB0aGUgY2hpbGRyZW4sIGFuZCB1c2UgX3BSZWNhbGMgdG8gdHJhbnNmZXIgaW5oZXJpdGVkIHVwZGF0ZXMgaW5zdGVhZCBvZlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIF9yZWNhbGMgZGlyZWN0bHkuXG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBDaGFuZ2VzIGluIGRlc2NlbmRhbnRzIGFyZSBhdXRvbWF0aWNhbGx5IGV4ZWN1dGVkIHdpdGhpbiB0aGUgY3VycmVudCB1cGRhdGUgbG9vcCwgdGhvdWdoIHdlIG11c3RcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyB0YWtlIGNhcmUgdG8gbm90IHVwZGF0ZSB0aGUgaGFzVXBkYXRlcyBmbGFnIHVubmVjZXNzYXJpbHkgaW4gYW5jZXN0b3JzLiBXZSBhY2hpZXZlIHRoaXMgYnkgbWFraW5nXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gc3VyZSB0aGF0IHRoZSBoYXNVcGRhdGVzIGZsYWcgb2YgdGhpcyBlbGVtZW50IGlzIHR1cm5lZCBvbiwgd2hpY2ggYmxvY2tzIGl0IGZvciBhbmNlc3RvcnMuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5faGFzVXBkYXRlcyA9IHRydWU7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCByZWNhbGMgPSB0aGlzLl9yZWNhbGM7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcmVjYWxjID0gMDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmVsZW1lbnQuX2VuYWJsZVdpdGhpbkJvdW5kc01hcmdpbigpO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX3JlY2FsYykge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBUaGlzIGVsZW1lbnQgbmVlZHMgdG8gYmUgcmUtdXBkYXRlZCBub3csIGJlY2F1c2Ugd2Ugd2FudCB0aGUgZGltZW5zaW9ucyAoYW5kIG90aGVyIGNoYW5nZXMpIHRvIGJlIHVwZGF0ZWQuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnVwZGF0ZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlY2FsYyA9IHJlY2FsYztcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5lbGVtZW50Ll9kaXNhYmxlV2l0aGluQm91bmRzTWFyZ2luKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICAgICAgICAvLyBTZXQgdmlld3BvcnQgbmVjZXNzYXJ5IGZvciBjaGlsZHJlbiBzY2lzc29yIGNhbGN1bGF0aW9uLlxuICAgICAgICAgICAgICAgIGlmICh0aGlzLl92aWV3cG9ydCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl92aWV3cG9ydFsyXSA9IGJib3hXO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl92aWV3cG9ydFszXSA9IGJib3hIO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3ZpZXdwb3J0ID0gWzAsIDAsIGJib3hXLCBiYm94SF07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBGaWx0ZXIgb3V0IGJpdHMgdGhhdCBzaG91bGQgbm90IGJlIGNvcGllZCB0byB0aGUgY2hpbGRyZW4gKGN1cnJlbnRseSBhbGwgYXJlKS5cbiAgICAgICAgICAgIHRoaXMuX3BSZWNhbGMgPSAodGhpcy5fcmVjYWxjICYgMTM1KTtcblxuICAgICAgICAgICAgLy8gQ2xlYXIgZmxhZ3Mgc28gdGhhdCBmdXR1cmUgdXBkYXRlcyBhcmUgcHJvcGVybHkgZGV0ZWN0ZWQuXG4gICAgICAgICAgICB0aGlzLl9yZWNhbGMgPSAwO1xuICAgICAgICAgICAgdGhpcy5faGFzVXBkYXRlcyA9IGZhbHNlO1xuXG4gICAgICAgICAgICBpZiAodGhpcy5fb3V0T2ZCb3VuZHMgPCAyKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX3VzZVJlbmRlclRvVGV4dHVyZSkge1xuICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fd29ybGRDb250ZXh0LmlzSWRlbnRpdHkoKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gT3B0aW1pemF0aW9uLlxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gVGhlIHdvcmxkIGNvbnRleHQgaXMgYWxyZWFkeSBpZGVudGl0eTogdXNlIHRoZSB3b3JsZCBjb250ZXh0IGFzIHJlbmRlciBjb250ZXh0IHRvIHByZXZlbnRzIHRoZVxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gYW5jZXN0b3JzIGZyb20gaGF2aW5nIHRvIHVwZGF0ZSB0aGUgcmVuZGVyIGNvbnRleHQuXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gdGhpcy5fd29ybGRDb250ZXh0O1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gVGVtcG9yYXJpbHkgcmVwbGFjZSB0aGUgcmVuZGVyIGNvb3JkIGF0dHJpYnMgYnkgdGhlIGlkZW50aXR5IG1hdHJpeC5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFRoaXMgYWxsb3dzIHRoZSBjaGlsZHJlbiB0byBjYWxjdWxhdGUgdGhlIHJlbmRlciBjb250ZXh0LlxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcmVuZGVyQ29udGV4dCA9IEVsZW1lbnRDb3JlQ29udGV4dC5JREVOVElUWTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDsgaSA8IG47IGkrKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0udXBkYXRlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fdXNlUmVuZGVyVG9UZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlbmRlckNvbnRleHQgPSByO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2NoaWxkcmVuKSB7XG4gICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW5baV0uX2hhc1VwZGF0ZXMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9jaGlsZHJlbltpXS51cGRhdGUoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gTWFrZSBzdXJlIHdlIGRvbid0IGxvc2UgdGhlICdpbmhlcml0ZWQnIHVwZGF0ZXMuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0uX3JlY2FsYyB8PSB0aGlzLl9wUmVjYWxjO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLnVwZGF0ZU91dE9mQm91bmRzKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9vbkFmdGVyVXBkYXRlKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fb25BZnRlclVwZGF0ZSh0aGlzLmVsZW1lbnQpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHRoaXMuY3R4LnVwZGF0ZVRyZWVPcmRlciA9PT0gLTEgfHwgdGhpcy5fdXBkYXRlVHJlZU9yZGVyID49IHRoaXMuY3R4LnVwZGF0ZVRyZWVPcmRlcikge1xuICAgICAgICAgICAgICAgIC8vIElmIG5ldyB0cmVlIG9yZGVyIGRvZXMgbm90IGludGVyZmVyZSB3aXRoIHRoZSBjdXJyZW50IChnYXBzIGFsbG93ZWQpIHRoZXJlJ3Mgbm8gbmVlZCB0byB0cmF2ZXJzZSB0aGUgYnJhbmNoLlxuICAgICAgICAgICAgICAgIHRoaXMuY3R4LnVwZGF0ZVRyZWVPcmRlciA9IC0xO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLnVwZGF0ZVRyZWVPcmRlcigpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuXG4gICAgX2FwcGx5UmVsYXRpdmVEaW1GdW5jcygpIHtcbiAgICAgICAgaWYgKHRoaXMuX29wdEZsYWdzICYgMSkge1xuICAgICAgICAgICAgY29uc3QgeCA9IHRoaXMuX2Z1bmNYKHRoaXMuX3BhcmVudC53KTtcbiAgICAgICAgICAgIGlmICh4ICE9PSB0aGlzLl94KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fbG9jYWxQeCArPSAoeCAtIHRoaXMuX3gpO1xuICAgICAgICAgICAgICAgIHRoaXMuX3ggPSB4O1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9vcHRGbGFncyAmIDIpIHtcbiAgICAgICAgICAgIGNvbnN0IHkgPSB0aGlzLl9mdW5jWSh0aGlzLl9wYXJlbnQuaCk7XG4gICAgICAgICAgICBpZiAoeSAhPT0gdGhpcy5feSkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2xvY2FsUHkgKz0gKHkgLSB0aGlzLl95KTtcbiAgICAgICAgICAgICAgICB0aGlzLl95ID0geTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBjaGFuZ2VkRGltcyA9IGZhbHNlO1xuICAgICAgICBpZiAodGhpcy5fb3B0RmxhZ3MgJiA0KSB7XG4gICAgICAgICAgICBjb25zdCB3ID0gdGhpcy5fZnVuY1codGhpcy5fcGFyZW50LncpO1xuICAgICAgICAgICAgaWYgKHcgIT09IHRoaXMuX3cpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl93ID0gdztcbiAgICAgICAgICAgICAgICBjaGFuZ2VkRGltcyA9IHRydWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX29wdEZsYWdzICYgOCkge1xuICAgICAgICAgICAgY29uc3QgaCA9IHRoaXMuX2Z1bmNIKHRoaXMuX3BhcmVudC5oKTtcbiAgICAgICAgICAgIGlmIChoICE9PSB0aGlzLl9oKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5faCA9IGg7XG4gICAgICAgICAgICAgICAgY2hhbmdlZERpbXMgPSB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgaWYgKGNoYW5nZWREaW1zKSB7XG4gICAgICAgICAgICAv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aGlzLl9jaGlsZHJlbltpXS51cGRhdGVPdXRPZkJvdW5kcygpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHVwZGF0ZVRyZWVPcmRlcigpIHtcbiAgICAgICAgaWYgKHRoaXMuX2xvY2FsQWxwaGEgJiYgKHRoaXMuX291dE9mQm91bmRzICE9PSAyKSkge1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlVHJlZU9yZGVyID0gdGhpcy5jdHgudXBkYXRlVHJlZU9yZGVyKys7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwLCBuID0gdGhpcy5fY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2NoaWxkcmVuW2ldLnVwZGF0ZVRyZWVPcmRlcigpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIF9yZW5kZXJTaW1wbGUoKSB7XG4gICAgICAgIHRoaXMuX2hhc1JlbmRlclVwZGF0ZXMgPSAwO1xuXG4gICAgICAgIGlmICh0aGlzLl96U29ydCkge1xuICAgICAgICAgICAgdGhpcy5zb3J0WkluZGV4ZWRDaGlsZHJlbigpO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuX291dE9mQm91bmRzIDwgMiAmJiB0aGlzLl9yZW5kZXJDb250ZXh0LmFscGhhKSB7XG4gICAgICAgICAgICBsZXQgcmVuZGVyU3RhdGUgPSB0aGlzLnJlbmRlclN0YXRlO1xuXG4gICAgICAgICAgICBpZiAoKHRoaXMuX291dE9mQm91bmRzID09PSAwKSAmJiB0aGlzLl9kaXNwbGF5ZWRUZXh0dXJlU291cmNlKSB7XG4gICAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0U2hhZGVyKHRoaXMuYWN0aXZlU2hhZGVyLCB0aGlzLl9zaGFkZXJPd25lcik7XG4gICAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0U2Npc3Nvcih0aGlzLl9zY2lzc29yKTtcbiAgICAgICAgICAgICAgICB0aGlzLnJlbmRlclN0YXRlLmFkZFF1YWQodGhpcyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIEFsc28gYWRkIGNoaWxkcmVuIHRvIHRoZSBWQk8uXG4gICAgICAgICAgICBpZiAodGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fekNvbnRleHRVc2FnZSkge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuW2ldLnJlbmRlcigpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9jaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbltpXS5fekluZGV4ID09PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gSWYgekluZGV4IGlzIHNldCwgdGhpcyBpdGVtIGFscmVhZHkgYmVsb25ncyB0byBhIHpJbmRleGVkQ2hpbGRyZW4gYXJyYXkgaW4gb25lIG9mIHRoZSBhbmNlc3RvcnMuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0ucmVuZGVyKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgfVxuIC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0dXJlSW5mbztcbiAgICAgICAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fdyA9PT0gMCB8fCB0aGlzLl9oID09PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIElnbm9yZSB0aGlzIGJyYW5jaCBhbmQgZG9uJ3QgZHJhdyBhbnl0aGluZy5cbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoIXRoaXMuX3RleHR1cml6ZXIuaGFzUmVuZGVyVGV4dHVyZSgpIHx8IChoYXNSZW5kZXJVcGRhdGVzID49IDMpKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFRlbGwgdGhlIHJlbmRlcmVyIHdlJ3JlIHJlbmRlcmluZyBhIHJlbmRlclRvVGV4dHVyZSBlbGVtZW50IGluIHRoaXMgZnJhbWVcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jdHgucmVuZGVyVG9UZXh0dXJlQ291bnQrKztcbiAgICAgICAgICAgICAgICAgICAgLy8gU3dpdGNoIHRvIGRlZmF1bHQgc2hhZGVyIGZvciBidWlsZGluZyB1cCB0aGUgcmVuZGVyIHRleHR1cmUuXG4gICAgICAgICAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFNoYWRlcihyZW5kZXJTdGF0ZS5kZWZhdWx0U2hhZGVyLCB0aGlzKTtcblxuICAgICAgICAgICAgICAgICAgICBwcmV2UmVuZGVyVGV4dHVyZUluZm8gPSByZW5kZXJTdGF0ZS5yZW5kZXJUZXh0dXJlSW5mbztcblxuICAgICAgICAgICAgICAgICAgICByZW5kZXJUZXh0dXJlSW5mbyA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIG5hdGl2ZVRleHR1cmU6IG51bGwsXG4gICAgICAgICAgICAgICAgICAgICAgICBvZmZzZXQ6IDAsICAvLyBTZXQgYnkgQ29yZVJlbmRlclN0YXRlLlxuICAgICAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5fdyxcbiAgICAgICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuX2gsXG4gICAgICAgICAgICAgICAgICAgICAgICBlbXB0eTogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGNsZWFyZWQ6IGZhbHNlLFxuICAgICAgICAgICAgICAgICAgICAgICAgaWdub3JlOiBmYWxzZSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGNhY2hlOiBmYWxzZVxuICAgICAgICAgICAgICAgICAgICB9O1xuXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl90ZXh0dXJpemVyLmhhc1Jlc3VsdFRleHR1cmUoKSB8fCAoIXJlbmRlclN0YXRlLmlzQ2FjaGluZ1RleHR1cml6ZXIgJiYgKGhhc1JlbmRlclVwZGF0ZXMgPCAzKSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8qKlxuICAgICAgICAgICAgICAgICAgICAgICAgICogV2UgZG9uJ3QgYWx3YXlzIGNhY2hlIHJlbmRlciB0ZXh0dXJlcy5cbiAgICAgICAgICAgICAgICAgICAgICAgICAqXG4gICAgICAgICAgICAgICAgICAgICAgICAgKiBUaGUgcnVsZSBpcywgdGhhdCBjYWNoaW5nIGZvciBhIHNwZWNpZmljIHJlbmRlciB0ZXh0dXJlIGlzIG9ubHkgZW5hYmxlZCBpZjpcbiAgICAgICAgICAgICAgICAgICAgICAgICAqIC0gVGhlcmUgaXMgYSByZXN1bHQgdGV4dHVyZSB0byBiZSB1cGRhdGVkLlxuICAgICAgICAgICAgICAgICAgICAgICAgICogLSBUaGVyZSB3ZXJlIG5vIHJlbmRlciB1cGRhdGVzIC13aXRoaW4gdGhlIGNvbnRlbnRzLSBzaW5jZSBsYXN0IGZyYW1lIChFbGVtZW50Q29yZS5oYXNSZW5kZXJVcGRhdGVzIDwgMylcbiAgICAgICAgICAgICAgICAgICAgICAgICAqIC0gQU5EIHRoZXJlIGFyZSBubyBhbmNlc3RvcnMgdGhhdCBhcmUgYmVpbmcgY2FjaGVkIGR1cmluZyB0aGlzIGZyYW1lIChDb3JlUmVuZGVyU3RhdGUuaXNDYWNoaW5nVGV4dHVyaXplcilcbiAgICAgICAgICAgICAgICAgICAgICAgICAqICAgSWYgYW4gYW5jZXN0b3IgaXMgY2FjaGVkIGFueXdheSwgaXQncyBwcm9iYWJseSBub3QgbmVjZXNzYXJ5IHRvIGtlZXAgZGVlcGVyIGNhY2hlcy4gSWYgdGhlIHRvcCBsZXZlbCBpcyB0b1xuICAgICAgICAgICAgICAgICAgICAgICAgICogICBjaGFuZ2Ugd2hpbGUgYSBsb3dlciBvbmUgaXMgbm90LCB0aGF0IGxvd2VyIGxldmVsIHdpbGwgYmUgY2FjaGVkIGluc3RlYWQuXG4gICAgICAgICAgICAgICAgICAgICAgICAgKlxuICAgICAgICAgICAgICAgICAgICAgICAgICogSW4gY2FzZSBvZiB0aGUgZmFzdCBibHVyIGVsZW1lbnQsIHRoaXMgcHJldmVudHMgaGF2aW5nIHRvIGNhY2hlIGFsbCBibHVyIGxldmVscyBhbmQgc3RhZ2VzLCBzYXZpbmcgYSBodWdlIGFtb3VudFxuICAgICAgICAgICAgICAgICAgICAgICAgICogb2YgR1BVIG1lbW9yeSFcbiAgICAgICAgICAgICAgICAgICAgICAgICAqXG4gICAgICAgICAgICAgICAgICAgICAgICAgKiBFc3BlY2lhbGx5IHdoZW4gdXNpbmcgbXVsdGlwbGUgc3RhY2tlZCBsYXllcnMgb2YgdGhlIHNhbWUgZGltZW5zaW9ucyB0aGF0IGFyZSBSVFQgdGhpcyB3aWxsIGhhdmUgYSB2ZXJ5XG4gICAgICAgICAgICAgICAgICAgICAgICAgKiBub3RpY2FibGUgZWZmZWN0IG9uIHBlcmZvcm1hbmNlIGFzIGxlc3MgcmVuZGVyIHRleHR1cmVzIG5lZWQgdG8gYmUgYWxsb2NhdGVkLlxuICAgICAgICAgICAgICAgICAgICAgICAgICovXG4gICAgICAgICAgICAgICAgICAgICAgICByZW5kZXJUZXh0dXJlSW5mby5jYWNoZSA9IHRydWU7XG4gICAgICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5pc0NhY2hpbmdUZXh0dXJpemVyID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIGlmICghdGhpcy5fdGV4dHVyaXplci5oYXNSZXN1bHRUZXh0dXJlKCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFdlIGNhbiBhbHJlYWR5IHJlbGVhc2UgdGhlIGN1cnJlbnQgdGV4dHVyZSB0byB0aGUgcG9vbCwgYXMgaXQgd2lsbCBiZSByZWJ1aWxkIGFueXdheS5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIEluIGNhc2Ugb2YgbXVsdGlwbGUgbGF5ZXJzIG9mICdmaWx0ZXJpbmcnLCB0aGlzIG1heSBzYXZlIHVzIGZyb20gaGF2aW5nIHRvIGNyZWF0ZSBvbmVcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vICByZW5kZXItdG8tdGV4dHVyZSBsYXllci5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIE5vdGljZSB0aGF0IHdlIGRvbid0IGRvIHRoaXMgd2hlbiB0aGVyZSBpcyBhIHJlc3VsdCB0ZXh0dXJlLCBhcyBhbnkgb3RoZXIgZWxlbWVudCBtYXkgcmVseSBvblxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gIHRoYXQgcmVzdWx0IHRleHR1cmUgYmVpbmcgZmlsbGVkLlxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci5yZWxlYXNlUmVuZGVyVGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0UmVuZGVyVGV4dHVyZUluZm8ocmVuZGVyVGV4dHVyZUluZm8pO1xuICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRTY2lzc29yKG51bGwpO1xuXG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9kaXNwbGF5ZWRUZXh0dXJlU291cmNlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBsZXQgciA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG5cbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFVzZSBhbiBpZGVudGl0eSBjb250ZXh0IGZvciBkcmF3aW5nIHRoZSBkaXNwbGF5ZWQgdGV4dHVyZSB0byB0aGUgcmVuZGVyIHRleHR1cmUuXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gRWxlbWVudENvcmVDb250ZXh0LklERU5USVRZO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBBZGQgZGlzcGxheWVkIHRleHR1cmUgc291cmNlIGluIGxvY2FsIGNvb3JkaW5hdGVzLlxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5yZW5kZXJTdGF0ZS5hZGRRdWFkKHRoaXMpO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZW5kZXJDb250ZXh0ID0gcjtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIG11c3RSZW5kZXJDaGlsZHJlbiA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgaWYgKCh0aGlzLl9vdXRPZkJvdW5kcyA9PT0gMCkgJiYgdGhpcy5fZGlzcGxheWVkVGV4dHVyZVNvdXJjZSkge1xuICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRTaGFkZXIodGhpcy5hY3RpdmVTaGFkZXIsIHRoaXMuX3NoYWRlck93bmVyKTtcbiAgICAgICAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0U2Npc3Nvcih0aGlzLl9zY2lzc29yKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5yZW5kZXJTdGF0ZS5hZGRRdWFkKHRoaXMpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gQWxzbyBhZGQgY2hpbGRyZW4gdG8gdGhlIFZCTy5cbiAgICAgICAgICAgIGlmIChtdXN0UmVuZGVyQ2hpbGRyZW4gJiYgdGhpcy5fY2hpbGRyZW4pIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5fekNvbnRleHRVc2FnZSkge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbiA9IHRoaXMuX3pJbmRleGVkQ2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgaSsrKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuW2ldLnJlbmRlcigpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDAsIG4gPSB0aGlzLl9jaGlsZHJlbi5sZW5ndGg7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbltpXS5fekluZGV4ID09PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gSWYgekluZGV4IGlzIHNldCwgdGhpcyBpdGVtIGFscmVhZHkgYmVsb25ncyB0byBhIHpJbmRleGVkQ2hpbGRyZW4gYXJyYXkgaW4gb25lIG9mIHRoZSBhbmNlc3RvcnMuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0ucmVuZGVyKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICh0aGlzLl91c2VSZW5kZXJUb1RleHR1cmUpIHtcbiAgICAgICAgICAgICAgICBsZXQgdXBkYXRlUmVzdWx0VGV4dHVyZSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIGlmIChtdXN0UmVuZGVyQ2hpbGRyZW4pIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gRmluaXNoZWQgcmVmcmVzaGluZyByZW5kZXJUZXh0dXJlLlxuICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5maW5pc2hlZFJlbmRlclRleHR1cmUoKTtcblxuICAgICAgICAgICAgICAgICAgICAvLyBJZiBub3RoaW5nIHdhcyByZW5kZXJlZCwgd2Ugc3RvcmUgYSBmbGFnIGluIHRoZSB0ZXh0dXJpemVyIGFuZCBwcmV2ZW50IHVubmVjZXNzYXJ5XG4gICAgICAgICAgICAgICAgICAgIC8vICByZW5kZXItdG8tdGV4dHVyZSBhbmQgZmlsdGVyaW5nLlxuICAgICAgICAgICAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLmVtcHR5ID0gcmVuZGVyVGV4dHVyZUluZm8uZW1wdHk7XG5cbiAgICAgICAgICAgICAgICAgICAgaWYgKHJlbmRlclRleHR1cmVJbmZvLmVtcHR5KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBXZSBpZ25vcmUgZW1wdHkgcmVuZGVyIHRleHR1cmVzIGFuZCBkbyBub3QgZHJhdyB0aGUgZmluYWwgcXVhZC5cblxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gVGhlIGZvbGxvd2luZyBjbGVhbnMgdXAgbWVtb3J5IGFuZCBlbmZvcmNlcyB0aGF0IHRoZSByZXN1bHQgdGV4dHVyZSBpcyBhbHNvIGNsZWFyZWQuXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLnJlbGVhc2VSZW5kZXJUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAocmVuZGVyVGV4dHVyZUluZm8ubmF0aXZlVGV4dHVyZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgLy8gSWYgbmF0aXZlVGV4dHVyZSBpcyBzZXQsIHdlIGNhbiByZXVzZSB0aGF0IGRpcmVjdGx5IGluc3RlYWQgb2YgY3JlYXRpbmcgYSBuZXcgcmVuZGVyIHRleHR1cmUuXG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl90ZXh0dXJpemVyLnJldXNlVGV4dHVyZUFzUmVuZGVyVGV4dHVyZShyZW5kZXJUZXh0dXJlSW5mby5uYXRpdmVUZXh0dXJlKTtcblxuICAgICAgICAgICAgICAgICAgICAgICAgcmVuZGVyVGV4dHVyZUluZm8uaWdub3JlID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLl90ZXh0dXJpemVyLnJlbmRlclRleHR1cmVSZXVzZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBRdWFkIG9wZXJhdGlvbnMgbXVzdCBiZSB3cml0dGVuIHRvIGEgcmVuZGVyIHRleHR1cmUgYWN0dWFsbHkgb3duZWQuXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci5yZWxlYXNlUmVuZGVyVGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgLy8gSnVzdCBjcmVhdGUgdGhlIHJlbmRlciB0ZXh0dXJlLlxuICAgICAgICAgICAgICAgICAgICAgICAgcmVuZGVyVGV4dHVyZUluZm8ubmF0aXZlVGV4dHVyZSA9IHRoaXMuX3RleHR1cml6ZXIuZ2V0UmVuZGVyVGV4dHVyZSgpO1xuICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgLy8gUmVzdG9yZSB0aGUgcGFyZW50J3MgcmVuZGVyIHRleHR1cmUuXG4gICAgICAgICAgICAgICAgICAgIHJlbmRlclN0YXRlLnNldFJlbmRlclRleHR1cmVJbmZvKHByZXZSZW5kZXJUZXh0dXJlSW5mbyk7XG5cbiAgICAgICAgICAgICAgICAgICAgdXBkYXRlUmVzdWx0VGV4dHVyZSA9IHRydWU7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLl90ZXh0dXJpemVyLmVtcHR5KSB7XG4gICAgICAgICAgICAgICAgICAgIGxldCByZXN1bHRUZXh0dXJlID0gdGhpcy5fdGV4dHVyaXplci5nZXRSZXN1bHRUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgICAgIGlmICh1cGRhdGVSZXN1bHRUZXh0dXJlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAocmVzdWx0VGV4dHVyZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIExvZ2dpbmcgdGhlIHVwZGF0ZSBmcmFtZSBjYW4gYmUgaGFuZHkgZm9yIHVzZXJsYW5kLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdFRleHR1cmUudXBkYXRlID0gcmVuZGVyU3RhdGUuc3RhZ2UuZnJhbWVDb3VudGVyO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fdGV4dHVyaXplci51cGRhdGVSZXN1bHRUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICBpZiAoIXRoaXMuX3RleHR1cml6ZXIucmVuZGVyT2Zmc2NyZWVuKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBSZW5kZXIgcmVzdWx0IHRleHR1cmUgdG8gdGhlIGFjdHVhbCByZW5kZXIgdGFyZ2V0LlxuICAgICAgICAgICAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0U2hhZGVyKHRoaXMuYWN0aXZlU2hhZGVyLCB0aGlzLl9zaGFkZXJPd25lcik7XG4gICAgICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRTY2lzc29yKHRoaXMuX3NjaXNzb3IpO1xuXG4gICAgICAgICAgICAgICAgICAgICAgICAvLyBJZiBubyByZW5kZXIgdGV4dHVyZSBpbmZvIGlzIHNldCwgdGhlIGNhY2hlIGNhbiBiZSByZXVzZWQuXG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBjYWNoZSA9ICFyZW5kZXJUZXh0dXJlSW5mbyB8fCByZW5kZXJUZXh0dXJlSW5mby5jYWNoZTtcblxuICAgICAgICAgICAgICAgICAgICAgICAgcmVuZGVyU3RhdGUuc2V0VGV4dHVyaXplcih0aGlzLl90ZXh0dXJpemVyLCBjYWNoZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9zdGFzaFRleENvb3JkcygpO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCF0aGlzLl90ZXh0dXJpemVyLmNvbG9yaXplKSB0aGlzLl9zdGFzaENvbG9ycygpO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5yZW5kZXJTdGF0ZS5hZGRRdWFkKHRoaXMsIHRydWUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCF0aGlzLl90ZXh0dXJpemVyLmNvbG9yaXplKSB0aGlzLl91bnN0YXNoQ29sb3JzKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl91bnN0YXNoVGV4Q29vcmRzKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICByZW5kZXJTdGF0ZS5zZXRUZXh0dXJpemVyKG51bGwpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAocmVuZGVyVGV4dHVyZUluZm8gJiYgcmVuZGVyVGV4dHVyZUluZm8uY2FjaGUpIHtcbiAgICAgICAgICAgICAgICAvLyBBb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gICBjb25zdCBuID0gdGhpcy5fekluZGV4ZWRDaGlsZHJlbi5sZW5ndGg7XG4gICAgICAgIGxldCBwdHIgPSAwO1xuICAgICAgICBjb25zdCBhID0gdGhpcy5fekluZGV4ZWRDaGlsZHJlbjtcblxuICAgICAgICAvLyBOb3RpY2UgdGhhdCBpdGVtcyBtYXkgb2NjdXIgbXVsdGlwbGUgdGltZXMgZHVlIHRvIHotaW5kZXggY2hhbmdpbmcuXG4gICAgICAgIGNvbnN0IGIgPSBbXTtcbiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuOyBpKyspIHtcbiAgICAgICAgICAgIGlmIChhW2ldLl96UGFyZW50ID09PSB0aGlzKSB7XG4gICAgICAgICAgICAgICAgaWYgKGFbaV0uX3pJbmRleFJlc29ydCkge1xuICAgICAgICAgICAgICAgICAgICBiLnB1c2goYVtpXSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHB0ciAhPT0gaSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgYVtwdHJdID0gYVtpXTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBwdHIrKztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBjb25zdCBtID0gYi5sZW5ndGg7XG4gICAgICAgIGlmIChtKSB7XG4gICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IG07IGorKykge1xuICAgICAgICAgICAgICAgIGJbal0uX3pJbmRleFJlc29ydCA9IGZhbHNlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBiLnNvcnQoRWxlbWVudENvcmUuc29ydFpJbmRleGVkQ2hpbGRyZW4pO1xuICAgICAgICAgICAgY29uc3QgbiA9IHB0cjtcbiAgICAgICAgICAgIGlmICghbikge1xuICAgICAgICAgICAgICAgIHB0ciA9IDA7XG4gICAgICAgICAgICAgICAgbGV0IGogPSAwO1xuICAgICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICAgICAgYVtwdHIrK10gPSBiW2orK107XG4gICAgICAgICAgICAgICAgfSB3aGlsZSAoaiA8IG0pO1xuXG4gICAgICAgICAgICAgICAgaWYgKGEubGVuZ3RoID4gcHRyKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIFNsaWNlIG9sZCAodW5uZWNlc3NhcnkpIHBhcnQgb2ZmIGFycmF5LlxuICAgICAgICAgICAgICAgICAgICBhLnNwbGljZShwdHIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgYS5zcGxpY2Uobik7IC8vIFJlbW92ZSBpdGVtcyB0aGF0IHdlcmUgc29ydGVkIGluIGIgYXJyYXksIHNvIHRoYXQgd2UgY2FuIHNvcnQgYVxuKyAgICAgICAgICAgICAgIC8vIEJld2FyZSB0aGF0IHRoZSBmdW5jdGlvbiBwYXNzZWQgaGVyZSB0byBBcnJheS5zb3J0IG11c3QgYmUgc3RhYmxlXG4rICAgICAgICAgICAgICAgYS5zb3J0KEVsZW1lbnRDb3JlLnNvcnRaSW5kZXhlZENoaWxkcmVuKTsgLy8gTmVlZGVkIGJlY2F1c2UgaXRlbXMgd2l0aCBzYW1lIF96SW5kZXggbWF5IG5vdCBiZSBvcmRlcmVkIGJ5IF91cGRhdGVUcmVlT3JkZXJcbiAgICAgICAgICAgICAgICAvLyBNZXJnZS1zb3J0IGFycmF5cztcbiAgICAgICAgICAgICAgICBwdHIgPSAwO1xuICAgICAgICAgICAgICAgIGxldCBpID0gMDtcbiAgICAgICAgICAgICAgICBsZXQgaiA9IDA7XG4gICAgICAgICAgICAgICAgY29uc3QgbWVyZ2VSZXN1bHQgPSBbXTtcbiAgICAgICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IHYgPSAoYVtpXS5fekluZGV4ID09PSBiW2pdLl96SW5kZXggPyBhW2ldLl91cGRhdGVUcmVlT3JkZXIgLSBiW2pdLl91cGRhdGVUcmVlT3JkZXIgOiBhW2ldLl96SW5kZXggLSBiW2pdLl96SW5kZXgpO1xuXG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IGFkZCA9IHYgPiAwID8gYltqKytdIDogYVtpKytdO1xuXG4gICAgICAgICAgICAgICAgICAgIGlmIChwdHIgPT09IDAgfHwgKG1lcmdlUmVzdWx0W3B0ciAtIDFdICE9PSBhZGQpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBtZXJnZVJlc3VsdFtwdHIrK10gPSBhZGQ7XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICBpZiAoaSA+PSBuKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgYWRkID0gYltqKytdO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwdHIgPT09IDAgfHwgKG1lcmdlUmVzdWx0W3B0ciAtIDFdICE9PSBhZGQpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1lcmdlUmVzdWx0W3B0cisrXSA9IGFkZDtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlIChqIDwgbSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChqID49IG0pIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBhZGQgPSBhW2krK107XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHB0ciA9PT0gMCB8fCAobWVyZ2VSZXN1bHRbcHRyIC0gMV0gIT09IGFkZCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbWVyZ2VSZXN1bHRbcHRyKytdID0gYWRkO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGkgPCBuKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSB3aGlsZSAodHJ1ZSk7XG5cbiAgICAgICAgICAgICAgICB0aGlzLl96SW5kZXhlZENoaWxkcmVuID0gbWVyZ2VSZXN1bHQ7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAoYS5sZW5ndGggPiBwdHIpIHtcbiAgICAgICAgICAgICAgICAvLyBTbGljZSBvbGQgKHVubmVjZXNzYXJ5KSBwYXJ0IG9mZiBhcnJheS5cbiAgICAgICAgICAgICAgICBhLnNwbGljZShwdHIpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgdGhpcy5felNvcnQgPSBmYWxzZTtcbiAgICB9O1xuXG4gICAgZ2V0IGxvY2FsVGEoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9sb2NhbFRhO1xuICAgIH07XG5cbiAgICBnZXQgbG9jYWxUYigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2xvY2FsVGI7XG4gICAgfTtcblxuICAgIGdldCBsb2NhbFRjKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbG9jYWxUYztcbiAgICB9O1xuXG4gICAgZ2V0IGxvY2FsVGQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9sb2NhbFRkO1xuICAgIH07XG5cbiAgICBnZXQgZWxlbWVudCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2VsZW1lbnQ7XG4gICAgfVxuXG4gICAgZ2V0IHJlbmRlclVwZGF0ZXMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9oYXNSZW5kZXJVcGRhdGVzO1xuICAgIH1cblxuICAgIGdldCB0ZXh0dXJpemVyKCkge1xuICAgICAgICBpZiAoIXRoaXMuX3RleHR1cml6ZXIpIHtcbiAgICAgICAgICAgIHRoaXMuX3RleHR1cml6ZXIgPSBuZXcgRWxlbWVudFRleHR1cml6ZXIodGhpcyk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRoaXMuX3RleHR1cml6ZXI7XG4gICAgfVxuXG4gICAgZ2V0Q29ybmVyUG9pbnRzKCkge1xuICAgICAgICBsZXQgdyA9IHRoaXMuX3dvcmxkQ29udGV4dDtcblxuICAgICAgICByZXR1cm4gW1xuICAgICAgICAgICAgdy5weCxcbiAgICAgICAgICAgIHcucHksXG4gICAgICAgICAgICB3LnB4ICsgdGhpcy5fdyAqIHcudGEsXG4gICAgICAgICAgICB3LnB5ICsgdGhpcy5fdyAqIHcudGMsXG4gICAgICAgICAgICB3LnB4ICsgdGhpcy5fdyAqIHcudGEgKyB0aGlzLl9oICogdy50YixcbiAgICAgICAgICAgIHcucHkgKyB0aGlzLl93ICogdy50YyArIHRoaXMuX2ggKiB3LnRkLFxuICAgICAgICAgICAgdy5weCArIHRoaXMuX2ggKiB3LnRiLFxuICAgICAgICAgICAgdy5weSArIHRoaXMuX2ggKiB3LnRkXG4gICAgICAgIF07XG4gICAgfTtcblxuICAgIGdldFJlbmRlclRleHR1cmVDb29yZHMocmVsWCwgcmVsWSkge1xuICAgICAgICBsZXQgciA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgICAgIHJldHVybiBbXG4gICAgICAgICAgICByLnB4ICsgci50YSAqIHJlbFggKyByLnRiICogcmVsWSxcbiAgICAgICAgICAgIHIucHkgKyByLnRjICogcmVsWCArIHIudGQgKiByZWxZXG4gICAgICAgIF07XG4gICAgfVxuXG4gICAgZ2V0QWJzb2x1dGVDb29yZHMocmVsWCwgcmVsWSkge1xuICAgICAgICBsZXQgdyA9IHRoaXMuX3JlbmRlckNvbnRleHQ7XG4gICAgICAgIHJldHVybiBbXG4gICAgICAgICAgICB3LnB4ICsgdy50YSAqIHJlbFggKyB3LnRiICogcmVsWSxcbiAgICAgICAgICAgIHcucHkgKyB3LnRjICogcmVsWCArIHcudGQgKiByZWxZXG4gICAgICAgIF07XG4gICAgfVxuXG4gICAgY29sbGVjdEF0Q29vcmQoeCwgeSwgY2hpbGRyZW4pIHtcbiAgICAgICAgLy8gcmV0dXJuIHdoZW4gYnJhbmNoIGlzIGhpZGRlblxuICAgICAgICBpZiAodGhpcy5fcmVuZGVyQ29udGV4dC5hbHBoYSA9PT0gMCkge1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHRoaXMuaW5Cb3VuZCh4LCB5KSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX3NjaXNzb3IpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5pblNjaXNzb3IoKSkge1xuICAgICAgICAgICAgICAgICAgICBjaGlsZHJlbi5wdXNoKHRoaXMpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgY2hpbGRyZW4ucHVzaCh0aGlzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmICh0aGlzLl9jaGlsZHJlbikge1xuICAgICAgICAgICAgY29uc3QgaiA9IHRoaXMuX2NoaWxkcmVuLmxlbmd0aDtcbiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgajsgaSsrKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fY2hpbGRyZW5baV0uY29sbGVjdEF0Q29vcmQoeCwgeSwgY2hpbGRyZW4pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIGNoaWxkcmVuLnNvcnQoRWxlbWVudENvcmUuc29ydFpJbmRleGVkQ2hpbGRyZW4pO1xuICAgIH1cblxuICAgIGluQm91bmQodHgsIHR5KSB7XG4gICAgICAgIGNvbnN0IGMgPSB0aGlzLmdldENvcm5l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CBkZWxheShwYXVzZSlcbiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgcGhyYXNlID09PSAnc3RyaW5nJyAmJiBwaHJhc2UubGVuZ3RoKSB7XG4gICAgICAgICAgLy8gU3BlYWsgaXRcbiAgICAgICAgICBjb25zdCB0b3RhbFJldHJpZXMgPSAzXG4gICAgICAgICAgbGV0IHJldHJpZXNMZWZ0ID0gdG90YWxSZXRyaWVzXG4gICAgICAgICAgd2hpbGUgKGFjdGl2ZSAmJiByZXRyaWVzTGVmdCA+IDApIHtcbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgIGF3YWl0IHNwZWFrKHBocmFzZSwgdXR0ZXJhbmNlcywgbGFuZylcbiAgICAgICAgICAgICAgcmV0cmllc0xlZnQgPSAwXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgICAgICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBuby11bmRlZlxuICAgICAgICAgICAgICBpZiAoZSBpbnN0YW5jZW9mIFNwZWVjaFN5bnRoZXNpc0Vycm9yRXZlbnQpIHtcbiAgICAgICAgICAgICAgICBpZiAoZS5lcnJvciA9PT0gJ25ldHdvcmsnKSB7XG4gICAgICAgICAgICAgICAgICByZXRyaWVzTGVmdC0tXG4gICAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oYFNwZWVjaCBzeW50aGVzaXMgbmV0d29yayBlcnJvci4gUmV0cmllcyBsZWZ0OiAke3JldHJpZXNMZWZ0fWApXG4gICAgICAgICAgICAgICAgICBhd2FpdCBkZWxheSg1MDAgKiAodG90YWxSZXRyaWVzIC0gcmV0cmllc0xlZnQpKVxuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoZS5lcnJvciA9PT0gJ2NhbmNlbGVkJyB8fCBlLmVycm9yID09PSAnaW50ZXJydXB0ZWQnKSB7XG4gICAgICAgICAgICAgICAgICAvLyBDYW5jZWwgb3IgaW50ZXJydXB0IGVycm9yIChpZ25vcmUpXG4gICAgICAgICAgICAgICAgICByZXRyaWVzTGVmdCA9IDBcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBTcGVlY2hTeW50aGVzaXNFcnJvckV2ZW50OiAke2UuZXJyb3J9YClcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgZVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBwaHJhc2UgPT09ICdmdW5jdGlvbicpIHtcbiAgICAgICAgICBjb25zdCBzZXJpZXNSZXN1bHQgPSBzcGVha1NlcmllcyhwaHJhc2UoKSwgbGFuZywgZmFsc2UpXG4gICAgICAgICAgbmVzdGVkU2VyaWVzUmVzdWx0cy5wdXNoKHNlcmllc1Jlc3VsdClcbiAgICAgICAgICBhd2FpdCBzZXJpZXNSZXN1bHQuc2VyaWVzXG4gICAgICAgIH0gZWxzZSBpZiAoQXJyYXkuaXNBcnJheShwaHJhc2UpKSB7XG4gICAgICAgICAgLy8gU3BlYWsgaXQgKHJlY3Vyc2l2ZWx5KVxuICAgICAgICAgIGNvbnN0IHNlcmllc1Jlc3VsdCA9IHNwZWFrU2VyaWVzKHBocmFzZSwgbGFuZywgZmFsc2UpXG4gICAgICAgICAgbmVzdGVkU2VyaWVzUmVzdWx0cy5wdXNoKHNlcmllc1Jlc3VsdClcbiAgICAgICAgICBhd2FpdCBzZXJpZXNSZXN1bHQuc2VyaWVzXG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9IGZpbmFsbHkge1xuICAgICAgYWN0aXZlID0gZmFsc2VcbiAgICB9XG4gIH0pKClcbiAgcmV0dXJuIHtcbiAgICBzZXJpZXM6IHNlcmllc0NoYWluLFxuICAgIGdldCBhY3RpdmUoKSB7XG4gICAgICByZXR1cm4gYWN0aXZlXG4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AgICAgICAgIHJldHVybiBQcm9taXNlLnJlc29sdmUoKVxuICAgICAgICB9LFxuICAgICAgfSlcbiAgICB9XG4gICAgY29uc3VtZXIgPSB2aWRlb1BsYXllckNvbnN1bWVyXG5cbiAgICByZXR1cm4gbmV3IFByb21pc2UocmVzb2x2ZSA9PiB7XG4gICAgICBMb2cuaW5mbygnQWQnLCAnU3RhcnRpbmcgc2Vzc2lvbicpXG4gICAgICBnZXRBZHMoY29uZmlnKS50aGVuKGFkcyA9PiB7XG4gICAgICAgIExvZy5pbmZvKCdBZCcsICdBUEkgcmVzdWx0JywgYWRzKVxuICAgICAgICByZXNvbHZlKHtcbiAgICAgICAgICBwcmVyb2xscygpIHtcbiAgICAgICAgICAgIGlmIChhZHMucHJlcm9sbCkge1xuICAgICAgICAgICAgICBzdGF0ZS5hY3RpdmUgPSB0cnVlXG4gICAgICAgICAgICAgIGZpcmVPbkNvbnN1bWVyKCdQcmVyb2xsU2xvdEltcHJlc3Npb24nLCBhZHMpXG4gICAgICAgICAgICAgIHNlbmRCZWFjb24oYWRzLnByZXJvbGwuY2FsbGJhY2tzLCAnc2xvdEltcHJlc3Npb24nKVxuICAgICAgICAgICAgICByZXR1cm4gcGxheVNsb3QoYWRzLnByZXJvbGwuYWRzKS50aGVuKCgpID0+IHtcbiAgICAgICAgICAgICAgICBmaXJlT25Db25zdW1lcignUHJlcm9sbFNsb3RFbmQnLCBhZHMpXG4gICAgICAgICAgICAgICAgc2VuZEJlYWNvbihhZHMucHJlcm9sbC5jYWxsYmFja3MsICdzbG90RW5kJylcbiAgICAgICAgICAgICAgICBzdGF0ZS5hY3RpdmUgPSBmYWxzZVxuICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSgpXG4gICAgICAgICAgfSxcbiAgICAgICAgICBtaWRyb2xscygpIHtcbiAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlc29sdmUoKVxuICAgICAgIC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2lvbicsIHRoaXMuY29uZmlnLnZlcnNpb24pXG4gICAgICAgICAgTG9nLmluZm8oJ1NESyB2ZXJzaW9uJywgcGFja2FnZUluZm8udmVyc2lvbilcblxuICAgICAgICAgIGlmIChwbGF0Zm9ybVNldHRpbmdzLnNob3dWZXJzaW9uKSB7XG4gICAgICAgICAgICB0aGlzLmNoaWxkTGlzdC5hKHtcbiAgICAgICAgICAgICAgcmVmOiAnVmVyc2lvbkxhYmVsJyxcbiAgICAgICAgICAgICAgdHlwZTogVmVyc2lvbkxhYmVsLFxuICAgICAgICAgICAgICB2ZXJzaW9uOiB0aGlzLmNvbmZpZy52ZXJzaW9uLFxuICAgICAgICAgICAgICBzZGtWZXJzaW9uOiBwYWNrYWdlSW5mby52ZXJzaW9uLFxuICAgICAgICAgICAgICB6SW5kZXg6IDEsXG4gICAgICAgICAgICB9KVxuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChwbGF0Zm9ybVNldHRpbmdzLnNob3dGcHMpIHtcbiAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmEoe1xuICAgICAgICAgICAgICByZWY6ICdGcHNDb3VudGVyJyxcbiAgICAgICAgICAgICAgdHlwZTogRnBzQ291bnRlcixcbiAgICAgICAgICAgICAgekluZGV4OiAxLFxuICAgICAgICAgICAgfSlcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBzdXBlci5fc2V0dXAoKVxuICAgICAgICB9KVxuICAgICAgICAuY2F0Y2goY29uc29sZS5lcnJvcilcbiAgICB9XG5cbiAgICBfaGFuZGxlQmFjaygpIHtcbiAgICAgIHRoaXMuY2xvc2VBcHAoKVxuICAgIH1cblxuICAgIF9oYW5kbGVFeGl0KCkge1xuICAgICAgdGhpcy5jbG9zZUFwcCgpXG4gICAgfVxuXG4gICAgY2xvc2VBcHAoKSB7XG4gICAgICBMb2cuaW5mbygnU2lnbmFsaW5nIEFwcCBDbG9zZScpXG5cbiAgICAgIGlmIChwbGF0Zm9ybVNldHRpbmdzLm9u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XG4gIH0gZWxzZSBpZiAoMzAwIDw9IGggJiYgaCA8IDM2MCkge1xuICAgIHIgPSBjXG4gICAgYiA9IHhcbiAgfVxuXG4gIHIgPSBNYXRoLnJvdW5kKChyICsgbSkgKiAyNTUuMClcbiAgZyA9IE1hdGgucm91bmQoKGcgKyBtKSAqIDI1NS4wKVxuICBiID0gTWF0aC5yb3VuZCgoYiArIG0pICogMjU1LjApXG4gIHJldHVybiBnZXRBcmdiTnVtYmVyKFtyLCBnLCBiLCBjb2xvci5hICogMjU1XSlcbn1cblxuZXhwb3J0IGNvbnN0IGFyZ2JUb0hTTEEgPSBhcmdiID0+IHtcbiAgY29uc3QgY29sID0gZ2V0UmdiYUNvbXBvbmVudHMoYXJnYilcbiAgY29uc3QgciA9IGNvbC5yIC8gMjU1XG4gIGNvbnN0IGcgPSBjb2wuZyAvIDI1NVxuICBjb25zdCBiID0gY29sLmIgLyAyNTVcblxuICBjb25zdCBtYXggPSBNYXRoLm1heChyLCBnLCBiKVxuICBjb25zdCBtaW4gPSBNYXRoLm1pbihyLCBnLCBiKVxuXG4gIGxldCBoID0gMFxuICBsZXQgcyA9IDBcbiAgY29uc3QgbCA9IChtaW4gKyBtYXgpICogMC41XG4gIGlmIChsID4gMCkge1xuICAgIGNvbnN0IG1heE1pbiA9IG1heCAtIG1pblxuICAgIGlmIChtYXhNaW4gPiAwKSB7XG4gICAgICBjb25zdCByMiA9IChtYXggLSByKSAvIG1heE1pblxuICAgICAgY29uc3QgZzIgPSAobWF4IC0gZykgLyBtYXhNaW5cbiAgICAgIGNvbnN0IGIyID0gKG1heCAtIGIpIC8gbWF4TWluXG4gICAgICBpZiAobCA8IDAuNSkge1xuICAgICAgICBzID0gbWF4ICsgbWluXG4gICAgICB9IGVsc2Uge1xuICAgICAgICBzID0gMiAtIG1heCAtIG1pblxuICAgICAgfVxuXG4gICAgICBpZiAociA9PT0gbWF4ICYmIGcgPT09IG1pbikge1xuICAgICAgICBoID0gNS4wICsgYjJcbiAgICA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pbiArIG1pbk1heEZyYWN0XG4gICAgY29uc3QgbWlkMiA9IG1heCAtIG1pbk1heEZyYWN0XG5cbiAgICBpZiAoc2V4dGFudCA9PT0gMCkge1xuICAgICAgciA9IG1heFxuICAgICAgZyA9IG1pZDFcbiAgICAgIGIgPSBtaW5cbiAgICB9XG4gICAgaWYgKHNleHRhbnQgPT09IDEpIHtcbiAgICAgIHIgPSBtaWQyXG4gICAgICBnID0gbWF4XG4gICAgICBiID0gbWluXG4gICAgfVxuICAgIGlmIChzZXh0YW50ID09PSAyKSB7XG4gICAgICByID0gbWluXG4gICAgICBnID0gbWF4XG4gICAgICBiID0gbWlkMVxuICAgIH1cbiAgICBpZiAoc2V4dGFudCA9PT0gMykge1xuICAgICAgciA9IG1pblxuICAgICAgZyA9IG1pZDJcbiAgICAgIGIgPSBtYXhcbiAgICB9XG4gICAgaWYgKHNleHRhbnQgPT09IDQpIHtcbiAgICAgIHIgPSBtaWQxXG4gICAgICBnID0gbWluXG4gICAgICBiID0gbWF4XG4gICAgfVxuICAgIGlmIChzZXh0YW50ID09PSA1KSB7XG4gICAgICByID0gbWF4XG4gICAgICBnID0gbWluXG4gICAgICBiID0gbWlkMlxuICAgIH1cbiAgfVxuICByZXR1cm4gZ2V0QXJnYk51bWJlcihbTWF0aC5mbG9vcihyICogMjU1KSwgTWF0aC5mbG9vcihnICogMjU1KSwgTWF0aC5mbG9vcihiICogMjU1KSwgaHNsYS5hXSlcbn1cbiIsIi8qXG4gKiBJZiBub3Qgc3RhdGVkIG90aGVyd2lzZSBpbiB0aGlzIGZpbGUgb3IgdGhpcyBjb21wb25lbnQncyBMSUNFTlNFIGZpbGUgdGhlXG4gKiBmb2xsb3dpbmcgY29weXJpZ2h0IGFuZCBsaWNlbnNlcyBhcHBseTpcbiAqXG4gKiBDb3B5cmlnaHQgMjAyMCBNZXRyb2xvZ2ljYWxcbiAqXG4gKiBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcn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aW5nLlRvb2xzLmdldFJvdW5kUmVjdCg4MCwgODAsIDQwKSxcbiAgICAgIGg6IDgwLFxuICAgICAgdzogODAsXG4gICAgICB4OiAxMDAsXG4gICAgICB5OiAxMDAsXG4gICAgICBtb3VudDogMSxcbiAgICAgIEJhY2tncm91bmQ6IHtcbiAgICAgICAgeDogMyxcbiAgICAgICAgeTogMyxcbiAgICAgICAgdGV4dHVyZTogTGlnaHRuaW5nLlRvb2xzLmdldFJvdW5kUmVjdCg3MiwgNzIsIDM2KSxcbiAgICAgICAgY29sb3I6IDB4ZmYwMDgwMDAsXG4gICAgICB9LFxuICAgICAgQ291bnRlcjoge1xuICAgICAgICB3OiB3ID0+IHcsXG4gICAgICAgIGg6IGggPT4gaCxcbiAgICAgICAgeTogMTAsXG4gICAgICAgIHRleHQ6IHtcbiAgICAgICAgICBmb250U2l6ZTogMzIsXG4gICAgICAgICAgdGV4dEFsaWduOiAnY2VudGVyJyxcbiAgICAgICAgfSxcbiAgICAgIH0sXG4gICAgICBUZXh0OiB7XG4gICAgICAgIHc6IHcgPT4gdyxcbiAgICAgICAgaDogaCA9PiBoLFxuICAgICAgICB5OiA0OCxcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIGZvbnRTaXplOiAxNSxcbiAgICAgICAgICB0ZXh0QWxpZ246ICdjZW50ZXInLFxuICAgICAgICAgIHRleHQ6ICdGUFMnLFxuICAgICAgICB9LFxuICAgICAgfSxcbiAgICB9XG4gIH1cblxuICBfc2V0dXAoKSB7XG4gICAgdGhpcy5jb25maWcgPSB7XG4gICAgICAuLi57XG4gICAgICAgIGxvZzogZmFsc2UsXG4gICAgICAgIGludGVydmFsOiA1MDAsXG4gICAgICAgIHRocmVzaG9sZDogMSxcbiAgICAgIH0sXG4gICAgICAuLi5TZXR0aW5ncy5nZXQoJ3BsYXRmb3JtJywgJ3Nob3dGcHMnKSxcbiAgICB9XG5cbiAgICB0aGlzLmZwcyA9IDBcbiAgICB0aGlzLmxhc3RGcHMgPS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Gxhbmd1YWdlXG4gICAgICAgICAgICAgIC50aGVuKGxhbmcgPT5cbiAgICAgICAgICAgICAgICBzZXRMYW5ndWFnZShsYW5nKVxuICAgICAgICAgICAgICAgICAgLnRoZW4ocmVzb2x2ZSlcbiAgICAgICAgICAgICAgICAgIC5jYXRjaChyZWplY3QpXG4gICAgICAgICAgICAgIClcbiAgICAgICAgICAgICAgLmNhdGNoKGUgPT4ge1xuICAgICAgICAgICAgICAgIExvZy5lcnJvcihlKVxuICAgICAgICAgICAgICAgIHJlamVjdChlKVxuICAgICAgICAgICAgICB9KVxuICAgICAgICAgIDogc2V0TGFuZ3VhZ2UobGFuZ3VhZ2UpXG4gICAgICAgICAgICAgIC50aGVuKHJlc29sdmUpXG4gICAgICAgICAgICAgIC5jYXRjaChyZWplY3QpXG4gICAgICB9KVxuICAgICAgLmNhdGNoKCgpID0+IHtcbiAgICAgICAgY29uc3QgZXJyb3IgPSAnTGFuZ3VhZ2UgZmlsZSAnICsgZmlsZSArICcgbm90IGZvdW5kJ1xuICAgICAgICBMb2cuZXJyb3IoZXJyb3IpXG4gICAgICAgIHJlamVjdChlcnJvcilcbiAgICAgIH0pXG4gIH0pXG59XG5cbmNvbnN0IHNldFRyYW5zbGF0aW9ucyA9IG9iaiA9PiB7XG4gIGlmICgnbWV0YScgaW4gb2JqKSB7XG4gICAgbWV0YSA9IHsgLi4ub2JqLm1ldGEgfVxuICAgIGRlbGV0ZSBvYmoubWV0YVxuICB9XG4gIHRyYW5zbGF0aW9ucyA9IG9ialxufVxuXG5jb25zdCBnZXRMYW5ndWFnZSA9ICgpID0+IHtcbiAgcmV0dXJuIGxhbmd1YWdlXG59XG5cbmNvbnN0IHNldExhbmd1YWdlID0gbG5nID0+IHtcbiAgbGFuZ3VhZ2UgPSBudWxsXG4gIGRpY3Rpb25hcnkgPSBudWxsXG5cbiAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICBpZiAobG5nIGluIHR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cbiAgICAgICAgLy8gaW4gZnV0dXJlIHNkayByZWxlYXNlXG4gICAgICAgIGlmIChTZXR0aW5ncy5nZXQoJ2FwcCcsICdobHMnKSkge1xuICAgICAgICAgIGlmICghd2luZG93Lkhscykge1xuICAgICAgICAgICAgd2luZG93LkhscyA9IGNsYXNzIEhscyB7XG4gICAgICAgICAgICAgIHN0YXRpYyBpc1N1cHBvcnRlZCgpIHtcbiAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oJ2hscy1saWdodCBub3QgaW5jbHVkZWQnKVxuICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmICh3aW5kb3cuSGxzLmlzU3VwcG9ydGVkKCkpIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5faGxzKSB0aGlzLl9obHMgPSBuZXcgd2luZG93Lkhscyh7IGxpdmVEdXJhdGlvbkluZmluaXR5OiB0cnVlIH0pXG4gICAgICAgICAgICB0aGlzLl9obHMubG9hZFNvdXJjZShzZXR0aW5ncy5zdHJlYW0uc3JjKVxuICAgICAgICAgICAgdGhpcy5faGxzLmF0dGFjaE1lZGlhKHRoaXMudmlkZW9FbClcbiAgICAgICAgICAgIHRoaXMudmlkZW9FbC5zdHlsZS5kaXNwbGF5ID0gJ2Jsb2NrJ1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB0aGlzLm9wZW4oc2V0dGluZ3Muc3RyZWFtLnNyYylcbiAgICAgICAgfVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgdGhpcy5jbG9zZSgpXG4gICAgICB9XG4gICAgICB0aGlzLl9zdHJlYW0gPSBzZXR0aW5ncy5zdHJlYW1cbiAgICB9XG5cbiAgICB0aGlzLl9zZXRIaWRlKHNldHRpbmdzLmhpZGUpXG4gICAgdGhpcy5fc2V0VmlkZW9BcmVhKHNldHRpbmdzLnZpZGVvUG9z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XG4gICAgICAgIH0pKTtcbiAgICB9O1xufVxuXG5mdW5jdGlvbiBvd25LZXlzKGUsIHIpIHtcbiAgICB2YXIgdCA9IE9iamVjdC5rZXlzKGUpO1xuICAgIGlmIChPYmplY3QuZ2V0T3duUHJvcGVydHlTeW1ib2xzKSB7XG4gICAgICAgIHZhciBvID0gT2JqZWN0LmdldE93blByb3BlcnR5U3ltYm9scyhlKTtcbiAgICAgICAgciAmJiAobyA9IG8uZmlsdGVyKChmdW5jdGlvbihyKSB7XG4gICAgICAgICAgICByZXR1cm4gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihlLCByKS5lbnVtZXJhYmxlO1xuICAgICAgICB9KSkpLCB0LnB1c2guYXBwbHkodCwgbyk7XG4gICAgfVxuICAgIHJldHVybiB0O1xufVxuXG5mdW5jdGlvbiBfb2JqZWN0U3ByZWFkKGUpIHtcbiAgICBmb3IgKHZhciByID0gMTsgciA8IGFyZ3VtZW50cy5sZW5ndGg7IHIrKykge1xuICAgICAgICB2YXIgdCA9IG51bGwgIT0gYXJndW1lbnRzW3JdID8gYXJndW1lbnRzW3JdIDoge307XG4gICAgICAgIHIgJSAyID8gb3duS2V5cyhPYmplY3QodCksICEwKS5mb3JFYWNoKChmdW5jdGlvbihyKSB7XG4gICAgICAgICAgICBfZGVmaW5lUHJvcGVydHkoZSwgciwgdFtyXSk7XG4gICAgICAgIH0pKSA6IE9iamVjdC5nZXRPd25Qcm9wZXJ0eURlc2NyaXB0b3JzID8gT2JqZWN0LmRlZmluZVByb3BlcnRpZXMoZSwgT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcnModCkpIDogb3duS2V5cyhPYmplY3QodCkpLmZvckVhY2goKGZ1bmN0aW9uKHIpIHtcbiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShlLCByLCBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yKHQsIHIpKTtcbiAgICAgICAgfSkpO1xuICA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BBcnJheShfbGVuKSwgX2tleSA9IDA7IF9rZXkgPCBfbGVuOyBfa2V5KyspIHtcbiAgICAgICAgICAgIGFyZ3NbX2tleV0gPSBhcmd1bWVudHNbX2tleV07XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX2xvZ0NhbGxiYWNrKSB7XG4gICAgICAgICAgICB0aGlzLl9sb2dDYWxsYmFjayh7XG4gICAgICAgICAgICAgICAgbGV2ZWw6IFwibG9nXCIsXG4gICAgICAgICAgICAgICAgcGF5bG9hZDogYXJnc1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuZGVidWcpIHtcbiAgICAgICAgICAgIGNvbnNvbGUubG9nKHRoaXMuX3ByZWZpeCwgLi4uYXJncyk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgaW5mbygpIHtcbiAgICAgICAgZm9yICh2YXIgX2xlbjIgPSBhcmd1bWVudHMubGVuZ3RoLCBhcmdzID0gbmV3IEFycmF5KF9sZW4yKSwgX2tleTIgPSAwOyBfa2V5MiA8IF9sZW4yOyBfa2V5MisrKSB7XG4gICAgICAgICAgICBhcmdzW19rZXkyXSA9IGFyZ3VtZW50c1tfa2V5Ml07XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX2xvZ0NhbGxiYWNrKSB7XG4gICAgICAgICAgICB0aGlzLl9sb2dDYWxsYmFjayh7XG4gICAgICAgICAgICAgICAgbGV2ZWw6IFwiaW5mb1wiLFxuICAgICAgICAgICAgICAgIHBheWxvYWQ6IGFyZ3NcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLmRlYnVnKSB7XG4gICAgICAgICAgICBjb25zb2xlLmluZm8odGhpcy5fcHJlZml4LCAuLi5hcmdzKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICB3YXJuKCkge1xuICAgICAgICBmb3IgKHZhciBfbGVuMyA9IGFyZ3VtZW50cy5sZW5ndGgsIGFyZ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IgZm9ybWF0dGVkSXRlbSA9IGl0ZW07XG4gICAgICAgICAgICAgICAgdmFyIGJhZGdlID0gYmFkZ2VSZWdFeC5leGVjKGl0ZW0pO1xuICAgICAgICAgICAgICAgIHZhciBpY29uID0gaWNvblJlZ0V4LmV4ZWMoaXRlbSk7XG4gICAgICAgICAgICAgICAgdmFyIG5ld2xpbmUgPSBuZXdsaW5lUmVnRXguZXhlYyhpdGVtKTtcbiAgICAgICAgICAgICAgICB2YXIgdGV4dCA9IHRleHRSZWdFeC5leGVjKGl0ZW0pO1xuICAgICAgICAgICAgICAgIGlmIChiYWRnZSAmJiBiYWRnZVsxXSkge1xuICAgICAgICAgICAgICAgICAgICBmb3JtYXR0ZWRJdGVtID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgYmFkZ2U6IGJhZGdlWzFdXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChpY29uICYmIGljb25bMV0pIHtcbiAgICAgICAgICAgICAgICAgICAgZm9ybWF0dGVkSXRlbSA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRpdGxlOiBpY29uWzFdLFxuICAgICAgICAgICAgICAgICAgICAgICAgaWNvbjogaWNvblsyXSB8fCBpY29uWzFdXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChuZXdsaW5lKSB7XG4gICAgICAgICAgICAgICAgICAgIGZvcm1hdHRlZEl0ZW0gPSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBuZXdsaW5lOiB0cnVlXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0ZXh0ICYmIHRleHRbMV0pIHtcbiAgICAgICAgICAgICAgICAgICAgZm9ybWF0dGVkSXRlbSA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRleHQ6IHRleHRbMV0sXG4gICAgICAgICAgICAgICAgICAgICAgICBzdHlsZTogdGV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hbHVlKSkge1xuICAgICAgICAgICAgdGhpcy5fa2V5TWV0cmljc0NhbGxiYWNrID0gdmFsdWU7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgbG9nZ2VySW5zdGFuY2Uud2FybihcImNvbnRleHQga2V5TWV0cmljc0NhbGxiYWNrIGV4cGVjdGVkIGEgZnVuY3Rpb24uIFJlY2VpdmVkIFwiLmNvbmNhdCh0eXBlb2YgdmFsdWUpKTtcbiAgICB9XG59XG5cbnZhciBtZXRyaWNzSW5zdGFuY2UgPSBuZXcgTWV0cmljcztcblxudmFyIGV2ZW50RW1pdHRlckluc3RhbmNlID0gbmV3IGxuZy5FdmVudEVtaXR0ZXI7XG5cbnZhciBldmVudHMgPSBldmVudEVtaXR0ZXJJbnN0YW5jZTtcblxudmFyIGJhc2VUaGVtZSA9IHtcbiAgICBuYW1lOiBcIkJhc2UgTGlnaHRuaW5nIFRWXCIsXG4gICAgYWxwaGE6IHtcbiAgICAgICAgcHJpbWFyeTogMSxcbiAgICAgICAgc2Vjb25kYXJ5OiAuNyxcbiAgICAgICAgdGVydGlhcnk6IC4xLFxuICAgICAgICBpbmFjdGl2ZTogLjUsXG4gICAgICAgIGZ1bGw6IDEsXG4gICAgICAgIG5vbmU6IDAsXG4gICAgICAgIGFscGhhMTogLjEsXG4gICAgICAgIGFscGhhMjogLjMsXG4gICAgICAgIGFscGhhMzogLjUsXG4gICAgICAgIGFscGhhNDogLjcsXG4gICAgICAgIGFscGhhNTogLjlcbiAgICB9LFxuICAgIGFuaW1hdGlvbjoge1xuICAgICAgICBkdXJhdGlvbjoge1xuICAgICAgICAgICAgbm9uZTogMCxcbiAgICAgICAgICAgIHhmYXN0OiAuMSxcbiAgICAgICAgICAgIGZhc3Q6IC4yNSxcbiAgICAgICAgICAgIG5vcm1hbDogLjUsXG4gICAgICAgICAgICBzbG93OiAuNzUsXG4gICAgICAgICAgICB4c2xvdzogLjlcbiAgICAgICAgfSxcbiAgICAgICAgZGVsYXk6IHtcbiAgICAgICAgICAgIG5vbmU6IDAsXG4gICAgICAgICAgICB4ZmFzdDogLjAxLFxuICAgICAgICAgICAgZmFzdDogLjAyNSxcbiAgICAgICAgICAgIG5vcm1hbDogLjA1LFxuICAgICAgICAgICAgc2xvdzogLjA3NSxcbiAgICAgICAgICAgIHhzbG93OiAuMDlcbiAgICAgICAgfSxcbiAgICAgICAgZXhwcmVzc2l2ZToge1xuICAgICAgICAgICAgdGltaW5nRnVuY3Rpb246IFwiY3ViaWMtYmV6aWVyKDAsIDAsIDEsIDEpXCIsXG4gICAgICAgICAgICBkZWxheTogMCxcbiAgICAgICAgICAgIGR1cmF0aW9uOiAuMjVcbiAgICAgICAgfSxcbiAgICAgICAgZXhwcmVzc2l2ZUVudHJhbmNlOiB7XG4gICAgICAgICAgICB0aW1pbmdGdW5jdGlvbjogXCJjdWJpYy1iZXppZXIoMCwgMCwgMSwgMSlcIixcbiAgICAgICAgICAgIGRlbGF5OiAwLFxuICAgICAgICAgICAgZHVyYXRpb246IC4yNVxuICAgICAgICB9LFxuICAgICAgICBleHByZXNzaXZlRXhpdDoge1xuICAgICAgICAgICAgdGltaW5nRnVuY3Rpb246IFwiY3ViaWMtYmV6aWVyKDAsIDAsIDEsIDEpXCIsXG4gICAgICAgICAgICBkZWxheTogMCxcbiAgICAgICAgICAgIGR1cmF0aW9uOiAuMjVcbiAgICAgICAgfSxcbiAgICAgICAgc3RhbmRhcmQ6IHtcbiAgICAgICAgICAgIHRpbWluZ0Z1bmN0aW9uOiBcImN1YmljLWJlemllcigwLCAwLCAxLCAxKVwiLFxuICAgICAgICAgICAgZGVsYXk6IDAsXG4gICAgICAgICAgICBkdXJhdGlvbjogLjI1XG4gICAgICAgIH0sXG4gICAgICAgIHN0YW5kYXJkRW50cmFuY2U6IHtcbiAgICAgICAgICAgIHRpbWluZ0Z1bmN0aW9uOiBcImN1YmljLWJlemllcigwLCAwLCAxLCAxKVwiLFxuICAgICAgICAgICAgZGVsYXk6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S0JrQUlKVUVpK2RFNkFrb0dRQWdsUVNMNTBUb0NTZ1pBQ0NWQkl2blJPZ0pLQmtBSUpVRWkrZEU2QWtvR1FBZ2xRU0w1MFRvQ1NnWkFDQ1ZCSXZuUk9nSktCa0FJSlVFaStkRTZBa29HUUFnbFFTTDUwVG9DU2daQUNDVkJJdm5UK0gwalBUODFKM3hXV0FBQUFBRWxGVGtTdVFtQ0NcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfSxcbiAgICBmb250OiBbXSxcbiAgICBsYXlvdXQ6IHtcbiAgICAgICAgY29sdW1uQ291bnQ6IDEwLFxuICAgICAgICBmb2N1c1NjYWxlOiAxLjIsXG4gICAgICAgIGd1dHRlclg6IDIwLFxuICAgICAgICBndXR0ZXJZOiAyMCxcbiAgICAgICAgbWFyZ2luWDogMTUwLFxuICAgICAgICBtYXJnaW5ZOiAxNTAsXG4gICAgICAgIHNhZmU6IDUwLFxuICAgICAgICBzY3JlZW5XOiAxOTIwLFxuICAgICAgICBzY3JlZW5IOiAxMDgwXG4gICAgfSxcbiAgICByYWRpdXM6IHtcbiAgICAgICAgbm9uZTogMCxcbiAgICAgICAgeHM6IDIsXG4gICAgICAgIHNtOiA0LFxuICAgICAgICBtZDogOCxcbiAgICAgICAgbGc6IDE2LFxuICAgICAgICB4bDogMjRcbiAgICB9LFxuICAgIHNwYWNlcjoge1xuICAgICAgICBub25lOiAwLFxuICAgICAgICB4eHM6IDIsXG4gICAgICAgIHhzOiA0LFxuICAgICAgICBzbTogOCxcbiAgICAgICAgbWQ6IDEwLFxuICAgICAgICBsZzogMjAsXG4gICAgICAgIHhsOiAzMCxcbiAgICAgICAgeHhsOiA0MCxcbiAgICAgICAgeHh4bDogNTBcbiAgICB9LFxuICAgIHN0cm9rZToge1xuICAgICAgICBub25lOiAwLFxuICAgICAgICBzbTogMixcbiAgICAgICAgbWQ6IDQsXG4gICAgICAgIGxnOiA2LFxuICAgICAgICB4bDogOFxuICAgIH0sXG4gICAgdHlwb2dyYXBoeToge1xuICAgICAgICBkaXNwbGF5MToge1xuICAgICAgICAgICAgZm9udEZhbWlseTogXCJBcmlhbFwiLFxuICAgICAgICAgICAgZm9udFNpemU6IDc1LFxuICAgICAgICAgICAgbGluZUhlaWdodDogODUsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiNTAwXCIsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiBcIm1pZGRsZVwiLFxuICAgICAgICAgICAgdGV4dEJhc2VsaW5lOiBcImJvdHRvbVwiXG4gICAgICAgIH0sXG4gICAgICAgIGRpc3BsYXkyOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogNTAsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiA2MCxcbiAgICAgICAgICAgIGZvbnRTdHlsZTogXCI1MDBcIixcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgaGVhZGxpbmUxOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogMzUsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiNTAwXCIsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiA0OCxcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgaGVhZGxpbmUyOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogMzAsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiNTAwXCIsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiA0MCxcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgaGVhZGxpbmUzOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogMjUsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiNTAwXCIsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiAzNixcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgYm9keTE6IHtcbiAgICAgICAgICAgIGZvbnRGYW1pbHk6IFwiQXJpYWxcIixcbiAgICAgICAgICAgIGZvbnRTaXplOiAyNSxcbiAgICAgICAgICAgIGZvbnRTdHlsZTogXCIzMDBcIixcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDQwLFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogXCJtaWRkbGVcIixcbiAgICAgICAgICAgIHRleHRCYXNlbGluZTogXCJib3R0b21cIlxuICAgICAgICB9LFxuICAgICAgICBib2R5Mjoge1xuICAgICAgICAgICAgZm9udEZhbWlseTogXCJBcmlhbFwiLFxuICAgICAgICAgICAgZm9udFNpemU6IDIyLFxuICAgICAgICAgICAgZm9udFN0eWxlOiBcIjMwMFwiLFxuICAgICAgICAgICAgbGluZUhlaWdodDogMzIsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiBcIm1pZGRsZVwiLFxuICAgICAgICAgICAgdGV4dEJhc2VsaW5lOiBcImJvdHRvbVwiXG4gICAgICAgIH0sXG4gICAgICAgIGJvZHkzOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogMjAsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiMzAwXCIsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiAzMixcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgYnV0dG9uMToge1xuICAgICAgICAgICAgZm9udEZhbWlseTogXCJBcmlhbFwiLFxuICAgICAgICAgICAgZm9udFNpemU6IDI1LFxuICAgICAgICAgICAgZm9udFN0eWxlOiBcIjUwMFwiLFxuICAgICAgICAgICAgbGluZUhlaWdodDogMzIsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiBcIm1pZGRsZVwiLFxuICAgICAgICAgICAgdGV4dEJhc2VsaW5lOiBcImJvdHRvbVwiXG4gICAgICAgIH0sXG4gICAgICAgIGJ1dHRvbjI6IHtcbiAgICAgICAgICAgIGZvbnRGYW1pbHk6IFwiQXJpYWxcIixcbiAgICAgICAgICAgIGZvbnRTaXplOiAyMCxcbiAgICAgICAgICAgIGZvbnRTdHlsZTogXCI1MDBcIixcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDMyLFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogXCJtaWRkbGVcIixcbiAgICAgICAgICAgIHRleHRCYXNlbGluZTogXCJib3R0b21cIlxuICAgICAgICB9LFxuICAgICAgICBjYWxsb3V0MToge1xuICAgICAgICAgICAgZm9udEZhbWlseTogXCJBcmlhbFwiLFxuICAgICAgICAgICAgZm9udFNpemU6IDIwLFxuICAgICAgICAgICAgZm9udFN0eWxlOiBcIjUwMFwiLFxuICAgICAgICAgICAgbGluZUhlaWdodDogMzIsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiBcIm1pZGRsZVwiLFxuICAgICAgICAgICAgdGV4dEJhc2VsaW5lOiBcImJvdHRvbVwiXG4gICAgICAgIH0sXG4gICAgICAgIGNhcHRpb24xOiB7XG4gICAgICAgICAgICBmb250RmFtaWx5OiBcIkFyaWFsXCIsXG4gICAgICAgICAgICBmb250U2l6ZTogMTUsXG4gICAgICAgICAgICBmb250U3R5bGU6IFwiNTAwXCIsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiAyNCxcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246IFwibWlkZGxlXCIsXG4gICAgICAgICAgICB0ZXh0QmFzZWxpbmU6IFwiYm90dG9tXCJcbiAgICAgICAgfSxcbiAgICAgICAgdGFnMToge1xuICAgICAgICAgICAgZm9udEZhbWlseTogXCJBcmlhbFwiLFxuICAgICAgICAgICAgZm9udFNpemU6IDIwLFxuICAgICAgICAgICAgZm9udFN0eWxlOiBcIjUwMFwiLFxuICAgICAgICAgICAgbGluZUhlaWdodDogMjQsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiBcIm1pZGRsZVwiLFxuICAgICAgICAgICAgdGV4dEJhc2VsaW5lOiBcImJvdHRvbVwiXG4gICAgICAgIH0sXG4gICAgICAgIGZvb3Rub3RlMToge1xuICAgICAgICAgICAgZm9udEZhbWlseTogXCJBcmlhbFwiLFxuICAgICAgICAgICAgZm9udFNpemU6IDIyLFxuICAgICAgICAgICAgZm9udFN0eWxlOiBcIjMwMFwiLFxuICAgICAgICAgICAgbGluZUhlaWdodDogMzAsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiBcIm1pZGRsZVwiLFxuICAgICAgICAgICAgdGV4dEJhc2VsaW5lOiBcImJvdHRvbVwiXG4gICAgICAgIH1cbiAgICB9XG59O1xuXG52YXIgY3VzdG9tRm9udEZhY2VzID0gW107XG5cbnZhciBmb250TG9hZGVyID0gZm9udHMgPT4ge1xuICAgIHZhciBwcm9taXNlcyA9IFtdO1xuICAgIHZhciBfbG9vcCA9IGZ1bmN0aW9uIF9sb29wKCkge1xuICAgICAgICB2YXIge2ZhbWlseTogZmFtaWx5LCBzcmM6IHNyYywgZGVzY3JpcHRvcnM6IGRlc2NyaXB0b3JzfSA9IGZvbnRzW2ldO1xuICAgICAgICB2YXIgZm9udFNyYyA9IHNyYyAmJiBBcnJheS5pc0FycmF5KHNyYykgJiYgc3JjLmxlbmd0aCA/IHNyYy5tYXAoKHVybCA9PiB1cmwuc3Vic3RyKDAsIDUpID09PSBcImxvY2FsXCIgPyB1cmwgOiBcInVybChcIi5jb25jYXQodXJsLCBcIilcIikpKS5qb2luKFwiLFwiKSA6IFwidXJsKFwiICsgc3JjICsgXCIpXCI7XG4gICAgICAgIHZhciBmb250RmFjZSA9IG5ldyBGb250RmFjZShmYW1pbHksIGZvbnRTcmMsIGRlc2NyaXB0b3JzIHx8IHt9KTtcbiAgICAgICAgbG9nZ2VySW5zdGFuY2UuaW5mbyhcIkxvYWRpbmcgZm9udFwiLCBmYW1pbHkpO1xuICAgICAgICBkb2N1bWVudC5mb250cy5hZGQoZm9udEZhY2UpO1xuICAgICAgICBwcm9taXNlcy5wdXNoKG5ldyBQcm9taXNlKChyZXNvbHZlID0+IHtcbiAgICAgICAgICAgIGZvbnRGYWNlLmxvYWQoKS50aGVuKCgoKSA9PiB7XG4gICAgICAgICAgICAgICAgY3VzdG9tRm9udEZhY2VzLnB1c2goZm9udEZhY2UpO1xuICAgICAgICAgICAgICAgIHJlc29sdmUoZmFtaWx5KTtcbiAgICAgICAgICAgIH0pKS5jYXRjaCgoZXJyID0+IHtcbiAgICAgICAgICAgICAgICByZXNvbHZlKG5ldyBFcnJvcihcIlwiLmNvbmNhdChmYW1pbHksIFwiOiBcIikuY29uY2F0KGVyci5tZXNzYWdlKSkpO1xuICAgICAgICAgICAgfSkpO1xuICAgICAgICB9KSkpO1xuICAgIH07XG4gICAgZm9yICh2YXIgaSA9IDA7IGkgPCBmb250cy5sZW5ndGg7IGkrKykge1xuICAgICAgICBfbG9vcCgpO1xuICAgIH1cbiAgICByZXR1cm4g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gICAgICAgICAgICAgbG9nZ2VySW5zdGFuY2UuaW5mbyhcIlJlbW92aW5nIGZvbnRcIiwgZm9udEZhY2UuZmFtaWx5KTtcbiAgICAgICAgICAgICAgICAgICAgZG9jdW1lbnQuZm9udHMuZGVsZXRlKGZvbnRGYWNlKTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBmb250RmFjZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBsb2dnZXJJbnN0YW5jZS5pbmZvKFwiVW5hYmxlIHRvIHJlbW92ZSBtYW51YWxseS1hZGRlZCBmb250c1wiKTtcbiAgICAgICAgfVxuICAgIH0pKTtcbiAgICByZXR1cm4gZnVuY3Rpb24gY2xlYW51cEZvbnRzKF94KSB7XG4gICAgICAgIHJldHVybiBfcmVmMy5hcHBseSh0aGlzLCBhcmd1bWVudHMpO1xuICAgIH07XG59KCk7XG5cbnZhciBUSEVNRV9LRVlfUkVQTEFDRVIgPSB7XG4gICAgZm9udEZhbWlseTogXCJmb250RmFjZVwiXG59O1xuXG52YXIgbWVyZ2UgPSB7XG4gICAgYWxsOiBvYmpBcnJheSA9PiB7XG4gICAgICAgIHZhciByZXN1bHQgPSB7fTtcbiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBvYmpBcnJheS5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgcmVzdWx0ID0gY2xvbmUocmVzdWx0LCBvYmpBcnJheVtpXSk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICB9XG59O1xuXG52YXIgYmFzZTY0Q2FjaGUgPSBbXTtcblxudmFyIGlzU3ViVGhlbWUgPSB0aGVtZU5hbWUgPT4gXCJzdWJUaGVtZVwiID09PSB0aGVtZU5hbWUuc2xpY2Uo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aWNlKG9mZnNldCwgb2Zmc2V0ICsgNTEyKTtcbiAgICAgICAgICAgIHZhciBieXRlTnVtYmVycyA9IG5ldyBBcnJheShzbGljZS5sZW5ndGgpO1xuICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBzbGljZS5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgICAgIGJ5dGVOdW1iZXJzW2ldID0gc2xpY2UuY2hhckNvZGVBdChpKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBieXRlQXJyYXkgPSBuZXcgVWludDhBcnJheShieXRlTnVtYmVycyk7XG4gICAgICAgICAgICBieXRlQXJyYXlzLnB1c2goYnl0ZUFycmF5KTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgYmxvYiA9IG5ldyBCbG9iKGJ5dGVBcnJheXMsIHtcbiAgICAgICAgICAgIHR5cGU6IG1pbWVUeXBlXG4gICAgICAgIH0pO1xuICAgICAgICB2YXIgYmxvYlVSTCA9IFVSTC5jcmVhdGVPYmplY3RVUkwoYmxvYik7XG4gICAgICAgIHJldHVybiBibG9iVVJMO1xuICAgIH0gY2F0Y2ggKGVycm9yKSB7XG4gICAgICAgIGxvZ2dlckluc3RhbmNlLmluZm8oXCJVbmFibGUgdG8gY29udmVydCBiYXNlNjQgaW1hZ2UgdG8gVVJMXCIpO1xuICAgICAgICByZXR1cm4gbnVsbDtcbiAgICB9XG59XG5cbmNsYXNzIFRoZW1lTWFuYWdlciB7XG4gICAgY29uc3RydWN0b3IoKSB7XG4gICAgICAgIHRoaXMuX2NhY2hlID0gbmV3IE1hcDtcbiAgICAgICAgaWYgKHR5cGVvZiB3aW5kb3cgPT09IFwidW5kZWZpbmVkXCIpIHJldHVybjtcbiAgICAgICAgaWYgKCF3aW5kb3cuTFVJKSB7XG4gICAgICAgICAgICB3aW5kb3cuTFVJID0ge307XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF3aW5kb3cuTFVJLnRoZW1lTWFuYWdlckluc3Rhbm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cIiA9PT0gdHlwZW9mIGtleSAmJiBpc1N1YlRoZW1lKGtleSkpIHtcbiAgICAgICAgICAgICAgICB2YXIgX2NhY2hlID0gdGhpcy5fY2FjaGUuZ2V0KGtleSk7XG4gICAgICAgICAgICAgICAgaWYgKF9jYWNoZS5vcmlnaW5hbCkgdGhpcy51cGRhdGVTdWJUaGVtZShrZXkucmVwbGFjZSgvXnN1YlRoZW1lLywgXCJcIiksIF9jYWNoZS5vcmlnaW5hbCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pKTtcbiAgICB9XG4gICAgX2xvYWRGb250cyhmb250QXJyYXkpIHtcbiAgICAgICAgcmV0dXJuIF9hc3luY1RvR2VuZXJhdG9yKChmdW5jdGlvbiooKSB7XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgIHlpZWxkIGZvbnRMb2FkZXIoZm9udEFycmF5KTtcbiAgICAgICAgICAgIH0gY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICAgIGxvZ2dlckluc3RhbmNlLmVycm9yKFwiVW5hYmxlIHRvIGxvYWQgZm9udDogXCIuY29uY2F0KGVycikpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KSkoKTtcbiAgICB9XG4gICAgdXBkYXRlVGhlbWUodGhlbWVDb25maWcpIHtcbiAgICAgICAgdmFyIF90aGlzMyA9IHRoaXM7XG4gICAgICAgIHJldHVybiBfYXN5bmNUb0dlbmVyYXRvcigoZnVuY3Rpb24qKCkge1xuICAgICAgICAgICAgdmFyIHZhbHVlO1xuICAgICAgICAgICAgaWYgKEFycmF5LmlzQXJyYXkodGhlbWVDb25maWcpKSB7XG4gICAgICAgICAgICAgICAgdmFsdWUgPSBtZXJnZS5hbGwodGhlbWVDb25maWcpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB2YWx1ZSA9IHRoZW1lQ29uZmlnO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdmFyIGN1cnJlbnRUaGVtZSA9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b25zdHJ1Y3Rvci5uYW1lICYmICFBcnJheS5pc0FycmF5KHZhbHVlKSkge1xuICAgICAgICAgICAgICAgIHRoZW1lRnVuY3Rpb25zW2tleV0gPSB2YWx1ZTtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9IGVsc2UgaWYgKFwic3RyaW5nXCIgPT09IHR5cGVvZiB2YWx1ZSAmJiB2YWx1ZS5pbmNsdWRlcyhcInRoZW1lLlwiKSkge1xuICAgICAgICAgICAgICAgIHZhciB0aGVtZVZhbHVlID0gZ2V0VmFsRnJvbU9ialBhdGgoe1xuICAgICAgICAgICAgICAgICAgICB0aGVtZTogdGhlbWVcbiAgICAgICAgICAgICAgICB9LCB2YWx1ZSk7XG4gICAgICAgICAgICAgICAgaWYgKHRoZW1lVmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoZW1lVmFsdWU7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHZhbHVlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdmFyIHZhbGlkQ29sb3IgPSBnZXRWYWxpZENvbG9yKHZhbHVlKTtcbiAgICAgICAgICAgICAgICBpZiAodmFsaWRDb2xvcikge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdmFsaWRDb2xvcjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIHZhbHVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KSk7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgSlNPTi5wYXJzZSh0aGVtZVN0cmluZykpLCB0aGVtZUZ1bmN0aW9ucyksIHt9LCB7XG4gICAgICAgICAgICBleHRlbnNpb25zOiBleHRlbnNpb25zXG4gICAgICAgIH0pO1xuIC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cG9uZW50KCk7XG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgICAgICAgICAgY29udGV4dEluc3RhbmNlLmVycm9yKFwiRXJyb3IgdXBkYXRpbmcgY29tcG9uZW50IHRoZW1lc1wiLCBlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSkpO1xuICAgICAgICB0aGlzLl91cGRhdGVUaGVtZVNldC5jbGVhcigpO1xuICAgICAgICB0aGlzLl9yZXF1ZXN0VXBkYXRlU2V0LmZvckVhY2goKGNvbXBvbmVudCA9PiB7XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgIGNvbXBvbmVudC5yZXF1ZXN0VXBkYXRlKCk7XG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgICAgICAgICAgY29udGV4dEluc3RhbmNlLmVycm9yKFwiRXJyb3IgdXBkYXRpbmcgY29tcG9uZW50XCIsIGUpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KSk7XG4gICAgICAgIHRoaXMuX3JlcXVlc3RVcGRhdGVTZXQuY2xlYXIoKTtcbiAgICB9XG4gICAgZmx1c2goKSB7XG4gICAgICAgIGlmICghdGhpcy5fdGltZW91dCkgcmV0dXJuO1xuICAgICAgICBjbGVhclRpbWVvdXQodGhpcy5fdGltZW91dCk7XG4gICAgICAgIHRoaXMuX3J1blVwZGF0ZXNUaW1lb3V0SGFuZGxlcigpO1xuICAgIH1cbiAgICBhZGRVcGRhdGVUaGVtZShjb21wb25lbnQpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGhlbWVTZXQuYWRkKGNvbXBvbmVudCk7XG4gICAgICAgIGlmICghdGhpcy5fdGltZW91dCkge1xuICAgICAgICAgICAgdGhpcy5fdGltZW91dCA9IHNldFRpbWVvdXQodGhpcy5fcnVuVXBkYXRlc1RpbWVvdXRIYW5kbGVyLCAwKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBkZWxldGVVcGRhdGVUaGVtZShjb21wb25lbn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Iikge1xuICAgICAgICByZXN1bHQgPSBjbG9uZShjb21wb25lbnRDb25maWdQcm9wLCBwcm9wKTtcbiAgICB9XG4gICAgcmV0dXJuIChfcmVzdWx0ID0gcmVzdWx0KSAhPT0gbnVsbCAmJiBfcmVzdWx0ICE9PSB2b2lkIDAgPyBfcmVzdWx0IDogY29tcG9uZW50Q29uZmlnUHJvcDtcbn1cblxuZnVuY3Rpb24gZ2V0UHJvcGVydHlEZXNjcmlwdG9yJDEobmFtZSwga2V5KSB7XG4gICAgcmV0dXJuIHtcbiAgICAgICAgZ2V0KCkge1xuICAgICAgICAgICAgdmFyIF90aGlzJF9fY29tcG9uZW50Q29uZjM7XG4gICAgICAgICAgICB2YXIgY3VzdG9tR2V0dGVyID0gdGhpc1tcIl9nZXRcIi5jb25jYXQoY2FwaXRhbChuYW1lKSldO1xuICAgICAgICAgICAgaWYgKGN1c3RvbUdldHRlciAmJiB0eXBlb2YgY3VzdG9tR2V0dGVyID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgICAgICB2YXIgX3RoaXMkX19jb21wb25lbnRDb25mLCBfdGhpcyRfX2NvbXBvbmVudENvbmYyO1xuICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IGN1c3RvbUdldHRlci5jYWxsKHRoaXMsIHRoaXNba2V5XSk7XG4gICAgICAgICAgICAgICAgdGhpc1trZXldID0gdmFsdWUgfHwgKChfdGhpcyRfX2NvbXBvbmVudENvbmYgPSB0aGlzLl9fY29tcG9uZW50Q29uZmlnUHJvcHMpID09PSBudWxsIHx8IF90aGlzJF9fY29tcG9uZW50Q29uZiA9PT0gdm9pZCAwID8gdm9pZCAwIDogX3RoaXMkX19jb21wb25lbnRDb25mW25hbWVdKTtcbiAgICAgICAgICAgICAgICByZXR1cm4gbWVyZ2VQcm9wcygoX3RoaXMkX19jb21wb25lbnRDb25mMiA9IHRoaXMuX19jb21wb25lbnRDb25maWdQcm9wcykgPT09IG51bGwgfHwgX3RoaXMkX19jb21wb25lbnRDb25mMiA9PT0gdm9pZCAwID8gdm9pZCAwIDogX3RoaXMkX19jb21wb25lbnRDb25mMltuYW1lXSwgdmFsdWUpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIG1lcmdlUHJvcHMoKF90aGlzJF9fY29tcG9uZW50Q29uZjMgPSB0aGlzLl9fY29tcG9uZW50Q29uZmlnUHJvcHMpID09PSBudWxsIHx8IF90aGlzJF9fY29tcG9uZW50Q29uZjMgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJF9fY29tcG9uZW50Q29uZjNbbmFtZV0sIHRoaXNba2V5XSk7XG4gICAgICAgIH0sXG4gICAgICAgIHNldCh2YWx1ZSkge1xuICAgICAgICAgICAgdmFyIG9sZFZhbHVlID0gdGhpc1trZXldO1xuICAgICAgICAgICAgaWYgKHZhbHVlICE9PSBvbGRWYWx1ZSkge1xuICAgICAgICAgICAgICAgIHZhciBjaGFuZ2VIYW5kbGVyID0gdGhpc1tcIl9zZXRcIi5jb25jYXQoY2FwaXRhbChuYW1lKSldO1xuICAgICAgICAgICAgICAgIGlmIChjaGFuZ2VIYW5kbGVyICYmIHR5cGVvZiBjaGFuZ2VIYW5kbGVyID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgICAgICAgICAgdmFsdWUgPSBjaGFuZ2VIYW5kbGVyLmNhbGwodGhpcywgdmFsdWUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB2YXIgbmV3VmFsdWUgPSBrZXkgPT09IFwic3R5bGVcIiA/IGNsb25lKHRoaXNba2V5XSwgdmFsdWUpIDogdmFsdWU7XG4gICAgICAgICAgICAgICAgaWYgKHR5cGVvZiB0aGlzW2tleV0gPT09IFwib2JqZWN0XCIgJiYgdGhpc1trZXldICE9PSBudWxsICYmIHRoaXNba2V5XS5zdHlsZSkge1xuICAgICAgICAgICAgICAgICAgICB2YXIgc3R5bGUgPSBjbG9uZSh0aGlzW2tleV0uc3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ybiBCYXNlLm5hbWU7XG4gICAgICAgIH1cbiAgICAgICAgX2NvbnN0cnVjdCgpIHtcbiAgICAgICAgICAgIHZhciBwcm90b3R5cGUgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2YodGhpcyk7XG4gICAgICAgICAgICBpZiAoIXByb3RvdHlwZS5fd2l0aFVwZGF0ZXNJbml0aWFsaXplZCkge1xuICAgICAgICAgICAgICAgIHZhciBwcm9wcyA9IHRoaXMuY29uc3RydWN0b3IucHJvcGVydGllcyB8fCBbXTtcbiAgICAgICAgICAgICAgICBwcm9wcy5mb3JFYWNoKChuYW1lID0+IHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIGtleSA9IFwiX1wiICsgbmFtZTtcbiAgICAgICAgICAgICAgICAgICAgdmFyIGRlc2NyaXB0b3IgPSBnZXRQcm9wZXJ0eURlc2NyaXB0b3IkMShuYW1lLCBrZXkpO1xuICAgICAgICAgICAgICAgICAgICBpZiAoZGVzY3JpcHRvciAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkocHJvdG90eXBlLCBuYW1lLCBkZXNjcmlwdG9yKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICB2YXIgYWxpYXNQcm9wcyA9IHRoaXMuY29uc3RydWN0b3IuYWxpYXNQcm9wZXJ0aWVzIHx8IFtdO1xuICAgICAgICAgICAgICAgIGFsaWFzUHJvcHMuZm9yRWFjaCgoYWxpYXMgPT4ge1xuICAgICAgICAgICAgICAgICAgICBpZiAoYWxpYXMgJiYgdHlwZW9mIGFsaWFzLnByZXYgPT09IFwic3RyaW5nXCIgJiYgdHlwZW9mIGFsaWFzLmN1cnIgPT09IFwic3RyaW5nXCIpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBkZXNjcmlwdG9yID0gZ2V0QWxpYXNQcm9wZXJ0eURlc2NyaXB0b3IoYWxpYXMucHJldiwgYWxpYXMuY3Vycik7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGVzY3JpcHRvciAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHByb3RvdHlwZSwgYWxpYXMucHJldiwgZGVzY3JpcHRvcik7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICAgICAgcHJvdG90eXBlLl93aXRoVXBkYXRlc0luaXRpYWxpemVkID0gdHJ1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX3doZW5FbmFibGVkID0gbmV3IFByb21pc2UoKHJlc29sdmUgPT4ge1xuICAgICAgICAgICAgICAgIHRoaXMuX3doZW5FbmFibGVkUmVzb2x2ZXIgPSByZXNvbHZlO1xuICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCAmJiBzdXBlci5fY29uc3RydWN0KCk7XG4gICAgICAgIH1cbiAgICAgICAgcXVldWVSZXF1ZXN0VXBkYXRlKCkge1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9pc0F0dGFjaGVkKCkpIHJldHVybjtcbiAgICAgICAgICAgIHVwZGF0ZU1hbmFnZXIuYWRkUmVxdWVzdFVwZGF0ZSh0aGlzKTtcbiAgICAgICAgfVxuICAgICAgICBfZmlyc3RFbmFibGUoKSB7XG4gICAgICAgICAgICB0aGlzLl9yZWFkeUZvclVwZGF0ZXMgPSB0cnVlO1xuICAgICAgICAgICAgdGhpcy5fd2hlbkVuYWJsZWRSZXNvbHZlcigpO1xuICAgICAgICAgICAgdXBkYXRlTWFuYWdlci5kZWxldGVSZXF1ZXN0VXBkYXRlKHRoaXMpO1xuICAgICAgICAgICAgdGhpcy5yZXF1ZXN0VXBkYXRlKCk7XG4g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oKSB7XG4gICAgICAgICAgICByZXR1cm4gQmFzZS5uYW1lO1xuICAgICAgICB9XG4gICAgICAgIF9jb25zdHJ1Y3QoKSB7XG4gICAgICAgICAgICB2YXIgcHJvdG90eXBlID0gT2JqZWN0LmdldFByb3RvdHlwZU9mKHRoaXMpO1xuICAgICAgICAgICAgaWYgKCFwcm90b3R5cGUuX3dpdGhUYWdzSW5pdGlhbGl6ZWQpIHtcbiAgICAgICAgICAgICAgICB2YXIgdGFncyA9IHRoaXMuY29uc3RydWN0b3IudGFncyB8fCBbXTtcbiAgICAgICAgICAgICAgICB0YWdzLmZvckVhY2goKHRhZyA9PiB7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgdGFnID09PSBcIm9iamVjdFwiKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIge25hbWU6IG5hbWUsIHBhdGg6IHBhdGh9ID0gdGFnO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIG5hbWUgPSB0YWc7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgcGF0aCA9IHRhZztcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB2YXIga2V5ID0gXCJfXCIgKyBuYW1lO1xuICAgICAgICAgICAgICAgICAgICB2YXIgZGVzY3JpcHRvciA9IGdldFByb3BlcnR5RGVzY3JpcHRvcihwYXRoKTtcbiAgICAgICAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHByb3RvdHlwZSwga2V5LCBkZXNjcmlwdG9yKTtcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICAgICAgcHJvdG90eXBlLl93aXRoVGFnc0luaXRpYWxpemVkID0gdHJ1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHN1cGVyLl9jb25zdHJ1Y3QgJiYgc3VwZXIuX2NvbnN0cnVjdCgpO1xuICAgICAgICB9XG4gICAgfTtcbn1cblxuZnVuY3Rpb24gd2l0aEhhbmRsZUtleShCYXNlKSB7XG4gICAgcmV0dXJuIGNsYXNzIGV4dGVuZHMgQmFzZSB7XG4gICAgICAgIHN0YXRpYyBnZXQgbmFtZSgpIHtcbiAgICAgICAgICAgIHJldHVybiBCYXNlLm5hbWU7XG4gICAgICAgIH1cbiAgICAgICAgX2hhbmRsZUtleShrZXlFdmVudCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3Byb2Nlc3NFdmVudChrZXlFdmVudCk7XG4gICAgICAgIH1cbiAgICAgICAgX2hhbmRsZUtleVJlbGVhc2Uoa2V5RXZlbnQpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9wcm9jZXNzRXZlbnQoa2V5RXZlbnQsIFwiUmVsZWFzZVwiKTtcbiAgICAgICAgfVxuICAgICAgICBfcHJvY2Vzc0V2ZW50KGtleUV2ZW50KSB7XG4gICAgICAgICAgICB2YXIgc3VmZml4ID0gYXJndW1lbnRzLmxlbmd0aCA+IDEgJiYgYXJndW1lbnRzWzFdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMV0gOiBcIlwiO1xuICAgICAgICAgICAgdmFyIGtleU1hcCA9IHRoaXMuc3RhZ2UuYXBwbGljYXRpb24uX19rZXltYXAgfHwge307XG4gICAgICAgICAgICB2YXIga2V5ID0ga2V5TWFwW2tleUV2ZW50LmtleUNvZGVdO1xuICAgICAgICAgICAgaWYgKCFrZXkpIHtcbiAgICAgICAgICAgICAgICBrZXkgPSBrZXlFdmVudC5rZXk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoa2V5ICYmIHR5cGVvZiB0aGlzW1wib25cIi5jb25jYXQoa2V5KS5jb25jYXQoc3VmZml4KV0gPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICAgICAgICAgIHRoaXMuX2ludm9rZUtleVBheWxvYWRDYWxsYmFjayhrZXkgKyBzdWZmaXgpO1xuICAgICAgICAgICAgICAgI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AgICAgICAgICAgaXRlbUxheW91dCA9IEpTT04ucGFyc2UoSlNPTi5zdHJpbmdpZnkodiwgKChrLCB2KSA9PiB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChrICE9PSBcImNpcmNsZVwiICYmIHYgPCAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjb250ZXh0SW5zdGFuY2UuZXJyb3IoXCJpdGVtTGF5b3V0IGZvciBcIi5jb25jYXQoY29tcG9uZW50TmFtZSwgXCIgcmVjZWl2ZWQgYW4gaW52YWxpZCB2YWx1ZSBvZiBcIikuY29uY2F0KHYsIFwiIGZvciBcIikuY29uY2F0KGspKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChrID09PSBcImNpcmNsZVwiKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gQm9vbGVhbih2KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gdjtcbiAgICAgICAgICAgICAgICB9KSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKCFzdHJpbmdpZnlDb21wYXJlKHRoaXMuX2l0ZW1MYXlvdXQsIGl0ZW1MYXlvdXQpKSB7XG4gICAgICAgICAgICAgICAgaWYgKGl0ZW1MYXlvdXQgJiYgIWl0ZW1MYXlvdXQudXBDb3VudCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9vcmlnaW5hbFcgPSB0aGlzLnc7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX29yaWdpbmFsSCA9IHRoaXMuaDtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5faXRlbUxheW91dCA9IF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5fb3JpZ2luYWxXLFxuICAgICAgICAgICAgICAgICAgICAgICAgaDogdGhpcy5fb3JpZ2luYWxIXG4gICAgICAgICAgICAgICAgICAgIH0sIGl0ZW1MYXlvdXQpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2l0ZW1MYXlvdXQgPSBpdGVtTGF5b3V0O1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVJdGVtTGF5b3V0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgX2FsbG93VXBkYXRlKCkge1xuICAgICAgICAgICAgdmFyIHt3OiB3ID0gXCJcIiwgaDogaCA9IFwiXCIsIGNpcmNsZTogY2lyY2xlID0gXCJcIiwgcmF0aW9YOiByYXRpb1ggPSBcIlwiLCByYXRpb1k6IHJhdGlvWSA9IFwiXCIsIHVwQ291bnQ6IHVwQ291bnQgPSBcIlwifSA9IHRoaXMuX2l0ZW1MYXlvdXQgfHwge307XG4gICAgICAgICAgICB2YXIgbGF5b3V0U3RyaW5nID0gT2JqZWN0LnZhbHVlcyhjb250ZXh0SW5zdGFuY2UudGhlbWUubGF5b3V0KS5qb2luKFwiXCIpICsgXCJcIi5jb25jYXQodykuY29uY2F0KGgpLmNvbmNhdChjaXJjbGUgPyAxIDogMCkuY29uY2F0KHJhdGlvWCkuY29uY2F0KHJhdGlvWSkuY29uY2F0KHVwQ291bnQpO1xuICAgICAgICAgICAgaWYgKGxheW91dFN0cmluZyAhPT0gdGhpcy5fcHJldmlvdXNEaW1lbnNpb25EYXRhKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fcHJldmlvdXNEaW1lbnNpb25EYXRhID0gbGF5b3V0U3RyaW5nO1xuICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIF91cGRhdGVJdGVtTGF5b3V0KCkge1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9hbGxvd1VwZGF0ZSgpKSByZXR1cm47XG4gICAgICAgICAgICB2YXIge3c6IHcsIGg6IGh9ID0gZ2V0RGltZW5zaW9ucyh0aGlzLnRoZW1lLCB0aGlzLl9pdGVtTGF5b3V0KTtcbiAgICAgICAgICAgIGlmIChoIHx8IHcpIHtcbiAgICAgICAgICAgICAgICB2YXIgd2lkdGggPSBjb250ZXh0SW5zdGFuY2UudGhlbWUubGF5b3V0LnNjcmVlblc7XG4gICAgICAgICAgICAgICAgdmFyIGhlaWdodCA9IGNvbnRleHRJbnN0YW5jZS50aGVtZS5sYXlvdXQuc2NyZWVuSDtcbiAgICAgICAgICAgICAgICB2YXIgY2FsY3VsYXRlZFdpZHRoID0gdyB8fCBoICogKHdpZHRoIC8gaGVpZ2h0KTtcbiAgICAgICAgICAgICAgICB2YXIgY2FsY3VsYXRlZEhlaWdodCA9IGggfHwgdyAqIChoZWlnaHQgLyB3aWR0aCk7XG4gICAgICAgICAgICAgICAgdGhpcy53ID0gdGhpcy5faXRlbUxheW91dCAmJiB0aGlzLl9pdGVtTGF5b3V0LmNpcmNsZSA/IGNhbGN1bGF0ZWRIZWlnaHQgOiBjYWxjdWxhdGVkV2lkdGg7XG4gICAgICAgICAgICAgICAgdGhpcy5oID0gY2FsY3VsYXRlZEhlaWdodDtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5faXRlbUxheW91dCAmJiB0aGlzLl9pdGVtTGF5b3V0LmNpcmNsZSAmJiB0aGlzLnN0eWxlLnJhZGl1cykge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9jaXJjbGVTZXQgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9vcmlnaW5hbFJhZGl1cyA9IHRoaXMuc3R5bGUucmFkaXVzO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnN0eWxlID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJhZGl1czogY2FsY3VsYXRlZEhlaWdodCAvIDJcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9jaXJjbGVTZXQpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdHlsZSA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICByYWRpdXM6IHRoaXMuX29yaWdpbmFsUmFkaXVzXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9vcmlnaW5hbFJhZGl1cyA9IHVuZGVmaW5lZDtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fY2lyY2xlU2V0ID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHRoaXMucXVldWVSZXF1ZXN0VXBkYXRlICYmIHRoaXMucXVldWVSZXF1ZXN0VXBkYXRlKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKFwiJGl0ZW1DaGFuZ2VkXCIpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfTtcbn1cblxudmFyIGdldENoYXJhY3RlclZhbHVlID0gKGNoYXIsIGluZGV4KSA9PiBjaGFyLmNoYXJDb2RlQXQoMCkgKiAoaW5kZXggKyAxKTtcblxudmFyIHNvcnRPYmplY3QgPSBvYmogPT4ge1xuICAgIHZhciBzb3J0ZWRPYmogPSB7fTtcbiAgICBPYmplY3Qua2V5cyhvYmopLnNvcnQoKS5mb3JFYWNoKChrZXkgPT4ge1xuICAgICAgICBpZiAodHlwZW9mIG9ialtrZXldID09PSBcIm9iamVjdFwiICYmIG9ialtrZXldICE9PSBudWxsICYmICFBcnJheS5pc0FycmF5KG9ialtrZXldKSkge1xuICAgICAgICAgICAgc29ydGVkT2JqW2tleV0gPSBzb3J0T2JqZWN0KG9ialtrZXldKTt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uT2JqZWN0cyA9IG5ldyBNYXA7XG4gICAgZnVuY3Rpb24gaGFzaChvYmplY3QpIHtcbiAgICAgICAgcmV0dXJuIEpTT04uc3RyaW5naWZ5KG9iamVjdCwgT2JqZWN0LmtleXMob2JqZWN0KS5zb3J0KCkpO1xuICAgIH1cbiAgICBmdW5jdGlvbiBwcm9jZXNzKGN1cnJlbnRPYmopIHtcbiAgICAgICAgZm9yICh2YXIga2V5IGluIGN1cnJlbnRPYmopIHtcbiAgICAgICAgICAgIGlmIChjdXJyZW50T2JqLmhhc093blByb3BlcnR5KGtleSkpIHtcbiAgICAgICAgICAgICAgICB2YXIgdmFsdWUgPSBjdXJyZW50T2JqW2tleV07XG4gICAgICAgICAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSA9PT0gXCJvYmplY3RcIiAmJiB2YWx1ZSAhPT0gbnVsbCkge1xuICAgICAgICAgICAgICAgICAgICB2YXIgdmFsdWVIYXNoID0gaGFzaCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChzZWVuT2JqZWN0cy5oYXModmFsdWVIYXNoKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudE9ialtrZXldID0gc2Vlbk9iamVjdHMuZ2V0KHZhbHVlSGFzaCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzZWVuT2JqZWN0cy5zZXQodmFsdWVIYXNoLCB2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBwcm9jZXNzKHZhbHVlKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbiAgICBwcm9jZXNzKG9iaik7XG4gICAgcmV0dXJuIG9iajtcbn1cblxuZnVuY3Rpb24gZ2V0VW5pcXVlUHJvcGVydGllcygpIHtcbiAgICB2YXIgZGVmYXVsdFByb3BzID0gYXJndW1lbnRzLmx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GlucHV0T2JqLmhhc093blByb3BlcnR5KGZhbGxiYWNrKSkpO1xuICAgICAgICAgICAgaWYgKGZhbGxiYWNrS2V5KSB7XG4gICAgICAgICAgICAgICAgdmFyIGZhbGxiYWNrID0gaW5wdXRPYmpbZmFsbGJhY2tLZXldO1xuICAgICAgICAgICAgICAgIHJlc3VsdFtrZXldID0gdHlwZW9mIGZhbGxiYWNrICE9PSBcIm9iamVjdFwiID8ge30gOiBmYWxsYmFjaztcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmVzdWx0W2tleV0gPSB7fTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICh0eXBlb2YgaW5wdXRPYmpba2V5XSAhPT0gXCJvYmplY3RcIikge1xuICAgICAgICAgICAgICAgIHJlc3VsdFtrZXldID0ge307XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJlc3VsdFtrZXldID0gaW5wdXRPYmpba2V5XTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4gcmVzdWx0O1xufVxuXG52YXIgZ2VuZXJhdGVDb21wb25lbnRTdHlsZVNvdXJjZSA9IGZ1bmN0aW9uIGdlbmVyYXRlQ29tcG9uZW50U3R5bGVTb3VyY2UoKSB7XG4gICAgdmFyIHt0aGVtZTogdGhlbWUgPSB7fSwgc3R5bGVDaGFpbjogc3R5bGVDaGFpbiA9IFtdLCBpbmxpbmVTdHlsZTogaW5saW5lU3R5bGUgPSB7fSwgYWxpYXM6IGFsaWFzID0gW119ID0gYXJndW1lbnRzLmxlbmd0aCA+IDAgJiYgYXJndW1lbnRzWzBdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMF0gOiB7fTtcbiAgICBpZiAodHlwZW9mIHRoZW1lICE9PSBcIm9iamVjdFwiKSB7XG4gICAgICAgIHRocm93IG5ldyBFcnJvcihcIkV4cGVjdGVkI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G4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciB0aGVtZVN0eWxlID0gcHJvdG8uY29uc3RydWN0b3IuaGFzT3duUHJvcGVydHkoXCJfX3RoZW1lU3R5bGVcIikgJiYgcHJvdG8uY29uc3RydWN0b3IuX190aGVtZVN0eWxlO1xuICAgICAgICAgICAgaWYgKE9iamVjdC5rZXlzKHRoZW1lU3R5bGUgfHwge30pLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgIGlmICghc3R5bGVNYXAuaGFzKHRoZW1lU3R5bGUpKSB7XG4gICAgICAgICAgICAgICAgICAgIHN0eWxlTWFwLnNldCh0aGVtZVN0eWxlLCB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzdHlsZTogX29iamVjdFNwcmVhZCh7fSwgdGhlbWVTdHlsZSlcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdGhlbWVTdHlsZSA9PT0gXCJmdW5jdGlvblwiKSB7XG4gICAgICAgICAgICAgICAgaWYgKCFzdHlsZU1hcC5oYXModGhlbWVTdHlsZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgc3R5bGVNYXAuc2V0KHRoZW1lU3R5bGUsIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0eWxlOiB0aGVtZVN0eWxlXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBtaXhpblN0eWxlID0gcHJvdG8uY29uc3RydWN0b3IuaGFzT3duUHJvcGVydHkoXCJfX21peGluU3R5bGVcIikgJiYgcHJvdG8uY29uc3RydWN0b3IuX19taXhpblN0eWxlO1xuICAgICAgICAgICAgaWYgKE9iamVjdC5rZXlzKG1peGluU3R5bGUgfHwge30pLmxlbmd0aCkge1xuICA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RfZ2V0Q2FjaGUyO1xuICAgICAgICAgICAgdmFyIHN0eWxlU291cmNlID0gKF90aGlzJF9nZXRDYWNoZSA9IHRoaXMuX2dldENhY2hlKFwic3R5bGVTb3VyY2VcIikpID09PSBudWxsIHx8IF90aGlzJF9nZXRDYWNoZSA9PT0gdm9pZCAwID8gdm9pZCAwIDogX3RoaXMkX2dldENhY2hlLnBheWxvYWQ7XG4gICAgICAgICAgICBpZiAoIXN0eWxlU291cmNlKSB7XG4gICAgICAgICAgICAgICAgc3R5bGVTb3VyY2UgPSBnZW5lcmF0ZUNvbXBvbmVudFN0eWxlU291cmNlKHtcbiAgICAgICAgICAgICAgICAgICAgYWxpYXM6IHRoaXMuY29tcG9uZW50LmNvbnN0cnVjdG9yLmFsaWFzU3R5bGVzLFxuICAgICAgICAgICAgICAgICAgICBjb21wb25lbnRDb25maWc6IHRoaXMuY29tcG9uZW50Ll9jb21wb25lbnRDb25maWcsXG4gICAgICAgICAgICAgICAgICAgIGlubGluZVN0eWxlOiB0aGlzLmNvbXBvbmVudC5fY29tcG9uZW50TGV2ZWxTdHlsZSxcbiAgICAgICAgICAgICAgICAgICAgc3R5bGVDaGFpbjogZ2V0U3R5bGVDaGFpbk1lbW9pemVkKHRoaXMuY29tcG9uZW50KSxcbiAgICAgICAgICAgICAgICAgICAgdGhlbWU6IHRoaXMuY29tcG9uZW50LnRoZW1lXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgdGhpcy5fYWRkQ2FjaGUoXCJzdHlsZVNvdXJjZVwiLCBzdHlsZVNvdXJjZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgc3R5bGUgPSAoX3RoaXMkX2dldENhY2hlMiA9IHRoaXMuX2dldENhY2hlKFwic3R5bGVfXCIuY29uY2F0KG1vZGUsIFwiX1wiKS5jb25jYXQodG9uZSkpKSA9PT0gbnVsbCB8fCBfdGhpcyRfZ2V0Q2FjaGUyID09PSB2b2lkIDAgPyB2b2lkI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XRoU2Vjb25kRG9taW5hbnQoaXRlbSwgQXJyYXkuaXNBcnJheShzZWNvbmRPYmopID8gc2Vjb25kT2JqW2luZGV4XSA6IHVuZGVmaW5lZCkpKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHZhciByZXN1bHQgPSB7fTtcbiAgICAgICAgICAgIHZhciBhbGxLZXlzID0gbmV3IFNldChbIC4uLk9iamVjdC5rZXlzKGZpcnN0T2JqKSwgLi4uT2JqZWN0LmtleXMoc2Vjb25kT2JqKSBdKTtcbiAgICAgICAgICAgIGFsbEtleXMuZm9yRWFjaCgoa2V5ID0+IHtcbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIGZpcnN0T2JqW2tleV0gPT09IFwib2JqZWN0XCIgJiYgZmlyc3RPYmpba2V5XSAhPT0gbnVsbCkge1xuICAgICAgICAgICAgICAgICAgICByZXN1bHRba2V5XSA9IG1lcmdlT2JqZWN0c1dpdGhTZWNvbmREb21pbmFudChmaXJzdE9ialtrZXldLCBzZWNvbmRPYmpba2V5XSB8fCB7fSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2Ygc2Vjb25kT2JqW2tleV0gPT09IFwib2JqZWN0XCIgJiYgc2Vjb25kT2JqW2tleV0gIT09IG51bGwpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0W2tleV0gPSBtZXJnZU9iamVjdHNXaXRoU2Vjb25kRG9taW5hbnQoZmlyc3RPYmpba2V5XSB8fCB7fSwgc2Vjb25kT2JqW2tleV0pO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdFtrZXldID0gc2Vjb25kT2JqLmhhc093blByb3BlcnR5KGtleSkgPyBzZWNvbmRPYmpba2V5XSA6IHVuZGVmaW5lZDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICByZXR1cm4gcmVzdWx0O1xuICAgICAgICB9XG4g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RlID0gXCJmb2N1c2VkXCI7XG4gICAgICAgICAgICBzdXBlci5fZm9jdXMoKTtcbiAgICAgICAgfVxuICAgICAgICBfY2hlY2tEaW1lbnNpb25VcGRhdGVzKCkge1xuICAgICAgICAgICAgdmFyIGRpbWVuc2lvblVwZGF0ZVJlcXVpcmVkID0gZmFsc2U7XG4gICAgICAgICAgICBpZiAoIXRoaXMuX3dTZXRCeVVzZXIgJiYgdGhpcy5zdHlsZS53ICYmIHRoaXMuX3cgIT09IHRoaXMuc3R5bGUudykge1xuICAgICAgICAgICAgICAgIHRoaXMuX3cgPSB0aGlzLnN0eWxlLnc7XG4gICAgICAgICAgICAgICAgZGltZW5zaW9uVXBkYXRlUmVxdWlyZWQgPSB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKCF0aGlzLl9oU2V0QnlVc2VyICYmIHRoaXMuc3R5bGUuaCAmJiB0aGlzLl9oICE9PSB0aGlzLnN0eWxlLmgpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9oID0gdGhpcy5zdHlsZS5oO1xuICAgICAgICAgICAgICAgIGRpbWVuc2lvblVwZGF0ZVJlcXVpcmVkID0gdHJ1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChkaW1lbnNpb25VcGRhdGVSZXF1aXJlZCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX3VwZGF0ZURpbWVuc2lvbnMoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBfdXBkYXRlVGhlbWVDb21wb25lbnQoKSB7XG4gICAgICAgICAgICBpZiAoIXRoaXMuc3R5bGUpIHJldHVybjtcbiAgICAgICAgICAgIGlmICghdGhpcy5faXNBdHRhY2hlZCgpKSByZXR1cm47XG4gICAgICAgICAgICB0aGlzLl9jaGVja0RpbWVuc2lvblVwZGF0ZXMoKTtcbiAgICAgICAgICAgIHRoaXMucXVldWVSZXF1ZXN0VXBkYXRlID8gdGhpcy5xdWV1ZVJlcXV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ICAgICAgIHJldHVybiBzdWJUaGVtZSB8fCBjb250ZXh0SW5zdGFuY2UudGhlbWU7XG4gICAgICAgIH1cbiAgICAgICAgc2V0IHN0eWxlKHYpIHtcbiAgICAgICAgICAgIGlmIChPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nLmNhbGwodikgIT09IFwiW29iamVjdCBPYmplY3RdXCIpIHtcbiAgICAgICAgICAgICAgICBjb250ZXh0SW5zdGFuY2UuZXJyb3IoXCJzdHlsZSBtdXN0IGJlIGFuIG9iamVjdFwiKTtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9jb21wb25lbnRMZXZlbFN0eWxlID0gdjtcbiAgICAgICAgICAgIHRoaXMuX3N0eWxlTWFuYWdlci5jbGVhclN0eWxlQ2FjaGUoKTtcbiAgICAgICAgICAgIHRoaXMuX3N0eWxlTWFuYWdlci51cGRhdGUoKTtcbiAgICAgICAgfVxuICAgICAgICBnZXQgc3R5bGUoKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fc3R5bGU7XG4gICAgICAgIH1cbiAgICAgICAgZ2V0IF9jb21wb25lbnRTdHlsZSgpIHtcbiAgICAgICAgICAgIGNvbnRleHRJbnN0YW5jZS5pbmZvKFwiX2NvbXBvbmVudFN0eWxlIHdpbGwgc29vbiBiZSBkZXByZWNhdGVkLiBQbGVhc2UgdXNlIENvbXBvbmVudC5zdHlsZVwiKTtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9zdHlsZTtcbiAgICAgICAgfVxuICAgICAgICBzZXQgc3R5bGVDb25maWcodikge1xuICAgICAgICAgICAgY29udGV4dEluc3RhbmNlLmluZm8oXCJzdHlsZSBjb25maWcgaXMgZGVwcmVjYXRlZC4gUGxlYXNlIHVzZSBzdHlsZSA9IHsgYmFzZToge30sIHRvbmU6IHt9LCBtb2RlOiB7fSB9XCIpO1xuICAgICAgICAgICAgdGhpcy5fc3R5bGVDb25maWcgPSB2O1xuICAgICAgICAgICAgdGhpcy5fc3R5bGVNYW5hZ2VyLnVwZGF0ZSgpO1xuICAgICAgICB9XG4gICAgICAgIGdldCBzdHlsZUNvbmZpZygpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9zdHlsZUNvbmZpZztcbiAgICAgICAgfVxuICAgICAgICBnZXQgX2NvbXBvbmVudENvbmZpZygpIHtcbiAgICAgICAgICAgIHJldHVybiBnZXRDb21wb25lbnRDb25maWcodGhpcyk7XG4gICAgICAgIH1cbiAgICAgICAgZ2V0IG1vZGUoKSB7XG4gICAgICAgICAgICB2YXIgX3RoaXMkX2NvbXBvbmVudENvbmZpO1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX21vZGUgfHwgKChfdGhpcyRfY29tcG9uZW50Q29uZmkgPSB0aGlzLl9jb21wb25lbnRDb25maWcpID09PSBudWxsIHx8IF90aGlzJF9jb21wb25lbnRDb25maSA9PT0gdm9pZCAwID8gdm9pZCAwIDogX3RoaXMkX2NvbXBvbmVudENvbmZpLm1vZGUpIHx8IFwidW5mb2N1c2VkXCI7XG4gICAgICAgIH1cbiAgICAgICAgc2V0IG1vZGUodikge1xuICAgICAgICAgICAgaWYgKHR5cGVvZiB2ICE9PSBcInN0cmluZ1wiIHx8IHRoaXMuX21vZGUgPT09IHYpIHJldHVybjtcbiAgICAgICAgICAgIHRoaXMuX21vZGUgPSB2O1xuICAgICAgICAgICAgdmFyIGV2ZW50ID0gdGhpc1tcIm9uXCIuY29uY2F0KGNhcGl0YWxpemVGaXJzdExldHRlcih2KSldO1xuICAgICAgICAgICAgaWYgKGV2ZW50ICYmIHR5cGVvZiBldmVudCA9PT0gXCJmdW5jdGlvblwiKSBldmVudC5jYWxsKHRoaXMpO1xuICAgICAgICAgICAgdGhpcy5fc3R5bGVNYW5hZ2VyLnVwZGF0ZSgpO1xuICAgICAgICB9XG4gICAgICAgIGdldCB0b25lKCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3RvbmU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ICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgICBnZXQgX3Byb3RvdHlwZUNoYWluKCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX19wcm90b3R5cGVDaGFpbikgcmV0dXJuIHRoaXMuX19wcm90b3R5cGVDaGFpbjtcbiAgICAgICAgICAgIHZhciBwcm90b3R5cGVDaGFpbiA9IG5ldyBTZXQ7XG4gICAgICAgICAgICB2YXIgcHJvdG8gPSB0aGlzO1xuICAgICAgICAgICAgZG8ge1xuICAgICAgICAgICAgICAgIHByb3RvID0gT2JqZWN0LmdldFByb3RvdHlwZU9mKHByb3RvKTtcbiAgICAgICAgICAgICAgICBpZiAobnVsbCAhPT0gcHJvdG8gJiYgdHlwZW9mIHByb3RvID09PSBcIm9iamVjdFwiKSB7XG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAocHJvdG8uY29uc3RydWN0b3IuX19jb21wb25lbnROYW1lKSBwcm90b3R5cGVDaGFpbi5hZGQocHJvdG8uY29uc3RydWN0b3IuX19jb21wb25lbnROYW1lKTtcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyb3IpIHt9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSB3aGlsZSAocHJvdG8pO1xuICAgICAgICAgICAgdGhpcy5fX3Byb3RvdHlwZUNoYWluID0gcHJvdG90eXBlQ2hhaW47XG4gICAgICAgICAgICByZXR1cm4gcHJvdG90eXBlQ2hhaW47XG4gICAgICAgIH1cbiAgICAgICAgZ2V0IF9leHRlbnNpb25zKCkge1xuICAgICAgICAgICAgdmFyIGV4dGVuc2lvbnMgPSBjb250ZXh0SW5zdGFuY2UgJiYgY29udGV4dEluc3RhbmNlLnRoZW1lICYmIGNvbnRleHRJbnN0YW5jZS50aGVtZS5leHRlbnNpb25zO1xuICAgICAgICAgICAgaWYgKCFleHRlbnNpb25zIHx8ICFBcnJheS5pc0FycmF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HRhcmdldENvbXBvbmVudC5maW5kKChwYXR0ZXJuID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwYXR0ZXJuLnN0YXJ0c1dpdGgoXCIvXCIpICYmIHBhdHRlcm4uZW5kc1dpdGgoXCIvXCIpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdmFyIENvbXBvbmVudFJlZ0V4cCA9IG5ldyBSZWdFeHAocGF0dGVybi5zbGljZSgxLCAtMSkpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBBcnJheS5mcm9tKHRoaXMuX3Byb3RvdHlwZUNoYWluKS5zb21lKChuYW1lID0+IENvbXBvbmVudFJlZ0V4cC50ZXN0KG5hbWUpKSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLl9wcm90b3R5cGVDaGFpbi5oYXMocGF0dGVybik7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgfSkpLnJlZHVjZSgoKGFjYywgX3JlZjEzKSA9PiB7XG4gICAgICAgICAgICAgICAgdmFyIHtleHRlbnNpb246IGV4dGVuc2lvbn0gPSBfcmVmMTM7XG4gICAgICAgICAgICAgICAgYWNjLnB1c2goZXh0ZW5zaW9uKTtcbiAgICAgICAgICAgICAgICByZXR1cm4gYWNjO1xuICAgICAgICAgICAgfSksIFtdKTtcbiAgICAgICAgfVxuICAgICAgICBnZXQgX2V4dGVuc2lvbkFwcGxpZWQoKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fY3VycmVudENvbXBvbmVudEV4dGVuc2lvbkxlbmd0aCA9PT0gdGhpcy5fYXBwbGllZEV4dGVuc2lvbkxlbmd0aDtcbiAgICAgICAgfVxuICAgICAgICB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GVkID0ge307XG4gICAgICAgICAgICB2YXIgZXh0ZW5zaW9uT3ZlcnJpZGVzID0gdGhpcy5fY29tcG9uZW50RXh0ZW5zaW9ucy5yZWR1Y2UoKChhY2MsIGV4dGVuc2lvbikgPT4ge1xuICAgICAgICAgICAgICAgIHZhciBleHRlbnNpb25DbGFzcyA9IG5ldyBleHRlbnNpb24oY2xhc3MgRmFrZUNsYXNzIHt9KTtcbiAgICAgICAgICAgICAgICB2YXIgaW5zdGFuY2UgPSBuZXcgZXh0ZW5zaW9uQ2xhc3M7XG4gICAgICAgICAgICAgICAgdmFyIG9yaWdpbmFsQ29tcG9uZW50RGVzY3JpcHRvcnMgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9ycyhPYmplY3QuZ2V0UHJvdG90eXBlT2YoaW5zdGFuY2UpKTtcbiAgICAgICAgICAgICAgICBPYmplY3Qua2V5cyhvcmlnaW5hbENvbXBvbmVudERlc2NyaXB0b3JzKS5mb3JFYWNoKChwcm9wID0+IHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKFsgXCJjb25zdHJ1Y3RvclwiIF0uaW5jbHVkZXMocHJvcCkpIHJldHVybjtcbiAgICAgICAgICAgICAgICAgICAgaWYgKG9yaWdpbmFsQ29tcG9uZW50RGVzY3JpcHRvcnNbcHJvcF0uZ2V0IHx8IG9yaWdpbmFsQ29tcG9uZW50RGVzY3JpcHRvcnNbcHJvcF0uc2V0KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBleHRlbmRlZFtwcm9wXSA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBcImFjY2Vzc29yXCJcbiAgICAgICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgICAgICAgICBhY2NbcHJvcF0gPSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZ2V0OiBmdW5jdGlvbiBnZXQoKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzW3Byb3AgKyBTVUZGSVhdO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgc2V0OiBmdW5jdGlvbiBzZXQodikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzW3Byb3AgKyBTVUZGSVhdID0gdjtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGV4dGVuZGVkW3Byb3BdID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogXCJtZXRob2RcIlxuICAgICAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgICAgICBhY2NbcHJvcF0gPSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdmFsdWUoKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpc1twcm9wICsgU1VGRklYXSAmJiB0aGlzW3Byb3AgKyBTVUZGSVhdKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgICAgIHJldHVybiBhY2M7XG4gICAgICAgICAgICB9KSwge30pO1xuICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnRpZXMoYmFzZVByb3RvLCBleHRlbnNpb25PdmVycmlkZXMpO1xuICAgICAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKGJhc2VQcm90bywgdGhpcyk7XG4gICAgICAgICAgICByZXR1cm4gZXh0ZW5kZWQ7XG4gICAgICAgIH1cbiAgICAgICAgX3NldENvbXBvbmVudEFsaWFzZXMoYWxpYXNPYmopIHtcbiAgICAgICAgICAgIE9iamVjdC5rZXlzKGFsaWFzT2JqKS5mb3JFYWNoKChwcm9wID0+IHtcbiAgICAgICAgICAgICAgICB0aGlzW3Byb3AgKyBTVUZGSVhdID0gdGhpc1twcm9wXTtcbiAgICAgICAgICAgICAgICBpZiAoYWxpYXNPYmpbcHJvcF0udHlwZSA9PT0gXCJtZXRob2RcIikge1xuICAgICAgICAgICAgICAgICAgICB0aGlzW3Byb3BdID0gdGhpcy5fZXh0ZW5zaW9uSW5zdGFuY2VbcHJvcF07XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChhbGlhc09ialtwcm9wXS50eXBlID09PSBcImFjY2Vzc29yXCIpIHtcbiAgICAgICAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsIHByb3AsIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGdldCgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5fZXh0ZW5zaW9uSW5zdGFuY2VbcHJvcF07XG4gICAgICAgICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgICAgICAgc2V0KHYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9leHRlbnNpb25JbnN0YW5jZVtwcm9wXSA9IHY7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgfVxuICAgIH07XG59XG5cbmNsYXNzIEJhc2UgZXh0ZW5kcyBsbmcuQ29tcG9uZW50IHtcbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiQmFzZVwiO1xuICAgIH1cbiAgICBfY29uc3RydWN0KCkge1xuICAgICAgICB0aGlzLmNvbnN0cnVjdG9yLl9fY29tcG9uZW50T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WxzLmlzUFM0KSB7XG4gICAgICAgIGltYWdlLmNyb3NzT3JpZ2luID0gXCJBbm9ueW1vdXNcIjtcbiAgICB9XG4gICAgaW1hZ2Uub25lcnJvciA9IGZ1bmN0aW9uKCkge1xuICAgICAgICBpZiAoaW1hZ2Uuc3JjKSB7XG4gICAgICAgICAgICByZXR1cm4gY2IoXCJJbWFnZSBsb2FkIGVycm9yXCIpO1xuICAgICAgICB9XG4gICAgfTtcbiAgICBpbWFnZS5vbmxvYWQgPSBmdW5jdGlvbigpIHtcbiAgICAgICAgY2IobnVsbCwge1xuICAgICAgICAgICAgc291cmNlOiBpbWFnZSxcbiAgICAgICAgICAgIHJlbmRlckluZm86IHtcbiAgICAgICAgICAgICAgICBzcmM6IHNyYyxcbiAgICAgICAgICAgICAgICBjb21wcmVzc2VkOiBmYWxzZVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGhhc0FscGhhOiB0cnVlXG4gICAgICAgIH0pO1xuICAgIH07XG4gICAgaW1hZ2Uuc3JjID0gc3JjO1xuICAgIHJldHVybiBmdW5jdGlvbigpIHtcbiAgICAgICAgaW1hZ2Uub25lcnJvciA9IG51bGw7XG4gICAgICAgIGltYWdlLm9ubG9hZCA9IG51bGw7XG4gICAgICAgIGltYWdlLnJlbW92ZUF0dHJpYnV0ZShcInNyY1wiKTtcbiAgICB9O1xufVxuXG5jbGFzcyBDdXN0b21JbWFnZVRleHR1cmUgZXh0ZW5kcyBsbmcuVGV4dHVyZSB7XG4gICAgY29uc3RydWN0b3Ioc3RhZ2UpIHtcbiAgICAgICAgc3VwZXIoc3RhZ2UpO1xuICAgICAgICB0aGlzLl9zcmMgPSB1bmRlZmluZWQ7XG4gICAgICAgIHRoaXMuX2hhc0FscGhhID0gZmFsc2U7XG4gICAgfVxuICAgIGdldCBzcmMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9zcmM7XG4gICAgfVxuICAgIHNldCBzcmModikge1xuICAgICAgICBpZiAodGhpcy5fc3JjICE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gICAgICAgdmFyIGZjID0gc3JjLmNoYXJDb2RlQXQoMCk7XG4gICAgICAgICAgICBpZiAoc3JjLmluZGV4T2YoXCIvL1wiKSA9PT0gLTEgJiYgKGZjID49IDY1ICYmIGZjIDw9IDkwIHx8IGZjID49IDk3ICYmIGZjIDw9IDEyMiB8fCBmYyA9PSA0NikpIHtcbiAgICAgICAgICAgICAgICBzcmMgPSB0aGlzLnN0YWdlLmdldE9wdGlvbihcInNyY0Jhc2VQYXRoXCIpICsgc3JjO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBjYiA9PiB7XG4gICAgICAgICAgICB2YXIgZmlsZVR5cGUgPSBjaGVja0ZpbGVUeXBlKHNyYyk7XG4gICAgICAgICAgICBzd2l0Y2ggKGZpbGVUeXBlKSB7XG4gICAgICAgICAgICAgIGNhc2UgXCJTVkdcIjpcbiAgICAgICAgICAgICAgICByZXR1cm4gY3JlYXRlU3ZnKGNiLCB0aGlzLnN0YWdlLCBcImRhdGE6aW1hZ2Uvc3ZnK3htbCxcIi5jb25jYXQoZW5jb2RlVVJJQ29tcG9uZW50KHNyYykpLCB3LCBoKTtcblxuICAgICAgICAgICAgICBjYXNlIFwiQmxvYlwiOlxuICAgICAgICAgICAgICAgIHJldHVybiBpbWFnZUxvYWRlcih7XG4gICAgICAgICAgICAgICAgICAgIHNyYzogc3JjXG4gICAgICAgICAgICAgICAgfSwgY2IpO1xuXG4gICAgICAgICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuc3RhZ2UucGxhdGZvcm0ubG9hZFNyY1RleHR1cmUoe1xuICAgICAgICAgICAgICAgICAgICBzcmM6IHNyYyxcbiAgICAgICAgICAgICAgICAgICAgaGFzQWxwaGE6IGhhc0FscGhhXG4gICAgICAgICAgICAgICAgfSwgY2IpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBnZXROb25EZWZhdWx0cygpIHtcbiA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dXJyOiBcImZvcmVncm91bmRIZWlnaHRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBwcmV2OiBcImZvcmVncm91bmRXXCIsXG4gICAgICAgICAgICBjdXJyOiBcImZvcmVncm91bmRXaWR0aFwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgc3RhdGljIF90ZW1wbGF0ZSgpIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIHJ0dDogdHJ1ZSxcbiAgICAgICAgICAgIEltYWdlOiB7fVxuICAgICAgICB9O1xuICAgIH1cbiAgICBnZXQgX3Nob3VsZEJsdXIoKSB7XG4gICAgICAgIHZhciBzaG91bGRCdXIgPSB0aGlzLl9ibHVyIHx8IHRoaXMuX2hhc0NlbnRlckltYWdlO1xuICAgICAgICB0aGlzLl9JbWFnZS5ydHQgPSBzaG91bGRCdXI7XG4gICAgICAgIHJldHVybiBzaG91bGRCdXI7XG4gICAgfVxuICAgIGdldCBfaGFzQ2VudGVySW1hZ2UoKSB7XG4gICAgICAgIHJldHVybiAtMSA8IFsgXCJjaXJjbGVcIiwgXCJzcXVhcmVcIiBdLmluZGV4T2YodGhpcy5mb3JtYXQpIHx8IFwiY29udGFpblwiID09PSB0aGlzLmZvcm1hdCAmJiAhdGhpcy5fYXNwZWN0UmF0aW9FcXVhbDtcbiAgICB9XG4gICAgc2V0IHcodikge1xuICAgICAgICBpZiAodiA9PT0gc3VwZXIudykgcmV0dXJuO1xuICAgICAgICBzdXBlci53ID0gdjtcbiAgICAgICAgdGhpcy5fY29tcG9uZW50U3JjID0gdGhpcy5fZ2VuZXJhdGVQcm9taXNlKCk7XG4gICAgfVxuICAgIGdldCB3KCkge1xuICAgICAgICByZXR1cm4gc3VwZXIudztcbiAgICB9XG4gICAgc2V0IGgodikge1xuICAgICAgICBpZiAodiA9PT0gc3VwZXIuaCkgcmV0dXJuO1xuICAgICAgICBzdXBlci5oID0gdjtcbiAgICAgICAgdGhpcy5fY29tcG9uZW50U3JjID0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AgICAgICAgdzogdGhpcy53ICsgNCxcbiAgICAgICAgICAgIHg6IC0yLFxuICAgICAgICAgICAgeTogLTIsXG4gICAgICAgICAgICB6SW5kZXg6IHRoaXMuY29yZS5maW5kWkNvbnRleHQoKS56SW5kZXggKyB0aGlzLnN0eWxlLnpJbmRleFNldC5ncmFkaWVudFxuICAgICAgICB9O1xuICAgIH1cbiAgICBfY29uc3RydWN0KCkge1xuICAgICAgICBzdXBlci5fY29uc3RydWN0KCk7XG4gICAgICAgIHRoaXMuX3NyY0NhbGxiYWNrQXNwZWN0UmF0aW9zID0gWyBcIjE2eDlcIiwgXCIzeDRcIiwgXCI0eDNcIiwgXCIyeDFcIiwgXCIxeDFcIiBdO1xuICAgIH1cbiAgICBfc2V0U3JjKHYpIHtcbiAgICAgICAgdGhpcy5fY29tcG9uZW50U3JjID0gdGhpcy5fZ2VuZXJhdGVQcm9taXNlKCk7XG4gICAgICAgIHJldHVybiB2O1xuICAgIH1cbiAgICBfZ2V0RmFsbGJhY2tTcmMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9mYWxsYmFja1NyYyB8fCB0aGlzLnN0eWxlICYmIHRoaXMuc3R5bGUuZmFsbGJhY2tTcmM7XG4gICAgfVxuICAgIF9nZW5lcmF0ZVByb21pc2UoKSB7XG4gICAgICAgIHZhciByZXNvbHZlUHJvbWlzZSwgcmVqZWN0UHJvbWlzZTtcbiAgICAgICAgdmFyIGNvbXBsZXRlID0gbmV3IFByb21pc2UoKGZ1bmN0aW9uKHJlc29sdmUsIHJlamVjdCkge1xuICAgICAgICAgICAgcmVzb2x2ZVByb21pc2UgPSByZXNvbHZlO1xuICAgICAgICAgICAgcmVqZWN0UHJvbWlzZSA9IHJlamVjdDtcbiAgICAgICAgfSkpO1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgY29tcGxldGU6IGNvbXBsZXRlLFxuICAgICAgICAgICAgcmVzb2x2ZTogcmVzb2x2ZVByb21pc2UsXG4gICAgICAgICAgICBy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O1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB2YXIgX3RoaXM1ID0gdGhpcztcbiAgICAgICAgcmV0dXJuIF9hc3luY1RvR2VuZXJhdG9yKChmdW5jdGlvbiooKSB7XG4gICAgICAgICAgICBfdGhpczUuX3VwZGF0ZVJhZGl1cygpO1xuICAgICAgICAgICAgX3RoaXM1Ll91cGRhdGVHcmFkaWVudCgpO1xuICAgICAgICAgICAgeWllbGQgX3RoaXM1Ll91cGRhdGVJbWFnZSgpO1xuICAgICAgICAgICAgX3RoaXM1Ll91cGRhdGVGaWxsQ29sb3IoKTtcbiAgICAgICAgICAgIF90aGlzNS5fdXBkYXRlRm9yZWdyb3VuZEltYWdlKCk7XG4gICAgICAgICAgICBpZiAoIV90aGlzNS5zcmMpIHtcbiAgICAgICAgICAgICAgICBfdGhpczUuX3Nob3dDb21wb25lbnQoKTtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgIHlpZWxkIF90aGlzNS5fY29tcG9uZW50U3JjLmNvbXBsZXRlO1xuICAgICAgICAgICAgICAgIHlpZWxkIF90aGlzNS5fdXBkYXRlQ2VudGVySW1hZ2UoKTtcbiAgICAgICAgICAgICAgICBfdGhpczUuX3VwZGF0ZUJsdXIoKTtcbiAgICAgICAgICAgICAgICBfdGhpczUuX3Nob3dDb21wb25lbnQoKTtcbiAgICAgICAgICAgICAgICBfdGhpczUuX3VwZGF0ZVNjYWxlKCk7XG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgICAgICAgICAgX3RoaXM1Ll9oYW5kbGVJbWFnZUxvYWRFcnJvcigpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKF90aGlzNS5zaG91bGRTbW9vdGggPT09IHVuZGVmaW5lZCkgX3RoaXM1LnNob3VsZFNtb290aCA9IHRydWU7XG4gICAgICAgIH0pKSgpO1xuICAgIH1cbi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gICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdmFyIGZvcmVncm91bmRJbWFnZVBhdGNoID0ge1xuICAgICAgICAgICAgICAgIG1vdW50OiAuNSxcbiAgICAgICAgICAgICAgICB4OiBfdGhpczYudyAvIDIsXG4gICAgICAgICAgICAgICAgeTogX3RoaXM2LmggLyAyLFxuICAgICAgICAgICAgICAgIHpJbmRleDogX3RoaXM2LmNvcmUuZmluZFpDb250ZXh0KCkuekluZGV4ICsgX3RoaXM2LnN0eWxlLnpJbmRleFNldC5mb3JlZ3JvdW5kLFxuICAgICAgICAgICAgICAgIHRleHR1cmU6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogQ3VzdG9tSW1hZ2VUZXh0dXJlLFxuICAgICAgICAgICAgICAgICAgICBzcmM6IF90aGlzNi5fZm9yZWdyb3VuZFNyYyxcbiAgICAgICAgICAgICAgICAgICAgaGFzQWxwaGE6IHRydWVcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKF90aGlzNi5mb3JlZ3JvdW5kV2lkdGggJiYgX3RoaXM2LmZvcmVncm91bmRIZWlnaHQpIHtcbiAgICAgICAgICAgICAgICBmb3JlZ3JvdW5kSW1hZ2VQYXRjaC5oID0gX3RoaXM2LmZvcmVncm91bmRIZWlnaHQ7XG4gICAgICAgICAgICAgICAgZm9yZWdyb3VuZEltYWdlUGF0Y2gudyA9IF90aGlzNi5mb3JlZ3JvdW5kV2lkdGg7XG4gICAgICAgICAgICAgICAgX3RoaXM2LnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgRm9yZWdyb3VuZEltYWdlOiBmb3JlZ3JvdW5kSW1hZ2VQYXRjaFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChfdGhpczYuZm9yZWdyb3VuZFdpZHRoIHx8IF90aGlzNi5mb3JlZ3JvdW5kSGVpZ2h0KSB7XG4gICAgICAgICAgICAgICAgX3RoaXM2LnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgRm9yZWdyb3VuZEltYWdlOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGZvcmVncm91bmRJbWFnZVBhdGNoKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGFscGhhOiAuMDAxXG4gICAgICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgX3RoaXM2Ll9Gb3JlZ3JvdW5kSW1hZ2Uub25jZShcInR4TG9hZGVkXCIsICgoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBpbWFnZVcgPSBfdGhpczYuX0ZvcmVncm91bmRJbWFnZS50ZXh0dXJlLmdldFJlbmRlcldpZHRoKCk7XG4gICAgICAgICAgICAgICAgICAgIHZhciBpbWFnZUggPSBfdGhpczYuX0ZvcmVncm91bmRJbWFnZS50ZXh0dXJlLmdldFJlbmRlckhlaWdodCgpO1xuICAgICAgICAgICAgICAgICAgICBfdGhpczYuX0ZvcmVncm91bmRJbWFnZS5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgICAgICBhbHBoYTogMSxcbiAgICAgICAgICAgICAgICAgICAgICAgIHc6IF90aGlzNi5mb3JlZ3JvdW5kSGVpZ2h0ID8gX3RoaXM2LmZvcmVncm91bmRIZWlnaHQgKiAoaW1hZ2VXIC8gaW1hZ2VIKSA6IF90aGlzNi5mb3JlZ3JvdW5kV2lkdGgsXG4gICAgICAgICAgICAgICAgICAgICAgICBoOiBfdGhpczYuZm9yZWdyb3VuZFdpZHRoID8gX3RoaXM2LmZvcmVncm91bmRXaWR0aCAqIChpbWFnZUggLyBpbWFnZVcpIDogX3RoaXM2LmZvcmVncm91bmRIZWlnaHRcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgX3RoaXM2LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBGb3JlZ3JvdW5kSW1hZ2U6IGZvcmVncm91bmRJbWFnZVBhdGNoXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSkpKCk7XG4gICAgfVxuICAgIF91cGRhdGVCbHVyKCkge1xuICAgICAgICBpZiAoKCF0aGlzLl9zaG91bGRCbHVyIHx8IHRoaXMuX0ltYWdlICYmIHRoaXMuX0ltYWdlLnRleHR1cmUgJiYgdGhpcy5fSW1hZ2UudGV4dHVyZS5zcmMgPT09IHRoaXMuZmFsbGJhY2tTcmMpICYmIHRoaXMuX0JsdXIpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLnNob3VsZFNtb290aCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX0JsdXIuX2dldFRyYW5zaXRpb24oXCJhbHBoYVwiKS5vbmNlKFwiZmluaXNoXCIsICgoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICAgICAgQmx1cjogdW5kZWZpbmVkXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9CbHVyLnNtb290aCA9IHtcbiAgICAgICAgICAgICAgICAgICAgYWxwaGE6IFsgMCwgdGhpcy5zdHlsZS5hbmltYXRpb25CbHVyRXhpdCBdXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIEJsdXI6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIGlmICghdGhpcy5fc3JjRmFpbGVkICYmIHRoaXMuX3Nob3VsZEJsdXIpIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIEJsdXI6IHtcbiAgICAgICAgICAgICAgICAgICAgYWxwaGE6ICF0aGlzLl9CbHVyICYmIHRoaXMuc2hvdWxkU21vb3RoID8gLjAwMSA6IDEsXG4gICAgICAgICAgICAgICAgICAgIGFtb3VudDogdGhpcy5zdHlsZS5ibHVyLFxuICAgICAgICAgICAgICAgICAgICB6SW5kZXg6IHRoaXMuY29yZS5maW5kWkNvbnRleHQoKS56SW5kZXggKyB0aGlzLnN0eWxlLnpJbmRleFNldC5ibHVyLFxuICAgICAgICAgICAgICAgICAgICBjb250ZW50OiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBJbWFnZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuaCxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0ZXh0dXJlOiB0aGlzLl9JbWFnZS5nZXRUZXh0dXJlKCksXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdzogdGhpcy53XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuaCxcbiAgICAgICAgICAgICAgICAgICAgcnR0OiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICB0eXBlOiBsbmcuY29tcG9uZW50cy5GYXN0Qmx1ckNvbXBvbmVudCxcbiAgICAgICAgICAgICAgICAgICAgdzogdGhpcy53XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICBpZiAodGhpcy5fQmx1ci5hbHBoYSA8IDEpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9CbHVyLnNtb290aCA9IHtcbiAgICAgICAgICAgICAgICAgICAgYWxwaGE6IFsgMSwgdGhpcy5zdHlsZS5hbmltYXRpb25CbHVyRW50cmFuY2UgXVxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZUNlbnRlckltYWdlKCkge1xuICAgICAgICBpZiAodGhpcy5mb3JtYXQgPT09IFwiY29udGFpblwiKSB7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVGb3JtYXRDb250YWluKCk7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5mb3JtYXQgPT09IFwiY2lyY2xlXCIgfHwgdGhpcy5mb3JtYXQgPT09IFwic3F1YXJlXCIpIHtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUZvcm1hdFNxdWFyZUNpcmNsZSgpO1xuICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX0NlbnRlckltYWdlKSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBDZW50ZXJJbWFnZTogdW5kZWZpbmVkXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlRm9ybWF0Q29udGFpbigpIHtcbiAgICAgICAgdmFyIF90aGlzNyA9IHRoaXM7XG4gICAgICAgIHJldHVybiBfYXN5bmNUb0dlbmVyYXRvcigoZnVuY3Rpb24qKCkge1xuICAgICAgICAgICAgaWYgKF90aGlzNy5fQ2VudGVySW1hZ2UgJiYgX3RoaXM3Ll9DZW50ZXJJbWFnZS5tb2RlICE9PSBfdGhpczcuZm9ybWF0IHx8IF90aGlzNy5zcmMgPT09IF90aGlzNy5mYWxsYmFja1NyYyB8fCBfdGhpczcuX2FzcGVjdFJhdGlvRXF1YWwpIHtcbiAgICAgICAgICAgICAgICBfdGhpczcucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICBDZW50ZXJJbWFnZTogdW5kZWZpbmVkXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgaWYgKF90aGlzNy5zcmMgPT09IF90aGlzNy5mYWxsYmFja1NyYyB8fCBfdGhpczcuX2FzcGVjdFJhdGlvRXF1YWwpIHtcbiAgICAgICAgICAgICAgICAgICAgX3RoaXM3Ll9JbWFnZS5hbHBoYSA9IDE7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgaW1hZ2VXO1xuICAgICAgICAgICAgdmFyIGltYWdlSDtcbiAgICAgICAgICAgIHZhciByYXRpb1cgPSBNYXRoLmFicyhfdGhpczcuX0ltYWdlLnRleHR1cmUuc291cmNlLncgLyBfdGhpczcuX0ltYWdlLnRleHR1cmUuc291cmNlLmgpO1xuICAgICAgICAgICAgdmFyIHJhdGlvSCA9IE1hdGguYWJzKF90aGlzNy5fSW1hZ2UudGV4dHVyZS5zb3VyY2UuaCAvIF90aGlzNy5fSW1hZ2UudGV4dHVyZS5zb3VyY2Uudyk7XG4gICAgICAgICAgICBpZiAoX3RoaXM3Ll9JbWFnZS50ZXh0dXJlLnNvdXJjZS53IDwgX3RoaXM3Ll9JbWFnZS50ZXh0dXJlLnNvdXJjZS5oKSB7XG4gICAgICAgICAgICAgICAgaWYgKF90aGlzNy5oICogcmF0aW9XIDwgX3RoaXM3LncpIHtcbiAgICAgICAgICAgICAgICAgICAgaW1hZ2VXID0gX3RoaXM3LmggKiByYXRpb1c7XG4gICAgICAgICAgICAgICAgICAgIGltYWdlSCA9IF90aGlzNy5oO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGltYWdlVyA9IF90aGlzNy53O1xuICAgICAgICAgICAgICAgICAgICBpbWFnZUggPSBfdGhpczcudyAqIHJhdGlvSDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2UgaWYgKF90aGlzNy5fSW1hZ2UudGV4dHVyZS5zb3VyY2UudyA+IF90aGlzNy5fSW1hZ2UudGV4dHVyZS5zb3VyY2UuaCkge1xuICAgICAgICAgICAgICAgIGlmIChfdGhpczcudyAqIHJhdGlvSCA8IF90aGlzNy5oKSB7XG4gICAgICAgICAgICAgICAgICAgIGltYWdlVyA9IF90aGlzNy53O1xuICAgICAgICAgICAgICAgICAgICBpbWFnZUggPSBfdGhpczcudyAqIHJhdGlvSDtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBpbWFnZVcgPSBfdGhpczcuaCAqIHJhdGlvVztcbiAgICAgICAgICAgICAgICAgICAgaW1hZ2VIID0gX3RoaXM3Lmg7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBpbWFnZVcgPSBNYXRoLm1pbihfdGhpczcudywgX3RoaXM3LmgpO1xuICAgICAgICAgICAgICAgIGltYWdlSCA9IGltYWdlVztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBzcmMgPSB5aWVsZCBfdGhpczcuX3Byb2Nlc3NlZEltYWdlU3JjO1xuICAgICAgICAgICAgX3RoaXM3LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBDZW50ZXJJbWFnZToge1xuICAgICAgICAgICAgICAgICAgICBmb3JtYXQ6IF90aGlzNy5mb3JtYXQsXG4gICAgICAgICAgICAgICAgICAgIG1vdW50OiAuNSxcbiAgICAgICAgICAgICAgICAgICAgdzogaW1hZ2VXLFxuICAgICAgICAgICAgICAgICAgICBoOiBpbWFnZUgsXG4gICAgICAgICAgICAgICAgICAgIHg6IF90aGlzNy53IC8gMixcbiAgICAgICAgICAgICAgICAgICAgeTogX3RoaXM3LmggLyAyLFxuICAgICAgICAgICAgICAgICAgICB6SW5kZXg6IF90aGlzNy5jb3JlLmZpbmRaQ29udGV4dCgpLnpJbmRleCArIF90aGlzNy5zdHlsZS56SW5kZXhTZXQuY2VudGVySW1hZ2UsXG4gICAgICAgICAgICAgICAgICAgIHRleHR1cmU6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHNyYzogc3JjLFxuICAgICAgICAgICAgICAgICAgICAgICAgcmVzaXplTW9kZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGg6IGltYWdlSCxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBcImNvdmVyXCIsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdzogaW1hZ2VXXG4gICAgICAgICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogQ3VzdG9tSW1hZ2VUZXh0dXJlXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSkpKCk7XG4gICAgfVxuICAgIF91cGRhdGVGb3JtYXRTcXVhcmVDaXJjbGUoKSB7XG4gICAgICAgIGlmICh0aGlzLl9DZW50ZXJJbWFnZSAmJiB0aGlzLl9DZW50ZXJJbWFnZS5tb2RlICE9PSB0aGlzLmZvcm1hdCB8fCB0aGlzLnNyYyA9PT0gdGhpcy5mYWxsYmFja1NyYykge1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgQ2VudGVySW1hZ2U6IHVuZGVmaW5lZFxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICBpZiAodGhpcy5zcmMgPT09IHRoaXMuZmFsbGJhY2tTcmMpIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICB2YXIgaW1hZ2VTaXplID0gTWF0aC5taW4odGhpcy53LCB0aGlzLmgpIC0gdGhpcy5zdHlsZS5wYWRkaW5nICogMjtcbiAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICBDZW50ZXJJbWFnZToge1xuICAgICAgICAgICAgICAgIGZvcm1hdDogdGhpcy5mb3JtYXQsXG4gICAgICAgICAgICAgICAgaDogaW1hZ2VTaXplLFxuICAgICAgICAgICAgICAgIHNoYWRlcjoge1xuICAgICAgICAgICAgICAgICAgICByYWRpdXM6IFwiY2lyY2xlXCIgPT09IHRoaXMuZm9ybWF0ID8gaW1hZ2VTaXplIC8gMiA6IHRoaXMuc3R5bGUuY2VudGVySW1hZ2VSYWRpdXMsXG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IGxuZy5zaGFkZXJzLlJvdW5kZWRSZWN0YW5nbGVcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIHc6IGltYWdlU2l6ZSxcbiAgICAgICAgICAgICAgICB6SW5kZXg6IHRoaXMuY29yZS5maW5kWkNvbnRleHQoKS56SW5kZXggKyB0aGlzLnN0eWxlLnpJbmRleFNldC5jZW50ZXJJbWFnZSxcbiAgICAgICAgICAgICAgICBJbWFnZToge1xuICAgICAgICAgICAgICAgICAgICBoOiBpbWFnZVNpemUsXG4gICAgICAgICAgICAgICAgICAgIG1vdW50OiAuNSxcbiAgICAgICAgICAgICAgICAgICAgcnR0OiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICB3OiBpbWFnZVNpemUsXG4gICAgICAgICAgICAgICAgICAgIHg6IHRoaXMudyAvIDIsXG4gICAgICAgICAgICAgICAgICAgIHk6IHRoaXMuaCAvIDIsXG4gICAgICAgICAgICAgICAgICAgIHRleHR1cmU6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHNyYzogdGhpcy5fSW1hZ2UudGV4dHVyZS5zcmMsXG4gICAgICAgICAgICAgICAgICAgICAgICByZXNpemVNb2RlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaDogaW1hZ2VTaXplLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFwiY292ZXJcIixcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB3OiBpbWFnZVNpemVcbiAgICAgICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBDdXN0b21JbWFnZVRleHR1cmVcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVHcmFkaWVudCgpIHtcbiAgICAgICAgaWYgKCF0aGlzLmdyYWRpZW50KSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fR3JhZGllbnQpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5zaG91bGRTbW9vdGgpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fR3JhZGllbnQuX2dldFRyYW5zaXRpb24oXCJhbHBoYVwiKS5vbmNlKFwiZmluaXNoXCIsICgoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgdHJhbnNpdGlvbiA9IHRoaXMuX0dyYWRpZW50ICYmIHRoaXMuX0dyYWRpZW50Ll9nZXRUcmFuc2l0aW9uKFwiYWxwaGFcIik7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXRoaXMuZ3JhZGllbnQgJiYgdHJhbnNpdGlvbiAmJiB0cmFuc2l0aW9uLnAgPT09IDEpIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIEdyYWRpZW50OiB1bmRlZmluZWRcbiAgICAgICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX0dyYWRpZW50LnBhdGNoKHRoaXMuX2dyYWRpZW50UGF0Y2gpO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9HcmFkaWVudC5zbW9vdGggPSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBhbHBoYTogWyAwLCB0aGlzLnN0eWxlLmFuaW1hdGlvbkdyYWRpZW50RXhpdCBdXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgICAgICBHcmFkaWVudDogdW5kZWZpbmVkXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9jcmVhdGVHcmFkaWVudCgpO1xuICAgIH1cbiAgICBfY3JlYXRlR3JhZGllbnQoKSB7XG4gICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgR3JhZGllbnQ6IHRoaXMuX2dyYWRpZW50UGF0Y2hcbiAgICAgICAgfSk7XG4gICAgICAgIGlmICh0aGlzLnNob3VsZFNtb290aCkge1xuICAgICAgICAgICAgdGhpcy5hcHBseVNtb290aCh0aGlzLl9HcmFkaWVudCwge1xuICAgICAgICAgICAgICAgIGFscGhhOiBbIDEsIHRoaXMuc3R5bGUuYW5pbWF0aW9uR3JhZGllbnRFbnRyYW5jZSBdXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlSW1hZ2UoKSB7XG4gICAgICAgIHZhciBfdGhpczggPSB0aGlzO1xuICAgICAgICByZXR1cm4gX2FzeW5jVG9HZW5lcmF0b3IoKGZ1bmN0aW9uKigpIHtcbiAgICAgICAgICAgIF90aGlzOC5fYXNwZWN0UmF0aW9FcXVhbCA9IGZhbHNlO1xuICAgICAgICAgICAgaWYgKCFfdGhpczguX3Byb2Nlc3NlZEltYWdlU3JjKSB7XG4gICAgICAgICAgICAgICAgaWYgKF90aGlzOC5fSW1hZ2UpIHtcbiAgICAgICAgICAgICAgICAgICAgX3RoaXM4Ll9JbWFnZS50ZXh0dXJlID0gdW5kZWZpbmVkO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgc3JjID0geWllbGQgX3RoaXM4Ll9wcm9jZXNzZWRJbWFnZVNyYztcbiAgICAgICAgICAgIF90aGlzOC5fSW1hZ2UucGF0Y2goe1xuICAgICAgICAgICAgICAgIGFscGhhOiBfdGhpczguc3JjICE9PSBfdGhpczguZmFsbGJhY2tTcmMgJiYgKF90aGlzOC5fYmx1ciB8fCBfdGhpczguX2hhc0NlbnRlckltYWdlKSA/IC4wMDEgOiAxLFxuICAgICAgICAgICAgICAgIGg6IF90aGlzOC5oLFxuICAgICAgICAgICAgICAgIHRleHR1cmU6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogQ3VzdG9tSW1hZ2VUZXh0dXJlLFxuICAgICAgICAgICAgICAgICAgICBzcmM6IHNyYyxcbiAgICAgICAgICAgICAgICAgICAgcmVzaXplTW9kZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogXCJjb3ZlclwiLFxuICAgICAgICAgICAgICAgICAgICAgICAgdzogX3RoaXM4LncsXG4gICAgICAgICAgICAgICAgICAgICAgICBoOiBfdGhpczguaFxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICB3OiBfdGhpczgudyxcbiAgICAgICAgICAgICAgICB6SW5kZXg6IF90aGlzOC5jb3JlLmZpbmRaQ29udGV4dCgpLnpJbmRleCArIF90aGlzOC5zdHlsZS56SW5kZXhTZXQuaW1hZ2VcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KSkoKTtcbiAgICB9XG4gICAgX3VwZGF0ZUZpbGxDb2xvcigpIHtcbiAgICAgICAgaWYgKCF0aGlzLmZpbGwpIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIEZpbGxDb2xvcjogdW5kZWZpbmVkXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIEZpbGxDb2xvcjoge1xuICAgICAgICAgICAgICAgICAgICByZWN0OiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLncsXG4gICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuaCxcbiAgICAgICAgICAgICAgICAgICAgY29sb3I6IHRoaXMuc3R5bGUuZmlsbENvbG9yLFxuICAgICAgICAgICAgICAgICAgICB6SW5kZXg6IDVcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlUmFkaXVzKCkge1xuICAgICAgICB0aGlzLnBhdGNoKHRoaXMuc3R5bGUucmFkaXVzID8ge1xuICAgICAgICAgICAgc2hhZGVyOiB7XG4gICAgICAgICAgICAgICAgdHlwZTogbG5nLnNoYWRlcnMuUm91bmRlZFJlY3RhbmdsZSxcbiAgICAgICAgICAgICAgICByYWRpdXM6IGdldE1heFJvdW5kUmFkaXVzKHRoaXMuc3R5bGUucmFkaXVzLCB0aGlzLncsIHRoaXMuaClcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSA6IHtcbiAgICAgICAgICAgIHNoYWRlcjogdW5kZWZpbmVkXG4gICAgICAgIH0pO1xuICAgIH1cbn1cblxudmFyIHRvbmUkbyA9IHRoZW1lID0+ICh7XG4gICAgbmV1dHJhbDoge1xuICAgICAgICBjb2xvcjogdGhlbWUuY29sb3IuZmlsbE5ldXRyYWxcbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgY29sb3I6IHRoZW1lLmNvbG9yLmZpbGxJbnZlcnNlXG4gICAgfSxcbiAgICBicmFuZDoge1xuICAgICAgICBjb2xvcjogdGhlbWUuY29sb3IuZmlsbEJyYW5kXG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMkUSA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICB0b25lOiB0b25lJG9cbn0pO1xuXG5jbGFzcyBJY29uIGV4dGVuZHMgQmFzZSQxIHtcbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiSWNvblwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRRO1xuICAgIH1cbiA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iYXNlOiBiYXNlJFAsXG4gICAgdG9uZTogdG9uZSRuXG59KTtcblxuY2xhc3MgQmFkZ2UgZXh0ZW5kcyBCYXNlJDEge1xuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBUZXh0OiB7XG4gICAgICAgICAgICAgICAgbW91bnRZOiAuNVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIEljb246IHtcbiAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgIG1vdW50WTogLjUsXG4gICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICBpdGVtQ2hhbmdlZDogXCJfdXBkYXRlTGF5b3V0XCJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJCYWRnZVwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRQO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwidGl0bGVcIiwgXCJpY29uXCIsIFwiaWNvbkFsaWduXCIsIFwiaWNvbldpZHRoXCIsIFwiaWNvbkhlaWdodFwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJCYWNrZ3JvdW5kXCIsIFwiVGV4dFwiLCBcIkljb25cIiBdO1xuICAgIH1cbiAgICBfaW5pdCgpIHtcbiAgICAgICAgdGhpcy5fVGV4dC5vbihcInR4TG9hZGVkXCIsIHRoaXMuX3VwZGF0ZUxheW91dC5iaW5kKHRoaXMpKTtcbiAgICAgICAgc3VwZXIuX2luaXQoKTtcbiAgIC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gIGlmICh0aGlzLl9UZXh0KSB7XG4gICAgICAgICAgICB0aGlzLl9UZXh0LnBhdGNoKHtcbiAgICAgICAgICAgICAgICB0ZXh0OiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUudGV4dFN0eWxlKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dDogdGhpcy50aXRsZSB8fCBcIlwiXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVJY29uKCkge1xuICAgICAgICB0aGlzLl9JY29uLnBhdGNoKHtcbiAgICAgICAgICAgIGljb246IHRoaXMuaWNvbixcbiAgICAgICAgICAgIHc6IHRoaXMuaWNvbldpZHRoLFxuICAgICAgICAgICAgaDogdGhpcy5pY29uSGVpZ2h0LFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICBjb2xvcjogZ2V0SGV4Q29sb3IodGhpcy5zdHlsZS5pY29uQ29sb3IpXG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlV2lkdGgoKSB7XG4gICAgICAgIHZhciB3aWR0aCA9IDA7XG4gICAgICAgIGlmICh0aGlzLnRpdGxlICYmIHRoaXMuaWNvbikge1xuICAgICAgICAgICAgd2lkdGggPSB0aGlzLl9UZXh0LnJlbmRlcldpZHRoICsgdGhpcy5fSWNvbi5maW5hbFcgKyB0aGlzLnN0eWxlLmNvbnRlbnRTcGFjaW5nICsgdGhpcy5zdHlsZS5wYWRkaW5nWCAqIDI7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy50aXRsZSkge1xuICAgICAgICAgICAgd2lkdGggPSB0aGlzLl9UZXh0LnJlbmRlcldpZHRoICsgdGhpcy5zdHlsZS5wYWRkaW5nWCAqIDI7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5pY29uKSB7XG4gICAgICAgICAgICB3aW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B0aGVtZSA9PiAoe1xuICAgIGZvY3VzZWQ6IHtcbiAgICAgICAgdGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHRJbnZlcnNlXG4gICAgICAgIH0sXG4gICAgICAgIGNvbnRlbnRDb2xvcjogdGhlbWUuY29sb3IuZmlsbEludmVyc2UsXG4gICAgICAgIHRvbmU6IHtcbiAgICAgICAgICAgIGludmVyc2U6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgY29udGVudENvbG9yOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGJyYW5kOiB7XG4gICAgICAgICAgICAgICAgY29udGVudENvbG9yOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbFxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfSxcbiAgICBkaXNhYmxlZDoge1xuICAgICAgICB0ZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICB9LFxuICAgICAgICBjb250ZW50Q29sb3I6IHRoZW1lLmNvbG9yLmZpbGxOZXV0cmFsRGlzYWJsZWRcbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyRPID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkTyxcbiAgICBtb2RlOiBtb2RlJGdcbn0pO1xuXG5jbGFzcyBGb2N1c01hbmFnZXIgZXh0ZW5kcyBCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJGb2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ZGVyKCkge31cbiAgICBfZmlyc3RGb2N1c2FibGVJbmRleCgpIHtcbiAgICAgICAgaWYgKCF0aGlzLml0ZW1zLmxlbmd0aCkgcmV0dXJuIDA7XG4gICAgICAgIHZhciBmaXJzdEl0ZW0gPSB0aGlzLml0ZW1zLnJlZHVjZSgoKGFjYywgaXRlbSwgaWR4KSA9PiB7XG4gICAgICAgICAgICBpZiAoIWl0ZW0uc2tpcEZvY3VzKSB7XG4gICAgICAgICAgICAgICAgYWNjLnB1c2goX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBpdGVtKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgb3JpZ2luYWxJZHg6IGlkeFxuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiBhY2M7XG4gICAgICAgIH0pLCBbXSkuc2hpZnQoKTtcbiAgICAgICAgcmV0dXJuIGZpcnN0SXRlbS5vcmlnaW5hbElkeDtcbiAgICB9XG4gICAgX2xhc3RGb2N1c2FibGVJbmRleCgpIHtcbiAgICAgICAgaWYgKCF0aGlzLml0ZW1zLmxlbmd0aCkgcmV0dXJuIDA7XG4gICAgICAgIHZhciBsYXN0SXRlbSA9IHRoaXMuaXRlbXMucmVkdWNlKCgoYWNjLCBpdGVtLCBpZHgpID0+IHtcbiAgICAgICAgICAgIGlmICghaXRlbS5za2lwRm9jdXMpIHtcbiAgICAgICAgICAgICAgICBhY2MucHVzaChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGl0ZW0pLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBvcmlnaW5hbElkeDogaWR4XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgfSksIFtdKS5wb3AoKTtcbiAgICAgICAgcmV0dXJuIGxhc3RJdGVtLm9yaWdpbmFsSWR4O1xuICAgIH1cbiAgICBz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IHRoaXNbbGVuZ3RoRGltZW5zaW9uXSAtIHNjcm9sbE9mZnNldCA+IGVuZE9mTGFzdENoaWxkO1xuICAgICAgICAgICAgICAgIGlmIChjYW5TY3JvbGxUb0NoaWxkKSB7XG4gICAgICAgICAgICAgICAgICAgIGxhc3RTY3JvbGxJbmRleCA9IGk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fbGFzdFNjcm9sbEluZGV4ID0gbGFzdFNjcm9sbEluZGV4O1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9sYXN0U2Nyb2xsSW5kZXggPiB0aGlzLml0ZW1zLmxlbmd0aCkge1xuICAgICAgICAgICAgdGhpcy5fbGFzdFNjcm9sbEluZGV4ID0gdGhpcy5pdGVtcy5sZW5ndGggLSAxO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9jYWxjQ3Jvc3NEaW1lbnNpb25TaXplKGNvbXApIHtcbiAgICAgICAgaWYgKHRoaXMuX2lzUm93KSB7XG4gICAgICAgICAgICByZXR1cm4gZ2V0SChjb21wKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5faXNDb2x1bW4pIHtcbiAgICAgICAgICAgIHJldHVybiBnZXRXKGNvbXApO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9jYWxjQXhpc1Bvc2l0aW9uKGNvbXApIHtcbiAgICAgICAgaWYgKHRoaXMuX2lzUm93KSB7XG4gICAgICAgICAgICByZXR1cm4gZ2V0WChjb21wKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5faXNDb2x1bW4pIHtcbiAgICAgICAgICAgIHJldHVybiBnZXRZKGNvbXApO1xuICAgICAgICB9XG4gICAgfVxuICAgIF90cmFuc2l0aW9uTGlzdGVuZXIoKSB7XG4gICAgICAgI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ByZXYpO1xuICAgICAgICAgICAgdmFyIHNlbGVjdGVkWCA9IHRoaXMuc2VsZWN0ZWQueDtcbiAgICAgICAgICAgIGlmIChfcHJldkluZGV4ID09PSAtMSkge1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChfcHJldkluZGV4ID4gdGhpcy5zZWxlY3RlZEluZGV4KSB7XG4gICAgICAgICAgICAgICAgaXRlbXNDb250YWluZXJYID0gLXNlbGVjdGVkWCArIHRoaXMuaXRlbVBvc1g7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKF9wcmV2SW5kZXggPCB0aGlzLnNlbGVjdGVkSW5kZXgpIHtcbiAgICAgICAgICAgICAgICBpdGVtc0NvbnRhaW5lclggPSB0aGlzLncgLSBzZWxlY3RlZFggLSB0aGlzLnNlbGVjdGVkLnc7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gaXRlbXNDb250YWluZXJYO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0aGlzLl9nZXRTY3JvbGxYKCk7XG4gICAgfVxuICAgIF9nZXRTY3JvbGxYKCkge1xuICAgICAgICBpZiAodGhpcy5fc2VsZWN0ZWRQYXN0QWRkZWQpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9nZXRQcmVwZW5kZWRPZmZzZXQoKTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgaXRlbXNDb250YWluZXJYO1xuICAgICAgICB2YXIgaXRlbUluZGV4ID0gdGhpcy5zZWxlY3RlZEluZGV4IC0gdGhpcy5zY3JvbGxJbmRleDtcbiAgICAgICAgaXRlbUluZGV4ID0gaXRlbUluZGV4IDwgMCA/IDAgOiBpdGVtSW5kZXg7XG4gICAgICAgIGlmIChpdGVtSW5kZXggPT09IHRoaXMuX2ZpcnN0Rm9jdXNhYmxlSW5kZXgoKSkge1xuICAgICAgICAgICAgaXRlbUluZGV4ID0gMDtcbiAgICAgICAgfVxuICAgICAgIC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Agc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkSjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBhbGlhc1N0eWxlcygpIHtcbiAgICAgICAgcmV0dXJuIFsge1xuICAgICAgICAgICAgcHJldjogXCJpY29uSFwiLFxuICAgICAgICAgICAgY3VycjogXCJpY29uSGVpZ2h0XCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgcHJldjogXCJpY29uV1wiLFxuICAgICAgICAgICAgY3VycjogXCJpY29uV2lkdGhcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIF9jb25zdHJ1Y3QoKSB7XG4gICAgICAgIHN1cGVyLl9jb25zdHJ1Y3QoKTtcbiAgICAgICAgdGhpcy5fbWF4TGluZXNTdWZmaXggPSBcIi4uXCI7XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUNvbnRlbnQoKTtcbiAgICAgICAgdGhpcy5fd2FpdEZvckNvbXBvbmVudExvYWQoKTtcbiAgICB9XG4gICAgX3VwZGF0ZUNvbnRlbnQoKSB7XG4gICAgICAgIHRoaXMuY2hpbGRMaXN0LmNsZWFyKCk7XG4gICAgICAgIGlmICh0aGlzLl9zaG91bGRUcnVuY2F0ZSkge1xuICAgICAgICAgICAgdGhpcy5hbHBoYSA9IC4wMDE7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX3BhcnNlZENvbnRlbnQgJiYgdGhpcy5fcGFyc2VkQ29udGVudC5sZW5ndGgpIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIGZsZXg6IHtcbiAgICAgICAgICAgICAgICAgICAgZGlyZWN0aW9uOiBcInJvd1wiLFxuICAgICAgICAgICAgICAgICAgICB3cmFwOiAhIXRoaXMuY29udGVudFdyYXAsXG4gICAgICAgICAgICAgICAgICAgIGp1c3RpZnlDb250ZW50OiB0aGlzLmp1c3RpZnkgIT0gdW5kZWZpbmVkID8gdGhpcy5qdXN0aWZ5IDogdGhpcy5zdHlsZS5qdXN0aWZ5XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB0aGlzLl9wYXJzZWRDb250ZW50LmZvckVhY2goKChpdGVtLCBpbmRleCkgPT4ge1xuICAgICAgICAgICAgICAgIHZhciBpc0xhc3QgPSBpbmRleCA9PT0gdGhpcy5fcGFyc2VkQ29udGVudC5sZW5ndGggLSAxO1xuICAgICAgICAgICAgICAgIHZhciBiYXNlID0ge1xuICAgICAgICAgICAgICAgICAgICBmbGV4SXRlbTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLmNvbnRlbnRQcm9wZXJ0aWVzKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIG1hcmdpbkJvdHRvbTogaXNMYXN0ID8gMCA6IHRoaXMuX21hcmdpbkJvdHRvbSxcbiAgICAgICAgICAgICAgICAgICAgICAgIG1hcmdpblJpZ2h0OiBpc0xhc3QgPyAwIDogdGhpcy5jb250ZW50UHJvcGVydGllcy5tYXJnaW5SaWdodCB8fCB0aGlzLnN0eWxlLmNvbnRlbnRTcGFjaW5nXG4gICAgICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICBpZiAoaXNUZXh0KGl0ZW0pKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBuZXh0SXRlbSA9IHRoaXMuX3BhcnNlZENvbnRlbnRbaW5kZXggKyAxXTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKG5leHRJdGVtICYmIGlzVGV4dChuZXh0SXRlbSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGJhc2UuZmxleEl0ZW0ubWFyZ2luUmlnaHQgPSAwO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmEodGhpcy5fY3JlYXRlVGV4dChiYXNlLCBpdGVtKSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChpc0ljb24oaXRlbSkpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QuYSh0aGlzLl9jcmVhdGVJY29uKGJhc2UsIGl0ZW0pKTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGlzQmFkZ2UoaXRlbSkpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QuYSh0aGlzLl9jcmVhdGVCYWRnZShiYXNlLCBpdGVtLmJhZGdlKSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChpdGVtLm5ld2xpbmUgJiYgdGhpcy5jb250ZW50V3JhcCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmNoaWxkTGlzdC5hKHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGg6IDAsXG4gICAgICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLndcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSkpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF93YWl0Rm9yQ29tcG9uZW50TG9hZCgpIHtcbiAgICAgICAgaWYgKHRoaXMuY2hpbGRyZW4ubGVuZ3RoKSB7XG4gICAgICAgICAgICBQcm9taXNlLmFsbCh0aGlzLmNoaWxkcmVuLm1hcCgoY2hpbGQgPT4gbmV3IFByb21pc2UoKHJlc29sdmUgPT4ge1xuICAgICAgICAgICAgICAgIGlmIChjaGlsZC5oID09PSAwICYmIGNoaWxkLncgPT09IHRoaXMudykge1xuICAgICAgICAgICAgICAgICAgICByZXNvbHZlKCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgY2hpbGQub24oXCJ0eExvYWRlZFwiLCByZXNvbHZlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KSkpKSkuZmluYWxseSgoKCkgPT4gdGhpcy5fY29udGVudExvYWRlZCgpKSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLmggPSAwO1xuICAgICAgICAgICAgdGhpcy5fY29udGVudExvYWRlZCgpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9ub3RpZnlBbmNlc3RvcnMoKSB7XG4gICAgICAgIHRoaXMuZmlyZUFuY2VzdG9ycyhcIiRsb2FkZWRJbmxpbmVDb250ZW50XCIsIHRoaXMpO1xuICAgICAgICB0aGlzLnNpZ25hbChcImxvYWRlZElubGluZUNvbnRlbnRcIiwgdGhpcy5maW5hbFcsIHRoaXMubXVsdGlMaW5lSGVpZ2h0KTtcbiAgICB9XG4gICAgX2NvbnRlbnRMb2FkZWQoKSB7XG4gICAgICAgIGlmICh0aGlzLmNoaWxkcmVuLmxlbmd0aCkge1xuICAgICAgICAgICAgc2V0VGltZW91dCgoKCkgPT4ge1xuICAgICAgICAgICAgICAgIHRoaXMubXVsdGlMaW5lSGVpZ2h0ID0gdGhpcy5maW5hbEg7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuZmxleCAmJiB0aGlzLmZsZXguX2xheW91dCAmJiB0aGlzLmZsZXguX2xheW91dC5fbGluZUxheW91dGVyICYmIHRoaXMuZmxleC5fbGF5b3V0Ll9saW5lTGF5b3V0ZXIuX2xpbmVzKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciB0b3RhbEhlaWdodCA9IDA7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZmxleC5fbGF5b3V0Ll9saW5lTGF5b3V0ZXIuX2xpbmVzLmZvckVhY2goKGxpbmUgPT4ge1xuICAgICAgICAgICAgICAgICAgICAgICAgdG90YWxIZWlnaHQgKz0gT2JqZWN0LmVudHJpZXMobGluZS5pdGVtcykuc29ydCgoKGEsIGIpID0+IGJbMV0uaCAtIGFbMV0uaCkpWzBdWzFdLmg7XG4gICAgICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5tdWx0aUxpbmVIZWlnaHQgPSB0b3RhbEhlaWdodDtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuX3Nob3VsZFRydW5jYXRlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZW5kZXJNYXhMaW5lcygpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX25vdGlmeUFuY2VzdG9ycygpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2NvbnRlbnRMb2FkZWQoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KSwgMTApO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fbm90aWZ5QW5jZXN0b3JzKCk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3JlbmRlck1heExpbmVzKCkge1xuICAgICAgICB2YXIgY2hpbGRyZW5EaW1lbnNpb25zID0gdGhpcy5fY2FsY0NoaWxkcmVuRGltZW5zaW9ucygpO1xuICAgICAgICB0aGlzLmNoaWxkTGlzdC5jbGVhcigpO1xuICAgICAgICB2YXIgcmVuZGVyZWRMYXN0RWxlbWVudCA9IGZhbHNlO1xuICAgICAgICBjaGlsZHJlbkRpbWVuc2lvbnMuZm9yRWFjaCgoKGNoaWxkLCBpbmRleCkgPT4ge1xuICAgICAgICAgICAgaWYgKHJlbmRlcmVkTGFzdEVsZW1lbnQpIHtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgbmV4dENoaWxkID0gY2hpbGRyZW5EaW1lbnNpb25zW2luZGV4ICsgMV07XG4gICAgICAgICAgICBpZiAoIW5leHRDaGlsZCkge1xuICAgICAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmFkZChjaGlsZC5jb21wb25lbnQpO1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBpc09uTGFzdExpbmUgPSBjaGlsZC5saW5lID09PSB0aGlzLm1heExpbmVzO1xuICAgICAgICAgICAgdmFyIGlzTGFzdEJlZm9yZU1heExpbmVzID0gaXNPbkxhc3RMaW5lICYmIG5leHRDaGlsZC5saW5lID4gdGhpcy5tYXhMaW5lcztcbiAgICAgICAgICAgIHZhciBjYW5SZW5kZXJMYXN0V2l0aFN1ZmZpeCA9IGlzTGFzdEJlZm9yZU1heExpbmVzICYmIGNoaWxkLmhhc1NwYWNlRm9yU3VmZml4O1xuICAgICAgICAgICAgdmFyIGlzTGFzdFdpdGhTcGFjZUZvclN1ZmZpeCA9IGlzT25MYXN0TGluZSAmJiBjaGlsZC5oYXNTcGFjZUZvclN1ZmZpeCAmJiAhbmV4dENoaWxkLmhhc1NwYWNlRm9yU3VmZml4O1xuICAgICAgICAgICAgdmFyIGlzTGFzdCA9ICFuZXh0Q2hpbGQgfHwgY2FuUmVuZGVyTGFzdFdpdGhTdWZmaXggfHwgaXNMYXN0V2l0aFNwYWNlRm9yU3VmZml4O1xuICAgICAgICAgICAgaWYgKGNoaWxkLmxpbmUgPD0gdGhpcy5tYXhMaW5lcykge1xuICAgICAgICAgICAgICAgIGlmIChpc0xhc3QgJiYgaW5kZXggIT09IGNoaWxkcmVuRGltZW5zaW9ucy5sZW5ndGggLSAxKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuY2hpbGRMaXN0LmFkZCh0aGlzLl9hZGRTdWZmaXgoY2hpbGQpKTtcbiAgICAgICAgICAgICAgICAgICAgcmVuZGVyZWRMYXN0RWxlbWVudCA9IHRydWU7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QuYWRkKGNoaWxkLmNvbXBvbmVudCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KSk7XG4gICAgICAgIHRoaXMuYWxwaGEgPSAxO1xuICAgIH1cbiAgICBfY2FsY0NoaWxkcmVuRGltZW5zaW9ucygpIHtcbiAgICAgICAgdmFyIHN1ZmZpeFcgPSBtZWFzdXJlVGV4dFdpZHRoKF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS50ZXh0U3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgdGV4dDogdGhpcy5tYXhMaW5lc1N1ZmZpeFxuICAgICAgICB9KSk7XG4gICAgICAgIHZhciBjb250ZW50RW5kWCA9IDA7XG4gICAgICAgIHZhciBsaW5lID0gMTtcbiAgICAgICAgcmV0dXJuIHRoaXMuY2hpbGRyZW4ucmVkdWNlKCgoYWNjLCBjaGlsZCkgPT4ge1xuICAgICAgICAgICAgdmFyIGNvbXBvbmVudCA9IGNoaWxkO1xuICAgICAgICAgICAgdmFyIHR5cGUsIGNvbnRlbnQsIHc7XG4gICAgICAgICAgICB2YXIgaXNOZXdMaW5lRWxlbWVudCA9IGNoaWxkLncgPT0gdGhpcy53ICYmIGNoaWxkLmggPT09IDA7XG4gICAgICAgICAgICBpZiAoaXNOZXdMaW5lRWxlbWVudCkge1xuICAgICAgICAgICAgICAgIGxpbmUrKztcbiAgICAgICAgICAgICAgICBjb250ZW50RW5kWCA9IDA7XG4gICAgICAgICAgICAgICAgdmFyIF9kYXRhID0ge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBcImxpbmVicmVha1wiLFxuICAgICAgICAgICAgICAgICAgICBjb21wb25lbnQ6IGNvbXBvbmVudCxcbiAgICAgICAgICAgICAgICAgICAgY29udGVudDogY29udGVudCxcbiAgICAgICAgICAgICAgICAgICAgbGluZTogbGluZSxcbiAgICAgICAgICAgICAgICAgICAgaGFzU3BhY2VGb3JTdWZmaXg6IHRydWVcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgIGFjYy5wdXNoKF9kYXRhKTtcbiAgICAgICAgICAgICAgICByZXR1cm4gYWNjO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKGlzVGV4dChjaGlsZCkpIHtcbiAgICAgICAgICAgICAgICB0eXBlID0gXCJ0ZXh0XCI7XG4gICAgICAgICAgICAgICAgY29udGVudCA9IGNoaWxkLnRleHQudGV4dDtcbiAgICAgICAgICAgICAgICB3ID0gY2hpbGQudGV4dHVyZS5nZXRSZW5kZXJXaWR0aCgpO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChpc0ljb24oY2hpbGQpKSB7XG4gICAgICAgICAgICAgICAgdHlwZSA9IFwiaWNvblwiO1xuICAgICAgICAgICAgICAgIHcgPSBjaGlsZC53O1xuICAgICAgICAgICAgfSBlbHNlIGlmIChjaGlsZC5jb25zdHJ1Y3Rvci5fX2NvbXBvbmVudE5hbWUgPT09IFwiQmFkZ2VcIikge1xuICAgICAgICAgICAgICAgIHR5cGUgPSBcImJhZGdlXCI7XG4gICAgICAgICAgICAgICAgdyA9IGNoaWxkLnc7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjb250ZW50RW5kWCArPSB3O1xuICAgICAgICAgICAgY29udGVudEVuZFggKz0gY2hpbGQuZmxleEl0ZW0ubWFyZ2luUmlnaHQ7XG4gICAgICAgICAgICBpZiAoTWF0aC5jZWlsKGNvbnRlbnRFbmRYKSA+PSB0aGlzLncpIHtcbiAgICAgICAgICAgICAgICBsaW5lKys7XG4gICAgICAgICAgICAgICAgY29udGVudEVuZFggPSB3O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdmFyIGhhc1NwYWNlRm9yU3VmZml4ID0gTWF0aC5jZWlsKGNvbnRlbnRFbmRYKSArIHN1ZmZpeFcgPD0gdGhpcy53O1xuICAgICAgICAgICAgdmFyIGRhdGEgPSB7XG4gICAgICAgICAgICAgICAgdHlwZTogdHlwZSxcbiAgICAgICAgICAgICAgICBjb21wb25lbnQ6IGNvbXBvbmVudCxcbiAgICAgICAgICAgICAgICBjb250ZW50OiBjb250ZW50LFxuICAgICAgICAgICAgICAgIGxpbmU6IGxpbmUsXG4gICAgICAgICAgICAgICAgaGFzU3BhY2VGb3JTdWZmaXg6IGhhc1NwYWNlRm9yU3VmZml4XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgYWNjLnB1c2goZGF0YSk7XG4gICAgICAgICAgICByZXR1cm4gYWNjO1xuICAgICAgICB9KSwgW10pO1xuICAgIH1cbiAgICBfYWRkU3VmZml4KF9yZWYxNikge1xuICAgICAgICB2YXIge3R5cGU6IHR5cGUsIGNvbXBvbmVudDogY29tcG9uZW50LCBjb250ZW50OiBjb250ZW50fSA9IF9yZWYxNjtcbiAgICAgICAgdmFyIG5lZ2F0ZWRSaWdodE1hcmdpbiA9IGNvbXBvbmVudC5mbGV4SXRlbS5tYXJnaW5SaWdodCAqIC0xO1xuICAgICAgICB2YXIgc3VmZml4O1xuICAgICAgICBpZiAodHlwZSA9PT0gXCJ0ZXh0XCIpIHtcbiAgICAgICAgICAgIHZhciB7Zm9udEZhY2U6IGZvbnRGYWNlLCBmb250U2l6ZTogZm9udFNpemUsIGZvbnRTdHlsZTogZm9udFN0eWxlLCBsaW5lSGVpZ2h0OiBsaW5lSGVpZ2h0LCB2ZXJ0aWNhbEFsaWduOiB2ZXJ0aWNhbEFsaWdufSA9IGNvbXBvbmVudC50ZXh0O1xuICAgICAgICAgICAgc3VmZml4ID0gdGhpcy5fY3JlYXRlVGV4dCh7XG4gICAgICAgICAgICAgICAgZmxleEl0ZW06IHRoaXMuY29udGVudFByb3BlcnRpZXNcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0ZXh0OiBcIlwiLmNvbmNhdChjb250ZW50LnRyaW0oKSkuY29uY2F0KHRoaXMubWF4TGluZXNTdWZmaXgpLFxuICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIGZvbnRGYWNlOiBmb250RmFjZSxcbiAgICAgICAgICAgICAgICAgICAgZm9udFNpemU6IGZvbnRTaXplLFxuICAgICAgICAgICAgICAgICAgICBmb250U3R5bGU6IGZvbnRTdHlsZSxcbiAgICAgICAgICAgICAgICAgICAgbGluZUhlaWdodDogbGluZUhlaWdodCxcbiAgICAgICAgICAgICAgICAgICAgdmVydGljYWxBbGlnbjogdmVydGljYWxBbGlnblxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5jaGlsZExpc3QuYWRkKGNvbXBvbmVudCk7XG4gICAgICAgICAgICBzdWZmaXggPSB0aGlzLl9jcmVhdGVUZXh0KHtcbiAgICAgICAgICAgICAgICBmbGV4SXRlbTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLmNvbnRlbnRQcm9wZXJ0aWVzKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgbWFyZ2luTGVmdDogbmVnYXRlZFJpZ2h0TWFyZ2luXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH0sIHRoaXMubWF4TGluZXNTdWZmaXgpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBzdWZmaXg7XG4gICAgfVxuICAgIF9jcmVhdGVJY29uKGJhc2UsIGljb25Qcm9wcykge1xuICAgICAgICB2YXIgeSA9ICh0aGlzLnRleHRIZWlnaHQgPiB0aGlzLnN0eWxlLnRleHRTdHlsZS5saW5lSGVpZ2h0ID8gdGhpcy50ZXh0SGVpZ2h0IDogdGhpcy5zdHlsZS50ZXh0U3R5bGUubGluZUhlaWdodCkgLSB0aGlzLnN0eWxlLmljb25IZWlnaHQ7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGJhc2UpLCB7fSwge1xuICAgICAgICAgICAgdHlwZTogSWNvbixcbiAgICAgICAgICAgIHk6IHksXG4gICAgICAgICAgICB3OiB0aGlzLnN0eWxlLmljb25XaWR0aCxcbiAgICAgICAgICA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gKGlzVGV4dChpdGVtKSkge1xuICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgaXRlbSA9PT0gXCJvYmplY3RcIikge1xuICAgICAgICAgICAgICAgICAgICB2YXIgZm9ybWF0dGVkV29yZHMgPSBpdGVtLnRleHQuc3BsaXQod2hpdGVzcGFjZSkubWFwKCh3b3JkID0+IHdvcmQgJiYgX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBpdGVtKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRleHQ6IHdvcmRcbiAgICAgICAgICAgICAgICAgICAgfSkpKTtcbiAgICAgICAgICAgICAgICAgICAgYWNjLnB1c2goLi4uZm9ybWF0dGVkV29yZHMpO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gYWNjO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBwYXJzZWQgPSBpdGVtLnNwbGl0KHdoaXRlc3BhY2UpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgYWNjLnB1c2gocGFyc2VkKTtcbiAgICAgICAgICAgIHJldHVybiBhY2M7XG4gICAgICAgIH0pLCBbXSkpLm1hcCgoKGl0ZW0sIGluZGV4LCBhcnIpID0+IHtcbiAgICAgICAgICAgIGlmIChpdGVtID09PSBcIiBcIikgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgaWYgKGFycltpbmRleCArIDFdID09PSBcIiBcIikgcmV0dXJuIGl0ZW0gKyBcIiBcIjtcbiAgICAgICAgICAgIHJldHVybiBpdGVtO1xuICAgICAgICB9KSkuZmlsdGVyKEJvb2xlYW4pO1xuICAgIH1cbiAgICBfc2V0Q29udGVudChjb250ZW50KSB7XG4gICAgICAgIGlmIChjb250ZW50ICE9PSB0aGlzLl9jb250ZW50KSB7XG4gICAgICAgICAgICB0aGlzLl9jb250ZW50ID0gY29udGVudDtcbiAgICAgICAgICAgIHZhciBwYXJzZWRDb250ZW50ID0gdGhpcy5fY29udGVudDtcbiAgICAgICAgICAgIGlmIChjb250ZW50ICYmICFBcnJheS5pc0FycmF5KGNvbnRlbnQpKSB7XG4gICAgICAgICAgICAgICAgcGFyc2VkQ29udGVudCA9IHBhcnNlSW5saW5lQ29udGVudChjb250ZW50KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX3BhcnNlZENvbnRlbnQgPSB0aGlzLl9mb3JtYXRTcGFjZXMocGFyc2VkQ29udGVudCk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGNvbnRlbnQ7XG4gICAgfVxuICAgIF9zZXRCYWRnZVByb3BlcnRpZXMoYmFkZ2VQcm9wZXJ0aWVzKSB7XG4gICAgICAgIGlmICh0eXBlb2YgYmFkZ2VQcm9wZXJ0aWVzID09PSBcIm9iamVjdFwiKSB7XG4gICAgICAgICAgICByZXR1cm4gYmFkZ2VQcm9wZXJ0aWVzO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9nZXRCYWRnZVByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9iYWRnZVByb3BlcnRpZXMgfHwge307XG4gICAgfVxuICAgIF9zZXRDb250ZW50UHJvcGVydGllcyhjb250ZW50UHJvcGVydGllcykge1xuICAgICAgICBpZiAodHlwZW9mIGNvbnRlbnRQcm9wZXJ0aWVzID09PSBcIm9iamVjdFwiKSB7XG4gICAgICAgICAgICByZXR1cm4gY29udGVudFByb3BlcnRpZXM7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX2dldENvbnRlbnRQcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fY29udGVudFByb3BlcnRpZXMgfHwge307XG4gICAgfVxuICAgIF9zZXRDdXN0b21TdHlsZU1hcHBpbmdzKGN1c3RvbVN0eWxlTWFwcGluZ3MpIHtcbiAgICAgICAgaWYgKHR5cGVvZiBjdXN0b21TdHlsZU1hcHBpbmdzID09PSBcIm9iamVjdFwiKSB7XG4gICAgICAgICAgICByZXR1cm4gY3VzdG9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tcbiAgICAgICAgICAgICAgICBib3VuZHNNYXJnaW46IFtdLFxuICAgICAgICAgICAgICAgIENvbnRlbnRCb3g6IHtcbiAgICAgICAgICAgICAgICAgICAgQ29udGVudDoge30sXG4gICAgICAgICAgICAgICAgICAgIENvbnRlbnRMb29wVGV4dHVyZToge31cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJNYXJxdWVlXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJEk7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJDb250ZW50Q2xpcHBlclwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIkNvbnRlbnRCb3hcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGVudENsaXBwZXIuQ29udGVudEJveFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiQ29udGVudFwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50Q2xpcHBlci5Db250ZW50Qm94LkNvbnRlbnRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIkNvbnRlbnRMb29wVGV4dHVyZVwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50Q2xpcHBlci5Db250ZW50Qm94LkNvbnRlbnRMb29wVGV4dHVyZVwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gWyBcImF1dG9TdGFydFwiLCBcInRpdGxlXCIsIFwiY29udGVudFRleHR1cmVcIiwgXCJjb2xvclwiLCBcImNlbnRlckFsaWduXCIsIFwiZGVsYXlcIiwgXCJyZXBlY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mUoKSB7XG4gICAgICAgIHZhciBjb250ZW50ID0ge1xuICAgICAgICAgICAgcnR0OiB0cnVlXG4gICAgICAgIH07XG4gICAgICAgIGlmICh0aGlzLmNvbnRlbnRUZXh0dXJlKSB7XG4gICAgICAgICAgICBjb250ZW50LnRleHR1cmUgPSB0aGlzLmNvbnRlbnRUZXh0dXJlO1xuICAgICAgICB9IGVsc2UgaWYgKHRoaXMudGl0bGUpIHtcbiAgICAgICAgICAgIGNvbnRlbnQudGV4dCA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlLnRleHRTdHlsZSksIHRoaXMudGl0bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgIHRleHQ6IHRoaXMudGV4dENvbnRlbnRcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgQ29udGVudENsaXBwZXI6IHtcbiAgICAgICAgICAgICAgICB3OiB0aGlzLncgKyAxNCxcbiAgICAgICAgICAgICAgICBDb250ZW50Qm94OiB7XG4gICAgICAgICAgICAgICAgICAgIENvbnRlbnQ6IGNvbnRlbnQsXG4gICAgICAgICAgICAgICAgICAgIENvbnRlbnRMb29wVGV4dHVyZToge31cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgICB0aGlzLnNpZ25hbChcIm1hcnF1ZWVDb250ZW50TG9hZGVkXCIpO1xuICAgIH1cbiAgICBfdXBkYXRlU2hhZGVyKCkge1xuICAgICAgICB0aGlzLl9Db250ZW50Q2xpcHBlci5wYXRjaCh7XG4gICAgICAgICAgICB3OiB0aGlzLncgPiAwID8gdGhpcy53ICsgdGhpcy5zdHlsZS5mYWRlV2lkdGggLyAyIDogMCxcbiAgICAgICAgICAgIHNoYWRlcjoge1xuICAgICAgICAgICAgICAgIHR5cGU6IEZhZGVTaGFkZXIsXG4gICAgICAgICAgICAgICAgcG9zaXRpb25MZWZ0OiAwLFxuICAgICAgICAgICAgICAgIHBvc2l0aW9uUmlnaHQ6IHRoaXMuc3R5bGUuZmFkZVdpZHRoXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgcnR0OiB0cnVlXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlQW5pbWF0aW9uKCkge1xuICAgICAgICB0aGlzLl9zY3JvbGxBbmltYXRpb24gJiYgdGhpcy5fc2Nyb2xsQW5pbWF0aW9uLnN0b3BOb3coKTtcbiAgICAgICAgdGhpcy5fc2Nyb2xsQW5pbWF0aW9uID0gdGhpcy5hbmltYXRpb24oe1xuICAgICAgICAgICAgZHVyYXRpb246IHRoaXMuX2xvb3BXaWR0aCAvIDUwLFxuICAgICAgICAgICAgZGVsYXk6IGlzTmFOKHRoaXMuZGVsYXkpID8gMS41IDogdGhpcy5kZWxheSxcbiAgICAgICAgICAgIHJlcGVhdDogaXNOYU4odGhpcy5yZXBlYXQpID8gLTEgOiB0aGlzLnJlcGVhdCxcbiAgICAgICAgICAgIGFjdGlvbnM6IFsge1xuICAgICAgICAgICAgICAgIHQ6IFwiQ29udGVudEJveFwiLFxuICAgICAgICAgICAgICAgIHA6IFwieFwiLFxuICAgICAgICAgICAgICAgIHY6IHtcbiAgICAgICAgICAgICAgICAgICAgc206IDAsXG4gICAgICAgICAgICAgICAgICAgIDA6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHY6IDBcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgLjU6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHY6IC0odGhpcy5fbG9vcFdpZHRoICsgdGhpcy5zdHlsZS5vZmZzZXQpXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdDogXCJDb250ZW50Q2xpcHBlclwiLFxuICAgICAgICAgICAgICAgIHA6IFwic2hhZGVyLnBvc2l0aW9uTGVmdFwiLFxuICAgICAgICAgICAgICAgIHY6IHtcbiAgICAgICAgICAgICAgICAgICAgc206IDAsXG4gICAgICAgICAgICAgICAgICAgIDA6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHY6IDBcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgLjE6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHY6IHRoaXMuc3R5bGUuZmFkZVdpZHRoXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIC40OiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2OiB0aGlzLnN0eWxlLmZhZGVXaWR0aFxuICAgICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgICAuNToge1xuICAgICAgICAgICAgICAgICAgICAgICAgdjogMFxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBdXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfcG9zaXRpb25UZXh0dXJlKCkge1xuICAgICAgICB2YXIgeCA9IHRoaXMuX3Nob3VsZENlbnRlcigpID8gKHRoaXMudyAtIHRoaXMuX3RleHRSZW5kZXJlZFcpIC8gMiA6IDA7XG4gICAgICAgIGlmICh0aGlzLnN0eWxlLnNob3VsZFNtb290aCkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudEJveC5zbW9vdGggPSB7XG4gICAgICAgICAgICAgICAgeDogeFxuICAgICAgICAgICAgfTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnRCb3gueCA9IHg7XG4gICAgICAgIH1cbiAgICB9XG4gICAgc3RhcnRTY3JvbGxpbmcoKSB7XG4gICAgICAgIHRoaXMuX0NvbnRlbnQub2ZmKFwidHhMb2FkZWRcIiwgdGhpcy5zdGFydFNjcm9sbGluZy5iaW5kKHRoaXMpKTt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gIHRoaXMuaCA9IGhlaWdodDtcbiAgICAgICAgICAgIGlmICghdGhpcy5maXhlZCkge1xuICAgICAgICAgICAgICAgIHRoaXMudyA9IHdpZHRoO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKCF0aGlzLmhpZGVPbkxvYWQgJiYgdGhpcy5hbHBoYSA8IDEpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmFscGhhID0gMTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX25vdGlmeUFuY2VzdG9ycygpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9zZXRDb250ZW50KGNvbnRlbnQpIHtcbiAgICAgICAgdGhpcy5faXNJbmxpbmVDb250ZW50ID0gZmFsc2U7XG4gICAgICAgIGlmIChBcnJheS5pc0FycmF5KGNvbnRlbnQpIHx8IHV0aWxzJDEuaXNNYXJrdXBTdHJpbmcoY29udGVudCkpIHtcbiAgICAgICAgICAgIHRoaXMuX2lzSW5saW5lQ29udGVudCA9IHRydWU7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKFwic3RyaW5nXCIgIT09IHR5cGVvZiBjb250ZW50ICYmICF0aGlzLl9pc0lubGluZUNvbnRlbnQpIHtcbiAgICAgICAgICAgIHJldHVybiBcIlwiO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBjb250ZW50O1xuICAgIH1cbiAgICBnZXQgdGl0bGUoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9jb250ZW50O1xuICAgIH1cbiAgICBfbm90aWZ5QW5jZXN0b3JzKCkge1xuICAgICAgICB2YXIgdyA9IGFyZ3VtZW50cy5sZW5ndGggPiAwICYmIGFyZ3VtZW50c1swXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzBdIDogdGhpcy53O1xuICAgICAgICB2YXIgaCA9IGFyZ3VtZW50cy5sZW5ndGggPiAxICYmIGFyZ3VtZW50c1sxXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzFdIDogdGhpcy5oO1xuICAgICAgICB0aGlzLmZpcmVBbmNlc3RvcnMoXCIkaXRlbUNoYW5nZWRcIik7XG4gICAgICAgIHRoaXMuc2lnbmFsKFwidGV4dEJveENoYW5nZWRcIiwge1xuICAgICAgICAgICAgdzogdyxcbiAgICAgICAgICAgIGg6IGhcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF9jb25zdHJ1Y3QoKSB7XG4gICAgICAgIHN1cGVyLl9jb25zdHJ1Y3QoKTtcbiAgICAgICAgdGhpcy5fbWFycXVlZUNvbnRlbnRMaXN0ZW5lckF0dGFjaGVkID0gZmFsc2U7XG4gICAgICAgIHRoaXMuX21hcnF1ZWVPdmVycmlkZUxvb3BYID0gdW5kZWZpbmVkO1xuICAgICAgICB0aGlzLl9yZXNldE1hcnF1ZWVQcm9taXNlKCk7XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIGlmICghdGhpcy5jb250ZW50KSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fVGV4dCB8fCB0aGlzLl9JbmxpbmVDb250ZW50KSB7XG4gICAgICAgICAgICAgICAgdGhpcy53ID0gdGhpcy5oID0gMDtcbiAgICAgICAgICAgICAgICB0aGlzLl9ub3RpZnlBbmNlc3RvcnMoKTtcbiAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVNYXJxdWVlKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIFRleHQ6IHVuZGVmaW5lZCxcbiAgICAgICAgICAgICAgICAgICAgSW5saW5lQ29udGVudDogdW5kZWZpbmVkXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5faXNJbmxpbmVDb250ZW50ID8gdGhpcy5fdXBkYXRlSW5saW5lQ29udGVudCgpIDogdGhpcy5fdXBkYXRlVGV4dCgpO1xuICAgICAgICB0aGlzLl91cGRhdGVNYXJxdWVlKCk7XG4gICAgfVxuICAgIF91cGRhdGVJbmxpbmVDb250ZW50KCkge1xuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIFRleHQ6IHVuZGVmaW5lZFxuICAgICAgICB9KTtcbiAgICAgICAgdmFyIGlubGluZUNvbnRlbnRQYXRjaCA9IElubGluZUNvbnRlbnQucHJvcGVydGllcy5yZWR1Y2UoKChhY2MsIHByb3ApID0+IHtcbiAgICAgICAgICAgIGlmICh0aGlzW3Byb3BdICE9IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgIGFjY1twcm9wXSA9IHRoaXNbcHJvcF07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gYWNjO1xuICAgICAgICB9KSwge1xuICAgICAgICAgICAgc3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB0aGlzLl90ZXh0U3R5bGVTZXRcbiAgICAgICAgICAgIH0pXG4gICAgICAgIH0pO1xuICAgICAgICBpZiAodGhpcy5fdGV4dFN0eWxlU2V0LndvcmRXcmFwV2lkdGgpIHtcbiAgICAgICAgICAgIGlubGluZUNvbnRlbnRQYXRjaC53ID0gdGhpcy5fdGV4dFN0eWxlU2V0LndvcmRXcmFwV2lkdGg7XG4gICAgICAgICAgICBpbmxpbmVDb250ZW50UGF0Y2gucnR0ID0gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fdGV4dFN0eWxlU2V0Lm1heExpbmVzKSB7XG4gICAgICAgICAgICBpbmxpbmVDb250ZW50UGF0Y2gubWF4TGluZXMgPSB0aGlzLl90ZXh0U3R5bGVTZXQubWF4TGluZXM7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX3RleHRTdHlsZVNldC5tYXhMaW5lc1N1ZmZpeCkge1xuICAgICAgICAgICAgaW5saW5lQ29udGVudFBhdGNoLm1heExpbmVzU3VmZml4ID0gdGhpcy5fdGV4dFN0eWxlU2V0Lm1heExpbmVzU3VmZml4O1xuICAgICAgICB9XG4gICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgYWxwaGE6IDEsXG4gICAgICAgICAgICBJbmxpbmVDb250ZW50OiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgIHR5cGU6IElubGluZUNvbnRlbnQsXG4gICAgICAgICAgICAgICAgdzogdGhpcy53XG4gICAgICAgICAgICB9LCBpbmxpbmVDb250ZW50UGF0Y2gpLCB7fSwge1xuICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgbG9hZGVkSW5saW5lQ29udGVudDogXCJfc2V0RGltZW5zaW9uc1wiXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSlcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVUZXh0KCkge1xuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIElubGluZUNvbnRlbnQ6IHVuZGVmaW5lZFxuICAgICAgICB9KTtcbiAgICAgICAgaWYgKCF0aGlzLl9UZXh0KSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBUZXh0OiB7fVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB0aGlzLl9UZXh0Lm9uKFwidHhMb2FkZWRcIiwgdGhpcy5fc2V0RGltZW5zaW9ucy5iaW5kKHRoaXMpKTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgZm9udFN0eWxlID0gdGhpcy5fdGV4dFN0eWxlU2V0O1xuICAgICAgICBpZiAodGhpcy5fVGV4dCkge1xuICAgICAgICAgICAgdGhpcy5fVGV4dC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgeTogdGhpcy5zdHlsZS5vZmZzZXRZLFxuICAgICAgICAgICAgICAg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IGlmICh0aGlzLl9NYXJxdWVlICYmICF0aGlzLm1hcnF1ZWUpIHtcbiAgICAgICAgICAgIHRoaXMuX3RvZ2dsZU1hcnF1ZWUodGhpcy5fY29udGVudFRhZyk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMubWFycXVlZSkge1xuICAgICAgICAgICAgdGhpcy5fcmVzZXRNYXJxdWVlUHJvbWlzZSgpO1xuICAgICAgICAgICAgdmFyIG1hcnF1ZWVQYXRjaCA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5tYXJxdWVlUHJvcHMpLCB7fSwge1xuICAgICAgICAgICAgICAgIHc6IHRoaXMuX3RleHRTdHlsZVNldC53b3JkV3JhcFdpZHRoIHx8IHRoaXMudyxcbiAgICAgICAgICAgICAgICBoOiB0aGlzLmgsXG4gICAgICAgICAgICAgICAgeTogdGhpcy5zdHlsZS5vZmZzZXRZLFxuICAgICAgICAgICAgICAgIHg6IHRoaXMuc3R5bGUub2Zmc2V0WCxcbiAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIG1hcnF1ZWVDb250ZW50TG9hZGVkOiBcIl9sb2FkZWRNYXJxdWVlQ29udGVudFwiXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICBpZiAoIXRoaXMuX01hcnF1ZWUpIHtcbiAgICAgICAgICAgICAgICBtYXJxdWVlUGF0Y2gudHlwZSA9IE1hcnF1ZWU7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy5faXNJbmxpbmVDb250ZW50KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fSW5saW5lQ29udGVudC53ID0gMDtcbiAgICAgICAgICAgICAgICBtYXJxdWVlUGF0Y2gudGl0bGUgPSB1bmRlZmluZWQ7XG4gICAgICAgICAgICAgICAgbWFycXVlZVBhdGNoLmNvbnRlbnRUZXh0dXJlID0gdGhpcy5fY29udGVudFRhZy5nZXRUZXh0dXJlKCk7XG4gICAgICAgICAgICAgICAgbWFycXVlZVBhdGNoLncgPSB0aGlzLl90ZXh0U3R5bGVTZXQud29yZFdyYXBXaWR0aCB8fCB0aGlzLnc7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIG1hcnF1ZWVQYXRjaC5jb250ZW50VGV4dHVyZSA9IHVuZGVmaW5lZDtcbiAgICAgICAgICAgICAgICBtYXJxdWVlUGF0Y2gudGl0bGUgPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgICAgICB0ZXh0OiB0aGlzLl9jb250ZW50VGFnLnRleHQudGV4dFxuICAgICAgICAgICAgICAgIH0sIHRoaXMuX3RleHRTdHlsZVNldCksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IDAsXG4gICAgICAgICAgICAgICAgICAgIG1heExpbmVzOiAxXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBNYXJxdWVlOiBtYXJxdWVlUGF0Y2hcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9tYXJxdWVlQ29udGVudExpc3RlbmVyQXR0YWNoZWQpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9tYXJxdWVlQ29udGVudExpc3RlbmVyQXR0YWNoZWQgPSB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKFwidW5kZWZpbmVkXCIgIT09IHR5cGVvZiB0aGlzLl9tYXJxdWVlT3ZlcnJpZGVMb29wWCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2F3YWl0TWFycXVlZU92ZXJyaWRlWC50aGVuKCgoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3RvZ2dsZU1hcnF1ZWUodGhpcy5fY29udGV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XCJ0ZXh0XCIgOiBwcm9wO1xuICAgICAgICAgICAgICAgIGZvbnRTdHlsZVtrZXldID0gdGhpc1tcIl9cIi5jb25jYXQocHJvcCldO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KSk7XG4gICAgICAgIGlmICh0aGlzLncgJiYgIXRoaXMuX2lzSW5saW5lQ29udGVudCAmJiAhdGhpcy5zdHlsZS50ZXh0U3R5bGUud29yZFdyYXBXaWR0aCAmJiB0aGlzLmZpeGVkKSB7XG4gICAgICAgICAgICBmb250U3R5bGUud29yZFdyYXBXaWR0aCA9IHRoaXMudztcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZm9udFN0eWxlO1xuICAgIH1cbiAgICBnZXQgX2NvbnRlbnRUYWcoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9pc0lubGluZUNvbnRlbnQgPyB0aGlzLl9JbmxpbmVDb250ZW50IDogdGhpcy5fVGV4dDtcbiAgICB9XG4gICAgX3RvZ2dsZU1hcnF1ZWUoY29udGVudFRhZykge1xuICAgICAgICBpZiAodGhpcy5tYXJxdWVlKSB7XG4gICAgICAgICAgICBpZiAoY29udGVudFRhZykge1xuICAgICAgICAgICAgICAgIGNvbnRlbnRUYWcuYWxwaGEgPSAuMDAxO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRoaXMuX01hcnF1ZWUpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9NYXJxdWVlLmFscGhhID0gMTtcbiAgICAgICAgICAgICAgICB0aGlzLl9NYXJxdWVlLnN0YXJ0U2Nyb2xsaW5nKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAoY29udGVudFRhZykge1xuICAgICAgICAgICAgICAgIGNvbnRlbnRUYWcuYWxwaGEgPSAxO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRoaXMuX01hcnF1ZWUpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9NYXJxdWVlLmFscGhhID0gLjAwMTtcbiAgICAgICAgICAgICAgICB0aGlzLl9NYXJxdWVlLnN0b3BTY3JvbGxpbmcoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbiAgICB0b2dnbGVNYXJxdWVlKCkge1xuICAgICAgICB0aGlzLl90b2dnbGVNYXJxdWVlKHRoaXMuX2NvbnRlbnRUYWcpO1xuICAgIH1cbiAgICBnZXQgYW5ub3VuY2UoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9hbm5vdW5jZSB8fCAodGhpcy5faXNJbmxpbmVDb250ZW50ICYmIHRoaXMuX0lubGluZUNvbnRlbnQgPyB0aGlzLl9JbmxpbmVDb250ZW50LmFubm91bmNlIDogdGhpcy5jb250ZW50KTtcbiAgICB9XG4gICAgc2V0IGFubm91bmNlKGFubm91bmNlKSB7XG4gICAgICAgIHN1cGVyLmFubm91bmNlID0gYW5ub3VuY2U7XG4gICAgfVxuICAgIHNldCBzbW9vdGgodikge1xuICAgICAgICBjb250ZXh0SW5zdGFuY2Uud2FybihcIndhcm5pbmc6IHZhbHVlIHNtb290aGluZyBpcyBrbm93biB0byBjYXVzZSBidWdzIHdpdGggdGhlIFRleHRCb3ggLSBwYXRjaCB1cGRhdGVkIHZhbHVlcyBpbnN0ZWFkLlwiKTtcbiAgICAgICAgc3VwZXIuc21vb3RoID0gdjtcbiAgICB9XG59XG5cbmNsYXNzIEJ1dHRvbiBleHRlbmRzIFN1cmZhY2Uge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJCdXR0b25cIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkTztcbiAgICB9XG4gICAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gWyBcImZpeGVkXCIsIFwianVzdGlmeVwiLCBcInByZWZpeFwiLCBcInN1ZmZpeFwiLCBcInRpdGxlXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBhbGlhc1N0eWxlcygpIHtcbiAgICAgICAgcmV0dXJuIFsge1xuICAgICAgICAgICAgcHJldjogXCJ0aXRsZVBhZGRpbmdcIixcbiAgICAgICAgICAgIGN1cnI6IFwiY29udGVudFNwYWNpbmdcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIudGFncywgXCJDb250ZW50XCIsIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGV4dFdyYXBwZXJcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGVudC5UZXh0V3JhcHBlclwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGl0bGVcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGVudC5UZXh0V3JhcHBlci5UaXRsZVwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiUHJlZml4XCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRlbnQuUHJlZml4XCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJTdWZmaXhcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGVudC5TdWZmaXhcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHN1cGVyLl90ZW1wbGF0ZSgpKSwge30sIHtcbiAgICAgICAgICAgIENvbnRlbnQ6IHtcbiAgICAgICAgICAgICAgICBtb3VudDogLjUsXG4gICAgICAgICAgICAgICAgeDogdyA9PiB3IC8gMixcbiAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyLFxuICAgICAgICAgICAgICAgIHpJbmRleDogMlxuICAgICAg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ID0gdGhpcy5fdGl0bGVYO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLl9oYXNTdWZmaXggJiYgdGhpcy5fU3VmZml4ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIHRoaXMuX1N1ZmZpeC54ID0gdGhpcy5fc3VmZml4WDtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlUHJlZml4KCkge1xuICAgICAgICB2YXIgcHJlZml4U3RyaW5nID0gSlNPTi5zdHJpbmdpZnkodGhpcy5wcmVmaXgpO1xuICAgICAgICBpZiAodGhpcy5wcmVmaXgpIHtcbiAgICAgICAgICAgIHZhciBwcmVmaXhQYXRjaCA9IHtcbiAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICBpdGVtU3BhY2luZzogdGhpcy5zdHlsZS5pdGVtU3BhY2luZ1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICBpZiAoIXRoaXMuX1ByZWZpeCkge1xuICAgICAgICAgICAgICAgIHByZWZpeFBhdGNoID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLl9yb3dQcm9wcyksIHByZWZpeFBhdGNoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgIFByZWZpeDogcHJlZml4UGF0Y2hcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlUHJlZml4U3VmZml4U3R5bGVzKFwicHJlZml4XCIpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgUHJlZml4OiB1bmRlZmluZWRcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX3ByZXZQcmVmaXggPSBwcmVmaXhTdHJpbmc7XG4gICAgfVxuICAgIF91cGRhdGVQcmVmaXhTdWZmaXhTdHlsZXMoKSB7XG4gICAgICAgIHZhciB0eXBlID0gYXJndW1lbnRzLmxlbmd0aCA+IDAgJiYgYXJndW1lbnRzWzBdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMF0gOiBcInByZWZpeFwiO1xuICAgICAgICB2YXIgbWFwID0ge1xuICAgICAgICAgICAgcHJlZml4OiB7XG4gICAgICAgICAgICAgICAgdGFnOiB0aGlzLl9QcmVmaXgsXG4gICAgICAgICAgICAgICAgcHJvcDogdGhpcy5wcmVmaXgsXG4gICAgICAgICAgICAgICAgcHJldlByb3A6IHRoaXMuX3ByZXZQcmVmaXhcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBzdWZmaXg6IHtcbiAgICAgICAgICAgICAgICB0YWc6IHRoaXMuX1N1ZmZpeCxcbiAgICAgICAgICAgICAgICBwcm9wOiB0aGlzLnN1ZmZpeCxcbiAgICAgICAgICAgICAgICBwcmV2UHJvcDogdGhpcy5fcHJldlN1ZmZpeFxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICB2YXIge3RhZzogdGFnLCBwcm9wOiBwcm9wfSA9IG1hcFt0eXBlXTtcbiAgICAgICAgdmFyIHtwcmV2UHJvcDogcHJldlByb3B9ID0gbWFwW3R5cGVdO1xuICAgICAgICB2YXIgcHJvcFN0cmluZyA9IEpTT04uc3RyaW5naWZ5KHByb3ApO1xuICAgICAgICBpZiAocHJvcFN0cmluZyAhPT0gcHJldlByb3ApIHtcbiAgICAgICAgICAgIHByZXZQcm9wID0gcHJvcFN0cmluZztcbiAgICAgICAgICAgIHRhZy5pdGVtcyA9IHRoaXMuX2FkZEJ1dHRvblByb3BzKHByb3ApO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGFnLkl0ZW1zLmNoaWxkcmVuLmZvckVhY2goKChpdGVtLCBpZHgpID0+IHtcbiAgICAgICAgICAgICAgICBpdGVtLmNvbG9yID0gQXJyYXkuaXNBcnJheShwcm9wKSA/IHByb3BbaWR4XS5jb2xvciA6IHByb3AuY29sb3I7XG4gICAgICAgICAgICAgICAgaXRlbS5zdHlsZSA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgaXRlbS5zdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIGNvbG9yOiB0aGlzLnN0eWxlLmNvbnRlbnRDb2xvclxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfSkpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVUaXRsZSgpIHtcbiAgICAgICAgaWYgKHRoaXMuX2hhc1RpdGxlKSB7XG4gICAgICAgICAgICB2YXIgdGl0bGVQYXRjaCA9IHtcbiAgICAgICAgICAgICAgICBjb250ZW50OiB0aGlzLnRpdGxlLFxuICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogdGhpcy5zdHlsZS50ZXh0U3R5bGVcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9UaXRsZSkge1xuICAgICAgICAgICAgICAgIHRpdGxlUGF0Y2ggPSBfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgeTogaCA9PiBoIC8gMixcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX29uVGl0bGVUZXh0Qm94Q2hhbmdlZFwiXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9LCB0aXRsZVBhdGNoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgIFRleHRXcmFwcGVyOiB7XG4gICAgICAgICAgICAgICAgICAgIG1vdW50WTogLjUsXG4gICAgICAgICAgICAgICAgICAgIFRpdGxlOiB0aXRsZVBhdGNoXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBUZXh0V3JhcHBlcjoge1xuICAgICAgICAgICAgICAgICAgICBUaXRsZTogdW5kZWZpbmVkXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVN1ZmZpeCgpIHtcbiAgICAgICAgaWYgKHRoaXMuc3VmZml4KSB7XG4gICAgICAgICAgICB2YXIgc3VmZml4UGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgaXRlbVNwYWNpbmc6IHRoaXMuc3R5bGUuaXRlbVNwYWNpbmdcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9TdWZmaXgpIHtcbiAgICAgICAgICAgICAgICBzdWZmaXhQYXRjaCA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5fcm93UHJvcHMpLCBzdWZmaXhQYXRjaCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBTdWZmaXg6IHN1ZmZpeFBhdGNoXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVByZWZpeFN1ZmZpeFN0eWxlcyhcInN1ZmZpeFwiKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgIFN1ZmZpeDogdW5kZWZpbmVkXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlVHJ1bmNhdGlvbigpIHtcbiAgICAgICAgaWYgKHRoaXMuX1RpdGxlKSB7XG4gICAgICAgICAgICB0aGlzLl9UaXRsZS5wYXRjaCh7XG4gICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dFN0eWxlOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUudGV4dFN0eWxlKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0aGlzLmZpeGVkLFxuICAgICAgICAgICAgICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogdGhpcy5maXhlZCA/IHRoaXMuX2ZpeGVkV29yZFdyYXBXaWR0aCA6IDBcbiAgICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlQ29udGVudERpbWVuc2lvbnMoKSB7XG4gICAgICAgIHZhciBjb250ZW50RGltZW5zaW9uc1BhdGNoID0ge307XG4gICAgICAgIHZhciB5ID0gdGhpcy5oIC8gMjtcbiAgICAgICAgaWYgKHRoaXMuX0NvbnRlbnQudHJhbnNpdGlvbihcIndcIikudGFyZ2V0VmFsdWUgIT09IHRoaXMuX2NvbnRlbnRXKSB7XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50LncgPSB0aGlzLl9jb250ZW50VztcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fQ29udGVudC55ICE9PSB5KSB7XG4gICAgICAgICAgICBjb250ZW50RGltZW5zaW9uc1BhdGNoLnkgPSB5O1xuICAgICAgICB9XG4gICAgICAgIGlmIChPYmplY3Qua2V5cyhjb250ZW50RGltZW5zaW9uc1BhdGNoKS5sZW5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maXgpID8gdGhpcy5fY29udGVudFcgKyB0aGlzLl9wYWRkaW5nWCA6IE1hdGgubWF4KHRoaXMuX2NvbnRlbnRXICsgdGhpcy5fcGFkZGluZ1gsIHRoaXMuc3R5bGUubWluV2lkdGgpO1xuICAgIH1cbiAgICBfYWRkQnV0dG9uUHJvcHMoYXJyKSB7XG4gICAgICAgIHZhciBpdGVtcyA9IEFycmF5LmlzQXJyYXkoYXJyKSA/IGFyciA6IFsgYXJyIF07XG4gICAgICAgIHJldHVybiBpdGVtcy5tYXAoKGl0ZW0gPT4gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuX2J1dHRvblByb3BzKSwgaXRlbSksIHt9LCB7XG4gICAgICAgICAgICBzdHlsZTogX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgY29sb3I6IHRoaXMuc3R5bGUuY29udGVudENvbG9yXG4gICAgICAgICAgICB9LCBpdGVtLnN0eWxlKVxuICAgICAgICB9KSkpO1xuICAgIH1cbiAgICBfZ2V0SnVzdGlmeSgpIHtcbiAgICAgICAgcmV0dXJuICEhdGhpcy5fanVzdGlmeSA/IHRoaXMuX2p1c3RpZnkgOiB0aGlzLnN0eWxlLmp1c3RpZnk7XG4gICAgfVxuICAgIGdldCBfY29udGVudFByb3BzKCkge1xuICAgICAgICB2YXIgbW91bnRYO1xuICAgICAgICB2YXIgeDtcbiAgICAgICAgc3dpdGNoICh0aGlzLmp1c3RpZnkpIHtcbiAgICAgICAgICBjYXNlIFwibGVmdFwiOlxuICAgICAgICAgICAgbW91bnRYID0gMDtcbiAgICAgICAgICAgIHggPSB0aGlzLl9wYWRkaW5nTGVmdDtcbiAgICAgICAgICAgIGJyZWFrO1xuXG4gICAgICAgICAgY2FzZSBcInJpZ2h0XCI6XG4gICAgICAgICAgICBtb3VudFggPSAxO1xuICAgICAgICAgICAgeCA9IHRoaXMudyAtIHRoaXMuX3BhZGRpbmdSaWdodDtcbiAgICAgICAgICAgIGJyZWFrO1xuXG4gICAgICAgICAgY2FzZSBcImNlbnRlclwiOlxuICAgICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgICBtb3VudFggPSAuNTtcbiAgICAgICAgICAgIHggPSB0aGlzLncgLyAyO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIG1vdW50WDogbW91bnRYLFxuICAgICAgICAgICAgeDogeFxuICAgICAgICB9O1xuICAgIH1cbiAgICBnZXQgX2J1dHRvblByb3BzKCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgY2VudGVySW5QYXJlbnQ6IHRydWUsXG4gICAgICAgICAgICBtb2RlOiB0aGlzLm1vZGVcbiAgICAgICAgfTtcbiAgICB9XG4gICAgZ2V0IF9oYXNQcmVmaXgoKSB7XG4gICAgICAgIHJldHVybiAhISh0aGlzLnByZWZpeCAmJiBPYmplY3Qua2V5cyh0aGlzLnByZWZpeCkubGVuZ3RoKTtcbiAgICB9XG4gICAgZ2V0IF9wcmVmaXhXKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5faGFzUHJlZml4ICYmIHRoaXMuX1ByZWZpeCAhPT0gdW5kZWZpbmVkID8gdGhpcy5fUHJlZml4LncgOiAwO1xuICAgIH1cbiAgICBnZXQgX3ByZWZpeFgoKSB7XG4gICAgICAgIHJldHVybiAwO1xuICAgIH1cbiAgICBnZXQgX2hhc1RpdGxlKCkge1xuICAgICAgICByZXR1cm4gISF0aGlzLnRpdGxlO1xuICAgIH1cbiAgICBnZXQgX3RpdGxlVygpIHtcbiAgICAgICAgaWYgKHRoaXMuX2hhc1RpdGxlICYmIHRoaXMuX1RpdGxlICYmIHRoaXMuX1RpdGxlLl9UZXh0ICYmIHRoaXMuX1RpdGxlLnZpc2libGUpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLl9UaXRsZS53O1xuICAgICAgICB9XG4gICAgICAgIHJldHVyb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uICAgIH0sXG4gICAgZGlzYWJsZWQ6IHtcbiAgICAgICAgdGl0bGVUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICB9XG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMkRyA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJEcsXG4gICAgbW9kZTogbW9kZSRlXG59KTtcblxuY2xhc3MgQ2FyZCBleHRlbmRzIFN1cmZhY2Uge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJDYXJkXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJEc7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIucHJvcGVydGllcywgXCJ0aXRsZVwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIudGFncywgXCJUaXRsZVwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHN1cGVyLl90ZW1wbGF0ZSgpKSwge30sIHtcbiAgICAgICAgICAgIFRpdGxlOiB7XG4gICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRCb3hDaGFuZ2VkOiBcIl91cGRhdGVQb3NpdGlvbnNcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfS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9LFxuICAgICAgICBkZXRhaWxzVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgfVxuICAgIH1cbn0pO1xuXG52YXIgc3R5bGVzJEYgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSRGLFxuICAgIG1vZGU6IG1vZGUkZFxufSk7XG5cbmNsYXNzIENhcmRUaXRsZSBleHRlbmRzIENhcmQge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJDYXJkVGl0bGVcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkRjtcbiAgICB9XG4gICAgc3RhdGljIGdldCB0YWdzKCkge1xuICAgICAgICByZXR1cm4gWyAuLi5zdXBlci50YWdzLCBcIkRlc2NyaXB0aW9uXCIsIFwiRGV0YWlsc1wiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIucHJvcGVydGllcywgXCJkZXNjcmlwdGlvblwiLCBcImRldGFpbHNcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBzdXBlci5fdGVtcGxhdGUoKSksIHt9LCB7XG4gICAgICAgICAgICBEZXNjcmlwdGlvbjoge1xuICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Qm94Q2hhbmdlZDogXCJfdXBkYXRlUG9zaXRpb25zXCJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgRGV0YWlsczoge1xuICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgbW91bnRZOiAxXG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICBzdXBlci5fdXBkYXRlKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZURlc2NyaXB0aW9uKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZURldGFpbHMoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlUG9zaXRpb25zKCk7XG4gICAgfVxuICAgIF91cGRhdGVQb3NpdGlvbnMoKSB7XG4gICAgICAgIHN1cGVyLl91cGRhdGVQb3NpdGlvbnMoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlRGVzY3JpcHRpb25Qb3NpdGlvbigpO1xuICAgICAgICB0aGlzLl91cGRhdGVEZXRhaWxzUG9zaXRpb24oKTtcbiAgICB9XG4gICAgX3VwZGF0ZURlc2NyaXB0aW9uKCkge1xuICAgICAgICB0aGlzLl9EZXNjcmlwdGlvbi5wYXRjaCh7XG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLmRlc2NyaXB0aW9uLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS5kZXNjcmlwdGlvblRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuX2NhbGN1bGF0ZVRleHRXaWR0aCgpXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVEZXNjcmlwdGlvblBvc2l0aW9uKCkge1xuICAgICAgICB0aGlzLl9EZXNjcmlwdGlvbi54ID0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ICAgICAgICBCb2R5OiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgIHJ0dDogdHJ1ZVxuICAgICAgICAgICAgfSwgY2VudGVyKSwge30sIHtcbiAgICAgICAgICAgICAgICBLbm9iOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGNlbnRlciksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIGFscGhhOiAwXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgU3Ryb2tlOiBjZW50ZXJcbiAgICAgICAgfTtcbiAgICB9XG4gICAgc3RhdGljIGdldCB0YWdzKCkge1xuICAgICAgICByZXR1cm4gWyBcIktub2JcIiwgXCJCb2R5XCIsIFwiU3Ryb2tlXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gWyBcImNoZWNrZWRcIiBdO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVCb2R5KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVN0cm9rZSgpO1xuICAgICAgICB0aGlzLl91cGRhdGVLbm9iKCk7XG4gICAgICAgIGlmICh0aGlzLl9jaGVja2VkQ2hhbmdlZCkge1xuICAgICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKFwiJGFubm91bmNlXCIsIHRoaXMuYW5ub3VuY2UpO1xuICAgICAgICAgICAgdGhpcy5fY2hlY2tlZENoYW5nZWQgPSBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl91cGRhdGVPcGFjaXR5KCk7XG4gICAgfVxuICAgIF91cGRhdGVCb2R5KCkge1xuICAgICAgICB2YXIgYm9keUNvbG9yID0gdGhpcy5jaGVja2VkID8gdGhpcy5zdHlsZS5iYWNrZ3JvdW5kQ29sb3JDaGVja2VkIDogdGhpcy5zdHlsZS5i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c3RhdGljIGdldCB0YWdzKCkge1xuICAgICAgICByZXR1cm4gWyAuLi5zdXBlci50YWdzLCBcIkljb25cIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIC4uLnN1cGVyLnByb3BlcnRpZXMsIFwiaWNvbldpZHRoXCIsIFwiaWNvbkhlaWdodFwiLCBcImljb25TcmNcIiBdO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICBzdXBlci5fdXBkYXRlKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUljb24oKTtcbiAgICB9XG4gICAgX3VwZGF0ZUljb24oKSB7XG4gICAgICAgIHZhciB7aWNvbldpZHRoOiBpY29uV2lkdGgsIGljb25IZWlnaHQ6IGljb25IZWlnaHR9ID0gdGhpcy5zdHlsZTtcbiAgICAgICAgdmFyIGljb25PYmplY3QgPSB7XG4gICAgICAgICAgICB3OiBpY29uV2lkdGgsXG4gICAgICAgICAgICBoOiBpY29uSGVpZ2h0LFxuICAgICAgICAgICAgaWNvbjogdGhpcy5pY29uU3JjLFxuICAgICAgICAgICAgeDogdGhpcy53IC0gaWNvbldpZHRoIC0gdGhpcy5zdHlsZS5wYWRkaW5nSG9yaXpvbnRhbCxcbiAgICAgICAgICAgIHk6ICh0aGlzLl9UaXRsZS5zdHlsZS50ZXh0U3R5bGUubGluZUhlaWdodCAtIGljb25IZWlnaHQpIC8gMiArIHRoaXMuc3R5bGUucGFkZGluZ1ZlcnRpY2FsXG4gICAgICAgIH07XG4gICAgICAgIGlmICghdGhpcy5fSWNvbikge1xuICAgICAgICAgICAgaWNvbk9iamVjdC50eXBlID0gSWNvbjtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIEljb246IGljb25PYmplY3RcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF9jYWxjdWxhdGVUZXh0V2lkdGgoKSB7XG4gICAgICAgIHZh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gICAgICAgIHJldHVybiBzdHlsZXMkQTtcbiAgICB9XG4gICAgc3RhdGljIF90ZW1wbGF0ZSgpIHtcbiAgICAgICAgdmFyIGNlbnRlciA9IHtcbiAgICAgICAgICAgIG1vdW50OiAuNSxcbiAgICAgICAgICAgIHg6IHcgPT4gdyAvIDIsXG4gICAgICAgICAgICB5OiBoID0+IGggLyAyXG4gICAgICAgIH07XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBCb2R5OiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgIHJ0dDogdHJ1ZVxuICAgICAgICAgICAgfSwgY2VudGVyKSwge30sIHtcbiAgICAgICAgICAgICAgICBDaGVjazogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogSWNvblxuICAgICAgICAgICAgICAgIH0sIGNlbnRlciksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIGFscGhhOiAwXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgU3Ryb2tlOiBjZW50ZXJcbiAgICAgICAgfTtcbiAgICB9XG4gICAgc3RhdGljIGdldCB0YWdzKCkge1xuICAgICAgICByZXR1cm4gWyBcIkNoZWNrXCIsIFwiQm9keVwiLCBcIlN0cm9rZVwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJjaGVja2VkXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBhbGlhc1N0eWxlcygpIHtcbiAgICAgICAgcmV0dXJuIFsge1xuICAgICAgICAgICAgcHJldjogXCJjaGVja1NyY1wiLFxuICAgICAgICAgICAgY3VycjogXCJpY29uXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgcHJldjogXCJjaGVja0hcIixcbiAgICAgICAgICAgIGN1cnI6IFwiaWNvbkhlaWdodFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIHByZXY6IFwiY2hlY2tXXCIsXG4gICAgICAgICAgICBjdXJyOiBcImljb25XaWR0aFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIHByZXY6IFwiY2hlY2tIZWlnaHRcIixcbiAgICAgICAgICAgIGN1cnI6IFwiaWNvbkhlaWdodFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIHByZXY6IFwiY2hlY2tXaWR0aFwiLFxuICAgICAgICAgICAgY3VycjogXCJpY29uV2lkdGhcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUJvZHkoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlU3Ryb2tlKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUNoZWNrKCk7XG4gICAgICAgIGlmICh0aGlzLl9jaGVja2VkQ2hhbmdlZCkge1xuICAgICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKFwiJGFubm91bmNlXCIsIHRoaXMuYW5ub3VuY2UpO1xuICAgICAgICAgICAgdGhpcy5fY2hlY2tlZENoYW5nZWQgPSBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl91cGRhdGVPcGFjaXR5KCk7XG4gICAgfVxuICAgIF91cGRhdGVDaGVjaygpIHtcbiAgICAgICAgdGhpcy5fQ2hlY2sucGF0Y2goe1xuICAgICAgICAgICAgdzogdGhpcy5zdHlsZS5pY29uV2lkdGgsXG4gICAgICAgICAgICBoOiB0aGlzLnN0eWxlLmljb25IZWlnaHQsXG4gICAgICAgICAgICBpY29uOiB0aGlzLnN0eWxlLmljb24sXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIGNvbG9yOiB0aGlzLnN0eWxlLmNoZWNrQ29sb3JcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIHZhciBhbHBoYVBhdGNoID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tcbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgQmFja2dyb3VuZDoge30sXG4gICAgICAgICAgICBUZXh0OiB7XG4gICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICBtb3VudFg6IC41LFxuICAgICAgICAgICAgICAgIHRleHQ6IHt9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJMYWJlbFwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyR6O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwidGl0bGVcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIFwiQmFja2dyb3VuZFwiLCBcIlRleHRcIiBdO1xuICAgIH1cbiAgICBfaW5pdCgpIHtcbiAgICAgICAgdGhpcy5fVGV4dC5vbihcInR4TG9hZGVkXCIsIHRoaXMuX3VwZGF0ZUJhY2tncm91bmQuYmluZCh0aGlzKSk7XG4gICAgICAgIHN1cGVyLl9pbml0KCk7XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUJhY2tncm91bmQoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGV4dCgpO1xuICAgIH1cbiAgICBfdXBkYXRlVGV4dCgpIHtcbiAgICAgICAgaWYgKHRoaXMuX1RleHQpIHtcbiAgICAgICAgICAgIHRoaXMuX1RleHQucGF0Y2goe1xuICAgICAgICAgICAgICAgIHRleHQ6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHls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XJxdWVlU3luYyhCYXNlKSB7XG4gICAgcmV0dXJuIGNsYXNzIGV4dGVuZHMgQmFzZSB7XG4gICAgICAgIHN0YXRpYyBnZXQgbmFtZSgpIHtcbiAgICAgICAgICAgIHJldHVybiBCYXNlLm5hbWU7XG4gICAgICAgIH1cbiAgICAgICAgX2luaXQoKSB7XG4gICAgICAgICAgICBzdXBlci5faW5pdCgpO1xuICAgICAgICAgICAgaWYgKHRoaXMuX3Nob3VsZFN5bmMpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVTaWduYWxzKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgX3VwZGF0ZSgpIHtcbiAgICAgICAgICAgIHN1cGVyLl91cGRhdGUoKTtcbiAgICAgICAgICAgIGlmICh0aGlzLl9zaG91bGRTeW5jKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fdXBkYXRlU2lnbmFscygpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9jbGVhbnVwU3luY1ZhbHVlcygpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIF9jbGVhbnVwU3luY1ZhbHVlcygpIHtcbiAgICAgICAgICAgIHRoaXMuc3luY0FycmF5Lm1hcCgoY29tcG9uZW50ID0+IHtcbiAgICAgICAgICAgICAgICBjb21wb25lbnQubWFycXVlZU92ZXJyaWRlTG9vcFggPSB1bmRlZmluZWQ7XG4gICAgICAgICAgICAgICAgY29tcG9uZW50LnNpZ25hbHMgJiYgY29tcG9uZW50LnNpZ25hbHMud2lsbE1hcnF1ZWUgJiYgZGVsZXRlIGNvbXBvbmVudC5zaWduYWxzLndpbGxNYXJxdWVlO1xuICAgICAgICAgICAgfSkpO1xuICAgICAgICB9XG4gICAgICAgIF91cGRhdGVTaWduYWxzKCkge1xuICAgICAgICAgICAgaWYgKHRoaXMuc3luY0FycmF5KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5zeW5jQXJyYXkubWFwKChjb21wb25lbnQgPT4ge1xuICAgICAgICAgICAgICAgICAgICBjb21wb25lbnQuc2lnbmFscyA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgY29tcG9uZW50LnNpZ25hbHMpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgd2lsbE1hcnF1ZWU6IFwiX3dpbGxNYXJxdWVlXCJcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIF93aWxsTWFycXVlZShjb21wUmVmKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fc2hvdWxkU3luYykge1xuICAgICAgICAgICAgICAgIHRoaXMuX2xvbmdlc3RNYXJxdWVlV2lkdGggPSBNYXRoLm1heChjb21wUmVmLl90ZXh0UmVuZGVyZWRXIHx8IDAsIHRoaXMuX2xvbmdlc3RNYXJxdWVlV2lkdGggfHwgMCk7XG4gICAgICAgICAgICAgICAgdGhpcy5zeW5jQXJyYXkubWFwKChjb21wb25lbnQgPT4ge1xuICAgICAgICAgICAgICAgICAgICBjb21wb25lbnQubWFycXVlZU92ZXJyaWRlTG9vcFggPSB0aGlzLl9sb25nZXN0TWFycXVlZVdpZHRoO1xuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBnZXQgX3Nob3VsZFN5bmMoKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5zdHlsZS5tYXJxdWVlU3luYyA9PT0gZmFsc2UpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoIXRoaXMuc3luY0FycmF5KSB7XG4gICAgICAgICAgICAgICAgbG9nZ2VySW5zdGFuY2Uud2FybihcIndhcm5pbmc6IGNvbXBvbmVudHMgdXNpbmcgTWFycXVlZVN5bmMgbXVzdCBoYXZlIGE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G9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIGRldGFpbHNUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgdGl0bGVUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dEludmVyc2VcbiAgICAgICAgfSxcbiAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0SW52ZXJzZVxuICAgICAgICB9LFxuICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0SW52ZXJzZVNlY29uZGFyeVxuICAgICAgICB9LFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIHRpdGxlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH0sXG4gICAgYnJhbmQ6IHtcbiAgICAgICAgdGl0bGVUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxcbiAgICAgICAgfSxcbiAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICB9LFxuICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFNlY29uZGFyeVxuICAgICAgICB9LFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIHRpdGxlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH1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4gICAgICAgIHJldHVybiBbIFwiVGV4dFwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIlRpdGxlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHQuVGl0bGVcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlN1YnRpdGxlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHQuU3VidGl0bGVcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIkRldGFpbHNXcmFwcGVyXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHQuRGV0YWlsc1dyYXBwZXJcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIkRldGFpbHNcIixcbiAgICAgICAgICAgIHBhdGg6IFwiVGV4dC5EZXRhaWxzV3JhcHBlci5EZXRhaWxzXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJEZXNjcmlwdGlvblwiLFxuICAgICAgICAgICAgcGF0aDogXCJUZXh0LkRlc2NyaXB0aW9uXCJcbiAgICAgICAgfSwgXCJMb2dvXCIgXTtcbiAgICB9XG4gICAgX3RpdGxlTG9hZGVkKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVMYXlvdXQoKTtcbiAgICB9XG4gICAgX3N1YnRpdGxlTG9hZGVkKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVMYXlvdXQoKTtcbiAgICB9XG4gICAgX2RldGFpbHNMb2FkZWQoX3JlZjE5KSB7XG4gICAgICAgIHZhciB7dzogdywgaDogaH0gPSBfcmVmMTk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZURldGFpbHNMYXlvdXQoe1xuICAgICAgICAgICAgdzogdyxcbiAgICAgICAgICAgIGg6IGhcbiAgICAgICAgfSk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUxheW91dCgpO1xuICAgIH1cbiAgICBfZGVzY3JpcHRpb25Mb2FkZWQoKSB7XG4gICAgICAgIHRoaXMuX3VwZ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lUG9zaXRpb25zKCkge1xuICAgICAgICB0aGlzLl9UZXh0LnggPSB0aGlzLmxvZ28gJiYgdGhpcy5sb2dvUG9zaXRpb24gPT09IFwibGVmdFwiID8gdGhpcy5sb2dvV2lkdGggKyB0aGlzLnN0eWxlLmxvZ29QYWRkaW5nIDogMDtcbiAgICAgICAgdGhpcy5fVGV4dC55ID0gKHRoaXMuaCAtIHRoaXMuX1RleHQuaCkgLyAyO1xuICAgIH1cbiAgICBfdXBkYXRlTWV0YWRhdGFIZWlnaHQoKSB7XG4gICAgICAgIHZhciBuZXdIID0gTWF0aC5tYXgodGhpcy5sb2dvSGVpZ2h0LCB0aGlzLl9UZXh0LmgpO1xuICAgICAgICBpZiAodGhpcy5oICE9PSBuZXdIKSB7XG4gICAgICAgICAgICB0aGlzLmggPSBuZXdIO1xuICAgICAgICAgICAgdGhpcy5zaWduYWwoXCJ1cGRhdGVDb21wb25lbnREaW1lbnNpb25zXCIpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVUaXRsZSgpIHtcbiAgICAgICAgaWYgKCF0aGlzLnRpdGxlICYmICF0aGlzLl9UaXRsZSkge1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIGlmICghdGhpcy5fVGl0bGUpIHtcbiAgICAgICAgICAgIHRoaXMuX1RleHQuY2hpbGRMaXN0LmFkZEF0KHtcbiAgICAgICAgICAgICAgICByZWY6IFwiVGl0bGVcIixcbiAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3RpdGxlTG9hZGVkXCJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LCAwKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9UaXRsZS5wYXRjaCh7XG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLnRpdGxlLFxuICAgICAgICAgICAgbWFycXVlZTogdGhpcy5tYXJxdWVlLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS50aXRsZVRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIG1heExpbmVzOiAxLFxuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogdGhpcy5fVGV4dC53XG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVTdWJ0aXRsZSgpIHtcbiAgICAgICAgaWYgKCF0aGlzLnN1YnRpdGxlICYmICF0aGlzLl9TdWJ0aXRsZSkge1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIGlmICghdGhpcy5fU3VidGl0bGUpIHtcbiAgICAgICAgICAgIHRoaXMuX1RleHQuY2hpbGRMaXN0LmFkZEF0KHtcbiAgICAgICAgICAgICAgICByZWY6IFwiU3VidGl0bGVcIixcbiAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3N1YnRpdGxlTG9hZGVkXCJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LCAxKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9TdWJ0aXRsZS5wYXRjaCh7XG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLnN1YnRpdGxlLFxuICAgICAgICAgICAgbWFycXVlZTogdGhpcy5tYXJxdWVlLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS5kZXNjcmlwdGlvblRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIG1heExpbmVzOiAxLFxuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogdGhpcy5fVGV4dC53XG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIHJlc2V0TWFycXVlZSgpIHtcbiAgICAgICAgaWYgKHRoaXMubWFycXVlZSkge1xuICAgICAgICAgICAgaWYgKHRoaXMudGl0bGUpIHtcbiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuX1RpdGxlKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVRpdGxlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHRoaXMuX1RpdGxlLnRvZ2dsZU1hcnF1ZWUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICh0aGlzLmRlc2NyaXB0aW9uKSB7XG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLl9EZXNjcmlwdGlvbikge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVEZXNjcmlwdGlvbigpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0aGlzLl9EZXNjcmlwdGlvbi50b2dnbGVNYXJxdWVlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZURldGFpbHMoKSB7XG4gICAgICAgIGlmICghdGhpcy5kZXRhaWxzICYmICF0aGlzLl9EZXRhaWxzKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLl9EZXRhaWxzKSB7XG4gICAgICAgICAgICB0aGlzLl9EZXRhaWxzV3JhcHBlci5wYXRjaCh7XG4gICAgICAgICAgICAgICAgRGV0YWlsczoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0Qm94Q2hhbmdlZDogXCJfZGV0YWlsc0xvYWRlZFwiXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9EZXRhaWxzLnBhdGNoKHtcbiAgICAgICAgICAgIGNvbnRlbnQ6IHRoaXMuZGV0YWlscyxcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB0aGlzLnN0eWxlLmRldGFpbHNUZXh0U3R5bGVcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIGlmICh0aGlzLl9EZXRhaWxzLmZpbmFsVyA+IHRoaXMuX3RleHRXKCkpIHtcbiAgICAgICAgICAgIHRoaXMuX0RldGFpbHMucGF0Y2goe1xuICAgICAgICAgICAgICAgIHc6IHRoaXMuX3RleHRXKCkgKyB0aGlzLnN0eWxlLmZhZGVXaWR0aCAvIDIsXG4gICAgICAgICAgICAgICAgc2hhZGVyOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEZhZGVTaGFkZXIsXG4gICAgICAgICAgICAgICAgICAgIHBvc2l0aW9uTGVmdDogMCxcbiAgICAgICAgICAgICAgICAgICAgcG9zaXRpb25SaWdodDogdGhpcy5zdHlsZS5mYWRlV2lkdGhcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIHJ0dDogdHJ1ZVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9EZXRhaWxzV3JhcHBlci5zaGFkZXIgPSB1bmRlZmluZWQ7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fRGV0YWlsc1dyYXBwZXIudmlzaWJsZSA9IHRoaXMuZGV0YWlscyA/IHRydWUgOiBmYWxzZTtcbiAgICAgICAgdGhpcy5fRGV0YWlsc1dyYXBwZXIuYWxwaGEgPSB0aGlzLnN0eWxlLmFscGhhO1xuICAgIH1cbiAgICBfdXBkYXRlRGVzY3JpcHRpb24oKSB7XG4gICAgICAgIGlmICghdGhpcy5kZXNjcmlwdGlvbiAmJiAhdGhpcy5fRGVzY3JpcHRpb24pIHtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICBpZiAoIXRoaXMuX0Rlc2NyaXB0aW9uKSB7XG4gICAgICAgICAgICB0aGlzLl9UZXh0LmNoaWxkTGlzdC5hZGQoe1xuICAgICAgICAgICAgICAgIHJlZjogXCJEZXNjcmlwdGlvblwiLFxuICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Qm94Q2hhbmdlZDogXCJfZGVzY3JpcHRpb25Mb2FkZWRcIlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX0Rlc2NyaXB0aW9uLnBhdGNoKHtcbiAgICAgICAgICAgIGNvbnRlbnQ6IHRoaXMuZGVzY3JpcHRpb24sXG4gICAgICAgICAgICBtYXJxdWVlOiB0aGlzLm1hcnF1ZWUsXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlLmRlc2NyaXB0aW9uVGV4dFN0eWxlKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgbWF4TGluZXM6IDEsXG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcFdpZHRoOiB0aGlzLl9UZXh0LndcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZUxvZ28oKSB7XG4gICAgICAgIGlmICghdGhpcy5sb2dvICYmICF0aGlzLl9Mb2dvKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLl9Mb2dvKSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBMb2dvOiB7XG4gICAgICAgICAgICAgICAgICAgIGZsZXhJdGVtOiBmYWxzZSxcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogSWNvblxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMubG9nb1Bvc2l0aW9uID0gdGhpcy5sb2dvUG9zaXRpb24gfHwgXCJyaWdodFwiO1xuICAgICAgICB2YXIgc3VidGl0bGVIID0gdGhpcy5zdWJ0aXRsZSAmJiB0aGlzLl9TdWJ0aXRsZSAmJiB0aGlzLl9TdWJ0aXRsZS5oIHx8IDA7XG4gICAgICAgIHRoaXMuX0xvZ28ucGF0Y2goe1xuICAgICAgICAgICAgdzogdGhpcy5sb2dvV2lkdGgsXG4gICAgICAgICAgICBoOiB0aGlzLmxvZ29IZWlnaHQsXG4gICAgICAgICAgICBpY29uOiB0aGlzLmxvZ28sXG4gICAgICAgICAgICBhbHBoYTogdGhpcy5zdHlsZS5hbHBoYVxuICAgICAgICB9KTtcbiAgICAgICAgdGhpcy5fTG9nby54ID0gdGhpcy5sb2dvUG9zaXRpb24gPT09IFwibGVmdFwiID8gMCA6IHRoaXMudyAtIHRoaXMuX0xvZ28udztcbiAgICAgICAgdGhpcy5fTG9nby55ID0gKHRoaXMuaCAtIHRoaXMubG9nb0hlaWdodCArIHN1YnRpdGx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tZS50eXBvZ3JhcGh5LmhlYWRsaW5lMyxcbiAgICBkZXNjcmlwdGlvblRleHRTdHlsZTogdGhlbWUudHlwb2dyYXBoeS5ib2R5M1xufSk7XG5cbnZhciB0b25lJGcgPSB0aGVtZSA9PiAoe1xuICAgIG5ldXRyYWw6IHtcbiAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFNlY29uZGFyeVxuICAgICAgICB9LFxuICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICB9LFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIGRldGFpbHNUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0SW52ZXJzZVNlY29uZGFyeVxuICAgICAgICB9LFxuICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0SW52ZXJzZVxuICAgICAgICB9LFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIGRldGFpbHNUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBkZXNjcmlwdGlvblRleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGJyYW5kOiB7XG4gICAgICAgIGRldGFpbHNUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxTZWNvbmRhcnlcbiAgICAgICAgfSxcbiAgICAgICAgZGVzY3JpcHRpb25UZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxcbiAgICAgICAgfSxcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZGlzYWJsZWQ6IHtcbiAgICAgICAgICAgICAgICBkZXRhaWxzVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxEaXNhYmxlZFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgZGVzY3JpcHRpb25UZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMkeCA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJHgsXG4gICAgdG9uZTogdG9uZSRnXG59KTtcblxuY2xhc3MgTWV0YWRhdGFUaWxlIGV4dGVuZHMgTWV0YWRhdGFCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJNZXRhZGF0YVRpbGVcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkeDtcbiAgICB9XG4gICAgX3VwZGF0ZURldGFpbHMoKSB7XG4gICAgICAgIGlmICghdGhpcy5kZXRhaWxzICYmICF0aGlzLl9EZXRhaWxzKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuZGVzY3JpcHRpb24gJiYgdGhpcy5fRGV0YWlscykge1xuICAgICAgICAgICAgdGhpcy5fRGV0YWlscy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgY29udGVudDogXCJcIlxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB0aGlzLl9EZXRhaWxzLmFscGhhID0gMDtcbiAgICAgICAgICAgIHRoaXMuX0RldGFpbHMudmlzaWJsZSA9IGZhbHNlO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3VwZXIuX3VwZGF0ZURldGFpbHMoKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlRGV0YWlsc0xheW91dChfcmVmMjEpIHtcbiAgICAgICAgdmFyIHtoOiBofSA9IF9yZWYyMTtcbiAgICAgICAgaWYgKCF0aGlzLmRldGFpbHMgJiYgIXRoaXMuX0RldGFpbHMpIHtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5fRGV0YWlscyAmJiAhdGhpcy5kZXNjcmlwdGlvbikge1xuICAgICAgICAgICAgdGhpcy5fRGV0YWlsc1dy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UgPSB0aGVtZSA9PiAoe1xuICAgIG5ldXRyYWw6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIGJhY2tncm91bmRDb2xvcjogdGhlbWUuY29sb3IuaW50ZXJhY3RpdmVOZXV0cmFsRm9jdXNTb2Z0XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIGJhY2tncm91bmRDb2xvcjogdGhlbWUuY29sb3IuaW50ZXJhY3RpdmVJbnZlcnNlRm9jdXNTb2Z0XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGJyYW5kOiB7XG4gICAgICAgIG1vZGU6IHtcbiAgICAgICAgICAgIGZvY3VzZWQ6IHtcbiAgICAgICAgICAgICAgICBiYWNrZ3JvdW5kQ29sb3I6IHRoZW1lLmNvbG9yLmludGVyYWN0aXZlQnJhbmRGb2N1c1NvZnRcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbn0pO1xuXG52YXIgbW9kZSQ4ID0gdGhlbWUgPT4gKHtcbiAgICBkaXNhYmxlZDoge1xuICAgICAgICBhbHBoYTogdGhlbWUuYWxwaGEuaW5hY3RpdmVcbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyR2ID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkdixcbiAgICBtb2RlOiBtb2RlJDgsXG4gICAgdG9uZTogdG9uZSRlXG59KTtcblxuY2xhc3MgVGlsZSBleHRlbmRzIFN1cmZhY2Uge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJUaWxlXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJHY7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHN1cGVyLl90ZW1wbGF0ZSgpKSwge30sIHtcbiAgICAgICAgICAgIFRpbGU6IHtcbiAgICAgICAgICAgICAgICBBcnR3b3JrOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEFydHdvcmssXG4gICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGltYWdlTG9hZGVkOiBcIl9pbWFnZUxvYWRlZFwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIG1vdW50OiAuNVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgQ29udGVudDoge1xuICAgICAgICAgICAgICAgICAgICBtb3VudDogLjVcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwiYXJ0d29ya1wiLCBcImJhZGdlXCIsIFwiY2hlY2tib3hcIiwgXCJjaXJjbGVcIiwgXCJsYWJlbFwiLCBcImxvZ29cIiwgXCJtZXRhZGF0YVwiLCBcIm1ldGFkYXRhTG9jYXRpb25cIiwgXCJwZXJzaXN0ZW50TWV0YWRhdGFcIiwgXCJwcm9ncmVzc0JhclwiLCBcInNyY1wiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgYWxpYXNTdHlsZXMoKSB7XG4gICAgICAgIHJldHVybiBbIHtcbiAgICAgICAgICAgIHByZXY6IFwiaWNvbkhlaWdodFwiLFxuICAgICAgICAgICAgY3VycjogXCJsb2dvSGVpZ2h0XCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgcHJldjogXCJpY29uV2lkdGhcIixcbiAgICAgICAgICAgIGN1cnI6IFwibG9nb1dpZHRoXCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IGFsaWFzUHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsge1xuICAgICAgICAgICAgcHJldjogXCJpY29uU3JjXCIsXG4gICAgICAgICAgICBjdXJyOiBcImxvZ29cIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIudGFncywgXCJBcnR3b3JrXCIsIFwiQ29udGVudFwiLCBcIlRpbGVcIiwge1xuICAgICAgICAgICAgbmFtZTogXCJCYWRnZVwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50LkJhZGdlXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJDaGVja2JveFwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50LkNoZWNrYm94XCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJMb2dvXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRlbnQuTG9nb1wiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiTWV0YWRhdGFcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGVudC5NZXRhZGF0YVwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiUHJvZ3Jlc3NCYXJcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGVudC5Qcm9ncmVzc0JhclwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiTGFiZWxcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGVudC5MYWJlbFwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgc2V0IGFubm91bmNlKGFubm91bmNlKSB7XG4gICAgICAgI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ID0gdGhpcy5zdHlsZS5hbHBoYTtcbiAgICB9XG4gICAgX3VwZGF0ZUNvbnRlbnQoKSB7XG4gICAgICAgIHZhciBpdGVtQ29udGFpbmVyUGF0Y2ggPSB7XG4gICAgICAgICAgICBoOiB0aGlzLl9oLFxuICAgICAgICAgICAgdzogdGhpcy5fdyxcbiAgICAgICAgICAgIHg6IHRoaXMuX3cgLyAyLFxuICAgICAgICAgICAgeTogdGhpcy5faCAvIDJcbiAgICAgICAgfTtcbiAgICAgICAgdGhpcy5hcHBseVNtb290aCh0aGlzLl9Db250ZW50LCBpdGVtQ29udGFpbmVyUGF0Y2gsIE9iamVjdC5rZXlzKGl0ZW1Db250YWluZXJQYXRjaCkucmVkdWNlKCgoYWNjLCBwcm9wKSA9PiB7XG4gICAgICAgICAgICBhY2NbcHJvcF0gPSBbIGl0ZW1Db250YWluZXJQYXRjaFtwcm9wXSwgdGhpcy5faXNGb2N1c2VkTW9kZSA/IHRoaXMuc3R5bGUuYW5pbWF0aW9uRW50cmFuY2UgOiB0aGlzLnN0eWxlLmFuaW1hdGlvbkV4aXQgXTtcbiAgICAgICAgICAgIHJldHVybiBhY2M7XG4gICAgICAgIH0pLCB7fSkpO1xuICAgIH1cbiAgICBfdXBkYXRlTG9nbygpIHtcbiAgICAgICAgaWYgKCF0aGlzLmxvZ28pIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIExvZ286IHVuZGVmaW5lZFxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgdmFyIGxvZ29PYmplY3QgPSB7XG4gICAgICAgICAgICB3OiB0aGlzLnN0eWxlLmxvZ29XaWR0aCxcbiAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUubG9nb0hlaWdodCxcbiAgICAgICAgICAgIGljb246IHRoaXMubG9nbyxcbiAgICAgICAgICAgIGFscGhhOiB0aGlzLl9zaG91bGRTaG93TG9nbyA/IHRo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tcbiAgICAgICAgdmFyIF90aGlzJHN0eWxlMywgX3RoaXMkYXJ0d29yaztcbiAgICAgICAgdGhpcy5fQXJ0d29yay5wYXRjaChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgbW9kZTogdGhpcy5tb2RlLFxuICAgICAgICAgICAgaDogdGhpcy5faCxcbiAgICAgICAgICAgIHc6IHRoaXMuX3csXG4gICAgICAgICAgICB4OiB0aGlzLl93IC8gMixcbiAgICAgICAgICAgIHk6IHRoaXMuX2ggLyAyLFxuICAgICAgICAgICAgc3JjOiB0aGlzLnNyY1xuICAgICAgICB9LCB0aGlzLmFydHdvcmsgfHwge30pLCB7fSwge1xuICAgICAgICAgICAgc3R5bGU6IF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgIHJhZGl1czogKF90aGlzJHN0eWxlMyA9IHRoaXMuc3R5bGUpID09PSBudWxsIHx8IF90aGlzJHN0eWxlMyA9PT0gdm9pZCAwID8gdm9pZCAwIDogX3RoaXMkc3R5bGUzLnJhZGl1c1xuICAgICAgICAgICAgfSwgKF90aGlzJGFydHdvcmsgPSB0aGlzLmFydHdvcmspID09PSBudWxsIHx8IF90aGlzJGFydHdvcmsgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJGFydHdvcmsuc3R5bGUpLFxuICAgICAgICAgICAgZ3JhZGllbnQ6IHRoaXMuX3Nob3VsZFNob3dHcmFkaWVudCxcbiAgICAgICAgICAgIHNob3VsZFNjYWxlOiB0aGlzLl9pc0ZvY3VzZWRNb2RlXG4gICAgICAgIH0pKTtcbiAgICB9XG4gICAgX2dldFNyYygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuYXJ0d29yayAmJiB0aGlzLmFydHdvcmsuc3JjIHx8IHRoaXMuX3NyYztcbiAgICB9XG4gICAgX2ltYWdlTG9hZGVkKCkge1xuICAgICAgICB0aGlzLl9CYWNrZ3JvdW5kLmFscGhhID0gMDtcbiAgICB9XG4gICAgX3VwZGF0ZUJhZGdlKCkge1xuICAgICAgICB2YXIgX3RoaXMkYmFkZ2U7XG4gICAgICAgIGlmICghKChfdGhpcyRiYWRnZSA9IHRoaXMuYmFkZ2UpICE9PSBudWxsICYmIF90aGlzJGJhZGdlICE9PSB2b2lkIDAgJiYgX3RoaXMkYmFkZ2UudGl0bGUpIHx8IHRoaXMuX2lzQ2lyY2xlTGF5b3V0KSB7XG4gICAgICAgICAgICBpZiAodGhpcy5fQmFkZ2UpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgQmFkZ2U6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHZhciBiYWRnZVBhdGNoID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLmJhZGdlKSwge30sIHtcbiAgICAgICAgICAgIG1vZGU6IHRoaXMubW9kZSxcbiAgICAgICAgICAgIHg6IHRoaXMuc3R5bGUucGFkZGluZ1gsXG4gICAgICAgICAgICB5OiB0aGlzLnN0eWxlLnBhZGRpbmdZLFxuICAgICAgICAgICAgYWxwaGE6IHRoaXMuX3Nob3VsZFNob3dCYWRnZUxhYmVsID8gMSA6IC4wMDFcbiAgICAgICAgfSk7XG4gICAgICAgIGlmICghdGhpcy5fQmFkZ2UpIHtcbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgIEJhZGdlOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBCYWRnZVxuICAgICAgICAgICAgICAgIH0sIGJhZGdlUGF0Y2gpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBsb2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bGUucGFkZGluZ1ksXG4gICAgICAgICAgICBhbHBoYTogdGhpcy5fc2hvdWxkU2hvd0JhZGdlTGFiZWwgPyAxIDogLjAwMVxuICAgICAgICB9KTtcbiAgICAgICAgaWYgKCF0aGlzLl9MYWJlbCkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgTGFiZWw6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IExhYmVsLFxuICAgICAgICAgICAgICAgICAgICBtb3VudFg6IDFcbiAgICAgICAgICAgICAgICB9LCBsYWJlbFBhdGNoKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgbG9hZGVkTGFiZWw6IFwiX3VwZGF0ZUxhYmVsXCJcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX0xhYmVsLnBhdGNoKGxhYmVsUGF0Y2gpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuYXBwbHlTbW9vdGgodGhpcy5fTGFiZWwsIGxhYmVsUGF0Y2gsIF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgbGFiZWxQYXRjaCksIHt9LCB7XG4gICAgICAgICAgICB4OiBbIGxhYmVsUGF0Y2gueCwgdGhpcy5fc2hvdWxkU2hvd0JhZGdlTGFiZWwgPyB0aGlzLnN0eWxlLmFuaW1hdGlvbkVudHJhbmNlIDogdGhpcy5zdHlsZS5hbmltYXRpb25FeGl0IF1cbiAgICAgICAgfSwgdGhpcy5fYmFkZ2VMYWJlbFRyYW5zaXRpb25zKSk7XG4gICAgfVxuICAgIGdldCBfc2hvdWxkU2hvd0JhZGdlTGFiZWwoKS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ICAgQ2hlY2tib3g6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHZhciBjaGVja2JveFBhdGNoID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLmNoZWNrYm94KSwge30sIHtcbiAgICAgICAgICAgIG1vZGU6IHRoaXMubW9kZSxcbiAgICAgICAgICAgIHg6IHRoaXMuX3cgLSB0aGlzLnN0eWxlLnBhZGRpbmdYLFxuICAgICAgICAgICAgeTogdGhpcy5faCAtIHRoaXMuc3R5bGUucGFkZGluZ1lcbiAgICAgICAgfSk7XG4gICAgICAgIGlmICghdGhpcy5fQ2hlY2tib3gpIHtcbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgIENoZWNrYm94OiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGNoZWNrYm94UGF0Y2gpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBDaGVja2JveCxcbiAgICAgICAgICAgICAgICAgICAgbW91bnQ6IDFcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5hcHBseVNtb290aCh0aGlzLl9DaGVja2JveCwgY2hlY2tib3hQYXRjaCk7XG4gICAgfVxuICAgIGdldCBfcHJvZ3Jlc3NCYXJZKCkge1xuICAgICAgICByZXR1cm4gKHRoaXMuX1Byb2dyZXNzQmFyICYmIHRoaXMuX1Byb2dyZXNzQmFyLl9nZXRUcmFuc2l0aW9uKFwiYWxwaGFcIikuX3RhcmdldFZhbHVlICE9PSAwID8gdGhpcy5fUHJvZ3Jlc3NCYXIuX2dldFRyYW5zaXRpb24oXCJ5XCIpLl90YXJnZXRWYWx1ZSB8fCB0aGlzLl9Qcm9ncmVzc0Jhci55IDogMCkgfHwgMDtcbiAgICB9XG4gICAgX3VwZGF0ZVByb2dyZXNzQmFyKCkge1xuICAgICAgICB2YXIgX3RoaXMkcHJvZ3Jlc3NCYXIyO1xuICAgICAgICBpZiAoISh0eXBlb2YgKChfdGhpcyRwcm9ncmVzc0JhcjIgPSB0aGlzLnByb2dyZXNzQmFyKSA9PT0gbnVsbCB8fCBfdGhpcyRwcm9ncmVzc0JhcjIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJHByb2dyZXNzQmFyMi5wcm9ncmVzcykgPT09IFwibnVtYmVyXCIgJiYgdGhpcy5wcm9ncmVzc0Jhci5wcm9ncmVzcykgfHwgdGhpcy5faXNDaXJjbGVMYXlvdXQpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLl9Qcm9ncmVzc0Jhcikge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLnNob3VsZFNtb290aCkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9Qcm9ncmVzc0Jhci5fZ2V0VHJhbnNpdGlvbihcImFscGhhXCIpLm9uY2UoXCJmaW5pc2hcIiwgKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3JlbW92ZVByb2dyZXNzQmFyKCk7XG4gICAgICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fUHJvZ3Jlc3NCYXIuc21vb3RoID0ge1xuICAgICAgICAgICAgICAgICAgICAgICAgYWxwaGE6IDBcbiAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9yZW1vdmVQcm9ncmVzc0JhcigpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5wcm9ncmVzc0Jhci5wcm9ncmVzcyA+IDApIHtcbiAgICAgICAgICAgIHZhciBwcm9ncmVzc1BhdGNoID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnByb2dyZXNzQmFyKSwge30sIHtcbiAgICAgICAgICAgICAgICBtb2RlOiB0aGlzLm1vZGUsXG4gICAgICAgICAgICAgICAgdzogdGhpcy5fdyAtIHRoaXMuc3R5bGUucGFkZGluZ1ggKiAyLFxuICAgICAgICAgICAgICAgIHg6IHRoaXMuX3cgLyAyLFxuICAgICAgICAgICAgICAgIHk6IHRoaXMuX2ggLSB0aGlzLnN0eWxlLnBhZGRpbmdZUHJvZ3Jlc3NcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9Qcm9ncmVzc0Jhcikge1xuICAgICAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgICAgICBQcm9ncmVzc0JhcjogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBwcm9ncmVzc1BhdGNoKSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFByb2dyZXNzQmFyLFxuICAgICAgICAgICAgICAgICAgICAgICAgbW91bnRYOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgICAgIG1vdW50WTogMSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGFscGhhOiB0aGlzLl9oYXNNZXRhZGF0YSAmJiB0aGlzLnNob3VsZFNtb290aCA/IC4wMDEgOiAxXG4gICAgICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuc2hvdWxkU21vb3RoKSB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX1Byb2dyZXNzQmFyLnNtb290aCA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGFscGhhOiBbIDEsIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWxheTogdGhpcy5z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dGhpcyRfbWV0YWRhdGFMb2NhdGkgOiB0aGlzLnN0eWxlLm1ldGFkYXRhTG9jYXRpb247XG4gICAgfVxuICAgIF91cGRhdGVNZXRhZGF0YSgpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9oYXNNZXRhZGF0YSkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgTWV0YWRhdGE6IHVuZGVmaW5lZFxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCF0aGlzLl9NZXRhZGF0YSAmJiB0aGlzLl9oYXNNZXRhZGF0YSkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgTWV0YWRhdGE6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IE1ldGFkYXRhVGlsZSxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdXBkYXRlQ29tcG9uZW50RGltZW5zaW9uczogXCJfbWV0YWRhdGFMb2FkZWRcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSwgdGhpcy5fbm9uU21vb3RoaW5nTWV0YWRhdGFQYXRjaCksIHRoaXMuX21ldGFkYXRhUGF0Y2gpXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9NZXRhZGF0YS5wYXRjaCh0aGlzLl9ub25TbW9vdGhpbmdNZXRhZGF0YVBhdGNoKTtcbiAgICAgICAgdGhpcy5fYW5pbWF0ZU1ldGFkYXRhKCk7XG4gICAgfVxuICAgIF9hbmltYXRlTWV0YWRhdGEoKSB7XG4gICAgICAgIGlmICghdGhpcy5fTWV0YWRhdGEpIHtcbiAgICAgICAgICAgIH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RoaXMudmlzaWJsZUNvdW50KS5mb3JFYWNoKChwcm92aWRlciA9PiB7XG4gICAgICAgICAgICB2YXIgcGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgY2VudGVySW5QYXJlbnQ6IHRydWUsXG4gICAgICAgICAgICAgICAgcmFkaXVzOiB0aGlzLmRpc2FibGVSYWRpdXMgPyAwIDogZ2V0TWF4Um91bmRSYWRpdXModGhpcy5zdHlsZS5yYWRpdXMsIHRoaXMuc3R5bGUuaXRlbVNpemUsIHRoaXMuc3R5bGUuaXRlbVNpemUpLFxuICAgICAgICAgICAgICAgIGFscGhhOiB0aGlzLnN0eWxlLmFscGhhLFxuICAgICAgICAgICAgICAgIHN0eWxlOiBwcm92aWRlci5zdHlsZSB8fCB7fVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmIChwcm92aWRlci50eXBlID09PSBJY29uICYmIHByb3ZpZGVyLmljb24gJiYgcHJvdmlkZXIudyAmJiBwcm92aWRlci5oKSB7XG4gICAgICAgICAgICAgICAgdmFyIHJhdGlvID0gcHJvdmlkZXIudyAvIHByb3ZpZGVyLmg7XG4gICAgICAgICAgICAgICAgcGF0Y2ggPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgICAgICBpY29uOiBwcm92aWRlci5pY29uXG4gICAgICAgICAgICAgICAgfSwgcHJvdmlkZXIpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLnN0eWxlLml0ZW1TaXplICogcmF0aW8sXG4gICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuaXRlbVNpemVcbiAgICAgICAgICAgICAgICB9LCBwYXRjaCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHBhdGNoID0gX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEljb24sXG4gICAgICAgICAgICAgICAgICAgIHc6IHRoaXMuc3R5bGUuaXRlbVNpemUsXG4gICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuaXRlbVNpemVcbiAgICAgICAgICAgICAgICB9LCBwYXRjaCk7XG4gICAgICAgICAgICAgICAgaWYgKHR5cGVvZiBwcm92aWRlciA9PT0gXCJvYmplY3RcIikge1xuICAgICAgICAgICAgICAgICAgICBwYXRjaCA9IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgcGF0Y2gpLCBwcm92aWRlcik7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcGF0Y2guaWNvbiA9IHByb3ZpZGVyO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHByb3ZpZGVyTGlzdC5wdXNoKHBhdGNoKTtcbiAgICAgICAgfSkpO1xuICAgICAgICB0aGlzLl9Sb3cucGF0Y2goe1xuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICBpdGVtU3BhY2luZzogdGhpcy5zdHlsZS5pdGVtU3BhY2luZ1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGl0ZW1zOiBwcm92aWRlckxpc3QsXG4gICAgICAgICAgICBoOiB0aGlzLnN0eWxlLml0ZW1TaXplXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlQ291bnRlcigpIHtcbiAgICAgICAgaWYgKHRoaXMucHJvdmlkZXJzLmxlbmd0aCA+IHRoaXMudmlzaWJsZUNvdW50KSB7XG4gICAgICAgICAgICB2YXIgcmVtYWluaW5nID0gdGhpcy5wcm92aWRlcnNIaWRkZW47XG4gICAgICAgICAgICB2YXIgY291bnRlciA9IHtcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCIrXCIuY29uY2F0KHJlbWFpbmluZyksXG4gICAgICAgICAgICAgICAgYWxwaGE6IHRoaXMuc3R5bGUuYWxwaGEsXG4gICAgICAgICAgICAgICAgdzogdGhpcy5zdHlsZS5pdGVtU2l6ZSxcbiAgICAgICAgICAgICAgICBoOiB0aGlzLnN0eWxlLml0ZW1TaXplLFxuICAgICAgICAgICAgICAgIGNlbnRlckluUGFyZW50OiB0cnVlLFxuICAgICAgICAgICAgICAgIEJhY2tncm91bmQ6IHtcbiAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5zdHlsZS5pdGVtU2l6ZSxcbiAgICAgICAgICAgICAgICAgICAgaDogdGhpcy5zdHlsZS5pdGVtU2l6ZSxcbiAgICAgICAgICAgICAgICAgICAgdGV4dHVyZTogbG5nLlRvb2xzLmdldFJvdW5kUmVjdCh0aGlzLnN0eWxlLml0ZW1TaXplLCB0aGlzLnN0eWxlLml0ZW1TaXplLCBnZXRNYXhSb3VuZFJhZGl1cyh0aGlzLnN0eWxlLnJhZGl1cywgdGhpcy5zdHlsZS5pdGVtU2l6ZSwgdGhpcy5zdHlsZS5pdGVtU2l6ZSksIDAsIG51bGwsIHRydWUsIHRoaXMuc3R5bGUuY291bnRlckJhY2tncm91bmRDb2xvcilcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIFRleHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgbW91bnRYOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgeDogdGhpcy5zdHlsZS5pdGVtU2l6ZSAvIDIsXG4gICAgICAgICAgICAgICAgICAgIHk6IHRoaXMuc3R5bGUuaXRlbVNpemUgLyAyLFxuICAgICAgICAgICAgICAgICAgICBjb250ZW50OiB0aGlzLmNvdW50ZXJUZXh0IHx8IFwiK1wiLmNvbmNhdChyZW1haW5pbmcpLFxuICAgICAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB0aGlzLnN0eWxlLmNvdW50ZXJUZXh0U3R5bGVcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICB0aGlzLl9Sb3cuYXBwZW5kSXRlbXMoWyBjb3VudGVyIF0pO1xuICAgICAgICB9XG4gICAgfVxuICAgICRpdGVtQ2hhbmdlZCgpIHtcbiAgICAgICAgdGhpcy5zaWduYWwoXCJwcm92aWRlckNoYW5nZWRcIik7XG4gICAgfVxuICAgIF9nZXRWaXNpYmxlQ291bnQoKSB7XG4gICAgICAgIHZhciBtaW4gPSAxO1xuICAgICAgICB2YXIgbWF4ID0gdGhpcy5wcm92aWRlcnMubGVuZ3RoO1xuICAgICAgICB2YXIgdmlzaWJsZUNvdW50ID0gTWF0aC5taW4oTWF0aC5tYXgobWluLCB0aGlzLl92aXNpYmxlQ291bnQpLCBtYXgpO1xuICAgICAgICBpZiAodGhpcy5fdmlzaWJsZUNvdW50IDwgbWluKSB7XG4gICAgICAgICAgICBjb25zb2xlLndhcm4oXCJXYXJuaW5nOiBUaGUgc3BlY2lmaWVkIHZpc2libGUgY291bnQgKFwiLmNvbmNhdCh0aGlzLl92aXNpYmxlQ291bnQsIFwiKSBpcyBsZXNzIHRoYW4gdGhlIG1pbmltdW0gdmFsdWUgKFwiKS5jb25jYXQobWluLCBcIikuIFNldHRpbmcgaXQgdG8gXCIpLmNvbmNhdChtaW4sIFwiLlwiKSk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX3Zpc2libGVDb3VudCA+IG1heCkge1xuICAgICAgICAgICAgY29uc29sZS53YXJuKFwiV2FybmluZzogVGhlIHNwZWNpZmllZCB2aXNpYmxlIGNvdW50IChcIi5jb25jYXQodGhpcy5fdmlzaWJsZUNvdW50LCBcIikgaXMgZ3JlYXRlciB0aGFuIHRoZSBtYXhpbXVtIHZhbHVlIChcIikuY29uY2F0KG1heCwgXCIpLiBTZXR0aW5nIGl0IHRvIFwiKS5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cbiAgICAgICAgICAgIGRpc2FibGVkOiB7XG4gICAgICAgICAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0SW52ZXJzZVxuICAgICAgICB9LFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIGRldGFpbHNUZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfSxcbiAgICBicmFuZDoge1xuICAgICAgICBkZXRhaWxzVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgICAgIH0sXG4gICAgICAgIG1vZGU6IHtcbiAgICAgICAgICAgIGRpc2FibGVkOiB7XG4gICAgICAgICAgICAgICAgZGV0YWlsc1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsRGlzYWJsZWRcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyR0ID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkdCxcbiAgICB0b25lOiB0b25lJGNcbn0pO1xuXG5jbGFzcyBNZXRhZGF0YUNhcmRDb250ZW50IGV4dGVuZHMgTWV0YWRhdGFCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJNZXRhZGF0YUNhcmRDb250ZW50XCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJHQ7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBUZXh0OiB7XG4gICAgICAgICAgICAgICAgZmxleDoge1xuICAgICAgICAgICAgICAgICAgICBkaXJlY3Rpb246IFwiY29sdW1uXCIsXG4gICAgICAgICAgICAgICAgICAgIGp1c3RpZnlDb250ZW50OiBcImZsZXgtc3RhcnRcIlxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgVGl0bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgRGVzY3JpcHRpb246IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgRGVzY3JpcHRpb25EZXRhaWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3hcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgRGV0YWlsc1dyYXBwZXI6IHtcbiAgICAgICAgICAgICAgICBEZXRhaWxzRmFkZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgRGV0YWlsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3Jlc29sdmVEZXRhaWxzXCJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgUHJvdmlkZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgbW91bnQ6IDEsXG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IFByb3ZpZGVyLFxuICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBwcm92aWRlckNoYW5nZWQ6IFwiX3Jlc29sdmVQcm92aWRlclwiXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJkZXNjcmlwdGlvblwiLCBcImRlc2NyaXB0aW9uRGV0YWlsc1wiLCBcImRldGFpbHNcIiwgXCJwcm92aWRlclwiLCBcInRpdGxlXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCB0YWdzKCkge1xuICAgICAgICByZXR1cm4gWyBcIlRleHRcIiwge1xuICAgICAgICAgICAgbmFtZTogXCJUaXRsZVwiLFxuICAgICAgICAgICAgcGF0aDogXCJUZXh0LlRpdGxlXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJEZXNjcmlwdGlvblwiLFxuICAgICAgICAgICAgcGF0aDogXCJUZXh0LkRlc2NyaXB0aW9uXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJEZXNjcmlwdGlvbkRldGFpbHNcIixcbiAgICAgICAgICAgIHBhdGg6IFwiVGV4dC5EZXNjcmlwdGlvbkRldGFpbHNcIlxuICAgICAgICB9LCBcIkRldGFpbHNXcmFwcGVyXCIsIHtcbiAgICAgICAgICAgIG5hbWU6IFwiRGV0YWlsc0ZhZGVyXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkRldGFpbHNXcmFwcGVyLkRldGFpbHNGYWRlclwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiRGV0YWlsc1wiLFxuICAgICAgICAgICAgcGF0aDogXCJEZXRhaWxzV3JhcHBlci5EZXRhaWxzRmFkZXIuRGV0YWlsc1wiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiUHJvdmlkZXJcIixcbiAgICAgICAgICAgIHBhdGg6IFwiRGV0YWlsc1dyYXBwZXIuUHJvdmlkZXJcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIF9zZXREZXRhaWxzKGRldGFpbHMpIHtcbiAgICAgICAgaWYgKGRldGFpbHMpIHtcbiAgICAgICAgICAgIHRoaXMuX2RldGFpbHNQcm9taXNlID0gbmV3IFByb21pc2UoKHJlc29sdmUgPT4ge1xuICAgICAgICAgICAgICAgIHRoaXMuX2RldGFpbHNQcm9taXNlUmVzb2x2ZXIgPSByZXNvbHZlO1xuICAgICAgICAgICAgfSkpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fZGV0YWlsc1Byb21pc2UgPSB1bmRlZmluZWQ7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGRldGFpbHM7XG4gICAgfVxuICAgIF9zZXRQcm92aWRlcihwcm92aWRlcikge1xuICAgICAgICBpZiAocHJvdmlkZXIpIHtcbiAgICAgICAgICAgIHRoaXMuX3Byb3ZpZGVyUHJvbWlzZSA9IG5ldyBQcm9taXNlKChyZXNvbHZlID0+IHtcbiAgICAgICAgICAgICAgICB0aGlzLl9wcm92aWRlclByb21pc2VSZXNvbHZlciA9IHJlc29sdmU7XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlz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gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcFdpZHRoOiB0aGlzLl9UZXh0LndcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZURlc2NyaXB0aW9uRGV0YWlscygpIHtcbiAgICAgICAgdGhpcy5fRGVzY3JpcHRpb25EZXRhaWxzLnBhdGNoKHtcbiAgICAgICAgICAgIGNvbnRlbnQ6IHRoaXMuZGVzY3JpcHRpb25EZXRhaWxzLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS5kZXNjcmlwdGlvbkRldGFpbHNUZXh0U3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBtYXhMaW5lczogMSxcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXA6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuX1RleHQud1xuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgeTogdGhpcy5zdHlsZS5kZXNjcmlwdGlvbkRldGFpbHNTdHlsZS5wYWRkaW5nWVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZURldGFpbHMoKSB7XG4gICAgICAgIHZhciBtYXhXaWR0aCA9IHRoaXMuX2RldGFpbHNNYXhXO1xuICAgICAgICB0aGlzLl9EZXRhaWxzLnBhdGNoKHtcbiAgICAgICAgICAgIGNvbnRlbnQ6IHRoaXMuZGV0YWlscyxcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUuZGV0YWlsc1RleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICBtYXhMaW5lczogMSxcbiAgICAgICAgICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogbWF4V2lkdGggKyB0aGlzLnN0eWxlLmZhZGVXaWR0aCAvIDJcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgaWYgKHRoaXMuX0RldGFpbHMuZmluYWxXID4gbWF4V2lkdGgpIHtcbiAgICAgICAgICAgIHRoaXMuX0RldGFpbHNGYWRlci5wYXRjaCh7XG4gICAgICAgICAgICAgICAgdzogbWF4V2lkdGggKyB0aGlzLnN0eWxlLmZhZGVXaWR0aCAvIDIsXG4gICAgICAgICAgICAgICAgc2hhZGVyOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEZhZGVTaGFkZXIsXG4gICAgICAgICAgICAgICAgICAgIHBvc2l0aW9uTGVmdDogMCxcbiAgICAgICAgICAgICAgICAgICAgcG9zaXRpb25SaWdodDogdGhpcy5zdHlsZS5mYWRlV2lkdGhcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX0RldGFpbHNGYWRlci5zaGFkZXIgPSB1bmRlZmluZWQ7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3Jlc29sdmVEZXRhaWxzKCkge1xuICAgICAgICB0aGlzLl9kZXRhaWxzUHJvbWlzZVJlc29sdmVyICYmIHRoaXMuX2RldGFpbHNQcm9taXNlUmVzb2x2ZXIoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlUG9zaXRpb25zKCk7XG4gICAgfVxuICAgIF91cGRhdGVQcm92aWRlcigpIHtcbiAgICAgICAgaWYgKHRoaXMucHJvdmlkZXIpIHtcbiAgICAgICAgICAgIHRoaXMuX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QodGhlbWUsIDIpLFxuICAgIGV4cGFuZGVkSGVpZ2h0OiB1dGlscyQxLmdldERpbWVuc2lvbnModGhlbWUsIHtcbiAgICAgICAgcmF0aW9YOiAxNixcbiAgICAgICAgcmF0aW9ZOiA5LFxuICAgICAgICB1cENvdW50OiA0XG4gICAgfSkuaCxcbiAgICBpbWFnZVNpemU6IHtcbiAgICAgICAgd2lkdGg6IHV0aWxzJDEuZ2V0RGltZW5zaW9ucyh0aGVtZSwge1xuICAgICAgICAgICAgcmF0aW9YOiAxNixcbiAgICAgICAgICAgIHJhdGlvWTogOSxcbiAgICAgICAgICAgIHVwQ291bnQ6IDRcbiAgICAgICAgfSkudyxcbiAgICAgICAgaGVpZ2h0OiB1dGlscyQxLmdldERpbWVuc2lvbnModGhlbWUsIHtcbiAgICAgICAgICAgIHJhdGlvWDogMTYsXG4gICAgICAgICAgICByYXRpb1k6IDksXG4gICAgICAgICAgICB1cENvdW50OiA0XG4gICAgICAgIH0pLmhcbiAgICB9LFxuICAgIG1ldGFkYXRhOiB7XG4gICAgICAgIGRlc2NyaXB0aW9uVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICBtYXhMaW5lczogMlxuICAgICAgICB9XG4gICAgfSxcbiAgICBwYWRkaW5nVmVydGljYWw6IHRoZW1lLnNwYWNlci5tZCAqIDEuNVxufSk7XG5cbnZhciBzdHlsZXMkcyA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJHNcbn0pO1xuXG5jbGFzcyBDYXJkQ29udGVudCBleHRlbmRzIENhcmQge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJDYXJkQ29udGVudFwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRzO1xuICAgIH1cbiAgICBzdGF0aWMgX3Rlb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b250ZW50VmVydGljYWwgZXh0ZW5kcyBDYXJkQ29udGVudCB7XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIHJldHVybiBcIkNhcmRDb250ZW50VmVydGljYWxcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkcTtcbiAgICB9XG4gICAgX2luaXQoKSB7XG4gICAgICAgIHRoaXMuX29yaWVudGF0aW9uID0gXCJ2ZXJ0aWNhbFwiO1xuICAgICAgICBzdXBlci5faW5pdCgpO1xuICAgIH1cbn1cblxudmFyIGJhc2UkcCA9IHRoZW1lID0+ICh7XG4gICAgZXhwYW5kZWRIZWlnaHQ6IHV0aWxzJDEuZ2V0RGltZW5zaW9ucyh0aGVtZSwge1xuICAgICAgICByYXRpb1g6IDE2LFxuICAgICAgICByYXRpb1k6IDksXG4gICAgICAgIHVwQ291bnQ6IDRcbiAgICB9KS5oICsgdGhlbWUuc3BhY2VyLm1kICogMTQsXG4gICAgbWV0YWRhdGE6IHtcbiAgICAgICAgZGVzY3JpcHRpb25UZXh0U3R5bGU6IHtcbiAgICAgICAgICAgIG1heExpbmVzOiAxXG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyRwID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkcFxufSk7XG5cbmNsYXNzIENhcmRDb250ZW50VmVydGljYWxTbWFsbCBleHRlbmRzIENhcmRDb250ZW50VmVydGljYWwge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJDYXJkQ29udGVudFZlcnRpY2FsU21hbGxcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkcDtcbiAgICB9XG4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YWRpdXMueGw7XG4gICAgdmFyIGxvZ29SYWRpdXMgPSBNYXRoLm1heChyYWRpdXMgLSBwYWRkaW5nWCAvIDIsIDApO1xuICAgIHJldHVybiB7XG4gICAgICAgIGhlaWdodDogdGhlbWUuc3BhY2VyLm1kICogOCxcbiAgICAgICAgaWNvblN0eWxlOiB7XG4gICAgICAgICAgICByYWRpdXM6IHJhZGl1cyxcbiAgICAgICAgICAgIHdpZHRoOiB0aGVtZS5zcGFjZXIueHh4bCxcbiAgICAgICAgICAgIGhlaWdodDogdGhlbWUuc3BhY2VyLnh4eGxcbiAgICAgICAgfSxcbiAgICAgICAgbG9nb1N0eWxlOiB7XG4gICAgICAgICAgICByYWRpdXM6IGxvZ29SYWRpdXMsXG4gICAgICAgICAgICB3aWR0aDogdGhlbWUuc3BhY2VyLm1kICogNyxcbiAgICAgICAgICAgIGhlaWdodDogdGhlbWUuc3BhY2VyLm1kICogNlxuICAgICAgICB9LFxuICAgICAgICBtaW5XaWR0aDogdGhlbWUuc3BhY2VyLm1kICogOSxcbiAgICAgICAgcGFkZGluZ1g6IHBhZGRpbmdYLFxuICAgICAgICBwYWRkaW5nWE5vVGl0bGU6IHRoZW1lLnNwYWNlci5tZCxcbiAgICAgICAgcHJlZml4UGFkZGluZzogdGhlbWUuc3BhY2VyLm1kLFxuICAgICAgICByYWRpdXM6IHJhZGl1cyxcbiAgICAgICAgY29udGVudFNwYWNpbmc6IHRoZW1lLnNwYWNlci5tZFxuICAgIH07XG59O1xuXG52YXIgc3R5bGVzJG0gPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSRtXG59KTtcblxuY2xhc3MgQ29udHJvbCBleHRlbmRzIEJ1dHRvblNtYWxsIHtcbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiQ29udHJvbFwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF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AgICAgICAgICAgfSwgdGhpcy5zdHlsZS5sb2dvU3R5bGUpXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuaWNvbikge1xuICAgICAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVByZWZpeE9iaih0aGlzLmljb24sIHtcbiAgICAgICAgICAgICAgICAgICAgc3R5bGU6IHRoaXMuc3R5bGUuaWNvblN0eWxlXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3BhdGNoVGl0bGUoeCwgbW91bnRYKSB7XG4gICAgICAgIHRoaXMuX1RpdGxlLnBhdGNoKHtcbiAgICAgICAgICAgIHg6IHgsXG4gICAgICAgICAgICBtb3VudFg6IG1vdW50WFxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZUNvbnRlbnRQb3NpdGlvbigpIHtcbiAgICAgICAgaWYgKHRoaXMuX3ByZWZpeCAmJiB0aGlzLl9UaXRsZSkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgbW91bnRYOiAwLFxuICAgICAgICAgICAgICAgIHg6IHRoaXMuX3BhZGRpbmdMZWZ0XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHN3aXRjaCAodGhpcy5fanVzdGlmeSkge1xuICAgICAgICAgICAgICBjYXNlIFwibGVmdFwiOlxuICAgICAgICAgICAgICAgIHRoaXMuX3BhdGNoVGl0bGUoMCwgMCk7XG4gICAgICAgICAgICAgICAgYnJlYWs7XG5cbiAgICAgICAgICAgICAgY2FzZSBcInJpZ2h0XCI6XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMudyA8IHRoaXMuX1ByZWZpeC53ICsgdGhpcy5fVGl0bGUudykge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9wYXRjaFRpdGxlKDAsIDApO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBsZWZ0T3ZlclNwYWNlID0gdGhpcy53IC0gKHRoaXMuX3BhZGRpbmdMZWZ0ICsgdGhpcy5fcGFkZGluZ1JpZ2h0ICsgdGhpcy5fUHJlZml4LncgKyB0aGlzLnN0eWxlLmNvbnRlbnRTcGFjaW5nKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fcGF0Y2hUaXRsZShsZWZ0T3ZlclNwYWNlLCAxKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWs7XG5cbiAgICAgICAgICAgICAgY2FzZSBcImNlbnRlclwiOlxuICAgICAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgICAgIGlmICh0aGlzLmZpeGVkKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLncgPCB0aGlzLl9QcmVmaXgudyArIHRoaXMuX1RpdGxlLncpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX3BhdGNoVGl0bGUoMCwgMCk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgbWlkZGxlID0gKHRoaXMudyAtICh0aGlzLl9wYWRkaW5nTGVmdCArIHRoaXMuX1ByZWZpeC53ICsgdGhpcy5fcGFkZGluZ1JpZ2h0KSkgLyAyO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5fcGF0Y2hUaXRsZShtaWRkbGUsIC41KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fUHJlZml4ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIF9taWRkbGUgPSAodGhpcy53IC0gKHRoaXMuX3BhZGRpbmdMZWZ0ICsgdGhpcy5fUHJlZml4LncgKyB0aGlzLnN0eWxlLmNvbnRlbnRTcGFjaW5nICsgdGhpcy5fcGFkZGluZ1JpZ2h0KSkgLyAyO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9wYXRjaFRpdGxlKF9taWRkbGUsIC41KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzdXBlci5fdXBkYXRlQ29udGVudFBvc2l0aW9uKCk7XG4gICAgICAgICAgICB0aGlzLl9UaXRsZSAmJiB0aGlzLl9wYXRjaFRpdGxlKDAsIDApO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9zZXRQcmVmaXgoKSB7XG4gICAgICAgIHJldHVybjtcbiAgICB9XG4gICAgX3NldFN1ZmZpeCgpIHtcbiAgICAgICAgcmV0dXJuO1xuICAgIH1cbiAgICBfdXBkYXRlUHJlZml4T2JqKGljb24pIHtcbiAgICAgICAgdmFyIHByb3BzID0gYXJndW1lbnRzLmxlbmd0aCA+IDEgJiYgYXJndW1lbnRzWzFdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMV0gOiB7fTtcbiAgICAgICAgdGhpcy5fcHJlZml4ID0gX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgaWNvbjogaWNvblxuICAgICAgICB9LCBwcm9wcyk7XG4gICAgfVxuICAgIF9zZXRJY29uKGljb24pIHtcbiAgICAgICAgaWYgKCF0aGlzLmxvZ28pIHtcbiAgICAgICAgICAgIGlmIChpY29uKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fdXBkYXRlUHJlZml4T2JqKGljb24sIHtcbiAgICAgICAgICAgICAgICAgICAgc3R5bGU6IHRoaXMuc3R5bGUuaWNvblN0eWxlXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX3ByZWZpeCA9IGljb247XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAg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Hx8IHRoaXMuc3R5bGUudztcbiAgICAgICAgdGhpcy5oID0gdGhpcy5hdXRvUmVzaXplSGVpZ2h0ID8gdGhpcy5JdGVtcy55ICsgdGhpcy5JdGVtcy5oIDogdGhpcy5oO1xuICAgIH1cbiAgICBfdXBkYXRlVGl0bGUoKSB7XG4gICAgICAgIGlmICghdGhpcy50aXRsZSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuX1RpdGxlKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIFRpdGxlOiB1bmRlZmluZWRcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICB2YXIgdGl0bGVQYXRjaCA9IHtcbiAgICAgICAgICAgIHg6IHRoaXMuc3R5bGUudGl0bGVNYXJnaW5MZWZ0LFxuICAgICAgICAgICAgY29udGVudDogdGhpcy50aXRsZSxcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB0aGlzLnN0eWxlLnRpdGxlVGV4dFN0eWxlXG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICAgIGlmICghdGhpcy5fVGl0bGUpIHtcbiAgICAgICAgICAgIHRpdGxlUGF0Y2ggPSBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuX3RpdGxlRmlyc3RMb2FkUHJvcHMpLCB0aXRsZVBhdGNoKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIFRpdGxlOiB0aXRsZVBhdGNoXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBnZXQgX3RpdGxlRmlyc3RMb2FkUHJvcHMoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgc2lnbmFsczoge1xuICAg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IuX3RlbXBsYXRlKCkpLCB7fSwge1xuICAgICAgICAgICAgYWxwaGE6IDAsXG4gICAgICAgICAgICBsYXp5U2Nyb2xsOiB0cnVlLFxuICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgIHNlbGVjdGVkQ2hhbmdlOiBcIl9nZXRNb3JlSXRlbXNcIlxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gWyAuLi5zdXBlci5wcm9wZXJ0aWVzLCBcImV4dHJhSXRlbVNwYWNpbmdcIiBdO1xuICAgIH1cbiAgICBfY29uc3RydWN0KCkge1xuICAgICAgICBzdXBlci5fY29uc3RydWN0KCk7XG4gICAgICAgIHRoaXMuX2xlZnRDb250cm9scyA9IFtdO1xuICAgICAgICB0aGlzLl9jb250ZW50SXRlbXMgPSBbXTtcbiAgICAgICAgdGhpcy5fcmlnaHRDb250cm9scyA9IFtdO1xuICAgICAgICB0aGlzLl9sYXN0TGVmdENvbnRyb2xJbmRleCA9IC0xO1xuICAgICAgICB0aGlzLl9sYXN0SXRlbUluZGV4ID0gLTE7XG4gICAgICAgIHRoaXMuX2xhenlMb2FkQnVmZmVyID0gMDtcbiAgICB9XG4gICAgX3VwZGF0ZUNvbnRlbnQoKSB7XG4gICAgICAgIHZhciBpdGVtc1RvQXBwZW5kID0gW107XG4gICAgICAgIGlmICh0aGlzLmxlZnRDb250cm9scy5sZW5ndGgpIHtcbiAgICAgICAgICAgIGl0ZW1zVG9BcHBlbmQucHVzaCguLi50aGlzLl93aXRoRXh0cmFTcGFjaW5nKHRoaXMubGVmdENvbnRyb2xzLCB0cnVlKSk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuY29udGVudEl0ZW1zLmxlbmd0aCkge1xuICAgICAgICAgICAgaXRlbXNUb0FwcGVuZC5wdXNoKC4uLnRoaXMuX3dpdGhFeHRyYVNwYWN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W5kZXgsIHRoaXMuX2xhc3RMZWZ0Q29udHJvbEluZGV4KTtcbiAgICAgICAgaWYgKHRoaXMuX2xlZnRDb250cm9scykge1xuICAgICAgICAgICAgdGhpcy5fbGVmdENvbnRyb2xzID0gWyAuLi50aGlzLl9sZWZ0Q29udHJvbHMsIC4uLmNvbnRyb2xzIF07XG4gICAgICAgICAgICB0aGlzLl9sYXN0TGVmdENvbnRyb2xJbmRleCA9IHRoaXMuX2xlZnRDb250cm9scy5sZW5ndGggLSAxO1xuICAgICAgICAgICAgdGhpcy5fbGFzdEl0ZW1JbmRleCArPSBjb250cm9scy5sZW5ndGg7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICBzdGFydExhenlTY3JvbGxJbmRleDogdGhpcy5sZWZ0Q29udHJvbHMubGVuZ3RoLFxuICAgICAgICAgICAgc3RvcExhenlTY3JvbGxJbmRleDogdGhpcy5sZWZ0Q29udHJvbHMubGVuZ3RoICsgdGhpcy5pdGVtcy5sZW5ndGggLSAxXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBhZGRMZWZ0Q29udHJvbHNBdChjb250cm9scywgaW5kZXgpIHtcbiAgICAgICAgdmFyIGl0ZW1zVG9BZGQgPSB0aGlzLl9jcmVhdGVDb250cm9scyhjb250cm9scyk7XG4gICAgICAgIGlmIChpbmRleCA9PT0gdGhpcy5fbGFzdExlZnRDb250cm9sSW5kZXggKyAxKSB7XG4gICAgICAgICAgICB0aGlzLmFkZExlZnRDb250cm9scyhjb250cm9scyk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9hcHBlbmRJdGVtc0F0KGl0ZW1zVG9BZGQsIGluZGV4KTtcbiAgICAgICAgICAgIGlmICh0aGlzLmxlZnRDb250cm9scykge1xuICAgICAgICAgICAgICAgIHRoaXMuX2xlZnRDb250cm9scy5zcGxpY2UoaW5kZXgsIDAsIC4uLmNvbnRyb2xzKTtcbiAgICAgICAgICAgICAgICB0aGlzLl9sYXN0TGVmdENvbnRyb2xJbmRleCA9IHRoaXMuX2xlZnRDb250cm9scy5sZW5ndGggLSAxO1xuICAgICAgICAgICAgICAgIHRoaXMuX2xhc3RJdGVtSW5kZXggKz0gY29udHJvbHMubGVuZ3RoO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgc3RhcnRMYXp5U2Nyb2xsSW5kZXg6IHRoaXMubGVmdENvbnRyb2xzLmxlbmd0aCxcbiAgICAgICAgICAgICAgICBzdG9wTGF6eVNjcm9sbEluZGV4OiB0aGlzLmxlZnRDb250cm9scy5sZW5ndGggKyB0aGlzLml0ZW1zLmxlbmd0aCAtIDFcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIHJlbW92ZUxlZnRDb250cm9sQXQoaW5kZXgpIHtcbiAgICAgICAgdGhpcy5yZW1vdmVJdGVtQXQoaW5kZXgpO1xuICAgICAgICB0aGlzLl9sYXN0TGVmdENvbnRyb2xJbmRleC0tO1xuICAgICAgICB0aGlzLl9sYXN0SXRlbUluZGV4LS07XG4gICAgICAgIGlmICh0aGlzLmxlZnRDb250cm9scykge1xuICAgICAgICAgICAgdGhpcy5fbGVmdENvbnRyb2xzLnNwbGljZShpbmRleCwgMSk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICBzdGFydExhenlTY3JvbGxJbmRleDogdGhpcy5sZWZ0Q29udHJvbHMubGVuZ3RoLFxuICAgICAgICAgICAgc3RvcExhenlTY3JvbGxJbmRleDogdGhpcy5sZWZ0Q29udHJvbHMubGVuZ3RoICsgdGhpcy5pdGVtcy5sZW5ndGggLSAxXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBhZGRSaWdodENvbnRyb2xzKGNvbnRyb2xzKSB7XG4gICAgICAgIHRoaXMuX3JpZ2h0Q29udHJvbHMucHVzaCguLi5jb250cm9scyk7XG4gICAgICAgIHRoaXMuX2FwcGVuZEl0ZW1zQXQodGhpcy5fY3JlYXRlQ29udHJvbHMoY29udHJvbHMpLCB0aGlzLml0ZW1zLmxlbmd0aCk7XG4gICAgfVxuICAgIGFkZFJpZ2h0Q29udHJvbHNBdChjb250cm9scywgaW5kZXgpIHtcbiAgICAgICAgdmFyIGFwcGVuZEluZGV4ID0gdGhpcy5fbGVmdENvbnRyb2xzLmxlbmd0aCArIHRoaXMuX2NvbnRlbnRJdGVtcy5sZW5ndGggKyBpbmRleDtcbiAgICAgICAgdGhpcy5fcmlnaHRDb250cm9scy5zcGxpY2UoaW5kZXgsIDAsIC4uLmNvbnRyb2xzKTtcbiAgICAgICAgdGhpcy5fYXBwZW5kSXRlbXNBdCh0aGlzLl9jcmVhdGVDb250cm9scyhjb250cm9scyksIGFwcGVuZEluZGV4KTtcbiAgICB9XG4gICAgcmVtb3ZlUmlnaHRDb250cm9sQXQoaW5kZXgpIHtcbiAgICAgICAgdmFyIHJlbW92ZUluZGV4ID0gdGhpcy5sZWZ0Q29udHJvbHMubGVuZ3RoICsgdGhpcy5jb250ZW50SXRlbXMubGVuZ3RoICsgaW5kZXg7XG4gICAgICAgIHRoaXMucmVtb3ZlSXRlbUF0KHJlbW92ZUluZGV4KTtcbiAgICAgICAgaWYgKHRoaXMucmlnaHRDb250cm9scykge1xuICAgICAgICAgICAgdGhpcy5fcmlnaHRDb250cm9scy5zcGxpY2UoaW5kZXgsIDEpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9jcmVhdGVDb250cm9scyhjb250cm9scykge1xuICAgICAgICByZXR1cm4gY29udHJvbHMubWFwKChjb250cm9sUHJvcHMgPT4gX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICBiYWNrZ3JvdW5kVHlwZTogXCJmaWxsXCIsXG4gICAgICAgICAgICBjZW50ZXJJblBhcmVudDogdHJ1ZVxuICAgICAgICB9LCBjb250cm9sUHJvcHMpKSk7XG4gICAgfVxuICAgIF9jcmVhdGVDb250ZW50SXRlbXMoY29udGVudEl0ZW1zKSB7XG4gICAgICAgIHZhciBuZXdDb250ZW50SXRlbXMgPSBjb250ZW50SXRlbXMubWFwKChpdGVtUHJvcHMgPT4gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBpdGVtUHJvcHMpLCB7fSwge1xuICAgICAgICAgICAgY2VudGVySW5QYXJlbnQ6IHRydWVcbiAgICAgICAgfSkpKTtcbiAgICAgICAgcmV0dXJuIG5ld0NvbnRlbnRJdGVtcztcbiAgICB9XG4gICAgX3NldExlZnRDb250cm9scyhsZWZ0Q29udHJvbHMpIHtcbiAgICAgICAgdGhpcy5fbGVmdENvbnRyb2xzID0gdGhpcy5fY3JlYXRlQ29udHJvbHMobGVmdENvbnRyb2xzKTtcbiAgICAgICAgdGhpcy5fbGFzdExlZnRDb250cm9sSW5kZXggPSBsZWZ0Q29udHJvbHMubGVuZ3RoIC0gMTtcbiAgICAgICAgdGhpcy5fdXBkYXRlQ29udGVudCgpO1xuICAgIH1cbiAgICBfZ2V0TGVmdENvbnRyb2xzKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fbGVmdENvbnRyb2xzO1xuICAgIH1cbiAgICBfc2V0UmlnaHRDb250cm9scyhyaWdodENvbnRyb2xzKSB7XG4gICAgICAgIHRoaXMuX3JpZ2h0Q29udHJvbHMgPSB0aGlzLl9jcmVhdGVDb250cm9scyhyaWdodENvbnRyb2xzKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlQ29udGVudCgpO1xuICAgIH1cbiAgICBfZ2V0UmlnaHRDb250cm9scygpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3JpZ2h0Q29udHJvbHM7XG4gICAgfVxuICAgIF9nZXRDb250ZW50SXRlbXMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9jb250ZW50SXRlbXM7XG4gICAgfVxuICAgIF9zZXRDb250ZW50SXRlbXMoaXRlbXMpIHtcbiAgICAgICAgdGhpcy5fY29udGV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vci50ZXh0TmV1dHJhbFxuICAgIH0pLFxuICAgIHZhbHVlVGV4dFN0eWxlOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoZW1lLnR5cG9ncmFwaHkuYm9keTEpLCB7fSwge1xuICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgfSlcbn0pO1xuXG52YXIgc3R5bGVzJGkgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSRpXG59KTtcblxuY2xhc3MgU3BhY2VyIGV4dGVuZHMgQmFzZSQxIHtcbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiU3BhY2VyXCI7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBMaW5lOiB7XG4gICAgICAgICAgICAgICAgaDogU3BhY2VyLl9saW5lVGhpY2tuZXNzLFxuICAgICAgICAgICAgICAgIHJlY3Q6IHRydWUsXG4gICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICBUaWNrTGVmdDogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBTcGFjZXIuX3RpY2spLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICB4OiBTcGFjZXIuX2xpbmVUaGlja25lc3MgKiAtMVxuICAgICAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgICAgIFRpY2tSaWdodDogU3BhY2VyLl90aWNrXG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJsaW5lQ29sb3JcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICA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XJsYXlcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkaTtcbiAgICB9XG4gICAgc3RhdGljIF90ZW1wbGF0ZSgpIHtcbiAgICAgICAgdmFyIHRleHRSb3cgPSB7XG4gICAgICAgICAgICB0eXBlOiBSb3csXG4gICAgICAgICAgICBhdXRvUmVzaXplSGVpZ2h0OiB0cnVlLFxuICAgICAgICAgICAgSXRlbXM6IHtcbiAgICAgICAgICAgICAgICBQcm9wZXJ0eToge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0Qm94Q2hhbmdlZDogXCJfdXBkYXRlXCJcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgVmFsdWU6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3VwZGF0ZVwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIGNlbnRlckluUGFyZW50OiB0cnVlXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgQ29sdW1uczoge1xuICAgICAgICAgICAgICAgIGFscGhhOiAuMDAxLFxuICAgICAgICAgICAgICAgIHR5cGU6IFJvd1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIE1hcmdpbnM6IHtcbiAgICAgICAgICAgICAgICBhbHBoYTogLjAwMSxcbiAgICAgICAgICAgICAgICBIb3Jpem9udGFsOiB7XG4gICAgICAgICAgICAgICAgICAgIExlZnQ6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFNwYWNlcixcbiAgICAgICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzcGFjZXJMb2FkZWQ6IFwiX3VwZGF0ZVwiXG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIFJpZ2h0OiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBTcGFjZXIsXG4gICAgICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgc3BhY2VyTG9hZGVkOiBcIl91cGRhdGVcIlxuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBWZXJ0aWNhbDoge1xuICAgICAgICAgICAgICAgICAgICBUb3A6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFNwYWNlcixcbiAgICAgICAgICAgICAgICAgICAgICAgIHZlcnRpY2FsOiB0cnVlXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgU2FmZToge1xuICAgICAgICAgICAgICAgIGFscGhhOiAuMDAxLFxuICAgICAgICAgICAgICAgIEhvcml6b250YWw6IHtcbiAgICAgICAgICAgICAgICAgICAgTGVmdDoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogU3BhY2VyLFxuICAgICAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNwYWNlckxvYWRlZDogXCJfdXBkYXRlXCJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgUmlnaHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFNwYWNlcixcbiAgICAgICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzcGFjZXJMb2FkZWQ6IFwiX3VwZGF0ZVwiXG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIFZlcnRpY2FsOiB7XG4gICAgICAgICAgICAgICAgICAgIFRvcDoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogU3BhY2VyLFxuICAgICAgICAgICAgICAgICAgICAgICAgdmVydGljYWw6IHRydWVcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgQm90dG9tOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBTcGFjZXIsXG4gICAgICAgICAgICAgICAgICAgICAgICB2ZXJ0aWNhbDogdHJ1ZVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIEd1dHRlcnM6IHtcbiAgICAgICAgICAgICAgICBhbHBoYTogLjAwMSxcbiAgICAgICAgICAgICAgICBIb3Jpem9udGFsOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IFNwYWNlcixcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3BhY2VyTG9hZGVkOiBcIl91cGRhdGVcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIFRleHRQYW5lbDoge1xuICAgICAgICAgICAgICAgIGFscGhhOiAuMDAxLFxuICAgICAgICAgICAgICAgIHR5cGU6IENvbHVtbixcbiAgICAgICAgICAgICAgICBhdXRvUmVzaXplSGVpZ2h0OiB0cnVlLFxuICAgICAgICAgICAgICAgIEl0ZW1zOiB7XG4gICAgICAgICAgICAgICAgICAgIFNjcmVlblc6IHRleHRSb3csXG4gICAgICAgICAgICAgICAgICAgIFNjcmVlbkg6IHRleHRSb3csXG4gICAgICAgICAgICAgICAgICAgIENvbHVtbkNvdW50OiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBNYXJnaW5YOiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBNYXJnaW5ZOiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBHdXR0ZXJYOiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBHdXR0ZXJZOiB0ZXh0Um93LFxuICAgICAgICAgICAgICAgICAgICBTYWZlOiB0ZXh0Um93XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwic2hvd0NvbHVtbnNcIiwgXCJzaG93TWFyZ2luc1wiLCBcInNob3dTYWZlXCIsIFwic2hvd0d1dHRlcnNcIiwgXCJzaG93VGV4dFwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJDb2x1bW5zXCIsIFwiTWFyZ2luc1wiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIk1hcmdpbkhvcml6b250YWxcIixcbiAgICAgICAgICAgIHBhdGg6IFwiTWFyZ2lucy5Ib3Jpem9udGFsXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJNYXJnaW5MZWZ0XCIsXG4gICAgICAgICAgICBwYXRoOiBcIk1hcmdpbnMuSG9yaXpvbnRhbC5MZWZ0XCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJNYXJnaW5SaWdodFwiLFxuICAgICAgICAgICAgcGF0aDogXCJNYXJnaW5zLkhvcml6b250YWwuUmlnaHRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIk1hcmdpblZlcnRpY2FsXCIsXG4gICAgICAgICAgICBwYXRoOiBcIk1hcmdpbnMuVmVydGljYWxcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIk1hcmdpblRvcFwiLFxuICAgICAgICAgICAgcGF0aDogXCJNYXJnaW5zLlZlcnRpY2FsLlRvcFwiXG4gICAgICAgIH0sIFwiU2FmZVwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIlNhZmVIb3Jpem9udGFsXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlNhZmUuSG9yaXpvbnRhbFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiU2FmZUxlZnRcIixcbiAgICAgICAgICAgIHBhdGg6IFwiU2FmZS5Ib3Jpem9udGFsLkxlZnRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlNhZmVSaWdodFwiLFxuICAgICAgICAgICAgcGF0aDogXCJTYWZlLkhvcml6b250YWwuUmlnaHRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlNhZmVWZXJ0aWNhbFwiLFxuICAgICAgICAgICAgcGF0aDogXCJTYWZlLlZlcnRpY2FsXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJTYWZlVG9wXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlNhZmUuVmVydGljYWwuVG9wXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJTYWZlQm90dG9tXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlNhZmUuVmVydGljYWwuQm90dG9tXCJcbiAgICAgICAgfSwgXCJHdXR0ZXJzXCIsIHtcbiAgICAgICAgICAgIG5hbWU6IFwiR3V0dGVySG9yaXpvbnRhbFwiLFxuICAgICAgICAgICAgcGF0aDogXCJHdXR0ZXJzLkhvcml6b250YWxcIlxuICAgICAgICB9LCBcIlRleHRQYW5lbFwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIlRleHRTY3JlZW5XXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHRQYW5lbC5JdGVtcy5TY3JlZW5XXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJUZXh0U2NyZWVuSFwiLFxuICAgICAgICAgICAgcGF0aDogXCJUZXh0UGFuZWwuSXRlbXMuU2NyZWVuSFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGV4dENvbHVtbkNvdW50XCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHRQYW5lbC5JdGVtcy5Db2x1bW5Db3VudFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGV4dE1hcmdpblhcIixcbiAgICAgICAgICAgIHBhdGg6IFwiVGV4dFBhbmVsLkl0ZW1zLk1hcmdpblhcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlRleHRNYXJnaW5ZXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHRQYW5lbC5JdGVtcy5NYXJnaW5ZXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJUZXh0R3V0dGVyWFwiLFxuICAgICAgICAgICAgcGF0aDogXCJUZXh0UGFuZWwuSXRlbXMuR3V0dGVyWFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGV4dEd1dHRlcllcIixcbiAgICAgICAgICAgIHBhdGg6IFwiVGV4dFBhbmVsLkl0ZW1zLkd1dHRlcllcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlRleHRTYWZlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIlRleHRQYW5lbC5JdGVtcy5TYWZlXCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBfY29uc3RydWN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V4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICB9LFxuICAgICAgICBoZWxwVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsU2Vjb25kYXJ5XG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHRvbmUkYSA9IHRoZW1lID0+ICh7XG4gICAgaW52ZXJzZToge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBmb2N1c2VkOiB7XG4gICAgICAgICAgICAgICAgZXllYnJvd1RleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBoZWxwVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyRoID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkaCxcbiAgICBtb2RlOiBtb2RlJDYsXG4gICAgdG9uZTogdG9uZSRhXG59KTtcblxuY2xhc3MgSW5wdXQgZXh0ZW5kcyBCdXR0b24ge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJJbnB1dFwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRoO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9L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Ck7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVRpdGxlU2Nyb2xsUG9zaXRpb24oKTtcbiAgICB9XG4gICAgX3VwZGF0ZVBhc3N3b3JkKCkge1xuICAgICAgICB0aGlzLnRpdGxlID0gdGhpcy5wYXNzd29yZCA/IHRoaXMubWFzay5yZXBlYXQodGhpcy5hY3R1YWxUaXRsZS5sZW5ndGgpIDogdGhpcy5hY3R1YWxUaXRsZTtcbiAgICB9XG4gICAgX3VwZGF0ZVRydW5jYXRpb24oKSB7XG4gICAgICAgIGlmICh0aGlzLl9UaXRsZSkge1xuICAgICAgICAgICAgdGhpcy5fVGl0bGUucGF0Y2goe1xuICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlLnRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogZmFsc2VcbiAgICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlRXllYnJvdygpIHtcbiAgICAgICAgdGhpcy5fRXllYnJvdy5wYXRjaCh7XG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLmV5ZWJyb3csXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIHRleHRTdHlsZTogdGhpcy5zdHlsZS5leWVicm93VGV4dFN0eWxlXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgbW91bnRZOiAxLFxuICAgICAgICAgICAgeDogdGhpcy5zdHlsZS5wYWRkaW5nWCxcbiAgICAgICAgICAgIHk6IHRoaXMueSAtIHRoaXMuc3R5bGUucGFkZGluZ1lcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVIZWxwVGV4dCgpIHtcbiAgICAgICAgdGhpcy5fSGVscFRleHQucGF0Y2goe1xuICAgICAgICAgICAgY29udGVudDogdGhpcy5oZWxwVGV4dCxcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB0aGlzLnN0eWxlLmhlbHBUZXh0U3R5bGVcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICB4OiB0aGlzLnN0eWxlLnBhZGRpbmdYLFxuICAgICAgICAgICAgeTogdGhpcy55ICsgdGhpcy5pbm5lckggKyB0aGlzLnN0eWxlLnBhZGRpbmdZXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlVGV4dFdyYXBwZXIoKSB7XG4gICAgICAgIHRoaXMuX1RleHRXcmFwcGVyLmNsaXBwaW5nID0gdHJ1ZTtcbiAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIudyA9IHRoaXMuX3Zpc2libGVDb250ZW50V2lkdGg7XG4gICAgICAgIGlmICh0aGlzLl9UaXRsZSkge1xuICAgICAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIuaCA9IHRoaXMuX1RpdGxlLmg7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZUhpZGRlbkNvbnRlbnQoKSB7XG4gICAgICAgIGlmICghdGhpcy5fSGlkZGVuQ29udGVudCkge1xuICAgICAgICAgICAgdGhpcy5fQ29udGVudC5wYXRjaCh7XG4gICAgICAgICAgICAgICAgSGlkZGVuQ29udGVudDoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyLFxuICAgICAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0Qm94Q2hhbmdlZDogXCJfb25IaWRkZW5UZXh0Qm94Q2hhbmdlZFwiXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgIC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ICB9XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgdGhpcy5jdXJzb3JCbGluayA9IHRoaXMuX0N1cnNvci5hbmltYXRpb24oe1xuICAgICAgICAgICAgICAgICAgICBkdXJhdGlvbjogMS41LFxuICAgICAgICAgICAgICAgICAgICByZXBlYXQ6IC0xLFxuICAgICAgICAgICAgICAgICAgICBhY3Rpb25zOiBbIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHA6IFwiYWxwaGFcIixcbiAgICAgICAgICAgICAgICAgICAgICAgIHY6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAwOiAwLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC41OiAxLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIDE6IDBcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSBdXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9DdXJzb3IucGF0Y2godGhpcy5zdHlsZS5jdXJzb3JTdHlsZSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZUN1cnNvckxpc3RlbmluZygpIHtcbiAgICAgICAgaWYgKCF0aGlzLl9pc0Rpc2FibGVkTW9kZSkge1xuICAgICAgICAgICAgaWYgKHRoaXMuY3Vyc29yQmxpbmsgJiYgIXRoaXMuY3Vyc29yQmxpbmsuaXNQbGF5aW5nKCkpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmN1cnNvckJsaW5rLnN0YXJ0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAodGhpcy5jdXJzb3JCbGluaykgdGhpcy5pc0N1cnNvckFjdGl2ZSA/IHRoaXMuY3Vyc29yQmxpbmsuc3RhcnQoKSA6IHRoaXMuY3Vyc29yQmxpbmsuc3RvcCgpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX0N1cnNvci5zbW9vdGggPSB7XG4gICAgICAgICAgICBjb2xvcjogdGhpcy5zdHlsZS5jdXJzb3JTdHlsZS50ZXh0Q29sb3JcbiAgICAgICAgfTtcbiAgICB9XG4gICAgX3VwZGF0ZUN1cnNvckJsaW5rKCkge1xuICAgICAgICBpZiAodGhpcy5jdXJzb3JCbGluaykge1xuICAgICAgICAgICAgaWYgKHRoaXMuaXNDdXJzb3JBY3RpdmUpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmN1cnNvckJsaW5rLnN0YXJ0KCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuY3Vyc29yQmxpbmsuc3RvcCgpO1xuICAgICAgICAgICAgICAgIHRoaXMuX0N1cnNvci5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIGFscGhhOiAuMDAxXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZUN1cnNvclBvc2l0aW9uKCkge1xuICAgICAgICB0aGlzLl9DdXJzb3IueCA9IHRoaXMuX3RpdGxlWCArICh0aGlzLl9pc092ZXJmbG93ID8gdGhpcy5fVGV4dFdyYXBwZXIudyA6IHRoaXMuX0hpZGRlbkNvbnRlbnQudyk7XG4gICAgfVxuICAgIF91cGRhdGVUaXRsZVNjcm9sbFBvc2l0aW9uKCkge1xuICAgICAgICBpZiAodGhpcy5fVGl0bGUpIHtcbiAgICAgICAgICAgIHRoaXMuX1RpdGxlLnggPSB0aGlzLl9pc092ZXJmbG93ID8gdGhpcy5fdmlzaWJsZUNvbnRlbnRXaWR0aCAtIHRoaXMuX0hpZGRlbkNvbnRlbnQudyA6IDA7XG4gICAgICAgICAgICBpZiAodGhpcy5fSGlkZGVuQ29udGVudCAmJiB0aGlzLl9UZXh0V3JhcHBlcikge1xuICAgICAgICAgICAgICAgIHRoaXMuX0hpZGRlbkNvbnRlbnQueCA9IHRoaXMuX1RleHR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eXBlb2YgdGhpcy5vbkxlZnQgPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMub25MZWZ0KHRoaXMpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0cnVlO1xuICAgIH1cbiAgICBfaGFuZGxlUmlnaHQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9pc0Rpc2FibGVkTW9kZSkge1xuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMubW92ZVJpZ2h0KCk7XG4gICAgICAgIGlmICh0eXBlb2YgdGhpcy5vblJpZ2h0ID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLm9uUmlnaHQodGhpcyk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgfVxuICAgIG1vdmVMZWZ0KCkge1xuICAgICAgICB2YXIge3Bvc2l0aW9uOiBwb3NpdGlvbn0gPSB0aGlzO1xuICAgICAgICBpZiAocG9zaXRpb24gPj0gMCkge1xuICAgICAgICAgICAgdGhpcy5wb3NpdGlvbi0tO1xuICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cbiAgICBtb3ZlUmlnaHQoKSB7XG4gICAgICAgIHZhciB7cG9zaXRpb246IHBvc2l0aW9uLCB0aXRsZTogdGl0bGV9ID0gdGhpcztcbiAgICAgICAgaWYgKHBvc2l0aW9uIDwgdGl0bGUubGVuZ3RoKSB7XG4gICAgICAgICAgICB0aGlzLnBvc2l0aW9uKys7XG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuICAgIHNldCBhbm5vdW5jZShhbm5vdW5jZSkge1xuICAgICAgICBzdXBlci5hbm5vdW5jZSA9IGFubm91bmNlO1xuICAgIH1cbiAgICBnZXQgYW5ub3VuY2UoKSB7XG4gICAgICAgIGlmICh0aGlzLl9hbm5vdW5jZSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2Fubm91bmNlO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLnBhc3N3b3JkKSB7XG4gICAgICAgICAgICByZXR1cm4gWyB0aGlzLmV5ZWJyb3csIHRoaXMuaGVscFRleHQgXTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiBbIHRoaXMuZXllYnJvdywgXCJJbnB1dDogXCIgKyB0aGlzLnRpdGxlLCB0aGlzLmhlbHBUZXh0IF07XG4gICAgICAgIH1cbiAgICB9XG59XG5cbnZhciBiYXNlJGcgPSB0aGVtZSA9PiB7XG4gICAgdmFyIHRleHRTdHlsZSA9IHRoZW1lLnR5cG9ncmFwaHkuaGVhZGxpbmUyO1xuICAgIHJldHVybiB7XG4gICAgICAgIGhlaWdodDogdGhlbWUuc3BhY2VyLm1kICogOSxcbiAgICAgICAgbWluV2lkdGg6IHRoZW1lLnNwYWNlci5tZCAqIDcsXG4gICAgICAgIHBhZGRpbmdYOiB0aGVtZS5zcGFjZXIubWQsXG4gICAgICAgIHRleHRTdHlsZTogdGV4dFN0eWxlLFxuICAgICAgICBzaXplczoge1xuICAgICAgICAgICAgc206IDEsXG4gICAgICAgICAgICBtZDogMixcbiAgICAgICAgICAgIGxnOiAzLFxuICAgICAgICAgICAgeGw6IDQsXG4gICAgICAgICAgICB4eGw6IDVcbiAgICAgICAgfSxcbiAgICAgICAgYmFzZVdpZHRoOiB0aGVtZS5zcGFjZXIubWQgKiA3LFxuICAgICAgICBpY29uV2lkdGg6IHRleHRTdHlsZS5saW5lSGVpZ2h0LFxuICAgICAgICBpY29uSGVpZ2h0OiB0ZXh0U3R5bGUubGluZUhlaWdodFxuICAgIH07XG59O1xuXG52YXIgc3R5bGVzJGcgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51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2lkdGggKiBzaXplTXVsdGlwbGllcjtcbiAgICAgICAgdmFyIHBhZGRpbmcgPSB0aGlzLmtleVNwYWNpbmcgKiAoc2l6ZU11bHRpcGxpZXIgLSAxKTtcbiAgICAgICAgcmV0dXJuIGJhc2VTaXplICsgcGFkZGluZztcbiAgICB9XG4gICAgX3VwZGF0ZVByZWZpeFN0eWxlKCkge1xuICAgICAgICBpZiAodGhpcy5fcHJlZml4ICYmIHRoaXMuaWNvbikge1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlUHJlZml4T2JqKHRoaXMuaWNvbiwge1xuICAgICAgICAgICAgICAgIHN0eWxlOiB0aGlzLnN0eWxlLmljb25TdHlsZVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVByZWZpeE9iaihpY29uKSB7XG4gICAgICAgIHZhciBwcm9wcyA9IGFyZ3VtZW50cy5sZW5ndGggPiAxICYmIGFyZ3VtZW50c1sxXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzFdIDoge307XG4gICAgICAgIHRoaXMuX3ByZWZpeCA9IF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgdHlwZTogSWNvbixcbiAgICAgICAgICAgIGljb246IGljb24sXG4gICAgICAgICAgICB3OiB0aGlzLnN0eWxlLmljb25XaWR0aCxcbiAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuaWNvbkhlaWdodFxuICAgICAgICB9LCBwcm9wcyk7XG4gICAgfVxuICAgIF9zZXRJY29uKGljb24pIHtcbiAgICAgICAgaWYgKGljb24pIHtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZVByZWZpeE9iaihpY29uLCB7XG4gICAgICAgICAgICAgICAgc3R5bGU6IHRoaXMuc3R5bGUuaWNvblN0eWxlXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX3ByZWZpeCA9IGljb247XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGljb247XG4gICAgfVxuICAgIHNldCBhbm5vdW5jZShhbm5vdW5jZSkge1xuICAgICAgICBzdXBlci5hbm5vdW5jZSA9IGFubm91bmNlO1xuICAgIH1cbiAgICBnZXQgYW5ub3VuY2UoKSB7XG4gICAgICAgIGlmICh0aGlzLl9hbm5vdW5jZSkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2Fubm91bmNlO1xuICAgICAgICB9XG4gICAgICAgIGlmIChpc1VwcGVyQ2FzZSh0aGlzLnRpdGxlKSkge1xuICAgICAgICAgICAgcmV0dXJuIFwiQ2FwaXRhbCBcIi5jb25jYXQoZ2V0TmF0byh0aGlzLnRpdGxlKSwgXCIsIGJ1dHRvblwiKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gZ2V0TmF0byh0aGlzLnRpdGxlKSArIFwiLCBidXR0b25cIjtcbiAgICB9XG4gICAgX2hhbmRsZUVudGVyKCkge1xuICAgICAgICBpZiAodHlwZW9mIHRoaXMub25FbnRlciA9PT0gXCJmdW5jdGlvblwiKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5vbkVudGVyKHRoaXMpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKHRoaXMudG9nZ2xlKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKFwiJHRvZ2dsZUtleWJvYXJkXCIsIHRoaXMudG9nZ2xlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuZmlyZUFuY2VzdG9ycyhcIiRvblNvZnRLZXlcIiwge1xuICAgICAgICAgICAgICAgIGtleTogdGhpcy5rZXlJZCB8fCB0aGlzLnRpdGxlLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogdGhpcy50b2dnbGVcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9XG59XG5cbnZhciBiYXNlJGYgPSB0aGV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ZXldOiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IENvbHVtbixcbiAgICAgICAgICAgICAgICAgICAgcGxpbmtvOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICBpdGVtczogcm93cyxcbiAgICAgICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGl0ZW1TcGFjaW5nOiB0aGlzLnN0eWxlLmtleVNwYWNpbmdcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgYXV0b1Jlc2l6ZVdpZHRoOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICBhdXRvUmVzaXplSGVpZ2h0OiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICBuZXZlclNjcm9sbDogdHJ1ZVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9jcmVhdGVSb3dzKCkge1xuICAgICAgICB2YXIgcm93cyA9IGFyZ3VtZW50cy5sZW5ndGggPiAwICYmIGFyZ3VtZW50c1swXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzBdIDogW107XG4gICAgICAgIHZhciBrZXlib2FyZCA9IGFyZ3VtZW50cy5sZW5ndGggPiAxID8gYXJndW1lbnRzWzFdIDogdW5kZWZpbmVkO1xuICAgICAgICByZXR1cm4gcm93cy5tYXAoKGtleXMgPT4ge1xuICAgICAgICAgICAgdmFyIF90aGlzJF9jdXJyZW50S2V5Ym9hcjtcbiAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgdHlwZTogUm93LFxuICAgICAgICAgICAgICAgIGF1dG9SZXNpemVIZWlnaHQ6IHRydWUsXG4gICAgICAgICAgICAgICAgYXV0b1Jlc2l6ZVdpZHRoOiB0cnVlLFxuICAgICAgICAgICAgICAgIGNlbnRlckluUGFyZW50OiB0aGlzLmNlbnRlcktleXMsXG4gICAgICAgICAgICAgICAgbmV2ZXJTY3JvbGw6IHRydWUsXG4gICAgICAgICAgICAgICAgd3JhcFNlbGVjdGVkOiB0aGlzLnJvd1dyYXAgIT09IHVuZGVmaW5lZCA/IHRoaXMucm93V3JhcCA6IHRydWUsXG4gICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgaXRlbVNwYWNpbmc6IHRoaXMuc3R5bGUua2V5U3BhY2luZ1xuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgaXRlbXM6IHRoaXMuX2NyZWF0ZUtleXMoa2V5cywga2V5Ym9hcmQpLFxuICAgICAgICAgICAgICAgIHNlbGVjdGVkSW5kZXg6ICgoX3RoaXMkX2N1cnJlbnRLZXlib2FyID0gdGhpcy5fY3VycmVudEtleWJvYXJkKSA9PT0gbnVsbCB8fCBfdGhpcyRfY3VycmVudEtleWJvYXIgPT09IHZvaWQgMCB8fCAoX3RoaXMkX2N1cnJlbnRLZXlib2FyID0gX3RoaXMkX2N1cnJlbnRLZXlib2FyLnNlbGVjdGVkKSA9PT0gbnVsbCB8fCBfdGhpcyRfY3VycmVudEtleWJvYXIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJF9jdXJyZW50S2V5Ym9hci5zZWxlY3RlZEluZGV4KSB8fCAwXG4gICAgICAgICAgICB9O1xuICAgICAgICB9KSk7XG4gICAgfVxuICAgIF9jcmVhdGVLZXlzKCkge1xuICAgICAgICB2YXIga2V5cyA9IGFyZ3VtZW50cy5sZW5ndGggPiAwICYmIGFyZ3VtZW50c1swXSAhPT0gdW5kZWZpbmVkID8gYXJndW1lbnRzWzBdIDogW107XG4gICAgICAgIHZhciBrZXlib2FyZCA9IGFyZ3VtZW50cy5sZW5ndGggPiAxID8gYXJndW1lbnRzWzFdIDogdW5kZWZpbmVkO1xuICAgICAgICByZXR1cm4ga2V5cy5tYXAoKGtleVByb3BzID0+IHtcbiAgICAgICAgICAgIGlmICgha2V5UHJvcHMpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiB0aGlzLmtleUNvbXBvbmVudCB8fCBLZXksXG4gICAgICAgICAgICAgICAgICAgIGtleVNwYWNpbmc6IHRoaXMuc3R5bGUua2V5U3BhY2luZyxcbiAgICAgICAgICAgICAgICAgICAgc2tpcEZvY3VzOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICBhbHBoYTogLjAxXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBrZXkgPSB7XG4gICAgICAgICAgICAgICAgdHlwZTogdGhpcy5rZXlDb21wb25lbnQgfHwgS2V5LFxuICAgICAgICAgICAgICAgIGtleVNwYWNpbmc6IHRoaXMuc3R5bGUua2V5U3BhY2luZ1xuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmICh0eXBlb2Yga2V5UHJvcHMgPT09IFwib2JqZWN0XCIpIHtcbiAgICAgICAgICAgICAgICB2YXIgX3RoaXMkc3R5bGUka2V5UHJvcHMsIF90aGlzJHN0eWxlJGtleVByb3BzMjtcbiAgICAgICAgICAgICAgICB2YXIga2V5TmFtZSA9IGtleVByb3BzLmtleUlkIHx8IGtleVByb3BzLnRpdGxlO1xuICAgICAgICAgICAgICAgIHZhciBrZXlPdmVycmlkZXMgPSAoKF90aGlzJHN0eWxlJGtleVByb3BzID0gdGhpcy5zdHlsZS5rZXlQcm9wcykgPT09IG51bGwgfHwgX3RoaXMkc3R5bGUka2V5UHJvcHMgPT09IHZvaWQgMCB8fCAoX3RoaXMkc3R5bGUka2V5UHJvcHMgPSBfdGhpcyRzdHlsZSRrZXlQcm9wc1trZXlib2FyZF0pID09PSBudWxsIHx8IF90aGlzJHN0eWxlJGtleVByb3BzID09PSB2b2lkIDAgPyB2b2lkIDAgOiBfdGhpcyRzdHlsZSRrZXlQcm9wc1trZXlOYW1lXSkgfHwgKChfdGhpcyRzdHlsZSRrZXlQcm9wczIgPSB0aGlzLnN0eWxlLmtleVByb3BzKSA9PT0gbnVsbCB8fCBfdGhpcyRzdHlsZSRrZXlQcm9wczIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF90aGlzJHN0eWxlJGtleVByb3BzMltrZXlOYW1lXSkgfHwge307XG4gICAgICAgICAgICAgICAgdmFyIGtleVBhdGNoID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIGtleSksIGtleVByb3BzKSwga2V5T3ZlcnJpZGVzKTtcbiAgICAgICAgICAgICAgICBpZiAoa2V5T3ZlcnJpZGVzICE9PSBudWxsICYmIGtleU92ZXJyaWRlcyAhPT0gdm9pZCAwICYmIGtleU92ZXJyaWRlcy5pY29uKSB7XG4gICAgICAgICAgICAgICAgICAgIGtleVBhdGNoLnN0eWxlID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBrZXlPdmVycmlkZXMuc3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWNvblN0eWxlOiBfb2JqZWN0U3ByZWFkKHt9LCBrZXlPdmVycmlkZXMuaWNvblN0eWxlKVxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIGtleVBhdGNoO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwga2V5KSwge30sIHtcbiAgICAgICAgICAgICAgICB0aXRsZToga2V5UHJvcHNcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KSk7XG4gICAgfVxuICAgIF9mb3JtYXRLZXlib2FyZERhdGEoKSB7XG4gICAgICAgIHZhciBkYXRhID0gYXJndW1lbnRzLmxlbmd0aCA+IDAgJiYgYXJndW1lbnRzWzBdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMF0gOiBbXTtcbiAgICAgICAgaWYgKEFycmF5LmlzQXJyYXkoZGF0YSkgJiYgZGF0YS5sZW5ndGgpIHtcbiAgICAgICAgICAgIGlmICghQXJyYXkuaXNBcnJheShkYXRhWzBdKSAmJiAhdGhpcy5pbmxpbmUpIHtcbiAgICAgICAgICAgICAgICB2YXIga2V5Um93cyA9IFtdO1xuICAgICAgICAgICAgICAgIHZhciBpZHgsIGNvdW50ZXI7XG4gICAgICAgICAgICAgICAgZm9yIChpZHggPSAwLCBjb3VudGVyID0gLTE7IGlkeCA8IGRhdGEubGVuZ3RoOyBpZHgrKykge1xuICAgICAgICAgICAgICAgICAgICBpZiAoaWR4ICUgdGhpcy5jb2x1bW5Db3VudCA9PT0gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgY291bnRlcisrO1xuICAgICAgICAgICAgICAgICAgICAgICAga2V5Um93c1tjb3VudGVyXSA9IFtdO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGtleVJvd3NbY291bnRlcl0ucHVzaChkYXRhW2lkeF0pO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4ga2V5Um93cztcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5pbmxpbmUpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gWyBkYXRhIF07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gZGF0YTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfZm9ybWF0S2V5cygpIHtcbiAgICAgICAgT2JqZWN0LmtleXModGhpcy5mb3JtYXRzKS5mb3JFYWNoKChmb3JtYXQgPT4ge1xuICAgICAgICAgICAgdmFyIGVsZW1lbnQgPSB0aGlzLnRhZyhjYXBpdGFsaXplKGZvcm1hdCkpO1xuICAgICAgICAgICAgaWYgKGVsZW1lbnQpIHtcbiAgICAgICAgICAgICAgICBlbGVtZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGl0ZW1TcGFjaW5nOiB0aGlzLnN0eWxlLmtleVNwYWNpbmdcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIGVsZW1lbnQuaXRlbXMuZm9yRWFjaCgocm93ID0+IHtcbiAgICAgICAgICAgICAgICAgICAgcm93LnBhdGNoKHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaXRlbVNwYWNpbmc6IHRoaXMuc3R5bGUua2V5U3BhY2luZ1xuICAgICAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGNlbnRlckluUGFyZW50OiB0aGlzLmNlbnRlcktleXMsXG4gICAgICAgICAgICAgICAgICAgICAgICB3cmFwU2VsZWN0ZWQ6IHRoaXMucm93V3JhcCAhPT0gdW5kZWZpbmVkID8gdGhpcy5yb3dXcmFwIDogdHJ1ZVxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICAgICAgZWxlbWVudC5xdWV1ZVJlcXVlc3RVcGRhdGUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSkpO1xuICAgIH1cbiAgICAkdG9nZ2xlS2V5Ym9hcmQobmV4dCkge1xuICAgICAgICB2YXIgbmV4dEtleWJvYXJkID0gY2FwaXRhbGl6ZShuZXh0KTtcbiAgICAgICAgaWYgKG5leHQgIT09IHRoaXMuX2N1cnJlbnRGb3JtYXQpIHtcbiAgICAgICAgICAgIHRoaXMuX2NyZWF0ZUZvcm1hdChuZXh0KTtcbiAgICAgICAgICAgIHZhciBuZXh0S2V5Ym9hcmRUYWcgPSB0aGlzLnRhZyhuZXh0S2V5Ym9hcmQpO1xuICAgICAgICAgICAgdGhpcy5zZWxlY3RLZXlPbihuZXh0S2V5Ym9hcmRUYWcpO1xuICAgICAgICAgICAgdGhpcy5fY3VycmVudEtleWJv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ICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIkFcIiwgXCJTXCIsIFwiRFwiLCBcIkZcIiwgXCJHXCIsIFwiSFwiLCBcIkpcIiwgXCJLXCIsIFwiTFwiLCBcIkBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIsOhw7bDu1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwiYWNjZW50c1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImFjY2VudHMsIGJ1dHRvblwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImFjY2VudHNcIlxuICAgICAgICAgICAgfSBdLCBbIFwiWlwiLCBcIlhcIiwgXCJDXCIsIFwiVlwiLCBcIkJcIiwgXCJOXCIsIFwiTVwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLlwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInBlcmlvZCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCItXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGFzaCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJfXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwidW5kZXJzY29yZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJzaGlmdFwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic2hpZnQgb2ZmLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzaGlmdFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5jb21cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGNvbVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5uZXRcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIG5ldFwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5lZHVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGVkdVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5vcmdcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIG9yZ1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5jb1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgY29cIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIudWtcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIHVrXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkNsZWFyXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImNsZWFyXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xlYXIsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiU3BhY2VcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3BhY2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzcGFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEb25lXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRvbmVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb25lLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdIF0sXG4gICAgICAgICAgICBsb3dlcmNhc2U6IFsgWyBcIjFcIiwgXCIyXCIsIFwiM1wiLCBcIjRcIiwgXCI1XCIsIFwiNlwiLCBcIjdcIiwgXCI4XCIsIFwiOVwiLCBcIjBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0sIFsgXCJxXCIsIFwid1wiLCBcImVcIiwgXCJyXCIsIFwidFwiLCBcInlcIiwgXCJ1XCIsIFwiaVwiLCBcIm9cIiwgXCJwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIjQCFcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcInN5bWJvbHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzeW1ib2wgbW9kZSwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3ltYm9sc1wiXG4gICAgICAgICAgICB9IF0sIFsgXCJhXCIsIFwic1wiLCBcImRcIiwgXCJmXCIsIFwiZ1wiLCBcImhcIiwgXCJqXCIsIFwia1wiLCBcImxcIiwgXCJAXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCLDocO2w7tcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhY2NlbnRzLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJhY2NlbnRzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcInpcIiwgXCJ4XCIsIFwiY1wiLCBcInZcIiwgXCJiXCIsIFwiblwiLCBcIm1cIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcInVwcGVyY2FzZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNoaWZ0IG9uLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzaGlmdFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5jb21cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGNvbVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5uZXRcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIG5ldFwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5lZHVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGVkdVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5vcmdcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIG9yZ1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5jb1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgY29cIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIudWtcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIHVrXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkNsZWFyXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImNsZWFyXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xlYXIsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiU3BhY2VcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3BhY2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzcGFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEb25lXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRvbmVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb25lLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdIF0sXG4gICAgICAgICAgICBhY2NlbnRzOiBbIFsgXCIxXCIsIFwiMlwiLCBcIjNcIiwgXCI0XCIsIFwiNVwiLCBcIjZcIiwgXCI3XCIsIFwiOFwiLCBcIjlcIiwgXCIwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEZWxldGVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGVsZXRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIFwiw6RcIiwgXCLDq1wiLCBcIsOvXCIsIFwiw7ZcIiwgXCLDvFwiLCBcIsO/XCIsIFwiw6BcIiwgXCLDqFwiLCBcIsOsXCIsIFwiw7JcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsO5XCIsIFwiw6FcIiwgXCLDqVwiLCBcIsOtXCIsIFwiw7NcIiwgXCLDulwiLCBcIsO9XCIsIFwiw6JcIiwgXCLDqlwiLCBcIkBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImFiY1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYWxwaGEgbW9kZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOuXCIsIFwiw7RcIiwgXCLDu1wiLCBcIsOjXCIsIFwiw7FcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNVcHBlclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNoaWZ0IG9mZiwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic2hpZnRcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuY29tXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBjb21cIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIubmV0XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBuZXRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuZWR1XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBlZHVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIub3JnXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBvcmdcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuY29cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGNvXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLnVrXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCB1a1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJDbGVhclwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJjbGVhclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsZWFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlNwYWNlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNwYWNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic3BhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRG9uZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkb25lXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG9uZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSBdLFxuICAgICAgICAgICAgYWNjZW50c1VwcGVyOiBbIFsgXCIxXCIsIFwiMlwiLCBcIjNcIiwgXCI0XCIsIFwiNVwiLCBcIjZcIiwgXCI3XCIsIFwiOFwiLCBcIjlcIiwgXCIwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEZWxldGVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGVsZXRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIFwiw4RcIiwgXCLDi1wiLCBcIsOPXCIsIFwiw5ZcIiwgXCLDnFwiLCBcIsW4XCIsIFwiw4BcIiwgXCLDiFwiLCBcIsOMXCIsIFwiw5JcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOZXCIsIFwiw4FcIiwgXCLDiVwiLCBcIsONXCIsIFwiw5NcIiwgXCLDmlwiLCBcIsOdXCIsIFwiw4JcIiwgXCLDilwiLCBcIkBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImFiY1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYWxwaGEgbW9kZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOOXCIsIFwiw5RcIiwgXCLDm1wiLCBcIsODXCIsIFwiw5FcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiX1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInVuZGVyc2NvcmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzaGlmdCBvZmYsIGJ1dHRvblwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNoaWZ0XCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLmNvbVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgY29tXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLm5ldFwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgbmV0XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLmVkdVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgZWR1XCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLm9yZ1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgb3JnXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLmNvXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBjb1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi51a1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdCwgdWtcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiQ2xlYXJcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiY2xlYXJcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjbGVhciwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJTcGFjZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwieGxcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzcGFjZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNwYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRvbmVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZG9uZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvbmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0gXSxcbiAgICAgICAgICAgIHN5bWJvbHM6IFsgWyBcIjFcIiwgXCIyXCIsIFwiM1wiLCBcIjRcIiwgXCI1XCIsIFwiNlwiLCBcIjdcIiwgXCI4XCIsIFwiOVwiLCBcIjBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiFcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJleGNsYW1hdGlvbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIFwiQFwiLCBcIiNcIiwgXCIkXCIsIFwiJVwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiXlwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNhcmV0IGNpcmN1bWZsZXgsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCBcIiZcIiwgXCIqXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIoXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwib3BlbiBwYXJlbnRoZXNpcywgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIpXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xvc2UgcGFyZW50aGVzaXMsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiYWJjXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJsb3dlcmNhc2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhbHBoYSBtb2RlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJ7XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwib3BlbiBicmFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJ9XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xvc2UgYnJhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiW1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcIm9wZW4gYnJhY2tldCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJdXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xvc2UgYnJhY2tldCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCI7XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic2VtaWNvbG9uLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiAnXCInLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdWJsZXF1b3RlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIixcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjb21tYSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJ8XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwidmVydGljYWwgYmFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlxcXFxcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJiYWNrc2xhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiL1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImZvcndhcmRzbGFzaCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCLDocO2w7tcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhY2NlbnRzLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJhY2NlbnRzXCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiPFwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImxlc3MgdGhhbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCI+XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZ3JlYXRlciB0aGFuLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIj9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJxdWVzdGlvbiBtYXJrLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIj1cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJlcXVhbCBzaWduLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImBcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJncmF2ZSBhY2NlbnQsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiflwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInRpbGRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjpcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjb2xvbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCItXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGFzaCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIrXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwicGx1cyBzaWduLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuY29tXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBjb21cIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIubmV0XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBuZXRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuZWR1XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBlZHVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIub3JnXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCBvcmdcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIuY29cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb3QsIGNvXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLnVrXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG90LCB1a1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJDbGVhclwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJjbGVhclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsZWFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlNwYWNlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNwYWNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic3BhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRG9uZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkb25lXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG9uZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSBdXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBLZXlib2FyZEZ1bGxTY3JlZW4gZXh0ZW5kcyBLZXlib2FyZCB7XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIHJldHVybiBcIktleWJvYXJkRnVsbFNjcmVlblwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRmO1xuICAgIH1cbiAgICBfY29uc3RydWN0KCkge1xuICAgICAgICBzdXBlci5fY29uc3RydWN0KCk7XG4gICAgICAgIHRoaXMuZm9ybWF0cyA9IHRoaXMuZnVsbHNjcmVlbkZvcm1hdDtcbiAgICB9XG4gICAgZ2V0IGZ1bGxzY3JlZW5Gb3JtYXQoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBsZXR0ZXJzOiBbIFsgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwgXCJcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJTcGFjZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzcGFjZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNwYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiIF0sIFsgXCJBXCIsIFwiQlwiLCBcIkNcIiwgXCJEXCIsIFwiRVwiLCBcIkZcIiwgXCJHXCIsIFwiSFwiLCBcIklcIiwgXCJKXCIsIFwiS1wiLCBcIkxcIiwgXCJNXCIsIFwiTlwiLCBcIk9cIiwgXCJQXCIsIFwiUVwiLCBcIlJcIiwgXCJTXCIsIFwiVFwiLCBcIlVcIiwgXCJWXCIsIFwiV1wiLCBcIlhcIiwgXCJZXCIsIFwiWlwiIF0gXSxcbiAgICAgICAgICAgIHN5bWJvbHM6IFsgWyBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiQUJDXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJsZXR0ZXJzXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2FwcyBvbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJTcGFjZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzcGFjZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNwYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiLCBcIlwiIF0sIFsgXCIxXCIsIFwiMlwiLCBcIjNcIiwgXCI0XCIsIFwiNVwiLCBcIjZcIiwgXCI3XCIsIFwiOFwiLCBcIjlcIiwgXCIwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIhXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZXhjbGFtYXRpb24sIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCBcIkBcIiwgXCIjXCIsIFwiJFwiLCBcIiVcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjYXJldCBjaXJjdW1mbGV4LCBidXR0b25cIlxuICAgICAgICAgICAgfSwgXCImXCIsIFwiKlwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiKFwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcIm9wZW4g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iLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRlbGV0ZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIlFcIiwgXCJXXCIsIFwiRVwiLCBcIlJcIiwgXCJUXCIsIFwiWVwiLCBcIlVcIiwgXCJJXCIsIFwiT1wiLCBcIlBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIkFcIiwgXCJTXCIsIFwiRFwiLCBcIkZcIiwgXCJHXCIsIFwiSFwiLCBcIkpcIiwgXCJLXCIsIFwiTFwiLCBcIkBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIsOhw7bDu1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwiYWNjZW50c1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImFjY2VudHMsIGJ1dHRvblwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImFjY2VudHNcIlxuICAgICAgICAgICAgfSBdLCBbIFwiWlwiLCBcIlhcIiwgXCJDXCIsIFwiVlwiLCBcIkJcIiwgXCJOXCIsIFwiTVwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiX1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInVuZGVyc2NvcmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLlwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInBlcmlvZCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCItXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGFzaCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJzaGlmdFwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic2hpZnQgb2ZmLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzaGlmdFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkNsZWFyXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImNsZWFyXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xlYXIsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiU3BhY2VcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3BhY2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzcGFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEb25lXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRvbmVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb25lLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdIF0sXG4gICAgICAgICAgICBsb3dlcmNhc2U6IFsgWyBcIjFcIiwgXCIyXCIsIFwiM1wiLCBcIjRcIiwgXCI1XCIsIFwiNlwiLCBcIjdcIiwgXCI4XCIsIFwiOVwiLCBcIjBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0sIFsgXCJxXCIsIFwid1wiLCBcImVcIiwgXCJyXCIsIFwidFwiLCBcInlcIiwgXCJ1XCIsIFwiaVwiLCBcIm9cIiwgXCJwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIjQCFcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcInN5bWJvbHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzeW1ib2wgbW9kZSwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3ltYm9sc1wiXG4gICAgICAgICAgICB9IF0sIFsgXCJhXCIsIFwic1wiLCBcImRcIiwgXCJmXCIsIFwiZ1wiLCBcImhcIiwgXCJqXCIsIFwia1wiLCBcImxcIiwgXCJAXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCLDocO2w7tcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhY2NlbnRzLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJhY2NlbnRzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcInpcIiwgXCJ4XCIsIFwiY1wiLCBcInZcIiwgXCJiXCIsIFwiblwiLCBcIm1cIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcInVwcGVyY2FzZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNoaWZ0IG9uLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzaGlmdFwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkNsZWFyXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImNsZWFyXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xlYXIsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiU3BhY2VcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic3BhY2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzcGFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEb25lXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJsZ1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcImRvbmVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkb25lLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdIF0sXG4gICAgICAgICAgICBhY2NlbnRzOiBbIFsgXCIxXCIsIFwiMlwiLCBcIjNcIiwgXCI0XCIsIFwiNVwiLCBcIjZcIiwgXCI3XCIsIFwiOFwiLCBcIjlcIiwgXCIwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEZWxldGVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGVsZXRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIFwiw6RcIiwgXCLDq1wiLCBcIsOvXCIsIFwiw7ZcIiwgXCLDvFwiLCBcIsO/XCIsIFwiw6BcIiwgXCLDqFwiLCBcIsOsXCIsIFwiw7JcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsO5XCIsIFwiw6FcIiwgXCLDqVwiLCBcIsOtXCIsIFwiw7NcIiwgXCLDulwiLCBcIsO9XCIsIFwiw6JcIiwgXCLDqlwiLCBcIkBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImFiY1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYWxwaGEgbW9kZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOuXCIsIFwiw7RcIiwgXCLDu1wiLCBcIsOjXCIsIFwiw7FcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNVcHBlclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNoaWZ0IG9mZiwgYnV0dG9uXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwic2hpZnRcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJDbGVhclwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJjbGVhclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsZWFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlNwYWNlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNwYWNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic3BhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRG9uZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkb25lXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG9uZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSBdLFxuICAgICAgICAgICAgYWNjZW50c1VwcGVyOiBbIFsgXCIxXCIsIFwiMlwiLCBcIjNcIiwgXCI0XCIsIFwiNVwiLCBcIjZcIiwgXCI3XCIsIFwiOFwiLCBcIjlcIiwgXCIwXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJEZWxldGVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZGVsZXRlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGVsZXRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIFwiw4RcIiwgXCLDi1wiLCBcIsOPXCIsIFwiw5ZcIiwgXCLDnFwiLCBcIsW4XCIsIFwiw4BcIiwgXCLDiFwiLCBcIsOMXCIsIFwiw5JcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiNAIVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwic3ltYm9sc1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInN5bWJvbCBtb2RlLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzeW1ib2xzXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOZXCIsIFwiw4FcIiwgXCLDiVwiLCBcIsONXCIsIFwiw5NcIiwgXCLDmlwiLCBcIsOdXCIsIFwiw4JcIiwgXCLDilwiLCBcIkBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImFiY1wiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICB0b2dnbGU6IFwibG93ZXJjYXNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiYWxwaGEgbW9kZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSwgWyBcIsOOXCIsIFwiw5RcIiwgXCLDm1wiLCBcIsODXCIsIFwiw5FcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIi5cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJwZXJpb2QsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiLVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiX1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInVuZGVyc2NvcmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwic2hpZnRcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcInhsXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJzaGlmdCBvZmYsIGJ1dHRvblwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNoaWZ0XCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiQ2xlYXJcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiY2xlYXJcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjbGVhciwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJTcGFjZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwieGxcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzcGFjZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNwYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRvbmVcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcImxnXCIsXG4gICAgICAgICAgICAgICAga2V5SWQ6IFwiZG9uZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvbmUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0gXSxcbiAgICAgICAgICAgIHN5bWJvbHM6IFsgWyBcIjFcIiwgXCIyXCIsIFwiM1wiLCBcIjRcIiwgXCI1XCIsIFwiNlwiLCBcIjdcIiwgXCI4XCIsIFwiOVwiLCBcIjBcIiwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIiFcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJleGNsYW1hdGlvbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIFwiQFwiLCBcIiNcIiwgXCIkXCIsIFwiJVwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiXlwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNhcmV0IGNpcmN1bWZsZXgsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCBcIiZcIiwgXCIqXCIsIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIoXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwib3BlbiBwYXJlbnRoZXNpcywgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIpXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xvc2UgcGFyZW50aGVzaXMsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiYWJjXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJtZFwiLFxuICAgICAgICAgICAgICAgIHRvZ2dsZTogXCJsb3dlcmNhc2VcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhbHBoYSBtb2RlLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJ7XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwib3BlbiBicmFjZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJ9XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xvc2UgYnJhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiW1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcIm9wZW4gYnJhY2tldCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJdXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiY2xvc2UgYnJhY2tldCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCI7XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic2VtaWNvbG9uLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiAnXCInLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImRvdWJsZXF1b3RlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIixcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjb21tYSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJ8XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwidmVydGljYWwgYmFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlxcXFxcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJiYWNrc2xhc2gsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiL1wiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImZvcndhcmRzbGFzaCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCLDocO2w7tcIixcbiAgICAgICAgICAgICAgICBzaXplOiBcIm1kXCIsXG4gICAgICAgICAgICAgICAgdG9nZ2xlOiBcImFjY2VudHNcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJhY2NlbnRzLCBidXR0b25cIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJhY2NlbnRzXCJcbiAgICAgICAgICAgIH0gXSwgWyB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiPFwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImxlc3MgdGhhbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCI+XCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZ3JlYXRlciB0aGFuLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIj9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJxdWVzdGlvbiBtYXJrLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIj1cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJlcXVhbCBzaWduLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcImBcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJncmF2ZSBhY2NlbnQsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiflwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInRpbGRlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIl9cIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJ1bmRlcnNjb3JlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjpcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJjb2xvbiwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCItXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZGFzaCwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0sIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCIrXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwicGx1cyBzaWduLCBidXR0b25cIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJDbGVhclwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJjbGVhclwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcImNsZWFyLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIlNwYWNlXCIsXG4gICAgICAgICAgICAgICAgc2l6ZTogXCJ4bFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcInNwYWNlXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwic3BhY2UsIGJ1dHRvblwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiRG9uZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibGdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkb25lXCIsXG4gICAgICAgICAgICAgICAgYW5ub3VuY2U6IFwiZG9uZSwgYnV0dG9uXCJcbiAgICAgICAgICAgIH0gXSBdXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBLZXlib2FyZElucHV0IGV4dGVuZHMgQmFzZSQxIHtcbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiS2V5Ym9hcmRJbnB1dFwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwiY2VudGVyS2V5Ym9hcmRcIiwgXCJkZWZhdWx0Rm9ybWF0XCIsIFwiaW5wdXRcIiwgXCJrZXlib2FyZFR5cGVcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRmO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgV3JhcHBlcjoge1xuICAgICAgICAgICAgICAgIHR5cGU6IENvbHVtbixcbiAgICAgICAgICAgICAgICBuZXZlclNjcm9sbDogdHJ1ZSxcbiAgICAgICAgICAgICAgICB3OiB0aGlzLncsXG4gICAgICAgICAgICAgICAgaXRlbXM6IFsge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJbnB1dCxcbiAgICAgICAgICAgICAgICAgICAgcmVmOiBcIklucHV0XCJcbiAgICAgICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEtleWJvYXJkLFxuICAgICAgICAgICAgICAgICAgICByZWY6IFwiS2V5Ym9hcmRcIixcbiAgICAgICAgICAgICAgICAgICAgcGFzc1NpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGtleWJvYXJkV2lkdGhDaGFuZ2VkOiB0cnVlXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IF0sXG4gICAgICAgICAgICAgICAgc2VsZWN0ZWRJbmRleDogMSxcbiAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIGtleWJvYXJkV2lkdGhDaGFuZ2VkOiBcIl91cGRhdGVXaWR0aFwiXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIFwiV3JhcHBlclwiLCB7XG4gICAgICAgICAgICBuYW1lOiBcIklucHV0XCIsXG4gICAgICAgICAgICBwYXRoOiBcIldyYXBwZXIuSW5wdXRcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIktleWJvYXJkXCIsXG4gICAgICAgICAgICBwYXRoOiBcIldyYXBwZXIuS2V5Ym9hcmRcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIF91cGRhdGUoKSB7XG4gICAgICAgIHRoaXMuX1dyYXBwZXIuc3R5bGUuaXRlbVNwYWNpbmcgPSB0aGlzLnN0eWxlLmlucHV0U3BhY2luZztcbiAgICAgICAgdGhpcy5fdXBkYXRlS2V5Ym9hcmRUeXBlKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUlucHV0KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUtleWJvYXJkKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUNlbnRlcktleWJvYXJkKCk7XG4gICAgfVxuICAgIF91cGRhdGVLZXlib2FyZFR5cGUoKSB7XG4gICAgICAgIGlmICh0aGlzLl9LZXlib2FyZC5jb25zdHJ1Y3RvciAhPT0gdGhpcy5rZXlib2FyZFR5cGUpIHtcbiAgICAgICAgICAgIHRoaXMuX1dyYXBwZXIuX3Jlc2V0SXRlbXMoKTtcbiAgICAgICAgICAgIHRoaXMuX1dyYXBwZXIuaXRlbXMgPSBbIHtcbiAgICAgICAgICAgICAgICB0eXBlOiBJbnB1dCxcbiAgICAgICAgICAgICAgICByZWY6IFwiSW5wdXRcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHR5cGU6IHRoaXMua2V5Ym9hcmRUeXBlLFxuICAgICAgICAgICAgICAgIHJlZjogXCJLZXlib2FyZFwiLFxuICAgICAgICAgICAgICAgIHBhc3NTaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIGtleWJvYXJkV2lkdGhDaGFuZ2VkOiB0cnVlXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSBdO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVJbnB1dCgpIHtcbiAgICAgICAgdGhpcy5fSW5wdXQucGF0Y2goX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLmlucHV0KSwge30sIHtcbiAgICAgICAgICAgIGNlbnRlckluUGFyZW50OiB0aGlzLmNlbnRlcktleWJvYXJkLFxuICAgICAgICAgICAgdzogdGhpcy5fS2V5Ym9hcmQudyxcbiAgICAgICAgICAgIHN0eWxlOiBfb2JqZWN0U3ByZWFkKHt9LCB0aGlzLnN0eWxlLmlucHV0U3R5bGUpLFxuICAgIC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XG4gICAgfVxuICAgIGdldCBzZWFyY2hGb3JtYXQoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICB1cHBlcmNhc2U6IFsgWyBcIkFcIiwgXCJCXCIsIFwiQ1wiLCBcIkRcIiwgXCJFXCIsIFwiRlwiIF0sIFsgXCJHXCIsIFwiSFwiLCBcIklcIiwgXCJKXCIsIFwiS1wiLCBcIkxcIiBdLCBbIFwiTVwiLCBcIk5cIiwgXCJPXCIsIFwiUFwiLCBcIlFcIiwgXCJSXCIgXSwgWyBcIlNcIiwgXCJUXCIsIFwiVVwiLCBcIlZcIiwgXCJXXCIsIFwiWFwiIF0sIFsgXCJZXCIsIFwiWlwiLCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiMVwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcIm51bWJlclwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiMlwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcIm51bWJlclwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiM1wiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcIm51bWJlclwiXG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgICAgdGl0bGU6IFwiNFwiLFxuICAgICAgICAgICAgICAgIGtleUlkOiBcIm51bWJlclwiXG4gICAgICAgICAgICB9IF0sIFsge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjVcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjZcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjdcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjhcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjlcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIjBcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJudW1iZXJcIlxuICAgICAgICAgICAgfSBdLCBbIHtcbiAgICAgICAgICAgICAgICB0aXRsZTogXCJTcGFjZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwieGxcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJzcGFjZVwiLFxuICAgICAgICAgICAgICAgIGFubm91bmNlOiBcInNwYWNlLCBidXR0b25cIlxuICAgICAgICAgICAgfSwge1xuICAgICAgICAgICAgICAgIHRpdGxlOiBcIkRlbGV0ZVwiLFxuICAgICAgICAgICAgICAgIHNpemU6IFwibWRcIixcbiAgICAgICAgICAgICAgICBrZXlJZDogXCJkZWxldGVcIixcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCJkZWxldGUsIGJ1dHRvblwiXG4gICAgICAgICAgICB9IF0gXVxuICAgICAgICB9O1xuICAgIH1cbn1cblxudmFyIGJhc2UkZSA9IHRoZW1lID0+IHtcbiAgICB2YXIgc2l6ZSA9IHRoZW1lLnNwYWNlci5sZztcbiAgICByZXR1cm4ge1xuICAgICAgICB3aWR0aDogc2l6ZSxcbiAgICAgICAgaGVpZ2h0OiBzaXplLFxuICAgICAgICByYWRpdXM6IHNpemUgLyAyXG4gICAgfTtcbn07XG5cbnZhciB0b25lJDkgPSB0aGVtZSA9PiAoe1xuICAgIG5ldXRyYWw6IHtcbiAgICAgICAgY2lyY2xlQ29sb3I6IHRoZW1lLmNvbG9yLmludGVyYWN0aXZlTmV1dHJhbEZvY3VzLFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIGNpcmNsZUNvbG9yOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbERpc2FibGVkXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgY2lyY2xlQ29sb3I6IHRoZW1lLmNvbG9yLmludGVyYWN0aXZlSW52ZXJzZUZvY3VzLFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIGNpcmNsZUNvbG9yOiB0aGVtZS5jb2xvci5maWxsSW52ZXJzZURpc2FibGVkXG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGJyYW5kOiB7XG4gICAgICAgIGNpcmNsZUNvbG9yOiB0aGVtZS5jb2xvci5pbnRlcmFjdGl2ZUJyYW5kRm9jdXMsXG4gICAgICAgIG1vZGU6IHtcbiAgICAgICAgICAgIGRpc2FibGVkOiB7XG4gICAgICAgICAgICAgICAgY2lyY2xlQ29sb3I6IHRoZW1lLmNvbG9yLmZpbGxJbnZlcnNlRGlzYWJsZWRcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbn0pO1xuXG52YXIgc3R5bGVzJGUgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSRlLFxuICAgIHRvbmU6IHRvbmUkOVxufSk7XG5cbmNsYXNzIEtub2IgZXh0ZW5kcyBCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJLbm9iXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJGU7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4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ZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICB0aXRsZVRleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMkZCA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJGQsXG4gICAgbW9kZTogbW9kZSQ1LFxuICAgIHRvbmU6IHRvbmUkOFxufSk7XG5cbmNsYXNzIExpc3RJdGVtIGV4dGVuZHMgQnV0dG9uIHtcbiAgICBzdGF0aWMgZ2V0IF9fY29tcG9uZW50TmFtZSgpIHtcbiAgICAgICAgcmV0dXJuIFwiTGlzdEl0ZW1cIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkZDtcbiAgICB9XG4gICAgc3RhdGljIF90ZW1wbGF0ZSgpIHtcbiAgICAgICAgcmV0dXJuIF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgc3VwZXIuX3RlbXBsYXRlKCkpLCB7fSwge1xuICAgICAgICAgICAganVzdGlmeTogXCJsZWZ0XCIsXG4gICAgICAgICAgICBmaXhlZDogdHJ1ZSxcbiAgICAgICAgICAgIENvbnRlbnQ6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgc3VwZXIuX3RlbXBsYXRlKCkuQ29udGVudCksIHt9LCB7XG4gICAgICAgICAgICAgICAgVGV4dFdyYXBwZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgZmxleDoge1xuICAgICAgICAgICAgICAgICAgICAgICAgZGlyZWN0aW9uOiBcImNvbHVtblwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIFRpdGxlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRleHRCb3hDaGFuZ2VkOiBcIl9vblRleHRCb3hDaGFuZ2VkXCJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pXG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIC4uLnN1cGVyLnByb3BlcnRpZXMsIFwiZGVzY3JpcHRpb25cIiwgXCJwcmVmaXhMb2dvXCIsIFwic3VmZml4TG9nb1wiLCBcInNob3VsZENvbGxhcHNlXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBhbGlhc1N0eWxlcygpIHtcbiAgICAgICAgcmV0dXJuIFsge1xuICAgICAgICAgICAgcHJldjogXCJ0aXRsZVBhZGRpbmdcIixcbiAgICAgICAgICAgIGN1cnI6IFwiY29udGVudFNwYWNpbmdcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIudGFncywge1xuICAgICAgICAgICAgbmFtZTogXCJEZXNjcmlwdGlvblwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50LlRleHRXcmFwcGVyLkRlc2NyaXB0aW9uXCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBfb25UZXh0Qm94Q2hhbmdlZCgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGl0bGUoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlRGVzY3JpcHRpb24oKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlVHJ1bmNhdGlvbigpO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVQcmVmaXhMb2dvKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVN1ZmZpeExvZ28oKTtcbiAgICAgICAgc3VwZXIuX3VwZGF0ZSgpO1xuICAgICAgICB0aGlzLl91cGRhdGVEZXNjcmlwdGlvbigpO1xuICAgIH1cbiAgICBfdXBkYXRlVGl0bGUoKSB7XG4gICAgICAgIHRoaXMuX1RleHRXcmFwcGVyLnBhdGNoKHtcbiAgICAgICAgICAgIFRpdGxlOiB7XG4gICAgICAgICAgICAgICAgY29udGVudDogdGhpcy50aXRsZSxcbiAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IHRoaXMuc3R5bGUudGl0bGVUZXh0U3R5bGVcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfdXBkYXRlRGVzY3JpcHRpb24oKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNEZXNjcmlwdGlvbikge1xuICAgICAgICAgICAgdmFyIGRlc2NyaXB0aW9uUGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgY29udGVudDogdGhpcy5kZXNjcmlwdGlvbixcbiAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS5kZXNjcmlwdGlvblRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdHJ1ZSxcbiAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuX2ZpeGVkV29yZFdyYXBXaWR0aFxuICAgICAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgdmlzaWJsZTogIXRoaXMuX2NvbGxhcHNlXG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9EZXNjcmlwdGlvbikge1xuICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uUGF0Y2ggPSBfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX29uVGV4dEJveENoYW5nZWRcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSwgZGVzY3JpcHRpb25QYXRjaCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9UZXh0V3JhcHBlci5wYXRjaCh7XG4gICAgICAgICAgICAgICAgRGVzY3JpcHRpb246IGRlc2NyaXB0aW9uUGF0Y2hcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIucGF0Y2goe1xuICAgICAgICAgICAgICAgIERlc2NyaXB0aW9uOiB1bmRlZmluZWRcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF91cGRhdGVUcnVuY2F0aW9uKCkge1xuICAgICAgICBpZiAodGhpcy5fVGl0bGUpIHtcbiAgICAgICAgICAgIHRoaXMuX1RpdGxlLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS50aXRsZVRleHRTdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcDogdGhpcy5maXhlZCxcbiAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuZml4ZWQgPyB0aGlzLl9maXhlZFdvcmRXcmFwV2lkdGggOiAwXG4gICAgICAgICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVByZWZpeExvZ28oKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNQcmVmaXhMb2dvKSB7XG4gICAgICAgICAgICB0aGlzLl9wcmVmaXggPSB0aGlzLl9hZGRMb2dvUHJvcHModGhpcy5fcHJlZml4TG9nbyk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVN1ZmZpeExvZ28oKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNTdWZmaXhMb2dvKSB7XG4gICAgICAgICAgICB0aGlzLl9zdWZmaXggPSB0aGlzLl9hZGRMb2dvUHJvcHModGhpcy5fc3VmZml4TG9nbyk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX2FkZExvZ29Qcm9wcyhpY29uKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgaWNvbjogaWNvbixcbiAgICAgICAgICAgIHN0eWxlOiBfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICBjb2xvcjogdW5kZWZpbmVkXG4gICAgICAgICAgICB9LCB0aGlzLnN0eWxlLmxvZ29TdHlsZSlcbiAgICAgICAgfTtcbiAgICB9XG4gICAgZ2V0IF9oYXNQcmVmaXhMb2dvKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5wcmVmaXhMb2dvO1xuICAgIH1cbiAgICBnZXQgX2hhc1N1ZmZpeExvZ28oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnN1ZmZpeExvZ287XG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cblxudmFyIGJhc2UkYyA9ICgpID0+ICh7XG4gICAgc2hvd0Fycm93czogZmFsc2UsXG4gICAgc2hvd0tub2I6IGZhbHNlXG59KTtcblxudmFyIG1vZGUkNCA9ICgpID0+ICh7XG4gICAgZm9jdXNlZDoge1xuICAgICAgICBzaG93QXJyb3dzOiB0cnVlXG4gICAgfVxufSk7XG5cbnZhciB0b25lJDcgPSB0aGVtZSA9PiAoe1xuICAgIG5ldXRyYWw6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIGFycm93Q29sb3I6IHRoZW1lLmNvbG9yLmZpbGxJbnZlcnNlLFxuICAgICAgICAgICAgICAgIHByb2dyZXNzQmFyOiB7XG4gICAgICAgICAgICAgICAgICAgIGJhckNvbG9yOiB0aGVtZS5jb2xvci5maWxsSW52ZXJzZVRlcnRpYXJ5LFxuICAgICAgICAgICAgICAgICAgICBwcm9ncmVzc0NvbG9yOiB0aGVtZS5jb2xvci5maWxsSW52ZXJzZVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH0sXG4gICAgaW52ZXJzZToge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBmb2N1c2VkOiB7XG4gICAgICAgICAgICAgICAgYXJyb3dDb2xvcjogdGhlbWUuY29sb3IuZmlsbE5ldXRyYWwsXG4gICAgICAgICAgICAgICAgcHJvZ3Jlc3NCYXI6IHtcbiAgICAgICAgICAgICAgICAgICAgYmFyQ29sb3I6IHRoZW1lLmNvbG9yLmZpbGxOZXV0cmFsVGVydGlhcnksXG4gICAgICAgICAgICAgICAgICAgIHByb2dyZXNzQ29sb3I6IHRoZW1lLmNvbG9yLmZpbGxOZXV0cmFsXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfSxcbiAgICBicmFuZDoge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICB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fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJGIsXG4gICAgbW9kZTogbW9kZSQzLFxuICAgIHRvbmU6IHRvbmUkNlxufSk7XG5cbmNsYXNzIFNsaWRlciBleHRlbmRzIEJhc2UkMSB7XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIHJldHVybiBcIlNsaWRlclwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRiO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgQ29udGFpbmVyOiB7XG4gICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyLFxuICAgICAgICAgICAgICAgIEJhcjoge1xuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgICAgICAgICBTbGlkZXJCYXI6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFByb2dyZXNzQmFyLFxuICAgICAgICAgICAgICAgICAgICAgICAgcHJvZ3Jlc3M6IC41LFxuICAgICAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGFubm91bmNlOiBcIlwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIENpcmNsZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogS25vYixcbiAgICAgICAgICAgICAgICAgICAgICAgIHpJbmRleDogNVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBMZWZ0QXJyb3c6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogSWNvbixcbiAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgeTogaCA9PiBoIC8gMlxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgUmlnaHRBcnJvdzoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwibWF4XCIsIFwibWluXCIsIFwic3RlcFwiLCBcInZhbHVlXCIsIFwidmVydGljYWxcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHRhZ3MoKSB7XG4gICAgICAgIHJldHVybiBbIFwiQ29udGFpbmVyXCIsIHtcbiAgICAgICAgICAgIG5hbWU6IFwiQmFyXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRhaW5lci5CYXJcIlxuICAgICAgICB9LCB7XG4gICAgICAgICAgICBuYW1lOiBcIlNsaWRlckJhclwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250YWluZXIuQmFyLlNsaWRlckJhclwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiQ2lyY2xlXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRhaW5lci5CYXIuQ2lyY2xlXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJMZWZ0QXJyb3dcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGFpbmVyLkxlZnRBcnJvd1wiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiUmlnaHRBcnJvd1wiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250YWluZXIuUmlnaHRBcnJvd1wiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgX2NvbnN0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XMub25MZWZ0KHRoaXMpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0cnVlO1xuICAgIH1cbiAgICBfaGFuZGxlUmlnaHQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9pc0Rpc2FibGVkTW9kZSkge1xuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX2luY3JlbWVudFZhbHVlKCk7XG4gICAgICAgIGlmICh0eXBlb2YgdGhpcy5vblJpZ2h0ID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLm9uUmlnaHQodGhpcyk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgfVxuICAgIF91cGRhdGVEaXJlY3Rpb24oKSB7XG4gICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgcGl2b3RYOiAwLFxuICAgICAgICAgICAgcm90YXRpb246IHRoaXMudmVydGljYWwgPyBkZWdyZWVzVG9SYWRpYW5zKDkwKSA6IDAsXG4gICAgICAgICAgICBtb3VudFk6IHRoaXMudmVydGljYWwgPyAuNSA6IDBcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVTbGlkZXJMYXlvdXQoKSB7XG4gICAgICAgIHZhciB3ID0gdGhpcy53IHx8IHRoaXMuc3R5bGUubWluV2lkdGg7XG4gICAgICAgIHRoaXMuX0NvbnRhaW5lci5wYXRjaCh7XG4gICAgICAgICAgICBoOiB0aGlzLnN0eWxlLmNvbnRhaW5lckhlaWdodCxcbiAgICAgICAgICAgIHc6IHcsXG4gICAgICAgICAgICBCYXI6IHtcbiAgICAgICAgICAgICAgICB4OiB0aGlzLl9jYWxjdWxhdGVkU2xpZGVyWCxcbiAgICAgICAgICAgICAgICBTbGlkZXJCYXI6IHtcbiAgICAgICAgICAgICAgICAgICAgeTogdGhpcy5zdHlsZS5jb250YWluZXJIZWlnaHQgLyAyLFxuICAgICAgICAgICAg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Ghpcy5taW4pIC8gKHRoaXMubWF4IC0gdGhpcy5taW4pICogdGhpcy5fY2FsY3VsYXRlZFNsaWRlcldpZHRoO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB4Q2lyY2xlUG9zaXRpb24gPSB0aGlzLnZhbHVlIC8gdGhpcy5tYXggKiB0aGlzLl9jYWxjdWxhdGVkU2xpZGVyV2lkdGg7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX0NpcmNsZSkge1xuICAgICAgICAgICAgdGhpcy5fQ2lyY2xlLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBtb2RlOiB0aGlzLm1vZGUsXG4gICAgICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgcmFkaXVzOiB0aGlzLnN0eWxlLnJhZGl1cyxcbiAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5zdHlsZS53LFxuICAgICAgICAgICAgICAgICAgICBoOiB0aGlzLnN0eWxlLmgsXG4gICAgICAgICAgICAgICAgICAgIGNpcmNsZUNvbG9yOiB0aGlzLnN0eWxlLmNpcmNsZUNvbG9yXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICB5OiB0aGlzLl9TbGlkZXJCYXIueSArIDEsXG4gICAgICAgICAgICAgICAgYWxwaGE6IHRoaXMuX2lzRm9jdXNlZE1vZGUgJiYgdGhpcy5zdHlsZS5zaG93S25vYiA/IDEgOiAwXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIGlmICh0aGlzLnN0eWxlLmNpcmNsZUFuaW1hdGlvbiAmJiBPYmplY3Qua2V5cyh0aGlzLnN0eWxlLmNpcmNsZUFuaW1hdGlvbikubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fQ2lyY2xlLnNtb290aCA9IHtcbiAgICAgICAgICAgICAgICAgICAgeDogWyB4Q2lyY2xlUG9zaXRpb24sIHRoaXMuc3R5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gICAgICB0aGlzLl9SaWdodEFycm93LnNtb290aCA9IHtcbiAgICAgICAgICAgIGFscGhhOiByaWdodEFscGhhXG4gICAgICAgIH07XG4gICAgfVxuICAgIF91cGRhdGVBcnJvd3MoKSB7XG4gICAgICAgIHZhciBhcnJvd1Byb3BzID0ge1xuICAgICAgICAgICAgdzogdGhpcy5zdHlsZS5hcnJvd1dpZHRoLFxuICAgICAgICAgICAgaDogdGhpcy5zdHlsZS5hcnJvd0hlaWdodCxcbiAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgY29sb3I6IHRoaXMuc3R5bGUuYXJyb3dDb2xvclxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICB0aGlzLl9MZWZ0QXJyb3cucGF0Y2goX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBhcnJvd1Byb3BzKSwge30sIHtcbiAgICAgICAgICAgIGljb246IHRoaXMuc3R5bGUuaWNvbkxlZnRTcmNcbiAgICAgICAgfSkpO1xuICAgICAgICB0aGlzLl9SaWdodEFycm93LnBhdGNoKF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgYXJyb3dQcm9wcyksIHt9LCB7XG4gICAgICAgICAgICBpY29uOiB0aGlzLnN0eWxlLmljb25SaWdodFNyY1xuICAgICAgICB9KSk7XG4gICAgICAgIHRoaXMuX1JpZ2h0QXJyb3cuc21vb3RoID0ge1xuICAgICAgICAgICAgeDogdGhpcy5zdHlsZS5hcnJvd1NwYWNpbmcgKyB0aGlzLl9jYWxjdWxhdGVkU2xpZGVyV2lkdGggKyB0aGlzLl9CYXIueFxuICAgICAgICB9O1xuICAgIH1cbiAgICBfZGVjcmVtZW50VmFsdWUoKSB7XG4gICAgICAgIHZhciB2YWx1ZSA9IHRoaXMudmFsdWUgLSB0aGlzLnN0ZXA7XG4gICAgICAgIHRoaXMudmFsdWUgPSB2YWx1ZSA+PSB0aGlzLm1pbiA/IHZhbHVlIDogdGhpc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N0cmluZygpO1xuICAgIH1cbiAgICBzdGF0aWMgX3N0YXRlcygpIHtcbiAgICAgICAgcmV0dXJuIFsgY2xhc3MgVmVydGljYWxTbGlkZXIgZXh0ZW5kcyh0aGlzKXtcbiAgICAgICAgICAgIF9oYW5kbGVMZWZ0KCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIF9oYW5kbGVSaWdodCgpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBfaGFuZGxlVXAoKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2lzRGlzYWJsZWRNb2RlKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdGhpcy5fZGVjcmVtZW50VmFsdWUoKTtcbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIHRoaXMub25VcCA9PT0gXCJmdW5jdGlvblwiKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLm9uVXAodGhpcyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgX2hhbmRsZURvd24oKSB7XG4gICAgICAgICAgICAgICAgaWYgKHRoaXMuX2lzRGlzYWJsZWRNb2RlKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdGhpcy5faW5jcmVtZW50VmFsdWUoKTtcbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIHRoaXMub25Eb3duID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMub25Eb3duKHRoaXMpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICA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uICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIHZhbHVlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dEludmVyc2VTZWNvbmRhcnlcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGludmVyc2U6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIHZhbHVlVGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxTZWNvbmRhcnlcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9LFxuICAgIGJyYW5kOiB7XG4gICAgICAgIG1vZGU6IHtcbiAgICAgICAgICAgIGZvY3VzZWQ6IHtcbiAgICAgICAgICAgICAgICB2YWx1ZVRleHRTdHlsZToge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHRJbnZlcnNlU2Vjb25kYXJ5XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMkYSA9IE9iamVjdC5mcmVlemUoe1xuICAgIF9fcHJvdG9fXzogbnVsbCxcbiAgICBiYXNlOiBiYXNlJGEsXG4gICAgbW9kZTogbW9kZSQyLFxuICAgIHRvbmU6IHRvbmUkNVxufSk7XG5cbmNsYXNzIExpc3RJdGVtU2xpZGVyIGV4dGVuZHMgTGlzdEl0ZW0ge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJMaXN0SXRlbVNsaWRlclwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IF9fdGhlbWVTdHlsZSgpIHtcbiAgICAgICAgcmV0dXJuIHN0eWxlcyRhO1xuICAgIH1cbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICB2YXIgdGVtcGxhdGUgPSBzdXBlci5fdGVtcGxhdGU7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRlbXBsYXRlKCkpLCB7fSwge1xuICAgICAgICAgICAgQ29udGVudDogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0ZW1wbGF0ZSgpLkNvbnRlbnQpLCB7fSwge1xuICAgICAgICAgICAgICAgIGZsZXg6IHtcbiAgICAgICAgICAgICAgICAgICAgZGlyZWN0aW9uOiBcImNvbHVtblwiXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBUZXh0V3JhcHBlcjogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCB0ZW1wbGF0ZSgpLkNvbnRlbnQuVGV4dFdyYXBwZXIpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IDAsXG4gICAgICAgICAgICAgICAgICAgIGZsZXg6IHVuZGVmaW5lZFxuICAgICAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgICAgIFNsaWRlcjoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBOZXN0ZWRTbGlkZXIsXG4gICAgICAgICAgICAgICAgICAgIG1vdW50WDogLjUsXG4gICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIG9uQ2hhbmdlOiBcIl9vblNsaWRlckNoYW5nZWRcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSlcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgcHJvcGVydGllcygpIHtcbiAgICAgICAgcmV0dXJuIFsgLi4uc3VwZXIucHJvcGVyd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X1ZhbHVlID8gdGhpcy5fVmFsdWUuaCA6IDApO1xuICAgIH1cbiAgICBfdXBkYXRlVmFsdWUoKSB7XG4gICAgICAgIGlmICh0aGlzLl9oYXNWYWx1ZSkge1xuICAgICAgICAgICAgdmFyIHZhbHVlUGF0Y2ggPSB7XG4gICAgICAgICAgICAgICAgY29udGVudDogdGhpcy52YWx1ZS50b1N0cmluZygpLFxuICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS52YWx1ZVRleHRTdHlsZSlcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIG1vdW50WDogMSxcbiAgICAgICAgICAgICAgICB4OiB0aGlzLncgLSB0aGlzLl9wYWRkaW5nWFxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmICghdGhpcy5fVmFsdWUpIHtcbiAgICAgICAgICAgICAgICB2YWx1ZVBhdGNoID0gX29iamVjdFNwcmVhZCh7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRleHRCb3hDaGFuZ2VkOiBcIl9vblRleHRCb3hDaGFuZ2VkXCJcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0sIHZhbHVlUGF0Y2gpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIucGF0Y2goe1xuICAgICAgICAgICAgICAgIFZhbHVlOiB2YWx1ZVBhdGNoXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX1RleHRXcmFwcGVyLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBWYWx1ZTogdW5kZWZpbmVkXG4gICAgICAgICAgICB9KTtcbiAgICAgICAg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AgICAgICB0aGlzLl9vcHRpb25zID0gW107XG4gICAgICAgIHRoaXMuX3NlbGVjdGVkSW5kZXggPSAwO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICBzdXBlci5fdXBkYXRlKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVBpY2tlcigpO1xuICAgICAgICB0aGlzLl91cGRhdGVBcnJvd3MoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlQXJyb3dzQWxwaGEoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlQWxpZ25tZW50KCk7XG4gICAgfVxuICAgIF91cGRhdGVBbGlnbm1lbnQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9pc0ZvY3VzZWRNb2RlKSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBqdXN0aWZ5OiBcImNlbnRlclwiXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIGp1c3RpZnk6IFwibGVmdFwiXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlQXJyb3dzKCkge1xuICAgICAgICBpZiAoIXRoaXMuX2lzRm9jdXNlZE1vZGUpIHtcbiAgICAgICAgICAgIHZhciBvZmZBbHBoYSA9IC4wMDE7XG4gICAgICAgICAgICBpZiAodGhpcy5fTGVmdEFycm93KSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fTGVmdEFycm93LmFscGhhID0gb2ZmQWxwaGE7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy5fUmlnaHRBcnJvdykge1xuICAgICAgICAgICAgICAgIHRoaXMuX1JpZ2h0QXJyb3cuYWxwaGEgPSBvZmZBbHBoYTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICB2YXIgYXJyb3dQcm9wcyA9IHtcbiAgICAgICAgICAgIHc6IHRoaXMuc3R5bGUuYXJyb3dXaWR0aCxcbiAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuYXJyb3dIZWlnaHQsXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIGNvbG9yOiB0aGlzLnN0eWxlLmFycm93Q29sb3JcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBhbHBoYTogdGhpcy5zdHlsZS5hcnJvd0FscGhhVmFsdWVcbiAgICAgICAgfTtcbiAgICAgICAgaWYgKCF0aGlzLl9MZWZ0QXJyb3cpIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgICAgIExlZnRBcnJvdzoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41LFxuICAgICAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fTGVmdEFycm93LnBhdGNoKF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgYXJyb3dQcm9wcyksIHt9LCB7XG4gICAgICAgICAgICBpY29uOiB0aGlzLnN0eWxlLmljb25MZWZ0U3JjXG4gICAgICAgIH0pKTtcbiAgICAgICAgdGhpcy5fTGVmdEFycm93LnNtb290aCA9IHtcbiAgICAgICAgICAgIHg6IHRoaXMuc3R5bGUucGFkZGluZ1hcbiAgICAgICAgfTtcbiAgICAgICAgaWYgKCF0aGlzLl9SaWdodEFycm93KSB7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBSaWdodEFycm93OiB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IEljb24sXG4gICAgICAgICAgICAgICAgICAgIG1vdW50WTogLjUsXG4gICAgICAgICAgICAgICAgICAgIG1vdW50WDogMSxcbiAgICAgICAgICAgICAgICAgICAgeTogaCA9PiBoIC8gMlxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX1JpZ2h0QXJyb3cucGF0Y2goX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBhcnJvd1Byb3BzKSwge30sIHtcbiAgICAgICAgICAgIGljb246IHRoaXMuc3R5bGUuaWNvblJpZ2h0U3JjXG4gICAgICAgIH0pKTtcbiAgICAgICAgdGhpcy5fUmlnaHRBcnJvdy5zbW9vdGggPSB7XG4gICAgICAgICAgICB4OiB0aGlzLncgLSB0aGlzLnN0eWxlLnBhZGRpbmdYXG4gICAgICAgIH07XG4gICAgfVxuICAgIF91cGRhdGVQaWNrZXIoKSB7XG4gICAgICAgIHZhciB3ID0gdGhpcy53IC0gdGhpcy5fcGFkZGluZ1ggLSB0aGlzLnN0eWxlLmFycm93V2lkdGggKiAyO1xuICAgICAgICBpZiAoIXRoaXMuX1BpY2tlcikge1xuICAgICAgICAgICAgdGhpcy5fVGV4dFdyYXBwZXIucGF0Y2goe1xuICAgICAgICAgICAgICAgIFBpY2tlcjoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBSb3csXG4gICAgICAgICAgICAgICAgICAgIGNsaXBwaW5nOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICBhbHdheXNTY3JvbGw6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGVjdGVkQ2hhbmdlOiBcIl91cGRhdGVBcnJvd3NBbHBoYVwiXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9QaWNrZXIucGF0Y2goe1xuICAgICAgICAgICAgdmlzaWJsZTogIXRoaXMuX2NvbGxhcHNlLFxuICAgICAgICAgICAgaDogdGhpcy5zdHlsZS5kZXNjcmlwdGlvblRleHRTdHlsZS5saW5lSGVpZ2h0LFxuICAgICAgICAgICAgdzogdyxcbiAgICAgICAgICAgIGl0ZW1zOiB0aGlzLm9wdGlvbnMubWFwKChvcHRpb24gPT4gKHtcbiAgICAgICAgICAgICAgICB0eXBlOiBNYXJxdWVlLFxuICAgICAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUuZGVzY3JpcHRpb25UZXh0U3R5bGUubGluZUhlaWdodCxcbiAgICAgICAgICAgICAgICB3OiB3LFxuICAgICAgICAgICAgICAgIGNlbnRlckFsaWduOiB0aGlzLl9pc0ZvY3VzZWRNb2RlLFxuICAgICAgICAgICAgICAgIHRpdGxlOiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUuZGVzY3JpcHRpb25UZXh0U3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICB0ZXh0OiBvcHRpb25cbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfSkpKSxcbiAgICAgICAgICAgIHNlbGVjdGVkSW5kZXg6IHRoaXMuc2VsZWN0ZWRJbmRleFxuICAgICAgICB9KTtcbiAgICAgICAgdGhpcy5fYWxpZ25QaWNrZXIoKTtcbiAgICB9XG4gICAgX2FsaWduUGlja2VyKCkge1xuICAgICAgICB0aGlzLl9QaWNrZXIucGF0Y2goe1xuICAgICAgICAgICAgbW91bnRYOiB0aGlzLl9pc0ZvY3VzZWRNb2RlID8gLjUgOiAwLFxuICAgICAgICAgICAgeDogdGhpcy5faXNGb2N1c2VkTW9kZSA/IHRoaXMuX1RpdGxlLncgLyAyIDogMFxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZUFycm93c0FscGhhKCkge1xuICAgICAgICBpZiAodGhpcy5fUGlja2VyKSB7XG4gICAgICAgICAgICB0aGlzLl9zZWxlY3RlZEluZGV4ID0gdGhpcy5fUGlja2VyLnNlbGVjdGVkSW5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bn0pO1xuXG5jbGFzcyBTY3JvbGxTbGlkZXIgZXh0ZW5kcyBTbGlkZXIge1xuICAgIHN0YXRpYyBnZXQgX19jb21wb25lbnROYW1lKCkge1xuICAgICAgICByZXR1cm4gXCJTY3JvbGxTbGlkZXJcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkNztcbiAgICB9XG59XG5cbmNsYXNzIFNjcm9sbFdyYXBwZXIgZXh0ZW5kcyBCYXNlJDEge1xuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJDg7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBjbGlwcGluZzogdHJ1ZSxcbiAgICAgICAgICAgIEZhZGVDb250YWluZXI6IHtcbiAgICAgICAgICAgICAgICBTY3JvbGxDb250YWluZXI6IHtcbiAgICAgICAgICAgICAgICAgICAgdzogX3cgPT4gX3csXG4gICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIFNsaWRlcjoge1xuICAgICAgICAgICAgICAgIHR5cGU6IFNjcm9sbFNsaWRlcixcbiAgICAgICAgICAgICAgICB2ZXJ0aWNhbDogdHJ1ZSxcbiAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIG9uU2l6ZUNoYW5nZTogXCJfdXBkYXRlU2Nyb2xsQ29udGFpbmVyU2l6ZVwiXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBhbm5vdW5jZTogXCIgXCJcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIH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odGV4dEJveCkge1xuICAgICAgICBpZiAodGhpcy5fcHJldlcgIT09IHRleHRCb3guZmluYWxXIHx8IHRoaXMuX3ByZXZIICE9PSB0ZXh0Qm94LmZpbmFsSCkge1xuICAgICAgICAgICAgdGhpcy5fcHJldlcgPSB0ZXh0Qm94LmZpbmFsVztcbiAgICAgICAgICAgIHRoaXMuX3ByZXZIID0gdGV4dEJveC5maW5hbEg7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVTY3JvbGxXcmFwcGVyTGF5b3V0KCk7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVBbHBoYSgpO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9yZXNldEZsZXhDb250YWluZXIoKSB7XG4gICAgICAgIHRoaXMuX0ZhZGVDb250YWluZXIucGF0Y2goe1xuICAgICAgICAgICAgU2Nyb2xsQ29udGFpbmVyOiB1bmRlZmluZWRcbiAgICAgICAgfSk7XG4gICAgICAgIHRoaXMuX0ZhZGVDb250YWluZXIucGF0Y2goe1xuICAgICAgICAgICAgU2Nyb2xsQ29udGFpbmVyOiB7XG4gICAgICAgICAgICAgICAgdzogX3cyID0+IF93MixcbiAgICAgICAgICAgICAgICB3b3JkV3JhcDogdHJ1ZVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZSgpIHtcbiAgICAgICAgaWYgKHRoaXMuX2NvbnRlbnRDaGFuZ2VkKSB7XG4gICAgICAgICAgICB0aGlzLl9yZXNldEZsZXhDb250YWluZXIoKTtcbiAgICAgICAgICAgIHRoaXMuX3VwZGF0ZUF1dG9TY3JvbGwoKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl91cGRhdGVTY3JvbGxDb250YWluZXIoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlU2Nyb2xsV3JhcHBlckxheW91dCgpO1xuICAgICAgICB0aGlzLl91cGRhdGVBbHBoYSgpO1xuICAgIH1cbiAgICBfdXBkYXRlQXV0b1Njcm9sbC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LFxuICAgICAgICAgICAgcnR0OiB0cnVlLFxuICAgICAgICAgICAgc2hhZGVyOiBzaG91bGRGYWRlID8ge1xuICAgICAgICAgICAgICAgIHR5cGU6IGxuZy5zaGFkZXJzLkZhZGVPdXQsXG4gICAgICAgICAgICAgICAgYm90dG9tOiB0aGlzLnN0eWxlLmZhZGVIZWlnaHRcbiAgICAgICAgICAgIH0gOiB1bmRlZmluZWRcbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF9zY3JvbGxDb250YWluZXJMb2FkZWQoX3JlZjIzKSB7XG4gICAgICAgIHZhciB7aDogaH0gPSBfcmVmMjM7XG4gICAgICAgIHRoaXMuX1Njcm9sbENvbnRhaW5lci5oID0gaDtcbiAgICAgICAgdGhpcy5fdXBkYXRlU2Nyb2xsV3JhcHBlckxheW91dCgpO1xuICAgIH1cbiAgICBfdXBkYXRlU2Nyb2xsQ29udGFpbmVyKCkge1xuICAgICAgICBpZiAoIXRoaXMuY29udGVudCkgcmV0dXJuO1xuICAgICAgICBpZiAodHlwZW9mIHRoaXMuY29udGVudCA9PT0gXCJzdHJpbmdcIikge1xuICAgICAgICAgICAgdGhpcy5fU2Nyb2xsQ29udGFpbmVyLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBmbGV4OiB7XG4gICAgICAgICAgICAgICAgICAgIGRpcmVjdGlvbjogXCJjb2x1bW5cIlxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgU2Nyb2xsYWJsZVRleHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgaDogMCxcbiAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5fY29udGVudFdpZHRoLFxuICAgICAgICAgICAgICAgICAgICB0eXBlOiBUZXh0Qm94LFxuICAgICAgICAgICAgICAgICAgICBjb250ZW50OiB0aGlzLmNvbnRlbnQsXG4gICAgICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgdGhpcy5zdHlsZS50ZXh0U3R5bGUpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IHRoaXMuX2NvbnRlbnRXaWR0aFxuICAgICAgICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3Njcm9sbENvbnRhaW5lckxvYWRlZFwiXG4gICAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICAgIG9uQWZ0ZXJVcGRhdGU6IHRoaXMuX2FmdGVyVGV4dEJveFVwZGF0ZS5iaW5kKHRoaXMpXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0gZWxzZSBpZiAoQXJyYXkuaXNBcnJheSh0aGlzLmNvbnRlbnQpKSB7XG4gICAgICAgICAgICB2YXIgY29udGVudCA9IHt9O1xuICAgICAgICAgICAgdGhpcy5jb250ZW50LmZvckVhY2goKChpdGVtLCBpbmRleCkgPT4ge1xuICAgICAgICAgICAgICAgIHZhciBpZCA9IFwiU2Nyb2xsVGV4dFwiLmNvbmNhdChpbmRleCk7XG4gICAgICAgICAgICAgICAgY29udGVudFtpZF0gPSBfb2JqZWN0U3ByZWFkKHtcbiAgICAgICAgICAgICAgICAgICAgdzogdGhpcy5fY29udGVudFdpZHRoXG4gICAgICAgICAgICAgICAgfSwgaXRlbSk7XG4gICAgICAgICAgICAgICAgaWYgKGl0ZW0udGV4dCkge1xuICAgICAgICAgICAgICAgICAgICBjb250ZW50W2lkXSA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IFRleHRCb3gsXG4gICAgICAgICAgICAgICAgICAgICAgICBjb250ZW50OiBpdGVtLnRleHQsXG4gICAgICAgICAgICAgICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHRoaXMuc3R5bGUudGV4dFN0eWxlKSwgaXRlbS5zdHlsZSksIHt9LCB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmRXcmFwOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3b3JkV3JhcFdpZHRoOiB0aGlzLl9jb250ZW50V2lkdGhcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgICAgIG9uQWZ0ZXJVcGRhdGU6IHRoaXMuX2FmdGVyVGV4dEJveFVwZGF0ZS5iaW5kKHRoaXMpXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgdGhpcy5fU2Nyb2xsQ29udGFpbmVyLnBhdGNoKF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgIGZsZXg6IHtcbiAgICAgICAgICAgICAgICAgICAgZGlyZWN0aW9uOiB0aGlzLmZsZXhEaXJlY3Rpb24sXG4gICAgICAgICAgICAgICAgICAgIHdyYXA6IHRoaXMuc2hvdWxkV3JhcFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0sIGNvbnRlbnQpKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfc2Nyb2xsRG93bigpIHtcbiAgICAgICAgdmFyIGhhc0NvbnRlbnRUb1Njcm9sbFRvID0gdGhpcy5fc2Nyb2xsQ29udGFpbmVyWSArIHRoaXMuX1Njcm9sbENvbnRhaW5lci5maW5hbEggPiB0aGlzLnJlbmRlckhlaWdodD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B0aGlzKTtcbiAgICAgICAgICAgICAgICB0aGlzLl91cGRhdGVGYWRlQ29udGFpbmVyKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3Njcm9sbFVwKCkge1xuICAgICAgICB2YXIgY2FuU2Nyb2xsVXAgPSB0aGlzLl9zY3JvbGxDb250YWluZXJZIDwgMDtcbiAgICAgICAgaWYgKGNhblNjcm9sbFVwKSB7XG4gICAgICAgICAgICB2YXIgdGFyZ2V0WSA9IHRoaXMuX3Njcm9sbENvbnRhaW5lclkgKyB0aGlzLnNjcm9sbFN0ZXA7XG4gICAgICAgICAgICB2YXIgY2FuU2Nyb2xsQnlTdGVwTGVuZ3RoID0gdGFyZ2V0WSA8IDA7XG4gICAgICAgICAgICB0aGlzLl9TY3JvbGxDb250YWluZXIucGF0Y2goe1xuICAgICAgICAgICAgICAgIHNtb290aDoge1xuICAgICAgICAgICAgICAgICAgICB5OiBbIGNhblNjcm9sbEJ5U3RlcExlbmd0aCA/IHRhcmdldFkgOiAwLCB0aGlzLl9zY3JvbGxBbmltYXRpb24gXVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgdmFyIGlzU2Nyb2xsYWJsZSA9IHRoaXMuX3Njcm9sbENvbnRhaW5lclkgKyB0aGlzLl9TY3JvbGxDb250YWluZXIuZmluYWxIID4gdGhpcy5yZW5kZXJIZWlnaHQ7XG4gICAgICAgICAgICBpZiAoaXNTY3JvbGxhYmxlKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5fYXV0b1Njcm9sbENvbXBsZXRlID0gZmFsc2U7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy5fc2Nyb2xsQ29udGFpbmVyWSA+PSAwKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKFwiJHNjcm9sbENoYW5nZWRcIiwgXCJlbmRVcFwiLCB0aGlzKTtcbiAgICAgICAgICAgIH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xlLmFuaW1hdGlvbiBdLFxuICAgICAgICAgICAgeTogWyB0aGlzLnN0eWxlLm9mZnNldFksIHRoaXMuc3R5bGUuYW5pbWF0aW9uIF0sXG4gICAgICAgICAgICB4OiBbIHRoaXMuc3R5bGUub2Zmc2V0WCwgdGhpcy5zdHlsZS5hbmltYXRpb24gXVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZSgpIHtcbiAgICAgICAgdmFyIHNoYWRvd1NpemUgPSB0aGlzLnN0eWxlLnNwcmVhZCArIHRoaXMuc3R5bGUuYmx1ciAqIDI7XG4gICAgICAgIHZhciBob2xlcHVuY2hFcnJvciA9IDQ7XG4gICAgICAgIHZhciBleHRyYUJvdW5kc1kgPSB0aGlzLnN0eWxlLm1heE9mZnNldFk7XG4gICAgICAgIHZhciBleHRyYUJvdW5kc1ggPSB0aGlzLnN0eWxlLm1heE9mZnNldFg7XG4gICAgICAgIHZhciByYWRpdXMgPSBnZXRNYXhSb3VuZFJhZGl1cyh0aGlzLnN0eWxlLnJhZGl1cywgdGhpcy53LCB0aGlzLmgpO1xuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIEZyYW1lOiB7XG4gICAgICAgICAgICAgICAgdzogdGhpcy53ICsgc2hhZG93U2l6ZSAqIDIgKyBleHRyYUJvdW5kc1gsXG4gICAgICAgICAgICAgICAgaDogdGhpcy5oICsgc2hhZG93U2l6ZSAqIDIgKyBleHRyYUJvdW5kc1ksXG4gICAgICAgICAgICAgICAgeDogKHRoaXMudyArIGV4dHJhQm91bmRzWCkgLyAyLFxuICAgICAgICAgICAgICAgIHk6ICh0aGlzLmggKyBleHRyYUJvdW5kc1kpIC8gMixcbiAgICAgICAgICAgICAgICBtb3VudDogLjUsXG4gICAgICAgICAgICAgICAgcnR0OiB0aGlzLm1hc2tTaGFkb3csXG4gICAgICAgICAgICAgICAgc2hhZGVyOiB0aGlzLm1hc2tTaGFkb3cgPyB7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6IGxuZy5zaGFkZXJzLkhvbGUsXG4gICAgICAgICAgICAgICAgICAgIHc6IHRoaXMudyAtIGhvbGVwdW5jaEVycm9yLFxuICAgICAgICAgICAgICAgICAgICBoOiB0aGlzLmggLSBob2xlcHVuY2hFcnJvcixcbiAgICAgICAgICAgICAgICAgICAgeDogc2hhZG93U2l6ZSArIGhvbGVwdW5jaEVycm9yIC8gMixcbiAgICAgICAgICAgICAgICAgICAgeTogc2hhZG93U2l6ZSArIGhvbGVwdW5jaEVycm9yIC8gMixcbiAgICAgICAgICAgICAgICAgICAgcmFkaXVzOiByYWRpdXNcbiAgICAgICAgICAgICAgICB9IDogdW5kZWZpbmVkLFxuICAgICAgICAgICAgICAgIFNoYWRvdzoge1xuICAgICAgICAgICAgICAgICAgICBjb2xvcjogdGhpcy5zdHlsZS5jb2xvcixcbiAgICAgICAgICAgICAgICAgICAgdGV4dHVyZTogbG5nLlRvb2xzLmdldFNoYWRvd1JlY3QodGhpcy53ICsgdGhpcy5zdHlsZS5zcHJlYWQgKiAyLCB0aGlzLmggKyB0aGlzLnN0eWxlLnNwcmVhZCAqIDIsIHJhZGl1cywgdGhpcy5zdHlsZS5ibHVyKVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIGlmICh0aGlzLnNob3VsZFNtb290aCA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICB0aGlzLnNob3VsZFNtb290aCA9IHRydWU7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5fdXBkYXRlRm9jdXNTdHlsZSgpO1xuICAgIH1cbn1cblxudmFyIGJhc2UkNSA9IHRoZW1lID0+IHtcbiAgICB2YXIgc2l6ZSA9IHRoZW1lLnNwYWNlci54eGw7XG4gICAgcmV0dXJuIHtcbiAgICAgICAgd2lkdGg6IHNpemUsXG4gICAgICAgIGhlaWdodDogc2l6ZSxcbiAgICAgICAgcmFkaXVzOiBzaXplIC8gMlxuICA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ICAgICAgICAgICAgICAgIHZhciBwcmV2Q29udGVudCA9IHRoaXMudGFnKFwiQ29udGVudFwiLmNvbmNhdCh0aGlzLl9wcmV2ZVNlbGVjdGVkSW5kZXgpKTtcbiAgICAgICAgICAgICAgICBwcmV2Q29udGVudC5zbW9vdGggPSB7XG4gICAgICAgICAgICAgICAgICAgIGFscGhhOiAwXG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5faGFzQ29udGVudCkge1xuICAgICAgICAgICAgICAgICAgICBwcmV2Q29udGVudC5fZ2V0VHJhbnNpdGlvbihcImFscGhhXCIpLm9uY2UoXCJmaW5pc2hcIiwgKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuX2ZhZGVJbkNvbnRlbnQoKTtcbiAgICAgICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5zZWxlY3RlZEluZGV4ICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fZmFkZUluQ29udGVudCgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5faGFzQ29udGVudCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2ZhZGVJbkNvbnRlbnQoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuX3ByZXZlU2VsZWN0ZWRJbmRleCA9IHRoaXMuc2VsZWN0ZWRJbmRleDtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfZmFkZUluQ29udGVudCgpIHtcbiAgICAgICAgdGhpcy5fc2VsZWN0ZWRDb250ZW50LnNtb290aCA9IHtcbiAgICAgICAgICAgIGFscGhhOiAxXG4gICAgICAgIH07XG4gICAgICAgIHRoaXMuX3NlbGVjdGVkQ29udGVudC5fZ2V0VHJhbnNpdGlvbihcImFscGhhXCIpLm9uY2UoXCJmaW5pc2hcIiwgKCgpID0+IHtcbiAgICAgICAgICAgIHRoaXMuaCA9IHRoaXMuX3NlbGVjdGVkQ29udGVudC5oO1xuICAgICAgICAgICAgdGhpcy5zaWduYWwoXCJjb250ZW50SGVpZ2h0Q2hhbmdlXCIsIHRoaXMuaCk7XG4gICAgICAgIH0pKTtcbiAgICB9XG4gICAgX3VwZGF0ZUNvbnRlbnQoKSB7XG4gICAgICAgIHZhciBhbGxDb250ZW50ID0gdGhpcy5jb250ZW50SXRlbXMucmVkdWNlKCgoYWNjLCBpdGVtLCBpZHgpID0+IHtcbiAgICAgICAgICAgIHZhciBjb21wb25lbnQ7XG4gICAgICAgICAgICB2YXIgdGFnTmFtZSA9IFwiQ29udGVudFwiLmNvbmNhdChpZHgpO1xuICAgICAgICAgICAgaWYgKHR5cGVvZiBpdGVtID09PSBcImZ1bmN0aW9uXCIpIHtcbiAgICAgICAgICAgICAgICB2YXIgY29tcG9uZW50TG9hZGVyID0gaXRlbSgpO1xuICAgICAgICAgICAgICAgIGlmIChjb21wb25lbnRMb2FkZXIudGhlbikge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9sb2FkQXN5bmNDb21wb25lbnQoY29tcG9uZW50TG9hZGVyLCBpZHgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbXBvbmVudCA9IGNvbXBvbmVudExvYWRlcjtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGNvbXBvbmVudCA9IGl0ZW07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoY29tcG9uZW50KSB7XG4gICAgICAgICAgICAgICAgYWNjW3RhZ05hbWVdID0gX29iamVjdFNwcmVhZChfb2JqZWN0U3ByZWFkKHt9LCBjb21wb25lbnQpLCB7fSwge1xuICAgICAgICAgICAgICAgICAgICBhbHBoYTogMFxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgfSksIHt9KTtcbiAgICAgICAgdGhpcy5wYXRjaChhbGxDb250ZW50KTtcbiAgICB9XG4gICAgX2xvYWRBc3luY0NvbXBvbmVudChjb21wb25lbnRMb2FkZXIsIGlkeCkge1xuICAgICAgICBjb21wb25lbnRMb2FkZXIudGhlbigoY29tcG9uZW50ID0+IHtcbiAgICAgICAgICAgIHZhciB0YWdOYW1lID0gXCJDb250ZW50XCIuY29uY2F0KGlkeCk7XG4gICAgICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgICAgICBbdGFnTmFtZV06IF9vYmplY3RTcHJlYWQoX29iamVjdFNwcmVhZCh7fSwgY29tcG9uZW50KSwge30sIHtcbiAgICAgICAgICAgICAgICAgICAgYWxwaGE6IDBcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pKTtcbiAgICB9XG4gICAgc2V0IGNvbnRlbnRJdGVtcyhjb250ZW50SXRlbXMpIHtcbiAgICAgICAgaWYgKCFzdHJpbmdpZnlDb21wYXJlKGNvbnRlbnRJdGVtcywgdGhpcy5fY29udGVudEl0ZW1zKSkge1xuICAgICAgICAgICAgdGhpcy5fY29udGVudEl0ZW1zID0gY29udGVudEl0ZW1zO1xuICAgICAgICAgICAgdGhpcy5fdXBkYXRlQ29udGVudCgpO1xuICAgICAgICB9XG4gICAgfVxuICAgIGdldCBjb250ZW50SXRlbXMoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLl9jb250ZW50SXRlbXM7XG4gICAgfVxuICAgIGdldCBfaGFzQ29udGVudCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3NlbGVjdGVkQ29udGVudCAmJiB0aGlzLl9zZWxlY3RlZENvbnRlbnQuY2hpbGRyZW4ubGVuZ3RoID4gMDtcbiAgICB9XG4gICAgZ2V0IF9zZWxlY3RlZENvbnRlbnQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnRhZyhcIkNvbnRlbnRcIi5jb25jYXQodGhpcy5zZWxlY3RlZEluZGV4KSk7XG4gICAgfVxuICAgIF9nZXRGb2N1c2VkKCkge1xuICAgICAgICBpZiAodGhpcy5faGFzQ29udGVudCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX3NlbGVjdGVkQ29udGVudDtcbiAgICAgICAgfVxuICAgIH1cbn1cblxudmFyIGJhc2UkNCA9IHRoZW1lID0+ICh7XG4gICAgdGFiU3BhY2luZzogdGhlbWUuc3BhY2VyLmxnLFxuICAgIHRhYnNNYXJnaW5Cb3R0b206IHRoZW1lLnNwYWNlci54eGxcbn0pO1xuXG52YXIgc3R5bGVzJDQgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSQ0XG59KTtcblxuY2xhc3MgVGFiQmFyIGV4dGVuZHMgQmFzZSQxIHtcbiAgICBzdGF0aWMgX3RlbXBsYXRlKCkge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgVGFiczoge1xuICAgICAgICAgICAgICAgIHR5cGU6IFJvdyxcbiAgICAgICAgICAgICAgICBhdXRvUmVzaXplSGVpZ2h0OiB0cnVlLFxuICAgICAgICAgICAgICAgIHNpZ25hbHM6IHtcbiAgICAgICAgICAgICAgICAgICAgc2VsZWN0ZWRDaGFuZ2U6IFwiX3NlbGVjdGVkVGFiQ2hhbmdlXCJcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgVGFiQ29udGVudDoge1xuICAgICAgICAgICAgICAgIHR5cGU6IENvbnRlbnRTd2l0Y2hlcixcbiAgICAgICAgICAgICAgICBzaWduYWxzOiB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnRlbnRIZWlnaHRDaGFuZ2U6IFwiX3VwZGF0ZVRhYkJhckhlaWdodFwiXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzd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hpcy5faXNVbmZvY3VzZWRNb2RlKSB7XG4gICAgICAgICAgICAgICAgdGFiLm1vZGUgPSBpc1NlbGVjdGVkVGFiICYmIHRoaXMucmV0YWluU2VsZWN0aW9uID8gXCJzZWxlY3RlZFwiIDogXCJ1bmZvY3VzZWRcIjtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5faXNGb2N1c2VkTW9kZSkge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLl9pc1RhYnNGb2N1c2VkKSB7XG4gICAgICAgICAgICAgICAgICAgIHRhYi5tb2RlID0gaXNTZWxlY3RlZFRhYiA/IFwiZm9jdXNlZFwiIDogXCJ1bmZvY3VzZWRcIjtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB0YWIubW9kZSA9IGlzU2VsZWN0ZWRUYWIgPyBcInNlbGVjdGVkXCIgOiBcInVuZm9jdXNlZFwiO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSkpO1xuICAgICAgICBpZiAodGhpcy5hbHBoYVNlbGVjdGVkVGFiKSB7XG4gICAgICAgICAgICB0aGlzLl91cGRhdGVUYWJBbHBoYXMoKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdXBkYXRlVGFiQWxwaGFzKCkge1xuICAgICAgICBpZiAodGhpcy5faXNUYWJzRm9jdXNlZCkge1xuICAgICAgICAgICAgdGhpcy5fVGFicy5pdGVtcy5mb3JFYWNoKCh0YWIgPT4ge1xuICAgICAgICAgICAgICAgIHRhYi5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIGFscGhhOiAxXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLl9UYWJzLml0ZW1zLmZvckVhY2goKHRhYiA9PiB7XG4gICAgICAgICAgICAgICAgdGFiLnBhdGNoKHtcbiAgICAgICAgICAgICAgICA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udGVudENvbG9yOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbCxcbiAgICAgICAgdGV4dFN0eWxlOiB7XG4gICAgICAgICAgICB0ZXh0Q29sb3I6IHRoZW1lLmNvbG9yLnRleHROZXV0cmFsXG4gICAgICAgIH1cbiAgICB9LFxuICAgIGRpc2FibGVkOiB7XG4gICAgICAgIGJhY2tncm91bmRDb2xvcjogdGhlbWUuY29sb3IuZmlsbFRyYW5zcGFyZW50LFxuICAgICAgICBjb250ZW50Q29sb3I6IHRoZW1lLmNvbG9yLmZpbGxOZXV0cmFsRGlzYWJsZWQsXG4gICAgICAgIHRleHRTdHlsZToge1xuICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbERpc2FibGVkXG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHRvbmUkMiA9IHRoZW1lID0+ICh7XG4gICAgbmV1dHJhbDoge30sXG4gICAgaW52ZXJzZToge1xuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBmb2N1c2VkOiB7XG4gICAgICAgICAgICAgICAgY29udGVudENvbG9yOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbCxcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IHtcbiAgICAgICAgICAgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH0sXG4gICAgYnJhbmQ6IHtcbiAgICAgICAgbW9kZToge1xuICAgICAgICAgICAgZm9jdXNlZDoge1xuICAgICAgICAgICAgICAgIGNvbnRlbnRDb2xvcjogdGhlbWUuY29sb3IuZmlsbE5ldXRyYWwsXG4gICAgICAgICAgICAgICAgdGV4dFN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRDb2xvcjogdGhlbWUuY29sb3IudGV4dE5ldXRyYWxcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59KTtcblxudmFyIHN0eWxlcyQzID0gT2JqZWN0LmZyZWV6ZSh7XG4gICAgX19wcm90b19fOiBudWxsLFxuICAgIGJhc2U6IGJhc2UkMyxcbiAgICBtb2RlOiBtb2RlLFxuICAgIHRvbmU6IHRvbmUkMlxufSk7XG5cbmNsYXNzIFRhYiBleHRlbmRzIFN1cmZhY2Uge1xuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiBfb2JqZWN0U3ByZWFkKF9vYmplY3RTcHJlYWQoe30sIHN1cGVyLl90ZW1wbGF0ZSgpKSwge30sIHtcbiAgICAgICAgICAgIENvbnRlbnQ6IHtcbiAgICAgICAgICAgICAgICBtb3VudDogLjUsXG4gICAgICAgICAgICAgICAgeDogdyA9PiB3IC8gMixcbiAgICAgICAgICAgICAgICB5OiBoID0+IGggLyAyLFxuICAgICAgICAgICAgICAgIFRleHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgbW91bnRZOiAuNSxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX29uVGV4dEJveENoYW5nZWRcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXMkMztcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIHJldHVybiBcIlRhYlwiO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwiaWNvblwiLCBcInRpdGxlXCIgXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCB0YWdzKCkge1xuICAgICAgICByZXR1cm4gWyAuLi5zdXBlci50YWdzLCBcIkNvbnRlbnRcIiwge1xuICAgICAgICAgICAgbmFtZTogXCJJY29uXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRlbnQuSWNvblwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGV4dFwiLFxuICAgICAgICAgICAgcGF0aDogXCJDb250ZW50LlRleHRcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgYWxpYXNTdHlsZXMoKSB7XG4gICAgICAgIHJldHVybiBbIHtcbiAgICAgICAgICAgIHByZXY6IFwibm9UaXRsZVBhZGRpbmdYXCIsXG4gICAgICAgICAgICBjdXJyOiBcInBhZGRpbmdYTm9UaXRsZVwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgX29uVGV4dEJveENoYW5nZWQoKSB7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUNvbnRlbnQoKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGFiU2l6ZSgpO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICBzdXBlci5fdXBkYXRlKCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUljb24oKTtcbiAgICAgICAgdGhpcy5fdXBkYXRlVGV4dCgpO1xuICAgICAgICB0aGlzLl91cGRhdGVDb250ZW50KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZVRhYlNpemUoKTtcbiAgICB9XG4gICAgX3VwZGF0ZUljb24oKSB7XG4gICAgICAgIGlmICghdGhpcy5pY29uKSB7XG4gICAgICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBJY29uOiB1bmRlZmluZWRcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHZhciBpY29uUGF0Y2ggPSB7XG4gICAgICAgICAgICBpY29uOiB0aGlzLmljb24sXG4gICAgICAgICAgICB3OiB0aGlzLnN0eWxlLmljb25TaXplLFxuICAgICAgICAgICAgaDogdGhpcy5zdHlsZS5pY29uU2l6ZSxcbiAgICAgICAgICAgIHk6IHRoaXMuX0NvbnRlbnQuaCAvIDIsXG4gICAgICAgICAgICBzdHlsZToge1xuICAgICAgICAgICAgICAgIGNvbG9yOiB0aGlzLnN0eWxlLmNvbnRlbnRDb2xvclxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICBpZiAodGhpcy50aXRsZSkge1xuICAgICAgICAgICAgaWNvblBhdGNoLnggPSAwO1xuICAgICAgICAgICAgaWNvblBhdGNoLm1vdW50WCA9IDA7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpY29uUGF0Y2gueCA9IHRoaXMuX0NvbnRlbnQudyAvIDI7XG4gICAgICAgICAgICBpY29uUGF0Y2gubW91bnRYID0gLjU7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMuX0ljb24pIHtcbiAgICAgICAgICAgIHRoaXMuX0ljb24ucGF0Y2goaWNvblBhdGNoKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuX0NvbnRlbnQucGF0Y2goe1xuICAgICAgICAgICAgICAgIEljb246IF9vYmplY3RTcHJlYWQoe1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBJY29uLFxuICAgICAgICAgICAgICAgICAgICBtb3VudFk6IC41XG4gICAgICAgICAgICAgICAgfSwgaWNvblBhdGNoKVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICB9XG4gICAgX3VwZGF0ZVRleHQoKSB7XG4gICAgICAgIHZhciB0ZXh0UGF0Y2ggPSB7XG4gICAgICAgICAgICBjb250ZW50OiB0aGlzLnRpdGxlLFxuICAgICAgICAgICAgc3R5bGU6IHtcbiAgICAgICAgICAgICAgICB0ZXh0U3R5bGU6IHRoaXMuc3R5bGUudGV4dFN0eWxlXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgeTogdGhpcy5fQ29udGVudC5oIC8gMlxuICAgICAgICB9O1xuICAgICAgICBpZiAodGhpcy5pY29uKSB7XG4gICAgICAgICAgICB0ZXh0UGF0Y2gueCA9IHRoaXMuX2ljb25XICsgdGhpcy5zdHlsZS5pY29uTWFyZ2luUmlnaHQ7XG4gICAgICAgICAgICB0ZXh0UGF0Y2gubW91bnRYID0gMDtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRleHRQYXRjaC54ID0gdGhpcy5fQ29udGVudC53IC8gMjtcbiAgICAgICAgICAgIHRleHRQYXRjaC5tb3VudFggPSAuNTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLl9UZXh0LnBhdGNoKHRleHRQYXRjaCk7XG4gICAgfVxuICAgIF91cGRhdGVDb250ZW50KCkge1xuICAgICAgICB0aGlzLl9Db250ZW50LnBhdGNoKHtcbiAgICAgICAgICAgIHc6IHRoaXMuX2ljb25XICsgKHRoaXMudGl0bGUgPyB0aGlzLnN0eWxlLmljb25NYXJnaW5SaWdodCA6IDApICsgdGhpcy5fdGV4dFcsXG4gICAgICAgICAgICBoOiBNYXRoLm1heCh0aGlzLl9pY29uSCwgdGhpcy5fVGV4dC5oKVxuICAgICAgICB9KTtcbiAgICB9XG4gICAgX3VwZGF0ZVRhYlNpemUoKSB7XG4gICAgICAgIGlmICh0aGlzLnRpdGxlIHx8IHRoaXMuaWNvbikge1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgdzogdGhpcy5fcGFkZGluZ1ggKiAyICsgdGhpcy5fQ29udGVudC53LFxuICAgICAgICAgICAgICAgIGg6IHRoaXMuc3R5bGUucGFkZGluZ1kgKiAyICsgdGhpcy5fQ29udGVudC5oXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMucGF0Y2goe1xuICAg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dHJva2VXaWR0aCkgKiAyLFxuICAgICAgICBrbm9iV2lkdGg6IGtub2JTaXplLFxuICAgICAgICBrbm9iSGVpZ2h0OiBrbm9iU2l6ZSxcbiAgICAgICAga25vYlJhZGl1czoga25vYlNpemUgLyAyLFxuICAgICAgICBrbm9iUGFkZGluZzoga25vYlBhZGRpbmcsXG4gICAgICAgIHN0cm9rZVdpZHRoOiBzdHJva2VXaWR0aCxcbiAgICAgICAgd2lkdGg6IChzdHJva2VXaWR0aCArIGtub2JQYWRkaW5nICogMiArIGtub2JTaXplKSAqIDJcbiAgICB9O1xufTtcblxudmFyIHRvbmUkMSA9IHRoZW1lID0+ICh7XG4gICAgbmV1dHJhbDoge1xuICAgICAgICBzdHJva2VDb2xvcjogdGhlbWUuY29sb3IuZmlsbE5ldXRyYWwsXG4gICAgICAgIGJhY2tncm91bmRDb2xvcjogdGhlbWUuY29sb3IuZmlsbEludmVyc2VUZXJ0aWFyeSxcbiAgICAgICAgYmFja2dyb3VuZENvbG9yQ2hlY2tlZDogdGhlbWUuY29sb3IuZmlsbE5ldXRyYWwsXG4gICAgICAgIGtub2JDb2xvcjogdGhlbWUuY29sb3IuZmlsbE5ldXRyYWwsXG4gICAgICAgIGtub2JDb2xvckNoZWNrZWQ6IHRoZW1lLmNvbG9yLmZpbGxJbnZlcnNlLFxuICAgICAgICBtb2RlOiB7XG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICAgIHN0cm9rZUNvbG9yOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbERpc2FibGVkLFxuICAgICAgICAgICAgICAgIGJhY2tncm91bmRDb2xvcjogdGhlbWUuY29sb3IuZmlsbEludmVyc2VEaXNhYmxlZCxcbiAgICAgICAgICAgICAgICBiYWNrZ3JvdW5kQ29sb3JDaGVja2VkOiB0aGVtZS5jb2xvci5maWxsTmV1dHJhbERpc2FibGVkLFxuICAgICAgICAgICAgICAgIGtub2JDb2xvcjogdGhlbWUuY29sb3IuZmlsb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2xlXCI7XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgX190aGVtZVN0eWxlKCkge1xuICAgICAgICByZXR1cm4gc3R5bGVzJDI7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBDb250YWluZXI6IHtcbiAgICAgICAgICAgICAgICBTdHJva2U6IHt9LFxuICAgICAgICAgICAgICAgIEtub2I6IHt9XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJDb250YWluZXJcIiwge1xuICAgICAgICAgICAgbmFtZTogXCJLbm9iXCIsXG4gICAgICAgICAgICBwYXRoOiBcIkNvbnRhaW5lci5Lbm9iXCJcbiAgICAgICAgfSwge1xuICAgICAgICAgICAgbmFtZTogXCJTdHJva2VcIixcbiAgICAgICAgICAgIHBhdGg6IFwiQ29udGFpbmVyLlN0cm9rZVwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkge1xuICAgICAgICByZXR1cm4gWyBcImNoZWNrZWRcIiBdO1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IGFsaWFzU3R5bGVzKCkge1xuICAgICAgICByZXR1cm4gWyB7XG4gICAgICAgICAgICBwcmV2OiBcInN0cm9rZVdlaWdodFwiLFxuICAgICAgICAgICAgY3VycjogXCJzdHJva2VXaWR0aFwiXG4gICAgICAgIH0gXTtcbiAgICB9XG4gICAgX2NvbnN0cnVjdCgpIHtcbiAgICAgICAgc3VwZXIuX2NvbnN0cnVjdCAmJiBzdXBlci5fY29uc3RydWN0KCk7XG4gICAgICAgIHRoaXMuX2NoZWNrZWQgPSBmYWxzZTtcbiAgICB9XG4gICAgX3VwZGF0ZSgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlS25vYlBvc2l0aW9uKCk7XG4gICAgICAgI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AgICAgICAgICAgdGV4dENvbG9yOiB0aGVtZS5jb2xvci50ZXh0TmV1dHJhbFxuICAgICAgICB9XG4gICAgfVxufSk7XG5cbnZhciBzdHlsZXMgPSBPYmplY3QuZnJlZXplKHtcbiAgICBfX3Byb3RvX186IG51bGwsXG4gICAgYmFzZTogYmFzZSxcbiAgICB0b25lOiB0b25lXG59KTtcblxuY2xhc3MgVG9vbHRpcCBleHRlbmRzIEJhc2UkMSB7XG4gICAgc3RhdGljIGdldCBfX2NvbXBvbmVudE5hbWUoKSB7XG4gICAgICAgIHJldHVybiBcIlRvb2x0aXBcIjtcbiAgICB9XG4gICAgc3RhdGljIGdldCBfX3RoZW1lU3R5bGUoKSB7XG4gICAgICAgIHJldHVybiBzdHlsZXM7XG4gICAgfVxuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBhbHBoYTogMCxcbiAgICAgICAgICAgIHNjYWxlOiAuNSxcbiAgICAgICAgICAgIG1vdW50WDogLjUsXG4gICAgICAgICAgICB4OiB3ID0+IHcgLyAyLFxuICAgICAgICAgICAgQmFja2dyb3VuZDoge1xuICAgICAgICAgICAgICAgIFRleHQ6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogVGV4dEJveCxcbiAgICAgICAgICAgICAgICAgICAgc2lnbmFsczoge1xuICAgICAgICAgICAgICAgICAgICAgICAgdGV4dEJveENoYW5nZWQ6IFwiX3RleHRMb2FkZWRcIlxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgIH1cbiAgICBzdGF0aWMgZ2V0IHByb3BlcnRpZXMoKSB7XG4gICAgICAgIHJldHVybiBbIFwidGl0bGVcIiwgXCJkZWxheVZpc2libGVcIiwgXCJ0aW1lVmlzaWJsZVwiIF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgdGFncygpIHtcbiAgICAgICAgcmV0dXJuIFsgXCJCYWNrZ3JvdW5kXCIsIHtcbiAgICAgICAgICAgIG5hbWU6IFwiVGV4dFwiLFxuICAgICAgICAgICAgcGF0aDogXCJCYWNrZ3JvdW5kLlRleHRcIlxuICAgICAgICB9IF07XG4gICAgfVxuICAgIHN0YXRpYyBnZXQgYWxpYXNTdHlsZXMoKSB7XG4gICAgICAgIHJldHVybiBbIHtcbiAgICAgICAgICAgIHByZXY6IFwicG9pbnRlckhcIixcbiAgICAgICAgICAgIGN1cnI6IFwicG9pbnRlckhlaWdodFwiXG4gICAgICAgIH0sIHtcbiAgICAgICAgICAgIHByZXY6IFwicG9pbnRlcldcIixcbiAgICAgICAgICAgIGN1cnI6IFwicG9pbnRlcldpZHRoXCJcbiAgICAgICAgfSBdO1xuICAgIH1cbiAgICBfdXBkYXRlKCkge1xuICAgICAgICB0aGlzLl91cGRhdGVUZXh0KCk7XG4gICAgICAgIHRoaXMuX3VwZGF0ZUJhY2tncm91bmQoKTtcbiAgICB9XG4gICAgX3VwZGF0ZVRleHQoKSB7XG4gICAgICAgIGlmICh0aGlzLl9UZXh0KSB7XG4gICAgICAgICAgICB0aGlzLl9UZXh0LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBjb250ZW50OiB0aGlzLnRpdGxlLFxuICAgICAgICAgICAgICAgIHN0eWxlOiB7XG4gICAgICAgICAgICAgICAgICAgIHRleHRTdHlsZTogdGhpcy5zdHlsZS50ZXh0U3R5bGVcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBfdGV4dExvYWRlZCgpIHtcbiAgICAgICAgdGhpcy5fdXBkYXRlQmFja2dyb3VuZEhlaWdodCgpO1xuICAgICAgICB0aGlzLl91cGRhdGVUZXh0UG9zaXRpb24oKTtcbiAgICB9XG4gICAgX3VwZGF0ZUJhY2tncm91bmQoKSB7XG4gICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgQmFja2dyb3VuZDoge1xuICAgICAgICAgICAgICAgIHRleHR1cmU6IHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogQnViYmxlLFxuICAgICAgICAgICAgICAgICAgICB3OiB0aGlzLl9CYWNrZ3JvdW5kLncsXG4gICAgICAgICAgICAgICAgICAgIGg6IHRoaXMuX0JhY2tncm91bmQuaCxcbiAgICAgICAgICAgICAgICAgICAgcmFkaXVzOiBnZXRNYXhSb3VuZFJhZGl1cyh0aGlzLnN0eWxlLnJhZGl1cywgdGhpcy5fQmFja2dyb3VuZC53IC0gdGhpcy5zdHlsZS5wb2ludGVySGVpZ2h0LCB0aGlzLl9CYWNrZ3JvdW5kLmggLSB0aGlzLnN0eWxlLnBvaW50ZXJIZWlnaHQpLFxuICAgICAgICAgICAgICAgICAgICBwb2ludGVyV2lkdGg6IHRoaXMuc3R5bGUucG9pbnRlcldpZHRoLFxuICAgICAgICAgICAgICAgICAgICBwb2ludGVySGVpZ2h0OiB0aGlzLnN0eWxlLnBvaW50ZXJIZWlnaHQsXG4gICAgICAgICAgICAgICAgICAgIGNvbG9yOiB0aGlzLnN0eWxlLmJhY2tncm91bmRDb2xvclxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVCYWNrZ3JvdW5kSGVpZ2h0KCkge1xuICAgICAgICB2YXIgYmFja2dyb3VuZEggPSB0aGlzLl9UZXh0LmZpbmFsSCArIHRoaXMuc3R5bGUucGFkZGluZ1kgKiAyICsgdGhpcy5zdHlsZS5wb2ludGVySGVpZ2h0O1xuICAgICAgICB2YXIgYmFja2dyb3VuZFcgPSB0aGlzLl9UZXh0LmZpbmFsVyArIHRoaXMuc3R5bGUucGFkZGluZ1ggKiAyO1xuICAgICAgICB0aGlzLnBhdGNoKHtcbiAgICAgICAgICAgIHc6IGJhY2tncm91bmRXLFxuICAgICAgICAgICAgaDogYmFja2dyb3VuZEgsXG4gICAgICAgICAgICBtb3VudFk6IDEsXG4gICAgICAgICAgICB5OiAtdGhpcy5zdHlsZS5tYXJnaW5Cb3R0b20sXG4gICAgICAgICAgICBCYWNrZ3JvdW5kOiB7XG4gICAgICAgICAgICAgICAgdzogYmFja2dyb3VuZFcsXG4gICAgICAgICAgICAgICAgaDogYmFja2dyb3VuZEgsXG4gICAgICAgICAgICAgICAgdGV4dHVyZToge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiBCdWJibGUsXG4gICAgICAgICAgICAgICAgICAgIHc6IGJhY2tncm91bmRXLFxuICAgICAgICAgICAgICAgICAgICBoOiBiYWNrZ3JvdW5kSFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgfVxuICAgIF91cGRhdGVUZXh0UG9zaXRpb24oKSB7XG4gICAgICAgIGlmICh0aGlzLl9UZXh0KSB7XG4gICAgICAgICAgICB0aGlzLl9UZXh0LnBhdGNoKHtcbiAgICAgICAgICAgICAgICBtb3VudDogLjUsXG4gICAgICAgICAgICAgICAgeDogdGhpcy5fQmFja2dyb3VuZC53IC8gMixcbiAgICAgICAgICAgICAgICB5OiAodGhpcy5fQmFja2dyb3VuZC5oIC0gdGhpcy5zdHlsZS5wb2ludGVySGVpZ2h0KSAvIDJcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgfVxuICAgIF9jbGVhclRpbWVycygpIHtcbiAgICAgICAgY2xlYXJUaW1lb3V0KHRoaXMuX2hpZGVUaW1lcik7XG4gICAgICAgIGNsZWFyVGltZW91dCh0aGlzLl9zaG93VGltZXIpO1xuICAgIH1cbiAgICBfdHJhbnNpdGlvbkluKCkge1xuICAgICAgICB2YXIgc21vb3RoID0ge1xuICAgICAgICAgICAgc21vb3RoOiB7XG4gICAgICAgICAgICAgICAgYWxwaGE6IFsgMSwgdGhpcy5zdHlsZS50cmFuc2l0aW9uIF0sXG4gICAgICAgICAgICAgICAgc2NhbGU6IFsgMSwgdGhpcy5zdHlsZS50cmFuc2l0aW9uIF1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgICAgaWYgKHRoaXMuZGVsYXlWaXNpYmxlKSB7XG4gICAgICAgICAgICB0aGlzLl9zaG93VGltZXIgPSBzZXRUaW1lb3V0KCgoKSA9PiB7XG4gICAgICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgICAgIHNtb290aDogc21vb3RoXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9KSwgdGhpcy5kZWxheVZpc2libGUpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhpcy5fc2hvd1RpbWVyID0gdW5kZWZpbmVkO1xuICAgICAgICAgICAgdGhpcy5wYXRjaCh7XG4gICAgICAgICAgICAgICAgc21vb3RoOiBzbW9vdGhcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMuX2hpZGVUaW1lciA9IHRoaXMudGltZVZpc2libGUgPyBzZXRUaW1lb3V0KCgoKSA9PiB7XG4gICAgICAgICAgICB0aGlzLl91bmZvY3VzKCk7XG4gICAgICAgIH0pLCB0aGlzLnRpbWVWaXNpYmxlICsgKHRoaXMuZGVsYXlWaXNpYmxlIHx8IDApKSA6IHVuZGVmaW5lZDtcbiAgICB9XG4gICAgX3RyYW5zaXRpb25PdXQoKSB7XG4gICAgICAgIHRoaXMucGF0Y2goe1xuICAgICAgICAgICAgc21vb3RoOiB7XG4gICAgICAgICAgICAgICAgYWxwaGE6IFsgMCwgdGhpcy5zdHlsZS50cmFuc2l0aW9uIF0sXG4gICAgICAgICAgICAgICAgc2NhbGU6IFsgLjUsIHRoaXMuc3R5bGUudHJhbnNpdGlvbiBdXG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH1cbiAgICBfZm9jdXMoKSB7XG4gICAgICAgIHRoaXMuX2NsZWFyVGltZXJzKCk7XG4gICAgICAgIHRoaXMuX3RyYW5zaXRpb25JbigpO1xuICAgIH1cbi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HJhc2VzID0gZmxhdHRlblN0cmluZ3MoQXJyYXkuaXNBcnJheShzZXJpZXMpID8gc2VyaWVzIDogWyBzZXJpZXMgXSk7XG4gICAgdmFyIG5lc3RlZFNlcmllc1Jlc3VsdHMgPSBbXTtcbiAgICB2YXIgdXR0ZXJhbmNlcyA9IFtdO1xuICAgIHZhciBhY3RpdmUgPSB0cnVlO1xuICAgIHZhciBzZXJpZXNDaGFpbiA9IF9hc3luY1RvR2VuZXJhdG9yKChmdW5jdGlvbiooKSB7XG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICB3aGlsZSAoYWN0aXZlICYmIHJlbWFpbmluZ1BocmFzZXMubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgdmFyIHBocmFzZSA9IHlpZWxkIFByb21pc2UucmVzb2x2ZShyZW1haW5pbmdQaHJhc2VzLnNoaWZ0KCkpO1xuICAgICAgICAgICAgICAgIGlmICghYWN0aXZlKSB7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHBocmFzZSA9PT0gXCJzdHJpbmdcIiAmJiBwaHJhc2UuaW5jbHVkZXMoXCJQQVVTRS1cIikpIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIHBhdXNlID0gcGhyYXNlLnNwbGl0KFwiUEFVU0UtXCIpWzFdICogMWUzO1xuICAgICAgICAgICAgICAgICAgICBpZiAoaXNOYU4ocGF1c2UpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBwYXVzZSA9IDA7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgeWllbGQgZGVsYXkocGF1c2UpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHBocmFzZSA9PT0gXCJzdHJpbmdcIiAmJiBwaHJhc2UubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciB0b3RhbFJldHJpZXMgPSAzO1xuICAgICAgICAgICAgICAgICAgICB2YXIgcmV0cmllc0xlZnQgPSB0b3RhbFJldHJpZXM7XG4gICAgICAgICAgICAgICAgICAgIHdoaWxlIChhY3RpdmUgJiYgcmV0cmllc0xlZnQgPiAwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHlpZWxkIHNwZWFrKHBocmFzZSwgdXR0ZXJhbmNlcywgbGFuZyk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0cmllc0xlZnQgPSAwO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlIGluc3RhbmNlb2YgU3BlZWNoU3ludGhlc2lzRXJyb3JFdmVudCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZS5lcnJvciA9PT0gXCJuZXR3b3JrXCIpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHJpZXNMZWZ0LS07XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oXCJTcGVlY2ggc3ludGhlc2lzIG5ldHdvcmsgZXJyb3IuIFJldHJpZXMgbGVmdDogXCIuY29uY2F0KHJldHJpZXNMZWZ0KSk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB5aWVsZCBkZWxheSg1MDAgKiAodG90YWxSZXRyaWVzIC0gcmV0cmllc0xlZnQpKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChlLmVycm9yID09PSBcImNhbmNlbGVkXCIgfHwgZS5lcnJvciA9PT0gXCJpbnRlcnJ1cHRlZFwiKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXRyaWVzTGVmdCA9IDA7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoXCJTcGVlY2hTeW50aGVzaXNFcnJvckV2ZW50OiBcIi5jb25jYXQoZS5lcnJvcikpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhyb3cgZTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBwaHJhc2UgPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICAgICAgICAgICAgICB2YXIgc2VyaWVzUmVzdWx0ID0gc3BlYWtTZXJpZXMocGhyYXNlKCksIGxhbmcsIGZhbHNlKTtcbiAgICAgICAgICAgICAgICAgICAgbmVzdGVkU2VyaWVzUmVzdWx0cy5wdXNoKHNlcmllc1Jlc3VsdCk7XG4gICAgICAgICAgICAgICAgICAgIHlpZWxkIHNlcmllc1Jlc3VsdC5zZXJpZXM7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KHBocmFzZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIF9zZXJpZXNSZXN1bHQgPSBzcGVha1NlcmllcyhwaHJhc2UsIGxhbmcsIGZhbHNlKTtcbiAgICAgICAgICAgICAgICAgICAgbmVzdGVkU2VyaWVzUmVzdWx0cy5wdXNoKF9zZXJpZXNSZXN1bHQpO1xuICAgICAgICAgICAgICAgICAgICB5aWVsZCBfc2VyaWVzUmVzdWx0LnNlcmllcztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gZmluYWxseSB7XG4gICAgICAgICAgICBhY3RpdmUgPSBmYWxzZTtcbiAgICAgICAgfVxuICAgI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AgICBpZiAodGhpcy5fdm9pY2VPdXREaXNhYmxlZCkge1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciB0b1NwZWFrID0gdG9Bbm5vdW5jZTtcbiAgICAgICAgICAgIGlmIChhbm5vdW5jZXJPcHRpb25zLmFiYnJldmlhdGlvbnNDb25maWcuYWJicmV2aWF0aW9uc1BhdHRlcm4pIHtcbiAgICAgICAgICAgICAgICB0b1NwZWFrID0gQXJyYXkuaXNBcnJheSh0b0Fubm91bmNlKSA/IHRvQW5ub3VuY2UubWFwKChwaHJhc2UgPT4gdHJhbnNsYXRlQWJicmV2KHBocmFzZSwgYW5ub3VuY2VyT3B0aW9ucy5hYmJyZXZpYXRpb25zQ29uZmlnKSkpIDogdHJhbnNsYXRlQWJicmV2KHRvQW5ub3VuY2UsIGFubm91bmNlck9wdGlvbnMuYWJicmV2aWF0aW9uc0NvbmZpZyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgc3BlZWNoID0gc3BlYWsodG9TcGVhaywgb3B0aW9ucy5sYW5ndWFnZSk7XG4gICAgICAgICAgICBpZiAoc3BlZWNoICYmIHNwZWVjaC5zZXJpZXMpIHtcbiAgICAgICAgICAgICAgICBzcGVlY2guc2VyaWVzLnRoZW4oKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5zdGFnZS5lbWl0KFwiYW5ub3VuY2VFbmRlZFwiKTtcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgdG9Bbm5vdW5jZVN0ciA9IEFycmF5LmlzQXJyYXkodG9TcGVhaykgPyB0b1NwZWFrLmNvbmNhdCgpLmpvaW4oXCIgXCIpIDogdG9TcGVhaztcbiAgICAgICAgICAgIHZhciB0b0Fubm91bmNlV29yZHMgPSB0b0Fubm91bmNlU3RyLnNwbGl0KFwiIFwiKTtcbiAgICAgICAgICAgIHZhciB0aW1lb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AgfVxuICAgICAgICBfZmlyc3RFbmFibGUoKSB7XG4gICAgICAgICAgICBzdXBlci5fZmlyc3RFbmFibGUgJiYgc3VwZXIuX2ZpcnN0RW5hYmxlKCk7XG4gICAgICAgICAgICB0aGlzLl9mb2N1c0NoYW5nZSgpO1xuICAgICAgICB9XG4gICAgICAgIF9kaXNhYmxlKCkge1xuICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHRoaXMuX2Fubm91bmNlRW5kZWRUaW1lb3V0KTtcbiAgICAgICAgICAgIHRoaXMuc3RhZ2UuZW1pdChcImFubm91bmNlRW5kZWRcIik7XG4gICAgICAgICAgICB0aGlzLnN0YWdlLmVtaXQoXCJhbm5vdW5jZVRpbWVvdXRFbmRlZFwiKTtcbiAgICAgICAgfVxuICAgICAgICBzZXQgYW5ub3VuY2VyRW5hYmxlZCh2YWwpIHtcbiAgICAgICAgICAgIHRoaXMuX2Fubm91bmNlckVuYWJsZWQgPSB2YWw7XG4gICAgICAgICAgICB0aGlzLl9mb2N1c0NoYW5nZSgpO1xuICAgICAgICB9XG4gICAgICAgIGdldCBhbm5vdW5jZXJFbmFibGVkKCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuX2Fubm91bmNlckVuYWJsZWQ7XG4gICAgICAgIH1cbiAgICAgICAgX2ZvY3VzQ2hhbmdlKCkge1xuICAgICAgICAgICAgaWYgKCF0aGlzLl9yZXNldEZvY3VzVGltZXIpIHtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9yZXNldEZvY3VzVGltZXIoKTtcbiAgICAgICAgICAgIHRoaXMuJGFubm91bmNlckNhbmNlbCgpO1xuICAgICAgICAgICAgdGhpcy5fZGVib3VuY2VBbm5vdW5jZUZvY3VzQ2hhbmdlcygpO1xuICAgICAgICB9XG4gICAgICAgIF9hbm5vdW5jZUZvY3VzQ2hhbmdlcygpIHtcbiAgICAgICAgICAgIHZhciBmb2N1c1BhdGggPSB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CJcIiBdKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgICAgIH0pLCBbXSk7XG4gICAgICAgICAgICBmb2N1c0RpZmYucmV2ZXJzZSgpLnJlZHVjZSgoKGFjYywgZWxtKSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKGVsbS5hbm5vdW5jZUNvbnRleHQpIHtcbiAgICAgICAgICAgICAgICAgICAgYWNjLnB1c2goWyBlbG1OYW1lKGVsbSksIFwiQ29udGV4dFwiLCBlbG0uYW5ub3VuY2VDb250ZXh0IF0pO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIGFjYy5wdXNoKFsgZWxtTmFtZShlbG0pLCBcIk5vIENvbnRleHRcIiwgXCJcIiBdKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuIGFjYztcbiAgICAgICAgICAgIH0pLCB0b0Fubm91bmNlKTtcbiAgICAgICAgICAgIGlmICh0aGlzLmRlYnVnKSB7XG4gICAgICAgICAgICAgICAgY29uc29sZS50YWJsZSh0b0Fubm91bmNlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRvQW5ub3VuY2UgPSB0b0Fubm91bmNlLnJlZHVjZSgoKGFjYywgYSkgPT4ge1xuICAgICAgICAgICAgICAgIHZhciB0eHQgPSBhWzJdO1xuICAgICAgICAgICAgICAgIHR4dCAmJiBhY2MucHVzaCh0eHQpO1xuICAgICAgICAgICAgICAgIHJldHVybiBhY2M7XG4gICAgICAgICAgICB9KSwgW10pO1xuICAgICAgICAgICAgaWYgKHRvQW5ub3VuY2UubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgdGhpcy4kYW5ub3VuY2VyQ2FuY2VsKCk7XG4gICAgICAgICAgICAgICAgdGhpcy5fY3VycmVudGx5U3BlYWtpbmcgPSB0aGlzLl92b2ljZU91dCh0b0Fubm91bmNlLnJlZHVjZSgoKGFjYywgdmFsKSA9PiBhY2MuY29uY2F0KHZhbCkpLCBbXSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgICRhbm5vdW5jZSh0b0Fubm91bmNlKSB7XG4gICAgICAgICAgICB2YXIge2FwcGVuZDogYXBwZW5kID0gZmFsc2UsIG5vdGlmaWNhdGlvbjogbm90aWZpY2F0aW9uID0gZmFsc2V9ID0gYXJndW1lbnRzLmxlbmd0aCA+IDEgJiYgYXJndW1lbnRzWzFdICE9PSB1bmRlZmluZWQgPyBhcmd1bWVudHNbMV0gOiB7fTtcbiAgICAgICAgICAgIGlmICghdG9Bbm5vdW5jZSB8fCAhdG9Bbm5vdW5jZS50cmltKCkubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRoaXMuYW5ub3VuY2VyRW5hYmxlZCkge1xuICAgICAgICAgICAgICAgIHRoaXMuX2RlYm91bmNlQW5ub3VuY2VGb2N1c0NoYW5nZXMuZmx1c2goKTtcbiAgICAgICAgICAgICAgICBpZiAoYXBwZW5kICYmIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nICYmIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nLmFjdGl2ZSkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLl9jdXJyZW50bHlTcGVha2luZy5hcHBlbmQodG9Bbm5vdW5jZSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy4kYW5ub3VuY2VyQ2FuY2VsKCk7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nID0gdGhpcy5fdm9pY2VPdXQodG9Bbm5vdW5jZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChub3RpZmljYXRpb24pIHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5fdm9pY2VPdXREaXNhYmxlZCA9IHRydWU7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nLnNlcmllcy5maW5hbGx5KCgoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLl92b2ljZU91dERpc2FibGVkID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLiRhbm5vdW5jZXJSZWZyZXNoKCk7XG4gICAgICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgJGFubm91bmNlckNhbmNlbCgpIHtcbiAgICAgICAgICAgIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nICYmIHRoaXMuX2N1cnJlbnRseVNwZWFraW5nLmNhbmNlbCgpO1xuICAgICAgICB9XG4gICAgICAgICRhbm5vdW5jZXJSZWZyZXNoKGRlcHRoKSB7XG4gICAgICAgICAgICBpZiAoZGVwdGgpIHtcbiAgICAgICAgICAgICAgICB0aGlzLl9sYXN0Rm9jdXNQYXRoID0gdGhpcy5fbGFzdEZvY3VzUGF0aC5zbGljZSgwLCBkZXB0aCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRoaXMuX2xhc3RGb2N1c1BhdGggPSB1bmRlZmluZWQ7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB0aGlzLl9yZXNldEZvY3VzVGltZXIoKTtcbiAgICAgICAgICAgIHRoaXMuX2ZvY3VzQ2hhbmdlKCk7XG4gICAgICAgIH1cbiAgICB9O1xufVxuXG5mdW5jdGlvbiBpbmRleCQxKGNsYXNzSW1wKSB7XG4gICAgdmFyIGNhY2hlID0gbmV3IE1hcDtcbiAgICByZXR1cm4gYmFzZSA9PiB7XG4gICAgICAgIGlmIChjYWNoZS5oYXMoYmFzZSkpIHtcbiAgICAgICAgICAgIHJldHVybiBjYWNoZS5nZXQoYmFzZSk7XG4gICAgICAgIH1cb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ByZXR1cm4gY2xhc3MgZXh0ZW5kcyBCYXNlIHtcbiAgICAgICAgX2luaXQoKSB7XG4gICAgICAgICAgICBzdXBlci5faW5pdCgpO1xuICAgICAgICAgICAgdGhpcy5pc0VkaXRpbmcgPSBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgICB0b2dnbGVFZGl0KCkge1xuICAgICAgICAgICAgdGhpcy5pc0VkaXRpbmcgPSAhdGhpcy5pc0VkaXRpbmc7XG4gICAgICAgIH1cbiAgICAgICAgX3N3YXBJdGVtQXJyYXlQb3MoYXJyYXksIGN1cnJlbnQsIHByZXZpb3VzKSB7XG4gICAgICAgICAgICBbYXJyYXlbY3VycmVudF0sIGFycmF5W3ByZXZpb3VzXV0gPSBbIGFycmF5W3ByZXZpb3VzXSwgYXJyYXlbY3VycmVudF0gXTtcbiAgICAgICAgICAgIHN1cGVyLnNlbGVjdGVkSW5kZXggPSBjdXJyZW50O1xuICAgICAgICB9XG4gICAgICAgIF91bmZvY3VzKCkge1xuICAgICAgICAgICAgdGhpcy5pc0VkaXRpbmcgPSBmYWxzZTtcbiAgICAgICAgICAgIHN1cGVyLl91bmZvY3VzKCk7XG4gICAgICAgIH1cbiAgICAgICAgZ2V0IHNlbGVjdGVkSW5kZXgoKSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fc2VsZWN0ZWRJbmRleDtcbiAgICAgICAgfVxuICAgICAgICBzZXQgc2VsZWN0ZWRJbmRleChpbmRleCkge1xuICAgICAgICAgICAgdmFyIF90aGlzMTAgPSB0aGlzO1xuICAgICAgICAgICAgaWYgKCF0aGlzLmlzRWRpdGluZykge1xuICAgICAgICAgICAgICAgIHN1cGVyLnNlbGVjdGVkSW5kZXggPSBpbmRleDtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAodGhpcy5zZWxlY3RlZEluZGV4ID49IHRoaXMuaXRlbXMubGVuZ3RoIC0gMSAmJiBpbmRleCA+IHRoaXM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bGQgY3VycmVudEl0ZW0uc2V0U21vb3RoKFwieFwiLCBuZXdQb3NYKTtcbiAgICAgICAgICAgICAgICB5aWVsZCBjdXJyZW50SXRlbS5zZXRTbW9vdGgoXCJ5XCIsIG5ld1Bvc1kpO1xuICAgICAgICAgICAgICAgIHlpZWxkIG5leHRJdGVtLnNldFNtb290aChcInhcIiwgb2xkUG9zWCk7XG4gICAgICAgICAgICAgICAgeWllbGQgbmV4dEl0ZW0uc2V0U21vb3RoKFwieVwiLCBvbGRQb3NZKTtcbiAgICAgICAgICAgICAgICBpZiAoIV90aGlzMTAuSXRlbXMuY2hpbGRyZW4ubGVuZ3RoIHx8ICFfdGhpczEwLkl0ZW1zLmNoaWxkcmVuW2luZGV4XSB8fCAhX3RoaXMxMC5JdGVtcy5jaGlsZHJlbltpbmRleF0uc2tpcEZvY3VzKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChfdGhpczEwLnNlbGVjdGVkKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpczEwLl9zZWxlY3RlZEluZGV4ID0gaW5kZXg7XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpczEwLl9yZW5kZXIoX3RoaXMxMC5zZWxlY3RlZCwgX3RoaXMxMC5wcmV2U2VsZWN0ZWQpO1xuICAgICAgICAgICAgICAgICAgICAgICAgX3RoaXMxMC5zaWduYWwoXCJzZWxlY3RlZENoYW5nZVwiLCBfdGhpczEwLnNlbGVjdGVkLCBfdGhpczEwLnByZXZTZWxlY3RlZCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgX3RoaXMxMC5fcmVmb2N1cygpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pKSgpO1xuICAgICAgICB9XG4gICAgfTtcbn1cblxudmFyIHJhZCA9IGRlZyA9PiBkZWcgKiBNYXRoLlBJIC8gMTgwO1xuXG52YXIgZGVnID0gcmFkID0+IHJhZCAqIDE4MCAvIE1hdGguUEk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d2lkdGggLyAyIC0gYTtcbiAgICAgICAgYnJlYWs7XG4gICAgfVxuICAgIGlmICh4MCA9PSAwKSB7XG4gICAgICAgIHgxID0gd2lkdGg7XG4gICAgICAgIHkxID0gaGVpZ2h0IC0geTA7XG4gICAgfVxuICAgIGlmICh5MCA9PSAwKSB7XG4gICAgICAgIHkxID0gaGVpZ2h0O1xuICAgICAgICB4MSA9IHdpZHRoIC0geDA7XG4gICAgfVxuICAgIGlmICh4MCA9PSB3aWR0aCkge1xuICAgICAgICB4MSA9IDA7XG4gICAgICAgIHkxID0gaGVpZ2h0IC0geTA7XG4gICAgfVxuICAgIGlmICh5MCA9PSBoZWlnaHQpIHtcbiAgICAgICAgeTEgPSAwO1xuICAgICAgICB4MSA9IHdpZHRoIC0geDA7XG4gICAgfVxuICAgIHJldHVybiB7XG4gICAgICAgIHgwOiB4MCxcbiAgICAgICAgeTA6IHkwLFxuICAgICAgICB4MTogeDEsXG4gICAgICAgIHkxOiB5MVxuICAgIH07XG59O1xuXG5jbGFzcyBMaW5lYXJHcmFkaWVudCBleHRlbmRzIGxuZy5UZXh0dXJlIHtcbiAgICBjb25zdHJ1Y3RvcihzdGFnZSkge1xuICAgICAgICBzdXBlcihzdGFnZSk7XG4gICAgICAgIHRoaXMuX3cgPSAwO1xuICAgICAgICB0aGlzLl9oID0gMDtcbiAgICAgICAgdGhpcy5fc3RlcHMgPSBbXTtcbiAgICAgICAgdGhpcy5fZGVncmVlcyA9IDA7XG4gICAgfVxuICAgIGdldCB3KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdztcbiAgICB9XG4gICAgc2V0IHcodykge1xuICAgICAgICB0aGlzLl93ID0gdztcbiAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgIH1cbiAgICBnZXQgaCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2g7XG4gICAgfVxuICAgIHNldCBoKGgpIHtcbiAgICAgICAgdGhpcy5faCA9IGg7XG4gICAgICAgIHRoaXMuX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yB3LCB5ICsgc3Ryb2tlUmFkaXVzWzFdLCBzdHJva2VSYWRpdXNbMV0pO1xuICAgICAgICAgICAgICAgIGN0eC5saW5lVG8oeCArIHcsIHkgKyBoIC0gc3Ryb2tlUmFkaXVzWzJdKTtcbiAgICAgICAgICAgICAgICBjdHguYXJjVG8oeCArIHcsIHkgKyBoLCB4ICsgdyAtIHN0cm9rZVJhZGl1c1syXSwgeSArIGgsIHN0cm9rZVJhZGl1c1syXSk7XG4gICAgICAgICAgICAgICAgY3R4LmxpbmVUbyh4ICsgc3Ryb2tlUmFkaXVzWzNdLCB5ICsgaCk7XG4gICAgICAgICAgICAgICAgY3R4LmFyY1RvKHgsIHkgKyBoLCB4LCB5ICsgaCAtIHN0cm9rZVJhZGl1c1szXSwgc3Ryb2tlUmFkaXVzWzNdKTtcbiAgICAgICAgICAgICAgICBjdHgubGluZVRvKHgsIHkgKyBzdHJva2VSYWRpdXNbMF0pO1xuICAgICAgICAgICAgICAgIGN0eC5hcmNUbyh4LCB5LCB4ICsgc3Ryb2tlUmFkaXVzWzBdLCB5LCBzdHJva2VSYWRpdXNbMF0pO1xuICAgICAgICAgICAgICAgIGN0eC5jbG9zZVBhdGgoKTtcbiAgICAgICAgICAgICAgICBjdHgubGluZVdpZHRoID0gc3Ryb2tlV2lkdGg7XG4gICAgICAgICAgICAgICAgY3R4LnN0cm9rZVN0eWxlID0gZ3JhZGllbnQ7XG4gICAgICAgICAgICAgICAgY3R4LnN0cm9rZSgpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjdHguZmlsbFN0eWxlID0gZ3JhZGllbnQ7XG4gICAgICAgICAgICAgICAgY3R4LmZpbGxSZWN0KDAsIDAsIHcsIGgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2IobnVsbCwge1xuICAgICAgICAgICAgICAgIHNvdXJjZTogY2FudmFzLFxuICAgICAgICAgICAgICAgIHc6IHcsXG4gICAgICAgICAgICAgICAgaDogaFxu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JtLmdldERyYXdpbmdDYW52YXMoKTtcbiAgICAgICAgdmFyIGRpbWVuc2lvbiA9IHJhZGl1cztcbiAgICAgICAgaWYgKHN0cm9rZSkge1xuICAgICAgICAgICAgZGltZW5zaW9uID0gcmFkaXVzICsgc3Ryb2tlV2lkdGggKiAyO1xuICAgICAgICB9XG4gICAgICAgIGNhbnZhcy53aWR0aCA9IGRpbWVuc2lvbiAqIDI7XG4gICAgICAgIGNhbnZhcy5oZWlnaHQgPSBkaW1lbnNpb24gKiAyO1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24oY2IpIHtcbiAgICAgICAgICAgIHZhciBjdHggPSBjYW52YXMuZ2V0Q29udGV4dChcIjJkXCIpO1xuICAgICAgICAgICAgY3R4LmxpbmVXaWR0aCA9IHN0cm9rZVdpZHRoO1xuICAgICAgICAgICAgY3R4LnN0cm9rZVN0eWxlID0gc3Ryb2tlQ29sb3I7XG4gICAgICAgICAgICBjdHguZmlsbFN0eWxlID0gY29sb3I7XG4gICAgICAgICAgICBjdHguYmVnaW5QYXRoKCk7XG4gICAgICAgICAgICBjdHguYXJjKGRpbWVuc2lvbiwgZGltZW5zaW9uLCByYWRpdXMsIDAsIDIgKiBNYXRoLlBJKTtcbiAgICAgICAgICAgIGlmIChmaWxsKSB7XG4gICAgICAgICAgICAgICAgY3R4LmZpbGwoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChzdHJva2UpIHtcbiAgICAgICAgICAgICAgICBjdHguc3Ryb2tlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjYihudWxsLCB7XG4gICAgICAgICAgICAgICAgc291cmNlOiBjYW52YXMsXG4gICAgICAgICAgICAgICAgcmFkaXVzOiByYWRpdXNcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9O1xuICAgIH1cbn1cblxuY2xhc3MgQXJyb3cgZXh0ZW5kcyBsbmcuVGV4dHVyZSB7XG4gICAgY29uc3RydWN0b3Ioc3RhZ2UpIHtcbiA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AgX2dldFNvdXJjZUxvYWRlcigpIHtcbiAgICAgICAgdmFyIGNvbG9yID0gdGhpcy5fY29sb3I7XG4gICAgICAgIHZhciB3ID0gdGhpcy5fdztcbiAgICAgICAgdmFyIGggPSB0aGlzLl9oO1xuICAgICAgICB2YXIgZGlyZWN0aW9uID0gdGhpcy5fZGlyZWN0aW9uO1xuICAgICAgICB2YXIgY2FudmFzID0gdGhpcy5zdGFnZS5wbGF0Zm9ybS5nZXREcmF3aW5nQ2FudmFzKCk7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbihjYikge1xuICAgICAgICAgICAgdmFyIGN0eCA9IGNhbnZhcy5nZXRDb250ZXh0KFwiMmRcIik7XG4gICAgICAgICAgICBjYW52YXMud2lkdGggPSB3O1xuICAgICAgICAgICAgY2FudmFzLmhlaWdodCA9IGg7XG4gICAgICAgICAgICBjdHguZmlsbFN0eWxlID0gY29sb3I7XG4gICAgICAgICAgICBjdHguc3Ryb2tlU3R5bGUgPSBjdHguZmlsbFN0eWxlO1xuICAgICAgICAgICAgY3R4LmxpbmVXaWR0aCA9IDI7XG4gICAgICAgICAgICBjdHgubGluZUNhcCA9IFwicm91bmRcIjtcbiAgICAgICAgICAgIGN0eC5saW5lSm9pbiA9IFwicm91bmRcIjtcbiAgICAgICAgICAgIHZhciBwID0gY3R4LmxpbmVXaWR0aCAvIDI7XG4gICAgICAgICAgICBjdHguYmVnaW5QYXRoKCk7XG4gICAgICAgICAgICBpZiAoZGlyZWN0aW9uID09PSBcInJpZ2h0XCIpIHtcbiAgICAgICAgICAgICAgICBjdHgubW92ZVRvKHAsIHApO1xuICAgICAgICAgICAgICAgIGN0eC5saW5lVG8ocCwgaCAtIHApO1xuICAgICAgICAgICAgICAgIGN0eC5saW5lVG8odyAtIHAsIGggLyAyKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoZGlyZWN0aW9uID09PSBcImRvd25cIikge1xuICAgICAgICAgICAgICAgIGN0eC5tb3ZlVG8ocCwgcCk7XG4gICAgICAgICAgICAgICAgY3R4LmxpbmVUbyh3IC0gcCwgcCk7XG4gICAgICAgICAgICAgICAgY3R4LmxpbmVUbyh3IC8gMiwgaCAtIHApO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBjdHgubW92ZVRvKHAsIGggLyAyKTtcbiAgICAgICAgICAgICAgICBjdHgubGluZVRvKHcgLSBwLCBwKTtcbiAgICAgICAgICAgICAgICBjdHgubGluZVRvKHcgLSBwLCBoIC0gcCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjdHguY2xvc2VQYXRoKCk7XG4gICAgICAgICAgICBjdHguc3Ryb2tlKCk7XG4gICAgICAgICAgICBjdHguZmlsbCgpO1xuICAgICAgICAgICAgY2IobnVsbCwge1xuICAgICAgICAgICAgICAgIHNvdXJjZTogY2FudmFzLFxuICAgICAgICAgICAgICAgIHc6IHcsXG4gICAgICAgICAgICAgICAgaDogaCxcbiAgICAgICAgICAgICAgICBkaXJlY3Rpb246IGRpcmVjdGlvblxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBMaW5lIGV4dGVuZHMgbG5nLlRleHR1cmUge1xuICAgIGNvbnN0cnVjdG9yKHN0YWdlKSB7XG4gICAgICAgIHN1cGVyKHN0YWdlKTtcbiAgICAgICAgdGhpcy5fdyA9IDA7XG4gICAgICAgIHRoaXMuX2ggPSAwO1xuICAgICAgICB0aGlzLl9yb3VuZGVkID0gZmFsc2U7XG4gICAgfVxuICAgIGdldCB3KCkge1xuICAgICAgICByZXR1cm4gdGhpcy5fdztcbiAgICB9XG4gICAgc2V0IHcobCkge1xuICAgICAgICB0aGlzLl93ID0gbDtcbiAgICAgICAgdGhpcy5fY2hhbmdlZCgpO1xuICAgIH1cbiAgICBnZXQgaCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX2g7XG4gICAgfVxuICAgIHNldCBoKGwpIHtcbiAgICAgICAgdGhpcy5faCA9IGw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0KHRoaXMuX3RpbWVvdXQpXG5cbiAgICAgIGlmICh2KSB7XG4gICAgICAgIHRoaXMuc2V0U21vb3RoKCdhbHBoYScsIDEpXG4gICAgICB9IGVsc2Uge1xuICAgICAgICB0aGlzLnNldFNtb290aCgnYWxwaGEnLCAwLjUpXG4gICAgICB9XG5cbiAgICAgIHRoaXMudGFnKCdOcicpLnBhdGNoKHtcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIHRleHQ6ICh2ICYmIHYudG9TdHJpbmcoKSkgfHwgJycsXG4gICAgICAgICAgZm9udFNpemU6IHYgPT09ICcqJyA/IDEyMCA6IDgwLFxuICAgICAgICB9LFxuICAgICAgfSlcblxuICAgICAgaWYgKHYgJiYgdiAhPT0gJyonKSB7XG4gICAgICAgIHRoaXMuX3RpbWVvdXQgPSBzZXRUaW1lb3V0KCgpID0+IHtcbiAgICAgICAgICB0aGlzLl90aW1lb3V0ID0gbnVsbFxuICAgICAgICAgIHRoaXMubnIgPSAnKidcbiAgICAgICAgfSwgNzUwKVxuICAgICAgfVxuICAgIH1cbiAgfVxuXG59XG5cbmV4cG9ydCBkZWZhdWx0ICgpID0+IHtcbiAgcmV0dXJuIGNsYXNzIFBpbkRpYWxvZyBleHRlbmRzIExpZ2h0bmluZy5Db21wb25lbnQge1xuICAgIHN0YXRpYyBfdGVtcGxhdGUoKSB7XG4gICAgICByZXR1cm4ge1xuICAgICAgICB6SW5kZXg6IDEsXG4gICAgICAgIHc6IHcgPT4gdyxcbiAgICAgICAgaDogaCA9PiBoLFxuICAgICAgICByZWN0OiB0cnVlLFxuICAgICAgICBjb2xvcjogMHhkZDAwMDAwMCxcbiAgICAgICAgYWxwaGE6IDAuMDAwMDAxLFxuICAgICAgICBEaWFsb2c6IHtcbiAgICAgICAgICB3OiA2NDgsXG4gICAgICAgICAgaDogMzIwLFxuICAgICAgICAgIHk6IGggPT4gKGggLSAzMjApIC8gMixcbiAgICAgICAgICB4OiB3ID0+ICh3IC0gNjQ4KSAvIDIsXG4gICAgICAgICAgcmVjdDogdHJ1ZSxcbiAgICAgICAgICBjb2xvcjogMHhkZDMzMzMzMyxcbiAgICAgICAgICBzaGFkZXI6IHsgdHlwZTogTGlnaHRuaW5nLnNoYWRlcnMuUm91bmRlZFJlY3RhbmdsZSwgcmFkaXVzOiAxMCB9LFxuICAgICAgICAgIEluZm86IHtcbiAgICAgICAgICAgIHk6IDI0LFxuICAgICAgICAgICAgeDogNDgsXG4gICAgICAgICAgICB0ZXh0OiB7IHRleHQ6ICdQbGVhc2UgZW50ZXIgeW91ciBQSU4nLCBmb250U2l6ZTogMzIgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIE1zZzoge1xuICAgICAgICAgICAgeTogMjYwLFxuICAgICAgICAgICAgeDogNDgsXG4gICAgICAgICAgICB0ZXh0OiB7IHRleHQ6ICcnLCBmb250U2l6ZTogMjgsIHRleHRDb2xvcjogMHhmZmZmZmZmZiB9LFxuICAgICAgICAgIH0sXG4gICAgICAgICAgQ29kZToge1xuICAgICAgICAgICAgeDogNDgsXG4gICAgICAgICAgICB5OiA5NixcbiAgICAgICAgICB9LFxuICAgICAgICB9LFxuICAgICAgfVxuICAgIH1cblxuICAgIF9pbml0KCkge1xuICAgICAgY29uc3QgY2hpbGRyZW4gPSBbXVxuICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCA0OyBpKyspIHtcbiAgICAgICAgY2hpbGRyZW4ucHVzaCh7XG4gICAgICAgICAgdHlwZTogUGluSW5wdXQoKSxcbiAgICAgICAgICBpbmRleDogaSxcbiAgICAgICAgfSlcbiAgICAgIH1cblxuICAgICAgdGhpcy50YWcoJ0NvZGUnKS5jaGlsZHJlbiA9IGNoaWxkcmVuXG4gICAgfVxuXG4gICAgZ2V0IHBpbigpIHtcbiAgICAgIGlmICghdGhpcy5fcGluKSB0aGlzLl9waW4gPSAnJ1xuICAgICAgcmV0dXJuIHRoaXMuX3BpblxuICAgIH1cblxuICAgIHNldCBwaW4odikge1xuICAgICAgaW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cbiAgICAgIH1cbiAgICAgIHRoaXMuX3RpbWVvdXQgPSBzZXRUaW1lb3V0KCgpID0+IHtcbiAgICAgICAgdGhpcy5tc2cgPSAnJ1xuICAgICAgfSwgMjAwMClcbiAgICB9XG5cbiAgICBfZmlyc3RBY3RpdmUoKSB7XG4gICAgICB0aGlzLnNldFNtb290aCgnYWxwaGEnLCAxKVxuICAgIH1cblxuICAgIF9oYW5kbGVLZXkoZXZlbnQpIHtcbiAgICAgIGlmICh0aGlzLm1zZykge1xuICAgICAgICB0aGlzLm1zZyA9IGZhbHNlXG4gICAgICB9IGVsc2Uge1xuICAgICAgICBjb25zdCB2YWwgPSBwYXJzZUludChldmVudC5rZXkpXG4gICAgICAgIGlmICh2YWwgPiAtMSkge1xuICAgICAgICAgIHRoaXMucGluICs9IHZhbFxuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuXG4gICAgX2hhbmRsZUJhY2soKSB7XG4gICAgICBpZiAodGhpcy5tc2cpIHtcbiAgICAgICAgdGhpcy5tc2cgPSBmYWxzZVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKHRoaXMucGluLmxlbmd0aCkge1xuICAgICAgICAgIHRoaXMucGluID0gdGhpcy5waW4uc2xpY2UoMCwgdGhpcy5waW4ubGVuZ3RoIC0gMSlcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICBQaW4uaGlkZSgpXG4gICAgICAgICAgdGhpcy5yZXNvbHZlKGZhbHNlKVxuICAgICAgICB9XG4gICAgICB9XG4gICAgfVxuXG4gICAgX2hhbmRsZUVudGVyKCkge1xuICAgICAgaWYgKHRoaXMubXNnKSB7XG4gICAgICAgIHRoaXMubXNnID0gZmFsc2VcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIFBpbi5zdWJtaXQodGhpcy5waW4pXG4gICAgICAgICAgLnRoZW4odmFsID0+IHtcbiAgICAgICAgICAgIHRoaXMubXNnID0gJ1VubG9ja2luZyAuLi4nXG4gICAgICAgICAgICBzZXR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ICAgIEFwcGxpY2F0aW9uSW5zdGFuY2UuZm9jdXMgPSBudWxsXG4gICAgQXBwbGljYXRpb25JbnN0YW5jZS5jaGlsZHJlbiA9IEFwcGxpY2F0aW9uSW5zdGFuY2UuY2hpbGRyZW4ubWFwKGNoaWxkID0+IGNoaWxkICE9PSBwaW5EaWFsb2cgJiYgY2hpbGQpXG4gICAgcGluRGlhbG9nID0gbnVsbFxuICB9LFxuICBzdWJtaXQocGluLCBjb250ZXh0KSB7XG4gICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgIHRyeSB7XG4gICAgICAgIGNvbnRleHQgPSBjb250ZXh0Q2hlY2soY29udGV4dClcbiAgICAgICAgaWYgKGNvbnRleHQpIHtcbiAgICAgICAgICBzdWJtaXQocGluLCBjb250ZXh0KVxuICAgICAgICAgICAgLnRoZW4ocmVzb2x2ZSlcbiAgICAgICAgICAgIC5jYXRjaChyZWplY3QpXG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgcmVqZWN0KCdJbmNvcnJlY3QgQ29udGV4dCBwcm92aWRlZCcpXG4gICAgICAgIH1cbiAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgcmVqZWN0KGUpXG4gICAgICB9XG4gICAgfSlcbiAgfSxcbiAgdW5sb2NrZWQoY29udGV4dCkge1xuICAgIHJldHVybiBuZXcgUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICB0cnkge1xuICAgICAgICBjb250ZXh0ID0gY29udGV4dENoZWNrKGNvbnRleHQpXG4gICAgICAgIGlmIChjb250ZXh0KSB7XG4gICAgICAgICAgY2hlY2soY29udGV4dClcbiAgICAgICAgICAgIC50aGVuKHJlc29sdmUpXG4gICAgICAgICAgICAuY2F0Y2gocmVqZWN0KVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHJlamVjdCgnSW5jb3JyZWN0IENvbnRleHQgcHJvdmlkZWQnKVxuICAgICAgICB9XG4gICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgIHJlamVjdChlKVxuICAgICAgfVxuICAgIH0pXG4gIH0sXG4gIGxvY2tlZChjb250ZXh0KSB7XG4gICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgIHRyeSB7XG4gICAgICAgIGNvbnRleHQgPSBjb250ZXh0Q2hlY2soY29udGV4dClcbiAgICAgICAgaWYgKGNvbnRleHQpIHtcbiAgICAgICAgICBjaGVjayhjb250ZXh0KVxuICAgICAgICAgICAgLnRoZW4odW5sb2NrZWQgPT4gcmVzb2x2ZSghISF1bmxvY2tlZCkpXG4gICAgICAgICAgICAuY2F0Y2gocmVqZWN0KVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHJlamVjdCgnSW5jb3JyZWN0IENvbnRleHQgcHJvdmlkZWQnKVxuICAgICAgICB9XG4gICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgIHJlamVjdChlKVxuICAgICAgfVxuICAgIH0pXG4gIH0sXG59XG4iLCIvKlxuICogSWYgbm90IHN0YXRlZCBvdGhlcndpc2UgaW4gdGhpcyBmaWxlIG9yIHRoaXMgY29tcG9uZW50J3MgTElDRU5TRSBmaWxlIHRoZVxuICogZm9sbG93aW5nIGNvcHlyaWdodCBhbmQgbGljZW5zZXMgYXBwbHk6XG4gKlxuICogQ29weXJpZ2h0IDIwMjAgTWV0cm9sb2dpY2FsXG4gKlxuICogTGljZW5zZWQgdW5kZXIgdGhlIEFwYWNoZSBMaWNlbnNlLCBWZXJzaW9uIDIuMCAodGhlIExpY2Vuc2UpO1xuICogeW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLlxuICogWW91IG1heSBvYnRhaW4gYSBjb3B5IG9mIHRoZSBMaWNlbnNlIGF0XG4gKlxuICogaHR0cDovL3d3dy5hcGFjaGUub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4gICAgICAgICAgICB1aWQsXG4gICAgICAgICAgICB0eXBlLFxuICAgICAgICAgIH0pXG4gICAgICAgICAgICAudGhlbihyZXNvbHZlKVxuICAgICAgICAgICAgLmNhdGNoKHJlamVjdClcbiAgICAgICAgfSlcbiAgICAgICAgLmNhdGNoKHJlamVjdClcbiAgICB9KVxuICB9LFxuICBjb25maXJtKHRyYW5zYWN0aW9uSWQpIHtcbiAgICByZXR1cm4gbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgYmlsbGluZ1JlcXVlc3QoJy9jb25maXJtJywge1xuICAgICAgICB0cmFuc2FjdGlvbklkLFxuICAgICAgfSlcbiAgICAgICAgLnRoZW4ocmVzb2x2ZSlcbiAgICAgICAgLmNhdGNoKHJlamVjdClcbiAgICB9KVxuICB9LFxuICBidXkoYXNzZXRJZCwgdHlwZSkge1xuICAgIHJldHVybiBuZXcgUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICBsZXQgdHJhbnNhY3Rpb25JZFxuICAgICAgc2VxdWVuY2UoW1xuICAgICAgICAoKSA9PiB0aGlzLnNpZ25hdHVyZShhc3NldElkKSxcbiAgICAgICAgc2lnbmF0dXJlID0+IHRoaXMucGF5bWVudChzaWduYXR1cmUsIHR5cGUpLFxuICAgICAgICB0cmFuc2FjdGlvbiA9PiB7XG4gICAgICAgICAgdHJhbnNhY3Rpb25JZCA9IHRyYW5zYWN0aW9uLnRyYW5zYWN0aW9uSWRcbiAgICAgICAgICByZXR1cm4gdGhpcy5zdWJzY3JpYmUoYXNzZXRJZCwgdHJhbnNhY3Rpb24pXG4gICAgICAgIH0sXG4gICAgICAgICgpID0+IHRoaXMuY29uZmlybSh0cmFuc2FjdGlvbklkKSxcbiAgICAgIF0pXG4gICAgICAgIC50aGVuKHJlc29sdmUpXG4gICAgICAgIC5jYXRjaChyZWplY3QpXG4gICAgfSlcbiAgfSxcbn1cbiIsIi8qXG4gKiBJZiBub3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FsIG1vY2sgbWV0aG9kc1xubGV0IG1ldGhvZHMgPSB7XG4gIGdldENoYW5uZWwoKSB7XG4gICAgaWYgKCFjdXJyZW50Q2hhbm5lbCkgY3VycmVudENoYW5uZWwgPSByYW5kb21DaGFubmVsKClcbiAgICByZXR1cm4gbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgaWYgKGN1cnJlbnRDaGFubmVsKSB7XG4gICAgICAgIGNvbnN0IGNoYW5uZWwgPSB7IC4uLmN1cnJlbnRDaGFubmVsIH1cbiAgICAgICAgZGVsZXRlIGNoYW5uZWwucHJvZ3JhbVxuICAgICAgICByZXNvbHZlKGNoYW5uZWwpXG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZWplY3QoJ05vIGNoYW5uZWwgZm91bmQnKVxuICAgICAgfVxuICAgIH0pXG4gIH0sXG4gIGdldFByb2dyYW0oKSB7XG4gICAgaWYgKCFjdXJyZW50Q2hhbm5lbCkgY3VycmVudENoYW5uZWwgPSByYW5kb21DaGFubmVsKClcbiAgICByZXR1cm4gbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgY3VycmVudENoYW5uZWwucHJvZ3JhbSA/IHJlc29sdmUoY3VycmVudENoYW5uZWwucHJvZ3JhbSkgOiByZWplY3QoJ05vIHByb2dyYW0gZm91bmQnKVxuICAgIH0pXG4gIH0sXG4gIHNldENoYW5uZWwobnVtYmVyKSB7XG4gICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgIGlmIChudW1iZXIpIHtcbiAgICAgICAgY29uc3QgbmV3Q2hhbm5lbCA9IGNoYW5uZWxzKCkuZmluZChjID0+IGMubnVtYmVyID09PSBudW1iZXIpXG4gICAgICAgIGlmIChuZXdDaGFubmVsKSB7XG4gICAgICAgICAgY3VycmVudENoYW5uZWwgPSBuZXdDaGFubmVsXG4gICAgICAgICAgY29uc3QgY2hhbm5l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GlzO1xuICAgIGlmICh0eXBlb2YgdGFyZ2V0ICE9PSAnZnVuY3Rpb24nIHx8IHRvU3RyLmFwcGx5KHRhcmdldCkgIT09IGZ1bmNUeXBlKSB7XG4gICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoRVJST1JfTUVTU0FHRSArIHRhcmdldCk7XG4gICAgfVxuICAgIHZhciBhcmdzID0gc2xpY3koYXJndW1lbnRzLCAxKTtcblxuICAgIHZhciBib3VuZDtcbiAgICB2YXIgYmluZGVyID0gZnVuY3Rpb24gKCkge1xuICAgICAgICBpZiAodGhpcyBpbnN0YW5jZW9mIGJvdW5kKSB7XG4gICAgICAgICAgICB2YXIgcmVzdWx0ID0gdGFyZ2V0LmFwcGx5KFxuICAgICAgICAgICAgICAgIHRoaXMsXG4gICAgICAgICAgICAgICAgY29uY2F0dHkoYXJncywgYXJndW1lbnRzKVxuICAgICAgICAgICAgKTtcbiAgICAgICAgICAgIGlmIChPYmplY3QocmVzdWx0KSA9PT0gcmVzdWx0KSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiB0aGlzO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0YXJnZXQuYXBwbHkoXG4gICAgICAgICAgICB0aGF0LFxuICAgICAgICAgICAgY29uY2F0dHkoYXJncywgYXJndW1lbnRzKVxuICAgICAgICApO1xuXG4gICAgfTtcblxuICAgIHZhciBib3VuZExlbmd0aCA9IG1heCgwLCB0YXJnZXQubGVuZ3RoIC0gYXJncy5sZW5ndGgpO1xuICAgIHZhciBib3VuZEFyZ3MgPSBbXTtcbiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGJvdW5kTGVuZ3RoOyBpKyspIHtcbiAgICAgICAgYm91bmRBcmdzW2ldID0gJyQnICsgaTtcbiAgICB9XG5cbiAgICBib3VuZCA9IEZ1bmN0aW9uKCdiaW5kZXInLCAncmV0dXJuIGZ1bmN0aW9u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ICAgIGlmIChpbmRleCArIDEgPT09IG1heCkgcmV0dXJuIHRydWU7XG4gICAgY2ggPSBkYXRhWysraW5kZXhdO1xuXG4gICAgLy8gYmFzZSAyLCBiYXNlIDgsIGJhc2UgMTZcblxuICAgIGlmIChjaCA9PT0gJ2InKSB7XG4gICAgICAvLyBiYXNlIDJcbiAgICAgIGluZGV4Kys7XG5cbiAgICAgIGZvciAoOyBpbmRleCA8IG1heDsgaW5kZXgrKykge1xuICAgICAgICBjaCA9IGRhdGFbaW5kZXhdO1xuICAgICAgICBpZiAoY2ggPT09ICdfJykgY29udGludWU7XG4gICAgICAgIGlmIChjaCAhPT0gJzAnICYmIGNoICE9PSAnMScpIHJldHVybiBmYWxzZTtcbiAgICAgICAgaGFzRGlnaXRzID0gdHJ1ZTtcbiAgICAgIH1cbiAgICAgIHJldHVybiBoYXNEaWdpdHMgJiYgY2ggIT09ICdfJztcbiAgICB9XG5cblxuICAgIGlmIChjaCA9PT0gJ3gnKSB7XG4gICAgICAvLyBiYXNlIDE2XG4gICAgICBpbmRleCsrO1xuXG4gICAgICBmb3IgKDsgaW5kZXggPCBtYXg7IGluZGV4KyspIHtcbiAgICAgICAgY2ggPSBkYXRhW2luZGV4XTtcbiAgICAgICAgaWYgKGNoID09PSAnXycpIGNvbnRpbnVlO1xuICAgICAgICBpZiAoIWlzSGV4Q29kZShkYXRhLmNoYXJDb2RlQXQoaW5kZXgpKSkgcmV0dXJuIGZhbHNlO1xuICAgICAgICBoYXNEaWdpdHMgPSB0cnVlO1xuICAgICAgfVxuICAgICAgcmV0dXJuIGhhc0RpZ2l0cyAmJiBjaCAhPT0gJ18nO1xuICAgIH1cblxuXG4gICAgaWYgKGNoID09PSAnbycpIHtcbiAgICAgIC8vIGJhc2UgOFxuICAgICAgaW5kZXgrKztcblxuICAgICAgZm9yICg7IGluZGV4IDwgbWF4OyBpbmRleCsrKSB7XG4gICAgICAgIGNoID0gZGF0YVtpbmRleF07XG4gICAgICAgIGlmIChjaCA9PT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V1bMC05XSkkJyk7ICAgICAgICAgICAgICAgICAgIC8vIFszXSBkYXlcblxudmFyIFlBTUxfVElNRVNUQU1QX1JFR0VYUCA9IG5ldyBSZWdFeHAoXG4gICdeKFswLTldWzAtOV1bMC05XVswLTldKScgICAgICAgICAgKyAvLyBbMV0geWVhclxuICAnLShbMC05XVswLTldPyknICAgICAgICAgICAgICAgICAgICsgLy8gWzJdIG1vbnRoXG4gICctKFswLTldWzAtOV0/KScgICAgICAgICAgICAgICAgICAgKyAvLyBbM10gZGF5XG4gICcoPzpbVHRdfFsgXFxcXHRdKyknICAgICAgICAgICAgICAgICArIC8vIC4uLlxuICAnKFswLTldWzAtOV0/KScgICAgICAgICAgICAgICAgICAgICsgLy8gWzRdIGhvdXJcbiAgJzooWzAtOV1bMC05XSknICAgICAgICAgICAgICAgICAgICArIC8vIFs1XSBtaW51dGVcbiAgJzooWzAtOV1bMC05XSknICAgICAgICAgICAgICAgICAgICArIC8vIFs2XSBzZWNvbmRcbiAgJyg/OlxcXFwuKFswLTldKikpPycgICAgICAgICAgICAgICAgICsgLy8gWzddIGZyYWN0aW9uXG4gICcoPzpbIFxcXFx0XSooWnwoWy0rXSkoWzAtOV1bMC05XT8pJyArIC8vIFs4XSB0eiBbOV0gdHpfc2lnbiBbMTBdIHR6X2hvdXJcbiAgJyg/OjooWzAtOV1bMC05XSkpPykpPyQnKTsgICAgICAgICAgIC8vIFsxMV0gdHpfbWludXRlXG5cbmZ1bmN0aW9uIHJlc29sdmVZYW1sVGltZXN0YW1wKGRhdGEpIHtcbiAgaWYgKGRhdGEgPT09IG51bGwpIHJldHVybiBmYWxzZTtcbiAgaWYgKFlBTUxfREFURV9SRUdFWFAuZXhlYyhkYXRhKSAhPT0gbnVsbCkgcmV0dXJuIHRydWU7XG4gIGlmIChZQU1MX1RJTUVTVEFNUF9SRUdFWFAuZXhlYyhkYXRhKSAhPT0gbnVsbCkgcmV0dXJuIHRydWU7XG4gIHJldHVybiBmYWxzZTtcbn1cblx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BVFRFUk5fVEFHX0hBTkRMRSAgICAgICAgICAgID0gL14oPzohfCEhfCFbYS16XFwtXSshKSQvaTtcbnZhciBQQVRURVJOX1RBR19VUkkgICAgICAgICAgICAgICA9IC9eKD86IXxbXixcXFtcXF1cXHtcXH1dKSg/OiVbMC05YS1mXXsyfXxbMC05YS16XFwtIztcXC9cXD86QCY9XFwrXFwkLF9cXC4hflxcKidcXChcXClcXFtcXF1dKSokL2k7XG5cblxuZnVuY3Rpb24gX2NsYXNzKG9iaikgeyByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZy5jYWxsKG9iaik7IH1cblxuZnVuY3Rpb24gaXNfRU9MKGMpIHtcbiAgcmV0dXJuIChjID09PSAweDBBLyogTEYgKi8pIHx8IChjID09PSAweDBELyogQ1IgKi8pO1xufVxuXG5mdW5jdGlvbiBpc19XSElURV9TUEFDRShjKSB7XG4gIHJldHVybiAoYyA9PT0gMHgwOS8qIFRhYiAqLykgfHwgKGMgPT09IDB4MjAvKiBTcGFjZSAqLyk7XG59XG5cbmZ1bmN0aW9uIGlzX1dTX09SX0VPTChjKSB7XG4gIHJldHVybiAoYyA9PT0gMHgwOS8qIFRhYiAqLykgfHxcbiAgICAgICAgIChjID09PSAweDIwLyogU3BhY2UgKi8pIHx8XG4gICAgICAgICAoYyA9PT0gMHgwQS8qIExGICovKSB8fFxuICAgICAgICAgKGMgPT09IDB4MEQvKiBDUiAqLyk7XG59XG5cbmZ1bmN0aW9uIGlzX0ZMT1dfSU5ESUNBVE9SKGMpIHtcbiAgcmV0dXJuIGMgPT09IDB4MkMvKiAsICovIHx8XG4gICAgICAgICBjID09PSAweDVCLyogWyAqLyB8fFxuICAgICAgICAgYyA9PT0gMHg1RC8qIF0gKi8gfHxcbiAgICAgICAgIGMgPT09IDB4N0IvKiB7ICovIHx8XG4gICAgICAgICBjID09PSAweDdELyogfSAqLztcbn1cblxuZnVuY3Rpb24gZnJvbUhleENvZGUoYykge1xuICB2YXIgbGM7XG5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T2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eTtcblxudmFyIENIQVJfQk9NICAgICAgICAgICAgICAgICAgPSAweEZFRkY7XG52YXIgQ0hBUl9UQUIgICAgICAgICAgICAgICAgICA9IDB4MDk7IC8qIFRhYiAqL1xudmFyIENIQVJfTElORV9GRUVEICAgICAgICAgICAgPSAweDBBOyAvKiBMRiAqL1xudmFyIENIQVJfQ0FSUklBR0VfUkVUVVJOICAgICAgPSAweDBEOyAvKiBDUiAqL1xudmFyIENIQVJfU1BBQ0UgICAgICAgICAgICAgICAgPSAweDIwOyAvKiBTcGFjZSAqL1xudmFyIENIQVJfRVhDTEFNQVRJT04gICAgICAgICAgPSAweDIxOyAvKiAhICovXG52YXIgQ0hBUl9ET1VCTEVfUVVPVEUgICAgICAgICA9IDB4MjI7IC8qIFwiICovXG52YXIgQ0hBUl9TSEFSUCAgICAgICAgICAgICAgICA9IDB4MjM7IC8qICMgKi9cbnZhciBDSEFSX1BFUkNFTlQgICAgICAgICAgICAgID0gMHgyNTsgLyogJSAqL1xudmFyIENIQVJfQU1QRVJTQU5EICAgICAgICAgICAgPSAweDI2OyAvKiAmICovXG52YXIgQ0hBUl9TSU5HTEVfUVVPVEUgICAgICAgICA9IDB4Mjc7IC8qICcgKi9cbnZhciBDSEFSX0FTVEVSSVNLICAgICAgICAgICAgID0gMHgyQTsgLyogKiAqL1xudmFyIENIQVJfQ09NTUEgICAgICAgICAgICAgICAgPSAweDJDOyAvKiAsICovXG52YXIgQ0hBUl9NSU5VUyAgICAgICAgICAgICAgICA9IDB4MkQ7IC8qIC0gKi9cbnZhciBDSEFSX0NPTE9OICAgICAgICAgICAgICAgID0gMHgzQTsgLyogOiAqL1xudmFyIENIQVJfRVFVQUxTICAgICAgICAgICAgICAgPSAweDNEOyAvKiA9ICovXG52YXIgQ0hBUl9HUkVBVEVSX1RIQU4gICAgICAgICA9IDB4M0U7IC8qID4gKi9cbnZhciBDSEFSX1FVRVNUSU9OICAg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gICAqXG4gICAgICogQHByaXZhdGVcbiAgICAgKiBAcGFyYW0ge09iamVjdH0gcHJvdG8gVGhlIG9iamVjdCB0byBpbmhlcml0IGZyb20uXG4gICAgICogQHJldHVybnMge09iamVjdH0gUmV0dXJucyB0aGUgbmV3IG9iamVjdC5cbiAgICAgKi9cbiAgICB2YXIgYmFzZUNyZWF0ZSA9IChmdW5jdGlvbigpIHtcbiAgICAgIGZ1bmN0aW9uIG9iamVjdCgpIHt9XG4gICAgICByZXR1cm4gZnVuY3Rpb24ocHJvdG8pIHtcbiAgICAgICAgaWYgKCFpc09iamVjdChwcm90bykpIHtcbiAgICAgICAgICByZXR1cm4ge307XG4gICAgICAgIH1cbiAgICAgICAgaWYgKG9iamVjdENyZWF0ZSkge1xuICAgICAgICAgIHJldHVybiBvYmplY3RDcmVhdGUocHJvdG8pO1xuICAgICAgICB9XG4gICAgICAgIG9iamVjdC5wcm90b3R5cGUgPSBwcm90bztcbiAgICAgICAgdmFyIHJlc3VsdCA9IG5ldyBvYmplY3Q7XG4gICAgICAgIG9iamVjdC5wcm90b3R5cGUgPSB1bmRlZmluZWQ7XG4gICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgICB9O1xuICAgIH0oKSk7XG5cbiAgICAvKipcbiAgICAgKiBUaGUgZnVuY3Rpb24gd2hvc2UgcHJvdG90eXBlIGNoYWluIHNlcXVlbmNlIHdyYXBwZXJzIGluaGVyaXQgZnJvbS5cbiAgICAgKlxuICAgICAqIEBwcml2YXRlXG4gICAgICovXG4gICAgZnVuY3Rpb24gYmFzZUxvZGFzaCgpIHtcbiAgICAgIC8vIE5vIG9wZXJhdGlvbiBwZXJmb3JtZWQuXG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogVGhlIGJhc2UgY29uc3RydWN0b3IgZm9yIGNyZWF0aW5nIGBsb2Rhc2hgIHdyYXBwZXIgb2JqZWN0cy5cbiAgICAgKlxuICAgICAqIEBwcml2YXRlXG4gICAgICogQHBhcmFtIHsqfSB2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AgICAgc2tpcCA9IG9iamVjdCA9PSBudWxsO1xuXG4gICAgICB3aGlsZSAoKytpbmRleCA8IGxlbmd0aCkge1xuICAgICAgICByZXN1bHRbaW5kZXhdID0gc2tpcCA/IHVuZGVmaW5lZCA6IGdldChvYmplY3QsIHBhdGhzW2luZGV4XSk7XG4gICAgICB9XG4gICAgICByZXR1cm4gcmVzdWx0O1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFRoZSBiYXNlIGltcGxlbWVudGF0aW9uIG9mIGBfLmNsYW1wYCB3aGljaCBkb2Vzbid0IGNvZXJjZSBhcmd1bWVudHMuXG4gICAgICpcbiAgICAgKiBAcHJpdmF0ZVxuICAgICAqIEBwYXJhbSB7bnVtYmVyfSBudW1iZXIgVGhlIG51bWJlciB0byBjbGFtcC5cbiAgICAgKiBAcGFyYW0ge251bWJlcn0gW2xvd2VyXSBUaGUgbG93ZXIgYm91bmQuXG4gICAgICogQHBhcmFtIHtudW1iZXJ9IHVwcGVyIFRoZSB1cHBlciBib3VuZC5cbiAgICAgKiBAcmV0dXJucyB7bnVtYmVyfSBSZXR1cm5zIHRoZSBjbGFtcGVkIG51bWJlci5cbiAgICAgKi9cbiAgICBmdW5jdGlvbiBiYXNlQ2xhbXAobnVtYmVyLCBsb3dlciwgdXBwZXIpIHtcbiAgICAgIGlmIChudW1iZXIgPT09IG51bWJlcikge1xuICAgICAgICBpZiAodXBwZXIgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgIG51bWJlciA9IG51bWJlciA8PSB1cHBlciA/IG51bWJlciA6IHVwcGVyO1xuICAgICAgICB9XG4gICAgICAgIGlmIChsb3dlciAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgbnVtYmVyID0gbnVtYmVyID49IGxvd2VyID8gbnVtYmVyIDogbG93ZXI7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHJldHVybiBudW1iZXI7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogVGhlIGJhc2UgaW1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YmIChpdGVyYXRlZSB8fCAobGVuZ3RoID49IDEyMCAmJiBhcnJheS5sZW5ndGggPj0gMTIwKSlcbiAgICAgICAgICA/IG5ldyBTZXRDYWNoZShvdGhJbmRleCAmJiBhcnJheSlcbiAgICAgICAgICA6IHVuZGVmaW5lZDtcbiAgICAgIH1cbiAgICAgIGFycmF5ID0gYXJyYXlzWzBdO1xuXG4gICAgICB2YXIgaW5kZXggPSAtMSxcbiAgICAgICAgICBzZWVuID0gY2FjaGVzWzBdO1xuXG4gICAgICBvdXRlcjpcbiAgICAgIHdoaWxlICgrK2luZGV4IDwgbGVuZ3RoICYmIHJlc3VsdC5sZW5ndGggPCBtYXhMZW5ndGgpIHtcbiAgICAgICAgdmFyIHZhbHVlID0gYXJyYXlbaW5kZXhdLFxuICAgICAgICAgICAgY29tcHV0ZWQgPSBpdGVyYXRlZSA/IGl0ZXJhdGVlKHZhbHVlKSA6IHZhbHVlO1xuXG4gICAgICAgIHZhbHVlID0gKGNvbXBhcmF0b3IgfHwgdmFsdWUgIT09IDApID8gdmFsdWUgOiAwO1xuICAgICAgICBpZiAoIShzZWVuXG4gICAgICAgICAgICAgID8gY2FjaGVIYXMoc2VlbiwgY29tcHV0ZWQpXG4gICAgICAgICAgICAgIDogaW5jbHVkZXMocmVzdWx0LCBjb21wdXRlZCwgY29tcGFyYXRvcilcbiAgICAgICAgICAgICkpIHtcbiAgICAgICAgICBvdGhJbmRleCA9IG90aExlbmd0aDtcbiAgICAgICAgICB3aGlsZSAoLS1vdGhJbmRleCkge1xuICAgICAgICAgICAgdmFyIGNhY2hlID0gY2FjaGVzW290aEluZGV4XTtcbiAgICAgICAgICAgIGlmICghKGNhY2hlXG4gICAgICAgICAgICAgICAgICA/IGNhY2hlSGFzKGNhY2hlLCBjb21wdXRlZClcbiAgICAgICAgICAgICAgICAgIDogaW5jbHVkZXMoYXJyYXlzW290aEluZGV4XSwgY29tcHV0ZWQsIGNvbXBhcmF0b3IpKVxuICAgICAgICAgICAgICAg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9ialRhZyA9PSBvYmplY3RUYWcsXG4gICAgICAgICAgb3RoSXNPYmogPSBvdGhUYWcgPT0gb2JqZWN0VGFnLFxuICAgICAgICAgIGlzU2FtZVRhZyA9IG9ialRhZyA9PSBvdGhUYWc7XG5cbiAgICAgIGlmIChpc1NhbWVUYWcgJiYgaXNCdWZmZXIob2JqZWN0KSkge1xuICAgICAgICBpZiAoIWlzQnVmZmVyKG90aGVyKSkge1xuICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgfVxuICAgICAgICBvYmpJc0FyciA9IHRydWU7XG4gICAgICAgIG9iaklzT2JqID0gZmFsc2U7XG4gICAgICB9XG4gICAgICBpZiAoaXNTYW1lVGFnICYmICFvYmpJc09iaikge1xuICAgICAgICBzdGFjayB8fCAoc3RhY2sgPSBuZXcgU3RhY2spO1xuICAgICAgICByZXR1cm4gKG9iaklzQXJyIHx8IGlzVHlwZWRBcnJheShvYmplY3QpKVxuICAgICAgICAgID8gZXF1YWxBcnJheXMob2JqZWN0LCBvdGhlciwgYml0bWFzaywgY3VzdG9taXplciwgZXF1YWxGdW5jLCBzdGFjaylcbiAgICAgICAgICA6IGVxdWFsQnlUYWcob2JqZWN0LCBvdGhlciwgb2JqVGFnLCBiaXRtYXNrLCBjdXN0b21pemVyLCBlcXVhbEZ1bmMsIHN0YWNrKTtcbiAgICAgIH1cbiAgICAgIGlmICghKGJpdG1hc2sgJiBDT01QQVJFX1BBUlRJQUxfRkxBRykpIHtcbiAgICAgICAgdmFyIG9iaklzV3JhcHBlZCA9IG9iaklzT2JqICYmIGhhc093blByb3BlcnR5LmNhbGwob2JqZWN0LCAnX193cmFwcGVkX18nKSxcbiAgICAgICAgICAgIG90aElzV3JhcHBlZCA9IG90aElzT2JqICYmIGhhc093blByb3BlcnR5LmNhbGwob3RoZXIsICdfX3dyYXBwZWRfXycpO1xuXG4gICAgICAgIGlmIChvYmpJc1dyYXBwZWQgfHwgb3RoSXNXcmFwcGVkKSB7XG4gICAgICAgIC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Chub0N1c3RvbWl6ZXIgJiYgZGF0YVsyXSlcbiAgICAgICAgICAgICAgPyBkYXRhWzFdICE9PSBvYmplY3RbZGF0YVswXV1cbiAgICAgICAgICAgICAgOiAhKGRhdGFbMF0gaW4gb2JqZWN0KVxuICAgICAgICAgICAgKSB7XG4gICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICB3aGlsZSAoKytpbmRleCA8IGxlbmd0aCkge1xuICAgICAgICBkYXRhID0gbWF0Y2hEYXRhW2luZGV4XTtcbiAgICAgICAgdmFyIGtleSA9IGRhdGFbMF0sXG4gICAgICAgICAgICBvYmpWYWx1ZSA9IG9iamVjdFtrZXldLFxuICAgICAgICAgICAgc3JjVmFsdWUgPSBkYXRhWzFdO1xuXG4gICAgICAgIGlmIChub0N1c3RvbWl6ZXIgJiYgZGF0YVsyXSkge1xuICAgICAgICAgIGlmIChvYmpWYWx1ZSA9PT0gdW5kZWZpbmVkICYmICEoa2V5IGluIG9iamVjdCkpIHtcbiAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgdmFyIHN0YWNrID0gbmV3IFN0YWNrO1xuICAgICAgICAgIGlmIChjdXN0b21pemVyKSB7XG4gICAgICAgICAgICB2YXIgcmVzdWx0ID0gY3VzdG9taXplcihvYmpWYWx1ZSwgc3JjVmFsdWUsIGtleSwgb2JqZWN0LCBzb3VyY2UsIHN0YWNrKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKCEocmVzdWx0ID09PSB1bmRlZmluZWRcbiAgICAgICAgICAgICAgICA/IGJhc2VJc0VxdWFsKHNyY1ZhbHVlLCBvYmpWYWx1ZSwgQ09NUEFSRV9QQVJUSUFMX0ZMQUcgfCBDT01QQVJFX1VOT1JERVJFRF9GTEFHLCBjdXN0b21pemVyLCBzdGFjaylcbiAgICAgICAgICAgICAgICA6IHJlc3VsdFxuICAgICA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pdmF0ZVxuICAgICAqIEBwYXJhbSB7QXJyYXl9IGFycmF5IFRoZSBhcnJheSB0byBtb2RpZnkuXG4gICAgICogQHBhcmFtIHtudW1iZXJbXX0gaW5kZXhlcyBUaGUgaW5kZXhlcyBvZiBlbGVtZW50cyB0byByZW1vdmUuXG4gICAgICogQHJldHVybnMge0FycmF5fSBSZXR1cm5zIGBhcnJheWAuXG4gICAgICovXG4gICAgZnVuY3Rpb24gYmFzZVB1bGxBdChhcnJheSwgaW5kZXhlcykge1xuICAgICAgdmFyIGxlbmd0aCA9IGFycmF5ID8gaW5kZXhlcy5sZW5ndGggOiAwLFxuICAgICAgICAgIGxhc3RJbmRleCA9IGxlbmd0aCAtIDE7XG5cbiAgICAgIHdoaWxlIChsZW5ndGgtLSkge1xuICAgICAgICB2YXIgaW5kZXggPSBpbmRleGVzW2xlbmd0aF07XG4gICAgICAgIGlmIChsZW5ndGggPT0gbGFzdEluZGV4IHx8IGluZGV4ICE9PSBwcmV2aW91cykge1xuICAgICAgICAgIHZhciBwcmV2aW91cyA9IGluZGV4O1xuICAgICAgICAgIGlmIChpc0luZGV4KGluZGV4KSkge1xuICAgICAgICAgICAgc3BsaWNlLmNhbGwoYXJyYXksIGluZGV4LCAxKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYmFzZVVuc2V0KGFycmF5LCBpbmRleCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gYXJyYXk7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogVGhlIGJhc2UgaW1wbGVtZW50YXRpb24gb2YgYF8ucmFuZG9tYCB3aXRob3V0IHN1cHBvcnQgZm9yIHJldHVybmluZ1xuICAgICAqIGZsb2F0aW5nLXBvaW50IG51bWJlcnMuXG4gICAgICpcbiAgICAgKiBAcHJpdmF0ZVxuICAgICAqIEBwYXJhbSB7bnVtYmVyfSBsb3dlciBUaGUgbG93ZXIgYm91bmQuXG4gICAgICogQH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4gICAgICAgIGlmIChwcmVjaXNpb24gJiYgbmF0aXZlSXNGaW5pdGUobnVtYmVyKSkge1xuICAgICAgICAgIC8vIFNoaWZ0IHdpdGggZXhwb25lbnRpYWwgbm90YXRpb24gdG8gYXZvaWQgZmxvYXRpbmctcG9pbnQgaXNzdWVzLlxuICAgICAgICAgIC8vIFNlZSBbTUROXShodHRwczovL21kbi5pby9yb3VuZCNFeGFtcGxlcykgZm9yIG1vcmUgZGV0YWlscy5cbiAgICAgICAgICB2YXIgcGFpciA9ICh0b1N0cmluZyhudW1iZXIpICsgJ2UnKS5zcGxpdCgnZScpLFxuICAgICAgICAgICAgICB2YWx1ZSA9IGZ1bmMocGFpclswXSArICdlJyArICgrcGFpclsxXSArIHByZWNpc2lvbikpO1xuXG4gICAgICAgICAgcGFpciA9ICh0b1N0cmluZyh2YWx1ZSkgKyAnZScpLnNwbGl0KCdlJyk7XG4gICAgICAgICAgcmV0dXJuICsocGFpclswXSArICdlJyArICgrcGFpclsxXSAtIHByZWNpc2lvbikpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBmdW5jKG51bWJlcik7XG4gICAgICB9O1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIENyZWF0ZXMgYSBzZXQgb2JqZWN0IG9mIGB2YWx1ZXNgLlxuICAgICAqXG4gICAgICogQHByaXZhdGVcbiAgICAgKiBAcGFyYW0ge0FycmF5fSB2YWx1ZXMgVGhlIHZhbHVlcyB0byBhZGQgdG8gdGhlIHNldC5cbiAgICAgKiBAcmV0dXJucyB7T2JqZWN0fSBSZXR1cm5zIHRoZSBuZXcgc2V0LlxuICAgICAqL1xuICAgIHZhciBjcmVhdGVTZXQgPSAhKFNldCAmJiAoMSAvIHNldFRvQXJyYXkobmV3IFNldChbLC0wXSkpWzFdKSA9PSBJTkZJTklUWSkgPyBub29wIDogZnVuY3Rpb24odmFsdWVzKSB7XG4gICAgICByZXR1cm4gbmV3IFNldCh2YWx1ZXMpO1xuICAgIH07XG5cbiAg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DT01QQVJFX1VOT1JERVJFRF9GTEFHKSA/IG5ldyBTZXRDYWNoZSA6IHVuZGVmaW5lZDtcblxuICAgICAgc3RhY2suc2V0KGFycmF5LCBvdGhlcik7XG4gICAgICBzdGFjay5zZXQob3RoZXIsIGFycmF5KTtcblxuICAgICAgLy8gSWdub3JlIG5vbi1pbmRleCBwcm9wZXJ0aWVzLlxuICAgICAgd2hpbGUgKCsraW5kZXggPCBhcnJMZW5ndGgpIHtcbiAgICAgICAgdmFyIGFyclZhbHVlID0gYXJyYXlbaW5kZXhdLFxuICAgICAgICAgICAgb3RoVmFsdWUgPSBvdGhlcltpbmRleF07XG5cbiAgICAgICAgaWYgKGN1c3RvbWl6ZXIpIHtcbiAgICAgICAgICB2YXIgY29tcGFyZWQgPSBpc1BhcnRpYWxcbiAgICAgICAgICAgID8gY3VzdG9taXplcihvdGhWYWx1ZSwgYXJyVmFsdWUsIGluZGV4LCBvdGhlciwgYXJyYXksIHN0YWNrKVxuICAgICAgICAgICAgOiBjdXN0b21pemVyKGFyclZhbHVlLCBvdGhWYWx1ZSwgaW5kZXgsIGFycmF5LCBvdGhlciwgc3RhY2spO1xuICAgICAgICB9XG4gICAgICAgIGlmIChjb21wYXJlZCAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgaWYgKGNvbXBhcmVkKSB7XG4gICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICB9XG4gICAgICAgICAgcmVzdWx0ID0gZmFsc2U7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgLy8gUmVjdXJzaXZlbHkgY29tcGFyZSBhcnJheXMgKHN1c2NlcHRpYmxlIHRvIGNhbGwgc3RhY2sgbGltaXRzKS5cbiAgICAgICAgaWYgKHNlZW4pIHtcbiAgICAgICAgICBpZiAoIWFycmF5U29tZShvdGhlciwgZnVuY3Rpb24ob3RoVmFsdWUsIG90aEluZGV4KSB7XG4gICAgICAgICAgICAgICAgaWYgKCFjYWNoZUhhcyhzZWVuLCBvdGhJbmRleCkgJiZcbiAgICAgICAgICAgICAgICAgICAgKGFyclZhbHVlID09PSBvdGhWYWx1ZSB8fCBlcXVhbEZ1bmMoYXJyVmFsdWUsIG90aFZhbHVlLCBiaXRtYXNrLCBjdXN0b21pemVyLCBzdGFjaykpKSB7XG4gICAgICAgICAgICAgICAgICByZXR1cm4gc2Vlbi5wdXNoKG90aEluZGV4KTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH0pKSB7XG4gICAgICAgICAgICByZXN1bHQgPSBmYWxzZTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIGlmICghKFxuICAgICAgICAgICAgICBhcnJWYWx1ZSA9PT0gb3RoVmFsdWUgfHxcbiAgICAgICAgICAgICAgICBlcXVhbEZ1bmMoYXJyVmFsdWUsIG90aFZhbHVlLCBiaXRtYXNrLCBjdXN0b21pemVyLCBzdGFjaylcbiAgICAgICAgICAgICkpIHtcbiAgICAgICAgICByZXN1bHQgPSBmYWxzZTtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgc3RhY2tbJ2RlbGV0ZSddKGFycmF5KTtcbiAgICAgIHN0YWNrWydkZWxldGUnXShvdGhlcik7XG4gICAgICByZXR1cm4gcmVzdWx0O1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIEEgc3BlY2lhbGl6ZWQgdmVyc2lvbiBvZiBgYmFzZUlzRXF1YWxEZWVwYCBmb3IgY29tcGFyaW5nIG9iamVjdHMgb2ZcbiAgICAgKiB0aGUgc2FtZSBgdG9TdHJpbmdUYWdgLlxuICAgICAqXG4gICAgICogKipOb3RlOioqIFRoaXMgZnVuY3Rpb24gb25seSBzdXBwb3J0cyBjb21wYXJpbmcgdmFsdWVzIHdpdGggdGFncyBvZlxuICAgICAqIGBCb29sZWFuYCwgYERhdGVgLCBgRXJyb3JgLCBgTnVtYmVyYCwgYFJlZ0V4cG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c2hvcnRPdXQoZnVuYykge1xuICAgICAgdmFyIGNvdW50ID0gMCxcbiAgICAgICAgICBsYXN0Q2FsbGVkID0gMDtcblxuICAgICAgcmV0dXJuIGZ1bmN0aW9uKCkge1xuICAgICAgICB2YXIgc3RhbXAgPSBuYXRpdmVOb3coKSxcbiAgICAgICAgICAgIHJlbWFpbmluZyA9IEhPVF9TUEFOIC0gKHN0YW1wIC0gbGFzdENhbGxlZCk7XG5cbiAgICAgICAgbGFzdENhbGxlZCA9IHN0YW1wO1xuICAgICAgICBpZiAocmVtYWluaW5nID4gMCkge1xuICAgICAgICAgIGlmICgrK2NvdW50ID49IEhPVF9DT1VOVCkge1xuICAgICAgICAgICAgcmV0dXJuIGFyZ3VtZW50c1swXTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgY291bnQgPSAwO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBmdW5jLmFwcGx5KHVuZGVmaW5lZCwgYXJndW1lbnRzKTtcbiAgICAgIH07XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogQSBzcGVjaWFsaXplZCB2ZXJzaW9uIG9mIGBfLnNodWZmbGVgIHdoaWNoIG11dGF0ZXMgYW5kIHNldHMgdGhlIHNpemUgb2YgYGFycmF5YC5cbiAgICAgKlxuICAgICAqIEBwcml2YXRlXG4gICAgICogQHBhcmFtIHtBcnJheX0gYXJyYXkgVGhlIGFycmF5IHRvIHNodWZmbGUuXG4gICAgICogQHBhcmFtIHtudW1iZXJ9IFtzaXplPWFycmF5Lmxlbmd0aF0gVGhlIHNpemUgb2YgYGFycmF5YC5cbiAgICAgKiBAcmV0dXJucyB7QXJyYXl9IFJldHVybnMgYGFycmF5YC5cbiAgICAgKi9cbiAgICBmdW5jdGlvbiBzaHVmZmxlU2VsZihhcnJheSwgc2l6ZSkge1xuICAgICAgdmFyIGluZGV4ID0gLTEsXG4gICAgICAgICAgbGVuZ3RoID0gYXJyYXkubGVuZ3RoLFxuICA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lvbi5cbiAgICAgKiBAcmV0dXJucyB7QXJyYXl9IFJldHVybnMgdGhlIG5ldyBhcnJheSBvZiByZW1vdmVkIGVsZW1lbnRzLlxuICAgICAqIEBleGFtcGxlXG4gICAgICpcbiAgICAgKiB2YXIgYXJyYXkgPSBbMSwgMiwgMywgNF07XG4gICAgICogdmFyIGV2ZW5zID0gXy5yZW1vdmUoYXJyYXksIGZ1bmN0aW9uKG4pIHtcbiAgICAgKiAgIHJldHVybiBuICUgMiA9PSAwO1xuICAgICAqIH0pO1xuICAgICAqXG4gICAgICogY29uc29sZS5sb2coYXJyYXkpO1xuICAgICAqIC8vID0+IFsxLCAzXVxuICAgICAqXG4gICAgICogY29uc29sZS5sb2coZXZlbnMpO1xuICAgICAqIC8vID0+IFsyLCA0XVxuICAgICAqL1xuICAgIGZ1bmN0aW9uIHJlbW92ZShhcnJheSwgcHJlZGljYXRlKSB7XG4gICAgICB2YXIgcmVzdWx0ID0gW107XG4gICAgICBpZiAoIShhcnJheSAmJiBhcnJheS5sZW5ndGgpKSB7XG4gICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgICB9XG4gICAgICB2YXIgaW5kZXggPSAtMSxcbiAgICAgICAgICBpbmRleGVzID0gW10sXG4gICAgICAgICAgbGVuZ3RoID0gYXJyYXkubGVuZ3RoO1xuXG4gICAgICBwcmVkaWNhdGUgPSBnZXRJdGVyYXRlZShwcmVkaWNhdGUsIDMpO1xuICAgICAgd2hpbGUgKCsraW5kZXggPCBsZW5ndGgpIHtcbiAgICAgICAgdmFyIHZhbHVlID0gYXJyYXlbaW5kZXhdO1xuICAgICAgICBpZiAocHJlZGljYXRlKHZhbHVlLCBpbmRleCwgYXJyYXkpKSB7XG4gICAgICAgICAgcmVzdWx0LnB1c2godmFsdWUpO1xuICAgICAgICAgIGluZGV4ZXMucHVzaChpbmRleCk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGJhc2VQdWxsQXQoYXJyYXksIGluZGV4ZXMpO1xuICAg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XBwbGllZCBhcmd1bWVudHMuXG4gICAgICpcbiAgICAgKiBAc3RhdGljXG4gICAgICogQG1lbWJlck9mIF9cbiAgICAgKiBAc2luY2UgMC4xMC4wXG4gICAgICogQGNhdGVnb3J5IEZ1bmN0aW9uXG4gICAgICogQHBhcmFtIHtPYmplY3R9IG9iamVjdCBUaGUgb2JqZWN0IHRvIGludm9rZSB0aGUgbWV0aG9kIG9uLlxuICAgICAqIEBwYXJhbSB7c3RyaW5nfSBrZXkgVGhlIGtleSBvZiB0aGUgbWV0aG9kLlxuICAgICAqIEBwYXJhbSB7Li4uKn0gW3BhcnRpYWxzXSBUaGUgYXJndW1lbnRzIHRvIGJlIHBhcnRpYWxseSBhcHBsaWVkLlxuICAgICAqIEByZXR1cm5zIHtGdW5jdGlvbn0gUmV0dXJucyB0aGUgbmV3IGJvdW5kIGZ1bmN0aW9uLlxuICAgICAqIEBleGFtcGxlXG4gICAgICpcbiAgICAgKiB2YXIgb2JqZWN0ID0ge1xuICAgICAqICAgJ3VzZXInOiAnZnJlZCcsXG4gICAgICogICAnZ3JlZXQnOiBmdW5jdGlvbihncmVldGluZywgcHVuY3R1YXRpb24pIHtcbiAgICAgKiAgICAgcmV0dXJuIGdyZWV0aW5nICsgJyAnICsgdGhpcy51c2VyICsgcHVuY3R1YXRpb247XG4gICAgICogICB9XG4gICAgICogfTtcbiAgICAgKlxuICAgICAqIHZhciBib3VuZCA9IF8uYmluZEtleShvYmplY3QsICdncmVldCcsICdoaScpO1xuICAgICAqIGJvdW5kKCchJyk7XG4gICAgICogLy8gPT4gJ2hpIGZyZWQhJ1xuICAgICAqXG4gICAgICogb2JqZWN0LmdyZWV0ID0gZnVuY3Rpb24oZ3JlZXRpbmcsIHB1bmN0dWF0aW9uKSB7XG4gICAgICogICByZXR1cm4gZ3JlZXRpbmcgKyAneWEgJyArIHRoaXMudXNlciArIHB1bmN0dWF0aW9uO1xuICAgICAqIH07XG4gICAgICpcbiAgICAgKiBib3VuZCgnIScpO1xu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IHtcbiAgICAgICAgICByZXR1cm4gaW52b2tlRnVuYyh0aW1lKTtcbiAgICAgICAgfVxuICAgICAgICBsYXN0QXJncyA9IGxhc3RUaGlzID0gdW5kZWZpbmVkO1xuICAgICAgICByZXR1cm4gcmVzdWx0O1xuICAgICAgfVxuXG4gICAgICBmdW5jdGlvbiBjYW5jZWwoKSB7XG4gICAgICAgIGlmICh0aW1lcklkICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICBjbGVhclRpbWVvdXQodGltZXJJZCk7XG4gICAgICAgIH1cbiAgICAgICAgbGFzdEludm9rZVRpbWUgPSAwO1xuICAgICAgICBsYXN0QXJncyA9IGxhc3RDYWxsVGltZSA9IGxhc3RUaGlzID0gdGltZXJJZCA9IHVuZGVmaW5lZDtcbiAgICAgIH1cblxuICAgICAgZnVuY3Rpb24gZmx1c2goKSB7XG4gICAgICAgIHJldHVybiB0aW1lcklkID09PSB1bmRlZmluZWQgPyByZXN1bHQgOiB0cmFpbGluZ0VkZ2Uobm93KCkpO1xuICAgICAgfVxuXG4gICAgICBmdW5jdGlvbiBkZWJvdW5jZWQoKSB7XG4gICAgICAgIHZhciB0aW1lID0gbm93KCksXG4gICAgICAgICAgICBpc0ludm9raW5nID0gc2hvdWxkSW52b2tlKHRpbWUpO1xuXG4gICAgICAgIGxhc3RBcmdzID0gYXJndW1lbnRzO1xuICAgICAgICBsYXN0VGhpcyA9IHRoaXM7XG4gICAgICAgIGxhc3RDYWxsVGltZSA9IHRpbWU7XG5cbiAgICAgICAgaWYgKGlzSW52b2tpbmcpIHtcbiAgICAgICAgICBpZiAodGltZXJJZCA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICByZXR1cm4gbGVhZGluZ0VkZ2UobGFzdENhbGxUaW1lKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKG1heGluZykge1xuICAgICAgICAgICAgLy8gSGFuZGxlIGludm9jYXRpb25zIGluIGEgdGlnaHQgbG9vcC5cbiAgICAgICAgIC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biAgICAvKipcbiAgICAgKiBDYXN0cyBgdmFsdWVgIGFzIGFuIGFycmF5IGlmIGl0J3Mgbm90IG9uZS5cbiAgICAgKlxuICAgICAqIEBzdGF0aWNcbiAgICAgKiBAbWVtYmVyT2YgX1xuICAgICAqIEBzaW5jZSA0LjQuMFxuICAgICAqIEBjYXRlZ29yeSBMYW5nXG4gICAgICogQHBhcmFtIHsqfSB2YWx1ZSBUaGUgdmFsdWUgdG8gaW5zcGVjdC5cbiAgICAgKiBAcmV0dXJucyB7QXJyYXl9IFJldHVybnMgdGhlIGNhc3QgYXJyYXkuXG4gICAgICogQGV4YW1wbGVcbiAgICAgKlxuICAgICAqIF8uY2FzdEFycmF5KDEpO1xuICAgICAqIC8vID0+IFsxXVxuICAgICAqXG4gICAgICogXy5jYXN0QXJyYXkoeyAnYSc6IDEgfSk7XG4gICAgICogLy8gPT4gW3sgJ2EnOiAxIH1dXG4gICAgICpcbiAgICAgKiBfLmNhc3RBcnJheSgnYWJjJyk7XG4gICAgICogLy8gPT4gWydhYmMnXVxuICAgICAqXG4gICAgICogXy5jYXN0QXJyYXkobnVsbCk7XG4gICAgICogLy8gPT4gW251bGxdXG4gICAgICpcbiAgICAgKiBfLmNhc3RBcnJheSh1bmRlZmluZWQpO1xuICAgICAqIC8vID0+IFt1bmRlZmluZWRdXG4gICAgICpcbiAgICAgKiBfLmNhc3RBcnJheSgpO1xuICAgICAqIC8vID0+IFtdXG4gICAgICpcbiAgICAgKiB2YXIgYXJyYXkgPSBbMSwgMiwgM107XG4gICAgICogY29uc29sZS5sb2coXy5jYXN0QXJyYXkoYXJyYXkpID09PSBhcnJheSk7XG4gICAgICogLy8gPT4gdHJ1ZVxuICAgICAqL1xuICAgIGZ1bmN0aW9uIGNhc3RBcnJheSgpIHtcbiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkge1xuICAgICAgICByZXR1cm4gW107XG4gICAgICB9XG4gICAgICB2YXIgdmFsdWUgPSBhcmd1bWVudHNbMF07X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b24gb3JkZXIgaXMgbm90IGd1YXJhbnRlZWQpXG4gICAgICpcbiAgICAgKiBfLnZhbHVlcygnaGknKTtcbiAgICAgKiAvLyA9PiBbJ2gnLCAnaSddXG4gICAgICovXG4gICAgZnVuY3Rpb24gdmFsdWVzKG9iamVjdCkge1xuICAgICAgcmV0dXJuIG9iamVjdCA9PSBudWxsID8gW10gOiBiYXNlVmFsdWVzKG9iamVjdCwga2V5cyhvYmplY3QpKTtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBDcmVhdGVzIGFuIGFycmF5IG9mIHRoZSBvd24gYW5kIGluaGVyaXRlZCBlbnVtZXJhYmxlIHN0cmluZyBrZXllZCBwcm9wZXJ0eVxuICAgICAqIHZhbHVlcyBvZiBgb2JqZWN0YC5cbiAgICAgKlxuICAgICAqICoqTm90ZToqKiBOb24tb2JqZWN0IHZhbHVlcyBhcmUgY29lcmNlZCB0byBvYmplY3RzLlxuICAgICAqXG4gICAgICogQHN0YXRpY1xuICAgICAqIEBtZW1iZXJPZiBfXG4gICAgICogQHNpbmNlIDMuMC4wXG4gICAgICogQGNhdGVnb3J5IE9iamVjdFxuICAgICAqIEBwYXJhbSB7T2JqZWN0fSBvYmplY3QgVGhlIG9iamVjdCB0byBxdWVyeS5cbiAgICAgKiBAcmV0dXJucyB7QXJyYXl9IFJldHVybnMgdGhlIGFycmF5IG9mIHByb3BlcnR5IHZhbHVlcy5cbiAgICAgKiBAZXhhbXBsZVxuICAgICAqXG4gICAgICogZnVuY3Rpb24gRm9vKCkge1xuICAgICAqICAgdGhpcy5hID0gMTtcbiAgICAgKiAgIHRoaXMuYiA9IDI7XG4gICAgICogfVxuICAgICAqXG4gICAgICogRm9vLnByb3RvdHlwZS5jID0gMztcbiAgICAgKlxuICAgICAqIF8udmFsdWVzSW4obmV3IEZvbyk7XG4gICAgICogLy8gPT4gWzEsIDIsIDNdIChpdGVyYXRpb24gb3JkZXIgaXMgbm90IGd1YXJhbnRlZWQpXG4gICAgICovXG4g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hdGlvbi5cbiAgICAgKiBAcGFyYW0ge251bWJlcn0gbXVsdGlwbGljYW5kIFRoZSBzZWNvbmQgbnVtYmVyIGluIGEgbXVsdGlwbGljYXRpb24uXG4gICAgICogQHJldHVybnMge251bWJlcn0gUmV0dXJucyB0aGUgcHJvZHVjdC5cbiAgICAgKiBAZXhhbXBsZVxuICAgICAqXG4gICAgICogXy5tdWx0aXBseSg2LCA0KTtcbiAgICAgKiAvLyA9PiAyNFxuICAgICAqL1xuICAgIHZhciBtdWx0aXBseSA9IGNyZWF0ZU1hdGhPcGVyYXRpb24oZnVuY3Rpb24obXVsdGlwbGllciwgbXVsdGlwbGljYW5kKSB7XG4gICAgICByZXR1cm4gbXVsdGlwbGllciAqIG11bHRpcGxpY2FuZDtcbiAgICB9LCAxKTtcblxuICAgIC8qKlxuICAgICAqIENvbXB1dGVzIGBudW1iZXJgIHJvdW5kZWQgdG8gYHByZWNpc2lvbmAuXG4gICAgICpcbiAgICAgKiBAc3RhdGljXG4gICAgICogQG1lbWJlck9mIF9cbiAgICAgKiBAc2luY2UgMy4xMC4wXG4gICAgICogQGNhdGVnb3J5IE1hdGhcbiAgICAgKiBAcGFyYW0ge251bWJlcn0gbnVtYmVyIFRoZSBudW1iZXIgdG8gcm91bmQuXG4gICAgICogQHBhcmFtIHtudW1iZXJ9IFtwcmVjaXNpb249MF0gVGhlIHByZWNpc2lvbiB0byByb3VuZCB0by5cbiAgICAgKiBAcmV0dXJucyB7bnVtYmVyfSBSZXR1cm5zIHRoZSByb3VuZGVkIG51bWJlci5cbiAgICAgKiBAZXhhbXBsZVxuICAgICAqXG4gICAgICogXy5yb3VuZCg0LjAwNik7XG4gICAgICogLy8gPT4gNFxuICAgICAqXG4gICAgICogXy5yb3VuZCg0LjAwNiwgMik7XG4gICAgICogLy8gPT4gNC4wMVxuICAgICAqXG4gICAgICogXy5yb3VuZCg0MDYwLCAtMik7XG4gICAgICogLy8gPT4gNDEwMFxuICAgICAqL1xuICAgIHZhciByb3V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wZXJ0eUlzRW51bWVyYWJsZTtcblxudmFyIGdQTyA9ICh0eXBlb2YgUmVmbGVjdCA9PT0gJ2Z1bmN0aW9uJyA/IFJlZmxlY3QuZ2V0UHJvdG90eXBlT2YgOiBPYmplY3QuZ2V0UHJvdG90eXBlT2YpIHx8IChcbiAgICBbXS5fX3Byb3RvX18gPT09IEFycmF5LnByb3RvdHlwZSAvLyBlc2xpbnQtZGlzYWJsZS1saW5lIG5vLXByb3RvXG4gICAgICAgID8gZnVuY3Rpb24gKE8pIHtcbiAgICAgICAgICAgIHJldHVybiBPLl9fcHJvdG9fXzsgLy8gZXNsaW50LWRpc2FibGUtbGluZSBuby1wcm90b1xuICAgICAgICB9XG4gICAgICAgIDogbnVsbFxuKTtcblxuZnVuY3Rpb24gYWRkTnVtZXJpY1NlcGFyYXRvcihudW0sIHN0cikge1xuICAgIGlmIChcbiAgICAgICAgbnVtID09PSBJbmZpbml0eVxuICAgICAgICB8fCBudW0gPT09IC1JbmZpbml0eVxuICAgICAgICB8fCBudW0gIT09IG51bVxuICAgICAgICB8fCAobnVtICYmIG51bSA+IC0xMDAwICYmIG51bSA8IDEwMDApXG4gICAgICAgIHx8ICR0ZXN0LmNhbGwoL2UvLCBzdHIpXG4gICAgKSB7XG4gICAgICAgIHJldHVybiBzdHI7XG4gICAgfVxuICAgIHZhciBzZXBSZWdleCA9IC9bMC05XSg/PSg/OlswLTldezN9KSsoPyFbMC05XSkpL2c7XG4gICAgaWYgKHR5cGVvZiBudW0gPT09ICdudW1iZXInKSB7XG4gICAgICAgIHZhciBpbnQgPSBudW0gPCAwID8gLSRmbG9vcigtbnVtKSA6ICRmbG9vcihudW0pOyAvLyB0cnVuYyhudW0pXG4gICAgICAgIGlmIChpbnQgIT09IG51bSkge1xuICAgICAgICAgICAgdmFyIGludFN0ciA9IFN0cmluZyhpbnQpO1xuICAgICAgICAgICAgdmFyIGRlYyA9ICRzbGljZS5jYWxsKHN0ciwgaW50U3RyLmxlbmd0aCArIDEpO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BhZGROdW1lcmljU2VwYXJhdG9yKG9iaiwgYmlnSW50U3RyKSA6IGJpZ0ludFN0cjtcbiAgICB9XG5cbiAgICB2YXIgbWF4RGVwdGggPSB0eXBlb2Ygb3B0cy5kZXB0aCA9PT0gJ3VuZGVmaW5lZCcgPyA1IDogb3B0cy5kZXB0aDtcbiAgICBpZiAodHlwZW9mIGRlcHRoID09PSAndW5kZWZpbmVkJykgeyBkZXB0aCA9IDA7IH1cbiAgICBpZiAoZGVwdGggPj0gbWF4RGVwdGggJiYgbWF4RGVwdGggPiAwICYmIHR5cGVvZiBvYmogPT09ICdvYmplY3QnKSB7XG4gICAgICAgIHJldHVybiBpc0FycmF5KG9iaikgPyAnW0FycmF5XScgOiAnW09iamVjdF0nO1xuICAgIH1cblxuICAgIHZhciBpbmRlbnQgPSBnZXRJbmRlbnQob3B0cywgZGVwdGgpO1xuXG4gICAgaWYgKHR5cGVvZiBzZWVuID09PSAndW5kZWZpbmVkJykge1xuICAgICAgICBzZWVuID0gW107XG4gICAgfSBlbHNlIGlmIChpbmRleE9mKHNlZW4sIG9iaikgPj0gMCkge1xuICAgICAgICByZXR1cm4gJ1tDaXJjdWxhcl0nO1xuICAgIH1cblxuICAgIGZ1bmN0aW9uIGluc3BlY3QodmFsdWUsIGZyb20sIG5vSW5kZW50KSB7XG4gICAgICAgIGlmIChmcm9tKSB7XG4gICAgICAgICAgICBzZWVuID0gJGFyclNsaWNlLmNhbGwoc2Vlbik7XG4gICAgICAgICAgICBzZWVuLnB1c2goZnJvbSk7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKG5vSW5kZW50KSB7XG4gICAgICAgICAgICB2YXIgbmV3T3B0cyA9IHtcbiAgICAgICAgICAgICAgICBkZXB0aDogb3B0cy5kZXB0aFxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIGlmIChoYXMob3B0cywgJ3F1b3RlU3R5bGUnKSkge1xuICAgICAgICAgICAgICAgIG5ld09wdHMucXVvdGVTdHlsZSA9IG9wd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m9kZU5hbWUpKTtcbiAgICAgICAgdmFyIGF0dHJzID0gb2JqLmF0dHJpYnV0ZXMgfHwgW107XG4gICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgYXR0cnMubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgIHMgKz0gJyAnICsgYXR0cnNbaV0ubmFtZSArICc9JyArIHdyYXBRdW90ZXMocXVvdGUoYXR0cnNbaV0udmFsdWUpLCAnZG91YmxlJywgb3B0cyk7XG4gICAgICAgIH1cbiAgICAgICAgcyArPSAnPic7XG4gICAgICAgIGlmIChvYmouY2hpbGROb2RlcyAmJiBvYmouY2hpbGROb2Rlcy5sZW5ndGgpIHsgcyArPSAnLi4uJzsgfVxuICAgICAgICBzICs9ICc8LycgKyAkdG9Mb3dlckNhc2UuY2FsbChTdHJpbmcob2JqLm5vZGVOYW1lKSkgKyAnPic7XG4gICAgICAgIHJldHVybiBzO1xuICAgIH1cbiAgICBpZiAoaXNBcnJheShvYmopKSB7XG4gICAgICAgIGlmIChvYmoubGVuZ3RoID09PSAwKSB7IHJldHVybiAnW10nOyB9XG4gICAgICAgIHZhciB4cyA9IGFyck9iaktleXMob2JqLCBpbnNwZWN0KTtcbiAgICAgICAgaWYgKGluZGVudCAmJiAhc2luZ2xlTGluZVZhbHVlcyh4cykpIHtcbiAgICAgICAgICAgIHJldHVybiAnWycgKyBpbmRlbnRlZEpvaW4oeHMsIGluZGVudCkgKyAnXSc7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuICdbICcgKyAkam9pbi5jYWxsKHhzLCAnLCAnKSArICcgXSc7XG4gICAgfVxuICAgIGlmIChpc0Vycm9yKG9iaikpIHtcbiAgICAgICAgdmFyIHBhcnRzID0gYXJyT2JqS2V5cyhvYmosIGluc3BlY3QpO1xuICAgICAgICBpZiAoISgnY2F1c2UnIGluIEVycm9yLnByb3RvdHlwZSkgJiYgJ2NhdXNlJyBpbiBvYmogJiYgIWlzRW51bWVyYWJsZS5jYWxsKG9iaiwgJ2NhdXNlJykpIHtcbiAgICAgICAgICAgIHJldHVybiAneyBbJyArIFN0cmluZyhvYmopICsgJ10gJyArICRqb2luLmNhbGwoJGNvbmNhdC5jYWxsKCdbY2F1c2VdOiAnICsgaW5zcGVjdChvYmouY2F1c2UpLCBwYXJ0cyksICcsICcpICsgJyB9JztcbiAgICAgICAgfVxuICAgICAgICBpZiAocGFydHMubGVuZ3RoID09PSAwKSB7IHJldHVybiAnWycgKyBTdHJpbmcob2JqKSArICddJzsgfVxuICAgICAgICByZXR1cm4gJ3sgWycgKyBTdHJpbmcob2JqKSArICddICcgKyAkam9pbi5jYWxsKHBhcnRzLCAnLCAnKSArICcgfSc7XG4gICAgfVxuICAgIGlmICh0eXBlb2Ygb2JqID09PSAnb2JqZWN0JyAmJiBjdXN0b21JbnNwZWN0KSB7XG4gICAgICAgIGlmIChpbnNwZWN0U3ltYm9sICYmIHR5cGVvZiBvYmpbaW5zcGVjdFN5bWJvbF0gPT09ICdmdW5jdGlvbicgJiYgdXRpbEluc3BlY3QpIHtcbiAgICAgICAgICAgIHJldHVybiB1dGlsSW5zcGVjdChvYmosIHsgZGVwdGg6IG1heERlcHRoIC0gZGVwdGggfSk7XG4gICAgICAgIH0gZWxzZSBpZiAoY3VzdG9tSW5zcGVjdCAhPT0gJ3N5bWJvbCcgJiYgdHlwZW9mIG9iai5pbnNwZWN0ID09PSAnZnVuY3Rpb24nKSB7XG4gICAgICAgICAgICByZXR1cm4gb2JqLmluc3BlY3QoKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBpZiAoaXNNYXAob2JqKSkge1xuICAgICAgICB2YXIgbWFwUGFydHMgPSBbXTtcbiAgICAgICAgaWYgKG1hcEZvckVhY2gpIHtcbiAgICAgICAgICAgIG1hcEZvckVhY2guY2FsbChvYmosIGZ1bmN0aW9uICh2YWx1ZSwga2V5KSB7XG4gICAgICAgICAgICAgICAgbWFwUGFydHMucHVzaChpbnNwZWN0KGtleSwgb2JqLCB0cnVlKSArICcgPT4gJyArIGluc3BlY3QodmFsdWUsIG9iaikpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGNvbGxlY3Rpb25PZignTWFwJywgbWFwU2l6ZS5jYWxsKG9iaiksIG1hcFBhcnRzLCBpbmRlbnQpO1xuICAgIH1cbiAgICBpZiAoaXNTZXQob2JqKSkge1xuICAgICAgICB2YXIgc2V0UGFydHMgPSBbXTtcbiAgICAgICAgaWYgKHNldEZvckVhY2gpIHtcbiAgICAgICAgICAgIHNldEZvckVhY2guY2FsbChvYmosIGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgIHNldFBhcnRzLnB1c2goaW5zcGVjdCh2YWx1ZSwgb2JqKSk7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gY29sbGVjdGlvbk9mKCdTZXQnLCBzZXRTaXplLmNhbGwob2JqKSwgc2V0UGFydHMsIGluZGVudCk7XG4gICAgfVxuICAgIGlmIChpc1dlYWtNYXAob2JqKSkge1xuICAgICAgICByZXR1cm4gd2Vha0NvbGxlY3Rpb25PZignV2Vha01hcCcpO1xuICAgIH1cbiAgICBpZiAoaXNXZWFrU2V0KG9iaikpIHtcbiAgICAgICAgcmV0dXJuIHdlYWtDb2xsZWN0aW9uT2YoJ1dlYWtTZXQnKTtcbiAgICB9XG4gICAgaWYgKGlzV2Vha1JlZihvYmopKSB7XG4gICAgICAgIHJldHVybiB3ZWFrQ29sbGVjdGlvbk9mKCdXZWFrUmVmJyk7XG4gICAgfVxuICAgIGlmIChpc051bWJlcihvYmopKSB7XG4gICAgICAgIHJldHVybiBtYXJrQm94ZWQoaW5zcGVjdChOdW1iZXIob2JqKSkpO1xuICAgIH1cbiAgICBpZiAoaXNCaWdJbnQob2JqKSkge1xuICAgICAgICByZXR1cm4gbWFya0JveGVkKGluc3BlY3QoYmlnSW50VmFsdWVPZi5jYWxsKG9iaikpKTtcbiAgICB9XG4gICAg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pbmcgaW5jbHVkZWQgaW4gdGhlIHN0cmluZyBrZXkgc2VjdGlvblxuICAgICAgICAgICAgY29udGludWU7IC8vIGVzbGludC1kaXNhYmxlLWxpbmUgbm8tcmVzdHJpY3RlZC1zeW50YXgsIG5vLWNvbnRpbnVlXG4gICAgICAgIH0gZWxzZSBpZiAoJHRlc3QuY2FsbCgvW15cXHckXS8sIGtleSkpIHtcbiAgICAgICAgICAgIHhzLnB1c2goaW5zcGVjdChrZXksIG9iaikgKyAnOiAnICsgaW5zcGVjdChvYmpba2V5XSwgb2JqKSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB4cy5wdXNoKGtleSArICc6ICcgKyBpbnNwZWN0KG9ialtrZXldLCBvYmopKTtcbiAgICAgICAgfVxuICAgIH1cbiAgICBpZiAodHlwZW9mIGdPUFMgPT09ICdmdW5jdGlvbicpIHtcbiAgICAgICAgZm9yICh2YXIgaiA9IDA7IGogPCBzeW1zLmxlbmd0aDsgaisrKSB7XG4gICAgICAgICAgICBpZiAoaXNFbnVtZXJhYmxlLmNhbGwob2JqLCBzeW1zW2pdKSkge1xuICAgICAgICAgICAgICAgIHhzLnB1c2goJ1snICsgaW5zcGVjdChzeW1zW2pdKSArICddOiAnICsgaW5zcGVjdChvYmpbc3ltc1tqXV0sIG9iaikpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxuICAgIHJldHVybiB4cztcbn1cbiIsIid1c2Ugc3RyaWN0JztcblxudmFyIGtleXNTaGltO1xuaWYgKCFPYmplY3Qua2V5cykge1xuXHQvLyBtb2RpZmllZCBmcm9tIGh0dHBzOi8vZ2l0aHViLmNvbS9lcy1zaGltcy9lczUtc2hpbVxuXHR2YXIgaGFzID0gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eTtcblx0dmFyIHRvU3RyID0gT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZztcblx0dmFyIGlzQXJncyA9IHJlcXVpcmUoJy4vaXN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Uk9SID0gLTY7XG5cblxuLyogY29tcHJlc3Npb24gbGV2ZWxzICovXG4vL3ZhciBaX05PX0NPTVBSRVNTSU9OICAgICAgPSAwO1xuLy92YXIgWl9CRVNUX1NQRUVEICAgICAgICAgID0gMTtcbi8vdmFyIFpfQkVTVF9DT01QUkVTU0lPTiAgICA9IDk7XG52YXIgWl9ERUZBVUxUX0NPTVBSRVNTSU9OID0gLTE7XG5cblxudmFyIFpfRklMVEVSRUQgICAgICAgICAgICA9IDE7XG52YXIgWl9IVUZGTUFOX09OTFkgICAgICAgID0gMjtcbnZhciBaX1JMRSAgICAgICAgICAgICAgICAgPSAzO1xudmFyIFpfRklYRUQgICAgICAgICAgICAgICA9IDQ7XG52YXIgWl9ERUZBVUxUX1NUUkFURUdZICAgID0gMDtcblxuLyogUG9zc2libGUgdmFsdWVzIG9mIHRoZSBkYXRhX3R5cGUgZmllbGQgKHRob3VnaCBzZWUgaW5mbGF0ZSgpKSAqL1xuLy92YXIgWl9CSU5BUlkgICAgICAgICAgICAgID0gMDtcbi8vdmFyIFpfVEVYVCAgICAgICAgICAgICAgICA9IDE7XG4vL3ZhciBaX0FTQ0lJICAgICAgICAgICAgICAgPSAxOyAvLyA9IFpfVEVYVFxudmFyIFpfVU5LTk9XTiAgICAgICAgICAgICA9IDI7XG5cblxuLyogVGhlIGRlZmxhdGUgY29tcHJlc3Npb24gbWV0aG9kICovXG52YXIgWl9ERUZMQVRFRCAgPSA4O1xuXG4vKj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0qL1xuXG5cbnZhciBNQVhfTUVNX0xFVkVMID0gOTtcbi8qIE1heGltdW0gdmFsdWUgZm9yIG1lbUxldmVsIGluIGRlZmxhdGVJbml0MiAqL1xudmFyIE1BWF9XQklUUyA9IDE1O1xuLyogMzJLIExaNzcgd2luZG93ICovXG52YXIgREVGX01FTV9MRVZFTCA9IDg7XG5cblxudmFyIEx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ryc3RhcnQrMjU4LlxuICAgICAqL1xuICAgIGRvIHtcbiAgICAgIC8qanNoaW50IG5vZW1wdHk6ZmFsc2UqL1xuICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiZcbiAgICAgICAgICAgICBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmXG4gICAgICAgICAgICAgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJlxuICAgICAgICAgICAgIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiZcbiAgICAgICAgICAgICBzY2FuIDwgc3RyZW5kKTtcblxuICAgIC8vIEFzc2VydChzY2FuIDw9IHMtPndpbmRvdysodW5zaWduZWQpKHMtPndpbmRvd19zaXplLTEpLCBcIndpbGQgc2NhblwiKTtcblxuICAgIGxlbiA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTtcbiAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIO1xuXG4gICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7XG4gICAgICBzLm1hdGNoX3N0YXJ0ID0gY3VyX21hdGNoO1xuICAgICAgYmVzdF9sZW4gPSBsZW47XG4gICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHtcbiAgICAgICAgYnJlYWs7XG4gICAgICB9XG4gICAgICBzY2FuX2VuZDEgID0gX3dpbltzY2FuICsgYmVzdF9sZW4gLSAxXTtcbiAgICAgIHNjYW5fZW5kICAgPSBfd2luW3NjYW4gKyBiZXN0X2xlbl07XG4gICAgfVxuICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltj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lIGdvbmU6XG4gICAgICovXG4gICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IChzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7XG4gICAgICAvKioqIEZMVVNIX0JMT0NLKHMsIDApOyAqKiovXG4gICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTtcbiAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7XG4gICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7XG4gICAgICB9XG4gICAgICAvKioqL1xuICAgIH1cbiAgfVxuXG4gIHMuaW5zZXJ0ID0gMDtcblxuICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7XG4gICAgLyoqKiBGTFVTSF9CTE9DSyhzLCAxKTsgKioqL1xuICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7XG4gICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHtcbiAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDtcbiAgICB9XG4gICAgLyoqKi9cbiAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7XG4gIH1cblxuICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHtcbiAgICAvKioqIEZMVVNIX0JMT0NLKHMsIDApOyAqKiovXG4gICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7XG4gICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHtcbiAgICAgIHJldHVybiBCU19ORUVEX01PUkU7XG4gICAgfVxuICAgIC8qKiovXG4gIH1cblxuICByZXR1cm4gQlNfTkVFRF9NT1JFO1xufVxuXG4vKiA9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT1cbiAqIENvbXByZXNzIGFzIG11Y2ggYXMgcG9zc2libGUgZnJvbSB0aGUgaW5wdXQgc3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gPT09IDApIHsgYnJlYWs7IH0gLyogZmx1c2ggdGhlIGN1cnJlbnQgYmxvY2sgKi9cbiAgICB9XG5cbiAgICAvKiBTZWUgaG93IG1hbnkgdGltZXMgdGhlIHByZXZpb3VzIGJ5dGUgcmVwZWF0cyAqL1xuICAgIHMubWF0Y2hfbGVuZ3RoID0gMDtcbiAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIICYmIHMuc3Ryc3RhcnQgPiAwKSB7XG4gICAgICBzY2FuID0gcy5zdHJzdGFydCAtIDE7XG4gICAgICBwcmV2ID0gX3dpbltzY2FuXTtcbiAgICAgIGlmIChwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSkge1xuICAgICAgICBzdHJlbmQgPSBzLnN0cnN0YXJ0ICsgTUFYX01BVENIO1xuICAgICAgICBkbyB7XG4gICAgICAgICAgLypqc2hpbnQgbm9lbXB0eTpmYWxzZSovXG4gICAgICAgIH0gd2hpbGUgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiZcbiAgICAgICAgICAgICAgICAgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJlxuICAgICAgICAgICAgICAgICBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmXG4gICAgICAgICAgICAgICAgIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiZcbiAgICAgICAgICAgICAgICAgc2NhbiA8IHN0cmVuZCk7XG4gICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUFYX01BVENIIC0gKHN0cmVuZCAtIHNjYW4pO1xuICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkge1xuICAgICAgICAgIHMub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hcnRdKTtcblxuICAgICAgcy5sb29rYWhlYWQtLTtcbiAgICAgIHMuc3Ryc3RhcnQrKztcbiAgICB9XG4gICAgaWYgKGJmbHVzaCkge1xuICAgICAgLyoqKiBGTFVTSF9CTE9DSyhzLCAwKTsgKioqL1xuICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7XG4gICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkge1xuICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFO1xuICAgICAgfVxuICAgICAgLyoqKi9cbiAgICB9XG4gIH1cbiAgcy5pbnNlcnQgPSAwO1xuICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7XG4gICAgLyoqKiBGTFVTSF9CTE9DSyhzLCAxKTsgKioqL1xuICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7XG4gICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHtcbiAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDtcbiAgICB9XG4gICAgLyoqKi9cbiAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7XG4gIH1cbiAgaWYgKHMubGFzdF9saXQpIHtcbiAgICAvKioqIEZMVVNIX0JMT0NLKHMsIDApOyAqKiovXG4gICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7XG4gICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHtcbiAgICAgIHJldHVybiBCU19ORUVEX01PUkU7XG4gICAgfVxuICAgIC8qKiovXG4gIH1cbiAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7XG59XG5cbi8qID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PVxuICogRm9yIFpfSFVGRk1BTl9PTkxZLCBkbyBub3QgbG9vayBmb3IgbWF0Y2hlcy4gIERvIG5vdCBtYWludGFpbiBhIGhhc2ggdGFibGUuXG4gK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2J5dGUocywgMTM5KTtcbiAgICAgIHB1dF9ieXRlKHMsIDgpO1xuICAgICAgaWYgKCFzLmd6aGVhZCkgeyAvLyBzLT5nemhlYWQgPT0gWl9OVUxMXG4gICAgICAgIHB1dF9ieXRlKHMsIDApO1xuICAgICAgICBwdXRfYnl0ZShzLCAwKTtcbiAgICAgICAgcHV0X2J5dGUocywgMCk7XG4gICAgICAgIHB1dF9ieXRlKHMsIDApO1xuICAgICAgICBwdXRfYnl0ZShzLCAwKTtcbiAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOlxuICAgICAgICAgICAgICAgICAgICAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMiA/XG4gICAgICAgICAgICAgICAgICAgICA0IDogMCkpO1xuICAgICAgICBwdXRfYnl0ZShzLCBPU19DT0RFKTtcbiAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFO1xuICAgICAgfVxuICAgICAgZWxzZSB7XG4gICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICtcbiAgICAgICAgICAgICAgICAgICAgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgK1xuICAgICAgICAgICAgICAgICAgICAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICtcbiAgICAgICAgICAgICAgICAgICAgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICtcbiAgICAgICAgICAgICAgICAgICAgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KVxuICAgICAgICApO1xuICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lICYgMHhmZik7XG4gICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50aW1lID4+IDgpICYgMHhmZik7XG4gICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50aW1lID4+IDE2KSAmIDB4ZmYpO1xuICAgICAgICBwdXRfYnl0ZShzLCAocy5nemhlYWQudGltZSA+PiAyNCkgJiAweGZmKTtcbiAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOlxuICAgICAgICAgICAgICAgICAgICAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMiA/XG4gICAgICAgICAgICAgICAgICAgICA0IDogMCkpO1xuICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5vcyAmIDB4ZmYpO1xuICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEgJiYgcy5nemhlYWQuZXh0cmEubGVuZ3RoKSB7XG4gICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmEubGVuZ3RoICYgMHhmZik7XG4gICAgICAgICAgcHV0X2J5dGUocywgKHMuZ3poZWFkLmV4dHJhLmxlbmd0aCA+PiA4KSAmIDB4ZmYpO1xuICAgICAgICB9XG4gICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7XG4gICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7XG4gICAgICAgIH1cbiAgICAgICAgcy5nemluZGV4ID0gMDtcbiAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTtcbiAgICAgIH1cbiAgICB9XG4gICAgZWxzZSAvLyBERUZMQVRFIGhlYWRlclxuICAgIHtcbiAgICAgIHZhciBoZWFkZXIgPSAoWl9ERUZMQVRFRCArICgocy53X2JpdHMgLSA4KSA8PCA0KSkgPDwgODtcbiAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xO1xuXG4gICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikge1xuICAgICAgICBsZXZlbF9mbGFncyA9IDA7XG4gICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPCA2KSB7XG4gICAgICAgIGxldmVsX2ZsYWd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cbiAgICAgIC8vaW50IHZhbDtcblxuICAgICAgZG8ge1xuICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHtcbiAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHtcbiAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7XG4gICAgICAgICAgfVxuICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7XG4gICAgICAgICAgYmVnID0gcy5wZW5kaW5nO1xuICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkge1xuICAgICAgICAgICAgdmFsID0gMTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICAvLyBKUyBzcGVjaWZpYzogbGl0dGxlIG1hZ2ljIHRvIGFkZCB6ZXJvIHRlcm1pbmF0b3IgdG8gZW5kIG9mIHN0cmluZ1xuICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHtcbiAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5uYW1lLmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMHhmZjtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB2YWwgPSAwO1xuICAgICAgICB9XG4gICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7XG4gICAgICB9IHdoaWxlICh2YWwgIT09IDApO1xuXG4gICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHtcbiAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTtcbiAgICAgIH1cbiAgICAgIGlmICh2YWwgPT09IDApIHtcbiAgICAgICAgcy5nemluZGV4ID0gMDtcbiAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFO1xuICAgICAgfVxuICAgIH1cbiAgICBlbHNlIHtcbiAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTtcbiAgICB9XG4gIH1cbiAgaWYgKHMuc3RhdHVzID09PSBDT01NRU5UX1NUQVRFKSB7XG4gICAgaWYgKHMuZ3poZWFkLmNvbW1lbnQvKiAhPSBaX05VTEwqLykge1xuICAgICAgYmVnID0gcy5wZW5kaW5nOyAgLyogc3RhcnQgb2YgYnl0ZXMgdG8gdXBkYXRlIGNyYyAqL1xuICAgICAgLy9pbnQgdmFsO1xuXG4gICAgICBkbyB7XG4gICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkge1xuICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykge1xuICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTtcbiAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7XG4gICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7XG4gICAgICAgICAgICB2YWwgPSAxO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIC8vIEpTIHNwZWNpZmljOiBsaXR0bGUgbWFnaWMgdG8gYWRkIHplcm8gdGVybWluYXRvciB0byBlbmQgb2Ygc3RyaW5nXG4gICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5jb21tZW50Lmxlbmd0aCkge1xuICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm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HMgLT0gb3A7XG4gICAgICBvcCA9IChoZXJlID4+PiAxNikgJiAweGZmLypoZXJlLm9wKi87XG4gICAgICBpZiAob3AgPT09IDApIHsgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIGxpdGVyYWwgKi9cbiAgICAgICAgLy9UcmFjZXZ2KChzdGRlcnIsIGhlcmUudmFsID49IDB4MjAgJiYgaGVyZS52YWwgPCAweDdmID9cbiAgICAgICAgLy8gICAgICAgIFwiaW5mbGF0ZTogICAgICAgICBsaXRlcmFsICclYydcXG5cIiA6XG4gICAgICAgIC8vICAgICAgICBcImluZmxhdGU6ICAgICAgICAgbGl0ZXJhbCAweCUwMnhcXG5cIiwgaGVyZS52YWwpKTtcbiAgICAgICAgb3V0cHV0W19vdXQrK10gPSBoZXJlICYgMHhmZmZmLypoZXJlLnZhbCovO1xuICAgICAgfVxuICAgICAgZWxzZSBpZiAob3AgJiAxNikgeyAgICAgICAgICAgICAgICAgICAgIC8qIGxlbmd0aCBiYXNlICovXG4gICAgICAgIGxlbiA9IGhlcmUgJiAweGZmZmYvKmhlcmUudmFsKi87XG4gICAgICAgIG9wICY9IDE1OyAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIG51bWJlciBvZiBleHRyYSBiaXRzICovXG4gICAgICAgIGlmIChvcCkge1xuICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHtcbiAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7XG4gICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgfVxuICAgICAgICAgIGxlbiArPSBob2xkICYgKCgxIDw8IG9wKSAtIDEpO1xuICAgICAgICAgIGhvbGQgPj4+PSBvcDtcbiAgICAgICAgICBiaXRzIC09IG9wO1xuICAgICAgICB9XG4gICAgICAgIC8vVHJhY2V2digoc3RkZXJyLCBcImluZmxhdGU6ICAgICAgICAgbGVuZ3RoICV1XFxuXCIsIGxlbikpO1xuICAgICAgICBpZiAoYml0cyA8IDE1KSB7XG4gICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0cztcbiAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0cztcbiAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgIH1cbiAgICAgICAgaGVyZSA9IGRjb2RlW2hvbGQgJiBkbWFza107XG5cbiAgICAgICAgZG9kaXN0OlxuICAgICAgICBmb3IgKDs7KSB7IC8vIGdvdG8gZW11bGF0aW9uXG4gICAgICAgICAgb3AgPSBoZXJlID4+PiAyNC8qaGVyZS5iaXRzKi87XG4gICAgICAgICAgaG9sZCA+Pj49IG9wO1xuICAgICAgICAgIGJpdHMgLT0gb3A7XG4gICAgICAgICAgb3AgPSAoaGVyZSA+Pj4gMTYpICYgMHhmZi8qaGVyZS5vcCovO1xuXG4gICAgICAgICAgaWYgKG9wICYgMTYpIHsgICAgICAgICAgICAgICAgICAgICAgLyogZGlzdGFuY2UgYmFzZSAqL1xuICAgICAgICAgICAgZGlzdCA9IGhlcmUgJiAweGZmZmYvKmhlcmUudmFsKi87XG4gICAgICAgICAgICBvcCAmPSAxNTsgICAgICAgICAgICAgICAgICAgICAgIC8qIG51bWJlciBvZiBleHRyYSBiaXRzICovXG4gICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7XG4gICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7XG4gICAgICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkge1xuICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7XG4gICAgICAgICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBkaXN0ICs9IGhvbGQgJiAoKDEgPDwgb3ApIC0gMSk7XG4vLyNpZmRlZiBJTkZMQVRFX1NUUklDVFxuICAgICAgICAgICAgaWYgKGRpc3QgPiBkbWF4KSB7XG4gICAgICAgICAgICAgIHN0cm0ubXNnID0gJ2ludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrJztcbiAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICAgICAgYnJlYWsgdG9wO1xuICAgICAgICAgICAgfVxuLy8jZW5kaWZcbiAgICAgICAgICAgIGhvbGQgPj4+PSBvcDtcbiAgICAgICAgICAgIGJpdHMgLT0gb3A7XG4gICAgICAgICAgICAvL1RyYWNldnYoKHN0ZGVyciwgXCJpbmZsYXRlOiAgICAgICAgIGRpc3RhbmNlICV1XFxuXCIsIGRpc3QpKTtcbiAgICAgICAgICAgIG9wID0gX291dCAtIGJlZzsgICAgICAgICAgICAgICAgLyogbWF4IGRpc3RhbmNlIGluIG91dHB1dCAqL1xuICAgICAgICAgICAgaWYgKGRpc3QgPiBvcCkgeyAgICAgICAgICAgICAgICAvKiBzZWUgaWYgY29weSBmcm9tIHdpbmRvdyAqL1xuICAgICAgICAgICAgICBvcCA9IGRpc3QgLSBvcDsgICAgICAgICAgICAgICAvKiBkaXN0YW5jZSBiYWNrIGluIHdpbmRvdyAqL1xuICAgICAgICAgICAgICBpZiAob3AgPiB3aGF2ZSkge1xuICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7XG4gICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICdpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayc7XG4gICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wO1xuICAgICAgICAgICAgICAgIH1cblxuLy8gKCEpIFRoaXMgYmxvY2sgaXMgZGlzYWJsZWQgaW4gemxpYiBkZWZhdWx0cyxcbi8vIGRvbid0IGVuYWJsZSBpdCBmb3IgYmluYXJ5IGNvbXBhdGliaWxpdHlcbi8vI2lmZGVmIElORkxBVEVfQUxMT1dfSU5WQUxJRF9ESVNUQU5DRV9UT09GQVJfQVJSUlxuLy8gICAgICAgICAgICAgICAgaWYgKGxlbiA8PSBvcCAtIHdoYXZlKSB7XG4vLyAgICAgICAgICAgICAgICAgIGRvIHtcbi8vICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IDA7XG4vLyAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tbGVuKTtcbi8vICAgICAgICAgICAgICAgICAgY29udGludWUgdG9wO1xuLy8gICAgICAgICAgICAgICAgfVxuLy8gICAgICAgICAgICAgICAgbGVuIC09IG9wIC0gd2hhdmU7XG4vLyAgICAgICAgICAgICAgICBkbyB7XG4vLyAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gMDtcbi8vICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3AgPiB3aGF2ZSk7XG4vLyAgICAgICAgICAgICAgICBpZiAob3AgPT09IDApIHtcbi8vICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0O1xuLy8gICAgICAgICAgICAgICAgICBkbyB7XG4vLyAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTtcbi8vICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1sZW4pO1xuLy8gICAgICAgICAgICAgICAgICBjb250aW51ZSB0b3A7XG4vLyAgICAgICAgICAgICAgICB9XG4vLyNlbmRpZlxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGZyb20gPSAwOyAvLyB3aW5kb3cgaW5kZXhcbiAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzX3dpbmRvdztcbiAgICAgICAgICAgICAgaWYgKHduZXh0ID09PSAwKSB7ICAgICAgICAgICAvKiB2ZXJ5IGNvbW1vbiBjYXNlICovXG4gICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSAtIG9wO1xuICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgeyAgICAgICAgIC8qIHNvbWUgZnJvbSB3aW5kb3cgKi9cbiAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDtcbiAgICAgICAgICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdO1xuICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7XG4gICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7ICAvKiByZXN0IGZyb20gb3V0cHV0ICovXG4gICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgZWxzZSBpZiAod25leHQgPCBvcCkgeyAgICAgIC8qIHdyYXAgYXJvdW5kIHdpbmRvdyAqL1xuICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgKyB3bmV4dCAtIG9wO1xuICAgICAgICAgICAgICAgIG9wIC09IHduZXh0O1xuICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgeyAgICAgICAgIC8qIHNvbWUgZnJvbSBlbmQgb2Ygd2luZG93ICovXG4gICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7XG4gICAgICAgICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApO1xuICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7XG4gICAgICAgICAgICAgICAgICBpZiAod25leHQgPCBsZW4pIHsgIC8qIHNvbWUgZnJvbSBzdGFydCBvZiB3aW5kb3cgKi9cbiAgICAgICAgICAgICAgICAgICAgb3AgPSB3bmV4dDtcbiAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wO1xuICAgICAgICAgICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdO1xuICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTtcbiAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OyAgICAgIC8qIHJlc3QgZnJvbSBvdXRwdXQgKi9cbiAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGVsc2UgeyAgICAgICAgICAgICAgICAgICAgICAvKiBjb250aWd1b3VzIGluIHdpbmRvdyAqL1xuICAgICAgICAgICAgICAgIGZyb20gKz0gd25leHQgLSBvcDtcbiAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsgICAgICAgICAvKiBzb21lIGZyb20gd2luZG93ICovXG4gICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7XG4gICAgICAgICAgICAgICAgICBkbyB7XG4gICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApO1xuICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OyAgLyogcmVzdCBmcm9tIG91dHB1dCAqL1xuICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHdoaWxlIChsZW4gPiAyKSB7XG4gICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdO1xuICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107XG4gICAgICAgICAgICAgICAgbGVuIC09IDM7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgaWYgKGxlbikge1xuICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkge1xuICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsgICAgICAgICAgLyogY29weSBkaXJlY3QgZnJvbSBvdXRwdXQgKi9cbiAgICAgICAgICAgICAgZG8geyAgICAgICAgICAgICAgICAgICAgICAgIC8qIG1pbmltdW0gbGVuZ3RoIGlzIHRocmVlICovXG4gICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdO1xuICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107XG4gICAgICAgICAgICAgICAgbGVuIC09IDM7XG4gICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiA+IDIpO1xuICAgICAgICAgICAgICBpZiAobGVuKSB7XG4gICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkge1xuICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7ICAgICAgICAgIC8qIDJuZCBsZXZlbCBkaXN0YW5jZSBjb2RlICovXG4gICAgICAgICAgICBoZXJlID0gZGNvZGVbKGhlcmUgJiAweGZmZmYpLypoZXJlLnZhbCovICsgKGhvbGQgJiAoKDEgPDwgb3ApIC0gMSkpXTtcbiAgICAgICAgICAgIGNvbnRpbnVlIGRvZGlzdDtcbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICBzdHJtLm1zZyA9ICdpbnZhbGlkIGRpc3RhbmNlIGNvZGUnO1xuICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICAgIGJyZWFrIHRvcDtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBicmVhazsgLy8gbmVlZCB0byBlbXVsYXRlIGdvdG8gdmlhIFwiY29udGludWVcIlxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsgICAgICAgICAgICAgIC8qIDJuZCBsZXZlbCBsZW5ndGggY29kZSAqL1xuICAgICAgICBoZXJlID0gbGNvZGVbKGhlcmUgJiAweGZmZmYpLypoZXJlLnZhbCovICsgKGhvbGQgJiAoKDEgPDwgb3ApIC0gMSkpXTtcbiAgICAgICAgY29udGludWUgZG9sZW47XG4gICAgICB9XG4gICAgICBlbHNlIGlmIChvcCAmIDMyKSB7ICAgICAgICAgICAgICAgICAgICAgLyogZW5kLW9mLWJsb2NrICovXG4gICAgICAgIC8vVHJhY2V2digoc3RkZXJyLCBcImluZmxhdGU6ICAgICAgICAgZW5kIG9mIGJsb2NrXFxuXCIpKTtcbiAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7XG4gICAgICAgIGJyZWFrIHRvcDtcbiAgICAgIH1cbiAgICAgIGVsc2Uge1xuICAgICAgICBzdHJtLm1zZyA9ICdpbnZhbGlkIGxpdGVyYWwvbGVuZ3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gYXJlIHVzZWQgZm9yIHNwZWNpYWwgYnV0IG5vcm1hbCBldmVudHMuXG4gKi9cbnZhciBaX09LICAgICAgICAgICAgPSAwO1xudmFyIFpfU1RSRUFNX0VORCAgICA9IDE7XG52YXIgWl9ORUVEX0RJQ1QgICAgID0gMjtcbi8vdmFyIFpfRVJSTk8gICAgICAgICA9IC0xO1xudmFyIFpfU1RSRUFNX0VSUk9SICA9IC0yO1xudmFyIFpfREFUQV9FUlJPUiAgICA9IC0zO1xudmFyIFpfTUVNX0VSUk9SICAgICA9IC00O1xudmFyIFpfQlVGX0VSUk9SICAgICA9IC01O1xuLy92YXIgWl9WRVJTSU9OX0VSUk9SID0gLTY7XG5cbi8qIFRoZSBkZWZsYXRlIGNvbXByZXNzaW9uIG1ldGhvZCAqL1xudmFyIFpfREVGTEFURUQgID0gODtcblxuXG4vKiBTVEFURVMgPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0qL1xuLyogPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ki9cblxuXG52YXIgICAgSEVBRCA9IDE7ICAgICAgIC8qIGk6IHdhaXRpbmcgZm9yIG1hZ2ljIGhlYWRlciAqL1xudmFyICAgIEZMQUdTID0gMjsgICAgICAvKiBpOiB3YWl0aW5nIGZvciBtZXRob2QgYW5kIGZsYWdzIChnemlwKSAqL1xudmFyICAgIFRJTUUgPSAzOyAgICAgICAvKiBpOiB3YWl0aW5nIGZvciBtb2RpZmljYXRpb24gdGltZSAoZ3ppcCkgKi9cbnZhciAgICBPUyA9IDQ7ICAgICAgICAgLyogaTogd2FpdGluZyBmb3IgZXh0cmEgZmxhZ3MgYW5kIG9wZXJhdGluZyBzeXN0ZW0gKGd6aXApICovXG52YXIgICAgRVhMRU4gPSA1OyAgICAgIC8qIGk6IHdhaXRpbmcgZm9yIGV4dHJhIGxl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gICBMRU5HVEggPSAyODsgICAgLyogaTogd2FpdGluZyBmb3IgMzItYml0IGxlbmd0aCAoZ3ppcCkgKi9cbnZhciAgICBET05FID0gMjk7ICAgICAgLyogZmluaXNoZWQgY2hlY2ssIGRvbmUgLS0gcmVtYWluIGhlcmUgdW50aWwgcmVzZXQgKi9cbnZhciAgICBCQUQgPSAzMDsgICAgICAgLyogZ290IGEgZGF0YSBlcnJvciAtLSByZW1haW4gaGVyZSB1bnRpbCByZXNldCAqL1xudmFyICAgIE1FTSA9IDMxOyAgICAgICAvKiBnb3QgYW4gaW5mbGF0ZSgpIG1lbW9yeSBlcnJvciAtLSByZW1haW4gaGVyZSB1bnRpbCByZXNldCAqL1xudmFyICAgIFNZTkMgPSAzMjsgICAgICAvKiBsb29raW5nIGZvciBzeW5jaHJvbml6YXRpb24gYnl0ZXMgdG8gcmVzdGFydCBpbmZsYXRlKCkgKi9cblxuLyogPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ki9cblxuXG5cbnZhciBFTk9VR0hfTEVOUyA9IDg1MjtcbnZhciBFTk9VR0hfRElTVFMgPSA1OTI7XG4vL3ZhciBFTk9VR0ggPSAgKEVOT1VHSF9MRU5TK0VOT1VHSF9ESVNUUyk7XG5cbnZhciBNQVhfV0JJVFMgPSAxNTtcbi8qIDMySyBMWjc3IHdpbmRvdyAqL1xudmFyIERFRl9XQklUUyA9IE1BWF9XQklUUztcblxuXG5mdW5jdGlvbiB6c3dhcDMyKHEpIHtcbiAgcmV0dXJuICAoKChxID4+PiAyNCkgJiAweGZmKSArXG4gICAgICAgICAgKChxID4+PiA4KSAmIDB4ZmYwMCkgK1xuICAgICAgICAgICgocSAmIDB4ZmYwMCkgPDwgOCkgK1xuICAgICAgICAgICgocSAmIDB4ZmYpIDw8IDI0KSk7XG59XG5cblxuZnVuY3Rpb24gSW5mbGF0ZVN0YXRlKCkge1xuICB0aGlzLm1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gICAgICAgICAgLy89PT0gSU5JVEJJVFMoKTtcbiAgICAgICAgICBob2xkID0gMDtcbiAgICAgICAgICBiaXRzID0gMDtcbiAgICAgICAgICAvLz09PS8vXG4gICAgICAgICAgc3RhdGUubW9kZSA9IEZMQUdTO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIHN0YXRlLmZsYWdzID0gMDsgICAgICAgICAgIC8qIGV4cGVjdCB6bGliIGhlYWRlciAqL1xuICAgICAgICBpZiAoc3RhdGUuaGVhZCkge1xuICAgICAgICAgIHN0YXRlLmhlYWQuZG9uZSA9IGZhbHNlO1xuICAgICAgICB9XG4gICAgICAgIGlmICghKHN0YXRlLndyYXAgJiAxKSB8fCAgIC8qIGNoZWNrIGlmIHpsaWIgaGVhZGVyIGFsbG93ZWQgKi9cbiAgICAgICAgICAoKChob2xkICYgMHhmZikvKkJJVFMoOCkqLyA8PCA4KSArIChob2xkID4+IDgpKSAlIDMxKSB7XG4gICAgICAgICAgc3RybS5tc2cgPSAnaW5jb3JyZWN0IGhlYWRlciBjaGVjayc7XG4gICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICBpZiAoKGhvbGQgJiAweDBmKS8qQklUUyg0KSovICE9PSBaX0RFRkxBVEVEKSB7XG4gICAgICAgICAgc3RybS5tc2cgPSAndW5rbm93biBjb21wcmVzc2lvbiBtZXRob2QnO1xuICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgLy8tLS0gRFJPUEJJVFMoNCkgLS0tLy9cbiAgICAgICAgaG9sZCA+Pj49IDQ7XG4gICAgICAgIGJpdHMgLT0gNDtcbiAgICAgICAgLy8tLS0vL1xuICAgICAgICBsZW4gPSAoaG9sZCAmIDB4MGYpLypCSVRTKDQpKi8gKyA4O1xuICAgICAgICBpZiAoc3RhdGUud2JpdHMgPT09IDApIHtcbiAgICAgICAgICBzdGF0ZS53Yml0cyA9IGxlbjtcbiAgICAgICAgfVxuICAgICAgICBlbHNlIGlmIChsZW4gPiBzdGF0ZS53Yml0cykge1xuICAgICAgICAgIHN0cm0ubXNnID0gJ2ludmFsaWQgd2luZG93IHNpemUnO1xuICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgc3RhdGUuZG1heCA9IDEgPDwgbGVuO1xuICAgICAgICAvL1RyYWNldigoc3RkZXJyLCBcImluZmxhdGU6ICAgemxpYiBoZWFkZXIgb2tcXG5cIikpO1xuICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAxLyphZGxlcjMyKDBMLCBaX05VTEwsIDApKi87XG4gICAgICAgIHN0YXRlLm1vZGUgPSBob2xkICYgMHgyMDAgPyBESUNUSUQgOiBUWVBFO1xuICAgICAgICAvLz09PSBJTklUQklUUygpO1xuICAgICAgICBob2xkID0gMDtcbiAgICAgICAgYml0cyA9IDA7XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgYnJlYWs7XG4gICAgICBjYXNlIEZMQUdTOlxuICAgICAgICAvLz09PSBORUVEQklUUygxNik7ICovXG4gICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHtcbiAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICB9XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgc3RhdGUuZmxhZ3MgPSBob2xkO1xuICAgICAgICBpZiAoKHN0YXRlLmZsYWdzICYgMHhmZikgIT09IFpfREVGTEFURUQpIHtcbiAgICAgICAgICBzdHJtLm1zZyA9ICd1bmtub3duIGNvbXByZXNzaW9uIG1ldGhvZCc7XG4gICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAweGUwMDApIHtcbiAgICAgICAgICBzdHJtLm1zZyA9ICd1bmtub3duIGhlYWRlciBmbGFncyBzZXQnO1xuICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHtcbiAgICAgICAgICBzdGF0ZS5oZWFkLnRleHQgPSAoKGhvbGQgPj4gOCkgJiAxKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAweDAyMDApIHtcbiAgICAgICAgICAvLz09PSBDUkMyKHN0YXRlLmNoZWNrLCBob2xkKTtcbiAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDB4ZmY7XG4gICAgICAgICAgaGJ1ZlsxXSA9IChob2xkID4+PiA4KSAmIDB4ZmY7XG4gICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7XG4gICAgICAgICAgLy89PT0vL1xuICAgICAgICB9XG4gICAgICAgIC8vPT09IElOSVRCSVRTKCk7XG4gICAgICAgIGhvbGQgPSAwO1xuICAgICAgICBiaXRzID0gMDtcbiAgICAgICAgLy89PT0vL1xuICAgICAgICBzdGF0ZS5tb2RlID0gVElNRTtcbiAgICAgICAgLyogZmFsbHMgdGhyb3VnaCAqL1xuICAgICAgY2FzZSBUSU1FOlxuICAgICAgICAvLz09PSBORUVEQklUUygzMik7ICovXG4gICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHtcbiAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICB9XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHtcbiAgICAgICAgICBzdGF0ZS5oZWFkLnRpbWUgPSBob2xkO1xuICAgICAgICB9XG4gICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDB4MDIwMCkge1xuICAgICAgICAgIC8vPT09IENSQzQoc3RhdGUuY2hlY2ssIGhvbGQpXG4gICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAweGZmO1xuICAgICAgICAgIGhidWZbMV0gPSAoaG9sZCA+Pj4gOCkgJiAweGZmO1xuICAgICAgICAgIGhidWZbMl0gPSAoaG9sZCA+Pj4gMTYpICYgMHhmZjtcbiAgICAgICAgICBoYnVmWzNdID0gKGhvbGQgPj4+IDI0KSAmIDB4ZmY7XG4gICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgNCwgMCk7XG4gICAgICAgICAgLy89PT1cbiAgICAgICAgfVxuICAgICAgICAvLz09PSBJTklUQklUUygpO1xuICAgICAgICBob2xkID0gMDtcbiAgICAgICAgYml0cyA9IDA7XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgc3RhdGUubW9kZSA9IE9TO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIE9TOlxuICAgICAgICAvLz09PSBORUVEQklUUygxNik7ICovXG4gICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHtcbiAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICB9XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHtcbiAgICAgICAgICBzdGF0ZS5oZWFkLnhmbGFncyA9IChob2xkICYgMHhmZik7XG4gICAgICAgICAgc3RhdGUuaGVhZC5vcyA9IChob2xkID4+IDgpO1xuICAgICAgICB9XG4gICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDB4MDIwMCkge1xuICAgICAgICAgIC8vPT09IENSQzIoc3RhdGUuY2hlY2ssIGhvbGQpO1xuICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMHhmZjtcbiAgICAgICAgICBoYnVmWzFdID0gKGhvbGQgPj4+IDgpICYgMHhmZjtcbiAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyKHN0YXRlLmNoZWNrLCBoYnVmLCAyLCAwKTtcbiAgICAgICAgICAvLz09PS8vXG4gICAgICAgIH1cbiAgICAgICAgLy89PT0gSU5JVEJJVFMoKTtcbiAgICAgICAgaG9sZCA9IDA7XG4gICAgICAgIGJpdHMgPSAwO1xuICAgICAgICAvLz09PS8vXG4gICAgICAgIHN0YXRlLm1vZGUgPSBFWExFTjtcbiAgICAgICAgLyogZmFsbHMgdGhyb3VnaCAqL1xuICAgICAgY2FzZSBFWExFTjpcbiAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMHgwNDAwKSB7XG4gICAgICAgICAgLy89PT0gTkVFREJJVFMoMTYpOyAqL1xuICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHtcbiAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkO1xuICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7XG4gICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhX2xlbiA9IGhvbGQ7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDB4MDIwMCkge1xuICAgICAgICAgICAgLy89PT0gQ1JDMihzdGF0ZS5jaGVjaywgaG9sZCk7XG4gICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDB4ZmY7XG4gICAgICAgICAgICBoYnVmWzFdID0gKGhvbGQgPj4+IDgpICYgMHhmZjtcbiAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApO1xuICAgICAgICAgICAgLy89PT0vL1xuICAgICAgICAgIH1cbiAgICAgICAgICAvLz09PSBJTklUQklUUygpO1xuICAgICAgICAgIGhvbGQgPSAwO1xuICAgICAgICAgIGJpdHMgPSAwO1xuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgfVxuICAgICAgICBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7XG4gICAgICAgICAgc3RhdGUuaGVhZC5leHRyYSA9IG51bGwvKlpfTlVMTCovO1xuICAgICAgICB9XG4gICAgICAgIHN0YXRlLm1vZGUgPSBFWFRSQTtcbiAgICAgICAgLyogZmFsbHMgdGhyb3VnaCAqL1xuICAgICAgY2FzZSBFWFRSQTpcbiAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMHgwNDAwKSB7XG4gICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDtcbiAgICAgICAgICBpZiAoY29weSA+IGhhdmUpIHsgY29weSA9IGhhdmU7IH1cbiAgICAgICAgICBpZiAoY29weSkge1xuICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHtcbiAgICAgICAgICAgICAgbGVuID0gc3RhdGUuaGVhZC5leHRyYV9sZW4gLSBzdGF0ZS5sZW5ndGg7XG4gICAgICAgICAgICAgIGlmICghc3RhdGUuaGVhZC5leHRyYSkge1xuICAgICAgICAgICAgICAgIC8vIFVzZSB1bnR5cGVkIGFycmF5IGZvciBtb3JlIGNvbnZlbmllbnQgcHJvY2Vzc2luZyBsYXRlclxuICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBuZXcgQXJyYXkoc3RhdGUuaGVhZC5leHRyYV9sZW4pO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KFxuICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEsXG4gICAgICAgICAgICAgICAgaW5wdXQsXG4gICAgICAgICAgICAgICAgbmV4dCxcbiAgICAgICAgICAgICAgICAvLyBleHRyYSBmaWVsZCBpcyBsaW1pdGVkIHRvIDY1NTM2IGJ5dGVzXG4gICAgICAgICAgICAgICAgLy8gLSBubyBuZWVkIGZvciBhZGRpdGlvbmFsIHNpemUgY2hlY2tcbiAgICAgICAgICAgICAgICBjb3B5LFxuICAgICAgICAgICAgICAgIC8qbGVuICsgY29weSA+IHN0YXRlLmhlYWQuZXh0cmFfbWF4IC0gbGVuID8gc3RhdGUuaGVhZC5leHRyYV9tYXggOiBjb3B5LCovXG4gICAgICAgICAgICAgICAgbGVuXG4gICAgICAgICAgICAgICk7XG4gICAgICAgICAgICAgIC8vem1lbWNweShzdGF0ZS5oZWFkLmV4dHJhICsgbGVuLCBuZXh0LFxuICAgICAgICAgICAgICAvLyAgICAgICAgbGVuICsgY29weSA+IHN0YXRlLmhlYWQuZXh0cmFfbWF4ID9cbiAgICAgICAgICAgICAgLy8gICAgICAgIHN0YXRlLmhlYWQuZXh0cmFfbWF4IC0gbGVuIDogY29weSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAweDAyMDApIHtcbiAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaGF2Z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V0LCBjb3B5LCBuZXh0KTtcbiAgICAgICAgICB9XG4gICAgICAgICAgaGF2ZSAtPSBjb3B5O1xuICAgICAgICAgIG5leHQgKz0gY29weTtcbiAgICAgICAgICBpZiAobGVuKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICB9XG4gICAgICAgIGVsc2UgaWYgKHN0YXRlLmhlYWQpIHtcbiAgICAgICAgICBzdGF0ZS5oZWFkLm5hbWUgPSBudWxsO1xuICAgICAgICB9XG4gICAgICAgIHN0YXRlLmxlbmd0aCA9IDA7XG4gICAgICAgIHN0YXRlLm1vZGUgPSBDT01NRU5UO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIENPTU1FTlQ6XG4gICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDB4MTAwMCkge1xuICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgIGNvcHkgPSAwO1xuICAgICAgICAgIGRvIHtcbiAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdO1xuICAgICAgICAgICAgLyogdXNlIGNvbnN0YW50IGxpbWl0IGJlY2F1c2UgaW4ganMgd2Ugc2hvdWxkIG5vdCBwcmVhbGxvY2F0ZSBtZW1vcnkgKi9cbiAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJlxuICAgICAgICAgICAgICAgIChzdGF0ZS5sZW5ndGggPCA2NTUzNiAvKnN0YXRlLmhlYWQuY29tbV9tYXgqLykpIHtcbiAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IHdoaWxlIChsZW4gJiYgY29weSA8IGhhdmUpO1xuICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDB4MDIwMCkge1xuICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBoYXZlIC09IGNvcHk7XG4gICAgICAgICAgbmV4dCArPSBjb3B5O1xuICAgICAgICAgIGlmIChsZW4pIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAoc3RhdGUuaGVhZCkge1xuICAgICAgICAgIHN0YXRlLmhlYWQuY29tbWVudCA9IG51bGw7XG4gICAgICAgIH1cbiAgICAgICAgc3RhdGUubW9kZSA9IEhDUkM7XG4gICAgICAgIC8qIGZhbGxzIHRocm91Z2ggKi9cbiAgICAgIGNhc2UgSENSQzpcbiAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMHgwMjAwKSB7XG4gICAgICAgICAgLy89PT0gTkVFREJJVFMoMTYpOyAqL1xuICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHtcbiAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICBpZiAoaG9sZCAhPT0gKHN0YXRlLmNoZWNrICYgMHhmZmZmKSkge1xuICAgICAgICAgICAgc3RybS5tc2cgPSAnaGVhZGVyIGNyYyBtaXNtYXRjaCc7XG4gICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vPT09IElOSVRCSVRTKCk7XG4gICAgICAgICAgaG9sZCA9IDA7XG4gICAgICAgICAgYml0cyA9IDA7XG4gICAgICAgICAgLy89PT0vL1xuICAgICAgICB9XG4gICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7XG4gICAgICAgICAgc3RhdGUuaGVhZC5oY3JjID0gKChzdGF0ZS5mbGFncyA+PiA5KSAmIDEpO1xuICAgICAgICAgIHN0YXRlLmhlYWQuZG9uZSA9IHRydWU7XG4gICAgICAgIH1cbiAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gMDtcbiAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7XG4gICAgICAgIGJyZWFrO1xuICAgICAgY2FzZSBESUNUSUQ6XG4gICAgICAgIC8vPT09IE5FRURCSVRTKDMyKTsgKi9cbiAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikge1xuICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgIGhhdmUtLTtcbiAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgIH1cbiAgICAgICAgLy89PT0vL1xuICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSB6c3dhcDMyKGhvbGQpO1xuICAgICAgICAvLz09PSBJTklUQklUUygpO1xuICAgICAgICBob2xkID0gMDtcbiAgICAgICAgYml0cyA9IDA7XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgc3RhdGUubW9kZSA9IERJQ1Q7XG4gICAgICAgIC8qIGZhbGxzIHRocm91Z2ggKi9cbiAgICAgIGNhc2UgRElDVDpcbiAgICAgICAgaWYgKHN0YXRlLmhhdmVkaWN0ID09PSAwKSB7XG4gICAgICAgICAgLy8tLS0gUkVTVE9SRSgpIC0tLVxuICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSBwdXQ7XG4gICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0O1xuICAgICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7XG4gICAgICAgICAgc3RybS5hdmFpbF9pbiA9IGhhdmU7XG4gICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7XG4gICAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7XG4gICAgICAgICAgLy8tLS1cbiAgICAgICAgICByZXR1cm4gWl9ORUVEX0RJQ1Q7XG4gICAgICAgIH1cbiAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gMS8qYWRsZXIzMigwTCwgWl9OVUxMLCAwKSovO1xuICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTtcbiAgICAgICAgLyogZmFsbHMgdGhyb3VnaCAqL1xuICAgICAgY2FzZSBUWVBFOlxuICAgICAgICBpZiAoZmx1c2ggPT09IFpfQkxPQ0sgfHwgZmx1c2ggPT09IFpfVFJFRVMpIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgIC8qIGZhbGxzIHRocm91Z2ggKi9cbiAgICAgIGNhc2UgVFlQRURPOlxuICAgICAgICBpZiAoc3RhdGUubGFzdCkge1xuICAgICAgICAgIC8vLS0tIEJZVEVCSVRTKCkgLS0tLy9cbiAgICAgICAgICBob2xkID4+Pj0gYml0cyAmIDc7XG4gICAgICAgICAgYml0cyAtPSBiaXRzICYgNztcbiAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgc3RhdGUubW9kZSA9IENIRUNLO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIC8vPT09IE5FRURCSVRTKDMpOyAqL1xuICAgICAgICB3aGlsZSAoYml0cyA8IDMpIHtcbiAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICB9XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgc3RhdGUubGFzdCA9IChob2xkICYgMHgwMSkvKkJJVFMoMSkqLztcbiAgICAgICAgLy8tLS0gRFJPUEJJVFMoMSkgLS0tLy9cbiAgICAgICAgaG9sZCA+Pj49IDE7XG4gICAgICAgIGJpdHMgLT0gMTtcbiAgICAgICAgLy8tLS0vL1xuXG4gICAgICAgIHN3aXRjaCAoKGhvbGQgJiAweDAzKS8qQklUUygyKSovKSB7XG4gICAgICAgICAgY2FzZSAwOiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLyogc3RvcmVkIGJsb2NrICovXG4gICAgICAgICAgICAvL1RyYWNldigoc3RkZXJyLCBcImluZmxhdGU6ICAgICBzdG9yZWQgYmxvY2slc1xcblwiLFxuICAgICAgICAgICAgLy8gICAgICAgIHN0YXRlLmxhc3QgPyBcIiAobGFzdClcIiA6IFwiXCIpKTtcbiAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBTVE9SRUQ7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlIDE6ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBmaXhlZCBibG9jayAqL1xuICAgICAgICAgICAgZml4ZWR0YWJsZXMoc3RhdGUpO1xuICAgICAgICAgICAgLy9UcmFjZXYoKHN0ZGVyciwgXCJpbmZsYXRlOiAgICAgZml4ZWQgY29kZXMgYmxvY2slc1xcblwiLFxuICAgICAgICAgICAgLy8gICAgICAgIHN0YXRlLmxhc3QgPyBcIiAobGFzdClcIiA6IFwiXCIpKTtcbiAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5fOyAgICAgICAgICAgICAvKiBkZWNvZGUgY29kZXMgKi9cbiAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykge1xuICAgICAgICAgICAgICAvLy0tLSBEUk9QQklUUygyKSAtLS0vL1xuICAgICAgICAgICAgICBob2xkID4+Pj0gMjtcbiAgICAgICAgICAgICAgYml0cyAtPSAyO1xuICAgICAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgMjogICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIGR5bmFtaWMgYmxvY2sgKi9cbiAgICAgICAgICAgIC8vVHJhY2V2KChzdGRlcnIsIFwiaW5mbGF0ZTogICAgIGR5bmFtaWMgY29kZXMgYmxvY2slc1xcblwiLFxuICAgICAgICAgICAgLy8gICAgICAgIHN0YXRlLmxhc3QgPyBcIiAobGFzdClcIiA6IFwiXCIpKTtcbiAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUQUJMRTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgMzpcbiAgICAgICAgICAgIHN0cm0ubXNnID0gJ2ludmFsaWQgYmxvY2sgdHlwZSc7XG4gICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICB9XG4gICAgICAgIC8vLS0tIERST1BCSVRTKDIpIC0tLS8vXG4gICAgICAgIGhvbGQgPj4+PSAyO1xuICAgICAgICBiaXRzIC09IDI7XG4gICAgICAgIC8vLS0tLy9cbiAgICAgICAgYnJlYWs7XG4gICAgICBjYXNlIFNUT1JFRDpcbiAgICAgICAgLy8tLS0gQllURUJJVFMoKSAtLS0vLyAvKiBnbyB0byBieXRlIGJvdW5kYXJ5ICovXG4gICAgICAgIGhvbGQgPj4+PSBiaXRzICYgNztcbiAgICAgICAgYml0cyAtPSBiaXRzICYgNztcbiAgICAgICAgLy8tLS0vL1xuICAgICAgICAvLz09PSBORUVEQklUUygzMik7ICovXG4gICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHtcbiAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICB9XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgaWYgKChob2xkICYgMHhmZmZmKSAhPT0gKChob2xkID4+PiAxNikgXiAweGZmZmYpKSB7XG4gICAgICAgICAgc3RybS5tc2cgPSAnaW52YWxpZCBzdG9yZWQgYmxvY2sgbGVuZ3Rocyc7XG4gICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkICYgMHhmZmZmO1xuICAgICAgICAvL1RyYWNldigoc3RkZXJyLCBcImluZmxhdGU6ICAgICAgIHN0b3JlZCBsZW5ndGggJXVcXG5cIixcbiAgICAgICAgLy8gICAgICAgIHN0YXRlLmxlbmd0aCkpO1xuICAgICAgICAvLz09PSBJTklUQklUUygpO1xuICAgICAgICBob2xkID0gMDtcbiAgICAgICAgYml0cyA9IDA7XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgc3RhdGUubW9kZSA9IENPUFlfO1xuICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgIC8qIGZhbGxzIHRocm91Z2ggKi9cbiAgICAgIGNhc2UgQ09QWV86XG4gICAgICAgIHN0YXRlLm1vZGUgPSBDT1BZO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIENPUFk6XG4gICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7XG4gICAgICAgIGlmIChjb3B5KSB7XG4gICAgICAgICAgaWYgKGNvcHkgPiBoYXZlKSB7IGNvcHkgPSBoYXZlOyB9XG4gICAgICAgICAgaWYgKGNvcHkgPiBsZWZ0KSB7IGNvcHkgPSBsZWZ0OyB9XG4gICAgICAgICAgaWYgKGNvcHkgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgLy8tLS0gem1lbWNweShwdXQsIG5leHQsIGNvcHkpOyAtLS1cbiAgICAgICAgICB1dGlscy5hcnJheVNldChvdXRwdXQsIGlucHV0LCBuZXh0LCBjb3B5LCBwdXQpO1xuICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICBoYXZlIC09IGNvcHk7XG4gICAgICAgICAgbmV4dCArPSBjb3B5O1xuICAgICAgICAgIGxlZnQgLT0gY29weTtcbiAgICAgICAgICBwdXQgKz0gY29weTtcbiAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgICAgICAvL1RyYWNldigoc3RkZXJyLCBcImluZmxhdGU6ICAgICAgIHN0b3JlZCBlbmRcXG5cIikpO1xuICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTtcbiAgICAgICAgYnJlYWs7XG4gICAgICBjYXNlIFRBQkxFOlxuICAgICAgICAvLz09PSBORUVEQklUUygxNCk7ICovXG4gICAgICAgIHdoaWxlIChiaXRzIDwgMTQpIHtcbiAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICB9XG4gICAgICAgIC8vPT09Ly9cbiAgICAgICAgc3RhdGUubmxlbiA9IChob2xkICYgMHgxZikvKkJJVFMoNSkqLyArIDI1NztcbiAgICAgICAgLy8tLS0gRFJPUEJJVFMoNSkgLS0tLy9cbiAgICAgICAgaG9sZCA+Pj49IDU7XG4gICAgICAgIGJpdHMgLT0gNTtcbiAgICAgICAgLy8tLS0vL1xuICAgICAgICBzdGF0ZS5uZGlzdCA9IChob2xkICYgMHgxZikvKkJJVFMoNSkqLyArIDE7XG4gICAgICAgIC8vLS0tIERST1BCSVRTKDUpIC0tLS8vXG4gICAgICAgIGhvbGQgPj4+PSA1O1xuICAgICAgICBiaXRzIC09IDU7XG4gICAgICAgIC8vLS0tLy9cbiAgICAgICAgc3RhdGUubmNvZGUgPSAoaG9sZCAmIDB4MGYpLypCSVRTKDQpKi8gKyA0O1xuICAgICAgICAvLy0tLSBEUk9QQklUUyg0KSAtLS0vL1xuICAgICAgICBob2xkID4+Pj0gNDtcbiAgICAgICAgYml0cyAtPSA0O1xuICAgICAgICAvLy0tLS8vXG4vLyNpZm5kZWYgUEtaSVBfQlVHX1dPUktBUk9VTkRcbiAgICAgICAgaWYgKHN0YXRlLm5sZW4gPiAyODYgfHwgc3RhdGUubmRpc3QgPiAzMCkge1xuICAgICAgICAgIHN0cm0ubXNnID0gJ3RvbyBtYW55IGxlbmd0aCBvciBkaXN0YW5jZSBzeW1ib2xzJztcbiAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4vLyNlbmRpZlxuICAgICAgICAvL1RyYWNldigoc3RkZXJyLCBcImluZmxhdGU6ICAgICAgIHRhYmxlIHNpemVzIG9rXFxuXCIpKTtcbiAgICAgICAgc3RhdGUuaGF2ZSA9IDA7XG4gICAgICAgIHN0YXRlLm1vZGUgPSBMRU5MRU5TO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIExFTkxFTlM6XG4gICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmNvZGUpIHtcbiAgICAgICAgICAvLz09PSBORUVEQklUUygzKTtcbiAgICAgICAgICB3aGlsZSAoYml0cyA8IDMpIHtcbiAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICBzdGF0ZS5sZW5z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gICAgICAgLy9UcmFjZXYoKHN0ZGVyciwgXCJpbmZsYXRlOiAgICAgICBjb2RlIGxlbmd0aHMgb2tcXG5cIikpO1xuICAgICAgICBzdGF0ZS5oYXZlID0gMDtcbiAgICAgICAgc3RhdGUubW9kZSA9IENPREVMRU5TO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIENPREVMRU5TOlxuICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IHN0YXRlLm5sZW4gKyBzdGF0ZS5uZGlzdCkge1xuICAgICAgICAgIGZvciAoOzspIHtcbiAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5sZW5jb2RlW2hvbGQgJiAoKDEgPDwgc3RhdGUubGVuYml0cykgLSAxKV07LypCSVRTKHN0YXRlLmxlbmJpdHMpKi9cbiAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0O1xuICAgICAgICAgICAgaGVyZV9vcCA9IChoZXJlID4+PiAxNikgJiAweGZmO1xuICAgICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgMHhmZmZmO1xuXG4gICAgICAgICAgICBpZiAoKGhlcmVfYml0cykgPD0gYml0cykgeyBicmVhazsgfVxuICAgICAgICAgICAgLy8tLS0gUFVMTEJZVEUoKSAtLS0vL1xuICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKGhlcmVfdmFsIDwgMTYpIHtcbiAgICAgICAgICAgIC8vLS0tIERST1BCSVRTKGhlcmUuYml0cykgLS0tLy9cbiAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7XG4gICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0cztcbiAgICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSsrXSA9IGhlcmVfdmFsO1xuICAgICAgICAgIH1cbiAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA9PT0gMTYpIHtcbiAgICAgICAgICAgICAgLy89PT0gTkVFREJJVFMoaGVyZS5iaXRzICsgMik7XG4gICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAyO1xuICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHtcbiAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICAgICAgYml0cyArPSA4O1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICAgICAgLy8tLS0gRFJPUEJJVFMoaGVyZS5iaXRzKSAtLS0vL1xuICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzO1xuICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0cztcbiAgICAgICAgICAgICAgLy8tLS0vL1xuICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSA9PT0gMCkge1xuICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gJ2ludmFsaWQgYml0IGxlbmd0aCByZXBlYXQnO1xuICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7XG4gICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgbGVuID0gc3RhdGUubGVuc1tzdGF0ZS5oYXZlIC0gMV07XG4gICAgICAgICAgICAgIGNvcHkgPSAzICsgKGhvbGQgJiAweDAzKTsvL0JJVFMoMik7XG4gICAgICAgICAgICAgIC8vLS0tIERST1BCSVRTKDIpIC0tLS8vXG4gICAgICAgICAgICAgIGhvbGQgPj4+PSAyO1xuICAgICAgICAgICAgICBiaXRzIC09IDI7XG4gICAgICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2UgaWYgKGhlcmVfdmFsID09PSAxNykge1xuICAgICAgICAgICAgICAvLz09PSBORUVEQklUUyhoZXJlLmJpdHMgKyAzKTtcbiAgICAgICAgICAgICAgbiA9IGhlcmVfYml0cyArIDM7XG4gICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikge1xuICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgICAgICAgIGhhdmUtLTtcbiAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgLy89PT0vL1xuICAgICAgICAgICAgICAvLy0tLSBEUk9QQklUUyhoZXJlLmJpdHMpIC0tLS8vXG4gICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7XG4gICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzO1xuICAgICAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgICAgIGxlbiA9IDA7XG4gICAgICAgICAgICAgIGNvcHkgPSAzICsgKGhvbGQgJiAweDA3KTsvL0JJVFMoMyk7XG4gICAgICAgICAgICAgIC8vLS0tIERST1BCSVRTKDMpIC0tLS8vXG4gICAgICAgICAgICAgIGhvbGQgPj4+PSAzO1xuICAgICAgICAgICAgICBiaXRzIC09IDM7XG4gICAgICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAvLz09PSBORUVEQklUUyhoZXJlLmJpdHMgKyA3KTtcbiAgICAgICAgICAgICAgbiA9IGhlcmVfYml0cyArIDc7XG4gICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikge1xuICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgICAgICAgIGhhdmUtLTtcbiAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgLy89PT0vL1xuICAgICAgICAgICAgICAvLy0tLSBEUk9QQklUUyhoZXJlLmJpdHMpIC0tLS8vXG4gICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7XG4gICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzO1xuICAgICAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgICAgIGxlbiA9IDA7XG4gICAgICAgICAgICAgIGNvcHkgPSAxMSArIChob2xkICYgMHg3Zik7Ly9CSVRTKDcpO1xuICAgICAgICAgICAgICAvLy0tLSBEUk9QQklUUyg3KSAtLS0vL1xuICAgICAgICAgICAgICBob2xkID4+Pj0gNztcbiAgICAgICAgICAgICAgYml0cyAtPSA3O1xuICAgICAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSArIGNvcHkgPiBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHtcbiAgICAgICAgICAgICAgc3RybS5tc2cgPSAnaW52YWxpZCBiaXQgbGVuZ3RoIHJlcGVhdCc7XG4gICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7XG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgd2hpbGUgKGNvcHktLSkge1xuICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YX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KSB7XG4gICAgICAgICAgc3RybS5tc2cgPSAnaW52YWxpZCBkaXN0YW5jZXMgc2V0JztcbiAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgICB9XG4gICAgICAgIC8vVHJhY2V2KChzdGRlcnIsICdpbmZsYXRlOiAgICAgICBjb2RlcyBva1xcbicpKTtcbiAgICAgICAgc3RhdGUubW9kZSA9IExFTl87XG4gICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgLyogZmFsbHMgdGhyb3VnaCAqL1xuICAgICAgY2FzZSBMRU5fOlxuICAgICAgICBzdGF0ZS5tb2RlID0gTEVOO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIExFTjpcbiAgICAgICAgaWYgKGhhdmUgPj0gNiAmJiBsZWZ0ID49IDI1OCkge1xuICAgICAgICAgIC8vLS0tIFJFU1RPUkUoKSAtLS1cbiAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0O1xuICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gbGVmdDtcbiAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0O1xuICAgICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlO1xuICAgICAgICAgIHN0YXRlLmhvbGQgPSBob2xkO1xuICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzO1xuICAgICAgICAgIC8vLS0tXG4gICAgICAgICAgaW5mbGF0ZV9mYXN0KHN0cm0sIF9vdXQpO1xuICAgICAgICAgIC8vLS0tIExPQUQoKSAtLS1cbiAgICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0O1xuICAgICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0O1xuICAgICAgICAgIGxlZnQgPSBzdHJtLmF2YWlsX291dDtcbiAgICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luO1xuICAgICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDtcbiAgICAgICAgICBoYXZlID0gc3RybS5hdmFpbF9pbjtcbiAgICAgICAgICBob2xkID0gc3RhdGUuaG9sZDtcbiAgICAgICAgICBiaXRzID0gc3RhdGUuYml0cztcbiAgICAgICAgICAvLy0tLVxuXG4gICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHtcbiAgICAgICAgICAgIHN0YXRlLmJhY2sgPSAtMTtcbiAgICAgICAgICB9XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgc3RhdGUuYmFjayA9IDA7XG4gICAgICAgIGZvciAoOzspIHtcbiAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtob2xkICYgKCgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMSldOyAgLypCSVRTKHN0YXRlLmxlbmJpdHMpKi9cbiAgICAgICAgICBoZXJlX2JpdHMgPSBoZXJlID4+PiAyNDtcbiAgICAgICAgICBoZXJlX29wID0gKGhlcmUgPj4+IDE2KSAmIDB4ZmY7XG4gICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgMHhmZmZmO1xuXG4gICAgICAgICAgaWYgKGhlcmVfYml0cyA8PSBiaXRzKSB7IGJyZWFrOyB9XG4gICAgICAgICAgLy8tLS0gUFVMTEJZVEUoKSAtLS0vL1xuICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgIGhhdmUtLTtcbiAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgLy8tLS0vL1xuICAgICAgICB9XG4gICAgICAgIGlmIChoZXJlX29wICYmIChoZXJlX29wICYgMHhmMCkgPT09IDApIHtcbiAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7XG4gICAgICAgICAgbGFzdF9vcCA9IGhlcmVfb3A7XG4gICAgICAgICAgbGFzdF92YWwgPSBoZXJlX3ZhbDtcbiAgICAgICAgICBmb3IgKDs7KSB7XG4gICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtsYXN0X3ZhbCArXG4gICAgICAgICAgICAgICAgICAgICgoaG9sZCAmICgoMSA8PCAobGFzdF9iaXRzICsgbGFzdF9vcCkpIC0gMSkpLypCSVRTKGxhc3QuYml0cyArIGxhc3Qub3ApKi8gPj4gbGFzdF9iaXRzKV07XG4gICAgICAgICAgICBoZXJlX2JpdHMgPSBoZXJlID4+PiAyNDtcbiAgICAgICAgICAgIGhlcmVfb3AgPSAoaGVyZSA+Pj4gMTYpICYgMHhmZjtcbiAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDB4ZmZmZjtcblxuICAgICAgICAgICAgaWYgKChsYXN0X2JpdHMgKyBoZXJlX2JpdHMpIDw9IGJpdHMpIHsgYnJlYWs7IH1cbiAgICAgICAgICAgIC8vLS0tIFBVTExCWVRFKCkgLS0tLy9cbiAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgICAgaGF2ZS0tO1xuICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgICAvLy0tLS8vXG4gICAgICAgICAgfVxuICAgICAgICAgIC8vLS0tIERST1BCSVRTKGxhc3QuYml0cykgLS0tLy9cbiAgICAgICAgICBob2xkID4+Pj0gbGFzdF9iaXRzO1xuICAgICAgICAgIGJpdHMgLT0gbGFzdF9iaXRzO1xuICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICBzdGF0ZS5iYWNrICs9IGxhc3RfYml0cztcbiAgICAgICAgfVxuICAgICAgICAvLy0tLSBEUk9QQklUUyhoZXJlLmJpdHMpIC0tLS8vXG4gICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7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hUOlxuICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHtcbiAgICAgICAgICAvLz09PSBORUVEQklUUyhzdGF0ZS5leHRyYSk7XG4gICAgICAgICAgbiA9IHN0YXRlLmV4dHJhO1xuICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikge1xuICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgICB9XG4gICAgICAgICAgLy89PT0vL1xuICAgICAgICAgIHN0YXRlLmxlbmd0aCArPSBob2xkICYgKCgxIDw8IHN0YXRlLmV4dHJhKSAtIDEpLypCSVRTKHN0YXRlLmV4dHJhKSovO1xuICAgICAgICAgIC8vLS0tIERST1BCSVRTKHN0YXRlLmV4dHJhKSAtLS0vL1xuICAgICAgICAgIGhvbGQgPj4+PSBzdGF0ZS5leHRyYTtcbiAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhO1xuICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhO1xuICAgICAgICB9XG4gICAgICAgIC8vVHJhY2V2digoc3RkZXJyLCBcImluZmxhdGU6ICAgICAgICAgbGVuZ3RoICV1XFxuXCIsIHN0YXRlLmxlbmd0aCkpO1xuICAgICAgICBzdGF0ZS53YXMgPSBzdGF0ZS5sZW5ndGg7XG4gICAgICAgIHN0YXRlLm1vZGUgPSBESVNUO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIERJU1Q6XG4gICAgICAgIGZvciAoOzspIHtcbiAgICAgICAgICBoZXJlID0gc3RhdGUuZGlzdGNvZGVbaG9sZCAmICgoMSA8PCBzdGF0ZS5kaXN0Yml0cykgLSAxKV07LypCSVRTKHN0YXRlLmRpc3RiaXRzKSovXG4gICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7XG4gICAgICAgICAgaGVyZV9vcCA9IChoZXJlID4+PiAxNikgJiAweGZmO1xuICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDB4ZmZmZjtcblxuICAgICAgICAgIGlmICgoaGVyZV9iaXRzKSA8PSBiaXRzKSB7IGJyZWFrOyB9XG4gICAgICAgICAgLy8tLS0gUFVMTEJZVEUoKSAtLS0vL1xuICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7IGJyZWFrIGluZl9sZWF2ZTsgfVxuICAgICAgICAgIGhhdmUtLTtcbiAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgLy8tLS0vL1xuICAgICAgICB9XG4gICAgICAgIGlmICgoaGVyZV9vcCAmIDB4ZjApID09PSAwKSB7XG4gICAgICAgICAgbGFzdF9iaXRzID0gaGVyZV9iaXRzO1xuICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wO1xuICAgICAgICAgIGxhc3RfdmFsID0gaGVyZV92YWw7XG4gICAgICAgICAgZm9yICg7Oykge1xuICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmRpc3Rjb2RlW2xhc3RfdmFsICtcbiAgICAgICAgICAgICAgICAgICAgKChob2xkICYgKCgxIDw8IChsYXN0X2JpdHMgKyBsYXN0X29wKSkgLSAxKSkvKkJJVFMobGFzdC5iaXRzICsgbGFzdC5vcCkqLyA+PiBsYXN0X2JpdHMpXTtcbiAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0O1xuICAgICAgICAgICAgaGVyZV9vcCA9IChoZXJlID4+PiAxNikgJiAweGZmO1xuICAgICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgMHhmZmZmO1xuXG4gICAgICAgICAgICBpZiAoKGxhc3RfYml0cyArIGhlcmVfYml0cykgPD0gYml0cykgeyBicmVhazsgfVxuICAgICAgICAgICAgLy8tLS0gUFVMTEJZVEUoKSAtLS0vL1xuICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgICAgIC8vLS0tLy9cbiAgICAgICAgICB9XG4gICAgICAgICAgLy8tLS0gRFJPUEJJVFMobGFzdC5iaXRzKSAtLS0vL1xuICAgICAgICAgIGhvbGQgPj4+PSBsYXN0X2JpdHM7XG4gICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7XG4gICAgICAgICAgLy8tLS0vL1xuICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzO1xuICAgICAgICB9XG4gICAgICAgIC8vLS0tIERST1BCSVRTKGhlcmUuYml0cykgLS0tLy9cbiAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0cztcbiAgICAgICAgYml0cyAtPSBoZXJlX2JpdHM7XG4gICAgICAgIC8vLS0tLy9cbiAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7XG4gICAgICAgIGlmIChoZXJlX29wICYgNjQpIHtcbiAgICAgICAgICBzdHJtLm1zZyA9ICdpbnZhbGlkIGRpc3RhbmNlIGNvZGUnO1xuICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7XG4gICAgICAgICAgYnJlYWs7XG4gICAgICAgIH1cbiAgICAgICAgc3RhdGUub2Zmc2V0ID0gaGVyZV92YWw7XG4gICAgICAgIHN0YXRlLmV4dHJhID0gKGhlcmVfb3ApICYgMTU7XG4gICAgICAgIHN0YXRlLm1vZGUgPSBESVNURVhUO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIERJU1RFWFQ6XG4gICAgICAgIGlmIChzdGF0ZS5leHRy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cHk7XG4vLyAgICAgICAgICBkbyB7XG4vLyAgICAgICAgICAgIG91dHB1dFtwdXQrK10gPSAwO1xuLy8gICAgICAgICAgfSB3aGlsZSAoLS1jb3B5KTtcbi8vICAgICAgICAgIGlmIChzdGF0ZS5sZW5ndGggPT09IDApIHsgc3RhdGUubW9kZSA9IExFTjsgfVxuLy8gICAgICAgICAgYnJlYWs7XG4vLyNlbmRpZlxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLnduZXh0KSB7XG4gICAgICAgICAgICBjb3B5IC09IHN0YXRlLnduZXh0O1xuICAgICAgICAgICAgZnJvbSA9IHN0YXRlLndzaXplIC0gY29weTtcbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICBmcm9tID0gc3RhdGUud25leHQgLSBjb3B5O1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLmxlbmd0aCkgeyBjb3B5ID0gc3RhdGUubGVuZ3RoOyB9XG4gICAgICAgICAgZnJvbV9zb3VyY2UgPSBzdGF0ZS53aW5kb3c7XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLyogY29weSBmcm9tIG91dHB1dCAqL1xuICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0O1xuICAgICAgICAgIGZyb20gPSBwdXQgLSBzdGF0ZS5vZmZzZXQ7XG4gICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDtcbiAgICAgICAgfVxuICAgICAgICBpZiAoY29weSA+IGxlZnQpIHsgY29weSA9IGxlZnQ7IH1cbiAgICAgICAgbGVmdCAtPSBjb3B5O1xuICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTtcbiAgICAgICAgZG8ge1xuICAgICAgICAgIG91dHB1dFtwdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdO1xuICAgICAgICB9IHdoaWxlICgtLWNvcHkpO1xuICAgICAgICBpZiAoc3RhdGUubGVuZ3RoID09PSAwKSB7IHN0YXRlLm1vZGUgPSBMRU47IH1cbiAgICAgICAgYnJlYWs7XG4gICAgICBjYXNlIExJVDpcbiAgICAgICAgaWYgKGxlZnQgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgIG91dHB1dFtwdXQrK10gPSBzdGF0ZS5sZW5ndGg7XG4gICAgICAgIGxlZnQtLTtcbiAgICAgICAgc3RhdGUubW9kZSA9IExFTjtcbiAgICAgICAgYnJlYWs7XG4gICAgICBjYXNlIENIRUNLOlxuICAgICAgICBpZiAoc3RhdGUud3JhcCkge1xuICAgICAgICAgIC8vPT09IE5FRURCSVRTKDMyKTtcbiAgICAgICAgICB3aGlsZSAoYml0cyA8IDMyKSB7XG4gICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgeyBicmVhayBpbmZfbGVhdmU7IH1cbiAgICAgICAgICAgIGhhdmUtLTtcbiAgICAgICAgICAgIC8vIFVzZSAnfCcgaW5zdGVhZCBvZiAnKycgdG8gbWFrZSBzdXJlIHRoYXQgcmVzdWx0IGlzIHNpZ25lZFxuICAgICAgICAgICAgaG9sZCB8PSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7XG4gICAgICAgICAgICBiaXRzICs9IDg7XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICBfb3V0IC09IGxlZnQ7XG4gICAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDtcbiAgICAgICAgICBzdGF0ZS50b3RhbCArPSBfb3V0O1xuICAgICAgICAgIGlmIChfb3V0KSB7XG4gICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPVxuICAgICAgICAgICAgICAgIC8qVVBEQVRFKHN0YXRlLmNoZWNrLCBwdXQgLSBfb3V0LCBfb3V0KTsqL1xuICAgICAgICAgICAgICAgIChzdGF0ZS5mbGFncyA/IGNyYzMyKHN0YXRlLmNoZWNrLCBvdXRwdXQsIF9vdXQsIHB1dCAtIF9vdXQpIDogYWRsZXIzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSk7XG5cbiAgICAgICAgICB9XG4gICAgICAgICAgX291dCA9IGxlZnQ7XG4gICAgICAgICAgLy8gTkI6IGNyYzMyIHN0b3JlZCBhcyBzaWduZWQgMzItYml0IGludCwgenN3YXAzMiByZXR1cm5zIHNpZ25lZCB0b29cbiAgICAgICAgICBpZiAoKHN0YXRlLmZsYWdzID8gaG9sZCA6IHpzd2FwMzIoaG9sZCkpICE9PSBzdGF0ZS5jaGVjaykge1xuICAgICAgICAgICAgc3RybS5tc2cgPSAnaW5jb3JyZWN0IGRhdGEgY2hlY2snO1xuICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIH1cbiAgICAgICAgICAvLz09PSBJTklUQklUUygpO1xuICAgICAgICAgIGhvbGQgPSAwO1xuICAgICAgICAgIGJpdHMgPSAwO1xuICAgICAgICAgIC8vPT09Ly9cbiAgICAgICAgICAvL1RyYWNldigoc3RkZXJyLCBcImluZmxhdGU6ICAgY2hlY2sgbWF0Y2hlcyB0cmFpbGVyXFxuXCIpKTtcbiAgICAgICAgfVxuICAgICAgICBzdGF0ZS5tb2RlID0gTEVOR1RIO1xuICAgICAgICAvKiBmYWxscyB0aHJvdWdoICovXG4gICAgICBjYXNlIExFTkdUSDpcbiAgICAgICAgaWYgKHN0YXRlLndyYXAgJiYgc3RhdGUuZmxhZ3MpIHtcbiAgICAgICAgICAvLz09PSBORUVEQklUUygzMik7XG4gICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikge1xuICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsgYnJlYWsgaW5mX2xlYXZlOyB9XG4gICAgICAgICAgICBoYXZlLS07XG4gICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0cztcbiAgICAgICAgICAgIGJpdHMgKz0gODtcbiAgICAgICAgICB9XG4gICAgICAgICAgLy89PT0vL1xuICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiAweGZmZmZmZmZmKSkge1xuICAgICAgICAgICAgc3RybS5tc2cgPSAnaW5jb3JyZWN0IGxlbmd0aCBjaGVjayc7XG4gICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vPT09IElOSVRCSVRTKCk7XG4gICAgICAgICAgaG9sZCA9IDA7XG4gICAgICAgICAgYml0cyA9IDA7XG4gICAgICAgICAgLy89PT0vL1xuICAgICAgICAgIC8vVHJhY2V2KChzdGRlcnIsIFwiaW5mbGF0ZTogICBsZW5ndGggbWF0Y2hlcyB0cmFpbGVyXFxuXCIpKTtcbiAgICAgICAgfVxuICAgICAgICBzdGF0ZS5tb2RlID0gRE9ORTtcbiAgICAgICAgLyogZmFsbHMgdGhyb3VnaCAqL1xuICAgICAgY2FzZSBET05FOlxuICAgICAgICByZXQgPSBaX1NUUkVBTV9FTkQ7XG4gICAgICAgIGJyZWFrIGluZl9sZWF2ZTtcbiAgICAgIGNhc2UgQkFEOlxuICAgICAgICByZXQgPSBaX0RBVEFfRVJST1I7XG4gICAgICAgIGJyZWFrIGluZl9sZWF2ZTtcbiAgICAgIGNhc2UgTUVNOlxuICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7XG4gICAgICBjYXNlIFNZTkM6XG4gICAgICAgIC8qIGZhbGxzIHRocm91Z2ggKi9cbiAgICAgIGRlZmF1bHQ6XG4gICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjtcbiAgICB9XG4gIH1cblxuICAvLyBpbmZfbGVhdmUgPC0gaGVyZSBpcyByZWFsIHBsYWNlIGZvciBcImdvdG8gaW5mX2xlYXZlXCIsIGVtdWxhdGVkIHZpYSBcImJyZWFrIGluZl9sZWF2ZVwi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kZXggLT0gMjU3O1xuICAgIGVuZCA9IDI1NjtcblxuICB9IGVsc2UgeyAgICAgICAgICAgICAgICAgICAgLyogRElTVFMgKi9cbiAgICBiYXNlID0gZGJhc2U7XG4gICAgZXh0cmEgPSBkZXh0O1xuICAgIGVuZCA9IC0xO1xuICB9XG5cbiAgLyogaW5pdGlhbGl6ZSBvcHRzIGZvciBsb29wICovXG4gIGh1ZmYgPSAwOyAgICAgICAgICAgICAgICAgICAvKiBzdGFydGluZyBjb2RlICovXG4gIHN5bSA9IDA7ICAgICAgICAgICAgICAgICAgICAvKiBzdGFydGluZyBjb2RlIHN5bWJvbCAqL1xuICBsZW4gPSBtaW47ICAgICAgICAgICAgICAgICAgLyogc3RhcnRpbmcgY29kZSBsZW5ndGggKi9cbiAgbmV4dCA9IHRhYmxlX2luZGV4OyAgICAgICAgICAgICAgLyogY3VycmVudCB0YWJsZSB0byBmaWxsIGluICovXG4gIGN1cnIgPSByb290OyAgICAgICAgICAgICAgICAvKiBjdXJyZW50IHRhYmxlIGluZGV4IGJpdHMgKi9cbiAgZHJvcCA9IDA7ICAgICAgICAgICAgICAgICAgIC8qIGN1cnJlbnQgYml0cyB0byBkcm9wIGZyb20gY29kZSBmb3IgaW5kZXggKi9cbiAgbG93ID0gLTE7ICAgICAgICAgICAgICAgICAgIC8qIHRyaWdnZXIgbmV3IHN1Yi10YWJsZSB3aGVuIGxlbiA+IHJvb3QgKi9cbiAgdXNlZCA9IDEgPDwgcm9vdDsgICAgICAgICAgLyogdXNlIHJvb3QgdGFibGUgZW50cmllcyAqL1xuICBtYXNrID0gdXNlZCAtIDE7ICAgICAgICAgICAgLyogbWFzayBmb3IgY29tcGFyaW5nIGxvdyAqL1xuXG4gIC8qIGNoZWNrIGF2YWlsYWJsZSB0YWJsZSBzcGFjZSAqL1xuICBpZiAoKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TKSB8fFxuICAgICh0eXBlID09PSBESVNUUyAmJiB1c2Vk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ZJWEVEICAgICAgICAgICAgICAgPSA0O1xuLy92YXIgWl9ERUZBVUxUX1NUUkFURUdZICA9IDA7XG5cbi8qIFBvc3NpYmxlIHZhbHVlcyBvZiB0aGUgZGF0YV90eXBlIGZpZWxkICh0aG91Z2ggc2VlIGluZmxhdGUoKSkgKi9cbnZhciBaX0JJTkFSWSAgICAgICAgICAgICAgPSAwO1xudmFyIFpfVEVYVCAgICAgICAgICAgICAgICA9IDE7XG4vL3ZhciBaX0FTQ0lJICAgICAgICAgICAgID0gMTsgLy8gPSBaX1RFWFRcbnZhciBaX1VOS05PV04gICAgICAgICAgICAgPSAyO1xuXG4vKj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0qL1xuXG5cbmZ1bmN0aW9uIHplcm8oYnVmKSB7IHZhciBsZW4gPSBidWYubGVuZ3RoOyB3aGlsZSAoLS1sZW4gPj0gMCkgeyBidWZbbGVuXSA9IDA7IH0gfVxuXG4vLyBGcm9tIHp1dGlsLmhcblxudmFyIFNUT1JFRF9CTE9DSyA9IDA7XG52YXIgU1RBVElDX1RSRUVTID0gMTtcbnZhciBEWU5fVFJFRVMgICAgPSAyO1xuLyogVGhlIHRocmVlIGtpbmRzIG9mIGJsb2NrIHR5cGUgKi9cblxudmFyIE1JTl9NQVRDSCAgICA9IDM7XG52YXIgTUFYX01BVENIICAgID0gMjU4O1xuLyogVGhlIG1pbmltdW0gYW5kIG1heGltdW0gbWF0Y2ggbGVuZ3RocyAqL1xuXG4vLyBGcm9tIGRlZmxhdGUuaFxuLyogPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09XG4gKiBJbnRlcm5hbCBjb21wcmVzc2lvbiBzdGF0ZS5cbiAqL1xuXG52YXIgTEVOR1RIX0NPREVTICA9IDI5O1xuLyogbnVtYmVyIG9mIGxlbmd0aCBjb2Rl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XkoMCksIGV4dHJhX2JsYml0cywgMCwgICAgICAgICBCTF9DT0RFUywgTUFYX0JMX0JJVFMpO1xuXG4gIC8vc3RhdGljX2luaXRfZG9uZSA9IHRydWU7XG59XG5cblxuLyogPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09XG4gKiBJbml0aWFsaXplIGEgbmV3IGJsb2NrLlxuICovXG5mdW5jdGlvbiBpbml0X2Jsb2NrKHMpIHtcbiAgdmFyIG47IC8qIGl0ZXJhdGVzIG92ZXIgdHJlZSBlbGVtZW50cyAqL1xuXG4gIC8qIEluaXRpYWxpemUgdGhlIHRyZWVzLiAqL1xuICBmb3IgKG4gPSAwOyBuIDwgTF9DT0RFUzsgIG4rKykgeyBzLmR5bl9sdHJlZVtuICogMl0vKi5GcmVxKi8gPSAwOyB9XG4gIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyAgbisrKSB7IHMuZHluX2R0cmVlW24gKiAyXS8qLkZyZXEqLyA9IDA7IH1cbiAgZm9yIChuID0gMDsgbiA8IEJMX0NPREVTOyBuKyspIHsgcy5ibF90cmVlW24gKiAyXS8qLkZyZXEqLyA9IDA7IH1cblxuICBzLmR5bl9sdHJlZVtFTkRfQkxPQ0sgKiAyXS8qLkZyZXEqLyA9IDE7XG4gIHMub3B0X2xlbiA9IHMuc3RhdGljX2xlbiA9IDA7XG4gIHMubGFzdF9saXQgPSBzLm1hdGNoZXMgPSAwO1xufVxuXG5cbi8qID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PVxuICogRmx1c2ggdGhlIGJpdCBidWZmZXIgYW5kIGFsaWduIHRoZSBvdXRwdXQgb24gYSBieXRlIGJvdW5kYXJ5XG4gKi9cbmZ1bmN0aW9uIGJpX3dpbmR1cChzKVxue1xuICBpZiAocy5iaV92YWxpZCA+IDgpIHtcbiAgICBw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JzZXQgPSAnaXNvLTg4NTktMSc7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHNraXBJbmRleCA9IGk7XG4gICAgICAgICAgICAgICAgaSA9IHBhcnRzLmxlbmd0aDsgLy8gVGhlIGVzbGludCBzZXR0aW5ncyBkbyBub3QgYWxsb3cgYnJlYWs7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBmb3IgKGkgPSAwOyBpIDwgcGFydHMubGVuZ3RoOyArK2kpIHtcbiAgICAgICAgaWYgKGkgPT09IHNraXBJbmRleCkge1xuICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgIH1cbiAgICAgICAgdmFyIHBhcnQgPSBwYXJ0c1tpXTtcblxuICAgICAgICB2YXIgYnJhY2tldEVxdWFsc1BvcyA9IHBhcnQuaW5kZXhPZignXT0nKTtcbiAgICAgICAgdmFyIHBvcyA9IGJyYWNrZXRFcXVhbHNQb3MgPT09IC0xID8gcGFydC5pbmRleE9mKCc9JykgOiBicmFja2V0RXF1YWxzUG9zICsgMTtcblxuICAgICAgICB2YXIga2V5LCB2YWw7XG4gICAgICAgIGlmIChwb3MgPT09IC0xKSB7XG4gICAgICAgICAgICBrZXkgPSBvcHRpb25zLmRlY29kZXIocGFydCwgZGVmYXVsdHMuZGVjb2RlciwgY2hhcnNldCwgJ2tleScpO1xuICAgICAgICAgICAgdmFsID0gb3B0aW9ucy5zdHJpY3ROdWxsSGFuZGxpbmcgPyBudWxsIDogJyc7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBrZXkgPSBvcHRpb25zLmRlY29kZXIocGFydC5zbGljZSgwLCBwb3MpLCBkZWZhdWx0cy5kZWNvZGVyLCBjaGFyc2V0LCAna2V5Jyk7XG4gICAgICAgICAgICB2YWwgPSB1dGlscy5tYXliZU1hcChcbiAgICAgICAgICAgICAgICBwYXJzZUFycmF5VmFsdWUocGFydC5zbGljZShwb3MgKyAxKSwgb3B0aW9ucyksXG4gICAgICAgICAgICAgICAgZnVuY3Rpb24gKGVuY29kZWRWYWwpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG9wdGlvbnMuZGVjb2RlcihlbmNvZGVkVmFsLCBkZWZhdWx0cy5kZWNvZGVyLCBjaGFyc2V0LCAndmFsdWUnKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICApO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHZhbCAmJiBvcHRpb25zLmludGVycHJldE51bWVyaWNFbnRpdGllcyAmJiBjaGFyc2V0ID09PSAnaXNvLTg4NTktMScpIHtcbiAgICAgICAgICAgIHZhbCA9IGludGVycHJldE51bWVyaWNFbnRpdGllcyh2YWwpO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKHBhcnQuaW5kZXhPZignW109JykgPiAtMSkge1xuICAgICAgICAgICAgdmFsID0gaXNBcnJheSh2YWwpID8gW3ZhbF0gOiB2YWw7XG4gICAgICAgIH1cblxuICAgICAgICB2YXIgZXhpc3RpbmcgPSBoYXMuY2FsbChvYmosIGtleSk7XG4gICAgICAgIGlmIChleGlzdGluZyAmJiBvcHRpb25zLmR1cGxpY2F0ZXMgPT09ICdjb21iaW5lJykge1xuICAgICAgICAgICAgb2JqW2tleV0gPSB1dGlscy5jb21iaW5lKG9ialtrZXldLCB2YWwpO1xuICAgICAgICB9IGVsc2UgaWYgKCFleGlzdGluZyB8fCBvcHRpb25zLmR1cGxpY2F0ZXMgPT09ICdsYXN0Jykge1xuICAgICAgICAgICAgb2JqW2tleV0gPSB2YWw7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gb2JqO1xufTtcblxudmFyIHBhcnNlT2JqZWN0ID0gZnVuY3Rpb24gKGNoYWluLCB2YWwsIG9wdGlvbnMsIHZhbHVlc1BhcnNlZCkge1xuICAgIHZhciBsZWFmID0gdmFsdWVzUGFyc2VkID8gdmFsIDogcGFyc2VBcnJheVZhbHVlKHZhbCwgb3B0aW9ucyk7XG5cbiAgICBmb3IgKHZhciBpID0gY2hhaW4ubGVuZ3RoIC0gMTsgaSA+PSAwOyAtLWkpIHtcbiAgICAgICAgdmFyIG9iajtcbiAgICAgICAgdmFyIHJvb3QgPSBjaGFpbltpXTtcblxuICAgICAgICBpZiAocm9vdCA9PT0gJ1tdJyAmJiBvcHRpb25zLnBhcnNlQXJyYXlzKSB7XG4gICAgICAgICAgICBvYmogPSBvcHRpb25zLmFsbG93RW1wdHlBcnJheXMgJiYgKGxlYWYgPT09ICcnIHx8IChvcHRpb25zLnN0cmljdE51bGxIYW5kbGluZyAmJiBsZWFmID09PSBudWxsKSlcbiAgICAgICAgICAgICAgICA/IFtdXG4gICAgICAgICAgICAgICAgOiBbXS5jb25jYXQobGVhZik7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBvYmogPSBvcHRpb25zLnBsYWluT2JqZWN0cyA/IE9iamVjdC5jcmVhdGUobnVsbCkgOiB7fTtcbiAgICAgICAgICAgIHZhciBjbGVhblJvb3QgPSByb290LmNoYXJBdCgwKSA9PT0gJ1snICYmIHJvb3QuY2hhckF0KHJvb3QubGVuZ3RoIC0gMSkgPT09ICddJyA/IHJvb3Quc2xpY2UoMSwgLTEpIDogcm9vdDtcbiAgICAgICAgICAgIHZhciBkZWNvZGVkUm9vdCA9IG9wdGlvbnMuZGVjb2RlRG90SW5LZXlzID8gY2xlYW5Sb290LnJlcGxhY2UoLyUyRS9nLCAnLicpIDogY2xlYW5Sb290O1xuICAgICAgICAgICAgdmFyIGluZGV4ID0gcGFyc2VJbnQoZGVjb2RlZFJvb3QsIDEwKTtcbiAgICAgICAgICAgIGlmICghb3B0aW9ucy5wYXJzZUFycmF5cyAmJiBkZWNvZGVkUm9vdCA9PT0gJycpIHtcbiAgICAgICAgICAgICAgICBvYmogPSB7IDA6IGxlYWYgfTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoXG4gICAgICAgICAgICAgICAgIWlzTmFOKGluZGV4KVxuICAgICAgICAgICAgICAgICYmIHJvb3QgIT09IGRlY29kZWRSb290XG4gICAgICAgICAgICAgICAgJiYgU3RyaW5nKGluZGV4KSA9PT0gZGVjb2RlZFJvb3RcbiAgICAgICAgICAgICAgICAmJiBpbmRleCA+PSAwXG4gICAgICAgICAgICAgICAgJiYgKG9wdGlvbnMucGFyc2VBcnJheXMgJiYgaW5kZXggPD0gb3B0aW9ucy5hcnJheUxpbWl0KVxuICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgb2JqID0gW107XG4gICAgICAgICAgICAgICAgb2JqW2luZGV4XSA9IGxlYWY7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKGRlY29kZWRSb290ICE9PSAnX19wcm90b19fJykge1xuICAgICAgICAgICAgICAgIG9ialtkZWNvZGVkUm9vdF0gPSBsZWFmO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgbGVhZiA9IG9iajtcbiAgICB9XG5cbiAgICByZXR1cm4gbGVhZjtcbn07XG5cbnZhciBwYXJzZUtleXMgPSBmdW5jdGlvbiBwYXJzZVF1ZXJ5U3RyaW5nS2V5cyhnaXZlbktleSwgdmFsLCBvcHRpb25zLCB2YWx1ZXNQYXJzZWQpIHtcbiAgICBpZiAoIWdpdmVuS2V5KSB7XG4gICAgICAgIHJldHVybjtcbiAgICB9XG5cbiAgICAvLyBUcmFuc2Zvcm0gZG90IG5vdGF0aW9uIHRvIGJyYWNrZXQgbm90YXRpb25cbiAgICB2YXIga2V5ID0gb3B0aW9ucy5hbGxvd0RvdHMgPyBnaXZlbktleS5yZXBsYWNlKC9cXC4oW14uW10rKS9nLCAnWyQxXScpIDogZ2l2ZW5LZXk7XG5cbiAgICAvLyBUaGUgcmVnZXggY2h1bmtzXG5cbiAgICB2YXIgYnJhY2tldHMgPSAvKFxcW1teW1xcXV0qXSkvO1xuICAgIHZhciBjaGlsZCA9IC8oXFxbW15bXFxdXSpdKS9nO1xuXG4gICAgLy8gR2V0IHRoZSBwYXJlbn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gZ2VuZXJhdGVBcnJheVByZWZpeCxcbiAgICAgICAgICAgIGNvbW1hUm91bmRUcmlwLFxuICAgICAgICAgICAgYWxsb3dFbXB0eUFycmF5cyxcbiAgICAgICAgICAgIHN0cmljdE51bGxIYW5kbGluZyxcbiAgICAgICAgICAgIHNraXBOdWxscyxcbiAgICAgICAgICAgIGVuY29kZURvdEluS2V5cyxcbiAgICAgICAgICAgIGdlbmVyYXRlQXJyYXlQcmVmaXggPT09ICdjb21tYScgJiYgZW5jb2RlVmFsdWVzT25seSAmJiBpc0FycmF5KG9iaikgPyBudWxsIDogZW5jb2RlcixcbiAgICAgICAgICAgIGZpbHRlcixcbiAgICAgICAgICAgIHNvcnQsXG4gICAgICAgICAgICBhbGxvd0RvdHMsXG4gICAgICAgICAgICBzZXJpYWxpemVEYXRlLFxuICAgICAgICAgICAgZm9ybWF0LFxuICAgICAgICAgICAgZm9ybWF0dGVyLFxuICAgICAgICAgICAgZW5jb2RlVmFsdWVzT25seSxcbiAgICAgICAgICAgIGNoYXJzZXQsXG4gICAgICAgICAgICB2YWx1ZVNpZGVDaGFubmVsXG4gICAgICAgICkpO1xuICAgIH1cblxuICAgIHJldHVybiB2YWx1ZXM7XG59O1xuXG52YXIgbm9ybWFsaXplU3RyaW5naWZ5T3B0aW9ucyA9IGZ1bmN0aW9uIG5vcm1hbGl6ZVN0cmluZ2lmeU9wdGlvbnMob3B0cykge1xuICAgIGlmICghb3B0cykge1xuICAgICAgICByZXR1cm4gZGVmYXVsdHM7XG4gICAgfVxuXG4gICAgaWYgKHR5cGVvZiBvcHRzLmFsbG93RW1wdHlBcnJheXMgIT09ICd1bmRlZmluZWQnICYmIHR5cGVvZiBvcHRzLmFsbG93RW1wdHlBcnJheXMgIT09ICdib29sZWFuJykge1xuICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdgYWxsb3dFbXB0eUFycmF5c2Agb3B0aW9uIGNhbiBvbmx5IGJlIGB0cnVlYCBvciBgZmFsc2VgLCB3a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ZGVDaGFubmVsID0gZ2V0U2lkZUNoYW5uZWwoKTtcbiAgICBmb3IgKHZhciBpID0gMDsgaSA8IG9iaktleXMubGVuZ3RoOyArK2kpIHtcbiAgICAgICAgdmFyIGtleSA9IG9iaktleXNbaV07XG5cbiAgICAgICAgaWYgKG9wdGlvbnMuc2tpcE51bGxzICYmIG9ialtrZXldID09PSBudWxsKSB7XG4gICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgfVxuICAgICAgICBwdXNoVG9BcnJheShrZXlzLCBzdHJpbmdpZnkoXG4gICAgICAgICAgICBvYmpba2V5XSxcbiAgICAgICAgICAgIGtleSxcbiAgICAgICAgICAgIGdlbmVyYXRlQXJyYXlQcmVmaXgsXG4gICAgICAgICAgICBjb21tYVJvdW5kVHJpcCxcbiAgICAgICAgICAgIG9wdGlvbnMuYWxsb3dFbXB0eUFycmF5cyxcbiAgICAgICAgICAgIG9wdGlvbnMuc3RyaWN0TnVsbEhhbmRsaW5nLFxuICAgICAgICAgICAgb3B0aW9ucy5za2lwTnVsbHMsXG4gICAgICAgICAgICBvcHRpb25zLmVuY29kZURvdEluS2V5cyxcbiAgICAgICAgICAgIG9wdGlvbnMuZW5jb2RlID8gb3B0aW9ucy5lbmNvZGVyIDogbnVsbCxcbiAgICAgICAgICAgIG9wdGlvbnMuZmlsdGVyLFxuICAgICAgICAgICAgb3B0aW9ucy5zb3J0LFxuICAgICAgICAgICAgb3B0aW9ucy5hbGxvd0RvdHMsXG4gICAgICAgICAgICBvcHRpb25zLnNlcmlhbGl6ZURhdGUsXG4gICAgICAgICAgICBvcHRpb25zLmZvcm1hdCxcbiAgICAgICAgICAgIG9wdGlvbnMuZm9ybWF0dGVyLFxuICAgICAgICAgICAgb3B0aW9ucy5lbmNvZGVWYWx1ZXNPbmx5LFxuICAgICAgICAgICAgb3B0aW9ucy5jaGFyc2V0LFxuICAgICAgICAgICAgc2lkZUNoYW5uZWxcbiAgICAgICAgKSk7XG4gICAgfVxuXG4gICAgdmFy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gICAgICAgIGlmIChcbiAgICAgICAgICAgICAgICBjID09PSAweDJEIC8vIC1cbiAgICAgICAgICAgICAgICB8fCBjID09PSAweDJFIC8vIC5cbiAgICAgICAgICAgICAgICB8fCBjID09PSAweDVGIC8vIF9cbiAgICAgICAgICAgICAgICB8fCBjID09PSAweDdFIC8vIH5cbiAgICAgICAgICAgICAgICB8fCAoYyA+PSAweDMwICYmIGMgPD0gMHgzOSkgLy8gMC05XG4gICAgICAgICAgICAgICAgfHwgKGMgPj0gMHg0MSAmJiBjIDw9IDB4NUEpIC8vIGEtelxuICAgICAgICAgICAgICAgIHx8IChjID49IDB4NjEgJiYgYyA8PSAweDdBKSAvLyBBLVpcbiAgICAgICAgICAgICAgICB8fCAoZm9ybWF0ID09PSBmb3JtYXRzLlJGQzE3MzggJiYgKGMgPT09IDB4MjggfHwgYyA9PT0gMHgyOSkpIC8vICggKVxuICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgYXJyW2Fyci5sZW5ndGhdID0gc2VnbWVudC5jaGFyQXQoaSk7XG4gICAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChjIDwgMHg4MCkge1xuICAgICAgICAgICAgICAgIGFyclthcnIubGVuZ3RoXSA9IGhleFRhYmxlW2NdO1xuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoYyA8IDB4ODAwKSB7XG4gICAgICAgICAgICAgICAgYXJyW2Fyci5sZW5ndGhdID0gaGV4VGFibGVbMHhDMCB8IChjID4+IDYpXVxuICAgICAgICAgICAgICAgICAgICArIGhleFRhYmxlWzB4ODAgfCAoYyAmIDB4M0YpXTtcbiAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGMgPCAweEQ4MDAgfHwgYyA+PSAweEUwMDApIHtcbiAgICAgICAgICAgICAgICBhcnJbYXJyLmxlbmd0aF0gPSBoZXhUYWJsZVsweEUwIHwgKGMgPj4gMTIpXVxuICAgICAgICAgICAgICAgICAgICArIGhleFRhYmxlWzB4ODAgfCAoKGMgPj4gNikgJiAweDNGKV1cbiAgICAgICAgICAgICAgICAgICAgKyBoZXhUYWJsZVsweDgwIHwgKGMgJiAweDNGKV07XG4gICAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGkgKz0gMTtcbiAgICAgICAgICAgIGMgPSAweDEwMDAwICsgKCgoYyAmIDB4M0ZGKSA8PCAxMCkgfCAoc2VnbWVudC5jaGFyQ29kZUF0KGkpICYgMHgzRkYpKTtcblxuICAgICAgICAgICAgYXJyW2Fyci5sZW5ndGhdID0gaGV4VGFibGVbMHhGMCB8IChjID4+IDE4KV1cbiAgICAgICAgICAgICAgICArIGhleFRhYmxlWzB4ODAgfCAoKGMgPj4gMTIpICYgMHgzRildXG4gICAgICAgICAgICAgICAgKyBoZXhUYWJsZVsweDgwIHwgKChjID4+IDYpICYgMHgzRildXG4gICAgICAgICAgICAgICAgKyBoZXhUYWJsZVsweDgwIHwgKGMgJiAweDNGKV07XG4gICAgICAgIH1cblxuICAgICAgICBvdXQgKz0gYXJyLmpvaW4oJycpO1xuICAgIH1cblxuICAgIHJldHVybiBvdXQ7XG59O1xuXG52YXIgY29tcGFjdCA9IGZ1bmN0aW9uIGNvbXBhY3QodmFsdWUpIHtcbiAgICB2YXIgcXVldWUgPSBbeyBvYmo6IHsgbzogdmFsdWUgfSwgcHJvcDogJ28nIH1dO1xuICAgIHZhciByZWZzID0gW107XG5cbiAgICBmb3IgKHZhciBpID0gMDsgaSA8IHF1ZXVlLmxlbmd0aDsgKytpKSB7XG4gICAgICAgIHZhciBpdGVtID0gcXVldWVbaV07XG4gICAgICAgIHZhciBvYmogPSBpdGVtLm9ialtpdGVtLnByb3BdO1xuXG4gICAgICAgIHZhciBrZXlzID0gT2JqZWN0LmtleXMob2JqKTtcbiAgICAgICAgZm9yICh2YXIgaiA9IDA7IGogPCBrZXlzLmxlbmd0aDsgKytqKSB7XG4gICAgICAgICAgICB2YXIga2V5ID0ga2V5c1tqXTtcbiAgICAgICAgICAgIHZhciB2YWwgPSBvYmpba2V5XTtcbiAgICAgICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAnb2JqZWN0JyAmJiB2YWwgIT09IG51bGwgJiYgcmVmcy5pbmRleE9mKHZhbCkgPT09IC0xKSB7XG4gICAgICAgICAgICAgICAgcXVldWUucHVzaCh7IG9iajogb2JqLCBwcm9wOiBrZXkgfSk7XG4gICAgICAgICAgICAgICAgcmVmcy5wdXNoKHZhbCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBjb21wYWN0UXVldWUocXVldWUpO1xuXG4gICAgcmV0dXJuIHZhbHVlO1xufTtcblxudmFyIGlzUmVnRXhwID0gZnVuY3Rpb24gaXNSZWdFeHAob2JqKSB7XG4gICAgcmV0dXJuIE9iamVjdC5wcm90b3R5cGUudG9TdHJpbmcuY2FsbChvYmopID09PSAnW29iamVjdCBSZWdFeHBdJztcbn07XG5cbnZhciBpc0J1ZmZlciA9IGZ1bmN0aW9uIGlzQnVmZmVyKG9iaikge1xuICAgIGlmICghb2JqIHx8IHR5cGVvZiBvYmogIT09ICdvYmplY3QnKSB7XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9XG5cbiAgICByZXR1cm4gISEob2JqLmNvbnN0cnVjdG9yICYmIG9iai5jb25zdHJ1Y3Rvci5pc0J1ZmZlciAmJiBvYmouY29uc3RydWN0b3IuaXNCdWZmZXIob2JqKSk7XG59O1xuXG52YXIgY29tYmluZSA9IGZ1bmN0aW9uIGNvbWJpbmUoYSwgYikge1xuICAgIHJldHVybiBbXS5jb25jYXQoYSwgYik7XG59O1xuXG52YXIgbWF5YmVNYXAgPSBmdW5jdGlvbiBtYXliZU1hcCh2YWwsIGZuKSB7XG4gICAgaWYgKGlzQXJyY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VxuICAgICAgICAgICAgOiB0aGlzLmRvKG5leHRPck9ic2VydmVyLCBlcnJvciwgY29tcGxldGUpO1xuICAgIH07XG4gICAgTm90aWZpY2F0aW9uLnByb3RvdHlwZS50b09ic2VydmFibGUgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgIHZhciBfYSA9IHRoaXMsIGtpbmQgPSBfYS5raW5kLCB2YWx1ZSA9IF9hLnZhbHVlLCBlcnJvciA9IF9hLmVycm9yO1xuICAgICAgICB2YXIgcmVzdWx0ID0ga2luZCA9PT0gJ04nXG4gICAgICAgICAgICA/XG4gICAgICAgICAgICAgICAgb2YodmFsdWUpXG4gICAgICAgICAgICA6XG4gICAgICAgICAgICAgICAga2luZCA9PT0gJ0UnXG4gICAgICAgICAgICAgICAgICAgID9cbiAgICAgICAgICAgICAgICAgICAgICAgIHRocm93RXJyb3IoZnVuY3Rpb24gKCkgeyByZXR1cm4gZXJyb3I7IH0pXG4gICAgICAgICAgICAgICAgICAgIDpcbiAgICAgICAgICAgICAgICAgICAgICAgIGtpbmQgPT09ICdDJ1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgID9cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRU1QVFlcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICA6XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDA7XG4gICAgICAgIGlmICghcmVzdWx0KSB7XG4gICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKFwiVW5leHBlY3RlZCBub3RpZmljYXRpb24ga2luZCBcIiArIGtpbmQpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgfTtcbiAgICBOb3RpZmljYXRpb24uY3JlYXRlTmV4dCA9IGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICByZXR1cm4gbmV3IE5vdGlmaWNhdGlvbignTicsIHZhbHVlKTtcbiAgICB9O1xuICAgIE5vdGlmaWNhdGlvbi5jcmVhdGVFc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gICAgICAgICAgIHZhciBfYSA9IF90aGlzLCBvcGVyYXRvciA9IF9hLm9wZXJhdG9yLCBzb3VyY2UgPSBfYS5zb3VyY2U7XG4gICAgICAgICAgICBzdWJzY3JpYmVyLmFkZChvcGVyYXRvclxuICAgICAgICAgICAgICAgID9cbiAgICAgICAgICAgICAgICAgICAgb3BlcmF0b3IuY2FsbChzdWJzY3JpYmVyLCBzb3VyY2UpXG4gICAgICAgICAgICAgICAgOiBzb3VyY2VcbiAgICAgICAgICAgICAgICAgICAgP1xuICAgICAgICAgICAgICAgICAgICAgICAgX3RoaXMuX3N1YnNjcmliZShzdWJzY3JpYmVyKVxuICAgICAgICAgICAgICAgICAgICA6XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpcy5fdHJ5U3Vic2NyaWJlKHN1YnNjcmliZXIpKTtcbiAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiBzdWJzY3JpYmVyO1xuICAgIH07XG4gICAgT2JzZXJ2YWJsZS5wcm90b3R5cGUuX3RyeVN1YnNjcmliZSA9IGZ1bmN0aW9uIChzaW5rKSB7XG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5fc3Vic2NyaWJlKHNpbmspO1xuICAgICAgICB9XG4gICAgICAgIGNhdGNoIChlcnIpIHtcbiAgICAgICAgICAgIHNpbmsuZXJyb3IoZXJyKTtcbiAgICAgICAgfVxuICAgIH07XG4gICAgT2JzZXJ2YWJsZS5wcm90b3R5cGUuZm9yRWFjaCA9IGZ1bmN0aW9uIChuZXh0LCBwcm9taXNlQ3Rvcikge1xuICAgICAgICB2YXIgX3RoaXMgPSB0aGlzO1xuICAgICAgICBwcm9taXNlQ3RvciA9IGdldFByb21pc2VDdG9yKHByb21pc2VDdG9yKTtcbiAgICAgICAgcmV0dXJuIG5ldyBwcm9taXNlQ3RvcihmdW5jdGlvbiAocmVzb2x2ZSwgcmVqZWN0KSB7XG4gICAgICAgICAgICB2YXIgc3Vic2NyaXB0aW9uO1xuICAgICAgICAgICAgc3Vic2NyaXB0aW9uID0gX3RoaXMuc3Vic2NyaWJlKGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIG5leHQodmFsdWUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgIHJlamVjdChlcnIpO1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpcHRpb24gPT09IG51bGwgfHwgc3Vic2NyaXB0aW9uID09PSB2b2lkIDAgPyB2b2lkIDAgOiBzdWJzY3JpcHRpb24udW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LCByZWplY3QsIHJlc29sdmUpO1xuICAgICAgICB9KTtcbiAgICB9O1xuICAgIE9ic2VydmFibGUucHJvdG90eXBlLl9zdWJzY3JpYmUgPSBmdW5jdGlvbiAoc3Vic2NyaWJlcikge1xuICAgICAgICB2YXIgX2E7XG4gICAgICAgIHJldHVybiAoX2EgPSB0aGlzLnNvdXJjZSkgPT09IG51bGwgfHwgX2EgPT09IHZvaWQgMCA/IHZvaWQgMCA6IF9hLnN1YnNjcmliZShzdWJzY3JpYmVyKTtcbiAgICB9O1xuICAgIE9ic2VydmFibGUucHJvdG90eXBlW1N5bWJvbF9vYnNlcnZhYmxlXSA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfTtcbiAgICBPYnNlcnZhYmxlLnByb3RvdHlwZS5waXBlID0gZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgb3BlcmF0aW9ucyA9IFtdO1xuICAgICAgICBmb3IgKHZhciBfaSA9IDA7IF9pIDwgYXJndW1lbnRzLmxlbmd0aDsgX2krKykge1xuICAgICAgICAgICAgb3BlcmF0aW9uc1tfaV0gPSBhcmd1bWVudHNbX2ldO1xuICAgICAgICB9XG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gICAgdmFyIF90aGlzID0gdGhpcztcbiAgICAgICAgZXJyb3JDb250ZXh0KGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIHZhciBlXzEsIF9hO1xuICAgICAgICAgICAgX3RoaXMuX3Rocm93SWZDbG9zZWQoKTtcbiAgICAgICAgICAgIGlmICghX3RoaXMuaXNTdG9wcGVkKSB7XG4gICAgICAgICAgICAgICAgdmFyIGNvcHkgPSBfdGhpcy5vYnNlcnZlcnMuc2xpY2UoKTtcbiAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBjb3B5XzEgPSBfX3ZhbHVlcyhjb3B5KSwgY29weV8xXzEgPSBjb3B5XzEubmV4dCgpOyAhY29weV8xXzEuZG9uZTsgY29weV8xXzEgPSBjb3B5XzEubmV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgb2JzZXJ2ZXIgPSBjb3B5XzFfMS52YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIG9ic2VydmVyLm5leHQodmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNhdGNoIChlXzFfMSkgeyBlXzEgPSB7IGVycm9yOiBlXzFfMSB9OyB9XG4gICAgICAgICAgICAgICAgZmluYWxseSB7XG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoY29weV8xXzEgJiYgIWNvcHlfMV8xLmRvbmUgJiYgKF9hID0gY29weV8xLnJldHVybikpIF9hLmNhbGwoY29weV8xKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBmaW5hbGx5IHsgaWYgKGVfMSkgdGhyb3cgZV8xLmVycm9yOyB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9O1xuICAgIFN1YmplY3QucHJvdG90eXBlLmVycm9yID0gZnVuY3Rpb24gKGVycikge1xuICAgICAgICB2YXIgX3RoaXMgPSB0aGlzO1xuICAgICAgICBlcnJvckNvbnRleHQoZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgX3RoaXMuX3Rocm93SWZDbG9zZWQoKTtcbiAgICAgICAgICAgIGlmICghX3RoaXMuaXNTdG9wcGVkKSB7XG4gICAgICAgICAgICAgICAgX3RoaXMuaGFzRXJyb3IgPSBfdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xuICAgICAgICAgICAgICAgIF90aGlzLnRocm93bkVycm9yID0gZXJyO1xuICAgICAgICAgICAgICAgIHZhciBvYnNlcnZlcnMgPSBfdGhpcy5vYnNlcnZlcnM7XG4gICAgICAgICAgICAgICAgd2hpbGUgKG9ic2VydmVycy5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXJzLnNoaWZ0KCkuZXJyb3IoZXJyKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH07XG4gICAgU3ViamVjdC5wcm90b3R5cGUuY29tcGxldGUgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgIHZhciBfdGhpcyA9IHRoaXM7XG4gICAgICAgIGVycm9yQ29udGV4dChmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICBfdGhpcy5fdGhyb3dJZkNsb3NlZCgpO1xuICAgICAgICAgICAgaWYgKCFfdGhpcy5pc1N0b3BwZWQpIHtcbiAgICAgICAgICAgICAgICBfdGhpcy5pc1N0b3BwZWQgPSB0cnVlO1xuICAgICAgICAgICAgICAgIHZhciBvYnNlcnZlcnMgPSBfdGhpcy5vYnNlcnZlcnM7XG4gICAgICAgICAgICAgICAgd2hpbGUgKG9ic2VydmVycy5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICAgICAgb2JzZXJ2ZXJzLnNoaWZ0KCkuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgIC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WROb3RpZmljYXRpb24oQ09NUExFVEVfTk9USUZJQ0FUSU9OLCB0aGlzKTtcbiAgICAgICAgfVxuICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgIHRoaXMuaXNTdG9wcGVkID0gdHJ1ZTtcbiAgICAgICAgICAgIHRoaXMuX2NvbXBsZXRlKCk7XG4gICAgICAgIH1cbiAgICB9O1xuICAgIFN1YnNjcmliZXIucHJvdG90eXBlLnVuc3Vic2NyaWJlID0gZnVuY3Rpb24gKCkge1xuICAgICAgICBpZiAoIXRoaXMuY2xvc2VkKSB7XG4gICAgICAgICAgICB0aGlzLmlzU3RvcHBlZCA9IHRydWU7XG4gICAgICAgICAgICBfc3VwZXIucHJvdG90eXBlLnVuc3Vic2NyaWJlLmNhbGwodGhpcyk7XG4gICAgICAgICAgICB0aGlzLmRlc3RpbmF0aW9uID0gbnVsbDtcbiAgICAgICAgfVxuICAgIH07XG4gICAgU3Vic2NyaWJlci5wcm90b3R5cGUuX25leHQgPSBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgdGhpcy5kZXN0aW5hdGlvbi5uZXh0KHZhbHVlKTtcbiAgICB9O1xuICAgIFN1YnNjcmliZXIucHJvdG90eXBlLl9lcnJvciA9IGZ1bmN0aW9uIChlcnIpIHtcbiAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgIHRoaXMuZGVzdGluYXRpb24uZXJyb3IoZXJyKTtcbiAgICAgICAgfVxuICAgICAgICBmaW5hbGx5IHtcbiAgICAgICAgICAgIHRoaXMudW5zdWJzY3JpYmUoKTtcbiAgICAgICAgfVxuICAgIH07XG4gICAgU3Vic2NyaWJlci5wcm90b3R5cGUuX2NvbXBsZXRlID0gZnVuY3Rpb24gKCkge1xuICAgICAgICB0cnkge1xuICAgICAgICAgICAgdGhpcy5kZXN0aW5hdGlvbi5jb21wbGV0ZSgpO1xuICAgICAgICB9XG4gICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgdGhpcy51bnN1YnNjcmliZS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NlcnZlck9yTmV4dDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG5leHQgPSBuZXh0ID09PSBudWxsIHx8IG5leHQgPT09IHZvaWQgMCA/IHZvaWQgMCA6IG5leHQuYmluZChjb250ZXh0XzEpO1xuICAgICAgICAgICAgZXJyb3IgPSBlcnJvciA9PT0gbnVsbCB8fCBlcnJvciA9PT0gdm9pZCAwID8gdm9pZCAwIDogZXJyb3IuYmluZChjb250ZXh0XzEpO1xuICAgICAgICAgICAgY29tcGxldGUgPSBjb21wbGV0ZSA9PT0gbnVsbCB8fCBjb21wbGV0ZSA9PT0gdm9pZCAwID8gdm9pZCAwIDogY29tcGxldGUuYmluZChjb250ZXh0XzEpO1xuICAgICAgICB9XG4gICAgICAgIF90aGlzLmRlc3RpbmF0aW9uID0ge1xuICAgICAgICAgICAgbmV4dDogbmV4dCA/IHdyYXBGb3JFcnJvckhhbmRsaW5nKG5leHQsIF90aGlzKSA6IG5vb3AsXG4gICAgICAgICAgICBlcnJvcjogd3JhcEZvckVycm9ySGFuZGxpbmcoZXJyb3IgIT09IG51bGwgJiYgZXJyb3IgIT09IHZvaWQgMCA/IGVycm9yIDogZGVmYXVsdEVycm9ySGFuZGxlciwgX3RoaXMpLFxuICAgICAgICAgICAgY29tcGxldGU6IGNvbXBsZXRlID8gd3JhcEZvckVycm9ySGFuZGxpbmcoY29tcGxldGUsIF90aGlzKSA6IG5vb3AsXG4gICAgICAgIH07XG4gICAgICAgIHJldHVybiBfdGhpcztcbiAgICB9XG4gICAgcmV0dXJuIFNhZmVTdWJzY3JpYmVyO1xufShTdWJzY3JpYmVyKSk7XG5leHBvcnQgeyBTYWZlU3Vic2NyaWJlciB9O1xuZnVuY3Rpb24gd3JhcEZvckVycm9ySGFuZGxpbmcoaGFuZGxlciwgaW5zdGFuY2UpIHtcbiAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgYXJncyA9IFtdO1xuICAgICAgICBmb3IgKHZhciBfaSA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EFycmF5LmlzQXJyYXkoX3BhcmVudGFnZSkpIHtcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAodmFyIF9wYXJlbnRhZ2VfMSA9IF9fdmFsdWVzKF9wYXJlbnRhZ2UpLCBfcGFyZW50YWdlXzFfMSA9IF9wYXJlbnRhZ2VfMS5uZXh0KCk7ICFfcGFyZW50YWdlXzFfMS5kb25lOyBfcGFyZW50YWdlXzFfMSA9IF9wYXJlbnRhZ2VfMS5uZXh0KCkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgcGFyZW50XzEgPSBfcGFyZW50YWdlXzFfMS52YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRfMS5yZW1vdmUodGhpcyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgY2F0Y2ggKGVfMV8xKSB7IGVfMSA9IHsgZXJyb3I6IGVfMV8xIH07IH1cbiAgICAgICAgICAgICAgICAgICAgZmluYWxseSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChfcGFyZW50YWdlXzFfMSAmJiAhX3BhcmVudGFnZV8xXzEuZG9uZSAmJiAoX2EgPSBfcGFyZW50YWdlXzEucmV0dXJuKSkgX2EuY2FsbChfcGFyZW50YWdlXzEpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxseSB7IGlmIChlXzEpIHRocm93IGVfMS5lcnJvcjsgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBfcGFyZW50YWdlLnJlbW92ZSh0aGlzKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgaW5pdGlhbFRlYXJkb3duID0gdGhpcy5pbml0aWFsVGVhcmRvd247XG4gICAgICAgICAgICBpZiAoaXNGdW5jdGlvbihpbml0aWFsVGVhcmRvd24pKSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgaW5pdGlhbFRlYXJkb3duKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNhdGNoIChlKSB7XG4gICAgICAgICAgICAgICAgICAgIGVycm9ycyA9IGUgaW5zdGFuY2VvZiBVbnN1YnNjcmlwdGlvbkVycm9yID8gZS5lcnJvcnMgOiBbZV07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdmFyIF90ZWFyZG93bnMgPSB0aGlzLl90ZWFyZG93bnM7XG4gICAgICAgICAgICBpZiAoX3RlYXJkb3ducykge1xuICAgICAgICAgICAgICAgIHRoaXMuX3RlYXJkb3ducyA9IG51bGw7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgX3RlYXJkb3duc18xID0gX192YWx1ZXMoX3RlYXJkb3ducyksIF90ZWFyZG93bnNfMV8xID0gX3RlYXJkb3duc18xLm5leHQoKTsgIV90ZWFyZG93bnNfMV8xLmRvbmU7IF90ZWFyZG93bnNfMV8xID0gX3RlYXJkb3duc18xLm5leHQoKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHRlYXJkb3duXzEgPSBfdGVhcmRvd25zXzFfMS52YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZXhlY1RlYXJkb3duKHRlYXJkb3duXzEpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVycm9ycyA9IGVycm9ycyAhPT0gbnVsbCAmJiBlcnJvcnMgIT09IHZvaWQgMCA/IGVycm9ycyA6IFtdO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlcnIgaW5zdGFuY2VvZiBVbnN1YnNjcmlwdGlvbkVycm9yKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVycm9ycyA9IF9fc3ByZWFkQXJyYXkoX19zcHJlYWRBcnJheShbXSwgX19yZWFkKGVycm9ycykpLCBfX3JlYWQoZXJyLmVycm9ycykpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZXJyb3JzLnB1c2goZXJyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgY2F0Y2ggKGVfMl8xKSB7IGVfMiA9IHsgZXJyb3I6IGVfMl8xIH07IH1cbiAgICAgICAgICAgICAgICBmaW5hbGx5IHtcbiAgICAgICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChfdGVhcmRvd25zXzFfMSAmJiAhX3RlYXJkb3duc18xXzEuZG9uZSAmJiAoX2IgPSBfdGVhcmRvd25zXzEucmV0dXJuKSkgX2IuY2FsbChfdGVhcmRvd25zXzEpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGZpbmFsbHkgeyBpZiAoZV8yKSB0aHJvdyBlXzIuZXJyb3I7IH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpZiAoZXJyb3JzKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IFVuc3Vic2NyaXB0aW9uRXJyb3IoZXJyb3JzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH07XG4gICAgU3Vic2NyaXB0aW9uLnByb3RvdHlwZS5hZGQgPSBmdW5jdGlvbiAodGVhcmRvd24pIHtcbiAgICAgICAgdmFyIF9hO1xuICAgICAgICBpZiAodGVhcmRvd24gJiYgdGVhcmRvd24gIT09IHRoaXMpIHtcbiAgICAgICAgICAgIGlmICh0aGlzLmNsb3NlZCkge1xuICAgICAgICAgICAgICAgIGV4ZWNUZWFyZG93bih0ZWFyZG93bik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICBpZiAodGVhcmRvd24gaW5zdGFuY2VvZiBTdWJzY3JpcHRpb24pIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRlYXJkb3duLmNsb3NlZCB8fCB0ZWFyZG93bi5faGFzUGFyZW50KHRoaXMpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgdGVhcmRvd24uX2FkZFBhcmVudCh0aGlzKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgKHRoaXMuX3RlYXJkb3ducyA9IChfYSA9IHRoaXMuX3RlYXJkb3ducykgIT09IG51bGwgJiYgX2EgIT09IHZvaWQgMCA/IF9hIDogW10pLnB1c2godGVhcmRvd24pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfTtcbiAgICBTdWJzY3JpcHRpb24ucHJvdG90eXBlLl9oYXNQYXJlbnQgPSBmdW5jdGlvbiAocGFyZW50KSB7XG4gICAgICAgIHZhciBfcGFyZW50YWdlID0gdGhpcy5fcGFyZW50YWdlO1xuICAgICAgICByZXR1cm4gX3BhcmVudGFnZSA9PT0gcGFyZW50IHx8IChBcnJheS5pc0FycmF5KF9wYXJlbnRhZ2UpICYmIF9wYXJlbnRhZ2UuaW5jb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luY2hyb25vdXNFcnJvckhhbmRsaW5nOiBmYWxzZSxcbiAgICB1c2VEZXByZWNhdGVkTmV4dENvbnRleHQ6IGZhbHNlLFxufTtcbi8vIyBzb3VyY2VNYXBwaW5nVVJMPWNvbmZpZy5qcy5tYXAiLCJpbXBvcnQgeyBFbXB0eUVycm9yIH0gZnJvbSAnLi91dGlsL0VtcHR5RXJyb3InO1xuaW1wb3J0IHsgU2FmZVN1YnNjcmliZXIgfSBmcm9tICcuL1N1YnNjcmliZXInO1xuZXhwb3J0IGZ1bmN0aW9uIGZpcnN0VmFsdWVGcm9tKHNvdXJjZSwgY29uZmlnKSB7XG4gICAgdmFyIGhhc0NvbmZpZyA9IHR5cGVvZiBjb25maWcgPT09ICdvYmplY3QnO1xuICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbiAocmVzb2x2ZSwgcmVqZWN0KSB7XG4gICAgICAgIHZhciBzdWJzY3JpYmVyID0gbmV3IFNhZmVTdWJzY3JpYmVyKHtcbiAgICAgICAgICAgIG5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgIHJlc29sdmUodmFsdWUpO1xuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIudW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBlcnJvcjogcmVqZWN0LFxuICAgICAgICAgICAgY29tcGxldGU6IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICBpZiAoaGFzQ29uZmlnKSB7XG4gICAgICAgICAgICAgICAgICAgIHJlc29sdmUoY29uZmlnLmRlZmF1bHRWYWx1ZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByZWplY3QobmV3IEVtcHR5RXJyb3IoKSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiAgICAgICAgfSk7XG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUoc3Vic2NyaWJlcik7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1maXJzdFZhbHVlRnJvbS5qcy5tYXAiLCJpbXBvcnQgeyBFbXB0eUVycm9yIH0gZnJvbSAnLi91dGlsL0VtcHR5RXJyb3InO1xuZXhwb3J0IGZ1bmN0aW9uIGxhc3RWYWx1ZUZyb20oc291cmNlLCBjb25maWcpIHtcbiAgICB2YXIgaGFzQ29uZmlnID0gdHlwZW9mIGNvbmZpZyA9PT0gJ29iamVjdCc7XG4gICAgcmV0dXJuIG5ldyBQcm9taXNlKGZ1bmN0aW9uIChyZXNvbHZlLCByZWplY3QpIHtcbiAgICAgICAgdmFyIF9oYXNWYWx1ZSA9IGZhbHNlO1xuICAgICAgICB2YXIgX3ZhbHVlO1xuICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKHtcbiAgICAgICAgICAgIG5leHQ6IGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgIF92YWx1ZSA9IHZhbHVlO1xuICAgICAgICAgICAgICAgIF9oYXNWYWx1ZSA9IHRydWU7XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgZXJyb3I6IHJlamVjdCxcbiAgICAgICAgICAgIGNvbXBsZXRlOiBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgaWYgKF9oYXNWYWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICByZXNvbHZlKF92YWx1ZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2UgaWYgKGhhc0NvbmZpZykge1xuICAgICAgICAgICAgICAgICAgICByZXNvbHZlKGNvbmZpZy5kZWZhdWx0VmFsdWUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBFbXB0eUVycm9yKCkpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0s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hbGxiYWNrSW50ZXJuYWxzKGlzTm9kZVN0eWxlLCBjYWxsYmFja0Z1bmMsIHJlc3VsdFNlbGVjdG9yLCBzY2hlZHVsZXIpIHtcbiAgICBpZiAocmVzdWx0U2VsZWN0b3IpIHtcbiAgICAgICAgaWYgKGlzU2NoZWR1bGVyKHJlc3VsdFNlbGVjdG9yKSkge1xuICAgICAgICAgICAgc2NoZWR1bGVyID0gcmVzdWx0U2VsZWN0b3I7XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHZhciBhcmdzID0gW107XG4gICAgICAgICAgICAgICAgZm9yICh2YXIgX2kgPSAwOyBfaSA8IGFyZ3VtZW50cy5sZW5ndGg7IF9pKyspIHtcbiAgICAgICAgICAgICAgICAgICAgYXJnc1tfaV0gPSBhcmd1bWVudHNbX2ldO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4gYmluZENhbGxiYWNrSW50ZXJuYWxzKGlzTm9kZVN0eWxlLCBjYWxsYmFja0Z1bmMsIHNjaGVkdWxlcilcbiAgICAgICAgICAgICAgICAgICAgLmFwcGx5KHRoaXMsIGFyZ3MpXG4gICAgICAgICAgICAgICAgICAgIC5waXBlKG1hcE9uZU9yTWFueUFyZ3MocmVzdWx0U2VsZWN0b3IpKTtcbiAgICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICB9XG4gICAgaWYgKHNjaGVkdWxlcikge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgdmFyIGFyZ3MgPSBbXTtcbiAgICAgICAgICAgIGZvciAodmFyIF9pID0gMDsgX2kgPCBhcmd1bWVudHMubGVuZ3RoOyBfaSsrKSB7XG4gICAgICAgICAgICAgICAgYXJnc1tfaV0gPSBhcmd1bWVudHNbX2ldO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGJpbmRDYWxsYmFja0ludGVybmFscyhpc05vZGVTdHlsZSwgY2FsbGJhY2tGdW5jKVxuICAgICAgICAgICAgICAgIC5hcHBseSh0aGlzLCBhcmdzKVxuICAgICAgICAgICAgICAgIC5waXBlKHN1YnNjcmliZU9uKHNjaGVkdWxlciksIG9ic2VydmVPbihzY2hlZHVsZXIpKTtcbiAgICAgICAgfTtcbiAgICB9XG4gICAgcmV0dXJuIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgdmFyIF90aGlzID0gdGhpcztcbiAgICAgICAgdmFyIGFyZ3MgPSBbXTtcbiAgICAgICAgZm9yICh2YXIgX2kgPSAwOyBfaSA8IGFyZ3VtZW50cy5sZW5ndGg7IF9pKyspIHtcbiAgICAgICAgICAgIGFyZ3NbX2ldID0gYXJndW1lbnRzW19pXTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgc3ViamVjdCA9IG5ldyBBc3luY1N1YmplY3QoKTtcbiAgICAgICAgdmFyIHVuaW5pdGlhbGl6ZWQgPSB0cnVlO1xuICAgICAgICByZXR1cm4gbmV3IE9ic2VydmFibGUoZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcbiAgICAgICAgICAgIHZhciBzdWJzID0gc3ViamVjdC5zdWJzY3JpYmUoc3Vic2NyaWJlcik7XG4gICAgICAgICAgICBpZiAodW5pbml0aWFsaXplZCkge1xuICAgICAgICAgICAgICAgIHVuaW5pdGlhbGl6ZWQgPSBmYWxzZTtcbiAgICAgICAgICAgICAgICB2YXIgaXNBc3luY18xID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgdmFyIGlzQ29tcGxldGVfMSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIGNhbGxiYWNrRnVuYy5hcHBseShfdGhpcywgX19zcHJlYWRBcnJheShfX3NwcmVhZEFycmF5KFtdLCBfX3JlYWQoYXJncykpLCBbXG4gICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciByZXN1bHRzID0gW107XG4gICAgICAgICAgICAgICAgICAgICAgICBmb3IgKHZhciBfaSA9IDA7IF9pIDwgYXJndW1lbnRzLmxlbmd0aDsgX2krKykge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdHNbX2ldID0gYXJndW1lbnRzW19pXTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpc05vZGVTdHlsZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhciBlcnIgPSByZXN1bHRzLnNoaWZ0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGVyciAhPSBudWxsKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YmplY3QuZXJyb3IoZXJyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YmplY3QubmV4dCgxIDwgcmVzdWx0cy5sZW5ndGggPyByZXN1bHRzIDogcmVzdWx0c1swXSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpc0NvbXBsZXRlXzEgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzQXN5bmNfMSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YmplY3QuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBdKSk7XG4gICAgICAgICAgICAgICAgaWYgKGlzQ29tcGxldGVfMSkge1xuICAgICAgICAgICAgICAgICAgICBzdWJqZWN0LmNvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlzQXN5bmNfMSA9IHRydWU7XG4gICAgICAgICAgICB9XG4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HVlVHJhbnNmb3JtID0gaWRlbnRpdHk7IH1cbiAgICByZXR1cm4gZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcbiAgICAgICAgbWF5YmVTY2hlZHVsZShzY2hlZHVsZXIsIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIHZhciBsZW5ndGggPSBvYnNlcnZhYmxlcy5sZW5ndGg7XG4gICAgICAgICAgICB2YXIgdmFsdWVzID0gbmV3IEFycmF5KGxlbmd0aCk7XG4gICAgICAgICAgICB2YXIgYWN0aXZlID0gbGVuZ3RoO1xuICAgICAgICAgICAgdmFyIHJlbWFpbmluZ0ZpcnN0VmFsdWVzID0gbGVuZ3RoO1xuICAgICAgICAgICAgdmFyIF9sb29wXzEgPSBmdW5jdGlvbiAoaSkge1xuICAgICAgICAgICAgICAgIG1heWJlU2NoZWR1bGUoc2NoZWR1bGVyLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBzb3VyY2UgPSBmcm9tKG9ic2VydmFibGVzW2ldLCBzY2hlZHVsZXIpO1xuICAgICAgICAgICAgICAgICAgICB2YXIgaGFzRmlyc3RWYWx1ZSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YWx1ZXNbaV0gPSB2YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghaGFzRmlyc3RWYWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhhc0ZpcnN0VmFsdWUgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlbWFpbmluZ0ZpcnN0VmFsdWVzLS07XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXJlbWFpbmluZ0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lbmd0aCkge1xuICAgICAgICAgICAgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG4gICAgICAgIHZhciB2YWx1ZXMgPSBuZXcgQXJyYXkobGVuZ3RoKTtcbiAgICAgICAgdmFyIHJlbWFpbmluZ0NvbXBsZXRpb25zID0gbGVuZ3RoO1xuICAgICAgICB2YXIgcmVtYWluaW5nRW1pc3Npb25zID0gbGVuZ3RoO1xuICAgICAgICB2YXIgX2xvb3BfMSA9IGZ1bmN0aW9uIChzb3VyY2VJbmRleCkge1xuICAgICAgICAgICAgdmFyIGhhc1ZhbHVlID0gZmFsc2U7XG4gICAgICAgICAgICBpbm5lckZyb20oc291cmNlc1tzb3VyY2VJbmRleF0pLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgIGlmICghaGFzVmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICByZW1haW5pbmdFbWlzc2lvbnMtLTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgdmFsdWVzW3NvdXJjZUluZGV4XSA9IHZhbHVlO1xuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIGlmICghLS1yZW1haW5pbmdDb21wbGV0aW9ucyB8fCAhaGFzVmFsdWUpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKCFyZW1haW5pbmdFbWlzc2lvbnMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dChrZXlzID8gY3JlYXRlT2JqZWN0KGtleXMsIHZhbHVlcykgOiB2YWx1ZXMpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIuY29tcGxld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lbmVyYXRvcihyZWFkYWJsZVN0cmVhbSkpO1xufVxuZnVuY3Rpb24gcHJvY2Vzcyhhc3luY0l0ZXJhYmxlLCBzdWJzY3JpYmVyKSB7XG4gICAgdmFyIGFzeW5jSXRlcmFibGVfMSwgYXN5bmNJdGVyYWJsZV8xXzE7XG4gICAgdmFyIGVfMiwgX2E7XG4gICAgcmV0dXJuIF9fYXdhaXRlcih0aGlzLCB2b2lkIDAsIHZvaWQgMCwgZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgdmFsdWUsIGVfMl8xO1xuICAgICAgICByZXR1cm4gX19nZW5lcmF0b3IodGhpcywgZnVuY3Rpb24gKF9iKSB7XG4gICAgICAgICAgICBzd2l0Y2ggKF9iLmxhYmVsKSB7XG4gICAgICAgICAgICAgICAgY2FzZSAwOlxuICAgICAgICAgICAgICAgICAgICBfYi50cnlzLnB1c2goWzAsIDUsIDYsIDExXSk7XG4gICAgICAgICAgICAgICAgICAgIGFzeW5jSXRlcmFibGVfMSA9IF9fYXN5bmNWYWx1ZXMoYXN5bmNJdGVyYWJsZSk7XG4gICAgICAgICAgICAgICAgICAgIF9iLmxhYmVsID0gMTtcbiAgICAgICAgICAgICAgICBjYXNlIDE6IHJldHVybiBbNCwgYXN5bmNJdGVyYWJsZV8xLm5leHQoKV07XG4gICAgICAgICAgICAgICAgY2FzZSAyOlxuICAgICAgICAgICAgICAgICAgICBpZiAoIShhc3luY0l0ZXJhYmxlXzFfMSA9IF9iLnNlbnQoKSwgIWFzeW5jSXRlcmFibGVfMV8xLmRvbmUpKSByZXR1cm4gWzMsIDRdO1xuICAgICAgICAgICAgICAgICAgICB2YWx1ZSA9IGFzeW5jSXRlcmFibGVfMV8xLnZhbHVlO1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQodmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICBpZiAoc3Vic2NyaWJlci5jbG9zZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbMl07XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgX2IubGFiZWwgPSAzO1xuICAgICAgICAgICAgICAgIGNhc2UgMzogcmV0dXJuIFszLCAxXTtcbiAgICAgICAgICAgICAgICBjYXNlIDQ6IHJldHVybiBbMywgMTFdO1xuICAgICAgICAgICAgICAgIGNhc2UgNTpcbiAgICAgICAgICAgICAgICAgICAgZV8yXzEgPSBfYi5zZW50KCk7XG4gICAgICAgICAgICAgICAgICAgIGVfMiA9IHsgZXJyb3I6IGVfMl8xIH07XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBbMywgMTFdO1xuICAgICAgICAgICAgICAgIGNhc2UgNjpcbiAgICAgICAgICAgICAgICAgICAgX2IudHJ5cy5wdXNoKFs2LCAsIDksIDEwXSk7XG4gICAgICAgICAgICAgICAgICAgIGlmICghKGFzeW5jSXRlcmFibGVfMV8xICYmICFhc3luY0l0ZXJhYmxlXzFfMS5kb25lICYmIChfYSA9IGFzeW5jSXRlcmFibGVfMS5yZXR1cm4pKSkgcmV0dXJuIFszLCA4XTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFs0LCBfYS5jYWxsKGFzeW5jSXRlcmFibGVfMSldO1xuICAgICAgICAgICAgICAgIGNhc2UgNzpcbiAgICAgICAgICAgICAgICAgICAgX2Iuc2VudCgpO1xuICAgICAgICAgICAgICAgICAgICBfYi5sYWJlbCA9IDg7XG4gICAgICAgICAgICAgICAgY2FzZSA4OiByZXR1cm4gWzMsIDEwXTtcbiAgICAgICAgICAgICAgICBjYXNlIDk6XG4gICAgICAgICAgICAgICAgICAgIGlmIChlXzIpIHRocm93IGVfMi5lcnJvcjtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFs3XTtcbiAgICAgICAgICAgICAgICBjYXNlIDEwOiByZXR1cm4gWzddO1xuICAgICAgICAgICAgICAgIGNhc2UgMTE6XG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIuY29t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25zO1xuICAgICAgICBpZiAoIXJlc3VsdFNlbGVjdG9yT3JTY2hlZHVsZXIgfHwgaXNTY2hlZHVsZXIocmVzdWx0U2VsZWN0b3JPclNjaGVkdWxlcikpIHtcbiAgICAgICAgICAgIHJlc3VsdFNlbGVjdG9yID0gaWRlbnRpdHk7XG4gICAgICAgICAgICBzY2hlZHVsZXIgPSByZXN1bHRTZWxlY3Rvck9yU2NoZWR1bGVyO1xuICAgICAgICB9XG4gICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgcmVzdWx0U2VsZWN0b3IgPSByZXN1bHRTZWxlY3Rvck9yU2NoZWR1bGVyO1xuICAgICAgICB9XG4gICAgfVxuICAgIGZ1bmN0aW9uIGdlbigpIHtcbiAgICAgICAgdmFyIHN0YXRlO1xuICAgICAgICByZXR1cm4gX19nZW5lcmF0b3IodGhpcywgZnVuY3Rpb24gKF9hKSB7XG4gICAgICAgICAgICBzd2l0Y2ggKF9hLmxhYmVsKSB7XG4gICAgICAgICAgICAgICAgY2FzZSAwOlxuICAgICAgICAgICAgICAgICAgICBzdGF0ZSA9IGluaXRpYWxTdGF0ZTtcbiAgICAgICAgICAgICAgICAgICAgX2EubGFiZWwgPSAxO1xuICAgICAgICAgICAgICAgIGNhc2UgMTpcbiAgICAgICAgICAgICAgICAgICAgaWYgKCEoIWNvbmRpdGlvbiB8fCBjb25kaXRpb24oc3RhdGUpKSkgcmV0dXJuIFszLCA0XTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFs0LCByZXN1bHRTZWxlY3RvcihzdGF0ZSldO1xuICAgICAgICAgICAgICAgIGNhc2UgMjpcbiAgICAgICAgICAgICAgICAgICAgX2Euc2VudCgpO1xuICAgICAgICAgICAgICAgICAgICBfYS5sYWJlbCA9IDM7XG4gICAgICAgICAgICAgICAgY2FzZSAzOlxuICAgICAgICAgICAgICAgICAgICBzdGF0ZSA9IGl0ZXJhdGUoc3RhdGUpO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gW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nVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICBpZiAobiA8IGVuZCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KG4rKyk7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnNjaGVkdWxlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgOlxuICAgICAgICAgICAgZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcbiAgICAgICAgICAgICAgICB2YXIgbiA9IHN0YXJ0O1xuICAgICAgICAgICAgICAgIHdoaWxlIChuIDwgZW5kICYmICFzdWJzY3JpYmVyLmNsb3NlZCkge1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQobisrKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1yYW5nZS5qcy5tYXAiLCJpbXBvcnQgeyBPYnNlcnZhYmxlIH0gZnJvbSAnLi4vT2JzZXJ2YWJsZSc7XG5pbXBvcnQgeyBpc0Z1bmN0aW9uIH0gZnJvbSAnLi4vdXRpbC9pc0Z1bmN0aW9uJztcbmV4cG9ydCBmdW5jdGlvbiB0aHJvd0Vycm9yKGVycm9yT3JFcnJvckZhY3RvcnksIHNjaGVkdWxlcikge1xuICAgIHZhciBlcnJvckZhY3RvcnkgPSBpc0Z1bmN0aW9uKGVycm9yT3JFcnJvckZhY3RvcnkpID8gZXJyb3JPckVycm9yRmFjdG9yeSA6IGZ1bmN0aW9uICgpIHsgcmV0dXJuIGVycm9yT3JFc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ZmVyKSB7IHJldHVybiBidWZmZXIubGVuZ3RoOyB9KSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHJlc3VsdCA9IGJ1ZmZlcnMubWFwKGZ1bmN0aW9uIChidWZmZXIpIHsgcmV0dXJuIGJ1ZmZlci5zaGlmdCgpOyB9KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dChyZXN1bHRTZWxlY3RvciA/IHJlc3VsdFNlbGVjdG9yLmFwcGx5KHZvaWQgMCwgX19zcHJlYWRBcnJheShbXSwgX19yZWFkKHJlc3VsdCkpKSA6IHJlc3VsdCk7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAoYnVmZmVycy5zb21lKGZ1bmN0aW9uIChidWZmZXIsIGkpIHsgcmV0dXJuICFidWZmZXIubGVuZ3RoICYmIGNvbXBsZXRlZFtpXTsgfSkpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbXBsZXRlZFtzb3VyY2VJbmRleF0gPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICAhYnVmZmVyc1tzb3VyY2VJbmRleF0ubGVuZ3RoICYmIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgZm9yICh2YXIgc291cmNlSW5kZXggPSAwOyAhc3Vic2NyaWJlci5jbG9zZWQgJiYgc291cmNlSW5kZXggPCBzb3VyY2VzLmxlbmd0aDsgc291cmNlSW5kZXgrKykge1xuICAgICAgICAgICAgICAgIF9sb29wXzEoc291cmNlSW5kZXgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICBidWZmZXJzID0gY29tcGxldGVkID0gbnVsbDtcbiAgICAgICAgICAgIH07XG4gICAgICAgIH0pXG4gICAgICAgIDogRU1QVFk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD16aXAuanMubWFwIiwiaW1wb3J0IHsgX19leHRlbmRzIH0gZnJvbSBcInRzbGliXCI7XG5pbXBvcnQgeyBTdWJzY3JpYmVyIH0gZnJvbSAnLi4vU3Vic2NyaWJlcic7XG52YXIgT3BlcmF0b3JTdWJzY3JpYmVyID0gKGZ1bmN0aW9uIChfc3VwZXIpIHtcbiAgICBfX2V4dGVuZHMoT3BlcmF0b3JTdWJzY3JpYmVyLCBfc3VwZXIpO1xuICAgIGZ1bmN0aW9uIE9wZXJhdG9yU3Vic2NyaWJlcihkZXN0aW5hdGlvbiwgb25OZXh0LCBvbkNvbXBsZXRlLCBvbkVycm9yLCBvbkZpbmFsaXplKSB7XG4gICAgICAgIHZhciBfdGhpcyA9IF9zdXBlci5jYWxsKHRoaXMsIGRlc3RpbmF0aW9uKSB8fCB0aGlzO1xuICAgICAgICBfdGhpcy5vbkZpbmFsaXplID0gb25GaW5hbGl6ZTtcbiAgICAgICAgX3RoaXMuX25leHQgPSBvbk5leHRcbiAgICAgICAgICAgID8gZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgb25OZXh0KHZhbHVlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICAgICAgICBkZXN0aW5hdGlvbi5lcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIDogX3N1cGVyLnByb3RvdHlwZS5fbmV4dDtcbiAgICAgICAgX3RoaXMuX2Vycm9yID0gb25FcnJvclxuICAgICAgICAgICAgPyBmdW5jdGlvbiAoZXJyKSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgb25FcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgIGRlc3RpbmF0aW9uLmVycm9yKGVycik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgOiBfc3VwZXIucHJvdG90eXBlLl9lcnJvcjtcbiAgICAgICAgX3RoaXMuX2NvbXBsZXRlID0gb25Db21wbGV0ZVxuICAgICAgICAgICAgPyBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgb25Db21wbGV0ZSgpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgIGRlc3RpbmF0aW9uLmVycm9yKGVycik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgOiBfc3VwZXIucHJvdG90eXBlLl9jb21wbGV0ZTtcbiAgICAgICAgcmV0dXJuIF90aGlzO1xuICAgIH1cbiAgICBPcGVyYXRvclN1YnNjcmliZXIucHJvdG90eXBlLnVuc3Vic2NyaWJlID0gZnVuY3Rpb24gKCkge1xuICAgICAgICB2YXIgX2E7XG4gICAgICAgIHZhciBjbG9zZWQgPSB0aGlzLmNsb3NlZDtcbiAgICAgICAgX3N1cGVyLnByb3RvdHlwZS51bnN1YnNjcmli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A9IG51bGw7XG4gICAgICAgICAgICBpZiAoaGFzVmFsdWUpIHtcbiAgICAgICAgICAgICAgICBoYXNWYWx1ZSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IGxhc3RWYWx1ZTtcbiAgICAgICAgICAgICAgICBsYXN0VmFsdWUgPSBudWxsO1xuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dCh2YWx1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBpc0NvbXBsZXRlICYmIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgfTtcbiAgICAgICAgdmFyIGNsZWFudXBEdXJhdGlvbiA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIGR1cmF0aW9uU3Vic2NyaWJlciA9IG51bGw7XG4gICAgICAgICAgICBpc0NvbXBsZXRlICYmIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgfTtcbiAgICAgICAgc291cmNlLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgaGFzVmFsdWUgPSB0cnVlO1xuICAgICAgICAgICAgbGFzdFZhbHVlID0gdmFsdWU7XG4gICAgICAgICAgICBpZiAoIWR1cmF0aW9uU3Vic2NyaWJlcikge1xuICAgICAgICAgICAgICAgIGlubmVyRnJvbShkdXJhdGlvblNlbGVjdG9yKHZhbHVlKSkuc3Vic2NyaWJlKChkdXJhdGlvblN1YnNjcmliZXIgPSBuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGVuZER1cmF0aW9uLCBjbGVhbnVwRHVyYXRpb24pKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIGlzQ29tcGxldGUgPSB0cnVlO1xuICAgICAgICAgICAgKCFoYXNWYWx1ZSB8fCAh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0b0VtaXQgIT09IHZvaWQgMCA/IHRvRW1pdCA6IFtdO1xuICAgICAgICAgICAgICAgICAgICAgICAgdG9FbWl0LnB1c2goYnVmZmVyKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGNhdGNoIChlXzFfMSkgeyBlXzEgPSB7IGVycm9yOiBlXzFfMSB9OyB9XG4gICAgICAgICAgICBmaW5hbGx5IHtcbiAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICBpZiAoYnVmZmVyc18xXzEgJiYgIWJ1ZmZlcnNfMV8xLmRvbmUgJiYgKF9hID0gYnVmZmVyc18xLnJldHVybikpIF9hLmNhbGwoYnVmZmVyc18xKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgZmluYWxseSB7IGlmIChlXzEpIHRocm93IGVfMS5lcnJvcjsgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKHRvRW1pdCkge1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIGZvciAodmFyIHRvRW1pdF8xID0gX192YWx1ZXModG9FbWl0KSwgdG9FbWl0XzFfMSA9IHRvRW1pdF8xLm5leHQoKTsgIXRvRW1pdF8xXzEuZG9uZTsgdG9FbWl0XzFfMSA9IHRvRW1pdF8xLm5leHQoKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGJ1ZmZlciA9IHRvRW1pdF8xXzEudmFsdWU7XG4gICAgICAgICAgICAgICAgICAgICAgICBhcnJSZW1vdmUoYnVmZmVycywgYnVmZmVyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dChidWZmZXIpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGNhdGNoIChlXzJfMSkgeyBlXzIgPSB7IGVycm9yOiBlXzJfMSB9OyB9XG4gICAgICAgICAgICAgICAgZmluYWxseSB7XG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBpZiAodG9FbWl0XzFfMSAmJiAhdG9FbWl0XzFfMS5kb25lICYmIChfYiA9IHRvRW1pdF8xLnJldHVybikpIF9iLmNhbGwodG9FbWl0XzEpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGZpbmFsbHkgeyBpZiAoZV8yKSB0aHJvdyBlXzIuZXJyb3I7IH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIHZhciBlXzMsIF9hO1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciBidWZmZXJzXzIgPSBfX3ZhbHVlcyhidWZmZXJzKSwgYnVmZmVyc18yXzEgPSBidWZmZXJzXzIubmV4dCgpOyAhYnVmZmVyc18yXzEuZG9uZTsgYnVmZmVyc18yXzEgPSBidWZmZXJzXzIubmV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciBidWZmZXIgPSBidWZmZXJzXzJfMS52YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KGJ1ZmZlcik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2F0Y2ggKGVfM18xKSB7IGVfMyA9IHsgZXJyb3I6IGVfM18xIH07IH1cbiAgICAgICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChidWZmZXJzXzJfMSAmJiAhYnVmZmVyc18yXzEuZG9uZSAmJiAoX2EgPSBidWZmZXJzXzIucmV0dXJuKSkgX2EuY2FsbChidWZmZXJzXzIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgIC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vciAodmFyIHJlY29yZHNDb3B5XzEgPSBfX3ZhbHVlcyhyZWNvcmRzQ29weSksIHJlY29yZHNDb3B5XzFfMSA9IHJlY29yZHNDb3B5XzEubmV4dCgpOyAhcmVjb3Jkc0NvcHlfMV8xLmRvbmU7IHJlY29yZHNDb3B5XzFfMSA9IHJlY29yZHNDb3B5XzEubmV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciByZWNvcmQgPSByZWNvcmRzQ29weV8xXzEudmFsdWU7XG4gICAgICAgICAgICAgICAgICAgIHZhciBidWZmZXIgPSByZWNvcmQuYnVmZmVyO1xuICAgICAgICAgICAgICAgICAgICBidWZmZXIucHVzaCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgIG1heEJ1ZmZlclNpemUgPD0gYnVmZmVyLmxlbmd0aCAmJiBlbWl0KHJlY29yZCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2F0Y2ggKGVfMV8xKSB7IGVfMSA9IHsgZXJyb3I6IGVfMV8xIH07IH1cbiAgICAgICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChyZWNvcmRzQ29weV8xXzEgJiYgIXJlY29yZHNDb3B5XzFfMS5kb25lICYmIChfYSA9IHJlY29yZHNDb3B5XzEucmV0dXJuKSkgX2EuY2FsbChyZWNvcmRzQ29weV8xKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgZmluYWxseSB7IGlmIChlXzEpIHRocm93IGVfMS5lcnJvcjsgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICB3aGlsZSAoYnVmZmVyUmVjb3JkcyA9PT0gbnVsbCB8fCBidWZmZXJSZWNvcmRzID09PSB2b2lkIDAgPyB2b2lkIDAgOiBidWZmZXJSZWNvcmRzLmxlbmd0aCkge1xuICAgICAgICAg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ID0gYXN5bmNTY2hlZHVsZXI7IH1cbiAgICByZXR1cm4gb3BlcmF0ZShmdW5jdGlvbiAoc291cmNlLCBzdWJzY3JpYmVyKSB7XG4gICAgICAgIHZhciBhY3RpdmVUYXNrID0gbnVsbDtcbiAgICAgICAgdmFyIGxhc3RWYWx1ZSA9IG51bGw7XG4gICAgICAgIHZhciBsYXN0VGltZSA9IG51bGw7XG4gICAgICAgIHZhciBlbWl0ID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgaWYgKGFjdGl2ZVRhc2spIHtcbiAgICAgICAgICAgICAgICBhY3RpdmVUYXNrLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgYWN0aXZlVGFzayA9IG51bGw7XG4gICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gbGFzdFZhbHVlO1xuICAgICAgICAgICAgICAgIGxhc3RWYWx1ZSA9IG51bGw7XG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KHZhbHVlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgICAgZnVuY3Rpb24gZW1pdFdoZW5JZGxlKCkge1xuICAgICAgICAgICAgdmFyIHRhcmdldFRpbWUgPSBsYXN0VGltZSArIGR1ZVRpbWU7XG4gICAgICAgICAgICB2YXIgbm93ID0gc2NoZWR1bGVyLm5vdygpO1xuICAgICAgICAgICAgaWYgKG5vdyA8IHRhcmdldFRpbWUpIHtcbiAgICAgICAgICAgICAgICBhY3RpdmVUYXNrID0gdGhpcy5zY2hlZHVsZSh1bmRlZmluZWQsIHRhcmdldFRpbWUgLSBub3cpO1xuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIuYWRkKGFjdGl2ZVRhc2spO1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVtaXQoKTtcbiAgICAgICAgfVxuICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmli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vbm5lY3RvciA9IGVsZW1lbnRPck9wdGlvbnMuY29ubmVjdG9yKTtcbiAgICAgICAgfVxuICAgICAgICB2YXIgZ3JvdXBzID0gbmV3IE1hcCgpO1xuICAgICAgICB2YXIgbm90aWZ5ID0gZnVuY3Rpb24gKGNiKSB7XG4gICAgICAgICAgICBncm91cHMuZm9yRWFjaChjYik7XG4gICAgICAgICAgICBjYihzdWJzY3JpYmVyKTtcbiAgICAgICAgfTtcbiAgICAgICAgdmFyIGhhbmRsZUVycm9yID0gZnVuY3Rpb24gKGVycikgeyByZXR1cm4gbm90aWZ5KGZ1bmN0aW9uIChjb25zdW1lcikgeyByZXR1cm4gY29uc3VtZXIuZXJyb3IoZXJyKTsgfSk7IH07XG4gICAgICAgIHZhciBncm91cEJ5U291cmNlU3Vic2NyaWJlciA9IG5ldyBHcm91cEJ5U3Vic2NyaWJlcihzdWJzY3JpYmVyLCBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgdmFyIGtleV8xID0ga2V5U2VsZWN0b3IodmFsdWUpO1xuICAgICAgICAgICAgICAgIHZhciBncm91cF8xID0gZ3JvdXBzLmdldChrZXlfMSk7XG4gICAgICAgICAgICAgICAgaWYgKCFncm91cF8xKSB7XG4gICAgICAgICAgICAgICAgICAgIGdyb3Vwcy5zZXQoa2V5XzEsIChncm91cF8xID0gY29ubmVjdG9yID8gY29ubmVjdG9yKCkgOiBuZXcgU3ViamVjdCgpKSk7XG4gICAgICAgICAgICAgICAgICAgIHZhciBncm91cGVkID0gY3JlYXRlR3JvdXBlZE9ic2VydmFibGUoa2V5XzEsIGdyb3VwXzEpO1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQoZ3JvdXBlZCk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChkdXJhdGlvbikge1xuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGR1cmF0aW9uU3Vic2NyaWJlcl8xID0gbmV3IE9wZXJhdG9yU3Vic2NyaWJlcihncm91cF8xLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JvdXBfMS5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGR1cmF0aW9uU3Vic2NyaWJlcl8xID09PSBudWxsIHx8IGR1cmF0aW9uU3Vic2NyaWJlcl8xID09PSB2b2lkIDAgPyB2b2lkIDAgOiBkdXJhdGlvblN1YnNjcmliZXJfMS51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSwgdW5kZWZpbmVkLCB1bmRlZmluZWQsIGZ1bmN0aW9uICgpIHsgcmV0dXJuIGdyb3Vwcy5kZWxldGUoa2V5XzEpOyB9KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwQnlTb3VyY2VTdWJzY3JpYmVyLmFkZChpbm5lckZyb20oZHVyYXRpb24oZ3JvdXBlZCkpLnN1YnNjcmliZShkdXJhdGlvblN1YnNjcmliZXJfMSkpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGdyb3VwXzEubmV4dChlbGVtZW50ID8gZWxlbWVudCh2YWx1ZSkgOiB2YWx1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgaGFuZGxlRXJyb3IoZXJyKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSwgZnVuY3Rpb24gKCkgeyByZXR1cm4gbm90aWZ5KGZ1bmN0aW9uIChjb25zdW1lcikgeyByZXR1cm4gY29uc3VtZXIuY29tcGxldGUoKTsgfSk7IH0sIGhhbmRsZUVycm9yLCBmdW5jdGlvbiAoKSB7IHJldHVybiBncm91cHMuY2xlYXIoKTsgfSk7XG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUoZ3JvdXBCeVNvdXJjZVN1YnNjcmliZXIpO1xuICAgICAgICBmdW5jdGlvbiBjcmVhdGVHcm91cGVkT2JzZXJ2YWJsZShrZXksIGdyb3VwU3ViamVjdCkge1xuICAgICAgICAgICAgdmFyIHJlc3VsdCA9IG5ldyBPYnNlcnZhYmxlKGZ1bmN0aW9uIChncm91cFN1YnNjcmliZXIpIHtcbiAgICAgICAgICAgICAgICBncm91cEJ5U291cmNlU3Vic2NyaWJlci5hY3RpdmVHcm91cHMrKztcbiAgICAgICAgICAgICAgICB2YXIgaW5uZXJTdWIgPSBncm91cFN1YmplY3Quc3Vic2NyaWJlKGdyb3VwU3Vic2NyaWJlcik7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgaW5uZXJTdWIudW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgICAgICAgICAgLS1ncm91cEJ5U291cmNlU3Vic2NyaWJlci5hY3RpdmVHcm91cHMgPT09IDAgJiZcbiAgICAgICAgICAgICAgICAgICAgICAgIGdyb3VwQnlTb3VyY2VTdWJzY3JpYmVyLnRlYXJkb3duQXR0ZW1wdGVkICYmXG4gICAgICAgICAgICAgICAgICAgICAgICBncm91cEJ5U291cmNlU3Vic2NyaWJlci51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHJlc3VsdC5rZXkgPSBrZXk7XG4gICAgICAgICAgICByZXR1cm4gcmVzdWx0O1xuICAgICAgICB9XG4gICAgfSk7XG59XG52YXIgR3JvdXBCeVN1YnNjcmliZXIgPSAoZnVuY3Rpb24gKF9zdXBlcikge1xuICAgIF9fZXh0ZW5kcyhHcm91cEJ5U3Vic2NyaWJlciwgX3N1cGVyKTtcbiAgICBmdW5jdGlvbiBHcm91cEJ5U3Vic2NyaWJlcigpIHtcbiAgICAgICAgdmFyIF90aGlzID0gX3N1cGVyICE9PSBudWxsICYmIF9zdXBlci5hcHBseSh0aGlzLCBhc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JheSB9IGZyb20gJy4uL3V0aWwvYXJnc09yQXJnQXJyYXknO1xuaW1wb3J0IHsgT3BlcmF0b3JTdWJzY3JpYmVyIH0gZnJvbSAnLi9PcGVyYXRvclN1YnNjcmliZXInO1xuaW1wb3J0IHsgbm9vcCB9IGZyb20gJy4uL3V0aWwvbm9vcCc7XG5leHBvcnQgZnVuY3Rpb24gb25FcnJvclJlc3VtZU5leHQoKSB7XG4gICAgdmFyIHNvdXJjZXMgPSBbXTtcbiAgICBmb3IgKHZhciBfaSA9IDA7IF9pIDwgYXJndW1lbnRzLmxlbmd0aDsgX2krKykge1xuICAgICAgICBzb3VyY2VzW19pXSA9IGFyZ3VtZW50c1tfaV07XG4gICAgfVxuICAgIHZhciBuZXh0U291cmNlcyA9IGFyZ3NPckFyZ0FycmF5KHNvdXJjZXMpO1xuICAgIHJldHVybiBvcGVyYXRlKGZ1bmN0aW9uIChzb3VyY2UsIHN1YnNjcmliZXIpIHtcbiAgICAgICAgdmFyIHJlbWFpbmluZyA9IF9fc3ByZWFkQXJyYXkoW3NvdXJjZV0sIF9fcmVhZChuZXh0U291cmNlcykpO1xuICAgICAgICB2YXIgc3Vic2NyaWJlTmV4dCA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIGlmICghc3Vic2NyaWJlci5jbG9zZWQpIHtcbiAgICAgICAgICAgICAgICBpZiAocmVtYWluaW5nLmxlbmd0aCA+IDApIHtcbiAgICAgICAgICAgICAgICAgICAgdmFyIG5leHRTb3VyY2UgPSB2b2lkIDA7XG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBuZXh0U291cmNlID0gaW5uZXJGcm9tKHJlbWFpbmluZy5zaGlmdCgpKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVOZXh0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgdmFyIGlubmVyU3ViID0gbmV3IE9wZXJhdG9yU3Vic2NyaWJlcihzdWJzY3JpYmVyLCB1bmRlZmluZWQsIG5vb3AsIG5vb3ApO1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLmFkZChuZXh0U291cmNlLnN1YnNjcmliZShpbm5lclN1YikpO1xuICAgICAgICAgICAgICAgICAgICBpbm5lclN1Yi5hZGQoc3Vic2NyaWJlTmV4dCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICBzdWJzY3JpYmVOZXh0KCk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1vbkVycm9yUmVzdW1lTmV4dC5qcy5tYXAiLCJpbXBvcnQgeyBvcGVyYXRlIH0gZnJvbSAnLi4vdXRpbC9saWZ0JztcbmltcG9ydCB7IE9wZXJhdG9yU3Vic2NyaWJlciB9IGZyb20gJy4vT3BlcmF0b3JTdWJzY3JpYmVyJztcbmV4cG9ydCBmdW5jdGlvbiBwYWlyd2lzZSgpIHtcbiAgICByZXR1cm4gb3BlcmF0ZShmdW5jdGlvbiAoc291cmNlLCBzdWJzY3JpYmVyKSB7XG4gICAgICAgIHZhciBwcmV2O1xuICAgICAgICB2YXIgaGFzUHJldiA9IGZhbHNlO1xuICAgICAgICBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgICAgICB2YXIgcCA9IHByZXY7XG4gICAgICAgICAgICBwcmV2ID0gdmFsdWU7XG4gICAgICAgICAgICB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gICAgICAgdmFyIHN1YnNjcmliZUZvclJlcGVhdCA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICB2YXIgc3luY1Vuc3ViID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgaW5uZXJTdWIgPSBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgdW5kZWZpbmVkLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICgrK3NvRmFyIDwgY291bnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbm5lclN1Yikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyU3ViLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJTdWIgPSBudWxsO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZUZvclJlcGVhdCgpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgc3luY1Vuc3ViID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgICAgICBpZiAoc3luY1Vuc3ViKSB7XG4gICAgICAgICAgICAgICAgICAgIGlubmVyU3ViLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgICAgIGlubmVyU3ViID0gbnVsbDtcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlRm9yUmVwZWF0KCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgIC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bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGlubmVyU3ViKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzdWJzY3JpYmVGb3JSZXBlYXRXaGVuKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzeW5jUmVzdWIgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICBpc05vdGlmaWVyQ29tcGxldGUgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICBjaGVja0NvbXBsZXRlKCk7XG4gICAgICAgICAgICAgICAgfSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGNvbXBsZXRpb25zJDtcbiAgICAgICAgfTtcbiAgICAgICAgdmFyIHN1YnNjcmliZUZvclJlcGVhdFdoZW4gPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICBpc01haW5Db21wbGV0ZSA9IGZhbHNlO1xuICAgICAgICAgICAgaW5uZXJTdWIgPSBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgdW5kZWZpbmVkLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgaXNNYWluQ29tcGxldGUgPSB0cnVlO1xuICAgICAgICAgICAgICAgICFjaGVja0NvbXBsZXRlKCkgJiYgZ2V0Q29tcGxldGlvblN1YmplY3QoKS5uZXh0KCk7XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICBpZiAoc3luY1Jlc3ViKSB7XG4gICAgICAgICAgICAgICAgaW5uZXJTdWIudW5zdWJzY3JpYmUoKTtcbiAgICAgICAgICAgICAgICBpbm5lclN1YiA9IG51bGw7XG4gICAgICAgICAgICAgICAgc3luY1Jlc3ViID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgc3Vic2NyaWJlRm9yUmVwZWF0V2hlbigpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgICBzdWJzY3JpYmVGb3JSZXBlYXRXaGVuKCk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1yZXBlYXRXaGVuLmpzLm1hcCIsImltcG9ydCB7IG9wZXJhdGUgfSBmcm9tICcuLi91dGlsL2xpZnQnO1xuaW1wb3J0IHsgT3BlcmF0b3JTdWJzY3JpYmVyIH0gZnJvbSAnLi9PcGVyYXRvclN1YnNjcmliZXInO1xuaW1wb3J0IHsgaWRlbnRpdHkgfSBmcm9tICcuLi91dGlsL2lkZW50aXR5JztcbmV4cG9ydCBmdW5jdGlvbiByZXRyeShjb25maWdPckNvdW50KSB7XG4gICAgaWYgKGNvbmZpZ09yQ291bnQgPT09IHZvaWQgMCkgeyBjb25maWdPckNvdW50ID0gSW5maW5pdHk7IH1cbiAgICB2YXIgY29uZmlnO1xuICAgIGlmIChjb25maWdPckNvdW50ICYmIHR5cGVvZiBjb25maWdPckNvdW50ID09PSAnb2JqZWN0Jykge1xuICAgICAgICBjb25maWcgPSBjb25maWdPckNvdW50O1xuICAgIH1cbiAgICBlbHNlIHtcbiAgICAgICAgY29uZmlnID0ge1xuICAgICAgICAgICAgY291bnQ6IGNvbmZpZ09yQ291bnQsXG4gICAgICAgIH07XG4gICAgfVxuICAgIHZhciBjb3VudCA9IGNvbmZpZy5jb3VudCwgX2EgPSBjb25maWcucmVzZXRPblN1Y2Nlc3MsIHJlc2V0T25TdWNjZXNzID0gX2EgPT09IHZvaWQgMCA/IGZhbHNlIDogX2E7XG4gICAgcmV0dXJuIGNvdW50IDw9IDBcbiAgICAgICAgPyBpZGVudGl0eVxuICAgICAgICA6IG9wZXJhdGUoZnVuY3Rpb24gKHNvdXJjZSwgc3Vic2NyaWJlcikge1xuICAgICAgICAgICAgdmFyIHNvRmFyID0gMDtcbiAgICAgICAgICAgIHZhciBpbm5lclN1YjtcbiAgICAgICAgICAgIHZhciBzdWJzY3JpYmVGb3JSZXRyeSA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICB2YXIgc3luY1Vuc3ViID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgaW5uZXJTdWIgPSBzb3VyY2Uuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChyZXNldE9uU3VjY2Vzcykge1xuICAgICAgICAgICAgICAgICAgICAgICAgc29GYXIgPSAwO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZXIubmV4dCh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgfSwgdW5kZWZpbmVkLCBmdW5jdGlvbiAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChzb0ZhcisrIDwgY291bnQpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbm5lclN1Yikge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyU3ViLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5uZXJTdWIgPSBudWxsO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YnNjcmliZUZvclJldHJ5KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzeW5jVW5zdWIgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5lcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgICAgICB9XG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TdWJqZWN0KCk7XG4gICAgICAgICAgICAgICAgICAgIG5vdGlmaWVyKGVycm9ycyQpLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBpbm5lclN1YiA/IHN1YnNjcmliZUZvclJldHJ5V2hlbigpIDogKHN5bmNSZXN1YiA9IHRydWUpO1xuICAgICAgICAgICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChlcnJvcnMkKSB7XG4gICAgICAgICAgICAgICAgICAgIGVycm9ycyQubmV4dChlcnIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pKTtcbiAgICAgICAgICAgIGlmIChzeW5jUmVzdWIpIHtcbiAgICAgICAgICAgICAgICBpbm5lclN1Yi51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgICAgIGlubmVyU3ViID0gbnVsbDtcbiAgICAgICAgICAgICAgICBzeW5jUmVzdWIgPSBmYWxzZTtcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVGb3JSZXRyeVdoZW4oKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgICAgc3Vic2NyaWJlRm9yUmV0cnlXaGVuKCk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1yZXRyeVdoZW4uanMubWFwIiwiaW1wb3J0IHsgb3BlcmF0ZSB9IGZyb20gJy4uL3V0aWwvbGlmdCc7XG5pbXBvcnQgeyBub29wIH0gZnJvbSAnLi4vdXRpbC9ub29wJztcbmltcG9ydCB7IE9wZXJhdG9yU3Vic2NyaWJlciB9IGZyb20gJy4vT3BlcmF0b3JTdWJzY3JpYmVyJztcbmV4cG9ydCBmdW5jdGlvbiBzYW1wbGUobm90aWZpZXIpIHtcbiAgICByZXR1cm4gb3BlcmF0ZShmdW5jdGlvbiAo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WJzY3JpYmVyLm5leHQoaXNFcXVhbCk7XG4gICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgIH07XG4gICAgICAgIHZhciBjcmVhdGVTdWJzY3JpYmVyID0gZnVuY3Rpb24gKHNlbGZTdGF0ZSwgb3RoZXJTdGF0ZSkge1xuICAgICAgICAgICAgdmFyIHNlcXVlbmNlRXF1YWxTdWJzY3JpYmVyID0gbmV3IE9wZXJhdG9yU3Vic2NyaWJlcihzdWJzY3JpYmVyLCBmdW5jdGlvbiAoYSkge1xuICAgICAgICAgICAgICAgIHZhciBidWZmZXIgPSBvdGhlclN0YXRlLmJ1ZmZlciwgY29tcGxldGUgPSBvdGhlclN0YXRlLmNvbXBsZXRlO1xuICAgICAgICAgICAgICAgIGlmIChidWZmZXIubGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbXBsZXRlID8gZW1pdChmYWxzZSkgOiBzZWxmU3RhdGUuYnVmZmVyLnB1c2goYSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAhY29tcGFyYXRvcihhLCBidWZmZXIuc2hpZnQoKSkgJiYgZW1pdChmYWxzZSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHNlbGZTdGF0ZS5jb21wbGV0ZSA9IHRydWU7XG4gICAgICAgICAgICAgICAgdmFyIGNvbXBsZXRlID0gb3RoZXJTdGF0ZS5jb21wbGV0ZSwgYnVmZmVyID0gb3RoZXJTdGF0ZS5idWZmZXI7XG4gICAgICAgICAgICAgICAgY29tcGxldGUgJiYgZW1pdChidWZmZXIubGVuZ3RoID09PSAwKTtcbiAgICAgICAgICAgICAgICBzZXF1ZW5jZUVxdWFsU3Vic2NyaWJlciA9PT0gbnVsbCB8fCBzZXF1ZW5jZUVxdWFsU3Vic2NyaWJl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vbXBsZXRlZCA9IGhhc0Vycm9yZWQgPSBmYWxzZTtcbiAgICAgICAgfTtcbiAgICAgICAgdmFyIHJlc2V0QW5kVW5zdWJzY3JpYmUgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICB2YXIgY29ubiA9IGNvbm5lY3Rpb247XG4gICAgICAgICAgICByZXNldCgpO1xuICAgICAgICAgICAgY29ubiA9PT0gbnVsbCB8fCBjb25uID09PSB2b2lkIDAgPyB2b2lkIDAgOiBjb25uLnVuc3Vic2NyaWJlKCk7XG4gICAgICAgIH07XG4gICAgICAgIHJldHVybiBvcGVyYXRlKGZ1bmN0aW9uIChzb3VyY2UsIHN1YnNjcmliZXIpIHtcbiAgICAgICAgICAgIHJlZkNvdW50Kys7XG4gICAgICAgICAgICBpZiAoIWhhc0Vycm9yZWQgJiYgIWhhc0NvbXBsZXRlZCkge1xuICAgICAgICAgICAgICAgIGNhbmNlbFJlc2V0KCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgZGVzdCA9IChzdWJqZWN0ID0gc3ViamVjdCAhPT0gbnVsbCAmJiBzdWJqZWN0ICE9PSB2b2lkIDAgPyBzdWJqZWN0IDogY29ubmVjdG9yKCkpO1xuICAgICAgICAgICAgc3Vic2NyaWJlci5hZGQoZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHJlZkNvdW50LS07XG4gICAgICAgICAgICAgICAgaWYgKHJlZkNvdW50ID09PSAwICYmICFoYXNFcnJvcmVkICYmICFoYXNDb21wbGV0ZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzZXRDb25uZWN0aW9uID0gaGFuZGxlUmVzZXQocmVzZXRBbmRVbnN1YnNjcmliZSwgcmVzZXRPblJlZkNvdW50WmVybyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICBkZXN0LnN1YnNjcmliZShzdWJzY3JpYmVyKTtcbiAgICAgICAgICAgIGlmICghY29ubmVjdGlvbikge1xuICAgICAgICAgICAgICAgIGNvbm5lY3Rpb24gPSBuZXcgU2FmZVN1YnNjcmliZXIoe1xuICAgICAgICAgICAgICAgICAgICBuZXh0OiBmdW5jdGlvbiAodmFsdWUpIHsgcmV0dXJuIGRlc3QubmV4dCh2YWx1ZSk7IH0sXG4gICAgICAgICAgICAgICAgICAgIGVycm9yOiBmdW5jdGlvbiAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBoYXNFcnJvcmVkID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNhbmNlbFJlc2V0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXNldENvbm5lY3Rpb24gPSBoYW5kbGVSZXNldChyZXNldCwgcmVzZXRPbkVycm9yLCBlcnIpO1xuICAgICAgICAgICAgICAgICAgICAgICAgZGVzdC5lcnJvcihlcnIpO1xuICAgICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgICBjb21wbGV0ZTogZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaGFzQ29tcGxldGVkID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNhbmNlbFJlc2V0KCk7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXNldENvbm5lY3Rpb24gPSBoYW5kbGVSZXNldChyZXNldCwgcmVzZXRPbkNvbXBsZXRlKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIGRlc3QuY29tcGxldGUoKTtcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICBmcm9tKHNvdXJjZSkuc3Vic2NyaWJlKGNvbm5lY3Rpb24pO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KSh3cmFwcGVyU291cmNlKTtcbiAgICB9O1xufVxuZnVuY3Rpb24gaGFuZGxlUmVzZXQocmVzZXQsIG9uKSB7XG4gICAgdmFyIGFyZ3MgPSBbXTtcbiAgICBmb3Ig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nW3ZhbHVlSW5kZXhdID0gdmFsdWU7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICB2YXIgaW5kZXggPSB2YWx1ZUluZGV4ICUgc2tpcENvdW50O1xuICAgICAgICAgICAgICAgICAgICB2YXIgb2xkVmFsdWUgPSByaW5nW2luZGV4XTtcbiAgICAgICAgICAgICAgICAgICAgcmluZ1tpbmRleF0gPSB2YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KG9sZFZhbHVlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICAgIHJpbmcgPSBudWxsO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1za2lwTGFzdC5qcy5tYXAiLCJpbXBvcnQgeyBvcGVyYXRlIH0gZnJvbSAnLi4vdXRpbC9saWZ0JztcbmltcG9ydCB7IE9wZXJhdG9yU3Vic2NyaWJlciB9IGZyb20gJy4vT3BlcmF0b3JTdWJzY3JpYmVyJztcbmltcG9ydCB7IGlubmVyRnJvbSB9IGZyb20gJy4uL29ic2VydmFibGUvZnJvbSc7XG5pbXBvcnQgeyBub29wIH0gZnJvbSAnLi4vdXRpbC9ub29wJztcbmV4cG9ydCBmdW5jdGlvbiBza2lwVW50aWwobm90aWZpZXIpIHtcbiAgICByZXR1cm4gb3BlcmF0ZShmdW5jdGlvbiAoc291cmNlLCBzdWJzY3JpYmVyKSB7XG4gICAgICAgIHZhciB0YWtpbmcgPSBmYWxzZTtcbiAgICAgICAgdmFyIHNraXBTdWJzY3JpYmVyID0gbmV3IE9wZXJhdG9yU3Vic2NyaWJlcihzdWJzY3JpYmVyLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICBza2lwU3Vic2NyaWJlciA9P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N1YnNjcmliZXInO1xuZXhwb3J0IGZ1bmN0aW9uIHRha2VMYXN0KGNvdW50KSB7XG4gICAgcmV0dXJuIGNvdW50IDw9IDBcbiAgICAgICAgPyBmdW5jdGlvbiAoKSB7IHJldHVybiBFTVBUWTsgfVxuICAgICAgICA6IG9wZXJhdGUoZnVuY3Rpb24gKHNvdXJjZSwgc3Vic2NyaWJlcikge1xuICAgICAgICAgICAgdmFyIGJ1ZmZlciA9IFtdO1xuICAgICAgICAgICAgc291cmNlLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgIGJ1ZmZlci5wdXNoKHZhbHVlKTtcbiAgICAgICAgICAgICAgICBjb3VudCA8IGJ1ZmZlci5sZW5ndGggJiYgYnVmZmVyLnNoaWZ0KCk7XG4gICAgICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgdmFyIGVfMSwgX2E7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgZm9yICh2YXIgYnVmZmVyXzEgPSBfX3ZhbHVlcyhidWZmZXIpLCBidWZmZXJfMV8xID0gYnVmZmVyXzEubmV4dCgpOyAhYnVmZmVyXzFfMS5kb25lOyBidWZmZXJfMV8xID0gYnVmZmVyXzEubmV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgdmFsdWUgPSBidWZmZXJfMV8xLnZhbHVlO1xuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KHZhbHVlKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjYXRjaCAoZV8xXzEpIHsgZV8xID0geyBlcnJvcjogZV8xXzEgfTsgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkge1xuICAgICAgICAgICAgICAgICAgICB0cnkge1x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ZSA9IGZhbHNlO1xuICAgICAgICB2YXIgZW5kVGhyb3R0bGluZyA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIHRocm90dGxlZCA9PT0gbnVsbCB8fCB0aHJvdHRsZWQgPT09IHZvaWQgMCA/IHZvaWQgMCA6IHRocm90dGxlZC51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgdGhyb3R0bGVkID0gbnVsbDtcbiAgICAgICAgICAgIGlmICh0cmFpbGluZykge1xuICAgICAgICAgICAgICAgIHNlbmQoKTtcbiAgICAgICAgICAgICAgICBpc0NvbXBsZXRlICYmIHN1YnNjcmliZXIuY29tcGxldGUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgICAgdmFyIGNsZWFudXBUaHJvdHRsaW5nID0gZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgdGhyb3R0bGVkID0gbnVsbDtcbiAgICAgICAgICAgIGlzQ29tcGxldGUgJiYgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICB9O1xuICAgICAgICB2YXIgc3RhcnRUaHJvdHRsZSA9IGZ1bmN0aW9uICh2YWx1ZSkge1xuICAgICAgICAgICAgcmV0dXJuICh0aHJvdHRsZWQgPSBpbm5lckZyb20oZHVyYXRpb25TZWxlY3Rvcih2YWx1ZSkpLnN1YnNjcmliZShuZXcgT3BlcmF0b3JTdWJzY3JpYmVyKHN1YnNjcmliZXIsIGVuZFRocm90dGxpbmcsIGNsZWFudXBUaHJvdHRsaW5nKSkpO1xuICAgICAgICB9O1xuICAgICAgICB2YXIgc2VuZCA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIGlmIChoYXNWYWx1ZSkge1xuICAgICAgICAgICAgICAgIGhhc1ZhbHVlID0gZmFsc2U7XG4gICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gc2VuZFZhbHVlO1xuICAgICAgICAgICAgICAgIHNlbmRWYWx1ZSA9IG51bGw7XG4gICAgICAgICAgICAgIC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IFtuZXcgU3ViamVjdCgpXTtcbiAgICAgICAgdmFyIHN0YXJ0cyA9IFtdO1xuICAgICAgICB2YXIgY291bnQgPSAwO1xuICAgICAgICBzdWJzY3JpYmVyLm5leHQod2luZG93c1swXS5hc09ic2VydmFibGUoKSk7XG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUobmV3IE9wZXJhdG9yU3Vic2NyaWJlcihzdWJzY3JpYmVyLCBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgICAgIHZhciBlXzEsIF9hO1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciB3aW5kb3dzXzEgPSBfX3ZhbHVlcyh3aW5kb3dzKSwgd2luZG93c18xXzEgPSB3aW5kb3dzXzEubmV4dCgpOyAhd2luZG93c18xXzEuZG9uZTsgd2luZG93c18xXzEgPSB3aW5kb3dzXzEubmV4dCgpKSB7XG4gICAgICAgICAgICAgICAgICAgIHZhciB3aW5kb3dfMSA9IHdpbmRvd3NfMV8xLnZhbHVlO1xuICAgICAgICAgICAgICAgICAgICB3aW5kb3dfMS5uZXh0KHZhbHVlKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjYXRjaCAoZV8xXzEpIHsgZV8xID0geyBlcnJvcjogZV8xXzEgfTsgfVxuICAgICAgICAgICAgZmluYWxseSB7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHdpbmRvd3NfMV8xICYmICF3aW5kb3dzXzFfMS5kb25lICYmIChfYSA9IHdpbmRvd3NfMS5yZXR1cm4pKSBfYS5jYWxsKHdpbmRvd3NfMSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkgeyBpZiAoZV8xKSB0aHJvdyBlXzEuZXJyb3I7IH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciBjID0gY291bnQgLSB3aW5kb3dTaXplICsgMTtcbiAgICAgICAgICAgIGlmIChjID49IDAgJiYgYyAlIHN0YXJ0RXZlcnkgPT09IDApIHtcbiAgICAgICAgICAgICAgICB3aW5kb3dzLnNoaWZ0KCkuY29tcGxldGUoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmICgrK2NvdW50ICUgc3RhcnRFdmVyeSA9PT0gMCkge1xuICAgICAgICAgICAgICAgIHZhciB3aW5kb3dfMiA9IG5ldyBTdWJqZWN0KCk7XG4gICAgICAgICAgICAgICAgd2luZG93cy5wdXNoKHdpbmRvd18yKTtcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQod2luZG93XzIuYXNPYnNlcnZhYmxlKCkpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9LCBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICB3aGlsZSAod2luZG93cy5sZW5ndGggPiAwKSB7XG4gICAgICAgICAgICAgICAgd2luZG93cy5zaGlmdCgpLmNvbXBsZXRlKCk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBzdWJzY3JpYmVyLmNvbXBsZXRlKCk7XG4gICAgICAgIH0sIGZ1bmN0aW9uIChlcnIpIHtcbiAgICAgICAgICAgIHdoaWxlICh3aW5kb3dzLmxlbmd0aCA+IDApIHtcbiAgICAgICAgICAgICAgICB3aW5kb3dzLnNoaWZ0KCkuZXJyb3IoZXJyKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHN1YnNjcmliZXIuZXJyb3IoZXJyKTtcbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgc3RhcnRzID0gbnVsbDtcbiAgICAgICAgICAgIHdpbmRvd3MgPSBudWxsO1xuICAgICAgICB9KSk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD13aW5kb3dDb3VudC5qcy5tYXAiLCJpbXBvcnQgeyBTdWJqZWN0IH0gZnJvbSAnLi4vU3ViamVjdCc7XG5pbXBvcnQgey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ICAgICAgICB2YXIgcmVzdGFydE9uQ2xvc2UgPSBmYWxzZTtcbiAgICAgICAgdmFyIGNsb3NlV2luZG93ID0gZnVuY3Rpb24gKHJlY29yZCkge1xuICAgICAgICAgICAgdmFyIHdpbmRvdyA9IHJlY29yZC53aW5kb3csIHN1YnMgPSByZWNvcmQuc3VicztcbiAgICAgICAgICAgIHdpbmRvdy5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgc3Vicy51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgYXJyUmVtb3ZlKHdpbmRvd1JlY29yZHMsIHJlY29yZCk7XG4gICAgICAgICAgICByZXN0YXJ0T25DbG9zZSAmJiBzdGFydFdpbmRvdygpO1xuICAgICAgICB9O1xuICAgICAgICB2YXIgc3RhcnRXaW5kb3cgPSBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICBpZiAod2luZG93UmVjb3Jkcykge1xuICAgICAgICAgICAgICAgIHZhciBzdWJzID0gbmV3IFN1YnNjcmlwdGlvbigpO1xuICAgICAgICAgICAgICAgIHN1YnNjcmliZXIuYWRkKHN1YnMpO1xuICAgICAgICAgICAgICAgIHZhciB3aW5kb3dfMSA9IG5ldyBTdWJqZWN0KCk7XG4gICAgICAgICAgICAgICAgdmFyIHJlY29yZF8xID0ge1xuICAgICAgICAgICAgICAgICAgICB3aW5kb3c6IHdpbmRvd18xLFxuICAgICAgICAgICAgICAgICAgICBzdWJzOiBzdWJzLFxuICAgICAgICAgICAgICAgICAgICBzZWVuOiAwLFxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgd2luZG93UmVjb3Jkcy5wdXNoKHJlY29yZF8xKTtcbiAgICAgICAgICAgICAgICBzdWJzY3JpYmVyLm5leHQod2luZG93XzEuYXNPYnNlcnZhYmxlKCkpO1xuICAgICAgICAgICAgICAgIHN1YnMuYWRkKHNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7IHJldHVybiBjbG9zZVdpbmRvdyhyZWNvcm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uICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBjbG9zaW5nTm90aWZpZXIgPSBpbm5lckZyb20oY2xvc2luZ1NlbGVjdG9yKG9wZW5WYWx1ZSkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICAgIGhhbmRsZUVycm9yKGVycik7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KHdpbmRvdy5hc09ic2VydmFibGUoKSk7XG4gICAgICAgICAgICBjbG9zaW5nU3Vic2NyaXB0aW9uLmFkZChjbG9zaW5nTm90aWZpZXIuc3Vic2NyaWJlKG5ldyBPcGVyYXRvclN1YnNjcmliZXIoc3Vic2NyaWJlciwgY2xvc2VXaW5kb3csIG5vb3AsIGhhbmRsZUVycm9yKSkpO1xuICAgICAgICB9LCBub29wKSk7XG4gICAgICAgIHNvdXJjZS5zdWJzY3JpYmUobmV3IE9wZXJhdG9yU3Vic2NyaWJlcihzdWJzY3JpYmVyLCBmdW5jdGlvbiAodmFsdWUpIHtcbiAgICAgICAgICAgIHZhciBlXzEsIF9hO1xuICAgICAgICAgICAgdmFyIHdpbmRvd3NDb3B5ID0gd2luZG93cy5zbGljZSgpO1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBmb3IgKHZhciB3aW5kb3dzQ29weV8xID0gX192YWx1ZXMod2luZG93c0NvcHkpLCB3aW5kb3dzQ29weV8xXzEgPSB3aW5kb3dzQ29weV8xLm5leHQoKTsgIXdpbmRvd3NDb3B5XzFfMS5kb25lOyB3aW5kb3dzQ29weV8xXzEgPSB3aW5kb3dzQ29weV8xLm5leHQoKSkge1xuICAgICAgICAgICAgICAgICAgICB2YXIgd2luZG93XzEgPSB3aW5kb3dzQ29weV8xXzEudmFsdWU7XG4gICAgICAgICAgICAgICAgICAgIHdpbmRvd18xLm5leHQodmFsdWUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGNhdGNoIChlXzFfMSkgeyBlXzEgPSB7IGVycm9yOiBlXzFfMSB9OyB9XG4gICAgICAgICAgICBmaW5hbGx5IHtcbiAgICAgICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICAgICAgICBpZiAod2luZG93c0NvcHlfMV8xICYmICF3aW5kb3dzQ29weV8xXzEuZG9uZSAmJiAoX2EgPSB3aW5kb3dzQ29weV8xLnJldHVybikpIF9hLmNhbGwod2luZG93c0NvcHlfMSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZpbmFsbHkgeyBpZiAoZV8xKSB0aHJvdyBlXzEuZXJyb3I7IH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgd2hpbGUgKDAgPCB3aW5kb3dzLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgIHdpbmRvd3Muc2hpZnQoKS5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICB9LCBoYW5kbGVFcnJvciwgZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgd2hpbGUgKDAgPCB3aW5kb3dzLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgIHdpbmRvd3Muc2hpZnQoKS51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KSk7XG4gICAgfSk7XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD13aW5kb3dUb2dnbGUuanMubWFwIiwiaW1wb3J0IHsgU3ViamVjdCB9IGZyb20gJy4uL1N1YmplY3QnO1xuaW1wb3J0IHsgb3BlcmF0ZSB9IGZyb20gJy4uL3V0aWwvbGlmdCc7XG5pbXBvcnQgeyBPcGVyYXRvclN1YnNjcmliZXIgfSBmcm9tICcuL09wZXJhdG9yU3Vic2NyaWJlcic7XG5pbXBvcnQgeyBpbm5lckZyb20gfSBmcm9tICcuLi9vYnNlcnZhYmxlL2Zyb20nO1xuZXhwb3J0IGZ1bmN0aW9uIHdpbmRvd1doZW4oY2xvc2luZ1NlbGVjdG9yKSB7XG4gICAgcmV0dXJuIG9wZXJhdGUoZnVuY3Rpb24gKHNvdXJjZSwgc3Vic2NyaWJlcikge1xuICAgICAgICB2YXIgd2luZG93O1xuICAgICAgICB2YXIgY2xvc2luZ1N1YnNjcmliZXI7XG4gICAgICAgIHZhciBoYW5kbGVFcnJvciA9IGZ1bmN0aW9uIChlcnIpIHtcbiAgICAgICAgICAgIHdpbmRvdy5lcnJvcihlcnIpO1xuICAgICAgICAgICAgc3Vic2NyaWJlci5lcnJvcihlcnIpO1xuICAgICAgICB9O1xuICAgICAgICB2YXIgb3BlbldpbmRvdyA9IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgIGNsb3NpbmdTdWJzY3JpYmVyID09PSBudWxsIHx8IGNsb3NpbmdTdWJzY3JpYmVyID09PSB2b2lkIDAgPyB2b2lkIDAgOiBjbG9zaW5nU3Vic2NyaWJlci51bnN1YnNjcmliZSgpO1xuICAgICAgICAgICAgd2luZG93ID09PSBudWxsIHx8IHdpbmRvdyA9PT0gdm9pZCAwID8gdm9pZCAwIDogd2luZG93LmNvbXBsZXRlKCk7XG4gICAgICAgICAgICB3aW5kb3cgPSBuZXcgU3ViamVjdCgpO1xuICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KHdpbmRvdy5hc09ic2VydmFibGUoKSk7XG4gICAgICAgICAgICB2YXIgY2xvc2luZ05vdGlmaWVyO1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBjbG9zaW5nTm90aWZpZXIgPSBpbm5lckZyb20oY2xvc2luZ1NlbGVjdG9yKCkpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICAgIGhhbmRsZUV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IE9ic2VydmFibGUoZnVuY3Rpb24gKHN1YnNjcmliZXIpIHtcbiAgICAgICAgdmFyIHN1YiA9IG5ldyBTdWJzY3JpcHRpb24oKTtcbiAgICAgICAgc3ViLmFkZChzY2hlZHVsZXIuc2NoZWR1bGUoZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgdmFyIGl0ZXJhdG9yID0gaW5wdXRbU3ltYm9sLmFzeW5jSXRlcmF0b3JdKCk7XG4gICAgICAgICAgICBzdWIuYWRkKHNjaGVkdWxlci5zY2hlZHVsZShmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgICAgdmFyIF90aGlzID0gdGhpcztcbiAgICAgICAgICAgICAgICBpdGVyYXRvci5uZXh0KCkudGhlbihmdW5jdGlvbiAocmVzdWx0KSB7XG4gICAgICAgICAgICAgICAgICAgIGlmIChyZXN1bHQuZG9uZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5jb21wbGV0ZSgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgc3Vic2NyaWJlci5uZXh0KHJlc3VsdC52YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICBfdGhpcy5zY2hlZHVsZSgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9KSk7XG4gICAgICAgIH0pKTtcbiAgICAgICAgcmV0dXJuIHN1YjtcbiAgICB9KTtcbn1cbi8vIyBzb3VyY2VNYXBwaW5nVVJMPXNjaGVkdWxlQXN5bmNJdGVyYWJsZS5qcy5tYXAiLCJpbXBvcnQgeyBPYnNlcnZhYmxlIH0gZnJvbSAnLi4vT2JzZXJ2YWJsZSc7XG5pbXBvcnQgeyBpdGVyYXRvciBhcyBTeW1ib2xfaXRlcmF0b3IgfSBmcm9tICcuLi9zeW1ib2wvaXRlcmF0b3InO1xuaW1wb3J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h0ID0gbnVsbDtcbmV4cG9ydCBmdW5jdGlvbiBlcnJvckNvbnRleHQoY2IpIHtcbiAgICBpZiAoY29uZmlnLnVzZURlcHJlY2F0ZWRTeW5jaHJvbm91c0Vycm9ySGFuZGxpbmcpIHtcbiAgICAgICAgdmFyIGlzUm9vdCA9ICFjb250ZXh0O1xuICAgICAgICBpZiAoaXNSb290KSB7XG4gICAgICAgICAgICBjb250ZXh0ID0geyBlcnJvclRocm93bjogZmFsc2UsIGVycm9yOiBudWxsIH07XG4gICAgICAgIH1cbiAgICAgICAgY2IoKTtcbiAgICAgICAgaWYgKGlzUm9vdCkge1xuICAgICAgICAgICAgdmFyIF9hID0gY29udGV4dCwgZXJyb3JUaHJvd24gPSBfYS5lcnJvclRocm93biwgZXJyb3IgPSBfYS5lcnJvcjtcbiAgICAgICAgICAgIGNvbnRleHQgPSBudWxsO1xuICAgICAgICAgICAgaWYgKGVycm9yVGhyb3duKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgZXJyb3I7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG4gICAgZWxzZSB7XG4gICAgICAgIGNiKCk7XG4gICAgfVxufVxuZXhwb3J0IGZ1bmN0aW9uIGNhcHR1cmVFcnJvcihlcnIpIHtcbiAgICBpZiAoY29uZmlnLnVzZURlcHJlY2F0ZWRTeW5jaHJvbm91c0Vycm9ySGFuZGxpbmcgJiYgY29udGV4dCkge1xuICAgICAgICBjb250ZXh0LmVycm9yVGhyb3duID0gdHJ1ZTtcbiAgICAgICAgY29udGV4dC5lcnJvciA9IGVycjtcbiAgICB9XG59XG4vLyMgc291cmNlTWFwcGluZ1VSTD1lcnJvckNvbnRleHQuanMubWFwIiwiZXhwb3J0IGZ1bmN0aW9uIGlkZW50aXR5KHgpIHtcbiAgICByZXR1cm4geDtcbn1cbi8vIyBzb3VyY2VNYXBwaW5nVVJMPWlkZW50aXR5LmpzLm1hcCIsImV4cG9ydCB2YXIgaXNBcnJheUxpa2UgPS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4gICAgICAgICAgICAgICAgY2FzZSAzOlxuICAgICAgICAgICAgICAgICAgICBfYSA9IF9iLnNlbnQoKSwgdmFsdWUgPSBfYS52YWx1ZSwgZG9uZSA9IF9hLmRvbmU7XG4gICAgICAgICAgICAgICAgICAgIGlmICghZG9uZSkgcmV0dXJuIFszLCA1XTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFs0LCBfX2F3YWl0KHZvaWQgMCldO1xuICAgICAgICAgICAgICAgIGNhc2UgNDogcmV0dXJuIFsyLCBfYi5zZW50KCldO1xuICAgICAgICAgICAgICAgIGNhc2UgNTogcmV0dXJuIFs0LCBfX2F3YWl0KHZhbHVlKV07XG4gICAgICAgICAgICAgICAgY2FzZSA2OiByZXR1cm4gWzQsIF9iLnNlbnQoKV07XG4gICAgICAgICAgICAgICAgY2FzZSA3OlxuICAgICAgICAgICAgICAgICAgICBfYi5zZW50KCk7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBbMywgMl07XG4gICAgICAgICAgICAgICAgY2FzZSA4OiByZXR1cm4gWzMsIDEwXTtcbiAgICAgICAgICAgICAgICBjYXNlIDk6XG4gICAgICAgICAgICAgICAgICAgIHJlYWRlci5yZWxlYXNlTG9jaygpO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gWzddO1xuICAgICAgICAgICAgICAgIGNhc2UgMTA6IHJldHVybiBbMl07XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgIH0pO1xufVxuZXhwb3J0IGZ1bmN0aW9uIGlzUmVhZGFibGVTdHJlYW1MaWtlKG9iaikge1xuICAgIHJldHVybiBpc0Z1bmN0aW9uKG9iaiA9PT0gbnVsbCB8fCBvYmogPT09IHZvaWQgMCA/IHZvaWQgMCA6IG9iai5nZXRSZWFkZXIpO1xufVxuLy8jIHNvdXJjZU1hcHBpbmdVUkw9aXNSZWFkYWJsZVN0cmVhbUxpa2UuanMubWFwIiwiaW1wb3J0IHsgaXNGdW5jdGlvbiB9IGZyb20gJy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AgICByZXMgKz0gYCR7am9pbn1cIi4uLiAke2dldEl0ZW1Db3VudChyZW1vdmVkS2V5cyl9IG5vdCBzdHJpbmdpZmllZFwiYFxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoc3BhY2VyICE9PSAnJykge1xuICAgICAgICAgICAgcmVzICs9IGBcXG4ke29yaWdpbmFsSW5kZW50YXRpb259YFxuICAgICAgICAgIH1cbiAgICAgICAgICBzdGFjay5wb3AoKVxuICAgICAgICAgIHJldHVybiBgWyR7cmVzfV1gXG4gICAgICAgIH1cblxuICAgICAgICBsZXQga2V5cyA9IE9iamVjdC5rZXlzKHZhbHVlKVxuICAgICAgICBjb25zdCBrZXlMZW5ndGggPSBrZXlzLmxlbmd0aFxuICAgICAgICBpZiAoa2V5TGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgcmV0dXJuICd7fSdcbiAgICAgICAgfVxuICAgICAgICBpZiAobWF4aW11bURlcHRoIDwgc3RhY2subGVuZ3RoICsgMSkge1xuICAgICAgICAgIHJldHVybiAnXCJbT2JqZWN0XVwiJ1xuICAgICAgICB9XG4gICAgICAgIGxldCB3aGl0ZXNwYWNlID0gJydcbiAgICAgICAgbGV0IHNlcGFyYXRvciA9ICcnXG4gICAgICAgIGlmIChzcGFjZXIgIT09ICcnKSB7XG4gICAgICAgICAgaW5kZW50YXRpb24gKz0gc3BhY2VyXG4gICAgICAgICAgam9pbiA9IGAsXFxuJHtpbmRlbnRhdGlvbn1gXG4gICAgICAgICAgd2hpdGVzcGFjZSA9ICcgJ1xuICAgICAgICB9XG4gICAgICAgIGNvbnN0IG1heGltdW1Qcm9wZXJ0aWVzVG9TdHJpbmdpZnkgPSBNYXRoLm1pbihrZXlMZW5ndGgsIG1heGltdW1CcmVhZHRoKVxuICAgICAgICBpZiAoZGV0ZXJtaW5pc3RpYyAmJiAhaXNUeXBlZEFycmF5V2l0aEVudHJpZXModmFsdWUpKSB7XG4gICAgICAgICAga2V5cyA9IGluc2VydFNvcnQoa2V5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C0xKSB7XG4gICAgICAgICAgcmV0dXJuIGNpcmN1bGFyVmFsdWVcbiAgICAgICAgfVxuXG4gICAgICAgIGNvbnN0IG9yaWdpbmFsSW5kZW50YXRpb24gPSBpbmRlbnRhdGlvblxuICAgICAgICBsZXQgcmVzID0gJydcbiAgICAgICAgbGV0IGpvaW4gPSAnLCdcblxuICAgICAgICBpZiAoQXJyYXkuaXNBcnJheSh2YWx1ZSkpIHtcbiAgICAgICAgICBpZiAodmFsdWUubGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgICByZXR1cm4gJ1tdJ1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAobWF4aW11bURlcHRoIDwgc3RhY2subGVuZ3RoICsgMSkge1xuICAgICAgICAgICAgcmV0dXJuICdcIltBcnJheV1cIidcbiAgICAgICAgICB9XG4gICAgICAgICAgc3RhY2sucHVzaCh2YWx1ZSlcbiAgICAgICAgICBpZiAoc3BhY2VyICE9PSAnJykge1xuICAgICAgICAgICAgaW5kZW50YXRpb24gKz0gc3BhY2VyXG4gICAgICAgICAgICByZXMgKz0gYFxcbiR7aW5kZW50YXRpb259YFxuICAgICAgICAgICAgam9pbiA9IGAsXFxuJHtpbmRlbnRhdGlvbn1gXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnN0IG1heGltdW1WYWx1ZXNUb1N0cmluZ2lmeSA9IE1hdGgubWluKHZhbHVlLmxlbmd0aCwgbWF4aW11bUJyZWFkdGgpXG4gICAgICAgICAgbGV0IGkgPSAwXG4gICAgICAgICAgZm9yICg7IGkgPCBtYXhpbXVtVmFsdWVzVG9TdHJpbmdpZnkgLSAxOyBpKyspIHtcbiAgICAgICAgICAgIGNvbnN0IHRtcCA9IHN0cmluZ2lmeUFycmF5UmVwbGFjZXIoU3RyaW5nKGkpLCB2YWx1ZVtpXSwgc3RhY2ssIHJlcGxhY2VyLCBzcGFjZXIsIGluZGVudGF0aW9uKVxuICAgICAgICAgICAgcmVzICs9IHRtcCAhPT0gdW5kZWZpbmVkID8gdG1wIDogJ251bGwnXG4gICAgICAgICAgICByZXMgKz0gam9pblxuICAgICAgICAgIH1cbiAgICAgICAgICBjb25zdCB0bXAgPSBzdHJpbmdpZnlBcnJheVJlcGxhY2VyKFN0cmluZyhpKSwgdmFsdWVbaV0sIHN0YWNrLCByZXBsYWNlciwgc3BhY2VyLCBpbmRlbnRhdGlvbilcbiAgICAgICAgICByZXMgKz0gdG1wICE9PSB1bmRlZmluZWQgPyB0bXAgOiAnbnVsbCdcbiAgICAgICAgICBpZiAodmFsdWUubGVuZ3RoIC0gMSA+IG1heGltdW1CcmVhZHRoKSB7XG4gICAgICAgICAgICBjb25zdCByZW1vdmVkS2V5cyA9IHZhbHVlLmxlbmd0aCAtIG1heGltdW1CcmVhZHRoIC0gMVxuICAgICAgICAgICAgcmVzICs9IGAke2pvaW59XCIuLi4gJHtnZXRJdGVtQ291bnQocmVtb3ZlZEtleXMpfSBub3Qgc3RyaW5naWZpZWRcImBcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKHNwYWNlciAhPT0gJycpIHtcbiAgICAgICAgICAgIHJlcyArPSBgXFxuJHtvcmlnaW5hbEluZGVudGF0aW9ufWBcbiAgICAgICAgICB9XG4gICAgICAgICAgc3RhY2sucG9wKClcbiAgICAgICAgICByZXR1cm4gYFske3Jlc31dYFxuICAgICAgICB9XG4gICAgICAgIHN0YWNrLnB1c2godmFsdWUpXG4gICAgICAgIGxldCB3aGl0ZXNwYWNlID0gJydcbiAgICAgICAgaWYgKHNwYWNlciAhPT0gJycpIHtcbiAgICAgICAgICBpbmRlbnRhdGlvbiArPSBzcGFjZXJcbiAgICAgICAgICBqb2luID0gYCxcXG4ke2luZGVudGF0aW9ufWBcbiAgICAgICAgICB3aGl0ZXNwYWNlID0gJyAnXG4gICAgICAgIH1cbiAgICAgICAgbGV0IHNlcGFyYXRvciA9ICcnXG4gICAgICAgIGZvciAoY29uc3Qga2V5IG9mIHJlcGxhY2VyKSB7XG4gICAgICAgICAg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ZpbmVkXG4gICAgfVxuICB9XG5cbiAgZnVuY3Rpb24gc3RyaW5naWZ5SW5kZW50IChrZXksIHZhbHVlLCBzdGFjaywgc3BhY2VyLCBpbmRlbnRhdGlvbikge1xuICAgIHN3aXRjaCAodHlwZW9mIHZhbHVlKSB7XG4gICAgICBjYXNlICdzdHJpbmcnOlxuICAgICAgICByZXR1cm4gc3RyRXNjYXBlKHZhbHVlKVxuICAgICAgY2FzZSAnb2JqZWN0Jzoge1xuICAgICAgICBpZiAodmFsdWUgPT09IG51bGwpIHtcbiAgICAgICAgICByZXR1cm4gJ251bGwnXG4gICAgICAgIH1cbiAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZS50b0pTT04gPT09ICdmdW5jdGlvbicpIHtcbiAgICAgICAgICB2YWx1ZSA9IHZhbHVlLnRvSlNPTihrZXkpXG4gICAgICAgICAgLy8gUHJldmVudCBjYWxsaW5nIGB0b0pTT05gIGFnYWluLlxuICAgICAgICAgIGlmICh0eXBlb2YgdmFsdWUgIT09ICdvYmplY3QnKSB7XG4gICAgICAgICAgICByZXR1cm4gc3RyaW5naWZ5SW5kZW50KGtleSwgdmFsdWUsIHN0YWNrLCBzcGFjZXIsIGluZGVudGF0aW9uKVxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAodmFsdWUgPT09IG51bGwpIHtcbiAgICAgICAgICAgIHJldHVybiAnbnVsbCdcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHN0YWNrLmluZGV4T2YodmFsdWUpICE9PSAtMSkge1xuICAgICAgICAgIHJldHVybiBjaXJjdWxhclZhbHVlXG4gICAgICAgIH1cbiAgICAgICAgY29uc3Qgb3JpZ2luYWxJbmRlbnRhdGlvbiA9IGluZGVudGF0aW9uXG5cbiAgICAgICAgaWYgKEFycmF5LmlzQXJyYXkodmFsdWUpKSB7XG4gICAgICAgICAgaWYgKHZhbHVlLmxlbmd0aCA9PT0gMCkge1xuICAgICAgICAgICAgcmV0dXJuICdbXSdcbiAgICAgICAgICB9XG4gICAgICAgICAgaWYgKG1heGltdW1EZXB0aCA8IHN0YWNrLmxlbmd0aCArIDEpIHtcbiAgICAgICAgICAgIHJldHVybiAnXCJbQXJyYXldXCInXG4gICAgICAgICAgfVxuICAgICAgICAgIHN0YWNrLnB1c2godmFsdWUpXG4gICAgICAgICAgaW5kZW50YXRpb24gKz0gc3BhY2VyXG4gICAgICAgICAgbGV0IHJlcyA9IGBcXG4ke2luZGVudGF0aW9ufWBcbiAgICAgICAgICBjb25zdCBqb2luID0gYCxcXG4ke2luZGVudGF0aW9ufWBcbiAgICAgICAgICBjb25zdCBtYXhpbXVtVmFsdWVzVG9TdHJpbmdpZnkgPSBNYXRoLm1pbih2YWx1ZS5sZW5ndGgsIG1heGltdW1CcmVhZHRoKVxuICAgICAgICAgIGxldCBpID0gMFxuICAgICAgICAgIGZvciAoOyBpIDwgbWF4aW11bVZhbHVlc1RvU3RyaW5naWZ5IC0gMTsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCB0bXAgPSBzdHJpbmdpZnlJbmRlbnQoU3RyaW5nKGkpLCB2YWx1ZVtpXSwgc3RhY2ssIHNwYWNlciwgaW5kZW50YXRpb24pXG4gICAgICAgICAgICByZXMgKz0gdG1wICE9PSB1bmRlZmluZWQgPyB0bXAgOiAnbnVsbCdcbiAgICAgICAgICAgIHJlcyArPSBqb2luXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnN0IHRtcCA9IHN0cmluZ2lmeUluZGVudChTdHJpbmcoaSksIHZhbHVlW2ldLCBzdGFjaywgc3BhY2VyLCBpbmRlbnRhdGlvbilcbiAgICAgICAgICByZXMgKz0gdG1wICE9PSB1bmRlZmluZWQgPyB0bXAgOiAnbnVsbCdcbiAgICAgICAgICBpZiAodmFsdWUubGVuZ3RoIC0gMSA+IG1heGltdW1CcmVhZHRoKSB7XG4gICAgICAgICAgICBjb25zdCByZW1vdmVkS2V5cyA9IHZhbHVlLmxlbmd0aCAtIG1heGltdW1CcmVhZHRoIC0gMVxuICAgICAgICAgICAgcmVzICs9IGAke2pvaW59XCIuLi4gJHtnZXRJdGVtQ291bnQocmVtb3ZlZEtleXMpfSBub3Qgc3RyaW5naWZpZWRcImBcbiAgICAgICAgICB9XG4gICAgICAgICAgcmVzICs9IGBcXG4ke29yaWdpbmFsSW5kZW50YXRpb259YFxuICAgICAgICAgIHN0YWNrLnBvcCgpXG4gICAgICAgICAgcmV0dXJuIGBbJHtyZXN9XWBcbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBrZXlzID0gT2JqZWN0LmtleXModmFsdWUpXG4gICAgICAgIGNvbnN0IGtleUxlbmd0aCA9IGtleXMubGVuZ3RoXG4gICAgICAgIGlmIChrZXlMZW5ndGggPT09IDApIHtcbiAgICAgICAgICByZXR1cm4gJ3t9J1xuICAgICAgICB9XG4gICAgICAgIGlmIChtYXhpbXVtRGVwdGggPCBzdGFjay5sZW5ndGggKyAxKSB7XG4gICAgICAgICAgcmV0dXJuICdcIltPYmplY3RdXCInXG4gICAgICAgIH1cbiAgICAgICAgaW5kZW50YXRpb24gKz0gc3BhY2VyXG4gICAgICAgIGNvbnN0IGpvaW4gPSBgLFxcbiR7aW5kZW50YXRpb259YFxuICAgICAgICBsZXQgcmVzID0gJydcbiAgICAgICAgbGV0IHNlcGFyYXRvciA9ICcnXG4gICAgICAgIGxldCBtYXhpbXVtUHJvcGVydGllc1RvU3RyaW5naWZ5ID0gTWF0aC5taW4oa2V5TGVuZ3RoLCBtYXhpbXVtQnJlYWR0aClcbiAgICAgICAgaWYgKGlzVHlwZWRBcnJheVdpdGhFbnRyaWVzKHZhbHVlKSkge1xuICAgICAgICAgIHJlcyArPSBzdHJpbmdpZnlUeXBlZEFycmF5KHZhbHVlLCBqb2luLCBtYXhpbXVtQnJlYWR0aClcbiAgICAgICAgICBrZXlzID0ga2V5cy5zbGljZSh2YWx1ZS5sZW5ndGgpXG4gICAgICAgICAgbWF4aW11bVByb3BlcnRpZXNUb1N0cmluZ2lmeSAtPSB2YWx1ZS5sZW5ndGhcbiAgICAgICAgICBzZXBhcmF0b3IgPSBqb2luXG4gICAgICAgIH1cbiAgICAgICAgaWYgKGRldGVybWluaXN0aWMpIHtcbiAgICAgICAgICBrZXlzID0gaW5zZXJ0U29ydChrZXlzKVxuICAgICAgICB9XG4gICAgICAgIHN0YWNrLnB1c2godmFsdWUpXG4gICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbWF4aW11bVByb3BlcnRpZXNUb1N0cmluZ2lmeTsgaSsrKSB7XG4gICAgICAgICAgY29uc3Qga2V5ID0ga2V5c1tpXVxuICAgICAgICAgIGNvbnN0IHRtcCA9IHN0cmluZ2lmeUluZGVudChrZXksIHZhbHVlW2tleV0sIHN0YWNrLCBzcGFjZXIsIGluZGVudGF0aW9uKVxuICAgICAgICAgIGlmICh0bXAgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgcmVzICs9IGAke3NlcGFyYXRvcn0ke3N0ckVzY2FwZShrZXkpfTogJHt0bXB9YFxuICAgICAgICAgICAgc2VwYXJhdG9yID0gam9pblxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAoa2V5TGVuZ3RoID4gbWF4aW11bUJyZWFkdGgpIHtcbiAgICAgICAgICBjb25zdCByZW1vdmVkS2V5cyA9IGtleUxlbmd0aCAtIG1heGltdW1CcmVhZHRoXG4gICAgICAgICAgcmVzICs9IGAke3NlcGFyYXRvcn1cIi4uLlwiOiBcIiR7Z2V0SXRlbUNvdW50KHJlbW92ZWRLZXlzKX0gbm90IHN0cmluZ2lmaWVkXCJgXG4gICAgICAgICAgc2VwYXJhdG9yID0gam9pblxuICAgICAgICB9XG4gICAgICAgIGlmIChzZXBhcmF0b3IgIT09ICcnKSB7XG4gICAgICAgICAgcmVzID0gYFxcbiR7aW5kZW50YXRpb259JHtyZXN9XFxuJHtvcmlnaW5hbEluZGVudGF0aW9ufWBcbiAgICAgICAgfVxuICAgICAgICBzdGFjay5wb3Ao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dmFsdWUgIT09ICdvYmplY3QnKSB7XG4gICAgICAgICAgICByZXR1cm4gc3RyaW5naWZ5U2ltcGxlKGtleSwgdmFsdWUsIHN0YWNrKVxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAodmFsdWUgPT09IG51bGwpIHtcbiAgICAgICAgICAgIHJldHVybiAnbnVsbCdcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHN0YWNrLmluZGV4T2YodmFsdWUpICE9PSAtMSkge1xuICAgICAgICAgIHJldHVybiBjaXJjdWxhclZhbHVlXG4gICAgICAgIH1cblxuICAgICAgICBsZXQgcmVzID0gJydcblxuICAgICAgICBpZiAoQXJyYXkuaXNBcnJheSh2YWx1ZSkpIHtcbiAgICAgICAgICBpZiAodmFsdWUubGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgICByZXR1cm4gJ1tdJ1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAobWF4aW11bURlcHRoIDwgc3RhY2subGVuZ3RoICsgMSkge1xuICAgICAgICAgICAgcmV0dXJuICdcIltBcnJheV1cIidcbiAgICAgICAgICB9XG4gICAgICAgICAgc3RhY2sucHVzaCh2YWx1ZSlcbiAgICAgICAgICBjb25zdCBtYXhpbXVtVmFsdWVzVG9TdHJpbmdpZnkgPSBNYXRoLm1pbih2YWx1ZS5sZW5ndGgsIG1heGltdW1CcmVhZHRoKVxuICAgICAgICAgIGxldCBpID0gMFxuICAgICAgICAgIGZvciAoOyBpIDwgbWF4aW11bVZhbHVlc1RvU3RyaW5naWZ5IC0gMTsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCB0bXAgPSBzdHJpbmdpZnlTaW1wbGUoU3RyaW5nKGkpLCB2YWx1ZVtpXSwgc3RhY2spXG4gICAgICAgICAgICByZXMgKz0gdG1wICE9PSB1bmRlZmluZWQgPyB0bXAgOiAnbnVsbCdcbiAgICAgICAgICAgIHJlcyArPSAnLCdcbiAgICAgICAgICB9XG4gICAgICAgICAgY29uc3QgdG1wID0gc3RyaW5naWZ5U2ltcGxlKFN0cmluZyhpKSwgdmFsdWVbaV0sIHN0YWNrKVxuICAgICAgICAgIHJlcyArPSB0bXAgIT09IHVuZGVmaW5lZCA/IHRtcCA6ICdudWxsJ1xuICAgICAgICAgIGlmICh2YWx1ZS5sZW5ndGggLSAxID4gbWF4aW11bUJyZWFkdGgpIHtcbiAgICAgICAgICAgIGNvbnN0IHJlbW92ZWRLZXlzID0gdmFsdWUubGVuZ3RoIC0gbWF4aW11bUJyZWFkdGggLSAxXG4gICAgICAgICAgICByZXMgKz0gYCxcIi4uLiAke2dldEl0ZW1Db3VudChyZW1vdmVkS2V5cyl9IG5vdCBzdHJpbmdpZmllZFwiYFxuICAgICAgICAgIH1cbiAgICAgICAgICBzdGFjay5wb3AoKVxuICAgICAgICAgIHJldHVybiBgWyR7cmVzfV1gXG4gICAgICAgIH1cblxuICAgICAgICBsZXQga2V5cyA9IE9iamVjdC5rZXlzKHZhbHVlKVxuICAgICAgICBjb25zdCBrZXlMZW5ndGggPSBrZXlzLmxlbmd0aFxuICAgICAgICBpZiAoa2V5TGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgcmV0dXJuICd7fSdcbiAgICAgICAgfVxuICAgICAgICBpZiAobWF4aW11bURlcHRoIDwgc3RhY2subGVuZ3RoICsgMSkge1xuICAgICAgICAgIHJldHVybiAnXCJbT2JqZWN0XVwiJ1xuICAgICAgICB9XG4gICAgICAgIGxldCBzZXBhcmF0b3IgPSAnJ1xuICAgICAgICBsZXQgbWF4aW11bVByb3BlcnRpZXNUb1N0cmluZ2lmeSA9IE1hdGgubWluKGtleUxlbmd0aCwgbWF4aW11bUJyZWFkdGgpXG4gICAgICAgIGlmIChpc1R5cGVkQXJyYXlXaXRoRW50cmllcyh2YWx1ZSkpIHtcbiAgICAgICAgICByZXMgKz0gc3RyaW5naWZ5VHlwZWRBcnJheSh2YWx1ZSwgJywnLCBtYXhpbXVtQnJlYWR0aClcbiAgICAgICAgICBr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5bSc6IDg1MDEsXG4gICAgJ2xhcnInOiA4NTkyLFxuICAgICd1YXJyJzogODU5MyxcbiAgICAncmFycic6IDg1OTQsXG4gICAgJ2RhcnInOiA4NTk1LFxuICAgICdoYXJyJzogODU5NixcbiAgICAnY3JhcnInOiA4NjI5LFxuICAgICdsQXJyJzogODY1NixcbiAgICAndUFycic6IDg2NTcsXG4gICAgJ3JBcnInOiA4NjU4LFxuICAgICdkQXJyJzogODY1OSxcbiAgICAnaEFycic6IDg2NjAsXG4gICAgJ2ZvcmFsbCc6IDg3MDQsXG4gICAgJ3BhcnQnOiA4NzA2LFxuICAgICdleGlzdCc6IDg3MDcsXG4gICAgJ2VtcHR5JzogODcwOSxcbiAgICAnbmFibGEnOiA4NzExLFxuICAgICdpc2luJzogODcxMixcbiAgICAnbm90aW4nOiA4NzEzLFxuICAgICduaSc6IDg3MTUsXG4gICAgJ3Byb2QnOiA4NzE5LFxuICAgICdzdW0nOiA4NzIxLFxuICAgICdtaW51cyc6IDg3MjIsXG4gICAgJ2xvd2FzdCc6IDg3MjcsXG4gICAgJ3JhZGljJzogODczMCxcbiAgICAncHJvcCc6IDg3MzMsXG4gICAgJ2luZmluJzogODczNCxcbiAgICAnYW5nJzogODczNixcbiAgICAnYW5kJzogODc0MyxcbiAgICAnb3InOiA4NzQ0LFxuICAgICdjYXAnOiA4NzQ1LFxuICAgICdjdXAnOiA4NzQ2LFxuICAgICdpbnQnOiA4NzQ3LFxuICAgICd0aGVyZTQnOiA4NzU2LFxuICAgICdzaW0nOiA4NzY0LFxuICAgICdjb25nJzogODc3MyxcbiAgICAnYXN5bXAnOiA4Nzc2LFxuICAgICduZSc6IDg4MDAsXG4gICAgJ2VxdWl2JzogODgwMSxcbiAgICAnbGUnOiA4ODA0LFxuICAgICdnZSc6IDg4MDUsXG4gICAgJ3N1Yic6IDg4MzQsXG4gICAgJ3N1cCc6IDg4MzUsXG4gICAgJ25zdWInOiA4ODM2LFxuICAgICdzdWJlJzogODgzOCxcbi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saW5lKytcbiAgICAgICAgICBwYXJzZXIuY29sdW1uID0gMFxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHBhcnNlci5jb2x1bW4rK1xuICAgICAgICB9XG4gICAgICB9XG5cbiAgICAgIHN3aXRjaCAocGFyc2VyLnN0YXRlKSB7XG4gICAgICAgIGNhc2UgUy5CRUdJTjpcbiAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkJFR0lOX1dISVRFU1BBQ0VcbiAgICAgICAgICBpZiAoYyA9PT0gJ1xcdUZFRkYnKSB7XG4gICAgICAgICAgICBjb250aW51ZVxuICAgICAgICAgIH1cbiAgICAgICAgICBiZWdpbldoaXRlU3BhY2UocGFyc2VyLCBjKVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkJFR0lOX1dISVRFU1BBQ0U6XG4gICAgICAgICAgYmVnaW5XaGl0ZVNwYWNlKHBhcnNlciwgYylcbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5URVhUOlxuICAgICAgICAgIGlmIChwYXJzZXIuc2F3Um9vdCAmJiAhcGFyc2VyLmNsb3NlZFJvb3QpIHtcbiAgICAgICAgICAgIHZhciBzdGFydGkgPSBpIC0gMVxuICAgICAgICAgICAgd2hpbGUgKGMgJiYgYyAhPT0gJzwnICYmIGMgIT09ICcmJykge1xuICAgICAgICAgICAgICBjID0gY2hhckF0KGNodW5rLCBpKyspXG4gICAgICAgICAgICAgIGlmIChjICYmIHBhcnNlci50cmFja1Bvc2l0aW9uKSB7XG4gICAgICAgICAgICAgICAgcGFyc2VyLnBvc2l0aW9uKytcbiAgICAgICAgICAgICAgICBpZiAoYyA9PT0gJ1xcbicpIHtcbiAgICAgICAgICAgICAgICAgIHBhcnNlci5saW5lKytcbiAgICAgICAgICAgICAgICAgIHBhcnNlci5jb2x1bW4gPSAwXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIHBhcnNlci5jb2x1bW4rK1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcGFyc2VyLnRleHROb2RlICs9IGNodW5rLnN1YnN0cmluZyhzdGFydGksIGkgLSAxKVxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoYyA9PT0gJzwnICYmICEocGFyc2VyLnNhd1Jvb3QgJiYgcGFyc2VyLmNsb3NlZFJvb3QgJiYgIXBhcnNlci5zdHJpY3QpKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLk9QRU5fV0FLQVxuICAgICAgICAgICAgcGFyc2VyLnN0YXJ0VGFnUG9zaXRpb24gPSBwYXJzZXIucG9zaXRpb25cbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKCFpc1doaXRlc3BhY2UoYykgJiYgKCFwYXJzZXIuc2F3Um9vdCB8fCBwYXJzZXIuY2xvc2VkUm9vdCkpIHtcbiAgICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdUZXh0IGRhdGEgb3V0c2lkZSBvZiByb290IG5vZGUuJylcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChjID09PSAnJicpIHtcbiAgICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUX0VOVElUWVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgcGFyc2VyLnRleHROb2RlICs9IGNcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuU0NSSVBUOlxuICAgICAgICAgIC8vIG9ubHkgbm9uLXN0cmljdFxuICAgICAgICAgIGlmIChjID09PSAnPCcpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0NSSVBUX0VORElOR1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuc2NyaXB0ICs9IGNcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuU0NSSVBUX0VORElORzpcbiAgICAgICAgICBpZiAoYyA9PT0gJy8nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNMT1NFX1RBR1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuc2NyaXB0ICs9ICc8JyArIGNcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0NSSVBUXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLk9QRU5fV0FLQTpcbiAgICAgICAgICAvLyBlaXRoZXIgYSAvLCA/LCAhLCBvciB0ZXh0IGlzIGNvbWluZyBuZXh0LlxuICAgICAgICAgIGlmIChjID09PSAnIScpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0dNTF9ERUNMXG4gICAgICAgICAgICBwYXJzZXIuc2dtbERlY2wgPSAnJ1xuICAgICAgICAgIH0gZWxzZSBpZiAoaXNXaGl0ZXNwYWNlKGMpKSB7XG4gICAgICAgICAgICAvLyB3YWl0IGZvciBpdC4uLlxuICAgICAgICAgIH0gZWxzZSBpZiAoaXNNYXRjaChuYW1lU3RhcnQsIGMpKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLk9QRU5fVEFHXG4gICAgICAgICAgICBwYXJzZXIudGFnTmFtZSA9IGNcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICcvJykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DTE9TRV9UQUdcbiAgICAgICAgICAgIHBhcnNlci50YWdOYW1lID0gJydcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICc/Jykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5QUk9DX0lOU1RcbiAgICAgICAgICAgIHBhcnNlci5wcm9jSW5zdE5hbWUgPSBwYXJzZXIucHJvY0luc3RCb2R5ID0gJydcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdVbmVuY29kZWQgPCcpXG4gICAgICAgICAgICAvLyBpZiB0aGVyZSB3YXMgc29tZSB3aGl0ZXNwYWNlLCB0aGVuIGFkZCB0aGF0IGluLlxuICAgICAgICAgICAgaWYgKHBhcnNlci5zdGFydFRhZ1Bvc2l0aW9uICsgMSA8IHBhcnNlci5wb3NpdGlvbikge1xuICAgICAgICAgICAgICB2YXIgcGFkID0gcGFyc2VyLnBvc2l0aW9uIC0gcGFyc2VyLnN0YXJ0VGFnUG9zaXRpb25cbiAgICAgICAgICAgICAgYyA9IG5ldyBBcnJheShwYWQpLmpvaW4oJyAnKSArIGNcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHBhcnNlci50ZXh0Tm9kZSArPSAnPCcgKyBjXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlRFWFRcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuU0dNTF9ERUNMOlxuICAgICAgICAgIGlmIChwYXJzZXIuc2dtbERlY2wgKyBjID09PSAnLS0nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNPTU1FTlRcbiAgICAgICAgICAgIHBhcnNlci5jb21tZW50ID0gJydcbiAgICAgICAgICAgIHBhcnNlci5zZ21sRGVjbCA9ICcnXG4gICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAocGFyc2VyLmRvY3R5cGUgJiYgcGFyc2VyLmRvY3R5cGUgIT09IHRydWUgJiYgcGFyc2VyLnNnbWxEZWNsKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVfRFREXG4gICAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSAnPCEnICsgcGFyc2VyLnNnbWxEZWNsICsgY1xuICAgICAgICAgICAgcGFyc2VyLnNnbWxEZWNsID0gJydcbiAgICAgICAgICB9IGVsc2UgaWYgKChwYXJzZXIuc2dtbERlY2wgKyBjKS50b1VwcGVyQ2FzZSgpID09PSBDREFUQSkge1xuICAgICAgICAgICAgZW1pdE5vZGUocGFyc2VyLCAnb25vcGVuY2RhdGEnKVxuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DREFUQVxuICAgICAgICAgICAgcGFyc2VyLnNnbWxEZWNsID0gJydcbiAgICAgICAgICAgIHBhcnNlci5jZGF0YSA9ICcnXG4gICAgICAgICAgfSBlbHNlIGlmICgocGFyc2VyLnNnbWxEZWNsICsgYykudG9VcHBlckNhc2UoKSA9PT0gRE9DVFlQRSkge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5ET0NUWVBFXG4gICAgICAgICAgICBpZiAocGFyc2VyLmRvY3R5cGUgfHwgcGFyc2VyLnNhd1Jvb3QpIHtcbiAgICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsXG4gICAgICAgICAgICAgICAgJ0luYXBwcm9wcmlhdGVseSBsb2NhdGVkIGRvY3R5cGUgZGVjbGFyYXRpb24nKVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcGFyc2VyLmRvY3R5cGUgPSAnJ1xuICAgICAgICAgICAgcGFyc2VyLnNnbWxEZWNsID0gJydcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICc+Jykge1xuICAgICAgICAgICAgZW1pdE5vZGUocGFyc2VyLCAnb25zZ21sZGVjbGFyYXRpb24nLCBwYXJzZXIuc2dtbERlY2wpXG4gICAgICAgICAgICBwYXJzZXIuc2dtbERlY2wgPSAnJ1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgfSBlbHNlIGlmIChpc1F1b3RlKGMpKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlNHTUxfREVDTF9RVU9URURcbiAgICAgICAgICAgIHBhcnNlci5zZ21sRGVjbCArPSBjXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5zZ21sRGVjbCArPSBjXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLlNHTUxfREVDTF9RVU9URUQ6XG4gICAgICAgICAgaWYgKGMgPT09IHBhcnNlci5xKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlNHTUxfREVDTFxuICAgICAgICAgICAgcGFyc2VyLnEgPSAnJ1xuICAgICAgICAgIH1cbiAgICAgICAgICBwYXJzZXIuc2dtbERlY2wgKz0gY1xuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkRPQ1RZUEU6XG4gICAgICAgICAgaWYgKGMgPT09ICc+Jykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgICBlbWl0Tm9kZShwYXJzZXIsICdvbmRvY3R5cGUnLCBwYXJzZXIuZG9jdHlwZSlcbiAgICAgICAgICAgIHBhcnNlci5kb2N0eXBlID0gdHJ1ZSAvLyBqdXN0IHJlbWVtYmVyIHRoYXQgd2Ugc2F3IGl0LlxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgICAgICBpZiAoYyA9PT0gJ1snKSB7XG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuRE9DVFlQRV9EVERcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoaXNRdW90ZShjKSkge1xuICAgICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVfUVVPVEVEXG4gICAgICAgICAgICAgIHBhcnNlci5xID0gY1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5ET0NUWVBFX1FVT1RFRDpcbiAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgICAgaWYgKGMgPT09IHBhcnNlci5xKSB7XG4gICAgICAgICAgICBwYXJzZXIucSA9ICcnXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuRE9DVFlQRV9EVEQ6XG4gICAgICAgICAgaWYgKGMgPT09ICddJykge1xuICAgICAgICAgICAgcGFyc2VyLmRvY3R5cGUgKz0gY1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5ET0NUWVBFXG4gICAgICAgICAgfSBlbHNlIGlmIChjID09PSAnPCcpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuT1BFTl9XQUtBXG4gICAgICAgICAgICBwYXJzZXIuc3RhcnRUYWdQb3NpdGlvbiA9IHBhcnNlci5wb3NpdGlvblxuICAgICAgICAgIH0gZWxzZSBpZiAoaXNRdW90ZShjKSkge1xuICAgICAgICAgICAgcGFyc2VyLmRvY3R5cGUgKz0gY1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5ET0NUWVBFX0RURF9RVU9URURcbiAgICAgICAgICAgIHBhcnNlci5xID0gY1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkRPQ1RZUEVfRFREX1FVT1RFRDpcbiAgICAgICAgICBwYXJzZXIuZG9jdHlwZSArPSBjXG4gICAgICAgICAgaWYgKGMgPT09IHBhcnNlci5xKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkRPQ1RZUEVfRFREXG4gICAgICAgICAgICBwYXJzZXIucSA9ICcnXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNPTU1FTlQ6XG4gICAgICAgICAgaWYgKGMgPT09ICctJykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DT01NRU5UX0VORElOR1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIuY29tbWVudCArPSBjXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNPTU1FTlRfRU5ESU5HOlxuICAgICAgICAgIGlmIChjID09PSAnLScpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ09NTUVOVF9FTkRFRFxuICAgICAgICAgICAgcGFyc2VyLmNvbW1lbnQgPSB0ZXh0b3B0cyhwYXJzZXIub3B0LCBwYXJzZXIuY29tbWVudClcbiAgICAgICAgICAgIGlmIChwYXJzZXIuY29tbWVudCkge1xuICAgICAgICAgICAgICBlbWl0Tm9kZShwYXJzZXIsICdvbmNvbW1lbnQnLCBwYXJzZXIuY29tbWVudClcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHBhcnNlci5jb21tZW50ID0gJydcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcGFyc2VyLmNvbW1lbnQgKz0gJy0nICsgY1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5DT01NRU5UXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNPTU1FTlRfRU5ERUQ6XG4gICAgICAgICAgaWYgKGMgIT09ICc+Jykge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdNYWxmb3JtZWQgY29tbWVudCcpXG4gICAgICAgICAgICAvLyBhbGxvdyA8IS0tIGJsYWggLS0gYmxvbyAtLT4gaW4gbm9uLXN0cmljdCBtb2RlLFxuICAgICAgICAgICAgLy8gd2hpY2ggaXMgYSBjb21tZW50IG9mIFwiIGJsYWggLS0gYmxvbyBcIlxuICAgICAgICAgICAgcGFyc2VyLmNvbW1lbnQgKz0gJy0tJyArIGNcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ09NTUVOVFxuICAgICAgICAgIH0gZWxzZSBpZiAocGFyc2VyLmRvY3R5cGUgJiYgcGFyc2VyLmRvY3R5cGUgIT09IHRydWUpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuRE9DVFlQRV9EVERcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNEQVRBOlxuICAgICAgICAgIGlmIChjID09PSAnXScpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ0RBVEFfRU5ESU5HXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5jZGF0YSArPSBjXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNEQVRBX0VORElORzpcbiAgICAgICAgICBpZiAoYyA9PT0gJ10nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNEQVRBX0VORElOR18yXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5jZGF0YSArPSAnXScgKyBjXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNEQVRBXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkNEQVRBX0VORElOR18yOlxuICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIGlmIChwYXJzZXIuY2RhdGEpIHtcbiAgICAgICAgICAgICAgZW1pdE5vZGUocGFyc2VyLCAnb25jZGF0YScsIHBhcnNlci5jZGF0YSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVtaXROb2RlKHBhcnNlciwgJ29uY2xvc2VjZGF0YScpXG4gICAgICAgICAgICBwYXJzZXIuY2RhdGEgPSAnJ1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgfSBlbHNlIGlmIChjID09PSAnXScpIHtcbiAgICAgICAgICAgIHBhcnNlci5jZGF0YSArPSAnXSdcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcGFyc2VyLmNkYXRhICs9ICddXScgKyBjXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkNEQVRBXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLlBST0NfSU5TVDpcbiAgICAgICAgICBpZiAoYyA9PT0gJz8nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlBST0NfSU5TVF9FTkRJTkdcbiAgICAgICAgICB9IGVsc2UgaWYgKGlzV2hpdGVzcGFjZShjKSkge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5QUk9DX0lOU1RfQk9EWVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwYXJzZXIucHJvY0luc3ROYW1lICs9IGNcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuUFJPQ19JTlNUX0JPRFk6XG4gICAgICAgICAgaWYgKCFwYXJzZXIucHJvY0luc3RCb2R5ICYmIGlzV2hpdGVzcGFjZShjKSkge1xuICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICc/Jykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5QUk9DX0lOU1RfRU5ESU5HXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5wcm9jSW5zdEJvZHkgKz0gY1xuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5QUk9DX0lOU1RfRU5ESU5HOlxuICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIGVtaXROb2RlKHBhcnNlciwgJ29ucHJvY2Vzc2luZ2luc3RydWN0aW9uJywge1xuICAgICAgICAgICAgICBuYW1lOiBwYXJzZXIucHJvY0luc3ROYW1lLFxuICAgICAgICAgICAgICBib2R5OiBwYXJzZXIucHJvY0luc3RCb2R5XG4gICAgICAgICAgICB9KVxuICAgICAgICAgICAgcGFyc2VyLnByb2NJbnN0TmFtZSA9IHBhcnNlci5wcm9jSW5zdEJvZHkgPSAnJ1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5URVhUXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHBhcnNlci5wcm9jSW5zdEJvZHkgKz0gJz8nICsgY1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5QUk9DX0lOU1RfQk9EWVxuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5PUEVOX1RBRzpcbiAgICAgICAgICBpZiAoaXNNYXRjaChuYW1lQm9keSwgYykpIHtcbiAgICAgICAgICAgIHBhcnNlci50YWdOYW1lICs9IGNcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbmV3VGFnKHBhcnNlcilcbiAgICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgICAgb3BlblRhZyhwYXJzZXIpXG4gICAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICcvJykge1xuICAgICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLk9QRU5fVEFHX1NMQVNIXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBpZiAoIWlzV2hpdGVzcGFjZShjKSkge1xuICAgICAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCBjaGFyYWN0ZXIgaW4gdGFnIG5hbWUnKVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLk9QRU5fVEFHX1NMQVNIOlxuICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIG9wZW5UYWcocGFyc2VyLCB0cnVlKVxuICAgICAgICAgICAgY2xvc2VUYWcocGFyc2VyKVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzdHJpY3RGYWlsKHBhcnNlciwgJ0ZvcndhcmQtc2xhc2ggaW4gb3BlbmluZyB0YWcgbm90IGZvbGxvd2VkIGJ5ID4nKVxuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuQVRUUklCOlxuICAgICAgICAgIC8vIGhhdmVuJ3QgcmVhZCB0aGUgYXR0cmlidXRlIG5hbWUgeWV0LlxuICAgICAgICAgIGlmIChpc1doaXRlc3BhY2UoYykpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfSBlbHNlIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIG9wZW5UYWcocGFyc2VyKVxuICAgICAgICAgIH0gZWxzZSBpZiAoYyA9PT0gJy8nKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLk9QRU5fVEFHX1NMQVNIXG4gICAgICAgICAgfSBlbHNlIGlmIChpc01hdGNoKG5hbWVTdGFydCwgYykpIHtcbiAgICAgICAgICAgIHBhcnNlci5hdHRyaWJOYW1lID0gY1xuICAgICAgICAgICAgcGFyc2VyLmF0dHJpYlZhbHVlID0gJydcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX05BTUVcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdJbnZhbGlkIGF0dHJpYnV0ZSBuYW1lJylcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuQVRUUklCX05BTUU6XG4gICAgICAgICAgaWYgKGMgPT09ICc9Jykge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJfVkFMVUVcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICc+Jykge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdBdHRyaWJ1dGUgd2l0aG91dCB2YWx1ZScpXG4gICAgICAgICAgICBwYXJzZXIuYXR0cmliVmFsdWUgPSBwYXJzZXIuYXR0cmliTmFtZVxuICAgICAgICAgICAgYXR0cmliKHBhcnNlcilcbiAgICAgICAgICAgIG9wZW5UYWcocGFyc2VyKVxuICAgICAgICAgIH0gZWxzZSBpZiAoaXNXaGl0ZXNwYWNlKGMpKSB7XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9OQU1FX1NBV19XSElURVxuICAgICAgICAgIH0gZWxzZSBpZiAoaXNNYXRjaChuYW1lQm9keSwgYykpIHtcbiAgICAgICAgICAgIHBhcnNlci5hdHRyaWJOYW1lICs9IGNcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdJbnZhbGlkIGF0dHJpYnV0ZSBuYW1lJylcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuQVRUUklCX05BTUVfU0FXX1dISVRFOlxuICAgICAgICAgIGlmIChjID09PSAnPScpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX1ZBTFVFXG4gICAgICAgICAgfSBlbHNlIGlmIChpc1doaXRlc3BhY2UoYykpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnQXR0cmlidXRlIHdpdGhvdXQgdmFsdWUnKVxuICAgICAgICAgICAgcGFyc2VyLnRhZy5hdHRyaWJ1dGVzW3BhcnNlci5hdHRyaWJOYW1lXSA9ICcnXG4gICAgICAgICAgICBwYXJzZXIuYXR0cmliVmFsdWUgPSAnJ1xuICAgICAgICAgICAgZW1pdE5vZGUocGFyc2VyLCAnb25hdHRyaWJ1dGUnLCB7XG4gICAgICAgICAgICAgIG5hbWU6IHBhcnNlci5hdHRyaWJOYW1lLFxuICAgICAgICAgICAgICB2YWx1ZTogJydcbiAgICAgICAgICAgIH0pXG4gICAgICAgICAgICBwYXJzZXIuYXR0cmliTmFtZSA9ICcnXG4gICAgICAgICAgICBpZiAoYyA9PT0gJz4nKSB7XG4gICAgICAgICAgICAgIG9wZW5UYWcocGFyc2VyKVxuICAgICAgICAgICAgfSBlbHNlIGlmIChpc01hdGNoKG5hbWVTdGFydCwgYykpIHtcbiAgICAgICAgICAgICAgcGFyc2VyLmF0dHJpYk5hbWUgPSBjXG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX05BTUVcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCBhdHRyaWJ1dGUgbmFtZScpXG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRTpcbiAgICAgICAgICBpZiAoaXNXaGl0ZXNwYWNlKGMpKSB7XG4gICAgICAgICAgICBjb250aW51ZVxuICAgICAgICAgIH0gZWxzZSBpZiAoaXNRdW90ZShjKSkge1xuICAgICAgICAgICAgcGFyc2VyLnEgPSBjXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9WQUxVRV9RVU9URURcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgaWYgKCFwYXJzZXIub3B0LnVucXVvdGVkQXR0cmlidXRlVmFsdWVzKSB7XG4gICAgICAgICAgICAgIGVycm9yKHBhcnNlciwgJ1VucXVvdGVkIGF0dHJpYnV0ZSB2YWx1ZScpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9WQUxVRV9VTlFVT1RFRFxuICAgICAgICAgICAgcGFyc2VyLmF0dHJpYlZhbHVlID0gY1xuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5BVFRSSUJfVkFMVUVfUVVPVEVEOlxuICAgICAgICAgIGlmIChjICE9PSBwYXJzZXIucSkge1xuICAgICAgICAgICAgaWYgKGMgPT09ICcmJykge1xuICAgICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9WQUxVRV9FTlRJVFlfUVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgcGFyc2VyLmF0dHJpYlZhbHVlICs9IGNcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfVxuICAgICAgICAgIGF0dHJpYihwYXJzZXIpXG4gICAgICAgICAgcGFyc2VyLnEgPSAnJ1xuICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX0NMT1NFRFxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9DTE9TRUQ6XG4gICAgICAgICAgaWYgKGlzV2hpdGVzcGFjZShjKSkge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJcbiAgICAgICAgICB9IGVsc2UgaWYgKGMgPT09ICc+Jykge1xuICAgICAgICAgICAgb3BlblRhZyhwYXJzZXIpXG4gICAgICAgICAgfSBlbHNlIGlmIChjID09PSAnLycpIHtcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuT1BFTl9UQUdfU0xBU0hcbiAgICAgICAgICB9IGVsc2UgaWYgKGlzTWF0Y2gobmFtZVN0YXJ0LCBjKSkge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdObyB3aGl0ZXNwYWNlIGJldHdlZW4gYXR0cmlidXRlcycpXG4gICAgICAgICAgICBwYXJzZXIuYXR0cmliTmFtZSA9IGNcbiAgICAgICAgICAgIHBhcnNlci5hdHRyaWJWYWx1ZSA9ICcnXG4gICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLkFUVFJJQl9OQU1FXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCBhdHRyaWJ1dGUgbmFtZScpXG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnRpbnVlXG5cbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9VTlFVT1RFRDpcbiAgICAgICAgICBpZiAoIWlzQXR0cmliRW5kKGMpKSB7XG4gICAgICAgICAgICBpZiAoYyA9PT0gJyYnKSB7XG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX0VOVElUWV9VXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBwYXJzZXIuYXR0cmliVmFsdWUgKz0gY1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgICB9XG4gICAgICAgICAgYXR0cmliKHBhcnNlcilcbiAgICAgICAgICBpZiAoYyA9PT0gJz4nKSB7XG4gICAgICAgICAgICBvcGVuVGFnKHBhcnNlcilcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcGFyc2VyLnN0YXRlID0gUy5BVFRSSUJcbiAgICAgICAgICB9XG4gICAgICAgICAgY29udGludWVcblxuICAgICAgICBjYXNlIFMuQ0xPU0VfVEFHOlxuICAgICAgICAgIGlmICghcGFyc2VyLnRhZ05hbWUpIHtcbiAgICAgICAgICAgIGlmIChpc1doaXRlc3BhY2UoYykpIHtcbiAgICAgICAgICAgICAgY29udGludWVcbiAgICAgICAgICAgIH0gZWxzZSBpZiAobm90TWF0Y2gobmFtZVN0YXJ0LCBjKSkge1xuICAgICAgICAgICAgICBpZiAocGFyc2VyLnNjcmlwdCkge1xuICAgICAgICAgICAgICAgIHBhcnNlci5zY3JpcHQgKz0gJzwvJyArIGNcbiAgICAgICAgICAgICAgICBwYXJzZXIuc3RhdGUgPSBTLlNDUklQVFxuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCB0YWduYW1lIGluIGNsb3NpbmcgdGFnLicpXG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHBhcnNlci50YWdOYW1lID0gY1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAoYyA9PT0gJz4nKSB7XG4gICAgICAgICAgICBjbG9zZVRhZyhwYXJzZXIpXG4gICAgICAgICAgfSBlbHNlIGlmIChpc01hdGNoKG5hbWVCb2R5LCBjKSkge1xuICAgICAgICAgICAgcGFyc2VyLnRhZ05hbWUgKz0gY1xuICAgICAgICAgIH0gZWxzZSBpZiAocGFyc2VyLnNjcmlwdCkge1xuICAgICAgICAgICAgcGFyc2VyLnNjcmlwdCArPSAnPC8nICsgcGFyc2VyLnRhZ05hbWVcbiAgICAgICAgICAgIHBhcnNlci50YWdOYW1lID0gJydcbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuU0NSSVBUXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGlmICghaXNXaGl0ZXNwYWNlKGMpKSB7XG4gICAgICAgICAgICAgIHN0cmljdEZhaWwocGFyc2VyLCAnSW52YWxpZCB0YWduYW1lIGluIGNsb3NpbmcgdGFnJylcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IFMuQ0xPU0VfVEFHX1NBV19XSElURVxuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5DTE9TRV9UQUdfU0FXX1dISVRFOlxuICAgICAgICAgIGlmIChpc1doaXRlc3BhY2UoYykpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChjID09PSAnPicpIHtcbiAgICAgICAgICAgIGNsb3NlVGFnKHBhcnNlcilcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc3RyaWN0RmFpbChwYXJzZXIsICdJbnZhbGlkIGNoYXJhY3RlcnMgaW4gY2xvc2luZyB0YWcnKVxuICAgICAgICAgIH1cbiAgICAgICAgICBjb250aW51ZVxuXG4gICAgICAgIGNhc2UgUy5URVhUX0VOVElUWTpcbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9FTlRJVFlfUTpcbiAgICAgICAgY2FzZSBTLkFUVFJJQl9WQUxVRV9FTlRJVFlfVTpcbiAgICAgICAgICB2YXIgcmV0dXJuU3RhdGVcbiAgICAgICAgICB2YXIgYnVmZmVyXG4gICAgICAgICAgc3dpdGNoIChwYXJzZXIuc3RhdGUpIHtcbiAgICAgICAgICAgIGNhc2UgUy5URVhUX0VOVElUWTpcbiAgICAgICAgICAgICAgcmV0dXJuU3RhdGUgPSBTLlRFWFRcbiAgICAgICAgICAgICAgYnVmZmVyID0gJ3RleHROb2RlJ1xuICAgICAgICAgICAgICBicmVha1xuXG4gICAgICAgICAgICBjYXNlIFMuQVRUUklCX1ZBTFVFX0VOVElUWV9ROlxuICAgICAgICAgICAgICByZXR1cm5TdGF0ZSA9IFMuQVRUUklCX1ZBTFVFX1FVT1RFRFxuICAgICAgICAgICAgICBidWZmZXIgPSAnYXR0cmliVmFsdWUnXG4gICAgICAgICAgICAgIGJyZWFrXG5cbiAgICAgICAgICAgIGNhc2UgUy5BVFRSSUJfVkFMVUVfRU5USVRZX1U6XG4gICAgICAgICAgICAgIHJldHVyblN0YXRlID0gUy5BVFRSSUJfVkFMVUVfVU5RVU9URURcbiAgICAgICAgICAgICAgYnVmZmVyID0gJ2F0dHJpYlZhbHVlJ1xuICAgICAgICAgICAgICBicmVha1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChjID09PSAnOycpIHtcbiAgICAgICAgICAgIHZhciBwYXJzZWRFbnRpdHkgPSBwYXJzZUVudGl0eShwYXJzZXIpXG4gICAgICAgICAgICBpZiAocGFyc2VyLm9wdC51bnBhcnNlZEVudGl0aWVzICYmICFPYmplY3QudmFsdWVzKHNheC5YTUxfRU5USVRJRVMpLmluY2x1ZGVzKHBhcnNlZEVudGl0eSkpIHtcbiAgICAgICAgICAgICAgcGFyc2VyLmVudGl0eSA9ICcnXG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IHJldHVyblN0YXRlXG4gICAgICAgICAgICAgIHBhcnNlci53cml0ZShwYXJzZWRFbnRpdHkpXG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBwYXJzZXJbYnVmZmVyXSArPSBwYXJzZWRFbnRpdHlcbiAgICAgICAgICAgICAgcGFyc2VyLmVudGl0eSA9ICcnXG4gICAgICAgICAgICAgIHBhcnNlci5zdGF0ZSA9IHJldHVyblN0YXRlXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChpc01hdGNoKHBhcnNlci5lbnRpdHkubGVuZ3RoID8gZW50aXR5Qm9keSA6IGVudGl0eVN0YXJ0LCBjKSkge1xuICAgICAgICAgICAgcGFyc2VyLmVudGl0eSArPSBjXG4gIC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H1cblxuICAgIGZ1bmN0aW9uIHJ1bih0YXNrKSB7XG4gICAgICAgIHZhciBjYWxsYmFjayA9IHRhc2suY2FsbGJhY2s7XG4gICAgICAgIHZhciBhcmdzID0gdGFzay5hcmdzO1xuICAgICAgICBzd2l0Y2ggKGFyZ3MubGVuZ3RoKSB7XG4gICAgICAgIGNhc2UgMDpcbiAgICAgICAgICAgIGNhbGxiYWNrKCk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSAxOlxuICAgICAgICAgICAgY2FsbGJhY2soYXJnc1swXSk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSAyOlxuICAgICAgICAgICAgY2FsbGJhY2soYXJnc1swXSwgYXJnc1sxXSk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgY2FzZSAzOlxuICAgICAgICAgICAgY2FsbGJhY2soYXJnc1swXSwgYXJnc1sxXSwgYXJnc1syXSk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgZGVmYXVsdDpcbiAgICAgICAgICAgIGNhbGxiYWNrLmFwcGx5KHVuZGVmaW5lZCwgYXJncyk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIHJ1bklmUHJlc2VudChoYW5kbGUpIHtcbiAgICAgICAgLy8gRnJvbSB0aGUgc3BlYzogXCJXYWl0IHVudGlsIGFueSBpbnZvY2F0aW9ucyBvZiB0aGlzIGFsZ29yaXRobSBzdGFydGVkIGJlZm9yZSB0aGlzIG9uZSBoYXZlIGNvbXBsZXRlZC5cIlxuICAgICAgICAvLyBTbyBpZiB3ZSdyZSBjdXJyZW50bHkgcnVubmluZyBhIHRhc2ssIHdlJ2xsIG5lZWQgdG8gZGVsYXkgdGhpcyBpbnZvY2F0aW9uLlxuICAgICAgICBpZiAoY3VycmVudGx5UnVubmluZ0FUYXNrKSB7XG4gICAgICAgICAgICAvLyBEZWxheSBieSBkb2luZyBhIHNldFRpbWVvdXQuIHNldEltbWVkaWF0ZSB3YXMgdHJpZWQgaW5zdGVhZCwgYnV0IGluIEZpcmVmb3ggNyBpdCBnZW5lcmF0ZWQgYVxuICAgICAgICAgICAgLy8gXCJ0b28gbXVjaCByZWN1cnNpb25cIiBlcnJvci5cbiAgICAgICAgICAgIHNldFRpbWVvdXQocnVuSWZQcmVzZW50LCAwLCBoYW5kbGUpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdmFyIHRhc2sgPSB0YXNrc0J5SGFuZGxlW2hhbmRsZV07XG4gICAgICAgICAgICBpZiAodGFzaykge1xuICAgICAgICAgICAgICAgIGN1cnJlbnRseVJ1bm5pbmdBVGFzayA9IHRydWU7XG4gICAgICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICAgICAgcnVuKHRhc2spO1xuICAgICAgICAgICAgICAgIH0gZmluYWxseSB7XG4gICAgICAgICAgICAgICAgICAgIGNsZWFySW1tZWRpYXRlKGhhbmRsZSk7XG4gICAgICAgICAgICAgICAgICAgIGN1cnJlbnRseVJ1bm5pbmdBVGFzayA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIGluc3RhbGxOZXh0VGlja0ltcGxlbWVudGF0aW9uKCkge1xuICAgICAgICByZWdpc3RlckltbWVkaWF0ZSA9IGZ1bmN0aW9uKGhhbmRsZSkge1xuICAgICAgICAgICAgcHJvY2Vzcy5uZXh0VGljayhmdW5jdGlvbiAoKSB7IHJ1bklmUHJlc2VudChoYW5kbGUpOyB9KTtcbiAgICAgICAgfTtcbiAgICB9XG5cbiAgICBmdW5jdGlvbiBjYW5Vc2VQb3N0TWVzc2FnZSgpIHtcbiAgICAgICAgLy8gVGhlIHRlc3QgYWdhaW5zdCBgaW1wb3J0U2NyaXB0c2AgcHJldmVudHMgdGhpcyBpbXBsZW1lbnRhdGlvbiBmcm9tIGJlaW5nI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W1lID0gbnVsbDtcbiAgICAgIHZhciBtZXRob2ROYW1lID0gbnVsbDtcbiAgICAgIHZhciBpc05hdGl2ZSA9IChsaW5lTWF0Y2hbNV0gPT09ICduYXRpdmUnKTtcblxuICAgICAgaWYgKGxpbmVNYXRjaFsxXSkge1xuICAgICAgICBmdW5jdGlvbk5hbWUgPSBsaW5lTWF0Y2hbMV07XG4gICAgICAgIHZhciBtZXRob2RTdGFydCA9IGZ1bmN0aW9uTmFtZS5sYXN0SW5kZXhPZignLicpO1xuICAgICAgICBpZiAoZnVuY3Rpb25OYW1lW21ldGhvZFN0YXJ0LTFdID09ICcuJylcbiAgICAgICAgICBtZXRob2RTdGFydC0tO1xuICAgICAgICBpZiAobWV0aG9kU3RhcnQgPiAwKSB7XG4gICAgICAgICAgb2JqZWN0ID0gZnVuY3Rpb25OYW1lLnN1YnN0cigwLCBtZXRob2RTdGFydCk7XG4gICAgICAgICAgbWV0aG9kID0gZnVuY3Rpb25OYW1lLnN1YnN0cihtZXRob2RTdGFydCArIDEpO1xuICAgICAgICAgIHZhciBvYmplY3RFbmQgPSBvYmplY3QuaW5kZXhPZignLk1vZHVsZScpO1xuICAgICAgICAgIGlmIChvYmplY3RFbmQgPiAwKSB7XG4gICAgICAgICAgICBmdW5jdGlvbk5hbWUgPSBmdW5jdGlvbk5hbWUuc3Vic3RyKG9iamVjdEVuZCArIDEpO1xuICAgICAgICAgICAgb2JqZWN0ID0gb2JqZWN0LnN1YnN0cigwLCBvYmplY3RFbmQpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB0eXBlTmFtZSA9IG51bGw7XG4gICAgICB9XG5cbiAgICAgIGlmIChtZXRob2QpIHtcbiAgICAgICAgdHlwZU5hbWUgPSBvYmplY3Q7XG4gICAgICAgIG1ldGhvZE5hbWUgPSBtZXRob2Q7XG4gICAgICB9XG5cbiAgICAgIGlmIChtZXRob2QgPT09ICc8YW5vbnltb3VzPicpIHtcbiAgICAgICAgbWV0aG9kTmF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AgICAgICAgICAgIGlmIChyICYmICFyLmRvbmUgJiYgKG0gPSBpW1wicmV0dXJuXCJdKSkgbS5jYWxsKGkpO1xyXG4gICAgICAgIH1cclxuICAgICAgICBmaW5hbGx5IHsgaWYgKGUpIHRocm93IGUuZXJyb3I7IH1cclxuICAgIH1cclxuICAgIHJldHVybiBhcjtcclxufVxyXG5cclxuLyoqIEBkZXByZWNhdGVkICovXHJcbmV4cG9ydCBmdW5jdGlvbiBfX3NwcmVhZCgpIHtcclxuICAgIGZvciAodmFyIGFyID0gW10sIGkgPSAwOyBpIDwgYXJndW1lbnRzLmxlbmd0aDsgaSsrKVxyXG4gICAgICAgIGFyID0gYXIuY29uY2F0KF9fcmVhZChhcmd1bWVudHNbaV0pKTtcclxuICAgIHJldHVybiBhcjtcclxufVxyXG5cclxuLyoqIEBkZXByZWNhdGVkICovXHJcbmV4cG9ydCBmdW5jdGlvbiBfX3NwcmVhZEFycmF5cygpIHtcclxuICAgIGZvciAodmFyIHMgPSAwLCBpID0gMCwgaWwgPSBhcmd1bWVudHMubGVuZ3RoOyBpIDwgaWw7IGkrKykgcyArPSBhcmd1bWVudHNbaV0ubGVuZ3RoO1xyXG4gICAgZm9yICh2YXIgciA9IEFycmF5KHMpLCBrID0gMCwgaSA9IDA7IGkgPCBpbDsgaSsrKVxyXG4gICAgICAgIGZvciAodmFyIGEgPSBhcmd1bWVudHNbaV0sIGogPSAwLCBqbCA9IGEubGVuZ3RoOyBqIDwgamw7IGorKywgaysrKVxyXG4gICAgICAgICAgICByW2tdID0gYVtqXTtcclxuICAgIHJldHVybiByO1xyXG59XHJcblxyXG5leHBvcnQgZnVuY3Rpb24gX19zcHJlYWRBcnJheSh0bywgZnJvbSkge1xyXG4gICAgZm9yICh2YXIgaSA9IDAsIGlsID0gZnJvbS5sZW5ndGgsIGogPSB0by5sZW5ndGg7IGkgPCBpbDsgaSsrLCBqKyspXHJcbiAgICAgICAgdG9bal0gPSBmcm9tW2ldO1xyXG4gICAgcmV0d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uICAgIGlmICghaXB2Nkhvc3RuYW1lKSB7XG4gICAgICB2YXIgaG9zdHBhcnRzID0gdGhpcy5ob3N0bmFtZS5zcGxpdCgvXFwuLyk7XG4gICAgICBmb3IgKHZhciBpID0gMCwgbCA9IGhvc3RwYXJ0cy5sZW5ndGg7IGkgPCBsOyBpKyspIHtcbiAgICAgICAgdmFyIHBhcnQgPSBob3N0cGFydHNbaV07XG4gICAgICAgIGlmICghcGFydCkgeyBjb250aW51ZTsgfVxuICAgICAgICBpZiAoIXBhcnQubWF0Y2goaG9zdG5hbWVQYXJ0UGF0dGVybikpIHtcbiAgICAgICAgICB2YXIgbmV3cGFydCA9ICcnO1xuICAgICAgICAgIGZvciAodmFyIGogPSAwLCBrID0gcGFydC5sZW5ndGg7IGogPCBrOyBqKyspIHtcbiAgICAgICAgICAgIGlmIChwYXJ0LmNoYXJDb2RlQXQoaikgPiAxMjcpIHtcbiAgICAgICAgICAgICAgLypcbiAgICAgICAgICAgICAgICogd2UgcmVwbGFjZSBub24tQVNDSUkgY2hhciB3aXRoIGEgdGVtcG9yYXJ5IHBsYWNlaG9sZGVyXG4gICAgICAgICAgICAgICAqIHdlIG5lZWQgdGhpcyB0byBtYWtlIHN1cmUgc2l6ZSBvZiBob3N0bmFtZSBpcyBub3RcbiAgICAgICAgICAgICAgICogYnJva2VuIGJ5IHJlcGxhY2luZyBub24tQVNDSUkgYnkgbm90aGluZ1xuICAgICAgICAgICAgICAgKi9cbiAgICAgICAgICAgICAgbmV3cGFydCArPSAneCc7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBuZXdwYXJ0ICs9IHBhcnRbal07XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIC8vIHdlIHRlc3QgYWdhaW4gd2l0aCBBU0NJSSBjaGFyIG9ubHlcbiAgICAgICAgICBpZiAoIW5ld3BhcnQubWF0Y2goaG9zdG5hbWVQYXJ0UGF0dGVybikpIHtcbiAgICAgICAgICAgI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mVtaXQoJ2Vycm9yJywgZXJyb3IpO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpdGVyKGVycm9yKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgc3RyZWFtLmRlc3Ryb3koKTtcbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoIWJ5dGVzKSB7XG4gICAgICAgICAgaWYgKGJ1ZmYpIHtcbiAgICAgICAgICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBlcWVxZXFcbiAgICAgICAgICAgIGlmIChvcHRpb25zLnN0YXJ0ID09IG51bGwgfHwgcm93ID4gb3B0aW9ucy5zdGFydCkge1xuICAgICAgICAgICAgICBpZiAoIWl0ZXIpIHtcbiAgICAgICAgICAgICAgICBzdHJlYW0uZW1pdCgnbGluZScsIGJ1ZmYpO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGl0ZXIobnVsbCwgYnVmZik7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJvdysrO1xuICAgICAgICAgICAgYnVmZiA9ICcnO1xuICAgICAgICAgIH1cbiAgICAgICAgICByZXR1cm4gc2V0VGltZW91dChyZWFkLCAxMDAwKTtcbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBkYXRhID0gZGVjb2RlLndyaXRlKGJ1ZmZlci5zbGljZSgwLCBieXRlcykpO1xuICAgICAgICBpZiAoIWl0ZXIpIHtcbiAgICAgICAgICBzdHJlYW0uZW1pdCgnZGF0YScsIGRhdGEpO1xuICAgICAgICB9XG5cbiAgICAgICAgZGF0YSA9IChidWZmICsgZGF0YSkuc3BsaXQoL1xcbisvKTtcblxuICAgICAgICBjb25zdCBsID0gZGF0YS5sZW5ndGggLSAxO1xuICAgICAgICBsZXQgaSA9IDA7XG5cbiAgICAgICAgZm9yICg7IGkgPCBsOyBpKyspIHtcbiAgICAgICAgICAvLyBlc2xpbnQt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tcbiAgICAgICAgfVxuICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICBpZiAoIWF0dGVtcHQpIHtcbiAgICAgICAgICBzdHJlYW0uZW1pdCgnZXJyb3InLCBlKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cblxuICAgIGZ1bmN0aW9uIHB1c2gobG9nKSB7XG4gICAgICBpZiAoXG4gICAgICAgIG9wdGlvbnMucm93cyAmJlxuICAgICAgICByZXN1bHRzLmxlbmd0aCA+PSBvcHRpb25zLnJvd3MgJiZcbiAgICAgICAgb3B0aW9ucy5vcmRlciAhPT0gJ2Rlc2MnXG4gICAgICApIHtcbiAgICAgICAgaWYgKHN0cmVhbS5yZWFkYWJsZSkge1xuICAgICAgICAgIHN0cmVhbS5kZXN0cm95KCk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuO1xuICAgICAgfVxuXG4gICAgICBpZiAob3B0aW9ucy5maWVsZHMpIHtcbiAgICAgICAgbG9nID0gb3B0aW9ucy5maWVsZHMucmVkdWNlKChvYmosIGtleSkgPT4ge1xuICAgICAgICAgIG9ialtrZXldID0gbG9nW2tleV07XG4gICAgICAgICAgcmV0dXJuIG9iajtcbiAgICAgICAgfSwge30pO1xuICAgICAgfVxuXG4gICAgICBpZiAob3B0aW9ucy5vcmRlciA9PT0gJ2Rlc2MnKSB7XG4gICAgICAgIGlmIChyZXN1bHRzLmxlbmd0aCA+PSBvcHRpb25zLnJvd3MpIHtcbiAgICAgICAgICByZXN1bHRzLnNoaWZ0KCk7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHJlc3VsdHMucHVzaChsb2cpO1xuICAgIH1cblxuICAgIGZ1bmN0aW9uIGNoZWNrKGxvZykge1xuICAgICAgaWYgKCFsb2cpIHtcbiAgICAgICAgcmV0dXJuO1xuICAgICAgfVxuXG4gICAgICBpZiAodHlwZW9mIGxvZyAhPT0gJ29iamVjdCcpIHtcbiAgICAgICAgcmV0dXJuO1xuICAgICAgfVxuXG4g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igoeyB2YWx1ZSwgZG9uZTogaXRlckRvbmUgfSkgPT4ge1xuICAgICAgICAgICAgLy9jb25zb2xlLmxvZygnZ290IHZhbHVlJywgdmFsdWUpXG4gICAgICAgICAgICBpZiAoY2FuY2VsZWQgfHwgZG9uZSkgcmV0dXJuO1xuICAgICAgICAgICAgYXdhaXRpbmcgPSBmYWxzZTtcbiAgICAgICAgICAgIGlmIChpdGVyRG9uZSkge1xuICAgICAgICAgICAgICAgIGRvbmUgPSB0cnVlO1xuICAgICAgICAgICAgICAgIGlmIChydW5uaW5nIDw9IDApIHtcbiAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZygnZG9uZSBuZXh0Q2InKVxuICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayhudWxsKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcnVubmluZysrO1xuICAgICAgICAgICAgaXRlcmF0ZWUodmFsdWUsIGlkeCwgaXRlcmF0ZWVDYWxsYmFjayk7XG4gICAgICAgICAgICBpZHgrKztcbiAgICAgICAgICAgIHJlcGxlbmlzaCgpO1xuICAgICAgICB9KS5jYXRjaChoYW5kbGVFcnJvcik7XG4gICAgfVxuXG4gICAgZnVuY3Rpb24gaXRlcmF0ZWVDYWxsYmFjayhlcnIsIHJlc3VsdCkge1xuICAgICAgICAvL2NvbnNvbGUubG9nKCdpdGVyYXRlZUNhbGxiYWNrJylcbiAgICAgICAgcnVubmluZyAtPSAxO1xuICAgICAgICBpZiAoY2FuY2VsZWQpIHJldHVybjtcbiAgICAgICAgaWYgKGVycikgcmV0dXJuIGhhbmRsZUVycm9yKGVycik7XG5cbiAgICAgICAgaWYgKGVyciA9PT0gZmFsc2UpIHtcbiAgICAgICAgICAgIGRvbmUgPSB0cnVlO1xuICAgICAgICAgICAgY2FuY2VsZWQgPSB0cnVlO1xuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9X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pO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChlcnIgPT09IGZhbHNlKSB7XG4gICAgICAgICAgICAgICAgZG9uZSA9IHRydWU7XG4gICAgICAgICAgICAgICAgY2FuY2VsZWQgPSB0cnVlO1xuICAgICAgICAgICAgfSBlbHNlIGlmICh2YWx1ZSA9PT0gX2JyZWFrTG9vcDIuZGVmYXVsdCB8fCBkb25lICYmIHJ1bm5pbmcgPD0gMCkge1xuICAgICAgICAgICAgICAgIGRvbmUgPSB0cnVlO1xuICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhudWxsKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIWxvb3BpbmcpIHtcbiAgICAgICAgICAgICAgICByZXBsZW5pc2goKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGZ1bmN0aW9uIHJlcGxlbmlzaCgpIHtcbiAgICAgICAgICAgIGxvb3BpbmcgPSB0cnVlO1xuICAgICAgICAgICAgd2hpbGUgKHJ1bm5pbmcgPCBsaW1pdCAmJiAhZG9uZSkge1xuICAgICAgICAgICAgICAgIHZhciBlbGVtID0gbmV4dEVsZW0oKTtcbiAgICAgICAgICAgICAgICBpZiAoZWxlbSA9PT0gbnVsbCkge1xuICAgICAgICAgICAgICAgICAgICBkb25lID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHJ1bm5pbmcgPD0gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2sobnVsbCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBydW5uaW5nICs9IDE7XG4gICAgICAgICAgICAgICAgaXRlcmF0ZWUoZWxlbS52YWx1ZSwgZWxlbS5rZXksICgwLCBfb25seU9uY2UyLmRlZmF1bHQpKGl0ZXJhdGVlQ2FsbGJhY2spKTtcbiAgICAgICAgICAgIH1c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lvbigpIHtcbiAqICAgICAgICAgICAgIGNhbGxiYWNrKG51bGwsICdvbmUnKTtcbiAqICAgICAgICAgfSwgMjAwKTtcbiAqICAgICB9LFxuICogICAgIGZ1bmN0aW9uKGNhbGxiYWNrKSB7XG4gKiAgICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24oKSB7XG4gKiAgICAgICAgICAgICBjYWxsYmFjayhudWxsLCAndHdvJyk7XG4gKiAgICAgICAgIH0sIDEwMCk7XG4gKiAgICAgfVxuICogXSkudGhlbihyZXN1bHRzID0+IHtcbiAqICAgICBjb25zb2xlLmxvZyhyZXN1bHRzKTtcbiAqICAgICAvLyByZXN1bHRzIGlzIGVxdWFsIHRvIFsnb25lJywndHdvJ11cbiAqIH0pLmNhdGNoKGVyciA9PiB7XG4gKiAgICAgY29uc29sZS5sb2coZXJyKTtcbiAqIH0pO1xuICpcbiAqIC8vIGFuIGV4YW1wbGUgdXNpbmcgYW4gb2JqZWN0IGluc3RlYWQgb2YgYW4gYXJyYXlcbiAqIGFzeW5jLnNlcmllcyh7XG4gKiAgICAgb25lOiBmdW5jdGlvbihjYWxsYmFjaykge1xuICogICAgICAgICBzZXRUaW1lb3V0KGZ1bmN0aW9uKCkge1xuICogICAgICAgICAgICAgLy8gZG8gc29tZSBhc3luYyB0YXNrXG4gKiAgICAgICAgICAgICBjYWxsYmFjayhudWxsLCAxKTtcbiAqICAgICAgICAgfSwgMjAwKTtcbiAqICAgICB9LFxuICogICAgIHR3bzogZnVuY3Rpb24oY2FsbGJhY2spIHtcbiAqICAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbigpIHtcbiAqICAgICAgICAgICAgIC8vIHRoZW4gZG8gYW5vdGhlciBhc3luYyB0YXNrXG4gKiAgICAgICAgICAgICBjYWxsYmFjayhudWxsLCAyKTtcbiAqICAgICAgICAgfSwgMTAwKTtcbiAqICAgICB9XG4gKiB9KS50aGVuKHJlc3VsdHMgPT4ge1xuICogICAgIGNvbnNvbGUubG9nKHJlc3VsdHMpO1xuICogICAgIC8vIHJlc3VsdHMgaXMgZXF1YWwgdG86IHsgb25lOiAxLCB0d286IDIgfVxuICogfSkuY2F0Y2goZXJyID0+IHtcbiAqICAgICBjb25zb2xlLmxvZyhlcnIpO1xuICogfSk7XG4gKlxuICogLy9Vc2luZyBhc3luYy9hd2FpdFxuICogYXN5bmMgKCkgPT4ge1xuICogICAgIHRyeSB7XG4gKiAgICAgICAgIGxldCByZXN1bHRzID0gYXdhaXQgYXN5bmMuc2VyaWVzKFtcbiAqICAgICAgICAgICAgIGZ1bmN0aW9uKGNhbGxiYWNrKSB7XG4gKiAgICAgICAgICAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbigpIHtcbiAqICAgICAgICAgICAgICAgICAgICAgLy8gZG8gc29tZSBhc3luYyB0YXNrXG4gKiAgICAgICAgICAgICAgICAgICAgIGNhbGxiYWNrKG51bGwsICdvbmUnKTtcbiAqICAgICAgICAgICAgICAgICB9LCAyMDApO1xuICogICAgICAgICAgICAgfSxcbiAqICAgICAgICAgICAgIGZ1bmN0aW9uKGNhbGxiYWNrKSB7XG4gKiAgICAgICAgICAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbigpIHtcbiAqICAgICAgICAgICAgICAgICAgICAgLy8gdGhlbiBkbyBhbm90aGVyIGFzeW5jIHRhc2tcbiAqICAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2sobnVsbCwgJ3R3bycpO1xuICogICAgICAgICAgICAgICAgIH0sIDEwMCk7XG4gKiAgICAgICAgICAgICB9XG4gKiAgICAgICAgIF0pO1xuICogICAgICAgICBjb25zb2xlLmxvZyhyZXN1bHRzKTtcbiAqICAgICAgICAgLy8gcmVzdWx0cyBpcyBlcXVhbCB0byBbJ29uZScsJ3R3byddXG4gKiAgICAgfVxuICogICAgIGNhdGNoIChlcnIpIHtcbiAqICAgICAgICAgY29uc29sZS5sb2coZXJyKTtcbiAqICAgICB9XG4gKiB9XG4gKlxuICogLy8gYW4gZXhhbXBsZSB1c2luZyBhbiBvYmplY3QgaW5zdGVhZCBvZiBhbiBhcnJheVxuICogYXN5bmMgKCkgPT4ge1xuICogICAgIHRyeSB7XG4gKiAgICAgICAgIGxldCByZXN1bHRzID0gYXdhaXQgYXN5bmMucGFyYWxsZWwoe1xuICogICAgICAgICAgICAgb25lOiBmdW5jdGlvbihjYWxsYmFjaykge1xuICogICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24oKSB7XG4gKiAgICAgICAgICAgICAgICAgICAgIC8vIGRvIHNvbWUgYXN5bmMgdGFza1xuICogICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayhudWxsLCAxKTtcbiAqICAgICAgICAgICAgICAgICB9LCAyMDApO1xuICogICAgICAgICAgICAgfSxcbiAqICAgICAgICAgICAgdHdvOiBmdW5jdGlvbihjYWxsYmFjaykge1xuICogICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24oKSB7XG4gKiAgICAgICAgICAgICAgICAgICAgIC8vIHRoZW4gZG8gYW5vdGhlciBhc3luYyB0YXNrXG4gKiAgICAgICAgICAgICAgICAgICAgIGNhbGxiYWNrKG51bGwsIDIpO1xuICogICAgICAgICAgICAgICAgIH0sIDEwMCk7XG4gKiAgICAgICAgICAgIH1cbiAqICAgICAgICAgfSk7XG4gKiAgICAgICAgIGNvbnNvbGUubG9nKHJlc3VsdHMpO1xuICogICAgICAgICAvLyByZXN1bHRzIGlzIGVxdWFsIHRvOiB7IG9uZTogMSwgdHdvOiAyIH1cbiAqICAgICB9XG4gKiAgICAgY2F0Y2ggKGVycikge1xuICogICAgICAgICBjb25zb2xlLmxvZyhlcnIpO1xuICogICAgIH1cbiAqIH1cbiAqXG4gKi9cbmZ1bmN0aW9uIHNlcmllcyh0YXNrcywgY2FsbGJhY2spIHtcbiAgICByZXR1cm4gKDAsIF9wYXJhbGxlbDMuZGVmYXVsdCkoX2VhY2hPZlNlcmllczIuZGVmYXVsdCwgdGFza3MsIGNhbGxiYWNrK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x0c1snMC4yJ10ucm9vdE5hbWUpKSB7XG4gICAgICAgIHJvb3ROYW1lID0gT2JqZWN0LmtleXMocm9vdE9iailbMF07XG4gICAgICAgIHJvb3RPYmogPSByb290T2JqW3Jvb3ROYW1lXTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHJvb3ROYW1lID0gdGhpcy5vcHRpb25zLnJvb3ROYW1lO1xuICAgICAgfVxuICAgICAgcmVuZGVyID0gKGZ1bmN0aW9uKF90aGlzKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbihlbGVtZW50LCBvYmopIHtcbiAgICAgICAgICB2YXIgYXR0ciwgY2hpbGQsIGVudHJ5LCBpbmRleCwga2V5LCB2YWx1ZTtcbiAgICAgICAgICBpZiAodHlwZW9mIG9iaiAhPT0gJ29iamVjdCcpIHtcbiAgICAgICAgICAgIGlmIChfdGhpcy5vcHRpb25zLmNkYXRhICYmIHJlcXVpcmVzQ0RBVEEob2JqKSkge1xuICAgICAgICAgICAgICBlbGVtZW50LnJhdyh3cmFwQ0RBVEEob2JqKSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBlbGVtZW50LnR4dChvYmopO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAoQXJyYXkuaXNBcnJheShvYmopKSB7XG4gICAgICAgICAgICBmb3IgKGluZGV4IGluIG9iaikge1xuICAgICAgICAgICAgICBpZiAoIWhhc1Byb3AuY2FsbChvYmosIGluZGV4KSkgY29udGludWU7XG4gICAgICAgICAgICAgIGNoaWxkID0gb2JqW2luZGV4XTtcbiAgICAgICAgICAgICAgZm9yIChrZXkgaW4gY2hpbGQpIHtcbiAgICAgICAgICAgICAgICBlbnRyeSA9IGNoaWxkW2tleV07XG4gICAgICAgICAgICAgICAgZWxlbWVudCA9IHJlbmRlcihlbGVtZW50LmVsZShrZXkpLCBlbnRyeSkudXAoKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBmb3IgKGtleSBpbiBvYmopIHtcbiAgICAgICAgICAgICAgaWYgKCFoYXNQcm9wLmNhbGwob2JqLCBrZXkpKSBjb250aW51ZTtcbiAgICAgICAgICAgICAgY2hpbGQgPSBvYmpba2V5XTtcbiAgICAgICAgICAgICAgaWYgKGtleSA9PT0gYXR0cmtleSkge1xuICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgY2hpbGQgPT09IFwib2JqZWN0XCIpIHtcbiAgICAgICAgICAgICAgICAgIGZvciAoYXR0ciBpbiBjaGlsZCkge1xuICAgICAgICAgICAgICAgICAgICB2YWx1ZSA9IGNoaWxkW2F0dHJdO1xuICAgICAgICAgICAgICAgICAgICBlbGVtZW50ID0gZWxlbWVudC5hdHQoYXR0ciwgdmFsdWUpO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfSBlbHNlIGlmIChrZXkgPT09IGNoYXJrZXkpIHtcbiAgICAgICAgICAgICAgICBpZiAoX3RoaXMub3B0aW9ucy5jZGF0YSAmJiByZXF1aXJlc0NEQVRBKGNoaWxkKSkge1xuICAgICAgICAgICAgICAgICAgZWxlbWVudCA9IGVsZW1lbnQucmF3KHdyYXBDREFUQShjaGlsZCkpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICBlbGVtZW50ID0gZWxlbWVudC50eHQoY2hpbGQpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KGNoaWxkKSkge1xuICAgICAgICAgICAgICAgIGZvciAoaW5kZXggaW4gY2hpbGQpIHtcbiAgICAgICAgICAgICAgICAgIGlmICghaGFzUHJvcC5jYWxsKGNoaWxkLCBpbmRleCkpIGNvbnRpbnVlO1xuICAgICAgICAgICAgICAgICAgZW50cnkgPSBjaGlsZFtpbmRleF07XG4gICAgICAgICAgICAgICAgICBpZiAodHlwZW9mIGVudHJ5ID09PSAnc3RyaW5nJykge1xuICAgICAgICAgICAgICAgICAgICBpZiAoX3RoaXMub3B0aW9ucy5jZGF0YSAmJiByZXF1aXJlc0NEQVRBKGVudHJ5KSkge1xuICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnQgPSBlbGVtZW50LmVsZShrZXkpLnJhdyh3cmFwQ0RBVEEoZW50cnkpKS51cCgpO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgIGVsZW1lbnQgPSBlbGVtZW50LmVsZShrZXksIGVudHJ5KS51cCgpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBlbGVtZW50ID0gcmVuZGVyKGVsZW1lbnQuZWxlKGtleSksIGVudHJ5KS51cCgpO1xuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgY2hpbGQgPT09IFwib2JqZWN0XCIpIHtcbiAgICAgICAgICAgICAgICBlbGVtZW50ID0gcmVuZGVyKGVsZW1lbnQuZWxlKGtleSksIGNoaWxkKS51cCgpO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgY2hpbGQgPT09ICdzdHJpbmcnICYmIF90aGlzLm9wdGlvbnMuY2RhdGEgJiYgcmVxdWlyZXNDREFUQShjaGlsZCkpIHtcbiAgICAgICAgICAgICAgICAgIGVsZW1lbnQgPSBlbGVtZW50LmVsZShrZXkpLnJhdyh3cmFwQ0RBVEEoY2hpbGQpKS51cCgpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICBpZiAoY2hpbGQgPT0gbnVsbCkge1xuICAgICAgICAgICAgICAgICAgICBjaGlsZCA9ICcnO1xuICAgICAgICAgICAgICAgICAg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pcy5zYXhQYXJzZXIud3JpdGUoY2h1bmspO1xuICAgICAgICAgIHJldHVybiB0aGlzLnNheFBhcnNlci5jbG9zZSgpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGNodW5rID0gdGhpcy5yZW1haW5pbmcuc3Vic3RyKDAsIHRoaXMub3B0aW9ucy5jaHVua1NpemUpO1xuICAgICAgICAgIHRoaXMucmVtYWluaW5nID0gdGhpcy5yZW1haW5pbmcuc3Vic3RyKHRoaXMub3B0aW9ucy5jaHVua1NpemUsIHRoaXMucmVtYWluaW5nLmxlbmd0aCk7XG4gICAgICAgICAgdGhpcy5zYXhQYXJzZXIgPSB0aGlzLnNheFBhcnNlci53cml0ZShjaHVuayk7XG4gICAgICAgICAgcmV0dXJuIHNldEltbWVkaWF0ZSh0aGlzLnByb2Nlc3NBc3luYyk7XG4gICAgICAgIH1cbiAgICAgIH0gY2F0Y2ggKGVycm9yMSkge1xuICAgICAgICBlcnIgPSBlcnJvcjE7XG4gICAgICAgIGlmICghdGhpcy5zYXhQYXJzZXIuZXJyVGhyb3duKSB7XG4gICAgICAgICAgdGhpcy5zYXhQYXJzZXIuZXJyVGhyb3duID0gdHJ1ZTtcbiAgICAgICAgICByZXR1cm4gdGhpcy5lbWl0KGVycik7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9O1xuXG4gICAgUGFyc2VyLnByb3RvdHlwZS5hc3NpZ25PclB1c2ggPSBmdW5jdGlvbihvYmosIGtleSwgbmV3VmFsdWUpIHtcbiAgICAgIGlmICghKGtleSBpbiBvYmopKSB7XG4gICAgICAgIGlmICghdGhpcy5vcHRpb25zLmV4cGxpY2l0QXJyYXkpIHtcbiAgICAgICAgICByZXR1cm4gb2JqW2tleV0gPSBuZXdWYWx1ZTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICByZXR1cm4gb2JqW2tleV0gPSBbbmV3VmFsdWVdO1xuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBpZiAoIShvYmpba2V5XSBpbnN0YW5jZW9mIEFycmF5KSkge1xuICAgICAgICAgIG9ialtrZXldID0gW29ialtrZXldXTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gb2JqW2tleV0ucHVzaChuZXdWYWx1ZSk7XG4gICAgICB9XG4gICAgfTtcblxuICAgIFBhcnNlci5wcm90b3R5cGUucmVzZXQgPSBmdW5jdGlvbigpIHtcbiAgICAgIHZhciBhdHRya2V5LCBjaGFya2V5LCBvbnRleHQsIHN0YWNrO1xuICAgICAgdGhpcy5yZW1vdmVBbGxMaXN0ZW5lcnMoKTtcbiAgICAgIHRoaXMuc2F4UGFyc2VyID0gc2F4LnBhcnNlcih0aGlzLm9wdGlvbnMuc3RyaWN0LCB7XG4gICAgICAgIHRyaW06IGZhbHNlLFxuICAgICAgICBub3JtYWxpemU6IGZhbHNlLFxuICAgICAgICB4bWxuczogdGhpcy5vcHRpb25zLnhtbG5zXG4gICAgICB9KTtcbiAgICAgIHRoaXMuc2F4UGFyc2VyLmVyclRocm93biA9IGZhbHNlO1xuICAgICAgdGhpcy5zYXhQYXJzZXIub25lcnJvciA9IChmdW5jdGlvbihfdGhpcykge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24oZXJyb3IpIHtcbiAgICAgICAgICBfdGhpcy5zYXhQYXJzZXIucmVzdW1lKCk7XG4gICAgICAgICAgaWYgKCFfdGhpcy5zYXhQYXJzZXIuZXJyVGhyb3duKSB7XG4gICAgICAgICAgICBfdGhpcy5zYXhQYXJzZXIuZXJyVGhyb3duID0gdHJ1ZTtcbiAgICAgICAgICAgIHJldHVybiBfdGhpcy5lbWl0KFwiZXJyb3JcIiwgZXJyb3IpO1xuICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgIH0pKHRoaXMpO1xuICAgICAgdGhpcy5zYXhQYXJzZXIub25lbmQgPSAoZnVuY3Rpb24oX3RoaXMpIHtcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKCkge1xuICAgICAg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nRyaW0pIHtcbiAgICAgICAgICAgICAgb2JqW2NoYXJrZXldID0gb2JqW2NoYXJrZXldLnRyaW0oKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChfdGhpcy5vcHRpb25zLm5vcm1hbGl6ZSkge1xuICAgICAgICAgICAgICBvYmpbY2hhcmtleV0gPSBvYmpbY2hhcmtleV0ucmVwbGFjZSgvXFxzezIsfS9nLCBcIiBcIikudHJpbSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgb2JqW2NoYXJrZXldID0gX3RoaXMub3B0aW9ucy52YWx1ZVByb2Nlc3NvcnMgPyBwcm9jZXNzSXRlbShfdGhpcy5vcHRpb25zLnZhbHVlUHJvY2Vzc29ycywgb2JqW2NoYXJrZXldLCBub2RlTmFtZSkgOiBvYmpbY2hhcmtleV07XG4gICAgICAgICAgICBpZiAoT2JqZWN0LmtleXMob2JqKS5sZW5ndGggPT09IDEgJiYgY2hhcmtleSBpbiBvYmogJiYgIV90aGlzLkVYUExJQ0lUX0NIQVJLRVkpIHtcbiAgICAgICAgICAgICAgb2JqID0gb2JqW2NoYXJrZXldO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoaXNFbXB0eShvYmopKSB7XG4gICAgICAgICAgICBpZiAodHlwZW9mIF90aGlzLm9wdGlvbnMuZW1wdHlUYWcgPT09ICdmdW5jdGlvbicpIHtcbiAgICAgICAgICAgICAgb2JqID0gX3RoaXMub3B0aW9ucy5lbXB0eVRhZygpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgb2JqID0gX3RoaXMub3B0aW9ucy5lbXB0eVRhZyAhPT0gJycgPyBfdGhpcy5vcHRpb25zLmVtcHR5VGFnIDogZW1wdHlTdHI7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChfdGhpcy5vcHRpb25zLnZhbGlkYXRvciAhPSBudWxsKSB7XG4gICAgICAgICAgICB4cGF0aCA9IFwiL1wiICsgKChmdW5jdGlvbigpIHtcbiAgICAgICAgICAgICAgdmFyIGksIGxlbiwgcmVzdWx0cztcbiAgICAgICAgICAgICAgcmVzdWx0cyA9IFtdO1xuICAgICAgICAgICAgICBmb3IgKGkgPSAwLCBsZW4gPSBzdGFjay5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xuICAgICAgICAgICAgICAgIG5vZGUgPSBzdGFja1tpXTtcbiAgICAgICAgICAgICAgICByZXN1bHRzLnB1c2gobm9kZVtcIiNuYW1lXCJdKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICByZXR1cm4gcmVzdWx0cztcbiAgICAgICAgICAgIH0pKCkpLmNvbmNhdChub2RlTmFtZSkuam9pbihcIi9cIik7XG4gICAgICAgICAgICAoZnVuY3Rpb24oKSB7XG4gICAgICAgICAgICAgIHZhciBlcnI7XG4gICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIG9iaiA9IF90aGlzLm9wdGlvbnMudmFsaWRhdG9yKHhwYXRoLCBzICYmIHNbbm9kZU5hbWVdLCBvYmopO1xuICAgICAgICAgICAgICB9IGNhdGNoIChlcnJvcjEpIHtcbiAgICAgICAgICAgICAgICBlcnIgPSBlcnJvcjE7XG4gICAgICAgICAgICAgICAgcmV0dXJuIF90aGlzLmVtaXQoXCJlcnJvclwiLCBlcnIpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KSgpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoX3RoaXMub3B0aW9ucy5leHBsaWNpdENoaWxkcmVuICYmICFfdGhpcy5vcHRpb25zLm1lcmdlQXR0cnMgJiYgdHlwZW9mIG9iaiA9PT0gJ29iamVjdCcpIHtcbiAgICAgICAgICAgIGlmICghX3RoaXMub3B0aW9ucy5wcmVzZXJ2ZUNoaWxkcmVuT3JkZXIpIHtcbiAgICAgICAgICAgICAgbm9kZSA9IE9iamVjdC5jcmVhdGUobnVsbCk7XG4gICAgICAgICAgICAgIGlmIChfdGhpcy5vcHRpb25zLmF0dHJrZXkgaW4gb2JqKSB7XG4gICAgICAgICAgICAgICAgbm9kZVtfdGhpcy5vcHRpb25zLmF0dHJrZXldID0gb2JqW190aGlzLm9wdGlvbnMuYXR0cmtleV07XG4gICAgICAgICAgICAgICAgZGVsZXRlIG9ialtfdGhpcy5vcHRpb25zLmF0dHJrZXldO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGlmICghX3RoaXMub3B0aW9ucy5jaGFyc0FzQ2hpbGRyZW4gJiYgX3RoaXMub3B0aW9ucy5jaGFya2V5IGluIG9iaikge1xuICAgICAgICAgICAgICAgIG5vZGVbX3RoaXMub3B0aW9ucy5jaGFya2V5XSA9IG9ialtfdGhpcy5vcHRpb25zLmNoYXJrZXldO1xuICAgICAgICAgICAgICAgIGRlbGV0ZSBvYmpbX3RoaXMub3B0aW9ucy5jaGFya2V5XTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBpZiAoT2JqZWN0LmdldE93blByb3BlcnR5TmFtZXMob2JqKS5sZW5ndGggPiAwKSB7XG4gICAgICAgICAgICAgICAgbm9kZVtfdGhpcy5vcHRpb25zLmNoaWxka2V5XSA9IG9iajtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBvYmogPSBub2RlO1xuICAgICAgICAgICAgfSBlbHNlIGlmIChzKSB7XG4gICAgICAgICAgICAgIHNbX3RoaXMub3B0aW9ucy5jaGlsZGtleV0gPSBzW190aGlzLm9wdGlvbnMuY2hpbGRrZXldIHx8IFtdO1xuICAgICAgICAgICAgICBvYmpDbG9uZSA9IE9iamVjdC5jcmVhdGUobnVsbCk7XG4gICAgICAgICAgICAgIGZvciAoa2V5IGluIG9iaikge1xuICAgICAgICAgICAgICAgIGlmICghaGFzUHJvcC5jYWxsKG9iaiwga2V5KSkgY29udGludWU7XG4gICAgICAgICAgICAgICAgb2JqQ2xvbmVba2V5XSA9IG9ialtrZXldO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHNbX3RoaXMub3B0aW9ucy5jaGlsZGtleV0ucHVzaChvYmpDbG9uZSk7XG4gICAgICAgICAgICAgIGRlbGV0ZSBvYmpbXCIjbmFtZVwiXTtcbiAgICAgICAgICAgICAgaWYgKE9iamVjdC5rZXlzKG9iaikubGVuZ3RoID09PSAxICYmIGNoYXJrZXkgaW4gb2JqICYmICFfdGhpcy5FWFBMSUNJVF9DSEFSS0VZKSB7XG4gICAgICAgICAgICAgICAgb2JqID0gb2JqW2NoYXJrZXldO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChzdGFjay5sZW5ndGggPiAwKSB7XG4gICAgICAgICAgICByZXR1cm4gX3RoaXMuYXNzaWduT3JQdXNoKHMsIG5vZGVOYW1lLCBvYmopO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBpZiAoX3RoaXMub3B0aW9ucy5leHBsaWNpdFJvb3QpIHtcbiAgICAgICAgICAgICAgb2xkID0gb2JqO1xuICAgICAgICAgICAgICBvYmogPSBPYmplY3QuY3JlYXRlKG51bGwpO1xuICAgICAgICAgICAgICBvYmpbbm9kZU5hbWVdID0gb2xkO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgX3RoaXMucmVzdWx0T2JqZWN0ID0gb2JqO1xuICAgICAgICAgICAgX3RoaXMuc2F4UGFyc2VyLmVuZGVkID0gdHJ1ZTtcbiAgICAgICAgICAgIHJldHVybiBfdGhpcy5lbWl0KFwiZW5kXCIsIF90aGlzLnJlc3VsdE9iamVjdCk7XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgfSkodGhpcyk7XG4gICAgICBvbnRleHQgPSAoZnVuY3Rpb24oX3RoaXMpIHtcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKHRleHQpIHtcbiAgICAgICAgICB2YXIgY2hhckNoaWxkLCBzO1xuICAgICAgICAgIHMgPSBzdGFja1tzdGFjay5sZW5ndGggLSAxXTtcbiAgICAgICAgICBpZiAocykge1xuICAgICAgICAgICAgc1tjaGFya2V5XSArPSB0ZXh0O1xuICAgICAgICAgICAgaWYgKF90aGlzLm9wdGlvbnMuZXhwbGljaXRDaGlsZHJlbiAmJiBfdGhpcy5vcHRpb25zLnByZXNlcnZlQ2hpbGRyZW5PcmRlciAmJiBfdGhpcy5vcHRpb25zLmNoYXJzQXNDaGlsZHJlbiAmJiAoX3RoaXMub3B0aW9ucy5pbmNsdWRlV2hpdGVDaGFycyB8fCB0ZXh0LnJlcGxhY2UoL1xcXFxuL2csICcnKS50cmltKCkgIT09ICcnKSkge1xuICAgICAgICAgICAgICBzW190aGlzLm9wdGlvbnMuY2hpbGRrZXldID0gc1tfdGhpcy5vcHRpb25zLmNoaWxka2V5XSB8fCBbXTtcbiAgICAgICAgICAgICAgY2hhckNoaWxkID0ge1xuICAgICAgICAgICAgICAgICcjbmFtZSc6ICdfX3RleHRfXydcbiAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgY2hhckNoaWxkW2NoYXJrZXldID0gdGV4dDtcbiAgICAgICAgICAgICAgaWYgKF90aGlzLm9wdGlvbnMubm9ybWFsaXplKSB7XG4gICAgICAgICAgICAgICAgY2hhckNoaWxkW2NoYXJrZXldID0gY2hhckNoaWxkW2NoYXJrZXldLnJlcGxhY2UoL1xcc3syLH0vZywgXCIgXCIpLnRyaW0oKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBzW190aGlzLm9wdGlvbnMuY2hpbGRrZXldLnB1c2goY2hhckNoaWxkKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiBzO1xuICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgIH0pKHRoaXMpO1xuICAgICAgdGhpcy5zYXhQYXJzZXIub250ZXh0ID0gb250ZXh0O1xuICAgICAgcmV0dXJuIHRoaXMuc2F4UGFyc2VyLm9uY2RhdGEgPSAoZnVuY3Rpb24oX3RoaXMpIHtcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKHRleHQpIHtcbiAgICAgICAgICB2YXIgcztcbiAgICAgICAgICBzID0gb250ZXh0KHRleHQpO1xuICAgICAgICAgIGlmIChzKSB7XG4gICAgICAgICAgICByZXR1cm4gcy5jZGF0YSA9IHRydWU7XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgfSkodGhpcyk7XG4gICAgfTtcblxuICAgIFBhcnNlci5wcm90b3R5cGUucGFyc2VTdHJpbmcgPSBmdW5jdGlvbihzdHIsIGNiKSB7XG4gICAgICB2YXIgZXJyO1xuICAgICAgaWYgKChjYiAhPSBudWxsKSAmJiB0eXBlb2YgY2IgPT09IFwiZnVuY3Rpb25cIikge1xuICAgICAgICB0aGlzLm9uKFwiZW5kXCIsIGZ1bmN0aW9uKHJlc3VsdCkge1xuICAgICAgICAgIHRoaXMucmVzZXQoKTtcbiAgICAgICAgICByZXR1cm4gY2IobnVsbCwgcmVzdWx0KTtcbiAgICAgICAgfSk7XG4gICAgICAgIHRoaXMub24oXCJlcnJvclwiLCBmdW5jdGlvbihlcnIpIHtcbiAgICAgICAgICB0aGlzLnJlc2V0KCk7XG4gICAgICAgICAgcmV0dXJuIGNiKGVycik7XG4gICAgICAgIH0pO1xuICAgICAgfVxuICAgICAgdHJ5IHtcbiAgICAgICAgc3RyID0gc3RyLnRvU3RyaW5nKCk7XG4gICAgICAgIGlmIChzdHIudHJpbSgpID09PSAnJykge1xuICAgICAgICAgIHRoaXMuZW1pdChcImVuZFwiLCBudWxsKTtcbiAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgICBzdHIgPSBib20uc3RyaXBCT00oc3RyKTtcbiAgICAgICAgaWYgKHRoaXMub3B0aW9ucy5hc3luYykge1xuICAgICAgICAgIHRoaXMucmVtYWluaW5nID0gc3RyO1xuICAgICAgICAgIHNldEltbWVkaWF0ZSh0aGlzLnByb2Nlc3NBc3luYyk7XG4gICAgICAgICAgcmV0dXJuIHRoaXMuc2F4UGFyc2VyO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0aGlzLnNheFBhcnNlci53cml0ZShzdHIpLmNsb3NlKCk7XG4gICAgICB9IGNhdGNoIChlcnJvcjEpIHtcbiAgICAgICAgZXJyID0gZXJyb3IxO1xuICAgICAgICBpZiAoISh0aGlzLnNheFBhcnNlci5lcnJUaHJvd24gfHwgdGhpcy5zYXhQYXJzZXIuZW5kZWQpKSB7XG4gICAgICAgICAgdGhpcy5lbWl0KCdlcnJvcicsIGVycik7XG4gICAgICAgICAgcmV0dXJuIHRoaXMuc2F4UGFyc2VyLmVyclRocm93biA9IHRydWU7XG4gICAgICAgIH0gZWxzZSBpZiAodGhpcy5zYXhQYXJzZXIuZW5kZWQpIHtcbiAgICAgICAgICB0aHJvdyBlcnI7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9O1xuXG4gICAgUGFyc2VyLnByb3RvdHlwZS5wYXJzZVN0cmluZ1Byb21pc2UgPSBmdW5jdGlvbihzdHIpIHtcbiAgICAgIHJldHVybiBuZXcgUHJvbWlzZSgoZnVuY3Rpb24oX3RoaXMpIHtcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKHJlc29sdmUsIHJlamVjdCkge1xuICAgICAgICAgIHJldHVybiBfdGhpcy5wYXJzZVN0cmluZyhzdHIsIGZ1bmN0aW9uKGVyciwgdmFsdWUpIHtcbiAgICAgICAgICAgIGlmIChlcnIpIHtcbiAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChlcnIpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgcmV0dXJuIHJlc29sdmUodmFsdWUpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pO1xuICAgICAgICB9O1xuICAgICAgfSkodGhpcykpO1xuICAgIH07XG5cbiAgICByZXR1cm4gUGFyc2VyO1xuXG4gIH0pKGV2ZW50cyk7XG5cb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mplY3QuZGVmaW5lUHJvcGVydHkoWE1MRG9jdW1lbnQucHJvdG90eXBlLCAnZG9jdHlwZScsIHtcbiAgICAgIGdldDogZnVuY3Rpb24oKSB7XG4gICAgICAgIHZhciBjaGlsZCwgaSwgbGVuLCByZWY7XG4gICAgICAgIHJlZiA9IHRoaXMuY2hpbGRyZW47XG4gICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IHJlZi5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xuICAgICAgICAgIGNoaWxkID0gcmVmW2ldO1xuICAgICAgICAgIGlmIChjaGlsZC50eXBlID09PSBOb2RlVHlwZS5Eb2NUeXBlKSB7XG4gICAgICAgICAgICByZXR1cm4gY2hpbGQ7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHJldHVybiBudWxsO1xuICAgICAgfVxuICAgIH0pO1xuXG4gICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KFhNTERvY3VtZW50LnByb3RvdHlwZSwgJ2RvY3VtZW50RWxlbWVudCcsIHtcbiAgICAgIGdldDogZnVuY3Rpb24oKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnJvb3RPYmplY3QgfHwgbnVsbDtcbiAgICAgIH1cbiAgICB9KTtcblxuICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShYTUxEb2N1bWVudC5wcm90b3R5cGUsICdpbnB1dEVuY29kaW5nJywge1xuICAgICAgZ2V0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgcmV0dXJuIG51bGw7XG4gICAgICB9XG4gICAgfSk7XG5cbiAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoWE1MRG9jdW1lbnQucHJvdG90eXBlLCAnc3RyaWN0RXJyb3JDaGVja2luZycsIHtcbiAgICAgIGdldDogZnVuY3Rpb24oKSB7XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgIH1cbiAgICB9KTtcblxuICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShYTUxEb2N1bWVudC5wc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hpbGRyZW4gPyAnPicgOiAnLz4nKSArIHRoaXMud3JpdGVyLmVuZGxpbmUobm9kZSwgdGhpcy53cml0ZXJPcHRpb25zLCB0aGlzLmN1cnJlbnRMZXZlbCk7XG4gICAgICAgICAgdGhpcy53cml0ZXJPcHRpb25zLnN0YXRlID0gV3JpdGVyU3RhdGUuSW5zaWRlVGFnO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHRoaXMud3JpdGVyT3B0aW9ucy5zdGF0ZSA9IFdyaXRlclN0YXRlLk9wZW5UYWc7XG4gICAgICAgICAgY2h1bmsgPSB0aGlzLndyaXRlci5pbmRlbnQobm9kZSwgdGhpcy53cml0ZXJPcHRpb25zLCB0aGlzLmN1cnJlbnRMZXZlbCkgKyAnPCFET0NUWVBFICcgKyBub2RlLnJvb3ROb2RlTmFtZTtcbiAgICAgICAgICBpZiAobm9kZS5wdWJJRCAmJiBub2RlLnN5c0lEKSB7XG4gICAgICAgICAgICBjaHVuayArPSAnIFBVQkxJQyBcIicgKyBub2RlLnB1YklEICsgJ1wiIFwiJyArIG5vZGUuc3lzSUQgKyAnXCInO1xuICAgICAgICAgIH0gZWxzZSBpZiAobm9kZS5zeXNJRCkge1xuICAgICAgICAgICAgY2h1bmsgKz0gJyBTWVNURU0gXCInICsgbm9kZS5zeXNJRCArICdcIic7XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChub2RlLmNoaWxkcmVuKSB7XG4gICAgICAgICAgICBjaHVuayArPSAnIFsnO1xuICAgICAgICAgICAgdGhpcy53cml0ZXJPcHRpb25zLnN0YXRlID0gV3JpdGVyU3RhdGUuSW5zaWRlVGFnO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aGlzLndyaXRlck9wdGlvbnMuc3RhdGUgPSBXcml0ZXJTdGF0ZS5DbG9zZVRhZztcbiAgICAgICAgICAgIGNodW5rICs9ICc+JztcbiAgICAgICAgICB9XG4gICAgICAgICAgY2h1bmsgKz0gdGhpcy53cml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ICAgIGkgPSB0aGlzLnBhcmVudC5jaGlsZHJlbi5pbmRleE9mKHRoaXMpO1xuICAgICAgICByZXR1cm4gdGhpcy5wYXJlbnQuY2hpbGRyZW5baSArIDFdIHx8IG51bGw7XG4gICAgICB9XG4gICAgfSk7XG5cbiAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoWE1MTm9kZS5wcm90b3R5cGUsICdvd25lckRvY3VtZW50Jywge1xuICAgICAgZ2V0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuZG9jdW1lbnQoKSB8fCBudWxsO1xuICAgICAgfVxuICAgIH0pO1xuXG4gICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KFhNTE5vZGUucHJvdG90eXBlLCAndGV4dENvbnRlbnQnLCB7XG4gICAgICBnZXQ6IGZ1bmN0aW9uKCkge1xuICAgICAgICB2YXIgY2hpbGQsIGosIGxlbiwgcmVmMiwgc3RyO1xuICAgICAgICBpZiAodGhpcy5ub2RlVHlwZSA9PT0gTm9kZVR5cGUuRWxlbWVudCB8fCB0aGlzLm5vZGVUeXBlID09PSBOb2RlVHlwZS5Eb2N1bWVudEZyYWdtZW50KSB7XG4gICAgICAgICAgc3RyID0gJyc7XG4gICAgICAgICAgcmVmMiA9IHRoaXMuY2hpbGRyZW47XG4gICAgICAgICAgZm9yIChqID0gMCwgbGVuID0gcmVmMi5sZW5ndGg7IGogPCBsZW47IGorKykge1xuICAgICAgICAgICAgY2hpbGQgPSByZWYyW2pdO1xuICAgICAgICAgICAgaWYgKGNoaWxkLnRleHRDb250ZW50KSB7XG4gICAgICAgICAgICAgIHN0ciArPSBjaGlsZC50ZXh0Q29udGVudDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgcmV0dXJuIHN0cjtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICByZXR1cm4gbnVsbDtcbiAgICAgICAgfVxuICAgICAgfSxcbiAgICAgIHNldDogZnVuY3Rpb24odmF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ICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHJlZjMgPSBkb2MuY2hpbGRyZW47XG4gICAgICBmb3IgKGkgPSBrID0gMCwgbGVuMSA9IHJlZjMubGVuZ3RoOyBrIDwgbGVuMTsgaSA9ICsraykge1xuICAgICAgICBjaGlsZCA9IHJlZjNbaV07XG4gICAgICAgIGlmIChjaGlsZC5pc1Jvb3QpIHtcbiAgICAgICAgICBkb2MuY2hpbGRyZW4uc3BsaWNlKGksIDAsIGRvY3R5cGUpO1xuICAgICAgICAgIHJldHVybiBkb2N0eXBlO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICBkb2MuY2hpbGRyZW4ucHVzaChkb2N0eXBlKTtcbiAgICAgIHJldHVybiBkb2N0eXBlO1xuICAgIH07XG5cbiAgICBYTUxOb2RlLnByb3RvdHlwZS51cCA9IGZ1bmN0aW9uKCkge1xuICAgICAgaWYgKHRoaXMuaXNSb290KSB7XG4gICAgICAgIHRocm93IG5ldyBFcnJvcihcIlRoZSByb290IG5vZGUgaGFzIG5vIHBhcmVudC4gVXNlIGRvYygpIGlmIHlvdSBuZWVkIHRvIGdldCB0aGUgZG9jdW1lbnQgb2JqZWN0LlwiKTtcbiAgICAgIH1cbiAgICAgIHJldHVybiB0aGlzLnBhcmVudDtcbiAgICB9O1xuXG4gICAgWE1MTm9kZS5wcm90b3R5cGUucm9vdCA9IGZ1bmN0aW9uKCkge1xuICAgICAgdmFyIG5vZGU7XG4gICAgICBub2RlID0gdGhpcztcbiAgICAgIHdoaWxlIChub2RlKSB7XG4gICAgICAgIGlmIChub2RlLnR5cGUgPT09IE5vZGVUeXBlLkRvY3VtZW50KSB7XG4gICAgICAgICAgcmV0dXJuIG5vZGUucm9vdE9iamVjdDtcbiAgICAgICAgfSBlbHNlIGlmIChub2RlLmlzUm9vdCkge1xuICAgICAgICAgIHJldHVybiBub2RlO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIG5vZGUgPSBub2RlLnBhcmVudDtcbiAgICA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09IC0xKSB7XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHJldHVybiBub2RlUG9zID4gdGhpc1BvcztcbiAgICAgIH1cbiAgICB9O1xuXG4gICAgWE1MTm9kZS5wcm90b3R5cGUudHJlZVBvc2l0aW9uID0gZnVuY3Rpb24obm9kZSkge1xuICAgICAgdmFyIGZvdW5kLCBwb3M7XG4gICAgICBwb3MgPSAwO1xuICAgICAgZm91bmQgPSBmYWxzZTtcbiAgICAgIHRoaXMuZm9yZWFjaFRyZWVOb2RlKHRoaXMuZG9jdW1lbnQoKSwgZnVuY3Rpb24oY2hpbGROb2RlKSB7XG4gICAgICAgIHBvcysrO1xuICAgICAgICBpZiAoIWZvdW5kICYmIGNoaWxkTm9kZSA9PT0gbm9kZSkge1xuICAgICAgICAgIHJldHVybiBmb3VuZCA9IHRydWU7XG4gICAgICAgIH1cbiAgICAgIH0pO1xuICAgICAgaWYgKGZvdW5kKSB7XG4gICAgICAgIHJldHVybiBwb3M7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gLTE7XG4gICAgICB9XG4gICAgfTtcblxuICAgIFhNTE5vZGUucHJvdG90eXBlLmZvcmVhY2hUcmVlTm9kZSA9IGZ1bmN0aW9uKG5vZGUsIGZ1bmMpIHtcbiAgICAgIHZhciBjaGlsZCwgaiwgbGVuLCByZWYyLCByZXM7XG4gICAgICBub2RlIHx8IChub2RlID0gdGhpcy5kb2N1bWVudCgpKTtcbiAgICAgIHJlZjIgPSBub2RlLmNoaWxkcmVuO1xuICAgICAgZm9yIChqID0gMCwgbGVuID0gcmVmMi5sZW5ndGg7IGogPCBsZW47IGorKykge1xuICAgICAgICBjaGlsZCA9IHJlZjJbal07XG4gICAgICAgIGlmIChyZXMgPSBmdW5jKGNoaWxkKSkge1xuICAgICAgICAgIHJldHVybiByZXM7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgcmVzID0gdGhpcy5mb3JlYW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25zLm5vVmFsaWRhdGlvbikge1xuICAgICAgICByZXR1cm4gdmFsO1xuICAgICAgfVxuICAgICAgcmV0dXJuIHRoaXMuYXNzZXJ0TGVnYWxDaGFyKCcnICsgdmFsIHx8ICcnKTtcbiAgICB9O1xuXG4gICAgWE1MU3RyaW5naWZpZXIucHJvdG90eXBlLmluc1ZhbHVlID0gZnVuY3Rpb24odmFsKSB7XG4gICAgICBpZiAodGhpcy5vcHRpb25zLm5vVmFsaWRhdGlvbikge1xuICAgICAgICByZXR1cm4gdmFsO1xuICAgICAgfVxuICAgICAgdmFsID0gJycgKyB2YWwgfHwgJyc7XG4gICAgICBpZiAodmFsLm1hdGNoKC9cXD8+LykpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiSW52YWxpZCBwcm9jZXNzaW5nIGluc3RydWN0aW9uIHZhbHVlOiBcIiArIHZhbCk7XG4gICAgICB9XG4gICAgICByZXR1cm4gdGhpcy5hc3NlcnRMZWdhbENoYXIodmFsKTtcbiAgICB9O1xuXG4gICAgWE1MU3RyaW5naWZpZXIucHJvdG90eXBlLnhtbFZlcnNpb24gPSBmdW5jdGlvbih2YWwpIHtcbiAgICAgIGlmICh0aGlzLm9wdGlvbnMubm9WYWxpZGF0aW9uKSB7XG4gICAgICAgIHJldHVybiB2YWw7XG4gICAgICB9XG4gICAgICB2YWwgPSAnJyArIHZhbCB8fCAnJztcbiAgICAgIGlmICghdmFsLm1hdGNoKC8xXFwuWzAtOV0rLykpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiSW52YWxpZCB2ZXJzaW9uIG51bWJlcjogXCIgKyB2YWwpO1xuICAgICAgfVxuICAgICAgcmV0dXJuIHZhbDtcbiAgICB9O1xuXG4gICAgWE1MU3RyaW5naWZpZXIucHJvdG90eXBlLnhtbEVuY29kaW5nID0gZnVuY3Rpb24odmFsKSB7XG4gICAgICBpZiAodGhpcy5vcHRpb25zLm5vVmFsaWRhdGlvbikge1xuICAgICAgICByZXR1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udCsrO1xuICAgICAgICBwcmV0dHlTdXBwcmVzc2VkID0gdHJ1ZTtcbiAgICAgICAgciArPSB0aGlzLndyaXRlQ2hpbGROb2RlKGZpcnN0Q2hpbGROb2RlLCBvcHRpb25zLCBsZXZlbCArIDEpO1xuICAgICAgICBvcHRpb25zLnN1cHByZXNzUHJldHR5Q291bnQtLTtcbiAgICAgICAgcHJldHR5U3VwcHJlc3NlZCA9IGZhbHNlO1xuICAgICAgICBvcHRpb25zLnN0YXRlID0gV3JpdGVyU3RhdGUuQ2xvc2VUYWc7XG4gICAgICAgIHIgKz0gJzwvJyArIG5vZGUubmFtZSArICc+JyArIHRoaXMuZW5kbGluZShub2RlLCBvcHRpb25zLCBsZXZlbCk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBpZiAob3B0aW9ucy5kb250UHJldHR5VGV4dE5vZGVzKSB7XG4gICAgICAgICAgcmVmMSA9IG5vZGUuY2hpbGRyZW47XG4gICAgICAgICAgZm9yIChpID0gMCwgbGVuID0gcmVmMS5sZW5ndGg7IGkgPCBsZW47IGkrKykge1xuICAgICAgICAgICAgY2hpbGQgPSByZWYxW2ldO1xuICAgICAgICAgICAgaWYgKChjaGlsZC50eXBlID09PSBOb2RlVHlwZS5UZXh0IHx8IGNoaWxkLnR5cGUgPT09IE5vZGVUeXBlLlJhdykgJiYgKGNoaWxkLnZhbHVlICE9IG51bGwpKSB7XG4gICAgICAgICAgICAgIG9wdGlvbnMuc3VwcHJlc3NQcmV0dHlDb3VudCsrO1xuICAgICAgICAgICAgICBwcmV0dHlTdXBwcmVzc2VkID0gdHJ1ZTtcbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIHIgKz0gJz4nICsgdGhpcy5lbmRsaW5lKG5vZGUsIG9wdGlvbnMsIGxldmVsKTtcbiAgICAgICAgb3B0aW9ucy5zdGF0ZSA9IFdyaXRlclN0YXRlLkluc2lkZVRhZztc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ICAgbG9nZ2VyLmVycm9yKCdDb3VsZCBub3Qgc2V0IHVwIHByb3ZpZGVycycgKyBlcnIsICdMb2FkZWRTdGF0ZScpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcHJvY2Vzcy5lbnYuQVBQT0JKRUNUID0gdGhpcztcbiAgICAgICAgICAgIGNvbnN0IG1lbnVzQnVpbGRlciA9IG5ldyBNZW51QnVpbGRlcigpO1xuICAgICAgICAgICAgTGlmZWN5Y2xlSGlzdG9yeS5nZXQoKS5pbml0KHRoaXMpO1xuICAgICAgICAgICAgY29uc3QgbWVudSA9IG5ldyBVUkxTZWFyY2hQYXJhbXMod2luZG93LmxvY2F0aW9uLnNlYXJjaCkuZ2V0KCdtZW51Jyk7XG4gICAgICAgICAgICB0aGlzLnRhZygnTWFpbicpLnBhdGNoKHtcbiAgICAgICAgICAgICAgTWFpbk1lbnU6IHtcbiAgICAgICAgICAgICAgICB0eXBlOiBNZW51LFxuICAgICAgICAgICAgICAgIG1lbnVzOiBtZW51c0J1aWxkZXIuYnVpbGQoKSxcbiAgICAgICAgICAgICAgICBpbml0aWFsTWVudTogbWVudSxcbiAgICAgICAgICAgICAgICB4OiA1MCxcbiAgICAgICAgICAgICAgICB5OiA1MCxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIH0pO1xuXG4gICAgICAgICAgICBpZiAoIXRoaXMucHViU3ViVXVpZFByZXNlbnQgJiYgc3lzdGVtdWkgPT09ICd0cnVlJykge1xuICAgICAgICAgICAgICB0aGlzLnNldEFwcElkKENPTlNUQU5UUy5GSVJFQk9MVF9DRVJUX1VJX0FQUElEKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHRoaXMuZ2V0QXBwSWQoKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgdGhpcy5fcmVmb2N1cygpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBfZ2V0Rm9jdXNlZCgpIHtcbiAgICAg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uZW52LkNVUlJFTlRfQVBQSUQsIGZvbnRTaXplOiAzMyB9IH0pO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgZ2V0Q3VycmVudEFwcElEKCkudGhlbigocmVzKSA9PiB7XG4gICAgICAgICAgICAgICAgdGhpcy5zZXRBcHBJZChyZXMpO1xuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGNhdGNoIChlcnIpIHtcbiAgICAgICAgICAgIGNvbnNvbGUubG9nKCdFcnJvciBnZXR0aW5nIEFwcCBJZCA6OiAnLCBlcnIpO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChxdWVyeS5wYXJhbXMudGVzdHRva2VuKSB7XG4gICAgICAgICAgICBwcm9jZXNzLmVudi5URVNUX1RPS0VOID0gcXVlcnkucGFyYW1zLnRlc3R0b2tlbjtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbG9nZ2VyLmVycm9yKCdObyBUZXN0IFRva2VuIEZvdW5kIGluIFBhcmFtZXRlciBJbml0aWFsaXphdGlvbiByZXNwb25zZS4uLicsICdnZXRQYXJhbWV0ZXJJbml0aWFsaXphdGlvblZhbHVlcycpO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChxdWVyeS5wYXJhbXMubWFjYWRkcmVzcykge1xuICAgICAgICAgICAgcHJvY2Vzcy5lbnYuTUFDQUREUkVTUyA9IHF1ZXJ5LnBhcmFtcy5tYWNhZGRyZXNzO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBsb2dnZXIuZXJyb3IoJ05vIE1hYyBBZGRyZXNzIEZvdW5kIGluIFBhcmFtZXRlciBJbml0aWFsaXphdGlvbiByZXNwb25zZS4uLicsICdnZXRQYXJhbWV0ZXJJbml0aWFsaXphdGlvblZhbHVlcycpO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChxdWVyeS5wYXJhbXMuaGFzT3duUHJvcGVydHk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FsSW52b2tlcnMgZnJvbSAnZXh0ZXJuYWxJbnZva2Vycyc7XG5cbmNvbnN0IGxvZ2dlciA9IHJlcXVpcmUoJy4vdXRpbHMvTG9nZ2VyJykoJ0NhcmRzLmpzJyk7XG5cbmV4cG9ydCBkZWZhdWx0IGNsYXNzIENhcmQgZXh0ZW5kcyBsbmcuQ29tcG9uZW50IHtcbiAgc3RhdGljIF90ZW1wbGF0ZSgpIHtcbiAgICByZXR1cm4ge1xuICAgICAgeDogMCxcbiAgICAgIHk6IDAsXG4gICAgICB3OiAodykgPT4gdyxcbiAgICAgIGg6IChoKSA9PiBoLFxuICAgICAgQmFja2dyb3VuZDoge1xuICAgICAgICB3OiAodykgPT4gdyxcbiAgICAgICAgaDogKGgpID0+IGgsXG4gICAgICB9LFxuICAgICAgVGl0bGU6IHtcbiAgICAgICAgeDogMTAwLFxuICAgICAgICB5OiA1MCxcbiAgICAgICAgdzogKHcpID0+IHcgLSAxMDAsXG4gICAgICAgIGg6IDEwMCxcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIGZvbnRTaXplOiA0NSxcbiAgICAgICAgfSxcbiAgICAgIH0sXG4gICAgICBTdW1tYXJ5OiB7XG4gICAgICAgIHg6IDE1MCxcbiAgICAgICAgeTogMjAwLFxuICAgICAgICB3OiA3NTAsXG4gICAgICAgIHRleHQ6IHtcbiAgICAgICAgICBmb250U2l6ZTogMzUsXG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgICAgRXhhbXBsZVRleHQ6IHtcbiAgICAgICAgeDogMTAwLFxuICAgICAgICB5OiAzMDAsXG4gICAgICAgIHc6IDc1MCxcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIGZvbnRTaXplOiAzMCxcbiAgICAgICAgfSxcbiAgICAgIH0sXG4gICAgICBSZXN1bHRUZXh0Qmc6IHtcbiAgICAgICAgeDogODAwLFxuICAgICAgICB5OiAwLFxuICAgICAgICBoOiAxMDgwLFxuICAgICAgICB3OiAxOTIwIC0gOTAw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LFxuICAgICAgICBpdGVtczogW1xuICAgICAgICAgIHtcbiAgICAgICAgICAgIHJlZjogJ1BsYXknLFxuICAgICAgICAgICAgdHlwZTogQnV0dG9uLFxuICAgICAgICAgICAgdGl0bGU6ICdQbGF5JyxcbiAgICAgICAgICAgIHc6IDIwMCxcbiAgICAgICAgICAgIGZpeGVkOiB0cnVlLFxuICAgICAgICAgICAgYmFja2dyb3VuZFR5cGU6ICdzdHJva2UnLFxuICAgICAgICAgICAgb25FbnRlcjogZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICB0aGlzLmZpcmVBbmNlc3RvcnMoJyRwbGF5Jyk7XG4gICAgICAgICAgICB9LFxuICAgICAgICAgIH0sXG4gICAgICAgICAge1xuICAgICAgICAgICAgcmVmOiAnVG9nZ2xlSW5hY3RpdmUnLFxuICAgICAgICAgICAgdHlwZTogVG9nZ2xlV2l0aFRleHQsXG4gICAgICAgICAgICB0aXRsZTogJ1BhdXNlIG9uIGluYWN0aXZhdGUuIEFsbCBhcHBzIHNob3VsZC4gVHVybiB0aGlzIG9mZiB0byB0ZXN0IG1pc2JlaGF2aW5nIGFwcCcsXG4gICAgICAgICAgfSxcbiAgICAgICAgXSxcbiAgICAgIH0sXG4gICAgfTtcbiAgfVxuXG4gIF9pbml0KCkge1xuICAgIGNvbnN0IHAgPSB0aGlzLnRhZygnUGxheWVyJyk7XG4gICAgTGlmZWN5Y2xlLmxpc3RlbignaW5hY3RpdmUnLCAoZXZlbnQpID0+IHtcbiAgICAgIGlmIChldmVudC5zdGF0ZSAmJiB0aGlzLnRhZygnUm93LlRvZ2dsZUluYWN0aXZlJykuY2hlY2tlZCkge1xuICAgICAgICBpZiAocC5pc1BsYXlpbmcoKSkge1xuICAgICAgICAgIGxvZ2dlci5pbmZvKCdVbnBhdXNpbmcgdmlkZW8nLCAnX2luaXQnKTtcbiAgICAgICAgICBwLnBsYXlQYXVzZSgpO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfSk7XG4gICAgTGl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SkpO1xuICAgIHRoaXMucGF0Y2goe1xuICAgICAgV3JhcHBlcjoge1xuICAgICAgICBNZW51OiB1bmRlZmluZWQsXG4gICAgICB9LFxuICAgIH0pO1xuICAgIHRoaXMucGF0Y2goe1xuICAgICAgV3JhcHBlcjoge1xuICAgICAgICBoOiA3MDAsXG4gICAgICAgIHc6IDUxMCxcbiAgICAgICAgeDogMCxcbiAgICAgICAgeTogMTAwLFxuICAgICAgICBjbGlwcGluZzogdHJ1ZSxcbiAgICAgICAgTWVudToge1xuICAgICAgICAgIHR5cGU6IENvbHVtbixcbiAgICAgICAgICB4OiAyMCxcbiAgICAgICAgICB5OiAwLFxuICAgICAgICAgIHc6IDUwMCxcbiAgICAgICAgICBoOiA1MDAsXG4gICAgICAgICAgc2Nyb2xsSW5kZXg6IDAsXG4gICAgICAgICAgYWx3YXlzU2Nyb2xsOiBmYWxzZSxcbiAgICAgICAgICBpdGVtczogaXRlbXMsXG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgIH0pO1xuICAgIHRoaXMuX3JlZm9jdXMoKTtcbiAgfVxuXG4gIF9wdXNoVmlldyhpdG0pIHtcbiAgICB0aGlzLl9tZW51U3RhY2sucHVzaChpdG0pO1xuICAgIHRoaXMuX3JlbmRlclZpZXcoaXRtKTtcbiAgfVxuXG4gIF9yZW5kZXJWaWV3KGl0bSkge1xuICAgIHRoaXMucGF0Y2goe1xuICAgICAgVmlldzoge1xuICAgICAgICB0eXBlOiBpdG0udmlldyxcbiAgICAgICAgdzogKHcpID0+IHcsXG4gICAgICAgIGg6IChoKSA9PiBoLFxuICAgICAgICBwYXJhbXM6IGl0bS5wYXJhbXMsXG4gICAgICB9LFxuICAgIH0pO1xuICAgIHRoaXMucGF0Y2goe1xuICAgICAgV3JhcHBlcjoge1xuICAgICAgICBNZW51OiB1bmRlZmluZWQsXG4gICAgICB9LFxuICAgIH0pO1xuICAgIHRoaXMuX3JlZm9jdXMoKTtcbiAgfVxuXG4gIF9oYW5kbGVCYWNr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9uYWxScGNFeGFtcGxlcykge1xuICAgICAgICAgICAgYWRkaXRpb25hbFJwY0V4YW1wbGVzLm1ldGhvZHMuZm9yRWFjaCgobWV0aG9kKSA9PiB7XG4gICAgICAgICAgICAgIGNvbnN0IGZvdW5kID0gT1BFTl9SUEMubWV0aG9kcy5maW5kKChtKSA9PiBtLm5hbWUudG9Mb3dlckNhc2UoKSA9PT0gbWV0aG9kLm5hbWUudG9Mb3dlckNhc2UoKSk7XG4gICAgICAgICAgICAgIGlmIChmb3VuZCkge1xuICAgICAgICAgICAgICAgIGZvdW5kLmV4YW1wbGVzLnB1c2goLi4ubWV0aG9kLmV4YW1wbGVzKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBPUEVOX1JQQy5tZXRob2RzLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICBjb25zdCBtb2R1bGUgPSBPUEVOX1JQQy5tZXRob2RzW2ldLm5hbWUuc3BsaXQoJy4nKVswXTtcbiAgICAgICAgICAgIGNvbnN0IG1ldGhvZCA9IE9QRU5fUlBDLm1ldGhvZHNbaV0ubmFtZS5zcGxpdCgnLicpWzFdO1xuICAgICAgICAgICAgY29uc3QgbWV0aG9kT2JqID0gT1BFTl9SUEMubWV0aG9kc1tpXTtcblxuICAgICAgICAgICAgaWYgKG1ldGhvZE9iaikge1xuICAgICAgICAgICAgICBvdmVycmlkZVBhcmFtc0Zyb21UZXN0RGF0YShtZXRob2RPYmopO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKElHTk9SRV9NT0RVTEVTLmluZGV4T2YobW9kdWxlKSA9PT0gLTEpIHtcbiAgICAgICAgICAgICAgY29uc3QgbW9kdWxlQ2FwID0gbW9kdWxlLmNoYXJBdCgwKS50b1VwcGVyQ2FzZSgpICsgbW9kdWxlLnNsaWNlKDEpO1xuICAgICAgICAgICAgICBjb25zdCBmaW5kID0gbWVudXMuZmlsdGVyKChtKSA9PiBtLnRpdGxlID09PSBtb2R1bGVDYXApO1xuICAgICAgICAgICAgICBsZXQgbW9kdWxlTWVudUl0ZW0gPSBmaW5kLmxlbmd0aCA9PT0gMCA/IG51bGwgOiBmaW5kWzBdO1xuICAgICAgICAgICAgICBpZiAobW9kdWxlTWVudUl0ZW0gPT0gbnVsbCkge1xuICAgICAgICAgICAgICAgIG1vZHVsZU1lbnVJdGVtID0ge1xuICAgICAgICAgICAgICAgICAgdGl0bGU6IG1vZHVsZUNhcCxcbiAgICAgICAgICAgICAgICAgIG1lbnVzOiBbXSxcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgICAgIG1lbnVzLnB1c2gobW9kdWxlTWVudUl0ZW0pO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGlmIChPUEVOX1JQQy5tZXRob2RzW2ldLmV4YW1wbGVzICYmIE9QRU5fUlBDLm1ldGhvZHNbaV0uZXhhbXBsZXMubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5hZGRQcm9wZXJ0eUV4YW1wbGVzKG1ldGhvZE9iaiwgT1BFTl9SUEMpO1xuICAgICAgICAgICAgICAgIHRoaXMuYWRkUG9seW1vcnBoaWNQdWxsRXhhbXBsZXMobWV0aG9kT2JqKTtcbiAgICAgICAgICAgICAgICBpZiAoT1BFTl9SUEMubWV0aG9kc1tpXS5leGFtcGxlcy5sZW5ndGggPiAxKSB7XG4gICAgICAgICAgICAgICAgICBjb25zdCBtZXRob2RNZW51SXRlbSA9IHtcbiAgICAgICAgICAgICAgICAgICAgdGl0bGU6IG1ldGhvZCxcbiAgICAgICAgICAgICAgICAgICAgbWVudXM6IFtdLFxuICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICAgIG1vZHVsZU1lbnVJdGVtLm1lbnVzLnB1c2gobWV0aG9kTWVudUl0ZW0pO1xuICAgICAgICAgICAgICAgICAgZm9yIChsZXQgZXhJZHggPSAwOyBleElkeCA8IE9QRU5fUlBDLm1ldGhvZHNbaV0uZXhhbXBsZXMubGVuZ3RoOyBleElkeCsrKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnN0IG5hbWUgPSAnIC0gJyArIE9QRU5fUlBDLm1ldGhvZHNbaV0uZXhhbXBsZXNbZXhJZHhdLm5hbWU7XG4gICAgICAgICAgICAgICAgICAgIG1ldGhvZE1lbnVJdGVtLm1lbnVzLnB1c2goe1xuICAgICAgICAgICAgICAgICAgICAgIHRpdGxlOiBtZXRob2QgKyBuYW1lLFxuICAgICAgICAgICAgICAgICAgICAgIHZpZXc6IENhcmQsXG4gICAgICAgICAgICAgICAgICAgICAgcGFyYW1zOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICBzZGs6IHNkayxcbiAgICAgICAgICAgICAgICAgICAgICAgIG1ldGhvZDogT1BFTl9SUEMubWV0aG9kc1tpXSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGV4YW1wbGVJbmRleDogZXhJZHgsXG4gICAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIG1vZHVsZU1lbnVJdGVtLm1lbnVzLnB1c2goe1xuICAgICAgICAgICAgICAgICAgICB0aXRsZTogbWV0aG9kLFxuICAgICAgICAgICAgICAgICAgICB2aWV3OiBDYXJkLFxuICAgICAgICAgICAgICAgICAgICBwYXJhbXM6IHtcbiAgICAgICAgICAgICAgICAgICAgICBzZGs6IHNkayxcbiAgICAgICAgICAgICAgICAgICAgICBtZXRob2Q6IE9QRU5fUlBDLm1ldGhvZHNbaV0sXG4gICAgICAgICAgICAgICAgICAgICAgZXhhbXBsZUluZGV4OiAwLFxuICAgICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICA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d1JlY3QoMTUwLCA0MCwgNCwgMSwgNCksXG4gICAgICAgIEJ1dHRvbnM6IHtcbiAgICAgICAgICB4OiAxMDAsXG4gICAgICAgICAgeTogMTUwLFxuICAgICAgICAgIExlZnRCdXR0b246IHtcbiAgICAgICAgICAgIHR5cGU6IEJ1dHRvblNtYWxsLFxuICAgICAgICAgICAgdGl0bGU6IENPTlNUQU5UUy5ZRVMsXG4gICAgICAgICAgICBiYWNrZ3JvdW5kVHlwZTogJ3N0cm9rZScsXG4gICAgICAgICAgICBidXR0b25UZXh0OiAnTGVmdCcsXG4gICAgICAgICAgICBvbkVudGVyOiBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgIHRoaXMuZmlyZUFuY2VzdG9ycygnJGludm9rZU1ldGhvZCcsIHRydWUpO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIFJpZ2h0QnV0dG9uOiB7XG4gICAgICAgICAgICB4OiAyNTAsXG4gICAgICAgICAgICB0eXBlOiBCdXR0b25TbWFsbCxcbiAgICAgICAgICAgIHRpdGxlOiBDT05TVEFOVFMuTk8sXG4gICAgICAgICAgICBiYWNrZ3JvdW5kVHlwZTogJ3N0cm9rZScsXG4gICAgICAgICAgICBidXR0b25UZXh0OiAnUmlnaHQnLFxuICAgICAgICAgICAgb25FbnRlcjogZnVuY3Rpb24gKCkge1xuICAgICAgICAgICAgICB0aGlzLmZpcmVBbmNlc3RvcnMoJyRpbnZva2VNZXRob2QnLCBmYWxzZSk7XG4gICAgICAgICAgICB9LFxuICAgICAgICAgIH0sXG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgIH07XG4gIH1cblxuICBfaW5pdCgpIHtcbiAgICB0aGlzLmJ1dHRvbkluZGV4ID0gMDtcbiAgfVxuXG4gIF9oYW5kbGVMZWZ0KCkge1xuICAgIHRoaXMuYnV0dG9uSW5kZXggPSAwO1xuICB9XG4gIF9oYW5kbGVSaWdodCgpIHtcbiAgICB0aGlzLmJ1dHR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XNzYWdlID0gSlNPTi5wYXJzZShkYXRhKTtcbiAgICAgICAgICBpZiAobWVzc2FnZS5oZWFkZXJzKSB7XG4gICAgICAgICAgICBoZWFkZXJzID0gbWVzc2FnZS5oZWFkZXJzO1xuICAgICAgICAgIH1cbiAgICAgICAgICBtZXNzYWdlID0gSlNPTi5wYXJzZShtZXNzYWdlLnBheWxvYWQpO1xuICAgICAgICAgIG1lc3NhZ2UgPSBKU09OLnBhcnNlKG1lc3NhZ2UuZGF0YS5xdWVyeSk7XG4gICAgICAgIH0gY2F0Y2ggKGVycikge1xuICAgICAgICAgIGxvZ2dlci5lcnJvcignUHVic3ViIG5vdGlmaWNhdGlvbiBwYXJzZSBmYWlsZWQnICsgZXJyLCAnc3RhcnRXZWJTb2NrZXQnKTtcbiAgICAgICAgfVxuXG4gICAgICAgIGNvbnN0IGludGVudFJlYWRlciA9IG5ldyBJbnRlbnRSZWFkZXIoKTtcblxuICAgICAgICB0cnkge1xuICAgICAgICAgIGlmIChtZXNzYWdlLnRhc2spIHtcbiAgICAgICAgICAgIGNvbnN0IHJlc3BvbnNlVG9waWMgPSB0aGlzLmdldFJlc3BvbnNlVG9waWMobWVzc2FnZSk7XG4gICAgICAgICAgICBpbnRlbnRSZWFkZXIucHJvY2Vzc0ludGVudChtZXNzYWdlKS50aGVuKChyZXNwb25zZVN0cmluZykgPT4ge1xuICAgICAgICAgICAgICBpZiAocmVzcG9uc2VTdHJpbmcpIHtcbiAgICAgICAgICAgICAgICBjbGllbnQucHVibGlzaChyZXNwb25zZVRvcGljLCByZXNwb25zZVN0cmluZywgaGVhZGVycyk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb25zdCByZXNwb25zZVRvcGljID0gdGhpcy5nZXRSZXNwb25zZVRvcGljKG1lc3NhZ2UpO1xuICAgICAgICAgICAgY29uc3QgcmVzcG9uc2VTdHJpbmcgPSB7IGNvZGU6IC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gICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5tZXRob2RGaWx0ZXJzLmlzU2V0TWV0aG9kKG1ldGhvZC5leGFtcGxlc1tleGFtcGxlSW5kZXhdKSkge1xuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgaWYgKHRoaXMubWV0aG9kRmlsdGVycy5zaG91bGRFeGNsdWRlRXhhbXBsZShtZXRob2QuZXhhbXBsZXNbZXhhbXBsZUluZGV4XSkpIHtcbiAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgbWV0aG9kV2l0aEV4YW1wbGVOYW1lID0gbWV0aG9kT2JqLm5hbWUgKyAnLicgKyBtZXRob2RPYmouZXhhbXBsZXNbZXhhbXBsZUluZGV4XS5uYW1lO1xuICAgICAgICAgICAgICAgIG1ldGhvZFV1aWQgPSB0aGlzLmNyZWF0ZVVVSUQoKTtcbiAgICAgICAgICAgICAgICBleGFtcGxlID0gbWV0aG9kLmV4YW1wbGVzW2V4YW1wbGVJbmRleF07XG4gICAgICAgICAgICAgICAgcGFyYW1WYWx1ZXMgPSBleGFtcGxlLnBhcmFtcy5tYXAoKHApID0+IHAudmFsdWUpO1xuXG4gICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IG51bGw7XG4gICAgICAgICAgICAgICAgaWYgKG1ldGhvZC5leGFtcGxlc1tleGFtcGxlSW5kZXhdLnNjaGVtYSkge1xuICAgICAgICAgICAgICAgICAgc2NoZW1hTWFwID0gbWV0aG9kLmV4YW1wbGVzW2V4YW1wbGVJbmRleF07XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIHNjaGVtYU1hcCA9IG1ldGhvZC5yZXN1bHQ7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAg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hbWU6IG1ldGhvZFdpdGhFeGFtcGxlTmFtZSxcbiAgICAgICAgICAgICAgICAgIG1ldGhvZFV1aWQ6IG1ldGhvZFV1aWQsXG4gICAgICAgICAgICAgICAgICBzY2hlbWFEYXRhOiBzY2hlbWFNYXAuc2NoZW1hLFxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgc2NoZW1hVmFsaWRhdGlvblJlc3VsdFNldC5wdXNoKHNjaGVtYVZhbGlkYXRpb25SZXN1bHRGb3JFYWNoRXhhbXBsZVNldCk7XG4gICAgICAgICAgICAgIH0gY2F0Y2ggKGVycm9yKSB7XG4gICAgICAgICAgICAgICAgbGV0IG9iajtcbiAgICAgICAgICAgICAgICBpZiAoc2NoZW1hTWFwID09IHVuZGVmaW5lZCAmJiBlcnJvciA9PSBDT05TVEFOVFMuVU5ERUZJTkVEX1JFU1BPTlNFX01FU1NBR0UpIHtcbiAgICAgICAgICAgICAgICAgIGxvZ2dlci5kZWJ1ZygnVGVzdENvbnRleHQgRGVidWc6IEVycm9yIGJsb2NrIG9uIGFwaSBleGVjdXRpb24gLSBBY2NlcHRhYmxlIE5vIHJlc3VsdDogJyArIGVycm9yICsgJyBmb3IgbWV0aG9kOiAnICsgbWV0aG9kV2l0aEV4YW1wbGVOYW1lLCAnbm9ydGhCb3VuZFNjaGVtYVZhbGlkYXRpb25BbmRSZXBvcnRHZW5lcmF0aW9uJyk7XG4gICAgICAgICAgICAgICAgICBlcnJvclNjaGVtYVJlc3VsdCA9IGZhbHNlO1xuICAgICAgICAgICAgICAgICAgb2JqID0ge1xuICAgICAgICAgICAgICAgICAgICByZXNwb25zZTogJ05vIHJlc3VsdCBvYmplY3QgLSBBY2NlcHRhYmxlJyxcbiAgICAgICAgICAgICAgICAgICAgcGFyYW06IGV4YW1wbGUucGFyYW1zLFxuICAgICAgICAgICAgICAgICAgICBlcnJvclNjaGVtYVJlc3VsdDogZXJyb3JTY2hlbWFSZXN1bHQsXG4gICAgICAgICAgICAgICAgICAgIG1ldGhvZFdpdGhFeGFtcGxlTmFtZTogbWV0aG9kV2l0aEV4YW1wbGVOYW1lLFxuICAgICAgICAgICAgICAgICAgICB2YWxpZGF0aW9uUmVzdWx0OiB7fSxcbiAgICAgICAgICAgICAgICAgICAgbWV0aG9kVXVpZDogbWV0aG9kVXVpZCxcbiAgICAgICAgICAgICAgICAgICAgc2NoZW1hRGF0YTogc2NoZW1hTWFwLnNjaGVtYSxcbiAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChlcnJvci5yZXNwb25zZUVycm9yKSB7XG4gICAgICAgICAgICAgICAgICBsb2dnZXIuZGVidWcoJ1Rlc3RDb250ZXh0IERlYnVnOiBFcnJvciBibG9jayBvbiBhcGkgZXhlY3V0aW9uIC0gaGFzIHJlc3BvbnNlRXJyb3I6ICcgKyBlcnJvciArICcgZm9yIG1ldGhvZDogJyArIG1ldGhvZFdpdGhFeGFtcGxlTmFtZSwgJ25vcnRoQm91bmRTY2hlbWFWYWxpZGF0aW9uQW5kUmVwb3J0R2VuZXJhdGlvbicpO1xuICAgICAgICAgICAgICAgICAgY29uc3QgZXJyID0gZXJyb3IucmVzcG9uc2VFcnJvcjtcbiAgICAgICAgICAgICAgICAgIGVycm9yU2NoZW1hUmVzdWx0ID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgIG9iaiA9IHtcbiAgICAgICAgICAgICAgICAgICAgZXJyb3I6IGVycixcbiAgICAgICAgICAgICAgICAgICAgcGFyYW06IGV4YW1wbGUucGFyYW1zLFxuICAgICAgICAgICAgICAgICAgICBlcnJvclNjaGVtYVJlc3VsdDogZXJyb3JTY2hlbWFSZXN1bHQsXG4gICAgICAgICAgICAgICAgICAgIG1ldGhvZFdpdGhFeGFtcGxlTmFtZTogbWV0aG9kV2l0aEV4YW1wbGVOYW1lLFxuICAgICAgICAgICAgICAgICAgICBtZXRob2RVdWlkOiBtZXRob2RVdWlkLFxuICAgICAgICAgICAgICAgICAgICBzY2hlbWFEYXRhOiBzY2hlbWFNYXAuc2NoZW1hLFxuICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgbG9nZ2VyLmRlYnVnKCdUZXN0Q29udGV4dCBEZWJ1ZzogRXJyb3IgYmxvY2sgb24gYXBpIGV4ZWN1dGlvbiAtIGhhcyBlcnJvciBtZXNzYWdlOiAnICsgZXJyb3IgKyAnIGZvciBtZXRob2Q6ICcgKyBtZXRob2RXaXRoRXhhbXBsZU5hbWUsICdub3J0aEJvdW5kU2NoZW1hVmFsaWRhdGlvbkFuZFJlcG9ydEdlbmVyYXRpb24nKTtcbiAgICAgICAgICAgICAgICAgIGlmICh0aGlzLm1ldGhvZEZpbHRlcnMuaXNFeGNlcHRpb25NZXRob2QobWV0aG9kT2JqLm5hbWUsIGV4YW1wbGUucGFyYW1zKSkge1xuICAgICAgICAgICAgICAgICAgICBvYmogPSB0aGlzLmVycm9yQ2hlY2tGb3JFeGVtcHRlZE1ldGhvZHMoZXJyb3IsIG1ldGhvZE9iaiwgbWV0aG9kV2l0aEV4YW1wbGVOYW1lLCBleGFtcGxlLCBzY2hlbWFNYXApO1xuICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgbGV0IGVyciA9IGVycm9yO1xuICAgICAgICAgICAgICAgICAgICBpZiAodHlwZW9mIGVycm9yID09ICdzdHJpbmcnKSB7XG4gICAgICAgICAgICAgICAgICAgICAgZXJyID0geyBjb2RlOiAnQ2VydEVycm9yJywgbWVzc2FnZTogZXJyb3IgfTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBlcnJvclNjaGVtYVJlc3VsdCA9IGZhbHNlO1xuICAgICAgICAgICAgICAgICAgICBvYmogPSB7XG4gICAgICAgICAgICAgICAgICAgICAgZXJyb3I6IGVycixcbiAgICAgICAgICAgICAgICAgICAgICBwYXJhbTogZXhhbXBsZS5wYXJhbXMsXG4gICAgICAgICAgICAgICAgICAgICAgZXJyb3JTY2hlbWFSZXN1bHQ6IGVycm9yU2NoZW1hUmVzdWx0LFxuICAgICAgICAgICAgICAgICAgICAgIG1ldGhvZFdpdGhFeGFtcGxlTmFtZTogbWV0aG9kV2l0aEV4YW1wbGVOYW1lLFxuICAgICAgICAgICAgICAgICAgICAgIG1ldGhvZFV1aWQ6IG1ldGhvZFV1aWQsXG4gICAgICAgICAgICAgICAgICAgICAgc2NoZW1hRGF0YTogc2NoZW1hTWFwLnNjaGVtYSxcbiAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgc2NoZW1hVmFsaWRhdGlvblJlc3VsdFNldC5wdXNoKG9iaik7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgLy8gQWRkaW5nIG9uIG1vcmUgZWxlbWVudCB0byBlcnIgT2JqZWN0IHRvIGRpc3BsYXkgbWV0aG9kIG5hbWUgb24gdGhlIHNjcmVlbiBmb3IgbXVsdGlwbGUgdGVzdGNhc2VzXG4gICAgICAgICAgICBsb2dnZXIuZGVidWcoJ1Rlc3RDb250ZXh0IERlYnVnOiBjb3VsZCBub3QgZmluZCBleGFtcGxlIGZvciBtZXRob2Q6ICcgKyBtZXRob2RXaXRoRXhhbXBsZU5hbWUsICdub3J0aEJvdW5kU2NoZW1hVmFsaWRhdGlvbkFuZFJlcG9ydEdlbmVyYXRpb24nKTtcbiAgICAgICAgICAgIGNvbnN0IGVyciA9IHtcbiAgICAgICAgICAgICAgY29kZTogJ0NlcnRFcnJvcicsXG4gICAgICAgICAgICAgIG1lc3NhZ2U6ICdDb3VsZCBub3QgZmluZCBhbiBleGFtcGxlIGZvciAnICsgbWV0aG9kLm5hbWUsXG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgY29uc3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gICAgICAgZXJyID0gQ09OU1RBTlRTLkVSUk9SX01FU1NBR0VfV1JPTkdfTUVUSE9EX05BTUU7XG4gICAgICB9XG4gICAgfSBjYXRjaCAoZXJyb3IpIHtcbiAgICAgIGNvbnNvbGUubG9nKCdFcnJvcjogJywgZXJyb3IpO1xuICAgICAgZXJyID0gZXJyb3I7XG4gICAgfVxuICAgIHJldHVybiB7XG4gICAgICByZXNwb25zZTogcmVzcG9uc2UgPT09IHVuZGVmaW5lZCA/ICd1bmRlZmluZWQnIDogcmVzcG9uc2UsXG4gICAgICBlcnJvcjogZXJyID09PSB1bmRlZmluZWQgPyBudWxsIDogZXJyLFxuICAgIH07XG4gIH1cblxuICBjcmVhdGVSZXN1bHRPYmplY3QocmVzdWx0LCBlcnJvcikge1xuICAgIGxldCByZXN1bHRPYmplY3Q7XG4gICAgaWYgKHByb2Nlc3MuZW52LlNUQU5EQUxPTkUgPT0gdHJ1ZSkge1xuICAgICAgcmVzdWx0T2JqZWN0ID0ge1xuICAgICAgICByZXN1bHQ6IHJlc3VsdCxcbiAgICAgICAgZXJyb3I6IGVycm9yLFxuICAgICAgICBzY2hlbWFSZXN1bHQ6IHNjaGVtYVJlc3VsdCxcbiAgICAgICAgY29udGVudFJlc3VsdDogY29udGVudFJlc3VsdCxcbiAgICAgIH07XG4gICAgfSBlbHNlIHtcbiAgICAgIGlmIChlcnJvciA9PSBudWxsKSB7XG4gICAgICAgIHJlc3VsdE9iamVjdCA9IHtcbiAgICAgICAgICBqc29ucnBjOiAnMi4wJyxcbiAgICAgICAgICByZXN1bHQ6IHJlc3VsdCxcbiAgICAgICAgICBpZDogcHJvY2Vzcy5lbnYuSUQgKyAxLFxuICAgICAgICB9O1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcmVzdWx0T2JqZWN0ID0ge1xuICAgICAgICAgIGpzb25ycGM6ICcyLjAnLFxuICAgICAgICAgIGVycm9yOiBlcnJvcixcbiAgICAgICAgICBpZDogcHJvY2Vzcy5lbnYu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gICAgY29udmVydGVkVmFsaWRhdGlvbkVyciA9IHZhbGlkYXRpb25FcnJvcjtcbiAgICAgICAgaWYgKHR5cGVvZiB2YWxpZGF0aW9uRXJyb3IgPT0gJ3N0cmluZycgfHwgQXJyYXkuaXNBcnJheSh2YWxpZGF0aW9uRXJyb3IpIHx8IHR5cGVvZiByZXN1bHQucmVzcG9uc2UgPT0gJ3VuZGVmaW5lZCcpIHtcbiAgICAgICAgICBjb252ZXJ0ZWRWYWxpZGF0aW9uRXJyID0geyBlcnI6IHZhbGlkYXRpb25FcnJvciB9O1xuICAgICAgICB9XG4gICAgICAgIGlmIChyZXNwb25zZSA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgaWYgKGhhc0NvbnRlbnRWYWxpZGF0aW9uRXhlY3V0ZWQpIHtcbiAgICAgICAgICAgIGNvbnZlcnRlZFJlc3BvbnNlID0gSlNPTi5zdHJpbmdpZnkoXG4gICAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgICBTY2hlbWE6IENPTlNUQU5UUy5GQUlMRUQsXG4gICAgICAgICAgICAgICAgQ29udGVudDogQ09OU1RBTlRTLlNDSEVNQV9DT05URU5UX1NLSVBQRUQsXG4gICAgICAgICAgICAgICAgTWVzc2FnZToge1xuICAgICAgICAgICAgICAgICAgQWN0dWFsOiAndW5kZWZpbmVkJyxcbiAgICAgICAgICAgICAgICAgIEV4cGVjdGVkOiBzY2hlbWFNYXAsXG4gICAgICAgICAgICAgICAgICBNZXNzYWdlOiBDT05TVEFOVFMuVU5ERUZJTkVEX1JFU1BPTlNFX01FU1NBR0UsXG4gICAgICAgICAgICAgICAgICBwYXJhbXM6IHBhcmFtcyxcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICBudWxsLFxuICAgICAgICAgICAgICAxXG4gICAgICAgICAgICApO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb252ZXJ0ZWRSZXNwb25zZSA9IEpTT04uc3RyaW5naWZ5KFxuICAgICAgICAgICAgICB7XG4gICAgICAgICAgICAgICAgU2NoZW1hOiBDT05TVEFOVFMuRkFJTEVELFxuICAgICAgICAgICAgICAgIENvbnRlbnQ6IENPTlNUQU5UUy5QRU5ESU5HLFxuICAgICAgICAgICAgICAgIE1lc3NhZ2U6IHtcbiAgICAgICAgICAgICAgICAgIEFjdHVhbDogJ3VuZGVmaW5lZCcsXG4gICAgICAgICAgICAgICAgICBFeHBlY3RlZDogc2NoZW1hTWFwLFxuICAgICAgICAgICAgICAgICAgTWVzc2FnZTogQ09OU1RBTlRTLlVOREVGSU5FRF9SRVNQT05TRV9NRVNTQUdFLFxuICAgICAgICAgICAgICAgICAgcGFyYW1zOiBwYXJhbXMsXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgbnVsbCxcbiAgICAgICAgICAgICAgMVxuICAgICAgICAgICAgKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgcmVzcG9uc2UgPSB1dGlscy5jZW5zb3JEYXRhKG1ldGhvZE9iai5uYW1lLCByZXNwb25zZSk7XG4gICAgICAgICAgaWYgKGhhc0NvbnRlbnRWYWxpZGF0aW9uRXhlY3V0ZWQpIHtcbiAgICAgICAgICAgIC8vIEFjdHVhbCBhbmQgRXhwZWN0ZWQgU2NoZW1hL0NvbnRlbnRcbiAgICAgICAgICAgIGlmIChzY2hlbWFWYWxpZGF0aW9uUmVzdWx0LmVycm9yc1swXS5tZXNzYWdlID09PSAnQ29udGVudCBpcyBub3QgdmFsaWQnKSB7XG4gICAgICAgICAgICAgIGNvbnZlcnRlZFJlc3BvbnNlID0gSlNPTi5zdHJpbmdpZnkoXG4gICAgICAgICAgICAgICAge1xuICAgICAgICAgICAgICAgICAgU2NoZW1hOiBDT05TVEFOVFMuUEFTU0VELFxuICAgICAgICAgICAgICAgICAgQ29udGVudDogQ09OU1RBTlRTLkZBSUxFRCxcbiAgICAgICAgICAgICAgICAgIE1lc3NhZ2U6IHtcbiAgICAgICAgICAgICAgICAgICAgQWN0dWFsOiAnTkEnLFxuICAgICAgICAgICAgICAgICAgICBFeHBlY3RlZDogJ05BJyxcbiAgICAgICAgICAgICAgICAgICAgRXJyb3I6IHNjaGVtYVZhbGlkYXRpb25SZXN1bHQuZXJyb3JzWzBdLm1lc3NhZ2UsXG4gICAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgICAgcGFyYW1zOiBwYXJhbXMsXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICBudWxsLFxuICAgICAgICAgICAgICAgIDFcbiAgICAgICAgICAgICAgKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIGNvbnZlcnRlZFJlc3BvbnNlID0gSlNPTi5zdHJpbmdpZnkoXG4gICAgICAgICAgICAgICAge1xuICAgICAgICAgICAgICAgICAgU2NoZW1hOiBDT05TVEFOVFMuRkFJTEVELFxuICAgICAgICAgICAgICAgICAgQ29udGVudDogQ09OU1RBTlRTLlNDSEVNQV9DT05URU5UX1NLSVBQRUQsXG4gICAgICAgICAgICAgICAgICBNZXNzYWdlOiB7IEFjdHVhbDogcmVzcG9uc2UsIEV4cGVjdGVkOiBzY2hlbWFNYXAsIEVycm9yOiBjb252ZXJ0ZWRWYWxpZGF0aW9uRXJyIH0sXG4gICAgICAgICAgICAgICAgICBwYXJhbXM6IHBhcmFtcyxcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIG51bGwsXG4gICAgICAgICAgICAgICAgMVxuICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb252ZXJ0ZWRSZXNwb25zZSA9IEpTT04uc3RyaW5naWZ5KFxuICAgICAgICAgICAgICB7XG4gICAgICAgICAgICAgICAgU2NoZW1hOiBDT05TVEFOVFMuRkFJTEVELFxuICAgICAgICAg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W9uRXJyb3IgfTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoaGFzQ29udGVudFZhbGlkYXRpb25FeGVjdXRlZCAmJiAhY29udGVudFBlbmRpbmcpIHtcbiAgICAgICAgICBpZiAocHJvY2Vzcy5lbnYuVEVTVENPTlRFWFQpIHtcbiAgICAgICAgICAgIGNvbnZlcnRlZFJlc3BvbnNlID0gSlNPTi5zdHJpbmdpZnkoXG4gICAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgICBTY2hlbWE6IENPTlNUQU5UUy5QQVNTRUQsXG4gICAgICAgICAgICAgICAgQ29udGVudDogQ09OU1RBTlRTLlBBU1NFRCxcbiAgICAgICAgICAgICAgICBNZXNzYWdlOiByZXNwb25zZSxcbiAgICAgICAgICAgICAgICBwYXJhbXM6IHBhcmFtcyxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgbnVsbCxcbiAgICAgICAgICAgICAgMVxuICAgICAgICAgICAgKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29udmVydGVkUmVzcG9uc2UgPSBKU09OLnN0cmluZ2lmeSh7IFNjaGVtYTogQ09OU1RBTlRTLlBBU1NFRCwgQ29udGVudDogQ09OU1RBTlRTLlBBU1NFRCwgcGFyYW1zOiBwYXJhbXMgfSwgbnVsbCwgMSk7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGlmIChwcm9jZXNzLmVudi5URVNUQ09OVEVYVCkge1xuICAgICAgICAgICAgY29udmVydGVkUmVzcG9uc2UgPSBKU09OLnN0cmluZ2lmeShcbiAgICAgICAgICAgICAge1xuICAgICAgICAgICAgICAgIFNjaGVtYTogQ09OU1RBTlRTLlBBU1NFRCxcbiAgICAgICAgICAgICAgICBDb250ZW50OiBDT05TVEFOVFMuUEVORElORyxcbiAgICAgICAgICAgICAgICBNZXNzYWdlOiByZXNwb25zZSxcbiAgICAgICAgICAgICAgICBwYXJhbXM6IHBhcmFtcyxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgbnVsbCxcbiAgICAgICAgICAgICAgMVxuICAgICAgICAgICAgKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29udmVydGVkUmVzcG9uc2UgPSBKU09OLnN0cmluZ2lmeSh7IFNjaGVtYTogQ09OU1RBTlRTLlBBU1NFRCwgQ29udGVudDogQ09OU1RBTlRTLlBFTkRJTkcsIHBhcmFtczogcGFyYW1zIH0sIG51bGwsIDEpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBpZiAocmVzcG9uc2UgPT0gJ05vIHJlc3VsdCBvYmplY3QgLSBBY2NlcHRhYmxlJykge1xuICAgICAgICAgIGlmIChwcm9jZXNzLmVudi5URVNUQ09OVEVYVCkge1xuICAgICAgICAgICAgY29udmVydGVkUmVzcG9uc2UgPSBKU09OLnN0cmluZ2lmeShcbiAgICAgICAgICAgICAge1xuICAgICAgICAgICAgICAgIFNjaGVtYTogQ09OU1RBTlRTLlNDSEVNQV9DT05URU5UX1NLSVBQRUQsXG4gICAgICAgICAgICAgICAgQ29udGVudDogQ09OU1RBTlRTLlNDSEVNQV9DT05URU5UX1NLSVBQRUQsXG4gICAgICAgICAgICAgICAgTWVzc2FnZTogcmVzcG9uc2UsXG4gICAgICAgICAgICAgICAgcGFyYW1zOiBwYXJhbXMsXG4gICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgIG51bGwsXG4gICAgICAgICAgICAgIDFcbiAgICAgICAgICAgICk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGNvbnZlcnRlZFJlc3BvbnNlID0gSlNPTi5zdHJpbmdpZnkoXG4gICAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgICBTY2hlbWE6IENPTlNUQU5UUy5TQ0hFTUFfQ09OVEVOVF9TS0lQUEVELFxuICAgICAgICAgICAgICAgIENvbnRlbnQ6IENPTlNUQU5UUy5TQ0hFTUFfQ09OVEVO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biAgc3RhdGljIF90ZW1wbGF0ZSgpIHtcbiAgICByZXR1cm4ge1xuICAgICAgeDogMCxcbiAgICAgIHk6IDAsXG4gICAgICB3OiAodykgPT4gdyxcbiAgICAgIGg6IChoKSA9PiBoLFxuICAgICAgSGlzdG9yeToge1xuICAgICAgICB3OiAodykgPT4gdyxcbiAgICAgICAgaDogKGgpID0+IGgsXG4gICAgICAgIHR5cGU6IENvbHVtbixcbiAgICAgIH0sXG4gICAgICBDb25zb2xlVmlldzoge1xuICAgICAgICB4OiA1MjAsXG4gICAgICAgIHk6IDAsXG4gICAgICAgIGg6IDk5MCxcbiAgICAgICAgdzogMTkyMCAtIDYwMCxcbiAgICAgICAgcmVjdDogdHJ1ZSxcbiAgICAgICAgejogMTAwMCxcbiAgICAgIH0sXG4gICAgICBOb3RpZmljYXRpb246IHtcbiAgICAgICAgdmlzaWJsZTogZmFsc2UsXG4gICAgICAgIHJlY3Q6IHRydWUsXG4gICAgICAgIGNvbG9yOiAweGZmMDAwMDAwLCAvLyBCbGFjayBjb2xvclxuICAgICAgICBvcGFjaXR5OiAwLjgsIC8vIE9wYWNpdHkgdmFsdWUgKDAuMCB0byAxLjApXG4gICAgICAgIHc6IDUwMCxcbiAgICAgICAgaDogMjAwLFxuICAgICAgICB4OiAxMzMwLFxuICAgICAgICB5OiA3NzUsXG4gICAgICAgIEVycm9yOiB7XG4gICAgICAgICAgeDogMjAsXG4gICAgICAgICAgeTogMTUsXG4gICAgICAgICAgdGV4dDoge1xuICAgICAgICAgICAgdGV4dDogQ09OU1RBTlRTLlBMQVRGT1JNX0VSUk9SX01FU1NBR0UsXG4gICAgICAgICAgICBmb250U2l6ZTogMjYsXG4gICAgICAgICAgICB0ZXh0Q29sb3I6IDB4ZmZmZjAwMDAsIC8vIFJlZCBjb2xvclxuICAgICAgICAgICAgd29yZFdyYXA6IGZhbHNlLFxuICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogMjgwLFxuICAgICAgICAgICAgdGV4dEFsaWduOiAnbGVmdCcsXG4gICAgICAgICAgfSxcbiAgICAgICAgfSxcbiAgICAgICAgUGxhdGZvcm06IHtcbiAgICAgICAgICB4OiAyMCxcbiAgICAgICAgICB5OiA2MCxcbiAgICAgICAgICB0ZXh0OiB7XG4gICAgICAgICAgICB0ZXh0OiBwcm9jZXNzLmVudi5QTEFURk9STSxcbiAgICAgICAgICAgIGZvbnRTaXplOiAxOCxcbiAgICAgICAgICAgIHRleHRDb2xvcjogMHhmZmZmZmZmZiwgLy8gd2hpdGUgY29sb3JcbiAgICAgICAgICAgIHdvcmRXcmFwOiBmYWxzZSxcbiAgICAgICAgICAgIHdvcmRXcmFwV2lkdGg6IDI4MCxcbiAgICAgICAgICAgIHRleHRBbGlnbjogJ2xlZnQnLFxuICAgICAgICAgIH0sXG4gICAgICAgIH0sXG4gICAgICAgIFRhcmdldDoge1xuICAgICAgICAgIHg6IDE1LFxuICAgICAgICAgIHk6IDExMCxcbiAgICAgICAgICB0ZXh0OiB7XG4gICAgICAgICAgICB0ZXh0OiBDT05TVEFOVFMuUExBVEZPUk1fVEFSR0VULFxuICAgICAgICAgICAgZm9udFNpemU6IDE4LFxuICAgICAgICAgICAgdGV4dENvbG9yOiAweGZmZmZmZmZmLCAvLyB3aGl0ZSBjb2xvclxuICAgICAgICAgICAgd29yZFdyYXA6IGZhbHNlLFxuICAgICAgICAgICAgd29yZFdyYXBXaWR0aDogMjgwLFxuICAgICAgICAgICAgdGV4dEFsaWduOiAnbGVmdCcsXG4gICAgICAgICAgfSxcbiAgICAgICAgfSxcbiAgICAgIH0sXG4gICAgICBVcGRhdGVUZXh0OiB7XG4gICAgICAgIHg6IDgyNSxcbiAgICAgICAgeTogMjUsXG4gICAgICAgIHc6IDE5MjAgLSA3MDAsXG4gICAgICAgIHRleHQ6IHtcbiAgICAgICAgICBmb250U2l6ZTogMzAsXG4gICAgICAgIH0sXG4gICAgICAgIGNvbG9yOiAweGZmZmYwMDBmLFxuICAgICAgfSxcbiAgICAgIEFwaXRpdGxlVGV4dDoge1xuICAgICAgICB4OiA1MzAsXG4gICAgICAgIHk6IDEwMCxcbiAgICAgICAgdzogMTkyMCAtIDcwMCxcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIGZvbnRTaXplOiAyNyxcbiAgICAgICAgfSxcbiAgICAgICAgY29sb3I6IDB4ZmYxMjM0NTYsXG4gICAgICB9LFxuICAgICAgU2NoZW1hVmFsaWRhdGlvblN0YXRlVGV4dDoge1xuICAgICAgICB4OiA1MzAsXG4gICAgICAgIHk6IDE1MCxcbiAgICAgICAgdzogMTkyMCAtIDcwMCxcbiAgICAgICAgdGV4dDoge1xuICAgICAgICAgIGZvbnRTaXplOiAyNyxcbiAgICAgICAgfSxcbiAgICAgICAgY29sb3I6IDB4ZmYxMjM0NTYsXG4gICAgICB9LFxuICAgICAgQ29udGVudFZhbGlkYXRpb25TdGF0ZVRleHQ6IHtcbiAgICAgICAgeDogNTMwLFxuICAgICAgICB5OiAyMDAsXG4gICAgICAgIHc6IDE5MjAgLSA3MDAsXG4gICAgICAgIHRleHQ6IHtcbiAgICAgICAgICBmb250U2l6ZTogMjcsXG4gICAgICAgIH0sXG4gICAgICAgIGNvbG9yOiAweGZmMTIzNDU2LFxuICAgICAgfSxcbiAgICAgIFZhbGlkYXRpb25EYXRhOiB7XG4gICAgICAgIHJlY3Q6IHRydWUsXG4gICAgICAgIHg6IDUzMCxcbiAgICAgICAgeTogMjUwLFxuICAgICAgICB3OiAxOTIwIC0gOTAwLFxuICAgICAgICB0ZXh0OiB7XG4gICAgICAgICAgZm9udFNpemU6IDI3LFxuICAgICAgICB9LFxuICAgICAgICBjb2xvcjogMHhmZjEyMzQ1NixcbiAgICAgIH0sXG4gICAgICBFeGVjdXRlQnV0dG9uOiB7XG4gICAgICAgIHR5cGU6IEJ1dHRvbixcbiAgICAgICAgdGl0bGU6ICdJbnZva2UnLFxuICAgICAgICBiYWNrZ3JvdW5kVHlwZTogJ3N0cm9rZScsXG4gICAgICAgIG9u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XlzJykucGF0Y2goe1xuICAgICAgICBPdmVybGF5OiB7XG4gICAgICAgICAgdHlwZTogQWNrbm93bGVkZ2VQcm9tcHQsXG4gICAgICAgICAgeDogKFdpbmRvdy53aWR0aCAtIDEwMDApIC8gMixcbiAgICAgICAgICB5OiAoV2luZG93LmhlaWdodCAtIDMwMCkgLyA0LFxuICAgICAgICAgIHc6IDEwMDAsXG4gICAgICAgICAgaDogMzAwLFxuICAgICAgICAgIHBhcmFtczoge1xuICAgICAgICAgICAgdGl0bGU6ICdEbyB5b3UgZ2l2ZSBhY2Nlc3MgdG8gJyArIGNoYWxsZW5nZS5yZXF1ZXN0b3IubmFtZSArICcgdG8gJyArIGNoYWxsZW5nZS5jYXBhYmlsaXR5ICsgJz8nLFxuICAgICAgICAgICAgZ3JhbnRDYWxsYmFjazogKCkgPT4ge1xuICAgICAgICAgICAgICByZXNwb25kZXIoe1xuICAgICAgICAgICAgICAgIGdyYW50ZWQ6IHRydWUsXG4gICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZXIpO1xuICAgICAgICAgICAgICByZXNvbHZlKHRydWUpO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGRlbnlDYWxsYmFjazogKCkgPT4ge1xuICAgICAgICAgICAgICByZXNwb25kZXIoe1xuICAgICAgICAgICAgICAgIGdyYW50ZWQ6IGZhbHNlLFxuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHRpbWVyKTtcbiAgICAgICAgICAgICAgcmVzb2x2ZSh0cnVlKTtcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBkZWZlcnJlZENhbGxiYWNrKCkge1xuICAgICAgICAgICAgICByZXNwb25kZXIoe1xuICAgICAgICAgICAgICAgIGdyYW50ZWQ6IG51bGwsXG4gICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZXIpO1xuICAgICAgICAgICAgICBy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TogUm93LFxuICAgICAgICB4OiAodykgPT4gKHcgLSAyNDApIC8gMixcbiAgICAgICAgeTogKGgpID0+IGggLSAxMDAsXG4gICAgICAgIGl0ZW1TcGFjaW5nOiA0MCxcbiAgICAgICAgaXRlbXM6IFtcbiAgICAgICAgICB7XG4gICAgICAgICAgICByZWY6ICdHcmFudEJ1dHRvbicsXG4gICAgICAgICAgICBtaW5XaWR0aDogMTAwLFxuICAgICAgICAgICAgdHlwZTogQnV0dG9uLFxuICAgICAgICAgICAgdGl0bGU6ICdZZXMnLFxuICAgICAgICAgICAgYmFja2dyb3VuZFR5cGU6ICdzdHJva2UnLFxuICAgICAgICAgICAgb25FbnRlclJlbGVhc2U6IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKCckZ3JhbnQnKTtcbiAgICAgICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKCckZGlzbWlzc092ZXJsYXknKTtcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgfSxcbiAgICAgICAgICB7XG4gICAgICAgICAgICByZWY6ICdEZW55QnV0dG9uJyxcbiAgICAgICAgICAgIG1pbldpZHRoOiAxMDAsXG4gICAgICAgICAgICB0eXBlOiBCdXR0b24sXG4gICAgICAgICAgICB0aXRsZTogJ05vJyxcbiAgICAgICAgICAgIGJhY2tncm91bmRUeXBlOiAnc3Ryb2tlJyxcbiAgICAgICAgICAgIG9uRW50ZXJSZWxlYXNlOiBmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgICAgIHRoaXMuZmlyZUFuY2VzdG9ycygnJGRlbnknKTtcbiAgICAgICAgICAgICAgdGhpcy5maXJlQW5jZXN0b3JzKCckZGlzbWlzc092ZXJsYXknKTtcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgfSxcbiAgICAgICAgXSxcbiAgICAgIH0sXG4gICAgfTtcbiAgfVxuXG4gICRncmFudCgpIHtcbiAgICBpZiAodGhpcy5fcGFyYW1zLmdyYW50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AgICAge1xuICAgICAgICAgICAgdzogODI4LFxuICAgICAgICAgICAgeDogMTYsXG4gICAgICAgICAgICB0eXBlOiBJbnB1dCxcbiAgICAgICAgICAgIHBsYWNlaG9sZGVyOiB0aGlzLnRpdGxlIHx8ICcgJyxcbiAgICAgICAgICAgIGNhcHRpb246IHRoaXMuY2FwdGlvbiB8fCAnJyxcbiAgICAgICAgICAgIGxhYmVsOiAnJyxcbiAgICAgICAgICAgIHJlZjogJ0lucHV0JyxcbiAgICAgICAgICB9LFxuICAgICAgICAgIHtcbiAgICAgICAgICAgIHRleHR1cmU6IGxuZy5Ub29scy5nZXRSb3VuZFJlY3QoODYwLCA0MDAsIDE2LCAwLCAwLCB0cnVlLCAweGZmMTQxNDE3KSxcbiAgICAgICAgICAgIEtleWJvYXJkOiB7XG4gICAgICAgICAgICAgIHg6IDE2LFxuICAgICAgICAgICAgICB5OiAyNCxcbiAgICAgICAgICAgICAgdzogODI4LFxuICAgICAgICAgICAgICB0eXBlOiBLZXlib2FyZFF3ZXJ0eSxcbiAgICAgICAgICAgICAgZGVmYXVsdEZvcm1hdDogJ2xvd2VyY2FzZScsXG4gICAgICAgICAgICAgIHJlZjogJ0tleWJvYXJkJyxcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgfSxcbiAgICAgICAgXSxcbiAgICAgICAgc2VsZWN0ZWRJbmRleDogMSxcbiAgICAgIH0sXG4gICAgfTtcbiAgfVxuXG4gICRvblNvZnRLZXkoeyBrZXkgfSkge1xuICAgIHN3aXRjaCAoa2V5KSB7XG4gICAgICBjYXNlICdkZWxldGUnOlxuICAgICAgICB0aGlzLl9JbnB1dC5iYWNrc3BhY2UoKTtcbiAgICAgICAgYnJlYWs7XG4gICAgICBjYXNlICdkb25lJzpcbiAgICAgICAgdGhpcy5kb25lUGVuZGluZyA9IHRydWU7XG4gICAgICAgIGJyZWFrO1xuICAgICAgY2FzZSAnc3BhY2UnOlxuICAgICAgICB0aGlzLl9JbnB1dC5pbnNlcnQoJy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yBQcm9taXNlKGFzeW5jIChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgIGNvbnN0IHRpbWVyID0gc2V0VGltZW91dCgoKSA9PiB7XG4gICAgICAgIHJlc3BvbmRlcih7XG4gICAgICAgICAgZ3JhbnRlZDogbnVsbCxcbiAgICAgICAgICByZWFzb246IFBpbkNoYWxsZW5nZS5SZXN1bHRSZWFzb24uQ0FOQ0VMTEVELFxuICAgICAgICB9KTtcbiAgICAgICAgcmVzb2x2ZSh0cnVlKTtcbiAgICAgIH0sIDE1MDAwKTtcblxuICAgICAgY29uc3Qgc2VsZiA9IHRoaXM7XG4gICAgICBsZXQgcHJvbXB0ID0gbnVsbDtcbiAgICAgIHRoaXMuX2FwcC5vdmVybGF5ZWQgPSB0cnVlO1xuICAgICAgdGhpcy5fYXBwLnRhZygnT3ZlcmxheXMnKS5hbHBoYSA9IDE7XG4gICAgICB0aGlzLl9hcHAudGFnKCdPdmVybGF5cycpLnBhdGNoKHtcbiAgICAgICAgT3ZlcmxheToge1xuICAgICAgICAgIHR5cGU6IFBpblByb21wdCxcbiAgICAgICAgICBwYXJhbXM6IHtcbiAgICAgICAgICAgIGhlYWRlcjogY2hhbGxlbmdlLnJlcXVlc3Rvci5uYW1lICsgJyBpcyByZXF1ZXN0aW5nIHRoYXQgeW91IGVudGVyIHlvdXIgJyArIGNoYWxsZW5nZS5waW5TcGFjZSArICcgcGluLicsXG4gICAgICAgICAgICBkZXRhaWw6ICcgJyxcbiAgICAgICAgICAgIGxpc3RlbmVyOiBuZXcgKGNsYXNzIGV4dGVuZHMgUGluUHJvbXB0LlBpblByb21wdExpc3RlbmVyIHtcbiAgICAgICAgICAgICAgb25QaW5FbnRlcmVkKHBpbikge1xuICAgICAgICAgICAgICAgIGlmIChwaW4gPT09IENPTlNUQU5UUy5QSU5TW2NoYWxsZW5nZS5waW5TcGFjZV0pIHtcbiAgICAgICAgICAgICAgICAgIHJlc3BvbmRlcih7XG4gICAgICAgICAgICAgICAgICAgIGdyYW50ZWQ6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHJlYXNvbjogUGluQ2hhbGxlbmdlLlJlc3VsdFJlYXNvbi5DT1JSRUNUX1BJTixcbiAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHRpbWVyKTtcbiAgICAgICAgICAgICAgICAgIHJlc29sdmUodHJ1ZSk7XG4gICAgICAgICAgICAgICAgICBwcm9tcHQuZmlyZUFuY2VzdG9ycygnJGRpc21pc3NPdmVybGF5Jyk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgIHNlbGYubnVtRmFpbHVyZXMrKztcbiAgICAgICAgICAgICAgICAgIGlmIChzZWxmLm51bUZhaWx1cmVzID49IENPTlNUQU5UUy5NQVhfRkFJTFVSRVMpIHtcbiAgICAgICAgICAgICAgICAgICAgc2VsZi5sb2NrZWRUaW1lID0gRGF0ZS5ub3coKTtcbiAgICAgICAgICAgICAgICAgICAgcmVzcG9uZGVyKHtcbiAgICAgICAgICAgICAgICAgICAgICBncmFudGVkOiBmYWxzZSxcbiAgICAgICAgICAgICAgICAgICAgICByZWFzb246IFBpbkNoYWxsZW5nZS5SZXN1bHRSZWFzb24uRVhDRUVERURfUElOX0ZBSUxVUkVTLFxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHRpbWVyKTtcbiAgICAgICAgICAgICAgICAgICAgcmVzb2x2ZSh0cnVlKTtcbiAgICAgICAgICAgICAgICAgICAgcHJvbXB0LmZpcmVBbmNlc3RvcnMoJyRkaXNtaXNzT3ZlcmxheScpO1xuICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgLy8gc2hvdyBhZ2FpblxuICAgICAgICAgICAgICAgICAgICBwcm9tcHQucGFyYW1zID0ge1xuICAgICAgICAgICAgICAgICAgICAgIGRldGFpbDogJ1RoYXQgd2FzIHdyb25nLCB0cnkgYWdhaW4uJyxcbiAgICAgICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHRpbWVyKTtcbiAgICAgICAgICAgICAgICAgICAgcmVzb2x2ZSh0cnVlKTtcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgb25EaXNtaXNzUmVxdWVzdGVkKCkge1xuICAgICAgICAgICAgICAgIHJlc3BvbmRlcih7XG4gICAgICAgICAgICAgICAgICBncmFudGVkOiBudWxsLFxuICAgICAgICAgICAgICAgICAgcmVhc29uOiBQaW5DaGFsbGVuZ2UuUmVzdWx0UmVhc29uLkNBTkNFTExFRCxcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZXIpO1xuICAgICAgICAgICAgICAgIHJlc29sdmUodHJ1ZSk7XG4gICAgICAgICAgICAgICAgcHJvbXB0LmZpcmVBbmNlc3RvcnMoJyRkaXNtaXNzT3ZlcmxheScpO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIG9uTG9hZGVkKHZpZXcpIHtcbiAgICAgICAgICAgICAgICBwcm9tcHQgPSB2aWV3O1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KSgpLFxuICAgICAgICAgIH0sXG4gICAgICAgIH0sXG4gICAgICB9KTtcbiAgICB9KTtcbiAgICB0aGlzLl9hcHAuX3JlZm9jdXMoKTtcbiAgfVxufVxuIiwiLyoqXG4gKiBDb3B5cmlnaHQgMjAyMyBDb21jYXN0IENhYmxlIENvbW11bmljYXRpb25zIE1hbmFnZW1lbnQsIExMQ1xuICpcbiAqIExpY2Vuc2VkIHVuZGVyIHRoZSBBcGFjaGUgTGljZW5zZSwgVmVyc2lvbiAyLjAgKHRoZSBcIkxpY2Vuc2VcIik7XG4gKiB5b3UgbWF5IG5v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tcbiAgICAgIE92ZXJsYXk6IHtcbiAgICAgICAgdHlwZTogUGluUHJvbXB0LFxuICAgICAgICBwYXJhbXM6IHtcbiAgICAgICAgICBoZWFkZXI6IGNoYWxsZW5nZS5yZXF1ZXN0b3IubmFtZSArICcgaXMgcmVxdWVzdGluZyB0aGF0IHlvdSBlbnRlciB5b3VyICcgKyBjaGFsbGVuZ2UucGluU3BhY2UgKyAnIHBpbi4nLFxuICAgICAgICAgIGRldGFpbDogJyAnLFxuICAgICAgICAgIGxpc3RlbmVyOiBuZXcgKGNsYXNzIGV4dGVuZHMgUGluUHJvbXB0LlBpblByb21wdExpc3RlbmVyIHtcbiAgICAgICAgICAgIG9uUGluRW50ZXJlZChwaW4pIHtcbiAgICAgICAgICAgICAgYWZ0ZXJQaW5FbnRlcmVkKHBpbiwgcmVzcG9uZGVyLCBjaGFsbGVuZ2UpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgb25EaXNtaXNzUmVxdWVzdGVkKCkge1xuICAgICAgICAgICAgICBkaXNtaXNzUGluT3ZlcmxheShyZXNwb25kZXIpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgb25Mb2FkZWQodmlldykge1xuICAgICAgICAgICAgICBwcm9tcHQgPSB2aWV3O1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pKCksXG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgIH0pO1xuICAgIHRoaXMuX2FwcC5fcmVmb2N1cygpO1xuICB9XG5cbiAgYWZ0ZXJQaW5FbnRlcmVkKHBpbiwgcmVzcG9uZGVyLCBjaGFsbGVuZ2UpIHtcbiAgICBuZXcgUHJvbWlzZShhc3luYyAocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICBjb25zdCB0aW1lciA9IHNldFRpbWVvdXQoKCkgPT4ge1xuICAgICAgICByZXNwb25kZXIoe1xuICAgICAgICAgIGdyYW50ZWQ6IG51bGwsXG4gICAgICAgICAgcmVhc29uOiBQaW5DaGFsbGVuZ2UuUmVzdWx0UmVhc29uLkNBTkNFTExFRCxcbiAgICAgICAgfSk7XG4gICAgICAgIHJlc29sdmUodHJ1ZSk7XG4gICAgICB9LCA1MDAwKTtcbiAgICAgIGlmIChwaW4pIHtcbiAgICAgICAgaWYgKHBpbiA9PT0gQ09OU1RBTlRTLlBJTlMucHVyY2hhc2UpIHtcbiAgICAgICAgICAvLyBDaGVjayB3aGV0aGVyIGNoYWxsZW5nZS5waW5zcGFjZSBpcyBmZXRlY2hpbmcgdGhlIHBpbiAnMTExMSdcbiAgICAgICAgICByZXNwb25kZXIoe1xuICAgICAgICAgICAgZ3JhbnRlZDogdHJ1ZSxcbiAgICAgICAgICAgIHJlYXNvbjogUGluQ2hhbGxlbmdlLlJlc3VsdFJlYXNvbi5DT1JSRUNUX1BJTixcbiAgICAgICAgICB9KTtcbiAgICAgICAgICAvLyBwcm9tcHQuZmlyZUFuY2VzdG9ycygnJGRpc21pc3NPdmVybGF5JylcbiAgICAgICAgICB0aGlzLl9hcHAuJGRpc21pc3NPdmVybGF5KCk7XG4gICAgICAgICAgY2xlYXJUaW1lb3V0KHRpbWVyKTtcbiAgICAgICAgICByZXNvbHZlKHRydWUpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGZvciAobGV0IG51bU9mRmFpbHVyZXMgPSAxOyBudW1PZkZhaWx1cmVzIDw9IHByb2Nlc3MuZW52Lm1heEF0dGVtcHRzOyBudW1PZkZhaWx1cmVzKyspIHtcbiAgICAgICAgICAgIGlmIChudW1PZkZhaWx1cmVzID09IHByb2Nlc3MuZW52Lm1heEF0dGVtcHRzKSB7XG4gICAgICAgICAgICAgIHRoaXMuX2FwcC4kZGlzbWlzc092ZXJsYXkoKTtcbiAgICAgICAgICAgICAgcmVzcG9uZGVyKHtcbiAgICAgICAgICAgICAgICBncmFudGVkOiBmYWxzZSxcbiAgICAgICAgICAgICAgICByZWFzb246IFBpbkNoYWxsZW5nZS5SZXN1bHRSZWFzb24uRVhDRUVERURfUElO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ue1xuICAgICAgICAgICAgZm9udEZhY2U6ICdYZmluaXR5QnJvd25Cb2xkJyxcbiAgICAgICAgICAgIGZvbnRTaXplOiA0OCxcbiAgICAgICAgICAgIGZvbnRXZWlnaHQ6IDcwMCxcbiAgICAgICAgICAgIGxldHRlclNwYWNpbmc6IC0wLjQsXG4gICAgICAgICAgICBsaW5lSGVpZ2h0OiA2NCxcbiAgICAgICAgICAgIHZlcnRpY2FsQWxpZ246ICdtaWRkbGUnLFxuICAgICAgICAgIH0sXG4gICAgICAgICAgdGV4dENvbG9yOiAnIzQwNzY4NjM0ODcnLFxuICAgICAgICAgIHRleHRBbGlnbjogJ2NlbnRlcicsXG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgICAgRGV0YWlsOiB7XG4gICAgICAgIHg6IDAsXG4gICAgICAgIHk6IEJPRFlfWSxcbiAgICAgICAgdzogU0NSRUVOLncsXG4gICAgICAgIHRleHQ6IHtcbiAgICAgICAgICAuLi57XG4gICAgICAgICAgICBmb250RmFjZTogJ1hmaW5pdHlTdGFuZGFyZE1lZGl1bScsXG4gICAgICAgICAgICBmb250U2l6ZTogMzIsXG4gICAgICAgICAgICBmb250V2VpZ2h0OiA1MDAsXG4gICAgICAgICAgICBsZXR0ZXJTcGFjaW5nOiAwLFxuICAgICAgICAgICAgbGluZUhlaWdodDogNDAsXG4gICAgICAgICAgICB2ZXJ0aWNhbEFsaWduOiAnbWlkZGxlJyxcbiAgICAgICAgICB9LFxuICAgICAgICAgIHRleHRDb2xvcjogJyMzNDM5MzI5Mjc5JyxcbiAgICAgICAgICB0ZXh0QWxpZ246ICdjZW50ZXInLFxuICAgICAgICB9LFxuICAgICAgfSxcbiAgICAgIFBpbkRpc3BsYXk6IHtcbiAgICAgICAgeDogMCxcbiAgICAgICAgeTogUElOX0RJU1BMQVlfWSxcbiAgICAgICAgdzogU0NSRUVOLncsXG4gICAgICAgIHRleHQ6IHtcbiAgICAgICAgICAuLi57XG4gICAgICAgICAgICBmb250RmFjZTogJ1hmaW5pdHlCcm93bkJvbGQnLFxuICAgICAgICAgICAgZm9udFNpemU6IDU2LFxuICAgICAgICAgICAgZm9udFdlaWdodDogNzAwLFxuICAgICAgICAgICAgbGV0dGVyU3BhY2luZzogLTAuNCxcbiAgICAgICAgICAgIGxpbmVIZWlnaHQ6IDcyLFxuICAgICAgICAgICAgdmVydGljYWxBbGlnbjogJ21pZGRsZScsXG4gICAgICAgICAgfSxcbiAgICAgICAgICBmb250U2l6ZTogNzIsXG4gICAgICAgICAgdGV4dENvbG9yOiAnIzQwNzY4NjM0ODcnLFxuICAgICAgICAgIHRleHRBbGlnbjogJ2NlbnRlcicsXG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgIH07XG4gIH1cblxuICBfY29uc3RydWN0KCkge1xuICAgIHRoaXMucGluID0gW107XG4gICAgdGhpcy5zb2Z0S2V5UGVuZGluZyA9IG51bGw7XG4gIH1cblxuICBfZ2V0Rm9jdXNlZCgpIHtcbiAgICByZXR1cm4gdGhpcy50YWcoJ0tleWJvYXJkJyk7XG4gIH1cblxuICAkb25Tb2Z0S2V5KGtleSkge1xuICAgIHRoaXMuc29mdEtleVBlbmRpbmcgPSBrZXkua2V5O1xuICB9XG5cbiAgcGluRW50cnkoZGlnaXQpIHtcbiAgICB0aGlzLnBpbi5wdXNoKGRpZ2l0KTtcbiAgICB0aGlzLl9yZW5kZXJQaW5EaWdpdHMoKTtcbiAgICBpZiAodGhpcy5waW4ubGVuZ3RoID09PSA0ICYmIHRoaXMubGlzdGVuZXIpIHtcbiAgICAgIHRoaXMubGlzdGVuZXIub25QaW5FbnRlcmVkKHRoaXMucGluLmpvaW4oJycpKTtcbiAgICB9XG4gIH1cblxuICAkY2xlYXJQaW4oKSB7XG4gICAgdGhpcy5waW4gPSBbXTtcbiAgICB0aGlzLl9yZW5kZXJQaW5EaWdpdHMoKTtcbiAgICBjb25zdCBrYiA9IHRoaXMudGFnKCdLZXlib2FyZC5OdW1iZXJzJyk7XG4gICAgaWYgK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TtcbiIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyIsIi8qIChpZ25vcmVkKSAqLyJdLCJzb3VyY2VSb290IjoiIn0=
\ No newline at end of file
diff --git a/PR-175/startupScripts.bundle.4e84a090734bd0d3d214.js b/PR-175/startupScripts.bundle.e78a84e2e87e55823e17.js
similarity index 99%
rename from PR-175/startupScripts.bundle.4e84a090734bd0d3d214.js
rename to PR-175/startupScripts.bundle.e78a84e2e87e55823e17.js
index 814611ee..524a5f41 100644
--- a/PR-175/startupScripts.bundle.4e84a090734bd0d3d214.js
+++ b/PR-175/startupScripts.bundle.e78a84e2e87e55823e17.js
@@ -170,4 +170,4 @@ module.exports = __webpack_require__(/*! ./plugins/startupScripts/index.js */"./
/***/ })
/******/ });
-//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAiLCJ3ZWJwYWNrOi8vLy4vcGx1Z2lucy9zdGFydHVwU2NyaXB0cy9hY3RpdmF0ZU1vY2tGaXJlYm9sdC5qcyIsIndlYnBhY2s6Ly8vLi9wbHVnaW5zL3N0YXJ0dXBTY3JpcHRzL2luZGV4LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O1FBQUE7UUFDQTs7UUFFQTtRQUNBOztRQUVBO1FBQ0E7UUFDQTtRQUNBO1FBQ0E7UUFDQTtRQUNBO1FBQ0E7UUFDQTtRQUNBOztRQUVBO1FBQ0E7O1FBRUE7UUFDQTs7UUFFQTtRQUNBO1FBQ0E7OztRQUdBO1FBQ0E7O1FBRUE7UUFDQTs7UUFFQTtRQUNBO1FBQ0E7UUFDQSwwQ0FBMEMsZ0NB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