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aWMgdm9pZCBkZWx0YVRvTGluZWFyUGNtRW52ZWxvcGVEZWNvZGluZyAoSEFORExFX1NCUl9IRUFERVJfREFUQSBoSGVhZGVyRGF0YSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEhBTkRMRV9TQlJfRlJBTUVfREFUQSBoX3Nicl9kYXRhLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSEFORExFX1NCUl9QUkVWX0ZSQU1FX0RBVEEgaF9wcmV2X2RhdGEpOwpzdGF0aWMgdm9pZCBkZWNvZGVOb2lzZUZsb29ybGV2ZWxzIChIQU5ETEVfU0JSX0hFQURFUl9EQVRBIGhIZWFkZXJEYXRhLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBIQU5ETEVfU0JSX0ZSQU1FX0RBVEEgaF9zYnJfZGF0YSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSEFORExFX1NCUl9QUkVWX0ZSQU1FX0RBVEEgaF9wcmV2X2RhdGEpOwpzdGF0aWMgdm9pZCB0aW1lQ29tcGVuc2F0ZUZpcnN0RW52ZWxvcGUgKEhBTkRMRV9TQlJfSEVBREVSX0RBVEEgaEhlYWRlckRhdGEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSEFORExFX1NCUl9GUkFNRV9EQVRBIGhfc2JyX2RhdGEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSEFORExFX1NCUl9QUkVWX0ZSQU1FX0RBVEEgaF9wcmV2X2RhdGEpOwpzdGF0aWMgaW50IGNoZWNrRW52ZWxvcGVEYXRhIChIQU5ETEVfU0JSX0hFQURFUl9EQVRBIGhIZWFkZXJEYXRhLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBIQU5ETEVfU0JSX0ZSQU1FX0RBVEEgaF9zYnJfZGF0YSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICA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ZXggdG8gc2NhbGVmYWN0b3IgYmFuZCAqLwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50IHJlcykgICAgICAgICAvKiE8IGZyZXF1ZW55IHJlc29sdXRpb24gKi8KewogIGlmKHJlcyA9PSAwKQogIHsKICAgIGlmIChvZmZzZXQgPj0gMCkKICAgIHsKICAgICAgICBpZihpbmRleCA8IG9mZnNldCkKICAgICAgICAgICAgcHJldkRhdGFbaW5kZXhdID0gY3VyclZhbDsKICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBwcmV2RGF0YVsyKmluZGV4IC0gb2Zmc2V0XSA9IGN1cnJWYWw7CiAgICAgICAgICAgIHByZXZEYXRhWzIqaW5kZXgrMSAtIG9mZnNldF0gPSBjdXJyVmFsOwogICAgICAgIH0KICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBvZmZzZXQgPSAtb2Zmc2V0OwogICAgICAgIGlmIChpbmRleCA8IG9mZnNldCkKICAgICAgICB7CiAgICAgICAgICAgIHByZXZEYXRhWzMqaW5kZXhdID0gY3VyclZhbDsKICAgICAgICAgICAgcHJldkRhdGFbMyppbmRleCsxXSA9IGN1cnJWYWw7CiAgICAgICAgICAgIHByZXZEYXRhWzMqaW5kZXgrMl0gPSBjdXJyVmFsOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBwcmV2RGF0YVsyKmluZGV4ICsgb2Zmc2V0XSA9IGN1cnJWYWw7CiAgICAgICAgICAgIHByZXZEYXRhWzIqaW5kZXggKyAxICsgb2Zmc2V0XSA9IGN1cnJWYWw7CiAgICAgICAgfQogICAgfQogIH0KICBlbHNlCiAgICBwcmV2RGF0YVtpbmRleF0gPSBjdXJyVmFsOwp9CgoKCi8qIQogIFxicmllZiAgICBDb252ZXJ0IHJhdyBlbnZlbG9wZSBhbmQgbm9pc2VmbG9vciBkYXRhIHRvIGVuZXJneSBsZXZlbHMKCiAgVGhpcyBmdW5jdGlvbiBpcyBiZ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