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xIYW5kbGVyTWF4OyBpKyspIAogICAgewogICAgICAgIHNwID0gJndlYnNVcmxIYW5kbGVyW2ldOwogICAgICAgIGlmIChzcC0+aGFuZGxlciAmJiBnc3RybmNtcChzcC0+dXJsUHJlZml4LCB3cC0+cGF0aCwgc3AtPmxlbikgPT0gMCkgCiAgICAgICAgewogICAgICAgICAgICBpZiAoZmlyc3QpIAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB3ZWJzU2V0RW52KHdwKTsKICAgICAgICAgICAgICAgIGZpcnN0ID0gMDsKICAgICAgICAgICAgfQoJCQkKCQkJaWYod2Vic1ZhbGlkKHdwKT09IDApewoJCQkJc29mdGFwX2Fzc2VydCgid2Vic1VybEhhbmRsZXJSZXF1ZXN0IDIiKTsKCQkJfQoKICAgICAgICAgICAgaWYgKCgqc3AtPmhhbmRsZXIpKHdwLCBzcC0+dXJsUHJlZml4LCBzcC0+d2ViRGlyLCBzcC0+YXJnLCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdwLT51cmwsIHdwLT5wYXRoLCB3cC0+cXVlcnkpKSAKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCF3ZWJzVmFsaWQod3ApKSAKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdHJhY2UoMCwgVCgid2ViczogaGFuZGxlciAlcyBjYWxsZWQgd2Vic0RvbmUsIGJ1dCBkaWRuJ3QgcmV0dXJuIDFcbiIpLCBzcC0+dXJsUHJlZml4KTsKICAgICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGlmIChpID49IHdlYnNVcmxIYW5kbGVyTWF4KSAKICAgIHsKICAgICAgICB3ZWJzRXJyb3Iod3AsIDIwMCwgVCgiTm8gaGFuZGxlciBmb3IgdGhpcyBVUkwiKSk7CiAgICB9CiAgICByZXR1cm4gMDsKfQoKc3RhdGljIGNo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