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RwczovLwogICAgaW50IGkgPSAwOwogICAgY2hhciBodHRwc19wcmVmaXhbXSA9ICJodHRwczovLyI7CiAgICBmb3IoaT0wO2k8ODtpKyspCiAgICB7CiAgICAgICAgaWYodXJsW2ldICE9IGh0dHBzX3ByZWZpeFtpXSkKICAgICAgICB7CiAgICAgICAgICAgIHByaW50ZigiaWxsZWdhbCB1cmwgPSAlcy5cbiIsdXJsKTsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIH0KICAgIH0KIAogICAgY29uc3QgY2hhciAqdGVtcCA9IHVybCtpOwogICAgd2hpbGUoKnRlbXAgIT0gJy8nKSAgLy9uZXh0IC8KICAgIHsKICAgICAgICBpZigqdGVtcCA9PSAnXDAnKSAgLy8KICAgICAgICB7CiAgICAgICAgICAgIHByaW50ZigiaWxsZWdhbCB1cmwgPSAlcy5cbiIsdXJsKTsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIH0KICAgICAgICB0ZW1wKys7CiAgICB9CiAKICAgIGNvbnN0IGNoYXIgKmhvc3RfcG9ydCA9IHVybCtpOwogICAgd2hpbGUoKmhvc3RfcG9ydCAhPSAnOicgJiYgKmhvc3RfcG9ydCAhPSAnLycpICAvL9XStb0gOrvy1d8gLyC94cr4CiAgICB7CiAgICAgICAgaG9zdF9wb3J0ICsrOwogICAgfQogCiAgICBpbnQgaG9zdF9sZW4gPSBob3N0X3BvcnQtdXJsLWk7ICAvL7z1tfRodHRwczovLwogICAgaW50IHBhdGhfbGVuID0gc3RybGVuKHRlbXApOwogICAgY2hhciAqaG9zdF90ZW1wID0gKGNoYXIgKiltYWxsb2MoaG9zdF9sZW4gKyAxKTsgIC8vtuDSu7j219a3+7SuveHK+LHqyrYgXDAKICAgIGlmKGhvc3RfdGVtcCA9PSBOVUxMKQogICAgewogICAgICAgIHByaW50ZigibWFsbG9jIGhvc3QgZmFpbC5cbiIpOwogICAgICAgIHJldHVybiAtMTsKICAgIH0KICAgIGlmKCpob3N0X3BvcnQrKyA9PSAnOicpICAvL3VybCDW0NPQtsu/2gogICAgewogICAgICAgICpwb3J0ID0gMDsKICAgICAgICB3aGlsZSgqaG9zdF9wb3J0ICE9Jy8nICYmICpob3N0X3BvcnQgIT0nXDAnKSAgLy/Krr341sbX1rf7tK7XqrPJyv3X1gogICAgICAgIHsKICAgICAgICAgICAgKnBvcnQgKj0gMTA7CiAgICAgICAgICAgICpwb3J0ICs9ICgqaG9zdF9wb3J0IC0gJzAnKTsKICAgICAgICAgICAgaG9zdF9wb3J0ICsrOwogICAgICAgIH0KICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICAqcG9ydCA9IDQ0MzsKICAgIH0KIAogICAgY2hhciAqcGF0aF90ZW1wID0gKGNoYXIgKiltYWxsb2MocGF0aF9sZW4gKyAxKTsgIC8vtuDSu7j219a3+7SuveHK+LHqyrYgXDAKICAgIGlmKHBhdGhfdGVtcCA9PSBOVUxMKQogICAgewogICAgICAgIHByaW50ZigibWFsbG9jIHBhdGggZmFpbC5cbiIpOwogICAgICAgIGZyZWUoaG9zdF90ZW1wKTsKICAgICAgICByZXR1cm4gLTE7CiAgICB9CiAgICBtZW1jcHkoaG9zdF90ZW1wLHVybCtpLGhvc3RfbGVuKTsKICAgIG1lbWNweShwYXRoX3RlbXAsdGVtcCxwYXRoX2xlbik7CiAgICBob3N0X3RlbXBbaG9zdF9sZW5dID0gJ1wwJzsKICAgIHBhdGhfdGVtcFtwYXRoX2xlbl0gPSAnXDAnOwogICAgKmhvc3QgPSBob3N0X3RlbXA7CiAgICAqcGF0aCA9IHBhdGhfdGVtcDsKICAgIHJldHVybiAwOwp9CiAKaW50IGh0dHBzX2luaXQoaHR0cHNfY29udGV4dF90ICpjb250ZXh0KQp7CglpbnQgcmV0ID0gMDsKICAgIGlmKGNvbnRleHQgPT0gTlVMTCkKICAgIHsKICAgICAgICBwcmludGYoImluaXQgaHR0cHNfY29udGV4dF90IGlzIG51bGwuXG4iKTsKICAgICAgICByZXR1cm4gLTE7CiA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glwcmludGYoIlNTTF9jb25uZWN0IHJldCAlZCBcbiIscmV0KTsKICAgIGlmKHJldCA9PSAtMSkKICAgIHsKICAgICAgICBnb3RvIGh0dHBzX2luaXRfZmFpbDsKICAgIH0KICAgIHJldHVybiAwOwpodHRwc19pbml0X2ZhaWw6CiAgICBodHRwc191bmluaXQoY29udGV4dCk7CiAgICByZXR1cm4gLTE7Cn0KIAppbnQgaHR0cHNfcmVhZChodHRwc19jb250ZXh0X3QgKmNvbnRleHQsdm9pZCogYnVmZixpbnQgbGVuKQp7CiAgICBpZihjb250ZXh0ID09IE5VTEwgfHwgY29udGV4dC0+c3NsID09IE5VTEwpCiAgICB7CiAgICAgICAgcHJpbnRmKCJyZWFkIGh0dHBzX2NvbnRleHRfdCBvciBzc2wgaXMgbnVsbC5cbiIpOwogICAgICAgIHJldHVybiAtMTsKICAgIH0KICAgIHJldHVybiBTU0xfcmVhZChjb250ZXh0LT5zc2wsYnVmZixsZW4pOwp9CiAKaW50IGh0dHBzX3dyaXRlKGh0dHBzX2NvbnRleHRfdCAqY29udGV4dCxjb25zdCB2b2lkKiBidWZmLGludCBsZW4pCnsKICAgIGlmKGNvbnRleHQgPT0gTlVMTCB8fCBjb250ZXh0LT5zc2wgPT0gTlVMTCkKICAgIHsKICAgICAgICBwcmludGYoIndyaXRlIGh0dHBzX2NvbnRleHRfdCBvciBzc2wgaXMgbnVsbC5cbiIpOwogICAgICAgIHJldHVybiAtMTsKICAgIH0KICAgIHJldHVybiBTU0xfd3JpdGUoY29udGV4dC0+c3NsLGJ1ZmYsbGVuKTsKfQogCmludCBodHRwc19nZXRfc3RhdHVzX2NvZGUoaHR0cHNfY29udGV4dF90ICpjb250ZXh0LCBpbnQgKmNvbnRlbnRfbGVuKQp7CiAgICBpbnQgcmV0OwogICAgaW50IGZsYWcgPTA7CiAgICBpbnQgcmVjdl9sZW4gPSAwOwogICAgY2hhciByZXNfaGVhZGVyWzEwMjRdID0gezB9OwoJCglpZihjb250ZXh0ID09IE5VTEwgfHwgY29udGV4dC0+c3NsID09IE5VTEwpCiAgICB7CiAgICAgICAgcHJpbnRmKCJnZXQgc3RhdHVzIGh0dHBzX2NvbnRleHRfdCBvciBzc2wgaXMgbnVsbC5cbiIpOwogICAgICAgIHJldHVybiAtMTsKICAgIH0KCQogICAgd2hpbGUocmVjdl9sZW4gPCAoc2l6ZW9mKHJlc19oZWFkZXIpLTEpKQogICAgewogICAgICAgIHJldCA9IFNTTF9yZWFkKGNvbnRleHQtPnNzbCwgcmVzX2hlYWRlcityZWN2X2xlbiwgMSk7CiAgICAgICAgaWYocmV0PDEpICAvLyByZWN2IGZhaWwKICAgICAgICB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICAvL9XStb3P7NOmzbe1xM23sr/Qxc+iLCDBvbj2IlxyXG4izqq31rjuteMKICAgICAgICBpZigocmVzX2hlYWRlcltyZWN2X2xlbl09PSdccicmJihmbGFnPT0wfHxmbGFnPT0yKSl8fChyZXNfaGVhZGVyW3JlY3ZfbGVuXT09J1xuJyYmKGZsYWc9PTF8fGZsYWc9PTMpKSkKICAgICAgICB7CiAgICAgICAgICAgIGZsYWcrKzsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgZmxhZyA9IDA7CiAgICAgICAgfQogICAgICAgIHJlY3ZfbGVuKz1yZXQ7CiAgICAgICAgaWYoZmxhZz09NCkKICAgICAgICB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIC8vcHJpbnRmKCJbaHR0cF0gcmVjdl9sZW49JWQgcmVzX2hlYWRlciA9ICVzLlxuIixyZWN2X2xlbixyZXNfaGVhZGVyKTsKICAgIC8qu/HIoc/s06bNt7XE0MXPoiovCiAgICBpbnQgc3RhdHVzX2NvZGUgPSAtMTsKICAgIGNoYXIgKnBvcyA9IHN0cnN0cihyZXNfaGVhZGVyLCAiSFRUUC8iKTsKICAgIGlmKHBvcykKICAgIHsKICAgICAg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F4X2xlbi1yZWN2X3NpemUpOwoJICAgaWYocmV0IDwgMSkKICAgICAgIHsKICAgICAgICAgICBicmVhazsKICAgICAgIH0KICAgICAgIHJlY3Zfc2l6ZSArPSByZXQ7CiAgICB9CiAgICByZXR1cm4gcmVjdl9zaXplOwp9Ci8vW0NodW5rtPPQoV1bu9iztV1bQ2h1bmvK/b7dzOVdW7vYs7VdW0NodW5rtPPQoV1bu9iztV1bQ2h1bmvK/b7dzOVdW7vYs7VdWzBdW7vYs7VdW2Zvb3RlcsTayN2jqNPQtcS7sKOpXVu72LO1XQovL9ei0uJjaHVuay1zaXplysfS1Mquwfm9+NbGtcRBU0NJScLrse3KvrXEo6yxyMjnODZBRaOoyrW8yrXEyq7B+b341sbTprjDysejujM4MzY2MTY1o6mjrLzGy+OzybOktsjTprjDysejujM0NDc4o6yx7cq+tNO72LO11q6689PQwazQ+LXEMzQ0NzjX1r3atcTK/b7dCmludCBodHRwc19yZWFkX2NodW5rZWRfY29udGVudChodHRwc19jb250ZXh0X3QgKmNvbnRleHQsY2hhciAqKnJlc3BfY29udGV0LGludCBtYXhfbGVuKQp7ICAgCiAgICBpbnQgcmV0ID0gMDsKCWludCBmbGFnID0gMDsKICAgIGludCByZWN2X3NpemUgPSAwOwoJCglpbnQgcmVjdl9sZW4gPSAwOwogICAgY2hhciBjaHVua19oZWFkZXJbMTAyNF0gPSB7MH07CgkKCWludCByZWFkX2ZsYWcgPSAwOwoJaW50IHJlYWRfbGVuID0gMTsKCQkKCWlmKGNvbnRleHQgPT0gTlVMTCB8fCBjb250ZXh0LT5zc2wgPT0gTlVMTCkKICAgIHsKICAgICAgICBwcmludGYoInJlYWQgY29udGVudCBodHRwc19jb250ZXh0X3Qgb3Igc3NsIGlzIG51bGwuXG4iKTsKICAgICAgICByZXR1cm4gLTE7CiAgICB9CgkKICAgIHdoaWxlKHJlY3Zfc2l6ZSA8IG1heF9sZW4pCiAgICB7CQkKCQlpZiAocmVhZF9mbGFnID09IDApIHsKCQkJ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pbAoJCQl7CgkJCQlicmVhazsKCQkJfQoJCQlyZWFkX2xlbiA9IDE7CgkJCXJlYWRfZmxhZyA9IDA7CgkJCXJlY3Zfc2l6ZSArPSByZXQ7CgkJfSAKCQllbHNlIHsKCQkJcmV0ID0gU1NMX3JlYWQoY29udGV4dC0+c3NsLCBjaHVua19oZWFkZXIsIHJlYWRfbGVuKTsKCQkJcHJpbnRmKCJjaHVua19oZWFkZXIjIyVzIyNcbiIsIGNodW5rX2hlYWRlcik7CgkJCWJyZWFrOwoJCX0KCiAgICB9CiAgICByZXR1cm4gcmVjdl9zaXplOwp9CgogCmludCBodHRwc191bmluaXQoaHR0cHNfY29udGV4dF90ICpjb250ZXh0KQp7CiAgICBpZihjb250ZXh0ID09IE5VTEwpCiAgICB7CiAgICAgICAgcHJpbnRmKCJ1bmluaXQgaHR0cHNfY29udGV4dF90IGlzIG51bGwuXG4iKTsKICAgICAgICByZXR1cm4gLTE7CiAgICB9CgogICAgaWYoY29udGV4dC0+aG9zdCAhPSBOVUxMKQogICAgewogICAgICAgIC8vZnJlZShjb250ZXh0LT5ob3N0KTsKICAgICAgICBjb250ZXh0LT5ob3N0ID0gTlVMTDsKICAgIH0KCQogICAgaWYoY29udGV4dC0+cGF0aCAhPSBOVUxMKQogICAgewogICAgICAgIC8vZnJlZShjb250ZXh0LT5wYXRoKTsKICAgICAgICBjb250ZXh0LT5wYXRoID0gTlVMTDsKICAgIH0KCiAgICBpZihjb250ZXh0LT5zc2wgIT0gTlVMTCkKICAgIHsKICAgICAgICBTU0xfc2h1dGRvd24oY29udGV4dC0+c3NsKTsKICAgICAgICAvL1NTbF9mcmVlKGNvbnRleHQtPnNzbCk7CiAgICAgICAgY29udGV4dC0+c3NsID0gTlVMTDsKICAgIH0KICAgIGlmKGNvbnRleHQtPnNzbF9jdCAhPSBOVUxMKQogICAgewogICAgICAgIFNTTF9DVFhfZnJlZShjb250ZXh0LT5zc2xfY3QpOwogICAgICAgIGNvbnRleHQtPnNzbF9jdCA9IE5VTEw7CiAgICB9CiAgICBpZihjb250ZXh0LT5zb2NrX2ZkID4gMCkKICAgIHsKICAgICAgICBjbG9zZShjb250ZXh0LT5zb2NrX2ZkKTsKICAgICAgICBjb250ZXh0LT5zb2NrX2ZkID0gLTE7CiAgICB9CiAgICByZXR1cm4gMDsKfQoK