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