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ICAgICAgbWV0aG9kc1trZXldID0gMQogICAgZm9yIGJhc2UgaW4gY2wuX19iYXNlc19fOgogICAgICAgIG1ldGhvZHMudXBkYXRlKGFsbG1ldGhvZHMoYmFzZSkpICMgYWxsIHlvdXIgYmFzZSBhcmUgYmVsb25nIHRvIHVzCiAgICBmb3Iga2V5IGluIG1ldGhvZHMua2V5cygpOgogICAgICAgIG1ldGhvZHNba2V5XSA9IGdldGF0dHIoY2wsIGtleSkKICAgIHJldHVybiBtZXRob2RzCgpkZWYgX3NwbGl0X2xpc3QocywgcHJlZGljYXRlKToKICAgICIiIlNwbGl0IHNlcXVlbmNlIHMgdmlhIHByZWRpY2F0ZSwgYW5kIHJldHVybiBwYWlyIChbdHJ1ZV0sIFtmYWxzZV0pLgoKICAgIFRoZSByZXR1cm4gdmFsdWUgaXMgYSAyLXR1cGxlIG9mIGxpc3RzLAogICAgICAgIChbeCBmb3IgeCBpbiBzIGlmIHByZWRpY2F0ZSh4KV0sCiAgICAgICAgIFt4IGZvciB4IGluIHMgaWYgbm90IHByZWRpY2F0ZSh4KV0pCiAgICAiIiIKCiAgICB5ZXMgPSBbXQogICAgbm8gPSBbXQogICAgZm9yIHggaW4gczoKICAgICAgICBpZiBwcmVkaWNhdGUoeCk6CiAgICAgICAgICAgIHllcy5hcHBlbmQoeCkKICAgICAgICBlbHNlOgogICAgICAgICAgICBuby5hcHBlbmQoeCkKICAgIHJldHVybiB5ZXMsIG5vCgpkZWYgdmlzaWJsZW5hbWUobmFtZSk6CiAgICAiIiJEZWNpZGUgd2hldGhlciB0byBzaG93IGRvY3VtZW50YXRpb24gb24gYSB2YXJpYWJsZS4iIiIKICAgICMgQ2VydGFpbiBzcGVjaWFsIG5hbWVzIGFyZSByZWR1bmRhbnQuCiAgICBpZiBuYW1lIGluIFsnX19idWlsdGluc19fJywgJ19fZG9jX18nLCAnX19maWxlX18nLCAnX19wYXRoX18nLAogICAgICAgICAgICAgICAgJ19fbW9kdWxlX18nLCAnX19uYW1lX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gICAgaWYgaW5mbyBhbmQgJ2InIGluIGluZm9bMl06ICMgYmluYXJ5IG1vZHVsZXMgaGF2ZSB0byBiZSBpbXBvcnRlZAogICAgICAgICAgICB0cnk6IG1vZHVsZSA9IGltcC5sb2FkX21vZHVsZSgnX190ZW1wX18nLCBmaWxlLCBmaWxlbmFtZSwgaW5mb1sxOl0pCiAgICAgICAgICAgIGV4Y2VwdDogcmV0dXJuIE5vbmUKICAgICAgICAgICAgcmVzdWx0ID0gc3BsaXQobW9kdWxlLl9fZG9jX18gb3IgJycsICdcbicpWzBdCiAgICAgICAgICAgIGRlbCBzeXMubW9kdWxlc1snX190ZW1wX18nXQogICAgICAgIGVsc2U6ICMgdGV4dCBtb2R1bGVzIGNhbiBiZSBkaXJlY3RseSBleGFtaW5lZAogICAgICAgICAgICBsaW5lID0gZmlsZS5yZWFkbGluZSgpCiAgICAgICAgICAgIHdoaWxlIGxpbmVbOjFdID09ICcjJyBvciBub3Qgc3RyaXAobGluZSk6CiAgICAgICAgICAgICAgICBsaW5lID0gZmlsZS5yZWFkbGluZSgpCiAgICAgICAgICAgICAgICBpZiBub3QgbGluZTogYnJlYWsKICAgICAgICAgICAgbGluZSA9IHN0cmlwKGxpbmUpCiAgICAgICAgICAgIGlmIGxpbmVbOjRdID09ICdyIiIiJzogbGluZSA9IGxpbmVbMTpdCiAgICAgICAgICAgIGlmIGxpbmVbOjNdID09ICciIiInOgogICAgICAgICAgICAgICAgbGluZSA9IGxpbmVbMzpdCiAgICAgICAgICAgICAgICBpZiBsaW5lWy0xOl0gPT0gJ1xcJzogbGluZSA9IGxpbmVbOi0xXQogICAgICAgICAgICAgICAgd2hpbGUgbm90IHN0cmlwKGxpbmUpOgogICAgICAgICAgICAgICAgICAgIGxpbmUgPSBmaWxlLnJlYWRsaW5lKCkKICAgICAgICAgICAgICAgICAgICBpZiBub3QgbGluZTogYnJlYWsKICAgICAgICAgICAgICAgIHJlc3VsdCA9IHN0cmlwKHNwbGl0KGxpbmUsICciI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lY3QuaXNyb3V0aW5lKG9iamVjdCk6IHJldHVybiBzZWxmLmRvY3JvdXRpbmUoKmFyZ3MpCiAgICAgICAgZXhjZXB0IEF0dHJpYnV0ZUVycm9yOgogICAgICAgICAgICBwYXNzCiAgICAgICAgcmV0dXJuIHNlbGYuZG9jb3RoZXIoKmFyZ3MpCgogICAgZGVmIGZhaWwoc2VsZiwgb2JqZWN0LCBuYW1lPU5vbmUsICphcmdzKToKICAgICAgICAiIiJSYWlzZSBhbiBleGNlcHRpb24gZm9yIHVuaW1wbGVtZW50ZWQgdHlwZXMuIiIiCiAgICAgICAgbWVzc2FnZSA9ICJkb24ndCBrbm93IGhvdyB0byBkb2N1bWVudCBvYmplY3QlcyBvZiB0eXBlICVzIiAlICgKICAgICAgICAgICAgbmFtZSBhbmQgJyAnICsgcmVwcihuYW1lKSwgdHlwZShvYmplY3QpLl9fbmFtZV9fKQogICAgICAgIHJhaXNlIFR5cGVFcnJvciwgbWVzc2FnZQoKICAgIGRvY21vZHVsZSA9IGRvY2NsYXNzID0gZG9jcm91dGluZSA9IGRvY290aGVyID0gZmFpbAoKICAgIGRlZiBnZXRkb2Nsb2Moc2VsZiwgb2JqZWN0KToKICAgICAgICAiIiJSZXR1cm4gdGhlIGxvY2F0aW9uIG9mIG1vZHVsZSBkb2NzIG9yIE5vbmUiIiIKCiAgICAgICAgdHJ5OgogICAgICAgICAgICBmaWxlID0gaW5zcGVjdC5nZXRhYnNmaWxlKG9iamVjdCkKICAgICAgICBleGNlcHQgVHlwZUVycm9yOgogICAgICAgICAgICBmaWxlID0gJyhidWlsdC1pbiknCgogICAgICAgIGRvY2xvYyA9IG9zLmVudmlyb24uZ2V0KCJQWVRIT05ET0NTIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiaHR0cDovL3d3dy5weXRob24ub3JnL2RvYy9jdXJyZW50L2xpYiIpCiAgICAgICAgYmFzZWRpciA9IG9zLnBhdGguam9pbihzeXMuZXhlY19wcmVmaXgsICJsaWIiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgInB5dGhvbiIrc3lzLnZlcnNpb25bMDozXSkKICAgICAgICBpZiAoaXNpbnN0YW5jZShvYmplY3QsIHR5cGUob3MpKSBhbmQKICAgICAgICAgICAgKG9iamVjdC5fX25hbWVfXyBpbiAoJ2Vycm5vJywgJ2V4Y2VwdGlvbnMnLCAnZ2MnLCAnaW1wJywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ21hcnNoYWwnLCAncG9zaXgnLCAnc2lnbmFsJywgJ3N5cycsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICd0aHJlYWQnLCAnemlwaW1wb3J0Jykgb3IKICAgICAgICAgICAgIChmaWxlLnN0YXJ0c3dpdGgoYmFzZWRpcikgYW5kCiAgICAgICAgICAgICAgbm90IGZpbGUuc3RhcnRzd2l0aChvcy5wYXRoLmpvaW4oYmFzZWRpciwgJ3NpdGUtcGFja2FnZXMnKSkpKSk6CiAgICAgICAgICAgIGh0bWxmaWxlID0gIm1vZHVsZS0lcy5odG1sIiAlIG9iamVjdC5fX25hbWVfXwogICAgICAgICAgICBpZiBkb2Nsb2Muc3RhcnRzd2l0aCgiaHR0cDovLyIpOgogICAgICAgICAgICAgICAgZG9jbG9jID0gIiVzLyVzIiAlIChkb2Nsb2MucnN0cmlwKCIvIiksIGh0bWxmaWxlKQogICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgZG9jbG9jID0gb3MucGF0aC5qb2luKGRvY2xvYywgaHRtbGZpbGUpCiAgICAgICAgZWxzZToKICAgICAgICAgICAgZG9jbG9jID0gTm9uZQogICAgICAgIHJldHVybiBkb2Nsb2MKCiMgLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gSFRNTCBkb2N1bWVudGF0aW9uIGdlbmVyYXRvcgoKY2xhc3MgSFRNTFJlcHIoUmVwcik6CiAgICAiIiJDbGFzcyBmb3Igc2FmZWx5IG1ha2luZyBhbiBIVE1MIHJlcHJlc2VudGF0aW9uIG9mIGEgUHl0aG9uIG9iamVjdC4iIiIKICAgIGRlZiBfX2luaXRfXyhzZWxmKToKICAgICAgICBSZXByLl9faW5pdF9fKHNlbGYpCiAgICAgICAgc2VsZi5tYXhsaXN0ID0gc2VsZi5tYXh0dXBsZSA9IDIwCiAgICAgICAgc2VsZi5tYXhkaWN0ID0gMTAKICAgICAgICBzZWxmLm1heHN0cmluZyA9IHNlbGYubWF4b3RoZXIgPSAxMDAKCiAgICBkZWYgZXNjYXBlKHNlbGYsIHRleHQpOgogICAgICAgIHJldHVybiByZXBsYWNlKHRleHQsICcmJywgJyZhbXA7JywgJzwnLCAnJmx0OycsICc+JywgJyZndDsnKQoKICAgIGRlZiByZXByKHNlbGYsIG9iamVjdCk6CiAgICAgICAgcmV0dXJuIFJlcHIucmVwcihzZWxmLCBvYmplY3QpCgogICAgZGVmIHJlcHIxKHNlbGYsIHgsIGxldmVsKToKICAgICAgICBpZiBoYXNhdHRyKHR5cGUoeCksICdfX25hbWVfXycpOgogICAgICAgICAgICBtZXRob2RuYW1lID0gJ3JlcHJfJyArIGpvaW4oc3BsaXQodHlwZSh4KS5fX25hbWVfXyksICdfJykKICAgICAgICAgICAgaWYgaGFzYXR0cihzZWxmLCBtZXRob2RuYW1lKToKICAgICAgICAgICAgICAgIHJldHVybiBnZXRhdHRyKHNlbGYsIG1ldGhvZG5hbWUpKHgsIGxldmVsKQogICAgICAgIHJldHVybiBzZWxmLmVzY2FwZShjcmFtKHN0cmlwaWQocmVwcih4KSksIHNlbGYubWF4b3RoZXIpKQoKICAgIGRlZiByZXByX3N0cmluZyhzZWxmLCB4LCBsZXZlbCk6CiAgICAgICAgdGVzdCA9IGNyYW0oeCwgc2VsZi5tYXhzdHJpbmcpCiAgICAgICAgdGVzdHJlcHIgPSByZXByKHRlc3QpCiAgICAgICAgaWYgJ1xcJyBpbiB0ZXN0IGFuZCAnXFwnIG5vdCBpbiByZXBsYWNlKHRlc3RyZXByLCByJ1xcJywgJycpOgogICAgICAgICAgICAjIEJhY2tzbGFzaGVzIGFyZSBvbmx5IGxpdGVyYWwgaW4gdGhlIHN0cmluZyBhbmQgYXJlIG5ldmVyCiAgICAgICAgICAgICMgbmVlZGVkIHRvIG1ha2UgYW55IHNwZWNpYWwgY2hhcmFjdGVycywgc28gc2hvdyBhIHJhdyBzdHJpbmcuCiAgICAgICAgICAgIHJldHVybiAncicgKyB0ZXN0cmVwclswXSArIHNlbGYuZXNjYXBlKHRlc3QpICsgdGVzdHJlcHJbMF0KICAgICAgICByZXR1cm4gcmUuc3ViKHInKChcXFtcXGFiZm5ydHZcJyJdfFxcWzAtOV0uLnxcXHguLnxcXHUuLi4uKSspJywKICAgICAgICAgICAgICAgICAgICAgIHInPGZvbnQgY29sb3I9IiNjMDQwYzAiPlwxPC9mb250PicsCiAgICAgICAgICAgICAgICAgICAgICBzZWxmLmVzY2FwZSh0ZXN0cmVwcikpCgogICAgcmVwcl9zdHIgPSByZXByX3N0cmluZwoKICAgIGRlZiByZXByX2luc3RhbmNlKHNlbGYsIHgsIGxldmVsKToKICAgICAgICB0cnk6CiAgICAgICAgICAgIHJldHVybiBzZWxmLmVzY2FwZShjcmFtKHN0cmlwaWQocmVwcih4KSksIHNlbGYubWF4c3RyaW5nKSkKICAgICAgICBleGNlcHQ6CiAgICAgICAgICAgIHJldHVybiBzZWxmLmVzY2FwZSgnPCVzIGluc3RhbmNlPicgJSB4Ll9fY2xhc3NfXy5fX25hbWVfXykKCiAgICByZXByX3VuaWNvZGUgPSByZXByX3N0cmluZwoKY2xhc3MgSFRNTERvYyhEb2MpOgogICAgIiIiRm9ybWF0dGVyIGNsYXNzIGZvciBIVE1MIGRvY3VtZW50YXRpb24uIiIiCgogICAgIyAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tIEhUTUwgZm9ybWF0dGluZyB1dGlsaXRpZXMKCiAgICBfcmVwc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CiAgICAgICAgIiIiTWFyayB1cCBzb21lIHBsYWluIHRleHQsIGdpdmVuIGEgY29udGV4dCBvZiBzeW1ib2xzIHRvIGxvb2sgZm9yLgogICAgICAgIEVhY2ggY29udGV4dCBkaWN0aW9uYXJ5IG1hcHMgb2JqZWN0IG5hbWVzIHRvIGFuY2hvciBuYW1lcy4iIiIKICAgICAgICBlc2NhcGUgPSBlc2NhcGUgb3Igc2VsZi5lc2NhcGUKICAgICAgICByZXN1bHRzID0gW10KICAgICAgICBoZXJlID0gMAogICAgICAgIHBhdHRlcm4gPSByZS5jb21waWxlKHInXGIoKGh0dHB8ZnRwKTovL1xTK1tcdy9dfCcKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByJ1JGQ1stIF0/KFxkKyl8JwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHInUEVQWy0gXT8oXGQrKXwnCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcicoc2VsZlwuKT8oXHcrKSknKQogICAgICAgIHdoaWxlIFRydWU6CiAgICAgICAgICAgIG1hdGNoID0gcGF0dGVybi5zZWFyY2godGV4dCwgaGVyZSkKICAgICAgICAgICAgaWYgbm90IG1hdGNoOiBicmVhawogICAgICAgICAgICBzdGFydCwgZW5kID0gbWF0Y2guc3BhbigpCiAgICAgICAgICAgIHJlc3VsdHMuYXBwZW5kKGVzY2FwZSh0ZXh0W2hlcmU6c3RhcnRdKSkKCiAgICAgICAgICAgIGFsbCwgc2NoZW1lLCByZmMsIHBlcCwgc2VsZmRvdCwgbmFtZSA9IG1hdGNoLmdyb3VwcygpCiAgICAgICAgICAgIGlmIHNjaGVtZToKICAgICAgICAgICAgICAgIHVybCA9IGVzY2FwZShhbGwpLnJlcGxhY2UoJyInLCAnJnF1b3Q7JykKICAgICAgICAgICAgICAgIHJlc3VsdHMuYXBwZW5kKCc8YSBocmVmPSIlcyI+JXM8L2E+JyAlICh1cmwsIHVybCkpCiAgICAgICAgICAgIGVsaWYgcmZjOgogIC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25lKToKICAgICAgICAiIiJQcm9kdWNlIEhUTUwgZm9yIGEgY2xhc3MgdHJlZSBhcyBnaXZlbiBieSBpbnNwZWN0LmdldGNsYXNzdHJlZSgpLiIiIgogICAgICAgIHJlc3VsdCA9ICcnCiAgICAgICAgZm9yIGVudHJ5IGluIHRyZWU6CiAgICAgICAgICAgIGlmIHR5cGUoZW50cnkpIGlzIHR5cGUoKCkpOgogICAgICAgICAgICAgICAgYywgYmFzZXMgPSBlbnRyeQogICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgJzxkdD48Zm9udCBmYWNlPSJoZWx2ZXRpY2EsIGFyaWFsIj4nCiAgICAgICAgICAgICAgICByZXN1bHQgPSByZXN1bHQgKyBzZWxmLmNsYXNzbGluayhjLCBtb2RuYW1lKQogICAgICAgICAgICAgICAgaWYgYmFzZXMgYW5kIGJhc2VzICE9IChwYXJlbnQsKToKICAgICAgICAgICAgICAgICAgICBwYXJlbnRzID0gW10KICAgICAgICAgICAgICAgICAgICBmb3IgYmFzZSBpbiBiYXNlczoKICAgICAgICAgICAgICAgICAgICAgICAgcGFyZW50cy5hcHBlbmQoc2VsZi5jbGFzc2xpbmsoYmFzZSwgbW9kbmFtZSkpCiAgICAgICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgJygnICsgam9pbihwYXJlbnRzLCAnLCAnKSArICcpJwogICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgJ1xuPC9mb250PjwvZHQ+JwogICAgICAgICAgICBlbGlmIHR5cGUoZW50cnkpIGlzIHR5cGUoW10pOgogICAgICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgJzxkZD5cbiVzPC9kZD5cbicgJSBzZWxmLmZvcm1hdHRyZWUoCiAgICAgICAgICAgICAgICAgICAgZW50cnksIG1vZG5hbWUsIGMpCiAgICAgICAgcmV0dXJuICc8ZGw+XG4lczwvZGw+XG4nICUgcmVzdWx0CgogICAgZGVmIGRvY21vZHVsZShzZWxmLCBvYmplY3QsIG5hbWU9Tm9uZSwgbW9kPU5vbmUsICppZ25vcmVkKToKICAgICAgICAiIiJQcm9kdWNlIEhUTUwgZG9jdW1lbnRhdGlvbiBmb3IgYSBtb2R1bGUgb2JqZWN0LiIiIgogICAgICAgIG5hbWUgPSBvYmplY3QuX19uYW1lX18gIyBpZ25vcmUgdGhlIHBhc3NlZC1pbiBuYW1lCiAgICAgICAgcGFydHMgPSBzcGxpdChuYW1lLCAnLicpCiAgICAgICAgbGlua3MgPSBbXQogICAgICAgIGZvciBpIGluIHJhbmdlKGxlbihwYXJ0cyktMSk6CiAgICAgICAgICAgIGxpbmtzLmFwcGVuZCgKICAgICAgICAgICAgICAgICc8YSBocmVmPSIlcy5odG1sIj48Zm9udCBjb2xvcj0iI2ZmZmZmZiI+JXM8L2ZvbnQ+PC9hPicgJQogICAgICAgICAgICAgICAgKGpvaW4ocGFydHNbOmkrMV0sICcuJyksIHBhcnRzW2ldKSkKICAgICAgICBsaW5rZWRuYW1lID0gam9pbihsaW5rcyArIHBhcnRzWy0xOl0sICcuJykKICAgICAgICBoZWFkID0gJzxiaWc+PGJpZz48c3Ryb25nPiVzPC9zdHJvbmc+PC9iaWc+PC9iaWc+JyAlIGxpbmtlZG5hbWUKICAgICAgICB0cnk6CiAgICAgICAgICAgIHBhdGggPSBpbnNwZWN0LmdldGFic2ZpbGUob2JqZWN0KQogICAgICAgICAgICB1cmwgPSBwYXRoCiAgICAgICAgICAgIGlmIHN5cy5wbGF0Zm9ybSA9PSAnd2luMzInOgogICAgICAgICAgICAgICAgaW1wb3J0IG50dXJsMnBhdGgKICAgICAgICAgICAgICAgIHVybCA9IG50dXJsMnBhdGgucGF0aG5hbWUydXJsKHBhdGgpCiAgICAgICAgICAgIGZpbGVsaW5rID0gJzxhIGhyZWY9ImZpbGU6JXMiPiVzPC9hPicgJSAodXJsLCBwYXRoKQogICAgICAgIGV4Y2VwdCBUeXBlRXJyb3I6CiAgICAgICAgICAgIGZpbGVsaW5rID0gJyhidWlsdC1pbiknCiAgICAgICAgaW5mbyA9IFtdCiAgICAgICAgaWYgaGFzYXR0cihvYmplY3QsICdfX3ZlcnNpb25fXycpOgogICAgICAgICAgICB2ZXJzaW9uID0gc3RyKG9iamVjdC5fX3ZlcnNpb25fXykKICAgICAgICAgICAgaWYgdmVyc2lvbls6MTFdID09ICckJyArICdSZXZpc2lvbjogJyBhbmQgdmVyc2lvblstMTpdID09ICckJzoKICAgICAgICAgICAgICAgIHZlcnNpb24gPSBzdHJpcCh2ZXJzaW9uWzExOi0xXSkKICAgICAgICAgICAgaW5mby5hcHBlbmQoJ3ZlcnNpb24gJXMnICUgc2VsZi5lc2NhcGUodmVyc2lvbikpCiAgICAgICAgaWYgaGFzYXR0cihvYmplY3QsICdfX2RhdGVfXycpOgogICAgICAgICAgICBpbmZvLmFwcGVuZChzZWxmLmVzY2FwZShzdHIob2JqZWN0Ll9fZGF0ZV9fKSkpCiAgICAgICAgaWYgaW5mbzoKICAgICAgICAgICAgaGVhZCA9IGhlYWQgKyAnICglcyknICUgam9pbihpbmZvLCAnLCAnKQogICAgICAgIGRvY2xvYyA9IHNlbGYuZ2V0ZG9jbG9jKG9iamVjdCkKICAgICAgICBpZiBkb2Nsb2MgaXMgbm90IE5vbmU6CiAgICAgICAgICAgIGRvY2xvYyA9ICc8YnI+PGEgaHJlZj0iJShkb2Nsb2MpcyI+TW9kdWxlIERvY3M8L2E+JyAlIGxvY2FscygpCiAgICAgICAgZWxzZToKICAgICAgICAgICAgZG9jbG9jID0gJycKICAgICAgICByZXN1bHQgPSBzZWxmLmhlYWRpbmcoCiAgICAgICAgICAgIGhlYWQsICcjZmZmZmZmJywgJyM3Nzk5ZWUnLAogICAgICAgICAgICAnPGEgaHJlZj0iLiI+aW5kZXg8L2E+PGJyPicgKyBmaWxlbGluayArIGRvY2xvYykKCiAgICAgICAgbW9kdWxlcyA9IGluc3BlY3QuZ2V0bWVtYmVycyhvYmplY3QsIGluc3BlY3QuaXNtb2R1bGUpCgogICAgICAgIGNsYXNzZXMsIGNkaWN0ID0gW10sIHt9CiAgICAgICAgZm9yIGtleSwgdmFsdWUgaW4gaW5zcGVjdC5nZXRtZW1iZXJzKG9iamVjdCwgaW5zcGVjdC5pc2NsYXNzKToKICAgICAgICAgICAgaWYgKGluc3BlY3QuZ2V0bW9kdWxlKHZhbHVlKSBvciBvYmplY3QpIGlzIG9iamVjdDoKICAgICAgICAgICAgICAgIGlmIHZpc2libGVuYW1lKGtleSk6CiAgICAgICAgICAgICAgICAgICAgY2xhc3Nlcy5hcHBlbmQoKGtleSwgdmFsdWUpKQogICAgICAgICAgICAgICAgICAgIGNkaWN0W2tleV0gPSBjZGljdFt2YWx1ZV0gPSAnIycgKyBrZXkKICAgICAgICBmb3Iga2V5LCB2YWx1ZSBpbiBjbGFzc2VzOgogICAgICAgICAgICBmb3IgYmFzZSBpbiB2YWx1ZS5fX2Jhc2VzX186CiAgICAgICAgICAgICAgICBrZXksIG1vZG5hbWUgPSBiYXNlLl9fbmFtZV9fLCBiYXNlLl9fbW9kdWxlX18KICAgICAgICAgICAgICAgIG1vZHVsZSA9IHN5cy5tb2R1bGVzLmdldChtb2RuYW1lKQogICAgICAgICAgICAgICAgaWYgbW9kbmFtZSAhPSBuYW1lIGFuZCBtb2R1bGUgYW5kIGhhc2F0dHIobW9kdWxlLCBrZXkpOgogICAgICAgICAgICAgICAgICAgIGlmIGdldGF0dHIobW9kdWxlLCBrZXkpIGlzIGJhc2U6CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIG5vdCBrZXkgaW4gY2RpY3Q6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjZGljdFtrZXldID0gY2RpY3RbYmFzZV0gPSBtb2RuYW1lICsgJy5odG1sIycgKyBrZXkKICAgICAgICBmdW5jcywgZmRpY3QgPSBbXSwge30KICAgICAgICBmb3Iga2V5LCB2YWx1ZSBpbiBpbnNwZWN0LmdldG1lbWJlcnMob2JqZWN0LCBpbnNwZWN0Lmlzcm91dGluZSk6CiAgICAgICAgICAgIGlmIGluc3BlY3QuaXNidWlsdGluKHZhbHVlKSBvciBpbnNwZWN0LmdldG1vZHVsZSh2YWx1ZSkgaXMgb2JqZWN0OgogICAgICAgICAgICAgICAgaWYgdmlzaWJsZW5hbWUoa2V5KToKICAgICAgICAgICAgICAgICAgICBmdW5jcy5hcHBlbmQoKGtleSwgdmFsdWUpKQogICAgICAgICAgICAgICAgICAgIGZkaWN0W2tleV0gPSAnIy0nICsga2V5CiAgICAgICAgICAgICAgICAgICAgaWYgaW5zcGVjdC5pc2Z1bmN0aW9uKHZhbHVlKTogZmRpY3RbdmFsdWVdID0gZmRpY3Rba2V5XQogICAgICAgIGRhdGEgPSBbXQogICAgICAgIGZvciBrZXksIHZhbHVlIGluIGluc3BlY3QuZ2V0bWVtYmVycyhvYmplY3QsIGlzZGF0YSk6CiAgICAgICAgICAgIGlmIHZpc2libGVuYW1lKGtleSk6CiAgICAgICAgICAgICAgICBkYXRhLmFwcGVuZCgoa2V5LCB2YWx1ZSkpCgogICAgICAgIGRvYyA9IHNlbGYubWFya3VwKGdldGRvYyhvYmplY3QpLCBzZWxmLnByZWZvcm1hdCwgZmRpY3QsIGNkaWN0KQogICAgICAgIGRvYyA9IGRvYyBhbmQgJzx0dD4lczwvdHQ+JyAlIGRvYwogICAgICAgIHJlc3VsdCA9IHJlc3VsdCArICc8cD4lczwvcD5cbicgJSBkb2MKCiAgICAgICAgaWYgaGFzYXR0cihvYmplY3QsICdfX3BhdGhfXycpOgogICAgICAgICAgICBtb2Rwa2dzID0gW10KICAgICAgICAgICAgbW9kbmFtZXMgPSBbXQogICAgICAgICAgICBmb3IgZmlsZSBpbiBvcy5saXN0ZGlyKG9iamVjdC5fX3BhdGhfX1swXSk6CiAgICAgICAgICAgICAgICBwYXRoID0gb3MucGF0aC5qb2luKG9iamVjdC5fX3BhdGhfX1swXSwgZmlsZSkKICAgICAgICAgICAgICAgIG1vZG5hbWUgPSBpbnNwZWN0LmdldG1vZHVsZW5hbWUoZmlsZSkKICAgICAgICAgICAgICAgIGlmIG1vZG5hbWUgIT0gJ19faW5pdF9fJzoKICAgICAgICAgICAgICAgICAgICBpZiBtb2RuYW1lIGFuZCBtb2RuYW1lIG5vdCBpbiBtb2RuYW1lczoKICAgICAgICAgICAgICAgICAgICAgICAgbW9kcGtncy5hcHBlbmQoKG1vZG5hbWUsIG5hbWUsIDAsIDApKQogICAgICAgICAgICAgICAgICAgICAgICBtb2RuYW1lcy5hcHBlbmQobW9kbmFtZSkKICAgICAgICAgICAgICAgICAgICBlbGlmIGlzcGFja2FnZShwYXRoKToKICAgICAgICAgICAgICAgICAgICAgICAgbW9kcGtncy5hcHBlbmQoKGZpbGUsIG5hbWUsIDEsIDApKQogICAgICAgICAgICBtb2Rwa2dzLnNvcnQoKQogICAgICAgICAgICBjb250ZW50cyA9IHNlbGYubXVsdGljb2x1bW4obW9kcGtncywgc2VsZi5tb2Rwa2dsaW5rKQogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQgKyBzZWxmLmJpZ3NlY3Rpb24oCiAgICAgICAgICAgICAgICAnUGFja2FnZSBDb250ZW50cycsICcjZmZmZmZmJywgJyNhYTU1Y2MnLCBjb250ZW50cykKICAgICAgICBlbGlmIG1vZHVsZXM6CiAgICAgICAgICAgIGNvbnRlbnRzID0gc2VsZi5tdWx0aWNvbHVtbigKICAgICAgICAgICAgICAgIG1vZHVsZXMsIGxhbWJkYSAoa2V5LCB2YWx1ZSksIHM9c2VsZjogcy5tb2R1bGVsaW5rKHZhbHVlKSkKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgc2VsZi5iaWdzZWN0aW9uKAogICAgICAgICAgICAgICAgJ01vZHVsZXMnLCAnI2ZmZmZmJywgJyNhYTU1Y2MnLCBjb250ZW50cykKCiAgICAgICAgaWYgY2xhc3NlczoKICAgICAgICAgICAgY2xhc3NsaXN0ID0gbWFwKGxhbWJkYSAoa2V5LCB2YWx1ZSk6IHZhbHVlLCBjbGFzc2VzKQogICAgICAgICAgICBjb250ZW50cyA9IFsKICAgICAgICAgICAgICAgIHNlbGYuZm9ybWF0dHJlZShpbnNwZWN0LmdldGNsYXNzdHJlZShjbGFzc2xpc3QsIDEpLCBuYW1lKV0KICAgICAgICAgICAgZm9yIGtleSwgdmFsdWUgaW4gY2xhc3NlczoKICAgICAgICAgICAgICAgIGNvbnRlbnRzLmFwcGVuZChzZWxmLmRvY3VtZW50KHZhbHVlLCBrZXksIG5hbWUsIGZkaWN0LCBjZGljdCkpCiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdCArIHNlbGYuYmlnc2VjdGlvbigKICAgICAgICAgICAgICAgICdDbGFzc2VzJywgJyNmZmZmZmYnLCAnI2VlNzdhYScsIGpvaW4oY29udGVudHMpKQogICAgICAgIGlmIGZ1bmNzOgogICAgICAgICAgICBjb250ZW50cyA9IFtdCiAgICAgICAgICAgIGZvciBrZXksIHZhbHVlIGluIGZ1bmNzOgogICAgICAgICAgICAgICAgY29udGVudHMuYXBwZW5kKHNlbGYuZG9jdW1lbnQodmFsdWUsIGtleSwgbmFtZSwgZmRpY3QsIGNkaWN0KSkKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgc2VsZi5iaWdzZWN0aW9uKAogICAgICAgICAgICAgICAgJ0Z1bmN0aW9ucycsICcjZmZmZmZmJywgJyNlZWFhNzcnLCBqb2luKGNvbnRlbnRzKSkKICAgICAgICBpZiBkYXRhOgogICAgICAgICAgICBjb250ZW50cyA9IFtdCiAgICAgICAgICAgIGZvciBrZXksIHZhbHVlIGluIGRhdGE6CiAgICAgICAgICAgICAgICBjb250ZW50cy5hcHBlbmQoc2VsZi5kb2N1bWVudCh2YWx1ZSwga2V5KSkKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgc2VsZi5iaWdzZWN0aW9uKAogICAgICAgICAgICAgICAgJ0RhdGEnLCAnI2ZmZmZmZicsICcjNTVhYTU1Jywgam9pbihjb250ZW50cywgJzxicj5cbicpKQogICAgICAgIGlmIGhhc2F0dHIob2JqZWN0LCAnX19hdXRob3JfXycpOgogICAgICAgICAgICBjb250ZW50cyA9IHNlbGYubWFya3VwKHN0cihvYmplY3QuX19hdXRob3JfXyksIHNlbGYucHJlZm9ybWF0KQogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQgKyBzZWxmLmJpZ3NlY3Rpb24oCiAgICAgICAgICAgICAgICAnQXV0aG9yJywgJyNmZmZmZmYnLCAnIzc3OTllZScsIGNvbnRlbnRzKQogICAgICAgIGlmIGhhc2F0dHIob2JqZWN0LCAnX19jcmVkaXRzX18nKToKICAgICAgICAgICAgY29udGVudHMgPSBzZWxmLm1hcmt1cChzdHIob2JqZWN0Ll9fY3JlZGl0c19fKSwgc2VsZi5wcmVmb3JtYXQpCiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdCArIHNlbGYuYmlnc2VjdGlvbigKICAgICAgICAgICAgICAgICdDcmVkaXRzJywgJyNmZmZmZmYnLCAnIzc3OTllZScsIGNvbnRlbnRzKQoKICAgICAgICByZXR1cm4gcmVzdWx0CgogICAgZGVmIGRvY2NsYXNzKHNlbGYsIG9iamVjdCwgbmFtZT1Ob25lLCBtb2Q9Tm9uZSwgZnVuY3M9e30sIGNsYXNzZXM9e30sCiAgICAgICAgICAgICAgICAgKmlnbm9yZWQpOgogICAgICAgICIiIlByb2R1Y2UgSFRNTCBkb2N1bWVudGF0aW9uIGZvciBhIGNsYXNzIG9iamVjdC4iIiIKICAgICAgICByZWFsbmFtZSA9IG9iamVjdC5fX25hbWVfXwogICAgICAgIG5hbWUgPSBuYW1lIG9yIHJlYWxuYW1lCiAgICAgICAgYmFzZXMgPSBvYmplY3QuX19iYXNlc19fCgogICAgICAgIGNvbnRlbnRzID0gW10KICAgICAgICBwdXNoID0gY29udGVudHMuYXBwZW5kCgogICAgICAgICMgQ3V0ZSBsaXR0bGUgY2xhc3MgdG8gcHVtcCBvdXQgYSBob3Jpem9udGFsIHJ1bGUgYmV0d2VlbiBzZWN0aW9ucy4KICAgICAgICBjbGFzcyBIb3Jpem9udGFsUnVsZToKICAgICAgICAgICAgZGVmIF9faW5pdF9fKHNlbGYpOgogICAgICAgICAgICAgICAgc2VsZi5uZWVkb25lID0gMAogICAgICAgICAgICBkZWYgbWF5YmUoc2VsZik6CiAgICAgICAgICAgICAgICBpZiBzZWxmLm5lZWRvbmU6CiAgICAgICAgICAgICAgICAgICAgcHVzaCgnPGhyPlxuJykKICAgICAgICAgICAgICAgIHNlbGYubmVlZG9uZSA9IDEKICAgICAgICBociA9IEhvcml6b250YWxSdWxlKCkKCiAgICAgICAgIyBMaXN0IHRoZSBtcm8sIGlmIG5vbi10cml2aWFsLgogICAgICAgIG1ybyA9IGRlcXVlKGluc3BlY3QuZ2V0bXJvKG9iamVjdCkpCiAgICAgICAgaWYgbGVuKG1ybykgPiAyOgogICAgICAgICAgICBoci5tYXliZSgpCiAgICAgICAgICAgIHB1c2goJzxkbD48ZHQ+TWV0aG9kIHJlc29sdXRpb24gb3JkZXI6PC9kdD5cbicpCiAgICAgICAgICAgIGZvciBiYXNlIGluIG1ybzoKICAgICAgICAgICAgICAgIHB1c2goJzxkZD4lczwvZGQ+XG4nICUgc2VsZi5jbGFzc2xpbmsoYmFzZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JqZWN0Ll9fbW9kdWxlX18pKQogICAgICAgICAgICBwdXNoKCc8L2RsPlxuJykKCiAgICAgICAgZGVmIHNwaWxsKG1zZywgYXR0cnMsIHByZWRpY2F0ZSk6CiAgICAgICAgICAgIG9rLCBhdHRycyA9IF9zcGxpdF9saXN0KGF0dHJzLCBwcmVkaWNhdGUpCiAgICAgICAgICAgIGlmIG9rOgogICAgICAgICAgICAgICAgaHIubWF5YmUoKQogICAgICAgICAgICAgICAgcHVzaChtc2cpCiAgICAgICAgICAgICAgICBmb3IgbmFtZSwga2luZCwgaG9tZWNscywgdmFsdWUgaW4gb2s6CiAgICAgICAgICAgICAgICAgICAgcHVzaChzZWxmLmRvY3VtZW50KGdldGF0dHIob2JqZWN0LCBuYW1lKSwgbmFtZSwgbW9kLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmdW5jcywgY2xhc3NlcywgbWRpY3QsIG9iamVjdCkpCiAgICAgICAgICAgICAgICAgICAgcHVzaCgnXG4nKQogICAgICAgICAgICByZXR1cm4gYXR0cnMKCiAgICAgICAgZGVmIHNwaWxscHJvcGVydGllcyhtc2csIGF0dHJzLCBwcmVkaWNhdGUpOgogICAgICAgICAgICBvaywgYXR0cnMgPSBfc3BsaXRfbGlzdChhdHRycywgcHJlZGljYXRlKQogICAgICAgICAgICBpZiBvazoKICAgICAgICAgICAgICAgIGhyLm1heWJlKCkKICAgICAgICAgICAgICAgIHB1c2gobXNnKQogICAgICAgICAgICAgICAgZm9yIG5hbWUsIGtpbmQsIGhvbWVjbHMsIHZhbHVlIGluIG9rOgogICAgICAgICAgICAgICAgICAgIHB1c2goJzxkbD48ZHQ+PHN0cm9uZz4lczwvc3Ryb25nPjwvZHQ+XG4nICUgbmFtZSkKICAgICAgICAgICAgICAgICAgICBpZiB2YWx1ZS5fX2RvY19fIGlzIG5vdCBOb25lOgogICAgICAgICAgICAgICAgICAgICAgICBkb2MgPSBzZWxmLm1hcmt1cCh2YWx1ZS5fX2RvY19fLCBzZWxmLnByZWZvcm1hdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnVuY3MsIGNsYXNzZXMsIG1kaWN0KQogICAgICAgICAgICAgICAgICAgICAgICBwdXNoKCc8ZGQ+PHR0PiVzPC90dD48L2RkPlxuJyAlIGRvYykKICAgICAgICAgICAgICAgICAgICBmb3IgYXR0ciwgdGFnIGluIFsoJ2ZnZXQnLCAnPGVtPmdldDwvZW0+JyksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKCdmc2V0JywgJzxlbT5zZXQ8L2VtPicpLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICgnZmRlbCcsICc8ZW0+ZGVsZXRlPC9lbT4nKV06CiAgICAgICAgICAgICAgICAgICAgICAgIGZ1bmMgPSBnZXRhdHRyKHZhbHVlLCBhdHRyKQogICAgICAgICAgICAgICAgICAgICAgICBpZiBmdW5jIGlzIG5vdCBOb25lOgogICAgICAgICAgICAgICAgICAgICAgICAgICAgYmFzZSA9IHNlbGYuZG9jdW1lbnQoZnVuYywgdGFnLCBtb2QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmdW5jcywgY2xhc3NlcywgbWRpY3QsIG9iamVjdCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHB1c2goJzxkZD4lczwvZGQ+XG4nICUgYmFzZSkKICAgICAgICAgICAgICAgICAgICBwdXNoKCc8L2RsPlxuJykKICAgICAgICAgICAgcmV0dXJuIGF0dHJzCgogICAgICAgIGRlZiBzcGlsbGRhdGEobXNnLCBhdHRycywgcHJlZGljYXRlKToKICAgICAgICAgICAgb2ssIGF0dHJzID0gX3NwbGl0X2xpc3QoYXR0cnMsIHByZWRpY2F0ZSkKICAgICAgICAgICAgaWYgb2s6CiAgICAgICAgICAgICAgICBoci5tYXliZSgpCiAgICAgICAgICAgICAgICBwdXNoKG1zZykKICAgICAgICAgICAgICAgIGZvciBuYW1lLCBraW5kLCBob21lY2xzLCB2YWx1ZSBpbiBvazoKICAgICAgICAgICAgICAgICAgICBiYXNlID0gc2VsZi5kb2NvdGhlcihnZXRhdHRyKG9iamVjdCwgbmFtZSksIG5hbWUsIG1vZCkKICAgICAgICAgICAgICAgICAgICBpZiBjYWxsYWJsZSh2YWx1ZSkgb3IgaW5zcGVjdC5pc2RhdGFkZXNjcmlwdG9yKHZhbHVlKToKICAgICAgICAgICAgICAgICAgICAgICAgZG9jID0gZ2V0YXR0cih2YWx1ZSwgIl9fZG9jX18iLCBOb25lKQogICAgICAgICAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICAgICAgICAgIGRvYyA9IE5vbmUKICAgICAgICAgICAgICAgICAgICBpZiBkb2MgaXMgTm9uZToKICAgICAgICAgICAgICAgICAgICAgICAgcHVzaCgnPGRsPjxkdD4lczwvZGw+XG4nICUgYmFzZSkKICAgICAgICAgICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgICAgICAgICBkb2MgPSBzZWxmLm1hcmt1cChnZXRkb2ModmFsdWUpLCBzZWxmLnByZWZvcm1hdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnVuY3MsIGNsYXNzZXMsIG1kaWN0KQogICAgICAgICAgICAgICAgICAgICAgICBkb2MgPSAnPGRkPjx0dD4lczwvdHQ+JyAlIGRvYwogICAgICAgICAgICAgICAgICAgICAgICBwdXNoKCc8ZGw+PGR0PiVzJXM8L2RsPlxuJyAlIChiYXNlLCBkb2MpKQogICAgICAgICAgICAgICAgICAgIHB1c2goJ1xuJykKICAgICAgICAgICAgcmV0dXJuIGF0dHJzCgogICAgICAgIGF0dHJzID0gZmlsdGVyKGxhbWJkYSAobmFtZSwga2luZCwgY2xzLCB2YWx1ZSk6IHZpc2libGVuYW1lKG5hbWUpLAogICAgICAgICAgICAgICAgICAgICAgIGluc3BlY3QuY2xhc3NpZnlfY2xhc3NfYXR0cnMob2JqZWN0KSkKICAgICAgICBtZGljdCA9IHt9CiAgICAgICAgZm9yIGtleSwga2luZCwgaG9tZWNscywgdmFsdWUgaW4gYXR0cnM6CiAgICAgICAgICAgIG1kaWN0W2tleV0gPSBhbmNob3IgPSAnIycgKyBuYW1lICsgJy0nICsga2V5CiAgICAgICAgICAgIHZhbHVlID0gZ2V0YXR0cihvYmplY3QsIGtleSkKICAgICAgICAgICAgdHJ5OgogICAgICAgICAgICAgICAgIyBUaGUgdmFsdWUgbWF5IG5vdCBiZSBoYXNoYWJsZSAoZS5nLiwgYSBkYXRhIGF0dHIgd2l0aAogICAgICAgICAgICAgICAgIyBhIGRpY3Qgb3IgbGlzdCB2YWx1ZSkuCiAgICAgICAgICAgICAgICBtZGljdFt2YWx1ZV0gPSBhbmNob3IKICAgICAgICAgICAgZXhjZXB0IFR5cGVFcnJvcjoKICAgICAgICAgICAgICAgIHBhc3MKCiAgICAgICAgd2hpbGUgYXR0cnM6CiAgICAgICAgICAgIGlmIG1ybzoKICAgICAgICAgICAgICAgIHRoaXNjbGFzcyA9IG1yby5wb3BsZWZ0KCkKICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgIHRoaXNjbGFzcyA9IGF0dHJzWzBdWzJdCiAgICAgICAgICAgIGF0dHJzLCBpbmhlcml0ZWQgPSBfc3BsaXRfbGlzdChhdHRycywgbGFtYmRhIHQ6IHRbMl0gaXMgdGhpc2NsYXNzKQoKICAgICAgICAgICAgaWYgdGhpc2NsYXNzIGlzIF9fYnVpbHRpbl9fLm9iamVjdDoKICAgICAgICAgICAgICAgIGF0dHJzID0gaW5oZXJpdGVkCiAgICAgICAgICAgICAgICBjb250aW51ZQogICAgICAgICAgICBlbGlmIHRoaXNjbGFzcyBpcyBvYmplY3Q6CiAgICAgICAgICAgICAgICB0YWcgPSAnZGVmaW5lZCBoZXJlJwogICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgdGFnID0gJ2luaGVyaXRlZCBmcm9tICVzJyAlIHNlbGYuY2xhc3NsaW5rKHRoaXNjbGFzcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYmplY3QuX19tb2R1bGVfXykKICAgICAgICAgICAgdGFnICs9ICc6PGJyPlxuJwoKICAgICAgICAgICAgIyBTb3J0IGF0dHJzIGJ5IG5hbWUuCiAgICAgICAgICAgIGF0dHJzLnNvcnQoa2V5PWxhbWJkYSB0OiB0WzBdKQoKICAgICAgICAgICAgIyBQdW1wIG91dCB0aGUgYXR0cnMsIHNlZ3JlZ2F0ZWQgYnkga2luZC4KICAgICAgICAgICAgYXR0cnMgPSBzcGlsbCgnTWV0aG9kcyAlcycgJSB0YWcsIGF0dHJzLAogICAgICAgICAgICAgICAgICAgICAgICAgIGxhbWJkYSB0OiB0WzFdID09ICdtZXRob2QnKQogICAgICAgICAgICBhdHRycyA9IHNwaWxsKCdDbGFzcyBtZXRob2RzICVzJyAlIHRhZywgYXR0cnMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgbGFtYmRhIHQ6IHRbMV0gPT0gJ2NsYXNzIG1ldGhvZCcpCiAgICAgICAgICAgIGF0dHJzID0gc3BpbGwoJ1N0YXRpYyBtZXRob2RzICVzJyAlIHRhZywgYXR0cnMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgbGFtYmRhIHQ6IHRbMV0gPT0gJ3N0YXRpYyBtZXRob2QnKQogICAgICAgICAgICBhdHRycyA9IHNwaWxscHJvcGVydGllcygnUHJvcGVydGllcyAlcycgJSB0YWcsIGF0dHJzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsYW1iZGEgdDogdFsxXSA9PSAncHJvcGVydHknKQogICAgICAgICAgICBhdHRycyA9IHNwaWxsZGF0YSgnRGF0YSBhbmQgb3RoZXIgYXR0cmlidXRlcyAlcycgJSB0YWcsIGF0dHJzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsYW1iZGEgdDogdFsxXSA9PSAnZGF0YScpCiAgICAgICAgICAgIGFzc2VydCBhdHRycyA9PSBbXQogICAgICAgICAgICBhdHRycyA9IGluaGVyaXRlZAoKICAgICAgICBjb250ZW50cyA9ICcnLmpvaW4oY29udGVudHMpCgogICAgICAgIGlmIG5hbWUgPT0gcmVhbG5hbWU6CiAgICAgICAgICAgIHRpdGxlID0gJzxhIG5hbWU9IiVzIj5jbGFzcyA8c3Ryb25nPiVzPC9zdHJvbmc+PC9hPicgJSAoCiAgICAgICAgICAgICAgICBuYW1lLCByZWFsbmFtZSkKICAgICAgICBlbHNlOgogICAgICAgICAgICB0aX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XRob2Qgb2JqZWN0LiIiIgogICAgICAgIHJlYWxuYW1lID0gb2JqZWN0Ll9fbmFtZV9fCiAgICAgICAgbmFtZSA9IG5hbWUgb3IgcmVhbG5hbWUKICAgICAgICBhbmNob3IgPSAoY2wgYW5kIGNsLl9fbmFtZV9fIG9yICcnKSArICctJyArIG5hbWUKICAgICAgICBub3RlID0gJycKICAgICAgICBza2lwZG9jcyA9IDAKICAgICAgICBpZiBpbnNwZWN0LmlzbWV0aG9kKG9iamVjdCk6CiAgICAgICAgICAgIGltY2xhc3MgPSBvYmplY3QuaW1fY2xhc3MKICAgICAgICAgICAgaWYgY2w6CiAgICAgICAgICAgICAgICBpZiBpbWNsYXNzIGlzIG5vdCBjbDoKICAgICAgICAgICAgICAgICAgICBub3RlID0gJyBmcm9tICcgKyBzZWxmLmNsYXNzbGluayhpbWNsYXNzLCBtb2QpCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICBpZiBvYmplY3QuaW1fc2VsZjoKICAgICAgICAgICAgICAgICAgICBub3RlID0gJyBtZXRob2Qgb2YgJXMgaW5zdGFuY2UnICUgc2VsZi5jbGFzc2xpbmsoCiAgICAgICAgICAgICAgICAgICAgICAgIG9iamVjdC5pbV9zZWxmLl9fY2xhc3NfXywgbW9kKQogICAgICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICAgICBub3RlID0gJyB1bmJvdW5kICVzIG1ldGhvZCcgJSBzZWxmLmNsYXNzbGluayhpbWNsYXNzLG1vZCkKICAgICAgICAgICAgb2JqZWN0ID0gb2JqZWN0LmltX2Z1bmMKCiAgICAgICAgaWYgbmFtZSA9PSByZWFsbmFtZToKICAgICAgICAgICAgdGl0bGUgPSAnPGEgbmFtZT0iJXMiPjxzdHJvbmc+JXM8L3N0cm9uZz48L2E+JyAlIChhbmNob3IsIHJlYWxuYW1lKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIGlmIChjbCBhbmQgcmVhbG5hbWUgaW4gY2wuX19kaWN0X18gYW5kCiAgICAgICAgICAgICAgICBjbC5fX2RpY3RfX1tyZWFsbmFtZV0gaXMgb2JqZWN0KToKICAgICAgICAgICAgICAgIHJlYWxsaW5rID0gJzxhIGhyZWY9IiMlcyI+JXM8L2E+JyAlICgKICAgICAgICAgICAgICAgICAgICBjbC5fX25hbWVfXyArICctJyArIHJlYWxuYW1lLCByZWFsbmFtZSkKICAgICAgICAgICAgICAgIHNraXBkb2NzID0gMQogICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgcmVhbGxpbmsgPSByZWFsbmFtZQogICAgICAgICAgICB0aXRsZSA9ICc8YSBuYW1lPSIlcyI+PHN0cm9uZz4lczwvc3Ryb25nPjwvYT4gPSAlcycgJSAoCiAgICAgICAgICAgICAgICBhbmNob3IsIG5hbWUsIHJlYWxsaW5rKQogICAgICAgIGlmIGluc3BlY3QuaXNmdW5jdGlvbihvYmplY3QpOgogICAgICAgICAgICBhcmdzLCB2YXJhcmdzLCB2YXJrdywgZGVmYXVsdHMgPSBpbnNwZWN0LmdldGFyZ3NwZWMob2JqZWN0KQogICAgICAgICAgICBhcmdzcGVjID0gaW5zcGVjdC5mb3JtYXRhcmdzcGVjKAogICAgICAgICAgICAgICAgYXJncywgdmFyYXJncywgdmFya3csIGRlZmF1bHRzLCBmb3JtYXR2YWx1ZT1zZWxmLmZvcm1hdHZhbHVlKQogICAgICAgICAgICBpZiByZWFsbmFtZSA9PSAnPGxhbWJkYT4nOgogICAgICAgICAgICAgICAgdGl0bGUgPSAnPHN0cm9uZz4lczwvc3Ryb25nPiA8ZW0+bGFtYmRhPC9lbT4gJyAlIG5hbWUKICAgICAgICAgICAgICAgIGFyZ3NwZWMgPSBhcmdzcGVjWzE6LTFdICMgcmVtb3ZlIHBhcmVudGhlc2VzCiAgICAgICAgZWxzZToKICAgICAgICAgICAgYXJnc3BlYyA9ICcoLi4uKScKCiAgICAgICAgZGVjbCA9IHRpdGxlICsgYXJnc3BlYyArIChub3RlIGFuZCBzZWxmL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tLS0tLS0tLS0tLS0tLS0tLS0tLSB0ZXh0IGRvY3VtZW50YXRpb24gZ2VuZXJhdG9yCgpjbGFzcyBUZXh0UmVwcihSZXByKToKICAgICIiIkNsYXNzIGZvciBzYWZlbHkgbWFraW5nIGEgdGV4dCByZXByZXNlbnRhdGlvbiBvZiBhIFB5dGhvbiBvYmplY3QuIiIiCiAgICBkZWYgX19pbml0X18oc2VsZik6CiAgICAgICAgUmVwci5fX2luaXRfXyhzZWxmKQogICAgICAgIHNlbGYubWF4bGlzdCA9IHNlbGYubWF4dHVwbGUgPSAyMAogICAgICAgIHNlbGYubWF4ZGljdCA9IDEwCiAgICAgICAgc2VsZi5tYXhzdHJpbmcgPSBzZWxmLm1heG90aGVyID0gMTAwCgogICAgZGVmIHJlcHIxKHNlbGYsIHgsIGxldmVsKToKICAgICAgICBpZiBoYXNhdHRyKHR5cGUoeCksICdfX25hbWVfXycpOgogICAgICAgICAgICBtZXRob2RuYW1lID0gJ3JlcHJfJyArIGpvaW4oc3BsaXQodHlwZSh4KS5fX25hbWVfXyksICdfJykKICAgICAgICAgICAgaWYgaGFzYXR0cihzZWxmLCBtZXRob2RuYW1lKToKICAgICAgICAgICAgICAgIHJldHVybiBnZXRhdHRyKHNlbGYsIG1ldGhvZG5hbWUpKHgsIGxldmVsKQogICAgICAgIHJldHVybiBjcmFtKHN0cmlwaWQocmVwcih4KSksIHNlbGYubWF4b3RoZXIpCgogICAgZGVmIHJlcHJfc3RyaW5nKHNlbGYsIHgsIGxldmVsKToKICAgICAgICB0ZXN0ID0gY3JhbSh4LCBzZWxmLm1heHN0cmluZykKICAgICAgICB0ZXN0cmVwciA9IHJlcHIodGVzdCkKICAgICAgICBpZiAnXFwnIGluIHRlc3QgYW5kICdcXCcgbm90IGluIHJlcGxhY2UodGVzdHJlcHIsIHInXFwnLCAnJyk6CiAgICAgICAgICAgICMgQmFja3NsYXNoZXMgYXJlIG9ubHkgbGl0ZXJhbCBpbiB0aGUgc3RyaW5nIGFuZ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a2V5KToKICAgICAgICAgICAgICAgIGRhdGEuYXBwZW5kKChrZXksIHZhbHVlKSkKCiAgICAgICAgaWYgaGFzYXR0cihvYmplY3QsICdfX3BhdGhfXycpOgogICAgICAgICAgICBtb2Rwa2dzID0gW10KICAgICAgICAgICAgZm9yIGZpbGUgaW4gb3MubGlzdGRpcihvYmplY3QuX19wYXRoX19bMF0pOgogICAgICAgICAgICAgICAgcGF0aCA9IG9zLnBhdGguam9pbihvYmplY3QuX19wYXRoX19bMF0sIGZpbGUpCiAgICAgICAgICAgICAgICBtb2RuYW1lID0gaW5zcGVjdC5nZXRtb2R1bGVuYW1lKGZpbGUpCiAgICAgICAgICAgICAgICBpZiBtb2RuYW1lICE9ICdfX2luaXRfXyc6CiAgICAgICAgICAgICAgICAgICAgaWYgbW9kbmFtZSBhbmQgbW9kbmFtZSBub3QgaW4gbW9kcGtnczoKICAgICAgICAgICAgICAgICAgICAgICAgbW9kcGtncy5hcHBlbmQobW9kbmFtZSkKICAgICAgICAgICAgICAgICAgICBlbGlmIGlzcGFja2FnZShwYXRoKToKICAgICAgICAgICAgICAgICAgICAgICAgbW9kcGtncy5hcHBlbmQoZmlsZSArICcgKHBhY2thZ2UpJykKICAgICAgICAgICAgbW9kcGtncy5zb3J0KCkKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0ICsgc2VsZi5zZWN0aW9uKAogICAgICAgICAgICAgICAgJ1BBQ0tBR0UgQ09OVEVOVFMnLCBqb2luKG1vZHBrZ3MsICdcbicpKQoKICAgICAgICBpZiBjbGFzc2VzOgogICAgICAgICAgICBjbGFzc2xpc3QgPSBtYXAobGFtYmRhIChrZXksIHZhbHVlKTogdmFsdWUsIGNsYXNzZXMpCiAgICAgICAgICAgIGNvbnRlbnRzID0gW3NlbGYuZm9ybWF0dHJlZSgKICAgICAgICAgICAgICAgIGluc3BlY3QuZ2V0Y2xhc3N0cmVlKGNsYXNzbGlzdCwgMSksIG5hbWUpXQogICAgICAgICAgICBmb3Iga2V5LCB2YWx1ZSBpbiBjbGFzc2VzOgogICAgICAgICAgICAgICAgY29udGVudHMuYXBwZW5kKHNlbGYuZG9jdW1lbnQodmFsdWUsIGtleSwgbmFtZSkpCiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdCArIHNlbGYuc2VjdGlvbignQ0xBU1NFUycsIGpvaW4oY29udGVudHMsICdcbicpKQoKICAgICAgICBpZiBmdW5jczoKICAgICAgICAgICAgY29udGVudHMgPSBbXQogICAgICAgICAgICBmb3Iga2V5LCB2YWx1ZSBpbiBmdW5jczoKICAgICAgICAgICAgICAgIGNvbnRlbnRzLmFwcGVuZChzZWxmLmRvY3VtZW50KHZhbHVlLCBrZXksIG5hbWUpKQogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQgKyBzZWxmLnNlY3Rpb24oJ0ZVTkNUSU9OUycsIGpvaW4oY29udGVudHMsICdcbicpKQoKICAgICAgICBpZiBkYXRhOgogICAgICAgICAgICBjb250ZW50cyA9IFtdCiAgICAgICAgICAgIGZvciBrZXksIHZhbHVlIGluIGRhdGE6CiAgICAgICAgICAgICAgICBjb250ZW50cy5hcHBlbmQoc2VsZi5kb2NvdGhlcih2YWx1ZSwga2V5LCBuYW1lLCA3MCkpCiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdCArIHNlbGYuc2VjdGlvbignREFUQScsIGpvaW4oY29udGVudHMsICdcbicpKQoKICAgICAgICBpZiBoYXNhdHRyKG9iamVjdCwgJ19fdmVyc2lvbl9fJyk6CiAgICAgICAgICAgIHZlcnNpb24gPSBzdHIob2JqZWN0Ll9fdmVyc2lvbl9fKQogICAgICAgICAgICBpZiB2ZXJzaW9uWzoxMV0gPT0gJyQnICsgJ1JldmlzaW9uOiAnIGFuZCB2ZXJzaW9uWy0xOl0gPT0gJyQnOgogICAgICAgICAgICAgICAgdmVyc2lvbiA9IHN0cmlwKHZlcnNpb25bMTE6LTFdKQogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQgKyBzZWxmLn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bGFzcyAnICsgcmVhbG5hbWUKICAgICAgICBpZiBiYXNlczoKICAgICAgICAgICAgcGFyZW50cyA9IG1hcChtYWtlbmFtZSwgYmFzZXMpCiAgICAgICAgICAgIHRpdGxlID0gdGl0bGUgKyAnKCVzKScgJSBqb2luKHBhcmVudHMsICcsICcpCgogICAgICAgIGRvYyA9IGdldGRvYyhvYmplY3QpCiAgICAgICAgY29udGVudHMgPSBkb2MgYW5kIFtkb2MgKyAnXG4nXSBvciBbXQogICAgICAgIHB1c2ggPSBjb250ZW50cy5hcHBlbmQKCiAgICAgICAgIyBMaXN0IHRoZSBtcm8sIGlmIG5vbi10cml2aWFsLgogICAgICAgIG1ybyA9IGRlcXVlKGluc3BlY3QuZ2V0bXJvKG9iamVjdCkpCiAgICAgICAgaWYgbGVuKG1ybykgPiAyOgogICAgICAgICAgICBwdXNoKCJNZXRob2QgcmVzb2x1dGlvbiBvcmRlcjoiKQogICAgICAgICAgICBmb3IgYmFzZSBpbiBtcm86CiAgICAgICAgICAgICAgICBwdXNoKCcgICAgJyArIG1ha2VuYW1lKGJhc2UpKQogICAgICAgICAgICBwdXNoKCcnKQoKICAgICAgICAjIEN1dGUgbGl0dGxlIGNsYXNzIHRvIHB1bXAgb3V0IGEgaG9yaXpvbnRhbCBydWxlIGJldHdlZW4gc2VjdGlvbnMuCiAgICAgICAgY2xhc3MgSG9yaXpvbnRhbFJ1bGU6CiAgICAgICAgICAgIGRlZiBfX2luaXRfXyhzZWxmKToKICAgICAgICAgICAgICAgIHNlbGYubmVlZG9uZSA9IDAKICAgICAgICAgICAgZGVmIG1heWJlKHNlbGYpOgogICAgICAgICAgICAgICAgaWYgc2VsZi5uZWVkb25lOgogICAgICAgICAgICAgICAgICAgIHB1c2goJy0nICogNzApCiAgICAgICAgICAgICAgICBzZWxmLm5lZWRvbmUgPSAxCiAgICAgICAgaHIgPSBIb3Jpem9udGFsUnVsZSgpCgogICAgICAgIGRlZiBzcGlsbChtc2csIGF0dHJzLCBwcmVkaWNhdGUpOgogICAgICAgICAgICBvaywgYXR0cnMgPSBfc3BsaXRfbGlzdChhdHRycywgcHJlZGljYXRlKQogICAgICAgICAgICBpZiBvazoKICAgICAgICAgICAgICAgIGhyLm1heWJlKCkKICAgICAgICAgICAgICAgIHB1c2gobXNnKQogICAgICAgICAgICAgICAgZm9yIG5hbWUsIGtpbmQsIGhvbWVjbHMsIHZhbHVlIGluIG9rOgogICAgICAgICAgICAgICAgICAgIHB1c2goc2VsZi5kb2N1bWVudChnZXRhdHRyKG9iamVjdCwgbmFtZSksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5hbWUsIG1vZCwgb2JqZWN0KSkKICAgICAgICAgICAgcmV0dXJuIGF0dHJzCgogICAgICAgIGRlZiBzcGlsbHByb3BlcnRpZXMobXNnLCBhdHRycywgcHJlZGljYXRlKToKICAgICAgICAgICAgb2ssIGF0dHJzID0gX3NwbGl0X2xpc3QoYXR0cnMsIHByZWRpY2F0ZSkKICAgICAgICAgICAgaWYgb2s6CiAgICAgICAgICAgICAgICBoci5tYXliZSgpCiAgICAgICAgICAgICAgICBwdXNoKG1zZykKICAgICAgICAgICAgICAgIGZvciBuYW1lLCBraW5kLCBob21lY2xzLCB2YWx1ZSBpbiBvazoKICAgICAgICAgICAgICAgICAgICBwdXNoKG5hbWUpCiAgICAgICAgICAgICAgICAgICAgbmVlZF9ibGFua19hZnRlcl9kb2MgPSAwCiAgICAgICAgICAgICAgICAgICAgZG9jID0gZ2V0ZG9jKHZhbHVlKSBvciAnJwogICAgICAgICAgICAgICAgICAgIGlmIGRvYzoKICAgICAgICAgICAgICAgICAgICAgICAgcHVzaChzZWxmLmluZGVudChkb2MpKQogICAgICAgICAgICAgICAgICAgICAgICBuZWVkX2JsYW5rX2FmdGVyX2RvYyA9IDEKICAgICAgICAgICAgICAgICAgICBmb3IgYXR0ciwgdGFnIGluIFsoJ2ZnZXQnLCAnPGdldD4nKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoJ2ZzZXQnLCAnPHNldD4nKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoJ2ZkZWwnLCAnPGRlbGV0ZT4nKV06CiAgICAgICAgICAgICAgICAgICAgICAgIGZ1bmMgPSBnZXRhdHRyKHZhbHVlLCBhdHRyKQogICAgICAgICAgICAgICAgICAgICAgICBpZiBmdW5jIGlzIG5vdCBOb25lOgogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgbmVlZF9ibGFua19hZnRlcl9kb2M6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHVzaCgnJykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZWVkX2JsYW5rX2FmdGVyX2RvYyA9IDAKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJhc2UgPSBzZWxmLmRvY3VtZW50KGZ1bmMsIHRhZywgbW9kKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgcHVzaChzZWxmLmluZGVudChiYXNlKSkKICAgICAgICAgICAgcmV0dXJuIGF0dHJzCgogICAgICAgIGRlZiBzcGlsbGRhdGEobXNnLCBhdHRycywgcHJlZGljYXRlKToKICAgICAgICAgICAgb2ssIGF0dHJzID0gX3NwbGl0X2xpc3QoYXR0cnMsIHByZWRpY2F0ZSkKICAgICAgICAgICAgaWYgb2s6CiAgICAgICAgICAgICAgICBoci5tYXliZSgpCiAgICAgICAgICAgICAgICBwdXNoKG1zZykKICAgICAgICAgICAgICAgIGZvciBuYW1lLCBraW5kLCBob21lY2xzLCB2YWx1ZSBpbiBvazoKICAgICAgICAgICAgICAgICAgICBpZiBjYWxsYWJsZSh2YWx1ZSkgb3IgaW5zcGVjdC5pc2RhdGFkZXNjcmlwdG9yKHZhbHVlKToKICAgICAgICAgICAgICAgICAgICAgICAgZG9jID0gZ2V0YXR0cih2YWx1ZSwgIl9fZG9jX18iLCBOb25lKQogICAgICAgICAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICAgICAgICAgIGRvYyA9IE5vbmUKICAgICAgICAgICAgICAgICAgICBwdXNoKHNlbGYuZG9jb3RoZXIoZ2V0YXR0cihvYmplY3QsIG5hbWUpLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuYW1lLCBtb2QsIDcwLCBkb2MpICsgJ1xuJykKICAgICAgICAgICAgcmV0dXJuIGF0dHJzCgogICAgICAgIGF0dHJzID0gZmlsdGVyKGxhbWJkYSAobmFtZSwga2luZCwgY2xzLCB2YWx1ZSk6IHZpc2libGVuYW1lKG5hbWUpLAogICAgICAgICAgICAgICAgICAgICAgIGluc3BlY3QuY2xhc3NpZnlfY2xhc3NfYXR0cnMob2JqZWN0KSkKICAgICAgICB3aGlsZSBhdHRyczoKICAgICAgICAgICAgaWYgbXJvOgogICAgICAgICAgICAgICAgdGhpc2NsYXNzID0gbXJvLnBvcGxlZnQoKQogICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgdGhpc2NsYXNzID0gYXR0cnNbMF1bMl0KICAgICAgICAgICAgYXR0cnMsIGluaGVyaXRlZCA9IF9zcGxpdF9saXN0KGF0dHJzLCBsYW1iZGEgdDogdFsyXSBpcyB0aGlzY2xhc3MpCgogICAgICAgICAgICBpZiB0aGlzY2xhc3MgaXMgX19idWlsdGluX18ub2JqZWN0OgogICAgICAgICAgICAgICAgYXR0cnMgPSBpbmhlcml0ZWQKICAgICAgICAgICAgICAgIGNvbnRpbnVlCiAgICAgICAgICAgIGVsaWYgdGhpc2NsYXNzIGlzIG9iamVjdDoKICAgICAgICAgICAgICAgIHRhZyA9ICJkZWZpbmVkIGhlcmUiCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICB0YWcgPSAiaW5oZXJpdGVkIGZyb20gJXMiICUgY2xhc3NuYW1lKHRoaXNjbGFzcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JqZWN0Ll9fbW9kdWxlX18pCiAgICAgICAgICAgIGZpbHRlcihsYW1iZGEgdDogbm90IHRbMF0uc3RhcnRzd2l0aCgnXycpLCBhdHRycykKCiAgICAgICAgICAgICMgU29ydCBhdHRycyBieSBuYW1lLgogICAgICAgICAgICBhdHRycy5zb3J0KCkKCiAgICAgICAgICAgICMgUHVtcCBvdXQgdGhlIGF0dHJzLCBzZWdyZWdhdGVkIGJ5IGtpbmQuCiAgICAgICAgICAgIGF0dHJzID0gc3BpbGwoIk1ldGhvZHMgJXM6XG4iICUgdGFnLCBhdHRycywKICAgICAgICAgICAgICAgICAgICAgICAgICBsYW1iZGEgdDogdFsxXSA9PSAnbWV0aG9kJykKICAgICAgICAgICAgYXR0cnMgPSBzcGlsbCgiQ2xhc3MgbWV0aG9kcyAlczpcbiIgJSB0YWcsIGF0dHJzLAogICAgICAgICAgICAgICAgICAgICAgICAgIGxhbWJkYSB0OiB0WzFdID09ICdjbGFzcyBtZXRob2QnKQogICAgICAgICAgICBhdHRycyA9IHNwaWxsKCJTdGF0aWMgbWV0aG9kcyAlczpcbiIgJSB0YWcsIGF0dHJzLAogICAgICAgICAgICAgICAgICAgICAgICAgIGxhbWJkYSB0OiB0WzFdID09ICdzdGF0aWMgbWV0aG9kJykKICAgICAgICAgICAgYXR0cnMgPSBzcGlsbHByb3BlcnRpZXMoIlByb3BlcnRpZXMgJXM6XG4iICUgdGFnLCBhdHRycywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGFtYmRhIHQ6IHRbMV0gPT0gJ3Byb3BlcnR5JykKICAgICAgICAgICAgYXR0cnMgPSBzcGlsbGRhdGEoIkRhdGEgYW5kIG90aGVyIGF0dHJpYnV0ZXMgJXM6XG4iICUgdGFnLCBhdHRycywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGFtYmRhIHQ6IHRbMV0gPT0gJ2RhdGEnKQogICAgICAgICAgICBhc3NlcnQgYXR0cnMgPT0gW10KICAgICAgICAgICAgYXR0cnMgPSBpbmhlcml0ZWQKCiAgICAgICAgY29udGVudHMgPSAnXG4nLmpvaW4oY29udGVudHMpCiAgICAgICAgaWYgbm90IGNvbnRlbnRzOgogICAgICAgICAgICByZXR1cm4gdGl0bGUgKyAnXG4nCiAgICAgICAgcmV0dXJuIHRpdGxlICsgJ1xuJyArIHNlbGYuaW5kZW50KHJzdHJpcChjb250ZW50cyksICcgfCAgJykgKyAnXG4nCgogICAgZGVmIGZvcm1hdHZhbHVlKHNlbGYsIG9iamVjdCk6CiAgICAgICAgIiIiRm9ybWF0IGFuIGFyZ3VtZW50IGRlZmF1bHQgdmFsdWUgYXMgdGV4dC4iIiIKICAgICAgICByZXR1cm4gJz0nICsgc2VsZi5yZXByKG9iamVjdCkKCiAgICBkZWYgZG9jcm91dGluZShzZWxmLCBvYmplY3QsIG5hbWU9Tm9uZSwgbW9kPU5vbmUsIGNsPU5vbmUpOgogICAgICAgICIiIlByb2R1Y2UgdGV4dCBkb2N1bWVudGF0aW9uIGZvciBhIGZ1bmN0aW9uIG9yIG1ldGhvZCBvYmplY3QuIiIiCiAgICAgICAgcmVhbG5hbWUgPSBvYmplY3QuX19uYW1lX18KICAgICAgICBuYW1lID0gbmFtZSBvciByZWFsbmFtZQogICAgICAgIG5vdGUgPSAnJwogICAgICAgIHNraXBkb2NzID0gMAogICAgICAgIGlmIGluc3BlY3QuaXNtZXRob2Qob2JqZWN0KToKICAgICAgICAgICAgaW1jbGFzcyA9IG9iamVjdC5pbV9jbGFzcwogICAgICAgICAgICBpZiBjbDoKICAgICAgICAgICAgICAgIGlmIGltY2xhc3MgaXMgbm90IGNsOgogICAgICAgICAgICAgICAgICAgIG5vdGUgPSAnIGZyb20gJyArIGNsYXNzbmFtZShpbWNsYXNzLCBtb2QpCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICBpZiBvYmplY3QuaW1fc2VsZjoKICAgICAgICAgICAgICAgICAgICBub3RlID0gJyBtZXRob2Qgb2YgJXMgaW5zdGFuY2UnICUgY2xhc3NuYW1lKAogICAgICAgICAgICAgICAgICAgICAgICBvYmplY3QuaW1fc2VsZi5fX2NsYXNzX18sIG1vZCkKICAgICAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICAgICAgbm90ZSA9ICcgdW5ib3VuZCAlcyBtZXRob2QnICUgY2xhc3NuYW1lKGltY2xhc3MsbW9kKQogICAgICAgICAgICBvYmplY3QgPSBvYmplY3QuaW1fZnVuYwoKICAgICAgICBpZiBuYW1lID09IHJlYWxuYW1lOgogICAgICAgICAgICB0aXRsZSA9IHNlbGYuYm9sZChyZWFsbmFtZSkKICAgICAgICBlbHNlOgogICAgICAgICAgICBpZiAoY2wgYW5kIHJlYWxuYW1lIGluIGNsLl9fZGljdF9fIGFuZAogICAgICAgICAgICAgICAgY2wuX19kaWN0X19bcmVhbG5hbWVdIGlzIG9iamVjdCk6CiAgICAgICAgICAgICAgICBza2lwZG9jcyA9IDEKICAgICAgICAgICAgdGl0bGUgPSBzZWxmLmJvbGQobmFtZSkgKyAnID0gJyArIHJlYWxuYW1lCiAgICAgICAgaWYgaW5zcGVjdC5pc2Z1bmN0aW9uKG9iamVjdCk6CiAgICAgICAgICAgIGFyZ3MsIHZhcmFyZ3MsIHZhcmt3LCBkZWZhdWx0cyA9IGluc3BlY3QuZ2V0YXJnc3BlYyhvYmplY3QpCiAgICAgICAgICAgIGFyZ3NwZWMgPSBpbnNwZWN0LmZvcm1hdGFyZ3NwZWMoCiAgICAgICAgICAgICAgICBhcmdzLCB2YXJhcmdzLCB2YXJrdywgZGVmYXVsdHMsIGZvcm1hdHZhbHVlPXNlbGYuZm9ybWF0dmFsdWUpCiAgICAgICAgICAgIGlmIHJlYWxuYW1lID09ICc8bGFtYmRhPic6CiAgICAgICAgICAgICAgICB0aXRsZSA9ICdsYW1iZGEnCiAgICAgICAgICAgICAgICBhcmdzcGVjID0gYXJnc3BlY1sxOi0xXSAjIHJlbW92ZSBwYXJlbnRoZXNlcwogICAgICAgIGVsc2U6CiAgICAgICAgICAgIGFyZ3NwZWMgPSAnKC4uLiknCiAgICAgICAgZGVjbCA9IHRpdGxlICsgYXJnc3BlYyArIG5vdGUKCiAgICAgICAgaWYgc2tpcGRvY3M6CiAgICAgICAgICAgIHJldHVybiBkZWNsICsgJ1xuJwogICAgICAgIGVsc2U6CiAgICAgICAgICAgIGRvYyA9IGdldGRvYyhvYmplY3QpIG9yICcnCiAgICAgICAgICAgIHJldHVybiBkZWNsICsgJ1xuJyArIChkb2MgYW5kIHJzdHJpcChzZWxmLmluZGVudChkb2MpKSArICdcbicpCgogICAgZGVmIGRvY290aGVyKHNlbGYsIG9iamVjdCwgbmFtZT1Ob25lLCBtb2Q9Tm9uZSwgbWF4bGVuPU5vbmUsIGRvYz1Ob25lKToKICAgICAgICAiIiJQcm9kdWNlIHRleHQgZG9jdW1lbnRhdGlvbiBmb3IgYSBkYXRhIG9iamVjdC4iIiIKICAgICAgICByZXByID0gc2VsZi5yZXByKG9iamVjdCkKICAgICAgICBpZiBtYXhsZW46CiAgICAgICAgICAgIGxpbmUgPSAobmFtZSBhbmQgbmFtZSArICcgPSAnIG9yICcnKSArIHJlcHIKICAgICAgICAgICAgY2hvcCA9IG1heGxlbiAtIGxlbihsaW5lKQogICAgICAgICAgICBpZiBjaG9wIDwgMDogcmVwciA9IHJlcHJbOmNob3BdICsgJy4uLicKICAgICAgICBsaW5lID0gKG5hbWUgYW5kIHNlbGYuYm9sZChuYW1lKSArICcgPSAnIG9yICcnKSArIHJlcHIKICAgICAgICBpZiBkb2MgaXMgbm90IE5vbmU6CiAgICAgICAgICAgIGxpbmUgKz0gJ1xuJyArIHNlbGYuaW5kZW50KHN0cihkb2MpKQogICAgICAgIHJldHVybiBsaW5lCgojIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSB1c2VyIGludGVyZmFjZXMKCmRlZiBwYWdlcih0ZXh0KToKICAgICIiIlRoZSBmaXJzdCB0aW1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AgICAgciA9IGluYyA9IG9zLmVudmlyb24uZ2V0KCdMSU5FUycsIDI1KSAtIDEKICAgICAgICBzeXMuc3Rkb3V0LndyaXRlKGpvaW4obGluZXNbOmluY10sICdcbicpICsgJ1xuJykKICAgICAgICB3aGlsZSBsaW5lc1tyOl06CiAgICAgICAgICAgIHN5cy5zdGRvdXQud3JpdGUoJy0tIG1vcmUgLS0nKQogICAgICAgICAgICBzeXMuc3Rkb3V0LmZsdXNoKCkKICAgICAgICAgICAgYyA9IGdldGNoYXIoKQoKICAgICAgICAgICAgaWYgYyBpbiBbJ3EnLCAnUSddOgogICAgICAgICAgICAgICAgc3lzLnN0ZG91dC53cml0ZSgnXHIgICAgICAgICAgXHInKQogICAgICAgICAgICAgICAgYnJlYWsKICAgICAgICAgICAgZWxpZiBjIGluIFsnXHInLCAnXG4nXToKICAgICAgICAgICAgICAgIHN5cy5zdGRvdXQud3JpdGUoJ1xyICAgICAgICAgIFxyJyArIGxpbmVzW3JdICsgJ1xuJykKICAgICAgICAgICAgICAgIHIgPSByICsgMQogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgaWYgYyBpbiBbJ2InLCAnQicsICdceDFiJ106CiAgICAgICAgICAgICAgICByID0gciAtIGluYyAtIGluYwogICAgICAgICAgICAgICAgaWYgciA8IDA6IHIgPSAwCiAgICAgICAgICAgIHN5cy5zdGRvdXQud3JpdGUoJ1xuJyArIGpvaW4obGluZXNbcjpyK2luY10sICdcbicpICsgJ1xuJykKICAgICAgICAgICAgciA9IHIgKyBpbmMKCiAgICBmaW5hbGx5OgogICAgICAgIGlmIHR0eToKICAgICAgICAgICAgdHR5LnRjc2V0YXR0cihmZCwgdHR5LlRDU0FGTFVTSCwgb2xkKQoKZGVmIHBsYWlucGFnZXIodGV4dCk6CiAgICAiIiJTaW1wbHkgcHJpbnQgdW5mb3JtYXR0ZWQgdGV4dC4gIFRoaXMgaXMgdGhlIHVsdGltYXRlIGZhbGxiYWNrLiIiIgogICAgc3lzL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GgpOgogICAgICAgICAgICBtb2RuYW1lID0gaW5zcGVjdC5nZXRtb2R1bGVuYW1lKHBhdGgpCiAgICAgICAgICAgIGlmIG1vZG5hbWU6CiAgICAgICAgICAgICAgICBpZiBtb2RuYW1lID09ICdfX2luaXRfXyc6CiAgICAgICAgICAgICAgICAgICAgbW9kbmFtZSA9IHBrZ3BhdGhbOi0xXSAjIHJlbW92ZSB0cmFpbGluZyBwZXJpb2QKICAgICAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICAgICAgbW9kbmFtZSA9IHBrZ3BhdGggKyBtb2RuYW1lCiAgICAgICAgICAgICAgICBpZiBtb2RuYW1lIG5vdCBpbiBkb25lOgogICAgICAgICAgICAgICAgICAgIGRvbmVbbW9kbmFtZV0gPSAxCiAgICAgICAgICAgICAgICAgICAgd3JpdGVkb2MobW9kbmFtZSkKCmNsYXNzIEhlbHBlcjoKICAgIGtleXdvcmRzID0gewogICAgICAgICdhbmQnOiAnQk9PTEVBTicsCiAgICAgICAgJ2Fzc2VydCc6ICgncmVmL2Fzc2VydCcsICcnKSwKICAgICAgICAnYnJlYWsnOiAoJ3JlZi9icmVhaycsICd3aGlsZSBmb3InKSwKICAgICAgICAnY2xhc3MnOiAoJ3JlZi9jbGFzcycsICdDTEFTU0VTIFNQRUNJQUxNRVRIT0RTJyksCiAgICAgICAgJ2NvbnRpbnVlJzogKCdyZWYvY29udGludWUnLCAnd2hpbGUgZm9yJyksCiAgICAgICAgJ2RlZic6ICgncmVmL2Z1bmN0aW9uJywgJycpLAogICAgICAgICdkZWwnOiAoJ3JlZi9kZWwnLCAnQkFTSUNNRVRIT0RTJyksCiAgICAgICAgJ2VsaWYnOiAnaWYnLAogICAgICAgICdlbHNlJzogKCdyZWYvaWYnLCAnd2hpbGUgZm9yJyksCiAgICAgICAgJ2V4Y2VwdCc6ICd0cnknLAogICAgICAgICdleGVjJzogKCdyZWYvZXhlYycsICcnKSwKICAgICAgICAnZmluYWxseSc6ICd0cnknLAogICAgICAgICdmb3InOiAoJ3JlZi9mb3InLCAnYnJlYWsgY29udGludWUgd2hpbGUnKSwKICAgICAgICAnZnJvbSc6ICdpbXBvcnQnLAogICAgICAgICdnbG9iYWwnOiAoJ3JlZi9nbG9iYWwnLCAnTkFNRVNQQUNFUycpLAogICAgICAgICdpZic6ICgncmVmL2lmJywgJ1RSVVRIVkFMVUUnKSwKICAgICAgICAnaW1wb3J0JzogKCdyZWYvaW1wb3J0JywgJ01PRFVMRVMnKSwKICAgICAgICAnaW4nOiAoJ3JlZi9jb21wYXJpc29ucycsICdTRVFVRU5DRU1FVEhPRFMyJyksCiAgICAgICAgJ2lzJzogJ0NPTVBBUklTT04nLAogICAgICAgICdsYW1iZGEnOiAoJ3JlZi9sYW1iZGFzJywgJ0ZVTkNUSU9OUycpLAogICAgICAgICdub3QnOiAnQk9PTEVBTicsCiAgICAgICAgJ29yJzogJ0JPT0xFQU4nLAogICAgICAgICdwYXNzJzogKCdyZWYvcGFzcycsICcnKSwKICAgICAgICAncHJpbnQnOiAoJ3JlZi9wcmludCcsICcnKSwKICAgICAgICAncmFpc2UnOiAoJ3JlZi9yYWlzZScsICdFWENFUFRJT05TJyksCiAgICAgICAgJ3JldHVybic6ICgncmVmL3JldHVybicsICdGVU5DVElPTlMnKSwKICAgICAgICAndHJ5JzogKCdyZWYvdHJ5JywgJ0VYQ0VQVElPTlMnKSwKICAgICAgICAnd2hpbGUnOiAoJ3JlZi93aGlsZScsICdicmVhayBjb250aW51ZSBpZiBUUlVUSFZBTFVFJyksCiAgICAgICAgJ3lpZWxkJzogKCdyZWYveWllbGQnLCAnJyksCiAgICB9CgogICAgdG9waWNzID0gewogICAgICAgICdUWVBFUyc6ICgncmVmL3R5cGVzJywgJ1NUUklOR1MgVU5JQ09ERSBOVU1CRVJTIFNFUVVFTkNFUyBNQVBQSU5HUyBGVU5DVElPTlMgQ0xBU1NFUyBNT0RVTEVTIEZJTEVTIGluc3BlY3QnKSwKICAgICAgICAnU1RSSU5H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V0YWJsZSkKICAgICAgICBob21lZGlyID0gb3MuZW52aXJvbi5nZXQoJ1BZVEhPTkhPTUUnKQogICAgICAgIGZvciBkaXIgaW4gW29zLmVudmlyb24uZ2V0KCdQWVRIT05ET0NTJyksCiAgICAgICAgICAgICAgICAgICAgaG9tZWRpciBhbmQgb3MucGF0aC5qb2luKGhvbWVkaXIsICdkb2MnKSwKICAgICAgICAgICAgICAgICAgICBvcy5wYXRoLmpvaW4oZXhlY2RpciwgJ2RvYycpLAogICAgICAgICAgICAgICAgICAgICcvdXNyL2RvYy9weXRob24tZG9jcy0nICsgc3BsaXQoc3lzLnZlcnNpb24pWzBdLAogICAgICAgICAgICAgICAgICAgICcvdXNyL2RvYy9weXRob24tJyArIHNwbGl0KHN5cy52ZXJzaW9uKVswXSwKICAgICAgICAgICAgICAgICAgICAnL3Vzci9kb2MvcHl0aG9uLWRvY3MtJyArIHN5cy52ZXJzaW9uWzozXSwKICAgICAgICAgICAgICAgICAgICAnL3Vzci9kb2MvcHl0aG9uLScgKyBzeXMudmVyc2lvbls6M10sCiAgICAgICAgICAgICAgICAgICAgb3MucGF0aC5qb2luKHN5cy5wcmVmaXgsICdSZXNvdXJjZXMvRW5nbGlzaC5scHJvai9Eb2N1bWVudGF0aW9uJyldOgogICAgICAgICAgICBpZiBkaXIgYW5kIG9zLnBhdGguaXNkaXIob3MucGF0aC5qb2luKGRpciwgJ2xpYicpKToKICAgICAgICAgICAgICAgIHNlbGYuZG9jZGlyID0gZGlyCgogICAgZGVmIF9fcmVwcl9fKHNlbGYpOgogICAgICAgIGlmIGluc3BlY3Quc3RhY2soKVsxXVszXSA9PSAnPyc6CiAgICAgICAgICAgIHNlbGYoKQogICAgICAgICAgICByZXR1cm4gJycKICAgICAgICByZXR1cm4gJzxweWRvYy5IZWxwZXIgaW5zdGFuY2U+JwoKICAgIGRlZiBfX2NhbGxfXyhzZWxmLCByZXF1ZXN0PU5vbmUpOgogICAgICAgIGlmIHJlcXVlc3QgaXMgbm90IE5vbmU6CiAgICAgICAgICAgIHNlbGYuaGVscChyZXF1ZXN0KQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHNlbGYuaW50cm8oKQogICAgICAgICAgICBzZWxmLmludGVyYWN0KCkKICAgICAgICAgICAgc2VsZi5vdXRwdXQud3JpdGUoJycnCllvdSBhcmUgbm93IGxlYXZpbmcgaGVscCBhbmQgcmV0dXJuaW5nIHRvIHRoZSBQeXRob24gaW50ZXJwcmV0ZXIuCklmIHlvdSB3YW50IHRvIGFzayBmb3IgaGVscCBvbiBhIHBhcnRpY3VsYXIgb2JqZWN0IGRpcmVjdGx5IGZyb20gdGhlCmludGVycHJldGVyLCB5b3UgY2FuIHR5cGUgImhlbHAob2JqZWN0KSIuICBFeGVjdXRpbmcgImhlbHAoJ3N0cmluZycpIgpoYXMgdGhlIHNhbWUgZWZmZWN0IGFzIHR5cGluZyBhIHBhcnRpY3VsYXIgc3RyaW5nIGF0IHRoZSBoZWxwPiBwcm9tcHQuCicnJykKCiAgICBkZWYgaW50ZXJhY3Qoc2VsZik6CiAgICAgICAgc2VsZi5vdXRwdXQud3JpdGUoJ1xuJykKICAgICAgICB3aGlsZSBUcnVlOgogICAgICAgICAgICBzZWxmLm91dHB1dC53cml0ZSgnaGVscD4gJykKICAgICAgICAgICAgc2VsZi5vdXRwdXQuZmx1c2goKQogICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICByZXF1ZXN0ID0gc2VsZi5pbnB1dC5yZWFkbGluZSgpCiAgICAgICAgICAgICAgICBpZiBub3QgcmVxdWVzdDogYnJlYWsKICAgICAgICAgICAgZXhjZXB0IEtleWJvYXJkSW50ZXJydXB0OiBicmVhawogICAgICAgICAgICByZXF1ZXN0ID0gc3RyaXAocmVwbGFjZShyZXF1ZXN0LCAnIicsICcnLCAiJyIsICcnKSkKICAgICAgICAgICAgaWYgbG93ZXIocmVxdWVzdCkgaW4gWydxJywgJ3F1aXQnXTogYnJlYWsKICAgICAgICAgICAgc2VsZi5oZ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G9zLnBhdGguaXNsaW5rKGRpcikgYW5kIGlub2RlIGluIHNlbGYuaW5vZGVzKToKICAgICAgICAgICAgc2VsZi5pbm9kZXMuYXBwZW5kKGlub2RlKSAjIGRldGVjdCBjaXJjdWxhciBzeW1ib2xpYyBsaW5rcwogICAgICAgICAgICByZXR1cm4gaXNwYWNrYWdlKGRpcikKICAgICAgICByZXR1cm4gRmFsc2UKCiAgICBkZWYgcnVuKHNlbGYsIGNhbGxiYWNrLCBrZXk9Tm9uZSwgY29tcGxldGVyPU5vbmUpOgogICAgICAgIGlmIGtleToga2V5ID0gbG93ZXIoa2V5KQogICAgICAgIHNlbGYucXVpdCA9IEZhbHNlCiAgICAgICAgc2VlbiA9IHt9CgogICAgICAgIGZvciBtb2RuYW1lIGluIHN5cy5idWlsdGluX21vZHVsZV9uYW1lczoKICAgICAgICAgICAgaWYgbW9kbmFtZSAhPSAnX19tYWluX18nOgogICAgICAgICAgICAgICAgc2Vlblttb2RuYW1lXSA9IDEKICAgICAgICAgICAgICAgIGlmIGtleSBpcyBOb25lOgogICAgICAgICAgICAgICAgICAgIGNhbGxiYWNrKE5vbmUsIG1vZG5hbWUsICcnKQogICAgICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICAgICBkZXNjID0gc3BsaXQoX19pbXBvcnRfXyhtb2RuYW1lKS5fX2RvY19fIG9yICcnLCAnXG4nKVswXQogICAgICAgICAgICAgICAgICAgIGlmIGZpbmQobG93ZXIobW9kbmFtZSArICcgLSAnICsgZGVzYyksIGtleSkgPj0gMDoKICAgICAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2soTm9uZSwgbW9kbmFtZSwgZGVzYykKCiAgICAgICAgd2hpbGUgbm90IHNlbGYucXVpdDoKICAgICAgICAgICAgbm9kZSA9IHNlbGYubmV4dCgpCiAgICAgICAgICAgIGlmIG5vdCBub2RlOiBicmVhawogICAgICAgICAgICBwYXRoLCBwYWNrYWdlID0gbm9kZQogICAgICAgICAgICBtb2RuYW1lID0gaW5zcGVjdC5nZXRtb2R1bGVuYW1lKHBhdGgpCiAgICAgICAgICAgIGlmIG9zLnBhdGguaXNmaWxlKHBhdGgpIGFuZCBtb2RuYW1lOgogICAgICAgICAgICAgICAgbW9kbmFtZSA9IHBhY2thZ2UgKyAocGFja2FnZSBhbmQgJy4nKSArIG1vZG5hbWUKICAgICAgICAgICAgICAgIGlmIG5vdCBtb2RuYW1lIGluIHNlZW46CiAgICAgICAgICAgICAgICAgICAgc2Vlblttb2RuYW1lXSA9IDEgIyBpZiB3ZSBzZWUgc3BhbS5weSwgc2tpcCBzcGFtLnB5YwogICAgICAgICAgICAgICAgICAgIGlmIGtleSBpcyBOb25lOgogICAgICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayhwYXRoLCBtb2RuYW1lLCAnJykKICAgICAgICAgICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgICAgICAgICBkZXNjID0gc3lub3BzaXMocGF0aCkgb3IgJycKICAgICAgICAgICAgICAgICAgICAgICAgaWYgZmluZChsb3dlcihtb2RuYW1lICsgJyAtICcgKyBkZXNjKSwga2V5KSA+PSAwOgogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2FsbGJhY2socGF0aCwgbW9kbmFtZSwgZGVzYykKICAgICAgICBpZiBjb21wbGV0ZXI6IGNvbXBsZXRlcigpCgpkZWYgYXByb3BvcyhrZXkpOgogICAgIiIiUHJpbnQgYWxsIHRoZSBvbmUtbGluZSBtb2R1bGUgc3VtbWFyaWVzIHRoYXQgY29udGFpbiBhIHN1YnN0cmluZy4iIiIKICAgIGRlZiBjYWxsYmFjayhwYXRoLCBtb2RuYW1lLCBkZXNjKToKICAgICAgICBpZiBtb2RuYW1lWy05Ol0gPT0gJy5fX2luaXRfXyc6CiAgICAgICAgICAgIG1vZG5hbWUgPSBtb2RuYW1lWzotOV0gKyAnIChwYWNrYWdlKScKICAgICAgICBwcmludCBtb2RuYW1lLCBkZXNjIGFuZCAnLSAnICsgZGVzYwogICAgdHJ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CYXNlSFRUUFNlcnZlci5CYXNlSFRUUFJlcXVlc3RIYW5kbGVyKToKICAgICAgICBkZWYgc2VuZF9kb2N1bWVudChzZWxmLCB0aXRsZSwgY29udGVudHMpOgogICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICBzZWxmLnNlbmRfcmVzcG9uc2UoMjAwKQogICAgICAgICAgICAgICAgc2VsZi5zZW5kX2hlYWRlcignQ29udGVudC1UeXBlJywgJ3RleHQvaHRtbCcpCiAgICAgICAgICAgICAgICBzZWxmLmVuZF9oZWFkZXJzKCkKICAgICAgICAgICAgICAgIHNlbGYud2ZpbGUud3JpdGUoaHRtbC5wYWdlKHRpdGxlLCBjb250ZW50cykpCiAgICAgICAgICAgIGV4Y2VwdCBJT0Vycm9yOiBwYXNzCgogICAgICAgIGRlZiBkb19HRVQoc2VsZik6CiAgICAgICAgICAgIHBhdGggPSBzZWxmLnBhdGgKICAgICAgICAgICAgaWYgcGF0aFstNTpdID09ICcuaHRtbCc6IHBhdGggPSBwYXRoWzotNV0KICAgICAgICAgICAgaWYgcGF0aFs6MV0gPT0gJy8nOiBwYXRoID0gcGF0aFsxOl0KICAgICAgICAgICAgaWYgcGF0aCBhbmQgcGF0aCAhPSAnLic6CiAgICAgICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICAgICAgb2JqID0gbG9jYXRlKHBhdGgsIGZvcmNlbG9hZD0xKQogICAgICAgICAgICAgICAgZXhjZXB0IEVycm9yRHVyaW5nSW1wb3J0LCB2YWx1ZToKICAgICAgICAgICAgICAgICAgICBzZWxmLnNlbmRfZG9jdW1lbnQocGF0aCwgaHRtbC5lc2NhcGUoc3RyKHZhbHVlKSkpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgICAgICAgICBpZiBvYmo6CiAgICAgICAgICAgICAgICAgICAgc2VsZi5zZW5kX2RvY3VtZW50KGRlc2NyaWJlKG9iaiksIGh0bWwuZG9jdW1lbnQob2JqLCBwYXRoKSkKICAgICAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICAgICAgc2VsZi5zZW5kX2RvY3VtZW50KHBhdGgsCidubyBQeXRob24gZG9jdW1lbnRhdGlvbiBmb3VuZCBmb3IgJXMnICUgcmVwcihwYXRoKSkKICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgIGhlYWRpbmcgPSBodG1sLmhlYWRpbmcoCic8YmlnPjxiaWc+PHN0cm9uZz5QeXRob246IEluZGV4IG9mIE1vZHVsZXM8L3N0cm9uZz48L2JpZz48L2JpZz4nLAonI2ZmZmZmZicsICcjNzc5OWVlJykKICAgICAgICAgICAgICAgIGRlZiBibHRpbmxpbmsobmFtZSk6CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuICc8YSBocmVmPSIlcy5odG1sIj4lczwvYT4nICUgKG5hbWUsIG5hbWUpCiAgICAgICAgICAgICAgICBuYW1lcyA9IGZpbHRlcihsYW1iZGEgeDogeCAhPSAnX19tYWluX18nLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3lzLmJ1aWx0aW5fbW9kdWxlX25hbWVzKQogICAgICAgICAgICAgICAgY29udGVudHMgPSBodG1sLm11bHRpY29sdW1uKG5hbWVzLCBibHRpbmxpbmspCiAgICAgICAgICAgICAgICBpbmRpY2VzID0gWyc8cD4nICsgaHRtbC5iaWdzZWN0aW9uKAogICAgICAgICAgICAgICAgICAgICdCdWlsdC1pbiBNb2R1bGVzJywgJyNmZmZmZmYnLCAnI2VlNzdhYScsIGNvbnRlbnRzKV0KCiAgICAgICAgICAgICAgICBzZWVuID0ge30KICAgICAgICAgICAgICAgIGZvciBkaXIgaW4gcGF0aGRpcnMoKToKICAgICAgICAgICAgICAgICAgICBpbmRpY2VzLmFwcGVuZChodG1sLmluZGV4KGRpciwgc2VlbikpCiAgICAgICAgICAgICAgICBjb250ZW50cyA9IGhlYWRpbmcgKyBqb2luKGluZGljZXMpICsgJycnPHAgYWxpZ249cmlnaHQ+Cjxmb250IGNvbG9yP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CkKICAgICAgICAgICAgc2VsZi5iaWdtaW5oZWlnaHQgPSAoc2VsZi5zZXJ2ZXJfZnJtLndpbmZvX3JlcWhlaWdodCgpICsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5zZWFyY2hfZnJtLndpbmZvX3JlcWhlaWdodCgpICsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5yZXN1bHRfbHN0LndpbmZvX3JlcWhlaWdodCgpICsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5yZXN1bHRfZnJtLndpbmZvX3JlcWhlaWdodCgpKQogICAgICAgICAgICBzZWxmLmJpZ3dpZHRoLCBzZWxmLmJpZ2hlaWdodCA9IHNlbGYubWlud2lkdGgsIHNlbGYuYmlnbWluaGVpZ2h0CiAgICAgICAgICAgIHNlbGYuZXhwYW5kZWQgPSAwCiAgICAgICAgICAgIHNlbGYud2luZG93LndtX2dlb21ldHJ5KCclZHglZCcgJSAoc2VsZi5taW53aWR0aCwgc2VsZi5taW5oZWlnaHQpKQogICAgICAgICAgICBzZWxmLndpbmRvdy53bV9taW5zaXplKHNlbGYubWlud2lkdGgsIHNlbGYubWluaGVpZ2h0KQogICAgICAgICAgICBzZWxmLndpbmRvdy50ay53aWxsZGlzcGF0Y2goKQoKICAgICAgICAgICAgaW1wb3J0IHRocmVhZGluZwogICAgICAgICAgICB0aHJlYWRpbmcuVGhyZWFkKAogICAgICAgICAgICAgICAgdGFyZ2V0PXNlcnZlLCBhcmdzPShwb3J0LCBzZWxmLnJlYWR5LCBzZWxmLnF1aXQpKS5zdGFydCgpCgogICAgICAgIGRlZiByZWFkeShzZWxmLCBzZXJ2ZXIpOgogICAgICAgICAgICBzZWxmLnNlcnZlciA9IHNlcnZlcgogICAgICAgICAgICBzZWxmLnRpdGxlX2xibC5jb25maWcoCiAgICAgICAgICAgICAgICB0ZXh0PSdQeXRob24gZG9jdW1lbnRhdGlvbiBzZXJ2ZXIgYXRcbicgKyBzZXJ2ZXIudXJsKQogICAgICAgICAgICBzZWxmLm9wZW5fYnRuLmNvbmZpZyhzdGF0ZT0nbm9ybWFsJykKICAgICAgICAgICAgc2VsZi5xdWl0X2J0bi5jb25maWcoc3RhdGU9J25vcm1hbCcpCgogICAgICAgIGRlZiBvcGVuKHNlbGYsIGV2ZW50PU5vbmUsIHVybD1Ob25lKToKICAgICAgICAgICAgdXJsID0gdXJsIG9yIHNlbGYuc2VydmVyLnVybAogICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICBpbXBvcnQgd2ViYnJvd3NlcgogICAgICAgICAgICAgICAgd2ViYnJvd3Nlci5vcGVuKHVybCkKICAgICAgICAgICAgZXhjZXB0IEltcG9ydEVycm9yOiAjIHByZS13ZWJicm93c2VyLnB5IGNvbXBhdGliaWxpdHkKICAgICAgICAgICAgICAgIGlmIHN5cy5wbGF0Zm9ybSA9PSAnd2luMzInOgogICAgICAgICAgICAgICAgICAgIG9zLnN5c3RlbSgnc3RhcnQgIiVzIicgJSB1cmwpCiAgICAgICAgICAgICAgICBlbGlmIHN5cy5wbGF0Zm9ybSA9PSAnbWFjJzoKICAgICAgICAgICAgICAgICAgICB0cnk6IGltcG9ydCBpYwogICAgICAgICAgICAgICAgICAgIGV4Y2VwdCBJbXBvcnRFcnJvcjogcGFzcwogICAgICAgICAgICAgICAgICAgIGVsc2U6IGljLmxhdW5jaHVybCh1cmwpCiAgICAgICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgICAgIHJjID0gb3Muc3lzdGVtKCduZXRzY2FwZSAtcmVtb3RlICJvcGVuVVJMKCVzKSIgJicgJSB1cmwpCiAgICAgICAgICAgICAgICAgICAgaWYgcmM6IG9zLnN5c3RlbSgnbmV0c2NhcGUgIiVzIiAmJyAlIHVybCkKCiAgICAgICAgZGVmIHF1aXQoc2VsZiwgZXZlbnQ9Tm9uZSk6CiAgICAgICAgICAgIGlmIHNlbGYuc2VydmVyOgogICAgICAgICAgICAgICAgc2VsZ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09ICcuX19pbml0X18nOgogICAgICAgICAgICAgICAgbW9kbmFtZSA9IG1vZG5hbWVbOi05XSArICcgKHBhY2thZ2UpJwogICAgICAgICAgICBzZWxmLnJlc3VsdF9sc3QuaW5zZXJ0KCdlbmQnLAogICAgICAgICAgICAgICAgbW9kbmFtZSArICcgLSAnICsgKGRlc2Mgb3IgJyhubyBkZXNjcmlwdGlvbiknKSkKCiAgICAgICAgZGVmIHN0b3Aoc2VsZiwgZXZlbnQ9Tm9uZSk6CiAgICAgICAgICAgIGlmIHNlbGYuc2Nhbm5lcjoKICAgICAgICAgICAgICAgIHNlbGYuc2Nhbm5lci5xdWl0ID0gMQogICAgICAgICAgICAgICAgc2VsZi5zY2FubmVyID0gTm9uZQoKICAgICAgICBkZWYgZG9uZShzZWxmKToKICAgICAgICAgICAgc2VsZi5zY2FubmVyID0gTm9uZQogICAgICAgICAgICBzZWxmLnNlYXJjaF9sYmwuY29uZmlnKHRleHQ9J1NlYXJjaCBmb3InKQogICAgICAgICAgICBzZWxmLnNlYXJjaF9sYmwucGFjayhzaWRlPSdsZWZ0JykKICAgICAgICAgICAgc2VsZi5zZWFyY2hfZW50LnBhY2soc2lkZT0ncmlnaHQnLCBmaWxsPSd4JywgZXhwYW5kPTEpCiAgICAgICAgICAgIGlmIHN5cy5wbGF0Zm9ybSAhPSAnd2luMzInOiBzZWxmLnN0b3BfYnRuLmZvcmdldCgpCiAgICAgICAgICAgIHNlbGYuc3RvcF9idG4uY29uZmlnKHN0YXRlPSdkaXNhYmxlZCcpCgogICAgICAgIGRlZiBzZWxlY3Qoc2VsZiwgZXZlbnQ9Tm9uZSk6CiAgICAgICAgICAgIHNlbGYuZ290b19idG4uY29uZmlnKHN0YXRlPSdub3JtYWwnKQoKICAgICAgICBkZWYgZ290byhzZWxmLCBldmVudD1Ob25lKToKICAgICAgICAgICAgc2VsZWN0aW9uID0gc2VsZi5yZXN1bHRfbHN0LmN1cnNlbGVjdGlvbigpCiAgICAgICAgICAgIGlmIHNlbGVjdGlvbjoKICAgICAgICAgICAgICAgIG1vZG5hbWUgPSBzcGxpdChzZWxmLnJlc3VsdF9sc3QuZ2V0KHNlbGVjdGlvblswXSkpWzBdCiAgICAgICAgICAgICAgICBzZWxmLm9wZW4odXJsPXNlbGYuc2VydmVyLnVybCArIG1vZG5hbWUgKyAnLmh0bWwnKQoKICAgICAgICBkZWYgY29sbGFwc2Uoc2VsZik6CiAgICAgICAgICAgIGlmIG5vdCBzZWxmLmV4cGFuZGVkOiByZXR1cm4KICAgICAgICAgICAgc2VsZi5yZXN1bHRfZnJtLmZvcmdldCgpCiAgICAgICAgICAgIHNlbGYucmVzdWx0X3Njci5mb3JnZXQoKQogICAgICAgICAgICBzZWxmLnJlc3VsdF9sc3QuZm9yZ2V0KCkKICAgICAgICAgICAgc2VsZi5iaWd3aWR0aCA9IHNlbGYud2luZG93LndpbmZvX3dpZHRoKCkKICAgICAgICAgICAgc2VsZi5iaWdoZWlnaHQgPSBzZWxmLndpbmRvdy53aW5mb19oZWlnaHQoKQogICAgICAgICAgICBzZWxmLndpbmRvdy53bV9nZW9tZXRyeSgnJWR4JWQnICUgKHNlbGYubWlud2lkdGgsIHNlbGYubWluaGVpZ2h0KSkKICAgICAgICAgICAgc2VsZi53aW5kb3cud21fbWluc2l6ZShzZWxmLm1pbndpZHRoLCBzZWxmLm1pbmhlaWdodCkKICAgICAgICAgICAgc2VsZi5leHBhbmRlZCA9IDAKCiAgICAgICAgZGVmIGV4cGFuZChzZWxmKToKICAgICAgICAgICAgaWYgc2VsZi5leHBhbmRlZDogcmV0dXJuCiAgICAgICAgICAgIHNlbGYucmVzdWx0X2ZybS5wYWNrKHNpZGU9J2JvdHRvbScsIGZpbGw9J3gnKQogICAgICAgICAgICBzZWxmLnJlc3VsdF9zY3IucGFjayhzaWRlPSdyaWdodCcsIGZpbGw9J3knKQogICAgICAgICAgICBzZWxmLnJlc3VsdF9sc3QucGFjayhzaWRlPSd0b3AnLCBmaWxsPSdib3RoJywgZXhwYW5kPTEpCiAgICAgICAgICAgIHNlbGYud2luZG93LndtX2dlb21ldHJ5KCclZHglZCcgJSAoc2VsZi5iaWd3aWR0aCwgc2VsZi5iaWdoZWlnaHQpKQogICAgICAgICAgICBzZWxmLndpbmRvdy53bV9taW5zaXplKHNlbGYubWlud2lkdGgsIHNlbGYuYmlnbWluaGVpZ2h0KQogICAgICAgICAgICBzZWxmLmV4cGFuZGVkID0gMQoKICAgICAgICBkZWYgaGlkZShzZWxmLCBldmVudD1Ob25lKToKICAgICAgICAgICAgc2VsZi5zdG9wKCkKICAgICAgICAgICAgc2VsZi5jb2xsYXBzZSgpCgogICAgaW1wb3J0IFRraW50ZXIKICAgIHRyeToKICAgICAgICBndWkgPSBHVUkoVGtpbnRlci5UaygpKQogICAgICAgIFRraW50ZXIubWFpbmxvb3AoKQogICAgZXhjZXB0IEtleWJvYXJkSW50ZXJydXB0OgogICAgICAgIHBhc3MKCiMgLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gY29tbWFuZC1saW5lIGludGVyZmFjZQoKZGVmIGlzcGF0aCh4KToKICAgIHJldHVybiBpc2luc3RhbmNlKHgsIHN0cikgYW5kIGZpbmQoeCwgb3Muc2VwKSA+PSAwCgpkZWYgY2xpKCk6CiAgICAiIiJDb21tYW5kLWxpbmUgaW50ZXJmYWNlIChsb29rcyBhdCBzeXMuYXJndiB0byBkZWNpZGUgd2hhdCB0byBkbykuIiIiCiAgICBpbXBvcnQgZ2V0b3B0CiAgICBjbGFzcyBCYWRVc2FnZTogcGFzcwoKICAgICMgU2NyaXB0cyBkb24ndCBnZXQgdGhlIGN1cnJlbnQgZGlyZWN0b3J5IGluIHRoZWlyIHBhdGggYnkgZGVmYXVsdC4KICAgIHNjcmlwdGRpciA9IG9zLnBhdGguZGlybmFtZShzeXMuYXJndlswXSkKICAgIGlmIHNjcmlwdGRpciBpbiBzeXMucGF0aDoKICAgICAgICBzeXMucGF0aC5yZW1vdmUoc2NyaXB0ZGlyKQogICAgc3lzLnBhdGguaW5zZXJ0KDAsICcuJykKCiAgICB0cnk6CiAgICAgICAgb3B0cywgYXJncyA9IGdldG9wdC5nZXRvcHQoc3lzLmFyZ3ZbMTpdLCAnZ2s6cDp3JykKICAgICAgICB3cml0aW5nID0gMAoKICAgICAgICBmb3Igb3B0LCB2YWwgaW4gb3B0czoKICAgICAgICAgICAgaWYgb3B0ID09ICctZyc6CiAgICAgICAgICAgICAgICBndWkoKQogICAgICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgICAgIGlmIG9wdCA9PSAnLWsnOgogICAgICAgICAgICAgICAgYXByb3Bvcyh2YWwpCiAgICAgICAgICAgICAgICByZXR1cm4KICAgICAgICAgICAgaWYgb3B0ID09ICctcCc6CiAgICAgICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICAgICAgcG9ydCA9IGludCh2YWwpCiAgICAgICAgICAgICAgICBleGNlcHQgVmFsdWVFcnJvcjoKICAgICAgICAgICAgICAgICAgICByYWlzZSBCYWRVc2FnZQogICAgICAgICAgICAgICAgZGVmIHJlYWR5KHNlcnZlcik6CiAgICAgICAgICAgICAgICAgICAgcHJpbnQgJ3B5ZG9jIHNlcnZlciByZWFkeSBhdCAlcycgJSBzZXJ2ZXIudXJsCiAgICAgICAgICAgICAgICBkZWYgc3RvcHBlZCgpOgogICAgICAgICAgICAgICAgICAgIHByaW50ICdweWRvYyBzZXJ2ZXIgc3RvcHBlZCcKICAgICAgICAgICAgICAgIHNlcnZlKHBvcnQsIHJlYWR5LCBzdG9wcGVkKQogICAgICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgICAgIGlmIG9wdCA9PSAnLXcnOgogICAgICAgICAgICAgICAgd3JpdGluZyA9IDEKCiAgICAgICAgaWYgbm90IGFyZ3M6IHJhaXNlIEJhZFVzYWdlCiAgICAgICAgZm9yIGFyZyBpbiBhcmdzOgogICAgICAgICAgICBpZiBpc3BhdGgoYXJnKSBhbmQgbm90IG9zLnBhdGguZXhpc3RzKGFyZyk6CiAgICAgICAgICAgICAgICBwcmludCAnZmlsZSAlciBkb2VzIG5vdCBleGlzdCcgJSBhcmcKICAgICAgICAgICAgICAgIGJyZWFrCiAgICAgICAgICAgIHRyeToKICAgICAgICAgICAgICAgIGlmIGlzcGF0aChhcmcpIGFuZCBvcy5wYXRoLmlzZmlsZShhcmcpOgogICAgICAgICAgICAgICAgICAgIGFyZyA9IGltcG9ydGZpbGUoYXJnKQogICAgICAgICAgICAgICAgaWYgd3JpdGluZzoKICAgICAgICAgICAgICAgICAgICBpZiBpc3BhdGgoYXJnKSBhbmQgb3MucGF0aC5pc2RpcihhcmcpOgogICAgICAgICAgICAgICAgICAgICAgICB3cml0ZWRvY3MoYXJnKQogICAgICAgICAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICAgICAgICAgIHdyaXRlZG9jKGFyZykKICAgICAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICAgICAgaGVscC5oZWxwKGFyZykKICAgICAgICAgICAgZXhjZXB0IEVycm9yRHVyaW5nSW1wb3J0LCB2YWx1ZToKICAgICAgICAgICAgICAgIHByaW50IHZhbHVlCgogICAgZXhjZXB0IChnZXRvcHQuZXJyb3IsIEJhZFVzYWdlKToKICAgICAgICBjbWQgPSBvcy5wYXRoLmJhc2VuYW1lKHN5cy5hcmd2WzBdKQogICAgICAgIHByaW50ICIiInB5ZG9jIC0gdGhlIFB5dGhvbiBkb2N1bWVudGF0aW9uIHRvb2wKCiVzIDxuYW1lPiAuLi4KICAgIFNob3cgdGV4dCBkb2N1bWVudGF0aW9uIG9uIHNvbWV0aGluZy4gIDxuYW1lPiBtYXkgYmUgdGhlIG5hbWUgb2YgYQogICAgUHl0aG9uIGtleXdvcmQsIHRvcGljLCBmdW5jdGlvbiwgbW9kdWxlLCBvciBwYWNrYWdlLCBvciBhIGRvdHRlZAogICAgcmVmZXJlbmNlIHRvIGEgY2xhc3Mgb3IgZnV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