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vZih4WzBdKTsKICAgIGZvciAodW5zaWduZWQgaSA9IDA7IGkgPCBOOyArK2kpCiAgICB7CiAgICAgICAgc3RkOjpjb21wbGV4PGRvdWJsZT4gciA9IGxvZyh4W2ldKTsKICAgICAgICBpZiAoeFtpXS5yZWFsKCkgPT0gMCAmJiB4W2ldLmltYWcoKSA9PSAwKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKHN0ZDo6c2lnbmJpdCh4W2ldLnJlYWwoKSkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGFzc2VydChzdGQ6OmlzaW5mKHIucmVhbCgpKSk7CiAgICAgICAgICAgICAgICBhc3NlcnQoci5yZWFsKCkgPCAwKTsKICAgICAgICAgICAgICAgIGlmIChzdGQ6OnNpZ25iaXQoeFtpXS5pbWFnKCkpKQogICAgICAgICAgICAgICAgICAgIGlzX2Fib3V0KHIuaW1hZygpLCAtcGkpOwogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgIGlzX2Fib3V0KHIuaW1hZygpLCBwaSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBhc3NlcnQoc3RkOjppc2luZihyLnJlYWwoKSkpOwogICAgICAgICAgICAgICAgYXNzZXJ0KHIucmVhbCgpIDwgMCk7CiAgICAgICAgICAgICAgICBhc3NlcnQoci5pbWFnKCkgPT0gMCk7CiAgICAgICAgICAgICAgICBhc3NlcnQoc3RkOjpzaWduYml0KHhbaV0uaW1hZygpKSA9PSBzdGQ6OnNpZ25iaXQoci5pbWFnKCkpKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChzdGQ6OmlzZmluaXRlKHhbaV0ucmVhbCgpKSAmJiBzdGQ6OmlzaW5mKHhbaV0uaW1hZygpKSkKICAgICAgICB7CiAgICAgICAgICAgIGFzc2VydChzdGQ6OmlzaW5mKHIucmVhbCgpKSk7CiAgICAgICAgICAgIGFzc2VydChyLnJlYWwoKSA+IDApOwogICAgICAgICAgICBpZiAoeFtpXS5pbWFnKCkgPiAwKQogICAgICAgICAgICAgICAgaXNfYWJvdXQoci5pbWFnKCksIHBpLzIpOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBpc19hYm91dChyLmltYWcoKSwgLXBpLzIpOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChzdGQ6OmlzZmluaXRlKHhbaV0ucmVhbCgpKSAmJiBzdGQ6OmlzbmFuKHhbaV0uaW1hZygpKSkKICAgICAgICB7CiAgICAgICAgICAgIGFzc2VydChzdGQ6OmlzbmFuKHIucmVhbCgpKSk7CiAgICAgICAgICAgIGFzc2VydChzdGQ6OmlzbmFuKHIuaW1hZygpKSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKHN0ZDo6aXNpbmYoeFtpXS5yZWFsKCkpICYmIHhbaV0ucmVhbCgpIDwgMCAmJiBzdGQ6OmlzZmluaXRlKHhbaV0uaW1hZygpKSkKICAgICAgICB7CiAgICAgICAgICAgIGFzc2VydChzdGQ6OmlzaW5mKHIucmVhbCgpKSAmJiByLnJlYWwoKSA+IDApOwogICAgICAgICAgICBpZiAoci5pbWFnKCkgPiAwKQogICAgICAgICAgICAgICAgaXNfYWJvdXQoci5pbWFnKCksIHBpKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgaXNfYWJvdXQoci5pbWFnKCksIC1waSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKHN0ZDo6aXNpbmYoeFtpXS5yZWFsKCkpICYmIHhbaV0ucmVhbCgpID4gMCAmJiBzdGQ6OmlzZmluaXRlKHhbaV0uaW1hZygpKSkKICAgICAgICB7CiAgICAgICAgICAgIGFzc2VydChzdGQ6OmlzaW5mKHIucmVhbCgpKSAmJiByLnJlYWwoKSA+IDApOwogICAgICAgICAgICBhc3NlcnQoci5pbWFnKCkgPT0gMCk7CiAgICAgICAgICAgIGFzc2VydChzdGQ6OnNpZ25iaXQoeFtpXS5pbWFnKCkpID09IHN0ZDo6c2lnbmJpdChyLmltYWcoKSkpOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmICh4W2ldLnJlYWwoKSA9PSAxICYmIHhbaV0uaW1hZygpID09IDApCiAgICAgICAgewogICAgICAgICAgICBhc3NlcnQoci5yZWFsKCkgPT0gMCk7CiAgICAgICAgICAgIGFzc2VydChzdGQ6OnNpZ25iaXQoci5pbWFnKCkpID09IHN0ZDo6c2lnbmJpdCh4W2ldLmltYWcoKSkpOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmICh4W2ldLnJlYWwoKSA9PSAwICYmIHhbaV0uaW1hZygpID09IDEpCiAgICAgICAgewogICAgICAgICAgICBhc3NlcnQoci5yZWFsKCkgPT0gMCk7CiAgICAgICAgICAgIGlzX2Fib3V0KHIuaW1hZygpLCBwaS8yKTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoeFtpXS5yZWFsKCkgPT0gLTEgJiYgeFtpXS5pbWFnKCkgPT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIGFzc2VydChyLnJlYWwoKSA9PSAwKTsKICAgICAgICAgICAgaWYgKHN0ZDo6c2lnbmJpdCh4W2ldLmltYWcoKSkpCiAgICAgICAgICAgICAgICBpc19hYm91dChyLmltYWcoKSwgLXBpKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgaXNfYWJvdXQoci5pbWFnKCksICBwaSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKHhbaV0ucmVhbCgpID09IDAgJiYgeFtpXS5pbWFnKCkgPT0gLTEpCiAgICAgICAgewogICAgICAgICAgICBhc3NlcnQoci5yZWFsKCkgPT0gMCk7CiAgICAgICAgICAgIGlzX2Fib3V0KHIuaW1hZygpLCAtcGkvMik7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKHN0ZDo6aXNmaW5pdGUoeFtpXS5yZWFsKCkpICYmIHN0ZDo6aXNmaW5pdGUoeFtpXS5pbWFnKCkpICYmIGFicyh4W2ldKSA8IDEpCiAgICAgICAgewogICAgICAgICAgICBhc3NlcnQoIHN0ZDo6c2lnbmJpdChyLnJlYWwoKSkpOwogICAgICAgICAgICBhc3NlcnQoc3RkOjpzaWduYml0KHIuaW1hZygpKSA9PSBzdGQ6OnNpZ25iaXQoeFtpXS5pbWFnKCkpKTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoc3RkOjppc2Zpbml0ZSh4W2ldLnJlYWwoKSkgJiYgc3RkOjppc2Zpbml0ZSh4W2ldLmltYWcoKSkgJiYgYWJzKHhbaV0pID4gMSkKICAgICAgICB7CiAgICAgICAgICAgIGFzc2VydCghc3RkOjpzaWduYml0KHIucmVhbCgpKSk7CiAgICAgICAgICAgIGFzc2VydChzdGQ6OnNpZ25iaXQoci5pbWFnKCkpID09IHN0ZDo6c2lnbmJpdCh4W2ldLmltYWcoKSkpOwogICAgICAgIH0KICAgIH0KfQoKaW50IG1haW4oKQp7CiAgICB0ZXN0PGZsb2F0PigpOwogICAgdGVzdDxkb3VibGU+KCk7CiAgICB0ZXN0PGxvbmcgZG91YmxlPigpOwogICAgdGVzdF9lZGdlcygpOwp9Cg==