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KICAgIHdoaWxlKGZnZXRzKGJ1ZiwgMTI4LCBwcCkgIT0gTlVMTCkgICAgICAgIA0KICAgIHsgICAgICAgICAgICAgDQogICAgICAgIA0KICAgICAgICBpZihzdHJjbXAoYnVmLCJBQk5PUk1BTCIpPT0wKSAgLypwcyBjb21tYW5kIGVycm9yKi8gIA0KICAgICAgICB7DQogICAgICAgICAgICBwcmludGYoIlslc10gZGV0ZWN0X3Byb2Nlc3Mgc3RyZXJyb3I6ICVzXG4iLF9fRlVOQ1RJT05fXyxzdHJlcnJvcihlcnJubykpOw0KICAgICAgICAgICAgaWYoZXJybm8gPT0gRUlOVFIpIC8vSW50ZXJydXB0ZWQgc3lzdGVtIGNhbGwstMvKsb/J1tjK1A0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIGdvdG8gYWdhaW47DQogICAgICAgICAgICB9DQogICAgICAgICAgICANCiAgICAgICAgICAgIHBjbG9zZShwcCk7Ly+52LHVudy1wA0KICAgICAgICAgICAgcmV0dXJuIDsgDQogICAgICAgICB9DQogICAgICAgICBtZW1zZXQobWFjX3RtcCwgMCwgMTgpOyAgICAgICAgICAgIA0KICAgICAgICAgaWYoKHAgPSBzdHJzdHIoYnVmLCAiOiIpKSAhPSBOVUxMKSAgICAgICAgICAgIA0KICAgICAgICAgeyAgICAgICAgICAgICAgICANCiAgICAgICAgICAgICBwX3RtcCA9IHAtMjsgICAgICAgICAgICAgICANCiAgICAgICAgICAgICBzdHJuY3B5KG1hY190bXAsIHBfdG1wLCAxNyk7ICAgICAgICAgICAgICAgDQogICAgICAgICAgICAgICAgICAgICAgICAgDQogICAgICAgICAgICAgZm9yKHM9MCxrPTA7IHM8NjsgcysrLGsrPTMpICAgICAgICAgICAgICAgIA0KICAgICAgICAgICAgIHsgICAgICAgICAgICAgICAgICAgIA0KICAgICAgICAgICAgICAgICBzdHJuY3B5KG51bV90bXAsIG1hY190bXAgKyBrLCAyKTsgICAgICAgICAgICAgICAgICAgDQogICAgICAgICAgICAgICAgLy9wcmludGYoInpob3V0aSBudW1fdG1wIGlzICVzXG4iLCBudW1fdG1wKTsgICAgICAgICAgICAgICAgICAgIA0KICAgICAgICAgICAgICAgIC8vdGFibGUuRW50cnlbc3RhX251bV0uQWRkcltzXT1hdG9pKG51bV90bXApOyAgICAgICAgICAgICAgICAgICAgDQogICAgICAgICAgICAgICAgbWFjX2xpc3QtPkVudHJ5W21hY19saXN0LT5OdW1dLkFkZHJbc10gPSBzMngobnVtX3RtcCk7ICANCiAgICAgICAgICAgICAgICAvL21hY19saXN0LT5FbnRyeVttYWNfbGlzdC0+TnVtXS5BZGRyW3NdID0gMDsgDQogICAgICAgICAgICAgfSAgICAgICAgICAgICAgICANCiAgICAgICAgICAgICBtYWNfbGlzdC0+TnVtICs9IDE7ICANCiAgICAgICAgICAgIA0KICAgICAgICAgfSAgICAgICAgICAgIA0KICAgICAgICBtZW1zZXQoYnVmLCAwLCBzaXplb2YoYnVmKSk7ICAgICAgICANCiAgICB9ICAgIA0KICAgICgqbWFjbGlzdCk9ICgqbWFjX2xpc3QpOw0KICAgIGlmKG1hY19saXN0KSANCiAgICB7DQogICAgICAgIGZyZWUobWFjX2xpc3QpOw0KICAgICAgICBtYWNfbGlzdD1OVUxMOw0KICAgIH0NCiAgICBwY2xvc2UocHApOyAvL7nYsdW53LXAOw0KICAgICAgICAgICAgDQp9DQoNCnN0YXRpYyB2b2lkIHp0ZV93bGFuX2dldF93aWZpX3N0YXRpb25fbGlzdChSVF84MDJfMTFfTUFDX1RBQkxFICpzdGFpb25saXN0KQ0KeyAgICANCiAgICAgICAgDQogICAgaW50IGkgPSAwOw0KICAgIGNoYXIgYnVmWzEyOF09ezB9Ow0KICAgIEZJTEUgKnBwMiA9IE5VTEw7DQogICAgY2hhciBtYWNfdG1wWzE4XSA9IHswfTsNCiAgICBjaGFyICpwX3RtcCA9IE5VTEw7DQogICAgY2hhciBzdGF0aW9uX21hY1sxOCozMl09ezB9OyAvLyAwMDowMDowMDowMDowMDowMDsNCiAgICBjaGFyIHN0YXRpb25pbmZvWzEwMF0gPSB7MH07DQogICAgY2hhciBtYWNfdGltZVszM10gPSB7MH07DQogICAgDQogICAgUlRfODAyXzExX01BQ19UQUJMRSAqc3RhX2xpc3QgPSBOVUxMOw0KICAgIHN0YV9saXN0ID0gKFJUXzgwMl8xMV9NQUNfVEFCTEUqKW1hbGxvYyhzaXplb2YoUlRfODAyXzExX01BQ19UQUJMRSkpOw0KICAgIGlmKHN0YV9saXN0ID09IE5VTEwpDQogICAgew0KICAgICAgICAgICAgYXNzZXJ0KHN0YV9saXN0KTsNCiAgICB9DQogICAgZWxzZQ0KICAgIHsNCiAgICAgICAgbWVtc2V0KHN0YV9saXN0LCAwLCBzaXplb2YoUlRfODAyXzExX01BQ19UQUJMRSkrMSk7DQogICAgfQ0KICAgIHp0ZV93bGFuX2dldF93aWZpX21hY19saXN0KHN0YV9saXN0KTsNCg0KICAgIGZvciAoaSA9IDA7IGkgPHN0YV9saXN0LT5OdW07IGkrKykNCiAgICB7DQogICAgICAgIHNwcmludGYoc3RhdGlvbl9tYWMgKyBpICogMTgsICIlMi4yWDolMi4yWDolMi4yWDolMi4yWDolMi4yWDolMi4yWDsiLFwNCiAgICAgICAgICAgICAgICAgICBzdGFfbGlzdC0+RW50cnlbaV0uQWRkclswXSwgc3RhX2xpc3QtPkVudHJ5W2ldLkFkZHJbMV0sDQogICAgICAgICAgICAgICAgICAgIHN0YV9saXN0LT5FbnRyeVtpXS5BZGRyWzJdLCBzdGFfbGlzdC0+RW50cnlbaV0uQWRkclszXSwNCiAgICAgICAgICAgICAgICAgICAgc3RhX2xpc3QtPkVudHJ5W2ldLkFkZHJbNF0sIHN0YV9saXN0LT5FbnRyeVtpXS5BZGRyWzVdKTsNCiAgICAgICAgc3ByaW50ZihzdGF0aW9uaW5mbywid2wgc3RhX2luZm8gJTIuMlg6JTIuMlg6JTIuMlg6JTIuMlg6JTIuMlg6JTIuMlggXA0KICAgICAgICAgICAgfCBncmVwIFwiaW4gbmV0d29ya1wiIHwgY3V0IC1kXCIgXCIgLWY0IiwNCiAgICAgICAgICAgICAgICAgICAgc3RhX2xpc3QtPkVudHJ5W2ldLkFkZHJbMF0sIHN0YV9saXN0LT5FbnRyeVtpXS5BZGRyWzFdLA0KICAgICAgICAgICAgICAgICAgICBzdGFfbGlzdC0+RW50cnlbaV0uQWRkclsyXSwgc3RhX2xpc3QtPkVudHJ5W2ldLkFkZHJbM10sDQogICAgICAgICAgICAgICAgICAgIHN0YV9saXN0LT5FbnRyeVtpXS5BZGRyWzRdLCBzdGFfbGlzdC0+RW50cnlbaV0uQWRkcls1XSk7DQogICAgICAgIA0KICAgICAgICBwcmludGYoIlslczolc11zdGF0aW9uaW5mbzolc1xuIixfX0ZJTEVfXywgX19GVU5DVElPTl9fLCBzdGF0aW9uaW5mbyk7DQogICAgICAgIHBwMiA9IHBvcGVuKHN0YXRpb25pbmZvLCAiciIpOyAvL72owaK53LXADQogICAgICAgIA0KICAgICAgICBpZihOVUxMID09IHBwMikgICAgDQogICAgICAgIHsgICAgICAgIA0KICAgICAgICAgICAgY29udGludWU7DQogICAgICAgIH0gDQogICAgICAgIG1lbXNldChidWYsIDAsIHNpemVvZihidWYpKTsgDQogICAgICAgIHN0cmNweShidWYsIkFCTk9STUFMIik7DQogICAgICAgIHdoaWxlKGZnZXRzKGJ1Ziwgc2l6ZW9mKGJ1ZiksIHBwMikpDQogICAgICAgIHsNCg0KICAgICAgICAgICAgaWYoc3RyY21wKGJ1ZiwiQUJOT1JNQUwiKT09MCkgIC8qcHMgY29tbWFuZCBlcnJvciovICANCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICBwcmludGYoIlslc10gZGV0ZWN0X3Byb2Nlc3Mgc3RyZXJyb3I6ICVzXG4iLF9fRlVOQ1RJT05fXyxzdHJlcnJvcihlcnJubykpOw0KICAgICAgIA0KICAgICAgICAgICAgICAgIHBjbG9zZShwcDIpOy8vudix1bnctcANCiAgICAgICAgICAgICAgICByZXR1cm4gOyANCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIG1lbXNldChtYWNfdGltZSwwLDMzKTsNCiAgICAgICAgICAgIHN0cm5jcHkobWFjX3RpbWUsYnVmLDMyKTsNCiAgICAgICAgICAgDQogICAgICAgICAgICBwcmludGYoIlslczolc11idWYwOiVzXG4iLF9fRklMRV9fLCBfX0ZVTkNUSU9OX18sIGJ1Zik7DQogICAgICAgICAgIA0KICAgICAgICAgICAgaWYoTlVMTCAhPSBtYWNfdGltZSkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICBzdGFfbGlzdC0+RW50cnlbaV0uQ29ubmVjdGVkVGltZSA9IGF0b2wobWFjX3RpbWUpOw0KICAgICAgICAgICAgICAgIHByaW50ZigiWyVzOiVzXUNvbm5lY3RlZFRpbWUtPk51bTM6JWRcbiIsX19GSUxFX18sIF9fRlVOQ1RJT05fXywgc3RhX2xpc3QtPkVudHJ5W2ldLkNvbm5lY3RlZFRpbWUpOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIHN0YV9saXN0LT5FbnRyeVtpXS5Db25uZWN0ZWRUaW1lID0gMDsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIG1lbXNldChidWYsIDAsIHNpemVvZihidWYpKTsgIA0KICAgICAgICAgICAgcHJpbnRmKCJbJXM6JXNdbWFjX3RpbWU6JWRcbiIsX19GSUxFX18sIF9fRlVOQ1RJT05fXywgbWFjX3RpbWUpOw0KICAgICAgICAgICAgDQogICAgICAgIH0NCiAgICAgICAgDQogICAgICBwY2xvc2UocHAyKTsgLy+52LHVudy1wA0KICAgIH0NCiAgICANCiAgICAoKnN0YWlvbmxpc3QpPSAoKnN0YV9saXN0KTsNCiAgICBpZihzdGFfbGlzdCkgDQogICAgew0KICAgICAgICBmcmVlKHN0YV9saXN0KTsgDQogICAgICAgIHN0YV9saXN0PU5VTEw7DQogICAgfQ0KICAgIA0K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aXBlIGZhaWxlZCEhXG4iKTsNCiAgICAgICAgcmV0dXJuIDA7DQogICAgfQ0KDQogICAgc3RyY3B5KGJ1ZiwiQUJOT1JNQUwiKTsNCiAgICANCkFnYWluOg0KICAgIHdoaWxlKGZnZXRzKGJ1ZiwgMTI4LCBwcCkgIT0gTlVMTCkgICANCgl7ICAgICAgDQogICAgICAgIGlmKHN0cmNtcChidWYsIkFCTk9STUFMIik9PTApICAvL2ZnZXRzIGVycm9yIA0KICAgICAgICB7DQogICAgICAgICAgICBwcmludGYoIlt3bGFuLWludGVyZmFjZV1lcnJvciEhIFslc10gc3RyZXJyb3I6ICVzXG4iLF9fRlVOQ1RJT05fXyxzdHJlcnJvcihlcnJubykpOw0KICAgICAgICAgICAgaWYoZXJybm8gPT0gRUlOVFIpIC8vSW50ZXJydXB0ZWQgc3lzdGVtIGNhbGwsdHJ5IGFnYWluDQogICAgICAgICAgICB7DQogICAgICAgICAgICAgICAgZ290byBBZ2FpbjsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIA0KICAgICAgICAgICAgcGNsb3NlKHBwKTsvL2Nsb3NlIHBpcGUNCiAgICAgICAgICAgIHJldHVybiAwOyANCiAgICAgICAgfQ0KDQogICAgICAgIGlmKHN0cmxlbihidWYpID4gMCkNCiAgICAgICAgew0KCQkgICAgaWYoKHRtcCA9IHN0cnN0cihidWYsICI6IikpICE9IE5VTEwpICAgICAgICAgICAgDQoJCSAgICB7ICAgICAgICAgICAgICAgIA0KCQkgICAgICB0b3RhbF9zdGF0aW9uX251bSArPSAxOyAgICAgICAgICAgIA0KCQkgICAgfSAgDQogICAgICAgIH0NCiAgICAgICAgbWVtc2V0KGJ1ZiwwLDEyOCk7DQogICAgICAgIHN0cmNweShidWYsIkFCTk9STUFMIik7DQogICAgICAgIAkgCQkNCgl9ICAgIA0KCQ0KICAgIHBjbG9zZShwcCk7Ly9jbG9zZSBwaXBlDQogICAgcHJpbnRmKCJbd2xhbi1pbnRlcmZhY2VdIHRvd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