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GlzX2NvbnZlcnRpYmxlPF9QLCBwb2ludGVyPjo6dmFsdWU+Ojp0eXBlKiA9IDApCiAgICAgICAgOiBfX21faXRlcl8oX19pdC5fX21faXRlcl8pLCBfX3B0cl8oX19pdC5fX3B0cl8pIHt9CgogICAgX0xJQkNQUF9JTkxJTkVfVklTSUJJTElUWSByZWZlcmVuY2Ugb3BlcmF0b3IqKCkgY29uc3Qge3JldHVybiAqX19wdHJfO30KICAgIF9MSUJDUFBfSU5MSU5FX1ZJU0lCSUxJVFkgcG9pbnRlciBvcGVyYXRvci0+KCkgY29uc3Qge3JldHVybiBfX3B0cl87fQoKICAgIF9MSUJDUFBfSU5MSU5FX1ZJU0lCSUxJVFkgX19kZXF1ZV9pdGVyYXRvciYgb3BlcmF0b3IrKygpCiAgICB7CiAgICAgICAgaWYgKCsrX19wdHJfIC0gKl9fbV9pdGVyXyA9PSBfX2Jsb2NrX3NpemUpCiAgICAgICAgewogICAgICAgICAgICArK19fbV9pdGVyXzsKICAgICAgICAgICAgX19wdHJfID0gKl9fbV9pdGVyXzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICp0aGlzOwogICAgfQoKICAgIF9MSUJDUFBfSU5MSU5FX1ZJU0lCSUxJVFkgX19kZXF1ZV9pdGVyYXRvciBvcGVyYXRvcisrKGludCkKICAgIHsKICAgICAgICBfX2RlcXVlX2l0ZXJhdG9yIF9fdG1wID0gKnRoaXM7CiAgICAgICAgKysoKnRoaXMpOwogICAgICAgIHJldHVybiBfX3RtcDsKICAgIH0KCiAgICBfTElCQ1BQX0lOTElORV9WSVNJQklMSVRZIF9fZGVxdWVfaXRlcmF0b3ImIG9wZXJhdG9yLS0oKQogICAgewogICAgICAgIGlmIChfX3B0cl8gPT0gKl9fbV9pdGVyXykKICAgICAgICB7CiAgICAgICAgICAgIC0tX19tX2l0ZXJfOwogICAgICAgICAgICBfX3B0cl8gPSAqX19tX2l0ZXJfICsgX19ibG9ja19zaXplOwogICAgICAgIH0KICAgICAgICAtLV9fcHRyXzsKICAgICAgICByZXR1cm4gKnRoaXM7CiAgICB9CgogICAgX0xJQkNQUF9JTkxJTkVfVklTSUJJTElUWSBfX2RlcXVlX2l0ZXJhdG9yIG9wZXJhdG9yLS0oaW50KQogICAgewogICAgICAgIF9fZGVxdWVfaXRlcmF0b3IgX190bXAgPSAqdGhpczsKICAgICAgICAtLSgqdGhpcyk7CiAgICAgICAgcmV0dXJuIF9fdG1wOwogICAgfQoKICAgIF9MSUJDUFBfSU5MSU5FX1ZJU0lCSUxJVFkgX19kZXF1ZV9pdGVyYXRvciYgb3BlcmF0b3IrPShkaWZmZXJlbmNlX3R5cGUgX19uKQogICAgewogICAgICAgIGlmIChfX24gIT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIF9fbiArPSBfX3B0cl8gLSAqX19tX2l0ZXJfOwogICAgICAgICAgICBpZiAoX19uID4gMCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgX19tX2l0ZXJfICs9IF9fbiAvIF9fYmxvY2tfc2l6ZTsKICAgICAgICAgICAgICAgIF9fcHRyXyA9ICpfX21faXRlcl8gKyBfX24gJSBfX2Jsb2NrX3NpemU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSAvLyAoX19uIDwgMCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZGlmZmVyZW5jZV90eXBlIF9feiA9IF9fYmxvY2tfc2l6ZSAtIDEgLSBfX247CiAgICAgICAgICAgICAgICBfX21faXRlcl8gLT0gX196IC8gX19ibG9ja19zaXplOwogICAgICAgICAgICAgICAgX19wdHJfID0gKl9fbV9pdGVyXyArIChfX2Jsb2NrX3NpemUgLSAxIC0gX196ICUgX19ibG9ja19zaXplKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gKnRoaXM7CiAgICB9CiAgICAKICAgIF9MSUJDUFBfSU5MSU5FX1ZJU0lCSUxJVFkgX19kZXF1ZV9pdGVyYXRvciYgb3BlcmF0b3ItPShkaWZmZXJlbmNlX3R5cGUgX19uKQogICAgewogICAgICAgIHJldHVybiAqdGhpcyArPSAtX19uOwogICAgfQogICAgCiAgICBfTElCQ1BQX0lOTElORV9WSVNJQklMSVRZIF9fZGVxdWVfaXRlcmF0b3Igb3BlcmF0b3IrKGRpZmZlcmVuY2VfdHlwZSBfX24pIGNvbnN0CiAgICB7CiAgICAgICAgX19kZXF1ZV9pdGVyYXRvciBfX3QoKnRoaXMpOwogICAgICAgIF9fdCArPSBfX247CiAgICAgICAgcmV0dXJuIF9fdDsKICAgIH0KICAgIAogICAgX0xJQkNQUF9JTkxJTkVfVklTSUJJTElUWSBfX2RlcXVlX2l0ZXJhdG9yIG9wZXJhdG9yLShkaWZmZXJlbmNlX3R5cGUgX19uKSBjb25zdAogICAgewogICAgICAgIF9fZGVxdWVfaXRlcmF0b3IgX190KCp0aGlzKTsKICAgICAgICBfX3QgLT0gX19uOwogICAgICAgIHJldHVybiBfX3Q7CiAgICB9CgogICAgX0xJQkNQUF9JTkxJTkVfVklTSUJJTElUWQogICAgZnJpZW5kIF9fZGVxdWVfaXRlcmF0b3Igb3BlcmF0b3IrKGRpZmZlcmVuY2VfdHlwZSBfX24sIGNvbnN0IF9fZGVxdWVfaXRlcmF0b3ImIF9faXQpCiAgICAgICAge3JldHVybiBfX2l0ICsgX19uO30KCiAgICBfTElCQ1BQX0lOTElORV9WSVNJQklMSVRZCiAgICBmcmllbmQgZGlmZmVyZW5jZV90eXBlIG9wZXJhdG9yLShjb25zdCBfX2RlcXVlX2l0ZXJhdG9yJiBfX3gsIGNvbnN0IF9fZGVxdWVfaXRlcmF0b3ImIF9feSkKICAgIHsKICAgICAgICBpZiAoX194ICE9IF9feSkKICAgICAgICAgICAgcmV0dXJuIChfX3guX19tX2l0ZXJfIC0gX195Ll9fbV9pdGVyXykgKiBfX2Jsb2NrX3NpemUKICAgICAgICAgICAgICAgICArIChfX3guX19wdHJfIC0gKl9feC5fX21faXRlcl8pCiAgICAgICAgICAgICAgICAgLSAoX195Ll9fcHRyXyAtICpfX3kuX19tX2l0ZXJfKTsKICAgICAgICByZXR1cm4gMDsKICAgIH0KCiAgICBfTElCQ1BQX0lOTElORV9WSVNJQklMSVRZIHJlZmVyZW5jZSBvcGVyYXRvcltdKGRpZmZlcmVuY2VfdHlwZSBfX24pIGNvbnN0CiAgICAgICAge3JldHVybiAqKCp0aGlzICsgX19uKTt9CgogICAgX0xJQkNQUF9JTkxJTkVfVklTSUJJTElUWSBmcmllbmQKICAgICAgICBib29sIG9wZXJhdG9yPT0oY29uc3QgX19kZXF1ZV9pdGVyYXRvciYgX194LCBjb25zdCBfX2RlcXVlX2l0ZXJhdG9yJiBfX3kpCiAgICAgICAge3JldHVybiBfX3guX19wdHJfID09IF9feS5fX3B0cl87fQoKICAgIF9MSUJDUFBfSU5MSU5FX1ZJU0lCSUxJVFkgZnJpZW5kCiAgICAgICAgYm9vbCBvcGVyYXRvciE9KGNvbnN0IF9fZGVxdWVfaXRlcmF0b3ImIF9feCwgY29uc3QgX19kZXF1ZV9pdGVyYXRvciYgX195KQogICAgICAgIHtyZXR1cm4gIShfX3ggPT0gX195KTt9CgogICAgX0xJQkNQUF9JTkxJTkVfVklTSUJJTElUWSBmcmllbmQKICAgICAgICBib29sIG9wZXJhdG9yPChjb25zdCBfX2RlcXVlX2l0ZXJhdG9yJiBfX3gsIGNvbnN0IF9fZGVxdWVfaXRlcmF0b3ImIF9feSkKICAgICAgICB7cmV0dXJuIF9feC5fX21faXRlcl8gPCBfX3kuX19tX2l0ZXJfIHx8CiAgICAgICAgICAgICAgIChfX3guX19tX2l0ZXJfID09IF9feS5fX21faXRlcl8gJiYgX194Ll9fcHRyXyA8IF9feS5fX3B0cl8pO30KCiAgICBfTElCQ1BQX0lOTElORV9WSVNJQklMSVRZIGZyaWVuZAogICAgICAgIGJvb2wgb3BlcmF0b3I+KGNvbnN0IF9fZGVxdWVfaXRlcmF0b3ImIF9feCwgY29uc3QgX19kZXF1ZV9pdGVyYXRvciYgX195KQog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b2M8cG9pbnRlcj4KI2Vsc2UKICAgICAgICAgICAgICAgIHJlYmluZF9hbGxvYzxwb2ludGVyPjo6b3RoZXIKI2VuZGlmCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fcG9pbnRlcl9hbGxvY2F0b3I7CiAgICB0eXBlZGVmIGFsbG9jYXRvcl90cmFpdHM8X19wb2ludGVyX2FsbG9jYXRvcj4gICAgICAgIF9fbWFwX3RyYWl0czsKICAgIHR5cGVkZWYgdHlwZW5hbWUgX19tYXBfdHJhaXRzOjpwb2ludGVyICAgICAgICAgICAgICAgX19tYXBfcG9pbnRlcjsKICAgIHR5cGVkZWYgdHlwZW5hbWUgX19tYXBfdHJhaXRzOjpjb25zdF9wb2ludGVyICAgICAgICAgX19tYXBfY29uc3RfcG9pbnRlcjsKICAgIHR5cGVkZWYgX19zcGxpdF9idWZmZXI8cG9pbnRlciwgX19wb2ludGVyX2FsbG9jYXRvcj4gX19tYXA7CgogICAgdHlwZWRlZiBfX2RlcXVlX2l0ZXJhdG9yPHZhbHVlX3R5cGUsIHBvaW50ZXIsIHJlZmVyZW5jZSwgX19tYXBfcG9pbnRlciwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkaWZmZXJlbmNlX3R5cGUsIF9fYmxvY2tfc2l6ZT4gICAgaXRlcmF0b3I7CiAgICB0eXBlZGVmIF9fZGVxdWVfaXRlcmF0b3I8dmFsdWVfdHlwZSwgY29uc3RfcG9pbnRlciwgY29uc3RfcmVmZXJlbmNlLCBfX21hcF9jb25zdF9wb2ludGVyLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRpZmZlcmVuY2VfdHlwZSwgX19ibG9ja19zaXplPiAgICBjb25zdF9pdGVyYXRvcjsKCiAgICBfX21hcCBfX21hcF87CiAgICBzaXplX3R5cGUgX19zdGFydF87CiAgICBfX2NvbXByZXNzZWRfcGFpcjxzaXplX3R5cGUsIGFsbG9jYXRvcl90eXBl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vciBfX2YpOwogICAgdm9pZCBfX2FkZF9mcm9udF9jYXBhY2l0eSgpOwogICAgdm9pZCBfX2FkZF9mcm9udF9jYXBhY2l0eShzaXplX3R5cGUgX19uKTsKICAgIHZvaWQgX19hZGRfYmFja19jYXBhY2l0eSgpOwogICAgdm9pZCBfX2FkZF9iYWNrX2NhcGFjaXR5KHNpemVfdHlwZSBfX24pOwogICAgaXRlcmF0b3IgX19tb3ZlX2FuZF9jaGVjayhpdGVyYXRvciBfX2YsIGl0ZXJhdG9yIF9fbCwgaXRlcmF0b3IgX19yLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdF9wb2ludGVyJiBfX3Z0KTsKICAgIGl0ZXJhdG9yIF9fbW92ZV9iYWNrd2FyZF9hbmRfY2hlY2soaXRlcmF0b3IgX19mLCBpdGVyYXRvciBfX2wsIGl0ZXJhdG9yIF9fciwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3RfcG9pbnRlciYgX192dCk7CiAgICB2b2lkIF9fbW92ZV9jb25zdHJ1Y3RfYW5kX2NoZWNrKGl0ZXJhdG9yIF9fZiwgaXRlcmF0b3IgX19sLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpdGVyYXRvciBfX3IsIGNvbnN0X3BvaW50ZXImIF9fdnQpOwogICAgdm9pZCBfX21vdmVfY29uc3RydWN0X2JhY2t3YXJkX2FuZF9jaGVjayhpdGVyYXRvciBfX2YsIGl0ZXJhdG9yIF9fbCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaXRlcmF0b3IgX19yLCBjb25zdF9wb2ludGVyJiBfX3Z0KTsKCiAgICB2b2lkIF9fY29weV9hc3NpZ25fYWxsb2MoY29uc3QgZGVxdWUmIF9fYykKICAgICAgICB7X19jb3B5X2Fzc2lnbl9hbGxvYyhfX2MsIGludGVncmFsX2NvbnN0YW50PGJvb2wsCiAgICAgICAgICAgICAgICAgICAgICBfX2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1RwLCBfQWxsb2NhdG9yPjo6aW5zZXJ0KGNvbnN0X2l0ZXJhdG9yIF9fcCwgdmFsdWVfdHlwZSYmIF9fdikKewogICAgc2l6ZV90eXBlIF9fcG9zID0gX19wIC0gX19iYXNlOjpiZWdpbigpOwogICAgc2l6ZV90eXBlIF9fdG9fZW5kID0gX19iYXNlOjpzaXplKCkgLSBfX3BvczsKICAgIGFsbG9jYXRvcl90eXBlJiBfX2EgPSBfX2Jhc2U6Ol9fYWxsb2MoKTsKICAgIGlmIChfX3BvcyA8IF9fdG9fZW5kKQogICAgeyAgIC8vIGluc2VydCBieSBzaGlmdGluZyB0aGluZ3MgYmFja3dhcmQKICAgICAgICBpZiAoX19mcm9udF9zcGFyZSgpID09IDApCiAgICAgICAgICAgIF9fYWRkX2Zyb250X2NhcGFjaXR5KCk7CiAgICAgICAgLy8gX19mcm9udF9zcGFyZSgpID49IDEKICAgICAgICBpZiAoX19wb3MgPT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIF9fYWxsb2NfdHJhaXRzOjpjb25zdHJ1Y3QoX19hLCBhZGRyZXNzb2YoKi0tX19iYXNlOjpiZWdpbigpKSwgX1NURDo6bW92ZShfX3YpKTsKICAgICAgICAgICAgLS1fX2Jhc2U6Ol9fc3RhcnRfOwogICAgICAgICAgICArK19fYmFzZTo6c2l6ZSgpOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpdGVyYXRvciBfX2IgPSBfX2Jhc2U6OmJlZ2luKCk7CiAgICAgICAgICAgIGl0ZXJhdG9yIF9fYm0xID0gcHJldihfX2IpOwogICAgICAgICAgICBfX2FsbG9jX3RyYWl0czo6Y29uc3RydWN0KF9fYSwgYWRkcmVzc29mKCpfX2JtMSksIF9TVEQ6Om1vdmUoKl9fYikpOwogICAgICAgICAgICAtLV9fYmFzZTo6X19zdGFydF87CiAgICAgICAgICAgICsrX19iYXNlOjpzaXplKCk7CiAgICAgICAgICAgIGlmIChfX3BvcyA+IDEpCiAgICAgICAgICAgICAgICBfX2IgPSBfU1REOjptb3ZlKG5leHQoX19iKSwgX19iICsgX19wb3MsIF9fYik7CiAgICAgICAgICAgICpfX2IgPSBfU1REOjptb3ZlKF9fdik7CiAgICAgICAgfQogICAgfQogICAgZWxzZQogICAgeyAgIC8vIGluc2VydCBieSBzaGlmdGluZyB0aGluZ3MgZm9yd2FyZAogICAgICAgIGlmIChfX2JhY2tfc3BhcmUoKSA9PSAwKQogICAgICAgICAgICBfX2FkZF9iYWNrX2NhcGFjaXR5KCk7CiAgICAgICAgLy8gX19iYWNrX2NhcGFjaXR5ID49IDEKICAgICAgICBzaXplX3R5cGUgX19kZSA9IF9fYmFzZTo6c2l6ZSgpIC0gX19wb3M7CiAgICAgICAgaWYgKF9fZGUgPT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIF9fYWxsb2NfdHJhaXRzOjpjb25zdHJ1Y3QoX19hLCBhZGRyZXNzb2YoKl9fYmFzZTo6ZW5kKCkpLCBfU1REOjptb3ZlKF9fdikpOwogICAgICAgICAgICArK19fYmFzZTo6c2l6ZSgpOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpdGVyYXRvciBfX2UgPSBfX2Jhc2U6OmVuZCgpOwogICAgICAgICAgICBpdGVyYXRvciBfX2VtMSA9IHByZXYoX19lKTsKICAgICAgICAgICAgX19hbGxvY190cmFpdHM6OmNvbnN0cnVjdChfX2EsIGFkZHJlc3NvZigqX19lKSwgX1NURDo6bW92ZSgqX19lbTEpKTsKICAgICAgICAgICAgKytfX2Jhc2U6OnNpemUoKTsKICAgICAgICAgICAgaWYgKF9fZGUgPiAxKQogICAgICAgICAgICAgICAgX19lID0gX1NURDo6bW92ZV9iYWNrd2FyZChfX2UgLSBfX2RlLCBfX2VtMSwgX19lKTsKICAgICAgICAgICAgKi0tX19lID0gX1NURDo6bW92ZShfX3YpOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBfX2Jhc2U6OmJ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9IF9fbjsKICAgICAgICBpdGVyYXRvciBfX29sZF9iZWdpbiA9IF9fYmFzZTo6YmVnaW4oKTsKICAgICAgICBpdGVyYXRvciBfX2kgPSBfX29sZF9iZWdpbjsKICAgICAgICBpZiAoX19uID4gX19wb3MpCiAgICAgICAgewogICAgICAgICAgICBmb3IgKHNpemVfdHlwZSBfX20gPSBfX24gLSBfX3BvczsgX19tOyAtLV9fbSwgLS1fX2Jhc2U6Ol9fc3RhcnRfLCArK19fYmFzZTo6c2l6ZSgpKQogICAgICAgICAgICAgICAgX19hbGxvY190cmFpdHM6OmNvbnN0cnVjdChfX2EsIGFkZHJlc3NvZigqLS1fX2kpLCBfX3YpOwogICAgICAgICAgICBfX24gPSBfX3BvczsKICAgICAgICB9CiAgICAgICAgaWYgKF9fbiA+IDApCiAgICAgICAgewogICAgICAgICAgICBjb25zdF9wb2ludGVyIF9fdnQgPSBwb2ludGVyX3RyYWl0czxjb25zdF9wb2ludGVyPjo6cG9pbnRlcl90byhfX3YpOwogICAgICAgICAgICBpdGVyYXRvciBfX29ibiA9IF9fb2xkX2JlZ2luICsgX19uOwogICAgICAgICAgICBfX21vdmVfY29uc3RydWN0X2JhY2t3YXJkX2FuZF9jaGVjayhfX29sZF9iZWdpbiwgX19vYm4sIF9faSwgX192dCk7CiAgICAgICAgICAgIGlmIChfX24gPCBfX3BvcykKICAgICAgICAgICAgICAgIF9fb2xkX2JlZ2luID0gX19tb3ZlX2FuZF9jaGVjayhfX29ibiwgX19vbGRfYmVnaW4gKyBfX3BvcywgX19vbGRfYmVnaW4sIF9fdnQpOwogICAgICAgICAgICBfU1REOjpmaWxsX24oX19vbGRfYmVnaW4sIF9fbiwgKl9fdnQpOwogICAgICAgIH0KICAgIH0KICAgIGVsc2UKICAgIHsgICAvLyBpbnNlcnQgYnkgc2hpZnRpbmcgdGhpbmdzIGZvcndhcmQKICAgICAgICBzaXplX3R5cGUgX19iYWNrX2NhcGFjaXR5ID0gX19iYWNrX3NwYXJlKCk7CiAgICAgICAgaWYgKF9fbiA+IF9fYmFja19jYXBhY2l0eSkKICAgICAgICAgICAgX19hZGRfYmFja19jYXBhY2l0eShfX24gLSBfX2JhY2tfY2FwYWNpdHkpOwogICAgICAgIC8vIF9fbiA8PSBfX2JhY2tfY2FwYWNpdHkKICAgICAgICBzaXplX3R5cGUgX19vbGRfbiA9IF9fbjsKICAgICAgICBpdGVyYXRvciBfX29sZF9lbmQgPSBfX2Jhc2U6OmVuZCgpOwogICAgICAgIGl0ZXJhdG9yIF9faSA9IF9fb2xkX2VuZDsKICAgICAgICBzaXplX3R5cGUgX19kZSA9IF9fYmFzZTo6c2l6ZSgpIC0gX19wb3M7CiAgICAgICAgaWYgKF9fbiA+IF9fZGUpCiAgICAgICAgewogICAgICAgICAgICBmb3IgKHNpemVfdHlwZSBfX20gPSBfX24gLSBfX2RlOyBfX207IC0tX19tLCArK19faSwgKytfX2Jhc2U6OnNpemUoKSkKICAgICAgICAgICAgICAgIF9fYWxsb2NfdHJhaXRzOjpjb25zdHJ1Y3QoX19hLCBhZGRyZXNzb2YoKl9faSksIF9fdik7CiAgICAgICAgICAgIF9fbiA9IF9fZGU7CiAgICAgICAgfQogICAgICAgIGlmIChfX24gPiAwKQogICAgICAgIHsKICAgICAgICAgICAgY29uc3RfcG9pbnRlciBfX3Z0ID0gcG9pbnRlcl90cmFpdHM8Y29uc3RfcG9pbnRlcj46OnBvaW50ZXJfdG8oX192KTsKICAgICAgICAgICAgaXRlcmF0b3IgX19vZW4gPSBfX29sZF9lbmQgLSBfX247CiAgICAgICAgICAgIF9fbW92ZV9jb25zdHJ1Y3RfYW5kX2NoZWNrKF9fb2VuLCBfX29sZF9lbmQsIF9faSwgX192dCk7CiAgICAgICAgICAgIGlmIChfX24gPCBfX2RlKQogICAgICAgICAgICAgICAgX19vbGRfZW5kID0gX19tb3ZlX2JhY2t3YXJkX2FuZF9jaGVjayhfX29sZF9lbmQgLSBfX2RlLCBfX29lbiwgX19vbGRfZW5kLCBfX3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7CiAgICAgICAgaWYgKF9fbiA+IF9fcG9zKQogICAgICAgIHsKICAgICAgICAgICAgX19tID0gX19wb3MgPCBfX24gLyAyID8gX1NURDo6cHJldihfX2wsIF9fcG9zKSA6IF9TVEQ6Om5leHQoX19mLCBfX24gLSBfX3Bvcyk7CiAgICAgICAgICAgIGZvciAoX0JpSXRlciBfX2ogPSBfX207IF9faiAhPSBfX2Y7IC0tX19iYXNlOjpfX3N0YXJ0XywgKytfX2Jhc2U6OnNpemUoKSkKICAgICAgICAgICAgICAgIF9fYWxsb2NfdHJhaXRzOjpjb25zdHJ1Y3QoX19hLCBhZGRyZXNzb2YoKi0tX19pKSwgKi0tX19qKTsKICAgICAgICAgICAgX19uID0gX19wb3M7CiAgICAgICAgfQogICAgICAgIGlmIChfX24gPiAwKQogICAgICAgIHsKICAgICAgICAgICAgaXRlcmF0b3IgX19vYm4gPSBfX29sZF9iZWdpbiArIF9fbjsKICAgICAgICAgICAgZm9yIChpdGVyYXRvciBfX2ogPSBfX29ibjsgX19qICE9IF9fb2xkX2JlZ2luOykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgX19hbGxvY190cmFpdHM6OmNvbnN0cnVjdChfX2EsIGFkZHJlc3NvZigqLS1fX2kpLCBfU1REOjptb3ZlKCotLV9faikpOwogICAgICAgICAgICAgICAgLS1fX2Jhc2U6Ol9fc3RhcnRfOwogICAgICAgICAgICAgICAgKytfX2Jhc2U6OnNpemUoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoX19uIDwgX19wb3MpCiAgICAgICAgICAgICAgICBfX29sZF9iZWdpbiA9IF9TVEQ6Om1vdmUoX19vYm4sIF9fb2xkX2JlZ2luICsgX19wb3MsIF9fb2xkX2JlZ2luKTsKICAgICAgICAgICAgX1NURDo6Y29weShfX20sIF9fbCwgX19vbGRfYmVnaW4pOwogICAgICAgIH0KICAgIH0KICAgIGVsc2UKICAgIHsgICAvLyBpbnNlcnQgYnkgc2hpZnRpbmcgdGhpbmdzIGZvcndhcmQKICAgICAgICBzaXplX3R5cGUgX19iYWNrX2NhcGFjaXR5ID0gX19iYWNrX3NwYXJlKCk7CiAgICAgICAgaWYgKF9fbiA+IF9fYmFja19jYXBhY2l0eSkKICAgICAgICAgICAgX19hZGRfYmFja19jYXBhY2l0eShfX24gLSBfX2JhY2tfY2FwYWNpdHkpOwogICAgICAgIC8vIF9fbiA8PSBfX2JhY2tfY2FwYWNpdHkKICAgICAgICBzaXplX3R5cGUgX19vbGRfbiA9IF9fbjsKICAgICAgICBpdGVyYXRvciBfX29sZF9lbmQgPSBfX2Jhc2U6OmVuZCgpOwogICAgICAgIGl0ZXJhdG9yIF9faSA9IF9fb2xkX2VuZDsKICAgICAgICBfQmlJdGVyIF9fbSA9IF9fbDsKICAgICAgICBzaXplX3R5cGUgX19kZSA9IF9fYmFzZTo6c2l6ZSgpIC0gX19wb3M7CiAgICAgICAgaWYgKF9fbiA+IF9fZGUpCiAgICAgICAgewogICAgICAgICAgICBfX20gPSBfX2RlIDwgX19uIC8gMiA/IF9TVEQ6Om5leHQoX19mLCBfX2RlKSA6IF9TVEQ6OnByZXYoX19sLCBfX24gLSBfX2RlKTsKICAgICAgICAgICAgZm9yIChfQmlJdGVyIF9faiA9IF9fbTsgX19qICE9IF9fbDsgKytfX2ksICsrX19qLCArK19fYmFzZTo6c2l6ZSgpKQogICAgICAgICAgICAgICAgX19hbGxvY190cmFpdHM6OmNvbnN0cnVjdChfX2EsIGFkZHJlc3NvZigqX19pKSwgKl9faik7CiAgICAgICAgICAgIF9fbiA9IF9fZGU7CiAgICAgICAgfQogICAgICAgIGlmIChfX24gPiAwKQogICAgICAgIHsKICAgICAgICAgICAgaXRlcmF0b3IgX19vZW4gPSBfX29sZF9lbmQgLSBfX247CiAgICAgICAgICAgIGZvciAoaXRlcmF0b3IgX19qID0gX19vZW47IF9faiAhPSBfX29sZF9lbmQ7ICsrX19pLCArK19faiwgKytfX2Jhc2U6OnNpemUoKSkKICAgICAgICAgICAgICAgI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ZShfX2EsIF9fYmFzZTo6X19ibG9ja19zaXplKSk7CiNpZm5kZWYgX0xJQkNQUF9OT19FWENFUFRJT05TCiAgICAgICAgfQogICAgICAgIGNhdGNoICguLi4pCiAgICAgICAgewogICAgICAgICAgICBfX2FsbG9jX3RyYWl0czo6ZGVhbGxvY2F0ZShfX2EsIF9fYnVmLmZyb250KCksIF9fYmFzZTo6X19ibG9ja19zaXplKTsKICAgICAgICAgICAgdGhyb3c7CiAgICAgICAgfQojZW5kaWYKICAgICAgICBmb3IgKHR5cGVuYW1lIF9fYmFzZTo6X19tYXBfcG9pbnRlciBfX2kgPSBfX2Jhc2U6Ol9fbWFwXy5iZWdpbigpOwogICAgICAgICAgICAgICAgX19pICE9IF9fYmFzZTo6X19tYXBfLmVuZCgpOyArK19faSkKICAgICAgICAgICAgX19idWYucHVzaF9iYWNrKCpfX2kpOwogICAgICAgIF9TVEQ6OnN3YXAoX19iYXNlOjpfX21hcF8uX19maXJzdF8sIF9fYnVmLl9fZmlyc3RfKTsKICAgICAgICBfU1REOjpzd2FwKF9fYmFzZTo6X19tYXBfLl9fYmVnaW5fLCBfX2J1Zi5fX2JlZ2luXyk7CiAgICAgICAgX1NURDo6c3dhcChfX2Jhc2U6Ol9fbWFwXy5fX2VuZF8sIF9fYnVmLl9fZW5kXyk7CiAgICAgICAgX1NURDo6c3dhcChfX2Jhc2U6Ol9fbWFwXy5fX2VuZF9jYXAoKSwgX19idWYuX19lbmRfY2FwKCkpOwogICAgICAgIF9fYmFzZTo6X19zdGFydF8gPSBfX2Jhc2U6Ol9fbWFwXy5zaXplKCkgPT0gMSA/CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2Jhc2U6Ol9fYmxvY2tfc2l6ZSAvIDIgOgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX19iYXNlOjpfX3N0YXJ0XyArIF9fYmFzZTo6X19ibG9ja19zaXplOwogICAgfQp9CgovLyBDcmVhdGUgZnJvbnQgY2FwYWNpdHkg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KSwKICAgICAgICAgICAgICAgICAgMCwgX19iYXNlOjpfX21hcF8uX19hbGxvYygpKTsKI2lmbmRlZiBfTElCQ1BQX05PX0VYQ0VQVElPTlMKICAgICAgICB0cnkKICAgICAgICB7CiNlbmRpZgogICAgICAgICAgICBmb3IgKDsgX19uYiA+IDA7IC0tX19uYikKICAgICAgICAgICAgICAgIF9fYnVmLnB1c2hfYmFjayhfX2FsbG9jX3RyYWl0czo6YWxsb2NhdGUoX19hLCBfX2Jhc2U6Ol9fYmxvY2tfc2l6ZSkpOwojaWZuZGVmIF9MSUJDUFBfTk9fRVhDRVBUSU9OUwogICAgICAgIH0KICAgICAgICBjYXRjaCAoLi4uKQogICAgICAgIHsKICAgICAgICAgICAgZm9yICh0eXBlbmFtZSBfX2Jhc2U6Ol9fbWFwX3BvaW50ZXIgX19pID0gX19idWYuYmVnaW4oKTsKICAgICAgICAgICAgICAgICAgICBfX2kgIT0gX19idWYuZW5kKCk7ICsrX19pKQogICAgICAgICAgICAgICAgX19hbGxvY190cmFpdHM6OmRlYWxsb2NhdGUoX19hLCAqX19pLCBfX2Jhc2U6Ol9fYmxvY2tfc2l6ZSk7CiAgICAgICAgICAgIHRocm93OwogICAgICAgIH0KI2VuZGlmCiAgICAgICAgZm9yICg7IF9fYmFja19jYXBhY2l0eSA+IDA7IC0tX19iYWNrX2NhcGFjaXR5KQogICAgICAgIHsKICAgICAgICAgICAgX19idWYucHVzaF9iYWNrKF9fYmFzZTo6X19tYXBfLmJhY2soKSk7CiAgICAgICAgICAgIF9fYmFzZTo6X19tYXBfLnBvcF9iYWNrKCk7CiAgICAgICAgfQogICAgICAgIGZvciAodHlwZW5hbWUgX19iYXNlOjpfX21hcF9wb2ludGVyIF9faSA9IF9fYmFzZTo6X19tYXBfLmJlZ2luKCk7CiAgICAgICAgICAgICAgICBfX2kgIT0gX19iYXNlOjpfX21hcF8uZW5kKCk7ICsrX19pKQogICAgICAgICAgICBfX2J1Zi5wdXNoX2JhY2soKl9faSk7C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kKiB3ZSBuZWVkIHRvIHJlYWxsb2NhdGUgX19tYXBfLgogICAgZWxzZQogICAgewogICAgICAgIF9fc3BsaXRfYnVmZmVyPHBvaW50ZXIsIHR5cGVuYW1lIF9fYmFzZTo6X19wb2ludGVyX2FsbG9jYXRvciY+CiAgICAgICAgICAgIF9fYnVmKG1heDxzaXplX3R5cGU+KDIqIF9fYmFzZTo6X19tYXBfLmNhcGFjaXR5KCksIDEpLAogICAgICAgICAgICAgICAgICBfX2Jhc2U6Ol9fbWFwXy5zaXplKCksCiAgICAgICAgICAgICAgICAgIF9fYmFzZTo6X19tYXBfLl9fYWxsb2MoKSk7CiNpZm5kZWYgX0xJQkNQUF9OT19FWENFUFRJT05TCiAgICAgICAgdHJ5CiAgICAgICAgewojZW5kaWYKICAgICAgICAgICAgX19idWYucHVzaF9iYWNrKF9fYWxsb2NfdHJhaXRzOjphbGxvY2F0ZShfX2EsIF9fYmFzZTo6X19ibG9ja19zaXplKSk7CiNpZm5kZWYgX0xJQkNQUF9OT19FWENFUFRJT05TCiAgICAgICAgfQogICAgICAgIGNhdGNoICguLi4pCiAgICAgICAgewogICAgICAgICAgICBfX2FsbG9jX3RyYWl0czo6ZGVhbGxvY2F0ZShfX2EsIF9fYnVmLmJhY2soKSwgX19iYXNlOjpfX2Jsb2NrX3NpemUpOwogICAgICAgICAgICB0aHJvdzsKICAgICAgICB9CiNlbmRpZgogICAgICAgIGZvciAodHlwZW5hbWUgX19iYXNlOjpfX21hcF9wb2ludGVyIF9faSA9IF9fYmFzZTo6X19tYXBfLmVuZCgpOwogICAgICAgICAgICAgICAgX19pICE9IF9fYmFzZTo6X19tYXBfLmJlZ2luKCk7KQogICAgICAgICAgICBfX2J1Zi5wdXNoX2Zyb250KCotLV9faSk7CiAgICAgICAgX1NURDo6c3dhcChfX2Jhc2U6Ol9fbWFwXy5fX2ZpcnN0XywgX19idWYuX19maXJzdF8pOwogICAgICAgIF9TVEQ6OnN3YXAoX19iYXNlOjpfX21hcF8uX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9fc3BsaXRfYnVmZmVyPHBvaW50ZXIsIHR5cGVuYW1lIF9fYmFzZTo6X19wb2ludGVyX2FsbG9jYXRvciY+CiAgICAgICAgICAgIF9fYnVmKG1heDxzaXplX3R5cGU+KDIqIF9fYmFzZTo6X19tYXBfLmNhcGFjaXR5KCksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fbmIgKyBfX2Jhc2U6Ol9fbWFwXy5zaXplKCkpLAogICAgICAgICAgICAgICAgICBfX2Jhc2U6Ol9fbWFwXy5zaXplKCkgLSBfX2Zyb250X2NhcGFjaXR5LAogICAgICAgICAgICAgICAgICBfX2Jhc2U6Ol9fbWFwXy5fX2FsbG9jKCkpOwojaWZuZGVmIF9MSUJDUFBfTk9fRVhDRVBUSU9OUwogICAgICAgIHRyeQogICAgICAgIHsKI2VuZGlmCiAgICAgICAgICAgIGZvciAoOyBfX25iID4gMDsgLS1fX25iKQogICAgICAgICAgICAgICAgX19idWYucHVzaF9iYWNrKF9fYWxsb2NfdHJhaXRzOjphbGxvY2F0ZShfX2EsIF9fYmFzZTo6X19ibG9ja19zaXplKSk7CiNpZm5kZWYgX0xJQkNQUF9OT19FWENFUFRJT05TCiAgICAgICAgfQogICAgICAgIGNhdGNoICguLi4pCiAgICAgICAgewogICAgICAgICAgICBmb3IgKHR5cGVuYW1lIF9fYmFzZTo6X19tYXBfcG9pbnRlciBfX2kgPSBfX2J1Zi5iZWdpbigpOwogICAgICAgICAgICAgICAgICAgIF9faSAhPSBfX2J1Zi5lbmQoKTsgKytfX2kpCiAgICAgICAgICAgICAgICBfX2FsbG9jX3RyYWl0czo6ZGVhbGxvY2F0ZShfX2EsICpfX2ksIF9fYmFzZTo6X19ibG9ja19zaXplKTsKICAgICAgICAgICAgdGhyb3c7CiAgICAgICAgfQojZW5kaWYKICAgICAgICBmb3IgKDsgX19mcm9udF9jYXBhY2l0eSA+IDA7IC0tX19mcm9udF9jYXBhY2l0eSkKICAgICAgICB7CiAgICAgICAgICAgI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uY2VfdHlwZSBfX2JzID0gX19sZSAtIF9fbGI7CiAgICAgICAgaWYgKF9fYnMgPiBfX24pCiAgICAgICAgewogICAgICAgICAgICBfX2JzID0gX19uOwogICAgICAgICAgICBfX2xiID0gX19sZSAtIF9fYnM7CiAgICAgICAgfQogICAgICAgIGlmIChfX2xiIDw9IF9fdnQgJiYgX192dCA8IF9fbGUpCiAgICAgICAgICAgIF9fdnQgPSAoY29uc3RfaXRlcmF0b3IoX19sLl9fbV9pdGVyXywgX192dCkgKz0gX19yIC0gX19sIC0gMSkuX19wdHJfOwogICAgICAgIF9fciA9IF9TVEQ6Om1vdmVfYmFja3dhcmQoX19sYiwgX19sZSwgX19yKTsKICAgICAgICBfX24gLT0gX19iczsKICAgICAgICBfX2wgLT0gX19icyAtIDE7CiAgICB9CiAgICByZXR1cm4gX19yOwp9CgovLyBtb3ZlIGNvbnN0cnVjdCBbX19mLCBfX2wpIHRvIFtfX3IsIF9fciArIChfX2wtX19mKSkuCi8vIElmIF9fdnQgcG9pbnRzIGludG8gW19fZiwgX19sKSwgdGhlbiBhZGQgKF9fciAtIF9fZikgdG8gX192dC4KdGVtcGxhdGUgPGNsYXNzIF9UcCwgY2xhc3MgX0FsbG9jYXRvcj4Kdm9pZApkZXF1ZTxfVHAsIF9BbGxvY2F0b3I+OjpfX21vdmVfY29uc3RydWN0X2FuZF9jaGVjayhpdGVyYXRvciBfX2YsIGl0ZXJhdG9yIF9fbCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaXRlcmF0b3IgX19yLCBjb25zdF9wb2ludGVyJiBfX3Z0KQp7CiAgICBhbGxvY2F0b3JfdHlwZSYgX19hID0gX19iYXNlOjpfX2FsbG9jKCk7CiAgICAvLyBhcyBpZgogICAgLy8gICBmb3IgKDsgX19mICE9IF9fbDsgKytfX3IsICsrX19mLCArK19fYmFzZTo6c2l6ZSgpKQogICAgLy8gICAgICAgX19hbGxvY190cmFpdHM6OmNvbnN0cnVjdChfX2EsIGFkZHJlc3NvZigqX19yKSwgX1NURDo6bW92ZSgqX19mKSk7CiAgICBkaWZmZXJlbmNlX3R5cGUgX19uID0gX19sIC0gX19mOwogICAgd2hpbGUgKF9fbiA+IDApCiAgICB7CiAgICAgICAgcG9pbnRlciBfX2ZiID0gX19mLl9fcHRyXzsKICAgICAgICBwb2ludGVyIF9fZmUgPSAqX19mLl9fbV9pdGVyXyArIF9fYmFzZTo6X19ibG9ja19zaXplOwogICAgICAgIGRpZmZlcmVuY2VfdHlwZSBfX2JzID0gX19mZSAtIF9fZmI7CiAgICAgICAgaWYgKF9fYnMgPiBfX24pCiAgICAgICAgewogICAgICAgICAgICBfX2JzID0gX19uOwogICAgICAgICAgICBfX2ZlID0gX19mYiArIF9fYnM7CiAgICAgICAgfQogICAgICAgIGlmIChfX2ZiIDw9IF9fdnQgJiYgX192dCA8IF9fZmUpCiAgICAgICAgICAgIF9fdnQgPSAoY29uc3RfaXRlcmF0b3IoX19mLl9fbV9pdGVyXywgX192dCkgKz0gX19yIC0gX19mKS5fX3B0cl87CiAgICAgICAgZm9yICg7IF9fZmIgIT0gX19mZTsgKytfX2ZiLCArK19fciwgKytfX2Jhc2U6OnNpemUoKSkKICAgICAgICAgICAgX19hbGxvY190cmFpdHM6OmNvbnN0cnVjdChfX2EsIGFkZHJlc3NvZigqX19yKSwgX1NURDo6bW92ZSgqX19mYikpOwogICAgICAgIF9fbiAtPSBfX2JzOwogICAgICAgIF9fZiArPSBfX2JzOwogICAgfQp9CgovLyBtb3ZlIGNvbnN0cnVjdCBbX19mLCBfX2wpIHRvIFtfX3IgLSAoX19sLV9fZiksIF9fcikgYmFja3dhcmRzLgovLyBJZiBfX3Z0IHBvaW50cyBpbnRvIFtfX2YsIF9fbCksIHRoZW4gc3VidHJhY3QgKF9fbCAtIF9fcikgZnJvbSBfX3Z0Lgp0ZW1wbGF0ZSA8Y2xhc3MgX1RwLCBjbGFzcyBfQWxsb2NhdG9yPgp2b2lkCmRlcXVlPF9UcCwgX0FsbG9jYXRvcj46Ol9fbW92ZV9jb25zdHJ1Y3RfYmFja3dhcmRfYW5kX2NoZWNrKGl0ZXJhdG9yIF9fZiwgaXRlcmF0b3IgX19sLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpdGVyYXRvciBfX3IsIGNvbnN0X3BvaW50ZXImIF9fdnQpCnsKICAgIGFsbG9jYXRvcl90eXBlJiBfX2EgPSBfX2Jhc2U6Ol9fYWxsb2MoKTsKICAgIC8vIGFzIGlmCiAgICAvLyAgIGZvciAoaXRlcmF0b3IgX19qID0gX19sOyBfX2ogIT0gX19mOykKICAgIC8vICAgewogICAgLy8gICAgICAgX19hbGxvY190cmFpdHNjb25zdHJ1Y3QoX19hLCBhZGRyZXNzb2YoKi0tX19yKSwgX1NURDo6bW92ZSgqLS1fX2opKTsKICAgIC8vICAgICAgIC0tX19iYXNlOjpfX3N0YXJ0XzsKICAgIC8vICAgICAgICsrX19iYXNlOjpzaXplKCk7CiAgICAvLyAgIH0KICAgIGRpZmZlcmVuY2VfdHlwZSBfX24gPSBfX2wgLSBfX2Y7CiAgICB3aGlsZSAoX19uID4gMCkKICAgIHsKICAgICAgICAtLV9fbDsKICAgICAgICBwb2ludGVyIF9fbGIgPSAqX19sLl9fbV9pdGVyXzsKICAgICAgICBwb2ludGVyIF9fbGUgPSBfX2wuX19wdHJfICsgMTsKICAgICAgICBkaWZmZXJlbmNlX3R5cGUgX19icyA9IF9fbGUgLSBfX2xiOwogICAgICAgIGlmIChfX2JzID4gX19uKQogICAgICAgIHsKICAgICAgICAgICAgX19icyA9IF9fbjsKICAgICAgICAgICAgX19sYiA9IF9fbGUgLSBfX2JzOwogICAgICAgIH0KICAgICAgICBpZiAoX19sYiA8PSBfX3Z0ICYmIF9fdnQgPCBfX2xlKQogICAgICAgICAgICBfX3Z0ID0gKGNvbnN0X2l0ZXJhdG9yKF9fbC5fX21faXRlcl8sIF9f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dGVyYXRvciBfX2wpCnsKICAgIGRpZmZlcmVuY2VfdHlwZSBfX24gPSBfX2wgLSBfX2Y7CiAgICBpdGVyYXRvciBfX2IgPSBfX2Jhc2U6OmJlZ2luKCk7CiAgICBkaWZmZXJlbmNlX3R5cGUgX19wb3MgPSBfX2YgLSBfX2I7CiAgICBpdGVyYXRvciBfX3AgPSBfX2IgKyBfX3BvczsKICAgIGlmIChfX24gPiAwKQogICAgewogICAgICAgIGFsbG9jYXRvcl90eXBlJiBfX2EgPSBfX2Jhc2U6Ol9fYWxsb2MoKTsKICAgICAgICBpZiAoX19wb3MgPCAoX19iYXNlOjpzaXplKCkgLSBfX24pIC8gMikKICAgICAgICB7ICAgLy8gZXJhc2UgZnJvbSBmcm9udAogICAgICAgICAgICBpdGVyYXRvciBfX2kgPSBfU1REOjptb3ZlX2JhY2t3YXJkKF9fYiwgX19wLCBfX3AgKyBfX24pOwogICAgICAgICAgICBmb3IgKDsgX19iICE9IF9faTsgKytfX2IpCiAgICAgICAgICAgICAgICBfX2FsbG9jX3RyYWl0czo6ZGVzdHJveShfX2EsIGFkZHJlc3NvZigqX19iKSk7CiAgICAgICAgICAgIF9fYmFzZTo6c2l6ZSgpIC09IF9fbjsKICAgICAgICAgICAgX19iYXNlOjpfX3N0YXJ0XyArPSBfX247CiAgICAgICAgICAgIHdoaWxlIChfX2Zyb250X3NwYXJlKCkgPj0gMiAqIF9fYmFzZTo6X19ibG9ja19zaXplKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBfX2FsbG9jX3RyYWl0czo6ZGVhbGxvY2F0ZShfX2EsIF9fYmFzZTo6X19tYXBfLmZyb250KCksIF9fYmFzZTo6X19ibG9ja19zaXplKTsKICAgICAgICAgICAgICAgIF9fYmFzZTo6X19tYXBfLnBvcF9mcm9udCgpOwogICAgICAgICAgICAgICAgX19iYXNlOjpfX3N0YXJ0XyAtPSBfX2Jhc2U6Ol9fYmxvY2tfc2l6ZTsKICAgICAgICAgICAgfQogICAgICA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