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ogICAgICAgICAgICBpbnN0YWxsKG5ldyBtb25leXB1bmN0X2J5bmFtZTxjaGFyLCB0cnVlPihuYW1lKSk7CiAgICAgICAgICAgIGluc3RhbGwobmV3IG1vbmV5cHVuY3RfYnluYW1lPHdjaGFyX3QsIGZhbHNlPihuYW1lKSk7CiAgICAgICAgICAgIGluc3RhbGwobmV3IG1vbmV5cHVuY3RfYnluYW1lPHdjaGFyX3QsIHRydWU+KG5hbWUpKTsKICAgICAgICB9CiAgICAgICAgaWYgKGMgJiBsb2NhbGU6Om51bWVyaWMpCiAgICAgICAgewogICAgICAgICAgICBpbnN0YWxsKG5ldyBudW1wdW5jdF9ieW5hbWU8Y2hhcj4obmFtZSkpOwogICAgICAgICAgICBpbnN0YWxsKG5ldyBudW1wdW5jdF9ieW5hbWU8d2NoYXJfdD4obmFtZSkpOwogICAgICAgIH0KICAgICAgICBpZiAoYyAmIGxvY2FsZTo6dGltZSkKICAgICAgICB7CiAgICAgICAgICAgIGluc3RhbGwobmV3IHRpbWVfZ2V0X2J5bmFtZTxjaGFyPihuYW1lKSk7CiAgICAgICAgICAgIGluc3RhbGwobmV3IHRpbWVfZ2V0X2J5bmFtZTx3Y2hhcl90PihuYW1lKSk7CiAgICAgICAgICAgIGluc3RhbGwobmV3IHRpbWVfcHV0X2J5bmFtZTxjaGFyPihuYW1lKSk7CiAgICAgICAgICAgIGluc3RhbGwobmV3IHRpbWVfcHV0X2J5bmFtZTx3Y2hhcl90PihuYW1lKSk7CiAgICAgICAgfQogICAgICAgIGlmIChjICYgbG9jYWxlOjptZXNzYWdlcykKICAgICAgICB7CiAgICAgICAgICAgIGluc3RhbGwobmV3IG1lc3NhZ2VzX2J5bmFtZTxjaGFyPihuYW1lKSk7CiAgICAgICAgICAgIGluc3RhbGwobmV3IG1lc3NhZ2VzX2J5bmFtZTx3Y2hhcl90PihuYW1lKSk7CiAgICAgICAgfQogICAgfQogICAgY2F0Y2ggKC4uLikKICAgIHsKICAgICAgICBmb3IgKHVuc2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gICAgICAgIGlmIChpc3djbnRybF9sKCpsb3csIF9fbCkpCiAgICAgICAgICAgICAgICAqdmVjIHw9IGNudHJsOwogICAgICAgICAgICBpZiAoaXN3dXBwZXJfbCgqbG93LCBfX2wpKQogICAgICAgICAgICAgICAgKnZlYyB8PSB1cHBlcjsKICAgICAgICAgICAgaWYgKGlzd2xvd2VyX2woKmxvdywgX19sKSkKICAgICAgICAgICAgICAgICp2ZWMgfD0gbG93ZXI7CiAgICAgICAgICAgIGlmIChpc3dhbHBoYV9sKCpsb3csIF9fbCkpCiAgICAgICAgICAgICAgICAqdmVjIHw9IGFscGhhOwogICAgICAgICAgICBpZiAoaXN3ZGlnaXRfbCgqbG93LCBfX2wpKQogICAgICAgICAgICAgICAgKnZlYyB8PSBkaWdpdDsKICAgICAgICAgICAgaWYgKGlzd3B1bmN0X2woKmxvdywgX19sKSkKICAgICAgICAgICAgICAgICp2ZWMgfD0gcHVuY3Q7CiAgICAgICAgICAgIGlmIChpc3d4ZGlnaXRfbCgqbG93LCBfX2wpKQogICAgICAgICAgICAgICAgKnZlYyB8PSB4ZGlnaXQ7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGxvdzsKfQoKY29uc3Qgd2NoYXJfdCoKY3R5cGVfYnluYW1lPHdjaGFyX3Q+Ojpkb19zY2FuX2lzKG1hc2sgbSwgY29uc3QgY2hhcl90eXBlKiBsb3csIGNvbnN0IGNoYXJfdHlwZSogaGlnaCkgY29uc3QKewogICAgZm9yICg7IGxvdyAhPSBoaWdoOyArK2xvdykKICAgICAgICBpZiAoaXN3Y3R5cGVfbCgqbG93LCBtLCBfX2wpKQogICAgICAgICAgICBicmVhazsKICAgIHJldHVybiBsb3c7Cn0KCmNvbnN0IHdjaGFyX3QqCmN0eXBlX2J5bmFtZTx3Y2hhcl90Pjo6ZG9fc2Nhbl9ub3QobWFzayBtLCBjb25zdCBjaGFyX3R5cGUqIGxvdywgY29uc3QgY2hhcl90eXBlKiBoaWdoKSBjb25zdAp7C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Vfc3RhdGUgPSBzdDsKICAgICAgICBzaXplX3QgbiA9IHdjc25ydG9tYnNfbCh0bywgJmZybV9ueHQsIGZlbmQtZnJtLCB0b19lbmQtdG8sICZzdCwgX19sKTsKICAgICAgICBpZiAobiA9PSBzaXplX3QoLTEpKQogICAgICAgIHsKICAgICAgICAgICAgLy8gbmVlZCB0byByZWNvdmVyIHRvX254dAogICAgICAgICAgICBmb3IgKHRvX254dCA9IHRvOyBmcm0gIT0gZnJtX254dDsgKytmcm0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIG4gPSB3Y3J0b21iX2wodG9fbnh0LCAqZnJtLCAmc2F2ZV9zdGF0ZSwgX19sKTsKICAgICAgICAgICAgICAgIGlmIChuID09IHNpemVfdCgtMSkpCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB0b19ueHQgKz0gbjsKICAgICAgICAgICAgfQogICAgICAgICAgICBmcm1fbnh0ID0gZnJtOwogICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgfQogICAgICAgIGlmIChuID09IDApCiAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgIHRvX254dCArPSBuOwogICAgICAgIGlmICh0b19ueHQgPT0gdG9fZW5kKQogICAgICAgICAgICBicmVhazsKICAgICAgICBpZiAoZmVuZCAhPSBmcm1fZW5kKSAgLy8gc2V0IHVwIG5leHQgbnVsbCB0ZXJtaW5hdGVkIHNlcXVlbmNlCiAgICAgICAgewogICAgICAgICAgICAvLyBUcnkgdG8gd3JpdGUgdGhlIHRlcm1pbmF0aW5nIG51bGwKICAgICAgICAgICAgZXh0ZXJuX3R5cGUgdG1wW01CX0xFTl9NQVhdOwogICAgICAgICAgICBuID0gd2NydG9tYl9sKHRtcCwgaW50ZXJuX3R5cGUoKSwgJnN0LCBfX2wpOwogICAgICAgICAgICBpZiAobiA9PSBzaXplX3QoLTEpKSAgLy8gb24gZXJyb3IKICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgaWYgKG4gPiB0b19lbmQtdG9fbnh0KSAgLy8gaXMgdGhlcmUgcm9vbT8KICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICBmb3IgKGV4dGVybl90eXBlKiBwID0gdG1wOyBuOyAtLW4pICAvLyB3cml0ZSBpdAogICAgICAgICAgICAgICAgKnRvX254dCsrID0gKnArKzsKICAgICAgICAgICAgKytmcm1fbnh0OwogICAgICAgICAgICAvLyBsb29rIGZvciBuZXh0IG51bGwgaW4gZnJtCiAgICAgICAgICAgIGZvciAoZmVuZCA9IGZybV9ueHQ7IGZlbmQgIT0gZnJtX2VuZDsgKytmZW5kKQogICAgICAgICAgICAgICAgaWYgKCpmZW5kID09IDApCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGZybV9ueHQgPT0gZnJtX2VuZCA/IG9rIDogcGFydGlhbDsKfQoKY29kZWN2dDx3Y2hhcl90LCBjaGFyLCBtYnN0YXRlX3Q+OjpyZXN1bHQKY29kZWN2dDx3Y2hhcl90LCBjaGFyLCBtYnN0YXRlX3Q+Ojpkb19pbihzdGF0ZV90eXBlJiBzdCwKICAgIGNvbnN0IGV4dGVybl90eXBlKiBmcm0sIGNvbnN0IGV4dGVybl90eXBlKiBmcm1fZW5kLCBjb25zdCBleHRlcm5fdHlwZSomIGZybV9ueHQsIAogICAgaW50ZXJuX3R5cGUqIHRvLCBpbnRlcm5fdHlwZSogdG9fZW5kLCBpbnRlcm5fdHlwZSomIHRvX254dCkgY29uc3QKewogICAgLy8gbG9vayBmb3IgZmlyc3QgaW50ZXJuYWwgbnVsbCBpbiBmcm0KICAgIGNvbnN0IGV4dGVybl90eXBlKiBmZW5kID0gZnJtOwogICAgZm9yICg7IGZlbmQgIT0gZnJtX2VuZDsgKytmZW5kKQogICAgICAgIGlmICgqZmVuZCA9PSAwKQogICAgICAgICAgICBicmVhazsKICAgIC8vIGxvb3Agb3ZlciBhbGwgbnVsbC10ZXJtaW5hdGVkIHNlcXVlbmNlcyBpbiBmcm0KICAgIHRvX254dCA9IHRvOwogICAgZm9yIChmcm1fbnh0ID0gZnJtOyBmcm0gIT0gZnJtX2VuZCAmJiB0byAhPSB0b19lbmQ7IGZybSA9IGZybV9ueHQsIHRvID0gdG9fbnh0KQogICAgewogICAgICAgIC8vIHNhdmUgc3RhdGUgaW4gY2FzZSBuZWVkZWQgdG8gcmVvdmVyIHRvX254dCBvbiBlcnJvcgogICAgICAgIG1ic3RhdGVfdCBzYXZlX3N0YXRlID0gc3Q7CiAgICAgICAgc2l6ZV90IG4gPSBtYnNucnRvd2NzX2wodG8sICZmcm1fbnh0LCBmZW5kLWZybSwgdG9fZW5kLXRvLCAmc3QsIF9fbCk7CiAgICAgICAgaWYgKG4gPT0gc2l6ZV90KC0xKSkKICAgICAgICB7CiAgICAgICAgICAgIC8vIG5lZWQgdG8gcmVjb3ZlciB0b19ueHQKICAgICAgICAgICAgZm9yICh0b19ueHQgPSB0bzsgZnJtICE9IGZybV9ueHQ7ICsrdG9fbnh0KQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBuID0gbWJydG93Y19sKHRvX254dCwgZnJtLCBmZW5kLWZybSwgJnNhdmVfc3RhdGUsIF9fbCk7CiAgICAgICAgICAgICAgICBzd2l0Y2ggKG4pCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgKytmcm07CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIC0xOgogICAgICAgICAgICAgICAgICAgIGZybV9ueHQgPSBmcm07CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGVycm9yOwogICAgICAgICAgICAgICAgY2FzZSAtMjoKICAgICAgICAgICAgICAgICAgICBmcm1fbnh0ID0gZnJtOwogICAgICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgICAgICBmcm0gKz0gbjsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBmcm1fbnh0ID0gZnJtOwogICAgICAgICAgICByZXR1cm4gZnJtX254dCA9PSBmcm1fZW5kID8gb2sgOiBwYXJ0aWFsOwogICAgICAgIH0KICAgICAgICBpZiAobiA9PSAwKQogICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgdG9fbnh0ICs9IG47CiAgICAgICAgaWYgKHRvX254dCA9PSB0b19lbmQpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGlmIChmZW5kICE9IGZybV9lbmQpICAvLyBzZXQgdXAgbmV4dCBudWxsIHRlcm1pbmF0ZWQgc2VxdWVuY2UKICAgICAgICB7CiAgICAgICAgICAgIC8vIFRyeSB0byB3cml0ZSB0aGUgdGVybWluYXRpbmcgbnVsbAogICAgICAgICAgICBuID0gbWJydG93Y19sKHRvX254dCwgZnJtX254dCwgMSwgJnN0LCBfX2wpOwogICAgICAgICAgICBpZiAobiAhPSAwKSAgLy8gb24gZXJyb3IKICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgKyt0b19ueHQ7CiAgICAgICAgICAgICsrZnJtX254dDsKICAgICAgICAgICAgLy8gbG9vayBmb3IgbmV4dCBudWxsIGluIGZybQogICAgICAgICAgICBmb3IgKGZlbmQgPSBmcm1fbnh0OyBmZW5kICE9IGZybV9lbmQ7ICsrZmVuZCkKICAgICAgICAgICAgICAgIGlmICgqZmVuZCA9PSAwKQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBmcm1fbnh0ID09IGZybV9lbmQgPyBvayA6IHBhcnRpYWw7Cn0KCmNvZGVjdnQ8d2NoYXJfdCwgY2hhciwgbWJzdGF0ZV90Pjo6cmVzdWx0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AgICAgICAgIHJldHVybiAwOwogICAgfQogICAgcmV0dXJuIC0xOwp9Cgpib29sCmNvZGVjdnQ8d2NoYXJfdCwgY2hhciwgbWJzdGF0ZV90Pjo6ZG9fYWx3YXlzX25vY29udigpIGNvbnN0IHRocm93KCkKewogICAgcmV0dXJuIGZhbHNlOwp9CgppbnQKY29kZWN2dDx3Y2hhcl90LCBjaGFyLCBtYnN0YXRlX3Q+Ojpkb19sZW5ndGgoc3RhdGVfdHlwZSYgc3QsCiAgICBjb25zdCBleHRlcm5fdHlwZSogZnJtLCBjb25zdCBleHRlcm5fdHlwZSogZnJtX2VuZCwgc2l6ZV90IG14KSBjb25zdAp7CiAgICBpbnQgbmJ5dGVzID0gMDsKICAgIGZvciAoc2l6ZV90IG53Y2hhcl90ID0gMDsgbndjaGFyX3QgPCBteCAmJiBmcm0gIT0gZnJtX2VuZDsgKytud2NoYXJfdCkKICAgIHsKICAgICAgICBzaXplX3QgbiA9IG1icmxlbl9sKGZybSwgZnJtX2VuZC1mcm0sICZzdCwgX19sKTsKICAgICAgICBzd2l0Y2ggKG4pCiAgICAgICAgewogICAgICAgIGNhc2UgMDoKICAgICAgICAgICAgKytuYnl0ZXM7CiAgICAgICAgICAgICsrZnJtOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIC0xOgogICAgICAgIGNhc2UgLTI6CiAgICAgICAgICAgIHJldHVybiBuYnl0ZXM7CiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgbmJ5dGVzICs9IG47CiAgICAgICAgICAgIGZybSArPSBuOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gbmJ5dGVzOwp9CgppbnQKY29kZWN2dDx3Y2hhcl90LCBjaGFyLCBtYnN0YXRlX3Q+Ojpkb19tYXhfbGVuZ3RoKCkgY29uc3QgdGhyb3coKQp7CiAgICByZXR1cm4gX19sID09IDAgPyAxIDogTUJfQ1VSX01BWF9MKF9fbCk7Cn0KCi8vICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFZhbGlkIFVURiByYW5nZXMKLy8gICAgIFVURi0zMiAgICAgICAgICAgICAgIFVURi0xNiAgICAgICAgICAgICAgICAgICAgICAgICAgVVRGLTggICAgICAgICAgICAgICAjIG9mIGNvZGUgcG9pbnRzCi8vICAgICAgICAgICAgICAgICAgICAgZmlyc3QgICAgICBzZWNvbmQgICAgICAgZmlyc3QgICBzZWNvbmQgICAgdGhpcmQgICBmb3VydGgKLy8gMDAwMDAwIC0gMDAwMDdGICAwMDAwIC0gMDA3RiAgICAgICAgICAgICAgIDAwIC0gN0YgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAxMjcKLy8gMDAwMDgwIC0gMDAwN0ZGICAwMDgwIC0gMDdGRiAgICAgICAgICAgICAgIEMyIC0gREYsIDgwIC0gQkYgICAgICAgICAgICAgICAgICAgICAgIDE5MjAKLy8gMDAwODAwIC0gMDAwRkZGICAwODAwIC0gMEZGRiAgICAgICAgICAgICAgIEUwIC0gRTAsIEEwIC0gQkYsIDgwIC0gQkYgICAgICAgICAgICAgIDIwNDgKLy8gMDAxMDAwIC0gMDBDRkZGICAxMDAwIC0gQ0ZGRiAgICAgICAgICAgICAgIEUxIC0gRUMsIDgwIC0gQkYsIDgwIC0gQkYgICAgICAgICAgICAgNDkxNTIKLy8gMDBEMDAwIC0gMDBEN0ZGICBEMDAwIC0gRDdGRiAgICAgICAgICAgICAgIEVEIC0gRUQsIDgwIC0gOUYsIDgwIC0gQkYgICAgICAgICAgICAgIDIwNDgKLy8gMDBEODAwIC0gMDBERkZGICAgICAgICAgICAgICAgIGludmFsaWQKLy8gMDBFMDAwIC0gMDBGRkZGICBFMDAwIC0gRkZGRiAgICAgICAgICAgICAgIEVFIC0gRUYsIDgwIC0gQkYsIDgwIC0gQkYgICAgICAgICAgICAgIDgxOTIKLy8gMDEwMDAwIC0gMDNGRkZGICBEODAwIC0gRDhCRiwgREMwMCAtIERGRkYgIEYwIC0gRjA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ICh0b19lbmQtdG9fbnh0IDwgMSkKICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICAqdG9fbnh0KysgPSBzdGF0aWNfY2FzdDxleHRlcm5fdHlwZT4od2MxKTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAod2MxIDwgMHgwODAwKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKHRvX2VuZC10b19ueHQgPCAyKQogICAgICAgICAgICAgICAgcmV0dXJuIHBhcnRpYWw7CiAgICAgICAgICAgICp0b19ueHQrKyA9IHN0YXRpY19jYXN0PGV4dGVybl90eXBlPigweEMwIHwgKHdjMSA+PiA2KSk7CiAgICAgICAgICAgICp0b19ueHQrKyA9IHN0YXRpY19jYXN0PGV4dGVybl90eXBlPigweDgwIHwgKHdjMSAmIDB4MDNGKSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKHdjMSA8IDB4RDgwMCkKICAgICAgICB7CiAgICAgICAgICAgIGlmICh0b19lbmQtdG9fbnh0IDwgMykKICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICAqdG9fbnh0KysgPSBzdGF0aWNfY2FzdDxleHRlcm5fdHlwZT4oMHhFMCB8ICAod2MxID4+IDEyKSk7CiAgICAgICAgICAgICp0b19ueHQrKyA9IHN0YXRpY19jYXN0PGV4dGVybl90eXBlPigweDgwIHwgKCh3YzEgJiAweDBGQzApID4+IDYpKTsKICAgICAgICAgICAgKnRvX254dCsrID0gc3RhdGljX2Nhc3Q8ZXh0ZXJuX3R5cGU+KDB4ODAgfCAgKHdjMSAmIDB4MDAzRikpOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmICh3YzEgPCAweERDMDApCiAgICAgICAgewogICAgICAgICAgICBpZiAoZnJtX2VuZC1mcm1fbnh0IDwgMikKICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICBpbnRlcm5fdHlwZSB3YzIgPSBmcm1fbnh0WzFdOwogICAgICAgICAgICBpZiAoKHdjMiAmIDB4RkMwMCkgIT0gMHhEQzAwKQogICAgICAgICAgICAgICAgcmV0dXJuIGVycm9yOwogICAgICAgICAgICBpZiAodG9fZW5kLXRvX254dCA8IDQpCiAgICAgICAgICAgICAgICByZXR1cm4gcGFydGlhbDsKICAgICAgICAgICAgKytmcm1fbnh0OwogICAgICAgICAgICB1bnNpZ25lZCBjaGFyIHogPSAoKHdjMSAmIDB4MDNDMCkgPj4gNikgKyAxOwogICAgICAgICAgICAqdG9fbnh0KysgPSBzdGF0aWNfY2FzdDxleHRlcm5fdHlwZT4oMHhGMCB8ICh6ID4+IDIpKTsKICAgICAgICAgICAgKnRvX254dCsrID0gc3RhdGljX2Nhc3Q8ZXh0ZXJuX3R5cGU+KDB4ODAgfCAoKHogJiAweDAzKSA8PCA0KSAgICAgfCAoKHdjMSAmIDB4MDAzQykgPj4gMikpOwogICAgICAgICAgICAqdG9fbnh0KysgPSBzdGF0aWNfY2FzdDxleHRlcm5fdHlwZT4oMHg4MCB8ICgod2MxICYgMHgwMDAzKSA8PCA0KSB8ICgod2MyICYgMHgwM0MwKSA+PiA2KSk7CiAgICAgICAgICAgICp0b19ueHQrKyA9IHN0YXRpY19jYXN0PGV4dGVybl90eXBlPigweDgwIHwgICh3YzIgJiAweDAwM0YpKTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAod2MxIDwgMHhFMDAwKQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIGVycm9yOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpZiAodG9fZW5kLXRvX254dCA8IDMpCiAgICAgICAgICAgICAgICByZXR1cm4gcGFydGlhbDsKICAgICAgICAgICAgKnRvX254dCsrID0gc3RhdGljX2Nhc3Q8ZXh0ZXJuX3R5cGU+KDB4RTAgfCAgKHdjMSA+PiAxMikpOwogICAgICAgICAgICAqdG9fbnh0KysgPSBzdGF0aWNfY2FzdDxleHRlcm5fdHlwZT4oMHg4MCB8ICgod2MxICYgMHgwRkMwKSA+PiA2KSk7CiAgICAgICAgICAgICp0b19ueHQrKyA9IHN0YXRpY19jYXN0PGV4dGVybl90eXBlPigweDgwIHwgICh3YzEgJiAweDAwM0YpKTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gb2s7Cn0KCmNvZGVjdnQ8Y2hhcjE2X3QsIGNoYXIsIG1ic3RhdGVfdD46OnJlc3VsdApjb2RlY3Z0PGNoYXIxNl90LCBjaGFyLCBtYnN0YXRlX3Q+Ojpkb19pbihzdGF0ZV90eXBlJiwKICAgIGNvbnN0IGV4dGVybl90eXBlKiBmcm0sIGNvbnN0IGV4dGVybl90eXBlKiBmcm1fZW5kLCBjb25zdCBleHRlcm5fdHlwZSomIGZybV9ueHQsIAogICAgaW50ZXJuX3R5cGUqIHRvLCBpbnRlcm5fdHlwZSogdG9fZW5kLCBpbnRlcm5fdHlwZSomIHRvX254dCkgY29uc3QKewogICAgZm9yIChmcm1fbnh0ID0gZnJtLCB0b19ueHQgPSB0bzsgZnJtX254dCA8IGZybV9lbmQgJiYgdG9fbnh0IDwgdG9fZW5kOyArK3RvX254dCkKICAgIHsKICAgICAgICB1bnNpZ25lZCBjaGFyIGMxID0gc3RhdGljX2Nhc3Q8dW5zaWduZWQgY2hhcj4oKmZybV9ueHQpOwogICAgICAgIGlmIChjMSA8IDB4ODApCiAgICAgICAgewogICAgICAgICAgICAqdG9fbnh0ID0gc3RhdGljX2Nhc3Q8aW50ZXJuX3R5cGU+KGMxKTsKICAgICAgICAgICAgKytmcm1fbnh0OwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChjMSA8IDB4QzIpCiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKGMxIDwgMHhFMCkKICAgICAgICB7CiAgICAgICAgICAgIGlmIChmcm1fZW5kLWZybV9ueHQgPCAyKQogICAgICAgICAgICAgICAgcmV0dXJuIHBhcnRpYWw7CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzIgPSBmcm1fbnh0WzFdOwogICAgICAgICAgICBpZiAoKGMyICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgKnRvX254dCA9IHN0YXRpY19jYXN0PGludGVybl90eXBlPigoKGMxICYgMHgxRikgPDwgNikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwgKGMyICYgMHgzRikpOwogICAgICAgICAgICBmcm1fbnh0ICs9IDI7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKGMxIDwgMHhGMCkKICAgICAgICB7CiAgICAgICAgICAgIGlmIChmcm1fZW5kLWZybV9ueHQgPCAzKQogICAgICAgICAgICAgICAgcmV0dXJuIHBhcnRpYWw7CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzIgPSBmcm1fbnh0WzFdOwogICAgICAgICAgICB1bnNpZ25lZCBjaGFyIGMzID0gZnJtX254dFsyXTsKICAgICAgICAgICAgc3dpdGNoIChjMSkKICAgICAgICAgICAgewogICAgICAgICAgICBjYXNlIDB4RTA6CiAgICAgICAgICAgICAgICBpZiAoKGMyICYgMHhFMCkgIT0gMHhBMCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMHhFRDoKICAgICAgICAgICAgICAgIGlmICgoYzIgJiAweEUwKSAhPSAweDgwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGlmICgoYzIgJiAweEMwKSAhPSAweDgwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoKGMzICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgKnRvX254dCA9IHN0YXRpY19jYXN0PGludGVybl90eXBlPigoKGMxICYgMHgwRikgPDwgMTIpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwgKChjMiAmIDB4M0YpIDw8IDYpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwgIChjMyAmIDB4M0YpKTsKICAgICAgICAgICAgZnJtX254dCArPSAzOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChjMSA8IDB4RjUpCiAgICAgICAgewogICAgICAgICAgICBpZiAoZnJtX2VuZC1mcm1fbnh0IDwgNCkKICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICB1bnNpZ25lZCBjaGFyIGMyID0gZnJtX254dFsxXTsKICAgICAgICAgICAgdW5zaWduZWQgY2hhciBjMyA9IGZybV9ueHRbMl07CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzQgPSBmcm1fbnh0WzNdOwogICAgICAgICAgICBzd2l0Y2ggKGMxKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMHhGMDoKICAgICAgICAgICAgICAgIGlmICghKDB4OTAgPD0gYzIgJiYgYzIgPD0gMHhCRikpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGVycm9yOwogICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDB4RjQ6CiAgICAgICAgICAgICAgICBpZiAoKGMyICYgMHhGMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICBpZiAoKGMyICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKChjMyAmIDB4QzApICE9IDB4ODAgfHwgKGM0ICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgaWYgKHRvX2VuZC10b19ueHQgPCAyKQogICAgICAgICAgICAgICAgcmV0dXJuIHBhcnRpYWw7CiAgICAgICAgICAgICp0b19ueHQgPSBzdGF0aWNfY2FzdDxpbnRlcm5fdHlwZT4oCiAgICAgICAgICAgICAgICAgICAgMHhEODAwCiAgICAgICAgICAgICAgICAgIHwgKCgoKChjMSAmIDB4MDcpIDw8IDIpIHwgKChjMiAmIDB4MzApID4+IDQpKSAtIDEpIDw8IDYpCiAgICAgICAgICAgICAgICAgIHwgKChjMiAmIDB4MEYpIDw8IDIpCiAgICAgICAgICAgICAgICAgIHwgKChjMyAmIDB4MzApID4+IDQpKTsKICAgICAgICAgICAgKisrdG9fbnh0ID0gc3RhdGljX2Nhc3Q8aW50ZXJuX3R5cGU+KAogICAgICAgICAgICAgICAgICAgIDB4REMwMAogICAgICAgICAgICAgICAgICB8ICgoYzMgJiAweDBGKSA8PCA2KQogICAgICAgICAgICAgICAgICB8ICAoYzQgJiAweDNGKSk7CiAgICAgICAgICAgIGZybV9ueHQgKz0gNDsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIGVycm9yOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBmcm1fbnh0IDwgZnJtX2VuZCA/IHBhcnRpYWwgOiBvazsKfQoKY29kZWN2dDxjaGFyMTZfdCwgY2hhciwgbWJzdGF0ZV90Pjo6cmVzdWx0CmNvZGVjdnQ8Y2hhcjE2X3QsIGNoYXIsIG1ic3RhdGVfdD46OmRvX3Vuc2hpZnQoc3RhdGVfdHlwZSYsCiAgICBleHRlcm5fdHlwZSogdG8sIGV4d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AgICAgIGJyZWFrOwogICAgICAgICAgICBmcm1fbnh0ICs9IDI7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKGMxIDwgMHhGMCkKICAgICAgICB7CiAgICAgICAgICAgIGlmIChmcm1fZW5kLWZybV9ueHQgPCAzKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzIgPSBmcm1fbnh0WzFdOwogICAgICAgICAgICB1bnNpZ25lZCBjaGFyIGMzID0gZnJtX254dFsyXTsKICAgICAgICAgICAgc3dpdGNoIChjMSkKICAgICAgICAgICAgewogICAgICAgICAgICBjYXNlIDB4RTA6CiAgICAgICAgICAgICAgICBpZiAoKGMyICYgMHhFMCkgIT0gMHhBMCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4gc3RhdGljX2Nhc3Q8aW50Pihmcm1fbnh0IC0gZnJtKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDB4RUQ6CiAgICAgICAgICAgICAgICBpZiAoKGMyICYgMHhFMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4gc3RhdGljX2Nhc3Q8aW50Pihmcm1fbnh0IC0gZnJtKTsKICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGlmICgoYzIgJiAweEMwKSAhPSAweDgwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBzdGF0aWNfY2FzdDxpbnQ+KGZybV9ueHQgLSBmcm0pOwogICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICgoYzMgJiAweEMwKSAhPSAweDgwKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGZybV9ueHQgKz0gMzsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoYzEgPCAweEY1KQogICAgICAgIHsKICAgICAgICAgICAgaWYgKGZybV9lbmQtZnJtX254dCA8IDQgfHwgbXgtbmNoYXIxNl90IDwgMikKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB1bnNpZ25lZCBjaGFyIGMyID0gZnJtX254dFsxXTsKICAgICAgICAgICAgdW5zaWduZWQgY2hhciBjMyA9IGZybV9ueHRbMl07CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzQgPSBmcm1fbnh0WzNdOwogICAgICAgICAgICBzd2l0Y2ggKGMxKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMHhGMDoKICAgICAgICAgICAgICAgIGlmICghKDB4OTAgPD0gYzIgJiYgYzIgPD0gMHhCRikpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHN0YXRpY19jYXN0PGludD4oZnJtX254dCAtIGZybSk7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMHhGNDoKICAgICAgICAgICAgICAgIGlmICgoYzIgJiAweEYwKSAhPSAweDgwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBzdGF0aWNfY2FzdDxpbnQ+KGZybV9ueHQgLSBmcm0pOwogICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgaWYgKChjMiAmIDB4QzApICE9IDB4ODApCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHN0YXRpY19jYXN0PGludD4oZnJtX254dCAtIGZybSk7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKChjMyAmIDB4QzApICE9IDB4ODAgfHwgKGM0ICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICArK25jaGFyMTZfdDsKICAgICAgICAgICAgZnJtX254dCArPSA0OwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gc3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ICAgICByZXR1cm4gcGFydGlhbDsKICAgICAgICAgICAgKnRvX254dCsrID0gc3RhdGljX2Nhc3Q8ZXh0ZXJuX3R5cGU+KHdjKTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAod2MgPCAweDAwMDgwMCkKICAgICAgICB7CiAgICAgICAgICAgIGlmICh0b19lbmQtdG9fbnh0IDwgMikKICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICAqdG9fbnh0KysgPSBzdGF0aWNfY2FzdDxleHRlcm5fdHlwZT4oMHhDMCB8ICh3YyA+PiA2KSk7CiAgICAgICAgICAgICp0b19ueHQrKyA9IHN0YXRpY19jYXN0PGV4dGVybl90eXBlPigweDgwIHwgKHdjICYgMHgwM0YpKTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAod2MgPCAweDAxMDAwMCkKICAgICAgICB7CiAgICAgICAgICAgIGlmICh0b19lbmQtdG9fbnh0IDwgMykKICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICAqdG9fbnh0KysgPSBzdGF0aWNfY2FzdDxleHRlcm5fdHlwZT4oMHhFMCB8ICAod2MgPj4gMTIpKTsKICAgICAgICAgICAgKnRvX254dCsrID0gc3RhdGljX2Nhc3Q8ZXh0ZXJuX3R5cGU+KDB4ODAgfCAoKHdjICYgMHgwRkMwKSA+PiA2KSk7CiAgICAgICAgICAgICp0b19ueHQrKyA9IHN0YXRpY19jYXN0PGV4dGVybl90eXBlPigweDgwIHwgICh3YyAmIDB4MDAzRikpOwogICAgICAgIH0KICAgICAgICBlbHNlIC8vIGlmICh3YyA8IDB4MTEwMDAwKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKHRvX2VuZC10b19ueHQgPCA0KQogICAgICAgICAgICAgICAgcmV0dXJuIHBhcnRpYWw7CiAgICAgICAgICAgICp0b19ueHQrKyA9IHN0YXRpY19jYXN0PGV4dGVybl90eXBlPigweEYwIHwgICh3YyA+PiAxOCkp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pCiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKGMxIDwgMHhFMCkKICAgICAgICB7CiAgICAgICAgICAgIGlmIChmcm1fZW5kLWZybV9ueHQgPCAyKQogICAgICAgICAgICAgICAgcmV0dXJuIHBhcnRpYWw7CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzIgPSBmcm1fbnh0WzFdOwogICAgICAgICAgICBpZiAoKGMyICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgKnRvX254dCA9IHN0YXRpY19jYXN0PGludGVybl90eXBlPigoKGMxICYgMHgxRikgPDwgNikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwgKGMyICYgMHgzRikpOwogICAgICAgICAgICBmcm1fbnh0ICs9IDI7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKGMxIDwgMHhGMCkKICAgICAgICB7CiAgICAgICAgICAgIGlmIChmcm1fZW5kLWZybV9ueHQgPCAzKQogICAgICAgICAgICAgICAgcmV0dXJuIHBhcnRpYWw7CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzIgPSBmcm1fbnh0WzFdOwogICAgICAgICAgICB1bnNpZ25lZCBjaGFyIGMzID0gZnJtX254dFsyXTsKICAgICAgICAgICAgc3dpdGNoIChjMSkKICAgICAgICAgICAgewogICAgICAgICAgICBjYXNlIDB4RTA6CiAgICAgICAgICAgICAgICBpZiAoKGMyICYgMHhFMCkgIT0gMHhBMCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMHhFRDoKICAgICAgICAgICAgICAgIGlmICgoYzIgJiAweEUwKSAhPSAweDgwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGlmICgoYzIgJiAweEMwKSAhPSAweDgwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoKGMzICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgKnRvX254dCA9IHN0YXRpY19jYXN0PGludGVybl90eXBlPigoKGMxICYgMHgwRikgPDwgMTIpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwgKChjMiAmIDB4M0YpIDw8IDYpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwgIChjMyAmIDB4M0YpKTsKICAgICAgICAgICAgZnJtX254dCArPSAzOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChjMSA8IDB4RjUpCiAgICAgICAgewogICAgICAgICAgICBpZiAoZnJtX2VuZC1mcm1fbnh0IDwgNCkKICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICB1bnNpZ25lZCBjaGFyIGMyID0gZnJtX254dFsxXTsKICAgICAgICAgICAgdW5zaWduZWQgY2hhciBjMyA9IGZybV9ueHRbMl07CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzQgPSBmcm1fbnh0WzNdOwogICAgICAgICAgICBzd2l0Y2ggKGMxKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMHhGMDoKICAgICAgICAgICAgICAgIGlmICghKDB4OTAgPD0gYzIgJiYgYzIgPD0gMHhCRikpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGVycm9yOwogICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDB4RjQ6CiAgICAgICAgICAgICAgICBpZiAoKGMyICYgMHhGMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICBpZiAoKGMyICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKChjMyAmIDB4QzApICE9IDB4ODAgfHwgKGM0ICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcjsKICAgICAgICAgICAgKnRvX254dCA9IHN0YXRpY19jYXN0PGludGVybl90eXBlPigoKGMxICYgMHgwNykgPDwgMTgpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwgKChjMiAmIDB4M0YpIDw8IDEyKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8ICgoYzMgJiAweDNGKSA8PCA2KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8ICAoYzQgJiAweDNGKSk7CiAgICAgICAgICAgIGZybV9ueHQgKz0gNDsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIGVycm9yOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBmcm1fbnh0IDwgZnJtX2VuZCA/IHBhcnRpYWwgOiBvazsKfQoKY29kZWN2dDxjaGFyMzJfdCwgY2hhciwgbWJzdGF0ZV90Pjo6cmVzdWx0CmNvZGVjdnQ8Y2hhcjMyX3QsIGNoYXIsIG1ic3RhdGVfdD46OmRvX3Vuc2hpZnQoc3RhdGVfdHlwZSYsCiAgICBleHRlcm5fdHlwZSogdG8sIGV4dGVybl90eXBlKiwgZXh0ZXJuX3R5cGUqJiB0b19ueHQpIGNvbnN0CnsKICAgIHRvX254dCA9IHRvOwogICAgcmV0dXJuIG5vY29udjsKfQoKaW50CmNvZGVjdnQ8Y2hhcjMyX3QsIGNoYXIsIG1ic3RhdGVfdD46OmRvX2VuY29kaW5nKCkgY29uc3QgdGhyb3coKQp7CiAgICByZXR1cm4gMDsKfQoKYm9vbApjb2RlY3Z0PGNoYXIzMl90LCBjaGFyLCBtYnN0YXRlX3Q+Ojpkb19hbHdheXNfbm9jb252KCkgY29uc3QgdGhyb3coKQp7CiAgICByZXR1cm4gZmFsc2U7Cn0KCmludApjb2RlY3Z0PGNoYXIzMl90LCBjaGFyLCBtYnN0YXRlX3Q+Ojpkb19sZW5ndGgoc3RhdGVfdHlwZSYsCiAgICBjb25zdCBleHRlcm5fdHlwZSogZnJtLCBjb25zdCBleHRlcm5fdHlwZSogZnJtX2VuZCwgc2l6ZV90IG14KSBjb25zdAp7CiAgICBjb25zdCBleHRlcm5fdHlwZSogZnJtX254dCA9IGZybTsKICAgIGZvciAoc2l6ZV90IG5jaGFyMzJfdCA9IDA7IGZybV9ueHQgPCBmcm1fZW5kICYmIG5jaGFyMzJfdCA8IG14OyArK25jaGFyMzJfdCkKICAgIHsKICAgICAgICB1bnNpZ25lZCBjaGFyIGMxID0gc3RhdGljX2Nhc3Q8dW5zaWduZWQgY2hhcj4oKmZybV9ueHQpOwogICAgICAgIGlmIChjMSA8IDB4ODApCiAgICAgICAgewogICAgICAgICAgICArK2ZybV9ueHQ7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKGMxIDwgMHhDMikKICAgICAgICB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChjMSA8IDB4RTApCiAgICAgICAgewogICAgICAgICAgICBpZiAoKGZybV9lbmQtZnJtX254dCA8IDIpIHx8ICgoZnJtX254dFsxXSAmIDB4QzApICE9IDB4ODApKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGZybV9ueHQgKz0gMjsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoYzEgPCAweEYwKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKGZybV9lbmQtZnJtX254dCA8IDMpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgdW5zaWduZWQgY2hhciBjMiA9IGZybV9ueHRbMV07CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzMgPSBmcm1fbnh0WzJdOwogICAgICAgICAgICBzd2l0Y2ggKGMxKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMHhFMDoKICAgICAgICAgICAgICAgIGlmICgoYzIgJiAweEUwKSAhPSAweEEwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBzdGF0aWNfY2FzdDxpbnQ+KGZybV9ueHQgLSBmcm0pOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMHhFRDoKICAgICAgICAgICAgICAgIGlmICgoYzIgJiAweEUwKSAhPSAweDgwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBzdGF0aWNfY2FzdDxpbnQ+KGZybV9ueHQgLSBmcm0pOwogICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgaWYgKChjMiAmIDB4QzApICE9IDB4ODApCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHN0YXRpY19jYXN0PGludD4oZnJtX254dCAtIGZybSk7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKChjMyAmIDB4QzApICE9IDB4ODApCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgZnJtX254dCArPSAzOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChjMSA8IDB4RjUpCiAgICAgICAgewogICAgICAgICAgICBpZiAoZnJtX2VuZC1mcm1fbnh0IDwgNCkKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB1bnNpZ25lZCBjaGFyIGMyID0gZnJtX254dFsxXTsKICAgICAgICAgICAgdW5zaWduZWQgY2hhciBjMyA9IGZybV9ueHRbMl07CiAgICAgICAgICAgIHVuc2lnbmVkIGNoYXIgYzQgPSBmcm1fbnh0WzNdOwogICAgICAgICAgICBzd2l0Y2ggKGMxKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMHhGMDoKICAgICAgICAgICAgICAgIGlmICghKDB4OTAgPD0gYzIgJiYgYzIgPD0gMHhCRikpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHN0YXRpY19jYXN0PGludD4oZnJtX254dCAtIGZybSk7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMHhGNDoKICAgICAgICAgICAgICAgIGlmICgoYzIgJiAweEYwKSAhPSAweDgwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBzdGF0aWNfY2FzdDxpbnQ+KGZybV9ueHQgLSBmcm0pOwogICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgaWYgKChjMiAmIDB4QzApICE9IDB4ODApCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHN0YXRpY19jYXN0PGludD4oZnJtX254dCAtIGZybSk7CiAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKChjMyAmIDB4QzApICE9IDB4ODAgfHwgKGM0ICYgMHhDMCkgIT0gMHg4MCkKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBmcm1fbnh0ICs9IDQ7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBzdGF0aWNfY2FzdDxpbnQ+KGZybV9ueHQgLSBmcm0pOwp9CgppbnQKY29kZWN2dDxjaGFyMzJfdCwgY2hhciwgbWJzdGF0ZV90Pjo6ZG9fbWF4X2xlbmd0aCgpIGNvbnN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gICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGlmICh0b19lbmQtdG9fbnh0IDwgMikKICAgICAgICAgICAgICAgIHJldHVybiBwYXJ0aWFsOwogICAgICAgICAgICAqdG9fbnh0KysgPSBzdGF0aWNfY2FzdDxleHRlcm5fdHlwZT4oCiAgICAgICAgICAgICAgICAgICAgMHhEODAwCiAgICAgICAgICAgICAgICAgIHwgKCgoKHdjICYgMHgxRjAwMDApID4+IDE2KSAtIDEpIDw8IDYpCiAgICAgICAgICAgICAgICAgIHwgICAoKHdjICYgMHgwMEZDMDApID4+IDEwKSk7CiAgICAgICAgICAgICp0b19ueHQrKyA9IHN0YXRpY19jYXN0PGV4dGVybl90eXBlPigKICAgICAgICAgICAgICAgICAgICAweERDMDAKICAgICAgICAgICAgICAgICAgfCAod2MgJiAweDAzRkYpKTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gb2s7Cn0KCmNvZGVjdnQ8Y2hhcjMyX3QsIGNoYXIxNl90LCBtYnN0YXRlX3Q+OjpyZXN1bHQKY29kZWN2dDxjaGFyMzJfdCwgY2hhcjE2X3QsIG1ic3RhdGVfdD46OmRvX2luKHN0YXRlX3R5cGUmLAogICAgY29uc3QgZXh0ZXJuX3R5cGUqIGZybSwgY29uc3QgZXh0ZXJuX3R5cGUqIGZybV9lbmQsIGNvbnN0IGV4dGVybl90eXBlKiYgZnJtX254dCwgCiAgICBpbnRlcm5fdHlwZSogdG8sIGludGVybl90eXBlKiB0b19lbmQsIGludGVybl90eXBlKiYgdG9fbnh0KSBjb25zdAp7CiAgICBmb3IgKGZybV9ueHQgPSBmcm0sIHRvX254dCA9IHRvOyBmcm1fbnh0IDwgZnJtX2VuZCAmJiB0b19ueHQgPCB0b19lbmQ7ICsrdG9fbnh0KQogICAgewogICAgICAgIGV4dGVybl90eXBlIGMxID0gKmZybV9ueHQ7CiAgICAgICAgaWYgKChjMSAmIDB4RkMwMCkgPT0gMHhEQzAwKQogICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgaWYgKChjMSAmIDB4RkMwMCkgIT0gMHhEODAwKQogICAgICAgIHsKICAgICAgICAgICAgKnRvX254dCA9IHN0YXRpY19jYXN0PGludGVybl90eXBlPihjMSk7CiAgICAgICAgICAgICsrZnJtX254dDsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgaWYgKGZybV9lbmQtZnJtX254dCA8IDIpCiAgICAgICAgICAgICAgICByZXR1cm4gcGFydGlhbDsKICAgICAgICAgICAgZXh0ZXJuX3R5cGUgYzIgPSBmcm1fbnh0WzFdOwogICAgICAgICAgICBpZiAoKGMyICYgMHhGQzAwKSAhPSAweERDMDApCiAgICAgICAgICAgICAgICByZXR1cm4gZXJyb3I7CiAgICAgICAgICAgICp0b19ueHQgPSBzdGF0aWNfY2FzdDxpbnRlcm5fdHlwZT4oCiAgICAgICAgICAgICAgICAgICAgKCgoKGMxICYgMHgwM0MwKSA+PiA2KSArIDEpIDw8IDE2KQogICAgICAgICAgICAgICAgICB8ICAgKChjMSAmIDB4MDAzRikgPDwgMTApCiAgICAgICAgICAgICAgICAgIHwgICAgKGMyICYgMHgwM0ZGKSk7CiAgICAgICAgICAgIGZybV9ueHQgKz0gMjsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gZnJtX254dCA8IGZybV9lbmQgPyBwYXJ0aWFsIDogb2s7Cn0KCmNvZGVjdnQ8Y2hhcjMyX3QsIGNoYXIxNl90LCBtYnN0YXRlX3Q+OjpyZXN1bHQKY29kZWN2dDxjaGFyMzJfdCwgY2hhcjE2X3QsIG1ic3RhdGVfdD46OmRvX3Vuc2hpZnQoc3RhdGVfdHlwZSYsCiAgICBleHRlcm5fdHlwZSogdG8sIGV4dGVybl90eXBlKiwgZXh0ZXJuX3R5cGUqJiB0b19ueHQpIGNvbnN0CnsKICAgIHRvX254dCA9IHRvOwogICAgcmV0dXJuIG5vY29udjsKfQoKaW50CmNvZGVjdnQ8Y2hhcjMyX3QsIGNoYXIxNl90LCBtYnN0YXRlX3Q+Ojpkb19lbmNvZGluZygpIGNvbnN0IHRocm93KCkKewogICAgcmV0dXJuIDA7Cn0KCmJvb2wKY29kZWN2dDxjaGFyMzJfdCwgY2hhcjE2X3QsIG1ic3RhdGVfdD46OmRvX2Fsd2F5c19ub2NvbnYoKSBjb25zdCB0aHJvdygpCnsKICAgIHJldHVybiBmYWxzZTsKfQoKaW50CmNvZGVjdnQ8Y2hhcjMyX3QsIGNoYXIxNl90LCBtYnN0YXRlX3Q+Ojpkb19sZW5ndGgoc3RhdGVfdHlwZSYsCiAgICBjb25zdCBleHRlcm5fdHlwZSogZnJtLCBjb25zdCBleHRlcm5fdHlwZSogZnJtX2VuZCwgc2l6ZV90IG14KSBjb25zdAp7CiAgICBjb25zdCBleHRlcm5fdHlwZSogZnJtX254dCA9IGZybTsKICAgIGZvciAoc2l6ZV90IG5jaGFyMzJfdCA9IDA7IGZybV9ueHQgPCBmcm1fZW5kICYmIG5jaGFyMzJfdCA8IG14OyArK25jaGFyMzJfdCkKICAgIHsKICAgICAgICBleHRlcm5fdHlwZSBjMSA9ICpmcm1fbnh0OwogICAgICAgIGlmICgoYzEgJiAweEZDMDApID09IDB4REMwMCkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgaWYgKChjMSAmIDB4RkMwMCkgIT0gMHhEODAwKQogICAgICAgIHsKICAgICAgICAgICAgKytmcm1fbnh0OwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpZiAoKGZybV9lbmQtZnJtX254dCA8IDIpIHx8IChmcm1fbnh0WzFdICYgMHhGQzAwKSAhPSAweERDMDApCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgZnJtX254dCArPSAyOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBzdGF0aWNfY2FzdDxpbnQ+KGZybV9ueHQgLSBmcm0pOwp9CgppbnQKY29kZWN2dDxjaGFyMzJfdCwgY2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gICAgICAgY29uc3QgY2hhciogX19pZyA9IF9fZ3JvdXBpbmcuZGF0YSgpOwogICAgICAgIGNvbnN0IGNoYXIqIF9fZWcgPSBfX2lnICsgX19ncm91cGluZy5zaXplKCk7CiAgICAgICAgZm9yICh1bnNpZ25lZCogX19yID0gX19nOyBfX3IgPCBfX2dfZW5kLTE7ICsrX19yKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKDAgPCAqX19pZyAmJiAqX19pZyA8IG51bWVyaWNfbGltaXRzPGNoYXI+OjptYXgoKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYgKCpfX2lnICE9ICpfX3IpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgX19lcnIgPSBpb3NfYmFzZTo6ZmFpbGJpdDsKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKF9fZWcgLSBfX2lnID4gMSkKICAgICAgICAgICAgICAgICsrX19pZzsKICAgICAgICB9CiAgICAgICAgaWYgKDAgPCAqX19pZyAmJiAqX19pZyA8IG51bWVyaWNfbGltaXRzPGNoYXI+OjptYXgoKSkKICAgICAgICB7CiAgICAgICAgICAgIGlmICgqX19pZyA8IF9fZ19lbmRbLTFdIHx8IF9fZ19lbmRbLTFdID09IDApCiAgICAgICAgICAgICAgICBfX2VyciA9IGlvc19iYXNlOjpmYWlsYml0OwogICAgICAgIH0KICAgIH0KfQoKdm9pZApfX251bV9wdXRfYmFzZTo6X19mb3JtYXRfaW50KGNoYXIqIF9fZm10cCwgY29uc3QgY2hhciogX19sZW4sIGJvb2wgX19zaWduZCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpb3NfYmFzZTo6Zm10ZmxhZ3MgX19mbGFncykKewogICAgaWYgKF9fZmxhZ3MgJiBpb3NfYmFzZTo6c2hvd3BvcykKICAgICAgICAqX19mbXRwKysgPSAnKyc7CiAgICBpZiAoX19mbGFncyA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gJiBpb3NfYmFzZTo6dXBwZXJjYXNlOwogICAgaWYgKGZsb2F0ZmllbGQgPT0gKGlvc19iYXNlOjpmaXhlZCB8IGlvc19iYXNlOjpzY2llbnRpZmljKSkKICAgICAgICBzcGVjaWZ5X3ByZWNpc2lvbiA9IGZhbHNlOwogICAgZWxzZQogICAgewogICAgICAgICpfX2ZtdHArKyA9ICcuJzsKICAgICAgICAqX19mbXRwKysgPSAnKic7CiAgICB9CiAgICB3aGlsZSgqX19sZW4pCiAgICAgICAgKl9fZm10cCsrID0gKl9fbGVuKys7CiAgICBpZiAoZmxvYXRmaWVsZCA9PSBpb3NfYmFzZTo6Zml4ZWQpCiAgICB7CiAgICAgICAgaWYgKHVwcGVyY2FzZSkKICAgICAgICAgICAgKl9fZm10cCA9ICdGJzsKICAgICAgICBlbHNlCiAgICAgICAgICAgICpfX2ZtdHAgPSAnZic7CiAgICB9CiAgICBlbHNlIGlmIChmbG9hdGZpZWxkID09IGlvc19iYXNlOjpzY2llbnRpZmljKQogICAgewogICAgICAgIGlmICh1cHBlcmNhc2UpCiAgICAgICAgICAgICpfX2ZtdHAgPSAnRSc7CiAgICAgICAgZWxzZQogICAgICAgICAgICAqX19mbXRwID0gJ2UnOwogICAgfQogICAgZWxzZSBpZiAoZmxvYXRmaWVsZCA9PSAoaW9zX2Jhc2U6OmZpeGVkIHwgaW9zX2Jhc2U6OnNjaWVudGlmaWMpKQogICAgewogICAgICAgIGlmICh1cHBlcmNhc2UpCiAgICAgICAgICAgICpfX2ZtdHAgPSAnQSc7CiAgICAgICAgZWxzZQogICAgICAgICAgICAqX19mbXRwID0gJ2EnOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIGlmICh1cHBlcmNhc2UpCiAgICAgICAgICAgICpfX2ZtdHAgPSAnRyc7CiAgICAgICAgZWxzZQogICAgICAgICAgICAqX19mbXRwID0gJ2cnOwogICAgfQogICAgcmV0dXJuIHNwZWNpZnlfcHJlY2lzaW9uOwp9CgpjaGFyKgpfX251bV9wdXRfYmFzZTo6X19pZGVudGlmeV9wYWRkaW5nKGNoYXIqIF9fbmIsIGNoYXIqIF9fbmUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgaW9zX2Jhc2UmIF9faW9iKQp7CiAgICBzd2l0Y2ggKF9faW9iLmZsYWdzKCkgJiBpb3NfYmFzZTo6YWRqdXN0ZmllbGQpCiAgICB7CiAgICBjYXNlIGlvc19iYXNlOjppbnRlcm5hbDoKICAgICAgICBpZiAoX19uYlswXSA9PSAnLScgfHwgX19uYlswXSA9PSAnKycpCiAgICAgICAgICAgIHJldHVybiBfX25iKzE7CiAgICAgICAgaWYgKF9fbmUgLSBfX25iID49IDIgJiYgX19uYlswXSA9PSAnMCcKICAgICAgICAgICAgICAgICAgICAgICAgICAgICYmIChfX25iWzFdID09ICd4JyB8fCBfX25iWzFdID09ICdYJykpCiAgICAgICAgICAgIHJldHVybiBfX25iKzI7CiAgICAgICAgYnJlYWs7CiAgICBjYXNlIGlvc19iYXNlOjpsZWZ0OgogICAgICAgIHJldHVybiBfX25lOwogICAgY2FzZSBpb3NfYmFzZTo6cmlnaHQ6CiAgICBkZWZhdWx0OgogICAgICAgIGJyZWFrOwogICAgfQogICAgcmV0dXJuIF9fbmI7Cn0KCi8vIHRpbWVfZ2V0CgpzdGF0aWMKc3RyaW5nKgppbml0X3dlZWtzKCkKewogICAgc3RhdGljIHN0cmluZyB3ZWVrc1sxNF07CiAgICB3ZWVrc1swXSAgPSAiU3VuZGF5IjsKICAgIHdlZWtzWzFdICA9ICJNb25kYXkiOwogICAgd2Vla3NbMl0gID0gIlR1ZXNkYXkiOwogICAgd2Vla3NbM10gID0gIldlZG5lc2RheSI7CiAgICB3ZWVrc1s0XSAgPSAiVGh1cnNkYXkiOwogICAgd2Vla3NbNV0gID0gIkZyaWRheSI7CiAgICB3ZWVrc1s2XSAgPSAiU2F0dXJkYXkiOwogICAgd2Vla3NbN10gID0gIlN1biI7CiAgICB3ZWVrc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BjaGFyIGJ1ZlsxMDBdOwogICAgY2hhciBmWzNdID0gezB9OwogICAgZlswXSA9ICclJzsKICAgIGZbMV0gPSBmbXQ7CiAgICBzaXplX3QgbiA9IHN0cmZ0aW1lX2woYnVmLCAxMDAsIGYsICZ0LCBfX2xvY18pOwogICAgY2hhciogYmIgPSBidWY7CiAgICBjaGFyKiBiZSA9IGJ1ZiArIG47CiAgICBzdHJpbmcgcmVzdWx0OwogICAgd2hpbGUgKGJiICE9IGJlKQogICAgewogICAgICAgIGlmIChjdC5pcyhjdHlwZV9iYXNlOjpzcGFjZSwgKmJiKSkKICAgICAgICB7CiAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJyAnKTsKICAgICAgICAgICAgZm9yICgrK2JiOyBiYiAhPSBiZSAmJiBjdC5pcyhjdHlwZV9iYXNlOjpzcGFjZSwgKmJiKTsgKytiYikKICAgICAgICAgICAgICAgIDsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGNoYXIqIHcgPSBiYjsKICAgICAgICBpb3NfYmFzZTo6aW9zdGF0ZSBlcnIgPSBpb3NfYmFzZTo6Z29vZGJpdDsKICAgICAgICBpbnQgaSA9IF9fc2Nhbl9rZXl3b3JkKHcsIGJlLCB0aGlzLT5fX3dlZWtzXywgdGhpcy0+X193ZWVrc18rMTQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjdCwgZXJyLCBmYWxzZSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0gdGhpcy0+X193ZWVrc187CiAgICAgICAgaWYgKGkgPCAxNCkKICAgICAgICB7CiAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJyUnKTsKICAgICAgICAgICAgaWYgKGkgPCA3KQogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygnQScpOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKCdhJyk7CiAgICAgICAgICAgIGJiID0gdzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIHcgPSBiYjsKICAgICAgICBpID0gX19zY2FuX2tleXdvcmQodywgYmUsIHRoaXMtPl9fbW9udGhzXywgdGhpcy0+X19tb250aHNfKzI0LAogICAgICAgICAgICAgICAgICAgICAgICAgICBjdCwgZXJyLCBmYWxzZSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgLSB0aGlzLT5fX21vbnRoc187CiAgICAgICAgaWYgKGkgPCAyNCkKICAgICAgICB7CiAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJyUnKTsKICAgICAgICAgICAgaWYgKGkgPCAxMikKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJ0InKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygnYicpOwogICAgICAgICAgICBpZiAoZm10ID09ICd4JyAmJiBjdC5pcyhjdHlwZV9iYXNlOjpkaWdpdCwgdGhpcy0+X19tb250aHNfW2ldWzBdKSkKICAgICAgICAgICAgICAgIHJlc3VsdC5iYWNrKCkgPSAnbSc7CiAgICAgICAgICAgIGJiID0gdzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzLT5fX2FtX3BtX1swXS5zaXplKCkgKyB0aGlzLT5fX2FtX3BtX1sxXS5zaXplKCkgPiAwKQogICAgICAgIHsKICAgICAgICAgICAgdyA9IGJiOwogICAgICAgICAgICBpID0gX19zY2FuX2tleXdvcmQodywgYmUsIHRoaXMtPl9fYW1fcG1fLCB0aGlzLT5fX2FtX3BtXysyLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3QsIGVyciwgZmFsc2UpIC0gdGhpcy0+X19hbV9wbV87CiAgICAgICAgICAgIGlmIChpIDwgMikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygnJScpOwogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygncCcpOwogICAgICAgICAgICAgICAgYmIgPSB3OwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdyA9IGJiOwogICAgICAgIGlmIChjdC5pcyhjdHlwZV9iYXNlOjpkaWdpdCwgKmJiKSkKICAgICAgICB7CiAgICAgICAgICAgIHN3aXRjaChfX2dldF91cF90b19uX2RpZ2l0cyhiYiwgYmUsIGVyciwgY3QsIDQpKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgNjoKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJyUnKTsKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJ3cnKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDc6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKCclJyk7CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKCd1Jyk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAxMToKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJyUnKTsKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJ0knKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDEyOgogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygnJScpOwogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygnbScpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMjM6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKCclJyk7CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKCdIJyk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAzMToKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJyUnKTsKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJ2QnKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDU1OgogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygnJScpOwogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygnTScpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgNTk6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKCclJyk7CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKCdTJyk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSA2MToKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJyUnKTsKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJ3knKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDM2NDoKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJyUnKTsKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soJ2onKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDIwNjE6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKCclJyk7CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKCdZJyk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGZvciAoOyB3ICE9IGJiOyArK3cpCiAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygqdyk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgaWYgKCpiYiA9PSAnJScpCiAgICAgICAgewogICAgICAgICAgICByZXN1bHQucHVzaF9iY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NoYXJfdCogd2JlID0gd2JiICsgaTsKICAgIHdzdHJpbmcgcmVzdWx0OwogICAgd2hpbGUgKHdiYiAhPSB3YmUpCiAgICB7CiAgICAgICAgaWYgKGN0LmlzKGN0eXBlX2Jhc2U6OnNwYWNlLCAqd2JiKSkKICAgICAgICB7CiAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soTCcgJyk7CiAgICAgICAgICAgIGZvciAoKyt3YmI7IHdiYiAhPSB3YmUgJiYgY3QuaXMoY3R5cGVfYmFzZTo6c3BhY2UsICp3YmIpOyArK3diYikKICAgICAgICAgICAgICAgIDsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIHdjaGFyX3QqIHcgPSB3YmI7CiAgICAgICAgaW9zX2Jhc2U6Omlvc3RhdGUgZXJyID0gaW9zX2Jhc2U6Omdvb2RiaXQ7CiAgICAgICAgaW50IGkgPSBfX3NjYW5fa2V5d29yZCh3LCB3YmUsIHRoaXMtPl9fd2Vla3NfLCB0aGlzLT5fX3dlZWtzXysxNCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN0LCBlcnIsIGZhbHNlKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLSB0aGlzLT5fX3dlZWtzXzsKICAgICAgICBpZiAoaSA8IDE0KQogICAgICAgIHsKICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJyUnKTsKICAgICAgICAgICAgaWYgKGkgPCA3KQogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJ0EnKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJ2EnKTsKICAgICAgICAgICAgd2JiID0gdzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIHcgPSB3YmI7CiAgICAgICAgaSA9IF9fc2Nhbl9rZXl3b3JkKHcsIHdiZSwgdGhpcy0+X19tb250aHNfLCB0aGlzLT5fX21vbnRoc18rMjQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgIGN0LCBlcnIsIGZhbHNlKQogICAgICAgICAgICAgICAgICAgICAgICAgICAtIHRoaXMtPl9fbW9udGhzXzsKICAgICAgICBpZiAoaSA8IDI0KQogICAgICAgIHsKICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJyUnKTsKICAgICAgICAgICAgaWYgKGkgPCAxMikKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soTCdCJyk7CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soTCdiJyk7CiAgICAgICAgICAgIGlmIChmbXQgPT0gJ3gnICYmIGN0LmlzKGN0eXBlX2Jhc2U6OmRpZ2l0LCB0aGlzLT5fX21vbnRoc19baV1bMF0pKQogICAgICAgICAgICAgICAgcmVzdWx0LmJhY2soKSA9IEwnbSc7CiAgICAgICAgICAgIHdiYiA9IHc7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy0+X19hbV9wbV9bMF0uc2l6ZSgpICsgdGhpcy0+X19hbV9wbV9bMV0uc2l6ZSgpID4gMCkKICAgICAgICB7CiAgICAgICAgICAgIHcgPSB3YmI7CiAgICAgICAgICAgIGkgPSBfX3NjYW5fa2V5d29yZCh3LCB3YmUsIHRoaXMtPl9fYW1fcG1fLCB0aGlzLT5fX2FtX3BtXysyLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3QsIGVyciwgZmFsc2UpIC0gdGhpcy0+X19hbV9wbV87CiAgICAgICAgICAgIGlmIChpIDwgMikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJyUnKTsKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soTCdwJyk7CiAgICAgICAgICAgICAgICB3YmIgPSB3OwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdyA9IHdiYjsKICAgICAgICBpZiAoY3QuaXMoY3R5cGVfYmFzZTo6ZGlnaXQsICp3YmIpKQogICAgICAgIHsKICAgICAgICAgICAgc3dpdGNoKF9fZ2V0X3VwX3RvX25fZGlnaXRzKHdiYiwgd2JlLCBlcnIsIGN0LCA0KSkKICAgICAgICAgICAgewogICAgICAgICAgICBjYXNlIDY6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnJScpOwogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJ3cnKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDc6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnJScpOwogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJ3UnKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDExOgogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJyUnKTsKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soTCdJJyk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAxMjoKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soTCclJyk7CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnbScpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMjM6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnJScpOwogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJ0gnKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDMxOgogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJyUnKTsKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soTCdkJyk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSA1NToKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soTCclJyk7CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnTScpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgNTk6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnJScpOwogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJ1MnKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDYxOgogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJyUnKTsKICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soTCd5Jyk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAzNjQ6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnJScpOwogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJ2onKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDIwNjE6CiAgICAgICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnJScpOwogICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhMJ1knKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgZm9yICg7IHcgIT0gd2JiOyArK3cpCiAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjaygqdyk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgaWYgKGN0Lm5hcnJvdygqd2JiLCAwKSA9PSAnJScpCiAgICAgICAgewogICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnJScpOwogICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKEwnJScpOwogICAgICAgICAgICArK3diYjsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIHJlc3VsdC5wdXNoX2JhY2soKndiYik7CiAgICAgICAgKyt3YmI7CiAgICB9CiAgICByZXR1cm4gcmVzdWx0Owp9Cgp0ZW1wbGF0ZSA8Pgp2b2lkCl9fdGltZV9nZXRfc3RvcmFnZTxjaGFyPjo6aW5pdChjb25zdCBjdHlwZTxjaGFyPiYgY3QpCnsKICAgIHRtIHQ7CiAgICBjaGFyIGJ1ZlsxMDBdOwogICAgLy8gX193ZWVrc18KICAgIGZvciAoaW50IGkgPSAwOyBpIDwgNzsgKytpKQogICAgewogICAgICAgIHQudG1fd2RheSA9IGk7CiAgICAgICAgc3RyZnRpbWVfbChidWYsIDEwMCwgIiVBIiwgJnQsIF9fbG9jXyk7CiAgICAgICAgX193ZWVrc19baV0gPSBidWY7CiAgICAgICAgc3RyZnRpbWVfbChidWYsIDEwMCwgIiVhIiwgJnQsIF9fbG9jXyk7CiAgICAgICAgX193ZWVrc19baSs3XSA9IGJ1ZjsKICAgIH0KICAgIC8vIF9fbW9udGhzXwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAxMjsgKytpKQogICAgewogICAgICAgIHQudG1fbW9uID0gaTsKICAgICAgICBzdHJmdGltZV9sKGJ1ZiwgMTAwLCAiJUIiLCAmdCwgX19sb2NfKTsKICAgICAgICBfX21vbnRoc19baV0gPSBidWY7CiAgICAgICAgc3RyZnRpbWVfbChidWYsIDEwMCwgIiViIiwgJnQsIF9fbG9jXyk7CiAgICAgICAgX19tb250aHNfW2krMTJdID0gYnVmOwogICAgfQogICAgLy8gX19hbV9wbV8KICAgIHQudG1faG91ciA9IDE7CiAgICBzdHJmdGltZV9sKGJ1ZiwgMTAwLCAiJXAiLCAmdCwgX19sb2NfKTsKICAgIF9fYW1fcG1fWzBdID0gYnVmOwogICAgdC50bV9ob3VyID0gMTM7CiAgICBzdHJmdGltZV9sKGJ1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fX2xvY18pOwogICAgICAgIG1iID0gbWJzdGF0ZV90KCk7CiAgICAgICAgYmIgPSBidWY7CiAgICAgICAgaiA9IG1ic3J0b3djc19sKHdidWYsICZiYiwgc2l6ZW9mKHdidWYpL3NpemVvZih3YnVmWzBdKSwgJm1iLCBfX2xvY18pOwogICAgICAgIGlmIChqID09IC0xKQogICAgICAgICAgICBfX3Rocm93X3J1bnRpbWVfZXJyb3IoImxvY2FsZSBub3Qgc3VwcG9ydGVkIik7CiAgICAgICAgd2JlID0gd2J1ZiArIGo7CiAgICAgICAgX193ZWVrc19baSs3XS5hc3NpZ24od2J1Ziwgd2JlKTsKICAgIH0KICAgIC8vIF9fbW9udGhzXwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAxMjsgKytpKQogICAgewogICAgICAgIHQudG1fbW9uID0gaTsKICAgICAgICBiZSA9IHN0cmZ0aW1lX2woYnVmLCAxMDAsICIlQiIsICZ0LCBfX2xvY18pOwogICAgICAgIG1iID0gbWJzdGF0ZV90KCk7CiAgICAgICAgY29uc3QgY2hhciogYmIgPSBidWY7CiAgICAgICAgc2l6ZV90IGogPSBtYnNydG93Y3NfbCh3YnVmLCAmYmIsIHNpemVvZih3YnVmKS9zaXplb2Yod2J1ZlswXSksICZtYiwgX19sb2NfKTsKICAgICAgICBpZiAoaiA9PSAtMSkKICAgICAgICAgICAgX190aHJvd19ydW50aW1lX2Vycm9yKCJsb2NhbGUgbm90IHN1cHBvcnRlZCIpOwogICAgICAgIHdiZSA9IHdidWYgKyBqOwogICAgICAgIF9fbW9udGhzX1tpXS5hc3NpZ24od2J1Ziwgd2JlKTsKICAgICAgICBiZSA9IHN0cmZ0aW1lX2woYnVmLCAxMDAsICIlYiIsICZ0LCBfX2xvY18pOwogICAgICAgIG1iID0gbWJzdGF0ZV90KCk7CiAgICAgICAgYmIgPSBidWY7CiAgICAgICAgaiA9IG1ic3J0b3djc19sKHdidWYsICZiYiwgc2l6ZW9mKHdidWYpL3NpemVvZih3YnVmWz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Y29uc3QgX190aW1lX2dldF90ZW1wPHdjaGFyX3Q+IGN0KF9fbm0pOwogICAgaW5pdChjdCk7Cn0KCnRlbXBsYXRlIDw+Cl9fdGltZV9nZXRfc3RvcmFnZTx3Y2hhcl90Pjo6X190aW1lX2dldF9zdG9yYWdlKGNvbnN0IHN0cmluZyYgX19ubSkKICAgIDogX190aW1lX2dldChfX25tKQp7CiAgICBjb25zdCBfX3RpbWVfZ2V0X3RlbXA8d2NoYXJfdD4gY3QoX19ubSk7CiAgICBpbml0KGN0KTsKfQoKdGVtcGxhdGUgPD4KdGltZV9iYXNlOjpkYXRlb3JkZXIKX190aW1lX2dldF9zdG9yYWdlPGNoYXI+OjpfX2RvX2RhdGVfb3JkZXIoKSBjb25zdAp7CiAgICB1bnNpZ25lZCBpOwogICAgZm9yIChpID0gMDsgaSA8IF9feF8uc2l6ZSgpOyArK2kpCiAgICAgICAgaWYgKF9feF9baV0gPT0gJyUnKQogICAgICAgICAgICBicmVhazsKICAgICsraTsKICAgIHN3aXRjaCAoX194X1tpXSkKICAgIHsKICAgIGNhc2UgJ3knOgogICAgY2FzZSAnWSc6CiAgICAgICAgZm9yICgrK2k7IGkgPCBfX3hfLnNpemUoKTsgKytpKQogICAgICAgICAgICBpZiAoX194X1tpXSA9PSAnJScpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICBpZiAoaSA9PSBfX3hfLnNpemUoKSkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgKytpOwogICAgICAgIHN3aXRjaCAoX194X1tpXSkKICAgICAgICB7CiAgICAgICAgY2FzZSAnbSc6CiAgICAgICAgICAgIGZvciAoKytpOyBpIDwgX194Xy5zaXplKCk7ICsraSkKICAgICAgICAgICAgICAgIGlmIChfX3hfW2ldID09ICclJykKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgaWYgKGkgPT0gX194Xy5zaXplKCkpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgKytpOwogICAgICAgICAgICBpZiAoX194X1tpXSA9PSAnZCcpCiAgICAgICAgICAgICAgICByZXR1cm4gdGltZV9iYXNlOjp5bWQ7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgJ2QnOgogICAgICAgICAgICBmb3IgKCsraTsgaSA8IF9feF8uc2l6ZSgpOyArK2kpCiAgICAgICAgICAgICAgICBpZiAoX194X1tpXSA9PSAnJScpCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGlmIChpID09IF9feF8uc2l6ZSgpKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICsraTsKICAgICAgICAgICAgaWYgKF9feF9baV0gPT0gJ20nKQogICAgICAgICAgICAgICAgcmV0dXJuIHRpbWVfYmFzZTo6eWRtOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgYnJlYWs7CiAgICBjYXNlICdtJzoKICAgICAgICBmb3IgKCsraTsgaSA8IF9feF8uc2l6ZSgpOyArK2kpCiAgICAgICAgICAgIGlmIChfX3hfW2ldID09ICclJykKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGlmIChpID09IF9feF8uc2l6ZSgpKQogICAgICAgICAgICBicmVhazsKICAgICAgICArK2k7CiAgICAgICAgaWYgKF9feF9baV0gPT0gJ2QnKQogICAgICAgIHsKICAgICAgICAgICAgZm9yICgrK2k7IGkgPCBfX3hfLnNpemUoKTsgKytpKQogICAgICAgICAgICAgICAgaWYgKF9feF9baV0gPT0gJyUnKQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBpZiAoaSA9PSBfX3hfLnNpemUoKSkKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICArK2k7CiAgICAgICAgICAgIGlmIChfX3hfW2ldID09ICd5JyB8fCBfX3hfW2ldID09ICdZJykKICAgICAgICAgICAgICAgIHJldHVybiB0aW1lX2Jhc2U6Om1keTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIGJyZWFrOwogICAgY2FzZSAnZCc6CiAgICAgICAgZm9yICgrK2k7IGkgPCBfX3hfLnNpemUoKTsgKytpKQogICAgICAgICAgICBpZiAoX194X1tpXSA9PSAnJScpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICBpZiAoaSA9PSBfX3hfLnNpemUoKSkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgKytpOwogICAgICAgIGlmIChfX3hfW2ldID09ICdtJykKICAgICAgICB7CiAgICAgICAgICAgIGZvciAoKytpOyBpIDwgX194Xy5zaXplKCk7ICsraSkKICAgICAgICAgICAgICAgIGlmIChfX3hfW2ldID09ICclJykKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgaWYgKGkgPT0gX194Xy5zaXplKCkpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgKytpOwogICAgICAgICAgICBpZiAoX194X1tpXSA9PSAneScgfHwgX194X1tpXSA9PSAnWScpCiAgICAgICAgICAgICAgICByZXR1cm4gdGltZV9iYXNlOjpkbXk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBicmVhazsKICAgIH0KICAgIHJldHVybiB0aW1lX2Jhc2U6Om5vX29yZGVyOwp9Cgp0ZW1wbGF0ZSA8Pgp0aW1lX2Jhc2U6OmRhdGVvcmRlcgpfX3RpbWVfZ2V0X3N0b3JhZ2U8d2NoYXJfdD46Ol9fZG9fZGF0ZV9vcmRlcigpIGNvbnN0CnsKICAgIHVuc2lnbmVkIGk7CiAgICBmb3IgKGkgPSAwOyBpIDwgX194Xy5zaXplKCk7ICsraSkKICAgICAgICBpZiAoX194X1tpXSA9PSBMJyUnKQogICAgICAgICAgICBicmVhazsKICAgICsraTsKICAgIHN3aXRjaCAoX194X1tpXSkKICAgIHsKICAgIGNhc2UgTCd5JzoKICAgIGNhc2UgTCdZJzoKICAgICAgICBmb3IgKCsraTsgaSA8IF9feF8uc2l6ZSgpOyArK2kpCiAgICAgICAgICAgIGlmIChfX3hfW2ldID09IEwnJScpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICBpZiAoaSA9PSBfX3hfLnNpemUoKSkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgKytpOwogICAgICAgIHN3aXRjaCAoX194X1tpXSkKICAgICAgICB7CiAgICAgICAgY2FzZSBMJ20nOgogICAgICAgICAgICBmb3IgKCsraTsgaSA8IF9feF8uc2l6ZSgpOyArK2kpCiAgICAgICAgICAgICAgICBpZiAoX194X1tpXSA9PSBMJyUnKQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBpZiAoaSA9PSBfX3hfLnNpemUoKSkKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICArK2k7CiAgICAgICAgICAgIGlmIChfX3hfW2ldID09IEwnZCcpCiAgICAgICAgICAgICAgICByZXR1cm4gdGltZV9iYXNlOjp5bWQ7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgTCdkJzoKICAgICAgICAgICAgZm9yICgrK2k7IGkgPCBfX3hfLnNpemUoKTsgKytpKQogICAgICAgICAgICAgICAgaWYgKF9feF9baV0gPT0gTCclJykKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgaWYgKGkgPT0gX194Xy5zaXplKCkpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgKytpOwogICAgICAgICAgICBpZiAoX194X1tpXSA9PSBMJ20nKQogICAgICAgICAgICAgICAgcmV0dXJuIHRpbWVfYmFzZTo6eWRtOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgYnJlYWs7CiAgICBjYXNlIEwnbSc6CiAgICAgICAgZm9yICgrK2k7IGkgPCBfX3hfLnNpemUoKTsgKytpKQogICAgICAgICAgICBpZiAoX194X1tpXSA9PSBMJyUnKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgaWYgKGkgPT0gX194Xy5zaXplKCkpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICsraTsKICAgICAgICBpZiAoX194X1tpXSA9PSBMJ2QnKQogICAgICAgIHsKICAgICAgICAgICAgZm9yICgrK2k7IGkgPCBfX3hfLnNpemUoKTsgKytpKQogICAgICAgICAgICAgICAgaWYgKF9feF9baV0gPT0gTCclJykKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgaWYgKGkgPT0gX194Xy5zaXplKCkpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgKytpOwogICAgICAgICAgICBpZiAoX194X1tpXSA9PSBMJ3knIHx8IF9feF9baV0gPT0gTCdZJykKICAgICAgICAgICAgICAgIHJldHVybiB0aW1lX2Jhc2U6Om1keTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIGJyZWFrOwogICAgY2FzZSBMJ2QnOgogICAgICAgIGZvciAoKytpOyBpIDwgX194Xy5zaXplKCk7ICsraSkKICAgICAgICAgICAgaWYgKF9feF9baV0gPT0gTCclJykKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGlmIChpID09IF9feF8uc2l6ZSgpKQogICAgICAgICAgICBicmVhazsKICAgICAgICArK2k7CiAgICAgICAgaWYgKF9feF9baV0gPT0gTCdtJykKICAgICAgICB7CiAgICAgICAgICAgIGZvciAoKytpOyBpIDwgX194Xy5zaXplKCk7ICsraSkKICAgICAgICAgICAgICAgIGlmIChfX3hfW2ldID09IEwnJScpCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGlmIChpID09IF9feF8uc2l6ZSgpKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICsraTsKICAgICAgICAgICAgaWYgKF9feF9baV0gPT0gTCd5JyB8fCBfX3hfW2ldID09IEwnWScpCiAgICAgICAgICAgICAgICByZXR1cm4gdGltZV9iYXNlOjpkbXk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBicmVhazsKICAgIH0KICAgIHJldHVybiB0aW1lX2Jhc2U6Om5vX29yZGVyOwp9CgovLyB0aW1lX3B1dAoKX190aW1lX3B1dDo6X190aW1lX3B1dChjb25zdCBjaGFyKiBubSkKICAgIDogX19sb2NfKG5ld2xvY2FsZShMQ19BTExfTUFTSywgbm0sIDApKQp7CiAgICBpZiAoX19sb2NfID09IDApCiAgICAgICAgdGhyb3cgcnVudGltZV9lcnJvcigidGltZV9wdXRfYnluYW1lIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgIiBmYWlsZWQgdG8gY29uc3RydWN0IGZvciAiICsgc3RyaW5nKG5tKSk7Cn0KCl9fdGltZV9wdXQ6Ol9fdGltZV9wdXQoY29uc3Qgc3RyaW5nJiBubSkKICAgIDogX19sb2NfKG5ld2xvY2FsZShMQ19BTExfTUFTSywgbm0uY19zdHIoKSwgMCkpCnsKICAgIGlmIChfX2xvY18gPT0gMCkKICAgICAgICB0aHJvdyBydW50aW1lX2Vycm9yKCJ0aW1lX3B1dF9ieW5hbWUiCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAiIGZhaWxlZCB0byBjb25zdHJ1Y3QgZm9yICIgKyBubSk7Cn0KCl9fdGltZV9wdXQ6On5fX3RpbWVfcHV0KCkKewogICAgaWYgKF9fbG9jXykKICAgICAgICBmcmVlbG9jYWxlKF9fbG9jXyk7Cn0KCnZvaWQKX190aW1lX3B1dDo6X19kb19wdXQoY2hhciogX19uYiwgY2hhciomIF9fbmUsIGNvbnN0IHRtKiBfX3RtLAogICAgICAgICAgICAgICAgICAgICBjaGFyIF9fZm10LCBjaGFyIF9fbW9kKSBjb25zdAp7CiAgICBjaGFyIGZtdFtdID0geyclJywgX19mbXQsIF9fbW9kLCAwfTsKICAgIGlmIChfX21vZCAhPSAwKQogICAgICAgIHN3YXAoZm10WzFdLCBmbXRbMl0pOwogICAgc2l6ZV90IG4gPSBzdHJmdGltZV9sKF9fbmIsIF9fbmUtX19uYiwgZm10LCBfX3RtLCBfX2xvY18pOwogICAgX19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Y2hhciB2YWx1ZSA9IHN0YXRpY19jYXN0PGNoYXI+KG1vbmV5X2Jhc2U6OnZhbHVlKTsKICAgIHN3aXRjaCAoY3NfcHJlY2VkZXMpCiAgICB7CiAgICBjYXNlIDA6CiAgICAgICAgc3dpdGNoIChzaWduX3Bvc24pCiAgICAgICAgewogICAgICAgIGNhc2UgMDoKICAgICAgICAgICAgcGF0LmZpZWxkWzBdID0gc2lnbjsKICAgICAgICAgICAgcGF0LmZpZWxkWzFdID0gdmFsdWU7CiAgICAgICAgICAgIHBhdC5maWVsZFszXSA9IHN5bWJvbDsKICAgICAgICAgICAgc3dpdGNoIChzZXBfYnlfc3BhY2UpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzJdID0gbm9uZTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSBzcGFjZTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgMToKICAgICAgICAgICAgcGF0LmZpZWxkWzBdID0gc2lnbjsKICAgICAgICAgICAgcGF0LmZpZWxkWzNdID0gc3ltYm9sOwogICAgICAgICAgICBzd2l0Y2ggKHNlcF9ieV9zcGFjZSkKICAgICAgICAgICAgewogICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMV0gPSB2YWx1ZTsKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsyXSA9IG5vbmU7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IHZhbHVlOwogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzJdID0gc3BhY2U7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IHNwYWNlOwogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzJdID0gdmFsdWU7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgIHBhdC5maWVsZFswXSA9IHZhbHVlOwogICAgICAgICAgICBwYXQuZmllbGRbM10gPSBzaWduOwogICAgICAgICAgICBzd2l0Y2ggKHNlcF9ieV9zcGFjZSkKICAgICAgICAgICAgewogICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMV0gPSBub25lOwogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzJdID0gc3ltYm9sOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMV0gPSBzcGFjZTsKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsyXSA9IHN5bWJvbDsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzFdID0gc3ltYm9sOwogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzJdID0gc3BhY2U7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgIHBhdC5maWVsZFswXSA9IHZhbHVlOwogICAgICAgICAgICBwYXQuZmllbGRbM10gPSBzeW1ib2w7CiAgICAgICAgICAgIHN3aXRjaCAoc2VwX2J5X3NwYWNlKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMDoKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IG5vbmU7CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSBzaWduOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMV0gPSBzcGFjZTsKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsyXSA9IHNpZ247CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IHNpZ247CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSBzcGFjZTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgcGF0LmZpZWxkWzBdID0gdmFsdWU7CiAgICAgICAgICAgIHBhdC5maWVsZFszXSA9IHNpZ247CiAgICAgICAgICAgIHN3aXRjaCAoc2VwX2J5X3NwYWNlKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMDoKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IG5vbmU7CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSBzeW1ib2w7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IHNwYWNlOwogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzJdID0gc3ltYm9sOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMV0gPSBzeW1ib2w7CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSBzcGFjZTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBicmVhazsKICAgIGNhc2UgMToKICAgICAgICBzd2l0Y2ggKHNpZ25fcG9zbikKICAgICAgICB7CiAgICAgICAgY2FzZSAwOgogICAgICAgICAgICBwYXQuZmllbGRbMF0gPSBzaWduOwogICAgICAgICAgICBwYXQuZmllbGRbMV0gPSBzeW1ib2w7CiAgICAgICAgICAgIHBhdC5maWVsZFszXSA9IHZhbHVlOwogICAgICAgICAgICBzd2l0Y2ggKHNlcF9ieV9zcGFjZSkKICAgICAgICAgICAgewogICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSBub25lOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsyXSA9IHNwYWNlOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSAxOgogICAgICAgICAgICBwYXQuZmllbGRbMF0gPSBzaWduOwogICAgICAgICAgICBwYXQuZmllbGRbM10gPSB2YWx1ZTsKICAgICAgICAgICAgc3dpdGNoIChzZXBfYnlfc3BhY2UpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzFdID0gc3ltYm9sOwogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzJdID0gbm9uZTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzFdID0gc3ltYm9sOwogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzJdID0gc3BhY2U7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IHNwYWNlOwogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzJdID0gc3ltYm9sOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSAyOgogICAgICAgICAgICBwYXQuZmllbGRbMF0gPSBzeW1ib2w7CiAgICAgICAgICAgIHBhdC5maWVsZFszXSA9IHNpZ247CiAgICAgICAgICAgIHN3aXRjaCAoc2VwX2J5X3NwYWNlKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMDoKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IG5vbmU7CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSB2YWx1ZTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzFdID0gc3BhY2U7CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSB2YWx1ZTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzFdID0gdmFsdWU7CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSBzcGFjZTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgcGF0LmZpZWxkWzBdID0gc2lnbjsKICAgICAgICAgICAgcGF0LmZpZWxkWzNdID0gdmFsdWU7CiAgICAgICAgICAgIHN3aXRjaCAoc2VwX2J5X3NwYWNlKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGNhc2UgMDoKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IHN5bWJvbDsKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsyXSA9IG5vbmU7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IHN5bWJvbDsKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsyXSA9IHNwYWNlOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMV0gPSBzcGFjZTsKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsyXSA9IHN5bWJvbDsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgcGF0LmZpZWxkWzBdID0gc3ltYm9sOwogICAgICAgICAgICBwYXQuZmllbGRbM10gPSB2YWx1ZTsKICAgICAgICAgICAgc3dpdGNoIChzZXBfYnlfc3BhY2UpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzFdID0gc2lnbjsKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsyXSA9IG5vbmU7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgIHBhdC5maWVsZFsxXSA9IHNpZ247CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSBzcGFjZTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgcGF0LmZpZWxkWzFdID0gc3BhY2U7CiAgICAgICAgICAgICAgICBwYXQuZmllbGRbMl0gPSBzaWduOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgYnJlYWs7CiAgICBkZWZhdWx0OgogICAgICAgIGJyZWFrOwogICAgfQogICAgcGF0LmZpZWxkWzBdID0gc3ltYm9sOwogICAgcGF0LmZpZWxkWzFdID0gc2lnbjsKICAgIHBhdC5maWVsZFsyXSA9IG5vbmU7CiAgICBwYXQuZmllbGRbM10gPSB2YWx1ZTsKfQoKdGVtcGxhdGU8Pgp2b2lkCm1vbmV5cHVuY3RfYnluYW1lPGNoYXIsIGZhbHNlPjo6aW5pdChjb25zdCBjaGFyKiBubSkKewogICAgdHlwZWRlZiBtb25leXB1bmN0PGNoYXIsIGZhbHNlPiBiYXNlOwogICAgdW5pcXVlX3B0cjxfeGxvY2FsZSwgaW50KCopKGxvY2FsZV90KT4gIGxvYyhuZXdsb2NhbGUoTENfQUxMX01BU0ssIG5tLCAwKSwgZnJlZWxvY2FsZSk7CiAgICBpZiAobG9jID09IDApCiAgICAgICAgdGhyb3cgcnVudGltZV9lcnJvcigibW9uZXlwdW5jdF9ieW5hbWUiCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAiIGZhaWxlZCB0byBjb25zdHJ1Y3QgZm9yICIgKyBzdHJpbmcobm0pKTsKICAgIGxjb252KiBsYyA9IGxvY2FsZWNvbnZfbChsb2MuZ2V0KCkpOwogICAgaWYgKCpsYy0+bW9uX2RlY2ltYWxfc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Sk7CiAgICBpZiAobGMtPmZyYWNfZGlnaXRzICE9IENIQVJfTUFYKQogICAgICAgIF9fZnJhY19kaWdpdHNfID0gbGMtPmZyYWNfZGlnaXRzOwogICAgZWxzZQogICAgICAgIF9fZnJhY19kaWdpdHNfID0gYmFzZTo6ZG9fZnJhY19kaWdpdHMoKTsKICAgIGlmIChsYy0+cF9zaWduX3Bvc24gPT0gMCkKICAgICAgICBfX3Bvc2l0aXZlX3NpZ25fID0gTCIoKSI7CiAgICBlbHNlCiAgICB7CiAgICAgICAgbWIgPSBtYnN0YXRlX3QoKTsKICAgICAgICBiYiA9IGxjLT5wb3NpdGl2ZV9zaWduOwogICAgICAgIGogPSBtYnNydG93Y3NfbCh3YnVmLCAmYmIsIHNpemVvZih3YnVmKS9zaXplb2Yod2J1ZlswXSksICZtYiwgbG9jLmdldCgpKTsKICAgICAgICBpZiAoaiA9PSAtMSkKICAgICAgICAgICAgX190aHJvd19ydW50aW1lX2Vycm9yKCJsb2NhbGUgbm90IHN1cHBvcnRlZCIpOwogICAgICAgIHdiZSA9IHdidWYgKyBqOwogICAgICAgIF9fcG9zaXRpdmVfc2lnbl8uYXNzaWduKHdidWYsIHdiZSk7CiAgICB9CiAgICBpZiAobGMtPm5fc2lnbl9wb3NuID09IDApCiAgICAgICAgX19uZWdhdGl2ZV9zaWduXyA9IEwiKCkiOwogICAgZWxzZQogICAgewogICAgICAgIG1iID0gbWJzdGF0ZV90KCk7CiAgICAgICAgYmIgPSBsYy0+bmVnYXRpdmVfc2lnbjsKICAgICAgICBqID0gbWJzcnRvd2NzX2wod2J1ZiwgJmJiLCBzaXplb2Yod2J1Zikvc2l6ZW9mKHdidWZbMF0pLCAmbWIsIGxvYy5nZXQoKSk7CiAgICAgICAgaWYgKGogPT0gLTEpCiAgICAgICAgICAgIF9fdGhyb3dfcnVudGltZV9lcnJvcigibG9jYWxlIG5vdCBzdXBwb3J0ZWQiKTsKICAgICAgICB3YmUgPSB3YnVmICsgajsKICAgICAgICBf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