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dWxlX2lkLCBJUENfQ1JFQVR8MDYwMCk7DQogICAgDQogICAgLy+3osvNz/vPog0KICAgIHJldCA9IGlwY19zZW5kX21lc3NhZ2UobW9kdWxlX2lkLCBkc3RfaWQsIG1zZ19jbWQsIHNpemVvZihpbnQpLCAodW5zaWduZWQgY2hhciAqKSgmdm1vZGUpLCAwKTsNCiAgICBpZigwICE9IHJldCl7DQogICAgICAgIHByaW50ZigiJXM6IHNlbmQgbXNnIGVycm9yKCVkKSFcbiIsIF9fZnVuY19fLCByZXQpOw0KICAgICAgICBtc2djdGwobXNnX2hhbmRsZSxJUENfUk1JRCwwKTsNCiAgICAgICAgcmV0dXJuIHJldDsNCiAgICB9DQogICAgcHJpbnRmKCIlczogc2VuZCBtc2cgc3VjY2VzcyglZCkhXG4iLCBfX2Z1bmNfXywgcmV0KTsNCiAgICANCiAgICAvL73TytXP+8+iDQogICAgd2hpbGUoMSkNCgl7DQoJCW1lbXNldCgmbXNnLCAweDAwLCBzaXplb2YoTVNHX0JVRikpOw0KDQoJCS8vu/HIoc/7z6K208HQz/vPorKitKbA7Q0KCQlyZXQgPSBtc2dyY3YobXNnX2hhbmRsZSwgJm1zZywgbXNnX3NpemUsIDAsIDApOw0KICAgICAgICBpZigwID4gcmV0KXsNCiAgICAgICAgICAgIGNvbnRpbnVlOw0KICAgICAgICB9DQoNCiAgICAgICAgLy/GpcXktb3Kx01TR19DTURfQ0FQX1ZBTFNBX09QRU7KsbLFtKbA7Q0KICAgICAgICBpZihtc2dfY21kID09IG1zZy51c01zZ0NtZCl7DQogICAgICAgICAgICByZXQgPSAqKChpbnQgKiltc2cuYXVjRGF0YUJ1Zik7DQogICAgICAgICAgICBtc2djdGwobXNnX2hhbmRsZSxJUENfUk1JRCwwKTsNCiAgICAgICAgICAgIHByaW50ZigiJXM6IHJlY2VpdmUgbXNnIHN1Y2Nlc3MoJWQpIVxuIiwgX19mdW5jX18sIHJldCk7DQogICAgICAgICAgICBicmVhazsNCiAgICAgICAgfQ0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