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ZGRyOwoJdV9pbnQgZ2F0ZVdheTsKCWNoYXIgaWZOYW1lW0lGX05BTUVTSVpFXTsKfTsKCiNkZWZpbmUgQlVGU0laRSA4MTkyCgojZGVmaW5lIFNQSU5MT0NLX0lPQ19NQUdJQwknUycKCiNkZWZpbmUgU1BJTkxPQ0tfR0VUX1NUQVRVUyAgX0lPV1IoU1BJTkxPQ0tfSU9DX01BR0lDLDEsY2hhciAqKQoKI2RlZmluZSBSRUFEX0JVRl9TSVpFIDU2Ci8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqICAgICAgICAgICAgICAgICAgICAgIElubGluZSBmdW5jdGlvbiBpbXBsZW1lbnRhdGlvbnMgICAgICAgICAgICAgICAgICAgICAgICAqCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmlubGluZSBjaGFyICpzdHJpcF9zcGFjZShjaGFyICpzdHIpCnsKCXdoaWxlICgqc3RyID09ICcgJykKCQlzdHIrKzsKCXJldHVybiBzdHI7Cn0KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogICAgICAgICAgICAgICAgICAgICAgTG9jYWwgZnVuY3Rpb24gaW1wbGVtZW50YXRpb25zICAgICAgICAgICAgICAgICAgICAgICAgICoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KLyog0LTOxLz+stnX97qvyv0gKi8KaW50IHdyaXRlX2ZpbGUoY29uc3QgY2hhciAqZmlsZXBhdGgsIGludCBmbGFncywgY29uc3QgY2hhciAqYnVmLCBpbnQgc2l6ZSkKewoJaW50IGZkID0gMDsKCWludCByZXQgPSAwOwoKCWZkID0gb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oJICAgICAgICAxOTAwICsgdGltZXB0ci0+dG1feWVhcik7CglyZXR1cm4gcmVzdWx0Owp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKiAgICAgICAgICAgICAgICAgICAgICBHbG9iYWwgZnVuY3Rpb24gaW1wbGVtZW50YXRpb25zICAgICAgICAgICAgICAgICAgICAgICAgKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCi8vaW5wdXQ6ICBudl9zdHI6bnbE2sjd1rjV6yAgICAqIG52X3BhcmFtIL3izva687LOyv21xNa41esKLy9vdXRwdXQ6ICAgcGFyYW1fbnVtICAgICBudl9wYXJhbQovL8q+wP06Ci8vICAgaW50IG51bTsKLy8gICBjaGFyKiogbnZfcGFyYW07Ci8vICAgbnVtID0gbnZfYW5hbHl6ZShudl9zdHIsJm52X3BhcmFtKQovLyAgIHN0cmNtcChudl9wYXJhbVswXSwiYWFhIikgLi4uCi8vICAgc3RyY21wKG52X3BhcmFtWzFdLCJiYmIiKSAuLi4KLy8gICAuLi4KLy8gICBmcmVlKG52X3BhcmFtKTsKLy8KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCgppbnQgbnZfYW5hbHl6ZShjaGFyKiBudl9zdHIsIGNoYXIqKiogbnZfcGFyYW0pCnsKCWludCBwYXJhbV9udW0gPSAxOwoJaW50IGkgPSAwOwoJY2hhciogc3RyX3B0cjsKCWNoYXIqKiBtZW1fcHRyOwoJY2hhciogdG1wX3B0cjsKCWZvciAoc3RyX3B0ciA9IG52X3N0cjsgKnN0cl9wdHIgIT0gJ1wwJzsgc3RyX3B0cisrKSB7CgkJaWYgKCpzdHJfcHRyID09ICcrJykKCQkJcGFyYW1f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