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4gSU9FcnJvcgogICAgaXMgcmFpc2VkIGlmIHRoZSBzb3VyY2UgY29kZSBjYW5ub3QgYmUgcmV0cmlldmVkLiIiIgogICAgdHJ5OgogICAgICAgIGZpbGUgPSBvcGVuKGdldHNvdXJjZWZpbGUob2JqZWN0KSkKICAgIGV4Y2VwdCAoVHlwZUVycm9yLCBJT0Vycm9yKToKICAgICAgICByYWlzZSBJT0Vycm9yLCAnY291bGQgbm90IGdldCBzb3VyY2UgY29kZScKICAgIGxpbmVzID0gZmlsZS5yZWFkbGluZXMoKQogICAgZmlsZS5jbG9zZSgpCgogICAgaWYgaXNtb2R1bGUob2JqZWN0KToKICAgICAgICByZXR1cm4gbGluZXMsIDAKCiAgICBpZiBpc2NsYXNzKG9iamVjdCk6CiAgICAgICAgbmFtZSA9IG9iamVjdC5fX25hbWVfXwogICAgICAgIHBhdCA9IHJlLmNvbXBpbGUocideXHMqY2xhc3NccyonICsgbmFtZSArIHInXGInKQogICAgICAgIGZvciBpIGluIHJhbmdlKGxlbihsaW5lcykpOgogICAgICAgICAgICBpZiBwYXQubWF0Y2gobGluZXNbaV0pOiByZXR1cm4gbGluZXMsIGkKICAgICAgICBlbHNlOiByYWlzZSBJT0Vycm9yLCAnY291bGQgbm90IGZpbmQgY2xhc3MgZGVmaW5pdGlvbicKCiAgICBpZiBpc21ldGhvZChvYmplY3QpOgogICAgICAgIG9iamVjdCA9IG9iamVjdC5pbV9mdW5jCiAgICBpZiBpc2Z1bmN0aW9uKG9iamVjdCk6CiAgICAgICAgb2JqZWN0ID0gb2JqZWN0LmZ1bmNfY29kZQogICAgaWYgaXN0cmFjZWJhY2sob2JqZWN0KToKICAgICAgICBvYmplY3QgPSBvYmplY3QudGJfZnJhbWUKICAgIGlmIGlzZnJhbWUob2JqZWN0KToKICAgICAgICBvYmplY3QgPSBvYmplY3QuZl9jb2RlCiAgICBpZiBpc2NvZGUob2JqZWN0KToKICAgICAgICBpZiBub3QgaGFzYXR0cihvYmplY3QsICdjb19maXJzdGxpbmVubycpOgogICAgICAgICAgICByYWlzZSBJT0Vycm9yLCAnY291bGQgbm90IGZpbmQgZnVuY3Rpb24gZGVmaW5pdGlvbicKICAgICAgICBsbnVtID0gb2JqZWN0LmNvX2ZpcnN0bGluZW5vIC0gMQogICAgICAgIHBhdCA9IHJlLmNvbXBpbGUocideXHMqZGVmXHMnKQogICAgICAgIHdoaWxlIGxudW0gPiAwOgogICAgICAgICAgICBpZiBwYXQubWF0Y2gobGluZXNbbG51bV0pOiBicmVhawogICAgICAgICAgICBsbnVtID0gbG51bSAtIDEKICAgICAgICByZXR1cm4gbGluZXMsIGxudW0KCmRlZiBnZXRjb21tZW50cyhvYmplY3QpOgogICAgIiIiR2V0IGxpbmVzIG9mIGNvbW1lbnRzIGltbWVkaWF0ZWx5IHByZWNlZGluZyBhbiBvYmplY3QncyBzb3VyY2UgY29kZS4iIiIKICAgIHRyeTogbGluZXMsIGxudW0gPSBmaW5kc291cmNlKG9iamVjdCkKICAgIGV4Y2VwdCBJT0Vycm9yOiByZXR1cm4gTm9uZQoKICAgIGlmIGlzbW9kdWxlKG9iamVjdCk6CiAgICAgICAgIyBMb29rIGZvciBhIGNvbW1lbnQgYmxvY2sgYXQgdGhlIHRvcCBvZiB0aGUgZmlsZS4KICAgICAgICBzdGFydCA9IDAKICAgICAgICBpZiBsaW5lc1swXVs6Ml0gPT0gJyMhJzogc3RhcnQgPSAxCiAgICAgICAgd2hpbGUgc3RhcnQgPCBsZW4obGluZXMpIGFuZCBzdHJpbmcuc3RyaXAobGluZXNbc3RhcnRdKSBpbiBbJycsICcjJ106CiAgICAgICAgICAgIHN0YXJ0ID0gc3RhcnQgKyAxCiAgICAgICAgaWYgbGluZXNbc3RhcnRdWzoxXSA9PSAnIyc6CiAgICAgICAgICAgIGNvbW1lbnRzID0gW10KICAgICAgICAgICAgZW5kID0gc3RhcnQKICAgICAgICAgICAgd2hpbGUgZW5kIDwgbGVuKGxpbmVzKSBhbmQgbGluZXNbZW5kXVs6MV0gPT0gJyMnOgogICAgICAgICAgICAgICAgY29tbWVudHMuYXBwZW5kKHN0cmluZy5leHBhbmR0YWJzKGxpbmVzW2VuZF0pKQogICAgICAgICAgICAgICAgZW5kID0gZW5kICsgMQogICAgICAgICAgICByZXR1cm4gc3RyaW5nLmpvaW4oY29tbWVudHMsICcnKQoKICAgICMgTG9vayBmb3IgYSBwcmVjZWRpbmcgYmxvY2sgb2YgY29tbWVudHMgYXQgdGhlIHNhbWUgaW5kZW50YXRpb24uCiAgICBlbGlmIGxudW0gPiAwOgogICAgICAgIGluZGVudCA9IGluZGVudHNpemUobGluZXNbbG51bV0pCiAgICAgICAgZW5kID0gbG51bSAtIDEKICAgICAgICBpZiBlbmQgPj0gMCBhbmQgc3RyaW5nLmxzdHJpcChsaW5lc1tlbmRdKVs6MV0gPT0gJyMnIGFuZCBcCiAgICAgICAgICAgIGluZGVudHNpemUobGluZXNbZW5kXSkgPT0gaW5kZW50OgogICAgICAgICAgICBjb21tZW50cyA9IFtzdHJpbmcubHN0cmlwKHN0cmluZy5leHBhbmR0YWJzKGxpbmVzW2VuZF0pKV0KICAgICAgICAgICAgaWYgZW5kID4gMDoKICAgICAgICAgICAgICAgIGVuZCA9IGVuZCAtIDEKICAgICAgICAgICAgICAgIGNvbW1lbnQgPSBzdHJpbmcubHN0cmlwKHN0cmluZy5leHBhbmR0YWJzKGxpbmVzW2VuZF0pKQogICAgICAgICAgICAgICAgd2hpbGUgY29tbWVudFs6MV0gPT0gJyMnIGFuZCBpbmRlbnRzaXplKGxpbmVzW2VuZF0pID09IGluZGVudDoKICAgICAgICAgICAgICAgICAgICBjb21tZW50c1s6MF0gPSBbY29tbWVudF0KICAgICAgICAgICAgICAgICAgICBlbmQgPSBlbmQgLSAxCiAgICAgICAgICAgICAgICAgICAgaWYgZW5kIDwgMDogYnJlYWsKICAgICAgICAgICAgICAgICAgICBjb21tZW50ID0gc3RyaW5nLmxzdHJpcChzdHJpbmcuZXhwYW5kdGFicyhsaW5lc1tlbmRdKSkKICAgICAgICAgICAgd2hpbGUgY29tbWVudHMgYW5kIHN0cmluZy5zdHJpcChjb21tZW50c1swXSkgPT0gJyMnOgogICAgICAgICAgICAgICAgY29tbWVudHNbOjFdID0gW10KICAgICAgICAgICAgd2hpbGUgY29tbWVudHMgYW5kIHN0cmluZy5zdHJpcChjb21tZW50c1stMV0pID09ICcjJzoKICAgICAgICAgICAgICAgIGNvbW1lbnRzWy0xOl0gPSBbXQogICAgICAgICAgICByZXR1cm4gc3RyaW5nLmpvaW4oY29tbWVudHMsICcnKQoKY2xhc3MgTGlzdFJlYWRlcjoKICAgICIiIlByb3ZpZGUgYSByZWFkbGluZSgpIG1ldGhvZCB0byByZXR1cm4gbGluZXMgZnJvbSBhIGxpc3Qgb2Ygc3RyaW5ncy4iIiIKICAgIGRlZiBfX2luaXRfXyhzZWxmLCBsaW5lcyk6CiAgICAgICAgc2VsZi5saW5lcyA9IGxpbmVzCiAgICAgICAgc2VsZi5pbmRleCA9IDAKCiAgICBkZWYgcmVhZGxpbmUoc2VsZik6CiAgICAgICAgaSA9IHNlbGYuaW5kZXgKICAgICAgICBpZiBpIDwgbGVuKHNlbGYubGluZXMpOgogICAgICAgICAgICBzZWxmLmluZGV4ID0gaSArIDEKICAgICAgICAgICAgcmV0dXJuIHNlbGYubGluZXNbaV0KICAgICAgICBlbHNlOiByZXR1cm4gJycKCmNsYXNzIEVuZE9mQmxvY2soRXhjZXB0aW9uKTogcGFzcwoKY2xhc3MgQmxvY2tGaW5kZXI6CiAgICAiIiJQcm92aWRlIGEgdG9rZW5lYXRlcigpIG1ldGhvZCB0byBkZXRlY3QgdGhlIGVuZCBvZiBhIGNvZGUgYmxvY2suIiIiCiAgICBkZWYgX19pbml0X18oc2VsZik6CiAgICAgICAgc2VsZi5pbmRlbnQgPSAwCiAgICAgICAgc2VsZi5zdGFydGVkID0gMAogICAgICAgIHNlbGYubGFzdCA9IDAKCiAgICBkZWYgdG9rZW5lYXRlcihzZWxmLCB0e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EFWRV9BUkdVTUVOVDoKICAgICAgICAgICAgICAgICAgICBvcG5hbWUgPSBkaXMub3BuYW1lW29wXQogICAgICAgICAgICAgICAgICAgIHZhbHVlID0gb3JkKGNvZGVbc3RlcF0pICsgb3JkKGNvZGVbc3RlcCsxXSkqMjU2CiAgICAgICAgICAgICAgICAgICAgc3RlcCA9IHN0ZXAgKyAyCiAgICAgICAgICAgICAgICAgICAgaWYgb3BuYW1lIGluIFsnVU5QQUNLX1RVUExFJywgJ1VOUEFDS19TRVFVRU5DRSddOgogICAgICAgICAgICAgICAgICAgICAgICByZW1haW4uYXBwZW5kKHZhbHVlKQogICAgICAgICAgICAgICAgICAgICAgICBjb3VudC5hcHBlbmQodmFsdWUpCiAgICAgICAgICAgICAgICAgICAgZWxpZiBvcG5hbWUgPT0gJ1NUT1JFX0ZBU1QnOgogICAgICAgICAgICAgICAgICAgICAgICBzdGFjay5hcHBlbmQobmFtZXNbdmFsdWVdKQogICAgICAgICAgICAgICAgICAgICAgICByZW1haW5bLTFdID0gcmVtYWluWy0xXSAtIDEKICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgcmVtYWluWy0xXSA9PSAwOgogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVtYWluLnBvcCgpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaXplID0gY291bnQucG9wKCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0YWNrWy1zaXplOl0gPSBbc3RhY2tbLXNpemU6XV0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIG5vdCByZW1haW46IGJyZWFrCiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZW1haW5bLTFdID0gcmVtYWluWy0xXSAtIDEKICAgICAgICAgICAgICAgICAgICAgICAgaWYgbm90IHJlbWFpbjogYnJlYWsKICAgICAgICAgICAgYXJnc1tpXSA9IHN0YWNrWzBdCgogICAgdmFyYXJncyA9IE5vbmUKICAgIGlmIGNvLmNvX2ZsYWdzICYgQ09fVkFS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