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ICAgCiAqIEB3YXJuaW5nIAogKi8KaW50ICBhbXRfd3JpdGVfbnZfaXRlbShOdlBhcmFtX0FNVCBudlBhcmFtLCBVSU5UOCAqTnZJdGVtRGF0YSwgVUlOVDMyIE52SXRlbUxlbikKewogICAgVUlOVDMyICByZXRDb2RlID0gQ1BOVl9FUlJPUjsKICAgIFVJTlQzMiAgaSA9IDA7CgogICAgaWYgKG52UGFyYW0gPj0gTUFYQUJOVlBBUkFNX05WUEFSQU0gfHwgTlVMTCA9PSBOdkl0ZW1EYXRhIHx8IE52SXRlbUxlbiA9PSAwKQogICAgewogICAgICAgIHJldHVybiAgLTE7CiAgICB9CgogICAgZm9yIChpID0gMDsgaSA8IChzaXplb2YoZ19hbXRDb21tTnZDZmcpIC8gc2l6ZW9mIChnX2FtdENvbW1OdkNmZ1swXSkpOyBpKyspCiAgICB7CiAgICAgICAgaWYgKCBudlBhcmFtID09IGdfYW10Q29tbU52Q2ZnW2ldLmR3TXNnSUQgKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKE52SXRlbUxlbiA+IGdfYW10Q29tbU52Q2ZnW2ldLmR3U2l6ZSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgTnZJdGVtTGVuID0gZ19hbXRDb21tTnZDZmdbaV0uZHdTaXplOwogICAgICAgICAgICB9CgogICAgICAgICAgICByZXRDb2RlID0gYW10X252cm9fd3JpdGUoZ19hbXRDb21tTnZDZmdbaV0uZHdBZGRyZXNzLCBOdkl0ZW1MZW4sIE52SXRlbURhdGEpOwoKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgfQogICAgICAgICAgICAKICAgIGlmIChyZXRDb2RlICE9IENQTlZfT0spCiAgICB7CiAgICAgICAgYXNzZXJ0KDApOwogICAgfQogICAgcmV0dXJuICAwOwp9CgovKioKICogQGJyaWVmILbBs/bSu8/uTlZST8r9vt0KICogQHBhcmFtIG52UGFyYW0gILjDTlbP7sDg0M0KICogQHBhcmFtIE52SXRlbURhdGEgtsG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zaXplb2YgKGdfYW10Q29tbU52Q2ZnWzBdKSk7IGkrKykKICAgIHsKICAgICAgICBpZiAoIG52UGFyYW0gPT0gZ19hbXRDb21tTnZDZmdbaV0uZHdNc2dJRCApCiAgICAgICAgewogICAgICAgICAgICBpZiAoTnZJdGVtTGVuID4gZ19hbXRDb21tTnZDZmdbaV0uZHdTaXplKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBOdkl0ZW1MZW4gPSBnX2FtdENvbW1OdkNmZ1tpXS5kd1NpemU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0Q29kZSA9IGNwbnZfTnZJdGVtUmVhZChnX2FtdENvbW1OdkNmZ1tpXS5kd0FkZHJlc3MsIE52SXRlbURhdGEsIE52SXRlbUxlbik7CiAgICAgICAgICAgIGJyZWFrOyAgICAgICAgCiAgICAgICAgfQogICAgfQogICAgaWYocmV0Q29kZSA9PSBDUE5WX0VSUk9SKQogICAgewogICAgICAgICByZXR1cm4gIC0xOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgICByZXR1cm4gIDA7CiAgICB9Cn0KCi8qKgogKiBAYnJpZWYg0LTJ+rL6suLK1LHq1r7OuwogKiBAcGFyYW0gbnZQYXJhbSAgyfqy+rLiytSx6ta+zrvP7sO2vtnWtQogKiBAcGFyYW0gTnZJdGVtRGF0YSC0/dC0yOvK/b7dCiAqIEByZXR1cm4gMCCzybmmICAKICogQHJldHVybiAtMSDKp7DcCiAqIEBub3RlICAgCiAqIEB3YXJuaW5nIAogKi8KaW50IGFtdF93cml0ZV90ZXN0X2ZsYWdfaXRlbShOdlBhcmFtX0FNVEZsYWdzIG52UGFyYW0sVUlOVDggKk52SXRlbURhdGEpCnsKICAgIFVJTlQzMiByZXRDb2RlID0gQ1BOVl9FUlJPUjsKICAgIFVJTlQzMiBBTVRGbGFnQWRkcmVzcyA9IDA7CiAgICBCWVRFICAgcFRlc3RJbmZvQnVmWzFdOwogICAgQllURSAgICpwQnl0ZTsKICAgIGludCBieX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cmV0dXJuIDA7CiAgICB9Cn0KCgogLyoqCiAqIEBicmllZiDTptPDsuPF0LbPtbHHsMrHt/HKx2FtdMSjyr0KICogQHBhcmFtIAogKiBAcmV0dXJuIDEgYW10xKPKvQogKiBAcmV0dXJuIDAgbm9ybWFsxKPKvQogKiBAbm90ZSAgIAogKiBAd2FybmluZyAKICovCmludCBpc19hbXRfbW9kZSh2b2lkKQp7CiAgICBjaGFyIHZlck1vZGVbNF0gPSB7MH07CiAgICBpbnQgcmV0ID0gMDsKCiAgICByZXQgPSBzY19jZmdfZ2V0KCJ2ZXJfbW9kZSIsIHZlck1vZGUsIHNpemVvZih2ZXJNb2RlKSk7CiAgICBpZighc3RybmNtcCh2ZXJNb2RlLCAiMCIsIHN0cmxlbigiMCIpKSkKICAgIHsKICAgICAgICByZXQgPSAxOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIHJldCA9IDA7CiAgICB9CgkKCXJldHVybiByZXQ7Cn0KCi8qKgogKiBAYnJpZWYgyejWw2Jvb3TG9LavxKPKvQogKiBAcGFyYW0gYm9vdG1vZGUgMrj219a92rXEserKtjogCiAqICAgICAgICAgICAgICB7MHg1NCwweDAwfSA6IHVzZXIsCiAqICAgICAgICAgICAgICB7MHg1NCwweDAxfSA6IGRlYnVnLAogKiAgICAgICAgICAgICAgezB4NTQsMHgwMn0gOiBmYWN0b3J5LAogKiAgICAgICAgICAgICAgezB4NTQsMHg0RH0gOiBhbXQsCiAqIEByZXR1cm4gMCCzybmmICAKICogQHJldHVybiAtMSDKp7DcCiAqIEBub3RlICAgCiAqIEB3YXJuaW5nIAogKi8KdW5zaWduZWQgaW50IGFtdF9zZXRfYm9vdG1vZGUodW5zaWduZWQgY2hhciAgYm9vdG1vZGVbXSkKewogICAgdW5zaWduZWQgaW50ICByZXQgPSBDUE5WX09LOwoKICAgIGlmKENQTlZfRVJST1IgPT0gY3Budl9DaGFuZ2VGc1BhcnRpdGlvbkF0dHIoRlNfSU1BR0VGUywgMSkpCiAgIC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