xiaomianao666

插件名:global_東方永頁機

Jun 25th, 2023
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 海阔视界规则分享,当前分享的是:网页插件¥js_url¥global_東方永頁機@base64://Ly8gPT1Vc2VyU2NyaXB0PT0KLy8gQG5hbWUgICAgICAgICBQYWdldHVhbAovLyBAbmFtZTp6aC1DTiAgIOS4nOaWueawuOmhteacugovLyBAbmFtZTp6aC1UVyAgIOadseaWueawuOmggeapnwovLyBAbmFtZTpqYSAgICAgIOadseaWueawuOmggeapnwovLyBAbmFtZTpydSAgICAgIFBhZ2V0dWFsCi8vIEBuYW1lOmRlICAgICAgUGFnZXR1YWwKLy8gQG5hbWU6ZXMgICAgICBQYWdldHVhbAovLyBAbmFtZTpmciAgICAgIFBhZ2V0dWFsCi8vIEBuYW1lOml0ICAgICAgUGFnZXR1YWwKLy8gQG5hbWU6a28gICAgICDmnbHmlrnmsLjpoIHmqZ8KLy8gQG5hbWVzcGFjZSAgICBob290aGluCi8vIEB2ZXJzaW9uICAgICAgMS45LjM2LjM5Ci8vIEBkZXNjcmlwdGlvbiAgUGVycGV0dWFsIHBhZ2VzIC0gcG93ZXJmdWwgYXV0by1wYWdlciBzY3JpcHQuIEF1dG8gbG9hZGluZyBuZXh0IHBhZ2luYXRlZCB3ZWIgcGFnZXMgYW5kIGluc2VydGluZyBpbnRvIGN1cnJlbnQgcGFnZS4gU3VwcG9ydCB0aG91c2FuZHMgb2Ygd2ViIHNpdGVzIHdpdGhvdXQgYW55IHJ1bGUuCi8vIEBkZXNjcmlwdGlvbjp6aC1DTiAg57uI5p6B6Ieq5Yqo57+76aG1IC0g5Yqg6L295bm25ou85o6l5LiL5LiA5YiG6aG15YaF5a656Iez5b2T5YmN6aG15bC+77yM5pm66IO96YCC6YWN5Lu75oSP572R6aG1Ci8vIEBkZXNjcmlwdGlvbjp6aC1UVyAg57WC5qW16Ieq5YuV57+76aCBIC0g5Yqg6LyJ5Lim5ou85o6l5LiL5LiA5Yi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T0gJ25vbmUnKSBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuc3R5bGUuZGlzcGxheSA9ICdibG9jayc7CiAgICAgICAgaWYgKGRvY3VtZW50LmJvZHkgJiYgZ2V0Q29tcHV0ZWRTdHlsZShkb2N1bWVudC5ib2R5KS5kaXNwbGF5ID09ICdub25lJykgZG9jdW1lbnQuYm9keS5zdHlsZS5kaXNwbGF5ID0gJ2Jsb2NrJzsKICAgICAgICByZXR1cm47CiAgICB9CgogICAgaWYgKHdpbmRvdy50b3AgIT0gd2luZG93LnNlbGYpIHsKICAgICAgICB0cnkgewogICAgICAgICAgICBpZiAod2luZG93LnNlbGYuaW5uZXJXaWR0aCA8IDMwMCB8fCB3aW5kb3cuc2VsZi5pbm5lckhlaWdodCA8IDMwMCkgewogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICB9CgogICAgY29uc3Qgbm9SdWxlVGVzdCA9IGZhbHNlOwogICAgY29uc3QgbGFuZyA9IG5hdmlnYXRvci5hcHBOYW1lID09ICJOZXRzY2FwZSIgPyBuYXZpZ2F0b3IubGFuZ3VhZ2UgOiBuYXZpZ2F0b3IudXNlckxhbmd1YWdlOwogICAgbGV0IGNvbmZpZyA9IHt9OwogICAgc3dpdGNoIChsYW5nKSB7CiAgICAgICAgY2FzZSAiemgtQ04iOgogICAgICAgIGNhc2UgInpoLVNHIjoKICAgICAgICAgICAgY29uZmlnID0gewogICAgICAgICAgICAgICAgZW5hYmxlRGVidWc6ICLosIPor5XmqKHlvI/vvIzovpPlh7rkv6Hmga/oh7PmjqfliLblj7AiLAogICAgICAgICAgICAgICAgZGlzYWJsZTogIuaaguaXtuemgeeUqCIsCiAgICAgICAgICAgICAgICBkaXNhYmxlU2l0ZTogIuermeeCueemgeeUqOW8gOWFsyIsCiAgICAgICAgICAgICAgICBkaXNhYmxlU2l0ZVRpcHM6ICLlt7LlnKjmraTnq5nnpoHnlKgiLAogICAgICAgICAgICAgICAgZW5hYmxlU2l0ZVRpcHM6ICLlt7LlnKjmraTnq5nlkK/nlKgiLAogICAgICAgICAgICAgICAgZW5hYmxlOiAi5ZCv55So6Ieq5Yqo57+76aG1IiwKICAgICAgICAgICAgICAgIHRvVG9wOiAi5Zue5Yiw6aG26YOoIiwKICAgICAgICAgICAgICAgIHRvQm90dG9tOiAi5YmN5b6A6aG15bC+IiwKICAgICAgICAgICAgICAgIGN1cnJlbnQ6ICLlvZPliY3pobUiLAogICAgICAgICAgICAgICAgZm9yY2VJZnJhbWU6ICLlvLrliLbmi7zmjqUiLAogICAgICAgICAgICAgICAgY2FuY2VsRm9yY2VJZnJhbWU6ICLlj5bmtojlvLrliLbmi7zmjqUiLAogICAgICAgICAgICAgICAgY29uZmlndXJlOiAi5omT5byA6YWN572u6aG16Z2iIiwKICAgICAgICAgICAgICAgIGZpcnN0VXBkYXRlOiAi54K55Ye75q2k5aSE5Yid5aeL5YyW6KeE5YiZIiwKICAgICAgICAgICAgICAgIHVwZGF0ZTogIuabtOaWsOWcqOe6v+inhOWImSIsCiAgICAgICAgICAgICAgICBjbGljazJ1cGRhdGU6ICLngrnlh7vnq4vljbPmm7TmlrDop4TliJkiLAogICAgICAgICAgICAgICAgbG9hZE5vdzogIueri+WNs+e/u+mhtSIsCiAgICAgICAgICAgICAgICBsb2FkQ29uZmlybTogIuimgee/u+WHoOmhte+8n++8iDDkuLrkuI3pl7Tmlq3vvIkiLAogICAgICAgICAgICAgICAgbm9OZXh0OiAi5rKh5pyJ5om+5Yiw5LiL5LiA6aG177yM6K+35paw5bu66KeE5YiZIiwKICAgICAgICAgICAgICAgIHBhc3NTZWM6ICLmm7TmlrDkuo4gI3QjIOenkuWJjSIsCiAgICAgICAgICAgICAgICBwYXNzTWluOiAi5pu05paw5LqOICN0IyDliIbpkp/liY0iLAogICAgICAgICAgICAgICAgcGFzc0hvdXI6ICLmm7TmlrDkuo4gI3QjIOWwj+aXtuWJjSIsCiAgICAgICAgICAgICAgICBwYXNzRGF5OiAi5pu05paw5LqOICN0IyDlpKnliY0iLAogICAgICAgICAgICAgICAgY2FudERlbDogIuaXoOazleWIoOmZpOWGhee9ruinhOWImSIsCiAgICAgICAgICAgICAgICBjb25maXJtRGVsOiAi5piv5ZCm56Gu6K6k6KaB5Yig6Zmk5q2k6KeE5YiZ77yfIiwKICAgICAgICAgICAgICAgIHVwZGF0ZVN1Y2M6ICLmm7TmlrDmiJDlip8iLAogICAgICAgICAgICAgICAgYmVnaW5VcGRhdGU6ICLmraPlnKjmm7TmlrDvvIzor7fogJDlv4PnrYnlvoXvvIzkuI3opoHlhbPpl63pobXpnaIiLAogICAgICAgICAgICAgICAgY3VzdG9tVXJsczogIuWvvOWFpSBQYWdldHVhbCDmiJYgQXV0b1BhZ2VyaXplIOinhOWImSB1cmzvvIzkuIDooYzkuIDmnaEiLAogICAgICAgICAgICAgICAgY3VzdG9tUnVsZXM6ICLovpPlhaXjgJDkuJzmlrnmsLjpobXmnLrjgJHmoLzlvI/nmoToh6rlrprkuYnop4TliJkgPGEgaHJlZj0nI3QjJz7otKHnjK7op4TliJk8L2E+IiwKICAgICAgICAgICAgICAgIHNhdmU6ICLkv53lrZjorr7nva4iLAogICAgICAgICAgICAgICAgbG9hZGluZ1RleHQ6ICLlsJHlpbPnpYjnpbfkuK0uLi4iLAogICAgICAgICAgICAgICAgb3BhY2l0eTogIuS4jemAj+aYjuWAvCIsCiAgICAgICAgICAgICAgICBvcGFjaXR5UGxhY2Vob2xkZXI6ICIwOiDpmpDol4/liIbpmpTmnaEiLAogICAgICAgICAgICAgICAgaGlkZUJhcjogIumakOiXj+WIhumhtemalOadoSIsCiAgICAgICAgICAgICAgICBoaWRlQmFyQnV0Tm9TdG9wOiAi6ZqQ6JeP5L2G5LiN5YGc5q2iIiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcDogIuepuueZveWkhOWPjOWHu+aaguWBnOe/u+mhtSIsCiAgICAgICAgICAgICAgICBzb3J0VGl0bGU6ICLmjpLluo/lnKjkuIvmrKHmm7TmlrDop4TliJnlkI7nlJ/mlYgiLAogICAgICAgICAgICAgICAgYXV0b1J1bjogIuiHquWKqOWQr+eUqO+8jOWQpuWImeS4uueZveWQjeWNleaooeW8jyIsCiAgICAgICAgICAgICAgICBhdXRvTG9hZE51bTogIuiHquWKqOWKoOi9veaMh+WumumhteaVsCIsCiAgICAgICAgICAgICAgICB0dXJuUmF0ZTogIui3neemu+mhteWwvuOAkFjjgJHlgI3pobXpnaLpq5jluqbml7blsLHlvIDlp4vnv7vpobUiLAogICAgICAgICAgICAgICAgaW5wdXRQYWdlTnVtOiAi6L6T5YWl6aG156CB6Lez6L2sIiwKICAgICAgICAgICAgICAgIGVuYWJsZUhpc3Rvcnk6ICLnv7vpobXlkI7lhpnlhaXljoblj7LorrDlvZUiLAogICAgICAgICAgICAgICAgZW5hYmxlSGlzdG9yeUFmdGVySW5zZXJ0OiAi5ou85o6l5ZCO56uL5Y2z5YaZ5YWl5Y6G5Y+y6K6w5b2V77yM5ZCm5YiZ5rWP6KeI5a6M5q+V5ZCO5YaN6KGM5YaZ5YWlIiwKICAgICAgICAgICAgICAgIGNvbnRlbnRWaXNpYmlsaXR5OiAi6Ieq5Yqo5YiH5o2iIGNvbnRlbnRWaXNpYmlsaXR577yM5o+Q5Y2H5riy5p+T5oCn6IO9IiwKICAgICAgICAgICAgICAgIGluaXRSdW46ICLmiZPlvIDpobXpnaLlkI7nq4vljbPlsJ3or5Xnv7vpobXvvIzlkKbliJnmu5rliqjoh7PpobXlsL7lho3nv7vpobUiLAogICAgICAgICAgICAgICAgcHJlbG9hZDogIue/u+mhteWJjemihOivu+S4i+S4gOmhte+8jOWKoOmAn+a1j+iniCIsCiAgICAgICAgICAgICAgICBjbGljazJJbXBvcnRSdWxlOiAi54K55Ye75LiL5pa55re75Yqg54m55q6K6KeE5YiZ5bqT77yM5bm26Z2Z5b6F5pu05paw5oiQ5Yqf77yaIiwKICAgICAgICAgICAgICAgIGZvcmNlQWxsQm9keTogIuaYr+WQpuaLvOaOpeaVtOS4qumhtemdou+8nyIsCiAgICAgICAgICAgICAgICBvcGVuSW5OZXdUYWI6ICLkvb/mi7zmjqXpobXpnaLnmoTlhoXlrrnlnKjmlrDpobXpnaLmiZPlvIAiLAogICAgICAgICAgICAgICAgaW1wb3J0U3VjYzogIuWvvOWFpeaIkOWKnyIsCiAgICAgICAgICAgICAgICBpbXBvcnQ6ICLlr7zlhaUiLAogICAgICAgICAgICAgICAgZWRpdEN1cnJlbnQ6ICLnvJbovpHmraTnq5nop4TliJkiLAogICAgICAgICAgICAgICAgZWRpdEJsYWNrbGlzdDogIue8lui+kem7keWQjeWNlee9keWdgO+8jOS4gOihjOS4gOadoe+8jOaUr+aMgT8gKumAmumFjeespuS4juato+WImSIsCiAgICAgICAgICAgICAgICB1cEJ0bkltZzogIuWbnuWIsOmhtemmluWbvuaghyIsCiAgICAgICAgICAgICAgICBkb3duQnRuSW1nOiAi5YmN5b6A6aG15bC+5Zu+5qCHIiwKICAgICAgICAgICAgICAgIHNpZGVDb250cm9sbGVySWNvbjogIuS+p+i+ueagj+WbvuaghyIsCiAgICAgICAgICAgICAgICBsb2FkaW5nVGV4dFRpdGxlOiAi5Yqg6L295Lit5paH5a2XIiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcEN0cmw6ICJDdHJsIOmUriIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3BBbHQ6ICJBbHQg6ZSuIiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcFNoaWZ0OiAiU2hpZnQg6ZSuIiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcE1ldGE6ICJNZXRhIOmUriIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3BLZXk6ICLlv6vmjbfplK4iLAogICAgICAgICAgICAgICAgcGFnZUVsZW1lbnRDc3M6ICLpobXpnaLkuLvkvZPmoYbmnrbnmoTmoLflvI8iLAogICAgICAgICAgICAgICAgY3VzdG9tQ3NzOiAi6Ieq5a6a5LmJIGNzcyIsCiAgICAgICAgICAgICAgICBmaXJzdEFsZXJ0OiAi5L2g6L+Y5pyq5a+85YWl6KeE5YiZ5bqT77yM6K+36YCJ5oup5ZCI6YCC55qE6KeE5YiZ5bqT5a+85YWl5ZOmIiwKICAgICAgICAgICAgICAgIHBpY2tlcjogIuS4nOaWueawuOmhteacuuS4u+S9k+WFg+e0oOaKk+WPluWZqCIsCiAgICAgICAgICAgICAgICBjbG9zZVBpY2tlcjogIuWFs+mXreS4nOaWueawuOmhteacuuaKk+WPluWZqCIsCiAgICAgICAgICAgICAgICBwaWNrZXJQbGFjZWhvbGRlcjogIuWFg+e0oOmAieaLqeWZqO+8jOayoeaDs+azleW7uuiurueVmeepuiIsCiAgICAgICAgICAgICAgICBwaWNrZXJDaGVjazogIuajgOafpeS9oOe8lui+keeahOmAieaLqeWZqOW5tuWkjeWItiIsCiAgICAgICAgICAgICAgICBzd2l0Y2hTZWxlY3RvcjogIueCueWHu+WIh+aNouWFg+e0oCIsCiAgICAgICAgICAgICAgICBnb3RvRWRpdDogIuS9v+eUqOW9k+WJjeeahOmAieaLqeWZqOWJjeW+gOe8lui+keinhOWImSIsCiAgICAgICAgICAgICAgICBtYW51YWxNb2RlOiAi56aB55So5ou85o6l77yM5omL5Yqo55So5Y+z5pa55ZCR6ZSu57+76aG177yM5Y+v5L2/55So5bem5pa55ZCR6ZSu6L+U5ZueIiwKICAgICAgICAgICAgICAgIGNsaWNrTW9kZTogIuemgeeUqOaLvOaOpe+8jOa7muWKqOiHs+mhteWwvuaXtuiHquWKqOeCueWHu+S4i+S4gOmhtSIsCiAgICAgICAgICAgICAgICBwYWdlQmFyTWVudTogIueCueWHu+WIhumalOadoeS4remXtOW8ueWHuuiPnOWNlSIsCiAgICAgICAgICAgICAgICBuZXh0U3dpdGNoOiAi5YiH5o2i5YW25LuW6aG156CBIiwKICAgICAgICAgICAgICAgIGFycm93VG9TY3JvbGw6ICLlt6bmlrnlkJHplK7mu5rliqjoh7PkuIrkuIDpobXvvIzlj7PmlrnlkJHplK7mu5rliqjoh7PkuIvkuIDpobUiLAogICAgICAgICAgICAgICAgc2lkZUNvbnRyb2xsZXI6ICLlnKjkvqfovrnmmL7npLrnv7vpobXmjqfliLbmoI8iLAogICAgICAgICAgICAgICAgaGlkZUxvYWRpbmdJY29uOiAi6ZqQ6JeP5Yqg6L295Yqo55S7IiwKICAgICAgICAgICAgICAgIGhpZGVCYXJBcnJvdzogIumakOiXj+WIhumalOadoeWumuS9jeeureWktCIsCiAgICAgICAgICAgICAgICBkdXBsaWNhdGU6ICLmo4DmtYvliLDmsLjpobXmnLrph43lpI3lronoo4XvvIzor7fliKDpmaTlhbbku5bohJrmnKznrqHnkIblmajkuK3nmoTmsLjpobXmnLohIiwKICAgICAgICAgICAgICAgIGZvcmNlU3RhdGVJZnJhbWU6ICLku6UgaWZyYW1lIOW1jOWFpeaVtOmhtSIsCiAgICAgICAgICAgICAgICBmb3JjZVN0YXRlRHluYW1pYzogIumAmui/hyBpZnJhbWUg5Yqg6L295Yqo5oCB5YaF5a655ZCO5Y+W5Ye6IiwKICAgICAgICAgICAgICAgIGZvcmNlU3RhdGVEaXNhYmxlOiAi5Zyo5q2k56uZ56aB55SoIiwKICAgICAgICAgICAgICAgIGF1dG9TY3JvbGxSYXRlOiAi5rua5Yqo6YCf5bqm77yIMX4xMDAw77yJIiwKICAgICAgICAgICAgICAgIGRpc2FibGVBdXRvU2Nyb2xsOiAi5YGc5q2i6Ieq5Yqo5rua5YqoIiwKICAgICAgICAgICAgICAgIGVuYWJsZUF1dG9TY3JvbGw6ICLlvIDlkK/oh6rliqjmu5rliqgiLAogICAgICAgICAgICAgICAgdG9nZ2xlQXV0b1Njcm9sbDogIuiHquWKqOa7muWKqOW8gOWFsyIsCiAgICAgICAgICAgICAgICBwYWdlOiAiUGFnZSAiLAogICAgICAgICAgICAgICAgcHJldlBhZ2U6ICLkuIrkuIDpobUiLAogICAgICAgICAgICAgICAgbmV4dFBhZ2U6ICLkuIvkuIDpobUiLAogICAgICAgICAgICAgICAgZXJyb3JSdWxlc011c3RCZUFycmF5OiAi6KeE5YiZ5b+F6aG75Li65pWw57uE5b2i5byPISIsCiAgICAgICAgICAgICAgICBlcnJvckpzb246ICJKU09OIOagvOW8j+aciemUme+8jOivt+mHjeaWsOajgOafpSEiLAogICAgICAgICAgICAgICAgZWRpdFN1Y2Nlc3M6ICLnvJbovpHmiJDlip8iLAogICAgICAgICAgICAgICAgZXJyb3JXcm9uZ1VybDogIlVSTCDplJnor68sIOivt+mHjeaWsOajgOafpSEiLAogICAgICAgICAgICAgICAgZXJyb3JBbHJlYWR5RXhpc3RzOiAi5bey57uP5a2Y5ZyoISIsCiAgICAgICAgICAgICAgICBzZXR0aW5nc1NhdmVkOiAi6K6+572u5bey5L+d5a2Y77yM5Yi35paw5ZCO55Sf5pWIIiwKICAgICAgICAgICAgICAgIGlmcmFtZTogIuW8uuWItuaLvOaOpSIsCiAgICAgICAgICAgICAgICBkeW5hbWljOiAi5Yqo5oCB5Yqg6L29IiwKICAgICAgICAgICAgICAgIHJlbG9hZFBhZ2U6ICLnvJbovpHlrozmiJDvvIzmmK/lkKbnq4vljbPliLfmlrDpobXpnaLvvJ8iLAogICAgICAgICAgICAgICAgY29waWVkOiAi5bey5aSN5Yi2IiwKICAgICAgICAgICAgICAgIG5vVmFsaWRDb250ZW50OiAi5rKh5pyJ5qOA5rWL5Yiw5pyJ5pWI5YaF5a6577yM54K55Ye75p+l55yLIiwKICAgICAgICAgICAgICAgIG91dE9mRGF0ZTogIuiEmuacrOW3sui/h+aXtu+8jOivt+WPiuaXtuabtOaWsOWIsOacgOaWsOeJiOacrO+8gSIsCiAgICAgICAgICAgICAgICBoaWRlQmFyVGlwczogIumakOiXj+WIhumhtemalOadoe+8jOayiea1uOW8j+S9k+mqjCIsCiAgICAgICAgICAgICAgICBzZXRDb25maWdQYWdlOiAi5bCG5b2T5YmN6aG16Z2i6K6+5Li66buY6K6k6YWN572u6aG1IiwKICAgICAgICAgICAgICAgIHdlZGF0YTJnaXRodWI6ICLlsIYgd2VkYXRhIOWcsOWdgOabtOaUueS4uiBnaXRodWIg5LuT5bqT5YaF55qE6ZWc5YOP5Zyw5Z2AIiwKICAgICAgICAgICAgICAgIGFkZE90aGVyUHJvcDogIua3u+WKoOinhOWImeWxnuaApyIsCiAgICAgICAgICAgICAgICBhZGROZXh0U2VsZWN0b3I6ICLmt7vliqDpgInmi6nlmajlhoXlrrnkuLogbmV4dExpbmsiLAogICAgICAgICAgICAgICAgYWRkUGFnZVNlbGVjdG9yOiAi5re75Yqg6YCJ5oup5Zmo5YaF5a655Li6IHBhZ2VFbGVtZW50IiwKICAgICAgICAgICAgICAgIHByb3BOYW1lOiAi6L6T5YWl6KeE5YiZ5bGe5oCn5ZCNIiwKICAgICAgICAgICAgICAgIHByb3BWYWx1ZTogIui+k+WFpeinhOWImeWxnuaAp+WAvCIKICAgICAgICAgICAgfTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSAiemgtVFciOgogICAgICAgIGNhc2UgInpoLUhLIjoKICAgICAgICAgICAgY29uZmlnID0gewogICAgICAgICAgICAgICAgZW5hYmxlRGVidWc6ICLoqr/oqabmqKHlvI/vvIzovLjlh7rkv6Hmga/oh7PmjqfliLblj7AiLAogICAgICAgICAgICAgICAgZGlzYWJsZTogIuaaq+aZguemgeeUqCIsCiAgICAgICAgICAgICAgICBkaXNhYmxlU2l0ZTogIuermem7nuemgeeUqOmWi+mXnCIsCiAgICAgICAgICAgICAgICBkaXNhYmxlU2l0ZVRpcHM6ICLlt7LlnKjmraTnq5nnpoHnlKgiLAogICAgICAgICAgICAgICAgZW5hYmxlU2l0ZVRpcHM6ICLlt7LlnKjmraTnq5nllZ/nlKgiLAogICAgICAgICAgICAgICAgZW5hYmxlOiAi5ZWf55So6Ieq5YuV57+76aCBIiwKICAgICAgICAgICAgICAgIHRvVG9wOiAi5Zue5Yiw6aCC6YOoIiwKICAgICAgICAgICAgICAgIHRvQm90dG9tOiAi5YmN5b6A6aCB5bC+IiwKICAgICAgICAgICAgICAgIGN1cnJlbnQ6ICLnlbbliY3poIEiLAogICAgICAgICAgICAgICAgZm9yY2VJZnJhbWU6ICLlvLfliLbmi7zmjqUiLAogICAgICAgICAgICAgICAgY2FuY2VsRm9yY2VJZnJhbWU6ICLlj5bmtojlvLrliLbmi7zmjqUiLAogICAgICAgICAgICAgICAgY29uZmlndXJlOiAi5omT6ZaL6YWN572u6aCB6Z2iIiwKICAgICAgICAgICAgICAgIGZpcnN0VXBkYXRlOiAi6bue5pOK5q2k6JmV5Yid5aeL5YyW6KaP5YmHIiwKICAgICAgICAgICAgICAgIHVwZGF0ZTogIuabtOaWsOWcqOe2q+imj+WJhyIsCiAgICAgICAgICAgICAgICBjbGljazJ1cGRhdGU6ICLpu57mk4rnq4vljbPmm7TmlrDopo/liYciLAogICAgICAgICAgICAgICAgbG9hZE5vdzogIueri+WNs+e/u+mggSIsCiAgICAgICAgICAgICAgICBsb2FkQ29uZmlybTogIuimgee/u+WHoOmgge+8n++8iDDngrrkuI3plpPmlrfvvIkiLAogICAgICAgICAgICAgICAgbm9OZXh0OiAi5rKS5pyJ5om+5Yiw5LiL5LiA6aCB77yM6KuL5paw5bu66KaP5YmHIiwKICAgICAgICAgICAgICAgIHBhc3NTZWM6ICLmm7TmlrDkuo4gI3QjIOenkuWJjSIsCiAgICAgICAgICAgICAgICBwYXNzTWluOiAi5pu05paw5LqOICN0IyDliIbpkJjliY0iLAogICAgICAgICAgICAgICAgcGFzc0hvdXI6ICLmm7TmlrDkuo4gI3QjIOWwj+aZguWJjSIsCiAgICAgICAgICAgICAgICBwYXNzRGF5OiAi5pu05paw5LqOICN0IyDlpKnliY0iLAogICAgICAgICAgICAgICAgY2FudERlbDogIueEoeazleWIqumZpOWGhee9ruimj+WJhyIsCiAgICAgICAgICAgICAgICBjb25maXJtRGVsOiAi5piv5ZCm56K66KqN6KaB5Yiq6Zmk5q2k6KaP5YmH77yfIiwKICAgICAgICAgICAgICAgIHVwZGF0ZVN1Y2M6ICLmm7TmlrDmiJDlip8iLAogICAgICAgICAgICAgICAgYmVnaW5VcGRhdGU6ICLmraPlnKjmm7TmlrDvvIzoq4vnqI3lgJkiLAogICAgICAgICAgICAgICAgY3VzdG9tVXJsczogIuWwjuWFpSBQYWdldHVhbCDmiJYgQXV0b1BhZ2VyaXplIOimj+WJhyB1cmzvvIzkuIDooYzkuIDmop0iLAogICAgICAgICAgICAgICAgY3VzdG9tUnVsZXM6ICLovLjlhaXjgJDmnbHmlrnmsLjpoIHmqZ/jgJHmoLzlvI/nmoToh6rlrprnvqnopo/liYcgPGEgaHJlZj0nI3QjJz7osqLnjbvopo/liYc8L2E+IiwKICAgICAgICAgICAgICAgIHNhdmU6ICLlrZjlhLLoqK3nva4iLAogICAgICAgICAgICAgICAgbG9hZGluZ1RleHQ6ICLlsJHlpbPnpYjnprHkuK0uLi4iLAogICAgICAgICAgICAgICAgb3BhY2l0eTogIuS4jemAj+aYjuWAvCIsCiAgICAgICAgICAgICAgICBvcGFjaXR5UGxhY2Vob2xkZXI6ICIwOiDpmrHol4/liIbpmpTmop0iLAogICAgICAgICAgICAgICAgaGlkZUJhcjogIumaseiXj+WIhumggemalOainSIsCiAgICAgICAgICAgICAgICBoaWRlQmFyQnV0Tm9TdG9wOiAi6Zqx6JeP5L2G5LiN5YGc5q2iIiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcDogIuepuueZveiZlembmeaTiuaaq+WBnOe/u+mggSIsCiAgICAgICAgICAgICAgICBzb3J0VGl0bGU6ICLmjpLluo/lnKjkuIvmrKHmm7TmlrDopo/liYflvoznlJ/mlYgiLAogICAgICAgICAgICAgICAgYXV0b1J1bjogIuiHquWLleWVk+eUqO+8jOWQpuWJh+eCuueZveWQjeWWruaooeW8jyIsCiAgICAgICAgICAgICAgICBhdXRvTG9hZE51bTogIuiHquWLleWKoOi8ieaMh+WumumggeaVuCIsCiAgICAgICAgICAgICAgICB0dXJuUmF0ZTogIui3nemboumggeWwvuOAkFjjgJHlgI3poIHpnaLpq5jluqbmmYLlsLHplovlp4vnv7vpoIEiLAogICAgICAgICAgICAgICAgaW5wdXRQYWdlTnVtOiAi6Ly45YWl6aCB56K86Lez6L2JIiwKICAgICAgICAgICAgICAgIGVuYWJsZUhpc3Rvcnk6ICLnv7vpoIHlkI7lr6vlhaXmrbflj7LoqJjpjIQiLAogICAgICAgICAgICAgICAgZW5hYmxlSGlzdG9yeUFmdGVySW5zZXJ0OiAi5ou85o6l5b6M56uL5Y2z5a+r5YWl5q235Y+y6KiY6YyE77yM5ZCm5YmH54CP6Ka95a6M55Wi5b6M5YaN6KGM5a+r5YWlIiwKICAgICAgICAgICAgICAgIGNvbnRlbnRWaXNpYmlsaXR5OiAi6Ieq5YuV5YiH5o+bIGNvbnRlbnRWaXNpYmlsaXR577yM5o+Q5Y2H5riy5p+T5oCn6IO9IiwKICAgICAgICAgICAgICAgIGluaXRSdW46ICLmiZPplovpoIHpnaLlkI7nq4vljbPlmJfoqabnv7vpoIHvvIzlkKbliYfmu77li5Xoh7PpoIHlsL7lho3nv7vpoIEiLAogICAgICAgICAgICAgICAgcHJlbG9hZDogIue/u+mggeWJjemgkOiugOS4i+S4gOmgge+8jOWKoOmAn+eAj+imvSIsCiAgICAgICAgICAgICAgICBjbGljazJJbXBvcnRSdWxlOiAi6bue5pOK5LiL5pa55re75Yqg54m55q6K6KaP5YmH5bqr77yM5bm26Z2c5b6F5pu05paw5oiQ5Yqf77yaIiwKICAgICAgICAgICAgICAgIGZvcmNlQWxsQm9keTogIuaYr+WQpuaLvOaOpeaVtOWAi+mggemdou+8nyIsCiAgICAgICAgICAgICAgICBvcGVuSW5OZXdUYWI6ICLkvb/mi7zmjqXpoIHpnaLnmoTlhoXlrrnlnKjmlrDpoIHpnaLmiZPplosiLAogICAgICAgICAgICAgICAgaW1wb3J0U3VjYzogIuWwjuWFpeaIkOWKnyIsCiAgICAgICAgICAgICAgICBpbXBvcnQ6ICLlsI7lhaUiLAogICAgICAgICAgICAgICAgZWRpdEN1cnJlbnQ6ICLnt6jovK/mraTnq5nopo/liYciLAogICAgICAgICAgICAgICAgZWRpdEJsYWNrbGlzdDogIue3qOi8r+m7keWQjeWWrue2suWdgO+8jOS4gOihjOS4gOaine+8jOaUr+aMgT8gKumAmumFjeespuiIh+ato+WJhyIsCiAgICAgICAgICAgICAgICB1cEJ0bkltZzogIuWbnuWIsOmggemmluWcluaomSIsCiAgICAgICAgICAgICAgICBkb3duQnRuSW1nOiAi5YmN5b6A6aCB5bC+5ZyW5qiZIiwKICAgICAgICAgICAgICAgIHNpZGVDb250cm9sbGVySWNvbjogIuWBtOmCiuashOWcluaomSIsCiAgICAgICAgICAgICAgICBsb2FkaW5nVGV4dFRpdGxlOiAi5Yqg6LyJ5Lit5paH5a2XIiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcEN0cmw6ICJDdHJsIOmNtSIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3BBbHQ6ICJBbHQg6Y21IiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcFNoaWZ0OiAiU2hpZnQg6Y21IiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcE1ldGE6ICJNZXRhIOmNtSIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3BLZXk6ICLlv6vmjbfpjbUiLAogICAgICAgICAgICAgICAgcGFnZUVsZW1lbnRDc3M6ICLpoIHpnaLkuLvpq5TmoYbmnrbnmoTmqKPlvI8iLAogICAgICAgICAgICAgICAgY3VzdG9tQ3NzOiAi6Ieq5a6a576pIGNzcyIsCiAgICAgICAgICAgICAgICBmaXJzdEFsZXJ0OiAi5L2g6YKE5pyq5bCO5YWl6KaP5YmH5bqr77yM6KuL6YG45pOH5ZCI6YGp55qE6KaP5YmH5bqr5bCO5YWl5ZOmIiwKICAgICAgICAgICAgICAgIHBpY2tlcjogIuadseaWueawuOmggeapn+S4u+mrlOWFg+e0oOaKk+WPluWZqCIsCiAgICAgICAgICAgICAgICBjbG9zZVBpY2tlcjogIumXnOmWieadseaWueawuOmggeapn+aKk+WPluWZqCIsCiAgICAgICAgICAgICAgICBwaWNrZXJQbGFjZWhvbGRlcjogIuWFg+e0oOmBuOaTh+WZqO+8jOaykuaDs+azleW7uuitsOeVmeepuiIsCiAgICAgICAgICAgICAgICBwaWNrZXJDaGVjazogIuaqouafpeS9oOe3qOi8r+eahOmBuOaTh+WZqOS4puikh+ijvSIsCiAgICAgICAgICAgICAgICBzd2l0Y2hTZWxlY3RvcjogIum7nuaTiuWIh+aPm+WFg+e0oCIsCiAgICAgICAgICAgICAgICBnb3RvRWRpdDogIuS9v+eUqOeVtuWJjeeahOmBuOaTh+WZqOWJjeW+gOe3qOi8r+imj+WJhyIsCiAgICAgICAgICAgICAgICBtYW51YWxNb2RlOiAi56aB55So5ou85o6l77yM5omL5YuV55So5Y+z5pa55ZCR6Y2157+76aCB77yM5bem5pa55ZCR6Y216L+U5ZueIiwKICAgICAgICAgICAgICAgIGNsaWNrTW9kZTogIuemgeeUqOaLvOaOpe+8jOa7vuWLleiHs+mggeWwvuaZguiHquWLlem7nuaTiuS4i+S4gOmggSIsCiAgICAgICAgICAgICAgICBwYWdlQmFyTWVudTogIum7nuaTiuWIhumalOaineS4remWk+W9iOWHuuiPnOWWriIsCiAgICAgICAgICAgICAgICBuZXh0U3dpdGNoOiAi5YiH5o+b5YW25LuW6aCB56K8IiwKICAgICAgICAgICAgICAgIGFycm93VG9TY3JvbGw6ICLlt6bmlrnlkJHpjbXmu77li5Xoh7PkuIrkuIDpoIHvvIzlj7PmlrnlkJHpjbXmu77li5Xoh7PkuIvkuIDpoIEiLAogICAgICAgICAgICAgICAgc2lkZUNvbnRyb2xsZXI6ICLlnKjlgbTpgorpoa/npLrnv7vpoIHmjqfliLbmrIQiLAogICAgICAgICAgICAgICAgaGlkZUxvYWRpbmdJY29uOiAi6Zqx6JeP5Yqg6LyJ5YuV55WrIiwKICAgICAgICAgICAgICAgIGhpZGVCYXJBcnJvdzogIumaseiXj+WIhumalOaineWumuS9jeeuremgrSIsCiAgICAgICAgICAgICAgICBkdXBsaWNhdGU6ICLmqqLmuKzliLDmsLjpoIHmqZ/ph43opIflronoo53vvIzoq4vliKrpmaTlhbbku5bohbPmnKznrqHnkIblmajkuK3nmoTmsLjpoIHmqZ8hIiwKICAgICAgICAgICAgICAgIGZvcmNlU3RhdGVJZnJhbWU6ICLku6UgaWZyYW1lIOW1jOWFpeaVtOmggSIsCiAgICAgICAgICAgICAgICBmb3JjZVN0YXRlRHluYW1pYzogIumAmumBjiBpZnJhbWUg5Yqg6LyJ5YuV5oWL5YWn5a655b6M5Y+W5Ye6IiwKICAgICAgICAgICAgICAgIGZvcmNlU3RhdGVEaXNhYmxlOiAi5Zyo5q2k56uZ56aB55SoIiwKICAgICAgICAgICAgICAgIGF1dG9TY3JvbGxSYXRlOiAi5ru+5YuV6YCf5bqm77yIMX4xMDAw77yJIiwKICAgICAgICAgICAgICAgIGRpc2FibGVBdXRvU2Nyb2xsOiAi5YGc5q2i6Ieq5YuV5ru+5YuVIiwKICAgICAgICAgICAgICAgIGVuYWJsZUF1dG9TY3JvbGw6ICLplovllZ/oh6rli5Xmu77li5UiLAogICAgICAgICAgICAgICAgdG9nZ2xlQXV0b1Njcm9sbDogIuiHquWLlea7vuWLlemWi+mXnCIsCiAgICAgICAgICAgICAgICBwYWdlOiAiUGFnZSAiLAogICAgICAgICAgICAgICAgcHJldlBhZ2U6ICLkuIrkuIDpoIEiLAogICAgICAgICAgICAgICAgbmV4dFBhZ2U6ICLkuIvkuIDpoIEiLAogICAgICAgICAgICAgICAgZXJyb3JSdWxlc011c3RCZUFycmF5OiAi6KaP5YmH5b+F6aCI54K66Zmj5YiX5b2i5byPISIsCiAgICAgICAgICAgICAgICBlcnJvckpzb246ICJKU09OIOagvOW8j+aciemMr++8jOiri+mHjeaWsOaqouafpSEiLAogICAgICAgICAgICAgICAgZWRpdFN1Y2Nlc3M6ICLnt6jovK/miJDlip8iLAogICAgICAgICAgICAgICAgZXJyb3JXcm9uZ1VybDogIlVSTCDpjK/oqqQsIOiri+mHjeaWsOaqouafpSEiLAogICAgICAgICAgICAgICAgZXJyb3JBbHJlYWR5RXhpc3RzOiAi5bey57aT5a2Y5ZyoISIsCiAgICAgICAgICAgICAgICBzZXR0aW5nc1NhdmVkOiAi6Kit572u5bey5L+d5a2Y77yM5Yi35paw5b6M55Sf5pWIIiwKICAgICAgICAgICAgICAgIGlmcmFtZTogIuW8t+WItuaLvOaOpSIsCiAgICAgICAgICAgICAgICBkeW5hbWljOiAi5YuV5oWL5Yqg6LyJIiwKICAgICAgICAgICAgICAgIHJlbG9hZFBhZ2U6ICLnt6jovK/lrozmiJDvvIzmmK/lkKbnq4vljbPliLfmlrDpoIHpnaLvvJ8iLAogICAgICAgICAgICAgICAgY29waWVkOiAi5bey5b6p5Yi2IiwKICAgICAgICAgICAgICAgIG5vVmFsaWRDb250ZW50OiAi5rKS5pyJ5qqi5ris5Yiw5pyJ5pWI5YaF5a6577yM6bue5pOK5p+l55yLIiwKICAgICAgICAgICAgICAgIG91dE9mRGF0ZTogIuiEmuacrOW3sumBjuaZgu+8jOiri+WPiuaZguabtOaWsOWIsOacgOaWsOeJiOacrO+8gSIsCiAgICAgICAgICAgICAgICBoaWRlQmFyVGlwczogIumaseiXj+WIhumggemalOaine+8jOayiea1uOW8j+mrlOmplyIsCiAgICAgICAgICAgICAgICBzZXRDb25maWdQYWdlOiAi5bCH55W25YmN6aCB6Z2i6Kit54K66buY6KqN6YWN572u6aCBIiwKICAgICAgICAgICAgICAgIHdlZGF0YTJnaXRodWI6ICLlsIcgd2VkYXRhIOWcsOWdgOabtOaUueeCuiBnaXRodWIg5YCJ5bqr5YWn55qE6Y+h5YOP5Zyw5Z2AIiwKICAgICAgICAgICAgICAgIGFkZE90aGVyUHJvcDogIua3u+WKoOimj+WJh+WxrOaApyIsCiAgICAgICAgICAgICAgICBhZGROZXh0U2VsZWN0b3I6ICLmt7vliqDpgbjmk4flmajlhaflrrnngrogbmV4dExpbmsiLAogICAgICAgICAgICAgICAgYWRkUGFnZVNlbGVjdG9yOiAi5re75Yqg6YG45pOH5Zmo5YWn5a6554K6IHBhZ2VFbGVtZW50IiwKICAgICAgICAgICAgICAgIHByb3BOYW1lOiAi6Ly45YWl6KaP5YmH5bGs5oCn5ZCNIiwKICAgICAgICAgICAgICAgIHByb3BWYWx1ZTogIui8uOWFpeimj+WJh+WxrOaAp+WAvCIKICAgICAgICAgICAgfTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSAiamEiOgogICAgICAgICAgICBjb25maWcgPSB7CiAgICAgICAgICAgICAgICBlbmFibGVEZWJ1ZzogIuODh+ODkOODg+OCsOODouODvOODiSIsCiAgICAgICAgICAgICAgICBkaXNhYmxlOiAi5LiA5pmC55qE44Gr54Sh5Yq5IiwKICAgICAgICAgICAgICAgIGRpc2FibGVTaXRlOiAi54Sh5Yq554q25oWL44Gu5YiH44KK5pu/44GIIiwKICAgICAgICAgICAgICAgIGRpc2FibGVTaXRlVGlwczogIuOBk+OBruOCteOCpOODiOOBp+aXouOBq+eEoeWKueOBq+OBquOBo+OBpuOBhOOBvuOBmSIsCiAgICAgICAgICAgICAgICBlbmFibGVTaXRlVGlwczogIuOBk+OBruOCteOCpOODiOOBp+aXouOBq+acieWKueOBq+OBquOBo+OBpuOBhOOBvuOBmSIsCiAgICAgICAgICAgICAgICBlbmFibGU6ICLjg5rjg7zjgrjjgoHjgY/jgorjgpLmnInlirnjgavjgZnjgosiLAogICAgICAgICAgICAgICAgdG9Ub3A6ICLjg4jjg4Pjg5fjgavmiLvjgosiLAogICAgICAgICAgICAgICAgdG9Cb3R0b206ICLjg5rjg7zjgrjjga7kuIvpg6jjgavnp7vli5UiLAogICAgICAgICAgICAgICAgY3VycmVudDogIuePvuWcqOOBruODmuODvOOCuCIsCiAgICAgICAgICAgICAgICBmb3JjZUlmcmFtZTogIuW8t+WItuOCueODhuODg+ODgSIsCiAgICAgICAgICAgICAgICBjYW5jZWxGb3JjZUlmcmFtZTogIuW8t+WItuOCueODhuODg+ODgeOCkuOCreODo+ODs+OCu+ODqyIsCiAgICAgICAgICAgICAgICBjb25maWd1cmU6ICLoqK3lrprjg5rjg7zjgrjjgpLplovjgY8iLAogICAgICAgICAgICAgICAgZmlyc3RVcGRhdGU6ICLjgZPjgZPjgpLjgq/jg6rjg4Pjgq/jgZfjgabjg6vjg7zjg6vjgpLliJ3mnJ/ljJbjgZfjgb7jgZkiLAogICAgICAgICAgICAgICAgdXBkYXRlOiAi5pu05paw44Or44O844OrIiwKICAgICAgICAgICAgICAgIGNsaWNrMnVwZGF0ZTogIuS7iuOBmeOBkOODq+ODvOODq+OCkuabtOaWsOOBl+OBpuOBj+OBoOOBleOBhCIsCiAgICAgICAgICAgICAgICBsb2FkTm93OiAi5LuK44GZ44GQ44Oa44O844K444KS44KB44GP44KLIiwKICAgICAgICAgICAgICAgIGxvYWRDb25maXJtOiAi5pWw44Oa44O844K444KB44GP44KK44Gf44GE44Gn44GZ44GL77yf77yIMOOBr+mAlOWIh+OCjOOBquOBhO+8iSIsCiAgICAgICAgICAgICAgICBub05leHQ6ICLmrKHjga7jg5rjg7zjgrjjgYzopovjgaTjgYvjgorjgb7jgZvjgpPjgIHmlrDjgZfjgYTjg6vjg7zjg6vjgpLkvZzmiJDjgZfjgabjgY/jgaDjgZXjgYQiLAogICAgICAgICAgICAgICAgcGFzc1NlYzogIiN0I+enkuWJjeOBq+abtOaWsCIsCiAgICAgICAgICAgICAgICBwYXNzTWluOiAiI3Qj5YiG5YmN44Gr5pu05pawIiwKICAgICAgICAgICAgICAgIHBhc3NIb3VyOiAiI3Qj5pmC6ZaT5YmN44Gr5pu05pawIiwKICAgICAgICAgICAgICAgIHBhc3NEYXk6ICIjdCPml6XliY3jgavmm7TmlrAiLAogICAgICAgICAgICAgICAgY2FudERlbDogIue1hOOBv+i+vOOBv+ODq+ODvOODq+OCkuWJiumZpOOBp+OBjeOBvuOBm+OCkyIsCiAgICAgICAgICAgICAgICBjb25maXJtRGVsOiAi44GT44Gu44Or44O844Or44KS5YmK6Zmk44GX44Gm44KC44KI44KN44GX44GE44Gn44GZ44GL77yfIiwKICAgICAgICAgICAgICAgIHVwZGF0ZVN1Y2M6ICLmm7TmlrDjgavmiJDlip/jgZfjgb7jgZfjgZ8iLAogICAgICAgICAgICAgICAgYmVnaW5VcGRhdGU6ICLmm7TmlrDkuK3jgIHjgYrlvoXjgaHjgY/jgaDjgZXjgYQiLAogICAgICAgICAgICAgICAgY3VzdG9tVXJsczogIuOCpOODs+ODneODvOODiOODq+ODvOODq+OBrlVSTOOAgTHooYzjgasx44GkIiwKICAgICAgICAgICAgICAgIGN1c3RvbVJ1bGVzOiAi44CQ5p2x5pa55rC46aCB5qmf44CR44Gu5b2i5byP44Gn44Kr44K544K/44Og44Or44O844Or44KS5YWl5Yqb44GX44Gm44GP44Gg44GV44GEIDxhIGhyZWY9JyN0Iyc+5a+E56i/44Or44O844OrPC9hPiIsCiAgICAgICAgICAgICAgICBzYXZlOiAi6Kit5a6a44KS5L+d5a2YIiwKICAgICAgICAgICAgICAgIGxvYWRpbmdUZXh0OiAi5bCR5aWz56WI56W35LitLi4uIiwKICAgICAgICAgICAgICAgIG9wYWNpdHk6ICLkuI3pgI/mmI7lgKQiLAogICAgICAgICAgICAgICAgb3BhY2l0eVBsYWNlaG9sZGVyOiAiMDog6Zqg44GZIiwKICAgICAgICAgICAgICAgIGhpZGVCYXI6ICLjg5rjg7zjgrjljLrliIfjgormloflrZfjgpLpnZ7ooajnpLrjgavjgZfjgb7jgZkiLAogICAgICAgICAgICAgICAgaGlkZUJhckJ1dE5vU3RvcDogIumdnuihqOekuuOBq+OBmeOCi+OBjOWBnOatouOBl+OBquOBhCIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3A6ICLnqbrnmb3pg6jliIbjgpLjg4Djg5bjg6vjgq/jg6rjg4Pjgq/jgZfjgabjg5rjg7zjgrjjgoHjgY/jgorjgpLkuIDmmYLlgZzmraLjgZfjgb7jgZkiLAogICAgICAgICAgICAgICAgc29ydFRpdGxlOiAi5Lim44G55pu/44GI44Gv44CB5qyh44Gu44Or44O844Or44Gu5pu05paw5b6M44Gr5pyJ5Yq544Gr44Gq44KK44G+44GZIiwKICAgICAgICAgICAgICAgIGF1dG9SdW46ICLoh6rli5XnmoTjgavmnInlirkiLAogICAgICAgICAgICAgICAgYXV0b0xvYWROdW06ICLmjIflrprjgZfjgZ/jg5rjg7zjgrjmlbDjgpLoh6rli5XnmoTjgavoqq3jgb/ovrzjgb/jgb7jgZkiLAogICAgICAgICAgICAgICAgdHVyblJhdGU6ICLjg5rjg7zjgrjjga7nq6/jgYvjgonjg5rjg7zjgrjjga7pq5jjgZXjga7jgJBY44CR5YCN44Gr44Gq44Gj44Gf44KJ44Oa44O844K444KS44KB44GP44KLIiwKICAgICAgICAgICAgICAgIGlucHV0UGFnZU51bTogIuOCuOODo+ODs+ODl+OBmeOCi+ODmuODvOOCuOeVquWPt+OCkuWFpeWKmyIsCiAgICAgICAgICAgICAgICBlbmFibGVIaXN0b3J5OiAi44Oa44O844K444KB44GP44KK5b6M44Gu5bGl5q2044KS5pu444GPIiwKICAgICAgICAgICAgICAgIGVuYWJsZUhpc3RvcnlBZnRlckluc2VydDogIuOCueODl+ODqeOCpOOCt+ODs+OCsOOBruebtOW+jOOBq+WxpeattOODrOOCs+ODvOODieOCkuabuOOBjei+vOOBv+OBvuOBmeOAguOBneOCjOS7peWkluOBruWgtOWQiOOBr+OAgemWsuimp+W+jOOBq+abuOOBjei+vOOBv+OBvuOBmSIsCiAgICAgICAgICAgICAgICBjb250ZW50VmlzaWJpbGl0eTogImNvbnRlbnRWaXNpYmlsaXR5IOOCkuiHquWLleeahOOBq+WIh+OCiuabv+OBiOOBpuODrOODs+ODgOODquODs+OCsCDjg5Hjg5Xjgqnjg7zjg57jg7PjgrnjgpLlkJHkuIrjgZXjgZvjgosiLAogICAgICAgICAgICAgICAgaW5pdFJ1bjogIldlYuODmuODvOOCuOOCkumWi+OBhOOBn+ebtOW+jOOBq+ODmuODvOOCuOOCkuOCgeOBj+OCiyIsCiAgICAgICAgICAgICAgICBwcmVsb2FkOiAi5LqL5YmN44Gr5qyh44Gu44Oa44O844K444KS6Kqt44KAIiwKICAgICAgICAgICAgICAgIGNsaWNrMkltcG9ydFJ1bGU6ICLku6XkuIvjgpLjgq/jg6rjg4Pjgq/jgZfjgabjgIHjg6vjg7zjg6vjg5njg7zjgrnjgpLov73liqDjgZfjgb7jgZnvvJoiLAogICAgICAgICAgICAgICAgZm9yY2VBbGxCb2R5OiAi44OV44Or44Oa44O844K45Z+L44KB6L6844G/77yfIiwKICAgICAgICAgICAgICAgIG9wZW5Jbk5ld1RhYjogIuOCueODl+ODqeOCpOOCueOBleOCjOOBn+ODmuODvOOCuOOBruOCs+ODs+ODhuODs+ODhOOCkuaWsOOBl+OBhOODmuODvOOCuOOBp+mWi+OBjeOBvuOBmSIsCiAgICAgICAgICAgICAgICBpbXBvcnRTdWNjOiAi44Kk44Oz44Od44O844OI5a6M5LqGIiwKICAgICAgICAgICAgICAgIGltcG9ydDogIuOCpOODs+ODneODvOODiCIsCiAgICAgICAgICAgICAgICBlZGl0Q3VycmVudDogIuePvuWcqOOBruODq+ODvOODq+OBrue3qOmbhiIsCiAgICAgICAgICAgICAgICBlZGl0QmxhY2tsaXN0OiAi44OW44Op44OD44Kv44Oq44K544OI44GuVVJM44KS57eo6ZuG44GX44CBMeihjOOBmuOBpOOAgeOCteODneODvOODiD8gKuODr+OCpOODq+ODieOCq+ODvOODiSIsCiAgICAgICAgICAgICAgICB1cEJ0bkltZzogIuODiOODg+ODl+OCouOCpOOCs+ODs+OBq+aIu+OCiyIsCiAgICAgICAgICAgICAgICBkb3duQnRuSW1nOiAi44OV44OD44K/44O844Ki44Kk44Kz44Oz44Gr56e75YuVIiwKICAgICAgICAgICAgICAgIHNpZGVDb250cm9sbGVySWNvbjogIuOCteOCpOODieODkOODvCDjgqLjgqTjgrPjg7MiLAogICAgICAgICAgICAgICAgbG9hZGluZ1RleHRUaXRsZTogIuODhuOCreOCueODiOOCkuODreODvOODiSIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3BDdHJsOiAiQ3RybOOCreODvCIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3BBbHQ6ICJBbHTjgq3jg7wiLAogICAgICAgICAgICAgICAgZGJDbGljazJTdG9wU2hpZnQ6ICJTaGlmdOOCreODvCIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3BNZXRhOiAiTWV0YeOCreODvCIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3BLZXk6ICJTaG9ydGN1dOOCreODvCIsCiAgICAgICAgICAgICAgICBwYWdlRWxlbWVudENzczogIuODmuODvOOCuOacrOaWh+ODleODrOODvOODoOOBriBTVFlMRSIsCiAgICAgICAgICAgICAgICBjdXN0b21Dc3M6ICLjgqvjgrnjgr/jg6AgY3NzIiwKICAgICAgICAgICAgICAgIGZpcnN0QWxlcnQ6ICLjg6vjg7zjg6vjg5njg7zjgrnjgpLjgqTjg7Pjg53jg7zjg4jjgZfjgabjgYTjgarjgYTjgZ/jgoHjgIHjgqTjg7Pjg53jg7zjg4jjgZnjgovpganliIfjgarjg6vjg7zjg6vjg5njg7zjgrnjgpLpgbjmip7jgZfjgabjgY/jgaDjgZXjgYQiLAogICAgICAgICAgICAgICAgcGlja2VyOiAiUGFnZXR1YWzjg5rjg7zjgrjopoHntKDjg5Tjg4Pjgqvjg7wiLAogICAgICAgICAgICAgICAgY2xvc2VQaWNrZXI6ICJQYWdldHVhbOODlOODg+OCq+ODvOOCkumWieOBmOOCiyIsCiAgICAgICAgICAgICAgICBwaWNrZXJQbGFjZWhvbGRlcjogIuOCj+OBi+OCieOBquOBhOWgtOWQiOOBr+epuuOBruOBvuOBvuOBq+OBl+OBpuOBj+OBoOOBleOBhCIsCiAgICAgICAgICAgICAgICBwaWNrZXJDaGVjazogIuOCu+ODrOOCr+OCv+ODvOOCkuODgeOCp+ODg+OCr+OBl+OBpuOCs+ODlOODvCIsCiAgICAgICAgICAgICAgICBzd2l0Y2hTZWxlY3RvcjogIuOCr+ODquODg+OCr+OBl+OBpuimgee0oOOCkuWIh+OCiuabv+OBiOOBvuOBmSIsCiAgICAgICAgICAgICAgICBnb3RvRWRpdDogIuePvuWcqOOBruOCu+ODrOOCr+OCv+ODvOOBp+ODq+ODvOODq+OCkue3qOmbhuOBmeOCiyIsCiAgICAgICAgICAgICAgICBtYW51YWxNb2RlOiAi44K544OX44Op44Kk44K344Oz44Kw44KS54Sh5Yq544Gr44GX44G+44GZ44CC5omL5YuV44Gn5Y+z44Gu55+i5Y2w44Kt44O844KS5L2/55So44GX44Gm44Oa44O844K444KS44KB44GP44KK44G+44GZIiwKICAgICAgICAgICAgICAgIGNsaWNrTW9kZTogIuOCueODhuOCo+ODg+ODgeODs+OCsOOCkueEoeWKueOBq+OBl+OBvuOBmeOAguODmuODvOOCuOOBruacgOW+jOOBvuOBp+OCueOCr+ODreODvOODq+OBmeOCi+OBqOOAgeasoeOBruODmuODvOOCuOOBjOiHquWLleeahOOBq+OCr+ODquODg+OCr+OBleOCjOOBvuOBmSIsCiAgICAgICAgICAgICAgICBwYWdlQmFyTWVudTogIuODmuODvOOCuOODkOODvOOBruS4reWkruOCkuOCr+ODquODg+OCr+OBl+OBpuODoeODi+ODpeODvOOCkuODneODg+ODl+OCouODg+ODl+ihqOekuiIsCiAgICAgICAgICAgICAgICBuZXh0U3dpdGNoOiAi5qyh44Gu44Oa44O844K444Gr5YiH44KK5pu/44GIIiwKICAgICAgICAgICAgICAgIGFycm93VG9TY3JvbGw6ICLlt6bnn6LljbDjgq3jg7zjgafliY3jgbjjgIHlj7Pnn6LljbDjgq3jg7zjgafmrKHjgbgiLAogICAgICAgICAgICAgICAgc2lkZUNvbnRyb2xsZXI6ICLjgrXjgqTjg4njg5Djg7zjgavjg5rjg7zjgrjjg7PjgrAg44Kz44Oz44OI44Ot44O844OrIOODkOODvOOCkuihqOekuuOBmeOCiyIsCiAgICAgICAgICAgICAgICBoaWRlTG9hZGluZ0ljb246ICLoqq3jgb/ovrzjgb/kuK3jga7jgqLjg4vjg6Hjg7zjgrfjg6fjg7PjgpLpmqDjgZkiLAogICAgICAgICAgICAgICAgaGlkZUJhckFycm93OiAi5YiG5Ymy57ea44Gu5L2N572u55+i5Y2w44KS6Zqg44GZIiwKICAgICAgICAgICAgICAgIGR1cGxpY2F0ZTogIlBhZ2V0dWFsIOOBrumHjeikh+OCpOODs+OCueODiOODvOODq+OBjOaknOWHuuOBleOCjOOBvuOBl+OBn+OAguS7luOBruOCueOCr+ODquODl+ODiCDjg57jg43jg7zjgrjjg6PjgafmsLjntprnmoTjgarjg5rjg7zjgrgg44Oe44K344Oz44KS5YmK6Zmk44GX44Gm44GP44Gg44GV44GEISIsCiAgICAgICAgICAgICAgICBmb3JjZVN0YXRlSWZyYW1lOiAiaWZyYW1lIOOBq+ODmuODvOOCuOWFqOS9k+OCkuWfi+OCgei+vOOCgCIsCiAgICAgICAgICAgICAgICBmb3JjZVN0YXRlRHluYW1pYzogImlmcmFtZSDntYznlLHjgafli5XnmoTjgrPjg7Pjg4bjg7Pjg4TjgpLoqq3jgb/ovrzjgoAiLAogICAgICAgICAgICAgICAgZm9yY2VTdGF0ZURpc2FibGU6ICLjgZPjga7jgrnjg4bjg7zjgrfjg6fjg7Pjgafjga7jg5rjg7zjgrjjgoHjgY/jgorjgpLnhKHlirnjgavjgZnjgosiLAogICAgICAgICAgICAgICAgYXV0b1Njcm9sbFJhdGU6ICLjgrnjgq/jg63jg7zjg6vpgJ/luqYgKDF+MTAwMCkiLAogICAgICAgICAgICAgICAgZGlzYWJsZUF1dG9TY3JvbGw6ICLoh6rli5Xjgrnjgq/jg63jg7zjg6vjgpLlgZzmraLjgZfjgb7jgZkiLAogICAgICAgICAgICAgICAgRW5hYmxlQXV0b1Njcm9sbDogIuiHquWLleOCueOCr+ODreODvOODq+OCkuacieWKueOBq+OBmeOCiyIsCiAgICAgICAgICAgICAgICB0b2dnbGVBdXRvU2Nyb2xsOiAi6Ieq5YuV44K544Kv44Ot44O844Or44Gu5YiH44KK5pu/44GIIiwKICAgICAgICAgICAgICAgIHBhZ2U6ICJQYWdlICIsCiAgICAgICAgICAgICAgICBwcmV2UGFnZTogIlByZXYgcGFnZSIsCiAgICAgICAgICAgICAgICBuZXh0UGFnZTogIk5leHQgcGFnZSIsCiAgICAgICAgICAgICAgICBlcnJvclJ1bGVzTXVzdEJlQXJyYXk6ICJSdWxlcyBtdXN0IGJlIGEgQXJyYXkhIiwKICAgICAgICAgICAgICAgIGVycm9ySnNvbjogIkpTT04gZXJyb3IsIGNoZWNrIGFnYWluISIsCiAgICAgICAgICAgICAgICBlZGl0U3VjY2VzczogIkVkaXQgc3VjY2Vzc2Z1bGx5IiwKICAgICAgICAgICAgICAgIGVycm9yV3JvbmdVcmw6ICJXcm9uZyB1cmwsIGNoZWNrIGFnYWluISIsCiAgICAgICAgICAgICAgICBlcnJvckFscmVhZHlFeGlzdHM6ICJBbHJlYWR5IGV4aXN0cyEiLAogICAgICAgICAgICAgICAgc2V0dGluZ3NTYXZlZDogIlRoZSBzZXR0aW5ncyBhcmUgc2F2ZWQsIHJlZnJlc2ggdG8gdmlldyIsCiAgICAgICAgICAgICAgICBpZnJhbWU6ICJJZnJhbWUiLAogICAgICAgICAgICAgICAgZHluYW1pYzogIkR5bmFtaWMiLAogICAgICAgICAgICAgICAgcmVsb2FkUGFnZTogIkVkaXQgY29tcGxldGVkLCByZWxvYWQgcGFnZSBub3c/IiwKICAgICAgICAgICAgICAgIGNvcGllZDogIkNvcGllZCIsCiAgICAgICAgICAgICAgICBub1ZhbGlkQ29udGVudDogIuacieWKueOBquOCs+ODs+ODhuODs+ODhOOBjOaknOWHuuOBleOCjOOBvuOBm+OCk+OBp+OBl+OBn+OAguOCr+ODquODg+OCr+OBl+OBpuihqOekuiIsCiAgICAgICAgICAgICAgICBvdXRPZkRhdGU6ICLjgrnjgq/jg6rjg5fjg4jjgYzlj6TjgY/jgarjgaPjgabjgYTjgb7jgZnjgILmnIDmlrDjg5Djg7zjgrjjg6fjg7Pjgavmm7TmlrDjgZfjgabjgY/jgaDjgZXjgYTjgIIiLAogICAgICAgICAgICAgICAgaGlkZUJhclRpcHM6ICLjg5rjg7zjgrjjg43jg7zjgrfjg6fjg7Mg44OQ44O844KS6Z2e6KGo56S644Gr44GX44G+44GZ44CC5rKh5YWl5Z6L44Ko44Kv44K544Oa44Oq44Ko44Oz44K5IiwKICAgICAgICAgICAgICAgIHNldENvbmZpZ1BhZ2U6ICLnj77lnKjjga7jg5rjg7zjgrjjgpLjg4fjg5Xjgqnjg6vjg4joqK3lrprjg5rjg7zjgrjjgajjgZfjgaboqK3lrpoiLAogICAgICAgICAgICAgICAgd2VkYXRhMmdpdGh1YjogIndlZGF0YSDjgqLjg4njg6zjgrnjgpIgZ2l0aHViIOOCpuOCp+OCouODj+OCpuOCueOBruODn+ODqeODvCDjgqLjg4njg6zjgrnjgavlpInmm7QiLAogICAgICAgICAgICAgICAgYWRkT3RoZXJQcm9wOiAi44Or44O844Or44OX44Ot44OR44OG44Kj44KS6L+95YqgIiwKICAgICAgICAgICAgICAgIGFkZE5leHRTZWxlY3RvcjogIuOCu+ODrOOCr+OCv+ODvOOBruOCs+ODs+ODhuODs+ODhOOCkiBuZXh0TGluayDjgajjgZfjgabov73liqAiLAogICAgICAgICAgICAgICAgYWRkUGFnZVNlbGVjdG9yOiAi44K744Os44Kv44K/IOOCs+ODs+ODhuODs+ODhOOCkiBwYWdlRWxlbWVudCDjgajjgZfjgabov73liqAiLAogICAgICAgICAgICAgICAgcHJvcE5hbWU6ICLjg6vjg7zjg6vjga7jg5fjg63jg5Hjg4bjgqPlkI3jgpLlhaXlipvjgZfjgabjgY/jgaDjgZXjgYQiLAogICAgICAgICAgICAgICAgcHJvcFZhbHVlOiAi44Or44O844Or44Gu44OX44Ot44OR44OG44Kj5YCk44KS5YWl5Yqb44GX44Gm44GP44Gg44GV44GEIgogICAgICAgICAgICB9OwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlICJydSI6CiAgICAgICAgY2FzZSAicnUtUlUiOgogICAgICAgICAgICBjb25maWcgPSB7CiAgICAgICAgICAgICAgICBlbmFibGVEZWJ1ZzogItCS0LrQu9GO0YfQuNGC0Ywg0L7RgtC70LDQtNC60YMiLAogICAgICAgICAgICAgICAgZGlzYWJsZTogItCS0YvQutC70Y7Rh9C40YLRjCIsCiAgICAgICAgICAgICAgICBkaXNhYmxlU2l0ZTogItCS0LrQu9GO0YfQuNGC0Ywv0LLRi9C60LvRjtGH0LjRgtGMINC90LAg0YHQsNC50YLQtSIsCiAgICAgICAgICAgICAgICBkaXNhYmxlU2l0ZVRpcHM6ICLQktGL0LrQu9GO0YfQtdC90L4g0LTQu9GPINGN0YLQvtCz0L4g0YHQsNC50YLQsCIsCiAgICAgICAgICAgICAgICBlbmFibGVTaXRlVGlwczogItCS0LrQu9GO0YfQtdC90L4g0LTQu9GPINGN0YLQvtCz0L4g0YHQsNC50YLQsCIsCiAgICAgICAgICAgICAgICBlbmFibGU6ICLQktC60LvRjtGH0LjRgtGMIiwKICAgICAgICAgICAgICAgIHRvVG9wOiAi0J3QsNCy0LXRgNGFIiwKICAgICAgICAgICAgICAgIHRvQm90dG9tOiAi0JLQvdC40LciLAogICAgICAgICAgICAgICAgY3VycmVudDogItCi0LXQutGD0YnQsNGPINGB0YLRgNCw0L3QuNGG0LAiLAogICAgICAgICAgICAgICAgZm9yY2VJZnJhbWU6ICLQn9C+0LTQs9GA0YPQt9C40YLRjCDQtdGJ0ZEg0YHRgtGA0LDQvdC40YbRgyIsCiAgICAgICAgICAgICAgICBjYW5jZWxGb3JjZUlmcmFtZTogItCe0YLQvNC10L3QuNGC0Ywg0L/QvtC00LPRgNGD0LfQutGDIiwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyZTogItCd0LDRgdGC0YDQvtC50LrQuCIsCiAgICAgICAgICAgICAgICBmaXJzdFVwZGF0ZTogItCd0LDQttC80LjRgtC1INC30LTQtdGB0YwsINGH0YLQvtCx0Ysg0LjQvdC40YbQuNCw0LvQuNC30LjRgNC+0LLQsNGC0Ywg0L/RgNCw0LLQuNC70LAiLAogICAgICAgICAgICAgICAgdXBkYXRlOiAi0J7QsdC90L7QstC40YLRjCDQv9GA0LDQstC40LvQsCIsCiAgICAgICAgICAgICAgICBjbGljazJ1cGRhdGU6ICLQndCw0LbQvNC40YLQtSwg0YfRgtC+0LHRiyDQvtCx0L3QvtCy0LjRgtGMINC/0YDQsNCy0LjQu9CwIiwKICAgICAgICAgICAgICAgIGxvYWROb3c6ICLQl9Cw0LPRgNGD0LfQuNGC0Ywg0YHQu9C10LTRg9GO0YnRg9GOINGB0YLRgNCw0L3QuNGG0YMiLAogICAgICAgICAgICAgICAgbG9hZENvbmZpcm06ICLQodC60L7Qu9GM0LrQviDRgdGC0YDQsNC90LjRhiDQstGLINGF0L7RgtC40YLQtSDQt9Cw0LPRgNGD0LfQuNGC0Yw/ICgwINC+0LfQvdCw0YfQsNC10YIg0LHQtdGB0LrQvtC90LXRh9C90L7RgdGC0YwpIiwKICAgICAgICAgICAgICAgIG5vTmV4dDogItCh0YHRi9C70LrQsCDQvdCwINGB0LvQtdC00YPRjtGJ0YPRjiDRgdGC0YDQsNC90LjRhtGDINC90LUg0L3QsNC50LTQtdC90LAuINCf0L7QttCw0LvRg9C50YHRgtCwLCDRgdC+0LfQtNCw0LnRgtC1INC90L7QstC+0LUg0L/RgNCw0LLQuNC70L4iLAogICAgICAgICAgICAgICAgcGFzc1NlYzogItCe0LHQvdC+0LLQu9C10L3QviAjdCMg0YHQtdC60YPQvdC0INC90LDQt9Cw0LQiLAogICAgICAgICAgICAgICAgcGFzc01pbjog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QvNC10L3QuNGC0Ywg0YfQtdGA0L3Ri9C5INGB0L/QuNGB0L7Qui4g0J7QtNC90LAg0YHRgdGL0LvQutCwINC90LAg0YHRgtGA0L7QutGDLiDQn9C+0LTQtNC10YDQttC40LLQsNGO0YLRgdGPINC80LXRgtCw0YHQuNC80LLQvtC70Ys6ID8g0LggKiIsCiAgICAgICAgICAgICAgICB1cEJ0bkltZzogItCY0LrQvtC90LrQsCDQv9C10YDQtdGF0L7QtNCwINC6INC90LDRh9Cw0LvRgyIsCiAgICAgICAgICAgICAgICBkb3duQnRuSW1nOiAi0JjQutC+0L3QutCwINC/0LXRgNC10YXQvtC00LAg0Log0LrQvtC90YbRgyIsCiAgICAgICAgICAgICAgICBzaWRlQ29udHJvbGxlckljb246ICLQl9C90LDRh9C+0Log0LHQvtC60L7QstC+0Lkg0L/QsNC90LXQu9C4IiwKICAgICAgICAgICAgICAgIGxvYWRpbmdUZXh0VGl0bGU6ICLQotC10LrRgdGCINCy0L4g0LLRgNC10LzRjyDQt9Cw0LPRgNGD0LfQutC4IiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcEN0cmw6ICJDdHJsIiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcEFsdDogIkFsdCIsCiAgICAgICAgICAgICAgICBkYkNsaWNrMlN0b3BTaGlmdDogIlNoaWZ0IiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcE1ldGE6ICJNZXRhIiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcEtleTogItCa0LvQsNCy0LjRiNCwIiwKICAgICAgICAgICAgICAgIHBhZ2VFbGVtZW50Q3NzOiAi0J/QvtC70YzQt9C+0LLQsNGC0LXQu9GM0YHQutC40Lkg0YHRgtC40LvRjCDQtNC70Y8g0L7RgdC90L7QstC90YvRhSDRjdC70LXQvNC10L3RgtC+0LIg0YHRgtGA0LDQvdC40YbRiyIsCiAgICAgICAgICAgICAgICBjdXN0b21Dc3M6ICLQn9C+0LvQv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dC/0LXRiNC90L4iLAogICAgICAgICAgICAgICAgZXJyb3JXcm9uZ1VybDogItCh0YHRi9C70LrQsCDQvdC10LrQvtGA0YDQtdC60YLQvdCwLiDQn9C+0LbQsNC70YPQudGB0YLQsCwg0LjRgdC/0YDQsNCy0YzRgtC1INC10ZEiLAogICAgICAgICAgICAgICAgZXJyb3JBbHJlYWR5RXhpc3RzOiAi0KPQttC1INGB0YPRidC10YHRgtCy0YPQtdGCISIsCiAgICAgICAgICAgICAgICBzZXR0aW5nc1NhdmVkOiAi0J3QsNGB0YLRgNC+0LnQutC4INGB0L7RhdGA0LDQvdC10L3Riy4g0J7QsdC90L7QstC40YLQtSDRgdGC0YDQsNC90LjRhtGLIiwKICAgICAgICAgICAgICAgIGlmcmFtZTogImlmcmFtZSIsCiAgICAgICAgICAgICAgICBkeW5hbWljOiAi0JTQuNC90LDQvNC40YfQtdGB0LrQuCIsCiAgICAgICAgICAgICAgICByZWxvYWRQYWdlOiAi0KDQtdC00LDQutGC0LjRgNC+0LLQsNC90LjQtSDQt9Cw0LLQtdGA0YjQtdC90L4uINCe0LHQvdC+0LLQuNGC0Ywg0YHRgtGA0LDQvdC40YbRgz8iLAogICAgICAgICAgICAgICAgY29waWVkOiAi0KHQutC+0L/QuNGA0L7QstCw0L3QviIsCiAgICAgICAgICAgICAgICBub1ZhbGlkQ29udGVudDogItCU0LXQudGB0YLQstC40YLQtdC70YzQvdGL0Lkg0LrQvtC90YLQtdC90YIg0L3QtSDQvtCx0L3QsNGA0YPQttC10L0sINC90LDQttC80LjRgtC1INC00LvRjyDQv9GA0L7RgdC80L7RgtGA0LAiLAogICAgICAgICAgICAgICAgb3V0T2ZEYXRlOiAi0KHQutGA0LjQv9GCINGD0YHRgtCw0YDQtdC7LCDRgdCy0L7QtdCy0YDQtdC80LXQvdC90L4g0L7QsdC90L7QstC70Y/QudGC0LUg0LTQviDQv9C+0YHQu9C10LTQvdC10Lkg0LLQtdGA0YHQuNC4ISIsCiAgICAgICAgICA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6ICLQktCy0LXQtNC40YLQtSDQt9C90LDRh9C10L3QuNC1INGB0LLQvtC50YHRgtCy0LAg0L/RgNCw0LLQuNC70LAiCiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIGNvbmZpZyA9IHsKICAgICAgICAgICAgICAgIGVuYWJsZURlYnVnOiAiRW5hYmxlIGRlYnVnIG91dHB1dCIsCiAgICAgICAgICAgICAgICBkaXNhYmxlOiAiRGlzYWJsZSIsCiAgICAgICAgICAgICAgICBkaXNhYmxlU2l0ZTogIlRvZ2dsZSBkaXNhYmxlZCBzdGF0ZSIsCiAgICAgICAgICAgICAgICBkaXNhYmxlU2l0ZVRpcHM6ICJEaXNhYmxlZCBvbiB0aGlzIHNpdGUiLAogICAgICAgICAgICAgICAgZW5hYmxlU2l0ZVRpcHM6ICJFbmFibGVkIG9uIHRoaXMgc2l0ZSIsCiAgICAgICAgICAgICAgICBlbmFibGU6ICJFbmFibGUiLAogICAgICAgICAgICAgICAgdG9Ub3A6ICJUbyBUb3AiLAogICAgICAgICAgICAgICAgdG9Cb3R0b206ICJUbyBCb3R0b20iLAogICAgICAgICAgICAgICAgY3VycmVudDogIkN1cnJlbnQgUGFnZSIsCiAgICAgICAgICAgICAgICBmb3JjZUlmcmFtZTogIkZvcmNlIHRvIGpvaW4gbmV4dCBwYWdlIiwKICAgICAgICAgICAgICAgIGNhbmNlbEZvcmNlSWZyYW1lOiAiQ2FuY2VsIEZvcmNlIGpvaW4iLAogICAgICAgICAgICAgICAgY29uZmlndXJlOiAiQ29uZmlndXJlIiwKICAgICAgICAgICAgICAgIGZpcnN0VXBkYXRlOiAiQ2xpY2sgaGVyZSB0byBpbml0aWFsaXplIHRoZSBydWxlcyIsCiAgICAgICAgICAgICAgICB1cGRhdGU6ICJVcGRhdGUgb25saW5lIHJ1bGVzIiwKICAgICAgICAgICAgICAgIGNsaWNrMnVwZGF0ZTogIkNsaWNrIHRvIHVwZGF0ZSBydWxlcyBmcm9tIHVybCBub3ciLAogICAgICAgICAgICAgICAgbG9hZE5vdzogIkxvYWQgbmV4dCBwYWdlIG1hbnVhbGx5IiwKICAgICAgICAgICAgICAgIGxvYWRDb25maXJtOiAiSG93IG11Y2ggcGFnZXMgZG8geW91IHdhbnQgdG8gbG9hZD8gKDAgbWVhbnMgaW5maW5pdGUpIiwKICAgICAgICAgICAgICAgIG5vTmV4dDogIk5vIG5leHQgbGluayBmb3VuZCwgcGxlYXNlIGNyZWF0ZSBhIG5ldyBydWxlIiwKICAgICAgICAgICAgICAgIHBhc3NTZWM6ICJVcGRhdGVkICN0IyBzZWNvbmRzIGFnbyIsCiAgICAgICAgICAgICAgICBwYXNzTWluOiAiVXBkYXRlZCAjdCMgbWludXRlcyBhZ28iLAogICAgICAgICAgICAgICAgcGFzc0hvdXI6ICJVcGRhdGVkICN0IyBob3VycyBhZ28iLAogICAgICAgICAgICAgICAgcGFzc0RheTogIlVwZGF0ZWQgI3QjIGRheXMgYWdvIiwKICAgICAgICAgICAgICAgIGNhbnREZWw6ICJDYW4ndCBkZWxldGUgYnVpbGRpbiBydWxlcyIsCiAgICAgICAgICAgICAgICBjb25maXJtRGVsOiAiQXJlIHlvdSBzdXJlIHlvdSB3YW50IHRvIGRlbGV0ZSB0aGlzIHJ1bGU/IiwKICAgICAgICAgICAgICAgIHVwZGF0ZVN1Y2M6ICJVcGRhdGUgc3VjY2VlZGVkIiwKICAgICAgICAgICAgICAgIGJlZ2luVXBkYXRlOiAiQmVnaW4gdXBkYXRlLCB3YWl0IGEgbWludXRlIHBsZWFzZSIsCiAgICAgICAgICAgICAgICBjdXN0b21VcmxzOiAiSW1wb3J0IFBhZ2V0dWFsIG9yIEF1dG9QYWdlcml6ZSBydWxlIHVybCwgT25lIHVybCBwZXIgbGluZSIsCiAgICAgICAgICAgICAgICBjdXN0b21SdWxlczogIklucHV0IGN1c3RvbSBydWxlcyB3aXRoIFtQYWdldHVhbF0gZm9ybWF0LiA8YSBocmVmPScjdCMnPkNvbnRyaWJ1dGUgcnVsZXM8L2E+IiwKICAgICAgICAgICAgICAgIHNhdmU6ICJTYXZlIiwKICAgICAgICAgICAgICAgIGxvYWRpbmdUZXh0OiAiU2hvam8gTm93IExvYWRpbmcuLi4iLAogICAgICAgICAgICAgICAgb3BhY2l0eTogIk9wYWNpdHkiLAogICAgICAgICAgICAgICAgb3BhY2l0eVBsYWNlaG9sZGVyOiAiMDogaGlkZSBzcGFjZXIiLAogICAgICAgICAgICAgICAgaGlkZUJhcjogIkhpZGUgdGhlIHBhZ2luZyBzcGFjZXIiLAogICAgICAgICAgICAgICAgaGlkZUJhckJ1dE5vU3RvcDogIkhpZGUgYnV0IG5vdCBzdG9wIiwKICAgICAgICAgICAgICAgIGRiQ2xpY2syU3RvcDogIkRvdWJsZS1jbGljayBvbiB0aGUgYmxhbmsgc3BhY2UgdG8gcGF1c2UiLAogICAgICAgICAgICAgICAgc29ydFRpdGxlOiAiU29ydGluZyB0YWtlcyBlZmZlY3QgYWZ0ZXIgdGhlIG5leHQgcnVsZSB1cGRhdGUiLAogICAgICAgICAgICAgICAgYXV0b1J1bjogIkF1dG8gcnVuIChibGFjayBsaXN0IG1vZGUpIiwKICAgICAgICAgICAgICAgIGF1dG9Mb2FkTnVtOiAiQW1vdW50IGZvciBwcmVsb2FkIHBhZ2VzIiwKICAgICAgICAgICAgICAgIHR1cm5SYXRlOiAiVHVybiB0aGUgbmV4dCBwYWdlIHdoZW4gaXQncyBsZXNzIHRoYW4g44CQWOOAkSB0aW1lcyBwYWdlIGhlaWdodCBmcm9tIHRoZSBmb290ZXIiLAogICAgICAgICAgICAgICAgaW5wdXRQYWdlTnVtOiAiRW50ZXIgcGFnZSBudW1iZXIgdG8ganVtcCIsCiAgICAgICAgICAgICAgICBlbmFibGVIaXN0b3J5OiAiV3JpdGUgaGlzdG9yeSBhZnRlciBwYWdlIHR1cm5pbmciLAogICAgICAgICAgICAgICAgZW5hYmxlSGlzdG9y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xlIHByb3BlcnR5IiwKICAgICAgICAgICAgICAgIGFkZE5leHRTZWxlY3RvcjogIkFkZCBzZWxlY3RvciBjb250ZW50IGFzIG5leHRMaW5rIiwKICAgICAgICAgICAgICAgIGFkZFBhZ2VTZWxlY3RvcjogIkFkZCBzZWxlY3RvciBjb250ZW50IGFzIHBhZ2VFbGVtZW50IiwKICAgICAgICAgICAgICAgIHByb3BOYW1lOiAiRW50ZXIgcnVsZSBwcm9wZXJ0eSBuYW1lIiwKICAgICAgICAgICAgICAgIHByb3BWYWx1ZTogIkVudGVyIHJ1bGUgcHJvcGVydHkgdmFsdWUiCiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGJyZWFrOwogICAgfQogICAgdmFyIGVuYWJsZURlYnVnID0gdHJ1ZTsKICAgIGZ1bmN0aW9uIGkxOG4obmFtZSwgcGFyYW0pIHsKICAgICAgICByZXR1cm4gY29uZmlnW25hbWVdID8gY29uZmlnW25hbWVdLnJlcGxhY2UoIiN0IyIsIHBhcmFtKSA6IG5hbWU7CiAgICB9OwoKICAgIGZ1bmN0aW9uIGRlYnVnKHN0ciwgdGl0bGUpIHsKICAgICAgICBpZiAoZW5hYmxlRGVidWcpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coCiAgICAgICAgICAgICAgICBgJWPjgJBQYWdldHVhbCB2LiR7X0dNX2luZm8uc2NyaXB0LnZlcnNpb25944CRICR7dGl0bGUgPyB0aXRsZSA6ICdkZWJ1Zyd9OmAsCiAgICAgICAgICAgICAgICAnY29sb3I6IHllbGxvdztmb250LXNpemU6IGxhcmdlO2ZvbnQtd2VpZ2h0OiBib2xkO2JhY2tncm91bmQtY29sb3I6IGRhcmtibHVlOycsCiAgICAgICAgICAgICAgICBzdHIKICAgICAgICAgICAgKTsKICAgICAgICB9CiAgICB9OwoKICAgIHZhciBfR01feG1saHR0cFJlcXVlc3QsIF9HTV9yZWdpc3Rlck1lbnVDb21tYW5kLCBfR01fbm90aWZpY2F0aW9uLCBfR01fYWRkU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dmdW5jdGlvbicgJiYgdHlwZW9mIEdNX2dldFZhbHVlKCdhJywgJ2InKSAhPSAndW5kZWZpbmVkJywKICAgICAgICBzdXBwb3J0R01Qcm9taXNlOiB0eXBlb2YgR00gIT0gJ3VuZGVmaW5lZCcgJiYgdHlwZW9mIEdNLmdldFZhbHVlID09ICdmdW5jdGlvbicgJiYgdHlwZW9mIEdNLmdldFZhbHVlKCdhJywgJ2InKSAhPSAndW5kZWZpbmVkJyAmJiB0eXBlb2YgR00uZ2V0VmFsdWUoJ2EnLCAnYicpLnRoZW4gPT0gJ2Z1bmN0aW9uJywKICAgICAgICBzdXBwb3J0Q3Jvc3NTYXZlOiBmdW5jdGlvbigpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuc3VwcG9ydEdNIHx8IHRoaXMuc3VwcG9ydEdNUHJvbWlzZTsKICAgICAgICB9LAogICAgICAgIG14QXBwU3RvcmFnZTogKGZ1bmN0aW9uKCkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgcmV0dXJuIHdpbmRvdy5leHRlcm5hbC5teEdldFJ1bnRpbWUoKS5zdG9yYWdlOwogICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgfQogICAgICAgIH0pKCksCiAgICAgICAgb3BlcmFVSlNTdG9yYWdlOiAoZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICByZXR1cm4gd2luZG93Lm9wZXJhLnNjcmlwdFN0b3JhZ2U7CiAgICAgICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICB9CiAgICAgICAgfSkoKSwKICAgICAgICBzZXRJdGVtOiBmdW5jdGlvbihrZXksIHZhbHVlKSB7CiAgICAgICAgICAgIGlmICh0aGlzLnN1cHBvcnRHTVByb21pc2UpIHsKICAgICAgICAgICAgICAgIEdNLnNldFZhbHVlKGtleSwgdmFsdWUpOwogICAgICAgICAgICAgICAgaWYgKHZhbHVlID09PSAiIiAmJiB0eXBlb2YgR00gIT0gJ3VuZGVmaW5lZCcgJiYgdHlwZW9mIEdNLmRlbGV0ZVZhbHVlICE9ICd1bmRlZmluZWQnKSB7CiAgICAgICAgICAgICAgICAgICAgR00uZGVsZXRlVmFsdWUoa2V5KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLnN1cHBvcnRHTSkgewogICAgICAgICAgICAgICAgR01fc2V0VmFsdWUoa2V5LCB2YWx1ZSk7CiAgICAgICAgICAgICAgICBpZiAodmFsdWUgPT09ICIiICYmIHR5cGVvZiBHTV9kZWxldGVWYWx1ZSAhPSAndW5kZWZpbmVkJykgewogICAgICAgICAgICAgICAgICAgIEdNX2RlbGV0ZVZhbHVlKGtleSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5vcGVyYVVKU1N0b3JhZ2UpIHsKICAgICAgICAgICAgICAgIHRoaXMub3BlcmFVSlNTdG9yYWdlLnNldEl0ZW0oa2V5LCB2YWx1ZSk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5teEFwcFN0b3JhZ2UpIHsKICAgICAgICAgICAgICAgIHRoaXMubXhBcHBTdG9yYWdlLnNldENvbmZpZyhrZXksIHZhbHVlKTsKICAgICAgICAgICAgfSBlbHNlIGlmICh3aW5kb3cubG9jYWxTdG9yYWdlKSB7CiAgICAgICAgICAgICAgICB3aW5kb3cubG9jYWxTdG9yYWdlLnNldEl0ZW0oa2V5LCB2YWx1ZSk7CiAgICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGdldEl0ZW06IGZ1bmN0aW9uKGtleSwgY2IpIHsKICAgICAgICAgICAgdmFyIHZhbHVlOwogICAgICAgICAgICBpZiAodGhpcy5zdXBwb3J0R01Qcm9taXNlKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSA9IEdNLmdldFZhbHVlKGtleSkudGhlbih2ID0+IHtjYih2KX0pOwogICAgICAgICAgICAgICAgcm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3VtZW50OwogICAgICAgIGNvbnRleHROb2RlID0gY29udGV4dE5vZGUgfHwgZG9jOwogICAgICAgIHZhciByZXN1bHQgPSBbXTsKICAgICAgICB0cnkgewogICAgICAgICAgICB2YXIgcXVlcnkgPSBkb2MuZXZhbHVhdGUoeHBhdGgsIGNvbnRleHROb2RlLCBudWxsLCBYUGF0aFJlc3VsdC5PUkRFUkVEX05PREVfU05BUFNIT1RfVFlQRSwgbnVsbCk7CiAgICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgcXVlcnkuc25hcHNob3RMZW5ndGg7IGkrKykgewogICAgICAgICAgICAgICAgdmFyIG5vZGUgPSBxdWVyeS5zbmFwc2hvdEl0ZW0oaSk7CiAgICAgICAgICAgICAgICBpZiAobm9kZS5ub2RlVHlwZSA9PT0gMSkgcmVzdWx0LnB1c2gobm9kZSk7CiAgICAgICAgICAgIH0KICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgZGVidWcoYEludmFsaWQgeHBhdGg6ICR7eHBhdGh9YCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICB9CgogICAgZnVuY3Rpb24gaXNYUGF0aCh4cGF0aCkgewogICAgICAgIGlmICgheHBhdGgpIHJldHVybiBmYWxzZTsKICAgICAgICByZXR1cm4gL15cKCooZGVzY2VuZGFudDo6fFwuXC98XC98aWRcKCkvLnRlc3QoeHBhdGgpOwogICAgfQoKICAgIGZ1bmN0aW9uIGdldEFsbEVsZW1lbnRzKHNlbCwgZG9jLCBjb250ZXh0Tm9kZSkgewogICAgICAgIHRyeSB7CiAgICAgICAgICAgIGlmICghaXNYUGF0aChzZWwpKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gZG9jLnF1ZXJ5U2VsZWN0b3JBbGwoc2VsKTsKICAgICAgICAgICAgfQogICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICBkZWJ1ZyhlLCAnRXJyb3Igc2VsZWN0b3InKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGdldEFsbEVsZW1lbnRzQnlYcGF0aChzZWwsIGNvbnRleHROb2RlLCBkb2MpOwogICAgfQoKICAgIGZ1bmN0aW9uIGdldEVsZW1lbnQoc2VsLCBkb2MsIGNvbnRleHROb2RlKSB7CiAgICAgICAgdHJ5IHsKICAgICAgICAgICAgaWYgKCFpc1hQYXRoKHNlbCkpIHsKICAgICAgICAgICAgICAgIHJldHVybiBkb2MucXVlcnlTZWxlY3RvcihzZWwpOwogICAgICAgICAgICB9CiAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgIGRlYnVnKGUsICdFcnJvciBzZWxlY3RvcicpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZ2V0RWxlbWVudEJ5WHBhdGgoc2VsLCBjb250ZXh0Tm9kZSwgZG9jKTsKICAgIH0KCiAgICBmdW5jdGlvbiBnZW5lU2VsZWN0b3IoZWxlLCBhZGRJRCkgewogICAgICAgIGxldCBzZWxlY3RvciA9IGVsZS5ub2RlTmFtZS50b0xvd2VyQ2FzZSgpOwogICAgICAgIC8vR29vZ2xlIGlkIGNsYXNz6YO95piv6Zqo5qmf44CC55m+5bqm5pu06YGO5YiG77yMc3R5bGUgc2NyaXB06aCG5bqP6YO95piv6Zqo5qmf55qECiAgICAgICAgaWYgKHNlbGVjdG9yICE9ICJodG1sIiAmJiBzZWxlY3RvciAhPSAiYm9keSIpIHsKICAgICAgICAgICAgbGV0IGhhc0lkID0gZmFsc2U7CiAgICAgICAgICAgIGlmIChhZGRJRCAmJiBlbGUuaWQgJiYgL15bYS16X11bXHdcLV9dKiQvaS50ZXN0KGVsZS5pZCkpIHsKICAgICAgICAgICAgICAgIGlmIChlbGUub3duZXJEb2N1bWVudCAmJiBlbGUub3duZXJEb2N1bWVudC5xdWVyeVNlbGVjdG9yQWxsKCIjIiArIGVsZS5pZCkubGVuZ3RoID09IDEpIHsKICAgICAgICAgICAgICAgICAgICBoYXNJZCA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgc2VsZWN0b3IgPSAnIycgKyBlbGUuaWQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCFoYXNJZCkgewogICAgICAgICAgICAgICAgbGV0IGNsYXNzTmFtZSA9ICIiOwogICAgICAgICAgICAgICAgaWYgKGVsZS5jbGFzc05hbWUpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgY2xhc3NMaXN0ID0gZWxlLmNsYXNzTGlzdCwgaSA9IDA7CiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBjbGFzc0xpc3QubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGMgPSBjbGFzc0xpc3RbaV07CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICgvXltcd1wtX10rJC8udGVzdChjKSAmJiAhL1xkezQsfS8udGVzdChjKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2xhc3NOYW1lICs9ICcuJyArIGM7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgc2VsZWN0b3IgKz0gY2xhc3NOYW1lOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgbGV0IHBhcmVudCA9IGVsZS5wYXJlbnRFbGVtZW50OwogICAgICAgICAgICAgICAgaWYgKHBhcmVudCkgewogICAgICAgICAgICAgICAgICAgIHNlbGVjdG9yID0gZ2VuZVNlbGVjdG9yKHBhcmVudCwgYWRkSUQpICsgJyA+ICcgKyBzZWxlY3RvcjsKICAgICAgICAgICAgICAgICAgICBpZiAoIWNsYXNzTmFtZSAmJiAhaGFzSWQgJiYgcGFyZW50LmNoaWxkcmVuLmxlbmd0aCA+IDEgJiYgIS9eSFRNTCQvaS50ZXN0KHBhcmVudC5ub2RlTmFtZSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGksIG50aCA9IDAsIGFsbCA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBwYXJlbnQuY2hpbGRyZW4ubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwYXJlbnQuY2hpbGRyZW5baV0ubm9kZU5hbWUgPT0gZWxlLm5vZGVOYW1lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYWxsKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBhcmVudC5jaGlsZHJlbltpXSA9PSBlbGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbnRoID0gYWxsOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobnRoID4gMCAmJiBhbGwgPiAxKSBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBzZWxlY3RvciArPSAoYWxsID09IDEgPyAiIiA6IGA6bnRoLW9mLXR5cGUoJHtudGh9KWApOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gc2VsZWN0b3I7CiAgICB9CgogICAgZnVuY3Rpb24gY3JlYXRlWFBhdGhGcm9tRWxlbWVudChlbG0pIHsKICAgICAgICBsZXQgYWxsTm9kZXMgPSBkb2N1bWVudC5nZXRFbGVtZW50c0J5VGFnTmFtZSgnKicpLCBzZWdzOwogICAgICAgIGZvciAoc2VncyA9IFtdOyBlbG0gJiYgZWxtLm5vZGVUeXBlID09IDE7IGVsbSA9IGVsbS5wYXJlbnROb2RlKSB7CiAgICAgICAgICAgIGlmICgvXihCT0RZfEhUTUwpJC9pLnRlc3QoZWxtLm5vZGVOYW1lKSkgewogICAgICAgICAgICAgICAgc2Vncy51bnNoaWZ0KGVsbS5sb2NhbE5hbWUudG9Mb3dlckNhc2UoKSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZWxtLmhhc0F0dHJpYnV0ZSAmJiBlbG0uaGFzQXR0cmlidXRlKCdpZCcpKSB7CiAgICAgICAgICAgICAgICB2YXIgdW5pcXVlSWRDb3VudCA9IDA7CiAgICAgICAgICAgICAgICBmb3IgKHZhciBuID0gMDsgbiA8IGFsbE5vZGVzLmxlbmd0aDsgbisrKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGFsbE5vZGVzW25dLmhhc0F0dHJpYnV0ZSgnaWQnKSAmJiBhbGxOb2Rlc1tuXS5pZCA9PSBlbG0uaWQpIHVuaXF1ZUlkQ291bnQrKzsKICAgICAgICAgICAgICAgICAgICBpZiAodW5pcXVlSWRDb3VudCA+IDEpIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKCB1bmlxdWVJZENvdW50ID09IDEpIHsKICAgICAgICAgICAgICAgICAgICBzZWdzLnVuc2hpZnQoJ2lkKCInICsgZWxtLmdldEF0dHJpYnV0ZSgnaWQnKSArICciKScpOwogICAgICAgICAgICAgICAgICAgIHJldHVybiBzZWdzLmpvaW4oJy8nKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgc2Vncy51bnNoaWZ0KGVsbS5sb2NhbE5hbWUudG9Mb3dlckNhc2UoKSArICdbQGlkPSInICsgZWxtLmdldEF0dHJpYnV0ZSgnaWQnKSArICciXScpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgaWYgKGVsbS5oYXNBdHRyaWJ1dGUgJiYgZWxtLmhhc0F0dHJpYnV0ZSgnY2xhc3MnKSkgewogICAgICAgICAgICAgICAgc2Vncy51bnNoaWZ0KGVsbS5sb2NhbE5hbWUudG9Mb3dlckNhc2UoKSArICdbQGNsYXNzPSInICsgZWxtLmdldEF0dHJpYnV0ZSgnY2xhc3MnKSArICciXScpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgbGV0IGksIHNpYjsKICAgICAgICAgICAgICAgIGZvciAoaSA9IDEsIHNpYiA9IGVsbS5wcmV2aW91c1NpYmxpbmc7IHNpYjsgc2liID0gc2liLnByZXZpb3VzU2libGluZykgewogICAgICAgICAgICAgICAgICAgIGlmIChzaWIubG9jYWxOYW1lID09IGVsbS5sb2NhbE5hbWUpIGkrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHNlZ3MudW5zaGlmdChlbG0ubG9jYWxOYW1lLnRvTG93ZXJDYXNlKCkgKyAnWycgKyBpICsgJ10nKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gc2Vncy5sZW5ndGggPyAnLycgKyBzZWdzLmpvaW4oJy8nKSA6IG51bGw7CiAgICB9CgogICAgY29uc3QgZXNjYXBlSFRNTFBvbGljeSA9IChfdW5zYWZlV2luZG93LnRydXN0ZWRUeXBlcyAmJiBfdW5zYWZlV2luZG93LnRydXN0ZWRUeXBlcy5jcmVhdGVQb2xpY3kpID8gX3Vuc2FmZVdpbmRvdy50cnVzdGVkVHlwZXMuY3JlYXRlUG9saWN5KCdwYWdldHVhbF9kZWZhdWx0JywgewogICAgICAgIGNyZWF0ZUhUTUw6IChzdHJpbmcsIHNpbmspID0+IHN0cmluZwogICAgfSkgOiBudWxsOwoKICAgIGZ1bmN0aW9uIGNyZWF0ZUhUTUwoaHRtbCkgewogICAgICAgIHJldHVybiBlc2NhcGVIVE1MUG9saWN5ID8gZXNjYXBlSFRNTFBvbGljeS5jcmVhdGVIVE1MKGh0bWwpIDogaHRtbDsKICAgIH0KCiAgICBjb25zdCBBc3luY0Z1bmN0aW9uID0gT2JqZWN0LmdldFByb3RvdHlwZU9mKGFzeW5jIGZ1bmN0aW9uKCl7fSkuY29uc3RydWN0b3I7CgogICAgYXN5bmMgZnVuY3Rpb24gc2xlZXAodGltZSkgewogICAgICAgIGF3YWl0IG5ldyBQcm9taXNlKChyZXNvbHZlKSA9PiB7CiAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgcmVzb2x2ZSgpOwogICAgICAgICAgICB9LCB0aW1lKTsKICAgICAgICB9KQogICAgfQoKICAgIGNsYXNzIFJ1bGVQYXJzZXIgewogICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgICB0aGlzLmhwUnVsZXMgPSBbXTsKICAgICAgICAgICAgdGhpcy5zbWFydFJ1bGVzID0gW107CiAgICAgICAgICAgIHRoaXMuY3VzdG9tUnVsZXMgPSBbXTsKICAgICAgICAgICAgdGhpcy5ydWxlcyA9IFtdOwogICAgICAgICAgICB0aGlzLnBhZ2VEb2MgPSBkb2N1bWVudDsKICAgICAgICAgICAgdGhpcy5uZXh0TGlua0hyZWYgPSBudWxsOwogICAgICAgICAgICB0aGlzLm5leHRUaXRsZSA9ICIiOwogICAgICAgICAgICB0aGlzLm9sZFVybCA9ICIiOwogICAgICAgICAgICB0aGlzLmN1clVybCA9IGxvY2F0aW9uLmhyZWY7CiAgICAgICAgICAgIHRoaXMuY3VyU2l0ZVJ1bGUgPSB7fTsKICAgICAgICB9CgogICAgICAgIGluaXRTYXZlZFJ1bGVzKGNhbGxiYWNrKSB7CiAgICAgICAgICAgIHZhciBzZWxmID0gdGhpczsKICAgICAgICAgICAgc3RvcmFnZS5nZXRJdGVtKCJzbWFydFJ1bGVzIiwgc21hcnRSdWxlcyA9PiB7CiAgICAgICAgICAgICAgICBpZiAoc21hcnRSdWxlcykgc2VsZi5zbWFydFJ1bGVzID0gc21hcnRSdWxlczsKICAgICAgICAgICAgICAgIHN0b3JhZ2UuZ2V0SXRlbSgiaHBSdWxlcyIsIGhwUnVsZXMgPT4gewogICAgICAgICAgICAgICAgICAgIGlmIChocFJ1bGVzKSBzZWxmLmhwUnVsZXMgPSBocFJ1bGVzOwogICAgICAgICAgICAgICAgICAgIHN0b3JhZ2UuZ2V0SXRlbSgiY3VzdG9tUnVsZXMiLCBjdXN0b21SdWxlcyA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXN0b21SdWxlcykgc2VsZi5jdXN0b21SdWxlcyA9IGN1c3RvbVJ1bGVzOwogICAgICAgICAgICAgICAgICAgICAgICBzdG9yYWdlLmdldEl0ZW0oInJ1bGVzIiwgcnVsZXMgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJ1bGVzKSBzZWxmLnJ1bGVzID0gcnVsZXM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjYWxsYmFjaygpOwogICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9KTsKICAgICAgICB9CgogICAgICAgIHNhdmVDdXJTaXRlUnVsZSgpIHsKICAgICAgICAgICAgLyppZighdGhpcy5jdXJTaXRlUnVsZSB8fCAhdGhpcy5jdXJTaXRlUnVsZS51cmwgfHwgdGhpcy5jdXJTaXRlUnVsZS5zaW5nbGVVcmwgfHwgdGhpcy5jdXJTaXRlUnVsZS51cmwubGVuZ3RoPDEzKXJldHVybjsKICAgICAgICAgICAgdGhpcy5ocFJ1bGVzPXRoaXMuaHBSdWxlcy5maWx0ZXIoaXRlbT0+e3JldHVybiBpdGVtJiZpdGVtLnVybCE9dGhpcy5jdXJTaXRlUnVsZS51cmx9KTsKICAgICAgICAgICAgdGhpcy5ocFJ1bGVzLnVuc2hpZnQodGhpcy5jdXJTaXRlUnVsZSk7CiAgICAgICAgICAgIGlmKHRoaXMuaHBSdWxlcy5sZW5ndGg+MzApewogICAgICAgICAgICAgICAgdGhpcy5ocFJ1bGVzLnBvcCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgiaHBSdWxlcyIsIHRoaXMuaHBSdWxlcyk7Ki8KICAgICAgICB9CgogICAgICAgIHJlcXVlc3RKU09OKHVybCwgY2FsbGJhY2spIHsKICAgICAgICAgICAgX0dNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgICAgIHVybDogdXJsLAogICAgICAgICAgICAgICAgbWV0aG9kOiAnR0VUJywKICAgICAgICAgICAgICAgIHRpbWVvdXQ6IDIwMDAwLAogICAgICAgICAgICAgICAgb25sb2FkOiBmdW5jdGlvbihyZXMpIHsKICAgICAgICAgICAgICAgICAgICBsZXQganNvbiA9IG51bGw7CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAganNvbiA9IEpTT04ucGFyc2UocmVzLnJlc3BvbnNlIHx8IHJlcy5yZXNwb25zZVRleHQpOwogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhlLCAnRXJyb3IganNvbicpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayhqc29uKTsKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICBvbmVycm9yOiBmdW5jdGlvbihlKSB7CiAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2sobnVsbCwgZSk7CiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgb250aW1lb3V0OiBmdW5jdGlvbihlKSB7CiAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2sobnVsbCwgZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pOwogICAgICAgIH0KCiAgICAgICAgZm9ybWF0UnVsZShpdGVtLCBmcm9tKSB7CiAgICAgICAgICAgIGlmIChpdGVtLmRhdGEgJiYgaXRlbS5kYXRhLnVybCkgewogICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IHsKICAgICAgICAgICAgICAgICAgICBuYW1lOiBpdGVtLm5hbWUsCiAgICAgICAgICAgICAgICAgICAgZnJvbTogZnJvbSwKICAgICAgICAgICAgICAgICAgICBhY3Rpb246IGl0ZW0uZGF0YS5mb3JjZUlmcmFtZT09InRydWUiPzE6dW5kZWZpbmVkLAogICAgICAgICAgICAgICAgICAgIHVybDogaXRlbS5kYXRhLnVybCwKICAgICAgICAgICAgICAgICAgICBwYWdlRWxlbWVudDogaXRlbS5kYXRhLnBhZ2VFbGVtZW50LAogICAgICAgICAgICAgICAgICAgIG5leHRMaW5rOiBpdGVtLmRhdGEubmV4dExpbmssCiAgICAgICAgICAgICAgICAgICAgaW5zZXJ0OiBpdGVtLmRhdGEuaW5zZXJ0QmVmb3JlfHx1bmRlZmluZWQsCiAgICAgICAgICAgICAgICAgICAgdXBkYXRlZEF0OiBpdGVtLnVwZGF0ZWRfYXQKICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICBsZXQgX2NzcyA9IChpdGVtLmRhdGEuU3R5bHVzIHx8ICcnKSArIChpdGVtLmRhdGEuQ1NTIHx8ICcnKTsKICAgICAgICAgICAgICAgIGlmIChfY3NzKSByZXN1bHQuY3NzID0gX2NzczsKICAgICAgICAgICAgICAgIGlmIChpdGVtLmRhdGEuYm9va21hcmtsZXQpIHJlc3VsdC5wYWdlQWN0aW9uID0gaXRlbS5kYXRhLmJvb2ttYXJrbGV0OwogICAgICAgICAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGl0ZW0uZnJvbSA9IGZyb207CiAgICAgICAgICAgICAgICByZXR1cm4gaXRlbTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgICAgICB9CgogICAgICAgIGFkZFJ1bGVCeVVybCh1cmwsIGZyb20sIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICh1cmwuaW5kZXhPZigiPyIpID09IC0xKSB7CiAgICAgICAgICAgICAgICB1cmwgPSB1cmwgKyAiPyIgKyBEYXRlLm5vdygpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdXJsID0gdXJsICsgIiYiICsgRGF0ZS5ub3coKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnJlcXVlc3RKU09OKHVybCwgKGpzb24sZXJyKSA9PiB7CiAgICAgICAgICAgICAgICBpZiAoIWpzb24pIHsKICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhlcnIsICJVcGRhdGUgIiArIHVybCArICIgcnVsZXMgZmFpbCEiKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRoaXMuYWRkUnVsZXMoanNvbiwgZnJvbSk7CiAgICAgICAgICAgICAgICBjYWxsYmFjayhqc29uLCBlcnIpOwogICAgICAgICAgICB9KTsKICAgICAgICB9CgogICAgICAgIGFkZFJ1bGVzKHJ1bGVzLCBmcm9tKSB7CiAgICAgICAgICAgIGlmIChydWxlcyAmJiBydWxlcy5sZW5ndGggPiAwKSB7CiAgICAgICAgICAgICAgICBsZXQgZmlyc3QgPSAtMTsKICAgICAgICAgICAgICAgIHRoaXMucnVsZXMgPSB0aGlzLnJ1bGVzLmZpbHRlcigoaXRlbSwgaSkgPT4gewogICAgICAgICAgICAgICAgICAgIGlmIChpdGVtLmZyb20gPT0gZnJvbSkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZmlyc3QgPT0gLTEpIGZpcnN0ID0gaTsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSByZXR1cm4gdHJ1ZTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgaWYgKGZpcnN0ID09IC0xKSBmaXJzdCA9IDA7CiAgICAgICAgICAgICAgICBydWxlcy5mb3JFYWNoKGl0ZW0gPT4gewogICAgICAgICAgICAgICAgICAgIGxldCBydWxlID0gdGhpcy5mb3JtYXRSdWxlKGl0ZW0sIGZyb20pOwogICAgICAgICAgICAgICAgICAgIGlmIChydWxlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucnVsZXMuc3BsaWNlKGZpcnN0LCAwLCBydWxlKQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBydWxlTWF0Y2hQcmUocikgewogICAgICAgICAgICBpZiAoci5pbmNsdWRlKSB7CiAgICAgICAgICAgICAgICBsZXQgaW5jbHVkZTsKICAgICAgICAgICAgICAgIGlmIChBcnJheSAmJiBBcnJheS5pc0FycmF5ICYmIEFycmF5LmlzQXJyYXkoci5pbmNsdWRlKSkgewogICAgICAgICAgICAgICAgICAgIGluY2x1ZGUgPSByLmluY2x1ZGUuZXZlcnkoKHNlbCwgaSkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZWxlID0gZ2V0RWxlbWVudChzZWwsIGRvY3VtZW50KTsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuICEhZWxlOwogICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgfSBlbHNlIGluY2x1ZGUgPSBnZXRFbGVtZW50KHIuaW5jbHVkZSwgZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgaWYgKCFpbmNsdWRlKSByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHIuZXhjbHVkZSkgewogICAgICAgICAgICAgICAgbGV0IGV4Y2x1ZGU7CiAgICAgICAgICAgICAgICBpZiAoQXJyYXkgJiYgQXJyYXkuaXNBcnJheSAmJiBBcnJheS5pc0FycmF5KHIuZXhjbHVkZSkpIHsKICAgICAgICAgICAgICAgICAgICBleGNsdWRlID0gIXIuZXhjbHVkZS5ldmVyeSgoc2VsLCBpKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBlbGUgPSBnZXRFbGVtZW50KHNlbCwgZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gIWVsZTsKICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIH0gZWxzZSBleGNsdWRlID0gZ2V0RWxlbWVudChyLmV4Y2x1ZGUsIGRvY3VtZW50KTsKICAgICAgICAgICAgICAgIGlmIChleGNsdWRlKSByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQoKICAgICAgICBydWxlTWF0Y2hSZWFkeShyKSB7CiAgICAgICAgICAgIGxldCBmaW5kSW5kZXggPSAwOwogICAgICAgICAgICBpZiAoci5uZXh0TGluayAmJiByLm5leHRMaW5rICE9IDApIHsKICAgICAgICAgICAgICAgIGxldCBuZXh0TGlua1NlbCA9IHIubmV4dExpbmssIG5leHRMaW5rOwogICAgICAgICAgICAgICAgaWYgKEFycmF5ICYmIEFycmF5LmlzQXJyYXkgJiYgQXJyYXkuaXNBcnJheShuZXh0TGlua1NlbCkpIHsKICAgICAgICAgICAgICAgICAgICBuZXh0TGluayA9ICFuZXh0TGlua1NlbC5ldmVyeSgoc2VsLCBpKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBlbGUgPSBnZXRFbGVtZW50KHNlbCwgZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZWxlKSBmaW5kSW5kZXggPSBpOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gIWVsZTsKICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIH0gZWxzZSBuZXh0TGluayA9IGdldEVsZW1lbnQobmV4dExpbmtTZWwsIGRvY3VtZW50KTsKICAgICAgICAgICAgICAgIGlmICghbmV4dExpbmspIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoci5wYWdlRWxlbWVudCkgewogICAgICAgICAgICAgICAgbGV0IHBhZ2VFbGVtZW50U2VsID0gci5wYWdlRWxlbWVudCwgcGFnZUVsZW1lbnQ7CiAgICAgICAgICAgICAgICBpZiAoQXJyYXkgJiYgQXJyYXkuaXNBcnJheSAmJiBBcnJheS5pc0FycmF5KHBhZ2VFbGVtZW50U2VsKSkgewogICAgICAgICAgICAgICAgICAgIHBhZ2VFbGVtZW50U2VsID0gcGFnZUVsZW1lbnRTZWxbZmluZEluZGV4XTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHBhZ2VFbGVtZW50ID0gZ2V0RWxlbWVudChwYWdlRWxlbWVudFNlbCwgZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgaWYgKCFwYWdlRWxlbWVudCkgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChyLmluc2VydCkgewogICAgICAgICAgICAgICAgbGV0IGluc2VydFNlbCA9IHIuaW5zZXJ0LCBpbnNlcnQ7CiAgICAgICAgICAgICAgICBpZiAoQXJyYXkgJiYgQXJyYXkuaXNBcnJheSAmJiBBcnJheS5pc0FycmF5KGluc2VydFNlbCkpIHsKICAgICAgICAgICAgICAgICAgICBpbnNlcnRTZWwgPSBpbnNlcnRTZWxbZmluZEluZGV4XTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGluc2VydCA9IGdldEVsZW1lbnQoaW5zZXJ0U2VsLCBkb2N1bWVudCk7CiAgICAgICAgICAgICAgICBpZiAoIWluc2VydCkgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIC8vaWYgKGZpbmRJbmRleCAhPT0gMCkgbmV4dEluZGV4ID0gZmluZEluZGV4OwogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CgogICAgICAgIHJ1bGVNYXRjaChyKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLnJ1bGVNYXRjaFByZShyKSAmJiB0aGlzLnJ1bGVNYXRjaFJlYWR5KHIpOwogICAgICAgIH0KCiAgICAgICAgc2Nyb2xsVG9TaG93KHNlbCwgZG9jKSB7CiAgICAgICAgICAgIGxldCBleGNsdWRlID0gZ2V0RWxlbWVudChzZWwsIGRvYyk7CiAgICAgICAgICAgIGlmIChleGNsdWRlKSB7CiAgICAgICAgICAgICAgICB2YXIgYWN0dWFsVG9wID0gZXhjbHVkZS5vZmZzZXRUb3A7CiAgICAgICAgICAgICAgICB2YXIgY3VycmVudCA9IGV4Y2x1ZGUub2Zmc2V0UGFyZW50OwogICAgICAgICAgICAgICAgd2hpbGUgKGN1cnJlbnQgIT09IG51bGwpIHsKICAgICAgICAgICAgICAgICAgICBhY3R1YWxUb3AgKz0gY3VycmVudC5vZmZzZXRUb3A7CiAgICAgICAgICAgICAgICAgICAgY3VycmVudCA9IGN1cnJlbnQub2Zmc2V0UGFyZW50OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZ2V0Qm9keShkb2MpLnNjcm9sbFRvcCA9IDA7CiAgICAgICAgICAgICAgICBkb2MuZG9jdW1lbnRFbGVtZW50LnNjcm9sbFRvcCA9IDA7CiAgICAgICAgICAgICAgICBsZXQgbWF4SGVpZ2h0ID0gTWF0aC5tYXgoZ2V0Qm9keShkb2MpLnNjcm9sbEhlaWdodCwgZG9jLmRvY3VtZW50RWxlbWVudC5zY3JvbGxIZWlnaHQpOwogICAgICAgICAgICAgICAgZ2V0Qm9keShkb2MpLnNjcm9sbFRvcCA9IGFjdHVhbFRvcCAtIDEwOwogICAgICAgICAgICAgICAgZG9jLmRvY3VtZW50RWxlbWVudC5zY3JvbGxUb3AgPSBhY3R1YWxUb3AgLSAxMDsKICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIHdoaWxlIChhY3R1YWxUb3AgPCBtYXhIZWlnaHQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgYWN0dWFsVG9wICs9IDIwMDsKICAgICAgICAgICAgICAgICAgICAgICAgZ2V0Qm9keShkb2MpLnNjcm9sbFRvcCA9IGFjdHVhbFRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgZG9jLmRvY3VtZW50RWxlbWVudC5zY3JvbGxUb3AgPSBhY3R1YWxUb3A7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSwgMCk7CiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQoKICAgICAgICB3YWl0RWxlbWVudChkb2MsIHNlbEFycikgewogICAgICAgICAgICBpZiAoIXNlbEFycikgc2VsQXJyID0gdGhpcy5jdXJTaXRlUnVsZS53YWl0RWxlbWVudDsKICAgICAgICAgICAgaWYgKCFBcnJheS5pc0FycmF5KHNlbEFycikpIHsKICAgICAgICAgICAgICAgIHNlbEFyciA9IFtzZWxBcnJdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxldCBpbmNsdWRlU2VsID0gc2VsQXJyWzBdLnRyaW0oKSwgZXhjbHVkZVNlbDsKICAgICAgICAgICAgaWYgKHNlbEFyci5sZW5ndGggPT0gMikgewogICAgICAgICAgICAgICAgZXhjbHVkZVNlbCA9IHNlbEFyclsxXS50cmltKCkucmVwbGFjZSgvXiEvLCAnJyk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaW5jbHVkZVNlbC5pbmRleE9mKCchJykgPT0gMCkgewogICAgICAgICAgICAgICAgZXhjbHVkZVNlbCA9IGluY2x1ZGVTZWwucmVwbGFjZSgvXiEvLCAnJyk7CiAgICAgICAgICAgICAgICBpbmNsdWRlU2VsID0gJyc7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGluY2x1ZGVTZWwpIHsKICAgICAgICAgICAgICAgIGxldCBpbmNsdWRlID0gZ2V0RWxlbWVudChpbmNsdWRlU2VsLCBkb2MpOwogICAgICAgICAgICAgICAgaWYgKCFpbmNsdWRlKSB7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChkb2MgPT09IGRvY3VtZW50KSByZXR1cm4gdHJ1ZTsKICAgICAgICAgICAgaWYgKGV4Y2x1ZGVTZWwpIHsKICAgICAgICAgICAgICAgIGlmICghdGhpcy5zY3JvbGxUb1Nob3coZXhjbHVkZVNlbCwgZG9jKSkgewogICAgICAgICAgICAgICAgICAgIGlmICghbG9hZGluZ0Rpdi5vZmZzZXRQYXJlbnQgJiYgdGhpcy5pbnNlcnQucGFyZW50Tm9kZSkgewogICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmluc2VydEVsZW1lbnQobG9hZGluZ0Rpdik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CgogICAgICAgIGdldFJ1bGUoY2FsbGJhY2spIHsKICAgICAgICAgICAgaWYobm9SdWxlVGVzdCkgewogICAgICAgICAgICAgICAgdGhpcy5jdXJTaXRlUnVsZSA9IHt9OwogICAgICAgICAgICAgICAgdGhpcy5jdXJTaXRlUnVsZS51cmwgPSBsb2NhdGlvbi5vcmlnaW4gKyBsb2NhdGlvbi5wYXRobmFtZTsKICAgICAgICAgICAgICAgIHRoaXMuY3VyU2l0ZVJ1bGUuc2luZ2xlVXJsID0gdHJ1ZTsKICAgICAgICAgICAgICAgIGNhbGxiYWNrKCk7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGhyZWYgPSBsb2NhdGlvbi5ocmVmLnNsaWNlKDAsIDUwMCk7CiAgICAgICAgICAgIGlmICh0aGlzLmN1clNpdGVSdWxlICYmIHRoaXMuY3VyU2l0ZVJ1bGUudXJsICYmICF0aGlzLmN1clNpdGVSdWxlLnNpbmdsZVVybCkgewogICAgICAgICAgICAgICAgbGV0IHVybFJlZyA9IG5ldyBSZWdFeHAodGhpcy5jdXJTaXRlUnVsZS51cmwsICJpIik7CiAgICAgICAgICAgICAgICBpZiAodXJsUmVnLnRlc3QoaHJlZikgJiYgdGhpcy5ydWxlTWF0Y2godGhpcy5jdXJTaXRlUnVsZSkpIHsKICAgICAgICAgICAgICAgICAgICByZXR1cm4gY2FsbGJhY2soKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodGhpcy5wb3NzaWJsZVJ1bGUpIHsKICAgICAgICAgICAgICAgIGxldCB1cmxSZWcgPSBuZXcgUmVnRXhwKHRoaXMucG9zc2libGVSdWxlLnVybCwgImkiKTsKICAgICAgICAgICAgICAgIGlmICh1cmxSZWcudGVzdChocmVmKSAmJiB0aGlzLnJ1bGVNYXRjaCh0aGlzLnBvc3NpYmxlUnVsZSkpIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLmN1clNpdGVSdWxlID0gdGhpcy5wb3NzaWJsZVJ1bGU7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNhbGxiYWNrKCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5jdXJTaXRlUnVsZSA9IHt9OwogICAgICAgICAgICB2YXIgc2VsZiA9IHRoaXM7CgogICAgICAgICAgICBmdW5jdGlvbiBzZXRSdWxlKHIpIHsKICAgICAgICAgICAgICAgIGlmIChzZWxmLnByZVNpdGVSdWxlKSB7CiAgICAgICAgICAgICAgICAgICAgaHJlZiA9IGxvY2F0aW9uLmhyZWYuc2xpY2UoMCwgNTAwKTsKICAgICAgICAgICAgICAgICAgICBsZXQgdXJsUmVnID0gbmV3IFJlZ0V4cChzZWxmLnByZVNpdGVSdWxlLnVybCwgImkiKTsKICAgICAgICAgICAgICAgICAgICBpZiAodXJsUmVnLnRlc3QoaHJlZikgJiYgc2VsZi5ydWxlTWF0Y2goc2VsZi5wcmVTaXRlUnVsZSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5jdXJTaXRlUnVsZSA9IHNlbGYucHJlU2l0ZVJ1bGU7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjaygpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICghci5zaW5nbGVVcmwpIHsKICAgICAgICAgICAgICAgICAgICBzZWxmLmN1clNpdGVSdWxlID0gcjsKICAgICAgICAgICAgICAgICAgICBzZWxmLnByZVNpdGVSdWxlID0gcjsKICAgICAgICAgICAgICAgICAgICBpZiAoci5lbmFibGUgIT09IDApIGRlYnVnKHIsICdNYXRjaCBydWxlJyk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKCFzZWxmLmN1clNpdGVSdWxlIHx8ICFzZWxmLmN1clNpdGVSdWxlLnNpbmdsZVVybCkgc2VsZi5jdXJTaXRlUnVsZSA9IHI7CiAgICAgICAgICAgICAgICBjYWxsYmFjaygpOwogICAgICAgICAgICB9CgogICAgICAgICAgICBmdW5jdGlvbiBjaGVja1J1bGUocikgewogICAgICAgICAgICAgICAgaWYgKHIuZnJvbSA9PSAxICYmIHIudXJsLmxlbmd0aCA8PSAxMykgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgICAgbGV0IHVybFJlZyA9IG5ldyBSZWdFeHAoci51cmwsICJpIik7CiAgICAgICAgICAgICAgICBpZiAodXJsUmVnLnRlc3QoaHJlZikpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoIXNlbGYucnVsZU1hdGNoUHJlKHIpKSByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgaWYgKHIudXJsLmxlbmd0aCA+IDE1KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYucG9zc2libGVSdWxlID0gcjsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKHIud2FpdEVsZW1lbnQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHdhaXRUaW1lID0gNTAwOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgY2hlY2tSZWFkeSA9ICgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICghc2VsZi53YWl0RWxlbWVudChkb2N1bWVudCwgci53YWl0RWxlbWVudCkgfHwgIXNlbGYucnVsZU1hdGNoUmVhZHkocikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tSZWFkeSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNldFJ1bGUocik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSwgcGFyc2VJbnQod2FpdFRpbWUpKTsKICAgICAgICAgICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tSZWFkeSgpOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHIud2FpdCkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgd2FpdFRpbWUgPSA1MDAsIGNoZWNrRXZhbCwgbWF4Q2hlY2tUaW1lcyA9IDUwOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNOYU4oci53YWl0KSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGVja0V2YWwgPSAodHlwZW9mIF91bnNhZmVXaW5kb3cucGFnZXR1YWxXYWl0ID09ICd1bmRlZmluZWQnKSA/IEZ1bmN0aW9uKCJkb2MiLCcidXNlIHN0cmljdCI7JyArIHIud2FpdCkgOiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsV2FpdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGUsICdFcnJvciB3aGVuIGNoZWNrZXZhbCcpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgd2FpdFRpbWUgPSByLndhaXQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGNoZWNrUmVhZHkgPSAoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobWF4Q2hlY2tUaW1lcy0tIDw9IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWJ1ZygiV2FpdCBmb3IgcnVsZSByZWFkeSBidXQgZmFpbGVkIik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2V0UnVsZShyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXNlbGYucnVsZU1hdGNoUmVhZHkocikgfHwgKGNoZWNrRXZhbCAmJiAhY2hlY2tFdmFsKGRvY3VtZW50KSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tSZWFkeSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNldFJ1bGUocik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSwgcGFyc2VJbnQod2FpdFRpbWUpKTsKICAgICAgICAgICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tSZWFkeSgpOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKHIucGluVXJsKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNldFJ1bGUocik7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoIXNlbGYucnVsZU1hdGNoUmVhZHkocikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBzZXRSdWxlKHIpOwogICAgICAgICAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICB9CgogICAgICAgICAgICBmb3IgKGxldCBpIGluIHRoaXMuaHBSdWxlcykgewogICAgICAgICAgICAgICAgbGV0IHJ1bGUgPSB0aGlzLmhwUnVsZXNbaV07CiAgICAgICAgICAgICAgICBpZiAoIXJ1bGUgfHwgIXJ1bGUudXJsKSBjb250aW51ZTsKICAgICAgICAgICAgICAgIGlmIChydWxlLnNpbmdsZVVybCkgewogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGNoZWNrUnVsZShydWxlKSkgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGZvciAobGV0IGkgaW4gdGhpcy5jdXN0b21SdWxlcykgewogICAgICAgICAgICAgICAgbGV0IHJ1bGUgPSB0aGlzLmN1c3RvbVJ1bGVzW2ldOwogICAgICAgICAgICAgICAgaWYgKCFydWxlIHx8ICFydWxlLnVybCkgY29udGludWU7CiAgICAgICAgICAgICAgICBpZiAoY2hlY2tSdWxlKHJ1bGUpKSByZXR1cm47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yIChsZXQgaSBpbiB0aGlzLnNtYXJ0UnVsZXMpIHsKICAgICAgICAgICAgICAgIGxldCBydWxlID0gdGhpcy5zbWFydFJ1bGVzW2ldOwogICAgICAgICAgICAgICAgaWYgKCFydWxlIHx8ICFydWxlLnVybCkgY29udGludWU7CiAgICAgICAgICAgICAgICBpZiAocnVsZS5zaW5nbGVVcmwpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgc2luZ2xlVXJsID0gbG9jYXRpb24ub3JpZ2luICsgbG9jYXRpb24ucGF0aG5hbWU7CiAgICAgICAgICAgICAgICAgICAgaWYgKHNpbmdsZVVybCA9PSBydWxlLnVybCkgewogICAgICAgICAgICAgICAgICAgICAgICBzZXRSdWxlKHJ1bGUpOwogICAgICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayA9ICgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzZWxmLmN1clNpdGVSdWxlICYmICFzZWxmLmN1clNpdGVSdWxlLnNpbmdsZVVybCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuc21hcnRSdWxlcyA9IHNlbGYuc21hcnRSdWxlcy5maWx0ZXIoaXRlbSA9PiB7cmV0dXJuIGl0ZW0gJiYgaXRlbS51cmwgIT0gc2luZ2xlVXJsfSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJzbWFydFJ1bGVzIiwgc2VsZi5zbWFydFJ1bGVzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoc2VsZi5jdXJTaXRlUnVsZS51cmwubGVuZ3RoID4gMTMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5hZGRUb0hwUnVsZXMoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBsZXQgciA9IDA7CiAgICAgICAgICAgIGZ1bmN0aW9uIHNlYXJjaEJ5VGltZSgpIHsKICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIGxldCBlbmQgPSByICsgNTA7CiAgICAgICAgICAgICAgICAgICAgZW5kID0gZW5kID4gc2VsZi5ydWxlcy5sZW5ndGggPyBzZWxmLnJ1bGVzLmxlbmd0aCA6IGVuZDsKICAgICAgICAgICAgICAgICAgICBmb3IgKDsgciA8IGVuZDsgcisrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBydWxlID0gc2VsZi5ydWxlc1tyXTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJ1bGUuZnJvbSA9PSAyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWxldGUgcnVsZS5hdXRvTG9hZE51bTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlbGV0ZSBydWxlLmhpc3Rvcnk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWxldGUgcnVsZS5zaWRlQ29udHJvbGxlcjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChydWxlLnBhZ2VCYXIgPT0gMCkgZGVsZXRlIHJ1bGUucGFnZUJhcjsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoY2hlY2tSdWxlKHJ1bGUpKSByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChlbmQgPj0gc2VsZi5ydWxlcy5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgc2V0UnVsZSh7dXJsOiBsb2NhdGlvbi5vcmlnaW4gKyBsb2NhdGlvbi5wYXRobmFtZSwgc2luZ2xlVXJsOiB0cnVlfSk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzZWFyY2hCeVRpbWUoKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9LCAxKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzZWFyY2hCeVRpbWUoKTsKICAgICAgICB9CgogICAgICAgIGFkZFRvSHBSdWxlcyhpbnN0ZWFkKSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuaHBSdWxlcykgdGhpcy5ocFJ1bGVzID0gW107CiAgICAgICAgICAgICAgICBsZXQgdXJsID0gdGhpcy5jdXJTaXRlUnVsZSAmJiB0aGlzLmN1clNpdGVSdWxlLnVybCwgc2VsZiA9IHRoaXM7CiAgICAgICAgICAgICAgICBsZXQgaHJlZiA9IGxvY2F0aW9uLmhyZWYuc2xpY2UoMCwgNTAwKTsKICAgICAgICAgICAgICAgIGxldCBtYXRjaGVkUnVsZXMgPSB0aGlzLmhwUnVsZXMuZmlsdGVyKHJ1bGUgPT4gcnVsZSAhPSBzZWxmLmN1clNpdGVSdWxlICYmIG5ldyBSZWdFeHAocnVsZS51cmwsICJpIikudGVzdChocmVmKSAmJiBzZWxmLnJ1bGVNYXRjaChydWxlKSk7CiAgICAgICAgICAgICAgICBpZiAodXJsKSBtYXRjaGVkUnVsZXMucHVzaCh0aGlzLmN1clNpdGVSdWxlKTsKICAgICAgICAgICAgICAgIG1hdGNoZWRSdWxlcy5zb3J0KChhLCBiKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgaWYgKChhLmluY2x1ZGUgfHwgYS5leGNsdWRlKSAmJiAoIWIuaW5jbHVkZSAmJiAhYi5leGNsdWRlKSkgewogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICgoYi5pbmNsdWRlIHx8IGIuZXhjbHVkZSkgJiYgKCFhLmluY2x1ZGUgJiYgIWEuZXhjbHVkZSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKChhLm5leHRMaW5rIHx8IGEucGFnZUVsZW1lbnQpICYmICghYi5uZXh0TGluayAmJiAhYi5wYWdlRWxlbWVudCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICgoYi5uZXh0TGluayB8fCBiLnBhZ2VFbGVtZW50KSAmJiAoIWEubmV4dExpbmsgJiYgIWEucGFnZUVsZW1lbnQpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhLnVybC5sZW5ndGggPiBiLnVybC5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGEudXJsLmxlbmd0aCA8IGIudXJsLmxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgdGhpcy5ocFJ1bGVzID0gdGhpcy5ocFJ1bGVzLmZpbHRlcihpdGVtID0+IHsKICAgICAgICAgICAgICAgICAgICByZXR1cm4gaXRlbSAmJiAhbWF0Y2hlZFJ1bGVzLmZpbmQocnVsZSA9PiBpdGVtLnVybCA9PSBydWxlLnVybCAmJiBKU09OLnN0cmluZ2lmeShpdGVtKSA9PSBKU09OLnN0cmluZ2lmeShydWxlKSk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIGlmIChpbnN0ZWFkKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHVybCkgdGhpcy5ocFJ1bGVzLnVuc2hpZnQodGhpcy5jdXJTaXRlUnVsZSk7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHRoaXMuaHBSdWxlcyA9IG1hdGNoZWRSdWxlcy5jb25jYXQodGhpcy5ocFJ1bGVzKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChtYXRjaGVkUnVsZXMgJiYgbWF0Y2hlZFJ1bGVzLmxlbmd0aCkgdGhpcy5jdXJTaXRlUnVsZSA9IG1hdGNoZWRSdWxlc1swXTsKICAgICAgICAgICAgICAgIGlmICh0aGlzLmhwUnVsZXMubGVuZ3RoID4gMzApIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLmhwUnVsZXMucG9wKCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oImhwUnVsZXMiLCB0aGlzLmhwUnVsZXMpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBkZWJ1ZyhlKTsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgcmVwbGFjZUVsZW1lbnQoZG9jKSB7CiAgICAgICAgICAgIGlmICghZG9jIHx8IGRvYyA9PT0gZG9jdW1lbnQpIHJldHVybjsKICAgICAgICAgICAgbGV0IHJlcGxhY2VFbGVtZW50U2VsID0gdGhpcy5jdXJTaXRlUnVsZS5yZXBsYWNlRWxlbWVudDsKICAgICAgICAgICAgaWYgKHJlcGxhY2VFbGVtZW50U2VsKSB7CiAgICAgICAgICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkocmVwbGFjZUVsZW1lbnRTZWwpKSB7CiAgICAgICAgICAgICAgICAgICAgcmVwbGFjZUVsZW1lbnRTZWwgPSBbcmVwbGFjZUVsZW1lbnRTZWxdOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcmVwbGFjZUVsZW1lbnRTZWwuZm9yRWFjaChzZWwgPT4gewogICAgICAgICAgICAgICAgICAgIGxldCBwYWdlRWxlcyA9IGdldEFsbEVsZW1lbnRzKHNlbCwgZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgICAgIGxldCByZXBsYWNlRWxlcyA9IGdldEFsbEVsZW1lbnRzKHNlbCwgZG9jKTsKICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHBhZ2VFbGVzLmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCByZXBsYWNlRWxlID0gcmVwbGFjZUVsZXNbaV07CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBwYWdlRWxlID0gcGFnZUVsZXNbaV07CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZXBsYWNlRWxlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYWdlRWxlLnBhcmVudE5vZGUucmVwbGFjZUNoaWxkKHJlcGxhY2VFbGUuY2xvbmVOb2RlKHRydWUpLCBwYWdlRWxlKTsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICByZWZyZXNoQnlDbGljaygpIHsKICAgICAgICAgICAgbGV0IHJlZnJlc2hCeUNsaWNrU2VsID0gdGhpcy5jdXJTaXRlUnVsZS5yZWZyZXNoQnlDbGljazsKICAgICAgICAgICAgaWYgKHJlZnJlc2hCeUNsaWNrU2VsKSB7CiAgICAgICAgICAgICAgICBsZXQgc2VsZiA9IHRoaXM7CiAgICAgICAgICAgICAgICBkb2N1bWVudC5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgICAgIGlmICghc2VsZi5yZWZyZXNoaW5nKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYucmVmcmVzaGluZyA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5yZWZyZXNoaW5nID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgY2hlY2tFbGVzID0gZ2V0QWxsRWxlbWVudHMocmVmcmVzaEJ5Q2xpY2tTZWwsIGRvY3VtZW50KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgY2hlY2tFbGVzLmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNoZWNrRWxlc1tpXSA9PT0gZS50YXJnZXQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdXJsQ2hhbmdlZCA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzUGF1c2UgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXJ1bGVQYXJzZXIubmV4dExpbmtIcmVmKSBpc0xvYWRpbmcgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9LCAzMDApOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBnZXRWYWxpZEhlaWdodChlbGUsIHdpbikgewogICAgICAgICAgICBpZiAoIWVsZS5vZmZzZXRQYXJlbnQpIHJldHVybiAwOwogICAgICAgICAgICBsZXQgaCA9IGVsZS5zY3JvbGxIZWlnaHQ7CiAgICAgICAgICAgIGlmICh3aW4gJiYgd2luLmdldENvbXB1dGVkU3R5bGUoZWxlKS5vdmVyZmxvdyA9PSAiaGlkZGVuIikgewogICAgICAgICAgICAgICAgaCA9IGVsZS5vZmZzZXRIZWlnaHQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGggPT09IDAgJiYgZWxlLnBhcmVudE5vZGUgJiYgZWxlLnBhcmVudE5vZGUuY2hpbGRyZW4ubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgICAgICBoID0gZWxlLnBhcmVudE5vZGUuc2Nyb2xsSGVpZ2h0OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxldCBtb3JlQ2hpbGQgPSBlbGUuY2hpbGRyZW5bMF0sIG1pbk9mZnNldFRvcCA9IGg7CiAgICAgICAgICAgIHdoaWxlIChtb3JlQ2hpbGQpIHsKICAgICAgICAgICAgICAgIGlmIChtb3JlQ2hpbGQub2Zmc2V0UGFyZW50ID09IGVsZSAmJiBtb3JlQ2hpbGQub2Zmc2V0VG9wIDwgbWluT2Zmc2V0VG9wKSB7CiAgICAgICAgICAgICAgICAgICAgbWluT2Zmc2V0VG9wID0gbW9yZUNoaWxkLm9mZnNldFRvcDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG1vcmVDaGlsZCA9IG1vcmVDaGlsZC5uZXh0RWxlbWVudFNpYmxpbmc7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKG1pbk9mZnNldFRvcCAhPSBoICYmIG1pbk9mZnNldFRvcCA+IDApIHsKICAgICAgICAgICAgICAgIGggLT0gbWluT2Zmc2V0VG9wOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBoOwogICAgICAgIH0KCiAgICAgICAgZ2V0UGFnZUVsZW1lbnQoZG9jLCBjdXJXaW4sIGRvbnRGaW5kKSB7CiAgICAgICAgICAgIGlmIChkb2MgPT0gZG9jdW1lbnQgJiYgdGhpcy5kb2NQYWdlRWxlbWVudCkgewogICAgICAgICAgICAgICAgbGV0IHBhcmVudCA9IHRoaXMuZG9jUGFnZUVsZW1lbnQgJiYgdGhpcy5kb2NQYWdlRWxlbWVudFswXTsKICAgICAgICAgICAgICAgIHdoaWxlIChwYXJlbnQgJiYgIS9eQk9EWSQvaS50ZXN0KHBhcmVudC5ub2RlTmFtZSkpIHsKICAgICAgICAgICAgICAgICAgICBwYXJlbnQgPSBwYXJlbnQucGFyZW50Tm9kZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChwYXJlbnQgJiYgL15CT0RZJC9pLnRlc3QocGFyZW50Lm5vZGVOYW1lKSkgewogICAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLmRvY1BhZ2VFbGVtZW50OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGxldCBwYWdlRWxlbWVudCA9IG51bGw7CiAgICAgICAgICAgIGxldCBzZWxmID0gdGhpczsKICAgICAgICAgICAgbGV0IGJvZHkgPSBnZXRCb2R5KGRvYyk7CiAgICAgICAgICAgIGlmICh0aGlzLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50KSB7CiAgICAgICAgICAgICAgICBsZXQgcGFnZUVsZW1lbnRTZWwgPSB0aGlzLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50OwogICAgICAgICAgICAgICAgaWYgKEFycmF5ICYmIEFycmF5LmlzQXJyYXkgJiYgQXJyYXkuaXNBcnJheShwYWdlRWxlbWVudFNlbCkpIHsKICAgICAgICAgICAgICAgICAgICBwYWdlRW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gICAgICAgICAgICAgIGlmIChwYWdlRWxlbWVudCAmJiBwYWdlRWxlbWVudC5sZW5ndGggPT0gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRhcmdldENoaWxkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGFnZUVsZW1lbnQgPSBwYWdlRWxlbWVudC5jaGlsZHJlbjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQgPSB0ZW1wU2VsICsgKHRhcmdldENoaWxkID8gIj4qIiA6ICIiKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmICghcGFnZUVsZW1lbnQgfHwgcGFnZUVsZW1lbnQubGVuZ3RoID09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGFnZUVsZW1lbnRTZWwgPSBwYWdlRWxlbWVudFNlbC5yZXBsYWNlKC86bnRoLW9mLXR5cGVcKFxkK1wpL2csICIiKTsKICAgICAgICAgICAgICAgICAgICAgICAgcGFnZUVsZW1lbnQgPSBnZXRBbGxFbGVtZW50cyhwYWdlRWxlbWVudFNlbCwgZG9jKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBhZ2VFbGVtZW50ICYmIHBhZ2VFbGVtZW50Lmxlbmd0aCA9PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAodGFyZ2V0Q2hpbGQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYWdlRWxlbWVudCA9IHBhZ2VFbGVtZW50LmNoaWxkcmVuOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCA9IHBhZ2VFbGVtZW50U2VsICsgKHRhcmdldENoaWxkID8gIj4qIiA6ICIiKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICh0aGlzLmN1clNpdGVSdWxlLnNpbmdsZVVybCAmJiBwYWdlRWxlbWVudCAmJiBwYWdlRWxlbWVudC5sZW5ndGggJiYgY3VyV2luICYmIGN1cldpbiAhPSBfdW5zYWZlV2luZG93KSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IHBhcmVudCA9IHBhZ2VFbGVtZW50WzBdLnBhcmVudE5vZGU7CiAgICAgICAgICAgICAgICAgICAgbGV0IGxvYWRpbmcgPSBwYXJlbnQucXVlcnlTZWxlY3RvcignW2NsYXNzKj1sb2FkaW5nXScpOwogICAgICAgICAgICAgICAgICAgIGlmIChsb2FkaW5nICYmIGxvYWRpbmcub2Zmc2V0UGFyZW50ICYmIGxvYWRpbmcub2Zmc2V0SGVpZ2h0ID4gcGFyZW50Lm9mZnNldEhlaWdodD4+MikgewogICAgICAgICAgICAgICAgICAgICAgICBwYWdlRWxlbWVudCA9IG51bGw7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChwYWdlRWxlbWVudCAmJiBwYWdlRWxlbWVudC5sZW5ndGggPT09IDEgJiYgcGFnZUVsZW1lbnRbMF0uc3R5bGUuZGlzcGxheSA9PT0gJ25vbmUnKSB7CiAgICAgICAgICAgICAgICBwYWdlRWxlbWVudCA9IFtib2R5XTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodGhpcy5jdXJTaXRlUnVsZS5zaW5nbGVVcmwgJiYgcGFnZUVsZW1lbnQgJiYgcGFnZUVsZW1lbnQubGVuZ3RoID4gMCAmJiAvXlRSJC9pLnRlc3QocGFnZUVsZW1lbnRbMF0ubm9kZU5hbWUpKSB7CiAgICAgICAgICAgICAgICBsZXQgbWFpblRyID0gdGhpcy5pbnNlcnQucGFyZW50Tm9kZS5xdWVyeVNlbGVjdG9yKCd0cicpLCBtYWluVGROdW0gPSAwLCBuZXdUZE51bSA9IDA7CiAgICAgICAgICAgICAgICBbXS5mb3JFYWNoLmNhbGwobWFpblRyLmNoaWxkcmVuLCBlbCA9PiB7CiAgICAgICAgICAgICAgICAgICAgaWYgKC9eKFREfFRIKSQvaS50ZXN0KGVsLm5vZGVOYW1lKSkgewogICAgICAgICAgICAgICAgICAgICAgICBtYWluVGROdW0gKz0gZWwuY29sU3BhbiB8fCAxOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgW10uZm9yRWFjaC5jYWxsKHBhZ2VFbGVtZW50WzBdLmNoaWxkcmVuLCBlbCA9PiB7CiAgICAgICAgICAgICAgICAgICAgaWYgKC9eKFREfFRIKSQvaS50ZXN0KGVsLm5vZGVOYW1lKSkgewogICAgICAgICAgICAgICAgICAgICAgICBuZXdUZE51bSArPSBlbC5jb2xTcGFuIHx8IDE7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBpZiAobWFpblRkTnVtICE9IG5ld1RkTnVtKSB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCA9IGFsbE9mQm9keTsKICAgICAgICAgICAgICAgICAgICBwYWdlRWxlbWVudCA9IFtib2R5XTsKICAgICAgICAgICAgICAgICAgICB0aGlzLmdldEluc2VydCh0cnVlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoKHRoaXMuY3VyU2l0ZVJ1bGUuc2luZ2xlVXJsIHx8ICF0aGlzLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50KSAmJiAoIXBhZ2VFbGVtZW50IHx8IHBhZ2VFbGVtZW50Lmxlbmd0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AgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFtlbGUucGFyZW50Tm9kZV07CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChlbGUuY2hpbGRyZW4gJiYgZWxlLmNoaWxkcmVuLmxlbmd0aCA9PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBoYXNUZXh0ID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgaW4gZWxlLmNoaWxkTm9kZXMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBjaGlsZCA9IGVsZS5jaGlsZE5vZGVzW2ldOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNoaWxkLm5vZGVUeXBlID09IDMgJiYgY2hpbGQubm9kZVZhbHVlLnRyaW0oKSAhPT0gJycpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBoYXNUZXh0ID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoIWhhc1RleHQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZSA9IGVsZS5jaGlsZHJlblswXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1ckhlaWdodCA9IHNlbGYuZ2V0VmFsaWRIZWlnaHQoZWxlLCBjdXJXaW4pOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VyV2lkdGggPSBwYXJzZUludChlbGUub2Zmc2V0V2lkdGggfHwgZWxlLnNjcm9sbFdpZHRoKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoL15QSUNUVVJFJC9pLnRlc3QoZWxlLm5vZGVOYW1lKSB8fCAhZWxlLmlubmVyVGV4dCB8fCBlbGUuaW5uZXJUZXh0LnRyaW0oKSA9PSAnJykgewogICAgICAgICAgICAgICAgICAgICAgICBzZWxmLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50ID0gZ2VuZVNlbGVjdG9yKGVsZS5wYXJlbnROb2RlKSArICI+IiArIGVsZS5ub2RlTmFtZS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhzZWxmLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50LCAnUGFnZSBlbGVtZW50Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbZWxlXTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKGN1ckhlaWdodCAvIGJvZHlIZWlnaHQgPD0gMC4yMikgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgYXJ0aWNsZSA9IGRvYy5xdWVyeVNlbGVjdG9yQWxsKG1haW5TZWwpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYXJ0aWNsZSAmJiBhcnRpY2xlLmxlbmd0aCA9PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhcnRpY2xlID0gYXJ0aWNsZVswXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQgPSBhcnRpY2xlLm5vZGVOYW1lLnRvTG93ZXJDYXNlKCkgKyAoYXJ0aWNsZS5pZCA/ICIjIiArIGFydGljbGUuaWQgOiAiIikgKyAoYXJ0aWNsZS5jbGFzc05hbWUgPyAiLiIgKyBhcnRpY2xlLmNsYXNzTmFtZS5yZXBsYWNlKC8gL2csICIuIikgOiAiIikgKyAiPioiOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoc2VsZi5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCwgJ1BhZ2UgZWxlbWVudCcpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGFydGljbGUuY2hpbGRyZW47CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCA9IGFsbE9mQm9keTsKICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoc2VsZi5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCwgJ1BhZ2UgZWxlbWVudCcpOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gW2JvZHldOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoL15GT1JNJC9pLnRlc3QoZWxlLm5vZGVOYW1lKSAmJiBlbGUucGFyZW50Tm9kZSAhPSBnZXRCb2R5KGRvY3VtZW50KSkgewogICAgICAgICAgICAgICAgICAgICAgICBzZWxmLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50ID0gZ2VuZVNlbGVjdG9yKGVsZSkgKyAiPioiOwogICAgICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhzZWxmLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50LCAnUGFnZSBlbGVtZW50Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBlbGUuY2hpbGRyZW47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChlbGUuY2hpbGRyZW4ubGVuZ3RoID09IDAgJiYgIXNlbGYuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC9eUCQvaS50ZXN0KGVsZS5wYXJlbnROb2RlLm5vZGVOYW1lKSkgZWxlID0gZWxlLnBhcmVudE5vZGU7CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQgPSBnZW5lU2VsZWN0b3IoZWxlLnBhcmVudE5vZGUpICsgIj4iICsgZWxlLm5vZGVOYW1lLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKHNlbGYuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQsICdQYWdlIGVsZW1lbnQnKTsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGdldEFsbEVsZW1lbnRzKHNlbGYuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQsIGRvYyk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxldCBpLCBtaW5IZWlnaHQgPSBjdXJIZWlnaHQgKiAwLjUyLCBjdXJNYXhFbGUgPSBudWxsLCBjdXJNYXhBcmVhID0gMCwgbWluV2lkdGggPSBNYXRoLm1pbihjdXJXaWR0aCAqIDAuMzgsIDUwMCk7CiAgICAgICAgICAgICAgICAgICAgbGV0IGlzSG9yaSwgcHJlT2Zmc2V0VG9wID0gLTE7CiAgICAgICAgICAgICAgICAgICAgbGV0IGFydGljbGVOdW0gPSAwOwogICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBlbGUuY2hpbGRyZW4ubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGN1ck5vZGUgPSBlbGUuY2hpbGRyZW5baV07CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICgvXihDQU5WQVN8TkFWKSQvaS50ZXN0KGN1ck5vZGUubm9kZU5hbWUpKSBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFjdXJOb2RlLm9mZnNldFBhcmVudCkgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghL15JTUckL2kudGVzdChjdXJOb2RlLm5vZGVOYW1lKSAmJiBjdXJOb2RlLnF1ZXJ5U2VsZWN0b3IoJ2ltZycpID09IG51bGwgJiYgL15ccyokLy50ZXN0KGN1ck5vZGUuaW5uZXJUZXh0KSkgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChuZWVkQ2hlY2tOZXh0ICYmICFjdXJOb2RlLmNvbnRhaW5zKHNlbGYuaW5pdE5leHQpICYmIGdldEVsZW1lbnRUb3AoY3VyTm9kZSkgPiB3aW5kb3dIZWlnaHQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICgvXkFSVElDTEUkL2kudGVzdChjdXJOb2RlLm5vZGVOYW1lKSkgYXJ0aWNsZU51bSsrOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgaCA9IHNlbGYuZ2V0VmFsaWRIZWlnaHQoY3VyTm9kZSwgY3VyV2luKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHcgPSBjdXJOb2RlLnNjcm9sbFdpZHRoOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNOYU4oaCkgfHwgaXNOYU4odykpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgICAgICBpc0hvcmkgPSBNYXRoLmFicyhwcmVPZmZzZXRUb3AgLSBjdXJOb2RlLm9mZnNldFRvcCkgPD0gMjAgPyB0cnVlIDogKHByZU9mZnNldFRvcCA9PSAtMSAmJiBjdXJOb2RlLm5leHRFbGVtZW50U2libGluZyAmJiBjdXJOb2RlLm5leHRFbGVtZW50U2libGluZy5vZmZzZXRUb3AgPT0gY3VyTm9kZS5vZmZzZXRUb3ApOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNIb3JpICYmIGggPD0gNTApIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNIb3JpICYmIG5leHRMZWZ0UG9zICYmIGN1ck1heEVsZSAmJiBjdXJXaWR0aCA+IDUwMCAmJiBjdXJIZWlnaHQgPiA1MDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBjdXJSZWN0ID0gY3VyTm9kZS5nZXRCb3VuZGluZ0NsaWVudFJlY3QoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJSZWN0LmxlZnQgPD0gbmV4dExlZnRQb3MgJiYgY3VyUmVjdC5yaWdodCA+IG5leHRMZWZ0UG9zKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGEgPSBoICogdywgbW9yZUNoaWxkID0gY3VyTm9kZS5jaGlsZHJlblswXTsKICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKG1vcmVDaGlsZCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGNoID0gc2VsZi5nZXRWYWxpZEhlaWdodChtb3JlQ2hpbGQsIGN1cldpbik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgY3cgPSBtb3JlQ2hpbGQuc2Nyb2xsV2lkdGg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaCA8IGNoKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaCA9IGNoOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG1vcmVDaGlsZC5pbm5lclRleHQgIT0gIiIgJiYgY2ggJiYgY3cpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhICs9IGNoICogY3c7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBtb3JlQ2hpbGQgPSBtb3JlQ2hpbGQubmV4dEVsZW1lbnRTaWJsaW5nOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBpc01heCA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNIb3JpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoY3VyTWF4RWxlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGN1cldpZHRoIDwgdykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc01heCA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChjdXJXaWR0aCA8IHcgKyAzMDAgJiYgY3VyTWF4QXJlYSA8IGEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaXNNYXggPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJNYXhFbGUgJiYgY3VyTWF4RWxlLm9mZnNldFBhcmVudCA9PSBjdXJOb2RlLm9mZnNldFBhcmVudCAmJiBjdXJNYXhFbGUub2Zmc2V0VG9wID09IGN1ck5vZGUub2Zmc2V0VG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGN1ck1heEFyZWEgKiAyID4gYSkgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc01heCA9IGN1ck1heEFyZWEgPCBhOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJNYXhFbGUgPT0gbnVsbCB8fCBpc01heCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzSG9yaSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3IDwgbWluV2lkdGgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGggPCBtaW5IZWlnaHQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIW5lZWRDaGVja05leHQgfHwgaCA8ICh3aW5kb3dIZWlnaHQ+PjIpIHx8ICFlbGUuY29udGFpbnMoc2VsZi5pbml0TmV4dCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VySGVpZ2h0ID0gaDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1ck1heEFyZWEgPSBhOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VyV2lkdGggPSB3OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VyTWF4RWxlID0gY3VyTm9kZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHByZU9mZnNldFRvcCA9IGN1ck5vZGUub2Zmc2V0VG9wOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChjdXJNYXhFbGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHNhbWVDbGFzc051bSA9IDAsIGhhc0RpZmZlcmVudCA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoY3VyTWF4RWxlLmNsYXNzTmFtZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yKGkgPSAwOyBpIDwgZWxlLmNoaWxkcmVuLmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGN1ck5vZGUgPSBlbGUuY2hpbGRyZW5baV07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGN1ck1heEVsZSAhPSBjdXJOb2RlICYmIGN1ck5vZGUuc3R5bGUuZGlzcGxheSAhPT0gJ25vbmUnICYmIGN1ck1heEVsZS5jbGFzc05hbWUgPT0gY3VyTm9kZS5jbGFzc05hbWUgJiYgY3VyTWF4RWxlLm5vZGVOYW1lID09IGN1ck5vZGUubm9kZU5hbWUpewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzYW1lQ2xhc3NOdW0rKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGN1ck1heEVsZS5jbGFzc05hbWUgIT0gY3VyTm9kZS5jbGFzc05hbWUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzRGlmZmVyZW50ID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNhbWVDbGFzc051bSA8IDIgfHwgKHNhbWVDbGFzc051bSA8IDUgJiYgaGFzRGlmZmVyZW50KSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNoZWNrRWxlbWVudChjdXJNYXhFbGUpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChlbGUucGFyZW50Tm9kZS5jaGlsZHJlbi5sZW5ndGggPT0gMSAmJiBjdXJXaW4uZ2V0Q29tcHV0ZWRTdHlsZShlbGUucGFyZW50Tm9kZSkuZmxvYXQgPT0gJ25vbmUnKSBlbGUgPSBlbGUucGFyZW50Tm9kZTsKICAgICAgICAgICAgICAgICAgICBlbHNlIGlmICgvXihQfEJSfFREKSQvaS50ZXN0KGVsZS5ub2RlTmFtZSkpIGVsZSA9IGVsZS5wYXJlbnROb2RlOwogICAgICAgICAgICAgICAgICAgIGVsc2UgaWYgKC9eVEJPRFkkL2kudGVzdChlbGUubm9kZU5hbWUpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQgPSBnZW5lU2VsZWN0b3IoZWxlKSArICI+KiI7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlbGUuY2hpbGRyZW4ubGVuZ3RoID4gMCAmJiBlbGUuY2hpbGRyZW5bMF0ucXVlcnlTZWxlY3RvcigidGgiKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCArPSAiOm5vdCg6Zmlyc3QtY2hpbGQpIjsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhzZWxmLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50LCAnUGFnZSBlbGVtZW50Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBlbGUuY2hpbGRyZW47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxldCBpbWdzID0gZWxlLnF1ZXJ5U2VsZWN0b3JBbGwoJ2ltZycpOwogICAgICAgICAgICAgICAgICAgIGlmIChpbWdzLmxlbmd0aCA9PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBpbWcgPSBpbWdzWzBdOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW1nLm9mZnNldFdpZHRoID4gZWxlLm9mZnNldFdpZHRoIC8gMyAqIDIgJiYgaW1nLm9mZnNldEhlaWdodCA+IGVsZS5vZmZzZXRIZWlnaHQgLyAyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbGUgPSBpbWc7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgc2VsZi5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCA9IGdlbmVTZWxlY3RvcihlbGUpOwogICAgICAgICAgICAgICAgICAgIGxldCBwZiA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgIGlmIChlbGUucGFyZW50Tm9kZSkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgcGFTdHlsZSA9IGN1cldpbi5nZXRDb21wdXRlZFN0eWxlKGVsZS5wYXJlbnROb2RlKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHBhRGlzcGxheSA9IHBhU3R5bGUuZGlzcGxheTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHBhT3ZlcmZsb3cgPSBwYVN0eWxlLm92ZXJmbG93OwogICAgICAgICAgICAgICAgICAgICAgICBwZiA9IHBhRGlzcGxheS5pbmRleE9mKCdmbGV4JykgIT09IC0xIHx8IHBhRGlzcGxheS5pbmRleE9mKCdncmlkJykgIT09IC0xIHx8IHBhT3ZlcmZsb3cgPT0gImhpZGRlbiI7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxldCBjdXJTdHlsZSA9IGN1cldpbi5nZXRDb21wdXRlZFN0eWxlKGVsZSk7CiAgICAgICAgICAgICAgICAgICAgaWYgKGVsZS5jaGlsZHJlbi5sZW5ndGggPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhcnRpY2xlTnVtID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCArPSAiPmFydGljbGUiOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlID0gZWxlLmNoaWxkcmVuOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGhhc1RleHQgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgaW4gZWxlLmNoaWxkTm9kZXMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgY2hpbGQgPSBlbGUuY2hpbGROb2Rlc1tpXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoY2hpbGQubm9kZVR5cGUgPT0gMyAmJiBjaGlsZC5ub2RlVmFsdWUudHJpbSgpICE9PSAnJykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBoYXNUZXh0ID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlID0gW2VsZV07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICghaGFzVGV4dCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBncmlkQXJlYSA9IGN1clN0eWxlLmdyaWRBcmVhOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChncmlkQXJlYSAmJiBncmlkQXJlYSAhPSAiYXV0byAvIGF1dG8gLyBhdXRvIC8gYXV0byIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCArPSAiPioiOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbGUgPSBlbGUuY2hpbGRyZW47CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IG1pZGRsZUNoaWxkID0gZWxlLmNoaWxkcmVuW3BhcnNlSW50KGVsZS5jaGlsZHJlbi5sZW5ndGggLyAyKV07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJTdHlsZS5kaXNwbGF5ID09PSAnZmxleCcgfHwgKHJ1bGVzRGF0YS5vcGFjaXR5ICE9IDAgJiYgIXBmKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlID0gW2VsZV07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG1pZGRsZUNoaWxkLnN0eWxlICYmIG1pZGRsZUNoaWxkLnN0eWxlLnBvc2l0aW9uID09PSAiYWJzb2x1dGUiICYmIG1pZGRsZUNoaWxkLnN0eWxlLmxlZnQgJiYgbWlkZGxlQ2hpbGQuc3R5bGUudG9wKSB8fCAvXlVMJC9pLnRlc3QoZWxlLm5vZGVOYW1lKSB8fCBjdXJIZWlnaHQgPT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlID0gW2VsZV07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZWxmLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50ICs9ICI+KiI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbGUgPSBlbGUuY2hpbGRyZW47CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHBmIHx8IGN1clN0eWxlLnBvc2l0aW9uID09PSAiYWJzb2x1dGUiKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQgKz0gIj4qIjsKICAgICAgICAgICAgICAgICAgICAgICAgZWxlID0gZWxlLmNoaWxkcmVuOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGVsZSA9IFtlbGVdOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhzZWxmLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50LCAnUGFnZSBlbGVtZW50Jyk7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGVsZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHBhZ2VFbGVtZW50ID0gY2hlY2tFbGVtZW50KGJvZHkpOwogICAgICAgICAgICAgICAgaWYgKHBhZ2VFbGVtZW50ICYmIHBhZ2VFbGVtZW50Lmxlbmd0aCA+IDAgJiYgc2VsZi5pbml0TmV4dCkgewogICAgICAgICAgICAgICAgICAgIGxldCBsYXN0Qm90dG9tID0gZ2V0RWxlbWVudEJvdHRvbShwYWdlRWxlbWVudFtwYWdlRWxlbWVudC5sZW5ndGggLSAxXSk7CiAgICAgICAgICAgICAgICAgICAgaWYgKGxhc3RCb3R0b20gJiYgZ2V0RWxlbWVudFRvcChzZWxmLmluaXROZXh0KSAtIGxhc3RCb3R0b20gPiAxMDAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKCJTdG9wIGFzIHRvbyBsb25nIGJldHdlZW4gbmV4dCAmIHBhZ2UgZWxlbWVudCIpOwogICAgICAgICAgICAgICAgICAgICAgICBpc1BhdXNlID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgcGFnZUVsZW1lbnQgPSBbXTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAocGFnZUVsZW1lbnQubGVuZ3RoID09IDEgJiYgL15JTUckL2kudGVzdChwYWdlRWxlbWVudFswXS5ub2RlTmFtZSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuY3VyU2l0ZVJ1bGUucGFnZUJhciA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAvL2lmKHBhZ2VFbGVtZW50KXRoaXMuc2F2ZUN1clNpdGVSdWxlKCk7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIGlmIChkb2MgIT09IGRvY3VtZW50KSB7CiAgICAgICAgICAgICAgICB0aGlzLnNldFBhZ2VFbGVtZW50Q3NzKHBhZ2VFbGVtZW50KTsKICAgICAgICAgICAgICAgIHRoaXMubGF6eUltZ0FjdGlvbihwYWdlRWxlbWVudCk7CiAgICAgICAgICAgICAgICB0aGlzLmZpbHRlckVsZXMoZG9jLCBwYWdlRWxlbWVudCk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoIXRoaXMuZG9jUGFnZUVsZW1lbnQpIHsKICAgICAgICAgICAgICAgIHRoaXMuc2V0UGFnZUVsZW1lbnRDc3MocGFnZUVsZW1lbnQsIHRydWUpOwogICAgICAgICAgICAgICAgdGhpcy5kb2NQYWdlRWxlbWVudCA9IHBhZ2VFbGVtZW50OwogICAgICAgICAgICAgICAgdGhpcy5maWx0ZXJFbGVzKGRvYywgcGFnZUVsZW1lbnQpOwogICAgICAgICAgICAgICAgaWYgKHRoaXMubmV4dExpbmtIcmVmKSB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5vcGVuSW5OZXdUYWIocGFnZUVsZW1lbnQpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0aGlzLmN1clNpdGVSdWxlLnNpbmdsZVVybCAmJiBwYWdlRWxlbWVudCAmJiBwYWdlRWxlbWVudC5sZW5ndGggPiAwKSB7CiAgICAgICAgICAgICAgICBsZXQgdGFyZ2V0RWxlID0gcGFnZUVsZW1lbnQubGVuZ3RoID4gMSA/IHBhZ2VFbGVtZW50WzBdLnBhcmVudE5vZGUgOiBwYWdlRWxlbWVudFswXTsKICAgICAgICAgICAgICAgIGxldCB2aWRlbyA9IHRhcmdldEVsZS5xdWVyeVNlbGVjdG9yKCJ2aWRlbyxpZnJhbWVbaWQqPXBsYXldLFtpZCo9cGxheV0+aWZyYW1lLGlmcmFtZVtzcmMqPXBsYXllcl0saWZyYW1lW3NyYyo9bTN1OF0iKTsKICAgICAgICAgICAgICAgIGlmICh2aWRlbyAmJiBkb2MgPT0gZG9jdW1lbnQpIHsKICAgICAgICAgICAgICAgICAgICBpZiAodmlkZW8gJiYgdmlkZW8ub2Zmc2V0UGFyZW50ICYmIHZpZGVvLm5hbWUgIT0gJ3BhZ2V0dWFsLWlmcmFtZScpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHNjcm9sbFdpZHRoID0gdmlkZW8uc2Nyb2xsV2lkdGggfHwgdmlkZW8ub2Zmc2V0V2lkdGg7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBzY3JvbGxIZWlnaHQgPSB2aWRlby5zY3JvbGxIZWlnaHQgfHwgdmlkZW8ub2Zmc2V0SGVpZ2h0OwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoc2Nyb2xsV2lkdGggPiAxMDAgJiYgc2Nyb2xsSGVpZ2h0ID4gMTAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgd2luV2lkdGggPSB3aW5kb3cuaW5uZXJXaWR0aMKgfHzCoGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5jbGllbnRXaWR0aDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCB3aW5IZWlnaHQgPSB3aW5kb3cuaW5uZXJIZWlnaHTCoHx8wqBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuY2xpZW50SGVpZ2h0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNjcm9sbFdpZHRoID4gd2luV2lkdGg+PjEgJiYgc2Nyb2xsSGVpZ2h0ID4gd2luSGVpZ2h0Pj4xKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoIkRpc2FibGUgd2hlbiBsYXJnZSBtZWRpYSBmb3VuZCIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2aWRlbyA9IG51bGw7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2aWRlbyA9IG51bGw7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICB2aWRlbyA9IG51bGw7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHZpZGVvKSB7CiAgICAgICAgICAgICAgICAgICAgaXNQYXVzZSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5jbGVhckFkZGVkRWxlbWVudHMoKTsKICAgICAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcGFnZUVsZW1lbnQ7CiAgICAgICAgfQoKICAgICAgICBjaGFuZ2VWaXNpYmlsaXR5KCkgewogICAgICAgICAgICBsZXQgY29udGVudFZpc2liaWxpdHkgPSB0aGlzLmN1clNpdGVSdWxlLmNvbnRlbnRWaXNpYmlsaXR5IHx8IHJ1bGVzRGF0YS5jb250ZW50VmlzaWJpbGl0eTsKICAgICAgICAgICAgaWYgKCFjb250ZW50VmlzaWJpbGl0eSkgcmV0dXJuOwogICAgICAgICAgICBpZiAoIXRoaXMuY2hhbmdpbmdWaXNpYmlsaXR5KSB7CiAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGhpcy5jaGFuZ2VWaXNpYmlsaXR5VGltZXIpOwogICAgICAgICAgICAgICAgdGhpcy5jaGFuZ2VWaXNpYmlsaXR5VGltZXIgPSBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICB0aGlzLmNoYW5naW5nVmlzaWJpbGl0eSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5jaGFuZ2VWaXNpYmlsaXR5KCk7CiAgICAgICAgICAgICAgICB9LCAzMDApOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuY2hhbmdpbmdWaXNpYmlsaXR5ID0gZmFsc2U7CiAgICAgICAgICAgIGlmICghdGhpcy52aXNpYmlsaXR5SXRlbXMgfHwgIXRoaXMudmlzaWJpbGl0eUl0ZW1zLmxlbmd0aCB8fCB0aGlzLnZpc2libGVJbmRleCA8IDApIHJldHVybjsKICAgICAgICAgICAgbGV0IHRlbXBJbmRleCA9IHRoaXMudmlzaWJsZUluZGV4LCBmaW5kVmlzaWJsZSA9IGZhbHNlLCBsYXN0VmlzaWJsZSA9IDA7CiAgICAgICAgICAgIGxldCB2aWV3UG9ydEhlaWdodCA9IHdpbmRvdy5pbm5lckhlaWdodCB8fCBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuY2xpZW50SGVpZ2h0IHx8IGdldEJvZHkoZG9jdW1lbnQpLmNsaWVudEhlaWdodDsKICAgICAgICAgICAgbGV0IGNoZWNrSXRlbSA9IHRoaXMudmlzaWJpbGl0eUl0ZW1zW3RlbXBJbmRleF07CiAgICAgICAgICAgIHdoaWxlKGNoZWNrSXRlbSkgewogICAgICAgICAgICAgICAgaWYgKGNoZWNrSXRlbS5vZmZzZXRQYXJlbnQpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoIWNoZWNrSXRlbS5zdHlsZS5jb250YWluSW50cmluc2ljU2l6ZSkgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIGxldCBjbGllbnRSZWN0ID0gY2hlY2tJdGVtLmdldEJvdW5kaW5nQ2xpZW50UmVjdCgpOwogICAgICAgICAgICAgICAgICAgIGxldCB0b3AgPSBjbGllbnRSZWN0ICYmIGNsaWVudFJlY3QudG9wOwogICAgICAgICAgICAgICAgICAgIGxldCBib3R0b20gPSBjbGllbnRSZWN0ICYmIGNsaWVudFJlY3QuYm90dG9tOwogICAgICAgICAgICAgICAgICAgIGlmIChib3R0b20gPiAwICYmIHRvcCA8IHZpZXdQb3J0SGVpZ2h0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghZmluZFZpc2libGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZpbmRWaXNpYmxlID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxhc3RWaXNpYmxlID0gdGVtcEluZGV4OwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrSXRlbS5zdHlsZS5jb250ZW50VmlzaWJpbGl0eSA9ICJ2aXNpYmxlIjsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAodG9wIDwgdmlld1BvcnRIZWlnaHQgJiYgY2hlY2tJdGVtLnN0eWxlLmNvbnRlbnRWaXNpYmlsaXR5ID09ICJhdXRvIikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBjaGVja0l0ZW0uc3R5bGUuY29udGVudFZpc2liaWxpdHkgPSAiYXV0byI7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHRlbXBJbmRleCA9PSAwKSBicmVhazsKICAgICAgICAgICAgICAgIHRlbXBJbmRleC0tOwogICAgICAgICAgICAgICAgY2hlY2tJdGVtID0gdGhpcy52aXNpYmlsaXR5SXRlbXNbdGVtcEluZGV4XTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0ZW1wSW5kZXggPSB0aGlzLnZpc2libGVJbmRleCArIDE7CiAgICAgICAgICAgIGlmIChmaW5kVmlzaWJsZSkgewogICAgICAgICAgICAgICAgdGhpcy52aXNpYmxlSW5kZXggPSBsYXN0VmlzaWJsZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjaGVja0l0ZW0gPSB0aGlzLnZpc2liaWxpdHlJdGVtc1t0ZW1wSW5kZXhdOwogICAgICAgICAgICB3aGlsZShjaGVja0l0ZW0pIHsKICAgICAgICAgICAgICAgIGlmIChjaGVja0l0ZW0ub2Zmc2V0UGFyZW50KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFjaGVja0l0ZW0uc3R5bGUuY29udGFpbkludHJpbnNpY1NpemUpIHJldHVybjsKICAgICAgICAgICAgICAgICAgICBsZXQgY2xpZW50UmVjdCA9IGNoZWNrSXRlbS5nZXRCb3VuZGluZ0NsaWVudFJlY3QoKTsKICAgICAgICAgICAgICAgICAgICBsZXQgdG9wID0gY2xpZW50UmVjdCAmJiBjbGllbnRSZWN0LnRvcDsKICAgICAgICAgICAgICAgICAgICBsZXQgYm90dG9tID0gY2xpZW50UmVjdCAmJiBjbGllbnRSZWN0LmJvdHRvbTsKICAgICAgICAgICAgICAgICAgICBpZiAoYm90dG9tID4gMCAmJiB0b3AgPCB2aWV3UG9ydEhlaWdodCkgewogICAgICAgICAgICAgICAgICAgICAgICBmaW5kVmlzaWJsZSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgIGxhc3RWaXNpYmxlID0gdGVtcEluZGV4OwogICAgICAgICAgICAgICAgICAgICAgICBjaGVja0l0ZW0uc3R5bGUuY29udGVudFZpc2liaWxpdHkgPSAidmlzaWJsZSI7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGZpbmRWaXNpYmxlICYmIGNoZWNrSXRlbS5zdHlsZS5jb250ZW50VmlzaWJpbGl0eSA9PSAiYXV0byIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgY2hlY2tJdGVtLnN0eWxlLmNvbnRlbnRWaXNpYmlsaXR5ID0gImF1dG8iOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICh0ZW1wSW5kZXggPT0gdGhpcy52aXNpYmlsaXR5SXRlbXMubGVuZ3RoIC0gMSkgYnJlYWs7CiAgICAgICAgICAgICAgICB0ZW1wSW5kZXgrKzsKICAgICAgICAgICAgICAgIGNoZWNrSXRlbSA9IHRoaXMudmlzaWJpbGl0eUl0ZW1zW3RlbXBJbmRleF07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGZpbmRWaXNpYmxlKSB7CiAgICAgICAgICAgICAgICB0aGlzLnZpc2libGVJbmRleCA9IGxhc3RWaXNpYmxlOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBzZXRQYWdlRWxlbWVudENzcyhwYWdlRWxlbWVudCwgaW5pdCkgewogICAgICAgICAgICBsZXQgc2VsZiA9IHRoaXM7CiAgICAgICAgICAgIGlmIChwYWdlRWxlbWVudCAmJiBwYWdlRWxlbWVudC5sZW5ndGggPiAwKSB7CiAgICAgICAgICAgICAgICBsZXQgcGFnZUVsZW1lbnRDc3MgPSB0aGlzLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50Q3NzIHx8IHJ1bGVzRGF0YS5wYWdlRWxlbWVudENzczsKICAgICAgICAgICAgICAgIGlmICghcGFnZUVsZW1lbnRDc3MgJiYgaW5pdCAmJiAhdGhpcy5uZXh0TGlua0hyZWYpIHJldHVybjsKICAgICAgICAgICAgICAgIGxldCBjb250ZW50VmlzaWJpbGl0eSA9IHRoaXMuY3VyU2l0ZVJ1bGUuY29udGVudFZpc2liaWxpdHkgfHwgcnVsZXNEYXRhLmNvbnRlbnRWaXNpYmlsaXR5OwogICAgICAgICAgICAgICAgaWYgKCFjb250ZW50VmlzaWJpbGl0eSAmJiAhcGFnZUVsZW1lbnRDc3MpIHJldHVybjsKICAgICAgICAgICAgICAgIFtdLmZvckVhY2guY2FsbChwYWdlRWxlbWVudCwgKGVsZSwgaSkgPT4gewogICAgICAgICAgICAgICAgICAgIGlmICghL0xJTkt8TUVUQXxTVFlMRXxTQ1JJUFQvaS50ZXN0KGVsZS5ub2RlTmFtZSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBhZ2VFbGVtZW50Q3NzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGFnZUVsZW1lbnRDc3MgIT09ICcwJyAmJiAhZWxlLmRhdGFzZXQucGFnZXR1YWxQYWdlRWxlbWVudCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZS5zdHlsZS5jc3NUZXh0ID0gKGVsZS5zdHlsZS5jc3NUZXh0IHx8ICcnKSArIHBhZ2VFbGVtZW50Q3NzOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZS5kYXRhc2V0LnBhZ2V0dWFsUGFnZUVsZW1lbnQgPSAxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjb250ZW50VmlzaWJpbGl0eSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxlLnN0eWxlLmNvbnRhaW5JbnRyaW5zaWNTaXplID0gYGF1dG8gJHtlbGUub2Zmc2V0SGVpZ2h0IHx8IHNlbGYucHJlVmlzaWJsZUhlaWdodCB8fCAxMDB9cHhgOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGVsZS5zdHlsZS5jb250YWluSW50cmluc2ljU2l6ZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlbGUub2Zmc2V0SGVpZ2h0KSBzZWxmLnByZVZpc2libGVIZWlnaHQgPSBlbGUub2Zmc2V0SGVpZ2h0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbml0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZS5zdHlsZS5jb250ZW50VmlzaWJpbGl0eSA9ICJ2aXNpYmxlIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi52aXNpYmlsaXR5SXRlbXMucHVzaChlbGUpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZWxmLnZpc2libGVJbmRleCsrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsZS5zdHlsZS5jb250ZW50VmlzaWJpbGl0eSA9IGVtdUlmcmFtZSA/ICJ2aXNpYmxlIiA6ICJhdXRvIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgY2xlYXJBZGRlZEVsZW1lbnRzKCkgewogICAgICAgICAgICBpZiAodGhpcy5hZGRlZEVsZVBvb2wgJiYgdGhpcy5hZGRlZEVsZVBvb2wubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB0aGlzLmFkZGVkRWxlUG9vbC5mb3JFYWNoKGVsZSA9PiB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGVsZS5wYXJlbnROb2RlKSBlbGUucGFyZW50Tm9kZS5yZW1vdmVDaGlsZChlbGUpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5hZGRlZEVsZVBvb2wgPSBbXTsKICAgICAgICAgICAgc2lkZUNvbnRyb2xsZXIucmVtb3ZlKCk7CiAgICAgICAgfQoKICAgICAgICBhc3luYyBnZXRQYWdlKGRvYykgewogICAgICAgICAgICBpZiAoZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LmNsYXNzTmFtZS5pbmRleE9mKCdkaXNjb3Vyc2UnKSAhPSAtMSkgcmV0dXJuIHt9OwogICAgICAgICAgICBsZXQgYm9keSA9IGdldEJvZHkoZG9jKTsKICAgICAgICAgICAgbGV0IGN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YXRjaDJbMV07CiAgICAgICAgICAgICAgICAgICAgcGFnZU51bSA9IHBhcnNlSW50KHBhZ2VNYXRjaDJbMl0pOwogICAgICAgICAgICAgICAgICAgIGFmdGVyU3RyID0gcGFnZU1hdGNoMlszXTsKICAgICAgICAgICAgICAgICAgICBpZiAoL15cLz8kLy50ZXN0KGFmdGVyU3RyKSAmJiAhLyhwKGFnZSk/fF98XC18XC8pJC8udGVzdChwcmVTdHIpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHByZVN0ciA9ICIiOwogICAgICAgICAgICAgICAgICAgICAgICBhZnRlclN0ciA9ICIiOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocGFnZU51bSA+IDk5OSkgewogICAgICAgICAgICAgICAgcGFnZU51bSA9IDE7CiAgICAgICAgICAgICAgICBwcmVTdHIgPSAiIjsKICAgICAgICAgICAgICAgIGFmdGVyU3RyID0gIiI7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbGV0IGN1clBhZ2UgPSBkb2MsIGksIGN1ciwganNOZXh0OwogICAgICAgICAgICBsZXQgbmV4dDEsIG5leHQyLCBuZXh0MywgbmV4dDQsIG5leHRKczEsIG5leHRKczIsIG5leHRKczM7CiAgICAgICAgICAgIGxldCBuZXh0ID0gYm9keS5xdWVyeVNlbGVjdG9yKCIucGFnZS1uZXh0PmEiKSB8fAogICAgICAgICAgICAgICAgYm9keS5xdWVyeVNlbGVjdG9yKCJhLm5leHRfcGFnZSIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoIiNuZXh0X3BhZ2UiKSB8fAogICAgICAgICAgICAgICAgYm9keS5xdWVyeVNlbGVjdG9yKCIubmV4dFBhZ2UiKSB8fAogICAgICAgICAgICAgICAgYm9keS5xdWVyeVNlbGVjdG9yKCIucGFnaW5hdGlvbi1uZXh0PmEiKSB8fAogICAgICAgICAgICAgICAgYm9keS5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iaW5wdXRbdmFsdWU9J25leHQnXSIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoImlucHV0W3ZhbHVlPSdOZXh0IHBhZ2UnXSIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoImlucHV0W3ZhbHVlPSfkuIvkuIDpobUnXSIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoImlucHV0W3ZhbHVlPSfkuIvkuIDpoIEnXSIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoImEjcGJfbmV4dCIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoImEjcmlnaHRGaXgiKSB8fAogICAgICAgICAgICAgICAgYm9keS5xdWVyeVNlbGVjdG9yKCJhI2J0blByZUduIikgfHwKICAgICAgICAgICAgICAgIGJvZHkucXVlcnlTZWxlY3RvcigiYS5wYWdlLW5leHQiKSB8fAogICAgICAgICAgICAgICAgYm9keS5xdWVyeVNlbGVjdG9yKCJhLnBhZ2VzLW5leHQiKSB8fAogICAgICAgICAgICAgICAgYm9keS5xdWVyeVNlbGVjdG9yKCJhLnBhZ2UucmlnaHQiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIW5leHQpIHsKICAgICAgICAgICAgICAgIGF3YWl0IHNsZWVwKDEpOwogICAgICAgICAgICAgICAgbmV4dCA9IGJvZHkucXVlcnlTZWxlY3RvcigiYSNuZXh0IikgfHwKICAgICAgICAgICAgICAgIGJvZHkucXVlcnlTZWxlY3RvcigiLm5leHQ+YSIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoIi5uZXh0PmJ1dHRvbiIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoImFbYWx0PW5leHRdIikgfHwKICAgICAgICAgICAgICAgIGJvZHkucXVlcnlTZWxlY3RvcigiLnBnX2FyZWE+ZW0rYSIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoImJ1dHRvbi5uZXh0Om5vdChbZGlzYWJsZWRdKSIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoIi5idG5fbmV4dDpub3QoW2Rpc2FibGVkXSkiKSB8fAogICAgICAgICAgICAgICAgYm9keS5xdWVyeVNlbGVjdG9yKCIuYnRuLW5leHQ6bm90KFtkaXNhYmxlZF0pIikgfHwKICAgICAgICAgICAgICAgIGJvZHkucXVlcnlTZWxlY3RvcigiYSNsaW5rTmV4dCIpIHx8CiAgICAgICAgICAgICAgICBib2R5LnF1ZXJ5U2VsZWN0b3IoImFbY2xhc3MqPXBhZ2VfX25leHRdIik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCFuZXh0KSB7CiAgICAgICAgICAgICAgICBhd2FpdCBzbGVlcCgxKTsKICAgICAgICAgICAgICAgIGxldCBuZXh0cyA9IGJvZHkucXVlcnlTZWxlY3RvckFsbCgiYS5uZXh0Iik7CiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbmV4dHMubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgICAgICAgICBpZiAobmV4dHNbaV0uc3R5bGUuZGlzcGxheSAhPT0gIm5vbmUiICYmCiAgICAgICAgICAgICAgICAgICAgICAgbmV4dHNbaV0ucGFyZW50Tm9kZS5zdHlsZS5kaXNwbGF5ICE9PSAibm9uZSIgJiYKICAgICAgICAgICAgICAgICAgICAgICAhL15ccyooW+S4iuWJjemmluWwvl18cHJldmlvdXMpL2kudGVzdChuZXh0c1tpXS5pbm5lclRleHQudHJpbSgpKSkgewogICAgICAgICAgICAgICAgICAgICAgICBuZXh0ID0gbmV4dHNbaV07CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAobmV4dCAmJiAoIW5leHQuaHJlZiB8fCAvXihqYXZhc2NyaXB0fCMpLy50ZXN0KG5leHQuaHJlZi5yZXBsYWNlKGxvY2F0aW9uLmhyZWYsICIiKSkpKSB7CiAgICAgICAgICAgICAgICBqc05leHQgPSBuZXh0OwogICAgICAgICAgICAgICAgbmV4dCA9IG51bGw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCFuZXh0KSB7CiAgICAgICAgICAgICAgICBuZXh0ID0gYm9keS5xdWVyeVNlbGVjdG9yQWxsKCJbYXJpYS1sYWJlbD0nTmV4dCBwYWdlJ10iKTsKICAgICAgICAgICAgICAgIGlmIChuZXh0ICYmIG5leHQubGVuZ3RoID09IDEpIHsKICAgICAgICAgICAgICAgICAgICBuZXh0ID0gbmV4dFswXTsKICAgICAgICAgICAgICAgICAgICBpZiAoIW5leHQuaHJlZiB8fCAvXihqYXZhc2NyaXB0fCMpLy50ZXN0KG5leHQuaHJlZi5yZXBsYWNlKGxvY2F0aW9uLmhyZWYsICIiKSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFqc05leHQpIGpzTmV4dCA9IG5leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgIG5leHQgPSBudWxsOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgbmV4dCA9IG51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGpzTmV4dCkgewogICAgICAgICAgICAgICAgaWYgKGpzTmV4dC5jbGFzc05hbWUpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoL3NsaWNrfHNsaWRlfGdhbGxlcnkvaS50ZXN0KGpzTmV4dC5jbGFzc05hbWUpKSBqc05leHQgPSBudWxsOwogICAgICAgICAgICAgICAgICAgIGVsc2UgaWYgKGpzTmV4dC5jbGFzc0xpc3QgJiYganNOZXh0LmNsYXNzTGlzdC5jb250YWlucygnZGlzYWJsZWQnKSkganNOZXh0ID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChqc05leHQpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgYXJpYUxhYmVsID0ganNOZXh0LmdldEF0dHJpYnV0ZSgiYXJpYS1sYWJlbCIpOwogICAgICAgICAgICAgICAgICAgIGlmIChhcmlhTGFiZWwgJiYgL3NsaWNrfHNsaWRlfGdhbGxlcnkvaS50ZXN0KGFyaWFMYWJlbCkpIGpzTmV4dCA9IG51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKG5leHQgJiYgbmV4dFRleHRSZWcyLnRlc3QobmV4dC5pbm5lclRleHQudHJpbSgpKSkgewogICAgICAgICAgICAgICAgbmV4dDIgPSBuZXh0OwogICAgICAgICAgICAgICAgbmV4dCA9IG51bGw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCFuZXh0KSB7CiAgICAgICAgICAgICAgICBuZXh0ID0gYm9keS5xdWVyeVNlbGVjdG9yKCJhLmN1cnIrYSIpIHx8CiAgICAgICAgICAgICAgICAgICAgYm9keS5xdWVyeVNlbGVjdG9yKCJkaXYud3AtcGFnZW5hdmk+c3Bhbi5jdXJyZW50K2EsZGl2LnBhZ2UtbmF2PnNwYW4uY3VycmVudCthLGRpdi5hcnRpY2xlLXBhZ2luZz5zcGFuK2EiKSB8fAogICAgICAgICAgICAgICAgICAgIGJvZHkucXVlcnlTZWxlY3RvcigiLm51bWJlcj51bD5saS5hY3RpdmUrbGk+YSIpOzsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIW5leHQpIHsKICAgICAgICAgICAgICAgIGxldCBwYWdlRGl2ID0gYm9keS5xdWVyeVNlbGVjdG9yKCJkaXYucGFnZXM+dWwiKTsKICAgICAgICAgICAgICAgIGlmIChwYWdlRGl2KSB7CiAgICAgICAgICAgICAgICAgICAgY3VyID0gcGFnZURpdi5xdWVyeVNlbGVjdG9yKCJsaT5iIik7CiAgICAgICAgICAgICAgICAgICAgaWYgKGN1cikgbmV4dCA9IGN1ci5wYXJlbnROb2RlLm5leHRFbGVtZW50U2libGluZzsKICAgICAgICAgICAgICAgICAgICBpZiAobmV4dCkgbmV4dCA9IG5leHQucXVlcnlTZWxlY3RvcigiYSIpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghbmV4dCkgewogICAgICAgICAgICAgICAgbmV4dCA9IGJvZHkucXVlcnlTZWxlY3RvcigiLnBhZ2VzPmFbaHJlZj0namF2YXNjcmlwdDo7J10rYSIpOwogICAgICAgICAgICAgICAgaWYgKG5leHQgJiYgKG5leHQuaHJlZiA9PSAiamF2YXNjcmlwdDo7IiB8fCBuZXh0LmdldEF0dHJpYnV0ZSgiaHJlZiIpID09ICIjIikpIG5leHQgPSBudWxsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghbmV4dCkgewogICAgICAgICAgICAgICAgYXdhaXQgc2xlZXAoMSk7CiAgICAgICAgICAgICAgICBsZXQgcGFnZURpdiA9IGJvZHkucXVlcnlTZWxlY3RvcigiLnBhZ2luYXRpb24iKTsKICAgICAgICAgICAgICAgIGlmIChwYWdlRGl2KSB7CiAgICAgICAgICAgICAgICAgICAgY3VyID0gcGFnZURpdi5xdWVyeVNlbGVjdG9yKCJbY2xhc3MqPWN1cnJlbnRdIik7CiAgICAgICAgICAgICAgICAgICAgaWYgKGN1cikgbmV4dCA9IGN1ci5wYXJlbnROb2RlLm5leHRFbGVtZW50U2libGluZzsKICAgICAgICAgICAgICAgICAgICBpZiAobmV4dCkgbmV4dCA9IG5leHQucXVlcnlTZWxlY3RvcigiYSIpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghbmV4dCkgewogICAgICAgICAgICAgICAgYXdhaXQgc2xlZXAoMSk7CiAgICAgICAgICAgICAgICBsZXQgcGFnZURpdnMgPSBib2R5LnF1ZXJ5U2VsZWN0b3JBbGwoIltjbGFzcyo9cGFnaW5hdGlvbl0sW2NsYXNzKj1QYWdpbmF0aW9uXSIpOwogICAgICAgICAgICAgICAgaWYgKHBhZ2VEaXZzICYmIHBhZ2VEaXZzLmxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgcGFnZURpdnMubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHAgPSBwYWdlRGl2c1tpXTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC8obmV4dFxzKijCu3w+Pnw+fOKAunzihpJ84p2vKT98Jmd0O3zilrZ8PnzigLp84oaSfOKdrykvaS50ZXN0KHAudGl0bGUgfHwgcC52YWx1ZSB8fCAnJykpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5leHQgPSBwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoL14obmV4dFxzKijCu3w+Pnw+fOKAunzihpJ84p2vKT98Jmd0O3zilrZ8PnzigLp84oaSfOKdrykkL2kudGVzdCgocC5pbm5lclRleHQgfHwgJycpLnRyaW0oKSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5leHQgPSBwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCFuZXh0KSB7CiAgICAgICAgICAgICAgICBsZXQgYVRhZ3MgPSBib2R5LnF1ZXJ5U2VsZWN0b3JBbGwoImEsYnV0dG9uLFt0eXBlPSdidXR0b24nXSIpOwogICAgICAgICAgICAgICAgZm9yIChpID0gYVRhZ3MubGVuZ3RoIC0gMTsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAobmV4dDEpIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIGlmIChpICUgMzAwID09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgYXdhaXQgc2xlZXAoMSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxldCBhVGFnID0gYVRhZ3NbaV07CiAgICAgICAgICAgICAgICAgICAgaWYgKGFUYWcuc3R5bGUuZGlzcGxheSA9PSAibm9uZSIpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgIGxldCBpbm5lclRleHQgPSAoYVRhZy5pbm5lclRleHQgfHwgYVRhZy52YWx1ZSB8fCBhVGFnLnRpdGxlIHx8ICcnKTsKICAgICAgICAgICAgICAgICAgICBpZiAoaW5uZXJUZXh0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbm5lclRleHQgPT0gIsKnIikgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyVGV4dCA9IGlubmVyVGV4dC50cmltKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbm5lclRleHQubGVuZ3RoID4gODApIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBsZXQgYXZhaWxhYmxlSHJlZiA9IGFUYWcuaHJlZiAmJiBhVGFnLmhyZWYubGVuZ3RoIDwgMjUwICYmIC9eaHR0cC8udGVzdChhVGFnLmhyZWYpOwogICAgICAgICAgICAgICAgICAgIGlmIChhdmFpbGFibGVIcmVmICYmIC9uZXh0XC0/KHBhZ2UpPyQvaS50ZXN0KGFUYWcuaHJlZikpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgIGlmIChhVGFnLmNsYXNzTmFtZSkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoL3NsaWNrfHNsaWRlfGdhbGxlcnkvaS50ZXN0KGFUYWcuY2xhc3NOYW1lKSkgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhVGFnLmNsYXNzTGlzdCAmJiBhVGFnLmNsYXNzTGlzdC5jb250YWlucygnZGlzYWJsZWQnKSkgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChhVGFnLmRhdGFzZXQgJiYgYVRhZy5kYXRhc2V0LnByZXZpZXcpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgIGxldCBhcmlhTGFiZWwgPSBhVGFnLmdldEF0dHJpYnV0ZSgiYXJpYS1sYWJlbCIpOwogICAgICAgICAgICAgICAgICAgIGlmIChhcmlhTGFiZWwgJiYgL3NsaWNrfHNsaWRlfGdhbGxlcnkvaS50ZXN0KGFyaWFMYWJlbCkpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgIGlmIChhVGFnLnBhcmVudE5vZGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGFUYWcucGFyZW50Tm9kZS5jbGFzc05hbWUgJiYgL3NsaWNrfHNsaWRlfGdhbGxlcnkvaS50ZXN0KGFUYWcucGFyZW50Tm9kZS5jbGFzc05hbWUpKSBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGFUYWcucGFyZW50Tm9kZS5jbGFzc0xpc3QgJiYgYVRhZy5wYXJlbnROb2RlLmNsYXNzTGlzdC5jb250YWlucygnZGlzYWJsZWQnKSkgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhVGFnLnBhcmVudE5vZGUuY2xhc3NMaXN0ICYmIGFUYWcucGFyZW50Tm9kZS5jbGFzc0xpc3QuY29udGFpbnMoJ2FjdGl2ZScpKSBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC9eQkxPQ0tRVU9URSQvaS50ZXN0KGFUYWcucGFyZW50Tm9kZS5ub2RlTmFtZSkpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoYVRhZy5wcmV2aW91c0VsZW1lbnRTaWJsaW5nICYmIC9cYihwbGF5fHZvbHVtZSlcYi8udGVzdChhVGFnLnByZXZpb3VzRWxlbWVudFNpYmxpbmcuY2xhc3NOYW1lKSkgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgaWYgKGFUYWcubmV4dEVsZW1lbnRTaWJsaW5nICYmIC9cYihwbGF5fHZvbHVtZSlcYi8udGVzdChhVGFnLm5leHRFbGVtZW50U2libGluZy5jbGFzc05hbWUpKSBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgICBsZXQgaXNKcyA9ICFhVGFnLmhyZWYgfHwgIWFUYWcuaHJlZi5yZXBsYWNlIHx8IC9eKGphdmFzY3JpcHR8IykvLnRlc3QoYVRhZy5ocmVmLnJlcGxhY2UobG9jYXRpb24uaHJlZiwgIiIpKTsKICAgICAgICAgICAgICAgICAgICBpZiAoaW5uZXJUZXh0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlubmVyVGV4dCA9IGlubmVyVGV4dC5zcGxpdCgvXG4vKVswXS5yZXBsYWNlKC8gL2csICcnKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzSnMgJiYgL14owrt8Pj58PnzigLp84oaSfOKdrykkLy50ZXN0KGlubmVyVGV4dCkpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5uZXJUZXh0ICYmIGlubmVyVGV4dC5sZW5ndGggPD0gMjUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICghbmV4dDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobmV4dFRleHRSZWcxLnRlc3QoaW5uZXJUZXh0KSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaXNKcykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFuZXh0SnMxKSBuZXh0SnMxID0gYVRhZzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5leHQxID0gYVRhZzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICghbmV4dDQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIW5leHQyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChuZXh0VGV4dFJlZzIudGVzdChpbm5lclRleHQpIHx8IC9uZXh0cGFnZXxwYWdlclwtb2xkZXIvaS50ZXN0KGFUYWcuY2xhc3NOYW1lKSB8fCAvXijCu3w+PikkLy50ZXN0KGlubmVyVGV4dCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpc0pzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFuZXh0SnMyKSBuZXh0SnMyID0gYVRhZzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV4dDIgPSBhVGFnOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICghbmV4dDMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC9eKG5leHRccyoowrt8Pj58PnzigLp84oaSfOKdryk/fCZndDt84pa2fD584oC6fOKGknzina8pJC9pLnRlc3QoaW5uZXJUZXh0KSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzSnMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIW5leHRKczMpIG5leHRKczMgPSBhVGFnOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZXh0MyA9IGFUYWc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKGlzSnMpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgIGlmICghbmV4dDQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHByZXZFbGUgPSBhVGFnLnByZXZpb3VzRWxlbWVudFNpYmxpbmc7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwcmV2RWxlICYmICgvXihCfFNQQU58U1RST05HKSQvaS50ZXN0KHByZXZFbGUubm9kZU5hbWUpKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC9eXGQrJC8udGVzdChhVGFnLmlubmVyVGV4dC50cmltKCkpICYmIC9eXGQrJC8udGVzdChwcmV2RWxlLmlubmVyVGV4dC50cmltKCkpICYmIHBhcnNlSW50KGFUYWcuaW5uZXJUZXh0KSA9PSBwYXJzZUludChwcmV2RWxlLmlubmVyVGV4dCkgKyAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV4dDQgPSBhVGFnOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmICghbmV4dDQgJiYgYXZhaWxhYmxlSHJlZikgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYVRhZy5ocmVmLmluZGV4T2YobG9jYXRpb24uaG9zdG5hbWUpID09PSAtMSkgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBfYUhyZWYgPSBhVGFnLmhyZWYucmVwbGFjZSgiPyYiLCAiPyIpLnJlcGxhY2UoImluZGV4LnBocD8iLCAiPyIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwcmVTdHIgfHwgYWZ0ZXJTdHIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBfYUhyZWZUcmltID0gX2FIcmVmOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHByZVN0cikgX2FIcmVmVHJpbSA9IF9hSHJlZlRyaW0ucmVwbGFjZShwcmVTdHIsICIiKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhZnRlclN0cikgX2FIcmVmVHJpbSA9IF9hSHJlZlRyaW0ucmVwbGFjZShhZnRlclN0ciwgIiIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKF9hSHJlZlRyaW0gPT0gcGFnZU51bSArIDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZXh0NCA9IGFUYWc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5jdXJVcmwgIT0gYVRhZy5ocmVmKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBfYUhyZWYgPSBfYUhyZWYucmVwbGFjZSgvXC5zP2h0bWw/JC9pLCAiIik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoX2FIcmVmLmluZGV4T2YoX3VybCkgIT0gLTEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgcGFnZVR3b01hdGNoID0gX2FIcmVmLnJlcGxhY2UoX3VybCwgIiIpLm1hdGNoKHBhZ2VUd29SZWcpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwYWdlVHdvTWF0Y2gpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYWZ0ZXJTdHIgPSBwYWdlVHdvTWF0Y2hbMl07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5leHQ0ID0gYVRhZzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG5leHQ0ICYmICEvcGFnZS8udGVzdChuZXh0NC5ocmVmKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGN1ckhyZWYgPSBuZXh0NC5nZXRBdHRyaWJ1dGUoImhyZWYiKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBjdXJQYWdlUmVnID0gbmV3IFJlZ0V4cCgiKC4qKSIgKyAocGFnZU51bSArIDEpICsgYWZ0ZXJTdHIucmVwbGFjZSgvKFtcLlw/XSkvZywgJ1xcJDEnKSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgb3RoZXJQYWdlSHJlZiA9IGN1ckhyZWYucmVwbGFjZShjdXJQYWdlUmVnLCBgJDEke3BhZ2VOdW19JHthZnRlclN0cn1gKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBvdGhlclBhZ2VFbGUgPSBib2R5LnF1ZXJ5U2VsZWN0b3IoYGFbaHJlZj0nJHtvdGhlclBhZ2VIcmVmfSddYCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIW90aGVyUGFnZUVsZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG90aGVyUGFnZUhyZWYgPSBjdXJIcmVmLnJlcGxhY2UoY3VyUGFnZVJlZywgYCQxJHtwYWdlTnVtICsgMn0ke2FmdGVyU3RyfWApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG90aGVyUGFnZUVsZSA9IGJvZHkucXVlcnlTZWxlY3RvcihgYVtocmVmPScke290aGVyUGFnZUhyZWZ9J11gKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvdGhlclBhZ2VFbGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgcGFyZW50ID0gb3RoZXJQYWdlRWxlLnBhcmVudE5vZGU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBhcmVudCAmJiBwYXJlbnQucGFyZW50Tm9kZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnQgPSBwYXJlbnQucGFyZW50Tm9kZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBhcmVudC5wYXJlbnROb2RlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnQgPSBwYXJlbnQucGFyZW50Tm9kZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGFyZW50ICYmIHBhcmVudC5jb250YWlucyhvdGhlclBhZ2VFbGUpICYmICEvXlxkKyQvLnRlc3Qob3RoZXJQYWdlRWxlLmlubmVyVGV4dC50cmltKCkpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5leHQ0ID0gbnVsbDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAobmV4dDIgJiYgZG91YnRUZXh0UmVnLnRlc3QobmV4dDIuaW5uZXJUZXh0KSkgewogICAgICAgICAgICAgICAgICAgIG5leHQyID0gdGhpcy52ZXJpZnlOZXh0KG5leHQyLCBkb2MpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKG5leHRKczIgJiYgZG91YnRUZXh0UmVnLnRlc3QobmV4dEpzMi5pbm5lclRleHQpKSB7CiAgICAgICAgICAgICAgICAgICAgbmV4dEpzMiA9IHRoaXMudmVyaWZ5TmV4dChuZXh0SnMyLCBkb2MpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKG5leHQzKSB7CiAgICAgICAgICAgICAgICAgICAgbmV4dDMgPSB0aGlzLnZlcmlmeU5leHQobmV4dDMsIGRvYyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAobmV4dEpzMykgewogICAgICAgICAgICAgICAgICAgIG5leHRKczMgPSB0aGlzLnZlcmlmeU5leHQobmV4dEpzMywgZG9jKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIW5leHQpIG5leHQgPSBuZXh0MSB8fCBuZXh0NCB8fCBuZXh0MyB8fCBuZXh0MjsKICAgICAgICAgICAgaWYgKCFuZXh0KSB7CiAgICAgICAgICAgICAgICBuZXh0ID0ganNOZXh0IHx8IG5leHRKczEgfHwgbmV4dEpzMyB8fCBuZXh0SnMyOwogICAgICAgICAgICAgICAgaWYgKG5leHQgJiYgbmV4dC5wYXJlbnROb2RlLmNsYXNzTmFtZS5pbmRleE9mKCd0YWInKSAhPSAtMSkgbmV4dCA9IG51bGw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKG5leHQgJiYgbmV4dC5jbGFzc0xpc3QgJiYgbmV4dC5jbGFzc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RUb3AobmV4dCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKHRvcCA8IDIwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG5leHQgPSBudWxsOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBib3R0b20gPSB0b3AgKyBuZXh0Lm9mZnNldEhlaWdodCB8fCAwOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgc2Nyb2xsSCA9IE1hdGgubWF4KGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5zY3JvbGxIZWlnaHQsIGdldEJvZHkoZG9jdW1lbnQpLnNjcm9sbEhlaWdodCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzY3JvbGxIIC0gYm90dG9tIDwgMTApIG5leHQgPSBudWxsOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmV4dDsKICAgICAgICB9CgogICAgICAgIGNhbm9uaWNhbFVyaShzcmMpIHsKICAgICAgICAgICAgaWYgKCFzcmMpIHsKICAgICAgICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc3JjLmNoYXJBdCgwKSA9PSAiIyIpIHJldHVybiB0aGlzLmN1clVybCArIHNyYzsKICAgICAgICAgICAgaWYgKHNyYy5jaGFyQXQoMCkgPT0gIj8iKSByZXR1cm4gdGhpcy5jdXJVcmwucmVwbGFjZSgvXihbXlw/I10rKS4qLywgIiQxIiArIHNyYyk7CiAgICAgICAgICAgIGxldCBvcmlnaW4gPSBsb2NhdGlvbi5wcm90b2NvbCArICcvLycgKyBsb2NhdGlvbi5ob3N0OwogICAgICAgICAgICBsZXQgdXJsID0gdGhpcy5iYXNlUGF0aCB8fCBvcmlnaW47CiAgICAgICAgICAgIHVybCA9IHVybC5yZXBsYWNlKC8oXD98IykuKi8sICIiKTsKICAgICAgICAgICAgaWYgKC9odHRwcz86XC9cL1teXC9dKyQvLnRlc3QodXJsKSkgdXJsID0gdXJsICsgJy8nOwogICAgICAgICAgICBpZiAodXJsLmluZGV4T2YoImh0dHAiKSAhPT0gMCkgdXJsID0gb3JpZ2luICsgdXJsOwogICAgICAgICAgICB2YXIgcm9vdF9wYWdlID0gL15bXlw/I10qXC8vLmV4ZWModXJsKVswXSwKICAgICAgICAgICAgICAgIHJvb3RfZG9tYWluID0gL15cdytcOlwvXC9cLz9bXlwvXSsvLmV4ZWMocm9vdF9wYWdlKVswXSwKICAgICAgICAgICAgICAgIGFic29sdXRlX3JlZ2V4ID0gL15cdytcOlwvXC8vOwogICAgICAgICAgICB0aGlzLnVwZGF0ZVVybCA9IGZhbHNlOwogICAgICAgICAgICB3aGlsZSAoc3JjLmluZGV4T2YoIi4uLyIpID09PSAwKSB7CiAgICAgICAgICAgICAgICBzcmMgPSBzcmMuc3Vic3RyKDMpOwogICAgICAgICAgICAgICAgcm9vdF9wYWdlID0gcm9vdF9wYWdlLnJlcGxhY2UoL1wvW15cL10rXC8kLywgIi8iKTsKICAgICAgICAgICAgICAgIHRoaXMudXBkYXRlVXJsID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzcmMgPSBzcmMucmVwbGFjZSgvXC5cLy8sICIiKTsKICAgICAgICAgICAgaWYgKC9eXC9cL1wvPy8udGVzdChzcmMpKSB7CiAgICAgICAgICAgICAgICBzcmMgPSBsb2NhdGlvbi5wcm90b2NvbCArIHNyYzsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gKGFic29sdXRlX3JlZ2V4LnRlc3Qoc3JjKSA/IHNyYyA6ICgoc3JjLmNoYXJBdCgwKSA9PSAiLyIgPyByb290X2RvbWFpbiA6IHJvb3RfcGFnZSkgKyBzcmMpKTsKICAgICAgICB9CgogICAgICAgIGdldExpbmtCeVBhZ2UodXJsLCBwYWdlTnVtKSB7CiAgICAgICAgICAgIGlmICghdXJsKSByZXR1cm47CiAgICAgICAgICAgIGlmICh0aGlzLmN1clNpdGVSdWxlLnBhZ2VOdW0pIHsKICAgICAgICAgICAgICAgIGxldCByZXN1bHQgPSB0aGlzLmN1clNpdGVSdWxlLnBhZ2VOdW07CiAgICAgICAgICAgICAgICBsZXQgc3RyTWF0Y2ggPSByZXN1bHQubWF0Y2goL1x7Lio/fS8pOwogICAgICAgICAgICAgICAgaWYgKCFzdHJNYXRjaCkgcmV0dXJuIG51bGw7CiAgICAgICAgICAgICAgICBsZXQgdXJsUmVnID0gbmV3IFJlZ0V4cCgiKCIgKyByZXN1bHQucmVwbGFjZShzdHJNYXRjaFswXSwgIilcXGQrKCIpICsgIikiLCAiaSIpOwogICAgICAgICAgICAgICAgbGV0IGNvZGUgPSBzdHJNYXRjaFswXS5yZXBsYWNlKC9eey8sICIiKS5yZXBsYWNlKC99JC8sICIiKS5yZXBsYWNlKC9cJHAvZywgcGFnZU51bSk7CiAgICAgICAgICAgICAgICBpZiAoY29kZSA9PSBwYWdlTnVtKSB7CiAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gdXJsLnJlcGxhY2UodXJsUmVnLCAiJDEiICsgY29kZSArICIkMiIpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICBjb2RlID0gRnVuY3Rpb24oJyJ1c2Ugc3RyaWN0IjtyZXR1cm4gJyArIGNvZGUpKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHVybC5yZXBsYWNlKHVybFJlZywgIiQxIiArIGNvZGUgKyAiJDIiKTsKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHJlc3VsdCAhPSB1cmwpIHsKICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiB1cmwucmVwbGFjZSgvKFsmXC9cP10ocD18cGFnZVs9XC9fLV0/KSlcZCsvaSwgIiQxIiArIHBhZ2VOdW0pLnJlcGxhY2UoLyhbXy1dKVxkK1wuL2ksICIkMSIgKyBwYWdlTnVtICsgIi4iKTsKICAgICAgICB9CgogICAgICAgIGdldFBhZ2VOdW1Gcm9tVXJsKHVybCkgewogICAgICAgICAgICBpZiAoIXVybCkgcmV0dXJuIGN1clBhZ2U7CiAgICAgICAgICAgIGlmICh0aGlzLmN1clNpdGVSdWxlLnBhZ2VOdW0pIHsKICAgICAgICAgICAgICAgIGxldCByZXN1bHQgPSB0aGlzLmN1clNpdGVSdWxlLnBhZ2VOdW07CiAgICAgICAgICAgICAgICBsZXQgc3RyTWF0Y2ggPSByZXN1bHQubWF0Y2goL1x7Lio/fS8pOwogICAgICAgICAgICAgICAgaWYgKCFzdHJNYXRjaCkgcmV0dXJuIG51bGw7CiAgICAgICAgICAgICAgICBsZXQgdXJsUmVnID0gbmV3IFJlZ0V4cCgiLioiICsgcmVzdWx0LnJlcGxhY2Uoc3RyTWF0Y2hbMF0sICIoXFxkKykiKSArICIuKiIsICJpIik7CiAgICAgICAgICAgICAgICBsZXQgY3VyU2hvd051bSA9IHVybC5yZXBsYWNlKHVybFJlZywgIiQxIik7CiAgICAgICAgICAgICAgICBpZiAoY3VyU2hvd051bSAhPSB1cmwpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgY29kZSA9IHN0ck1hdGNoWzBdLnJlcGxhY2UoL157LywgIiIpLnJlcGxhY2UoL30kLywgIiIpOwogICAgICAgICAgICAgICAgICAgIGlmIChjb2RlID09ICIkcCIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGN1clNob3dOdW07CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBwYWdlMSA9IEZ1bmN0aW9uKCcidXNlIHN0cmljdCI7cmV0dXJuICcgKyBjb2RlLnJlcGxhY2UoIiRwIiwgIjAiKSkoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBwYWdlMiA9IEZ1bmN0aW9uKCcidXNlIHN0cmljdCI7cmV0dXJuICcgKyBjb2RlLnJlcGxhY2UoIiRwIiwgIjEiKSkoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBudW1HYXAgPSBwYWdlMiAtIHBhZ2UxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIChjdXJTaG93TnVtIC0gcGFnZTEpIC8gbnVtR2FwOwogICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICByZXR1cm4gY3VyUGFnZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBsZXQgcGFnZU51bSA9IHVybC5yZXBsYWNlKC8uKlsmXC9cP10ocD18cGFnZVs9XC9fLV0/KShcZCspLiovaSwgIiQyIik7CiAgICAgICAgICAgIHJldHVybiBwYWdlTnVtID09IHVybCA/IGN1clBhZ2UgOiAocGFnZU51bS5sZW5ndGggPiA0ID8gY3VyUGFnZSA6IHBhZ2VOdW0pOwogICAgICAgIH0KCiAgICAgICAgYXN5bmMgZ2V0TmV4dExpbmsoZG9jKSB7CiAgICAgICAgICAgIGxldCBuZXh0TGluayA9IG51bGwsIHBhZ2UsIGhyZWY7CiAgICAgICAgICAgIGxldCBnZXROZXh0TGlua0J5Rm9ybSA9IChmb3JtLCBzdWJtaXRCdG4sIG4pID0+IHsKICAgICAgICAgICAgICAgIGxldCBwYXJhbXMgPSBbXTsKICAgICAgICAgICAgICAgIGxldCBmb3JtRGF0YSA9IG5ldyBGb3JtRGF0YShmb3JtKTsKICAgICAgICAgICAgICAgIGlmIChzdWJtaXRCdG4gJiYgc3VibWl0QnRuLmdldEF0dHJpYnV0ZSkgewogICAgICAgICAgICAgICAgICAgIGxldCBidG5WYWx1ZSwgYnRuTmFtZTsKICAgICAgICAgICAgICAgICAgICBidG5OYW1lID0gc3VibWl0QnRuLmdldEF0dHJpYnV0ZSgibmFtZSIpOwogICAgICAgICAgICAgICAgICAgIGJ0blZhbHVlID0gc3VibWl0QnRuLmdldEF0dHJpYnV0ZSgidmFsdWUiKTsKICAgICAgICAgICAgICAgICAgICBpZiAoYnRuTmFtZSAmJiBidG5WYWx1ZSkgcGFyYW1zID0gW2J0bk5hbWUgKyAiPSIgKyBidG5WYWx1ZV07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmb3IgKGxldCBba2V5LCB2YWx1ZV0gb2YgZm9ybURhdGEpIHsKICAgICAgICAgICAgICAgICAgICBpZiAobiAmJiAvXihwfHBhZ2UpJC9pLnRlc3Qoa2V5KSkgewogICAgICAgICAgICAgICAgICAgICAgICBwYXJhbXMucHVzaChrZXkgKyAnPScgKyBuKTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBwYXJhbXMucHVzaChrZXkgKyAnPScgKyBlbmNvZGVVUklDb21wb25lbnQodmFsdWUpKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwYXJhbXMgPSBwYXJhbXMuam9pbignJicpOwogICAgICAgICAgICAgICAgcmV0dXJuIGZvcm0uYWN0aW9uICsgKGZvcm0uYWN0aW9uLmluZGV4T2YoJz8nKSA9PSAtMSA/ICc/JyA6ICcmJykgKyBwYXJhbXMgKyAoZm9ybS5tZXRob2QgPT0gJ3Bvc3QnID8gJyNweycgKyBwYXJhbXMgKyAnfScgOiAnJyk7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGlmICh0aGlzLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50QnlKcykgewogICAgICAgICAgICAgICAgdGhpcy5uZXh0TGlua0hyZWYgPSAiIyI7CiAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLmN1clNpdGVSdWxlLm5leHRMaW5rQnlKcykgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBsZXQgb3ZlciA9IF91cmwgPT4gewogICAgICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICAgICAgbGV0IHRhcmdldFVybCA9IGF3YWl0ICgodHlwZW9mIF91bnNhZmVXaW5kb3cucGFnZXR1YWxOZXh0TGlua0J5SnMgPT0gJ3VuZGVmaW5lZCcpID8gbmV3IEFzeW5jRnVuY3Rpb24oImRvYyIsICcidXNlIHN0cmljdCI7JyArIHRoaXMuY3VyU2l0ZVJ1bGUubmV4dExpbmtCeUpzKSA6IF91bnNhZmVXaW5kb3cucGFnZXR1YWxOZXh0TGlua0J5SnMpKGRvYyk7CiAgICAgICAgICAgICAgICAgICAgaWYgKHRhcmdldFVybCkgbmV4dExpbmsgPSB7aHJlZjogdGFyZ2V0VXJsfTsKICAgICAgICAgICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuY3VyU2l0ZVJ1bGUubmV4dExpbmtCeVVybCkgewogICAgICAgICAgICAgICAgbGV0IHRhcmdldFVybCA9IHRoaXMuY3VyVXJsLnJlcGxhY2UobmV3IFJlZ0V4cCh0aGlzLmN1clNpdGVSdWxlLm5leHRMaW5rQnlVcmxbMF0sICJpIiksIHRoaXMuY3VyU2l0ZVJ1bGUubmV4dExpbmtCeVVybFsxXSk7CiAgICAgICAgICAgICAgICBpZiAodGFyZ2V0VXJsICE9IHRoaXMuY3VyVXJsKSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGluY2x1ZGVTZWwgPSB0aGlzLmN1clNpdGVSdWxlLm5leHRMaW5rQnlVcmxbMl07CiAgICAgICAgICAgICAgICAgICAgbGV0IGV4Y2x1ZGVTZWwgPSB0aGlzLmN1clNpdGVSdWxlLm5leHRMaW5rQnlVcmxbM107CiAgICAgICAgICAgICAgICAgICAgaWYgKGluY2x1ZGVTZWwpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaW5jbHVkZVNlbCA9IGluY2x1ZGVTZWwudHJpbSgpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoIWdldEVsZW1lbnQoaW5jbHVkZVNlbCwgZG9jKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5uZXh0TGlua0hyZWY9ZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoZXhjbHVkZVNlbCkgewogICAgICAgICAgICAgICAgICAgICAgICBleGNsdWRlU2VsID0gZXhjbHVkZVNlbC50cmltKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChnZXRFbGVtZW50KGV4Y2x1ZGVTZWwsIGRvYykpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmPWZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG51bGw7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgbGV0IHJlcHMgPSB0YXJnZXRVcmwubWF0Y2goL3suKj99L2cpOwogICAgICAgICAgICAgICAgICAgIGlmIChyZXBzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlcHMuZm9yRWFjaChyZXAgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGNvZGUgPSByZXAucmVwbGFjZSgieyIsICIiKS5yZXBsYWNlKCJ9IiwgIiIpLnJlcGxhY2UoL1woXCkvZywgIjAiKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCByZXN1bHQgPSBjb2RlLm1hdGNoKC9eKFxkKilcKzEkLyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocmVzdWx0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcGFyc2VJbnQocmVzdWx0WzFdIHx8IDEpICsgMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gRnVuY3Rpb24oJyJ1c2Ugc3RyaWN0IjtyZXR1cm4gJyArIGNvZGUpKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRhcmdldFVybCA9IHRhcmdldFVybC5yZXBsYWNlKHJlcCwgcmVzdWx0KTsKICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgbmV4dExpbmsgPSB7aHJlZjogdGFyZ2V0VXJsfTsKICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLmN1clNpdGVSdWxlLm5leHRMaW5rKSB7CiAgICAgICAgICAgICAgICBsZXQgbmV4dExpbmtTZWwgPSB0aGlzLmN1clNpdGVSdWxlLm5leHRMaW5rOwogICAgICAgICAgICAgICAgaWYgKG5leHRMaW5rU2VsICE9IDApIHsKICAgICAgICAgICAgICAgICAgICBpZiAoQXJyYXkgJiYgQXJyYXkuaXNBcnJheSAmJiBBcnJheS5pc0FycmF5KG5leHRMaW5rU2VsKSkgewogICAgICAgICAgICAgICAgICAgICAgICBuZXh0TGluayA9IGdldEVsZW1lbnQobmV4dExpbmtTZWxbbmV4dEluZGV4XSwgZG9jKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFuZXh0TGluayAmJiBjdXJQYWdlID09IDEgJiYgbmV4dEluZGV4ICE9IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5leHRJbmRleCA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZXh0TGluayA9IGdldEVsZW1lbnQobmV4dExpbmtTZWxbbmV4dEluZGV4XSwgZG9jKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBuZXh0TGluayA9IGdldEVsZW1lbnQobmV4dExpbmtTZWwsIGRvYyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAobmV4dExpbmsgJiYgKHRoaXMuY3VyU2l0ZVJ1bGUuYWN0aW9uID09IDAgfHwgdGhpcy5jdXJTaXRlUnVsZS5hY3Rpb24gPT0gMSB8fCB0aGlzLmN1clNpdGVSdWxlLmFjdGlvbiA9PSAyKSkgewogICAgICAgICAgICAgICAgICAgIGxldCBmb3JtID0gZG9jLnF1ZXJ5U2VsZWN0b3IoJyNzZWFyY2gtZm9ybScpOwogICAgICAgICAgICAgICAgICAgIGlmICghbmV4dExpbmsuaHJlZiAmJiBuZXh0TGluay5oYXNBdHRyaWJ1dGUgJiYgbmV4dExpbmsuaGFzQXR0cmlidXRlKCJvbmNsaWNrIikgJiYgZm9ybSkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoL15cZCskLy50ZXN0KG5leHRMaW5rLmlubmVyVGV4dCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5leHRMaW5rLmhyZWYgPSBnZXROZXh0TGlua0J5Rm9ybShmb3JtLCBuZXh0TGluaywgbmV4dExpbmsuaW5uZXJUZXh0KTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoL15JTlBVVCQvaS50ZXN0KG5leHRMaW5rLm5vZGVOYW1lKSB8fCBuZXh0TGluay50eXBlID09ICJzdWJtaXQiKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvcm0gPSBuZXh0TGluay5wYXJlbnROb2RlOwogICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoZm9ybSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC9eRk9STSQvaS50ZXN0KGZvcm0ubm9kZU5hbWUpKSBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UgZm9ybSA9IGZvcm0ucGFyZW50Tm9kZTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZm9ybSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV4dExpbmsuaHJlZiA9IGdldE5leHRMaW5rQnlGb3JtKGZvcm0sIG5leHRMaW5rKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAobmV4dExpbmsuaHJlZiAmJiB0aGlzLmN1clNpdGVSdWxlLmFjdGlvbiAhPSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG5leHRMaW5rLmhyZWYgPSBuZXh0TGluay5ocmVmLnJlcGxhY2UoLyNwey4qLywgIiIpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBhZ2UgPSBhd2FpdCB0aGlzLmdldFBhZ2UoZG9jKTsKICAgICAgICAgICAgICAgIG5leHRMaW5rID0gcGFnZS5uZXh0OwogICAgICAgICAgICAgICAgaWYgKG5leHRMaW5rKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKC9eSU5QVVQkL2kudGVzdChuZXh0TGluay5ub2RlTmFtZSkgfHwgbmV4dExpbmsudHlwZSA9PSAic3VibWl0IikgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZm9ybSA9IG5leHRMaW5rLnBhcmVudE5vZGU7CiAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChmb3JtKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoL15GT1JNJC9pLnRlc3QoZm9ybS5ub2RlTmFtZSkpIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSBmb3JtID0gZm9ybS5wYXJlbnROb2RlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChmb3JtKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZXh0TGluay5ocmVmID0gZ2V0TmV4dExpbmtCeUZvcm0oZm9ybSwgbmV4dExpbmspOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxldCBwYXJlbnQgPSBuZXh0TGluazsKICAgICAgICAgICAgICAgICAgICB3aGlsZSAocGFyZW50ICYmICEvXkJPRFkkL2kudGVzdChwYXJlbnQubm9kZU5hbWUpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICgvXkFTSURFJC9pLnRlc3QocGFyZW50Lm5vZGVOYW1lKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5uZXh0TGlua0hyZWYgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBudWxsOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwYXJlbnQuaGFzQXR0cmlidXRlICYmIHBhcmVudC5oYXNBdHRyaWJ1dGUoImRpc2FibGVkIikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpZiAocGFyZW50LmNsYXNzTmFtZSAmJiBwYXJlbnQuY2xhc3NMaXN0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGFyZW50LmNsYXNzTGlzdC5jb250YWlucygibm9DbGljayIpIHx8IHBhcmVudC5jbGFzc0xpc3QuY29udGFpbnMoIm5vLXBhZ2VzIikgfHwgcGFyZW50LmNsYXNzTGlzdC5jb250YWlucygiZGlzYWJsZWQiKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG51bGw7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBhcmVudC5zdHlsZSAmJiBwYXJlbnQuc3R5bGUuZGlzcGxheSA9PT0gIm5vbmUiKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLm5leHRMaW5rSHJlZiA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG51bGw7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgcGFyZW50ID0gcGFyZW50LnBhcmVudE5vZGU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChkb2MgPT0gZG9jdW1lbnQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCghbmV4dExpbmsuaHJlZiB8fCAvXihqYXZhc2NyaXB0fCMpLy50ZXN0KG5leHRMaW5rLmhyZWYucmVwbGFjZShsb2NhdGlvbi5ocmVmLCAiIikpKSAmJiAhaXNWaXNpYmxlKG5leHRMaW5rLCBfdW5zYWZlV2luZG93KSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5uZXh0TGlua0hyZWYgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBudWxsOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IG5leHRMaW5rQ3MgPSBfdW5zYWZlV2luZG93LmdldENvbXB1dGVkU3R5bGUobmV4dExpbmspOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG5leHRMaW5rQ3MuY3Vyc29yID09ICJub3QtYWxsb3dlZCIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLm5leHRMaW5rSHJlZiA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBudWxsOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5pbml0TmV4dCA9IG5leHRMaW5rOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxldCBmb3JtID0gZG9jLnF1ZXJ5U2VsZWN0b3IoJyNzZWFyY2gtZm9ybScpOwogICAgICAgICAgICAgICAgICAgIGlmICghbmV4dExpbmsuaHJlZiAmJiBuZXh0TGluay5oYXNBdHRyaWJ1dGUoIm9uY2xpY2siKSAmJiBmb3JtKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChmb3JtICYmIC9eXGQrJC8udGVzdChuZXh0TGluay5pbm5lclRleHQpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBocmVmID0gZ2V0TmV4dExpbmtCeUZvcm0oZm9ybSwgbmV4dExpbmssIG5leHRMaW5rLmlubmVyVGV4dCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKG5leHRMaW5rKSB7CiAgICAgICAgICAgICAgICBpZiAoIXRoaXMuY2hlY2tTdG9wU2lnbihuZXh0TGluaywgZG9jKSkgcmV0dXJuIG51bGw7CiAgICAgICAgICAgICAgICBpZiAodGhpcy5jdXJTaXRlUnVsZS5hY3Rpb24gPT0gMykgewogICAgICAgICAgICAgICAgICAgIGlmIChkb2MgPT0gZG9jdW1lbnQpIGRlYnVnKG5leHRMaW5rLCAnTmV4dCBsaW5rJyk7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5uZXh0TGlua0hyZWYgPSAnIyc7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGxldCBuZWVkVXJsID0gKHRoaXMuY3VyU2l0ZVJ1bGUuYWN0aW9uID09IDAgfHwgdGhpcy5jdXJTaXRlUnVsZS5hY3Rpb24gPT0gMSB8fCB0aGlzLmN1clNpdGVSdWxlLmFjdGlvbiA9PSAyKTsKICAgICAgICAgICAgICAgICAgICBpZiAoIWhyZWYpIGhyZWYgPSBuZXh0TGluay5ocmVmOwogICAgICAgICAgICAgICAgICAgIGlmIChocmVmICYmIG5leHRMaW5rLmdldEF0dHJpYnV0ZSkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgX2hyZWYgPSBuZXh0TGluay5nZXRBdHRyaWJ1dGUoImhyZWYiKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKF9ocmVmKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoX2hyZWYuY2hhckF0KDApID09ICIjIiB8fCBfaHJlZiA9PSAiPyIpewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhyZWYgPSAiIyI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhyZWYgPSBfaHJlZjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChfaHJlZiA9PT0gIiIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhyZWYgPSBfaHJlZjsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgaWYgKG5lZWRVcmwgJiYgKGhyZWYgPT09ICIiIHx8IGhyZWYgPT09IG51bGwpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChuZWVkVXJsICYmIC9eKGphdmFzY3JpcHQ6fCMpLy50ZXN0KGhyZWYpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5uZXh0TGlua0hyZWYgPSAoaHJlZiAmJiAhL14oamF2YXNjcmlwdDp8IykvLnRlc3QoaHJlZikpID8gdGhpcy5jYW5vbmljYWxVcmkoaHJlZikgOiAiIyI7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCB0ZW1wVXJsID0gdGhpcy5uZXh0TGlua0hyZWYucmVwbGFjZSgvI3B7LiovLCAiIik7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0ZW1wVXJsICE9ICIjIiAmJiAodGhpcy5jb21wYXJlVXJsKHRlbXBVcmwsIHRoaXMuaW5pdFVybCkgfHwgdGhpcy5jb21wYXJlVXJsKHRlbXBVcmwsIHRoaXMuY3VyVXJsKSB8fCB0aGlzLmNvbXBhcmVVcmwodGVtcFVybCwgdGhpcy5jdXJVcmwgKyAiIyIpIHx8IHRoaXMuY29tcGFyZVVybCh0ZW1wVXJsLCB0aGlzLm9sZFVybCkgfHwgdGhpcy5jb21wYXJlVXJsKHRlbXBVcmwsIHRoaXMub2xkVXJsICsgIiMiKSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoZG9jID09IGRvY3VtZW50KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhuZXh0TGluaywgJ05leHQgbGluaycpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdGhpcy5uZXh0TGlua0hyZWYgPSBmYWxzZTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLm5leHRMaW5rRWxlID0gbmV4dExpbms7CiAgICAgICAgICAgIHRoaXMucHJlbG9hZCgpOwogICAgICAgICAgICByZXR1cm4gbmV4dExpbms7CiAgICAgICAgfQoKICAgICAgICBjb21wYXJlVXJsKHVybDEsIHVybDIpIHsKICAgICAgICAgICAgaWYgKHVybDEgPT0gdXJsMikgcmV0dXJuIHRydWU7CiAgICAgICAgICAgIGlmICghdXJsMSB8fCAhdXJsMikgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICBsZXQgdXJsMUFyciA9IHVybDEuc3BsaXQoIj8iKTsKICAgICAgICAgICAgbGV0IHVybDJBcnIgPSB1cmwyLnNwbGl0KCI/Iik7CiAgICAgICAgICAgIGlmICh1cmwxQXJyWzBdICE9IHVybDJBcnJbMF0pIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgaWYgKCF1cmwxQXJyWzFdIHx8ICF1cmwyQXJyWzFdKSByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgIHVybDFBcnIgPSB1cmwxQXJyWzFdLnNwbGl0KCImIikuc29ydCgpLmpvaW4oIiYiKTsKICAgICAgICAgICAgdXJsMkFyciA9IHVybDJBcnJbMV0uc3BsaXQoIiYiKS5zb3J0KCkuam9pbigiJiIpOwogICAgICAgICAgICByZXR1cm4gdXJsMUFyciA9PSB1cmwyQXJyOwogICAgICAgIH0KCiAgICAgICAgZmlsdGVyRWxlcyhkb2MsIGVsZXMpIHsKICAgICAgICAgICAgbGV0IGZpbHRlciA9IHRoaXMuY3VyU2l0ZVJ1bGUuZmlsdGVyOwogICAgICAgICAgICBpZiAoIWZpbHRlciB8fCAhZWxlcyB8fCBlbGVzLmxlbmd0aCA9PT0gMCkgcmV0dXJuOwogICAgICAgICAgICBpZiAoZWxlcy5sZW5ndGggPT09IDEpIHsKICAgICAgICAgICAgICAgIGVsZXMgPSBlbGVzWzBdLmNoaWxkcmVuOwogICAgICAgICAgICAgICAgaWYgKGVsZXMubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgZWxlcyA9IGVsZXNbMF0uY2hpbGRyZW47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHR5cGVvZiBmaWx0ZXIgPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgIGlmICgvXlxkKyQvLnRlc3QoZmlsdGVyKSkgewogICAgICAgICAgICAgICAgICAgIGZpbHRlciA9IHtjb3VudDogcGFyc2VJbnQoZmlsdGVyKX07CiAgICAgICAgICAgICAgICB9IGVsc2UgZmlsdGVyID0ge3dvcmRzOiBmaWx0ZXJ9OwogICAgICAgICAgICB9CiAgICAgICAgICAgIFtdLmZvckVhY2guY2FsbChlbGVzLCBlbGUgPT4gewogICAgICAgICAgICAgICAgaWYgKCFlbGUucGFyZW50Tm9kZSkgcmV0dXJuOwogICAgICAgICAgICAgICAgbGV0IGNhbktlZXAgPSAoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIGxldCBpbm5lclRleHQgPSAoZWxlLmlubmVyVGV4dCAmJiBlbGUuaW5uZXJUZXh0LnRyaW0oKSkgfHwgIiI7CiAgICAgICAgICAgICAgICAgICAgaWYgKGZpbHRlci5jb3VudCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5uZXJUZXh0Lmxlbmd0aCA8IGZpbHRlci5jb3VudCkgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoZmlsdGVyLndvcmRzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCB3b3Jkc1JlZ0V4cCA9IG5ldyBSZWdFeHAoZmlsdGVyLndvcmRzLCAiaSIpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5uZXJUZXh0ICYmIHdvcmRzUmVnRXhwLnRlc3QoaW5uZXJUZXh0KSkgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoZmlsdGVyLmxpbmspIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGxpbmtSZWdFeHAgPSBuZXcgUmVnRXhwKGZpbHRlci5saW5rLCAiaSIpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoL15BJC9pLnRlc3QoZWxlLm5vZGVOYW1lKSAmJiBsaW5rUmVnRXhwLnRlc3QoZWxlLmhyZWYpKSByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBhQ2hpbGRyZW4gPSBlbGUucXVlcnlTZWxlY3RvckFsbCgiYSIpOwogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGFDaGlsZHJlbi5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGNoaWxkID0gYUNoaWxkcmVuW2ldOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxpbmtSZWdFeHAudGVzdChjaGlsZC5ocmVmKSkgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChmaWx0ZXIuc2VsZWN0b3IpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGdldEVsZW1lbnQoZmlsdGVyLnNlbGVjdG9yLCBkb2MsIGVsZSkpIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICAgICAgICB9KSgpOwogICAgICAgICAgICAgICAgaWYgKCFjYW5LZWVwKSB7CiAgICAgICAgICAgICAgICAgICAgZWxlLnBhcmVudE5vZGUucmVtb3ZlQ2hpbGQoZWxlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSk7CiAgICAgICAgfQoKICAgICAgICBjaGVja1N0b3BTaWduKG5leHRMaW5rLCBkb2MpIHsKICAgICAgICAgICAgaWYgKHRoaXMuY3VyU2l0ZVJ1bGUuc3RvcFNpZ24pIHsKICAgICAgICAgICAgICAgIGxldCB0eXBlQXJyYXkgPSBBcnJheSAmJiBBcnJheS5pc0FycmF5ICYmIEFycmF5LmlzQXJyYXkodGhpcy5jdXJTaXRlUnVsZS5zdG9wU2lnbik7CiAgICAgICAgICAgICAgICBsZXQgdHlwZU9iamVjdCA9ICF0eXBlQXJyYXkgJiYgKHRoaXMuY3VyU2l0ZVJ1bGUuc3RvcFNpZ24uaW5jbHVkZSB8fCB0aGlzLmN1clNpdGVSdWxlLnN0b3BTaWduLmV4Y2x1ZGUgfHwgdGhpcy5jdXJTaXRlUnVsZS5zdG9wU2lnbi5wYWdlTnVtKTsKICAgICAgICAgICAgICAgIGlmICh0eXBlQXJyYXkgfHwgdHlwZU9iamVjdCkgewogICAgICAgICAgICAgICAgICAgIGxldCBpbmNsdWRlU2VsLCBleGNsdWRlU2VsLCBjdXJTaWduLCBtYXhTaWduOwogICAgICAgICAgICAgICAgICAgIGlmICh0eXBlQXJyYXkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaW5jbHVkZVNlbCA9IHRoaXMuY3VyU2l0ZVJ1bGUuc3RvcFNpZ25bMF07CiAgICAgICAgICAgICAgICAgICAgICAgIGV4Y2x1ZGVTZWwgPSB0aGlzLmN1clNpdGVSdWxlLnN0b3BTaWduWzFdOwogICAgICAgICAgICAgICAgICAgICAgICBjdXJTaWduID0gdGhpcy5jdXJTaXRlUnVsZS5zdG9wU2lnblsyXTsKICAgICAgICAgICAgICAgICAgICAgICAgbWF4U2lnbiA9IHRoaXMuY3VyU2l0ZVJ1bGUuc3RvcFNpZ25bM107CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChBcnJheSAmJiBBcnJheS5pc0FycmF5ICYmIEFycmF5LmlzQXJyYXkoaW5jbHVkZVNlbCkgJiYgIWN1clNpZ24pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1clNpZ24gPSBpbmNsdWRlU2VsOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5jbHVkZVNlbCA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChleGNsdWRlU2VsICYmIEFycmF5ICYmIEFycmF5LmlzQXJyYXkgJiYgQXJyYXkuaXNBcnJheShleGNsdWRlU2VsKSAmJiAhbWF4U2lnbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbWF4U2lnbiA9IGV4Y2x1ZGVTZWw7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBleGNsdWRlU2VsID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBpbmNsdWRlU2VsID0gdGhpcy5jdXJTaXRlUnVsZS5zdG9wU2lnbi5pbmNsdWRlOwogICAgICAgICAgICAgICAgICAgICAgICBleGNsdWRlU2VsID0gdGhpcy5jdXJTaXRlUnVsZS5zdG9wU2lnbi5leGNsdWRlOwogICAgICAgICAgICAgICAgICAgICAgICBjdXJTaWduID0gdGhpcy5jdXJTaXRlUnVsZS5zdG9wU2lnbi5wYWdlTnVtOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaW5jbHVkZVNlbCkgewogICAgICAgICAgICAgICAgICAgICAgICBpbmNsdWRlU2VsID0gaW5jbHVkZVNlbC50cmltKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghZ2V0RWxlbWVudChpbmNsdWRlU2VsLCBkb2MpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc1BhdXNlID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKGV4Y2x1ZGVTZWwpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZXhjbHVkZVNlbCA9IGV4Y2x1ZGVTZWwudHJpbSgpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZ2V0RWxlbWVudChleGNsdWRlU2VsLCBkb2MpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc1BhdXNlID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKGN1clNpZ24pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFtYXhTaWduKSBtYXhTaWduID0gY3VyU2lnbi5zbGljZSgyKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGN1cnJlbnRFbGUgPSBnZXRFbGVtZW50KGN1clNpZ25bMF0sIGRvYyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBtYXhFbGUgPSBnZXRFbGVtZW50KG1heFNpZ25bMF0sIGRvYyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJyZW50RWxlICYmIG1heEVsZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGN1cnJlbnRTaWduTnVtLCBtYXhTaWduTnVtOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC9cKC4qXCkvLnRlc3QoY3VyU2lnblsxXSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjdXJyZW50U2lnbk51bSA9IGN1cnJlbnRFbGUuaW5uZXJUZXh0Lm1hdGNoKG5ldyBSZWdFeHAoY3VyU2lnblsxXSkpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJyZW50U2lnbk51bSkgY3VycmVudFNpZ25OdW0gPSBjdXJyZW50U2lnbk51bVsxXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudEVsZS5nZXRBdHRyaWJ1dGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjdXJyZW50U2lnbk51bSA9IGN1cnJlbnRFbGUuZ2V0QXR0cmlidXRlKGN1clNpZ25bMV0pOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKC9cKC4qXCkvLnRlc3QobWF4U2lnblsxXSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhTaWduTnVtID0gbWF4RWxlLmlubmVyVGV4dC5tYXRjaChuZXcgUmVnRXhwKG1heFNpZ25bMV0pKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobWF4U2lnbk51bSkgbWF4U2lnbk51bSA9IG1heFNpZ25OdW1bMV07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG1heEVsZS5nZXRBdHRyaWJ1dGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhTaWduTnVtID0gbWF4RWxlLmdldEF0dHJpYnV0ZShtYXhTaWduWzFdKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjdXJyZW50U2lnbk51bSAmJiBtYXhTaWduTnVtICYmIGN1cnJlbnRTaWduTnVtID09IG1heFNpZ25OdW0pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc1BhdXNlID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLm5leHRMaW5rSHJlZiA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHN0b3BTaWduID0gKCh0eXBlb2YgX3Vuc2FmZVdpbmRvdy5zdG9wU2lnbiA9PSAndW5kZWZpbmVkJykgPyBGdW5jdGlvbigiZG9jIiwgIm5leHRMaW5rIiwgJyJ1c2Ugc3RyaWN0IjsnICsgdGhpcy5jdXJTaXRlUnVsZS5zdG9wU2lnbikgOiBfdW5zYWZlV2luZG93LnN0b3BTaWduKShkb2MsIG5leHRMaW5rKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0b3BTaWduKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc1BhdXNlID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KCiAgICAgICAgcHJlbG9hZCgpIHsKICAgICAgICAgICAgaWYgKCFydWxlc0RhdGEucHJlbG9hZCkgcmV0dXJuOwogICAgICAgICAgICBpZiAoIXRoaXMubmV4dExpbmtIcmVmIHx8IHRoaXMubmV4dExpbmtIcmVmID09ICIjIikgcmV0dXJuOwogICAgICAgICAgICBsZXQgc2VsZiA9IHRoaXMsIHVybCA9IHRoaXMubmV4dExpbmtIcmVmOwogICAgICAgICAgICBsZXQgcG9zdFBhcmFtcyA9IHVybC5tYXRjaCgvI3B7KC4qKX0kLyk7CiAgICAgICAgICAgIGlmIChwb3N0UGFyYW1zKSB7CiAgICAgICAgICAgICAgICBwb3N0UGFyYW1zID0gcG9zdFBhcmFtc1sxXTsKICAgICAgICAgICAgICAgIHVybCA9IHVybC5yZXBsYWNlKC8jcHsuKi8sICIiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBfR01feG1saHR0cFJlcXVlc3QoewogICAgICAgICAgICAgICAgdXJsOiB1cmwsCiAgICAgICAgICAgICAgICBtZXRob2Q6IHBvc3RQYXJhbXMgPyAnUE9TVCcgOiAnR0VUJywKICAgICAgICAgICAgICAgIGRhdGE6IHBvc3RQYXJhbXMsCiAgICAgICAgICAgICAgICBvdmVycmlkZU1pbWVUeXBlOiAndGV4dC9odG1sO2NoYXJzZXQ9JyArIChkb2N1bWVudC5jaGFyYWN0ZXJTZXQgfHwgZG9jdW1lbnQuY2hhcnNldCB8fCBkb2N1bWVudC5pbnB1dEVuY29kaW5nKSwKICAgICAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICAgICAnUmVmZXJlcic6IGxvY2F0aW9uLmhyZWYsCiAgICAgICAgICAgICAgICAgICAgJ1VzZXItQWdlbnQnOiBuYXZpZ2F0b3IudXNlckFnZW50LAogICAgICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAocG9zdFBhcmFtcyA/ICJhcHBsaWNhdGlvbi94LXd3dy1mb3JtLXVybGVuY29kZWQiIDogInRleHQvaHRtbCIpICsgIjtjaGFyc2V0PSIgKyAoZG9jdW1lbnQuY2hhcmFjdGVyU2V0IHx8IGRvY3VtZW50LmNoYXJzZXQgfHwgZG9jdW1lbnQuaW5wdXRFbmNvZGluZyksCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgdGltZW91dDogMTAwMDAsCiAgICAgICAgICAgICAgICBvbmxvYWQ6IGZ1bmN0aW9uKHJlcykgewogICAgICAgICAgICAgICAgICAgIHZhciBkb2MgPSBudWxsOwogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRvYyA9IGRvY3VtZW50LmltcGxlbWVudGF0aW9uLmNyZWF0ZUhUTUxEb2N1bWVudCgnJyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGRvYy5kb2N1bWVudEVsZW1lbnQuaW5uZXJIVE1MID0gcmVzLnJlc3BvbnNlOwogICAgICAgICAgICAgICAgICAgICAgICB2YXIgYm9keSA9IGdldEJvZHkoZG9jKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJvZHkgJiYgYm9keS5maXJzdENoaWxkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZWxmLmxhenlJbWdBY3Rpb24oYm9keS5jaGlsZHJlbik7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFzZWxmLnByZWxvYWREaXYpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYucHJlbG9hZERpdiA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ2RpdicpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5wcmVsb2FkRGl2LmlkID0gInBhZ2V0dWFsLXByZWxvYWQiOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5wcmVsb2FkRGl2LnN0eWxlLmNzc1RleHQgPSAnZGlzcGxheTpub25lIWltcG9ydGFudDsnOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgZ2V0Qm9keShkb2N1bWVudCkuYXBwZW5kQ2hpbGQoc2VsZi5wcmVsb2FkRGl2KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuY2hlY2tlZEltZ3MgPSB7fTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBbXS5mb3JFYWNoLmNhbGwoZG9jLmltYWdlcywgaSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgaVNyYyA9IGkuc3JjOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlTcmMgJiYgIXNlbGYuY2hlY2tlZEltZ3NbaVNyY10pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZWxmLmNoZWNrZWRJbWdzW2lTcmNdID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgaW1nID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgnaW1nJyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW1nLnNyYyA9IGlTcmM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5wcmVsb2FkRGl2LmFwcGVuZENoaWxkKGltZyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgY29kZSA9IHNlbGYuY3VyU2l0ZVJ1bGUucHJlbG9hZEltYWdlczsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNvZGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBpbWdTcmNBcnIgPSBuZXcgRnVuY3Rpb24oImRvYyIsICcidXNlIHN0cmljdCI7JyArIGNvZGUpKGRvYyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW1nU3JjQXJyICYmIGltZ1NyY0Fyci5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbWdTcmNBcnIuZm9yRWFjaChpbWdTcmMgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW1nU3JjICYmICFzZWxmLmNoZWNrZWRJbWdzW2ltZ1NyY10pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuY2hlY2tlZEltZ3NbaW1nU3JjXSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgaW1nID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgnaW1nJyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbWcuc3JjID0gaW1nU3JjOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5wcmVsb2FkRGl2LmFwcGVuZENoaWxkKGltZyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBjYXRjaChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9KTsKICAgICAgICB9CgogICAgICAgIGdldEluc2VydChyZWZyZXNoKSB7CiAgICAgICAgICAgIGlmIChyZWZyZXNoKSB7CiAgICAgICAgICAgICAgICB0aGlzLmluc2VydCA9IG51bGw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHRoaXMuaW5zZXJ0ICYmIGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5jb250YWlucyh0aGlzLmluc2VydCkpIHsKICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLmluc2VydDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodGhpcy5jdXJTaXRlUnVsZS5pbnNlcnQpIHsKICAgICAgICAgICAgICAgIGxldCBpbnNlcnRTZWwgPSB0aGlzLmN1clNpdGVSdWxlLmluc2VydDsKICAgICAgICAgICAgICAgIGlmIChBcnJheSAmJiBBcnJheS5pc0FycmF5ICYmIEFycmF5LmlzQXJyYXkoaW5zZXJ0U2VsKSkgewogICAgICAgICAgICAgICAgICAgIGluc2VydFNlbCA9IGluc2VydFNlbFtuZXh0SW5kZXggPCBpbnNlcnRTZWwubGVuZ3RoID8gbmV4dEluZGV4IDogMF07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0aGlzLmluc2VydCA9IGdldEVsZW1lbnQoaW5zZXJ0U2VsLCBkb2N1bWVudCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLmRvY1BhZ2VFbGVtZW50ID0gbnVsbDsKICAgICAgICAgICAgICAgIGxldCBwYWdlRWxlbWVudCA9IHRoaXMuZ2V0UGFnZUVsZW1lbnQoZG9jdW1lbnQsIF91bnNhZmVXaW5kb3cpOwogICAgICAgICAgICAgICAgaWYgKHRoaXMuY3VyU2l0ZVJ1bGUuc2luZ2xlVXJsICYmIHRoaXMubmV4dExpbmtIcmVmID09ICIjIiAmJiB0aGlzLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50ID09PSAnYm9keScpIHsKICAgICAgICAgICAgICAgICAgICBkZWJ1ZygiU3RvcCBhcyBqc05leHQgJiB3aG9sZSBib2R5Iik7CiAgICAgICAgICAgICAgICAgICAgaXNQYXVzZSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAocGFnZUVsZW1lbnQgJiYgcGFnZUVsZW1lbnQubGVuZ3RoID4gMCkgewogICAgICAgICAgICAgICAgICAgIHZhciBwRUxhc3QgPSBwYWdlRWxlbWVudFtwYWdlRWxlbWVudC5sZW5ndGggLSAxXTsKICAgICAgICAgICAgICAgICAgICB0aGlzLmluc2VydCA9IHBFTGFzdC5uZXh0U2libGluZyA/IHBFTGFzdC5uZXh0U2libGluZyA6IHBFTGFzdC5wYXJlbnROb2RlLmFwcGVuZENoaWxkKGRvY3VtZW50LmNyZWF0ZVRleHROb2RlKCcgJykpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiB0aGlzLmluc2VydDsKICAgICAgICB9CgogICAgICAgIHBhZ2VJbml0KGRvYywgZWxlcykgewogICAgICAgICAgICBsZXQgY29kZSA9IHRoaXMuY3VyU2l0ZVJ1bGUucGFnZUluaXQ7CiAgICAgICAgICAgIGlmIChjb2RlKSB7CiAgICAgICAgICAgICAgICBsZXQgaW5pdEZ1bmMgPSAoKHR5cGVvZiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsUGFnZUluaXQgPT0gJ3VuZGVmaW5lZCcpID8gRnVuY3Rpb24oImRvYyIsICJlbGVzIiwgJyJ1c2Ugc3RyaWN0IjsnICsgY29kZSkgOiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsUGFnZUluaXQpOwogICAgICAgICAgICAgICAgbGV0IGNoZWNrSW5pdCA9IChyZXNvbHZlKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGluaXRGdW5jKGRvYywgZWxlcykgPT09IGZhbHNlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGVja0luaXQocmVzb2x2ZSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LCAxMDApOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzb2x2ZSh0cnVlKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICAgICAgICAgICAgICByZXNvbHZlKGZhbHNlKTsKICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZSgocmVzb2x2ZSkgPT4gewogICAgICAgICAgICAgICAgICAgIGNoZWNrSW5pdChmdW5jdGlvbihlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlc29sdmUoZSkKICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIHBhZ2VBY3Rpb24oZG9jLCBlbGVzKSB7CiAgICAgICAgICAgIGxldCBjb2RlID0gdGhpcy5jdXJTaXRlUnVsZS5wYWdlQWN0aW9uOwogICAgICAgICAgICBpZiAoY29kZSkgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAoKHR5cGVvZiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsUGFnZUFjdGlvbiA9PSAndW5kZWZpbmVkJykgPyBGdW5jdGlvbigiZG9jIiwgImVsZXMiLCAnInVzZSBzdHJpY3QiOycgKyBjb2RlKSA6IF91bnNhZmVXaW5kb3cucGFnZXR1YWxQYWdlQWN0aW9uKShkb2MsIGVsZXMpOwogICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5vcGVuSW5OZXdUYWIoZWxlcyk7CiAgICAgICAgICAgIHRoaXMucmVwbGFjZUVsZW1lbnQoZG9jKTsKICAgICAgICB9CgogICAgICAgIG9wZW5Jbk5ld1RhYihlbGVzKSB7CiAgICAgICAgICAgIGlmIChvcGVuSW5OZXdUYWIpIHsKICAgICAgICAgICAgICAgIFtdLmZvckVhY2guY2FsbChlbGVzLCBlbGUgPT4gewogICAgICAgICAgICAgICAgICAgIGlmICgvXkEkL2kudGVzdChlbGUubm9kZU5hbWUpICYmIGVsZS5ocmVmICYmICEvXihtYWlsdG86fGphdmFzY3JpcHQ6KXwjLy50ZXN0KGVsZS5ocmVmKSkgewogICAgICAgICAgICAgICAgICAgICAgICBlbGUuc2V0QXR0cmlidXRlKCd0YXJnZXQnLCBvcGVuSW5OZXdUYWIgPT0gMSA/ICdfYmxhbmsnIDogJ19zZWxmJyk7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgW10uZm9yRWFjaC5jYWxsKGVsZS5xdWVyeVNlbGVjdG9yQWxsKCdhW2hyZWZdOm5vdChbaHJlZl49Im1haWx0bzoiXSk6bm90KFtocmVmXj0iamF2YXNjcmlwdDoiXSk6bm90KFtocmVmXj0iIyJdKScpLCBhID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcGVuSW5OZXdUYWIgPT0gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGEuc2V0QXR0cmlidXRlKCd0YXJnZXQnLCAnX2JsYW5rJyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGEuZ2V0QXR0cmlidXRlKCdvbmNsaWNrJykgPT0gJ2F0YXJnZXQodGhpcyknKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGEucmVtb3ZlQXR0cmlidXRlKCdvbmNsaWNrJyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGEuc2V0QXR0cmlidXRlKCd0YXJnZXQnLCAnX3NlbGYnKTsKICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGxhenlJbWdBY3Rpb24oZWxlcykgewogICAgICAgICAgICBpZiAoIWVsZXMgfHwgZWxlcy5sZW5ndGggPT0gMCkgcmV0dXJuOwogICAgICAgICAgICBsZXQgbGF6eUltZ1NyYyA9IHRoaXMuY3VyU2l0ZVJ1bGUubGF6eUltZ1NyYzsKICAgICAgICAgICAgaWYgKGxhenlJbWdTcmMgPT09IDAgfHwgbGF6eUltZ1NyYyA9PT0gJzAnKSByZXR1cm47CiAgICAgICAgICAgIGxldCBzZXRMYXp5SW1nID0gaW1nID0+IHsKICAgICAgICAgICAgICAgIGxldCByZWFsU3JjOwogICAgICAgICAgICAgICAgaWYgKGxhenlJbWdTcmMpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGF6eUltZ1NyYykpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGF6eUltZ1NyYyA9IFtsYXp5SW1nU3JjXTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgcmVhbFNyYyA9IGltZy5nZXRBdHRyaWJ1dGUobGF6eUltZ1NyY1swXSk7CiAgICAgICAgICAgICAgICAgICAgaWYgKGxhenlJbWdTcmMubGVuZ3RoID09IDIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHJlbW92ZVByb3BzID0gbGF6eUltZ1NyY1sxXS5zcGxpdCgiLCIpOwogICAgICAgICAgICAgICAgICAgICAgICByZW1vdmVQcm9wcy5mb3JFYWNoKHByb3AgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaW1nLnJlbW92ZUF0dHJpYnV0ZShwcm9wLnRyaW0oKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAocmVhbFNyYykgaW1nLnNyYyA9IHJlYWxTcmM7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoIXJlYWxTcmMpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgbGF6eUF0dHIgPSAiIjsKICAgICAgICAgICAgICAgICAgICBpZiAoaW1nLmdldEF0dHJpYnV0ZSgiX3NyYyIpICYmICFpbWcuc3JjKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxhenlBdHRyID0gIl9zcmMiOwogICAgICAgICAgICAgICAgICAgICAgICByZWFsU3JjID0gaW1nLmdldEF0dHJpYnV0ZShsYXp5QXR0cik7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSBpbiBsYXp5SW1nQXR0cikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGF6eUF0dHIgPSBsYXp5SW1nQXR0cltpXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBhdHRyVmFsdWUgPSBpbWcuZ2V0QXR0cmlidXRlKGxhenlBdHRyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhdHRyVmFsdWUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZWFsU3JjID0gYXR0clZhbHVlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmICghcmVhbFNyYyAmJiBpbWcuX2xhenlyaWFzICYmIGltZy5fbGF6eXJpYXMuc3Jjc2V0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlYWxTcmMgPSBpbWcuX2xhenlyaWFzLnNyY3NldFtpbWcuX2xhenlyaWFzLnNyY3NldC5sZW5ndGggLSAxXTsKICAgICAgICAgICAgICAgICAgICAgICAgbGF6eUF0dHIgPSAiX2xhenlyaWFzIjsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKCFyZWFsU3JjICYmIGltZy5zcmNzZXQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGF6eUF0dHIgPSAic3Jjc2V0IjsKICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHNyY3MgPSBpbWcuc3Jjc2V0LnNwbGl0KC9beHddLC9pKSwgbGFyZ2VTaXplID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgc3Jjcy5mb3JFYWNoKHNyY2kgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHNyY0luZm8gPSBzcmNpLnRyaW0oKS5zcGxpdCgiICIpLCBjdXJTaXplID0gcGFyc2VJbnQoc3JjSW5mb1sxXSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoc3JjSW5mb1sxXSAmJiBjdXJTaXplID4gbGFyZ2VTaXplKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGFyZ2VTaXplID0gY3VyU2l6ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZWFsU3JjID0gc3JjSW5mb1swXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChyZWFsU3JjKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGltZy5zcmMgPSByZWFsU3JjOwogICAgICAgICAgICAgICAgICAgICAgICBpbWcucmVtb3ZlQXR0cmlidXRlKCJzcmNzZXQiKTsKICAgICAgICAgICAgICAgICAgICAgICAgaW1nLnJlbW92ZUF0dHJpYnV0ZShsYXp5QXR0cik7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbWcuc3R5bGUuZGlzcGxheSA9PSAibm9uZSIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGltZy5zdHlsZS5kaXNwbGF5ID0gIiI7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGltZy5zdHlsZS52aXNpYmlsaXR5ID09ICJoaWRkZW4iKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbWcuc3R5bGUudmlzaWJpbGl0eSA9ICIiOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbWcuc3R5bGUub3BhY2l0eSA9PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbWcuc3R5bGUub3BhY2l0eSA9ICIiOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBbXS5mb3JFYWNoLmNhbGwoZWxlcywgZWxlID0+IHsKICAgICAgICAgICAgICAgIGlmICgvXklNRyQvaS50ZXN0KGVsZS5ub2RlTmFtZSkpIHsKICAgICAgICAgICAgICAgICAgICBzZXRMYXp5SW1nKGVsZSk7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIFtdLmZvckVhY2guY2FsbChlbGUucXVlcnlTZWxlY3RvckFsbCgiaW1nLHBpY3R1cmU+c291cmNlIiksIGltZyA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNldExhenlJbWcoaW1nKTsKICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICBbXS5mb3JFYWNoLmNhbGwoZWxlLnF1ZXJ5U2VsZWN0b3JBbGwoImRpdltkYXRhLXNyY11bZGF0YS10aHVtYl0iKSwgZGl2ID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgZGl2LnN0eWxlLnNldFByb3BlcnR5KCJiYWNrZ3JvdW5kLWltYWdlIiwgInVybCgiICsgZGl2LmRhdGFzZXQuc3JjICsgIikiLCAiaW1wb3J0YW50Iik7CiAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoL15BJC9pLnRlc3QoZWxlLm5vZGVOYW1lKSAmJiBlbGUuY2xhc3NMaXN0LmNvbnRhaW5zKCJsYXp5bG9hZCIpKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGVsZS5kYXRhc2V0Lm9yaWdpbmFsKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGVsZS5zdHlsZS5iYWNrZ3JvdW5kSW1hZ2UgPSAndXJsKCInICsgZWxlLmRhdGFzZXQub3JpZ2luYWwgKyAnIiknOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgW10uZm9yRWFjaC5jYWxsKGVsZS5xdWVyeVNlbGVjdG9yQWxsKCJhLmxhenlsb2FkIiksIGEgPT4gewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYS5kYXRhc2V0Lm9yaWdpbmFsKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhLnN0eWxlLmJhY2tncm91bmRJbWFnZSA9ICd1cmwoIicgKyBhLmRhdGFzZXQub3JpZ2luYWwgKyAnIiknOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pOwogICAgICAgIH0KCiAgICAgICAgaW5pdFBhZ2UoY2FsbGJhY2spIHsKICAgICAgICAgICAgbGV0IHNlbGYgPSB0aGlzOwogICAgICAgICAgICBpZiAoc2VsZi5pbml0aW5nKSByZXR1cm47CiAgICAgICAgICAgIHNlbGYuaW5pdGluZyA9IHRydWU7CiAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgc2VsZi5pbml0aW5nID0gZmFsc2U7CiAgICAgICAgICAgIH0sIDEwMCk7CiAgICAgICAgICAgIGN1clBhZ2UgPSAxOwogICAgICAgICAgICB1cmxDaGFuZ2VkID0gZmFsc2U7CiAgICAgICAgICAgIHRoaXMuY2xlYXJBZGRlZEVsZW1lbnRzKCk7CiAgICAgICAgICAgIHRoaXMuaW5zZXJ0ID0gbnVsbDsKICAgICAgICAgICAgdGhpcy52aXNpYmlsaXR5SXRlbXMgPSBbXTsKICAgICAgICAgICAgdGhpcy52aXNpYmxlSW5kZXggPSAtMTsKICAgICAgICAgICAgdGhpcy5wYWdlRG9jID0gZG9jdW1lbnQ7CiAgICAgICAgICAgIHRoaXMubmV4dExpbmtIcmVmID0gbnVsbDsKICAgICAgICAgICAgdGhpcy5jdXJVcmwgPSBsb2NhdGlvbi5ocmVmOwogICAgICAgICAgICB0aGlzLm9sZFVybCA9ICIiOwogICAgICAgICAgICB0aGlzLmluaXRVcmwgPSBsb2NhdGlvbi5ocmVmOwogICAgICAgICAgICB0aGlzLmhpc3RvcnlVcmwgPSAiIjsKICAgICAgICAgICAgbGV0IGJhc2UgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCJiYXNlIik7CiAgICAgICAgICAgIHRoaXMuYmFzZVBhdGggPSBiYXNlID8gYmFzZS5ocmVmIDogbG9jYXRpb24uaHJlZjsKICAgICAgICAgICAgdGhpcy5nZXRSdWxlKGFzeW5jICgpID0+IHsKICAgICAgICAgICAgICAgIGlzUGF1c2UgPSBmYWxzZTsKICAgICAgICAgICAgICAgIGlmIChzZWxmLmN1clNpdGVSdWxlLmVuYWJsZSA9PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgZGVidWcoIlN0b3AgYXMgcnVsZSBkaXNhYmxlIik7CiAgICAgICAgICAgICAgICAgICAgaXNQYXVzZSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgX0dNX3JlZ2lzdGVyTWVudUNvbW1hbmQoaTE4bigiZW5hYmxlIiksICgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd1RpcHMoaTE4bigiZW5hYmxlU2l0ZVRpcHMiKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKCFzZWxmLmN1c3RvbVJ1bGVzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZWxmLmN1c3RvbVJ1bGVzID0gW107CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSBpbiBzZWxmLmN1c3RvbVJ1bGVzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoc2VsZi5jdXN0b21SdWxlc1tpXS51cmwgPT0gc2VsZi5jdXJTaXRlUnVsZS51cmwpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZWxmLmN1c3RvbVJ1bGVzLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBzZWxmLmN1clNpdGVSdWxlLmVuYWJsZSA9IDE7CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuY3VzdG9tUnVsZXMudW5zaGlmdChzZWxmLmN1clNpdGVSdWxlKTsKICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJjdXN0b21SdWxlcyIsIHNlbGYuY3VzdG9tUnVsZXMpOwogICAgICAgICAgICAgICAgICAgICAgICBsb2NhdGlvbi5yZWxvYWQoKTsKICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAvL+iLpeaYr+WGjeS6guWMuemFjeWwseS4jee3qeWtmHdlZGF0Ye+8jOaIluiAheWPquWcqOaJvuWujOacrOWcsOimj+WJh+S5i+W+jOWGjeiAg+aFrndlZGF0YeeahOe3qeWtmAogICAgICAgICAgICAgICAgaWYgKHNlbGYuY3VyU2l0ZVJ1bGUuc2luZ2xlVXJsKSB7CiAgICAgICAgICAgICAgICAgICAgZGVsZXRlIHNlbGYuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQ7CiAgICAgICAgICAgICAgICAgICAgc2VsZi5zbWFydFJ1bGVzID0gc2VsZi5zbWFydFJ1bGVzLmZpbHRlcihpdGVtID0+IHtyZXR1cm4gaXRlbSAmJiBpdGVtLnVybCAhPSBzZWxmLmN1clNpdGVSdWxlLnVybH0pOwogICAgICAgICAgICAgICAgICAgIHNlbGYuc21hcnRSdWxlcy51bnNoaWZ0KHNlbGYuY3VyU2l0ZVJ1bGUpOwogICAgICAgICAgICAgICAgICAgIGlmIChzZWxmLnNtYXJ0UnVsZXMubGVuZ3RoID4gMTAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuc21hcnRSdWxlcy5wb3AoKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJzbWFydFJ1bGVzIiwgc2VsZi5zbWFydFJ1bGVzKTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc2VsZi5jdXJTaXRlUnVsZSAmJiBzZWxmLmN1clNpdGVSdWxlLnVybC5sZW5ndGggPiAxMykgewogICAgICAgICAgICAgICAgICAgIHNlbGYuYWRkVG9IcFJ1bGVzKCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZXQgY3NzID0gc2VsZi5jdXJTaXRlUnVsZS5jc3MgfHwgcnVsZXNEYXRhLmN1c3RvbUNzczsKICAgICAgICAgICAgICAgIGlmIChjc3MpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgY3NzQXJyID0gY3NzLnNwbGl0KCJpbklmcmFtZToiKTsKICAgICAgICAgICAgICAgICAgICBpZiAoY3NzQXJyICYmIGNzc0Fyci5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgX0dNX2FkZFN0eWxlKGNzc0FyclswXSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKC9zaWRlc2VhcmNoPSgxfHRydWUpJC8udGVzdChzZWxmLmN1clVybCkpIHsKICAgICAgICAgICAgICAgICAgICBvcGVuSW5OZXdUYWIgPSAwOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2Ygc2VsZi5jdXJTaXRlUnVsZS5vcGVuSW5OZXdUYWIgIT09ICd1bmRlZmluZWQnKSB7CiAgICAgICAgICAgICAgICAgICAgb3BlbkluTmV3VGFiID0gc2VsZi5jdXJTaXRlUnVsZS5vcGVuSW5OZXdUYWIgPyAxIDogMjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxldCBhdXRvQ2xpY2sgPSBzZWxmLmN1clNpdGVSdWxlLmF1dG9DbGljazsKICAgICAgICAgICAgICAgIGlmIChhdXRvQ2xpY2spIHsKICAgICAgICAgICAgICAgICAgICBsZXQgYXV0b0NsaWNrQnRuOwogICAgICAgICAgICAgICAgICAgIGF1dG9DbGlja0J0biA9IGdldEVsZW1lbnQoYXV0b0NsaWNrLCBkb2N1bWVudCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKGF1dG9DbGlja0J0bikgewogICAgICAgICAgICAgICAgICAgICAgICBlbXVDbGljayhhdXRvQ2xpY2tCdG4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxldCBjb2RlID0gc2VsZi5jdXJTaXRlUnVsZS5pbml0OwogICAgICAgICAgICAgICAgaWYgKGNvZGUpIHsKICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAoKHR5cGVvZiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsSW5pdCA9PSAndW5kZWZpbmVkJykgPyBuZXcgQXN5bmNGdW5jdGlvbignZG9jJywgJ3dpbicsICdpZnJhbWUnLCAnY2xpY2snLCAnZW50ZXInLCAnaW5wdXQnLCAnInVzZSBzdHJpY3QiOycgKyBjb2RlKSA6IF91bnNhZmVXaW5kb3cucGFnZXR1YWxJbml0KShudWxsLCBudWxsLCBudWxsLCBzZWwgPT4ge2NsaWNrQWN0aW9uKHNlbCwgZG9jdW1lbnQpfSwgc2VsID0+IHtlbnRlckFjdGlvbihzZWwsIGRvY3VtZW50KX0sIChzZWwsIHYpID0+e2lucHV0QWN0aW9uKHNlbCwgdiwgZG9jdW1lbnQpfSk7CiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGF3YWl0IHNlbGYuZ2V0TmV4dExpbmsoZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgaWYgKHNlbGYuY3VyU2l0ZVJ1bGUuc2luZ2xlVXJsICYmIHNlbGYubmV4dExpbmtIcmVmID09IGZhbHNlICYmIHNlbGYucG9zc2libGVSdWxlKSB7CiAgICAgICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuaW5pdFBhZ2UoKCkgPT4ge30pOwogICAgICAgICAgICAgICAgICAgIH0sIDEwMDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc2VsZi5yZWZyZXNoQnlDbGljaygpOwoKICAgICAgICAgICAgICAgIGxldCBwYWdlR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YucGFyZW50Tm9kZTsKICAgICAgICAgICAgICAgIGlmICgvXlRCT0RZJC9pLnRlc3QocGFyZW50Lm5vZGVOYW1lKSkgewogICAgICAgICAgICAgICAgICAgIHBhcmVudCA9IHBhcmVudC5wYXJlbnROb2RlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKC9eVEFCTEUkL2kudGVzdChwYXJlbnQubm9kZU5hbWUpKSB7CiAgICAgICAgICAgICAgICAgICAgcGFyZW50LnBhcmVudE5vZGUuYXBwZW5kQ2hpbGQobG9hZGluZ0Rpdik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZ2V0Qm9keShkb2N1bWVudCkuc2Nyb2xsVG9wID0gbGFzdFNjcm9sbFRvcDsKICAgICAgICAgICAgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LnNjcm9sbFRvcCA9IGxhc3RTY3JvbGxUb3A7CiAgICAgICAgfQoKICAgICAgICBpbnNlcnRFbGVtZW50KGVsZSkgewogICAgICAgICAgICBpZiAoIXRoaXMuaW5zZXJ0IHx8ICF0aGlzLmluc2VydC5wYXJlbnROb2RlKSB7CiAgICAgICAgICAgICAgICB0aGlzLmdldEluc2VydCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0aGlzLmluc2VydCkgewogICAgICAgICAgICAgICAgdGhpcy5hZGRlZEVsZVBvb2wucHVzaChlbGUpOwogICAgICAgICAgICAgICAgaWYgKHRoaXMuY3VyU2l0ZVJ1bGUuaW5zZXJ0UG9zID09IDIpIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLmluc2VydC5hcHBlbmRDaGlsZChlbGUpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLmluc2VydC5wYXJlbnROb2RlLmluc2VydEJlZm9yZShlbGUsIHRoaXMuaW5zZXJ0KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgYXN5bmMgaW5zZXJ0UGFnZShkb2MsIGVsZXMsIHVybCwgY2FsbGJhY2ssIHRyaWVkKSB7CiAgICAgICAgICAgIHRoaXMub2xkVXJsID0gdGhpcy5jdXJVcmw7CiAgICAgICAgICAgIGxldCBvbGRUaXRsZSA9IHRoaXMucGFnZURvYy50aXRsZTsKICAgICAgICAgICAgdGhpcy5wYWdlRG9jID0gZG9jOwogICAgICAgICAgICB0aGlzLmN1clVybCA9IHVybDsKICAgICAgICAgICAgaXNMb2FkaW5nID0gdHJ1ZTsKICAgICAgICAgICAgbGV0IG5leHRMaW5rID0gYXdhaXQgdGhpcy5nZXROZXh0TGluayhkb2MpOwogICAgICAgICAgICB0aGlzLm5leHRUaXRsZSA9ICIiOwogICAgICAgICAgICBpZiAodGhpcy5jdXJTaXRlUnVsZS5wYWdlQmFyVGV4dCkgewogICAgICAgICAgICAgICAgaWYgKHRoaXMuY3VyU2l0ZVJ1bGUucGFnZUJhclRleHQgPT0gMSB8fCB0aGlzLmN1clNpdGVSdWxlLnBhZ2VCYXJUZXh0ID09IHRydWUpIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLm5leHRUaXRsZSA9IGRvYy50aXRsZTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5uZXh0VGl0bGUgPSAoKHR5cGVvZiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsUGFnZUJhclRleHQgPT0gJ3VuZGVmaW5lZCcpID8gRnVuY3Rpb24oImRvYyIsJyJ1c2Ugc3RyaWN0IjsnICsgdGhpcy5jdXJTaXRlUnVsZS5wYWdlQmFyVGV4dCkgOiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsUGFnZUJhclRleHQpKGRvYyk7CiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoY3VyUGFnZSA9PSAxICYmICF0cmllZCAmJiAhbmV4dExpbmsgJiYgdGhpcy5jdXJTaXRlUnVsZS5zaW5nbGVVcmwgJiYgdGhpcy5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCAmJiB0aGlzLmN1clNpdGVSdWxlLmFjdGlvbiAhPSAwKSB7CiAgICAgICAgICAgICAgICB0aGlzLmN1clNpdGVSdWxlLmFjdGlvbiA9IDE7CiAgICAgICAgICAgICAgICB0aGlzLmN1clVybCA9IGxvY2F0aW9uLmhyZWY7CiAgICAgICAgICAgICAgICBpc0xvYWRpbmcgPSBmYWxzZTsKICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZXQgbGFzdFNjcm9sbFRvcCA9IGdldEJvZHkoZG9jdW1lbnQpLnNjcm9sbFRvcCB8fCBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuc2Nyb2xsVG9wOwogICAgICAgICAgICB0aGlzLmdldEluc2VydCgpOwogICAgICAgICAgICB2YXIgc2VsZiA9IHRoaXMsIG5ld0VsZXMgPSBbXTsKICAgICAgICAgICAgaWYgKCFlbGVzIHx8IGVsZXMubGVuZ3RoID09IDAgfHwgIXNlbGYuaW5zZXJ0IHx8ICFzZWxmLmluc2VydC5wYXJlbnROb2RlKSB7CiAgICAgICAgICAgICAgICBpZiAoY2FsbGJhY2spIGNhbGxiYWNrKGVsZXMpOwogICAgICAgICAgICAgICAgbG9hZFBhZ2VPdmVyKCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBhd2FpdCB0aGlzLnBhZ2VJbml0KGRvYywgZWxlcyk7CiAgICAgICAgICAgICAgICBpZiAoY2FsbGJhY2spIGNhbGxiYWNrKGVsZXMpOwogICAgICAgICAgICAgICAgbG9hZFBhZ2VPdmVyKCk7CiAgICAgICAgICAgICAgICBjb25zdCBjb2xsZWN0aW9uID0gZG9jdW1lbnQuY3JlYXRlRG9jdW1lbnRGcmFnbWVudCgpOwogICAgICAgICAgICAgICAgW10uZm9yRWFjaC5jYWxsKGVsZXMsIGVsZSA9PiB7CiAgICAgICAgICAgICAgICAgICAgbGV0IG5ld0VsZSA9IGVsZS5jbG9uZU5vZGUodHJ1ZSk7CiAgICAgICAgICAgICAgICAgICAgbGV0IG9sZENhbnZhc3MgPSBlbGUucXVlcnlTZWxlY3RvckFsbCgiY2FudmFzIik7CiAgICAgICAgICAgICAgICAgICAgbGV0IG5ld0NhbnZhc3MgPSBuZXdFbGUucXVlcnlTZWxlY3RvckFsbCgiY2FudmFzIik7CiAgICAgICAgICAgICAgICAgICAgaWYgKHNlbGYudXBkYXRlVXJsKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIFtdLmZvckVhY2guY2FsbChuZXdFbGUucXVlcnlTZWxlY3RvckFsbCgiaW1nIiksIGltZyA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW1nLmdldEF0dHJpYnV0ZSgic3JjIikpIGltZy5zcmMgPSBzZWxmLmNhbm9uaWNhbFVyaShpbWcuZ2V0QXR0cmlidXRlKCJzcmMiKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgICAgICBbXS5mb3JFYWNoLmNhbGwobmV3RWxlLnF1ZXJ5U2VsZWN0b3JBbGwoImEiKSwgYSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYS5nZXRBdHRyaWJ1dGUoImhyZWYiKSkgYS5ocmVmID0gc2VsZi5jYW5vbmljYWxVcmkoYS5nZXRBdHRyaWJ1dGUoImhyZWYiKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG9sZENhbnZhc3MubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IG9sZENhbnZhcyA9IG9sZENhbnZhc3NbaV07CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBuZXdDYW52YXMgPSBuZXdDYW52YXNzW2ldOwogICAgICAgICAgICAgICAgICAgICAgICBuZXdDYW52YXMuZ2V0Q29udGV4dCgnMmQnKS5kcmF3SW1hZ2Uob2xkQ2FudmFzLCAwLCAwKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKCEvXihTVFlMRXxTQ1JJUFQpJC8udGVzdChuZXdFbGUubm9kZU5hbWUpKSBzZWxmLnZpc2liaWxpdHlJdGVtcy5wdXNoKG5ld0VsZSk7CiAgICAgICAgICAgICAgICAgICAgY29sbGVjdGlvbi5hcHBlbmRDaGlsZChuZXdFbGUpCiAgICAgICAgICAgICAgICAgICAgbmV3RWxlcy5wdXNoKG5ld0VsZSk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIHNlbGYuaW5zZXJ0RWxlbWVudChjb2xsZWN0aW9uKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBnZXRCb2R5KGRvY3VtZW50KS5zY3JvbGxUb3AgPSBsYXN0U2Nyb2xsVG9wOwogICAgICAgICAgICBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuc2Nyb2xsVG9wID0gbGFzdFNjcm9sbFRvcDsKICAgICAgICAgICAgdGhpcy5wYWdlQWN0aW9uKGRvYywgbmV3RWxlcyk7CiAgICAgICAgICAgIGxldCBlbmFibGVIaXN0b3J5ID0gdGhpcy5jdXJTaXRlUnVsZS5oaXN0b3J5OwogICAgICAgICAgICBsZXQgZW5hYmxlSGlzdG9yeUFmdGVySW5zZXJ0ID0gZmFsc2U7CiAgICAgICAgICAgIGlmIChlbmFibGVIaXN0b3J5ID09IDEpIHsKICAgICAgICAgICAgICAgIGVuYWJsZUhpc3RvcnkgPSB0cnVlOwogICAgICAgIC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luZWQsIGhpc3RvcnlUaXRsZSwgdGhpcy5oaXN0b3J5VXJsKTsKICAgICAgICAgICAgICAgICAgICAgICAgZG9jdW1lbnQudGl0bGUgPSBoaXN0b3J5VGl0bGU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlzTG9hZGluZyA9IGZhbHNlOwogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICB9CiAgICB2YXIgcnVsZVBhcnNlciA9IG5ldyBSdWxlUGFyc2VyKCk7CgogICAgY2xhc3MgU2lkZUNvbnRyb2xsZXIgewogICAgICAgIC8vc3RhdGljIGNvbnRyb2xsZXI7CiAgICAgICAgY29uc3RydWN0b3IoKSB7CiAgICAgICAgICAgIHRoaXMuaW5pdGVkID0gZmFsc2U7CiAgICAgICAgfQoKICAgICAgICAvKnN0YXRpYyBnZXRJbnN0YW5jZSgpIHsKICAgICAgICAgICAgaWYgKCFTaWRlQ29udHJvbGxlci5jb250cm9sbGVyKSB7CiAgICAgICAgICAgICAgICBTaWRlQ29udHJvbGxlci5jb250cm9sbGVyID0gbmV3IFNpZGVDb250cm9sbGVyKCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIFNpZGVDb250cm9sbGVyLmNvbnRyb2xsZXI7CiAgICAgICAgfSovCgogICAgICAgIHNldHVwKCkgewogICAgICAgICAgICBpZiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5zaWRlQ29udHJvbGxlciA9PT0gZmFsc2UpIHJldHVybjsKICAgICAgICAgICAgaWYgKCFydWxlc0RhdGEuc2lkZUNvbnRyb2xsZXIgJiYgIXJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuc2lkZUNvbnRyb2xsZXIpIHJldHVybjsKICAgICAgICAgICAgdGhpcy5hZGRUb1N0YWdlKCk7CiAgICAgICAgfQoKICAgICAgICBpbml0KCkgewogICAgICAgICAgICBpZiAodGhpcy5pbml0ZWQpIHJldHVybjsKICAgICAgICAgICAgdGhpcy5pbml0ZWQgPSB0cnVlOwogICAgICAgICAgICBsZXQgc2VsZiA9IHRoaXM7CiAgICAgICAgICAgIHRoaXMuY3NzVGV4dCA9IGAKICAgICAgICAgICAgICNwYWdldHVhbC1zaWRlQ29udHJvbGxlciB7CiAgICAgICAgICAgICAgICAgcG9zaXRpb246IGZpeGVkOwogICAgICAgICAgICAgICAgIHRvcDogY2FsYyg1MCUgLSA4M3B4KTsKICAgICAgICAgICAgICAgICBsZWZ0OiBjYWxjKDk5JSAtIDQwcHgpOwogICAgICAgICAgICAgICAgIHdpZHRoOiA0MHB4OwogICAgICAgICAgICAgICAgIGJvcmRlci1yYWRpdXM6IDIwcHg7CiAgICAgICAgICAgICAgICAgYm94LXNoYWRvdzogcmdiKDAgMCAwKSAwcHggMHB4IDEwcHg7CiAgICAgICAgICAgICAgICAgdGV4dC1hbGlnbjogY2VudGVyOwogICAgICAgICAgICAgICAgIGJhY2tncm91bmQ6ICNmZmZmZmZkMCFpbXBvcnRhbnQ7CiAgICAgICAgICAgICAgICAgdXNlci1zZWxlY3Q6IG5vbmU7CiAgICAgICAgICAgICAgICAgei1pbmRleDogMjE0NzQ4MzY0NiFpbXBvcnRhbnQ7CiAgICAgICAgICAgICAgICAgcGFkZGluZzogMCFpbXBvcnRhbnQ7CiAgICAgICAgICAgICAgICAgb3BhY2l0eTogMC4zNTsKICAgICAgICAgICAgICAgICB0cmFuc2l0aW9uOiBvcGFjaXR5IC41cyBlYXNlLCBiYWNrZ3JvdW5kIC41cywgYm94LXNoYWRvdyAuNXM7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtc2lkZUNvbnRyb2xsZXI6aG92ZXIgewogICAgICAgICAgICAgICAgIG9wYWNpdHk6IDE7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtc2lkZUNvbnRyb2xsZXIgKiB7CiAgICAgICAgICAgICAgICAgZm9udC13ZWlnaHQ6IGJvbGQ7CiAgICAgICAgICAgICAgICAgZm9udC1mYW1pbHk6IGFyaWFsOwogICAgICAgICAgICAgICAgIGZvbnQtc3R5bGU6IG5vcm1hbDsKICAgICAgICAgICAgICAgICBmb250LXNpemU6IDIwcHghaW1wb3J0YW50OwogICAgICAgICAgICAgICAgIGNvbG9yOiBibGFjayFpbXBvcnRhbnQ7CiAgICAgICAgICAgICAgICAgbGluZS1oZWlnaHQ6IG5vcm1hbDsKICAgICAgICAgICAgICAgICBmbG9hdDogbm9uZTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1zaWRlQ29udHJvbGxlci5zdG9wIHsKICAgICAgICAgICAgICAgICAtd2Via2l0LWZpbHRlcjogaW52ZXJ0KDEwMCUpOwogICAgICAgICAgICAgICAgIGZpbHRlcjogaW52ZXJ0KDEwMCUpOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgLnBhZ2V0dWFsLXNpZGVDb250cm9sbGVyLWJ0biB7CiAgICAgICAgICAgICAgICAgcGFkZGluZzogNXB4IDA7CiAgICAgICAgICAgICAgICAgY3Vyc29yOiBwb2ludGVyOwogICAgICAgICAgICAgICAgIHRyYW5zaXRpb246IHRyYW5zZm9ybSAuMTVzIGVhc2UtaW4tb3V0LCBvcGFjaXR5IC4zcyBlYXNlOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXNpZGVDb250cm9sbGVyIC5wYWdldHVhbC1zaWRlQ29udHJvbGxlci1idG46aG92ZXIgewogICAgICAgICAgICAgICAgIHRyYW5zZm9ybTogc2NhbGUoMS41KTsKICAgICAgICAgICAgICAgICBjb2xvcjogcmVkIWltcG9ydGFudDsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1zaWRlQ29udHJvbGxlci5taW5TaXplIHsKICAgICAgICAgICAgICAgICBib3gtc2hhZG93OiByZ2IoMCAwIDAgLyAwJSkgMHB4IDBweCAwcHg7CiAgICAgICAgICAgICAgICAgYmFja2dyb3VuZDogIzAwMDAwMDAwIWltcG9ydGFudDsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1zaWRlQ29udHJvbGxlci5taW5TaXplIC5wYWdldHVhbC1zaWRlQ29udHJvbGxlci1idG4gewogICAgICAgICAgICAgICAgIG9wYWNpdHk6IDA7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtc2lkZUNvbnRyb2xsZXIgI3BhZ2V0dWFsLXNpZGVDb250cm9sbGVyLW1vdmUgPiBzdmcgewogICAgICAgICAgICAgICAgIHRyYW5zaXRpb246IHRyYW5zZm9ybSAuM3MgZWFzZTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1zaWRlQ29udHJvbGxlciAjcGFnZXR1YWwtc2lkZUNvbnRyb2xsZXItbW92ZSA+IHN2Zzpob3ZlciB7CiAgICAgICAgICAgICAgICAgdHJhbnNmb3JtOiBzY2FsZSgxLjIpOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXNpZGVDb250cm9sbGVyLm1pblNpemUgI3BhZ2V0dWFsLXNpZGVDb250cm9sbGVyLW1vdmUgPiBzdmcgewogICAgICAgICAgICAgICAgIGJhY2tncm91bmQ6IHdoaXRlOwogICAgICAgICAgICAgICAgIG9wYWNpdHk6IDA7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtc2lkZUNvbnRyb2xsZXIgI3BhZ2V0dWFsLXNpZGVDb250cm9sbGVyLW1vdmUgPiBpbWcsCiAgICAgICAgICAgICAjcGFnZXR1YWwtc2lkZUNvbnRyb2xsZXIgI3BhZ2V0dWFsLXNpZGVDb250cm9sbGVyLW1vdmUgPiBzcGFuIHsKICAgICAgICAgICAgICAgICB3aWR0aDogMzVweDsKICAgICAgICAgICAgICAgICBoZWlnaHQ6IDM1cHg7CiAgICAgICAgICAgICAgICAgY3Vyc29yOiBwb2ludGVyOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXNpZGVDb250cm9sbGVyLm1pblNpemUgI3BhZ2V0dWFsLXNpZGVDb250cm9sbGVyLW1vdmUgPiBpbWcsCiAgICAgICAgICAgICAjcGFnZXR1YWwtc2lkZUNvbnRyb2xsZXIubWluU2l6ZSAjcGFnZXR1YWwtc2lkZUNvbnRyb2xsZXItbW92ZSA+IHNwYW4gewogICAgICAgICAgICAgICAgIGJvcmRlci1yYWRpdXM6IDUwcHg7CiAgICAgICAgICAgICAgICAgdGV4dC1zaGFkb3c6IHJnYigyNTUgMjU1IDI1NSkgMHB4IDBweCAxMHB4OwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXNpZGVDb250cm9sbGVyICNwYWdldHVhbC1zaWRlQ29udHJvbGxlci1wYWdlbnVtIHsKICAgICAgICAgICAgICAgICBmb250LXNpemU6IDE1cHghaW1wb3J0YW50OwogICAgICAgICAgICAgICAgIGxpbmUtaGVpZ2h0OiAzMHB4OwogICAgICAgICAgICAgICAgIHRleHQtYWxpZ246IGNlbnRlcjsKICAgICAgICAgICAgICAgICBwb3NpdGlvbjogYWJzb2x1dGU7CiAgICAgICAgICAgICAgICAgcmlnaHQ6IGNhbGMoNTAlIC0gMTVweCk7CiAgICAgICAgICAgICAgICAgdG9wOiBjYWxjKDUwJSAtIDE1cHgpOwogICAgICAgICAgICAgICAgIGJvcmRlcjogMXB4IHNvbGlkICMwMDAwMDA5OTsKICAgICAgICAgICAgICAgICBkaXNwbGF5OiBpbmxpbmUtYmxvY2s7CiAgICAgICAgICAgICAgICAgd2lkdGg6IDMwcHg7CiAgICAgICAgICAgICAgICAgaGVpZ2h0OiAzMHB4OwogICAgICAgICAgICAgICAgIGJveC1zaXppbmc6IGJvcmRlci1ib3g7CiAgICAgICAgICAgICAgICAgYm9yZGVyLXJhZGl1czogNTAlOwogICAgICAgICAgICAgICAgIGJhY2tncm91bmQ6IHdoaXRlOwogICAgICAgICAgICAgICAgIG9wYWNpdHk6IDA7CiAgICAgICAgICAgICAgICAgdHJhbnNpdGlvbjogb3BhY2l0eSAuNXMgZWFzZTsKICAgICAgICAgICAgICAgICBwb2ludGVyLWV2ZW50czogbm9uZTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1zaWRlQ29udHJvbGxlci5taW5TaXplICNwYWdldHVhbC1zaWRlQ29udHJvbGxlci1wYWdlbnVtIHsKICAgICAgICAgICAgICAgICBvcGFjaXR5OiAwLjg7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgIGA7CiAgICAgICAgICAgIGxldCBmcmFtZSA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImRpdiIpOwogICAgICAgICAgICBmcmFtZS5pZCA9ICJwYWdldHVhbC1zaWRlQ29udHJvbGxlciI7CiAgICAgICAgICAgIGZyYW1lLmlubmVySFRNTCA9IGNyZWF0ZUhUTUwoYAogICAgICAgICAgICAgICAgPGRpdiBpZD0icGFnZXR1YWwtc2lkZUNvbnRyb2xsZXItdG9wIiBjbGFzcz0icGFnZXR1YWwtc2lkZUNvbnRyb2xsZXItYnRuIj7iirw8L2Rpdj4KICAgICAgICAgICAgICAgIDxkaXY+CiAgICAgICAgICAgICAgICAgIDxkaXYgaWQ9InBhZ2V0dWFsLXNpZGVDb250cm9sbGVyLXByZSIgY2xhc3M9InBhZ2V0dWFsLXNpZGVDb250cm9sbGVyLWJ0biI+4oinPC9kaXY+CiAgICAgICAgICAgICAgICAgIDxkaXYgaWQ9InBhZ2V0dWFsLXNpZGVDb250cm9sbGVyLW1vdmUiPjxzdmcgd2lkdGg9IjMwIiBoZWlnaHQ9IjMwIiBzdHlsZT0iYm9yZGVyLXJhZGl1czogMTVweDtkaXNwbGF5OiBpbml0aWFsO3Bvc2l0aW9uOiByZWxhdGl2ZTtjdXJzb3I6IHBvaW50ZXI7bWFyZ2luOiAwO3dpZHRoOiAzMHB4O2hlaWdodDogMzBweDt2ZX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gZnJhbWUuYWRkRXZlbnRMaXN0ZW5lcigiZGJsY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIGUucHJldmVudERlZmF1bHQoKTsKICAgICAgICAgICAgICAgIGUuc3RvcFByb3BhZ2F0aW9uKCk7CiAgICAgICAgICAgIH0sIHRydWUpOwoKICAgICAgICAgICAgZnJhbWUuYWRkRXZlbnRMaXN0ZW5lcigibW91c2VlbnRlciIsIGUgPT4gewogICAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHNlbGYuaGlkZVRpbWVyKTsKICAgICAgICAgICAgICAgIGZyYW1lLmNsYXNzTGlzdC5yZW1vdmUoIm1pblNpemUiKTsKICAgICAgICAgICAgfSk7CgogICAgICAgICAgICBmcmFtZS5hZGRFdmVudExpc3RlbmVyKCJtb3VzZWxlYXZlIiwgZSA9PiB7CiAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQoc2VsZi5oaWRlVGltZXIpOwogICAgICAgICAgICAgICAgc2VsZi5oaWRlVGltZXIgPSBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICBmcmFtZS5jbGFzc0xpc3QuYWRkKCJtaW5TaXplIik7CiAgICAgICAgICAgICAgICB9LCA4MDApOwogICAgICAgICAgICB9KTsKCiAgICAgICAgICAgIHByZS5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgbGV0IHByZVBhZ2VCYXIgPSBnZXRQYWdlQmFyKCkucHJlQmFyOwogICAgICAgICAgICAgICAgaWYgKHByZVBhZ2VCYXIpIHsKICAgICAgICAgICAgICAgICAgICBzY3JvbGxUb1BhZ2VCYXIocHJlUGFnZUJhcik7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGxldCBzY3JvbGxUb3AgPSBnZXRCb2R5KGRvY3VtZW50KS5zY3JvbGxUb3AgfHwgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LnNjcm9sbFRvcDsKICAgICAgICAgICAgICAgICAgICB3aW5kb3cuc2Nyb2xsVG8oeyB0b3A6IHNjcm9sbFRvcCAtICh3aW5kb3cuaW5uZXJIZWlnaHQgfHwgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LmNsaWVudEhlaWdodCksIGJlaGF2aW9yOiAnc21vb3RoJ30pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LCB0cnVlKTsKCiAgICAgICAgICAgIG5leHQuYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIGxldCBwYWdlQmFyT2JqID0gZ2V0UGFnZUJhcigpOwogICAgICAgICAgICAgICAgbGV0IG5leHRQYWdlQmFyID0gcGFnZUJhck9iai5uZXh0QmFyOwogICAgICAgICAgICAgICAgaWYgKG5leHRQYWdlQmFyKSB7CiAgICAgICAgICAgICAgICAgICAgc2Nyb2xsVG9QYWdlQmFyKG5leHRQYWdlQmFyKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBhZ2VCYXJPYmoucHJlQmFyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBzY3JvbGxIID0gTWF0aC5tYXgoZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LnNjcm9sbEhlaWdodCwgZ2V0Qm9keShkb2N1bWVudCkuc2Nyb2xsSGVpZ2h0KTsKICAgICAgICAgICAgICAgICAgICAgICAgd2luZG93LnNjcm9sbFRvKHsgdG9wOiAoc2Nyb2xsSCB8fCA5OTk5OTk5KSwgYmVoYXZpb3I6ICdzbW9vdGgnfSk7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHNjcm9sbFRvcCA9IGdldEJvZHkoZG9jdW1lbnQpLnNjcm9sbFRvcCB8fCBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuc2Nyb2xsVG9wOwogICAgICAgICAgICAgICAgICAgICAgICB3aW5kb3cuc2Nyb2xsVG8oeyB0b3A6IHNjcm9sbFRvcCArICh3aW5kb3cuaW5uZXJIZWlnaHQgfHwgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LmNsaWVudEhlaWdodCksIGJlaGF2aW9yOiAnc21vb3RoJ30pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSwgdHJ1ZSk7CgogICAgICAgICAgICB0b3AuYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIGdldEJvZHkoZG9jdW1lbnQpLnNjcm9sbFRvcD0wOwogICAgICAgICAgICAgICAgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LnNjcm9sbFRvcD0wOwogICAgICAgICAgICAgICAgZS5wcmV2ZW50RGVmYXVsdCgpOwogICAgICAgICAgICAgICAgZS5zdG9wUHJvcGFnYXRpb24oKTsKICAgICAgICAgICAgfSwgdHJ1ZSk7CgogICAgICAgICAgICBib3R0b20uYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIGlmICghZS5hbHRLZXkgJiYgIWUuY3RybEtleSAmJiAhZS5zaGlmdEtleSAmJiAhZS5tZXRhS2V5KSB7CiAgICAgICAgICAgICAgICAgICAgY2hhbmdlU3RvcCh0cnVlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxldCBzY3JvbGxIID0gTWF0aC5tYXgoZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LnNjcm9sbEhlaWdodCwgZ2V0Qm9keShkb2N1bWVudCkuc2Nyb2xsSGVpZ2h0KTsKICAgICAgICAgICAgICAgIGdldEJvZHkoZG9jdW1lbnQpLnNjcm9sbFRvcCA9IHNjcm9sbEggfHwgOTk5OTk5OTsKICAgICAgICAgICAgICAgIGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5zY3JvbGxUb3AgPSBzY3JvbGxIIHx8IDk5OTk5OTk7CiAgICAgICAgICAgICAgICBlLnByZXZlbnREZWZhdWx0KCk7CiAgICAgICAgICAgICAgICBlLnN0b3BQcm9wYWdhdGlvbigpOwogICAgICAgICAgICB9LCB0cnVlKTsKCiAgICAgICAgICAgIGxldCBpbml0WCwgaW5pdFksIG1vdmluZyA9IGZhbHNlOwogICAgICAgICAgICBtb3ZlLmFkZEV2ZW50TGlzdGVuZXIoImNsaWNrIiwgZSA9PiB7CiAgICAgICAgICAgICAgICBpZiAoIW1vdmluZykgewogICAgICAgICAgICAgICAgICAgIGNoYW5nZVN0b3AoIWlzUGF1c2UpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LCB0cnVlKTsKCiAgICAgICAgICAgIG1vdmUub25jb250ZXh0bWVudSA9IGUgPT4gewogICAgICAgICAgICAgICAgZS5wcmV2ZW50RGVmYXVsdCgpOwogICAgICAgICAgICAgICAgcGlja2VyLnN0YXJ0KCk7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGxldCByZW1vdmVUaW1lcjsKCiAgICAgICAgICAgIGxldCBtb3VzZU1vdmVIYW5kbGVyID0gZSA9PiB7CiAgICAgICAgICAgICAgICBpZiAobW92aW5nKSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IHdpbmRvd0hlaWdodD13aW5kb3cuaW5uZXJIZWlnaHQgfHwgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LmNsaWVudEhlaWdodDsKICAgICAgICAgICAgICAgICAgICBsZXQgd2luZG93V2lkdGg9d2luZG93LmlubmVyV2lkdGggfHwgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LmNsaWVudFdpZHRoOwogICAgICAgICAgICAgICAgICAgIGluaXRYID0gKGUuY2xpZW50WCAtIDEwICsgNDApIC8gd2luZG93V2lkdGggKiAxMDA7CiAgICAgICAgICAgICAgICAgICAgaW5pdFkgPSAoZS5jbGllbnRZIC0gODMgKyA4MykgLyB3aW5kb3dIZWlnaHQgKiAxMDA7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5mcmFtZS5zdHlsZS50b3AgPSBgY2FsYygke2luaXRZfSUgLSA4M3B4KWA7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5mcmFtZS5zdHlsZS5sZWZ0ID0gYGNhbGMoJHtpbml0WH0lIC0gNDBweClgOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChNYXRoLmFicyhlLmNsaWVudFggLSBpbml0WCkgKyBNYXRoLmFicyhlLmNsaWVudFkgLSBpbml0WSkgPiAyMCkgewogICAgICAgICAgICAgICAgICAgIG1vdmluZyA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHJlbW92ZVRpbWVyKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfTsKICAgICAgICAgICAgbGV0IG1vdXNlVXBIYW5kbGVyID0gZSA9PiB7CiAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQocmVtb3ZlVGltZXIpOwogICAgICAgICAgICAgICAgZG9jdW1lbnQucmVtb3ZlRXZlbnRMaXN0ZW5lcigibW91c2Vtb3ZlIiwgbW91c2VNb3ZlSGFuZGxlciwgdHJ1ZSk7CiAgICAgICAgICAgICAgICBkb2N1bWVudC5yZW1vdmVFdmVudExpc3RlbmVyKCJtb3VzZXVwIiwgbW91c2VVcEhhbmRsZXIsIHRydWUpOwogICAgICAgICAgICAgICAgaWYgKG1vdmluZykgewogICAgICAgICAgICAgICAgICAgIHJ1bGVzRGF0YS5zaWRlQ29udHJvbGxlclBvcyA9IHt4OiBwYXJzZUludChpbml0WCksIHk6IHBhcnNlSW50KGluaXRZKX07CiAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJydWxlc0RhdGEiLCBydWxlc0RhdGEpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwoKICAgICAgICAgICAgbW92ZS5hZGRFdmVudExpc3RlbmVyKCJtb3VzZWRvd24iLCBlID0+IHsKICAgICAgICAgICAgICAgIGluaXRYID0gZS5jbGllbnRYOwogICAgICAgICAgICAgICAgaW5pdFkgPSBlLmNsaWVudFk7CiAgICAgICAgICAgICAgICBtb3ZpbmcgPSBmYWxzZTsKICAgICAgICAgICAgICAgIGNsZWFyVGltZW91dChyZW1vdmVUaW1lcik7CiAgICAgICAgICAgICAgICByZW1vdmVUaW1lciA9IHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIHNlbGYucmVtb3ZlKCk7CiAgICAgICAgICAgICAgICB9LCAxNTAwKTsKICAgICAgICAgICAgICAgIGRvY3VtZW50LmFkZEV2ZW50TGlzdGVuZXIoIm1vdXNlbW92ZSIsIG1vdXNlTW92ZUhhbmRsZXIsIHRydWUpOwogICAgICAgICAgICAgICAgZG9jdW1lbnQuYWRkRXZlbnRMaXN0ZW5lcigibW91c2V1cCIsIG1vdXNlVXBIYW5kbGVyLCB0cnVlKTsKICAgICAgICAgICAgfSwgdHJ1ZSk7CgogICAgICAgICAgICB0aGlzLmZyYW1lID0gZnJhbWU7CiAgICAgICAgICAgIHRoaXMucGFnZW51bSA9IHBhZ2VudW07CiAgICAgICAgICAgIGlmIChydWxlc0RhdGEuc2lkZUNvbnRyb2xsZXJQb3MpIHsKICAgICAgICAgICAgICAgIHRoaXMuZnJhbWUuc3R5bGUudG9wID0gYGNhbGMoJHtydWxlc0RhdGEuc2lkZUNvbnRyb2xsZXJQb3MueX0lIC0gODNweClgOwogICAgICAgICAgICAgICAgdGhpcy5mcmFtZS5zdHlsZS5sZWZ0ID0gYGNhbGMoJHtydWxlc0RhdGEuc2lkZUNvbnRyb2xsZXJQb3MueH0lIC0gNDBweClgOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBhZGRUb1N0YWdlKCkgewogICAgICAgICAgICB0aGlzLmluaXQoKTsKICAgICAgICAgICAgaWYgKCF0aGlzLnN0eWxlRWxlIHx8ICF0aGlzLnN0eWxlRWxlLnBhcmVudE5vZGUpIHsKICAgICAgICAgICAgICAgIHRoaXMuc3R5bGVFbGUgPSBfR01fYWRkU3R5bGUodGhpcy5jc3NUZXh0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIWlzUGF1c2UpIHsKICAgICAgICAgICAgICAgIHRoaXMuZnJhbWUuY2xhc3NMaXN0LnJlbW92ZSgic3RvcCIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMucGFnZW51bS5pbm5lclRleHQgPSBjdXJQYWdlOwogICAgICAgICAgICB0aGlzLmZyYW1lLnRpdGxlID0gaTE4bigicGFnZSIpICsgY3VyUGFnZTsKICAgICAgICAgICAgaWYgKHRoaXMuZnJhbWUucGFyZW50Tm9kZSkgcmV0dXJuOwogICAgICAgICAgICBnZXRCb2R5KGRvY3VtZW50KS5hcHBlbmRDaGlsZCh0aGlzLmZyYW1lKTsKICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHRoaXMuaGlkZVRpbWVyKTsKICAgICAgICAgICAgdGhpcy5mcmFtZS5jbGFzc0xpc3QuYWRkKCJtaW5TaXplIik7CiAgICAgICAgfQoKICAgICAgICByZW1vdmUoKSB7CiAgICAgICAgICAgIGlmICh0aGlzLmZyYW1lICYmIHRoaXMuZnJhbWUucGFyZW50Tm9kZSkgdGhpcy5mcmFtZS5wYXJlbnROb2RlLnJlbW92ZUNoaWxkKHRoaXMuZnJhbWUpOwogICAgICAgIH0KICAgIH0KICAgIGNvbnN0IHNpZGVDb250cm9sbGVyID0gbmV3IFNpZGVDb250cm9sbGVyKCk7CgogICAgY2xhc3MgTmV4dFN3aXRjaCB7CiAgICAgICAgLy9zdGF0aWMgbmV4dFN3aXRjaDsKICAgICAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICAgICAgdGhpcy5pbml0ZWQgPSBmYWxzZTsKICAgICAgICB9CgogICAgICAgIC8qc3RhdGljIGdldEluc3RhbmNlKCkgewogICAgICAgICAgICBpZiAoIU5leHRTd2l0Y2gubmV4dFN3aXRjaCkgewogICAgICAgICAgICAgICAgTmV4dFN3aXRjaC5uZXh0U3dpdGNoID0gbmV3IE5leHRTd2l0Y2goKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gTmV4dFN3aXRjaC5uZXh0U3dpdGNoOwogICAgICAgIH0qLwoKICAgICAgICBpbml0KCkgewogICAgICAgICAgICBpZiAodGhpcy5pbml0ZWQpIHJldHVybjsKICAgICAgICAgICAgdGhpcy5pbml0ZWQgPSB0cnVlOwogICAgICAgICAgICBsZXQgc2VsZiA9IHRoaXM7CiAgICAgICAgICAgIHRoaXMuY3NzVGV4dCA9IGAKICAgICAgICAgICAgICNwYWdldHVhbC1uZXh0U3dpdGNoIHsKICAgICAgICAgICAgICBwb3NpdGlvbjogZml4ZWQ7CiAgICAgICAgICAgICAgdG9wOiAxMHB4OwogICAgICAgICAgICAgIGxlZnQ6IGNhbGMoNTAlIC0gMTYwcHgpOwogICAgICAgICAgICAgIGJhY2tncm91bmQ6IGFsaWNlYmx1ZTsKICAgICAgICAgICAgICBwYWRkaW5nOiAxMHB4OwogICAgICAgICAgICAgIGJvcmRlci1yYWRpdXM6IDVweDsKICAgICAgICAgICAgICB0ZXh0LWFsaWduOiBjZW50ZXI7CiAgICAgICAgICAgICAgb3BhY2l0eTogMC45NTsKICAgICAgICAgICAgICBjb2xvcjogIzE2MTYxNjsKICAgICAgICAgICAgICB6LWluZGV4OiAyMTQ3NDgzNjQ3OwogICAgICAgICAgICAgIGZvbnQtc2l6ZTogMTZweDsKICAgICAgICAgICAgICBib3gtc2hhZG93OiByZ2IoMCAwIDApIDBweCAwcHggMTBweDsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1uZXh0U3dpdGNoPi50aXRsZSB7CiAgICAgICAgICAgICAgbWFyZ2luOiAtNXB4IDQ1cHggMTBweCA0NXB4OwogICAgICAgICAgICAgIGZvbnQtc2l6ZTogMjBweDsKICAgICAgICAgICAgICBmb250LXdlaWdodDogYm9sZDsKICAgICAgICAgICAgICBib3JkZXItYm90dG9tOiAxcHggc29saWQgYmxhY2s7CiAgICAgICAgICAgICAgdXNlci1zZWxlY3Q6IG5vbmU7CiAgICAgICAgICAgICAgY29sb3I6IG9yYW5nZXJlZDsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1uZXh0U3dpdGNoPi5ncm91cCB7CiAgICAgICAgICAgICAgZGlzcGxheTogZmxleDsKICAgICAgICAgICAgICBmbGV4LWRpcmVjdGlvbjogY29sdW1uOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLW5leHRTd2l0Y2g+Lmdyb3VwPnNwYW4gewogICAgICAgICAgICAgIGNvbG9yOiAjMTYxNjE2OwogICAgICAgICAgICAgIGN1cnNvcjogcG9pbnRlcjsKICAgICAgICAgICAgICBtYXJnaW46IDNweDsKICAgICAgICAgICAgICBmb250LXNpemU6IGxhcmdlcjsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1uZXh0U3dpdGNoPi5ncm91cD5zcGFuOmhvdmVyIHsKICAgICAgICAgICAgICBjb2xvcjogcmVkOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLW5leHRTd2l0Y2g+Lmdyb3VwPnNwYW4uY3VycmVudCB7CiAgICAgICAgICAgICAgYm9yZGVyOiAycHggZG90dGVkIHJlZDsKICAgICAgICAgICAgICBib3JkZXItcmFkaXVzOiAxMHB4OwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLW5leHRTd2l0Y2g+LmNsb3NlU3dpdGNoIHsKICAgICAgICAgICAgICBwb3NpdGlvbjogYWJzb2x1dGU7CiAgICAgICAgICAgICAgdG9wOiAzcHg7CiAgICAgICAgICAgICAgcmlnaHQ6IDEwcHg7CiAgICAgICAgICAgICAgYmFja2dyb3VuZDogbm9uZTsKICAgICAgICAgICAgICBib3JkZXI6IG5vbmU7CiAgICAgICAgICAgICAgdmVydGljYWwtYWxpZ246IHRvcDsKICAgICAgICAgICAgICB0cmFuc2l0aW9uOiB0cmFuc2Zvcm0gLjE1cyBlYXNlLWluLW91dDsKICAgICAgICAgICAgICBmbG9hdDogcmlnaHQ7CiAgICAgICAgICAgICAgY3Vyc29yOiBwb2ludGVyOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLW5leHRTd2l0Y2ggc3ZnIHsKICAgICAgICAgICAgICB3aWR0aDogMzBweDsKICAgICAgICAgICAgICBoZWlnaHQ6IDMwcHg7CiAgICAgICAgICAgICAgdmVydGljYWwtYWxpZ246IG1pZGRsZTsKICAgICAgICAgICAgICBmaWxsOiAjMTYxNjE2OwogICAgICAgICAgICAgIG92ZXJmbG93OiBoaWRkZW47CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtbmV4dFN3aXRjaCBidXR0b246aG92ZXIgewogICAgICAgICAgICAgIHRyYW5zZm9ybTogc2NhbGUoMS4yKTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgYDsKICAgICAgICAgICAgbGV0IGZyYW1lID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiZGl2Iik7CiAgICAgICAgICAgIGZyYW1lLmlkID0gInBhZ2V0dWFsLW5leHRTd2l0Y2giOwogICAgICAgICAgICBmcmFtZS5pbm5lckhUTUwgPSBjcmVhdGVIVE1MKGAKICAgICAgICAgICAgICAgIDxkaXYgY2xhc3M9InRpdGxlIj4ke2kxOG4oIm5leHRTd2l0Y2giKX08L2Rpdj4KICAgICAgICAgICAgICAgIDxidXR0b24gdHlwZT0iYnV0dG9uIiBjbGFzcz0iY2xvc2VTd2l0Y2giPgogICAgICAgICAgICAgICAgICA8c3ZnIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBwLWlkPSIyNzU0Ij4KICAgICAgICAgICAgICAgICAgICA8c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xldCBzcGFuID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic3BhbiIpOwogICAgICAgICAgICAgICAgbGV0IHRhcmdldCA9IGdldEVsZW1lbnQobGluaywgZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgbGV0IGluZGV4ID0gIjxiPiIgKyAoaSArIDEpICsgIjwvYj46ICI7CiAgICAgICAgICAgICAgICBpZiAodGFyZ2V0KSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IHRhcmdldElubmVyID0gdGFyZ2V0LmlubmVyVGV4dC50cmltKCk7CiAgICAgICAgICAgICAgICAgICAgc3Bhbi5pbm5lckhUTUwgPSBpbmRleCArICh0YXJnZXRJbm5lciB8fCBsaW5rKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgc3Bhbi5pbm5lckhUTUwgPSBpbmRleCArICJOb3QgRm91bmQiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3Bhbi50aXRsZSA9IGxpbms7CiAgICAgICAgICAgICAgICBzcGFuLmFkZEV2ZW50TGlzdGVuZXIoImNsaWNrIiwgZSA9PiB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGN1cnJlbnRTcGFuKSBjdXJyZW50U3Bhbi5jbGFzc0xpc3QucmVtb3ZlKCJjdXJyZW50Iik7CiAgICAgICAgICAgICAgICAgICAgc3Bhbi5jbGFzc0xpc3QuYWRkKCJjdXJyZW50Iik7CiAgICAgICAgICAgICAgICAgICAgY3VycmVudFNwYW4gPSBzcGFuOwogICAgICAgICAgICAgICAgICAgIG5leHRJbmRleCA9IGk7CiAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJuZXh0U3dpdGNoXyIgKyBsb2NhdGlvbi5ob3N0LCBuZXh0SW5kZXggPT09IDAgPyAiIiA6IG5leHRJbmRleCk7CiAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5jdXJVcmwgKz0gIiNwYWdldHVhbCI7CiAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5vbGRVcmwgPSBydWxlUGFyc2VyLmN1clVybDsKICAgICAgICAgICAgICAgICAgICBhdXRvTG9hZE51bSA9IC0xOwogICAgICAgICAgICAgICAgICAgIGlmICghcnVsZVBhcnNlci5uZXh0TGlua0hyZWYpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaXNMb2FkaW5nID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuZ2V0TmV4dExpbmsocnVsZVBhcnNlci5wYWdlRG9jIHx8IGRvY3VtZW50KTsKICAgICAgICAgICAgICAgICAgICBzZWxmLmNsb3NlKCk7CiAgICAgICAgICAgICAgICB9LCB0cnVlKTsKICAgICAgICAgICAgICAgIGlmIChpID09IG5leHRJbmRleCkgewogICAgICAgICAgICAgICAgICAgIHNwYW4uY2xhc3NMaXN0LmFkZCgiY3VycmVudCIpOwogICAgICAgICAgICAgICAgICAgIGN1cnJlbnRTcGFuID0gc3BhbjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGdyb3VwLmFwcGVuZENoaWxkKHNwYW4pOwogICAgICAgICAgICB9KTsKICAgICAgICB9CgogICAgICAgIHN0YXJ0KCkgewogICAgICAgICAgICB0aGlzLmluaXQoKTsKICAgICAgICAgICAgaWYgKCF0aGlzLnN0eWxlRWxlIHx8ICF0aGlzLnN0eWxlRWxlLnBhcmVudE5vZGUpIHsKICAgICAgICAgICAgICAgIHRoaXMuc3R5bGVFbGUgPSBfR01fYWRkU3R5bGUodGhpcy5jc3NUZXh0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuYXBwZW5kQ2hpbGQodGhpcy5mcmFtZSk7CiAgICAgICAgfQoKICAgICAgICBjbG9zZSgpIHsKICAgICAgICAgICAgaWYgKHRoaXMuZnJhbWUucGFyZW50Tm9kZSkgdGhpcy5mcmFtZS5wYXJlbnROb2RlLnJlbW92ZUNoaWxkKHRoaXMuZnJhbWUpOwogICAgICAgIH0KICAgIH0KICAgIGNvbnN0IG5leHRTd2l0Y2ggPSBuZXcgTmV4dFN3aXRjaCgpOwoKICAgIGNsYXNzIFBpY2tlciB7CiAgICAgICAgLy9zdGF0aWMgcGlja2VyOwogICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgICB0aGlzLmluaXRlZCA9IGZhbHNlOwogICAgICAgIH0KCiAgICAgICAgLypzdGF0aWMgZ2V0SW5zdGFuY2UoKSB7CiAgICAgICAgICAgIGlmICghUGlja2VyLnBpY2tlcikgewogICAgICAgICAgICAgICAgUGlja2VyLnBpY2tlciA9IG5ldyBQaWNrZXIoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gUGlja2VyLnBpY2tlcjsKICAgICAgICB9Ki8KCiAgICAgICAgaW5pdCgpIHsKICAgICAgICAgICAgaWYgKHRoaXMuaW5pdGVkKSByZXR1cm47CiAgICAgICAgICAgIHRoaXMuaW5pdGVkID0gdHJ1ZTsKICAgICAgICAgICAgbGV0IHNlbGYgPSB0aGlzOwogICAgICAgICAgICB0aGlzLnNpZ25MaXN0ID0gW107CiAgICAgICAgICAgIHRoaXMuY3NzVGV4dCA9IGAKICAgICAgICAgICAgIGJvZHkucGFnZXR1YWwtcGlja2VyLAogICAgICAgICAgICAgYm9keS5wYWdldHVhbC1waWNrZXIgKjpob3ZlciwKICAgICAgICAgICAgIGJvZHkucGFnZXR1YWwtcGlja2VyIGE6aG92ZXIgewogICAgICAgICAgICAgIGN1cnNvcjogY3Jvc3NoYWlyICFpbXBvcnRhbnQ7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIHsKICAgICAgICAgICAgICBwb3NpdGlvbjogZml4ZWQ7CiAgICAgICAgICAgICAgdG9wOiAxMHB4OwogICAgICAgICAgICAgIGxlZnQ6IGNhbGMoNTAlIC0gMTc4cHgpOwogICAgICAgICAgICAgIGJhY2tncm91bmQ6IGFsaWNlYmx1ZTsKICAgICAgICAgICAgICBwYWRkaW5nOiAxMHB4OwogICAgICAgICAgICAgIGJvcmRlci1yYWRpdXM6IDVweDsKICAgICAgICAgICAgICB0ZXh0LWFsaWduOiBjZW50ZXI7CiAgICAgICAgICAgICAgb3BhY2l0eTogMC45NTsKICAgICAgICAgICAgICBjb2xvcjogIzE2MTYxNjsKICAgICAgICAgICAgICB6LWluZGV4OiAyMTQ3NDgzNjQ2OwogICAgICAgICAgICAgIGZvbnQtc2l6ZTogMTZweDsKICAgICAgICAgICAgICBib3gtc2hhZG93OiByZ2IoMCAwIDApIDBweCAwcHggMTBweDsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1waWNrZXIgKiB7CiAgICAgICAgICAgICAgbWFyZ2luOiAwOwogICAgICAgICAgICAgIHBhZGRpbmc6IDA7CiAgICAgICAgICAgICAgZm9udC1mYW1pbHk6IFRpbWVzIE5ldyBSb21hbjsKICAgICAgICAgICAgICBvdmVyZmxvdzogaW5pdGlhbDsKICAgICAgICAgICAgICB1c2VyLXNlbGVjdDogbm9uZTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1waWNrZXI+LnRpdGxlIHsKICAgICAgICAgICAgICBtYXJnaW46IC01cHggNDVweCAxMHB4IDQ1cHg7CiAgICAgICAgICAgICAgZm9udC1zaXplOiAyMHB4OwogICAgICAgICAgICAgIGZvbnQtd2VpZ2h0OiBib2xkOwogICAgICAgICAgICAgIGN1cnNvcjogbW92ZTsKICAgICAgICAgICAgICBib3JkZXItYm90dG9tOiAxcHggc29saWQgYmxhY2s7CiAgICAgICAgICAgICAgdXNlci1zZWxlY3Q6IG5vbmU7CiAgICAgICAgICAgICAgY29sb3I6IG9yYW5nZXJlZDsKICAgICAgICAgICAgICBoZWlnaHQ6IGluaXRpYWw7CiAgICAgICAgICAgICAgd2lkdGg6IGluaXRpYWw7CiAgICAgICAgICAgICAgcG9zaXRpb246IGluaXRpYWw7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIGJ1dHRvbiB7CiAgICAgICAgICAgICAgYmFja2dyb3VuZDogbm9uZTsKICAgICAgICAgICAgICBib3JkZXI6IG5vbmU7CiAgICAgICAgICAgICAgdmVydGljYWwtYWxpZ246IHRvcDsKICAgICAgICAgICAgICB0cmFuc2l0aW9uOiB0cmFuc2Zvcm0gLjE1cyBlYXNlLWluLW91dDsKICAgICAgICAgICAgICBmbG9hdDogcmlnaHQ7CiAgICAgICAgICAgICAgY3Vyc29yOiBwb2ludGVyOwogICAgICAgICAgICAgIG92ZXJmbG93OiBoaWRkZW47CiAgICAgICAgICAgICAgYmFja2dyb3VuZC1jb2xvcjogdW5zZXQhaW1wb3J0YW50OwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciBidXR0b246aG92ZXIgewogICAgICAgICAgICAgIHRyYW5zZm9ybTogc2NhbGUoMS4yKTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1waWNrZXI+LmNsb3NlUGlja2VyIHsKICAgICAgICAgICAgICBwb3NpdGlvbjogYWJzb2x1dGU7CiAgICAgICAgICAgICAgdG9wOiAzcHg7CiAgICAgICAgICAgICAgcmlnaHQ6IDEwcHg7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyPi5sb2dvSWNvbiB7CiAgICAgICAgICAgICAgcG9zaXRpb246IGFic29sdXRlOwogICAgICAgICAgICAgIHRvcDogM3B4OwogICAgICAgICAgICAgIGxlZnQ6IDEwcHg7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyPi5sb2dvSWNvbi5zaG93U2lnbj5zdmc+cGF0aCB7CiAgICAgICAgICAgICAgZmlsbDogZ3JheTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1waWNrZXIgdGV4dGFyZWF7CiAgICAgICAgICAgICAgZGlzcGxheTogaW5saW5lLWJsb2NrOwogICAgICAgICAgICAgIHdpZHRoOiBjYWxjKDEwMCUgLSA2NXB4KTsKICAgICAgICAgICAgICBoZWlnaHQ6IDIwcHg7CiAgICAgICAgICAgICAgbWluLXdpZHRoOiAyOTBweDsKICAgICAgICAgICAgICBtYXgtd2lkdGg6IGNhbGMoNjV2dyAtIDUwcHgpOwogICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IHVuc2V0OwogICAgICAgICAgICAgIHBhZGRpbmc6IDZweCAxMnB4OwogICAgICAgICAgICAgIGZvbnQtc2l6ZTogMTZweDsKICAgICAgICAgICAgICBmb250LXdlaWdodDogNDAwOwogICAgICAgICAgICAgIGxpbmUtaGVpZ2h0OiAxLjU7CiAgICAgICAgICAgICAgY29sb3I6ICM0OTUwNTc7CiAgICAgICAgICAgICAgYmFja2dyb3VuZC1jb2xvcjogI2ZmZjsKICAgICAgICAgICAgICBiYWNrZ3JvdW5kLWNsaXA6IHBhZGRpbmctYm94OwogICAgICAgICAgICAgIGJvcmRlcjogMXB4IHNvbGlkICNjZWQ0ZGE7CiAgICAgICAgICAgICAgYm9yZGVyLXJhZGl1czogNHB4OwogICAgICAgICAgICAgIHRyYW5zaXRpb246IGJvcmRlci1jb2xvciAuMTVzIGVhc2UtaW4tb3V0LGJveC1zaGFkb3cgLjE1cyBlYXNlLWluLW91dDsKICAgICAgICAgICAgICBib3gtc2l6aW5nOiBjb250ZW50LWJveDsKICAgICAgICAgICAgICBtYXJnaW4tcmlnaHQ6IDVweDsKICAgICAgICAgICAgICByZXNpemU6IGJvdGg7CiAgICAgICAgICAgICAgYm94LXNoYWRvdzogMCAxcHggNXB4IDFweCAjZGRkOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciB0ZXh0YXJlYTpmb2N1cyB7CiAgICAgICAgICAgICAgY29sb3I6IGJsYWNrOwogICAgICAgICAgICAgIGJhY2tncm91bmQtY29sb3I6ICNmZmY7CiAgICAgICAgICAgICAgYm9yZGVyLWNvbG9yOiAjODBiZGZmOwogICAgICAgICAgICAgIG91dGxpbmU6IDA7CiAgICAgICAgICAgICAgYm94LXNoYWRvdzogMCAwIDAgMy4ycHggcmdiKDAgMTIzIDI1NSAvIDI1JSk7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIFt0eXBlPWNoZWNrYm94XSwKICAgICAgICAgICAgICNwYWdldHVhbC1waWNrZXIgW3R5cGU9cmFkaW9dIHsKICAgICAgICAgICAgICBsaW5lLWhlaWdodDogMjBweDsKICAgICAgICAgICAgICBoZWlnaHQ6IDI1cHg7CiAgICAgICAgICAgICAgd2lkdGg6IDI1cHg7CiAgICAgICAgICAgICAgbWFyZ2luLWxlZnQ6IDVweDsKICAgICAgICAgICAgICB2ZXJ0aWNhbC1hbGlnbjogbWlkZGxlOwogICAgICAgICAgICAgIGFwcGVhcmFuY2U6IGF1dG87CiAgICAgICAgICAgICAgZGlzcGxheTogaW5saW5lLWJsb2NrOwogICAgICAgICAgICAgIHBvc2l0aW9uOiBpbml0aWFsOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciBsYWJlbCB7CiAgICAgICAgICAgICAgZm9udC1zaXplOiAxOHB4OwogICAgICAgICAgICAgIGxpbmUtaGVpZ2h0OiAyNXB4OwogICAgICAgICAgICAgIHZlcnRpY2FsLWFsaWduOiBtaWRkbGU7CiAgICAgICAgICAgICAgZGlzcGxheTogaW5saW5lLWJsb2NrOwogICAgICAgICAgICAgIGNvbG9yOiBibGFjazsKICAgICAgICAgICAgICBwb3NpdGlvbjogaW5pdGlhbDsKICAgICAgICAgICAgICBjdXJzb3I6IHBvaW50ZXI7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIC5ib3R0b20gewogICAgICAgICAgICAgIHRleHQtYWxpZ246IGxlZnQ7CiAgICAgICAgICAgICAgbWFyZ2luOiAxMHB4IDA7CiAgICAgICAgICAgICAgd2lkdGg6IDEwMCU7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIC5ib3R0b20+YnV0dG9uIHsKICAgICAgICAgICAgICBmbG9hdDogcmlnaHQ7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIHN2ZyB7CiAgICAgICAgICAgICAgd2lkdGg6IDMwcHg7CiAgICAgICAgICAgICAgaGVpZ2h0OiAzMHB4OwogICAgICAgICAgICAgIHZlcnRpY2FsLWFsaWduOiBtaWRkbGU7CiAgICAgICAgICAgICAgZmlsbDogIzE2MTYxNjsKICAgICAgICAgICAgICBvdmVyZmxvdzogaGlkZGVuOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciBzdmcgKiB7CiAgICAgICAgICAgICAgcG9pbnRlci1ldmVudHM6IG5vbmU7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIC5hbGxwYXRoIHsKICAgICAgICAgICAgICBmb250LXNpemU6IDE4cHg7CiAgICAgICAgICAgICAgbWFyZ2luOiAxMHB4IGF1dG87CiAgICAgICAgICAgICAgbWF4LXdpZHRoOiAzMzBweDsKICAgICAgICAgICAgICB3b3JkLWJyZWFrOiBicmVhay1hbGw7CiAgICAgICAgICAgICAgY3Vyc29yOiBjb250ZXh0LW1lbnU7CiAgICAgICAgICAgICAgb3ZlcmZsb3c6IGhpZGRlbjsKICAgICAgICAgICAgICBtYXgtaGVpZ2h0OiA0MnB4OwogICAgICAgICAgICAgIC1tb3otdHJhbnNpdGlvbjptYXgtaGVpZ2h0IDFzIGVhc2UtaW47CiAgICAgICAgICAgICAgLXdlYmtpdC10cmFuc2l0aW9uOm1heC1oZWlnaHQgMXMgZWFzZS1pbjsKICAgICAgICAgICAgICB0cmFuc2l0aW9uOm1heC1oZWlnaHQgMXMgZWFzZS1pbjsKICAgICAgICAgICAgICBjb2xvcjogYmxhY2s7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIC5hbGxwYXRoOmhvdmVyIHsKICAgICAgICAgICAgICBtYXgtaGVpZ2h0OiBjYWxjKDEwMHZoIC0gMTMwcHgpOwogICAgICAgICAgICAgIG92ZXJmbG93OiBhdXRvOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciAuYWxscGF0aD5zcGFuLnBhdGggewogICAgICAgICAgICAgIGN1cnNvcjogcG9pbnRlcjsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1waWNrZXIgLmFsbHBhdGg+c3Bhbi5wYXRoOmhvdmVyIHsKICAgICAgICAgICAgICBjb2xvcjogb3JhbmdlcmVkOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciAubW9yZUNvbmZpZyB7CiAgICAgICAgICAgICAgZGlzcGxheTogZmxleDsKICAgICAgICAgICAgICBqdXN0aWZ5LWNvbnRlbnQ6IHNwYWNlLWJldHdlZW47CiAgICAgICAgICAgICAgYm9yZGVyLXRvcDogMXB4IHNvbGlkOwogICAgICAgICAgICAgIHBhZGRpbmctdG9wOiAxMHB4OwogICAgICAgICAgICAgIHdpZHRoOiAxMDAlOwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciAuY29tbWFuZCB7CiAgICAgICAgICAgICAgd2lkdGg6IDEwMCU7CiAgICAgICAgICAgICAgY29sb3I6IGJsYWNrIWltcG9ydGFudDsKICAgICAgICAgICAgICB0ZXh0LWFsaWduOiBjZW50ZXI7CiAgICAgICAgICAgICAgZm9udC1zaXplOiBsYXJnZTsKICAgICAgICAgICAgICBtYXJnaW4tdG9wOiAxMHB4OwogICAgICAgICAgICAgIGJveC1zaGFkb3c6IDAgMXB4IDZweCAwIHJnYmEoMCwgMCwgMCwgMC4xMik7CiAgICAgICAgICAgICAgYm9yZGVyLXJhZGl1czogNXB4OwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciAuY29tbWFuZDpob3ZlciB7CiAgICAgICAgICAgICAgY29sb3I6IG9yYW5nZXJlZDsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1waWNrZXIgI3Nob3dEZXRhaWwgewogICAgICAgICAgICAgIGZsb2F0OiBpbml0aWFsOwogICAgICAgICAgICAgIG1hcmdpbi10b3A6IDEwcHg7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyICNzaG93RGV0YWlsLnNob3dEZXRhaWwgewogICAgICAgICAgICAgIGZsb2F0OiByaWdodDsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1waWNrZXIgI3Nob3dEZXRhaWw+c3ZnIHsKICAgICAgICAgICAgICAtbW96LXRyYW5zaXRpb246dHJhbnNmb3JtIDAuM3MgZWFzZTsKICAgICAgICAgICAgICAtd2Via2l0LXRyYW5zaXRpb246dHJhbnNmb3JtIDAuM3MgZWFzZTsKICAgICAgICAgICAgICB0cmFuc2l0aW9uOnRyYW5zZm9ybSAwLjMgZWFzZTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgICNwYWdldHVhbC1waWNrZXIgI3Nob3dEZXRhaWwuc2hvd0RldGFpbD5zdmcgewogICAgICAgICAgICAgIHRyYW5zZm9ybTogcm90YXRlKDE4MGRlZyk7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIC50ZW1wUnVsZSB7CiAgICAgICAgICAgICAgbWFyZ2luLXRvcDogMTBweDsKICAgICAgICAgICAgICBoZWlnaHQ6IDMwMHB4OwogICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDE1MHB4OwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciAjc2F2ZURldGFpbCB7CiAgICAgICAgICAgICAgZGlzcGxheTogbm9uZTsKICAgICAgICAgICAgICBwb3NpdGlvbjogYWJzb2x1dGU7CiAgICAgICAgICAgICAgYm90dG9tOiAxMHB4OwogICAgICAgICAgICAgIHJpZ2h0OiA4cHg7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIC5zaG93RGV0YWlsfiNzYXZlRGV0YWlsIHsKICAgICAgICAgICAgICBkaXNwbGF5OiBpbmxpbmUtYmxvY2s7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyICNzYXZlRGV0YWlsIHN2ZyB7CiAgICAgICAgICAgICAgd2lkdGg6IDM1cHg7CiAgICAgICAgICAgICAgaGVpZ2h0OiAzNXB4OwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciAuYWRkUHJvcCB7CiAgICAgICAgICAgICAgZGlzcGxheTogbm9uZTsKICAgICAgICAgICAgICBmbGV4LWRpcmVjdGlvbjogY29sdW1uOwogICAgICAgICAgICAgIHBvc2l0aW9uOiBhYnNvbHV0ZTsKICAgICAgICAgICAgICBib3R0b206IDQ1cHg7CiAgICAgICAgICAgICAgcmlnaHQ6IDEycHg7CiAgICAgICAgICAgICB9CiAgICAgICAgICAgICAjcGFnZXR1YWwtcGlja2VyIC5zaG93RGV0YWlsfi5hZGRQcm9wIHsKICAgICAgICAgICAgICBkaXNwbGF5OiBmbGV4OwogICAgICAgICAgICAgfQogICAgICAgICAgICAgI3BhZ2V0dWFsLXBpY2tlciAuYWRkUHJvcD5idXR0b24gewogICAgICAgICAgICAgIGZvbnQtc2l6ZTogMzBweDsKICAgICAgICAgICAgICBmb250LWZhbWlseTogQXJpYWwsc2Fucy1zZXJpZjsKICAgICAgICAgICAgICBsaW5lLWhlaWdodDogMzVweDsKICAgICAgICAgICAgICBjb2xvcj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HJhZGlvLmNoZWNrZWQpIHsKICAgICAgICAgICAgICAgICAgICBmb3JjZVN0YXRlID0gIiI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHN3aXRjaCAocmFkaW8uaWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY2FzZSAiZm9yY2VTdGF0ZUlmcmFtZSI6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3JjZVN0YXRlID0gMjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICBjYXNlICJmb3JjZVN0YXRlRHluYW1pYyI6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3JjZVN0YXRlID0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICBjYXNlICJmb3JjZVN0YXRlRGlzYWJsZSI6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3JjZVN0YXRlID0gMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgiZm9yY2VTdGF0ZV8iICsgbG9jYXRpb24uaG9zdCwgZm9yY2VTdGF0ZSk7CiAgICAgICAgICAgICAgICBzZWxmLmNsb3NlKCk7CiAgICAgICAgICAgICAgICBsb2NhdGlvbi5yZWxvYWQoKTsKICAgICAgICAgICAgfTsKICAgICAgICAgICAgZm9yY2VTdGF0ZUlmcmFtZS5wYXJlbnROb2RlLmFkZEV2ZW50TGlzdGVuZXIoIm1vdXNlZG93biIsIGNsaWNrUmFkaW8pOwogICAgICAgICAgICBmb3JjZVN0YXRlRHluYW1pYy5wYXJlbnROb2RlL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XV0b1Njcm9sbCkgfHwgMDsKICAgICAgICAgICAgICAgIGlmIChhdXRvU2Nyb2xsIDwgMCkgYXV0b1Njcm9sbCA9IDA7CiAgICAgICAgICAgICAgICBlbHNlIGlmIChhdXRvU2Nyb2xsID4gMTAwMCkgYXV0b1Njcm9sbCA9IDEwMDA7CiAgICAgICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oImF1dG9TY3JvbGxfIiArIGxvY2F0aW9uLmhvc3QgKyBsb2NhdGlvbi5wYXRobmFtZSwgYXV0b1Njcm9sbCk7CiAgICAgICAgICAgICAgICBzdGFydEF1dG9TY3JvbGwoKTsKICAgICAgICAgICAgfSwgdHJ1ZSk7CiAgICAgICAgICAgIGFkZE90aGVyUHJvcC5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgbGV0IHByb3BOYW1lID0gcHJvbXB0KGkxOG4oInByb3BOYW1lIikpOwogICAgICAgICAgICAgICAgaWYgKCFwcm9wTmFtZSkgcmV0dXJuOwogICAgICAgICAgICAgICAgbGV0IHByb3BWYWx1ZSA9IHByb21wdChpMThuKCJwcm9wVmFsdWUiKSk7CiAgICAgICAgICAgICAgICBpZiAoIXByb3BWYWx1ZSkgcmV0dXJuOwogICAgICAgICAgICAgICAgaWYgKHByb3BWYWx1ZSA9PT0gInRydWUiKSBwcm9wVmFsdWUgPSB0cnVlOwogICAgICAgICAgICAgICAgZWxzZSBpZiAocHJvcFZhbHVlID09PSAiZmFsc2UiKSBwcm9wVmFsdWUgPSBmYWxzZTsKICAgICAgICAgICAgICAgIGVsc2UgaWYgKC9eXGQrJC8udGVzdChwcm9wVmFsdWUpKSBwcm9wVmFsdWUgPSBwYXJzZUludChwcm9wVmFsdWUpOwogICAgICAgICAgICAgICAgbGV0IGVkaXRUZW1wID0gc2VsZi5nZXRUZW1wUnVsZSgpOwogICAgICAgICAgICAgICAgaWYgKCFlZGl0VGVtcCkgcmV0dXJuOwogICAgICAgICAgICAgICAgZWRpdFRlbXBbcHJvcE5hbWVdID0gcHJvcFZhbHVlOwogICAgICAgICAgICAgICAgc2VsZi50ZW1wUnVsZS52YWx1ZSA9IEpTT04uc3RyaW5naWZ5KGVkaXRUZW1wLCBudWxsLCA0KTsKICAgICAgICAgICAgfSwgdHJ1ZSk7CiAgICAgICAgICAgIGFkZE5leHRTZWxlY3Rvci5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgbGV0IGVkaXRUZW1wID0gc2VsZi5nZXRUZW1wUnVsZSgpOwogICAgICAgICAgICAgICAgaWYgKCFlZGl0VGVtcCkgcmV0dXJuOwogICAgICAgICAgICAgICAgbGV0IHNlbGVjdG9yID0gc2VsZi5zZWxlY3RvcklucHV0LnZhbHVlOwogICAgICAgICAgICAgICAgaWYgKHNlbGVjdG9yKSB7CiAgICAgICAgICAgICAgICAgICAgZWRpdFRlbXAubmV4dExpbmsgPSBzZWxlY3RvcjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHNlbGYudGVtcFJ1bGUudmFsdWUgPSBKU09OLnN0cmluZ2lmeShlZGl0VGVtcCwgbnVsbCwgNCk7CiAgICAgICAgICAgIH0sIHRydWUpOwogICAgICAgICAgICBhZGRQYWdlU2VsZWN0b3IuYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIGxldCBlZGl0VGVtcCA9IHNlbGYuZ2V0VGVtcFJ1bGUoKTsKICAgICAgICAgICAgICAgIGlmICghZWRpdFRlbXApIHJldHVybjsKICAgICAgICAgICAgICAgIGxldCBzZWxlY3RvciA9IHNlbGYuc2VsZWN0b3JJbnB1dC52YWx1ZTsKICAgICAgICAgICAgICAgIGlmIChzZWxlY3RvcikgewogICAgICAgICAgICAgICAgICAgIGVkaXRUZW1wLnBhZ2VFbGVtZW50ID0gc2VsZWN0b3I7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzZWxmLnRlbXBSdWxlLnZhbHVlID0gSlNPTi5zdHJpbmdpZnkoZWRpdFRlbXAsIG51bGwsIDQpOwogICAgICAgICAgICB9LCB0cnVlKTsKICAgICAgICAgICAgc2hvd0RldGFpbEJ0bi5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgaWYgKHRlbXBSdWxlLnN0eWxlLmRpc3BsYXkgPT0gIm5vbmUiKSB7CiAgICAgICAgICAgICAgICAgICAgdGVtcFJ1bGUuc3R5bGUuZGlzcGxheSA9ICIiOwogICAgICAgICAgICAgICAgICAgIHNob3dEZXRhaWxCdG4uY2xhc3NMaXN0LmFkZCgic2hvd0RldGFpbCIpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICB0ZW1wUnVsZS5zdHlsZS5kaXNwbGF5ID0gIm5vbmUiOwogICAgICAgICAgICAgICAgICAgIHNob3dEZXRhaWxCdG4uY2xhc3NMaXN0LnJlbW92ZSgic2hvd0RldGFpbCIpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LCB0cnVlKTsKICAgICAgICAgICAgc2F2ZURldGFpbEJ0bi5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgbGV0IGVkaXRUZW1wID0gc2VsZi5nZXRUZW1wUnVsZSh0cnVlKTsKICAgICAgICAgICAgICAgIGlmICh0ZW1wUnVsZS52YWx1ZSAmJiAhZWRpdFRlbXApIHsKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZighcnVsZVBhcnNlci5jdXN0b21SdWxlcykgewogICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuY3VzdG9tUnVsZXMgPSBbXTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZvciAobGV0IGkgaW4gcnVsZVBhcnNlci5jdXN0b21SdWxlcykgewogICAgICAgICAgICAgICAgICAgIGlmIChydWxlUGFyc2VyLmN1c3RvbVJ1bGVzW2ldLnVybCA9PSBlZGl0VGVtcC51cmwpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5jdXN0b21SdWxlcy5zcGxpY2UoaSwgMSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICh0ZW1wUnVsZS52YWx1ZSkgewogICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuY3VzdG9tUnVsZXMudW5zaGlmdChlZGl0VGVtcCk7CiAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5jdXJTaXRlUnVsZSA9IGVkaXRUZW1wOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBydWxlUGFyc2VyLmN1clNpdGVSdWxlID0ge307CiAgICAgICAgICAgICAgICAgICAgaXNQYXVzZSA9IHRydWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oImN1c3RvbVJ1bGVzIiwgcnVsZVBhcnNlci5jdXN0b21SdWxlcyk7CiAgICAgICAgICAgICAgICBpZiAocnVsZVBhcnNlci5ocFJ1bGVzICYmIHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUgJiYgIXJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuc2luZ2xlVXJsKSB7CiAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5hZGRUb0hwUnVsZXModHJ1ZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAod2luZG93LmNvbmZpcm0oaTE4bigicmVsb2FkUGFnZSIpKSkgewogICAgICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4ge2xvY2F0aW9uLnJlbG9hZCgpfSwgMTAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSwgdHJ1ZSk7CiAgICAgICAgICAgIG5leHRTd2l0Y2hCdG4uYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIHNlbGYuY2xvc2UoKTsKICAgICAgICAgICAgICAgIG5leHRTd2l0Y2guc3RhcnQoKTsKICAgICAgICAgICAgfSwgdHJ1ZSk7CiAgICAgICAgICAgIGxvYWROb3cuYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIHNlbGYuY2xvc2UoKTsKICAgICAgICAgICAgICAgIGxldCBsb2FkTnVtPXdpbmRvdy5wcm9tcHQoaTE4bigibG9hZENvbmZpcm0iKSwgIjEiKTsKICAgICAgICAgICAgICAgIGlmKGxvYWROdW09PT0iIiB8fCBsb2FkTnVtPT09bnVsbClyZXR1cm47CiAgICAgICAgICAgICAgICBhdXRvTG9hZE51bT1NYXRoLmFicyhwYXJzZUludChsb2FkTnVtKSk7CiAgICAgICAgICAgICAgICBuZXh0UGFnZSgpOwogICAgICAgICAgICB9LCB0cnVlKTsKICAgICAgICAgICAgY2xvc2VCdG4uYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIHNlbGYuY2xvc2UoKTsKICAgICAgICAgICAgfSwgdHJ1ZSk7CiAgICAgICAgICAgIHRoaXMuc2hvd1NpZ24gPSB0cnVlOwogICAgICAgICAgICBsb2dvQnRuLmFkZEV2ZW50TGlzdGVuZXIoImNsaWNrIiwgZSA9PiB7CiAgICAgICAgICAgICAgICBsb2dvQnRuLmNsYXNzTGlzdC50b2dnbGUoInNob3dTaWduIik7CiAgICAgICAgICAgICAgICBzZWxmLnNob3dTaWduID0gIXNlbGYuc2hvd1NpZ247CiAgICAgICAgICAgICAgICBnZXRCb2R5KGRvY3VtZW50KS5jbGFzc0xpc3QudG9nZ2xlKCJwYWdldHVhbC1waWNrZXIiKTsKICAgICAgICAgICAgfSwgdHJ1ZSk7CiAgICAgICAgICAgIGxldCBtb3ZpbmcgPSBmYWxzZTsKICAgICAgICAgICAgbGV0IGluaXRYID0gMCwgaW5pdFkgPSAwLCBpbml0UG9zID0ge3g6IDAsIHk6IDB9OwogICAgICAgICAgICBsZXQgbW92ZUhhbmxkZXIgPSBlID0+IHsKICAgICAgICAgICAgICAgIGlmIChtb3ZpbmcpIHsKICAgICAgICAgICAgICAgICAgICBmcmFtZS5zdHlsZS5sZWZ0ID0gZS5jbGllbnRYIC0gaW5pdFggKyAicHgiOwogICAgICAgICAgICAgICAgICAgIGZyYW1lLnN0eWxlLnRvcCA9IGUuY2xpZW50WSAtIGluaXRZICsgInB4IjsKICAgICAgICAgICAgICAgICAgICBlLnN0b3BQcm9wYWdhdGlvbigpOwogICAgICAgICAgICAgICAgICAgIGUucHJldmVudERlZmF1bHQoKTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZihNYXRoLmFicyhlLmNsaWVudFggLSBpbml0UG9zLngpICsgTWF0aC5hYnMoZS5jbGllbnRZIC0gaW5pdFBvcy55KSA+IDIwKSB7CiAgICAgICAgICAgICAgICAgICAgbW92aW5nID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfTsKICAgICAgICAgICAgbGV0IHVwSGFubGRlciA9IGUgPT4gewogICAgICAgICAgICAgICAgaWYgKG1vdmluZykgewogICAgICAgICAgICAgICAgICAgIG1vdmluZyA9IGZhbHNlOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBfR01fb3BlbkluVGFiKHJ1bGVzRGF0YS5jb25maWdQYWdlIHx8IGNvbmZpZ1BhZ2VbMF0sIHthY3RpdmU6IHRydWV9KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGRvY3VtZW50LnJlbW92ZUV2ZW50TGlzdGVuZXIoIm1vdXNlbW92ZSIsIG1vdmVIYW5sZGVyLCB0cnVlKTsKICAgICAgICAgICAgICAgIHRpdGxlLnJlbW92ZUV2ZW50TGlzdGVuZXIoIm1vdXNldXAiLCB1cEhhbmxkZXIsIHRydWUpOwogICAgICAgICAgICAgICAgZS5zdG9wUHJvcGFnYXRpb24oKTsKICAgICAgICAgICAgICAgIGUucHJldmVudERlZmF1bHQoKTsKICAgICAgICAgICAgfTsKICAgICAgICAgICAgdGl0bGUuYWRkRXZlbnRMaXN0ZW5lcigibW91c2Vkb3duIiwgZSA9PiB7CiAgICAgICAgICAgICAgICBpbml0UG9zID0ge3g6IGUuY2xpZW50WCwgeTogZS5jbGllbnRZfTsKICAgICAgICAgICAgICAgIGluaXRYID0gZS5jbGllbnRYIC0gcGFyc2VJbnQoZ2V0Q29tcHV0ZWRTdHlsZShmcmFtZSkubGVmdCk7CiAgICAgICAgICAgICAgICBpbml0WSA9IGUuY2xpZW50WSAtIHBhcnNlSW50KGdldENvbXB1dGVkU3R5bGUoZnJhbWUpLnRvcCk7CiAgICAgICAgICAgICAgICBkb2N1bWVudC5hZGRFdmVudExpc3RlbmVyKCJtb3VzZW1vdmUiLCBtb3ZlSGFubGRlciwgdHJ1ZSk7CiAgICAgICAgICAgICAgICB0aXRsZS5hZGRFdmVudExpc3RlbmVyKCJtb3VzZXVwIiwgdXBIYW5sZGVyLCB0cnVlKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGZyYW1lLmFkZEV2ZW50TGlzdGVuZXIoIm1vdXNlZW50ZXIiLCBlID0+IHsKICAgICAgICAgICAgICAgIGlmICghc2VsZi5zaG93U2lnbiB8fCBtb3ZpbmcpIHJldHVybjsKICAgICAgICAgICAgICAgIGlmIChzZWxmLm1haW5TaWduRGl2LnBhcmVudE5vZGUpIHNlbGYubWFpblNpZ25EaXYucGFyZW50Tm9kZS5yZW1vdmVDaGlsZChzZWxmLm1haW5TaWduRGl2KTsKICAgICAgICAgICAgICAgIHNlbGYuY2hlY2tJbnB1dFNlbGVjdG9yKCk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBmcmFtZS5hZGRFdmVudExpc3RlbmVyKCJtb3VzZWxlYXZlIiwgZSA9PiB7CiAgICAgICAgICAgICAgICBpZiAoIXNlbGYuc2hvd1NpZ24pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoc2VsZi5tYWluU2lnbkRpdi5wYXJlbnROb2RlKSBzZWxmLm1haW5TaWduRGl2LnBhcmVudE5vZGUucmVtb3ZlQ2hpbGQoc2VsZi5tYWluU2lnbkRpdik7CiAgICAgICAgICAgICAgICAgICAgc2VsZi5jbGVhclNpZ25zKCk7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKG1vdmluZykgcmV0dXJuOwogICAgICAgICAgICAgICAgZ2V0Qm9keShkb2N1bWVudCkuYXBwZW5kQ2hpbGQoc2VsZi5tYWluU2lnbkRpdik7CiAgICAgICAgICAgICAgICBzZWxmLmNsZWFyU2lnbnMoKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGNoZWNrQnRuLmFkZEV2ZW50TGlzdGVuZXIoImNsaWNrIiwgZSA9PiB7CiAgICAgICAgICAgICAgICBzZWxmLmNoZWNrSW5wdXRTZWxlY3RvcigpOwogICAgICAgICAgICAgICAgaWYgKHRoaXMuc2VsZWN0b3JJbnB1dC52YWx1ZSkgX0dNX3NldENsaXBib2FyZCh0aGlzLnNlbGVjdG9ySW5wdXQudmFsdWUpOwogICAgICAgICAgICAgICAgc2hvd1RpcHMoaTE4bigiY29waWVkIikpOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgeHBhdGguYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIGlmICghc2VsZWN0b3JJbnB1dC52YWx1ZSkgewogICAgICAgICAgICAgICAgICAgIHNlbGYuc2V0U2VsZWN0b3JEaXYoIiIpOwogICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxldCBlbGVtZW50ID0gZ2V0RWxlbWVudChzZWxlY3RvcklucHV0LnZhbHVlLCBkb2N1bWVudCk7CiAgICAgICAgICAgICAgICBsZXQgc2VsZWN0b3IgPSBzZWxmLmdldFNlbGVjdG9yRnJvbUVsZShlbGVtZW50KTsKICAgICAgICAgICAgICAgIHNlbGYuc2V0U2VsZWN0b3JEaXYoc2VsZWN0b3IpOwogICAgICAgICAgICAgICAgc2VsZWN0b3JJbnB1dC52YWx1ZSA9IHNlbGVjdG9yOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgZWRpdEJ0bi5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgcnVsZXNEYXRhLmVkaXRUZW1wID0gc2VsZi5nZXRUZW1wUnVsZSgpOwogICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJydWxlc0RhdGEiLCBydWxlc0RhdGEpOwogICAgICAgICAgICAgICAgX0dNX29wZW5JblRhYihydWxlc0RhdGEuY29uZmlnUGFnZSB8fCBjb25maWdQYWdlWzBdLCB7YWN0aXZlOiB0cnVlfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBlZGl0QnRuLm9uY29udGV4dG1lbnUgPSBlID0+IHsKICAgICAgICAgICAgICAgIGUucHJldmVudERlZmF1bHQoKTsKICAgICAgICAgICAgICAgIF9HTV9vcGVuSW5UYWIocnVsZXNEYXRhLmNvbmZpZ1BhZ2UgfHwgY29uZmlnUGFnZVswXSwge2FjdGl2ZTogdHJ1ZX0pOwogICAgICAgICAgICB9OwogICAgICAgICAgICB0aGlzLmZyYW1lID0gZnJhbWU7CiAgICAgICAgICAgIHRoaXMueHBhdGggPSB4cGF0aDsKICAgICAgICAgICAgdGhpcy5hbGxwYXRoID0gYWxscGF0aDsKICAgICAgICAgICAgdGhpcy5zZWxlY3RvcklucHV0ID0gc2VsZWN0b3JJbnB1dDsKICAgICAgICAgICAgdGhpcy5uZXh0U3dpdGNoQnRuID0gbmV4dFN3aXRjaEJ0bjsKICAgICAgICAgICAgdGhpcy5hdXRvU2Nyb2xsQnRuID0gYXV0b1Njcm9sbEJ0bjsKICAgICAgICAgICAgdGhpcy5sb2FkTm93ID0gbG9hZE5vdzsKICAgICAgICAgICAgdGhpcy50ZW1wUnVsZSA9IHRlbXBSdWxlOwogICAgICAgICAgICB0aGlzLmxvZ29CdG4gPSBsb2dvQnRuOwogICAgICAgICAgICBsZXQgc2V0VGl0bGVUaW1lcjsKICAgICAgICAgICAgdGhpcy5tb3ZlSGFuZGxlciA9IGUgPT4gewogICAgICAgICAgICAgICAgaWYgKCFzZWxmLnNob3dTaWduIHx8IGUudGFyZ2V0ID09PSBkb2N1bWVudCkgcmV0dXJuOwogICAgICAgICAgICAgICAgbGV0IHRhcmdldCA9IHNlbGYuZ2V0VGFyZ2V0KGUudGFyZ2V0KTsKICAgICAgICAgICAgICAgIHNlbGYuYWRqdXN0U2lnbkRpdihzZWxmLm1haW5TaWduRGl2LCB0YXJnZXQpOwogICAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHNldFRpdGxlVGltZXIpOwogICAgICAgICAgICAgICAgc2V0VGl0bGVUaW1lciA9IHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIGlmIChzZWxmLmluUGlja2VyICYmIHRhcmdldC5oYXNBdHRyaWJ1dGVzKCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHRpdGxlID0gdGFyZ2V0Lm5vZGVOYW1lLnRvTG93ZXJDYXNlKCkgKyAiXG4iOwogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGNvbnN0IGF0dHIgb2YgdGFyZ2V0LmF0dHJpYnV0ZXMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRpdGxlICs9IGDjgJAke2F0dHIubmFtZX3jgJEke2F0dHIudmFsdWUgPyAiIOKeoe+4jyAiICsgYXR0ci52YWx1ZSA6ICIifVxuYDsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBnZXRCb2R5KGRvY3VtZW50KS50aXRsZSA9IHRpdGxlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0sIDEwMCk7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIHRoaXMuY2xpY2tIYW5kbGVyID0gZSA9PiB7CiAgICAgICAgICAgICAgICBpZiAoIXNlbGYuc2hvd1NpZ24pIHJldHVybjsKICAgICAgICAgICAgICAgIGlmIChzZWxmLmluUGlja2VyKSB7CiAgICAgICAgICAgICAgICAgICAgZS5zdG9wUHJvcGFnYXRpb24oKTsKICAgICAgICAgICAgICAgICAgICBlLnByZXZlbnREZWZhdWx0KCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZXQgdGFyZ2V0ID0gc2VsZi5nZXRUYXJnZXQoZS50YXJnZXQpOwogICAgICAgICAgICAgICAgbGV0IHNlbGVjdG9yID0gc2VsZi5nZXRTZWxlY3RvckZyb21FbGUodGFyZ2V0KTsKICAgICAgICAgICAgICAgIHNlbGVjdG9ySW5wdXQudmFsdWUgPSBzZWxlY3RvcjsKICAgICAgICAgICAgICAgIHNlbGYuc2V0U2VsZWN0b3JEaXYoc2VsZWN0b3IpOwogICAgICAgICAgICB9OwogICAgICAgIH0KCiAgICAgICAgZ2V0VGVtcFJ1bGUoZGV0YWlsKSB7CiAgICAgICAgICAgIGlmICh0aGlzLnRlbXBSdWxlLnZhbHVlKSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIHRoaXMuZWRpdFRlbXAgPSBKU09OLnBhcnNlKHRoaXMudGVtcFJ1bGUudmFsdWUpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgIHRoaXMuZWRpdFRlbXAgPSBudWxsOwogICAgICAgICAgICAgICAgICAgIGlmIChkZXRhaWwpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHBvcyA9IGUgJiYgZS5tZXNzYWdlICYmIGUubWVzc2FnZS5tYXRjaCgvcG9zaXRpb24gKFxkKykvKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBvcykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zID0gcGFyc2VJbnQocG9zWzFdKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMudGVtcFJ1bGUudmFsdWUgPSB0aGlzLnRlbXBSdWxlLnZhbHVlLnNsaWNlKDAsIHBvcykgKyAi4p6h77iPIiArIHRoaXMudGVtcFJ1bGUudmFsdWVbcG9zXSArICLirIXvuI8iICsgdGhpcy50ZW1wUnVsZS52YWx1ZS5zbGljZShwb3MgKyAxKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCJlcnJvckpzb24iKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBudWxsOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIXRoaXMuZWRpdFRlbXApIHsKICAgICAgICAgICAgICAgIGlmIChydWxlUGFyc2VyLmN1clNpdGVSdWxlLnVybCAmJiAhcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5zaW5nbGVVcmwpIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLmVkaXRUZW1wID0gcnVsZVBhcnNlci5jdXJTaXRlUnVsZTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5lZGl0VGVtcCA9IHsKICAgICAgICAgICAgICAgICAgICAgICAgbmFtZTogZG9jdW1lbnQudGl0bGUsCiAgICAgICAgICAgICAgICAgICAgICAgIHVybDogIl4iICsgKGxvY2F0aW9uLm9yaWdpbiArIGxvY2F0aW9uLnBhdGhuYW1lKS5yZXBsYWNlKC9bXlwvXSokLywgIiIpLnJlcGxhY2UoL15odHRwcz8vLCAiaHR0cHM/IikucmVwbGFjZSgvXC4vZywgIlxcLiIpLAogICAgICAgICAgICAgICAgICAgICAgICBleGFtcGxlOiBsb2NhdGlvbi5ocmVmCiAgICAgICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGRlbGV0ZSB0aGlzLmVkaXRUZW1wLmZyb207CiAgICAgICAgICAgICAgICBkZWxldGUgdGhpcy5lZGl0VGVtcC50eXBlOwogICAgICAgICAgICAgICAgZGVsZXRlIHRoaXMuZWRpdFRlbXAudXBkYXRlZEF0OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0aGlzLnNlbGVjdG9ySW5wdXQudmFsdWUgJiYgdGhpcy50ZW1wUnVsZS5zdHlsZS5kaXNwbGF5ID09ICJub25lIikgewogICAgICAgICAgICAgICAgdGhpcy5lZGl0VGVtcC5wYWdlRWxlbWVudCA9IHRoaXMuc2VsZWN0b3JJbnB1dC52YWx1ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gdGhpcy5lZGl0VGVtcDsKICAgICAgICB9CgogICAgICAgIGdldFRhcmdldChlbGUpIHsKICAgICAgICAgICAgd2hpbGUgKGVsZS5wYXJlbnROb2RlICYmIChlbGUub2Zmc2V0V2lkdGggPT09IDAgfHwgZWxlLm9mZnNldEhlaWdodCA9PT0gMCkpIHsKICAgICAgICAgICAgICAgIGVsZSA9IGVsZS5wYXJlbnROb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBlbGU7CiAgICAgICAgfQoKICAgICAgICBjbG9zZSgpIHsKICAgICAgICAgICAgdGhpcy5jbGVhclNpZ25zKCk7CiAgICAgICAgICAgIGlmICh0aGlzLmZyYW1lLnBhcmVudE5vZGUpIHRoaXMuZnJhbWUucGFyZW50Tm9kZS5yZW1vdmVDaGlsZCh0aGlzLmZyYW1lKTsKICAgICAgICAgICAgaWYgKHRoaXMubWFpblNpZ25EaXYucGF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m5vbmUiKSB0aGlzLnRlbXBSdWxlLnZhbHVlID0gSlNPTi5zdHJpbmdpZnkodGhpcy5nZXRUZW1wUnVsZSgpLCBudWxsLCA0KTsKICAgICAgICB9CgogICAgICAgIHNldFNlbGVjdG9yRGl2KHNlbGVjdG9yKSB7CiAgICAgICAgICAgIHRoaXMuZmlsbFRlbXBSdWxlVGV4dGFyZWEoKTsKICAgICAgICAgICAgbGV0IHNlbGYgPSB0aGlzOwogICAgICAgICAgICB0aGlzLmFsbHBhdGguaW5uZXJIVE1MID0gY3JlYXRlSFRNTCgiIik7CiAgICAgICAgICAgIGlmICghc2VsZWN0b3IpIHJldHVybjsKICAgICAgICAgICAgaWYgKHRoaXMueHBhdGguY2hlY2tlZCkgewogICAgICAgICAgICAgICAgbGV0IHNwYW4gPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJzcGFuIik7CiAgICAgICAgICAgICAgICBzcGFuLmlubmVyVGV4dCA9IHNlbGVjdG9yOwogICAgICAgICAgICAgICAgc3Bhbi5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgICAgIHNlbGYuc2VsZWN0b3JJbnB1dC52YWx1ZSA9IHNlbGVjdG9yOwogICAgICAgICAgICAgICAgICAgIHNlbGYuY2hlY2tJbnB1dFNlbGVjdG9yKCk7CiAgICAgICAgICAgICAgICB9LCB0cnVlKTsKICAgICAgICAgICAgICAgIHRoaXMuYWxscGF0aC5hcHBlbmRDaGlsZChzcGFuKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHNlbGVjdG9yLnNwbGl0KCI+IikuZm9yRWFjaCgoaXRlbSwgaW5kZXgpID0+IHNlbGYuZ2VuZVNlbGVjdG9ySXRlbShpdGVtLCBpbmRleCkpOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBnZW5lU2VsZWN0b3JJdGVtKGl0ZW0sIGluZGV4KSB7CiAgICAgICAgICAgIGxldCBzZWxmID0gdGhpczsKICAgICAgICAgICAgaXRlbSA9IGl0ZW0udHJpbSgpOwogICAgICAgICAgICBpZiAoIWl0ZW0pIHJldHVybjsKICAgICAgICAgICAgaWYgKGluZGV4ICE9PSAwKSB7CiAgICAgICAgICAgICAgICBsZXQgc3BhbiA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInNwYW4iKTsKICAgICAgICAgICAgICAgIHNwYW4uaW5uZXJUZXh0ID0gIiA+ICI7CiAgICAgICAgICAgICAgICB0aGlzLmFsbHBhdGguYXBwZW5kQ2hpbGQoc3Bhbik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbGV0IHNwYW4gPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJzcGFuIik7CiAgICAgICAgICAgIHNwYW4uY2xhc3NOYW1lID0gInBhdGgiOwogICAgICAgICAgICBzcGFuLmlubmVyVGV4dCA9IGl0ZW07CiAgICAgICAgICAgIHNwYW4uYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgICAgIGxldCBzZWxlY3RvciA9ICIiOwogICAgICAgICAgICAgICAgbGV0IHRhcmdldCA9IGUudGFyZ2V0OwogICAgICAgICAgICAgICAgd2hpbGUgKHRhcmdldCkgewogICAgICAgICAgICAgICAgICAgIHNlbGVjdG9yID0gdGFyZ2V0LmlubmVyVGV4dCArIHNlbGVjdG9yOwogICAgICAgICAgICAgICAgICAgIHRhcmdldCA9IHRhcmdldC5wcmV2aW91c0VsZW1lbnRTaWJsaW5nOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc2VsZi5zZWxlY3RvcklucHV0LnZhbHVlID0gc2VsZWN0b3I7CiAgICAgICAgICAgICAgICBzZWxmLmNoZWNrSW5wdXRTZWxlY3RvcigpOwogICAgICAgICAgICB9LCB0cnVlKTsKICAgICAgICAgICAgdGhpcy5hbGxwYXRoLmFwcGVuZENoaWxkKHNwYW4pOwogICAgICAgIH0KCiAgICAgICAgY2hlY2tJbnB1dFNlbGVjdG9yKCkgewogICAgICAgICAgICBsZXQgc2VsZiA9IHRoaXM7CiAgICAgICAgICAgIHRoaXMuY2xlYXJTaWducygpOwogICAgICAgICAgICBpZiAoIXRoaXMuc2VsZWN0b3JJbnB1dC52YWx1ZSkgcmV0dXJuOwogICAgICAgICAgICBsZXQgZWxlcyA9IGdldEFsbEVsZW1lbnRzKHRoaXMuc2VsZWN0b3JJbnB1dC52YWx1ZSwgZG9jdW1lbnQpOwogICAgICAgICAgICBpZiAoZWxlcyAmJiBlbGVzLmxlbmd0aCA+IDApIHsKICAgICAgICAgICAgICAgIGVsZXMuZm9yRWFjaChlbGUgPT4gewogICAgICAgICAgICAgICAgICAgIGxldCBzaWduID0gc2VsZi5jcmVhdGVTaWduRGl2KCk7CiAgICAgICAgICAgICAgICAgICAgZ2V0Qm9keShkb2N1bWVudCkuYXBwZW5kQ2hpbGQoc2lnbik7CiAgICAgICAgICAgICAgICAgICAgc2VsZi5hZGp1c3RTaWduRGl2KHNpZ24sIGVsZSk7CiAgICAgICAgICAgICAgICAgICAgc2VsZi5zaWduTGlzdC5wdXNoKHNpZ24pOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICB0aGlzLmZpbGxUZW1wUnVsZVRleHRhcmVhKCk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGNsZWFyU2lnbnMoKSB7CiAgICAgICAgICAgIHRoaXMuc2lnbkxpc3QuZm9yRWFjaChzaWduID0+IHsKICAgICAgICAgICAgICAgIGlmIChzaWduLnBhcmVudE5vZGUpIHNpZ24ucGFyZW50Tm9kZS5yZW1vdmVDaGlsZChzaWduKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHRoaXMuc2lnbkxpc3QgPSBbXTsKICAgICAgICB9CgogICAgICAgIHN0YXJ0KCkgewogICAgICAgICAgICB0aGlzLmluaXQoKTsKICAgICAgICAgICAgaWYgKHRoaXMuaW5QaWNrZXIpIHJldHVybjsKICAg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XSwKICAgICAgICAgICAgdGVtcGxhdGVzOiBbCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgdGV4dDogJ05ldyBzaXRlJywKICAgICAgICAgICAgICAgICAgICB0aXRsZTogJ0luc2VydCBhIG5ldyBzaXRlJywKICAgICAgICAgICAgICAgICAgICBjbGFzc05hbWU6ICdqc29uZWRpdG9yLXR5cGUtb2JqZWN0JywKICAgICAgICAgICAgICAgICAgICBmaWVsZDogJ1NpdGVUZW1wbGF0ZScsCiAgICAgICAgICAgICAgICAgICAgdmFsdWU6IHsKICAgICAgICAgICAgICAgICAgICAgICAgJ25hbWUnOiAnU2l0ZSBuYW1lJywKICAgICAgICAgICAgICAgICAgICAgICAgJ3VybCc6ICdTaXRlIHVybCcKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIF0sCiAgICAgICAgICAgIHNjaGVtYTogewogICAgICAgICAgICAgICAgInRpdGxlIjogIlNpdGVzIGRhdGEiLAogICAgICAgICAgICAgICAgImRlc2NyaXB0aW9uIjogIk9iamVjdCBjb250YWluaW5nIHNpdGUgY29uZmlnIiwKICAgICAgICAgICAgICAgICJ0eXBlIjogImFycmF5IiwKICAgICAgICAgICAgICAgICJpdGVtcyI6IHsKICAgICAgICAgICAgICAgICAgICAidHlwZSI6ICdvYmplY3QnLAogICAgICAgICAgICAgICAgICAgICJwcm9wZXJ0aWVzIjogewogICAgICAgICAgICAgICAgICAgICAgICAibmFtZSI6IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICJ0aXRsZSI6ICJTaXRlIE5hbWUiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgImRlc2NyaXB0aW9uIjogIlRoZSBzaXRlJ3MgbmFtZS4iLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgImV4YW1wbGVzIjogWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICJHb29nbGUiCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBdLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgInR5cGUiOiAic3RyaW5nIgogICAgICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgICAgICAgICAidXJsIjogewogICAgICAgICAgICAgICAgICAgICAgICAgICAgInRpdGxlIjogIlNpdGUgVXJsIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICJkZXNjcmlwdGlvbiI6ICJUaGUgUmVnZXhwIG9mIHNpdGUncyB1cmwuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICJleGFtcGxlcyI6IFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiXmh0dHBzOlwvXC95YW5kZVxcLnJlXC8iCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBdLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgInR5cGUiOiAic3RyaW5nIgogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICAicmVxdWlyZWQiOiBbIm5hbWUiLCAidXJsIl0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSwKICAgICAgICAgICAgb25DaGFuZ2U6ICgpID0+IHsKICAgICAgICAgICAgICAgIGVkaXRvckNoYW5nZWQgPSB0cnVlOwogICAgICAgICAgICB9CiAgICAgICAgfTsKICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgdmFyIGNvbnRhaW5lciA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJqc29uZWRpdG9yIik7CiAgICAgICAgICAgIGNvbnRhaW5lci5zdHlsZS5oZWlnaHQgPSAnODAwcHgnOwogICAgICAgICAgICBjb250YWluZXIuaW5uZXJIVE1MID0gIiI7CiAgICAgICAgICAgIGVkaXRvciA9IG5ldyBKU09ORWRpdG9yKGNvbnRhaW5lciwgb3B0aW9ucyk7CiAgICAgICAgICAgIGVkaXRvci5zZXQocnVsZVBhcnNlci5jdXN0b21SdWxlcyk7CiAgICAgICAgfSwgNTAwKTsKICAgIH0KCiAgICBmdW5jdGlvbiBjaGVja0d1aWRlUGFnZShocmVmKSB7CiAgICAgICAgaWYgKGd1aWRlUGFnZS50ZXN0KGhyZWYpKSB7CiAgICAgICAgICAgIGlmICh0eXBlb2YgSlNPTkVkaXRvciAhPT0gJ3VuZGVmaW5lZCcpIHsKICAgICAgICAgICAgICAgIGNyZWF0ZUVkaXQoKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGxldCBjaGVja0VkaXRvclJlYWR5ID0gc2V0SW50ZXJ2YWwoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgSlNPTkVkaXRvciAhPT0gJ3VuZGVmaW5lZCcpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY3JlYXRlRWRpdCgpOwogICAgICAgICAgICAgICAgICAgICAgICBjbGVhckludGVydmFsKGNoZWNrRWRpdG9yUmVhZHkpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0sIDEwMCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgW10uZm9yRWFjaC5jYWxsKGdldEJvZHkoZG9jdW1lbnQpLnF1ZXJ5U2VsZWN0b3JBbGwoJ2EnKSwgZWxlID0+IHsKICAgICAgICAgICAgICAgIGVsZS50YXJnZXQgPSAiX2JsYW5rIjsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZmFsc2U7CiAgICB9CgogICAgZnVuY3Rpb24gc3RhcnRBdXRvU2Nyb2xsKCkgewogICAgICAgIGNsZWFySW50ZXJ2YWwoYXV0b1Njcm9sbEludGVydmFsKTsKICAgICAgICBpZiAoYXV0b1Njcm9sbCA8PSAwKSByZXR1cm47CiAgICAgICAgYXV0b1Njcm9sbEludGVydmFsID0gc2V0SW50ZXJ2YWwoKCkgPT4gewogICAgICAgICAgICBpZiAoaXNQYXVzZSkgcmV0dXJuOwogICAgICAgICAgICB3aW5kb3cuc2Nyb2xsKHdpbmRvdy5zY3JvbGxYLCB3aW5kb3cuc2Nyb2xsWSArIDEpOwogICAgICAgIH0sIHBhcnNlSW50KDEwMDAgLyBhdXRvU2Nyb2xsKSk7CiAgICB9CgogICAgdmFyIGluVXBkYXRlID0gZmFsc2U7CiAgICBmdW5jdGlvbiBpbml0Q29uZmlnKGhyZWYpIHsKICAgICAgICBsZXQgaXNHdWlkZVBhZ2UgPSBjaGVja0d1aWRlUGFnZShocmVmKTsKICAgICAgICBpZiAoIWlzR3VpZGVQYWdlKSB7CiAgICAgICAgICAgIGlmIChocmVmLmluZGV4T2YoIlBhZ2V0dWFsR3VpZGUiKSAhPSAtMSkgcmV0dXJuIHRydWU7CiAgICAgICAgICAgIGlmIChsb2NhdGlvbi5ob3N0bmFtZSA9PT0gInBhZ2V0dWFsLmhvb3RoaW4uY29tIikgcmV0dXJuIHRydWU7CiAgICAgICAgfQoKICAgICAgICB2YXIgY29uZmlnQ29uLCBpbnNlcnRQb3MsIGNsaWNrMmltcG9ydCwgaW1wb3J0VXJsUHJlOwoKICAgICAgICBsZXQgaW5Db25maWcgPSBpc0d1aWRlUGFnZTsKICAgICAgICBpZiAoIWluQ29uZmlnKSB7CiAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgY29uZmlnUGFnZS5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgICAgaWYgKGNvbmZpZ1BhZ2VbaV0gPT0gbG9jYXRpb24uaHJlZikgewogICAgICAgICAgICAgICAgICAgIGluQ29uZmlnID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocnVsZUltcG9ydFVybFJlZy50ZXN0KGhyZWYpIHx8IGluQ29uZmlnKSB7CiAgICAgICAgICAgIGxldCBpbXBvcnRpbmcgPSBmYWxzZTsKICAgICAgICAgICAgaWYgKCFpblVwZGF0ZSAmJiBydWxlc0RhdGEudW5pbml0ZWQpIHsKICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIGlmICghaW5VcGRhdGUgJiYgIWltcG9ydGluZykgc2hvd1RpcHMoaTE4bigiZmlyc3RBbGVydCIpKTsKICAgICAgICAgICAgICAgIH0sIDMwMDApOwogICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFpblVwZGF0ZSAmJiAhaW1wb3J0aW5nKSBzaG93VGlwcyhpMThuKCJmaXJzdEFsZXJ0IikpOwogICAgICAgICAgICAgICAgfSwgNjAwMCk7CiAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCJmaXJzdEFsZXJ0IikpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxldCBkZWZhdWx0T3B0aW9uID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvcignI2Rpc2N1c3Npb25fcmF0aW5nXzQnKTsKICAgICAgICAgICAgaWYgKGRlZmF1bHRPcHRpb24pIGRlZmF1bHRPcHRpb24uY2hlY2tlZCA9IHRydWU7CiAgICAgICAgICAgIGxldCBjcmVhdGVJbXBvcnRCdG4gPSAocHJlKSA9PiB7CiAgICAgICAgICAgICAgICBsZXQgaW1wb3J0QnRuID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiYnV0dG9uIik7CiAgICAgICAgICAgICAgICBpbXBvcnRCdG4uaWQgPSAicGFnZXR1YWxJbXBvcnQiOwogICAgICAgICAgICAgICAgaW1wb3J0QnRuLmlubmVyVGV4dCA9IGkxOG4oImltcG9ydCIpOwogICAgICAgICAgICAgICAgaW1wb3J0QnRuLnN0eWxlLm1hcmdpblRvcCA9ICIxMDBweCI7CiAgICAgICAgICAgICAgICBpbXBvcnRCdG4uc3R5bGUuZmxvYXQgPSAicmlnaHQiOwogICAgICAgICAgICAgICAgaW1wb3J0QnRuLnN0eWxlLnBvc2l0aW9uID0gInJlbGF0aXZlIjsKICAgICAgICAgICAgICAgIGltcG9ydEJ0bi5zdHlsZS5kaXNwbGF5ID0gImJsb2NrIjsKICAgICAgICAgICAgICAgIGltcG9ydEJ0bi5zdHlsZS5mb250U2l6ZSA9ICIyMHB4IjsKICAgICAgICAgICAgICAgIGltcG9ydEJ0bi5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgICAgIGxldCBwYXJlbnROb2RlID0gaW1wb3J0QnRuLnBhcmVudE5vZGU7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFwYXJlbnROb2RlKSByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgcGFyZW50Tm9kZS5yZW1vdmVDaGlsZChpbXBvcnRCdG4pOwogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBydWxlcyA9IHBhcmVudE5vZGUuaW5uZXJUZXh0LnRyaW0oKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGlzQ29udGVudCA9IC9bJyJdbmFtZVsnIl0vaS50ZXN0KHJ1bGVzKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzQ29udGVudCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHJ1bGVMaXN0ID0gSlNPTi5wYXJzZShgWyR7cnVsZXN9XWApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaSBpbiBydWxlTGlzdCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBoYXNSdWxlID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHIgPSBydWxlTGlzdFtpXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBqIGluIHJ1bGVQYXJzZXIuY3VzdG9tUnVsZXMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJ1bGVQYXJzZXIuY3VzdG9tUnVsZXNbal0ubmFtZSA9PSByLm5hbWUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuY3VzdG9tUnVsZXNbal0gPSByOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzUnVsZSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIWhhc1J1bGUpIHJ1bGVQYXJzZXIuY3VzdG9tUnVsZXMucHVzaChyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBydWxlUGFyc2VyLmhwUnVsZXMudW5zaGlmdChyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgiY3VzdG9tUnVsZXMiLCBydWxlUGFyc2VyLmN1c3RvbVJ1bGVzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgiaHBSdWxlcyIsIHJ1bGVQYXJzZXIuaHBSdWxlcyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oInNtYXJ0UnVsZXMiLCBbXSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCJpbXBvcnRTdWNjIikpOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcnVsZXMgPSBydWxlcy5zcGxpdCgiXG4iKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkaWZmID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBjID0gMDsgYyA8IHJ1bGVzLmxlbmd0aDsgYysrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHVybEFyciA9IHJ1bGVzW2NdLnNwbGl0KCJ8IiksIHVybCwgdHlwZSA9IDE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHVybEFyci5sZW5ndGggPT0gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1cmwgPSB1cmxBcnJbMF0udHJpbSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIS9eaHR0cC8udGVzdCh1cmwpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCJlcnJvcldyb25nVXJsIikpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICh1cmxBcnIubGVuZ3RoID09IDIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdHlwZSA9IHVybEFyclswXS50cmltKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVybCA9IHVybEFyclsxXS50cmltKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICghL15odHRwLy50ZXN0KHVybCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dUaXBzKGkxOG4oImVycm9yV3JvbmdVcmwiKSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IG1heElkID0gMSwgaGFzVXJsID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFydWxlc0RhdGEudXJscykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBydWxlc0RhdGEudXJscyA9IFtdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhJZCA9IDE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLnVybHMuZm9yRWFjaCh1ID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChtYXhJZCA8IHUuaWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhJZCA9IHUuaWQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAodS51cmwgPT0gdXJsKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzVXJsID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXNVcmwpIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkaWZmID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXJ1bGVzRGF0YS5zb3J0KSBydWxlc0RhdGEuc29ydCA9IFsxXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBydWxlc0RhdGEudXJscy5wdXNoKHtpZDogbWF4SWQgKyAxLCB1cmw6IHVybCwgdHlwZTogdHlwZX0pOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJ1bGVzRGF0YS5zb3J0LnVuc2hpZnQobWF4SWQgKyAxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICghZGlmZikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dUaXBzKGkxOG4oImVycm9yQWxyZWFkeUV4aXN0cyIpKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd1RpcHMoaTE4bigiYmVnaW5VcGRhdGUiKSwgIiIsIDMwMDAwKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdXBkYXRlUnVsZXMoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd1RpcHMoaTE4bigidXBkYXRlU3VjYyIpKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxvY2F0aW9uLnJlbG9hZCgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LCAocnVsZSwgZXJyKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhgVXBkYXRlICR7cnVsZS51cmx9IHJ1bGVzIGZhaWwhYCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhlcnIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LCA1MDApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgicnVsZXNEYXRhIiwgcnVsZXNEYXRhKTsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocnVsZXNEYXRhLnVybHMpIHJ1bGVVcmxzID0gcnVsZVVybHMuY29uY2F0KHJ1bGVzRGF0YS51cmxzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChydWxlc0RhdGEuc29ydCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCB1cmxzID0gW107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLnNvcnQuZm9yRWFjaChpZCA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvciAobGV0IHMgPSAwOyBzIDwgcnVsZVVybHMubGVuZ3RoOyBzKyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpZCA9PSBydWxlVXJsc1tzXS5pZCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVybHMucHVzaChydWxlVXJsc1tzXSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBydWxlVXJscyA9IHVybHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCJiZWdpblVwZGF0ZSIpLCAiIiwgMzAwMDApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgdXBkYXRlUnVsZXMoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dUaXBzKGkxOG4oInVwZGF0ZVN1Y2MiKSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbG9jYXRpb24ucmVsb2FkKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LCAocnVsZSwgZXJyKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd1RpcHMoYFVwZGF0ZSAke3J1bGUudXJsfSBydWxlcyBmYWlsIWApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGVycik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGltcG9ydGluZyA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIF9HTV9ub3RpZmljYXRpb24oZS50b1N0cmluZygpKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIGlmIChwcmUpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgY2xpZW50SGVpZ2h0ID0gMzUgLSBwcmUuY2xpZW50SGVpZ2h0OwogICAgICAgICAgICAgICAgICAgIGlmIChjbGllbnRIZWlnaHQgPiAtMjApIGNsaWVudEhlaWdodCA9IC0yMDsKICAgICAgICAgICAgICAgICAgICBpbXBvcnRCdG4uc3R5bGUubWFyZ2luVG9wID0gYCR7Y2xpZW50SGVpZ2h0fXB4YDsKICAgICAgICAgICAgICAgICAgICBwcmUuYXBwZW5kQ2hpbGQoaW1wb3J0QnRuKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHJldHVybiBpbXBvcnRCdG47CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIFtdLmZvckVhY2guY2FsbChkb2N1bWVudC5xdWVyeVNlbGVjdG9yQWxsKCdwcmVbbmFtZT1wYWdldHVhbF0scHJlW25hbWU9dXNlci1jb250ZW50LXBhZ2V0dWFsXScpLCBwcmUgPT4gewogICAgICAgICAgICAgICAgbGV0IGltcG9ydEJ0biA9IGNyZWF0ZUltcG9ydEJ0bihwcmUpOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgZG9jdW1lbnQuYWRkRXZlbnRMaXN0ZW5lcigibW91c2VvdmVyIiwgZSA9PiB7CiAgICAgICAgICAgICAgICBpZiAoL15QUkUkL2kudGVzdChlLnRhcmdldC5ub2RlTmFtZSkpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgbmFtZUF0dHIgPSBlLnRhcmdldC5nZXRBdHRyaWJ1dGUoIm5hbWUiKTsKICAgICAgICAgICAgICAgICAgICBpZiAobmFtZUF0dHIgPT0gInBhZ2V0dWFsIiB8fCBuYW1lQXR0ciA9PSAidXNlci1jb250ZW50LXBhZ2V0dWFsIikgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZS50YXJnZXQucXVlcnlTZWxlY3RvcignI3BhZ2V0dWFsSW1wb3J0JykpIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGltcG9ydEJ0biA9IGNyZWF0ZUltcG9ydEJ0bihlLnRhcmdldCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9KTsKCiAgICAgICAgICAgIGlmIChpbkNvbmZpZykgewogICAgICAgICAgICAgICAgaWYgKCFpblVwZGF0ZSAmJiBfR01faW5mby5zY3JpcHQgJiYgX0dNX2luZm8uc2NyaXB0LnZlcnNpb24gJiYgX0dNX2luZm8uc2NyaXB0LnZlcnNpb24gIT09ICcxLjAuMCcpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgdmVyc2lvbkVsZSA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJy5tYXJrZG93bi1ib2R5PmgxW2lkXSxhcnRpY2xlPmgxJyk7CiAgICAgICAgICAgICAgICAgICAgbGV0IGxhdGVzdFZlciA9IHZlcnNpb25FbGUgJiYgdmVyc2lvbkVsZS5pbm5lclRleHQubWF0Y2goL1xkW1xkXC5dKy8pWzBdOwogICAgICAgICAgICAgICAgICAgIGlmIChsYXRlc3RWZXIgJiYgbGF0ZXN0VmVyICE9IF9HTV9pbmZvLnNjcmlwdC52ZXJzaW9uKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dUaXBzKGkxOG4oJ291dE9mRGF0ZScpLCAiIiwgMzAwMCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgX0dNX2FkZFN0eWxlKGAKICAgICAgICAgICAgICAgICBwPnNwYW46bnRoLWNoaWxkKDEpLHA+c3BhbjpudGgtY2hpbGQoMikscD5zcGFuOm50aC1jaGlsZCgzKXsKICAgICAgICAgICAgICAgICAgY3Vyc29yOiBwb2ludGVyOwogICAgICAgICAgICAgICAgICB1c2VyLXNlbGVjdDogbm9uZTsKICAgICAgICAgICAgICAgICAgZGlzcGxheTogaW5saW5lLWJsb2NrOwogICAgICAgICAgICAgICAgICBtYXJnaW4tcmlnaHQ6IDVweDsKICAgICAgICAgICAgICAgICAgLW1vei10cmFuc2l0aW9uOmNvbG9yIDAuM3MgZWFzZSwgdHJhbnNmb3JtIDAuM3M7CiAgICAgICAgICAgICAgICAgIC13ZWJraXQtdHJhbnNpdGlvbjpjb2xvciAwLjNzIGVhc2UsIHRyYW5zZm9ybSAwLjNzOwogICAgICAgICAgICAgICAgICB0cmFuc2l0aW9uOmNvbG9yIDAuM3MgZWFzZSwgdHJhbnNmb3JtIDAuM3M7CiAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgIHA+c3BhbjpudGgtY2hpbGQoMSk6aG92ZXIscD5zcGFuOm50aC1jaGlsZCgyKTpob3ZlcixwPnNwYW46bnRoLWNoaWxkKDMpOmhvdmVyewogICAgICAgICAgICAgICAgICBjb2xvcjpyZWQ7CiAgICAgICAgICAgICAgICAgIHRyYW5zZm9ybTogc2NhbGUoMS41KTsKICAgICAgICAgICAgICAgICAgLXdlYmtpdC10cmFuc2Zvcm06IHNjYWxlKDEuNSk7CiAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgIC51cGRhdGVEYXRlewogICAgICAgICAgICAgICAgICBjdXJzb3I6IHBvaW50ZXI7CiAgICAgICAgICAgICAgICAgIHVzZXItc2VsZWN0OiBub25lOwogICAgICAgICAgICAgICAgICAtbW96LXRyYW5zaXRpb246Y29sb3IgMC4zcyBlYXNlLCB0cmFuc2Zvcm0gMC4zczsKICAgICAgICAgICAgICAgICAgLXdlYmtpdC10cmFuc2l0aW9uOmNvbG9yIDAuM3MgZWFzZSwgdHJhbnNmb3JtIDAuM3M7CiAgICAgICAgICAgICAgICAgIHRyYW5zaXRpb246Y29sb3IgMC4zcyBlYXNlLCB0cmFuc2Zvcm0gMC4zczsKICAgICAgICAgICAgICAgICAgdHJhbnNmb3JtLW9yaWdpbjogbGVmdDsKICAgICAgICAgICAgICAgICAgLXdlYmtpdC10cmFuc2Zvcm0tb3JpZ2luOiBsZWZ0OwogICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAudXBkYXRlRGF0ZTpob3ZlcnsKICAgICAgICAgICAgICAgICAgY29sb3I6cmVkOwogICAgICAgICAgICAgICAgICB0cmFuc2Zvcm06IHNjYWxlKDEuMSk7CiAgICAgICAgICAgICAgICAgIC13ZWJraXQtdHJhbnNmb3JtOiBzY2FsZSgxLjEpOwogICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICBpbnB1dFt0eXBlPW51bWJlcl06Oi13ZWJraXQtaW5uZXItc3Bpbi1idXR0b24sCiAgICAgICAgICAgICAgICAgaW5wdXRbdHlwZT1udW1iZXJdOjotd2Via2l0LW91dGVyLXNwaW4tYnV0dG9uIHsKICAgICAgICAgICAgICAgICAgLXdlYmtpdC1hcHBlYXJhbmNlOiBub25lOwogICAgICAgICAgICAgICAgICBtYXJnaW46IDA7CiAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgIGlucHV0W3R5cGU9bnVtYmVyXSB7CiAgICAgICAgICAgICAgICAgIC1tb3otYXBwZWFyYW5jZTp0ZXh0ZmllbGQ7CiAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgIHJlYWN0LWFwcD5kaXY+ZGl2PmRpdj5kaXY+ZGl2PmRpdj5kaXZbdGFiaW5kZXg9IjAiXTpub3QoW2RhdGEtc2VsZWN0b3JdKSB7CiAgICAgICAgICAgICAgICAgIGRpc3BsYXk6IG5vbmU7CiAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgIHRhYmxlIHRkPmgzIHsKICAgICAgICAgICAgICAgICAgbWFyZ2luOiAxNnB4IWltcG9ydGFudDsKICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgI3NhdmVCdG4gewogICAgICAgICAgICAgICAgICB3aWR0aDogMTAwJTsKICAgICAgICAgICAgICAgICAgcG9zaXRpb246IGZpeGVkOwogICAgICAgICAgICAgICAgICB6LWluZGV4OiA5OTk7CiAgICAgICAgICAgICAgICAgIGJvdHRvbTogMHB4OwogICAgICAgICAgICAgICAgICBsZWZ0OiAwcHg7CiAgICAgICAgICAgICAgICAgIGZvbnQtc2l6ZTogeC1sYXJnZTsKICAgICAgICAgICAgICAgICAgb3BhY2l0eTogMC44OwogICAgICAgICAgICAgICAgICBjdXJzb3I6IHBvaW50ZXI7CiAgICAgICAgICAgICAgICAgIC1tb3otdHJhbnNpdGlvbjpvcGFjaXR5IDAuM3MgZWFzZTsKICAgICAgICAgICAgICAgICAgLXdlYmtpdC10cmFuc2l0aW9uOm9wYWNpdHkgMC4zcyBlYXNlOwogICAgICAgICAgICAgICAgICB0cmFuc2l0aW9uOm9wYWNpdHkgMC4zcyBlYXNlOwogICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAjc2F2ZUJ0bjpob3ZlciB7CiAgICAgICAgICAgICAgICAgIG9wYWNpdHk6IDE7CiAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYCk7CiAgICAgICAgICAgICAgICBjbGljazJpbXBvcnQgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCJbbmFtZT0ndXNlci1jb250ZW50LWNsaWNrMmltcG9ydCddLFtuYW1lPSdjbGljazJpbXBvcnQnXSIpOwogICAgICAgICAgICAgICAgaWYgKGNsaWNrMmltcG9ydCkgY2xpY2syaW1wb3J0LmlubmVyVGV4dCA9IGkxOG4oImNsaWNrMkltcG9ydFJ1bGUiKQogICAgICAgICAgICAgICAgY29uZmlnQ29uID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiLm1hcmtkb3duLWJvZHksLnRoZW1lLWRlZmF1bHQtY29udGVudCIpOwogICAgICAgICAgICAgICAgaWYgKCFjb25maWdDb24pIHsKICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgbG9jYXRpb24ucmVsb2FkKCk7CiAgICAgICAgICAgICAgICAgICAgfSwgMTAwMCk7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpbnNlcnRQb3MgPSBjb25maWdDb24ucXVlcnlTZWxlY3RvcigiaHIsI2pzb25lZGl0b3IiKTsKCiAgICAgICAgICAgICAgICBpbXBvcnRVcmxQcmUgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCJwcmVbbmFtZT0ndXNlci1jb250ZW50LXBhZ2V0dWFsJ10scHJlW25hbWU9J3BhZ2V0dWFsJ10iKTsKICAgICAgICAgICAgICAgIGlmICghcnVsZXNEYXRhLnVuaW5pdGVkKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGltcG9ydFVybFByZSkgaW1wb3J0VXJsUHJlLnN0eWxlLmRpc3BsYXkgPSAibm9uZSI7CiAgICAgICAgICAgICAgICAgICAgaWYgKGNsaWNrMmltcG9ydCkgY2xpY2syaW1wb3J0LnN0eWxlLmRpc3BsYXkgPSAibm9uZSI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZXQgb3RoZXJjb25maWcgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCJhW25hbWU9J3VzZXItY29udGVudC1vdGhlcmNvbmZpZyddLGFbbmFtZT0nb3RoZXJjb25maWcnXSIpOwogICAgICAgICAgICAgICAgaWYgKG90aGVyY29uZmlnKSBvdGhlcmNvbmZpZy5wYXJlbnROb2RlLnJlbW92ZUNoaWxkKG90aGVyY29uZmlnKTsKICAgICAgICAgICAgfSBlbHNlIHJldHVybiB0cnVlOwogICAgICAgIH0gZWxzZSByZXR1cm4gZmFsc2U7CiAgICAgICAgY2xhc3MgUnVsZWJhciB7CiAgICAgICAgICAgIGluaXQocnVsZVVybCkgewogICAgICAgICAgICAgICAgbGV0IGlkID0gcnVsZVVybC5pZDsKICAgICAgICAgICAgICAgIHRoaXMucnVsZVVybCA9IHJ1bGVVcmw7CiAgICAgICAgICAgICAgICB0aGlzLml0ZW0gPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJwIik7CiAgICAgICAgICAgICAgICB0aGlzLml0ZW0uZGF0YXNldC5pZCA9IGlkOwogICAgICAgICAgICAgICAgbGV0IHVybCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImEiKTsKICAgICAgICAgICAgICAgIHVybC5ocmVmID0gcnVsZVVybC51cmw7CiAgICAgICAgICAgICAgICB1cmwuaW5uZXJIVE1MID0gcnVsZVVybC51cmw7CiAgICAgICAgICAgICAgICBsZXQgdXAgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJzcGFuIik7CiAgICAgICAgICAgICAgICB1cC5pbm5lckhUTUwgPSAi4oaRICI7CiAgICAgICAgICAgICAgICB1cC50aXRsZSA9IGkxOG4oInNvcnRUaXRsZSIpOwogICAgICAgICAgICAgICAgbGV0IGRvd24gPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJzcGFuIik7CiAgICAgICAgICAgICAgICBkb3duLmlubmVySFRNTCA9ICLihpMgIjsKICAgICAgICAgICAgICAgIGRvd24udGl0bGUgPSBpMThuKCJzb3J0VGl0bGUiKTsKICAgICAgICAgICAgICAgIGxldCBkZWwgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJzcGFuIik7CiAgICAgICAgICAgICAgICBkZWwuaW5uZXJIVE1MID0gIsOXICI7CiAgICAgICAgICAgICAgICB1cC5vbmNsaWNrID0gZSA9PiB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5tb3ZlVXAoKTsKICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICBkb3duLm9uY2xpY2sgPSBlID0+IHsKICAgICAgICAgICAgICAgICAgICB0aGlzLm1vdmVEb3duKCk7CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgZGVsLm9uY2xpY2sgPSBlID0+IHsKICAgICAgICAgICAgICAgICAgICB0aGlzLmRlbCgpOwogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICAgIHRoaXMuaXRlbS5hcHBlbmRDaGlsZCh1cCk7CiAgICAgICAgICAgICAgICB0aGlzLml0ZW0uYXBwZW5kQ2hpbGQoZG93bik7CiAgICAgICAgICAgICAgICB0aGlzLml0ZW0uYXBwZW5kQ2hpbGQoZGVsKTsKICAgICAgICAgICAgICAgIHRoaXMuaXRlbS5hcHBlbmRDaGlsZCh1cmwpOwogICAgICAgICAgICAgICAgaWYgKHJ1bGVQYXJzZXIucnVsZXMpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgcnVsZXNMZW5ndGggPSBydWxlUGFyc2VyLnJ1bGVzLnJlZHVjZSgoYWNjLCBjdXIpID0+IGFjYyArIChjdXIuZnJvbSA9PSBpZCA/IDEgOiAwKSwgMCk7CiAgICAgICAgICAgICAgICAgICAgbGV0IGlkU3BhbiA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInNwYW4iKTsKICAgICAgICAgICAgICAgICAgICBpZFNwYW4uc3R5bGUuZmxvYXQgPSAicmlnaHQiOwogICAgICAgICAgICAgICAgICAgIGlkU3Bhbi5pbm5lckhUTUwgPSBgW3J1bGVzOiAke3J1bGVzTGVuZ3RofV1gOwogICAgICAgICAgICAgICAgICAgIHRoaXMuaXRlbS5hcHBlbmRDaGlsZChpZFNwYW4pOwogICAgICAgICAgICAgICAgICAgIHRoaXMuaWRTcGFuID0gaWRTcGFuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgY29uZmlnQ29uLmluc2VydEJlZm9yZSh0aGlzLml0ZW0sIGluc2VydFBvcyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdXBkYXRlTnVtKCkgewogICAgICAgICAgICAgICAgaWYgKHJ1bGVQYXJzZXIucnVsZXMpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgcnVsZXNMZW5ndGggPSBydWxlUGFyc2VyLnJ1bGVzLnJlZHVjZSgoYWNjLCBjdXIpID0+IGFjYyArIChjdXIuZnJvbSA9PSB0aGlzLml0ZW0uZGF0YXNldC5pZCA/IDEgOiAwKSwgMCk7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5pZFNwYW4uaW5uZXJIVE1MID0gYFtydWxlczogJHtydWxlc0xlbmd0aH1dYDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBzYXZlU29ydCgpIHsKICAgICAgICAgICAgICAgIGxldCBzb3J0ID0gW107CiAgICAgICAgICAgICAgICBbXS5mb3JFYWNoLmNhbGwodGhpcy5pdGVtLnBhcmVudE5vZGUucXVlcnlTZWxlY3RvckFsbCgicFtkYXRhLWlkXSIpLCBpID0+IHsKICAgICAgICAgICAgICAgICAgICBzb3J0LnB1c2goaS5kYXRhc2V0LmlkKTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgcnVsZXNEYXRhLnNvcnQgPSBzb3J0OwogICAgICAgICAgICAgICAgbGV0IHVybHMgPSBbXTsKICAgICAgICAgICAgICAgIHNvcnQuZm9yRWFjaChpZCA9PiB7CiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgcyA9IDA7IHMgPCBydWxlVXJscy5sZW5ndGg7IHMrKykgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaWQgPT0gcnVsZVVybHNbc10uaWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVybHMucHVzaChydWxlVXJsc1tzXSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgcnVsZVVybHMgPSB1cmxzOwogICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJydWxlc0RhdGEiLCBydWxlc0RhdGEpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG1vdmVVcCgpIHsKICAgICAgICAgICAgICAgIGxldCBwcmVFID0gdGhpcy5pdGVtLnByZXZpb3VzRWxlbWVudFNpYmxpbmc7CiAgICAgICAgICAgICAgICBpZiAoL15QJC9pLnRlc3QocHJlRS5ub2RlTmFtZSkgJiYgcHJlRS5jaGlsZHJlbi5sZW5ndGggPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5pdGVtLnBhcmVudE5vZGUuaW5zZXJ0QmVmb3JlKHRoaXMuaXRlbSwgcHJlRSk7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5zYXZlU29ydCgpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIG1vdmVEb3duKCkgewogICAgICAgICAgICAgICAgbGV0IG5leHRFID0gdGhpcy5pdGVtLm5leHRFbGVtZW50U2libGluZzsKICAgICAgICAgICAgICAgIGlmICgvXlAkL2kudGVzdChuZXh0RS5ub2RlTmFtZSkgJiYgbmV4dEUuY2hpbGRyZW4ubGVuZ3RoID4gMSkgewogICAgICAgICAgICAgICAgICAgIHRoaXMuaXRlbS5wYXJlbnROb2RlLmluc2VydEJlZm9yZShuZXh0RSwgdGhpcy5pdGVtKTsKICAgICAgICAgICAgICAgICAgICB0aGlzLnNhdmVTb3J0KCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZGVsKCkgewogICAgICAgICAgICAgICAgaWYgKHRoaXMucnVsZVVybC5pZCA8IDIpIHsKICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCJjYW50RGVsIikpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmICh3aW5kb3cuY29uZmlybShpMThuKCJjb25maXJtRGVsIikpKSB7CiAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgdSA9IDA7IHUgPCBydWxlc0RhdGEudXJscy5sZW5ndGg7IHUrKykgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAodGhpcy5ydWxlVXJsLmlkID09IHJ1bGVzRGF0YS51cmxzW3VdLmlkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBydWxlc0RhdGEudXJscy5zcGxpY2UodSwgMSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCB1ID0gMDsgdSA8IHJ1bGVVcmxzLmxlbmd0aDsgdSsrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLnJ1bGVVcmwuaWQgPT0gcnVsZVVybHNbdV0uaWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJ1bGVVcmxzLnNwbGljZSh1LCAxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGZvciAobGV0IHUgPSAwOyB1IDwgcnVsZXNEYXRhLnNvcnQubGVuZ3RoOyB1KyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMucnVsZVVybC5pZCA9PSBydWxlc0RhdGEuc29ydFt1XSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLnNvcnQuc3BsaWNlKHUsIDEpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJydWxlc0RhdGEiLCBydWxlc0RhdGEpOwogICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIucnVsZXMgPSBydWxlUGFyc2VyLnJ1bGVzLmZpbHRlcihpdGVtID0+IHtyZXR1cm4gaXRlbS5mcm9tICE9IHRoaXMucnVsZVVybC5pZH0pOwogICAgICAgICAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgicnVsZXMiLCBydWxlUGFyc2VyLnJ1bGVzKTsKICAgICAgICAgICAgICAgICAgICB0aGlzLml0ZW0ucGFyZW50Tm9kZS5yZW1vdmVDaGlsZCh0aGlzLml0ZW0pOwogICAgICAgICAgICAgICAgICAgIC8vbG9jYXRpb24ucmVsb2FkKCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbGV0IHVwZGF0ZVAgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJwIiksIGkgPSAwOwogICAgICAgIGxldCBub3cgPSBuZXcgRGF0ZSgpLmdldFRpbWUoKTsKCgogICAgICAgIGxldCBwYXN0RGF0ZSA9IChuZXcgRGF0ZSh1cGRhdGVEYXRlKSkudG9TdHJpbmcoKSwgcGFzc1N0cjsKICAgICAgICBsZXQgcGFzc1RpbWUgPSAobm93IC0gdXBkYXRlRGF0ZSkgLyAxMDAwOwogICAgICAgIGlmIChpc05hTihwYXNzVGltZSkpIHsKICAgICAgICAgICAgcGFzc1N0ciA9IGkxOG4oImZpcnN0VXBkYXRlIik7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaWYgKHBhc3NUaW1lIDwgNjApIHsKICAgICAgICAgICAgICAgIHBhc3NTdHIgPSBpMThuKCJwYXNzU2VjIiwgcGFyc2VJbnQocGFzc1RpbWUpKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChwYXNzVGltZSA8IDYwICogNjApIHsKICAgICAgICAgICAgICAgIHBhc3NTdHIgPSBpMThuKCJwYXNzTWluIiwgcGFyc2VJbnQocGFzc1RpbWUgLyA2MCkpOwogICAgICAgICAgICB9IGVsc2UgaWYgKHBhc3NUaW1lIDwgNjAgKiA2MCAqIDI0KSB7CiAgICAgICAgICAgICAgICBwYXNzU3RyID0gaTE4bigicGFzc0hvdXIiLCBwYXJzZUludChwYXNzVGltZSAvIDM2MDApKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBhc3NTdHIgPSBpMThuKCJwYXNzRGF5IiwgcGFyc2VJbnQocGFzc1RpbWUgLyA4NjQwMCkpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHBhc3NTdHIgKz0gIiDwn5GGICIgKyBpMThuKCJjbGljazJ1cGRhdGUiKTsKICAgICAgICB9CgogICAgICAgIGxldCBydWxlYmFyTGlzdCA9IFtdLCB1cGRhdGVGYWlsID0gZmFsc2U7CiAgICAgICAgdXBkYXRlUC5jbGFzc05hbWUgPSAidXBkYXRlRGF0ZSI7CiAgICAgICAgdXBkYXRlUC5pbm5lckhUTUwgPSBwYXNzU3RyOwogICAgICAgIHVwZGF0ZVAudGl0bGUgPSBpMThuKCJ1cGRhdGUiKSArICIgLSAiICsgcGFzdERhdGU7CiAgICAgICAgY29uZmlnQ29uLmluc2VydEJlZm9yZSh1cGRhdGVQLCBpbnNlcnRQb3MpOwogICAgICAgIGlmIChydWxlVXJscykgewogICAgICAgICAgICBydWxlVXJscy5mb3JFYWNoKHJ1bGVVcmwgPT4gewogICAgICAgICAgICAgICAgbGV0IHJ1bGViYXIgPSBuZXcgUnVsZWJhcigpOwogICAgICAgICAgICAgICAgcnVsZWJhci5pbml0KHJ1bGVVcmwpOwogICAgICAgICAgICAgICAgcnVsZWJhckxpc3QucHVzaChydWxlYmFyKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGxldCBjdXN0b21VcmxzVGl0bGUgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJoMiIpOwogICAgICAgIGN1c3RvbVVybHNUaXRsZS5pbm5lckhUTUwgPSBpMThuKCJjdXN0b21VcmxzIik7CiAgICAgICAgY29uZmlnQ29uLmluc2VydEJlZm9yZShjdXN0b21VcmxzVGl0bGUsIGluc2VydFBvcyk7CiAgICAgICAgbGV0IGN1c3RvbVVybHNJbnB1dCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInRleHRhcmVhIik7CiAgICAgICAgY3VzdG9tVXJsc0lucHV0LnN0eWxlLndpZHRoID0gIjEwMCUiOwogICAgICAgIGN1c3RvbVVybHNJbnB1dC5wbGFjZWhvbGRlciA9ICJodHRwOi8vd2VkYXRhLm5ldC9kYXRhYmFzZXMvQXV0b1BhZ2VyaXplL2l0ZW1zX2FsbC5qc29uIFxuaHR0cHM6Ly9ob290aGluLmdpdGh1Yi5pby9Vc2VyU2NyaXB0cy9QYWdldHVhbC9wYWdldHVhbFJ1bGVzLmpzb24iOwogICAgICAgIGN1c3RvbVVybHNJbnB1dC5zcGVsbGNoZWNrID0gZmFsc2U7CiAgICAgICAgY29uZmlnQ29uLmluc2VydEJlZm9yZShjdXN0b21VcmxzSW5wdXQsIGluc2VydFBvcyk7CgogICAgICAgIGxldCBidG5zID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiZGl2Iik7CiAgICAgICAgYnRucy5zdHlsZS5kaXNwbGF5ID0gImZsZXgiOwogICAgICAgIGNvb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gyIik7CiAgICAgICAgc2lkZUNvbnRyb2xsZXJJY29uVGl0bGUuc3R5bGUud2hpdGVTcGFjZSA9ICJub3dyYXAiOwogICAgICAgIHNpZGVDb250cm9sbGVySWNvblRpdGxlLnN0eWxlLm92ZXJmbG93ID0gImF1dG8iOwogICAgICAgIHNpZGVDb250cm9sbGVySWNvblRpdGxlLmlubmVySFRNTCA9IGkxOG4oInNpZGVDb250cm9sbGVySWNvbiIpOwogICAgICAgIHNpZGVDb250cm9sbGVySWNvbkRpdi5hcHBlbmRDaGlsZChzaWRlQ29udHJvbGxlckljb25UaXRsZSk7CiAgICAgICAgbGV0IHNpZGVDb250cm9sbGVySWNvbklucHV0ID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiaW5wdXQiKTsKICAgICAgICBzaWRlQ29udHJvbGxlckljb25JbnB1dC5zdHlsZS53aWR0aCA9ICIxMDAlIjsKICAgICAgICBzaWRlQ29udHJvbGxlckljb25JbnB1dC5wbGFjZWhvbGRlciA9ICLwn6SNIjsKICAgICAgICBzaWRlQ29udHJvbGxlckljb25JbnB1dC52YWx1ZSA9IHJ1bGVzRGF0YS5zaWRlQ29udHJvbGxlckljb24gfHwgJyc7CiAgICAgICAgc2lkZUNvbnRyb2xsZXJJY29uSW5wdXQuc3BlbGxjaGVjayA9IGZhbHNlOwogICAgICAgIHNpZGVDb250cm9sbGVySWNvbkRpdi5hcHBlbmRDaGlsZChzaWRlQ29udHJvbGxlckljb25JbnB1dCk7CiAgICAgICAgYnRucy5hcHBlbmRDaGlsZChzaWRlQ29udHJvbGxlckljb25EaXYpOwoKICAgICAgICBsZXQgb3RoZXJCdG5zID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiZGl2Iik7CiAgICAgICAgb3RoZXJCdG5zLnN0eWxlLmRpc3BsYXkgPSAiZmxleCI7CiAgICAgICAgY29uZmlnQ29uLmluc2VydEJlZm9yZShvdGhlckJ0bnMsIGluc2VydFBvcyk7CiAgICAgICAgbGV0IGxv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iAgICAgICAgbGV0IGNvbmZpZ1Rib2R5ID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgidGJvZHkiKTsKICAgICAgICBjb25maWdUYm9keS5zdHlsZS53aWR0aCA9ICI5OSUiOwogICAgICAgIGNvbmZpZ1Rib2R5LnN0eWxlLmRpc3BsYXkgPSAiaW5saW5lLXRhYmxlIjsKICAgICAgICBjb25maWdUYWJsZS5hcHBlbmRDaGlsZChjb25maWdUYm9keSk7CiAgICAgICAgY29uZmlnQ29uLmluc2VydEJlZm9yZShjb25maWdUYWJsZSwgaW5zZXJ0UG9zKTsKICAgICAgICBmdW5jdGlvbiBjcmVhdGVDaGVja2JveChpbm5lclRleHQsIHZhbCwgdGFnLCBwYXJlbnRDaGVjaywgb3RoZXJUeXBlKSB7CiAgICAgICAgICAgIGlmICh0eXBlb2YgdmFsID09ICd1bmRlZmluZWQnKSB2YWwgPSAiIjsKICAgICAgICAgICAgbGV0IHRpdGxlID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCh0YWcgfHwgImgzIik7CiAgICAgICAgICAgIHRpdGxlLmlubmVySFRNTCA9IGlubmVyVGV4dDsKICAgICAgICAgICAgdGl0bGUuc3R5bGUub3ZlcmZsb3dXcmFwID0gIm5vcm1hbCI7CiAgICAgICAgICAgIGxldCBpbnB1dCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImlucHV0Iik7CiAgICAgICAgICAgIGlmIChvdGhlclR5cGUgPT09ICdrZXknKSB7CiAgICAgICAgICAgICAgICBpbnB1dC50eXBlID0gJ3RleHQnOwogICAgICAgICAgICAgICAgaW5wdXQuc2V0QXR0cmlidXRlKCdyZWFkT25seScsICdyZWFkb25seScpOwogICAgICAgICAgICAgICAgaW5wdXQuYWRkRXZlbnRMaXN0ZW5lcigia2V5ZG93biIsIGUgPT4gewogICAgICAgICAgICAgICAgICAgIGlmIChlLmtleSA9PT0gJ0VzY2FwZScgfHwgZS5rZXkgPT09ICdCYWNrc3BhY2UnKSBpbnB1dC52YWx1ZSA9ICcnOwogICAgICAgICAgICAgICAgICAgIGVsc2UgaW5wdXQudmFsdWUgPSBlLmtleTsKICAgICAgICAgICAgICAgICAgICBlLnN0b3BQcm9wYWdhdGlvbigpOwogICAgICAgICAgICAgICAgICAgIGUucHJldmVudERlZmF1bHQoKTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgaW5wdXQudHlwZSA9IG90aGVyVHlwZSB8fCAiY2hlY2tib3giOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlucHV0LnN0eWxlLndpZHRoID0gIjMwcHgiOwogICAgICAgICAgICBpbnB1dC5zdHlsZS5oZWlnaHQgPSAiMjBweCI7CiAgICAgICAgICAgIGlucHV0LnN0eWxlLmZsb2F0ID0gImxlZnQiOwogICAgICAgICAgICBpbnB1dC5zdHlsZS5tYXJnaW4gPSAiNXB4IjsKICAgICAgICAgICAgaW5wdXQudmFsdWUgPSB2YWw7CiAgICAgICAgICAgIGlucHV0LmNoZWNrZWQgPSB2YWw7CiAgICAgICAgICAgIGxldCB0ZCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInRkIik7CiAgICAgICAgICAgIHRkLmFwcGVuZENoaWxkKGlucHV0KTsKICAgICAgICAgICAgaWYgKHBhcmVudENoZWNrKSB7CiAgICAgICAgICAgICAgICB0aXRsZS5zdHlsZS5tYXJnaW4gPSAiMCI7CiAgICAgICAgICAgICAgICB0ZC5hcHBlbmRDaGlsZCh0aXRsZSk7CiAgICAgICAgICAgICAgICBsZXQgcGFyZW50ID0gcGFyZW50Q2hlY2sucGFyZW50Tm9kZS5uZXh0RWxlbWVudFNpYmxpbmc7CiAgICAgICAgICAgICAgICBsZXQgdHIgPSBwYXJlbnQucXVlcnlTZWxlY3RvcigidHIiKTsKICAgICAgICAgICAgICAgIGlmICghdHIpIHsKICAgICAgICAgICAgICAgICAgICB0ciA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInRyIik7CiAgICAgICAgICAgICAgICAgICAgcGFyZW50LmFwcGVuZENoaWxkKHRyKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRyLmFwcGVuZENoaWxkKHRkKTsKICAgICAgICAgICAgICAgIGlmICghcGFyZW50Q2hlY2suY2hlY2tlZCkgewogICAgICAgICAgICAgICAgICAgIHRkLnN0eWxlLmRpc3BsYXkgPSAibm9uZSI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwYXJlbnRDaGVjay5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgICAgIHRkLnN0eWxlLmRpc3BsYXkgPSBwYXJlbnRDaGVjay5jaGVja2VkID8gIiIgOiAibm9uZSI7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGxldCB0ciA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInRyIik7CiAgICAgICAgICAgICAgICB0ci5hcHBlbmRDaGlsZCh0ZCk7CiAgICAgICAgICAgICAgICB0ZCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInRkIik7CiAgICAgICAgICAgICAgICB0ZC5hcHBlbmRDaGlsZCh0aXRsZSk7CiAgICAgICAgICAgICAgICB0ci5hcHBlbmRDaGlsZCh0ZCk7CiAgICAgICAgICAgICAgICBjb25maWdUYWJsZS5jaGlsZHJlblswXS5hcHBlbmRDaGlsZCh0cik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbGV0IHhOb2RlUG9zID0gaW5uZXJUZXh0LmluZGV4T2YoJ+OAkFjjgJEnKTsKICAgICAgICAgICAgaWYgKHhOb2RlUG9zICE9PSAtMSkgewogICAgICAgICAgICAgICAgaW5wdXQuc3R5bGUuZmxvYXQgPSAiIjsKICAgICAgICAgICAgICAgIGxldCB4Tm9kZSA9IHRpdGxlLmZpcnN0Q2hpbGQuc3BsaXRUZXh0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uY2xpY2sgPSBlID0+IHsKICAgICAgICAgICAgdXBkYXRlRmFpbCA9IGZhbHNlOwogICAgICAgICAgICBydWxlUGFyc2VyLnJ1bGVzID0gW107CiAgICAgICAgICAgIHNob3dUaXBzKGkxOG4oImJlZ2luVXBkYXRlIiksICIiLCAzMDAwMCk7CiAgICAgICAgICAgIHVwZGF0ZVJ1bGVzKCgpID0+IHsKICAgICAgICAgICAgICAgIGlmICghdXBkYXRlRmFpbCkgewogICAgICAgICAgICAgICAgICAgIHNob3dUaXBzKGkxOG4oInVwZGF0ZVN1Y2MiKSk7CiAgICAgICAgICAgICAgICAgICAgaWYgKGltcG9ydFVybFByZSkgaW1wb3J0VXJsUHJlLnN0eWxlLmRpc3BsYXkgPSAibm9uZSI7CiAgICAgICAgICAgICAgICAgICAgaWYgKGNsaWNrMmltcG9ydCkgY2xpY2syaW1wb3J0LnN0eWxlLmRpc3BsYXkgPSAibm9uZSI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB1cGRhdGVQLmlubmVySFRNTCA9IGkxOG4oInBhc3NTZWMiLCAwKTsKICAgICAgICAgICAgICAgIHVwZGF0ZVAudGl0bGUgPSBpMThuKCJ1cGRhdGUiKTsKICAgICAgICAgICAgICAgIHJ1bGViYXJMaXN0LmZvckVhY2gocnVsZWJhciA9PiB7CiAgICAgICAgICAgICAgICAgICAgcnVsZWJhci51cGRhdGVOdW0oKTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9LCAocnVsZSwgZXJyKSA9PiB7CiAgICAgICAgICAgICAgICBpZiAocnVsZS5pZCA9PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgc2hvd1RpcHMoYFVwZGF0ZSB3ZWRhdGEgcnVsZXMgZmFpbCEgVHJ5IHRvIHN3aXRjaCB0byB3ZWRhdGEgbWlycm9yIWApOwogICAgICAgICAgICAgICAgICAgIHdlZGF0YTJnaXRodWJJbnB1dC5zY3JvbGxJbnRvVmlldygpOwogICAgICAgICAgIC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2VyLmN1c3RvbVJ1bGVzID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yIChsZXQgaSBpbiBydWxlUGFyc2VyLmN1c3RvbVJ1bGVzKSB7CiAgICAgICAgICAgICAgICBpZiAocnVsZVBhcnNlci5jdXN0b21SdWxlc1tpXS51cmwgPT0gcnVsZXNEYXRhLmVkaXRUZW1wLnVybCkgewogICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuY3VzdG9tUnVsZXMuc3BsaWNlKGksIDEpOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJ1bGVQYXJzZXIuY3VzdG9tUnVsZXMudW5zaGlmdChydWxlc0RhdGEuZWRpdFRlbXApOwogICAgICAgICAgICBydWxlc0RhdGEuZWRpdFRlbXAgPSBudWxsOwogICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oInJ1bGVzRGF0YSIsIHJ1bGVzRGF0YSk7CiAgICAgICAgICAgIGN1c3RvbVJ1bGVzSW5wdXQucHJldmlvdXNFbGVtZW50U2libGluZy5zY3JvbGxJbnRvVmlldygpOwogICAgICAgIH0KICAgICAgICBjdXN0b21SdWxlc0lucHV0LnN0eWxlLndpZHRoID0gIjEwMCUiOwogICAgICAgIGN1c3RvbVJ1bGVzSW5wdXQuc3R5bGUuaGVpZ2h0ID0gIjgwMHB4IjsKICAgICAgICBjdXN0b21SdWxlc0lucHV0LnBsYWNlaG9sZGVyID0gYFtcbiAge1xuICAgICJuYW1lIjoieWFuZGUiLFxuICAgICJhY3Rpb24iOiIwIixcbiAgICAidXJsIjoiXmh0dHBzOlwvXC95YW5kZVxcLnJlXC8iLFxuICAgICJwYWdlRWxlbWVudCI6InVsI3Bvc3QtbGlzdC1wb3N0cz5saSIsXG4gICAgIm5leHRMaW5rIjoiYS5uZXh0X3BhZ2UiLFxuICAgICJjc3MiOiIuamF2YXNjcmlwdC1oaWRlIHtkaXNwb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iI7CiAgICAgICAgbGV0IGJsYWNrbGlzdEJ0biA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImJ1dHRvbiIpOwogICAgICAgIGJsYWNrbGlzdEJ0bi5pbm5lclRleHQgPSBpMThuKCJlZGl0QmxhY2tsaXN0Iik7CiAgICAgICAgYmxhY2tsaXN0QnRuLnN0eWxlLndpZHRoID0gIjEwMCUiOwogICAgICAgIGJsYWNrbGlzdEJ0bi5vbmNsaWNrID0gZSA9PiB7CiAgICAgICAgICAgIGJsYWNrbGlzdElucHV0LnN0eWxlLmRpc3BsYXkgPSBibGFja2xpc3RJbnB1dC5zdHlsZS5kaXNwbGF5ID09ICJub25lIiA/ICIiIDogIm5vbmUiOwogICAgICAgIH07CiAgICAgICAgY29uZmlnQ29uLmluc2VydEJlZm9yZShibGFja2xpc3RCdG4sIGluc2VydFBvcyk7CiAgICAgICAgY29uZmlnQ29uLmluc2VydEJlZm9yZShibGFja2xpc3RJbnB1dCwgaW5zZXJ0UG9zKTsKICAgICAgICBsZXQgc2F2ZUJ0biA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImJ1dHRvbiIpOwogICAgICAgIHNhdmVCdG4uaW5uZXJIVE1MID0gaTE4bigic2F2ZSIpOwogICAgICAgIHNhdmVCdG4uaWQgPSAic2F2ZUJ0biI7CiAgICAgICAgY29uZmlnQ29uLmluc2VydEJlZm9yZShzYXZlQnRuLCBpbnNlcnRQb3MpOwogICAgICAgIHNhdmVCdG4ub25jbGljayA9IGUgPT4gewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbGV0IGN1c3RvbVJ1bGVzOwogICAgICAgICAgICAgICAgaWYgKGVkaXRvcikgewogICAgICAgICAgICAgICAgICAgIGlmIChlZGl0b3JDaGFuZ2VkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGVkaXRvckNoYW5nZWQgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJocFJ1bGVzIiwgW10pOwogICAgICAgICAgICAgICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oInNtYXJ0UnVsZXMiLCBbXSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGN1c3RvbVJ1bGVzID0gZWRpdG9yLmdldCgpOwogICAgICAgICAgICAgICAgICAgIGlmICghY3VzdG9tUnVsZXMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY3VzdG9tUnVsZXMgPSAiIjsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoQXJyYXkgJiYgQXJyYXkuaXNBcnJheSAmJiAhQXJyYXkuaXNBcnJheShjdXN0b21SdWxlcykpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dUaXBzKGkxOG4oImVycm9yUnVsZXNNdXN0QmVBcnJheSIpKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGN1c3RvbVJ1bGVzSW5wdXQudmFsdWUgIT0gcHJlQ3VzdG9tKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgiaHBSdWxlcyIsIFtdKTsKICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJzbWFydFJ1bGVzIiwgW10pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoY3VzdG9tUnVsZXNJbnB1dC52YWx1ZSA9PSAiIikgewogICAgICAgICAgICAgICAgICAgICAgICBjdXN0b21SdWxlcyA9ICIiOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGN1c3RvbVJ1bGVzID0gSlNPTi5wYXJzZShjdXN0b21SdWxlc0lucHV0LnZhbHVlKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKEFycmF5ICYmIEFycmF5LmlzQXJyYXkgJiYgIUFycmF5LmlzQXJyYXkoY3VzdG9tUnVsZXMpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCJlcnJvclJ1bGVzTXVzdEJlQXJyYXkiKSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgY3VzdG9tUnVsZXNJbnB1dC52YWx1ZSA9IEpTT04uc3RyaW5naWZ5KGN1c3RvbVJ1bGVzLCBudWxsLCA0KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBkZWJ1ZyhjdXN0b21SdWxlcyk7CiAgICAgICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oImN1c3RvbVJ1bGVzIiwgY3VzdG9tUnVsZXMpOwogICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICAgICAgbGV0IHBvcyA9IGUgJiYgZS5tZXNzYWdlICYmIGUubWVzc2FnZS5tYXRjaCgvcG9zaXRpb24gKFxkKykvKTsKICAgICAgICAgICAgICAgIGlmIChwb3MgJiYgIWVkaXRvcikgewogICAgICAgICAgICAgICAgICAgIHBvcyA9IHBhcnNlSW50KHBvc1sxXSk7CiAgICAgICAgICAgICAgICAgICAgY3VzdG9tUnVsZXNJbnB1dC52YWx1ZSA9IGN1c3RvbVJ1bGVzSW5wdXQudmFsdWUuc2xpY2UoMCwgcG9zKSArICLinqHvuI8iICsgY3VzdG9tUnVsZXNJbnB1dC52YWx1ZVtwb3NdICsgIuKshe+4jyIgKyBjdXN0b21SdWxlc0lucHV0LnZhbHVlLnNsaWNlKHBvcyArIDEpOwogICAgICAgICAgICA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ID0gZGJDbGljazJTdG9wQWx0SW5wdXQuY2hlY2tlZDsKICAgICAgICAgICAgcnVsZXNEYXRhLmRiQ2xpY2syU3RvcFNoaWZ0ID0gZGJDbGljazJTdG9wU2hpZnRJbnB1dC5jaGVja2VkOwogICAgICAgICAgICBydWxlc0RhdGEuZGJDbGljazJTdG9wTWV0YSA9IGRiQ2xpY2syU3RvcE1ldGFJbnB1dC5jaGVja2VkOwogICAgICAgICAgICBydWxlc0RhdGEuZGJDbGljazJTdG9wS2V5ID0gZGJDbGljazJTdG9wS2V5SW5wdXQudmFsdWU7CiAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgicnVsZXNEYXRhIiwgcnVsZXNEYXRhKTsKICAgICAgICAgICAgbGV0IGN1c3RvbVVybHMgPSBjdXN0b21VcmxzSW5wdXQudmFsdWUudHJpbSgpOwogICAgICAgICAgICBpZiAoY3VzdG9tVXJscykgewogICAgICAgICAgICAgICAgY3VzdG9tVXJscyA9IGN1c3RvbVVybHMuc3BsaXQoL1xuLyk7CiAgICAgICAgICAgICAgICBmb3IgKGxldCBjID0gMDsgYyA8IGN1c3RvbVVybHMubGVuZ3RoOyBjKyspIHsKICAgICAgICAgICAgICAgICAgICBsZXQgdXJsOwogICAgICAgICAgICAgICAgICAgIGlmICgvXjBccypcfC8udGVzdChjdXN0b21VcmxzW2NdKSkgewogICAgICAgICAgICAgICAgICAgICAgICB1cmwgPSBjdXN0b21VcmxzW2NdLnJlcGxhY2UoL14wXHMqXHxccyovLCAiIikudHJpbSgpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoIS9eaHR0cC8udGVzdCh1cmwpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCJlcnJvcldyb25nVXJsIikpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgdXJsID0gY3VzdG9tVXJsc1tjXS50cmltKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghL15odHRwLy50ZXN0KHVybCkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dUaXBzKGkxOG4oImVycm9yV3JvbmdVcmwiKSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgbGV0IG1heElkID0gMSwgaGFzVXJsID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFydWxlc0RhdGEudXJscykgewogICAgICAgICAgICAgICAgICAgICAgICBydWxlc0RhdGEudXJscyA9IFtdOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBydWxlVXJscy5mb3JFYWNoKHUgPT4gewogICAgICAgICAgICAgICAgICAgICAgICBpZiAobWF4SWQgPCB1LmlkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhJZCA9IHUuaWQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHUudXJsID09IHVybCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaGFzVXJsID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgIGlmIChoYXNVcmwpIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIGlmICghcnVsZXNEYXRhLnNvcnQpIHJ1bGVzRGF0YS5zb3J0ID0gWzFdOwogICAgICAgICAgICAgICAgICAgIHJ1bGVzRGF0YS51cmxzLnB1c2goe2lkOiBtYXhJZCArIDEsIHVybDogdXJsfSk7CiAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLnNvcnQucHVzaChtYXhJZCArIDEpOwogICAgICAgICAgICAgICA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93KTsKICAgICAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgicnVsZXMiLCBydWxlUGFyc2VyLnJ1bGVzKTsKICAgICAgICAgICAgICAgIGluVXBkYXRlID0gZmFsc2U7CiAgICAgICAgICAgICAgICBpZiAoYWxsT2spIHsKICAgICAgICAgICAgICAgICAgICBydWxlc0RhdGEudW5pbml0ZWQgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oInJ1bGVzRGF0YSIsIHJ1bGVzRGF0YSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdWNjZXNzKCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBsZXQgcnVsZSA9IHJ1bGVVcmxzW3J1bGVJbmRleC0tXTsKICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuYWRkUnVsZUJ5VXJsKHJ1bGUudXJsLCBydWxlLmlkLCAoanNvbiwgZXJyKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFqc29uKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGFsbE9rID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIGZhaWwocnVsZSwgZXJyKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgYWRkTmV4dFJ1bGUoKTsKICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgYWRkTmV4dFJ1bGUoKTsKICAgIH0KCiAgICBmdW5jdGlvbiBvYmpJc0FycihvYmopIHsKICAgICAgICByZXR1cm4gb2JqICYmCiAgICAgICAgICAgIHR5cGVvZiBvYmogPT09ICdvYmplY3QnICYmCiAgICAgICAgICAgIHR5cGVvZiBvYmoubGVuZ3RoID09PSAnbnVtYmVyJyAmJgogICAgICAgICAgICAhKG9iai5wcm9wZXJ0eUlzRW51bWVyYWJsZSgnbGVuZ3RoJykpOwogICAgfQoKICAg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iOwogICAgICAgIHJldHVybiBKU09OLnN0cmluZ2lmeShvYmosIG51bGwsIDQpOwogICAgfQoKICAgIGZ1bmN0aW9uIGdsb2JNYXRjaChmaXJzdCwgc2Vjb25kKSB7CiAgICAgICAgaWYgKGZpcnN0ID09PSAnKicpIHsKICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIGlmIChmaXJzdC5sZW5ndGggPT0gMCAmJiBzZWNvbmQubGVuZ3RoID09IDApewogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CgogICAgICAgIGlmIChmaXJzdC5sZW5ndGggPiAxICYmIGZpcnN0WzBdID09ICcqJyAmJgogICAgICAgICAgICBzZWNvbmQubGVuZ3RoID09IDApewogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQoKICAgICAgICBpZiAoKGZpcnN0Lmxlbmd0aCA+IDEgJiYgZmlyc3RbMF0gPT0gJz8nKSB8fAogICAgICAgICAgICAoZmlyc3QubGVuZ3RoICE9IDAgJiYgc2Vjb25kLmxlbmd0aCAhPSAwICYmCiAgICAgICAgICAgICBmaXJzdFswXSA9PSBzZWNvbmRbMF0pKXsKICAgICAgICAgICAgcmV0dXJuIGdsb2JNYXRjaChmaXJzdC5zdWJzdHJpbmcoMSksCiAgICAgICAgICAgICAgICAgICAgICAgICBzZWNvbmQuc3Vic3RyaW5nKDEpKTsKICAgICAgICB9CgogICAgICAgIGlmIChmaXJzdC5sZW5ndGggPiAwICYmIGZpcnN0WzBdID09ICcqJyl7CiAgICAgICAgICAgIHJldHVybiBnbG9iTWF0Y2goZmlyc3Quc3Vic3RyaW5nKDEpLCBzZWNvbmQpIHx8CiAgICAgICAgICAgICAgICBnbG9iTWF0Y2goZmlyc3QsIHNlY29uZC5zdWJzdHJpbmcoMSkpOwogICAgICAgIH0KCiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQoKICAgIGxldCBwYWdlUmVhZHkgPSBmYWxzZTsKICAgIGZ1bmN0aW9uIGluaXRSdWxlcyhjYWxsYmFjaykgewogICAgICAgIHN0b3JhZ2UuZ2V0SXRlbSgicnVsZXNEYXRhIiwgZGF0YSA9PiB7CiAgICAgICAgICAgIC8qMCB3ZWRhdGHmoLzlvI/vvIwxIHBhZ2V0dWFs5qC85byPKi8KICAgICAgICAgICAgcnVsZVVybHMgPSBbewogICAgICAgICAgICAgICAgaWQ6IDEsCiAgICAgICAgICAgICAgICB1cmw6IGRhdGEgJiYgZGF0YS53ZWRhdGEyZ2l0aHViID8gJ2h0dHBzOi8vaG9vdGhpbi5naXRodWIuaW8vVXNlclNjcmlwdHMvUGFnZXR1YWwvaXRlbXNfYWxsLmpzb24nIDogJ2h0dHA6Ly93ZWRhdGEubmV0L2RhdGFiYXNlcy9BdXRvUGFnZXJpemUvaXRlbXNfYWxsLmpzb24nLAogICAgICAgICAgICAgICAgdHlwZTogMCwKICAgICAgICAgICAgfV07CiAgICAgICAgICAgIGlmIChkYXRhKSB7CiAgICAgICAgICAgICAgICBydWxlc0RhdGEgPSBkYXRhOwogICAgICAgICAgICAgICAgaWYgKGRhdGEudXJscykgcnVsZVVybHMgPSBydWxlVXJscy5jb25jYXQoZGF0YS51cmxzKTsKICAgICAgICAgICAgICAgIGlmIChkYXRhLnNvcnQpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgdXJscyA9IFtdOwogICAgICAgICAgICAgICAgICAgIGRhdGEuc29ydC5mb3JFYWNoKGlkID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgcyA9IDA7IHMgPCBydWxlVXJscy5sZW5ndGg7IHMrKykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlkID09IHJ1bGVVcmxzW3NdLmlkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdXJscy5wdXNoKHJ1bGVVcmxzW3NdKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgIHJ1bGVVcmxzID0gdXJsczsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocnVsZXNEYXRhLmJsYWNrbGlzdCAmJiBydWxlc0RhdGEuYmxhY2tsaXN0Lmxlbmd0aCA+IDApIHsKICAgICAgICAgICAgICAgIGxldCBocmVmID0gbG9jYXRpb24uaHJlZi5zbGljZSgwLCA1MDApOwogICAgICAgICAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBydWxlc0RhdGEuYmxhY2tsaXN0Lmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGN1ckdsb2IgPSBydWxlc0RhdGEuYmxhY2tsaXN0W2ldOwogICAgICAgICAgICAgICAgICAgIGlmICghY3VyR2xvYikgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgaWYgKGN1ckdsb2IuaW5kZXhPZigiLyIpID09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHJlZ01hdGNoID0gY3VyR2xvYi5tYXRjaCgvXlwvKC4qKVwvKFx3KikkLyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyZWdNYXRjaCAmJiBuZXcgUmVnRXhwKHJlZ01hdGNoWzFdLCByZWdNYXRjaFsyXSkudGVzdChocmVmKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yY2VTdGF0ZSA9PSAxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChnbG9iTWF0Y2goY3VyR2xvYiwgaHJlZikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yY2VTdGF0ZSA9PSAxOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJ1bGVQYXJzZXIuaW5pdFNhdmVkUnVsZXMoKCkgPT4gewogICAgICAgICAgICAgICAgbGV0IHVwQnRuSW1nID0gcnVsZXNEYXRhLnVwQnRuSW1nLCBkb3duQnRuSW1nID0gcnVsZXNEYXRhLmRvd25CdG5JbWcsIF9zaWRlQ29udHJvbGxlckljb24gPSBydWxlc0RhdGEuc2lkZUNvbnRyb2xsZXJJY29uOwogICAgICAgICAgICAgICAgaWYgKHVwQnRuSW1nICYmIGRvd25CdG5JbWcpIHsKICAgICAgICAgICAgICAgICAgICBkb3duU3ZnQ1NTID0gZG93blN2Z0NTUy5yZXBsYWNlKCJ0cmFuc2Zvcm06IHJvdGF0ZSgxODBkZWcpOyIsICIiKTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodXBCdG5JbWcgJiYgIWRvd25CdG5JbWcpIHsKICAgICAgICAgICAgICAgICAgICBkb3duQnRuSW1nID0gdXBCdG5JbWc7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYoZG93bkJ0bkltZyAmJiAhdXBCdG5JbWcpIHsKICAgICAgICAgICAgICAgICAgICB1cEJ0bkltZyA9IGRvd25CdG5JbWc7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodXBCdG5JbWcpIHsKICAgICAgICAgICAgICAgICAgICB1cFN2ZyA9IC9odHRwcz86fGRhdGEvLnRlc3QodXBCdG5JbWcpID8gYDxpbWcgY2xhc3M9InBhZ2V0dWFsIiBzcmM9IiR7dXBCdG5JbWd9Ii8+YCA6IGA8c3Bhbj4ke3VwQnRuSW1nfTwvc3Bhbj5gOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGRvd25CdG5JbWcpIHsKICAgICAgICAgICAgICAgICAgICBkb3duU3ZnID0gL2h0dHBzPzp8ZGF0YS8udGVzdChkb3duQnRuSW1nKSA/IGA8aW1nIGNsYXNzPSJwYWdldHVhbCIgc3JjPSIke2Rvd25CdG5JbWd9Ii8+YCA6IGA8c3Bhbj4ke2Rvd25CdG5JbWd9PC9zcGFuPmA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoX3NpZGVDb250cm9sbGVySWNvbikgewogICAgICAgICAgICAgICAgICAgIHNpZGVDb250cm9sbGVySWNvbiA9IC9odHRwcz86fGRhdGEvLnRlc3QoX3NpZGVDb250cm9sbGVySWNvbikgPyBgPGltZyBjbGFzcz0icGFnZXR1YWwiIHNyYz0iJHtfc2lkZUNvbnRyb2xsZXJJY29ufSIvPmAgOiBgPHNwYW4+JHtfc2lkZUNvbnRyb2xsZXJJY29ufTwvc3Bhbj5gOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc2V0TG9hZGluZ0RpdihydWxlc0RhdGEubG9hZGluZ1RleHQgfHwgaTE4bigibG9hZGluZ1RleHQiKSk7CiAgICAgICAgICAgICAgICBpZiAodHlwZW9mKHJ1bGVzRGF0YS5vcGFjaXR5KSA9PSAidW5kZWZpbmVkIikgewogICAgICAgICAgICAgICAgICAgIHJ1bGVzRGF0YS5vcGFjaXR5ID0gMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICh0eXBlb2YocnVsZXNEYXRhLmhpZGVCYXIpID09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLmhpZGVCYXIgPSBmYWxzZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICh0eXBlb2YocnVsZXNEYXRhLmRiQ2xpY2syU3RvcCkgPT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgICAgICBydWxlc0RhdGEuZGJDbGljazJTdG9wID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICh0eXBlb2YocnVsZXNEYXRhLmVuYWJsZVdoaXRlTGlzdCkgPT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgICAgICBydWxlc0RhdGEuZW5hYmxlV2hpdGVMaXN0ID0gZmFsc2U7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodHlwZW9mKHJ1bGVzRGF0YS5lbmFibGVIaXN0b3J5KSA9PSAidW5kZWZpbmVkIikgewogICAgICAgICAgICAgICAgICAgIHJ1bGVzRGF0YS5lbmFibGVIaXN0b3J5ID0gZmFsc2U7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodHlwZW9mKHJ1bGVzRGF0YS5vcGVuSW5OZXdUYWIpID09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLm9wZW5Jbk5ld1RhYiA9IGZhbHNlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHR5cGVvZihydWxlc0RhdGEuZW5hYmxlRGVidWcpID09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLmVuYWJsZURlYnVnID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICh0eXBlb2YocnVsZXNEYXRhLmluaXRSdW4pID09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLmluaXRSdW4gPSB0cnVlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHR5cGVvZihydWxlc0RhdGEucHJlbG9hZCkgPT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgICAgICBydWxlc0RhdGEucHJlbG9hZCA9IHRydWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodHlwZW9mKHJ1bGVzRGF0YS5tYW51YWxNb2RlKSA9PSAidW5kZWZpbmVkIikgewogICAgICAgICAgICAgICAgICAgIHJ1bGVzRGF0YS5tYW51YWxNb2RlID0gZmFsc2U7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodHlwZW9mKHJ1bGVzRGF0YS5jbGlja01vZGUpID09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLmNsaWNrTW9kZSA9IGZhbHNlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHR5cGVvZihydWxlc0RhdGEucGFnZUJhck1lbnUpID09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLnBhZ2VCYXJNZW51ID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICh0eXBlb2YocnVsZXNEYXRhLmFycm93VG9TY3JvbGwpID09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLmFycm93VG9TY3JvbGwgPSBmYWxzZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICh0eXBlb2YocnVsZXNEYXRhLmhpZGVMb2FkaW5nSWNvbikgPT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgICAgICBydWxlc0RhdGEuaGlkZUxvYWRpbmdJY29uID0gZmFsc2U7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodHlwZW9mKHJ1bGVzRGF0YS5oaWRlQmFyQXJyb3cpID09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICAgICAgcnVsZXNEYXRhLmhpZGVCYXJBcnJvdyA9IGZhbHNlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHJ1bGVzRGF0YS5hdXRvTG9hZE51bSAmJiBydWxlc0RhdGEuaW5pdFJ1bikgewogICAgICAgICAgICAgICAgICAgIGF1dG9Mb2FkTnVtID0gcGFyc2VJbnQocnVsZXNEYXRhLmF1dG9Mb2FkTnVtKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG9wZW5Jbk5ld1RhYiA9IHJ1bGVzRGF0YS5vcGVuSW5OZXdUYWIgPyAxIDogMDsKICAgICAgICAgICAgICAgIGVuYWJsZURlYnVnID0gcnVsZXNEYXRhLmVuYWJsZURlYnVnOwogICAgICAgICAgICAgICAgc3RvcmFnZS5nZXRJdGVtKCJuZXh0U3dpdGNoXyIgKyBsb2NhdGlvbi5ob3N0LCBpID0+IHsKICAgICAgICAgICAgICAgICAgICBzdG9yYWdlLmdldEl0ZW0oImZvcmNlU3RhdGVfIiArIGxvY2F0aW9uLmhvc3QsIHYgPT4gewogICAgICAgICAgICAgICAgICAgICAgICBzdG9yYWdlLmdldEl0ZW0oImF1dG9TY3JvbGxfIiArIGxvY2F0aW9uLmhvc3QgKyBsb2NhdGlvbi5wYXRobmFtZSwgX2F1dG9TY3JvbGwgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5nZXRJdGVtKCJydWxlTGFzdFVwZGF0ZSIsIGRhdGUgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGF1dG9TY3JvbGwgPSBfYXV0b1Njcm9sbCB8fCAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0eXBlb2YoaSkgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5leHRJbmRleCA9IGk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0eXBlb2YodikgPT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdiA9IChydWxlc0RhdGEuZW5hYmxlV2hpdGVMaXN0ID8gMSA6IDApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3JjZVN0YXRlID0gdjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1cGRhdGVEYXRlID0gZGF0ZTsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGhyZWYgPSBsb2NhdGlvbi5ocmVmLnNsaWNlKDAsIDEwMCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKF91bnNhZmVXaW5kb3cuaW5pdGVkUGFnZXR1YWwpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChydWxlSW1wb3J0VXJsUmVnLnRlc3QoaHJlZikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCdkdXBsaWNhdGUnKSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX3Vuc2FmZVdpbmRvdy5pbml0ZWRQYWdldHVhbCA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7c2hvd1RpcHMoZSl9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGlzdGVuVXJsKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX0dNX3JlZ2lzdGVyTWVudUNvbW1hbmQoaTE4bigidXBkYXRlIiksICgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd1RpcHMoaTE4bigiYmVnaW5VcGRhdGUiKSwgIiIsIDYwMDAwKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdXBkYXRlUnVsZXMoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd1RpcHMoaTE4bigidXBkYXRlU3VjYyIpKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxvY2F0aW9uLnJlbG9hZCgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LChydWxlLCBlcnIpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dUaXBzKGBVcGRhdGUgJHtydWxlLnVybH0gcnVsZXMgZmFpbCFgKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGVycik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9HTV9yZWdpc3Rlck1lbnVDb21tYW5kKGkxOG4oZm9yY2VTdGF0ZSA9PSAxID8gImVuYWJsZSIgOiAiZGlzYWJsZVNpdGUiKSwgKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3JjZVN0YXRlID0gKGZvcmNlU3RhdGUgPT0gMSA/IDAgOiAxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJmb3JjZVN0YXRlXyIgKyBsb2NhdGlvbi5ob3N0LCBmb3JjZVN0YXRlKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd1RpcHMoaTE4bihmb3JjZVN0YXRlID09IDEgPyAiZGlzYWJsZVNpdGVUaXBzIiA6ICJlbmFibGVTaXRlVGlwcyIpKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFydWxlUGFyc2VyLmN1clNpdGVSdWxlLnVybCkgbG9jYXRpb24ucmVsb2FkKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX0dNX3JlZ2lzdGVyTWVudUNvbW1hbmQoaTE4bigidG9nZ2xlQXV0b1Njcm9sbCIpLCAoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGF1dG9TY3JvbGwgPSAoYXV0b1Njcm9sbCA/IDAgOiBwcm9tcHQoaTE4bigiYXV0b1Njcm9sbFJhdGUiKSwgNTApKSB8fCAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhdXRvU2Nyb2xsID0gcGFyc2VJbnQoYXV0b1Njcm9sbCkgfHwgMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGF1dG9TY3JvbGwgPCAwKSBhdXRvU2Nyb2xsID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSBpZiAoYXV0b1Njcm9sbCA+IDEwMDApIGF1dG9TY3JvbGwgPSAxMDAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oImF1dG9TY3JvbGxfIiArIGxvY2F0aW9uLmhvc3QgKyBsb2NhdGlvbi5wYXRobmFtZSwgYXV0b1Njcm9sbCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXJ0QXV0b1Njcm9sbCgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXJ0QXV0b1Njcm9sbCgpOwoKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGluaXRDb25maWcoaHJlZikpIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYWdlUmVhZHkgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChmb3JjZVN0YXRlID09IDEpIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgbm93ID0gbmV3IERhdGUoKS5nZXRUaW1lKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFkYXRlIHx8IG5vdyAtIGRhdGUgPiAyICogMjQgKiA2MCAqIDYwICogMTAwMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1cGRhdGVSdWxlcygoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0sIChydWxlLCBlcnIpID0+IHt9LCB0cnVlKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJydWxlTGFzdFVwZGF0ZSIsIG5vdyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNhbGxiYWNrKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICB9CgogICAgZnVuY3Rpb24gcmVxdWVzdERvYyh1cmwsIGNhbGxiYWNrKXsKICAgICAgICBsZXQgcG9zdFBhcmFtcyA9IHVybC5tYXRjaCgvI3B7KC4qKX0kLyk7CiAgICAgICAgaWYgKHBvc3RQYXJhbXMpIHsKICAgICAgICAgICAgcG9zdFBhcmFtcyA9IHBvc3RQYXJhbXNbMV07CiAgICAgICAgICAgIHVybCA9IHVybC5yZXBsYWNlKC8jcHsuKi8sICIiKTsKICAgICAgICB9CiAgICAgICAgbGV0IHJ1bGVIZWFkZXJzID0gcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5oZWFkZXJzOwogICAgICAgIGxldCBoZWFkZXJzID0gewogICAgICAgICAgICAnUmVmZXJlcic6IGxvY2F0aW9uLmhyZWYsCiAgICAgICAgICAgICdVc2VyLUFnZW50JzogbmF2aWdhdG9yLnVzZXJBZ2VudCwKICAgICAgICAgICAgJ2FjY2VwdCc6ICd0ZXh0L2h0bWwsYXBwbGljYXRpb24veGh0bWwreG1sLGFwcGxpY2F0aW9uL3htbCcsCiAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAocG9zdFBhcmFtcyA/ICJhcHBsaWNhdGlvbi94LXd3dy1mb3JtLXVybGVuY29kZWQiIDogInRleHQvaHRtbCIpICsgIjtjaGFyc2V0PSIgKyAoZG9jdW1lbnQuY2hhcmFjdGVyU2V0IHx8IGRvY3VtZW50LmNoYXJzZXQgfHwgZG9jdW1lbnQuaW5wdXRFbmNvZGluZyksCiAgICAgICAgfTsKICAgICAgICBpZiAocnVsZUhlYWRlcnMpIHsKICAgICAgICAgICAgaWYgKHJ1bGVIZWFkZXJzLnJlZmVyZXIpIHsKICAgICAgICAgICAgICAgIGhlYWRlcnMucmVmZXJlciA9IHJ1bGVIZWFkZXJzLnJlZmVyZXI7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHJ1bGVIZWFkZXJzLnVzZXJBZ2VudCkgewogICAgICAgICAgICAgICAgaGVhZGVycy51c2VyQWdlbnQgPSBydWxlSGVhZGVycy51c2VyQWdlbnQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHJ1bGVIZWFkZXJzLmFjY2VwdCkgewogICAgICAgICAgICAgICAgaGVhZGVycy5hY2NlcHQgPSBydWxlSGVhZGVycy5hY2NlcHQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHJ1bGVIZWFkZXJzLmNvbnRlbnRUeXBlKSB7CiAgICAgICAgICAgICAgICBoZWFkZXJzLmNvbnRlbnRUeXBlID0gcnVsZUhlYWRlcnMuY29udGVudFR5cGU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHJ1bGVIZWFkZXJzLmNvb2tpZSkgewogICAgICAgICAgICAgICAgaGVhZGVycy5jb29raWUgPSBydWxlSGVhZGVycy5jb29raWU7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgX0dNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgdXJsOiB1cmwsCiAgICAgICAgICAgIG1ldGhvZDogcG9zdFBhcmFtcyA/ICdQT1NUJyA6ICdHRVQnLAogICAgICAgICAgICBkYXRhOiBwb3N0UGFyYW1zLAogICAgICAgICAgICBvdmVycmlkZU1pbWVUeXBlOiAndGV4dC9odG1sO2NoYXJzZXQ9JyArIChkb2N1bWVudC5jaGFyYWN0ZXJTZXQgfHwgZG9jdW1lbnQuY2hhcnNldCB8fCBkb2N1bWVudC5pbnB1dEVuY29kaW5nKSwKICAgICAgICAgICAgaGVhZGVyczogaGVhZGVycywKICAgICAgICAgICAgdGltZW91dDogMjAwMDAsCiAgICAgICAgICAgIG9ubG9hZDogYXN5bmMgZnVuY3Rpb24ocmVzKSB7CiAgICAgICAgICAgICAgICBpZiAoaXNQYXVzZSkgcmV0dXJuIGNhbGxiYWNrKGZhbHNlKTsKICAgICAgICAgICAgICAgIHZhciBkb2MgPSBudWxsLCByZXNwb25zZSA9IHJlcy5yZXNwb25zZTsKICAgICAgICAgICAgICAgIGxldCBwcmVDb2RlID0gcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudFByZSB8fCBydWxlUGFyc2VyLmN1clNpdGVSdWxlLnBhZ2VQcmU7CiAgICAgICAgICAgICAgICBpZiAocHJlQ29kZSkgewogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgX3Vuc2FmZVdpbmRvdy5wYWdldHVhbFBhZ2VQcmUgIT0gJ3VuZGVmaW5lZCcpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3BvbnNlID0gX3Vuc2FmZVdpbmRvdy5wYWdldHVhbFBhZ2VQcmUocmVzcG9uc2UpOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHByZUNvZGUubGVuZ3RoID09IDIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3BvbnNlID0gcmVzcG9uc2UucmVwbGFjZShuZXcgUmVnRXhwKHByZUNvZGVbMF0sICJnaSIpLCBwcmVDb2RlWzFdKTsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3BvbnNlID0gRnVuY3Rpb24oInJlc3BvbnNlIiwnInVzZSBzdHJpY3QiOycgKyBwcmVDb2RlKShyZXNwb25zZSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBkb2MgPSBkb2N1bWVudC5pbXBsZW1lbnRhdGlvbi5jcmVhdGVIVE1MRG9jdW1lbnQoJycpOwogICAgICAgICAgICAgICAgICAgIGRvYy5kb2N1bWVudEVsZW1lbnQuaW5uZXJIVE1MID0gcmVzcG9uc2U7CiAgICAgICAgICAgICAgICAgICAgbGV0IGJhc2UgPSBkb2MucXVlcnlTZWxlY3RvcigiYmFzZSIpOwogICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuYmFzZVBhdGggPSBiYXNlID8gYmFzZS5ocmVmIDogdXJsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICBkZWJ1ZygncGFyc2UgZXJyb3I6JyArIGUudG9TdHJpbmcoKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZXQgcGFnZUVsZW1lbnQgPSBydWxlUGFyc2VyLmdldFBhZ2VFbGVtZW50KGRvYyk7CiAgICAgICAgICAgICAgICBpZiAoKCFwYWdlRWxlbWVudCB8fCBwYWdlRWxlbWVudC5sZW5ndGggPT0gMCkgJiYgcmVzLnN0YXR1cyA+PSA0MDApIHsKICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhyZXMuc3RhdHVzLCAiRXJyb3Igc3RhdHVzIik7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNhbGxiYWNrKGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChpbkNvcnMgJiYgKCFwYWdlRWxlbWVudCB8fCBwYWdlRWxlbWVudC5sZW5ndGggPT0gMCkgJiYgcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5zaW5nbGVVcmwpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgYXJ0aWNsZSA9IGRvYy5xdWVyeVNlbGVjdG9yQWxsKG1haW5TZWwpOwogICAgICAgICAgICAgICAgICAgIGlmIChhcnRpY2xlICYmIGFydGljbGUubGVuZ3RoID09IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgYXJ0aWNsZSA9IGFydGljbGVbMF07CiAgICAgICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQgPSBhcnRpY2xlLm5vZGVOYW1lLnRvTG93ZXJDYXNlKCkgKyAoYXJ0aWNsZS5pZCA/ICIjIiArIGFydGljbGUuaWQgOiAiIikgKyAoYXJ0aWNsZS5jbGFzc05hbWUgPyAiLiIgKyBhcnRpY2xlLmNsYXNzTmFtZS5yZXBsYWNlKC8gL2csICIuIikgOiAiIikgKyAiPioiOwogICAgICAgICAgICAgICAgICAgICAgICBwYWdlRWxlbWVudCA9IGFydGljbGUuY2hpbGRyZW47CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCA9IGFsbE9mQm9keTsKICAgICAgICAgICAgICAgICAgICAgICAgcGFnZUVsZW1lbnQgPSBydWxlUGFyc2VyLmdldFBhZ2VFbGVtZW50KGRvYyk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuZ2V0SW5zZXJ0KHRydWUpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgLy/lj6rmnIkx55qE6Kmx5oCV5LiN5piv5ZyW54mH5ZOmCiAgICAgICAgICAgICAgICBpZiAocGFnZUVsZW1lbnQgJiYgKHBhZ2VFbGVtZW50Lmxlbmd0aCA+IDEgfHwgKHBhZ2VFbGVtZW50Lmxlbmd0aCA9PSAxICYmICEvXklNRyQvaS50ZXN0KHBhZ2VFbGVtZW50WzBdLm5vZGVOYW1lKSkpKSB7CiAgICAgICAgICAgICAgICAgICAgYXdhaXQgcnVsZVBhcnNlci5pbnNlcnRQYWdlKGRvYywgcGFnZUVsZW1lbnQsIHVybCwgY2FsbGJhY2ssIGZhbHNlKTsKICAgICAgICAgICAgICAgICAgICBpZiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5hY3Rpb24gPT0gMSkgewogICAgICAgICAgICAgICAgICAgICAgICBpc0xvYWRpbmcgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICByZXF1ZXN0RnJvbUlmcmFtZSh1cmwsIChkb2MsIGVsZXMpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlbGVzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5pbnNlcnRQYWdlKGRvYywgZWxlcywgdXJsLCBjYWxsYmFjaywgdHJ1ZSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaXNMb2FkaW5nID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmFjdGlvbiA9IDA7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChydWxlUGFyc2VyLmN1clNpdGVSdWxlLnNpbmdsZVVybCB8fCBjdXJQYWdlID09IDEpICYmICFpbkNvcnMpIHsKICAgICAgICAgICAgICAgICAgICBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmFjdGlvbiA9IDE7CiAgICAgICAgICAgICAgICAgICAgcmVxdWVzdEZyb21JZnJhbWUodXJsLCAoZG9jLCBlbGVzKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlbGVzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBydWxlUGFyc2VyLmluc2VydFBhZ2UoZG9jLCBlbGVzLCB1cmwsIGNhbGxiYWNrLCB0cnVlKTsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlzTG9hZGluZyA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBkZWJ1ZygiU3RvcCBhcyBubyBwYWdlIGVsZW1lbnQiKTsKICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKCJub1ZhbGlkQ29udGVudCIpLCB1cmwpOwogICAgICAgICAgICAgICAgICAgIGlzUGF1c2UgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgIGNhbGxiYWNrKGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24oZSkgewogICAgICAgICAgICAgICAgZGVidWcoZSwgIk5ldEVycm9yIik7CiAgICAgICAgICAgICAgICBjYWxsYmFjayhmYWxzZSk7CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIG9udGltZW91dDogZnVuY3Rpb24oZSkgewogICAgICAgICAgICAgICAgZGVidWcoZSwgIk5ldFRpbWVvdXQiKTsKICAgICAgICAgICAgICAgIGNhbGxiYWNrKGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgIH0pOwogICAgfQoKICAgIGZ1bmN0aW9uIGluaXRQYWdlKCkgewogICAgICAgIHJ1bGVQYXJzZXIuaW5pdFBhZ2UoKCkgPT4gewogICAgICAgICAgICBpZiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5hdXRvTG9hZE51bSkgewogICAgICAgICAgICAgICAgYXV0b0xvYWROdW0gPSBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmF1dG9Mb2FkTnVtOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChydWxlUGFyc2VyLmN1clNpdGVSdWxlLm5leHRMaW5rICYmIEFycmF5ICYmIEFycmF5LmlzQXJyYXkgJiYgQXJyYXkuaXNBcnJheShydWxlUGFyc2VyLmN1clNpdGVSdWxlLm5leHRMaW5rKSkgewogICAgICAgICAgICAgICAgX0dNX3JlZ2lzdGVyTWVudUNvbW1hbmQoaTE4bigibmV4dFN3aXRjaCIpLCAoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgbmV4dFN3aXRjaC5zdGFydCgpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHJ1bGVQYXJzZXIubmV4dExpbmtIcmVmKSB7CiAgICAgICAgICAgICAgICBsZXQgaXNKcyA9IC9eKGphdmFzY3JpcHR8IykvLnRlc3QocnVsZVBhcnNlci5uZXh0TGlua0hyZWYucmVwbGFjZShsb2NhdGlvbi5ocmVmLCAiIikpOwogICAgICAgICAgICAgICAgaWYgKCFpc0pzKSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGluRm9yY2UgPSAoZm9yY2VTdGF0ZSA9PSAyIHx8IGZvcmNlU3RhdGUgPT0gMyk7CiAgICAgICAgICAgICAgICAgICAgX0dNX3JlZ2lzdGVyTWVudUNvbW1hbmQoaTE4bihpbkZvcmNlID8gImNhbmNlbEZvcmNlSWZyYW1lIiA6ICJmb3JjZUlmcmFtZSIpLCAoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbkZvcmNlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdG9yYWdlLnNldEl0ZW0oImZvcmNlU3RhdGVfIiArIGxvY2F0aW9uLmhvc3QsICIiKTsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBfc3RhdGUgPSBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmFjdGlvbiA+IDAgfHwgY29uZmlybShpMThuKCJmb3JjZUFsbEJvZHkiKSkgPyAyIDogMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0b3JhZ2Uuc2V0SXRlbSgiZm9yY2VTdGF0ZV8iICsgbG9jYXRpb24uaG9zdCwgX3N0YXRlKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBsb2NhdGlvbi5yZWxvYWQoKTsKICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIF9HTV9yZWdpc3Rlck1lbnVDb21tYW5kKGkxOG4oImxvYWROb3ciKSwgKCkgPT4gewogICAgICAgICAgICAgICAgICAgIGxldCBsb2FkTnVtID0gd2luZG93LnByb21wdChpMThuKCJsb2FkQ29uZmlybSIpLCAiMSIpOwogICAgICAgICAgICAgICAgICAgIGlmIChsb2FkTnVtID09PSAiIiB8fCBsb2FkTnVtID09PSBudWxsKSByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgYXV0b0xvYWROdW0gPSBNYXRoLmFicyhwYXJzZUludChsb2FkTnVtKSk7CiAgICAgICAgICAgICAgICAgICAgbmV4dFBhZ2UoKTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGluaXRMaXN0ZW5lcigpOwogICAgICAgIH0pOwogICAgfQoKICAgIHZhciBwYWdlQmFyU3R5bGUsIG1haW5TdHlsZUVsZSwgbWFpblN0eWxlU3R5bGU7CiAgICBmdW5jdGlvbiBpbml0VmlldygpIHsKICAgICAgICBpZiAoIW1haW5TdHlsZVN0eWxlKSB7CiAgICAgICAgICAgIG1haW5TdHlsZVN0eWxlID0gYAogICAgICAgICAucGFnZXR1YWxfcGFnZUJhcnsKICAgICAgICAgICAtbW96LXRyYW5zaXRpb246YWxsIDAuM3MgZWFzZS1pbi1vdXQgMHM7CiAgICAgICAgICAgLXdlYmtpdC10cmFuc2l0aW9uOmFsbCAwLjNzIGVhc2UtaW4tb3V0IDBzOwogICAgICAgICAgIHRyYW5zaXRpb246YWxsIDAuM3MgZWFzZS1pbi1vdXQgMHM7CiAgICAgICAgICAgZm9udC1mYW1pbHk6IEFyaWFsLHNhbnMtc2VyaWYgIWltcG9ydGFudDsKICAgICAgICAgICB0ZXh0LWFsaWduOiBjZW50ZXIgIWltcG9ydGFudDsKICAgICAgICAgfQogICAgICAgICAucGFnZXR1YWxfcGFnZUJhci5zdG9wIHsKICAgICAgICAgICAtd2Via2l0LWZpbHRlcjogaW52ZXJ0KDEwMCUpOwogICAgICAgICAgIGZpbHRlcjogaW52ZXJ0KDEwMCUpOwogICAgICAgICAgIG9wYWNpdHk6IDEhaW1wb3J0YW50OwogICAgICAgICB9CiAgICAgICAgIC5wYWdldHVhbF9wYWdlQmFyLmhpZGUgewogICAgICAgICAgIGRpc3BsYXk6IG5vbmUhaW1wb3J0YW50OwogICAgICAgICB9CiAgICAgICAgIC5wYWdldHVhbF9wYWdlQmFyOmhvdmVyIHsKICAgICAgICAgICBvcGFjaXR5OiAxIWltcG9ydGFudDsKICAgICAgICAgICBib3gtc2hhZG93OiAwcHggMHB4IDEwcHggMHB4ICMwMDAwMDBhYTsKICAgICAgICAgICBib3JkZXItcmFkaXVzOiAyMHB4OwogICAgICAgICAgIGJhY2tncm91bmQtY29sb3I6IHJnYigyNDAgMjQwIDI0MCAvIDgwJSk7CiAgICAgICAgICAgYm9yZGVyLWNvbG9yOiB0cmFuc3BhcmVudCFpbXBvcnRhbnQ7CiAgICAgICAgIH0KICAgICAgICAgLnBhZ2V0dWFsX3BhZ2VCYXIgc3BhbiB7CiAgICAgICAgICAgdmVydGljYWwtYWxpZ246IHN1cGVyOwogICAgICAgICB9CiAgICAgICAgIC5wYWdldHVhbF9wYWdlQmFyIGE6OmJlZm9yZSwKICAgICAgICAgLnBhZ2V0dWFsX3BhZ2VCYXIgYTo6YWZ0ZXIgewogICAgICAgICAgIGNvbnRlbnQ6IG5vbmU7CiAgICAgICAgIH0KICAgICAgICAgLnBhZ2V0dWFsX3BhZ2VCYXIgYT5zcGFuIHsKICAgICAgICAgICBtYXJnaW4tdG9wOiAwIWltcG9ydGFudDsKICAgICAgICAgICBwb2ludGVyLWV2ZW50czogbm9uZTsKICAgICAgICAgICBwYWRkaW5nOiB1bnNldDsKICAgICAgICAgICBvcGFjaXR5OiAwOwogICAgICAgICAgIC1tb3otdHJhbnNpdGlvbjptYXJnaW4tdG9wIDAuM3MgZWFzZS1pbi1vdXQgMHMsIG9wYWNpdHkgLjNzOwogICAgICAgICAgIC13ZWJraXQtdHJhbnNpdGlvbjptYXJnaW4tdG9wIDAuM3MgZWFzZS1pbi1vdXQgMHMsIG9wYWNpdHkgLjNzOwogICAgICAgICAgIHRyYW5zaXRpb246bWFyZ2luLXRvcCAwLjNzIGVhc2UtaW4tb3V0IDBzLCBvcGFjaXR5IC4zczsKICAgICAgICAgICB0cmFuc2Zvcm06IG5vbmU7CiAgICAgICAgICAgbGVmdDogMDsKICAgICAgICAgICBtYXJnaW4tbGVmdDogY2FsYyg1MCUgLSAyMHB4KTsKICAgICAgICAgfQogICAgICAgICAucGFnZXR1YWxfcGFnZUJhciBhPnNwYW46aG92ZXIgewogICAgICAgICAgIGNvbG9yOiByZWQ7CiAgICAgICAgIH0KICAgICAgICAgLnBhZ2V0dWFsX3BhZ2VCYXIgYTpob3Zlcj5zcGFuIHsKICAgICAgICAgICBvcGFjaXR5OiAxOwogICAgICAgICB9CiAgICAgICAgIC5wYWdldHVhbF9wYWdlQmFyIHNwYW4ucHJldlNjcmVlbiwKICAgICAg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9yaWdpbjogY2VudGVyOwogICAgICAgICAgIC1tb3otdHJhbnNpdGlvbjp0cmFuc2Zvcm0gMC4zcyBlYXNlOwogICAgICAgICAgIC13ZWJraXQtdHJhbnNpdGlvbjp0cmFuc2Zvcm0gMC4zcyBlYXNlOwogICAgICAgICAgIHRyYW5zaXRpb246dHJhbnNmb3JtIDAuMyBlYXNlOwogICAgICAgICB9CiAgICAgICAgIC5wYWdldHVhbF9wYWdlQmFyLnN0b3A6aG92ZXIgc3Bhbj5zdmc+cGF0aHsKICAgICAgICAgICB0cmFuc2Zvcm06IHVuc2V0OwogICAgICAgICB9CiAgICAgICAgIC5wYWdldHVhbF9wYWdlQmFyOmhvdmVyIHNwYW4+c3ZnIHsKICAgICAgICAgICBvcGFjaXR5OiAxOwogICAgICAgICB9CiAgICAgICAgIC5wYWdldHVhbF9wYWdlQmFyIHNwYW4+c3ZnLnVwU3ZnOmhvdmVyIHsKICAgICAgICAgICB0cmFuc2Zvcm06IHJvdGF0ZSgzNjBkZWcpIHNjYWxlM2QoMS4yLCAxLjIsIDEuMik7CiAgICAgICAgIH0KICAgICAgICAgLnBhZ2V0dWFsX3BhZ2VCYXIgc3Bhbj5zdmcuZG93blN2Zzpob3ZlciB7CiAgICAgICAgICAgdHJhbnNmb3JtOiByb3RhdGUoNTQwZGVnKSBzY2FsZTNkKDEuMiwgMS4yLCAxLjIpIWltcG9ydGFudDsKICAgICAgICAgfQogICAgICAgICAucGFnZXR1YWxfcGFnZUJhciAucGFnZXR1YWxfcGFnZU51bXsKICAgICAgICAgICBjb2xvcjogIzU1NTU1ZjsKICAgICAgICAgfQogICAgICAgICAucGFnZXR1YWxfcGFnZUJhciAucGFnZXR1YWxfcGFnZU51bTpob3ZlcnsKICAgICAgICAgICBjb2xvcjogI2ZmNjQ2NDsKICAgICAgICAgfQogICAgICAgICAucGFnZXR1YWxfdGlwc1dvcmRzIHsKICAgICAgICAgICBmb250LXNpemU6IDUwcHg7CiAgICAgICAgICAgZm9udC13ZWlnaHQ6IGJvbGQ7CiAgICAgICAgICAgZm9udC1mYW1pbHk6ICLpu5HkvZMiLCAtYXBwbGUtc3lzdGVtLCBCbGlua01hY1N5c3RlbUZvbnQsICJTZWdvZSBVSSIsICJSb2JvdG8iLAogICAgICAgICAgICAgIk94eWdlbiIsICJVYnVudHUiLCAiSGVsdmV0aWNhIE5ldWUiLCBBcmlhbCwgc2Fucy1zZXJpZiwgIkFwcGxlIENvbG9yIEVtb2ppIiwKICAgICAgICAgICAgICJTZWdvZSBVSSBFbW9qaSIsICJTZWdvZSBVSSBTeW1ib2wiOwogICAgICAgICAgIGNvbG9yOiAjZmZmZmZmOwogICAgICAgICAgIG1pbi1oZWlnaHQ6IDcwcHg7CiAgICAgICAgICAgbWF4LXdpZHRoOiA4MCU7CiAgICAgICAgICAgbGluZS1oZWlnaHQ6IDcwcHg7CiAgICAgICAgICAgcG9zaXRpb246IGZpeGVkOwogICAgICAgICAgIGxlZnQ6IDUwJTsKICAgICAgICAgICB0b3A6IDEwJTsKICAgICAgICAgICBtYXJnaW4tbGVmdDogLTk5OTk5cHg7CiAgICAgICAgICAgcGFkZGluZzogMCAxNXB4OwogICAgICAgICAgIHotaW5kZXg6IDIxNDc0ODM2NDc7CiAgICAgICAgICAgYmFja2dyb3VuZC1jb2xvcjogIzAwMDsKICAgICAgICAgICBib3JkZXI6IDFweCBzb2xpZCAjMzAzMDMwOwogICAgICAgICAgIGJvcmRlci1yYWRpdXM6IDEwcHg7CiAgICAgICAgICAgb3BhY2l0eTogMDsKICAgICAgICAgICBmaWx0ZXI6IGFscGhhKG9wYWNpdHk9NjUpOwogICAgICAgICAgIGJveC1zaGFkb3c6IDVweCA1cHggMjBweCAwcHggIzAwMDsKICAgICAgICAgICAtbW96LXRyYW5zaXRpb246b3BhY2l0eSAwLjNzIGVhc2UtaW4tb3V0IDBzOwogICAgICAgICAgIC13ZWJraXQtdHJhbnNpdGlvbjpvcGFjaXR5IDAuM3MgZWFzZS1pbi1vdXQgMHM7CiAgICAgICAgICAgdHJhbnNpdGlvbjpvcGFjaXR5IDAuM3MgZWFzZS1pbi1vdXQgMHM7CiAgICAgICAgICAgcG9pbnRlci1ldmVudHM6IG5vbmU7CiAgICAgICAgIH0KICAgICAgICAgLnBhZ2V0dWFsX3RpcHNXb3Jkcz5hIHsKICAgICAgICAgICBjb2xvcjogI2ZmZmZmZjsKICAgICAgICAgfQogICAgICAgICAucGFnZXR1YWxfbG9hZGluZyB7CiAgICAgICAgICAgd2lkdGg6IDUwcHg7CiAgICAgICAgICAgaGVpZ2h0OiA1MHB4OwogICAgICAgICAgIG1hcmdpbjogMTBweCBhdXRvOwogICAgICAgICAgIGJvcmRlci1yYWRpdXM6IDEwMCU7CiAgICAgICAgICAgZGlzcGxheTogZmxleDsKICAgICAgICAgICAtd2Via2l0LWFuaW1hdGlvbjogcGFnZXR1YWxfbG9hZGluZ19zY2FsZW91dCAxLjBzIGluZmluaXRlIGVhc2UtaW4tb3V0OwogICAgICAgICAgIGFuaW1hdGlvbjogcGFnZXR1YWxfbG9hZGluZ19zY2FsZW91dCAxLjBzIGluZmluaXRlIGVhc2UtaW4tb3V0OwogICAgICAgICB9CiAgICAgICAgIEAtd2Via2l0LWtleWZyYW1lcyBwYWdldHVhbF9sb2FkaW5nX3NjYWxlb3V0IHsKICAgICAgICAgICAwJSB7IC13ZWJraXQtdHJhbnNmb3JtOiBzY2FsZSgwLjApIH0KICAgICAgICAgICAxMDAlIHsKICAgICAgICAgICAgIC13ZWJraXQtdHJhbnNmb3JtOiBzY2FsZSgxLjApOwogICAgICAgICAgICAgb3BhY2l0eTogMDsKICAgICAgICAgICB9CiAgICAgICAgIH0KICAgICAgICAgQGtleWZyYW1lcyBwYWdldHVhbF9sb2FkaW5nX3NjYWxlb3V0IHsKICAgICAgICAgICAwJSB7CiAgICAgICAgICAgICB0cmFuc2Zvcm06IHNjYWxlKDAuMCk7CiAgICAgICAgICAgICAtd2Via2l0LXRyYW5zZm9ybTogc2NhbGUoMC4wKTsKICAgICAgICAgICB9IDEwMCUgewogICAgICAgICAgICAgdHJhbnNmb3JtOiBzY2FsZSgxLjApOwogICAgICAgICAgICAgLXdlYmtpdC10cmFuc2Zvcm06IHNjYWxlKDEuMCk7CiAgICAgICAgICAgICBvcGFjaXR5OiAwOwogICAgICAgICAgIH0KICAgICAgICAgfQogICAgICAgICAucGFnZXR1YWxfbG9hZGluZ190ZXh0IHsKICAgICAgICAgICB3aGl0ZS1zcGFjZTogbm93cmFwOwogICAgICAgICAgIC13ZWJraXQtYW5pbWF0aW9uOiBwYWdldHVhbF9sb2FkaW5nX29wYWNpdHkgMi42cyBpbmZpbml0ZSBlYXNlLWluLW91dDsKICAgICAgICAgICBhbmltYXRpb246IHBhZ2V0dWFsX2xvYWRpbmdfb3BhY2l0eSAyLjZzIGluZmluaXRlIGVhc2UtaW4tb3V0OwogICAgICAgICB9CiAgICAgICAgIEAtd2Via2l0LWtleWZyYW1lcyBwYWdldHVhbF9sb2FkaW5nX29wYWNpdHkgewogICAgICAgICAgIDAlIHsgb3BhY2l0eTogMSB9CiAgICAgICAgICAgNTAlIHsgb3BhY2l0eTogMC4yIH0KICAgICAgICAgICAxMDAlIHsgb3BhY2l0eTogMSB9CiAgICAgICAgIH0KICAgICAgICAgQGtleWZyYW1lcyBwYWdldHVhbF9sb2FkaW5nX29wYWNpdHkgewogICAgICAgICAgIDAlIHsgb3BhY2l0eTogMSB9CiAgICAgICAgICAgNTAlIHsgb3BhY2l0eTogMC4yIH0KICAgICAgICAgICAxMDAlIHsgb3BhY2l0eTogMSB9CiAgICAgICAgIH0KICAgICAgICBgOwogICAgICAgICAgICBsZXQgYm9keUNvbG9yCiAgICAgICAgICAgIHBhZ2VCYXJTdHlsZSA9IGBvdmVyZmxvdzogdmlzaWJsZTt0ZXh0LWluZGVudDogaW5pdGlhbDt2ZXJ0aWNhbC1hbGlnbjogc3VwZXI7bGluZS1oZWlnaHQ6MTtvcGFjaXR5OiR7cnVsZXNEYXRhLm9wYWNp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GFzc0xpc3QuYWRkKCJzdG9wIik7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBiYXIuY2xhc3NMaXN0LnJlbW92ZSgic3RvcCIpOwogICAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICB9CgogICAgZnVuY3Rpb24gY2hhbmdlSGlkZUJhcihoaWRlKSB7CiAgICAgICAgaXNIaWRlQmFyID0gaGlkZTsKICAgICAgICBbXS5mb3JFYWNoLmNhbGwoZ2V0Qm9keShkb2N1bWVudCkucXVlcnlTZWxlY3RvckFsbCgiLnBhZ2V0dWFsX3BhZ2VCYXIiKSwgYmFyID0+IHsKICAgICAgICAgICAgaWYgKGlzSGlkZUJhcikgewogICAgICAgICAgICAgICAgYmFyLmNsYXNzTGlzdC5hZGQoImhpZGUiKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGJhci5jbGFzc0xpc3QucmVtb3ZlKCJoaWRlIik7CiAgICAgICAgICAgIH0KICAgICAgICB9KTsKICAgIH0KCiAgICBmdW5jdGlvbsKgaXNJblZpZXdQb3J0KGVsZW1lbnQpwqB7CiAgICAgICAgaWYgKCFnZXRCb2R5KGRvY3VtZW50KS5jb250YWlucyhlbGVtZW50KSkgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmIChfdW5zYWZlV2luZG93LmdldENvbXB1dGVkU3R5bGUoZWxlbWVudCkuZGlzcGxheSA9PSAibm9uZSIpIHJldHVybiBmYWxzZTsKICAgICAgICBjb25zdMKgdmlld1dpZHRowqA9wqB3aW5kb3cuaW5uZXJXaWR0aMKgfHzCoGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5jbGllbnRXaWR0aDsKICAgICAgICBjb25zdMKgdmlld0hlaWdodMKgPcKgd2luZG93LmlubmVySGVpZ2h0wqB8fMKgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LmNsaWVudEhlaWdodDsKICAgICAgICBjb25zdMKgewogICAgICAgICAgICB0b3AsCiAgICAgICAgICAgIHJpZ2h0LAogICAgICAgICAgICBib3R0b20sCiAgICAgICAgICAgIGxlZnQsCiAgICAgICAgfcKgPcKgZWxlbWVudC5nZXRCb3VuZGluZ0NsaWVudFJlY3QoKTsKCiAgICAgICAgcmV0dXJuwqAoCiAgICAgICAgICAgIHRvcMKgPj3CoDDCoCYmCiAgICAgICAgICAgIGxlZnTCoD49wqAwwqAmJgogICAgICAgICAgICByaWdodMKgPD3CoHZpZXdXaWR0aCArIDHCoCYmCiAgICAgICAgICAgIHRvcMKgPD3CoHZpZXdIZWlnaHQgKiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5yYXRlIHx8IHJ1bGVzRGF0YS5yYXRlIHx8IDEpCiAgICAgICAgKTsKICAgIH0KCiAgICBmdW5jdGlvbiBnZXRQYWdlQmFyKCkgewogICAgICAgIGxldCBwcmVCYXIgPSBudWxsLCBuZXh0QmFyID0gbnVsbDsKICAgICAgICBsZXQgcGFnZUJhcnMgPSBbXS5zbGljZS5jYWxsKGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3JBbGwoIi5wYWdldHVhbF9wYWdlQmFyIikpOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgcGFnZUJhcnMubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgbGV0IHBhZ2VCYXIgPSBwYWdlQmFyc1tpXTsKICAgICAgICAgICAgaWYgKCFwYWdlQmFyIHx8ICFnZXRCb2R5KGRvY3VtZW50KS5jb250YWlucyhwYWdlQmFyKSkgY29udGludWU7CiAgICAgICAgICAgIGxldMKgewogICAgICAgICAgICAgICAgdG9wLAogICAgICAgICAgICAgICAgcmlnaHQsCiAgICAgICAgICAgICAgICBib3R0b20sCiAgICAgICAgICAgICAgICBsZWZ0LAogICAgICAgICAgICB9wqA9wqBwYWdlQmFyLmdldEJvdW5kaW5nQ2xpZW50UmVjdCgpOwogICAgICAgICAgICBpZiAodG9wID4gNTAwKSB7CiAgICAgICAgICAgICAgICBuZXh0QmFyID0gcGFnZUJhcjsKICAgICAgICAgICAgICAgIHByZUJhciA9IChpIC0gMSA+PSAwID8gcGFnZUJhcnNbaSAtIDFdIDogbnVsbCk7CiAgICAgICAgICAgICAgICBpZiAocGFnZUJhciAmJiBnZXRCb2R5KGRvY3VtZW50KS5jb250YWlucyhwYWdlQmFyKSkgewogICAgICAgICAgICAgICAgICAgIGxldMKgewogICAgICAgICAgICAgICAgICAgICAgICB0b3AsCiAgICAgICAgICAgICAgICAgICAgICAgIHJpZ2h0LAogICAgICAgICAgICAgICAgICAgICAgICBib3R0b20sCiAgICAgICAgICAgICAgICAgICAgICAgIGxlZnQsCiAgICAgICAgICAgICAgICAgICAgfcKgPcKgcGFnZUJhci5nZXRCb3VuZGluZ0NsaWVudFJlY3QoKTsKICAgICAgICAgICAgICAgICAgICBpZiAodG9wIDwgLTUwMCkgewogICAgICAgICAgICAgICAgICAgICAgICBwcmVCYXIgPSBwYWdlQmFyOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBwcmVCYXIgPSAoaSAtIDIgPj0gMCA/IHBhZ2VCYXJzW2kgLSAyXSA6IG51bGwpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKCFuZXh0QmFyKSBwcmVCYXIgPSBwYWdlQmFyc1twYWdlQmFycy5sZW5ndGggLSAyXTsKICAgICAgICByZXR1cm4ge3ByZUJhcjogcHJlQmFyLCBuZXh0QmFyOiBuZXh0QmFyfTsKICAgIH0KCiAgICB2YXIgdXJsQ2hhbmdlZCA9IGZhbHNlOwogICAgdmFyIHVybGNoYW5nZUhhbmRsZXIgPSBlID0+IHsKICAgICAgICBpZiAocnVsZVBhcnNlciAmJiBydWxlUGFyc2VyLmN1clNpdGVSdWxlICYmIHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUubGlzdGVuVXJsQ2hhbmdlID09IGZhbHNlKSByZXR1cm47CiAgICAgICAgaXNQYXVzZSA9IHRydWU7CiAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgIGxhc3RBY3RpdmVVcmwgPSBsb2NhdGlvbi5ocmVmOwogICAgICAgICAgICBsZXQgaHJlZiA9IGxvY2F0aW9uLmhyZWYuc2xpY2UoMCwgNjApOwogICAgICAgICAgICBpZiAoaHJlZiA9PSBjb25maWdQYWdlWzBdKSB7CiAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICBpbml0Q29uZmlnKGhyZWYpOwogICAgICAgICAgICAgICAgfSwgMTAwMCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICBpZiAoZ3VpZGVQYWdlLnRlc3QoaHJlZikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbml0Q29uZmlnKGhyZWYpOwogICAgICAgICAgICAgICAgICAgICAgICB9LCAxMDAwKTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICB1cmxDaGFuZ2VkID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFydWxlUGFyc2VyLm5leHRMaW5rSHJlZikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaXNMb2FkaW5nID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgLy9pZiAoIXBhZ2VSZWFkeSAmJiAhcnVsZUltcG9ydFVybFJlZy50ZXN0KGhyZWYpKSBsb2NhdGlvbi5yZWxvYWQoKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9LCA1MDApOwogICAgICAgICAgICB9CiAgICAgICAgfSwgMSk7CiAgICB9OwogICAgd2luZG93LmFkZE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1VybFRpbWUpOwogICAgICAgICAgICBpZiAoZG9jdW1lbnQuaGlkZGVuKSByZXR1cm47CiAgICAgICAgICAgIGxldCB1cmwgPSB3aW5kb3cubG9jYXRpb24ucGF0aG5hbWUgKyB3aW5kb3cubG9jYXRpb24uc2VhcmNoOwogICAgICAgICAgICBpZiAocHJldlN0YXRlICE9PSB1cmwgJiYgd2luZG93LmxvY2F0aW9uLmhyZWYgIT0gcnVsZVBhcnNlci5oaXN0b3J5VXJsKSB7CiAgICAgICAgICAgICAgICBjaGVja1VybFRpbWUgPSAyMDAwOwogICAgICAgICAgICAgICAgcHJldlN0YXRlID0gdXJsOwogICAgICAgICAgICAgICAgdmFyIGUgPSBuZXcgRXZlbnQoJ3BhZ2V0dWFsX3B1c2hTdGF0ZScpOwogICAgICAgICAgICAgICAgZS5hcmd1bWVudHMgPSBhcmd1bWVudHM7CiAgICAgICAgICAgICAgICB3aW5kb3cuZGlzcGF0Y2hFdmVudChlKTsKICAgICAgICAgICAgfQogICAgICAgIH07CiAgICAgICAgY2hlY2tVcmxUaW1lciA9IHNldFRpbWVvdXQoY2hlY2tGdW5jLCBjaGVja1VybFRpbWUpOwoKICAgICAgICBkb2N1bWVudC5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICBjaGVja1VybFRpbWUgPSAxMDA7CiAgICAgICAgICAgIGNsZWFyVGltZW91dChjaGVja1VybFRpbWVyKTsKICAgICAgICAgICAgY2hlY2tVcmxUaW1lciA9IHNldFRpbWVvdXQoY2hlY2tGdW5jLCBjaGVja1VybFRpbWUpOwogICAgICAgIH0pOwogICAgfQoKICAgIGZ1bmN0aW9uIGRpc3RUb0JvdHRvbSAoKSB7CiAgICAgICAgbGV0IHNjcm9sbHkgPSB3aW5kb3cuc2Nyb2xsWTsKICAgICAgICBsZXQgd2luZG93SGVpZ2h0ID0gd2luZG93LmlubmVySGVpZ2h0IHx8IGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5jbGll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vZGVLZXlIYW5kbGVyKTsKICAgICAgICBkb2N1bWVudC5yZW1vdmVFdmVudExpc3RlbmVyKCdwYWdldHVhbC5uZXh0JywgcGFnZXR1YWxOZXh0SGFuZGxlciwgZmFsc2UpOwogICAgICAgIGRvY3VtZW50LnJlbW92ZUV2ZW50TGlzdGVuZXIoJ2tleXVwJywga2V5dXBIYW5kbGVyKTsKICAgICAgICBsZXQgbG9hZG1vcmVCdG4sIGxvYWRpbmdNb3JlID0gdHJ1ZSwgbGFzdFNjcm9sbCA9IDAsIGNoZWNrTG9hZE1vcmVUaW1lcyA9IDA7CiAgICAgICAgaWYgKCFydWxlUGFyc2VyLmN1clNpdGVSdWxlLnNpbmdsZVVybCkgewogICAgICAgICAgICBpZiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5sb2FkTW9yZSkgewogICAgICAgICAgICAgICAgbG9hZGluZ01vcmUgPSBmYWxzZTsKICAgICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNoZWNrTG9hZE1vcmUgPSBzZXRJbnRlcnZhbCgoKSA9PiB7CiAgICAgICAgICAgICAgICBsb2FkbW9yZUJ0biA9IGdldExvYWRNb3JlKGRvY3VtZW50KTsKICAgICAgICAgICAgICAgIGlmIChsb2FkbW9yZUJ0biAmJiBpc1Zpc2libGUobG9hZG1vcmVCdG4sIF91bnNhZmVXaW5kb3cpKSB7CiAgICAgICAgICAgICAgICAgICAgbG9hZGluZ01vcmUgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICBpZiAoaXNJblZpZXdQb3J0KGxvYWRtb3JlQnRuKSkgewogICAgICAgICAgICAgICAgICAgICAgICBlbXVDbGljayhsb2FkbW9yZUJ0bik7CiAgICAgICAgICAgICAgICAgICAgICAgIGxvYWRpbmdNb3JlID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7bG9hZGluZ01vcmUgPSBmYWxzZX0sIDIwMCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGNsZWFySW50ZXJ2YWwoY2hlY2tMb2FkTW9yZSk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGNoZWNrTG9hZE1vcmVUaW1lcysrID4gMTApIHsKICAgICAgICAgICAgICAgICAgICBjbGVhckludGVydmFsKGNoZWNrTG9hZE1vcmUpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LCAxMDAwKTsKICAgICAgICB9CiAgICAgICAgY2xpY2tNb2RlID0gdHlwZW9mIHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuY2xpY2tNb2RlID09ICd1bmRlZmluZWQnID8gcnVsZXNEYXRhLmNsaWNrTW9kZSA6IHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuY2xpY2tNb2RlOwogICAgICAgIGxldCBjbGlja2luZ05leHQgPSBmYWxzZTsKICAgICAgICBsZXQgY2xpY2tOZXh0ID0gYXN5bmMgKCkgPT4gewogICAgICAgICAgICBpZiAoY2xpY2tpbmdOZXh0KSByZXR1cm47CiAgICAgICAgICAgIGNsaWNraW5nTmV4dCA9IHRydWU7CiAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgY2xpY2tpbmdOZXh0ID0gZmFsc2U7CiAgICAgICAgICAgIH0sIDE1MDApOwogICAgICAgICAgICBsZXQgbmV4dExpbmsgPSBydWxlUGFyc2VyLm5leHRMaW5rSHJlZjsKICAgICAgICAgICAgaWYgKCFuZXh0TGluaykgcmV0dXJuOwogICAgICAgICAgICBsZXQgaXNKcyA9IC9eKGphdmFzY3JpcHR8IykvLnRlc3QobmV4dExpbmsucmVwbGFjZShsb2NhdGlvbi5ocmVmLCAiIikpOwogICAgICAgICAgICBpZiAoaXNKcykgewogICAgICAgICAgICAgICAgbGV0IG5leHRCdG4gPSBydWxlUGFyc2VyLm5leHRMaW5rRWxlOwogICAgICAgICAgICAgICAgaWYgKCFuZXh0QnRuIHx8ICFuZXh0QnRuLm9mZnNldFBhcmVudCkgbmV4dEJ0biA9IGF3YWl0IHJ1bGVQYXJzZXIuZ2V0TmV4dExpbmsoZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgaWYgKG5leHRCdG4pIGVtdUNsaWNrKG5leHRCdG4pOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgd2luZG93LmxvY2F0aW9uLmhyZWYgPSBuZXh0TGluazsKICAgICAgICAgICAgfQogICAgICAgIH07CiAgICAgICAgbGV0IGNoZWNrU2Nyb2xsUmVhY2ggPSAoKSA9PiB7CiAgICAgICAgICAgIGxldCBkaXN0ID0gZGlzdFRvQm90dG9tKCk7CiAgICAgICAgICAgIGlmIChjbGlja01vZGUpIHsKICAgICAgICAgICAgICAgIGlmIChkaXN0IDwgMTApIHsKICAgICAgICAgICAgICAgICAgICBjbGlja05leHQoKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIGlmIChkaXN0IDwgYm90dG9tR2FwKSB7CiAgICAgICAgICAgICAgICBuZXh0UGFnZSgpOwogICAgICAgICAgICB9CiAgICAgICAgfTsKICAgICAgICBzY3JvbGxIYW5kbGVyID0gZSA9PiB7CiAgICAgICAgICAgIGlmICh1cmxDaGFuZ2VkICYmICFpc0xvYWRpbmcpIHsKICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuaW5pdFBhZ2UoKCkgPT4ge30pOwogICAgICAgICAgICAgICAgdXJsQ2hhbmdlZCA9IGZhbHNlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChpc1BhdXNlKSByZXR1cm47CiAgICAgICAgICAgIGlmICghbG9hZGluZ01vcmUpIHsKICAgICAgICAgICAgICAgIGxvYWRtb3JlQnRuID0gZ2V0TG9hZE1vcmUoZG9jdW1lbnQsIGxvYWRtb3JlQnRuKTsKICAgICAgICAgICAgICAgIGlmIChsb2FkbW9yZUJ0bikgewogICAgICAgICAgICAgICAgICAgIGlmIChpc0luVmlld1BvcnQobG9hZG1vcmVCdG4pKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGVtdUNsaWNrKGxvYWRtb3JlQnRuKTsKICAgICAgICAgICAgICAgICAgICAgICAgbG9hZGluZ01vcmUgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHtsb2FkaW5nTW9yZSA9IGZhbHNlfSwgMjAwKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGxvYWRpbmdNb3JlID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHtsb2FkaW5nTW9yZSA9IGZhbHNlfSwgMjAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIWlzTG9hZGluZyAmJiAhc3RvcFNjcm9sbCkgewogICAgICAgICAgICAgICAgY2hlY2tTY3JvbGxSZWFjaCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJ1bGVQYXJzZXIuY2hhbmdlVmlzaWJpbGl0eSgpOwogICAgICAgICAgICBpZiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5sb2NrU2Nyb2xsKSB7CiAgICAgICAgICAgICAgICBsZXQgY3VyU2Nyb2xsID0gZ2V0Qm9keShkb2N1bWVudCkuc2Nyb2xsVG9wIHx8IGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5zY3JvbGxUb3A7CiAgICAgICAgICAgICAgICBpZiAoaXNMb2FkaW5nICYmIE1hdGguYWJzKGxhc3RTY3JvbGwgLSBjdXJTY3JvbGwpID4gMzUwKSB7CiAgICAgICAgICAgICAgICAgICAgZ2V0Qm9keShkb2N1bWVudCkuc2Nyb2xsVG9wID0gbGFzdFNjcm9sbDsKICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuc2Nyb2xsVG9wID0gbGFzdFNjcm9sbDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgbGFzdFNjcm9sbCA9IGN1clNjcm9sbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH07CiAgICAgICAgZGJsY2xpY2tIYW5kbGVyID0gZSA9PiB7CiAgICAgICAgICAgIGlmIChmb3JjZVN0YXRlID09IDEgfHwgL14oSU5QVVR8VEVYVEFSRUF8U0VMRUNUKSQvaS50ZXN0KGUudGFyZ2V0Lm5vZGVOYW1lKSkgcmV0dXJuOwogICAgICAgICAgICBpZiAoIXJ1bGVzRGF0YS5kYkNsaWNrMlN0b3BLZXkpIHsKICAgICAgICAgICAgICAgIGlmICgocnVsZXNEYXRhLmRiQ2xpY2syU3RvcEN0cmwgJiYgIWUuY3RybEtleSkgfHwKICAgICAgICAgICAgICAgICAgIChydWxlc0RhdGEuZGJDbGljazJTdG9wQWx0ICYmICFlLmFsdEtleSkgfHwKICAgICAgICAgICAgICAgICAgIChydWxlc0RhdGEuZGJDbGljazJTdG9wU2hpZnQgJiYgIWUuc2hpZnRLZXkpIHx8CiAgICAgICAgICAgICAgICAgICAocnVsZXNEYXRhLmRiQ2xpY2syU3RvcE1ldGEgJiYgIWUubWV0YUtleSkpIHsKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCEvXkJPRFkkL2kudGVzdChlLnRhcmdldC5ub2RlTmFtZSkgJiYgZS50YXJnZXQuY2xhc3NOYW1lICE9PSAncGFnZXR1YWxfcGFnZUJhcicpIHsKICAgICAgICAgICAgICAgIGxldCBzZWxTdHIgPSBkb2N1bWVudC5nZXRTZWxlY3Rpb24oKS50b1N0cmluZygpOwogICAgICAgICAgICAgICAgaWYgKHNlbFN0ciAmJiBzZWxTdHIudHJpbSgpKSB7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChydWxlc0RhdGEuZGJDbGljazJTdG9wICYmIChydWxlUGFyc2VyLm5leHRMaW5rSHJlZiB8fCBsb2FkbW9yZUJ0bikpIHsKICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIGlmIChydWxlc0RhdGEuaGlkZUJhckJ1dE5vU3RvcCB8fCBydWxlc0RhdGEuaGlkZUJhcikgewogICAgICAgICAgICAgICAgICAgICAgICBjaGFuZ2VIaWRlQmFyKCFpc0hpZGVCYXIpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoIXJ1bGVzRGF0YS5oaWRlQmFyQnV0Tm9TdG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNoYW5nZVN0b3AoIWlzUGF1c2UpOwogICAgICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKGlzUGF1c2UgPyAiZGlzYWJsZSIgOiAiZW5hYmxlIikpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoIWlzUGF1c2UpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tTY3JvbGxSZWFjaCgpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0sIDEwKTsKICAgICAgICAgICAgfQogICAgICAgIH07CiAgICAgICAgZG9jdW1lbnQuYWRkRXZlbnRMaXN0ZW5lcignZGJsY2xpY2snLCBkYmxjbGlja0hhbmRsZXIpOwogICAgICAgIGNsaWNrVG9SZXNldEhhbmRsZXIgPSBlID0+IHsKICAgICAgICAgICAgaWYgKCFydWxlUGFyc2VyLm5leHRMaW5rSHJlZikgaXNMb2FkaW5nID0gZmFsc2U7CiAgICAgICAgfTsKICAgICAgICBkb2N1bWVudC5hZGRFdmVudExpc3RlbmVyKCdjbGljaycsIGNsaWNrVG9SZXNldEhhbmRsZXIpOwogICAgICAgIGlmIChydWxlc0RhdGEuZGJDbGljazJTdG9wS2V5KSB7CiAgICAgICAgICAgIGtleWRvd25IYW5kbGVyID0gZSA9PiB7CiAgICAgICAgICAgICAgICBpZiAoKHJ1bGVzRGF0YS5kYkNsaWNrMlN0b3BDdHJsICYmICFlLmN0cmxLZXkpIHx8CiAgICAgICAgICAgICAgICAgICAocnVsZXNEYXRhLmRiQ2xpY2syU3RvcEFsdCAmJiAhZS5hbHRLZXkpIHx8CiAgICAgICAgICAgICAgICAgICAocnVsZXNEYXRhLmRiQ2xpY2syU3RvcFNoaWZ0ICYmICFlLnNoaWZ0S2V5KSB8fAogICAgICAgICAgICAgICAgICAgKHJ1bGVzRGF0YS5kYkNsaWNrMlN0b3BNZXRhICYmICFlLm1ldGFLZXkpKSB7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGRvY3VtZW50LmFjdGl2ZUVsZW1lbnQgJiYKICAgICAgICAgICAgICAgICAgICAoL14oSU5QVVR8VEVYVEFSRUEpJC9pLnRlc3QoZG9jdW1lbnQuYWN0aXZlRWxlbWVudC5ub2RlTmFtZSkgfHwKICAgICAgICAgICAgICAgICAgICAgZG9jdW1lbnQuYWN0aXZlRWxlbWVudC5jb250ZW50RWRpdGFibGUgPT0gJ3RydWUnKSkgewogICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHZhciBrZXkgPSBlLmtleS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgICAgaWYgKHJ1bGVzRGF0YS5kYkNsaWNrMlN0b3BLZXkudG9Mb3dlckNhc2UoKSA9PSBrZXkpIHsKICAgICAgICAgICAgICAgICAgICBmb3JjZVN0YXRlID0gKGZvcmNlU3RhdGUgPT0gMSA/IDAgOiAxKTsKICAgICAgICAgICAgICAgICAgICBzaG93VGlwcyhpMThuKGZvcmNlU3RhdGUgPT0gMSA/ICJkaXNhYmxlU2l0ZVRpcHMiIDogImVuYWJsZVNpdGVUaXBzIikpOwogICAgICAgICAgICAgICAgICAgIGlmICghcnVsZVBhcnNlci5jdXJTaXRlUnVsZS51cmwpIHsKICAgICAgICAgICAgICAgICAgICAgICAgc3RvcmFnZS5zZXRJdGVtKCJmb3JjZVN0YXRlXyIgKyBsb2NhdGlvbi5ob3N0LCBmb3JjZVN0YXRlKTsKICAgICAgICAgICAgICAgICAgICAgICAgbG9jYXRpb24ucmVsb2FkKCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBkb2N1bWVudC5hZGRFdmVudExpc3RlbmVyKCdrZXlkb3duJywga2V5ZG93bkhhbmRsZXIpOwogICAgICAgIH0KICAgICAgICBpZiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5saXN0ZW5IYXNoQ2hhbmdlKSB7CiAgICAgICAgICAgIGhhc2hjaGFuZ2VIYW5kbGVyID0gKCkgPT4gewogICAgICAgICAgICAgICAgaXNQYXVzZSA9IHRydWU7CiAgICAgICAgICAgICAgICB1cmxDaGFuZ2VkID0gdHJ1ZTsKICAgICAgICAgICAgICAgIGlmICghcnVsZVBhcnNlci5uZXh0TGlua0hyZWYpIGlzTG9hZGluZyA9IGZhbHNlOwogICAgICAgICAgICB9OwogICAgICAgICAgICB3aW5kb3cuYWRkRXZlbnRMaXN0ZW5lcignaGFzaGNoYW5nZScsIGhhc2hjaGFuZ2VIYW5kbGVyLCBmYWxzZSk7CiAgICAgICAgfQogICAgICAgIGxldCBtYW51YWxNb2RlID0gdHlwZW9mIHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUubWFudWFsTW9kZSA9PSAndW5kZWZpbmVkJyA/IHJ1bGVzRGF0YS5tYW51YWxNb2RlIDogcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5tYW51YWxNb2RlOwogICAgICAgIGlmIChtYW51YWxNb2RlKSB7CiAgICAgICAgICAgIG1hbnVhbE1vZGVLZXlIYW5kbGVyID0gZSA9PiB7CiAgICAgICAgICAgICAgICBpZiAoZG9jdW1lbnQuYWN0aXZlRWxlbWVudCAmJgogICAgICAgICAgICAgICAgICAgICgvXihJTlBVVHxURVhUQVJFQSkkL2kudGVzdChkb2N1bWVudC5hY3RpdmVFbGVtZW50Lm5vZGVOYW1lKSB8fAogICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5hY3RpdmVFbGVtZW50LmNvbnRlbnRFZGl0YWJsZSA9PSAndHJ1ZScpKSB7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGUua2V5Q29kZSA9PSAzOSkgewogICAgICAgICAgICAgICAgICAgIGNsaWNrTmV4dCgpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChlLmtleUNvZGUgPT0gMzcpIHsKICAgICAgICAgICAgICAgICAgICBoaXN0b3J5LmJhY2soKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfTsKICAgICAgICAgICAgZG9jdW1lbnQuYWRkRXZlbnRMaXN0ZW5lcigna2V5ZG93bicsIG1hbnVhbE1vZGVLZXlIYW5kbGVyKTsKICAgICAgICAgICAgcGFnZXR1YWxOZXh0SGFuZGxlciA9ICgpID0+IHsKICAgICAgICAgICAgICAgIGNsaWNrTmV4dCgpOwogICAgICAgICAgICB9OwogICAgICAgICAgICBkb2N1bWVudC5hZGRFdmVudExpc3RlbmVyKCdwYWdldHVhbC5uZXh0JywgcGFnZXR1YWxOZXh0SGFuZGxlciwgZmFsc2UpOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGlmIChydWxlc0RhdGEuYXJyb3dUb1Njcm9sbCkgewogICAgICAgICAgICBrZXl1cEhhbmRsZXIgPSBlID0+IHsKICAgICAgICAgICAgICAgIGlmIChkb2N1bWVudC5hY3RpdmVFbGVtZW50ICYmCiAgICAgICAgICAgICAgICAgICAgKC9eKElOUFVUfFRFWFRBUkVBKSQvaS50ZXN0KGRvY3VtZW50LmFjdGl2ZUVsZW1lbnQubm9kZU5hbWUpIHx8CiAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LmFjdGl2ZUVsZW1lbnQuY29udGVudEVkaXRhYmxlID09ICd0cnVlJykpIHsKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoZS5rZXlDb2RlID09IDM5KSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IG5leHRQYWdlQmFyPWdldFBhZ2VCYXIoKS5uZXh0QmFyOwogICAgICAgICAgICAgICAgICAgIGlmIChuZXh0UGFnZUJhcikgewogICAgICAgICAgICAgICAgICAgICAgICBzY3JvbGxUb1BhZ2VCYXIobmV4dFBhZ2VCYXIpOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBzY3JvbGxUb3AgPSBnZXRCb2R5KGRvY3VtZW50KS5zY3JvbGxUb3AgfHwgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LnNjcm9sbFRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgd2luZG93LnNjcm9sbFRvKHsgdG9wOiBzY3JvbGxUb3AgKyAod2luZG93LmlubmVySGVpZ2h0IHx8IGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5jbGllbnRIZWlnaHQpLCBiZWhhdmlvcjogJ3Ntb290aCd9KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGUua2V5Q29kZSA9PSAzNykgewogICAgICAgICAgICAgICAgICAgIGxldCBwcmVQYWdlQmFyID0gZ2V0UGFnZUJhcigpLnByZUJhcjsKICAgICAgICAgICAgICAgICAgICBpZiAocHJlUGFnZUJhcikgewogICAgICAgICAgICAgICAgICAgICAgICBzY3JvbGxUb1BhZ2VCYXIocHJlUGFnZUJhcik7CiAgICAgICA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c3R5bGUuYmFja2dyb3VuZENvbG9yID0gYmFja0NvbG9yIHx8IDB4MDAwOwogICAgICAgIGxldCBfdGltZSA9IDE1MDA7CiAgICAgICAgaWYgKGhyZWYpIHsKICAgICAgICAgICAgX3RpbWUgPSAzNTAwOwogICAgICAgICAgICB0aXBzV29yZHMuaW5uZXJIVE1MID0gY3JlYXRlSFRNTChgPGEgaHJlZj0nJHtocmVmfSc+JHtjb250ZW50fTwvYT5gKTsKICAgICAgICAgICAgdGlwc1dvcmRzLnN0eWxlLnBvaW50ZXJFdmVudHMgPSAnYWxsJzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aXBzV29yZHMuaW5uZXJIVE1MID0gY3JlYXRlSFRNTChjb250ZW50KTsKICAgICAgICB9CiAgICAgICAgdGlwc1dvcmRzLnN0eWxlLm1hcmdpbkxlZnQgPSAtdGlwc1dvcmRzLm9mZnNldFdpZHRoIC8gMiArICJweCI7CiAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgIHRpcHNXb3Jkcy5zdHlsZS5tYXJnaW5MZWZ0ID0gLXRpcHNXb3Jkcy5vZmZzZXRXaWR0aCAvIDIgKyAicHgiOwogICAgICAgIH0sIDApOwogICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICB0aXBzV29yZHMuc3R5bGUub3BhY2l0eSA9IDAuODsKICAgICAgICAgICAgY2xlYXJUaW1lb3V0KGhpZGVUaXBzVGltZW91dCk7CiAgICAgICAgICAgIGhpZGVUaXBzVGltZW91dCA9IHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgdGlwc1dvcmRzLnN0eWxlLm9wYWNpdHkgPSAwOwogICAgICAgICAgICAgICAgdGlwc1dvcmRzLnN0eWxlLnBvaW50ZXJFdmVudHMgPSAnJzsKICAgICAgICAgICAgfSwgdGltZSB8fCBfdGltZSk7CiAgICAgICAgfSwgMSk7CiAgICB9CgogICAgY29uc3QgbG9hZG1vcmVSZW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ogICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGJ1dHRvbnMubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgICAgIGxldCBidXR0b24gPSBidXR0b25zW2ldOwogICAgICAgICAgICAgICAgaWYgKCFidXR0b24uaW5uZXJUZXh0IHx8IGJ1dHRvbi5pbm5lclRleHQubGVuZ3RoID4gMjApIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgaWYgKGJ1dHRvbiAmJiBsb2FkbW9yZVJlZy50ZXN0KGJ1dHRvbi5pbm5lclRleHQpKSB7CiAgICAgICAgICAgICAgICAgICAgbG9hZG1vcmVCdG4gPSBidXR0b247CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGxvYWRtb3JlQnRuICYmICFydWxlUGFyc2VyLmN1clNpdGVSdWxlLmxvYWRNb3JlICYmIGxvYWRtb3JlQnRuLmRhdGFzZXQuYWpheCAhPT0gInRydWUiKSB7CiAgICAgICAgICAgIGxldCBocmVmID0gbG9hZG1vcmVCdG4uZ2V0QXR0cmlidXRlKCJocmVmIik7CiAgICAgICAgICAgIGlmIChocmVmICYmIGhyZWYgIT0gIi8iICYmICEvXihqYXZhc2NyaXB0fCMpLy50ZXN0KGhyZWYucmVwbGFjZShsb2NhdGlvbi5ocmVmLCAiIikpKSB7CiAgICAgICAgICAgICAgICBsb2FkbW9yZUJ0biA9IG51bGw7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGxvYWRtb3JlQnRuICYmIC9sZXNzLy50ZXN0KGxvYWRtb3JlQnRuLmlubmVyVGV4dCkpIGxvYWRtb3JlQnRuID0gbnVsbDsKICAgICAgICByZXR1cm4gbG9hZG1vcmVCdG47CiAgICB9CgogICAgZnVuY3Rpb24gc2Nyb2xsVG9QYWdlQmFyKGJhcil7CiAgICAgICAgbGV0IHlPZmZzZXQgPSAtMjA7CiA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BhcnNlci5jdXJTaXRlUnVsZS5wYWdlTnVtIHx8IHBhZ2VOdW1SZWcudGVzdCh1cmwpKSB7CiAgICAgICAgICAgIHBhZ2VUZXh0LmlubmVySFRNTCArPSBpMThuKCJwYWdlIik7CiAgICAgICAgICAgIHBhZ2VOdW0gPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJzcGFuIik7CiAgICAgICAgICAgIGxldCBudW0gPSBydWxlUGFyc2VyLmdldFBhZ2VOdW1Gcm9tVXJsKHVybCk7CiAgICAgICAgICAgIHBhZ2VOdW0uaW5uZXJIVE1MID0gbnVtOwogICAgICAgICAgICBwYWdlTnVtLmNsYXNzTmFtZSA9ICJwYWdldHVhbF9wYWdlTnVtIjsKICAgICAgICAgICAgcGFnZU51bS50aXRsZSA9IGkxOG4oImlucHV0UGFnZU51bSIpOwogICAgICAgICAgICBwYWdlTnVtLnN0eWxlLmNzc1RleHQgPSBwYWdlVGV4dFN0eWxlOwogICAgICAgICAgICBwYWdlTnVtLnN0eWxlLmN1cnNvciA9ICJwb2ludGVyIjsKICAgICAgICAgICAgcGFnZU51bS5zdHlsZS5jb2xvciA9ICIiOwogICAgICAgICAgICBwYWdlTnVtLnN0eWxlLm1hcmdpbkxlZnQgPSAiNXB4IjsKICAgICAgICAgICAgcGFnZU51bS5hZGRFdmVudExpc3RlbmVyKCJjbGljayIsIGUgPT4gewogICAgICAgICAgICAgICAgbGV0IHBhZ2VJbnB1dCA9IHByb21wdChpMThuKCJpbnB1dFBhZ2VOdW0iKSwgbnVtIHx8ICIxIik7CiAgICAgICAgICAgICAgICBpZiAocGFnZUlucHV0KSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGxvY2FsUGFnZUJhciA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNwYWdldHVhbF9wYWdlQmFyIiArIHBhZ2VJbnB1dCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKGxvY2FsUGFnZUJhcikgewogICAgICAgICAgICAgICAgICAgICAgICBzY3JvbGxUb1BhZ2VCYXIobG9jYWxQYWdlQmFyKTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgcGFnZUxpbmsgPSBydWxlUGFyc2VyLmdldExpbmtCeVBhZ2UodXJsLCBwYWdlSW5wdXQpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAocGFnZUxpbmspIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9HTV9vcGVuSW5UYWIocGFnZUxpbmssIHthY3RpdmU6dHJ1ZX0pOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZS5wcmV2ZW50RGVmYXVsdCgpOwogICAgICAgICAgICAgICAgZS5zdG9wUHJvcGFnYXRpb24oKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHBhZ2VCYXIuYXBwZW5kQ2hpbGQocGFnZU51bSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcGFnZVRleHQuaW5uZXJIVE1MICs9IGkxOG4oInBhZ2UiKSArIGN1clBhZ2U7CiAgICAgICAgfQogICAgICAgIGxldCBwcmVCdG4gPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJzcGFuIik7CiAgICAgICAgcHJlQnRuLmlubmVySFRNTCA9ICLiiKciOwogICAgICAgIHByZUJ0bi50aXRsZSA9IGkxOG4oInByZXZQYWdlIik7CiAgICAgICAgcHJlQnRuLmNsYXNzTmFtZSA9ICJwcmV2U2NyZWVuIjsKICAgICAgICBwcmVCdG4uc3R5bGUuY3NzVGV4dCA9ICJkaXNwbGF5OiBub25lO3RleHQtYWxpZ246IGNlbnRlcjtyaWdodDogdW5zZXQ7IGZsb2F0OiBsZWZ0OyB3aWR0aDogNDBweDsgYmFja2dyb3VuZDogcmdiYSgyNDAsIDI0MCwgMjQwLCAwLjgpOyBwb3NpdGlvbjogYWJzb2x1dGU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cikgewogICAgICAgICAgICAgICAgc2Nyb2xsVG9QYWdlQmFyKHByZVBhZ2VCYXIpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgbGV0IHNjcm9sbFRvcCA9IGdldEJvZHkoZG9jdW1lbnQpLnNjcm9sbFRvcCB8fCBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuc2Nyb2xsVG9wOwogICAgICAgICAgICAgICAgd2luZG93LnNjcm9sbFRvKHsgdG9wOiBzY3JvbGxUb3AgLSAod2luZG93LmlubmVySGVpZ2h0IHx8IGRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5jbGllbnRIZWlnaHQpLCBiZWhhdmlvcjogJ3Ntb290aCd9KTsKICAgICAgICAgICAgfQogICAgICAgIH0pOwogICAgICAgIG5leHRCdG4uYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCBlID0+IHsKICAgICAgICAgICAgZS5zdG9wUHJvcGFnYXRpb24oKTsKICAgICAgICAgICAgZS5wcmV2ZW50RGVmYXVsdCgpOwogICAgICAgICAgICBsZXQgbmV4dFBhZ2VCYXIgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCIjcGFnZXR1YWxfcGFnZUJhciIgKyAobG9jYWxQYWdlICsgMSkpOwogICAgICAgICAgICBpZiAobmV4dFBhZ2VCYXIpIHsKICAgICAgICAgICAgICAgIHNjcm9sbFRvUGFnZUJhcihuZXh0UGFnZUJhcik7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzY3JvbGxIID0gTWF0aC5tYXgoZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LnNjcm9sbEhlaWdodCwgZ2V0Qm9keShkb2N1bWVudCkuc2Nyb2xsSGVpZ2h0KTsKICAgICAgICAgICAgICAgIHdpbmRvdy5zY3JvbGxUbyh7IHRvcDogc2Nyb2xsSCB8fCA5OTk5OTk5LCBiZWhhdmlvcjogJ3Ntb290aCd9KTsKICAgICAgICAgICAgfQogICAgICAgIH0pOwogICAgICAgIGlmICghcnVsZXNEYXRhLmhpZGVCYXJBcnJvdykgewogICAgICAgICAgICBwYWdlVGV4dC5pbnNlcnRCZWZvcmUocHJlQnRuLCBwYWdlVGV4dC5maXJzdENoaWxkKTsKICAgICAgICAgICAgcGFnZVRleHQuaW5zZXJ0QmVmb3JlKG5leHRCdG4sIHBhZ2VUZXh0LmZpcnN0Q2hpbGQpOwogICAgICAgIH0KICAgICAgICBwYWdlQmFyLmFwcGVuZENoaWxkKGRvd25TcGFuKTsKICAgICAgICBpZiAoZm9yY2VTdGF0ZSA9PSAyKSB7CiAgICAgICAgICAgIHBhZ2VCYXIuc3R5bGUud2lkdGggPSAiOTklIjsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBsZXQgcGFyZW50U3R5bGUgPSBfdW5zYWZlV2luZG93LmdldENvbXB1dGVkU3R5bGUoZXhhbXBsZS5wYXJlbnROb2RlKTsKICAgICAgICAgICAgbGV0IHBhcmVudFdpZHRoID0gZXhhbXBsZS5wYXJlbnROb2RlLm9mZnNldFdpZHRoIHx8IHBhcnNlSW50KHBhcmVudFN0eWxlLndpZHRoKTsKICAgICAgICAgICAgcGFnZUJhci5zdHlsZS53aWR0aCA9IHBhcmVudFdpZHRoIC0gcGFyc2VJbnQocGFyZW50U3R5bGUucGFkZGluZ0xlZnQpIC0gcGFyc2VJbnQocGFyZW50U3R5bGUucGFkZGluZ1JpZ2h0KSAtIDEwICsgInB4IjsKICAgICAgICAgICAgcGFnZUJhci5zdHlsZS5tYXJnaW4gPSAnMTBweCA1cHgnOwogICAgICAgICAgICBpZiAocGFyZW50U3R5bGUuZGlzcGxheSA9PSAiZ3JpZCIgfHwgcGFyZW50U3R5bGUuZGlzcGxheSA9PSAiaW5saW5lLWdyaWQiKSB7CiAgICAgICAgICAgICAgICBwYWdlQmFyLnN0eWxlLmdyaWRDb2x1bW4gPSAiMS8tMSI7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGluVGFibGUpIHsKICAgICAgICAgICAgICAgIGV4YW1wbGUgPSAoL14oVFJ8VEJPRFkpJC9pLnRlc3QoZXhhbXBsZS5ub2RlTmFtZSkpID8gZXhhbXBsZSA6IGV4YW1wbGUubmV4dEVsZW1lbnRTaWJsaW5nIHx8IGV4YW1wbGU7CiAgICAgICAgICAgICAgICBpZiAoL15UQk9EWSQvaS50ZXN0KGV4YW1wbGUubm9kZU5hbWUpKSBleGFtcGxlID0gZXhhbXBsZS5xdWVyeVNlbGVjdG9yKCJ0ciIpOwogICAgICAgICAgICAgICAgbGV0IG5leHRUciA9IGV4YW1wbGU7CiAgICAgICAgICAgICAgICB3aGlsZSAobmV4dFRyICYmIG5leHRUci5jaGlsZHJlbi5sZW5ndGggPT0gMCkgbmV4dFRyID0gbmV4dFRyLm5leHRFbGVtZW50U2libGluZzsKICAgICAgICAgICAgICAgIGlmIChuZXh0VHIpIGV4YW1wbGUgPSBuZXh0VHI7CiAgICAgICAgICAgICAgICBsZXQgdGROdW0gPSAwOwogICAgICAgICAgICAgICAgaWYgKGV4YW1wbGVTdHlsZS5kaXNwbGF5ID09ICJ0YWJsZS1yb3ciKSB7CiAgICAgICAgICAgICAgICAgICAgW10uZm9yRWFjaC5jYWxsKGV4YW1wbGUuY2hpbGRyZW4sIGVsID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgdGROdW0gKz0gZWwuY29sU3BhbiB8fCAxOwogICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBbXS5mb3JFYWNoLmNhbGwoZXhhbXBsZS5jaGlsZHJlbiwgZWwgPT4gewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoL14oVER8VEgpJC9pLnRlc3QoZWwubm9kZU5hbWUpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0ZE51bSArPSBlbC5jb2xTcGFuIHx8IDE7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHBhZ2VCYXIuc3R5bGUuY3NzVGV4dCA9ICIiOwogICAgICAgICAgICAgICAgcGFnZUJhci5zdHlsZS5kaXNwbGF5ID0gInRhYmxlLXJvdyI7CiAgICAgICAgICAgICAgICBwYWdlQmFyLnN0eWxlLmJhY2tncm91bmRDb2xvciA9ICJ1bnNldCI7CiAgICAgICAgICAgICAgICBwYWdlQmFyLnN0eWxlLmxpbmVIZWlnaHQgPSAiMjBweCI7CiAgICAgICAgICAgICAgICBwYWdlQmFyLnN0eWxlLmJveFNoYWRvdyA9ICIiOwogICAgICAgICAgICAgICAgbGV0IHRkID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgidGQiKTsKICAgICAgICAgICAgICAgIHRkLmNvbFNwYW4gPSB0ZE51bSB8fCAxOwogICAgICAgICAgICAgICAgbGV0IGluVGQgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJkaXYiKTsKICAgICAgICAgICAgICAgIGluVGQuc3R5bGUuY3NzVGV4dCA9IHBhZ2VCYXJTdHlsZTsKICAgICAgICAgICAgICAgIGluVGQuc3R5bGUuZGlzcGxheSA9ICIiOwogICAgICAgICAgICAgICAgaW5UZC5jbGFzc05hbWUgPSBwYWdlQmFyLmNsYXNzTmFtZTsKICAgICAgICAgICAgICAgIHBhZ2VCYXIuY2xhc3NOYW1lID0gIiI7CiAgICAgICAgICAgICAgICBpblRkLmFwcGVuZENoaWxkKHVwU3Bhbik7CiAgICAgICAgICAgICAgICBpblRkLmFwcGVuZENoaWxkKHBhZ2VUZXh0KTsKICAgICAgICAgICAgICAgIGlmIChwYWdlTnVtKSBpblRkLmFwcGVuZENoaWxkKHBhZ2VOdW0pOwogICAgICAgICAgICAgICAgaW5UZC5hcHBlbmRDaGlsZChkb3duU3Bhbik7CiAgICAgICAgICAgICAgICB0ZC5hcHBlbmRDaGlsZChpblRkKTsKICAgICAgICAgICAgICAgIHBhZ2VCYXIuYXBwZW5kQ2hpbGQodGQpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGluTGkpIHsKICAgICAgICAgICAgICAgIGV4YW1wbGUgPSAvXkxJJC9pLnRlc3QoZXhhbXBsZS5ub2RlTmFtZSkgPyBleGFtcGxlIDogZXhhbXBsZS5uZXh0RWxlbWVudFNpYmxpbmcgfHwgZXhhbXBsZTsKICAgICAgICAgICAgICAgIHBhZ2VCYXIuc3R5bGUub3BhY2l0eSA9IDE7CiAgICAgICAgICAgICAgICBwYWdlQmFyLnN0eWxlLmRpc3BsYXkgPSBnZXRDb21wdXRlZFN0eWxlKGV4YW1wbGUpLmRpc3BsYXk7CiAgICAgICAgICAgICAgICBwYWdlQmFyLnN0eWxlLmJhY2tncm91bmRDb2xvciA9ICJ1bnNldCI7CiAgICAgICAgICAgICAgICBwYWdlQmFyLnN0eWxlLmxpbmVIZWlnaHQgPSAiMjBweCI7CiAgICAgICAgICAgICAgICBwYWdlQmFyLnN0eWxlLmJveFNoYWRvdyA9ICIiOwogICAgICAgICAgICAgICAgcGFnZUJhci5zdHlsZS5ib3JkZXIgPSAiIjsKICAgICAgICAgICAgICAgIHBhZ2VCYXIuc3R5bGUubWF4V2lkdGggPSAidW5zZXQiOwogICAgICAgICAgICAgICAgcGFnZUJhci5zdHlsZS5mbGV4ID0gImF1dG8iOwogICAgICAgICAgICAgICAgbGV0IGluVGQgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCJkaXYiKTsKICAgICAgICAgICAgICAgIGluVGQuc3R5bGUuY3NzVGV4dCA9IHBhZ2VCYXJTdHlsZTsKICAgICAgICAgICAgICAgIGluVGQuc3R5bGUuZGlzcGxheSA9ICIiOwogICAgICAgICAgICAgICAgaW5UZC5zdHlsZS5tYXJnaW4gPSAiMCIKICAgICAgICAgICAgICAgIGluVGQuc3R5bGUucGFkZGluZyA9ICIwIDAiOwogICAgICAgICAgICAgICAgaW5UZC5zdHlsZS50ZXh0QWxpZ24gPSAiY2VudGVyIjsKICAgICAgICAgICAgICAgIGluVGQuc3R5bGUubWluV2lkdGggPSAiMTUwcHgiOwogICAgICAgICAgICAgICAgaW5UZC5zdHlsZS53aWR0aCA9ICdjYWxjKDEwMCUgLSAyMHB4KSc7CiAgICAgICAgICAgICAgICBpblRkLmNsYXNzTmFtZSA9IHBhZ2VCYXIuY2xhc3NOYW1lOwogICAgICAgICAgICAgICAgcGFnZUJhci5jbGFzc05hbWUgPSAiIjsKICAgICAgICAgICAgICAgIGluVGQuYXBwZW5kQ2hpbGQodXBTcGFuKTsKICAgICAgICAgICAgICAgIGluVGQuYXBwZW5kQ2hpbGQocGFnZVRleHQpOwogICAgICAgICAgICAgICAgaWYgKHBhZ2VOdW0pIGluVGQuYXBwZW5kQ2hpbGQocGFnZU51bSk7CiAgICAgICAgICAgICAgICBpblRkLmFwcGVuZENoaWxkKGRvd25TcGFuKTsKICAgICAgICAgICAgICAgIGlmIChwYWdlQmFyLnN0eWxlLmRpc3BsYXkgPT09ICd0YWJsZS1yb3cnKSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IHRkID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgidGQiKTsKICAgICAgICAgICAgICAgICAgICB0ZC5jb2xTcGFuID0gZXhhbXBsZS5jaGlsZHJlbi5sZW5ndGg7CiAgICAgICAgICAgICAgICAgICAgdGQuc3R5bGUud2lkdGggPSAnMTAwJSc7CiAgICAgICAgICAgICAgICAgICAgdGQuYXBwZW5kQ2hpbGQoaW5UZCk7CiAgICAgICAgICAgICAgICAgICAgcGFnZUJhci5hcHBlbmRDaGlsZCh0ZCk7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGluVGQuc3R5bGUud2lkdGggPSAnMTAwJSc7CiAgICAgICAgICAgICAgICAgICAgcGFnZUJhci5hcHBlbmRDaGlsZChpblRkKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgdXBTcGFuLmF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AgICAgICBwYWdlQmFyLnRpdGxlID0gaTE4bihpc1BhdXNlID8gImVuYWJsZSIgOiAiZGlzYWJsZSIpOwogICAgICAgIH0pOwogICAgICAgIHJ1bGVQYXJzZXIuaW5zZXJ0RWxlbWVudChwYWdlQmFyKTsKICAgICAgICBpZiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5wYWdlQmFyICYmIHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUucGFnZUJhciAhPT0gMCkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgKCh0eXBlb2YgX3Vuc2FmZVdpbmRvdy5wYWdldHVhbFBhZ2VCYXIgPT0gJ3VuZGVmaW5lZCcpID8gRnVuY3Rpb24oInBhZ2VCYXIiLCcidXNlIHN0cmljdCI7JyArIHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUucGFnZUJhcikgOiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsUGFnZUJhcikocGFnZUJhcik7CiAgICAgICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIHJldHVybiBwYWdlQmFyOwogICAgfQoKICAgIGFzeW5jIGZ1bmN0aW9uIHdhaXRGb3JFbGVtZW50KHNlbCwgZG9jKSB7CiAgICAgICAgaWYgKCFzZWwpIHJldHVybiBudWxsOwogICAgICAgIHJldHVybiBuZXcgUHJvbWlzZSgocmVzb2x2ZSkgPT4gewogICAgICAgICAgICBsZXQgY2hlY2tJbnYgPSBzZXRJbnRlcnZhbCgoKSA9PiB7CiAgICAgICAgICAgICAgICBsZXQgcmVzdWx0ID0gZ2V0RWxlbWVudChzZWwsIGRvYyk7CiAgICAgICAgICAgICAgICBpZiAocmVzdWx0KSB7CiAgICAgICAgICAgICAgICAgICAgY2xlYXJJbnRlcnZhbChjaGVja0ludik7CiAgICAgICAgICAgICAgICAgICAgcmVzb2x2ZShyZXN1bHQpOwogICAgICAgIC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hemltdXRoQW5nbGU6IDAsCiAgICAgICAgICAgIGJ1YmJsZXM6IHRydWUsCiAgICAgICAgICAgIGJ1dHRvbjogMCwKICAgICAgICAgICAgYnV0dG9uczogMCwKICAgICAgICAgICAgY2xpZW50WDogMSwKICAgICAgICAgICAgY2xpZW50WTogMSwKICAgICAgICAgICAgY2FuY2VsQnViYmxlOiBmYWxzZSwKICAgICAgICAgICAgY2FuY2VsYWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29tcG9zZWQ6IHRydWUsCiAgICAgICAgICAgIGN0cmxLZXk6IGZhbHNlLAogICAgICAgICAgICBkZWZhdWx0UHJldmVudGVkOiBmYWxzZSwKICAgICAgICAgICAgZGV0YWlsOiAxLAogICAgICAgICAgICBldmVudFBoYXNlOiAyLAogICAgICAgICAgICBmcm9tRWxlbWVudDogbnVsbCwKICAgICAgICAgICAgaGVpZ2h0OiAxLAogICAgICAgICAgICBpc1ByaW1hcnk6IGZhbHNlLAogICAgICAgICAgICBtZXRhS2V5OiBmYWxzZSwKICAgICAgICAgICAgcG9pbnRlcklkOiAxLAogICAgICAgICAgICBwb2ludGVyVHlwZTogIm1vdXNlIiwKICAgICAgICAgICAgcHJlc3N1cmU6IDAsCiAgICAgICAgICAgIHJlbGF0ZWRUYXJnZXQ6IG51bGwsCiAgICAgICAgICAgIHJldHVyblZhbHVlOiB0cnVlLAogICAgICAgICAgICBzaGlmdEtleTogZmFsc2UsCiAgICAgICAgICAgIHRvRWxlbWVudDogbnVsbCwKICAgICAgICAgICAgdHdpc3Q6IDAsCiAgICAgICAgICAgIHdoaWNoOiAxCiAgICAgICAgfTsKICAgICAgICBsZXQgbW91c2VFdmVudCA9IG5ldyBQb2ludGVyRXZlbnQoIm1vdXNlZG93biIsIGV2ZW50UGFyYW0pOwogICAgICAgIGJ0bi5kaXNwYXRjaEV2ZW50KG1vdXNlRXZlbnQpOwogICAgICAgIG1vdXNlRXZlbnQgPSBuZXcgUG9pbnRlckV2ZW50KCJtb3VzZXVwIiwgZXZlbnRQYXJhbSk7CiAgICAgICAgYnRuLmRpc3BhdGNoRXZlbnQobW91c2VFdmVudCk7CiAgICAgICAgbGV0IGRpc3BhdGNoVG91Y2hFdmVudCA9IChlbGUsIHR5cGUpID0+IHsKICAgICAgICAgICAgbGV0IHRvdWNoRXZlbnQ7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICB0b3VjaEV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnQoJ1RvdWNoRXZlbnQnKQogICAgICAgICAgICAgICAgdG91Y2hFdmVudC5pbml0VG91Y2hFdmVudCh0eXBlLCB0cnVlLCB0cnVlKQogICAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgdG91Y2hFdmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCdVSUV2ZW50JykKICAgICAgICAgICAgICAgICAgICB0b3VjaEV2ZW50LmluaXRVSUV2ZW50KHR5cGUsIHRydWUsIHRydWUpCiAgICAgICAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgICAgICAgICB0b3VjaEV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnQoJ0V2ZW50JykKICAgICAgICAgICAgICAgICAgICB0b3VjaEV2ZW50LmluaXRFdmVudCh0eXBlLCB0cnVlLCB0cnVlKQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0b3VjaEV2ZW50KSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIHRvdWNoRXZlbnQudGFyZ2V0VG91Y2hlcyA9IFt7CiAgICAgICAgICAgICAgICAgICAgICAgIHBhZ2VYOiAxLAogICAgICAgICAgICAgICAgICAgICAgICBwYWdlWTogMSwKICAgICAgICAgICAgICAgICAgICAgICAgY2xpZW50WDogMSwKICAgICAgICAgICAgICAgICAgICAgICAgY2xpZW50WTogMSwKICAgICAgICAgICAgICAgICAgICAgICAgdGFyZ2V0OiBidG4KICAgICAgICAgICAgICAgICAgICB9XTsKICAgICAgICAgICAgICAgICAgICB0b3VjaEV2ZW50LnRvdWNoZXMgPSBbewogICAgICAgICAgICAgICAgICAgICAgICBwYWdlWDogMSwKICAgICAgICAgICAgICAgICAgICAgICAgcGFnZVk6IDEsCiAgICAgICAgICAgICAgICAgICAgICAgIGNsaWVudFg6IDEsCiAgICAgICAgICAgICAgICAgICAgICAgIGNsaWVudFk6IDEsCiAgICAgICAgICAgICAgICAgICAgICAgIHRhcmdldDogYnRuCiAgICAgICAgICAgICAgICAgICAgfV07CiAgICAgICAgICAgICAgICAgICAgdG91Y2hFdmVudC5jaGFuZ2VkVG91Y2hlcyA9IFt7CiAgICAgICAgICAgICAgICAgICAgICAgIHBhZ2VYOiAxLAogICAgICAgICAgICAgICAgICAgICAgICBwYWdlWTogMSwKICAgICAgICAgICAgICAgICAgICAgICAgY2xpZW50WDogMSwKICAgICAgICAgICAgICAgICAgICAgICAgY2xpZW50WTogMSwKICAgICAgICAgICAgICAgICAgICAgICAgdGFyZ2V0OiBidG4KICAgICAgICAgICAgICAgICAgICB9XTsKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycikge30KICAgICAgICAgICAgICAgIGVsZS5kaXNwYXRjaEV2ZW50KHRvdWNoRXZlbnQpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRpc3BhdGNoVG91Y2hFdmVudChidG4sICJ0b3VjaHN0YXJ0Iik7CiAgICAgICAgZGlzcGF0Y2hUb3VjaEV2ZW50KGJ0biwgInRvdWNoZW5kIik7CgogICAgICAgIGJ0bi5jbGljaygpOwogICAgfQoKICAgIHZhciBmYWlsRnJvbUlmcmFtZSA9IDA7CiAgICB2YXIgaW5Db3JzID0gZmFsc2U7CiAgICB2YXIgY2hlY2tSZW1vdmVJbnR2OwogICAgZnVuY3Rpb24gcmVxdWVzdEZyb21JZnJhbWUodXJsLCBjY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VSdWxlLndhaXRFbGVtZW50KSB7CiAgICAgICAgICAgIGNoZWNrRXZhbCA9IGRvYyA9PiB7CiAgICAgICAgICAgICAgICByZXR1cm4gcnVsZVBhcnNlci53YWl0RWxlbWVudChkb2MpOwogICAgICAgICAgICB9OwogICAgICAgIH0gZWxzZSBpZiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS53YWl0KSB7CiAgICAgICAgICAgIGlmIChpc05hTihydWxlUGFyc2VyLmN1clNpdGVSdWxlLndhaXQpKSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIGNoZWNrRXZhbCA9ICh0eXBlb2YgX3Vuc2FmZVdpbmRvdy5wYWdldHVhbFdhaXQgPT0gJ3VuZGVmaW5lZCcpID8gRnVuY3Rpb24oImRvYyIsJyJ1c2Ugc3RyaWN0IjsnICsgcnVsZVBhcnNlci5jdXJTaXRlUnVsZS53YWl0KSA6IF91bnNhZmVXaW5kb3cucGFnZXR1YWxXYWl0OwogICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB3YWl0VGltZSA9IHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUud2FpdDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoY2hlY2tSZW1vdmVJbnR2KSBjbGVhckludGVydmFsKGNoZWNrUmVtb3ZlSW50dik7CiAgICAgICAgY2hlY2tSZW1vdmVJbnR2ID0gc2V0SW50ZXJ2YWwoKCkgPT4gewogICAgICAgICAgICBpZiAoIWlmcmFtZSB8fCAhZ2V0Qm9keShkb2N1bWVudCkuY29udGFpbnMoaWZyYW1lKSkgewogICAgICAgICAgICAgICAgY2xlYXJJbnRlcnZhbChjaGVja1JlbW92ZUludHYpOwogICAgICAgICAgICAgICAgbG9hZFBhZ2VPdmVyKCk7CiAgICAgICAgICAgIH0KICAgICAgICB9LCA1MDApOwogICAgICAgIGxldCBsb2FkZWRIYW5kbGVyID0gZSA9PiB7CiAgICAgICAgICAgIGlmIChlLmRhdGEgIT0gJ3BhZ2V0dWFsLWlmcmFtZTpET01Mb2FkZWQnICYmIGUudHlwZSAhPSAnbG9hZCcpIHJldHVybjsKICAgICAgICAgICAgY2xlYXJJbnRlcnZhbChjaGVja1JlbW92ZUludHYpOwogICAgICAgICAgICB3aW5kb3cucmVtb3ZlRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsIGxvYWRlZEhhbmRsZXIsIGZhbHNlKTsKICAgICAgICAgICAgaWZyYW1lLnJlbW92ZUV2ZW50TGlzdGVuZXIoJ2xvYWQnLCBsb2FkZWRIYW5kbGVyLCBmYWxzZSk7CiAgICAgICAgICAgIGxldCB0cnlUaW1lcyA9IDA7CiAgICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrSWZyYW1lKCkgewogICAgICAgICAgICAgICAgaWYgKHVybENoYW5nZWQgfHwgaXNQYXVzZSkgewogICAgICAgICAgICAgICAgICAgIHJldHVybiBjYWxsYmFjayhmYWxzZSwgZmFsc2UpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBsZXQgZG9jID0gaWZyYW1lLmNvbnRlbnREb2N1bWVudCB8fCBpZnJhbWUuY29udGVudFdpbmRvdy5kb2N1bWVudDsKICAgICAgICAgICAgICAgICAgICBsZXQgYmFzZSA9IGRvYy5xdWVyeVNlbGVjdG9yKCJiYXNlIik7CiAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5iYXNlUGF0aCA9IGJhc2UgPyBiYXNlLmhyZWYgOiB1cmw7CiAgICAgICAgICAgICAgICAgICAgbGV0IGVsZXMgPSBydWxlUGFyc2VyLmdldFBhZ2VFbGVtZW50KGRvYywgaWZyYW1lLmNvbnRlbnRXaW5kb3csIHRyeVRpbWVzIDwgMTApOwogICAgICAgICAgICAgICAgICAgIGlmIChjaGVja0V2YWwgJiYgIWNoZWNrRXZhbChkb2MpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tJZnJhbWUoKTsKICAgICAgICAgICAgICAgICAgICAgICAgfSwgd2FpdFRpbWUpOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChlbGVzICYmIGVsZXMubGVuZ3RoID4gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayhkb2MsIGVsZXMpOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodHJ5VGltZXMrKyA8IDEwMCkgewogICAgICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrSWZyYW1lKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0sIHdhaXRUaW1lKTsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChmYWlsRnJvbUlmcmFtZSsrID4gMikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZmFpbEZyb21JZnJhbWUgPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoIlN0b3AgYXMgZmFpbEZyb21JZnJhbWUiKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzUGF1c2UgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2soZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dUaXBzKGkxOG4oIm5vVmFsaWRDb250ZW50IiksIHVybCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayhmYWxzZSwgZmFsc2UpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgICAgICAgICAgaW5Db3JzID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICBpZiAoZm9yY2VTdGF0ZSA9PT0gMykgewogICAgICAgICAgICAgICAgICAgICAgICBkZWJ1ZygiU3RvcCBhcyBjb3JzIik7CiAgICAgICAgICAgICAgICAgICAgICAgIGlzUGF1c2UgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoIXJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUucGFnZUVsZW1lbnQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudCA9IGFsbE9mQm9keTsKICAgICAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5nZXRJbnNlcnQodHJ1ZSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuYWN0aW9uID0gMDsKICAgICAgICAgICAgICAgICAgICBydWxlUGFyc2VyLm5leHRMaW5rSHJlZiA9IHVybDsKICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayhmYWxzZSwgZmFsc2UpOwogICAgICAgICAgICAgICAgICAgIG5leHRQYWdlKCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoaWZyYW1lICYmIGlmcmFtZS5wYXJlbnROb2RlKSBpZnJhbWUucGFyZW50Tm9kZS5yZW1vdmVDaGlsZChpZnJhbWUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgY2hlY2tJZnJhbWUoKTsKICAgICAgICAgICAgfSwgd2FpdFRpbWUpOwogICAgICAgIH07CiAgICAgICAgbGV0IGNvZGUgPSBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmlmcmFtZUluaXQ7CiAgICAgICAgaWYgKGNvZGUpIHsKICAgICAgICAgICAgbGV0IGNoZWNrUmVhZHkgPSBzZXRJbnRlcnZhbCgoKSA9PiB7CiAgICAgICAgICAgICAgICBsZXQgZG9jOwogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBkb2MgPSBpZnJhbWUuY29udGVudERvY3VtZW50IHx8IChpZnJhbWUuY29udGVudFdpbmRvdyAmJiBpZnJhbWUuY29udGVudFdpbmRvdy5kb2N1bWVudCk7CiAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICBjbGVhckludGVydmFsKGNoZWNrUmVhZHkpOwogICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChkb2MpIHsKICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICBGdW5jdGlvbignd2luJywgJ2lmcmFtZScsICcidXNlIHN0cmljdCI7JyArIGNvZGUpKGlmcmFtZS5jb250ZW50V2luZG93LCBpZnJhbWUpOwogICAgICAgICAgICAgICAgICAgICAgICBjbGVhckludGVydmFsKGNoZWNrUmVhZHkpOwogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICAgICAgICAgICAgICBkZWJ1ZyhlKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0sIDUwKTsKICAgICAgICB9CiAgICAgICAgd2luZG93LmFkZEV2ZW50TGlzdGVuZXIoJ21lc3NhZ2UnLCBsb2FkZWRIYW5kbGVyLCBmYWxzZSk7CiAgICAgICAgaWZyYW1lLmFkZEV2ZW50TGlzdGVuZXIoJ2xvYWQnLCBsb2FkZWRIYW5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NlKSByZXR1cm4gbG9hZFBhZ2VPdmVyKCk7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBpZnJhbWVEb2MgPSBlbXVJZnJhbWUuY29udGVudERvY3VtZW50IHx8IGVtdUlmcmFtZS5jb250ZW50V2luZG93LmRvY3VtZW50OwogICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgIHJldHVybkZhbHNlKCJTdG9wIGFzIGNvcnMiKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgbGV0IHdhaXRUaW1lID0gMjAwLCBjaGVja0V2YWw7CiAgICAgICAgICAgIGlmIChydWxlUGFyc2VyLmN1clNpdGVSdWxlLndhaXRFbGVtZW50KSB7CiAgICAgICAgICAgICAgICBjaGVja0V2YWwgPSBkb2MgPT4gewogICAgICAgICAgICAgICAgICAgIHJldHVybiBydWxlUGFyc2VyLndhaXRFbGVtZW50KGRvYyk7CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICB9IGVsc2UgaWYocnVsZVBhcnNlci5jdXJTaXRlUnVsZS53YWl0KSB7CiAgICAgICAgICAgICAgICBpZiAoaXNOYU4ocnVsZVBhcnNlci5jdXJTaXRlUnVsZS53YWl0KSkgewogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrRXZhbCA9ICh0eXBlb2YgX3Vuc2FmZVdpbmRvdy5wYWdldHVhbFdhaXQgPT0gJ3VuZGVmaW5lZCcpID8gRnVuY3Rpb24oImRvYyIsICcidXNlIHN0cmljdCI7JyArIHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUud2FpdCkgOiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsV2FpdDsKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICB3YWl0VGltZSA9IHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUud2FpdDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgaWYgKCFvcmdQYWdlKSB7CiAgICAgICAgICAgICAgICBpZiAoIWxvYWRtb3JlRW5kKSB7CiAgICAgICAgICAgICAgICAgICAgbG9hZG1vcmVCdG4gPSBnZXRMb2FkTW9yZShpZnJhbWVEb2MpOwogICAgICAgICAgICAgICAgICAgIGlmIChsb2FkbW9yZUJ0biAmJiBpc1Zpc2libGUobG9hZG1vcmVCdG4sIGVtdUlmcmFtZS5jb250ZW50V2luZG93KSkgewogICAgICAgICAgICAgICAgICAgICAgICBlbXVDbGljayhsb2FkbW9yZUJ0bik7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBpbnR2ID0gc2V0SW50ZXJ2YWwoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbG9hZG1vcmVCdG4gPSBnZXRMb2FkTW9yZShpZnJhbWVEb2MpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFsb2FkbW9yZUJ0biB8fCAhZ2V0Qm9keShkb2N1bWVudCkuY29udGFpbnMobG9hZG1vcmVCdG4pIHx8ICFpc1Zpc2libGUobG9hZG1vcmVCdG4sIGVtdUlmcmFtZS5jb250ZW50V2luZG93KSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNsZWFySW50ZXJ2YWwoaW50dik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbG9hZG1vcmVFbmQgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGVja1BhZ2UoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LCA1MDApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChpc0luVmlld1BvcnQobG9hZG1vcmVCdG4pKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZW11Q2xpY2sobG9hZG1vcmVCdG4pOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9LCAyMDApOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgbG9hZG1vcmVFbmQgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChjaGVja0V2YWwgJiYgIWNoZWNrRXZhbChpZnJhbWVEb2MpKSB7CiAgICAgICAgICAgICAgICAgICAgd2FpdFRpbWVzID0gNTA7CiAgICAgICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrUGFnZSgpOwogICAgICAgICAgICAgICAgICAgIH0sIHdhaXRUaW1lKTsKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmICghbmV4dExpbmsgfHwgIW5leHRMaW5rLm9mZnNldFBhcmVudCkgbmV4dExpbmsgPSBhd2FpdCBydWxlUGFyc2VyLmdldE5leHRMaW5rKGlmcmFtZURvYyk7CiAgICAgICAgICAgICAgICAgICAgaWYgKG5leHRMaW5rKSBwYWdlRWxlID0gcnVsZVBhcnNlci5nZXRQYWdlRWxlbWVudChpZnJhbWVEb2MsIGVtdUlmcmFtZS5jb250ZW50V2luZG93LCB0cnVlKTsKICAgICAgICAgICAgICAgICAgICBpZiAoIXBhZ2VFbGUgfHwgcGFnZUVsZS5sZW5ndGggPT0gMCB8fCAhbmV4dExpbmspIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHdhaXRUaW1lcy0tID4gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tQYWdlKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LCB3YWl0VGltZSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoIXBhZ2VFbGUgfHwgcGFnZUVsZS5sZW5ndGggPT0gMCkgewogICAgICAgICAgICAgICAgICAgIHJldHVybkZhbHNlKCJTdG9wIGFzIG5vIHBhZ2Ugd2hlbiBlbXUiKTsKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoL15VTCQvaS50ZXN0KHBhZ2VFbGVbMF0ubm9kZU5hbWUpKSBwYWdlRWxlID0gcGFnZUVsZVswXS5jaGlsZHJlbjsKICAgICAgICAgICAgICAgIHBhZ2VFbGUgPSBwYWdlRWxlW3BhcnNlSW50KChwYWdlRWxlLmxlbmd0aCAtIDEpIC8gMildOwogICAgICAgICAgICAgICAgd2hpbGUocGFnZUVsZSAmJiAoKHBhZ2VFbGUuc2Nyb2xsSGVpZ2h0ICYmIHBhZ2VFbGUuc2Nyb2xsSGVpZ2h0IDwgNTApIHx8ICFwYWdlRWxlLm9mZnNldFBhcmVudCB8fCAoIS9eSU1HJC9pLnRlc3QocGFnZUVsZS5ub2RlTmFtZSkgJiYgIXBhZ2VFbGUuaW5uZXJIVE1MLnRyaW0oKSkpKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBhZ2VFbGUubmV4dEVsZW1lbnRTaWJsaW5nKSBwYWdlRWxlID0gcGFnZUVsZS5uZXh0RWxlbWVudFNpYmxpbmc7CiAgICAgICAgICAgICAgICAgICAgZWxzZSBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChydWxlUGFyc2VyLmN1clNpdGVSdWxlLnNpbmdsZVVybCAmJiBvcmdDb250ZW50ICE9IHBhZ2VFbGUuaW5uZXJIVE1MKSB7CiAgICAgICAgICAgICAgICAgICAgb3JnQ29udGVudCA9IHBhZ2VFbGUuaW5uZXJIVE1MOwogICAgICAgICAgICAgICAgICAgIGlmICh3YWl0VGltZXMtLSA+IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGVja1BhZ2UoKTsKICAgICAgICAgICAgICAgICAgICAgICAgfSwgd2FpdFRpbWUpOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgb3JnUGFnZSA9IHBhZ2VFbGU7CiAgICAgICAgICAgICAgICBpZiAobmV4dExpbmspIHsKICAgICAgICAgICAgICAgICAgICBpZiAoL15JTUckL2kudGVzdChvcmdQYWdlLm5vZGVOYW1lKSkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUubGF6eUltZ1NyYykgcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5sYXp5SW1nU3JjID0gIjAiOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAob3JnUGFnZS5zcmMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9yZ0NvbnRlbnQgPSBvcmdQYWdlLnNyYzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrUGFnZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSwgNTAwKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG9yZ0NvbnRlbnQgPSBvcmdQYWdlLmlubmVySFRNTDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgcHJlQ29udGVudCA9IG9yZ0NvbnRlbnQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFpc1Zpc2libGUobmV4dExpbmssIGVtdUlmcmFtZS5jb250ZW50V2luZG93KSkgewogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm5GYWxzZSgiU3RvcCBhcyBuZXh0IGhpZGUgd2hlbiBlbXUiKTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBlbXVDbGljayhuZXh0TGluayk7CiAgICAgICAgICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tQYWdlKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0sIDUwMCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICByZXR1cm5GYWxzZSgiU3RvcCBhcyBubyBuZXh0IHdoZW4gZW11Iik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCFydWxlUGFyc2VyLmNoZWNrU3RvcFNpZ24obmV4dExpbmssIGlmcmFtZURvYykpIHJldHVybiByZXR1cm5GYWxzZSgiU3RvcCBhcyBzdG9wU2lnbiIpOzsKICAgICAgICAgICAgaWYgKGNoZWNrVGltZXMrKyA+IDIwMCkgewogICAgICAgICAgICAgICAgcmV0dXJuRmFsc2UoIlN0b3AgYXMgdGltZW91dCB3aGVuIGVtdSIpOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxldCBlbGVzID0gcnVsZVBhcnNlci5nZXRQYWdlRWxlbWVudChpZnJhbWVEb2MsIGVtdUlmcmFtZS5jb250ZW50V2luZG93LCB0cnVlKSwgY2hlY2tJdGVtOwogICAgICAgICAgICBpZiAoZWxlcyAmJiBlbGVzLmxlbmd0aCA+IDApIHsKICAgICAgICAgICAgICAgIGNoZWNrSXRlbSA9IGVsZXM7CiAgICAgICAgICAgICAgICBpZiAoL15VTCQvaS50ZXN0KGVsZXNbMF0ubm9kZU5hbWUpKSBjaGVja0l0ZW0gPSBlbGVzWzBdLmNoaWxkcmVuOwogICAgICAgICAgICAgICAgY2hlY2tJdGVtID0gY2hlY2tJdGVtW3BhcnNlSW50KChjaGVja0l0ZW0ubGVuZ3RoIC0gMSkgLyAyKV07CiAgICAgICAgICAgICAgICB3aGlsZShjaGVja0l0ZW0gJiYgKChjaGVja0l0ZW0uc2Nyb2xsSGVpZ2h0ICYmIGNoZWNrSXRlbS5zY3JvbGxIZWlnaHQgPCA1MCkgfHwgIWNoZWNrSXRlbS5vZmZzZXRQYXJlbnQgfHwgKCEvXklNRyQvaS50ZXN0KGNoZWNrSXRlbS5ub2RlTmFtZSkgJiYgIWNoZWNrSXRlbS5pbm5lckhUTUwudHJpbSgpKSkpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoY2hlY2tJdGVtLm5leHRFbGVtZW50U2libGluZykgY2hlY2tJdGVtID0gY2hlY2tJdGVtLm5leHRFbGVtZW50U2libGluZzsKICAgICAgICAgICAgICAgICAgICBlbHNlIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghY2hlY2tJdGVtIHx8IChjaGVja0V2YWwgJiYgIWNoZWNrRXZhbChpZnJhbWVEb2MpKSkgewogICAgICAgICAgICAgICAgaWYgKGNoZWNrRXZhbCkgY2hlY2tUaW1lcyA9IDA7CiAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICBjaGVja1BhZ2UoKTsKICAgICAgICAgICAgICAgIH0sIHdhaXRUaW1lKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGxldCBjaGVja0lubmVyOwogICAgICAgICAgICAgICAgaWYgKC9eSU1HJC9pLnRlc3QoY2hlY2tJdGVtLm5vZGVOYW1lKSkgewogICAgICAgICAgICAgICAgICAgIGlmIChjaGVja0l0ZW0uc3JjKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrSW5uZXIgPSBjaGVja0l0ZW0uc3JjOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tQYWdlKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0sIHdhaXRUaW1lKTsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgY2hlY2tJbm5lciA9IGNoZWNrSXRlbS5pbm5lckhUTUw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAob3JnUGFnZSAhPSBjaGVja0l0ZW0gfHwgY2hlY2tJbm5lciAhPSBwcmVDb250ZW50KSB7CiAgICAgICAgICAgICAgICAgICAgY2hhbmdlZCA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgb3JnUGFnZSA9IGNoZWNrSXRlbTsKICAgICAgICAgICAgICAgICAgICBwcmVDb250ZW50ID0gY2hlY2tJbm5lcjsKICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tQYWdlKCk7CiAgICAgICAgICAgICAgICAgICAgfSwgd2FpdFRpbWUpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChjaGFuZ2VkKSB7CiAgICAgICAgICAgICAgICAgICAgY2hlY2tUaW1lcyA9IDA7CiAgICAgICAgICAgICAgICAgICAgaWYgKG9yZ0NvbnRlbnQgPT0gcHJlQ29udGVudCAmJiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5zaW5nbGVVcmwgfHwgcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5zdG9wU2FtZSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuRmFsc2UoIlN0b3AgYXMgc2FtZSBjb250ZW50Iik7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgb3JnQ29udGVudCA9IHByZUNvbnRlbnQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGNhbGxiYWNrKGlmcmFtZURvYywgZWxlcyk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBpZiAoY2hlY2tUaW1lcyAlIDEwID09PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghbmV4dExpbmsgfHwgIW5leHRMaW5rLm9mZnNldFBhcmVudCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV4dExpbmsgPSBhd2FpdCBydWxlUGFyc2VyLmdldE5leHRMaW5rKGlmcmFtZURvYyk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG5leHRMaW5rKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbXVDbGljayhuZXh0TGluayk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrUGFnZSgpOwogICAgICAgICAgICA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CFpbXBvcnRhbnQ7cG9pbnRlci1ldmVudHM6bm9uZSFpbXBvcnRhbnQ7cG9zaXRpb246Zml4ZWQ7dG9wOjBweDtsZWZ0OjBweDt6LWluZGV4Oi0yMTQ3NDgzNjQ3Oyc7CiAgICAgICAgICAgIGVtdUlmcmFtZS5hZGRFdmVudExpc3RlbmVyKCJsb2FkIiwgZSA9PiB7CiAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICBpZnJhbWVEb2MgPSBlbXVJZnJhbWUuY29udGVudERvY3VtZW50IHx8IGVtdUlmcmFtZS5jb250ZW50V2luZG93LmRvY3VtZW50OwogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZS5tZXNzYWdlICYmIGUubWVzc2FnZS5pbmRleE9mKCJjcm9zcy1vcmlnaW4iKSAhPSAtMSAmJiBub3RTZXRTYW5kYm94ICYmIGVtdUlmcmFtZS5oYXNBdHRyaWJ1dGUoInNhbmRib3giKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZW11SWZyYW1lLnJlbW92ZUF0dHJpYnV0ZSgic2FuZGJveCIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbWVldENvcnMgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2soZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybkZhbHNlKCJTdG9wIGFzIGNvcnMiKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIG1lZXRDb3JzID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgbGV0IGNvZGUgPSBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmluaXQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKGNvZGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5ldyBBc3luY0Z1bmN0aW9uKCdkb2MnLCd3aW4nLCdpZnJhbWUnLCdjbGljaycsICdlbnRlcicsICdpbnB1dCcsICcidXNlIHN0cmljdCI7JyArIGNvZGUpKGlmcmFtZURvYywgZW11SWZyYW1lLmNvbnRlbnRXaW5kb3csIGVtdUlmcmFtZSwgc2VsID0+IHtjbGlja0FjdGlvbihzZWwsIGlmcmFtZURvYyl9LCBzZWwgPT4ge2VudGVyQWN0aW9uKHNlbCwgaWZyYW1lRG9jKX0sIChzZWwsIHYpID0+e2lucHV0QWN0aW9uKHNlbCwgdiwgaWZyYW1lRG9jKX0pOwogICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChsb2FkZWQpIHJldHVybjsKICAgICAgICAgICAgICAgICAgICBsb2FkZWQgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgIGNoZWNrUGFnZSgpOwogICAgICAgICAgICAgICAgfSwgNTAwKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGxldCBjb2RlID0gcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5pZnJhbWVJbml0OwogICAgICAgICAgICBpZiAoY29kZSkgewogICAgICAgICAgICAgICAgbGV0IGNoZWNrUmVhZHkgPSBzZXRJbnRlcnZhbCgoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgaWZyYW1lRG9jID0gZW11SWZyYW1lLmNvbnRlbnREb2N1bWVudCB8fCAoZW11SWZyYW1lLmNvbnRlbnRXaW5kb3cgJiYgZW11SWZyYW1lLmNvbnRlbnRXaW5kb3cuZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgICAgICAgICAgICAgICBjbGVhckludGVydmFsKGNoZWNrUmVhZHkpOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChpZnJhbWVEb2MpIHsKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIEZ1bmN0aW9uKCd3aW4nLCAnaWZyYW1lJywgJyJ1c2Ugc3RyaWN0IjsnICsgY29kZSkoZW11SWZyYW1lLmNvbnRlbnRXaW5kb3csIGVtdUlmcmFtZSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjbGVhckludGVydmFsKGNoZWNrUmVhZHkpOwogICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSwgNTApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghbGFzdEFjdGl2ZVVybCkgbGFzdEFjdGl2ZVVybCA9IGxvY2F0aW9uLmhyZWY7CiAgICAgICAgICAgIGVtdUlmcmFtZS5zcmMgPSBsYXN0QWN0aXZlVXJsOwogICAgICAgICAgICBnZXRCb2R5KGRvY3VtZW50KS5hcHBlbmRDaGlsZChlbXVJZnJhbWUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGlmIChlbXVJZnJhbWUuc3JjICE9IGxhc3RBY3RpdmVVcmwgfHwgbWVldENvcnMpIHsKICAgICAgICAgICAgICAgIGVtdUlmcmFtZS5zcmMgPSBsYXN0QWN0aXZlVXJsOwogICAg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9wOwogICAgICAgIGlmIChydWxlUGFyc2VyLmN1clNpdGVSdWxlLnNpbmdsZVVybCB8fCBmb3JjZVN0YXRlID09PSAyKSB7CiAgICAgICAgICAgIGxldCBoZWlnaHQgPSAoZ2V0Qm9keShmcmFtZURvYykuc2Nyb2xsSGVpZ2h0IHx8IGdldEJvZHkoZnJhbWVEb2MpLm9mZnNldEhlaWdodCB8fCA1MDApOwogICAgICAgICAgICBpZiAoIWlmcmFtZS5zdHlsZS5oZWlnaHQgfHwgaGVpZ2h0IC0gcGFyc2VJbnQoaWZyYW1lLnN0eWxlLmhlaWdodCkgPiA1MCkgewogICAgICAgICAgICAgICAgaWZyYW1lLnN0eWxlLmhlaWdodCA9IGhlaWdodCArICJweCI7CiAgICAgICAgICAgICAgICBpZnJhbWUuc3R5bGUubWluSGVpZ2h0ID0gaWZyYW1lLnN0eWxlLmhlaWdodDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZnJhbWUuc3R5bGUud2lkdGggPSAiMTAwJSI7CiAgICAgICAgICAgIGZyYW1lRG9jLmRvY3VtZW50RWxlbWVudC5zY3JvbGxUb3AgPSAwOwogICAgICAgICAgICBmcmFtZURvYy5kb2N1bWVudEVsZW1lbnQuc2Nyb2xsTGVmdCA9IDA7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaWYgKHBhZ2VFbGUpIHsKICAgICAgICAgICAgICAgIGxldCBmaXRXaWR0aCA9IHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuZml0V2lkdGggIT09IGZhbHNlOwogICAgICAgICAgICAgICAgbGV0IHRhcmdldEVsZW1lbnQgPSBwYWdlRWxlWzBdOwogICAgICAgICAgICAgICAgaWYgKCF0YXJnZXRFbGVtZW50KSByZXR1cm47CiAgICAgICAgICAgICAgICBpZiAocGFnZUVsZS5sZW5ndGggPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgdGFyZ2V0RWxlbWVudCA9IHRhcmdldEVsZW1lbnQucGFyZW50Tm9kZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxldCBzY3JvbGxIZWlnaHQgPSB0YXJnZXRFbGVtZW50LnNjcm9sbEhlaWdodCB8fCB0YXJnZXRFbGVtZW50Lm9mZnNldEhlaWdodCB8fCA1MDA7CiAgICAgICAgICAgICAgICBpZnJhbWUuc3R5bGUuaGVpZ2h0ID0gc2Nyb2xsSGVpZ2h0ICsgInB4IjsKICAgICAgICAgICAgICAgIGxldCBzY3JvbGxUb3AgPSAwLCBzY3JvbGxMZWZ0ID0gMDsKICAgICAgICAgICAgICAgIGdldEJvZHkoZnJhbWVEb2MpLnNjcm9sbFRvcCA9IDA7CiAgICAgICAgICAgICAgICBnZXRCb2R5KGZyYW1lRG9jKS5zY3JvbGxMZWZ0ID0gMDsKICAgICAgICAgICAgICAgIHdoaWxlICh0YXJnZXRFbGVtZW50ICYmIHRhcmdldEVsZW1lbnQub2Zmc2V0UGFyZW50KSB7CiAgICAgICAgICAgICAgICAgICAgdGFyZ2V0RWxlbWVudC5vZmZzZXRQYXJlbnQuc2Nyb2xsVG9wID0gdGFyZ2V0RWxlbWVudC5vZmZzZXRUb3A7CiAgICAgICAgICAgICAgICAgICAgaWYgKHRhcmdldEVsZW1lbnQub2Zmc2V0UGFyZW50LnNjcm9sbFRvcCA9PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNjcm9sbFRvcCArPSB0YXJnZXRFbGVtZW50Lm9mZnNldFRvcDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKGZpdFdpZHRoKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHRhcmdldEVsZW1lbnQub2Zmc2V0UGFyZW50LnNjcm9sbExlZnQgPSB0YXJnZXRFbGVtZW50Lm9mZnNldExlZnQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0YXJnZXRFbGVtZW50Lm9mZnNldFBhcmVudC5zY3JvbGxMZWZ0ID09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNjcm9sbExlZnQgKz0gdGFyZ2V0RWxlbWVudC5vZmZzZXRMZWZ0OwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHRhcmdldEVsZW1lbnQgPSB0YXJnZXRFbGVtZW50Lm9mZnNldFBhcmVudDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZyYW1lRG9jLmRvY3VtZW50RWxlbWVudC5zY3JvbGxUb3AgPSBzY3JvbGxUb3A7CiAgICAgICAgICAgICAgICBmcmFtZURvYy5kb2N1bWVudEVsZW1lbnQuc2Nyb2xsTGVmdCA9IHNjcm9sbExlZnQ7CiAgICAgICAgICAgICAgICBpZiAoZnJhbWVEb2MuZG9jdW1lbnRFbGVtZW50LnNjcm9sbFRvcCA9PSAwICYmIGZyYW1lRG9jLmRvY3VtZW50RWxlbWVudC5zY3JvbGxMZWZ0ID09IDApIHsKICAgICAgICAgICAgICAgICAgICBnZXRCb2R5KGZyYW1lRG9jKS5zY3JvbGxUb3AgKz0gc2Nyb2xsVG9wOwogICAgICAgICAgICAgICAgICAgIGdldEJvZHkoZnJhbWVEb2MpLnNjcm9sbExlZnQgKz0gc2Nyb2xsTGVmdDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICghZml0V2lkdGggJiYgaWZyYW1lLnN0eWxlLm1hcmdpbkxlZnQgPT0gJzBweCcpIHsKICAgICAgICAgICAgICAgICAgICBpZnJhbWUuc3R5bGUud2lkdGggPSAiMTAwdnciOwogICAgICAgICAgICAgICAgICAgIGlmcmFtZS5zdHlsZS5tYXhXaWR0aCA9ICIxMDB2dyI7CiAgICAgICAgICAgICAgICAgICAgaWZyYW1lLnN0eWxlLm1pbldpZHRoID0gIjEwMHZ3IjsKICAgICAgICAgICAgICAgICAgICB2YXIgY1dpZHRoID0gZG9jdW1lbnQuYm9keS5jbGllbnRXaWR0aCB8fCBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuY2xpZW50V2lkdGg7CiAgICAgICAgICAgICAgICAgICAgdmFyIGlXaWR0aCA9IHdpbmRvdy5pbm5lcldpZHRoOwogICAgICAgICAgICAgICAgICAgIGlmcmFtZS5zdHlsZS5tYXJnaW5MZWZ0ID0gLWlmcmFtZS5nZXRCb3VuZGluZ0NsaWVudFJlY3QoKS5sZWZ0IC0gKGlXaWR0aCAtIGNXaWR0aCkgLyAyICsgInB4IjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXRCb2R5KGRvY3VtZW50KS5zY3JvbGxUb3AgPSBjdXJTY3JvbGw7CiAgICAgICAgZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LnNjcm9sbFRvcCA9IGN1clNjcm9sbDsKICAgIH0KCiAgICBmdW5jdGlvbiBzY3JvbGxUb1Jlc2l6ZShlKSB7CiAgICAgICAgaWYgKHNjcm9sbGluZ1RvUmVzaXplKSByZXR1cm47CiAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIHNjcm9sbGluZ1RvUmVzaXplID0gdHJ1ZTsKICAgICAgICAgICAgbGV0IHJlc2l6ZUhhbmRsZXIgPSAoKSA9PiB7CiAgICAgICAgICAgICAgICBsZXQgdG91Y2hlZCA9IDA7CiAgICAgICAgICAgICAgICBmb3IgKGxldCBpIGluIHJlc2l6ZVBvb2wpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgcmVzaXplQXJyID0gcmVzaXplUG9vbFtpXTsKICAgICAgICAgICAgICAgICAgICBsZXQgaWZyYW1lID0gcmVzaXplQXJyWzFdKCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKGlzVG91Y2hWaWV3UG9ydChpZnJhbWUpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHRvdWNoZWQrKzsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHBhZ2VFbGUgPSByZXNpemVBcnJbMF0oKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGZyYW1lRG9jID0gcmVzaXplQXJyWzJdKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlc2l6ZUlmcmFtZShpZnJhbWUsIGZyYW1lRG9jLCBwYWdlRWxlKTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRvdWNoZWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRvdWNoZWQgPT0gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHBhZ2VFbGUgPSByZXNpemVBcnJbMF0oKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBmcmFtZURvYyA9IHJlc2l6ZUFyclsyXSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzaXplSWZyYW1lKGlmcmFtZSwgZnJhbWVEb2MsIHBhZ2VFbGUpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoIWlmcmFtZS5wYXJlbnROb2RlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlc2l6ZVBvb2wuc3BsaWNlKGksIDEpOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgc2Nyb2xsaW5nVG9SZXNpemUgPSBmYWxzZTsKICAgICAgICAgICAgfSwgMzAwKTsKICAgICAgICAgICAgcmVzaXplSGFuZGxlcigpOwogICAgICAgIH0KICAgIH0KCiAgICBmdW5jdGlvbiBmb3JjZUlmcmFtZSh1cmwsIGNhbGxiYWNrKSB7CiAgICAgICAgdXJsID0gdXJsLmluZGV4T2YoJz0nKSA9PSAtMSA/IHVybC5yZXBsYWNlKC8jW14jXSovLCIiKSA6IHVybDsKICAgICAgICBsZXQgY3VySWZyYW1lID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgnaWZyYW1lJyksIGlmcmFtZURvYywgcGFnZUVsZW1lbnQgPSBudWxsLCBpc2xvYWRlZCA9IGZhbHNlLCBpbkFjdGlvbiA9IHRydWU7CiAgICAgICAgbGV0IGxvYWRlZEhhbmRsZXIgPSAoKSA9PiB7CiAgICAgICAgICAgIGxldCBnZXRQYWdlRWxlID0gKCkgPT4gewogICAgICAgICAgICAgICAgaWYgKHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuc2luZ2xlVXJsKSB7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG51bGw7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmICghcGFnZUVsZW1lbnQgfHwgcGFnZUVsZW1lbnQubGVuZ3RoID09PSAwIHx8ICFwYWdlRWxlbWVudFswXS5vZmZzZXRQYXJlbnQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGFnZUVsZW1lbnQgPSBydWxlUGFyc2VyLmdldFBhZ2VFbGVtZW50KGlmcmFtZURvYywgY3VySWZyYW1lLmNvbnRlbnRXaW5kb3cpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gcGFnZUVsZW1lbnQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIHJlc2l6ZUlmcmFtZShjdXJJZnJhbWUsIGlmcmFtZURvYywgZ2V0UGFnZUVsZSgpKTsKICAgICAgICAgICAgaWYgKGlzbG9hZGVkKSByZXR1cm47CiAgICAgICAgICAgIGlzbG9hZGVkID0gdHJ1ZTsKICAgICAgICAgICAgbGV0IGdldElmcmFtZSA9ICgpID0+IHsKICAgICAgICAgICAgICAgIHJldHVybiBjdXJJZnJhbWU7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGxldCBnZXRGcmFtZURvYyA9ICgpID0+IHsKICAgICAgICAgICAgICAgIHJldHVybiBpZnJhbWVEb2M7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIHJ1bGVQYXJzZXIuaW5zZXJ0UGFnZShpZnJhbWVEb2MsIFtdLCB1cmwsIGVsZSA9PiB7CiAgICAgICAgICAgICAgICBjYWxsYmFjayhjdXJJZnJhbWUpOwogICAgICAgICAgICAgICAgaW5BY3Rpb24gPSBmYWxzZTsKICAgICAgICAgICAgfSwgdHJ1ZSk7CiAgICAgICAgICAgIHJlc2l6ZVBvb2wucHVzaChbZ2V0UGFnZUVsZSwgZ2V0SWZyYW1lLCBnZXRGcmFtZURvY10pOwogICAgICAgIH07CiAgICAgICAgbGV0IGNoZWNrSWZyYW1lVGltZXIgPSBzZXRJbnRlcnZhbCgoKSA9PiB7CiAgICAgICAgICAgIGlmICghY3VySWZyYW1lLnBhcmVudE5vZGUpIHsKICAgICAgICAgICAgICAgIGNsZWFySW50ZXJ2YWwoY2hlY2tJZnJhbWVUaW1lcik7CiAgICAgICAgICAgICAgICByZXR1cm4gaXNsb2FkZWQgfHwgY2FsbGJhY2soZmFsc2UpOwogICAgICAgICAgICB9CiAgICAgICAgfSwgNTAwKTsKICAgICAgICBsZXQgY29kZSA9IHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuaWZyYW1lSW5pdDsKICAgICAgICBpZiAoY29kZSkgewogICAgICAgICAgICBsZXQgY2hlY2tSZWFkeSA9IHNldEludGVydmFsKCgpID0+IHsKICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgaWZyYW1lRG9jID0gY3VySWZyYW1lLmNvbnRlbnREb2N1bWVudCB8fCAoY3VySWZyYW1lLmNvbnRlbnRXaW5kb3cgJiYgY3VySWZyYW1lLmNvbnRlbnRXaW5kb3cuZG9jdW1lbnQpOwogICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgICAgICAgICAgY2xlYXJJbnRlcnZhbChjaGVja1JlYWR5KTsKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoaWZyYW1lRG9jKSB7CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgRnVuY3Rpb24oJ3dpbicsICdpZnJhbWUnLCAnInVzZSBzdHJpY3QiOycgKyBjb2RlKShjdXJJZnJhbWUuY29udGVudFdpbmRvdywgY3VySWZyYW1lKTsKICAgICAgICAgICAgICAgICAgICAgICAgY2xlYXJJbnRlcnZhbChjaGVja1JlYWR5KTsKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LCA1MCk7CiAgICAgICAgfQogICAgICAgIGN1cklmcmFtZS5uYW1lID0gJ3BhZ2V0dWFsLWlmcmFtZSc7CiAgICAgICAgY3VySWZyYW1lLnNhbmRib3ggPSAiYWxsb3ctc2FtZS1vcmlnaW4gYWxsb3ctc2NyaXB0cyBhbGxvdy1wb3B1cHMgYWxsb3ctZm9ybXMiOwogICAgICAgIGN1cklmcmFtZS5mcmFtZUJvcmRlciA9ICcwJzsKICAgICAgICBjdXJJZnJhbWUuc2Nyb2xsaW5nID0gIm5vIjsKICAgICAgICBjdXJJZnJhbWUuc3R5bGUuY3NzVGV4dCA9ICdkaXNwbGF5OiBibG9jazsgdmlzaWJpbGl0eTogdmlzaWJsZTsgZmxvYXQ6IG5vbmU7IGNsZWFyOiBib3RoOyB3aWR0aDogMTAwJTsgaGVpZ2h0OiAwOyBiYWNrZ3JvdW5kOiBpbml0aWFsOyBib3JkZXI6IDBweDsgYm9yZGVyLXJhZGl1czogMHB4OyBtYXJnaW46IDBweDsgcGFkZGluZzogMHB4OyB6LWluZGV4OiAyMTQ3NDgzNjQ3O2NvbnRlbnQtdmlzaWJpbGl0eTogYXV0bztjb250YWluLWludHJpbnNpYy1zaXplOiBhdXRvIDMwMHB4Oyc7CiAgICAgICAgY3VySWZyYW1lLmFkZEV2ZW50TGlzdGVuZXIoImxvYWQiLCBlID0+IHsKICAgICAgICAgICAgY2xlYXJJbnRlcnZhbChjaGVja0lmcmFtZVRpbWVyKTsKICAgICAgICAgICAgaWYgKGlzUGF1c2UpIHJldHVybiBjYWxsYmFjayhmYWxzZSk7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBpZnJhbWVEb2MgPSBjdXJJZnJhbWUuY29udGVudERvY3VtZW50IHx8IGN1cklmcmFtZS5jb250ZW50V2luZG93LmRvY3VtZW50OwogICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgIGRlYnVnKCJTdG9wIGFzIGNvcnMiKTsKICAgICAgICAgICAgICAgIGlzUGF1c2UgPSB0cnVlOwogICAgICAgICAgICAgICAgY2FsbGJhY2soZmFsc2UpOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxldCBjc3MgPSBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmNzcyB8fCBydWxlc0RhdGEuY3VzdG9tQ3NzOwogICAgICAgICAgICBpZiAoY3NzKSB7CiAgICAgICAgICAgICAgICBsZXQgY3NzQXJyID0gY3NzLnNwbGl0KCJpbklmcmFtZToiKTsKICAgICAgICAgICAgICAgIGlmIChjc3NBcnIgJiYgY3NzQXJyLmxlbmd0aCA+IDEpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgc3R5bGVFbGUgPSBpZnJhbWVEb2MuY3JlYXRlRWxlbWVudCgic3R5bGUiKTsKICAgICAgICAgICAgICAgICAgICBzdHlsZUVsZS5pbm5lckhUTUwgPSBjc3NBcnJbMV07CiAgICAgICAgICAgICAgICAgICAgaWZyYW1lRG9jLmhlYWQuYXBwZW5kQ2hpbGQoc3R5bGVFbGUpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGxvYWRlZEhhbmRsZXIoKTsKICAgICAgICAgICAgbGV0IGNvZGUgPSBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmluaXQ7CiAgICAgICAgICAgIGlmIChjb2RlKSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIG5ldyBBc3luY0Z1bmN0aW9uKCdkb2MnLCAnd2luJywgJ2lmcmFtZScsICdjbGljaycsICdlbnRlcicsICdpbnB1dCcsICcidXNlIHN0cmljdCI7JyArIGNvZGUpKGlmcmFtZURvYywgY3VySWZyYW1lLmNvbnRlbnRXaW5kb3csIGN1cklmcmFtZSwgc2VsID0+IHtjbGlja0FjdGlvbihzZWwsIGlmcmFtZURvYyl9LCBzZWwgPT4ge2VudGVyQWN0aW9uKHNlbCwgaWZyYW1lRG9jKX0sIChzZWwsIHYpID0+e2lucHV0QWN0aW9uKHNlbCwgdiwgaWZyYW1lRG9jKX0pOwogICAgICAgICAgICAgICAgfSBjYXRjaChlKSB7CiAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBsZXQgY2hlY2tUaW1lcyA9IDAsIGZpbmRQYWdlRWxlID0gZmFsc2U7CiAgICAgICAgbGV0IGZvcmNlUmVmcmVzaCA9IGUgPT4gewogICAgICAgICAgICBpZiAoaW5BY3Rpb24gfHwgIWlmcmFtZURvYykgcmV0dXJuOwogICAgICAgICAgICBpbkFjdGlvbiA9IHRydWU7CiAgICAgICAgICAgIGxldCBmb3VuZE5leHQgPSAoKSA9PiB7CiAgICAgICAgICAgICAgICBkb2N1bWVudC5yZW1vdmVFdmVudExpc3RlbmVyKCJzY3JvbGwiLCBmb3JjZVJlZnJlc2gpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHNldFRpbWVvdXQoYXN5bmMgKCkgPT4gewogICAgICAgICAgICAgICAgaW5BY3Rpb24gPSBmYWxzZTsKICAgICAgICAgICAgICAgIGlmICghcnVsZVBhcnNlci5uZXh0TGlua0hyZWYgJiYgIWlzUGF1c2UpIHsKICAgICAgICAgICAgICAgICAgICBjaGVja1RpbWVzKys7CiAgICAgICAgICAgICAgICAgICAgYXdhaXQgcnVsZVBhcnNlci5nZXROZXh0TGluayhpZnJhbWVEb2MpOwogICAgICAgICAgICAgICAgICAgIGlmIChydWxlUGFyc2VyLm5leHRMaW5rSHJlZikgewogICAgICAgICAgICAgICAgICAgICAgICBmb3VuZE5leHQoKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzTG9hZGluZykgaXNMb2FkaW5nID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChjaGVja1RpbWVzID49IDEwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvdW5kTmV4dCgpOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoY2hlY2tUaW1lcyA+PSAzICYmICFmaW5kUGFnZUVsZSkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoIXBhZ2VFbGVtZW50KSBwYWdlRWxlbWVudCA9IHJ1bGVQYXJzZXIuZ2V0UGFnZUVsZW1lbnQoaWZyYW1lRG9jLCBjdXJJZnJhbWUuY29udGVudFdpbmRvdyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghcGFnZUVsZW1lbnQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGluQWN0aW9uID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1cklmcmFtZS5jb250ZW50V2luZG93LmxvY2F0aW9uLnJlbG9hZCgpOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZmluZFBhZ2VFbGUgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAg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yA9IGZhbHNlOwogICAgICAgIHN0b3BTY3JvbGwgPSB0cnVlOwogICAgICAgIGxldCBkaXN0ID0gZGlzdFRvQm90dG9tKCk7CiAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7c3RvcFNjcm9sbCA9IGZhbHNlfSwgMzAwKTsKICAgICAgICBpZiAobG9hZGluZ0Rpdi5wYXJlbnROb2RlKSB7CiAgICAgICAgICAgIGxvYWRpbmdEaXYucGFyZW50Tm9kZS5yZW1vdmVDaGlsZChsb2FkaW5nRGl2KTsKICAgICAgICB9CiAgICAgICAgbGV0IHJhdGUgPSAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5yYXRlIHx8IHJ1bGVzRGF0YS5yYXRlIHx8IDEpOwogICAgICAgIGlmIChyYXRlICE9IDEgJiYgIWNsaWNrTW9kZSkgewogICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgIGlmIChkaXN0IDwgYm90dG9tR2FwKSB7CiAgICAgICAgICAgICAgICAgICAgbmV4dFBhZ2UoKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSwgMSk7CiAgICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIGNoZWNrQXV0b0xvYWROdW0oKSB7CiAgICAgICAgaWYgKGF1dG9Mb2FkTnVtID49IDApIHsKICAgICAgICAgICAgaWYgKGF1dG9Mb2FkTnVtICE9IDAgJiYgLS1hdXRvTG9hZE51bSA9PSAwKSB7CiAgICAgICAgICAgICAgICBhdXRvTG9hZE51bSA9IC0xOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiBuZXh0UGFnZSgpLCAxKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICB2YXIgdHJ5VGltZXMgPSAwOwogICAgYXN5bmMgZnVuY3Rpb24gbmV4dFBhZ2UoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBydWxlUGFyc2VyLmN1clNpdGVSdWxlLm1hbnVhbE1vZGUgPT0gJ3VuZGVmaW5lZCcgPyBydWxlc0RhdGEubWFudWFsTW9kZSA6IHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUubWFudWFsTW9kZSkgcmV0dXJuOwogICAgICAgIGlmIChjbGlja01vZGUpIHJldHVybjsKICAgICAgICBpZiAoaXNQYXVzZSB8fCBpc0xvYWRpbmcgfHwgZm9yY2VTdGF0ZSA9PSAxKSByZXR1cm47CiAgICAgICAgaWYgKHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuZGVsYXkpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgIGxldCBjaGVja0RlbGF5ID0gKCh0eXBlb2YgX3Vuc2FmZVdpbmRvdy5wYWdldHVhbERlbGF5PT0ndW5kZWZpbmVkJykgPyBGdW5jdGlvbignInVzZSBzdHJpY3QiOycgKyBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmRlbGF5KSA6IF91bnNhZmVXaW5kb3cucGFnZXR1YWxEZWxheSkoKTsKICAgICAgICAgICAgICAgIGlmICghY2hlY2tEZWxheSkgcmV0dXJuOwogICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgIGRlYnVnKGUpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGxldCBuZXh0TGluayA9IHJ1bGVQYXJzZXIubmV4dExpbmtIcmVmOwogICAgICAgIGlmICghbmV4dExpbmspIHsKICAgICAgICAgICAgaXNMb2FkaW5nID0gdHJ1ZTsKICAgICAgICAgICAgaWYgKGN1clBhZ2UgPT0gMSkgewogICAgICAgICAgICAgICAgYXdhaXQgcnVsZVBhcnNlci5nZXROZXh0TGluayhkb2N1bWVudCk7CiAgICAgICAgICAgICAgICBuZXh0TGluayA9IHJ1bGVQYXJzZXIubmV4dExpbmtIcmVmOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghbmV4dExpbmspIHsKICAgICAgICAgICAgICAgIGlmIChjdXJQYWdlID09IDEgJiYgKHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUucGluVXJsIHx8IHRyeVRpbWVzKysgPD0gMykpIHsKICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHtpc0xvYWRpbmcgPSBmYWxzZX0sIDUwMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaXNMb2FkaW5nID0gZmFsc2U7CiAgICAgICAgfQogICAgICAgIGxldCBwdkdhbGxlcnkgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCJzcGFuLnB2LWdhbGxlcnktY29udGFpbmVyIik7CiAgICAgICAgaWYgKHB2R2FsbGVyeSAmJiBwdkdhbGxlcnkuc3R5bGUuZGlzcGxheSAhPSAibm9uZSIpIHJldHVybjsKICAgICAgICBsZXQgaW5zZXJ0ID0gcnVsZVBhcnNlci5nZXRJbnNlcnQoKTsKICAgICAgICBpZiAoaW5zZXJ0KSB7CiAgICAgICAgICAgIGlmIChjdXJQYWdlID09IDEpIGluaXRWaWV3KCk7CiAgICAgICAgICAgIHNpZGVDb250cm9sbGVyLnNldHVwKCk7CiAgICAgICAgICAgIC8qaWYgKGN1clBhZ2UgPT0gMSkgewogICAgICAgICAgICAgICAgd2luZG93LnBvc3RNZXNzYWdlKHsKICAgICAgICAgICAgICAgICAgICBpbnNlcnQ6IGdlbmVTZWxlY3RvcihydWxlUGFyc2VyLmN1clNpdGVSdWxlLmluc2VydFBvcyA9PSAyID8gaW5zZXJ0IDogaW5zZXJ0LnBhcmVudE5vZGUsIHRydWUpLAogICAgICAgICAgICAgICAgICAgIGNvbW1hbmQ6ICdwYWdldHVhbC5pbnNlcnQnCiAgICAgICAgICAgICAgICB9LCAnKicpOwogICAgICAgICAgICB9Ki8KICAgICAgICAgICAgbGV0IGlzSnMgPSBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmFjdGlvbiA9PSAzIHx8IC9eKGphdmFzY3JpcHR8IykvLnRlc3QobmV4dExpbmsucmVwbGFjZShsb2NhdGlvbi5ocmVmLCAiIikpOwogICAgICAgICAgICBpZiAoIWlzSnMpIHsKICAgICAgICAgICAgICAgIGVtdUlmcmFtZSA9IG51bGw7CiAgICAgICAgICAgICAgICBsYXN0QWN0aXZlVXJsID0gbmV4dExpbms7CiAgICAgICAgICAgICAgICBpZiAobG9jYXRpb24ucHJvdG9jb2wgPT0gImh0dHBzOiIgJiYgL15odHRwOi8udGVzdChuZXh0TGluaykpIHsKICAgICAgICAgICAgICAgICAgICBuZXh0TGluayA9IG5leHRMaW5rLnJlcGxhY2UoL15odHRwLywgImh0dHBzIik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaXNMb2FkaW5nID0gdHJ1ZTsKICAgICAgICAgICAgaWYgKGN1clBhZ2UgIT0gMSB8fCAhaXNKcyB8fCAhcnVsZVBhcnNlci5jdXJTaXRlUnVsZS5zaW5nbGVVcmwpIHsKICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuYmVnaW5Mb2FkaW5nKGxvYWRpbmdEaXYpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxldCBzbGVlcCA9IHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuc2xlZXAgfHwgMDsKICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICBpZiAocnVsZVBhcnNlci5jdXJTaXRlUnVsZS5wYWdlRWxlbWVudEJ5SnMpIHsKICAgICAgICAgICAgICAgICAgICB2YXIgb3ZlciA9IGVsZXMgPT4gewogICAgICAgICAgICAgICAgICAgICAgICBpZiAodXJsQ2hhbmdlZCB8fCBpc1BhdXNlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsb2FkUGFnZU92ZXIoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZWxlcykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcnVsZVBhcnNlci5pbnNlcnRQYWdlKGRvY3VtZW50LCBlbGVzLCBuZXh0TGluaywgKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNyZWF0ZVBhZ2VCYXIobmV4dExpbmspOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrQXV0b0xvYWROdW0oKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0sIHRydWUpOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoIlN0b3AgYXMgbm8gcGFnZSB3aGVuIGdldCBieSBqcyIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaXNQYXVzZSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsb2FkUGFnZU92ZXIoKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgKCh0eXBlb2YgX3Vuc2FmZVdpbmRvdy5wYWdldHVhbFBhZ2VFbGVtZW50QnlKcyA9PSAndW5kZWZpbmVkJykgPyBGdW5jdGlvbigib3ZlciIsICJwYWdlTnVtIiwnInVzZSBzdHJpY3QiOycgKyBydWxlUGFyc2VyLmN1clNpdGVSdWxlLnBhZ2VFbGVtZW50QnlKcykgOiBfdW5zYWZlV2luZG93LnBhZ2V0dWFsUGFnZUVsZW1lbnRCeUpzKShvdmVyLCBjdXJQYWdlKTsKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGVidWcoZSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmICgoZm9yY2VTdGF0ZSA9PSAyIHx8IHJ1bGVQYXJzZXIuY3VyU2l0ZVJ1bGUuYWN0aW9uID09IDIpICYmICFpc0pzKSB7CiAgICAgICAgICAgICAgICAgICAgZm9yY2VJZnJhbWUobmV4dExpbmssIChpZnJhbWUpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHVybENoYW5nZWQgfHwgaXNQYXVzZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbG9hZFBhZ2VPdmVyKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHBhZ2VCYXIgPSBjcmVhdGVQYWdlQmFyKG5leHRMaW5rKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBhZ2VCYXIgJiYgaWZyYW1lICYmIGlmcmFtZS5wYXJlbnROb2RlKSBpZnJhbWUucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUocGFnZUJhciwgaWZyYW1lKTsKICAgICAgICAgICAgICAgICAgICAgICAgbG9hZFBhZ2VPdmVyKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrQXV0b0xvYWROdW0oKTsKICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKGZvcmNlU3RhdGUgPT0gMyB8fCBydWxlUGFyc2VyLmN1clNpdGVSdWxlLmFjdGlvbiA9PSAxKSAmJiAhaXNKcykgewogICAgICAgICAgICAgICAgICAgIHJlcXVlc3RGcm9tSWZyYW1lKG5leHRMaW5rLCAoZG9jLCBlbGVzKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh1cmxDaGFuZ2VkIHx8IGlzUGF1c2UpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxvYWRQYWdlT3ZlcigpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlbGVzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBydWxlUGFyc2VyLmluc2VydFBhZ2UoZG9jLCBlbGVzLCBuZXh0TGluaywgKCkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNyZWF0ZVBhZ2VCYXIobmV4dExpbmspOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNoZWNrQXV0b0xvYWROdW0oKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0sIHRydWUpOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgbG9hZFBhZ2VPdmVyKCk7CiAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmICghaXNKcykgewogICAgICAgICAgICAgICAgICAgICAgICByZXF1ZXN0RG9jKG5leHRMaW5rLCAoZWxlcykgPT4gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHVybENoYW5nZWQgfHwgaXNQYXVzZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxvYWRQYWdlT3ZlcigpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlbGVzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3JlYXRlUGFnZUJhcihuZXh0TGluayk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hlY2tBdXRvTG9hZE51bSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGxvYWRQYWdlT3ZlcigpOwogICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBlbXVQYWdlKChkb2MsIGVsZXMpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh1cmxDaGFuZ2VkIHx8IGlzUGF1c2UpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsb2FkUGFnZU92ZXIoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZWxlcykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJ1bGVQYXJzZXIuaW5zZXJ0UGFnZShkb2MsIGVsZXMsICIiLCAoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNyZWF0ZVBhZ2VCYXIobmV4dExpbmspOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGVja0F1dG9Mb2FkTnVtKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSwgdHJ1ZSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgbG9hZFBhZ2VPdmVyKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSwgc2xlZXApOwogICAgICAgIH0KICAgIH0KCiAgICBmdW5jdGlvbiBpbml0KCkgewogICAgICAgIGlmIChkb2N1bWVudC5yZWFkeVN0YXRlID09ICdsb2FkaW5nJyB8fCBkb2N1bWVudC5yZWFkeVN0YXRlID09ICd1bmluaXRpYWxpemVkJykgewogICAgICAgICAgICBsZXQgZG9tUmVhZHkgPSBlID0+IHsKICAgICAgICAgICAgICAgIGluaXRSdWxlcygoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgaW5pdFBhZ2UoKTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgZG9jdW1lbnQucmVtb3ZlRXZlbnRMaXN0ZW5lcigiRE9NQ29udGVudExvYWRlZCIsIGRvbVJlYWR5LCBmYWxzZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZG9jdW1lbnQuYWRkRXZlbnRMaXN0ZW5lcigiRE9NQ29udGVudExvYWRlZCIsIGRvbVJlYWR5LCBmYWxzZSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaW5pdFJ1bGVzKCgpID0+IHsKICAgICAgICAgICAgICAgIGluaXRQYWdlKCk7CiAgICAgICAgICAgIH0pOwogICAgICAgIH0KICAgIH0KCiAgICBmdW5jdGlvbiB2aXNpYmlsaXR5Y2hhbmdlSGFuZGxlcigpIHsKICAgICAgICBkb2N1bWVudC5yZW1vdmVFdmVudExpc3RlbmVyKCd2aXNpYmlsaXR5Y2hhbmdlJywgdmlzaWJpbGl0eWNoYW5nZUhhbmRsZXIpOwogICAgICAgIGluaXQoKTsKICAgIH0KCiAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICBpZiAoZG9jdW1lbnQuaGlkZGVuKSB7CiAgICAgICAgICAgIGRvY3VtZW50LmFkZEV2ZW50TGlzdGVuZXIoJ3Zpc2liaWxpdHljaGFuZ2UnLCB2aXNpYmlsaXR5Y2hhbmdlSGFuZGxlcik7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaW5pdCgpOwogICAgICAgIH0KICAgIH0sIDMwMCk7Cn0pKCk7Cg==
Add Comment
Please, Sign In to add comment