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gIHdoaWxlKGZnZXRzKGJ1ZiwgMTI4LCBwcCkgIT0gTlVMTCkgICAgICAgIA0KICAgIHsgICAgICAgICAgICAgDQogICAgICAgIA0KICAgICAgICBpZihzdHJjbXAoYnVmLCJBQk5PUk1BTCIpPT0wKSAgLypwcyBjb21tYW5kIGVycm9yKi8gIA0KICAgICAgICB7DQogICAgICAgICAgICBwcmludGYoIlslc10gZGV0ZWN0X3Byb2Nlc3Mgc3RyZXJyb3I6ICVzXG4iLF9fRlVOQ1RJT05fXyxzdHJlcnJvcihlcnJubykpOw0KICAgICAgICAgICAgaWYoZXJybm8gPT0gRUlOVFIpIC8vSW50ZXJydXB0ZWQgc3lzdGVtIGNhbGwstMvKsb/J1tjK1A0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIGdvdG8gYWdhaW47DQogICAgICAgICAgICB9DQogICAgICAgICAgICANCiAgICAgICAgICAgIHBjbG9zZShwcCk7Ly+52LHVudy1wA0KICAgICAgICAgICAgcmV0dXJuIDsgDQogICAgICAgICB9DQogICAgICAgICBtZW1zZXQobWFjX3RtcCwgMCwgMTgpOyAgICAgICAgICAgIA0KICAgICAgICAgaWYoKHAgPSBzdHJzdHIoYnVmLCAiOiIpKSAhPSBOVUxMKSAgICAgICAgICAgIA0KICAgICAgICAgeyAgICAgICAgICAgICAgICANCiAgICAgICAgICAgICBwX3RtcCA9IHAtMjsgICAgICAgICAgICAgICANCiAgICAgICAgICAgICBzdHJuY3B5KG1hY190bXAsIHBfdG1wLCAxNyk7ICAgICAgICAgICAgICAgDQogICAgICAgICAgICAgICAgICAgICAgICAgDQogICAgICAgICAgICAgZm9yKHM9MCxrPTA7IHM8NjsgcysrLGsrPTMpICAgICAgICAgICAgICAgIA0KICAgICAgICAgICAgIHsgICAgICAgICAgICAgICAgICAgIA0KICAgICAgICAgICAgICAgICBzdHJuY3B5KG51bV90bXAsIG1hY190bXAgKyBrLCAyKTsgICAgICAgICAgICAgICAgICAgDQogICAgICAgICAgICAgICAgLy9wcmludGYoInpob3V0aSBudW1fdG1wIGlzICVzXG4iLCBudW1fdG1wKTsgICAgICAgICAgICAgICAgICAgIA0KICAgICAgICAgICAgICAgIC8vdGFibGUuRW50cnlbc3RhX251bV0uQWRkcltzXT1hdG9pKG51bV90bXApOyAgICAgICAgICAgICAgICAgICAgDQogICAgICAgICAgICAgICAgbWFjX2xpc3QtPkVudHJ5W21hY19saXN0LT5OdW1dLkFkZHJbc10gPSBzMngobnVtX3RtcCk7ICANCiAgICAgICAgICAgICAgICAvL21hY19saXN0LT5FbnRyeVttYWNfbGlzdC0+TnVtXS5BZGRyW3NdID0gMDsgDQogICAgICAgICAgICAgfSAgICAgICAgICAgICAgICANCiAgICAgICAgICAgICBtYWNfbGlzdC0+TnVtICs9IDE7ICANCiAgICAgICAgICAgIA0KICAgICAgICAgfSAgICAgICAgICAgIA0KICAgICAgICBtZW1zZXQoYnVmLCAwLCBzaXplb2YoYnVmKSk7ICAgICAgICANCiAgICB9ICAgIA0KICAgICgqbWFjbGlzdCk9ICgqbWFjX2xpc3QpOw0KICAgIGlmKG1hY19saXN0KSANCiAgICB7DQogICAgICAgIGZyZWUobWFjX2xpc3QpOw0KICAgICAgICBtYWNfbGlzdD1OVUxMOw0KICAgIH0NCiAgICBwY2xvc2UocHApOyAvL7nYsdW53LXAOw0KICAgICAgICAgICAgDQp9DQoNCnN0YXRpYyB2b2lkIHp0ZV93bGFuX2dldF93aWZpX3N0YXRpb25fbGlzdChSVF84MDJfMTFfTUFDX1RBQkxFICpzdGFpb25saXN0KQ0KeyAgICANCiAgICAgICAgDQogICAgaW50IGkgPSAwOw0KICAgIGNoYXIgYnVmWzEyOF09ezB9Ow0KICAgIEZJTEUgKnBwMiA9IE5VTEw7DQogICAgY2hhciBtYWNfdG1wWzE4XSA9IHswfTsNCiAgICBjaGFyICpwX3RtcCA9IE5VTEw7DQogICAgY2hhciBzdGF0aW9uX21hY1sxOCozMl09ezB9OyAvLyAwMDowMDowMDowMDowMDowMDsNCiAgICBjaGFyIHN0YXRpb25pbmZvWzEwMF0gPSB7MH07DQogICAgY2hhciBtYWNfdGltZVszM10gPSB7MH07DQogICAgDQogICAgUlRfODAyXzExX01BQ19UQUJMRSAqc3RhX2xpc3QgPSBOVUxMOw0KICAgIHN0YV9saXN0ID0gKFJUXzgwMl8xMV9NQUNfVEFCTEUqKW1hbGxvYyhzaXplb2YoUlRfODAyXzExX01BQ19UQUJMRSkpOw0KICAgIGlmKHN0YV9saXN0ID09IE5VTEwpDQogICAgew0KICAgICAgICAgICAgYXNzZXJ0KHN0YV9saXN0KTsNCiAgICB9DQogICAgZWxzZQ0KICAgIHsNCiAgICAgICAgbWVtc2V0KHN0YV9saXN0LCAwLCBzaXplb2YoUlRfODAyXzExX01BQ19UQUJMRSkrMSk7DQogICAgfQ0KICAgIHp0ZV93bGFuX2dldF93aWZpX21hY19saXN0KHN0YV9saXN0KTsNCg0KICAgIGZvciAoaSA9IDA7IGkgPHN0YV9saXN0LT5OdW07IGkrKykNCiAgICB7DQogICAgICAgIHNwcmludGYoc3RhdGlvbl9tYWMgKyBpICogMTgsICIlMi4yWDolMi4yWDolMi4yWDolMi4yWDolMi4yWDolMi4yWDsiLFwNCiAgICAgICAgICAgICAgICAgICBzdGFfbGlzdC0+RW50cnlbaV0uQWRkclswXSwgc3RhX2xpc3QtPkVudHJ5W2ldLkFkZHJbMV0sDQogICAgICAgICAgICAgICAgICAgIHN0YV9saXN0LT5FbnRyeVtpXS5BZGRyWzJdLCBzdGFfbGlzdC0+RW50cnlbaV0uQWRkclszXSwNCiAgICAgICAgICAgICAgICAgICAgc3RhX2xpc3QtPkVudHJ5W2ldLkFkZHJbNF0sIHN0YV9saXN0LT5FbnRyeVtpXS5BZGRyWzVdKTsNCiAgICAgICAgc3ByaW50ZihzdGF0aW9uaW5mbywid2wgc3RhX2luZm8gJTIuMlg6JTIuMlg6JTIuMlg6JTIuMlg6JTIuMlg6JTIuMlggXA0KICAgICAgICAgICAgfCBncmVwIFwiaW4gbmV0d29ya1wiIHwgY3V0IC1kXCIgXCIgLWY0IiwNCiAgICAgICAgICAgICAgICAgICAgc3RhX2xpc3QtPkVudHJ5W2ldLkFkZHJbMF0sIHN0YV9saXN0LT5FbnRyeVtpXS5BZGRyWzFdLA0KICAgICAgICAgICAgICAgICAgICBzdGFfbGlzdC0+RW50cnlbaV0uQWRkclsyXSwgc3RhX2xpc3QtPkVudHJ5W2ldLkFkZHJbM10sDQogICAgICAgICAgICAgICAgICAgIHN0YV9saXN0LT5FbnRyeVtpXS5BZGRyWzRdLCBzdGFfbGlzdC0+RW50cnlbaV0uQWRkcls1XSk7DQogICAgICAgIA0KICAgICAgICBwcmludGYoIlslczolc11zdGF0aW9uaW5mbzolc1xuIixfX0ZJTEVfXywgX19GVU5DVElPTl9fLCBzdGF0aW9uaW5mbyk7DQogICAgICAgIHBwMiA9IHBvcGVuKHN0YXRpb25pbmZvLCAiciIpOyAvL72owaK53LXADQogICAgICAgIA0KICAgICAgICBpZihOVUxMID09IHBwMikgICAgDQogICAgICAgIHsgICAgICAgIA0KICAgICAgICAgICAgY29udGludWU7DQogICAgICAgIH0gDQogICAgICAgIG1lbXNldChidWYsIDAsIHNpemVvZihidWYpKTsgDQogICAgICAgIHN0cmNweShidWYsIkFCTk9STUFMIik7DQogICAgICAgIHdoaWxlKGZnZXRzKGJ1Ziwgc2l6ZW9mKGJ1ZiksIHBwMikpDQogICAgICAgIHsNCg0KICAgICAgICAgICAgaWYoc3RyY21wKGJ1ZiwiQUJOT1JNQUwiKT09MCkgIC8qcHMgY29tbWFuZCBlcnJvciovICANCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICBwcmludGYoIlslc10gZGV0ZWN0X3Byb2Nlc3Mgc3RyZXJyb3I6ICVzXG4iLF9fRlVOQ1RJT05fXyxzdHJlcnJvcihlcnJubykpOw0KICAgICAgIA0KICAgICAgICAgICAgICAgIHBjbG9zZShwcDIpOy8vudix1bnctcANCiAgICAgICAgICAgICAgICByZXR1cm4gOyANCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIG1lbXNldChtYWNfdGltZSwwLDMzKTsNCiAgICAgICAgICAgIHN0cm5jcHkobWFjX3RpbWUsYnVmLDMyKTsNCiAgICAgICAgICAgDQogICAgICAgICAgICBwcmludGYoIlslczolc11idWYwOiVzXG4iLF9fRklMRV9fLCBfX0ZVTkNUSU9OX18sIGJ1Zik7DQogICAgICAgICAgIA0KICAgICAgICAgICAgaWYoTlVMTCAhPSBtYWNfdGltZSkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICBzdGFfbGlzdC0+RW50cnlbaV0uQ29ubmVjdGVkVGltZSA9IGF0b2wobWFjX3RpbWUpOw0KICAgICAgICAgICAgICAgIHByaW50ZigiWyVzOiVzXUNvbm5lY3RlZFRpbWUtPk51bTM6JWRcbiIsX19GSUxFX18sIF9fRlVOQ1RJT05fXywgc3RhX2xpc3QtPkVudHJ5W2ldLkNvbm5lY3RlZFRpbWUpOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIHN0YV9saXN0LT5FbnRyeVtpXS5Db25uZWN0ZWRUaW1lID0gMDsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIG1lbXNldChidWYsIDAsIHNpemVvZihidWYpKTsgIA0KICAgICAgICAgICAgcHJpbnRmKCJbJXM6JXNdbWFjX3RpbWU6JWRcbiIsX19GSUxFX18sIF9fRlVOQ1RJT05fXywgbWFjX3RpbWUpOw0KICAgICAgICAgICAgDQogICAgICAgIH0NCiAgICAgICAgDQogICAgICBwY2xvc2UocHAyKTsgLy+52LHVudy1wA0KICAgIH0NCiAgICANCiAgICAoKnN0YWlvbmxpc3QpPSAoKnN0YV9saXN0KTsNCiAgICBpZihzdGFfbGlzdCkgDQogICAgew0KICAgICAgICBmcmVlKHN0YV9saXN0KTsgDQogICAgICAgIHN0YV9saXN0PU5VTEw7DQogICAgfQ0KICAgIA0KfQ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AwOw0KICAgIH0NCg0KICAgIHN0cmNweShidWYsIkFCTk9STUFMIik7DQogICAgDQpBZ2FpbjoNCiAgICB3aGlsZShmZ2V0cyhidWYsIDEyOCwgcHApICE9IE5VTEwpICAgDQoJeyAgICAgIA0KICAgICAgICBpZihzdHJjbXAoYnVmLCJBQk5PUk1BTCIpPT0wKSAgLy9mZ2V0cyBlcnJvciANCiAgICAgICAgew0KICAgICAgICAgICAgcHJpbnRmKCJbd2xhbi1pbnRlcmZhY2VdZXJyb3IhISBbJXNdIHN0cmVycm9yOiAlc1xuIixfX0ZVTkNUSU9OX18sc3RyZXJyb3IoZXJybm8pKTsNCiAgICAgICAgICAgIGlmKGVycm5vID09IEVJTlRSKSAvL0ludGVycnVwdGVkIHN5c3RlbSBjYWxsLHRyeSBhZ2Fpbg0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIGdvdG8gQWdhaW47DQogICAgICAgICAgICB9DQogICAgICAgICAgICANCiAgICAgICAgICAgIHBjbG9zZShwcCk7Ly9jbG9zZSBwaXBlDQogICAgICAgICAgICByZXR1cm4gMDsgDQogICAgICAgIH0NCg0KICAgICAgICBpZihzdHJsZW4oYnVmKSA+IDApDQogICAgICAgIHsNCgkJICAgIGlmKCh0bXAgPSBzdHJzdHIoYnVmLCAiOiIpKSAhPSBOVUxMKSAgICAgICAgICAgIA0KCQkgICAgeyAgICAgICAgICAgICAgICANCgkJICAgICAgdG90YWxfc3RhdGlvbl9udW0gKz0gMTsgICAgICAgICAgICANCgkJICAgIH0gIA0KICAgICAgICB9DQogICAgICAgIG1lbXNldChidWYsMCwxMjgpOw0KICAgICAgICBzdHJjcHkoYnVmLCJBQk5PUk1BTCIpOw0KICAgICAgICAJIAkJDQoJfSAgICANCgkNCiAgICBwY2xvc2UocHApOy8vY2xvc2UgcGlwZQ0KICAgIHByaW50ZigiW3dsYW4taW50ZXJmYWNlXSB0b3RhbF9zdGF0aW9uX251bT0lZFxuIix0b3RhbF9zdGF0aW9uX251bSk7D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