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YgKGkgPCBmb250X3dpZHRoKSB7CgkgICAgLyogSW52ZXJ0IGJhY2tncm91bmQgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqLwoJICAgIHBhdHRlcm4gfD0gMHgzOwoKCX0KCWVsc2UgewoJICAgIC8qIEJhY2tncm91bmQgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKi8KCSAgICBwYXR0ZXJuIHw9IDB4MjsKCX0KCWlmICgoaSAmIDMpID09IDMpIHsKCSAgICAqcHRyID0gcGF0dGVybjsKCSAgICAqKHB0ciArIGZvbnRfaGVpZ2h0ICogMTYpID0gMHhhYTsKCSAgICBwdHIgKys7CgkgICAgcGF0dGVybiA9IDA7Cgl9CglwYXR0ZXJuIDw8PSAyOwogICAgfQoKICAgIC8qIER1cGxpY2F0ZSB0aGlzIGxpbmUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqLwogICAgZm9yIChpID0gMTsgaSA8IGZvbnRfaGVpZ2h0OyBpKyspIHsKCW1lbWNweSAoKHZvaWQgKilwdHIsICh2b2lkICopKHB0ciAtIDE2KSwgMTYpOwoJcHRyICs9IDE2OwogICAgfQoKICAgIGZvciAoOyBpIDwgNjQ7IGkrKykgewoJbWVtY3B5ICgodm9pZCAqKShwdHIgKyAxNiksICh2b2lkICopcHRyLCAxNik7CglwdHIgKz0gMTY7CiAgICB9CgogICAgLyogU2VsZWN0IGN1cnNvciBtb2RlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICB3cml0ZUJ5dGUgKExDRF9DVVJTT1JfQ05UTCwgMSk7Cn0KI2VuZGlmCiNlbmRpZgo=