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hZGVuY2UzX0ZyZXE7ICAgICAKICAgIFdPUkQgICAgd0NhZGVuY2UzXzJuZEZyZXE7ICAKICAgIFdPUkQgICAgd0NhZGVuY2UzX0FtcDsgICAgICAKCiAgICBXT1JEICAgIHdDYWRlbmNlNF9ycHRjbnQ7CiAgICBXT1JEICAgIHdDYWRlbmNlNF9vbjsgICAKICAgIFdPUkQgICAgd0NhZGVuY2U0X29mZjsKICAgIFdPUkQgICAgd0NhZGVuY2U0X0ZyZXE7ICAgCiAgICBXT1JEICAgIHdDYWRlbmNlNF8ybmRGcmVxOwogICAgV09SRCAgICB3Q2FkZW5jZTRfQW1wOwoKICAgIFdPUkQgICAgd0R1cmE7IAogICAgQllURSAgICBiUm93U3RhdHVzOyAKICAgIEJZVEUgICAgYlJlc2VydmU7ICAgICAgICAgICAgICAgIAp9VE9ORV9BVFRSOwoKLypUT05FICBJRCovCgojZGVmaW5lICAgICBTSUdOQUxfUklORyAgICAgICAgICAgICAgICAgICAgIChXT1JEKTB4ODEwMCAgICAgICAgLyog1fHB5SAqLwojZGVmaW5lICAgICBTSUdOQUxfUklOR19UV08gICAgICAgICAgICAgICAgIChXT1JEKTB4ODEwMSAgICAgICAgLyogMrbO1fHB5SAqLwojZGVmaW5lICAgICBTSUdOQUxfUklOR19USFJFRSAgICAgICAgICAgICAgIChXT1JEKTB4ODEwMiAgICAgICAgLyogM7bO1fHB5SAqLwojZGVmaW5lICAgICBTSUdOQUxfUklOR19GT1VSICAgICAgICAgICAgICAgIChXT1JEKTB4ODEwMyAgICAgICAgLyogNLbO1fHB5SAqLwojZGVmaW5lICAgICBTSUdOQUxfUklOR19MT05HICAgICAgICAgICAgICAgIChXT1JEKTB4ODEwNCAgICAgICAgLyogs6TKsbzk1fHB5SAqLwoKI2RlZmluZSAgICAgU0lHTkFMX1RPTkUgICAgICAgICAgICAgICAgICAgICAoV09SRCkweDgyMDAgICAgICAgIC8qILfF0vQgKi8KI2RlZmluZSAgICAgU0lHTkFMX1RPTkVfVFdPICAgICAgICAgICAgICAgICAoV09SRCkweDgyMDEgICAgICAgIC8qIDK2zrfF0vQgKi8KI2RlZmluZSAgICAgU0lHTkFMX1RPTkVfVEhSRUUgICAgICAgICAgICAgICAoV09SRCkweDgyMDIgICAgICAgIC8qIDO2zrfF0vQgKi8KI2RlZmluZSAgICAgU0lHTkFMX1RPTkVfRk9VUiAgICAgICAgICAgICAgICAoV09SRCkweDgyMDMgICAgICAgIC8qIDS2zrfF0vQgKi8KI2RlZmluZSAgICAgU0lHTkFMX1RPTkVfTE9ORyAgICAgICAgICAgICAgICAoV09SRCkweDgyMDQgICAgICAgIC8qILOkyrG85LfF0vQgKi8KClRPTkVfQVRUUiBUb25lQXR0cltdID0gewovKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIApUb25lSWQgICAgICAgICAgICAgICAgICAgICAgICAgIENhZGVuY2UgICAgQ2FkZW5jZTEgICAgICAgICAgICAgICAgQ2FkZW5jZTIgICAgICAgICAgICAgICBDYWRlbmNlMyAgICAgICAgICAgICAgQ2FkZW5jZTQgICAgICAgICAgICAgRHVyYSAgICBSb3dTdGF0dXMgUmVzZSovCntTSUdOQUxfUklORywgICAgICAgICAgICAgICAgICAgIDEsICAgICAgICAxLDIwMCw4MDAsMjUsMCwxMDAsICAgICAwLDAsMCwwLDAsMCwgICAgICAgICAgIDAsMCwwLDAsMCwwLCAgICAgICAgICAwLDAsMCwwLDAsMCwgICAgICAgICAxMjAwMCwgIDEsICAgICAgICAwfSwKe1NJR05BTF9SSU5HX1RXTywgICAgICAgICAgICAgICAgMiwgICAgICAgIDEsMTAwLDgwMCwyNSwwLDEwMCwgICAgIDEsMjAwLDgwMCwyNSwwLDEwMCwgICAgMCwwLDAsMCwwLDAsICAgICAgICAgIDAsMCwwLDAsMCwwLCAgICAgICAgIDEyMDAwLCAgMSwgICAgICAgIDB9LAp7U0lHTkFMX1JJTkdfVEhSRUUsICAgICAgICAgICAgICAzLCAgICAgICAgMSwxMDAsODAwLDI1LDAsMTAwLCAgICAgMSw0MDAsODAwLDI1LDAsMTAwLCAgICAxLDIwMCw4MDAsMjUsMCwxMDAsICAgMCwwLDAsMCwwLDAsICAgICAgICAgMTIwMDAsICAxLCAgICAgICAgMH0sCntTSUdOQUxfUklOR19GT1VSLCAgICAgICAgICAgICAgIDQsICAgICAgICAxLDEwMCw4MDAsMjUsMCwxMDAsICAgICAxLDQwMCw4MDAsMjUsMCwxMDAsICAgIDEsMzAwLDMwMCwyNSwwLDEwMCwgICAxLDIwMCw4MDAsMjUsMCwxMDAsICAxMjAwMCwgIDEsICAgICAgICAwfSwKe1NJR05BTF9SSU5HX0xPTkcsICAgICAgICAgICAgICAgMSwgICAgICAgIDEsNjAwMCwwLDI1LDAsMTAwLCAgICAgIDAsMCwwLDAsMCwwLCAgICAgICAgICAgMCwwLDAsMCwwLDAsICAgICAgICAgIDAsMCwwLDAsMCwwLCAgICAgICAgIDEyMDAwLCAgMSwgICAgICAgIDB9LAoKe1NJR05BTF9UT05FLCAgICAgICAgICAgICAgICAgICAgMSwgICAgICAgIDEsNDAsNDAwLDQ1MCwwLDEwMCwgICAgIDAsMCwwLDAsMCwwLCAgICAgICAgICAgMCwwLDAsMCwwLDAsICAgICAgICAgIDAsMCwwLDAsMCwwLCAgICAgICAgIDEyMDAwLCAgMSwgICAgICAgIDB9LAp7U0lHTkFMX1RPTkVfVFdPLCAgICAgICAgICAgICAgICAyLCAgICAgICAgMSw0MCw0MDAsNDUwLDAsMTAwLCAgICAgMSwxMDAsODAwLDQ1MCwwLDEwMCwgICAwLDAsMCwwLDAsMCwgICAgICAgICAgMCwwLDAsMCwwLDAsICAgICAgICAgMTIwMDAsICAxLCAgICAgICAgMH0sCntTSUdOQUxfVE9ORV9USFJFRSwgICAgICAgICAgICAgIDMs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RvIHN0b3AgcG9ydCAyIHJpbmciKTsgIAogICAgd2hpbGUoIShkQyA9IGdldGNoYXIoKSkpIHsgO30KICAgIFNMSUNfU3RvcF9TaWduYWwoMSwgMCk7IAogICAgCiAgICBTTElDX01zZ0NscigpOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgIFNMSUNfRGVidWdMZXZlbCgwKTsKICAgIHJldHVybjsKfQovKmxpbnQgLXJlc3RvcmUqLwovKmxpbnQgLXNhdmUgLWUxNCovIAppbnQgbWFpbihpbnQgYXJnYywgY2hhcioqIGFyZ3YpCnsKICAgIFNJR05BTF9EQVRBIHRTaWcgPSB7MH07CiAgICBEV09SRCB3UmV2ID0gMDsgICAgCiAgICBXT1JEIHdQb3J0ID0gMDsKICAgIFdPUkQgd1BvcnRfdHlwZSA9IDA7CiAgICBXT1JEIHdUaW1lU2xvdCA9IDA7CiAgICBEV09SRCB3VGlkID0gMDsKICAgIFdPUkQgd1RpbWUgPSAwOwogICAgV09SRCB3TGV2ZWwgPSAwOwogICAgVE9ORV9BVFRSICpwVG9uZUF0dHIgPSBOVUxMOwoKICAgIHdSZXYgPSBTTElDX0luaXRpYWwoKTsKICAgIGlmICh3UmV2ID09IFNMSUNfRkFJTCkKICAgIHsKICAgICAgICBwcmludGYoIlxuIFNMSUMgaW5pdGlhbCBmYWlsZWQhIik7IAogICAgICAgIGV4aXQoMSk7CiAgICB9CiAgICAKICAgIGlmIChhcmdjIDwgMikKICAgIHsKICAgICAgICBwcmludGYoIlxuIFVzYWdlOiVzIGNtZCBwYXJtLi4uIiwgYXJndlswXSk7CiAgICAgICAgZXhpdCgxKTsgICAgCiAgICB9CiAgICAKICAgIGlmICgwID09IHN0cmNtcCgicmVzZXQiLCBhcmd2WzFdKSkgLyogcG9ydCByZXNldCAqLwogICAgewogICAgICAgIGlmIChhcmdjICE9IDQpCiAgICAgICAgewogICAgICAgICAgICBwcmludGYoIlxuIFVzYWdlOiVzIHJlc2V0IHBvcnQgdHlwZSIsIGFyZ3ZbMF0pOwogICAgICAgICAgICBleGl0KDEpOwogICAgICAgIH0KICAgICAgICB3UG9ydCA9IGF0b2koYXJndlsyXSk7CiAgICAgICAgd1BvcnRfdHlwZSA9IGF0b2koYXJndlszXSk7CiAgICAgICAgd1JldiA9IFNMSUNfUmVzZXRQb3J0KHdQb3J0LCB3UG9ydF90eXBlKTsgICAgICAgIAogICAgfSBlbHNlIGlmICgwID09IHN0cmNtcCgic2xvdHNldCIsIGFyZ3ZbMV0pKSAvKnRpbWUgc2xvdCBzZXQgKi8KICAgIHsKICAgICAgICBpZiAoYXJnYyAhPSA1KQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCJcbiBVc2FnZTolcyBzbG90c2V0IHBvcnQgdHlwZSB0aW1lc2xvdFxuIiwgYXJndlswXSk7CiAgICAgICAgICAgIGV4aXQoMSk7CiAgICAgICAgfSAgICAKICAgICAgICB3UG9ydCA9IGF0b2koYXJndlsyXSk7CiAgICAgICAgd1BvcnRfdHlwZSA9IGF0b2koYXJndlszXSk7ICAKICAgICAgICB3VGltZVNsb3QgPSBhdG9pKGFyZ3ZbNF0pOwogICAgICAgIHdSZXYgPSBTTElDX1NlbGVjdFRpbWVTbG90KHdQb3J0LCB3UG9ydF90eXBlLCB3VGltZVNsb3QsIHdUaW1lU2xvdCk7CiAgICAgICAgICAgICAgICAgICAgCiAgICB9IGVsc2UgaWYgKDAgPT0gc3RyY21wKCJyZXZlcnNlIiwgYXJndlsxXSkpIC8qIHBvbGFyaXR5IHJldmVyc2UgKi8KICAgIHsKICAgICAgICBpZiAoYXJnYyAhPSAzKQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCJcbiBVc2FnZTolcyByZXZlcnNlIHBvcnRcbiIsIGFyZ3ZbMF0pOwogICAgICAgICAgICBleGl0KDEpOwogICAgICAgIH0KICAgICAgICB3UG9ydCA9IGF0b2koYXJndlsyXSk7CiAgICAgICAgd1JldiA9IFNMSUNfRlhTX1BvbGFyaXR5U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ICovCiAgICB7CiAgICAgICAgd1JldiA9IFNMSUNfUENNX1NldF9XQigpOyAgICAgICAgICAgIAogICAgfSBlbHNlIGlmICgwID09IHN0cmNtcCgibG9jayIsIGFyZ3ZbMV0pKSAvKiBsb2NrIHBvcnQgKi8KICAgIHsKICAgICAgICBpZiAoYXJnYyAhPSA0KQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCJcbiBVc2FnZTolcyBsb2NrIHBvcnQgdHlwZVxuIiwgYXJndlswXSk7CiAgICAgICAgICAgIGV4aXQoMSk7CiAgICAgICAgfQogICAgICAgIHdQb3J0ID0gYXRvaShhcmd2WzJdKTsKICAgICAgICB3UG9ydF90eXBlID0gYXRvaShhcmd2WzNdKTsKICAgICAgICB3UmV2ID0gU0xJQ19Qb3J0X0xvY2sod1BvcnQsIHdQb3J0X3R5cGUpOyAKICAgIH0gZWxzZSBpZiAoMCA9PSBzdHJjbXAoInVubG9jayIsIGFyZ3ZbMV0pKSAvKiB1bmxvY2sgcG9ydCAqLwogICAgewogICAgICAgIGlmIChhcmdjICE9IDQpCiAgICAgICAgewogICAgICAgICAgICBwcmludGYoIlxuIFVzYWdlOiVzIHVubG9jayBwb3J0IHR5cGVcbiIsIGFyZ3ZbMF0pOwogICAgICAgICAgICBleGl0KDEpOwogICAgICAgIH0KICAgICAgICB3UG9ydCA9IGF0b2koYXJndlsyXSk7CiAgICAgICAgd1BvcnRfdHlwZSA9IGF0b2koYXJndlszXSk7CiAgICAgICAgd1JldiA9IFNMSUNfUG9ydF9VbkxvY2sod1BvcnQsIHdQb3J0X3R5cGUpOyAgICAgICAgIAogICAgfSBlbHNlIGlmICgwID09IHN0cmNtcCgiY29kZWNzZXQiLCBhcmd2WzFdKSkgICAgICAgICAgICAvKiBjb2RlY3NldCAqLwogICAgewogICAgICAgIEJZVEUgYkJ1ZlsyNTZdOwogICAgICAgIEJZVEUgYlRtcCA9IDA7CiAgICAgICAgQllURSBiU2l6ZSA9IDA7CiAgICAgICAgRFdPUkQgYlBhcm07CiAgICAgICAgaWYgKGFyZ2MgIT0gMykKICAgICAgICB7CiAgICAgICAgICAgIHByaW50ZigiXG4gVXNhZ2U6JXMgY29kZWNzZXQgcGFybXN0cmluZ1xuIiwgYXJndlswXSk7CiAgICAgICAgICAgIGV4aXQoMSk7CiAgICAgICAgfSAgICAgICAgCiAgICAgICAgc3NjYW5mKCYoYXJndlsyXVtiVG1wXSksICIleCIsICZiUGFybSk7CgogICAgICAgIGJCdWZbYlNpemUrK10gPSBiUGFybTsKCQlwcmludGYoIlxuIGNvZGVjc2V0IGFkZHIgJXhcbiIsIGJCdWZbMF0pOwogICAgICAgIGZvciAoYlRtcCA9IDA7IGFyZ3ZbMl1bYlRtcF0hPSAwOyBiVG1wKyspCiAgICAgICAgewogICAgICAgICAgICBpZiAoYXJndlsyXVtiVG1wXSAhPSAnICcpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHByaW50ZigiXG4gY29kZWNzZXQgYXJndlsyXVslZF0gJXhcbiIsIGJUbXAsIGFyZ3ZbMl1bYlRtcF0pOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgICAgIHNzY2FuZigmKGFyZ3ZbMl1bYlRtcF0pLCAiJXgiLCAmYlBhcm0pOwogICAgICAgICAgICBiQnVmW2JTaXplKytdID0gYlBhcm07CiAgICAgICAgfQoJCXByaW50ZigiXG4gY29kZWNzZXQgdmFsdWUgJXhcbiIsIGJCdWZbMV0pOwogICAgICAgIHdSZXYgPSBTTElDX0NmZ19Db2RlYyhiQnVmKTsKICAgIH0gZWxzZSBpZiAoMCA9PSBzdHJjbXAoImNvZGVjZ2V0IiwgYXJndlsxXSkpICAgLyogY29kZWNnZXQgKi8KICAgIHsKICAgICAgICBCWVRFIGJCdWZbMjU2XTsKICAgICAgICBCWVRFIGJTaXplID0gMDsKICAgICAgICBEV09SRCBiUGFybTsKICAgICAgICBpZiAoYXJnYyAhPSAzKQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCJcbiBVc2FnZTolcyBjb2RlY2dldCBhZGRyZXNzXG4iLCBhcmd2WzBdKTsKICAgICAgICAgICAgZXhpdCgxKTsKICAgICAgICB9ICAgICAgICAKICAgICAgICBzc2NhbmYoJihhcmd2WzJdWzBdKSwgIiV4IiwgJmJQYXJtKTsKICAgICAgICBiQnVmWzBdID0gYlBhcm07CgogICAgICAgIHdSZXYgPSBTTElDX1JlYWRfQ29kZWMoYkJ1Zik7ICAgICAgCiAgICB9IGVsc2UgaWYgKDAgPT0gc3RyY21wKCJyYW1zZXQiLCBhcmd2WzFdKSkgICAgICAgICAgICAvL3JhbXNldCAKICAgIHsKICAgICAgICBCWVRFIGJCdWZbMjU2XTsKICAgICAgICBCWVRFIGJUbXAgPSAwOwogICAgICAgIEJZVEUgYlNpemUgPSAwOwogICAgICAgIERXT1JEIGJQYXJtOwogICAgICAgIGlmIChhcmdjICE9IDMpCiAgICAgICAgewogICAgICAgICAgICBwcmludGYoIlxuIFVzYWdlOiVzIHJhbXNldCBwYXJtc3RyaW5nXG4iLCBhcmd2WzBdKTsKICAgICAgICAgICAgZXhpdCgxKTsKICAgICAgICB9ICAgICAgIAogICAgICAgIHNzY2FuZigmKGFyZ3ZbMl1bYlRtcF0pLCAiJXgiLCAmYlBhcm0pOwogICAgICAgIGJCdWZbYlNpemUrK10gPSAoQllURSliUGFybTsKICAgICAgICBiQnVmW2JTaXplKytdID0gKGJQYXJtPj44KSYoMHgwNyk7CgogICAgICAgIGZvciAoYlRtcCA9IDA7IGFyZ3ZbMl1bYlRtcF0hPSAwOyBiVG1wKyspCiAgICAgICAgewogICAgICAgICAgICBpZiAoYXJndlsyXVtiVG1wXSAhPSAnICcpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgICAgICBzc2NhbmYoJihhcmd2WzJdW2JUbXBdKSwgIiV4IiwgJmJQYXJtKTsKICAgICAgICAgICAgYkJ1ZltiU2l6ZSsrXSA9IChCWVRFKWJQYXJtOwogICAgICAgICAgICBiQnVmW2JTaXplKytdID0gKGJQYXJtPj44KSYoMHhmZik7CiAgICAgICAgICAgIGJCdWZbYlNpemUrK10gPSAoYlBhcm0+PjE2KSYoMHhmZik7CiAgICAgICAgICAgIGJCdWZbYlNpemUrK10gPSAoYlBhcm0+PjI0KSYoMHhmZik7CiAgICAgICAgfQogICAgICAgIHdSZXYgPSBTTElDX0NmZ19SYW0oYkJ1Zik7CgogICAgfWVsc2UgaWYgKDAgPT0gc3RyY21wKCJyYW1nZXQiLCBhcmd2WzFdKSkgICAvL3JhbWdldAogICAgewogICAgICAgIEJZVEUgYkJ1ZlsyNTZdOwogICAgICAgIEJZVEUgYlNpemUgPSAwOwogICAgICAgIERXT1JEIGR3UGFybTsKICAgICAgICBXT1JEICpwQWRkciA9IChXT1JEICopJmJCdWZbMF07CiAgICAgICAgaWYgKGFyZ2MgIT0gMykKICAgICAgICB7CiAgICAgICAgICAgIHByaW50ZigiXG4gVXNhZ2U6JXMgcmFtZ2V0IGFkZHJlc3NcbiIsIGFyZ3ZbMF0pOwogICAgICAgICAgICBleGl0KDEpOwogICAgICAgIH0KICAgICAgICBzc2NhbmYoJihhcmd2WzJdWzBdKSwgIiV4IiwgJmR3UGFybSk7CiAgICAgICAgKnBBZGRyID0gKFdPUkQpZHdQYXJtOwogICAgICAgIHByaW50ZigicmVhZCByYW0gJWQgXG4iLCAoaW50KWJCdWYpOwogICAgICAgIHdSZXYgPSBTTElDX1JlYWRfUmFtKGJCdWYpOwogIAogICAgfSBlbHNlIGlmICgwID09IHN0cmNtcCgiaG9va2xvdyIsIGFyZ3ZbMV0pKSAvKiBjb25maWcgaG9vayBsb3cgdGltZSAqLwogICAgewogICAgICAgIGlmIChhcmdjICE9IDQpCiAgICAgICAgewogICAgICAgICAgICBwcmludGYoIlxuIFVzYWdlOiVzIGhvb2tsb3cgcG9ydCB0aW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MF0pOwogICAgICAgICAgICBleGl0KDEpOwogICAgICAgIH0KICAgICAgICB3TGV2ZWwgPSBhdG9pKGFyZ3ZbMl0pOwogICAgICAgIFNMSUNfRGVidWdMZXZlbCh3TGV2ZWwpOyAgCiAgICB9IGVsc2UgaWYgKDAgPT0gc3RyY21wKCJzZWxmdGVzdCIsIGFyZ3ZbMV0pKSAvKiBzZWxmIHRlc3QgKi8KICAgIHsKICAgICAgICBpZiAoYXJnYyAhPSAyKQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCJcbiBVc2FnZTolcyBzZWxmdGVzdFxuIiwgYXJndlswXSk7CiAgICAgICAgICAgIGV4aXQoMSk7CiAgICAgICAgfQogICAgICAgIFNMSUNfU2VsZlRlc3QoKTsgICAgICAgICAgICAgICAgICAgICAgCiAgICB9IAogICAgZWxzZSBpZiAoMCA9PSBzdHJjbXAoImxlZyIsIGFyZ3ZbMV0pKSAvKiBjaGlwIGluaXRpYWwgICovCiAgICB7CgogICAgICAgIGlmIChhcmdjICE9IDMpCiAgICAgICAgewogICAgICAgICAgICBwcmludGYoIlxuIFVzYWdlOiVzIGxlZyBudW0oMTppbml0LG90aGVyIG51bSA6bm8gaW5pdClcbiIsIGFyZ3ZbMF0pOwogICAgICAgICAgICBleGl0KDEpOwogICAgICAgIH0KICAgICAgICB3UG9ydD1hdG9pKGFyZ3ZbMl0pOwogICAgICAgIGlmKHdQb3J0PT0xKQogICAgICAgIHsKICAgICAgICAgICAgd1JldiA9IFNMSUNfRGV2X0luaXQoKTsKICAgICAgICAgICAgaWYod1Jldj09U0xJQ19GQUlMKSAKICAgICAgICAgICAgICAgIHByaW50ZigibGVnIGluaXQgZmFpbCEhXG4iKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgcHJpbnRmKCJsZWcgaW5pdCBzdWNjZXNzIVxuIik7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICAgICAgZXhpdCgxKTsKICAgICAgIAogICAgfQogICAgZWxzZSBpZiAoMCA9PSBzdHJjbXAoInRlc3QiLCBhcmd2WzFdKSkgLyogMTEyIHRlc3Qgc3RhcnQgKi8KICAgIHsKICAgICAgICBXcml0ZUNtZF90IENtZCA9IHswfTsKICAgICAgICBpZiAoYXJnYyAhPSA2KQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCJcbiBVc2FnZTolcyB0ZXN0IHBvcnQgdHlwZSBpdGVtXG4iLCBhcmd2WzBdKTsKICAgICAgICAgICAgZXhpdCgxKTsKICAgICAgICB9CgogICAgICAgIENtZC5wb3J0ICAgICAgICA9IGF0b2koYXJndlsyXSk7CiAgICAgICAgQ21kLnBvcnRfdHlwZSAgID0gYXRvaShhcmd2WzNdKTsgIAogICAgICAgIENtZC5pdGVtICAgICAgICA9IGF0b2koYXJndls0XSk7CiAgICAgICAgQ21kLm9ibGlnYXRlICAgID0gYXRvaShhcmd2WzVdKTsKICAgICAgICB3UmV2ID0gU0xJQ18xMTJUZXN0U3RhcnQoKFdyaXRlQ21kX3QgKikmQ21kKTsKICAgIH0KICAgIGVsc2UgaWYgKDAgPT0gc3RyY21wKCJyZWFkcmVnIiwgYXJndlsxXSkpICAgLyogY29kZWNnZXQgKi8KICAgIHsKICAgICAgICBCWVRFIGJCdWZbMjU2XTsKICAgICAgICBCWVRFIGJTaXplID0gMTsKICAgICAgICBCWVRFIGxvb3BpOwogICAgICAgIGlmIChhcmdjICE9IDQpCiAgICAgICAgewogICAgICAgICAgICBwcmludGYoIlxuIFVzYWdlOiVzIGNvZGVjZ2V0IHBvcnQgdHlwZSBhZGRyZXNzIHNpemVcbiIsIGFyZ3ZbMF0pOwogICAgICAgICAgICBleGl0KDEpOwogICAgICAgIH0KICAgICAgICB3UG9ydCA9IGF0b2koYXJndlsyXSk7CiAgICAgICAgd1BvcnRfdHlwZSA9IGF0b2koYXJndlszXSk7CiAgICAgICAgCiAgICAgICAgZm9yKGxvb3BpPTA7IGxvb3BpPD0xMjY7IGxvb3BpKyspCiAgICAgICAgewogICAgICAgICAgICBiQnVmWzBdID0gbG9vcGk7CiAgICAgICAgICAgIHdSZXYgPSBTTElDX1JlYWRfQ29kZWMoYkJ1Zik7CiAgICAgICAgICAgIGlmICh3UmV2ICE9IFNMSUNfU1VDQ0VTUykgCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9ICAgIAogICAgfQogICAgZWxzZSBpZiAoMCA9PSBzdHJjbXAoInJlYWRyYW0iLCBhcmd2WzFdKSkgCiAgICB7CiAgICAgICAgQllURSBiU2l6ZSA9IDQ7ICAvL3NpbGljb25sYWIgMzIxNzYgcmVhZHJhbSAyOGJpdCBvbmNlICAgCiAgICAgICAgV09SRCBsb29waTsgICAgICAKICAgICAgICB1bmlvbiAKICAgICAgICB7CiAgICAgICAgICAgIERXT1JEIHdSZXR1cm52YWx1ZTsKICAgICAgICAgICAgV09SRCB3QWRkcmVzc19vbjEwOwogICAgICAgIH0geGNoYW5nZTsKICAgICAgICAKICAgICAgICBpZiAoYXJnYyAhPSA0KQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCJcbiBVc2FnZTolcyByZWFkcmFtIHBvcnQgcG9ydF90eXBlIHJlZ18xMFxuIiwgYXJndlswXSk7CiAgICAgICAgICAgIGV4aXQoMSk7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHdQb3J0ID0gYXRvaShhcmd2WzJdKTsKICAgICAgICB3UG9ydF90eXBlID0gYXRvaShhcmd2WzNdKTsgCiAgICAgICAgCiAgICAgICAgcHJpbnRmKCJfX19fc2hvdyBhbGwgcmFtc19fX19fIFxuIik7CiAgICAgICAgZm9yKGxvb3BpPTA7IGxvb3BpPD0xNTY1OyBsb29waSsrKQogICAgICAgIHsKICAgICAgICAgICAgeGNoYW5nZS53QWRkcmVzc19vbjEwID0gbG9vcGk7CiAgICAgICAgICAgIHdSZXYgPSBTTElDX1JlYWRfUmFtKChCWVRFICopICZ4Y2hhbmdlLndBZGRyZXNzX29uMTApOwogICAgICAgICAgICBpZiAod1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NlX2ZkLHJldCk7CgkJICAKICAgICAgICAgICAgIGNsb3NlKHZvaWNlX2ZkKTsKIAoKCSAgICBwcmludGYoInZvaWNlIHRlc3QgIVxuIik7CgkjZWxzZQoKICAgICAgICAgIGludCByZXQgPSAwOwogICAgICAgICAgaW50IHNlbDsKICAgICAgICAgIFRfVm9pY2VfUGFyYSAqcGFyYTsKCSAgIHNlbCA9IGF0b2koYXJndlsyXSk7Ly8wIGdzbSAgOzEgdGRuYmh3OzJ0ZG5ic2YgOzN0ZHdic2YKICAgIAkgIGlmIChzZWwgPT0gMCl7CgkgICAgICAgcGFyYSA9ICZnc21od3BhcmE7CQogICAgCSAgfQoJICBlbHNlIGlmKHNlbCA9PSAxKXsKCSAgICAgICBwYXJhID0gJnRkbmJod3BhcmE7CgkgIH0JCgkgIGVsc2UgaWYoc2VsID09IDIpewoJICAgICAgIHBhcmEgPSAmdGRuYnNmcGFyYTsJCgoJICB9CQkKCSAgZWxzZSBpZihzZWwgPT0gMyl7CiAgICAgICAgICAgICBwYXJhID0gJnRkd2JzZnBhcmE7CQoJICB9CgkgIGVsc2V7CiAgICAgICAgICAgIHByaW50Zigidm9pY2UgbGliIHRlc3QgaW52YWxpZCBwYXJhXG4iKTsKICAgICAgICAgICAgZXhpdCgxKTsKICAgICAgICB9CiAgICAgICByZXQgPSB2b2ljZV9vcGVuKHBhcmEpOwogICAgICAgcHJpbnRmKCJzbGN0b29sOiB2b2ljZV9vcGVuLHJldD0lZC5cbiIscmV0KTsKICAgICAgICAgICAgICB1c2xlZXAoMTAwMDAwMCk7CgoJICAgCiAgICAgICByZXQgPSB2b2ljZV9jbG9zZShwYXJhKTsKICAgICAgICNlbmRpZgoKCiAgICB9CiAgICBlbHNlIGlmICgwID09IHN0cmNtcCgidnBsb29wIiwgYXJndlsxXSkpIAogICAgewogICAgICAgICAgaW50IHJldCA9IDA7CgoJICAgICBpbnQgcGF0aCA9IDA7CSAgIAoJICAgICBwYXRoID0gYXRvaShhcmd2WzJdKTsvLzAgaGFuc2V0IDsxIHNwOzIgaGVhZHNldDsyNTUgb2ZmICAgICAgICAKICAgICAgICAgICAgcHJpbnRmKCJzbGljdG9vbCB2cGxvb3AgcGF0aD0lZCBcbiIscGF0aCk7CiAgICAgICAgICAgIGlmKChwYXRoID49MCkmJihwYXRoIDw9MikpewoJCSAgICByZXQgPSBTTElDX1BDTV9TZXRfTkIoKTsKCQkgICAgaWYgKHJldCAhPSAwKQoJCSAgICB7CgkJICAgICAgICBwcmludGYoIlNMSUNfUENNX1NldF9OQiBFcnJvciByZXQ9JWQhXG4iLHJldCk7IAoJCSAgICAgICAgZXhpdCgxKTsKCQkgICAgfQkJCgkJCXJldCA9IFNMSUNfU3RhcnRfUENNKCk7CgkJICAgICBpZiAocmV0ICE9IDApCgkJICAgIHsKCQkgICAgICAgIHByaW50ZigiU0xJQ19TdGFydF9QQ00gRXJyb3IgcmV0PSVkIVxuIixyZXQpOyAKCQkgICAgICAgIGV4aXQoMSk7CgkJICAgIH0JCQkgCgkgICAgIH0KCSAgICAgZWxzZSBpZihwYXRoID09IDI1NSl7CgkJICAgIHJldCA9IFNMSUNfU3RvcF9QQ00oKTsJIAoJCSAgICAgaWYgKHJldCAhPSAwKQoJCSAgICB7CgkJICAgICAgICBwcmludGYoIlNMSUNfU3RvcF9QQ00gRXJyb3IgcmV0PSVkIVxuIixyZXQpOyAKCQkgICAgICAgIGV4aXQoMSk7CgkJICAgIH0JCQkJIAoJICAgICAgICAgICBTTElDX1JlbGVhc2UoKTsKCQkJCQoJICAgICB9CQkJCgogICAgICAgICAgICByZXQgPSB2b2ljZV9WcGxvb3AoJnBhdGgpOwoJICAgICBpZiAocmV0ICE9IDApCgkgICAgewoJICAgICAgICBwcmludGYoInZwbG9vcCBFcnJvciByZXQ9JWQhXG4iLHJldCk7IAoJICAgICAgICBleGl0KDEpOwoJICAgIH0JCiAKICAgIH0KCQogICAgZWxzZQogICAgewogICAgICAgIHByaW50Zigibm90IHN1cHBvcnQhXG4iKTsgICAgCiAgICB9ICAgCgogICAgaWYgKHdSZXYgIT0gU0xJQ19TVUNDRVNTKQogICAgewogICAgICAgIHByaW50ZigiXG4gUnVuIEVycm9yIVxuIik7IAogICAgICAgIGV4aXQoMSk7CiAgICB9CiAgICAKICAgIFNMSUNfUmVsZWFzZSgpOwogICAgcmV0dXJuIDA7Cn0KLypsaW50IC1yZXN0b3JlKi8KCg==