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BtaW5zdGRfcmFuZDsKdHlwZWRlZiBtZXJzZW5uZV90d2lzdGVyX2VuZ2luZTx1aW50X2Zhc3QzMl90LCAzMiwgNjI0LCAzOTcsIDMxLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDB4OTkwOGIwZGYsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTEsIDB4ZmZmZmZmZmYsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgNywgIDB4OWQyYzU2ODAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTUsIDB4ZWZjNjAwMDAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTgsIDE4MTI0MzMyNTM+ICAgICAgICAgICAgICAgICAgICAgICAgIG10MTk5Mzc7CnR5cGVkZWYgbWVyc2VubmVfdHdpc3Rlcl9lbmdpbmU8dWludF9mYXN0NjRfdCwgNjQsIDMxMiwgMTU2LCAzMSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAweGI1MDI2ZjVhYTk2NjE5ZTksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMjksIDB4NTU1NTU1NTU1NTU1NTU1NSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAxNywgMHg3MWQ2N2ZmZmVkYTYwMDAwLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDM3LCAweGZmZjdlZWUwMDAwMDAwMDAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgNDMsIDYzNjQxMzYyMjM4NDY3OTMwMDU+ICAgICAgICAgICAgIG10MTk5MzdfNjQ7CnR5cGVkZWYgc3VidHJhY3Rfd2l0aF9jYXJyeV9lbmdpbmU8dWludF9mYXN0MzJfdCwgMjQsIDEwLCAyND4gICAgIHJhbmx1eDI0X2Jhc2U7CnR5cGVkZWYgc3VidHJhY3Rfd2l0aF9jYXJyeV9lbmdpbmU8dWludF9mYXN0NjRfdCwgNDgsICA1LCAxMj4gICAgIHJ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AgICAgICBjb25zdCByZXN1bHRfdHlwZSBfX3QwID0gX19hICogKF9feCAlIF9fcSk7CiAgICAgICAgY29uc3QgcmVzdWx0X3R5cGUgX190MSA9IF9fciAqIChfX3ggLyBfX3EpOwogICAgICAgIF9feCA9IF9fdDAgKyAoX190MCA8IF9fdDEpICogX19tIC0gX190MTsKICAgICAgICBfX3ggKz0gX19jIC0gKF9feCA+PSBfX20gLSBfX2MpICogX19tOwogICAgICAgIHJldHVybiBfX3g7CiAgICB9Cn07Cgp0ZW1wbGF0ZSA8dW5zaWduZWQgbG9uZyBsb25nIF9fYSwgdW5zaWduZWQgbG9uZyBsb25nIF9fbT4Kc3RydWN0IF9fbGNlX3RhPF9fYSwgMCwgX19tLCAodW5zaWduZWQgbG9uZyBsb25nKSh+MCksIHRydWU+CnsKICAgIHR5cGVkZWYgdW5zaWduZWQgbG9uZyBsb25nIHJlc3VsdF90eXBlOwogICAgc3RhdGljIHJlc3VsdF90eXBlIG5leHQocmVzdWx0X3R5cGUgX194KQogICAgewogICAgICAgIC8vIFNjaHJhZ2UncyBhbGdvcml0aG0KICAgICAgICBjb25zdCByZXN1bHRfdHlwZSBfX3EgPSBfX20gLyBfX2E7CiAgICAgICAgY29uc3QgcmVzdWx0X3R5cGUgX19yID0gX19tICUgX19hOwogICAgICAgIGNvbnN0IHJlc3VsdF90eXBlIF9fdDAgPSBfX2EgKiAoX194ICUgX19xKTsKICAgICAgICBjb25zdCByZXN1bHRfdHlwZSBfX3QxID0gX19yICogKF9feCAvIF9fcSk7CiAgICAgICAgX194ID0gX190MCArIChfX3QwIDwgX190MSkgKiBfX20gLSBfX3QxOwogICAgICAgIHJldHVybiBfX3g7CiAgICB9Cn07Cgp0ZW1wbGF0ZSA8dW5zaWduZWQgbG9uZyBsb25nIF9fYSwgdW5zaWduZWQgbG9uZyBsb25nIF9fYywgdW5zaWduZWQgbG9uZyBsb25nIF9fbT4Kc3RydWN0IF9fbGNlX3RhPF9fYSwgX19jLCBfX20sICh1b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19jb252ZXJ0aWJsZTxfU3NlcSwgcmVzdWx0X3R5cGU+Ojp2YWx1ZSwKICAgICAgICAgICAgdm9pZAogICAgICAgID46OnR5cGUKICAgICAgICBzZWVkKF9Tc2VxJiBfX3EpCiAgICAgICAgICAgIHtfX3NlZWQoX19xLCBpbnRlZ3JhbF9jb25zdGFudDx1bnNpZ25lZCwKICAgICAgICAgICAgICAgIDEgKyAoX19tID09IDAgPyAoc2l6ZW9mKHJlc3VsdF90eXBlKSAqIF9fQ0hBUl9CSVRfXyAtIDEpLzMyCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgOiAgKF9fbS0xKSAvIDB4MTAwMDAwMDAwdWxsKT4oKSk7fQoKICAgIC8vIGdlbmVyYXRpbmcgZnVuY3Rpb25zCiAgICByZXN1bHRfdHlwZSBvcGVyYXRvcigpKCkKICAgICAgICB7cmV0dXJuIF9feF8gPSBzdGF0aWNfY2FzdDxyZXN1bHRfdHlwZT4oX19sY2VfdGE8X19hLCBfX2MsIF9fbSwgX00+OjpuZXh0KF9feF8pKTt9CiAgICB2b2lkIGRpc2NhcmQodW5zaWduZWQgbG9uZyBsb25nIF9feikge2ZvciAoOyBfX3o7IC0tX196KSBvcGVyYXRvcigpKCk7fQoKICAgIGZyaWVuZCBib29sIG9wZXJhdG9yPT0oY29uc3QgbGluZWFyX2NvbmdydWVudGlhbF9lbmdpbmUmIF9feCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgbGluZWFyX2NvbmdydWVudGlhbF9lbmdpbmUmIF9feSkKICAgICAgICB7cmV0dXJuIF9feC5fX3hfID09IF9feS5fX3hfO30KICAgIGZyaWVuZCBib29sIG9wZXJhdG9yIT0oY29uc3QgbGluZWFyX2NvbmdydWVudGlhbF9lbmdpbmUmIF9feCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgbGluZWFyX2NvbmdydWVudGlhbF9lbmdpbmUmIF9feSkKICAgICAgICB7cmV0dXJuICEoX194ID09IF9feSk7fQ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GVyYXRvcj4+KGJhc2ljX2lzdHJlYW08X0NoYXJULCBfVHJhaXRzPiYgX19pcywKICAgICAgICAgICBsaW5lYXJfY29uZ3J1ZW50aWFsX2VuZ2luZTxfVUludFR5cGUsIF9fYSwgX19jLCBfX20+JiBfX3gpCnsKICAgIF9fc2F2ZV9mbGFnczxfQ2hhclQsIF9UcmFpdHM+IF8oX19pcyk7CiAgICBfX2lzLmZsYWdzKGlvc19iYXNlOjpkZWMgfCBpb3NfYmFzZTo6c2tpcHdzKTsKICAgIF9VSW50VHlwZSBfX3Q7CiAgICBfX2lzID4+IF9fdDsKICAgIGlmICghX19pcy5mYWlsKCkpCiAgICAgICAgX194Ll9feF8gPSBfX3Q7CiAgICByZXR1cm4gX19pczsKfQoKdHlwZWRlZiBsaW5lYXJfY29uZ3J1ZW50aWFsX2VuZ2luZTx1aW50X2Zhc3QzMl90LCAxNjgwNywgMCwgMjE0NzQ4MzY0Nz4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1pbnN0ZF9yYW5kMDsKdHlwZWRlZiBtaW5zdGRfcmFuZDAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlZmF1bHRfcmFuZG9tX2VuZ2luZTsKdHlwZWRlZiBsaW5lYXJfY29uZ3J1ZW50aWFsX2VuZ2luZTx1aW50X2Zhc3QzMl90LCA0ODI3MSwgMCwgMjE0NzQ4MzY0Nz4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtaW5zdGRfcmFuZDsKLy8gbWVyc2VubmVfdHdpc3Rlcl9lbmdpbmUKCnRlbXBsYXRlIDxjbGFzcyBfVUludFR5cGUsIHNpemVfdCBfX3csIHNpemVfdCBfX24sIHNpemVfdCBfX20sIHNpemVfdCBfX3IsCiAgICAgICAgICBfVUludFR5cGUgX19hLCBzaXplX3QgX191LCBfVUludF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aWJsZTxfU3NlcSwgcmVzdWx0X3R5cGU+Ojp2YWx1ZSwKICAgICAgICAgICAgdm9pZAogICAgICAgID46OnR5cGUKICAgICAgICBzZWVkKF9Tc2VxJiBfX3EpCiAgICAgICAgICAgIHtfX3NlZWQoX19xLCBpbnRlZ3JhbF9jb25zdGFudDx1bnNpZ25lZCwgMSArIChfX3cgLSAxKSAvIDMyPigpKTt9CgogICAgLy8gZ2VuZXJhdGluZyBmdW5jdGlvbnMKICAgIHJlc3VsdF90eXBlIG9wZXJhdG9yKCkoKTsKICAgIHZvaWQgZGlzY2FyZCh1bnNpZ25lZCBsb25nIGxvbmcgX196KSB7Zm9yICg7IF9fejsgLS1fX3opIG9wZXJhdG9yKCkoKTt9CgogICAgdGVtcGxhdGUgPGNsYXNzIF9VSSwgc2l6ZV90IF9XLCBzaXplX3QgX04sIHNpemVfdCBfTSwgc2l6ZV90IF9SLAogICAgICAgICAgICAgIF9VSSBfQSwgc2l6ZV90IF9VLCBfVUkgX0QsIHNpemVfdCBfUywKICAgICAgICAgICAgICBfVUkgX0IsIHNpemVfdCBfVCwgX1VJIF9DLCBzaXplX3QgX0wsIF9VSSBfRj4KICAgIGZyaWVuZAogICAgYm9vbAogICAgb3BlcmF0b3I9PShjb25zdCBtZXJzZW5uZV90d2lzdGVyX2VuZ2luZTxfVUksIF9XLCBfTiwgX00sIF9SLCBfQSwgX1UsIF9ELCBfUywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX0IsIF9ULCBfQywgX0wsIF9GPiYgX194LAogICAgICAgICAgICAgICBjb25zdCBtZXJzZW5uZV90d2lzdGVyX2VuZ2luZTxfVUksIF9XLCBfTiwgX00sIF9SLCBfQSwgX1UsIF9ELCBfUywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX0IsIF9ULCBfQywgX0wsIF9GPiYgX195KTsKICAgIAogICAgdGVtcGxhdGUgPGNsYXNzIF9VSSwgc2l6ZV90IF9XLCBzaXplX3QgX04sIHNpemVfdCBfTSwgc2l6ZV90IF9SLAogICAgICAgICAgICAgIF9VSSBfQSwgc2l6ZV90IF9VLCBfVUkgX0QsIHNpemVfdCBfUywKICAgICAgICAgICAgICBfVUkgX0IsIHNpemVfdCBfVCwgX1VJIF9DLCBzaXplX3QgX0wsIF9VSSBfRj4KICAgIGZyaWVuZAogICAgYm9vbAogICAgb3BlcmF0b3IhPShjb25zdCBtZXJzZW5uZV90d2lzdGVyX2VuZ2luZTxfVUksIF9XLCBfTiwgX00sIF9SLCBfQSwgX1UsIF9ELCBfUywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX0IsIF9ULCBfQywgX0wsIF9GPiYgX194LAogICAgICAgICAgICAgICBjb25zdCBtZXJzZW5uZV90d2lzdGVyX2VuZ2luZTxfVUksIF9XLCBfTiwgX00sIF9SLCBfQSwgX1UsIF9ELCBfUywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX0IsIF9ULCBfQywgX0wsIF9GPiYgX195KTsKCiAgICB0ZW1wbGF0ZSA8Y2xhc3MgX0NoYXJULCBjbGFzcyBfVHJhaXRzLAogICAgICAgICAgICAgIGNsYXNzIF9VSSwgc2l6ZV90IF9XLCBzaXplX3QgX04sIHNpemVfdCBfTSwgc2l6ZV90IF9SLAogICAgICAgICAgICAgIF9VSSBfQSwgc2l6ZV90IF9VLCBfVUkgX0QsIHNpemVfdCBfUywKICAgICAgICAgICAgICBfVUkgX0IsIHNpemVfdCBfVCwgX1VJIF9DLCBzaXplX3QgX0wsIF9VSSBfRj4KICAgIGZyaWVuZAogICAgYmFzaWNfb3N0cmVhbTxfQ2hhclQsIF9UcmFpdHM+JgogICAgb3BlcmF0b3I8PChiYXNpY19vc3RyZWFtPF9DaGFyVCwgX1RyYWl0cz4mIF9fb3MsCiAgICAgICAgICAgICAgIGNvbnN0IG1lcnNlbm5lX3R3aXN0ZXJfZW5naW5lPF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JsZV9pZgogICAgICAgIDwKICAgICAgICAgICAgX19jb3VudCA8IF9fdywKICAgICAgICAgICAgcmVzdWx0X3R5cGUKICAgICAgICA+Ojp0eXBlCiAgICAgICAgX19sc2hpZnQocmVzdWx0X3R5cGUgX194KSB7cmV0dXJuIChfX3ggPDwgX19jb3VudCkgJiBfTWF4O30KCiAgICB0ZW1wbGF0ZSA8c2l6ZV90IF9fY291bnQ+CiAgICAgICAgc3RhdGljCiAgICAgICAgdHlwZW5hbWUgZW5hYmxlX2lmCiAgICAgICAgPAogICAgICAgICAgICAoX19jb3VudCA+PSBfX3cpLAogICAgICAgICAgICByZXN1bHRfdHlwZQogICAgICAgID46OnR5cGUKICAgICAgICBfX2xzaGlmdChyZXN1bHRfdHlwZSBfX3gpIHtyZXR1cm4gcmVzdWx0X3R5cGUoMCk7fQoKICAgIHRlbXBsYXRlIDxzaXplX3QgX19jb3VudD4KICAgICAgICBzdGF0aWMKICAgICAgICB0eXBlbmFtZSBlbmFibGVfaWYKICAgICAgICA8CiAgICAgICAgICAgIF9fY291bnQgPCBfRHQsCiAgICAgICAgICAgIHJlc3VsdF90eXBlCiAgICAgICAgPjo6dHlwZQogICAgICAgIF9fcnNoaWZ0KHJlc3VsdF90eXBlIF9feCkge3JldHVybiBfX3ggPj4gX19jb3VudDt9CgogICAgdGVtcGxhdGUgPHNpemVfdCBfX2NvdW50PgogICAgICAgIHN0YXRpYwogICAgICAgIHR5cGVuYW1lIGVuYWJsZV9pZgogICAgICAgIDwKICAgICAgICAgICAgKF9fY291bnQgPj0gX0R0KSwKICAgICAgICAgICAgcmVzdWx0X3R5cGUKICAgICAgICA+Ojp0eXBlCiAgICAgICAgX19yc2hpZnQocmVzdWx0X3R5cGUgX194KSB7cmV0dXJuIHJlc3VsdF90eXBlKDApO30KfTsKCnRlbXBsYXRlIDxjbGFzcyBfVUludFR5cGUsIHNpemVfdCBfX3csIHNpemVfdCBfX24sIHNpemVfdCBfX20sIHNpemVfdCBfX3IsCiAgICAgICAgICBfVUludFR5cGUgX19hLCBzaXplX3QgX191LCBfVUludFR5cGUgX19kLCBzaXplX3QgX19zLAogICAgICAgICAgX1VJbnRUeXBlIF9fYiwgc2l6ZV90IF9fdCwgX1VJbnRUeXBlIF9fYywgc2l6ZV90IF9fbCwgX1VJbnRUeXBlIF9fZj4Kdm9pZAptZXJzZW5uZV90d2lzdGVyX2VuZ2luZTxfVUludFR5cGUsIF9fdywgX19uLCBfX20sIF9fciwgX19hLCBfX3UsIF9fZCwgX19zLCBfX2IsCiAgICBfX3QsIF9fYywgX19sLCBfX2Y+OjpzZWVkKHJlc3VsdF90eXBlIF9fc2QpCnsgICAvLyBfX3cgPj0gMgogICAgX194X1swXSA9IF9fc2QgJiBfTWF4OwogICAgZm9yIChzaXplX3QgX19pID0gMTsgX19pIDwgX19uOyArK19faSkKICAgICAgICBfX3hfW19faV0gPSAoX19mICogKF9feF9bX19pLTFdIF4gX19yc2hpZnQ8X193IC0gMj4oX194X1tfX2ktMV0pKSArIF9faSkgJiBfTWF4OwogICAgX19pXyA9IDA7Cn0KCnRlbXBsYXRlIDxjbGFzcyBfVUludFR5cGUsIHNpemVfdCBfX3csIHNpemVfdCBfX24sIHNpemVfdCBfX20sIHNpemVfdCBfX3IsCiAgICAgICAgICBfVUludFR5cGUgX19hLCBzaXplX3QgX191LCBfVUludFR5cGUgX19kLCBzaXplX3QgX19zLAogICAgICAgICAgX1VJbnRUeXBlIF9fYiwgc2l6ZV90IF9fdCwgX1VJbnRUeXBlIF9fYywgc2l6ZV90IF9fbCwgX1VJbnRUeXBlIF9fZj4KdGVtcGxhdGU8Y2xhc3MgX1NzZXE+CnZvaWQKbWVyc2VubmVfdHdpc3Rlcl9lbmdpbmU8X1VJbnRUeXBlLCBfX3csIF9fbiwgX19tLCBfX3IsIF9fYSwgX191LCBfX2QsIF9fcywgX19iLAogICAgX190LCBfX2MsIF9fbCwgX19mPjo6X19zZWVkKF9Tc2VxJiBfX3EsIGludGVncmFsX2NvbnN0YW50PHVuc2lnbmVkLCAxPikKewogICAgY29uc3QgdW5zaWduZWQgX19rID0gMTsKICAgIHVpbnQzMl90IF9fYXJbX19uICogX19rXTsKICAgIF9fcS5nZW5lcmF0ZShfX2FyLCBfX2FyICsgX19uICogX19rKTsKICAgIGZvciAoc2l6ZV90IF9faSA9IDA7IF9faSA8IF9fbjsgKytfX2kpCiAgICAgICAgX194X1tfX2ldID0gc3RhdGljX2Nhc3Q8cmVzdWx0X3R5cGU+KF9fYXJbX19pXSAmIF9NYXgpOwogICAgY29uc3QgcmVzdWx0X3R5cGUgX19tYXNrID0gX19yID09IF9EdCA/IHJlc3VsdF90eXBlKH4wKSA6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChyZXN1bHRfdHlwZSgxKSA8PCBfX3IpIC0gcmVzdWx0X3R5cGUoMSk7CiAgICBfX2lfID0gMDsKICAgIGlmICgoX194X1swXSAmIH5fX21hc2spID09IDApCiAgICB7CiAgICAgICAgZm9yIChzaXplX3QgX19pID0gMTsgX19pIDwgX19uOyArK19faSkKICAgICAgICAgICAgaWYgKF9feF9bX19pXSAhPSAwKQogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIF9feF9bMF0gPSBfTWF4OwogICAgfQp9Cgp0ZW1wbGF0ZSA8Y2xhc3MgX1VJbnRUeXBlLCBzaXplX3QgX193LCBzaXplX3QgX19uLCBzaXplX3QgX19tLCBzaXplX3QgX19yLAogICAgICAgICAgX1VJbnRUeXBlIF9fYSwgc2l6ZV90IF9fdSwgX1VJbnRUeXBlIF9fZCwgc2l6ZV90IF9fcywKICAgICAgICAgIF9VSW50VHlwZSBfX2IsIHNpemVfdCBfX3QsIF9VSW50VHlwZSBfX2MsIHNpemVfdCBfX2wsIF9VSW50VHlwZSBfX2Y+CnRlbXBsYXRlPGNsYXNzIF9Tc2VxPgp2b2lkCm1lcnNlbm5lX3R3aXN0ZXJfZW5naW5lPF9VSW50VHlwZSwgX193LCBfX24sIF9fbSwgX19yLCBfX2EsIF9fdSwgX19kLCBfX3MsIF9fYiwKICAgIF9fdCwgX19jLCBfX2wsIF9fZj46Ol9fc2VlZChfU3NlcSYgX19xLCBpbnRlZ3JhbF9jb25zdGFudDx1bnNpZ25lZCwgMj4pCnsKICAgIGNvbnN0IHVuc2lnbmVkIF9fayA9IDI7CiAgICB1aW50MzJfdCBfX2FyW19fbiAqIF9fa107CiAgICBfX3EuZ2VuZXJhdGUoX19hciwgX19hciArIF9fbiAqIF9fayk7CiAgICBmb3IgKHNpemVfdCBfX2kgPSAwOyBfX2kgPCBfX247ICsrX19pKQogICAgICAgIF9feF9bX19pXSA9IHN0YXRpY19jYXN0PHJlc3VsdF90eXBlPigKICAgICAgICAgICAgKF9fYXJbMiAqIF9faV0gKyAoKHVpbnQ2NF90KV9fYXJbMiAqIF9faSArIDFdIDw8IDMyKSkgJiBfTWF4KTsKICAgIGNvbnN0IHJlc3VsdF90eXBlIF9fbWFzayA9IF9fciA9PSBfRHQgPyByZXN1bHRfdHlwZSh+MCkgOgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAocmVzdWx0X3R5cGUoMSkgPDwgX19yKSAtIHJlc3VsdF90eXBlKDEpOwogICAgX19pXyA9IDA7CiAgICBpZiAoKF9feF9bMF0gJiB+X19tYXNrKSA9PSAwKQogICAgewogICAgICAgIGZvciAoc2l6ZV90IF9faSA9IDE7IF9faSA8IF9fbjsgKytfX2kpCiAgICAgICAgICAgIGlmIChfX3hfW19faV0gIT0gMCkKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICBfX3hfWzBdID0gX01heDsKICAgIH0KfQoKdGVtcGxhdGUgPGNsYXNzIF9VSW50VHlwZSwgc2l6ZV90IF9fdywgc2l6ZV90IF9fbiwgc2l6ZV90IF9fbSwgc2l6ZV90IF9fciwKICAgICAgICAgIF9VSW50VHlwZSBfX2EsIHNpemVfdCBfX3UsIF9VSW50VHlwZSBfX2QsIHNpemVfdCBfX3MsCiAgICAgICAgICBfVUludFR5cGUgX19iLCBzaXplX3QgX190LCBfVUludFR5cGUgX19jLCBzaXplX3QgX19sLCBfVUludFR5cGUgX19mPgpfVUludFR5cGUKbWVyc2VubmVfdHdpc3Rlcl9lbmdpbmU8X1VJbnRUeXBlLCBfX3csIF9fbiwgX19tLCBfX3IsIF9fYSwgX191LCBfX2QsIF9fcywgX19iLAogICAgX190LCBfX2MsIF9fbCwgX19mPjo6b3BlcmF0b3IoKSgpCnsKICAgIGNvbnN0IHNpemVfdCBfX2ogPSAoX19pXyArIDEpICUgX19uOwogICAgY29uc3QgcmVzdWx0X3R5cGUgX19tYXNrID0gX19yID09IF9EdCA/IHJlc3VsdF90eXBlKH4wKSA6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChyZXN1bHRfdHlwZSgxKSA8PCBfX3IpIC0gcmVzdWx0X3R5cGUoMSk7CiAgICBjb25zdCByZXN1bHRfdHlwZSBfWSA9IChfX3hfW19faV9dICYgfl9fbWFzaykgfCAoX194X1tfX2pdICYgX19tYXNrKTsKICAgIGNvbnN0IHNpemVfdCBfX2sgPSAoX19pXyArIF9fbSkgJSBfX247CiAgICBfX3hfW19faV9dID0gX194X1tfX2tdIF4gX19yc2hpZnQ8MT4oX1kpIF4gKF9fYSAqIChfWSAmIDEpKTsKICAgIHJlc3VsdF90eXBlIF9feiA9IF9feF9bX19pX10gXiAoX19yc2hpZnQ8X191PihfX3hfW19faV9dKSAmIF9fZCk7CiAgICBfX2lfID0gX19qOwogICAgX196IF49IF9fbHNoaWZ0PF9fcz4oX196KSAmIF9fYjsKICAgIF9feiBePSBfX2xzaGlmdDxfX3Q+KF9feikgJiBfX2M7CiAgICByZXR1cm4gX196IF4gX19yc2hpZnQ8X19sPihfX3opOwp9Cgp0ZW1wbGF0ZSA8Y2xhc3MgX1VJLCBzaXplX3QgX1csIHNpemVfdCBfTiwgc2l6ZV90IF9NLCBzaXplX3QgX1IsCiAgICAgICAgICBfVUkgX0EsIHNpemVfdCBfVSwgX1VJIF9ELCBzaXplX3QgX1MsCiAgICAgICAgICBfVUkgX0IsIHNpemVfdCBfVCwgX1VJIF9DLCBzaXplX3QgX0wsIF9VSSBfRj4KYm9vbApvcGVyYXRvcj09KGNvbnN0IG1lcnNlbm5lX3R3aXN0ZXJfZW5naW5lPF9VSSwgX1csIF9OLCBfTSwgX1IsIF9BLCBfVSwgX0QsIF9TLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9CLCBfVCwgX0MsIF9MLCBfRj4mIF9feCwKICAgICAgICAgICBjb25zdCBtZXJzZW5uZV90d2lzdGVyX2VuZ2luZTxfVUksIF9XLCBfTiwgX00sIF9SLCBfQSwgX1UsIF9ELCBfUywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfQiwgX1QsIF9DLCBfTCwgX0Y+JiBfX3kpCnsKICAgIGlmIChfX3guX19pXyA9PSBfX3kuX19pXykKICAgICAgICByZXR1cm4gX1NURDo6ZXF1YWwoX194Ll9feF8sIF9feC5fX3hfICsgX04sIF9feS5fX3hfKTsKICAgIGlmIChfX3guX19pXyA9PSAwIHx8IF9feS5fX2lfID09IDApCiAgICB7CiAgICAgICAgc2l6ZV90IF9faiA9IF9TVEQ6Om1pbihfTiAtIF9feC5fX2lfLCBfTiAtIF9feS5fX2lfKTsKICAgICAgICBpZiAoIV9TVEQ6OmVxdWFsKF9feC5fX3hfICsgX194Ll9faV8sIF9feC5fX3hfICsgX194Ll9faV8gKyBfX2osCiAgICAgICAgICAgICAgICAgICAgICAgICBfX3kuX194XyArIF9feS5fX2lfKSkKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmIChfX3guX19pXyA9PSAwKQogICAgICAgICAgICByZXR1cm4gX1NURDo6ZXF1YWwoX194Ll9feF8gKyBfX2osIF9feC5fX3hfICsgX04sIF9feS5fX3hfKTsKICAgICAgICByZXR1cm4gX1NURDo6ZXF1YWwoX194Ll9feF8sIF9feC5fX3hfICsgKF9OIC0gX19qKSwgX195Ll9feF8gKyBfX2opOwogICAgfQogICAgaWYgKF9feC5fX2lfIDwgX195Ll9faV8pCiAgICB7CiAgICAgICAgc2l6ZV90IF9faiA9IF9OIC0gX195Ll9faV87CiAgICAgICAgaWYgKCFfU1REOjplcXVhbChfX3guX194XyArIF9feC5fX2lfLCBfX3guX194XyArIChfX3guX19pXyArIF9faiksCiAgICAgICAgICAgICAgICAgICAgICAgICBfX3kuX194XyArIF9feS5fX2lfKSkKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmICghX1NURDo6ZXF1YWwoX194Ll9feF8gKyAoX194Ll9faV8gKyBfX2opLCBfX3guX194XyArIF9OLAogICAgICAgICAgICAgICAgICAgICAgICAgX195Ll9feF8pKQogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgcmV0dXJuIF9TVEQ6OmVxdWFsKF9feC5fX3hfLCBfX3guX194XyArIF9feC5fX2lfLAogICAgICAgICAgICAgICAgICAgICAgICAgICBfX3kuX194XyArIChfTiAtIChfX3guX19pXyArIF9faikpKTsKICAgIH0KICAgIHNpemVfdCBfX2ogPSBfTiAtIF9feC5fX2lfOwogICAgaWYgKCFfU1REOjplcXVhbChfX3kuX194XyArIF9feS5fX2lfLCBfX3kuX194XyArIChfX3kuX19pXyArIF9faiksCiAgICAgICAgICAgICAgICAgICAgIF9feC5fX3hfICsgX194Ll9faV8pKQogICAgICAgIHJldHVybiBmYWxzZTsKICAgIGlmICghX1NURDo6ZXF1YWwoX195Ll9feF8gKyAoX195Ll9faV8gKyBfX2opLCBfX3kuX194XyArIF9OLAogICAgICAgICAgICAgICAgICAgICBfX3guX194XykpCiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgcmV0dXJuIF9TVEQ6OmVxdWFsKF9feS5fX3hfLCBfX3kuX194XyArIF9feS5fX2lfLAogICAgICAgICAgICAgICAgICAgICAgIF9feC5fX3hfICsgKF9OIC0gKF9feS5fX2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fTSwgX1IsIF9BLCBfVSwgX0QsIF9TLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9CLCBfVCwgX0MsIF9MLCBfRj4mIF9feCkKewogICAgX19zYXZlX2ZsYWdzPF9DaGFyVCwgX1RyYWl0cz4gXyhfX2lzKTsKICAgIF9faXMuZmxhZ3MoaW9zX2Jhc2U6OmRlYyB8IGlvc19iYXNlOjpza2lwd3MpOwogICAgX1VJIF9fdFtfTl07CiAgICBmb3IgKHNpemVfdCBfX2kgPSAwOyBfX2kgPCBfTjsgKytfX2kpCiAgICAgICAgX19pcyA+PiBfX3RbX19pXTsKICAgIGlmICghX19pcy5mYWlsKCkpCiAgICB7CiAgICAgICAgZm9yIChzaXplX3QgX19pID0gMDsgX19pIDwgX047ICsrX19pKQogICAgICAgICAgICBfX3guX194X1tfX2ldID0gX190W19faV07CiAgICAgICAgX194Ll9faV8gPSAwOwogICAgfQogICAgcmV0dXJuIF9faXM7Cn0KCnR5cGVkZWYgbWVyc2VubmVfdHdpc3Rlcl9lbmdpbmU8dWludF9mYXN0MzJfdCwgMzIsIDYyNCwgMzk3LCAzMSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAweDk5MDhiMGRmLCAxMSwgMHhmZmZmZmZmZiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA3LCAgMHg5ZDJjNTY4MCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAxNSwgMHhlZmM2MDAwMCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAxOCwgMTgxMjQzMzI1Mz4gICAgICAgICAgICAgICAgICAgICAgICAgbXQxOTkzNzsKdHlwZWRlZiBtZXJzZW5uZV90d2lzdGVyX2VuZ2luZTx1aW50X2Zhc3Q2NF90LCA2NCwgMzEyLCAxNTYsIDMxLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDB4YjUwMjZmNWFhOTY2MTllOVVMTCwgMjksIDB4NTU1NTU1NTU1NTU1NTU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fZSgpICYgX01heCk7CiAgICBfX2NfID0gX194X1tfX3ItMV0gPT0gMDsKICAgIF9faV8gPSAwOwp9Cgp0ZW1wbGF0ZTxjbGFzcyBfVUludFR5cGUsIHNpemVfdCBfX3csIHNpemVfdCBfX3MsIHNpemVfdCBfX3I+CnZvaWQKc3VidHJhY3Rfd2l0aF9jYXJyeV9lbmdpbmU8X1VJbnRUeXBlLCBfX3csIF9fcywgX19yPjo6c2VlZChyZXN1bHRfdHlwZSBfX3NkLAogICAgICAgIGludGVncmFsX2NvbnN0YW50PHVuc2lnbmVkLCAyPikKewogICAgbGluZWFyX2NvbmdydWVudGlhbF9lbmdpbmU8cmVzdWx0X3R5cGUsIDQwMDE0dSwgMHUsIDIxNDc0ODM1NjN1PgogICAgICAgIF9fZShfX3NkID09IDB1ID8gZGVmYXVsdF9zZWVkIDogX19zZCk7CiAgICBmb3IgKHNpemVfdCBfX2kgPSAwOyBfX2kgPCBfX3I7ICsrX19pKQogICAgICAgIF9feF9bX19pXSA9IHN0YXRpY19jYXN0PHJlc3VsdF90eXBlPigKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKF9fZSgpICsgKCh1aW50NjRfdClfX2UoKSA8PCAzMikpICYgX01heCk7CiAgICBfX2NfID0gX194X1tfX3ItMV0gPT0gMDsKICAgIF9faV8gPSAwOwp9Cgp0ZW1wbGF0ZTxjbGFzcyBfVUludFR5cGUsIHNpemVfdCBfX3csIHNpemVfdCBfX3MsIHNpemVfdCBfX3I+CnRlbXBsYXRlPGNsYXNzIF9Tc2VxPgp2b2lkCnN1YnRyYWN0X3dpdGhfY2FycnlfZW5naW5lPF9VSW50VHlwZSwgX193LCBfX3MsIF9fcj46Ol9fc2VlZChfU3NlcSYgX19xLAogICAgICAgIGludGVncmFsX2NvbnN0YW50PHVuc2lnbmVkLCAxPikKewogICAgY29uc3QgdW5zaWduZWQgX19rID0gMTsKICAgIHVpbnQzMl90IF9fYXJbX19yICogX19rXTsKICAgIF9fcS5n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om9wZXJhdG9yKCkoKQp7CiAgICBjb25zdCByZXN1bHRfdHlwZSYgX194cyA9IF9feF9bKF9faV8gKyAoX19yIC0gX19zKSkgJSBfX3JdOwogICAgcmVzdWx0X3R5cGUmIF9feHIgPSBfX3hfW19faV9dOwogICAgcmVzdWx0X3R5cGUgX19uZXdfYyA9IF9fY18gPT0gMCA/IF9feHMgPCBfX3hyIDogX194cyAhPSAwID8gX194cyA8PSBfX3hyIDogMTsKICAgIF9feHIgPSAoX194cyAtIF9feHIgLSBfX2NfKSAmIF9NYXg7CiAgICBfX2NfID0gX19uZXdfYzsKICAgIF9faV8gPSAoX19pXyArIDEpICUgX19yOwogICAgcmV0dXJuIF9feHI7Cn0KCnRlbXBsYXRlPGNsYXNzIF9VSSwgc2l6ZV90IF9XLCBzaXplX3QgX1MsIHNpemVfdCBfUj4KYm9vbApvcGVyYXRvcj09KAogICAgY29uc3Qgc3VidHJhY3Rfd2l0aF9jYXJyeV9lbmdpbmU8X1VJLCBfVywgX1MsIF9SPiYgX194LAogICAgY29uc3Qgc3VidHJhY3Rfd2l0aF9jYXJyeV9lbmdpbmU8X1VJLCBfVywgX1MsIF9SPiYgX195KQp7CiAgICBpZiAoX194Ll9fY18gIT0gX195Ll9fY18pCiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgaWYgKF9feC5fX2lfID09IF9feS5fX2lfKQogICAgICAgIHJldHVybiBfU1REOjplcXVhbChfX3guX194XywgX194Ll9feF8gKyBfUiwgX195Ll9feF8pOwogICAgaWYgKF9feC5fX2lfID09IDAgfHwgX195Ll9faV8gPT0gMCkKICAgIHsKICAgICAgICBzaXplX3QgX19qID0gX1NURDo6bWluKF9SIC0gX194Ll9faV8sIF9SIC0gX195Ll9faV8pOwogICAgICAgIGlmICghX1NURDo6ZXF1YWwoX194Ll9feF8gKyBfX3guX19pXywgX194Ll9feF8gKyBfX3guX19pXyArIF9faiwKICAgICAgICAgICAgICAgICAgICAgICAgIF9feS5fX3hfICsgX195Ll9faV8pKQogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKF9feC5fX2lfID09IDApCiAgICAgICAgICAgIHJldHVybiBfU1REOjplcXVhbChfX3guX194XyArIF9faiwgX194Ll9feF8gKyBfUiwgX195Ll9feF8pOwogICAgICAgIHJldHVybiBfU1REOjplcXVhbChfX3guX194XywgX194Ll9feF8gKyAoX1IgLSBfX2opLCBfX3kuX194XyArIF9faik7CiAgICB9CiAgICBpZiAoX194Ll9faV8gPCBfX3kuX19pXykKICAgIHsKICAgICAgICBzaXplX3QgX19qID0gX1IgLSBfX3kuX19pXzsKICAgICAgICBpZiAoIV9TVEQ6OmVxdWFsKF9feC5fX3hfICsgX194Ll9faV8sIF9feC5fX3hfICsgKF9feC5fX2lfICsgX19qKSwKICAgICAgICAgICAgICAgICAgICAgICAgIF9feS5fX3hfICsgX195Ll9faV8pKQogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKCFfU1REOjplcXVhbChfX3guX194XyArIChfX3guX19pXyArIF9faiksIF9feC5fX3hfICsgX1IsCiAgICAgICAgICAgICAgICAgICAgICAgICBfX3kuX194XykpCiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICByZXR1cm4gX1NURDo6ZXF1YWwoX194Ll9feF8sIF9feC5fX3hfICsgX194Ll9faV8sCiAgICAgICAgICAgICAgICAgICAgICAgICAgIF9feS5fX3hfICsgKF9SIC0gKF9feC5fX2lfICsgX19qKSkpOwogICAgfQogICAgc2l6ZV90IF9faiA9IF9SIC0gX194Ll9faV87CiAgICBpZiAoIV9TVEQ6OmVxdWFsKF9feS5fX3hfICsgX195Ll9faV8sIF9feS5fX3hfICsgKF9feS5fX2lfICsgX19qKSwKICAgICAgICAgICAgICAgICAgICAgX194Ll9feF8gKyBfX3guX19pXykpCiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgaWYgKCFfU1REOjplcXVhbChfX3kuX194XyArIChfX3kuX19pXyArIF9faiksIF9feS5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KICAgIGZvciAoc2l6ZV90IF9faiA9IF9feC5fX2lfICsgMTsgX19qIDwgX1I7ICsrX19qKQogICAgICAgIF9fb3MgPDwgX19zcCA8PCBfX3guX194X1tfX2pdOwogICAgZm9yIChzaXplX3QgX19qID0gMDsgX19qIDwgX194Ll9faV87ICsrX19qKQogICAgICAgIF9fb3MgPDwgX19zcCA8PCBfX3guX194X1tfX2pdOwogICAgX19vcyA8PCBfX3NwIDw8IF9feC5fX2NfOwogICAgcmV0dXJuIF9fb3M7Cn0KCnRlbXBsYXRlIDxjbGFzcyBfQ2hhclQsIGNsYXNzIF9UcmFpdHMsCiAgICAgICAgICBjbGFzcyBfVUksIHNpemVfdCBfVywgc2l6ZV90IF9TLCBzaXplX3QgX1I+CmJhc2ljX2lzdHJlYW08X0NoYXJULCBfVHJhaXRzPiYKb3BlcmF0b3I+PihiYXNpY19pc3RyZWFtPF9DaGFyVCwgX1RyYWl0cz4mIF9faXMsCiAgICAgICAgICAgc3VidHJhY3Rfd2l0aF9jYXJyeV9lbmdpbmU8X1VJLCBfVywgX1MsIF9SPiYgX194KQp7CiAgICBfX3NhdmVfZmxhZ3M8X0NoYXJULCBfVHJhaXRzPiBfKF9faXMpOwogICAgX19pcy5mbGFncyhpb3NfYmFzZTo6ZGVjIHwgaW9zX2Jhc2U6OnNraXB3cyk7CiAgICBfVUkgX190W19SKzFdOwogICAgZm9yIChzaXplX3QgX19pID0gMDsgX19pIDwgX1IrMTsgKytfX2kpCiAgICAgICAgX19pcyA+PiBfX3RbX19pXTsKICAgIGlmICghX19pcy5mYWlsKCkpCiAgICB7CiAgICAgICAgZm9yIChzaXplX3QgX19pID0gMDsgX19pIDwgX1I7ICsrX19pKQogICAgICAgICAgICBfX3guX194X1tfX2ldID0gX190W19faV07CiAgICAgICAgX194Ll9fY18gPSBfX3RbX1JdOwogICAgICAgIF9feC5fX2lfID0gMDsKICAgIH0KICAgIHJldHVybiBfX2lzOwp9Cgp0eXBlZGVmIHN1YnRyYWN0X3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RzOwogICAgc3RhdGljIGNvbnN0IHNpemVfdCBfRUR0ID0gbnVtZXJpY19saW1pdHM8X0VuZ2luZV9yZXN1bHRfdHlwZT46OmRpZ2l0czsKICAgIHN0YXRpYyBjb25zdCBfV29ya2luZ19yZXN1bHRfdHlwZSBfX3kwID0gX193MCA+PSBfV0R0ID8gMCA6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChfUiA+PiBfX3cwKSA8PCBfX3cwOwogICAgc3RhdGljIGNvbnN0IF9Xb3JraW5nX3Jlc3VsdF90eXBlIF9feTEgPSBfX3cwID49IF9XRHQgLSAxID8gMCA6CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChfUiA+PiAoX193MCsxKSkgPDwgKF9fdzArMSk7CiAgICBzdGF0aWMgY29uc3QgX0VuZ2luZV9yZXN1bHRfdHlwZSBfX21hc2swID0gX193MCA+IDAgPwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9FbmdpbmVfcmVzdWx0X3R5cGUofjApID4+IChfRUR0IC0gX193MCkgOgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9FbmdpbmVfcmVzdWx0X3R5cGUoMCk7CiAgICBzdGF0aWMgY29uc3QgX0VuZ2luZV9yZXN1bHRfdHlwZSBfX21hc2sxID0gX193MCA8IF9FRHQgLSAxID8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfRW5naW5lX3Jlc3VsdF90eXBlKH4wKSA+PiAoX0VEdCAtIChfX3cwICsgMSkpIDoKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfRW5naW5lX3Jlc3VsdF90eXBlKH4wKTsKcHVibGljOgogICAgc3RhdGljIGNvbnN0IHJlc3VsdF90eXBlIF9NaW4gPSAwOwogICAgc3RhdGljIGNvbnN0IHJlc3VsdF90eXBlIF9NYXggPSBfX3cgPT0gX0R0ID8gcmVzdWx0X3R5cGUofjApIDoKIC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FyVCwgX1RyYWl0cz4mIF9fb3MsCiAgICAgICAgICAgICAgIGNvbnN0IGluZGVwZW5kZW50X2JpdHNfZW5naW5lPF9FbmcsIF9XLCBfVUk+JiBfX3gpOwogICAgCiAgICB0ZW1wbGF0ZSA8Y2xhc3MgX0NoYXJULCBjbGFzcyBfVHJhaXRzLAogICAgICAgICAgICAgIGNsYXNzIF9FbmcsIHNpemVfdCBfVywgY2xhc3MgX1VJPgogICAgZnJpZW5kCiAgICBiYXNpY19pc3RyZWFtPF9DaGFyVCwgX1RyYWl0cz4mCiAgICBvcGVyYXRvcj4+KGJhc2ljX2lzdHJlYW08X0NoYXJULCBfVHJhaXRzPiYgX19pcywKICAgICAgICAgICAgICAgaW5kZXBlbmRlbnRfYml0c19lbmdpbmU8X0VuZywgX1csIF9VST4mIF9feCk7Cgpwcml2YXRlOgogICAgcmVzdWx0X3R5cGUgX19ldmFsKGZhbHNlX3R5cGUpOwogICAgcmVzdWx0X3R5cGUgX19ldmFsKHRydWVfdHlwZSk7CgogICAgdGVtcGxhdGUgPHNpemVfdCBfX2NvdW50PgogICAgICAgIHN0YXRpYwogICAgICAgIHR5cGVuYW1lIGVuYWJsZV9pZgogICAgICAgIDwKICAgICAgICAgICAgX19jb3VudCA8IF9EdCwKICAgICAgICAgICAgcmVzdWx0X3R5cGUKICAgICAgICA+Ojp0eXBlCiAgICAgICAgX19sc2hpZnQocmVzdWx0X3R5cGUgX194KSB7cmV0dXJuIF9feCA8PCBfX2NvdW50O30KCiAgICB0ZW1wbGF0ZSA8c2l6ZV90IF9fY291bnQ+CiAgICAgICAgc3RhdGljCiAgICAgICAgdHlwZW5hbWUgZW5hYmxlX2lmCiAgICAgICAgPAogICAgICAgICAgICAoX19jb3VudCA+PSBfRHQpLAogICAgICAgICAgICByZXN1bHRfdHlwZQogICAgICAgID46OnR5cGUKICAgICAgICBfX2xzaGlmdChyZXN1bHRfdHlwZSBfX3gpIHtyZXR1cm4gcmVzdWx0X3R5cGUoMCk7fQp9OwoKdGVtcGxhdGU8Y2xhc3MgX0VuZ2luZSwgc2l6ZV90IF9fdywgY2xhc3MgX1VJbnRUeXBlPgppbmxpbmUKX1VJbnRUeXBlCmluZGVwZW5kZW50X2JpdHNfZW5naW5lPF9FbmdpbmUsIF9fdywgX1VJbnRUeXBlPjo6X19ldmFsKGZhbHNlX3R5cGUpCnsKICAgIHJldHVybiBzdGF0aWNfY2FzdDxyZXN1bHRfdHlwZT4oX19lXygpICYgX19tYXNrMCk7Cn0KCnRlbXBsYXRlPGNsYXNzIF9FbmdpbmUsIHNpemVfdCBfX3csIGNsYXNzIF9VSW50VHlwZT4KX1VJbnRUeXBlCmluZGVwZW5kZW50X2JpdHNfZW5naW5lPF9FbmdpbmUsIF9fdywgX1VJbnRUeXBlPjo6X19ldmFsKHRydWVfdHlwZSkKewogICAgcmVzdWx0X3R5cGUgX1MgPSAwOwogICAgZm9yIChzaXplX3QgX19rID0gMDsgX19rIDwgX19uMDsgKytfX2spCiAgICB7CiAgICAgICAgX0VuZ2luZV9yZXN1bHRfdHlwZSBfX3U7CiAgICAgICAgZG8KICAgICAgICB7CiAgICAgICAgICAgIF9fdSA9IF9fZV8oKSAtIF9FbmdpbmU6Om1pbigpOwogICAgICAgIH0gd2hpbGUgKF9fdSA+PSBfX3kwKTsKICAgICAgICBfUyA9IHN0YXRpY19jYXN0PHJlc3VsdF90eXBlPihfX2xzaGlmdDxfX3cwPihfUykgKyAoX191ICYgX19tYXNrMCkpOwogICAgfQogICAgZm9yIChzaXplX3QgX19rID0gX19uMDsgX19rIDwgX19uOyArK19faykKICAgIHsKICAgICAgICBfRW5naW5lX3Jlc3VsdF90eXBlIF9fdTsKICAgICAgICBkbwogICAgICAgIHsKICAgICAgICAgICAgX191ID0gX19lXygpIC0gX0VuZ2luZTo6bWluKCk7CiAgICAgICAgfSB3aGlsZSAoX191ID49IF9feTEpOwogICAgICAgIF9TID0gc3RhdGljX2Nhc3Q8cmVzdWx0X3R5cGU+KF9fbHNoaWZ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AgIH0KCiAgICByZXN1bHRfdHlwZSBfX2V2YWwoZmFsc2VfdHlwZSkge3JldHVybiBfX2V2YWwyKGludGVncmFsX2NvbnN0YW50PGJvb2wsIF9fayAmIDE+KCkpO30KICAgIHJlc3VsdF90eXBlIF9fZXZhbCh0cnVlX3R5cGUpIHtyZXR1cm4gX19ldmFsKF9fdXJhdGlvPF9faywgX1I+KCkpO30KCiAgICByZXN1bHRfdHlwZSBfX2V2YWwyKGZhbHNlX3R5cGUpIHtyZXR1cm4gX19ldmFsKF9fdXJhdGlvPF9fay8yLCAweDgwMDAwMDAwMDAwMDAwMDB1bGw+KCkpO30KICAgIHJlc3VsdF90eXBlIF9fZXZhbDIodHJ1ZV90eXBlKSB7cmV0dXJuIF9fZXZhbGY8X19rLCAwPigpO30KCiAgICB0ZW1wbGF0ZSA8dWludDY0X3QgX04sIHVpbnQ2NF90IF9EPgogICAgICAgIHR5cGVuYW1lIGVuYWJsZV9pZgogICAgICAgIDwKICAgICAgICAgICAgKF9fdXJhdGlvPF9OLCBfRD46Om51bSA+IDB4RkZGRkZGRkZGRkZGRkZGRnVsbCAvIChfTWF4IC0gX01pbikpLAogICAgICAgICAgICByZXN1bHRfdHlwZQogICAgICAgID46OnR5cGUKICAgICAgICBfX2V2YWwoX191cmF0aW88X04sIF9EPikKICAgICAgICAgICAge3JldHVybiBfX2V2YWxmPF9fdXJhdGlvPF9OLCBfRD46Om51bSwgX191cmF0aW88X04sIF9EPjo6ZGVuPigpO30KCiAgICB0ZW1wbGF0ZSA8dWludDY0X3QgX04sIHVpbnQ2NF90IF9EPgogICAgICAgIHR5cGVuYW1lIGVuYWJsZV9pZgogICAgICAgIDwKICAgICAgICAgICAgX191cmF0aW88X04sIF9EPjo6bnVtIDw9IDB4RkZGRkZGRkZGRkZGRkZGRnVsbCAvIChfTWF4IC0gX01pbiksCiAgICAgICAgICAgIHJlc3VsdF90eXBlCiAgICAgICAgPjo6dHlwZQogICAgICAgIF9fZXZhbChfX3VyYXRpbzxfTiwgX0Q+KQogICAgICAgIHsKICAgICAgICAgICAgY29uc3Qgc2l6ZV90IF9faiA9IHN0YXRpY19jYXN0PHNpemVfdD4oX191cmF0aW88X04sIF9EPjo6bnVtICogKF9ZXyAtIF9NaW4pCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8gX191cmF0aW88X04sIF9EPjo6ZGVuKTsKICAgICAgICAgICAgX1lfID0gX1ZfW19fal07CiAgICAgICAgICAgIF9WX1tfX2pdID0gX19lXygpOwogICAgICAgICAgICByZXR1cm4gX1lfOwogICAgICAgIH0KCiAgICB0ZW1wbGF0ZSA8dWludDY0X3QgX19uLCB1aW50NjRfdCBfX2Q+CiAgICAgICAgcmVzdWx0X3R5cGUgX19ldmFsZigpCiAgICAgICAgewogICAgICAgICAgICBjb25zdCBkb3VibGUgX0YgPSBfX2QgPT0gMCA/CiAgICAgICAgICAgICAgICBfX24gLyAoMi4gKiAweDgwMDAwMDAwMDAwMDAwMDB1bGwpIDoKICAgICAgICAgICAgICAgIF9fbiAvIChkb3VibGUpX19kOwogICAgICAgICAgICBjb25zdCBzaXplX3QgX19qID0gc3RhdGljX2Nhc3Q8c2l6ZV90PihfRiAqIChfWV8gLSBfTWluKSk7CiAgICAgICAgICAgIF9ZXyA9IF9WX1tfX2pdOwogICAgICAgICAgICBfVl9bX19qXSA9IF9fZV8oKTsKICAgICAgICAgICAgcmV0dXJuIF9ZXzsKICAgICAgICB9Cn07Cgp0ZW1wbGF0ZTxjbGFzcyBfRW5nLCBzaXplX3QgX0s+CmJvb2wKb3BlcmF0b3I9PSgKICAgIGNvbnN0IHNodWZmbGVfb3JkZXJfZW5naW5lPF9FbmcsIF9LPiYgX194LAogICAgY29uc3Qgc2h1ZmZsZV9vcmRlcl9lbmdpbmU8X0VuZywgX0s+JiBfX3kpCnsKICAgIHJldHVybiBfX3guX1lfID09IF9feS5fWV8gJiYgX1NURDo6ZXF1YWwoX194Ll9WXywgX194Ll9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AoX19uIC0gX190KSAvIDI7CiAgICAgICAgY29uc3Qgc2l6ZV90IF9fcSA9IF9fcCArIF9fdDsKICAgICAgICBjb25zdCBzaXplX3QgX19tID0gX1NURDo6bWF4KF9fcyArIDEsIF9fbik7CiAgICAgICAgLy8gX19rID0gMDsKICAgICAgICB7CiAgICAgICAgICAgIHJlc3VsdF90eXBlIF9fciA9IDE2NjQ1MjUgKiBfVChfX2ZpcnN0WzBdIF4gX19maXJzdFtfX3BdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF4gIF9fZmlyc3RbX19uIC0gMV0pOwogICAgICAgICAgICBfX2ZpcnN0W19fcF0gKz0gX19yOwogICAgICAgICAgICBfX3IgKz0gX19zOwogICAgICAgICAgICBfX2ZpcnN0W19fcV0gKz0gX19yOwogICAgICAgICAgICBfX2ZpcnN0WzBdID0gX19yOwogICAgICAgIH0KICAgICAgICBmb3IgKHNpemVfdCBfX2sgPSAxOyBfX2sgPD0gX19zOyArK19faykKICAgICAgICB7CiAgICAgICAgICAgIGNvbnN0IHNpemVfdCBfX2ttb2RuID0gX19rICUgX19uOwogICAgICAgICAgICBjb25zdCBzaXplX3QgX19rcG1vZG4gPSAoX19rICsgX19wKSAlIF9fbjsKICAgICAgICAgICAgcmVzdWx0X3R5cGUgX19yID0gMTY2NDUyNSAqIF9UKF9fZmlyc3RbX19rbW9kbl0gXiBfX2ZpcnN0W19fa3Btb2RuXQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXiBfX2ZpcnN0WyhfX2sgLSAxKSAlIF9fbl0pOwogICAgICAgICAgICBfX2ZpcnN0W19fa3Btb2RuXSArPSBfX3I7CiAgICAgICAgICAgIF9fciArPSAgX19rbW9kbiArIF9fdl9bX19rLTFdOwogICAgICAgICAgICBfX2ZpcnN0WyhfX2sgKyBfX3EpICUgX19uXSArPSBfX3I7CiAgICAgICAgICAgIF9fZmlyc3RbX19rbW9kbl0gPSBfX3I7CiAgICAgICAgfQogICAgICAgIGZvciAoc2l6ZV90IF9fayA9IF9fcyArIDE7IF9fayA8IF9fbTsgKytfX2spCiAgICAgICAgewogICAgICAgICAgICBjb25zdCBzaXplX3QgX19rbW9kbiA9IF9fayAlIF9fbjsKICAgICAgICAgICAgY29uc3Qgc2l6ZV90IF9fa3Btb2RuID0gKF9fayArIF9fcCkgJSBfX247CiAgICAgICAgICAgIHJlc3VsdF90eXBlIF9fciA9IDE2NjQ1MjUgKiBfVChfX2ZpcnN0W19fa21vZG5dIF4gX19maXJzdFtfX2twbW9kbl0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF4gX19maXJzdFsoX19rIC0gMSkgJSBfX25dKTsKICAgICAgICAgICAgX19maXJzdFtfX2twbW9kbl0gKz0gX19yOwogICAgICAgICAgICBfX3IgKz0gIF9fa21vZG47CiAgICAgICAgICAgIF9fZmlyc3RbKF9fayArIF9fcSkgJSBfX25dICs9IF9fcjsKICAgICAgICAgICAgX19maXJzdFtfX2ttb2RuXSA9IF9fcjsKICAgICAgICB9CiAgICAgICAgZm9yIChzaXplX3QgX19rID0gX19tOyBfX2sgPCBfX20gKyBfX247ICsrX19rKQogICAgICAgIHsKICAgICAgICAgICAgY29uc3Qgc2l6ZV90IF9fa21vZG4gPSBfX2sgJSBfX247CiAgICAgICAgICAgIGNvbnN0IHNpemVfdCBfX2twbW9kbiA9IChfX2sgKyBfX3ApICUgX19uOwogICAgICAgICAgICByZXN1bHRfdHlwZSBfX3IgPSAxNTY2MDgzOTQxICogX1QoX19maXJzdFtfX2ttb2RuXSArCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2ZpcnN0W19fa3Btb2RuXSArCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2ZpcnN0WyhfX2sgLSAxKSAlIF9fbl0pOwogICAgICAgICAgICBfX2ZpcnN0W19fa3Btb2RuXS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KICAgICAgICBfX3kwXyA9IDA7CiAgICBpZiAoX1IgLSBfX3kwXyA+IF9feTBfIC8gX19uXykKICAgIHsKICAgICAgICArK19fbl87CiAgICAgICAgX193MF8gPSBfX3dfIC8gX19uXzsKICAgICAgICBpZiAoX193MF8gPCBfV0R0KQogICAgICAgICAgICBfX3kwXyA9IChfUiA+PiBfX3cwXykgPDwgX193MF87CiAgICAgICAgZWxzZQogICAgICAgICAgICBfX3kwXyA9IDA7CiAgICB9CiAgICBfX24wXyA9IF9fbl8gLSBfX3dfICUgX19uXzsKICAgIGlmIChfX3cwXyA8IF9XRHQgLSAxKQogICAgICAgIF9feTFfID0gKF9SID4+IChfX3cwXyArIDEpKSA8PCAoX193MF8gKyAxKTsKICAgIGVsc2UKICAgICAgICBfX3kxXyA9IDA7CiAgICBfX21hc2swXyA9IF9fdzBfID4gMCA/IF9FbmdpbmVfcmVzdWx0X3R5cGUofjApID4+IChfRUR0IC0gX193MF8pIDoKICAgICAgICAgICAgICAgICAgICAgICAgICBfRW5naW5lX3Jlc3VsdF90eXBlKDApOwogICAgX19tYXNrMV8gPSBfX3cwXyA8IF9FRHQgLSAxID8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9FbmdpbmVfcmVzdWx0X3R5cGUofjApID4+IChfRUR0IC0gKF9fdzBfICsgMSkpIDoKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9FbmdpbmVfcmVzdWx0X3R5cGUofjApOwp9Cgp0ZW1wbGF0ZTxjbGFzcyBfRW5naW5lLCBjbGFzcyBfVUludFR5cGU+CmlubGluZQpfVUludFR5cGUKX19pbmRlcGVuZGVudF9iaXRzX2VuZ2luZTxfRW5naW5lLCBfVUludFR5cGU+OjpfX2V2YWwoZmFsc2VfdHlwZSkKewogICAgcmV0dXJuIHN0YXRpY19jYXN0PHJlc3VsdF90eXBlPihfX2VfKCkgJiBfX21hc2swXyk7Cn0KCnRlbXBsYXRlPGNsYXNzIF9FbmdpbmUsIGNsYXNzIF9VSW50VHlwZT4KX1VJbnRUeXBlCl9faW5kZXBlbmRlbnRfYml0c19lbmdpbmU8X0VuZ2luZSwgX1VJbnRUeXBlPjo6X19ldmFsKHRydWVfdHlwZSkKewogICAgcmVzdWx0X3R5cGUgX1MgPSAwOwogICAgZm9yIChzaXplX3QgX19rID0gMDsgX19rIDwgX19uMF87ICsrX19rKQogICAgewogICAgICAgIF9FbmdpbmVfcmVzdWx0X3R5cGUgX191OwogICAgICAgIGRvCiAgICAgICAgewogICAgICAgICAgICBfX3UgPSBfX2VfKCkgLSBfRW5naW5lOjptaW4oKTsKICAgICAgICB9IHdoaWxlIChfX3UgPj0gX195MF8pOwogICAgICAgIGlmIChfX3cwXyA8IF9FRHQpCiAgICAgICAgICAgIF9TIDw8PSBfX3cwXzsKICAgICAgICBlbHNlCiAgICAgICAgICAgIF9TID0gMDsKICAgICAgICBfUyArPSBfX3UgJiBfX21hc2swXzsKICAgIH0KICAgIGZvciAoc2l6ZV90IF9fayA9IF9fbjBfOyBfX2sgPCBfX25fOyArK19faykKICAgIHsKICAgICAgICBfRW5naW5lX3Jlc3VsdF90eXBlIF9fdTsKICAgICAgICBkbwogICAgICAgIHsKICAgICAgICAgICAgX191ID0gX19lXygpIC0gX0VuZ2luZTo6bWluKCk7CiAgICAgICAgfSB3aGlsZSAoX191ID49IF9feTFfKTsKICAgICAgICBpZiAoX193MF8gPCBfRUR0IC0gMSkKICAgICAgICAgICAgX1MgPDw9IF9fdzBfICsgMTsKICAgICAgICBlbHNlCiAgICAgICAgICAgIF9TID0gMDsKICAgICAgICBfUyArPSBfX3UgJiBfX21hc2sxXzsKICAgIH0KICAgIHJldHVybiBfUzsKfQoKdGVtcGxhdGU8Y2xhc3MgX0ludFR5cGUgPSBpbnQ+CmNsYXNzIHVuaWZvcm1faW50X2Rpc3RyaWJ1dGlvbgp7CnB1YmxpYzoKICAgIC8vIHR5cGVzCiAgICB0eXBlZGVmIF9JbnRUeXBlIHJlc3VsdF90eXBlOwoKICAgIGNsYXNzIHBhcmFtX3R5cGUKICAgIHsKICAgICAgICByZXN1bHRfdHlwZSBfX2FfOwogICAgICAgIHJlc3VsdF90eXBlIF9fYl87CiAgICBwdWJsaWM6CiAgICAgICAgdHlwZWRlZiB1bmlmb3JtX2ludF9kaXN0cmlidXRpb24gZGlzdHJpYnV0aW9uX3R5cGU7CgogICAgICAgIGV4cGxpY2l0IHBhcmFtX3R5cGUocmVzdWx0X3R5cGUgX19hID0gMCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdF90eXBlIF9fYiA9IG51bWVyaWNfbGltaXRzPHJlc3VsdF90eXBlPjo6bWF4KCkpCiAgICAgICAgICAgIDogX19hXyhfX2EpLCBfX2JfKF9fYikge30KCiAgICAgICAgcmVzdWx0X3R5cGUgYSgpIGNvbnN0IHtyZXR1cm4gX19hXzt9CiAgICAgICAgcmVzdWx0X3R5cGUgYigpIGNvbnN0IHtyZXR1cm4gX19iXzt9CgogICAgICAgIGZyaWVuZCBib29sIG9wZXJhdG9yPT0oY29uc3QgcGFyYW1fdHlwZSYgX194LCBjb25zdCBwYXJhbV90eXBlJiBfX3kpCiAgICAgICAgICAgIHtyZXR1cm4gX194Ll9fYV8gPT0gX195Ll9fYV8gJiYgX194Ll9fYl8gPT0gX195Ll9fYl87fQogICAgICAgIGZyaWVuZCBib29sIG9wZXJhdG9yIT0oY29uc3QgcGFyYW1fdHlwZSYgX194LCBjb25zdCBwYXJhbV90eXBlJiBfX3kpCiAgICAgICAgICAgIHtyZXR1cm4gIShfX3ggPT0gX195KTt9CiAgICB9OwoKcHJpdmF0ZToKICAgIHBhcmFtX3R5cGUgX19wXzsKCnB1YmxpYzoKICAgIC8vIGNvbnN0cnVjdG9ycyBhbmQgcmVzZXQgZnVuY3Rpb25zCiAgICBleHBsaWNpdCB1bmlmb3JtX2ludF9kaXN0cmlidXRpb24ocmVzdWx0X3R5cGUgX19hID0gMCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC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