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PXk8PXR5MSs1OiByZXR1cm4gVHJ1ZQogICAgICAgIHJldHVybiBGYWxzZQoKICAgIGxpbmVfdGV4dHMsIHkwID0gW10sIDAKICAgIGZvciBiIGluIHBhZ2UuZ2V0X3RleHQoImRpY3QiKVsiYmxvY2tzIl06CiAgICAgICAgaWYgYi5nZXQoInR5cGUiKSAhPSAwOiBjb250aW51ZQogICAgICAgIGZvciBsaW5lIGluIGIuZ2V0KCJsaW5lcyIsW10pOgogICAgICAgICAgICB4LCBwYXJ0cyA9IE5vbmUsIFtdCiAgICAgICAgICAgIGZvciBzIGluIGxpbmUuZ2V0KCJzcGFucyIsW10pOgogICAgICAgICAgICAgICAgdCA9IHJlLnN1YihyJ1x1MjAwYicsJycscy5nZXQoInRleHQiLCIiKSkKICAgICAgICAgICAgICAgIGlmIHQuc3RyaXAoKSBhbmQgeCBpcyBOb25lOiB4ID0gc1siYmJveCJdWzBdCiAgICAgICAgICAgICAgICBwYXJ0cy5hcHBlbmQodCkKICAgICAgICAgICAgdGV4dCA9ICcnLmpvaW4ocGFydHMpLnN0cmlwKCkKICAgICAgICAgICAgeTAgPSBsaW5lWydiYm94J11bMV0KICAgICAgICAgICAgaWYgdGV4dCBhbmQgeTA8dGIgYW5kIHRleHQgbm90IGluIGhlYWRlcl9wYXR0ZXJucyBhbmQgdGV4dCBub3QgaW4gZm9vdGVyX3BhdHRlcm5zOgogICAgICAgICAgICAgICAgaWYgeCBpcyBOb25lIG9yIG5vdCBpbl90YWJsZSh4LHkwKToKICAgICAgICAgICAgICAgICAgICBsaW5lX3RleHRzLmFwcGVuZCh0ZXh0KQogICAgaWYgbm90IGxpbmVfdGV4dHM6IHJldHVybiAwLjAKICAgIGhpdHMgPSBzdW0oMSBmb3IgdCBpbiBsaW5lX3RleHRzCiAgICAgICAgICAgICAgIGlmIF9OVU1fUC5tYXRjaCh0KSBvciBfQUxQSEFfUC5tYXRjaCh0KSBvciBfUk9NQU5fUC5tYXRjaCh0KSBvciBfREFTSF9QLm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