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KSB7CiNpZiAoQklUUyA9PSAxNikKICAgICAgICBtZW1jcHkoZGF0YV9kaXNwbGF5LCBkYXRhX2J1ZmZlciwgcy0+c2NyX3dpZHRoICogMik7CiAgICAgICAgZGF0YV9idWZmZXIgKz0gcy0+c2NyX3dpZHRoOwogICAgICAgIGRhdGFfZGlzcGxheSArPSBkc19nZXRfbGluZXNpemUocy0+ZHMpOwojZWxzZQogICAgICAgIGludCBqOwogICAgICAgIGZvciAoaiA9IDA7IGogPCBzLT5zY3Jfd2lkdGg7IGorKywgZGF0YV9kaXNwbGF5ICs9IEJJVFMgLyA4LCBkYXRhX2J1ZmZlcisrKSB7CiAgICAgICAgICAgIHVpbnQxNl90IGNvbG9yID0gKmRhdGFfYnVmZmVyOwogICAgICAgICAgICB1aW50MzJfdCBkZXN0X2NvbG9yID0gZ2x1ZShyZ2JfdG9fcGl4ZWwsIEJJVFMpKAogICAgICAgICAgICAgICAgICAgICAgICAgICAoKGNvbG9yICYgMHhmODAwKSAqIDB4MTA4KSA+PiAxMSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgKChjb2xvciAmIDB4N2UwKSAqIDB4NDEpID4+IDksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICgoY29sb3IgJiAweDFmKSAqIDB4MjEpID4+IDIKICAgICAgICAgICAgICAgICAgICAgICAgICAgKTsKICAgICAgICAgICAgU0VUX1BJWEVMKGRhdGFfZGlzcGxheSwgZGVzdF9jb2xvcik7CiAgICAgICAgfQojZW5kaWYKICAgIH0KfQoKI3VuZGVmIEJJVFMKI3VuZGVmIFNFVF9QSVhFTAo=