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sIHRyYWNrczsKICAgIGludCBCb290UCwgSW5mcDAsIEluZnBYLCBJbmZUbTsKICAgIGludCBzZWN0X3Blcl90cmFjazsKCiAgICAvKiBEaXNwbGF5IEJvb3QgaGVhZGVyICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKi8KICAgIFBSSU5URiAoIkp1bXAgdG8gYm9vdCBjb2RlICAgICAgICAgICAgICAgICAgMHglMDJ4IDB4JTAyeCAweCUwMnhcbiIsCiAgICAgICAgICAgIGJvb3QgLT4ganVtcCBbMF0sIGJvb3QgLT4ganVtcCBbMV0sIGJvb3QgLT4ganVtcFsyXSk7CiAgICBQUklOVEYgKCJPRU0gbmFtZSAmIHZlcnNpb24gICAgICAgICAgICAgICAgICclKi4qcydcbiIsCiAgICAgICAgICAgIEJBTk5FUl9MRywgQkFOTkVSX0xHLCBib290IC0+IGJhbm5lciApOwogICAgUFJJTlRGICgiQnl0ZXMgcGVyIHNlY3RvciBob3BlZnVsbHkgNTEyICAgICAlZFxuIiwKICAgICAgICAgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBzZWNzaXopKTsKICAgIFBSSU5URiAoIkNsdXN0ZXIgc2l6ZSBpbiBzZWN0b3JzICAgICAgICAgICAgJWRcbiIsCiAgICAgICAgICAgIGJvb3QgLT4gY2xzaXopOwogICAgUFJJTlRGICgiTnVtYmVyIG9mIHJlc2VydmVkIChib290KSBzZWN0b3JzICAlZFxuIiwKICAgICAgICAgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBucnN2c2VjdCkpOwogICAgUFJJTlRGICgiTnVtYmVyIG9mIEZBVCB0YWJsZXMgaG9wZWZ1bGx5IDIgICAlZFxuIiwKICAgICAgICAgICAgYm9vdCAtPiBuZmF0KTsKICAgIFBSSU5URiAoIk51bWJlciBvZiBkaXJlY3Rvcnkgc2xvdHMgICAgICAgICAgJWRcbiIsCiAgICAgICAgICAgIF9fbGUxNl90b19jcHUgKGJvb3QgLT4gZGlyZW50cykpOwogICAgUFJJTlRGICgiVG90YWwgc2VjdG9ycyBvbiBkaXNrICAgICAgICAgICAgICAlZFxuIiwKICAgICAgICAgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBwc2VjdCkpOwogICAgUFJJTlRGICgiTWVkaWEgZGVzY3JpcHRvcj1maXJzdCBieXRlIG9mIEZBVCAlZFxuIiwKICAgICAgICAgICAgYm9vdCAtPiBkZXNjcik7CiAgICBQUklOVEYgKCJTZWN0b3JzIGluIEZBVCAgICAgICAgICAgICAgICAgICAgICVkXG4iLAogICAgICAgICAgICBfX2xlMTZfdG9fY3B1IChib290IC0+IGZhdGxlbikpOwogICAgUFJJTlRGICgiU2VjdG9ycy90cmFjayAgICAgICAgICAgICAgICAgICAgICAlZFxuIiwKICAgICAgICAgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBuc2VjdCkpOwogICAgUFJJTlRGICgiSGVhZHMgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlZFxuIiwKICAgICAgICAgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBuaGVhZHMpKTsKICAgIFBSSU5URiAoIm51bWJlciBvZiBoaWRkZW4gc2VjdG9ycyAgICAgICAgICAgJWRcbiIsCiAgICAgICAgICAgIF9fbGUzMl90b19jcHUgKGJvb3QgLT4gbmhzKSk7CiAgICBQUklOVEYgKCJiaWcgdG90YWwgc2VjdG9ycyAgICAgICAgICAgICAgICAgICVkXG4iLAogICAgICAgICAgICBfX2xlMzJfdG9fY3B1IChib290IC0+IGJpZ3NlY3QpKTsKICAgIFBSSU5URiAoInBoeXNpY2FsIGRyaXZlID8gICAgICAgICAgICAgICAgICAgJWRcbiIsCiAgICAgICAgICAgIGJvb3QgLT4gcGh5c2RyaXZlKTsKICAgIFBSSU5URiAoInJlc2VydmVkICAgICAgICAgICAgICAgICAgICAgICAgICAgJWRcbiIsCiAgICAgICAgICAgIGJvb3QgLT4gcmVzZXJ2ZWQpOwogICAgUFJJTlRGICgiZG9zID4gNC4wIGRpc2tldHRlICAgICAgICAgICAgICAgICAlZFxuIiwKICAgICAgICAgICAgYm9vdCAtPiBkb3M0KTsKICAgIFBSSU5URiAoInNlcmlhbCBudW1iZXIgICAgICAgICAgICAgICAgICAgICAgJWRcbiIsCiAgICAgICAgICAgIF9fbGUzMl90b19jcHUgKGJvb3QgLT4gc2VyaWFsKSk7CiAgICBQUklOVEYgKCJkaXNrIGxhYmVsICAgICAgICAgICAgICAgICAgICAgICAgICUqLipzXG4iLAogICAgICAgICAgICBMQUJFTF9MRywgTEFCRUxfTEcsIGJvb3QgLT4gbGFiZWwpOwogICAgUFJJTlRGICgiRkFUIHR5cGUgICAgICAgICAgICAgICAgICAgICAgICAgICAlOC44c1xuIiwKICAgICAgICAgICAgYm9vdCAtPiBmYXRfdHlwZSk7CiAgICBQUklOVEYgKCJyZXNlcnZlZCBieSAyTSAgICAgICAgICAgICAgICAgICAgICVkXG4iLAogICAgICAgICAgICBib290IC0+IHJlc18ybSk7CiAgICBQUklOVEYgKCIyTSBjaGVja3N1bSAobm90IHVzZWQpICAgICAgICAgICAgICVkXG4iLAogICAgICAgICAgICBib290IC0+IENoZWNrU3VtKTsKICAgIFBSSU5URiAoIjJNRiBmb3JtYXQgdmVyc2lvbiAgICAgICAgICAgICAgICAgJWRcbiIsCiAgICAgICAgICAgIGJvb3QgLT4gZm10XzJtZik7CiAgICBQUklOVEYgKCIxIGlmIHdyaXRlIHRyYWNrIGFmdGVyIGZvcm1hdCAgICAgICVkXG4iLAogICAgICAgICAgICBib290IC0+IHd0KTsKICAgIFBSSU5URiAoImRhdGEgdHJhbnNmZXIgcmF0ZSBvbiB0cmFjayAwICAgICAgJWRcbiIsCiAgICAgICAgICAgIGJvb3QgLT4gcmF0ZV8wKTsKICAgIFBSSU5URiAoImRhdGEgdHJhbnNmZXIgcmF0ZSBvbiB0cmFjazw+MCAgICAgJWRcbiIsCiAgICAgICAgICAgIGJvb3QgLT4gcmF0ZV9hbnkpOwogICAgUFJJTlRGICgib2Zmc2V0IHRvIGJvb3QgcHJvZ3JhbSAgICAgICAgICAgICAlZFxuIiwKICAgICAgICAgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBCb290UCkpOwogICAgUFJJTlRGICgiVDE6IGluZm9ybWF0aW9uIGZvciB0cmFjayAwICAgICAgICAlZFxuIiwKICAgICAgICAgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBJbmZwMCkpOwogICAgUFJJTlRGICgiVDI6IGluZm9ybWF0aW9uIGZvciB0cmFjazw+MCAgICAgICAlZFxuIiwKICAgICAgICAgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBJbmZwWCkpOwogICAgUFJJTlRGICgiVDM6IHRyYWNrIHNlY3RvcnMgc2l6ZSB0YWJsZSAgICAgICAlZFxuIiwKICAgICAgICAgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBJbmZUbSkpOwogICAgUFJJTlRGICgiRm9ybWF0IGRhdGUgICAgICAgICAgICAgICAgICAgICAgICAweCUwNHhcbiIsCiAgICAgICAgICAgIF9fbGUxNl90b19jcHUgKGJvb3QgLT4gRGF0ZUYpKTsKICAgIFBSSU5URiAoIkZvcm1hdCB0aW1lICAgICAgICAgICAgICAgICAgICAgICAgMHglMDR4XG4iLAogICAgICAgICAgICBfX2xlMTZfdG9fY3B1IChib290IC0+IFRpbWVGKSk7CiAgICAKCiAgICAvKiBpbmZvcm1hdGlvbiBpcyBleHRyYWN0ZWQgZnJvbSBib290IHNlY3RvciAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICBoZWFkcyA9IF9fbGUxNl90b19jcHUgKGJvb3QgLT4gbmhlYWRzKTsKICAgIHNlY3RvcnMgPSBfX2xlMTZfdG9fY3B1IChib290IC0+IG5zZWN0KTsKICAgIGZzIC0+IHRvdF9zZWN0b3JzID0gX19sZTMyX3RvX2NwdSAoYm9vdCAtPiBiaWdzZWN0KTsKICAgIGlmIChfX2xlMTZfdG9fY3B1IChib290IC0+IHBzZWN0KSAhPSAwKSB7CiAgICAgICAgZnMgLT4gdG90X3NlY3RvcnMgPSBfX2xlMTZfdG9fY3B1IChib290IC0+IHBzZWN0KTsKICAgIH0KICAgIAogICAgc2VjdF9wZXJfdHJhY2sgPSBoZWFkcyAqIHNlY3RvcnM7CiAgICB0cmFja3MgPSAoZnMgLT4gdG90X3NlY3RvcnMgKyBzZWN0X3Blcl90cmFjayAtIDEpIC8gc2VjdF9wZXJfdHJhY2s7CiAgICAKICAgIEJvb3RQID0gX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBCb290UCk7CiAgICBJbmZwMCA9IF9fbGUxNl90b19jcHUgKGJvb3QgLT4gSW5mcDApOwogICAgSW5mcFggPSBfX2xlMTZfdG9fY3B1IChib290IC0+IEluZnBYKTsKICAgIEluZlRtID0gX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBJbmZUbSk7CiAgICAKICAgIGlmIChib290IC0+IGRvczQgPT0gRVhURU5ERURfQk9PVCAmJgogICAgICAgIHN0cm5jbXAoIGJvb3QtPmJhbm5lciwiMk0iLCAyICkgPT0gMCAmJgogICAgICAgIEJvb3RQIDwgU1pfU1REX1NFQ1RPUiAmJgogICAgICAgIEluZnAwIDwgU1pfU1REX1NFQ1RPUiAmJgogICAgICAgIEluZnBYIDwgU1pfU1REX1NFQ1RPUiAmJgogICAgICAgIEluZlRtIDwgU1pfU1REX1NFQ1RPUiAmJgogICAgICAgIEJvb3RQID49IEluZlRtICsgMiAmJgogICAgICAgIEluZlRtID49IEluZnBYICYmCiAgICAgICAgSW5mcFggPj0gSW5mcDAgJiYgCiAgICAgICAgSW5mcDAgPj0gNzYgKSB7CgogICAgICAgIHJldHVybiAoLTEpOwogICAgfQoKICAgIGlmIChoZWFkcyAhPSBOQl9IRUFEUyB8fAogICAgICAgIHRyYWNrcyAhPSBOQl9UUkFDS1MgfHwKICAgICAgICBzZWN0b3JzICE9IE5CX1NFQ1RPUlMgfHwKICAgICAgICBfX2xlMTZfdG9fY3B1IChib290IC0+IHNlY3NpeikgIT0gU1pfU1REX1NFQ1RPUiB8fAogICAgICAgIGZzIC0+IHRvdF9zZWN0b3JzID09IDAgfHwKICAgICAgICAoZnMgLT4gdG90X3NlY3RvcnMgJSBzZWN0b3JzKSAhPSAwKSB7CiAgICAgICAgcmV0dXJuICgtMSk7CiAgICB9CiAgICAKICAgIHJldHVybiAoMCk7Cn0KCgojZW5kaWYK