-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsample_overview.html
20 lines (19 loc) · 805 KB
/
sample_overview.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>chromoMap</title>
<script src="data:application/x-javascript;base64,KGZ1bmN0aW9uKCkgewogIC8vIElmIHdpbmRvdy5IVE1MV2lkZ2V0cyBpcyBhbHJlYWR5IGRlZmluZWQsIHRoZW4gdXNlIGl0OyBvdGhlcndpc2UgY3JlYXRlIGEKICAvLyBuZXcgb2JqZWN0LiBUaGlzIGFsbG93cyBwcmVjZWRpbmcgY29kZSB0byBzZXQgb3B0aW9ucyB0aGF0IGFmZmVjdCB0aGUKICAvLyBpbml0aWFsaXphdGlvbiBwcm9jZXNzICh0aG91Z2ggbm9uZSBjdXJyZW50bHkgZXhpc3QpLgogIHdpbmRvdy5IVE1MV2lkZ2V0cyA9IHdpbmRvdy5IVE1MV2lkZ2V0cyB8fCB7fTsKCiAgLy8gU2VlIGlmIHdlJ3JlIHJ1bm5pbmcgaW4gYSB2aWV3ZXIgcGFuZS4gSWYgbm90LCB3ZSdyZSBpbiBhIHdlYiBicm93c2VyLgogIHZhciB2aWV3ZXJNb2RlID0gd2luZG93LkhUTUxXaWRnZXRzLnZpZXdlck1vZGUgPQogICAgICAvXGJ2aWV3ZXJfcGFuZT0xXGIvLnRlc3Qod2luZG93LmxvY2F0aW9uKTsKCiAgLy8gU2VlIGlmIHdlJ3JlIHJ1bm5pbmcgaW4gU2hpbnkgbW9kZS4gSWYgbm90LCBpdCdzIGEgc3RhdGljIGRvY3VtZW50LgogIC8vIE5vdGUgdGhhdCBzdGF0aWMgd2lkZ2V0cyBjYW4gYXBwZWFyIGluIGJvdGggU2hpbnkgYW5kIHN0YXRpYyBtb2RlcywgYnV0CiAgLy8gb2J2aW91c2x5LCBTaGlueSB3aWRnZXRzIGNhbiBvbmx5IGFwcGVhciBpbiBTaGlueSBh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XQtZXJyb3IiOwogICAgICBpZiAoZXJyLnR5cGUgIT09IG51bGwpIHsKICAgICAgICAvLyB1c2UgdGhlIGNsYXNzZXMgb2YgdGhlIGVycm9yIGNvbmRpdGlvbiBhcyBDU1MgY2xhc3MgbmFtZXMKICAgICAgICBlcnJDbGFzcyA9IGVyckNsYXNzICsgIiAiICsgJC5tYXAoYXNBcnJheShlcnIudHlwZSksIGZ1bmN0aW9uKHR5cGUpIHsKICAgICAgICAgIHJldHVybiBlcnJDbGFzcyArICItIiArIHR5cGU7CiAgICAgICAgfSkuam9pbigiICIpOwogICAgICB9CiAgICAgIGVyckNsYXNzID0gZXJyQ2xhc3MgKyAiIGh0bWx3aWRnZXRzLWVycm9yIjsKCiAgICAgIC8vIElzIGVsIGlubGluZSBvciBibG9jaz8gSWYgaW5saW5lIG9yIGlubGluZS1ibG9jaywganVzdCBkaXNwbGF5Om5vbmUgaXQKICAgICAgLy8gYW5kIGFkZCBhbiBpbmxpbmUgZXJyb3IuCiAgICAgIHZhciBkaXNwbGF5ID0gJGVsLmNzcygiZGlzcGxheSIpOwogICAgICAkZWwuZGF0YSgicmVzdG9yZS1kaXNwbGF5LW1vZGUiLCBkaXNwbGF5KTsKCiAgICAgIGlmIChkaXNwbGF5ID09PSAiaW5saW5lIiB8fCBkaXNwbGF5ID09PSAiaW5saW5lLWJsb2NrIikgewogICAgICAgICRlbC5oaWRlKCk7CiAgICAgICAgaWYgKGVyci5tZXNzYWdlICE9PSAiIikgewogICAgICAgICAgdmFyIGVycm9yU3BhbiA9ICQoIjxzcGFuPiIpLmFkZENsYXNzKGVyckNsYXNzKTsKICAgICAgICAgIGVycm9yU3Bhbi50ZXh0KGVyci5tZXNzYWdlKTsKICAgICAgICAgICRlbC5hZnRlcihlcnJvclNwYW4pOwogICAgICAgIH0KICAgICAgfSBlbHNlIGlmIChkaXNwbGF5ID09PSAiYmxvY2siKSB7CiAgICAgICAgLy8gSWYgYmxvY2ssIGFkZCBhbiBlcnJvciBqdXN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ZWVwIHRoZSBzaXplL3Bvc2l0aW9uIG9mIHRoZSBlcnJvciBpbiBzeW5jIHdpdGgKICAgICAgICAgIC8vIHRoZSBwYXJlbnQgZWxlbWVudCBhcyB0aGUgd2luZG93IGlzIHJlc2l6ZWQgb3Igd2hhdGV2ZXIuCiAgICAgICAgICB2YXIgaW50SWQgPSBzZXRJbnRlcnZhbChmdW5jdGlvbigpIHsKICAgICAgICAgICAgaWYgKCFlcnJvckRpdlswXS5wYXJlbnRFbGVtZW50KSB7CiAgICAgICAgICAgICAgY2xlYXJJbnRlcnZhbChpbnRJZCk7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVycm9yRGl2CiAgICAgICAgICAgICAgLmNzcygidG9wIiwgZWwub2Zmc2V0VG9wKQogICAgICAgICAgICAgIC5jc3MoImxlZnQiLCBlbC5vZmZzZXRMZWZ0KQogICAgICAgICAgICAgIC5jc3MoIm1heFdpZHRoIiwgZWwub2Zmc2V0V2lkdGgpCiAgICAgICAgICAgICAgLmNzcygiaGVpZ2h0IiwgZWwub2Zmc2V0SGVpZ2h0KTsKICAgICAgICAgIH0sIDUwMCk7CiAgICAgICAgfQogICAgICB9CiAgICB9LAogICAgY2xlYXJFcnJvcjogZnVuY3Rpb24oZWwpIHsKICAgICAgdmFyICRlbCA9ICQoZWwpOwogICAgICB2YXIgZGlzcGxheSA9ICRlbC5kYXRhKCJyZXN0b3JlLWRpc3BsYXktbW9kZSIpOwogICAgICAkZWwuZGF0YSgicmVzdG9yZS1kaXNwbGF5LW1vZGUiLCBudWxsKTsKCiAgICAgIGlmIChkaXNwbGF5ID09PSAiaW5saW5lIiB8fCBkaXNwbGF5ID09PSAiaW5saW5lLWJsb2NrIikgewogICAgICAgIGlmIChkaXNwbGF5KQogICAgICAgICAgJGVsLmNzcygiZGlzcGxheSIsIGRpc3BsYXkpOwogICAgICAgICQoZWwubmV4dFNpYmxpbmcpLmZpbHRlcigiLmh0bWx3aWRnZ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W5nRGVmLnJlbmRlck9uTnVsbFZhbHVlKSB7CiAgICAgICAgICBpZiAoZGF0YS54ID09PSBudWxsKSB7CiAgICAgICAgICAgIGVsLnN0eWxlLnZpc2liaWxpdHkgPSAiaGlkZGVuIjsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZWwuc3R5bGUudmlzaWJpbGl0eSA9ICJpbmhlcml0IjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKCFlbGVtZW50RGF0YShlbCwgImluaXRpYWxpemVkIikpIHsKICAgICAgICAgIGluaXRTaXppbmcoZWwpOwoKICAgICAgICAgIGVsZW1lbnREYXRhKGVsLCAiaW5pdGlhbGl6ZWQiLCB0cnVlKTsKICAgICAgICAgIGlmIChiaW5kaW5nRGVmLmluaXRpYWxpemUpIHsKICAgICAgICAgICAgdmFyIHJlc3VsdCA9IGJpbmRpbmdEZWYuaW5pdGlhbGl6ZShlbCwgZWwub2Zmc2V0V2lkdGgsCiAgICAgICAgICAgICAgZWwub2Zmc2V0SGVpZ2h0KTsKICAgICAgICAgICAgZWxlbWVudERhdGEoZWwsICJpbml0X3Jlc3VsdCIsIHJlc3VsdCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGJpbmRpbmdEZWYucmVuZGVyVmFsdWUoZWwsIGRhdGEueCwgZWxlbWVudERhdGEoZWwsICJpbml0X3Jlc3VsdCIpKTsKICAgICAgICBldmFsQW5kUnVuKGRhdGEuanNIb29rcy5yZW5kZXIsIGVsZW1lbnREYXRhKGVsLCAiaW5pdF9yZXN1bHQiKSwgW2VsLCBkYXRhLnhdKTsKICAgICAgfTsKCiAgICAgIC8vIE9ubHkgb3ZlcnJpZGUgcmVzaXplIGlmIGJpbmRpbmdEZWYgaW1wbGVtZW50cyBpdAogICAgICBpZiAoYmluZGluZ0RlZi5yZXNpemUpIHsKICAgICAgICBzaGlueUJpbmRpbmcucmVzaXplID0gZnVuY3Rpb24o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LAogICAgICAgICAgICBoOiBzaXplT2JqID8gc2l6ZU9iai5nZXRIZWlnaHQoKSA6IGVsLm9mZnNldEhlaWdodAogICAgICAgICAgfTsKICAgICAgICAgIHZhciByZXNpemVIYW5kbGVyID0gZnVuY3Rpb24oZSkgewogICAgICAgICAgICB2YXIgc2l6ZSA9IHsKICAgICAgICAgICAgICB3OiBzaXplT2JqID8gc2l6ZU9iai5nZXRXaWR0aCgpIDogZWwub2Zmc2V0V2lkdGgsCiAgICAgICAgICAgICAgaDogc2l6ZU9iaiA/IHNpemVPYmouZ2V0SGVpZ2h0KCkgOiBlbC5vZmZzZXRIZWlnaHQKICAgICAgICAgICAgfTsKICAgICAgICAgICAgaWYgKHNpemUudyA9PT0gMCAmJiBzaXplLmggPT09IDApCiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICBpZiAoc2l6ZS53ID09PSBsYXN0U2l6ZS53ICYmIHNpemUuaCA9PT0gbGFzdFNpemUuaCkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGxhc3RTaXplID0gc2l6ZTsKICAgICAgICAgICAgYmluZGluZy5yZXNpemUoZWwsIHNpemUudywgc2l6ZS5oLCBpbml0UmVzdWx0KTsKICAgICAgICAgIH07CgogICAgICAgICAgb24od2luZG93LCAicmVzaXplIiwgcmVzaXplSGFuZGxlcik7CgogICAgICAgICAgLy8gVGhpcyBpcyBuZWVkZWQgZm9yIGNhc2VzIHdoZXJlIHdlJ3JlIHJ1bm5pbmcgaW4gYSBTaGlueQogICAgICAgICAgLy8gYXBwLCBidXQgdGhlIHdpZGdldCBpdHNlbGYgaXMgbm90IGEgU2hpbnkgb3V0cHV0LCBidXQKICAgICAgICAgIC8vIHJhdGhlciBhIHNpbXBsZSBzdGF0aWMgd2lkZ2V0LiBPbmUgZXhhbXBsZSBvZiB0aGlzIGlzCiAgICAgICAgICAvLyBhbiBybWFya2Rvd24gZG9jdW1lbnQgdGhhdCBoYXMgcnVudGltZTpzaGlueSBhbm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CAtIDFdICsgMC41LAogICAgICAgIHBvc2l0aW9uID0gKHNjYWxlLmJhbmR3aWR0aCA/IGNlbnRlciA6IG51bWJlciQxKShzY2FsZS5jb3B5KCkpLAogICAgICAgIHNlbGVjdGlvbiA9IGNvbnRleHQuc2VsZWN0aW9uID8gY29udGV4dC5zZWxlY3Rpb24oKSA6IGNvbnRleHQsCiAgICAgICAgcGF0aCA9IHNlbGVjdGlvbi5zZWxlY3RBbGwoIi5kb21haW4iKS5kYXRhKFtudWxsXSksCiAgICAgICAgdGljayA9IHNlbGVjdGlvbi5zZWxlY3RBbGwoIi50aWNrIikuZGF0YSh2YWx1ZXMsIHNjYWxlKS5vcmRlcigpLAogICAgICAgIHRpY2tFeGl0ID0gdGljay5leGl0KCksCiAgICAgICAgdGlja0VudGVyID0gdGljay5lbnRlcigpLmFwcGVuZCgiZyIpLmF0dHIoImNsYXNzIiwgInRpY2siKSwKICAgICAgICBsaW5lID0gdGljay5zZWxlY3QoImxpbmUiKSwKICAgICAgICB0ZXh0ID0gdGljay5zZWxlY3QoInRleHQiKTsKCiAgICBwYXRoID0gcGF0aC5tZXJnZShwYXRoLmVudGVyKCkuaW5zZXJ0KCJwYXRoIiwgIi50aWNrIikKICAgICAgICAuYXR0cigiY2xhc3MiLCAiZG9tYWluIikKICAgICAgICAuYXR0cigic3Ryb2tlIiwgIiMwMDAiKSk7CgogICAgdGljayA9IHRpY2subWVyZ2UodGlja0VudGVyKTsKCiAgICBsaW5lID0gbGluZS5tZXJnZSh0aWNrRW50ZXIuYXBwZW5kKCJsaW5lIikKICAgICAgICAuYXR0cigic3Ryb2tlIiwgIiMwMDAiKQogICAgICAgIC5hdHRyKHggKyAiMiIsIGsgKiB0aWNrU2l6ZUlubmVyKSk7CgogICAgdGV4dCA9IHRleHQubWVyZ2UodGlja0VudGVyLmFwcGVuZCgidGV4dCIpCiAgICAgICAgLmF0dHIoImZpbGwiLCAiIzAwMCIpCiAgICAgICAgLmF0dHIoeCwgayAqIHNwYW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AgKyAiSDAuNVYiICsgcmFuZ2UxICsgIkgiICsgayAqIHRpY2tTaXplT3V0ZXIKICAgICAgICAgICAgOiAiTSIgKyByYW5nZTAgKyAiLCIgKyBrICogdGlja1NpemVPdXRlciArICJWMC41SCIgKyByYW5nZTEgKyAiViIgKyBrICogdGlja1NpemVPdXRlcik7CgogICAgdGljawogICAgICAgIC5hdHRyKCJvcGFjaXR5IiwgMSkKICAgICAgICAuYXR0cigidHJhbnNmb3JtIiwgZnVuY3Rpb24oZCkgeyByZXR1cm4gdHJhbnNmb3JtKHBvc2l0aW9uKGQpKTsgfSk7CgogICAgbGluZQogICAgICAgIC5hdHRyKHggKyAiMiIsIGsgKiB0aWNrU2l6ZUlubmVyKTsKCiAgICB0ZXh0CiAgICAgICAgLmF0dHIoeCwgayAqIHNwYWNpbmcpCiAgICAgICAgLnRleHQoZm9ybWF0KTsKCiAgICBzZWxlY3Rpb24uZmlsdGVyKGVudGVyaW5nKQogICAgICAgIC5hdHRyKCJmaWxsIiwgIm5vbmUiKQogICAgICAgIC5hdHRyKCJmb250LXNpemUiLCAxMCkKICAgICAgICAuYXR0cigiZm9udC1mYW1pbHkiLCAic2Fucy1zZXJpZiIpCiAgICAgICAgLmF0dHIoInRleHQtYW5jaG9yIiwgb3JpZW50ID09PSByaWdodCA/ICJzdGFydCIgOiBvcmllbnQgPT09IGxlZnQgPyAiZW5kIiA6ICJtaWRkbGUiKTsKCiAgICBzZWxlY3Rpb24KICAgICAgICAuZWFjaChmdW5jdGlvbigpIHsgdGhpcy5fX2F4aXMgPSBwb3NpdGlvbjsgfSk7CiAgfQoKICBheGlzLnNjYWxlID0gZnVuY3Rpb24oXykgewogICAgcmV0dXJuIGFyZ3VtZW50cy5sZW5ndGggPyAoc2NhbGUgPSBfLCBheGlzKSA6IHNjYWxlOwogIH07CgogIGF4aXMudGlja3MgPSBmdW5jdGlvbigpIHsKICAgIHJldHVybiB0aWNrQXJndW1lbnRzID0gc2xpY2UkMS5jYWxsKGFyZ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gKiBrLCB0aGlzLm9wYWNpdHkpOwogIH0sCiAgcmdiOiBmdW5jdGlvbigpIHsKICAgIHZhciBoID0gaXNOYU4odGhpcy5oKSA/IDAgOiAodGhpcy5oICsgMTIwKSAqIGRlZzJyYWQsCiAgICAgICAgbCA9ICt0aGlzLmwsCiAgICAgICAgYSA9IGlzTmFOKHRoaXMucykgPyAwIDogdGhpcy5zICogbCAqICgxIC0gbCksCiAgICAgICAgY29zaCA9IE1hdGguY29zKGgpLAogICAgICAgIHNpbmggPSBNYXRoLnNpbihoKTsKICAgIHJldHVybiBuZXcgUmdiKAogICAgICAyNTUgKiAobCArIGEgKiAoQSAqIGNvc2ggKyBCICogc2luaCkpLAogICAgICAyNTUgKiAobCArIGEgKiAoQyAqIGNvc2ggKyBEICogc2luaCkpLAogICAgICAyNTUgKiAobCArIGEgKiAoRSAqIGNvc2gpKSwKICAgICAgdGhpcy5vcGFjaXR5CiAgICApOwogIH0KfSkpOwoKZnVuY3Rpb24gYmFzaXModDEsIHYwLCB2MSwgdjIsIHYzKSB7CiAgdmFyIHQyID0gdDEgKiB0MSwgdDMgPSB0MiAqIHQxOwogIHJldHVybiAoKDEgLSAzICogdDEgKyAzICogdDIgLSB0MykgKiB2MAogICAgICArICg0IC0gNiAqIHQyICsgMyAqIHQzKSAqIHYxCiAgICAgICsgKDEgKyAzICogdDEgKyAzICogdDIgLSAzICogdDMpICogdjIKICAgICAgKyB0MyAqIHYzKSAvIDY7Cn0KCmZ1bmN0aW9uIGJhc2lzJDEodmFsdWVzKSB7CiAgdmFyIG4gPSB2YWx1ZXMubGVuZ3RoIC0gMTsKICByZXR1cm4gZnVuY3Rpb24odCkgewogICAgdmFyIGkgPSB0IDw9IDAgPyAodCA9IDApIDogdCA+PSAxID8gKHQgPSAxLCBuIC0gMSkgOiBNYXRoLmZsb29yKHQgKiBuKSwKICAgICAgICB2MSA9IHZhbHVlc1tpXSwKICAgICAgICB2MiA9IHZhbHVlc1tpICsgMV0sCiAgICAgICAg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ICBjID0gbmV3IEFycmF5KG5iKSwKICAgICAgaTsKCiAgZm9yIChpID0gMDsgaSA8IG5hOyArK2kpIHhbaV0gPSBpbnRlcnBvbGF0ZVZhbHVlKGFbaV0sIGJbaV0pOwogIGZvciAoOyBpIDwgbmI7ICsraSkgY1tpXSA9IGJbaV07CgogIHJldHVybiBmdW5jdGlvbih0KSB7CiAgICBmb3IgKGkgPSAwOyBpIDwgbmE7ICsraSkgY1tpXSA9IHhbaV0odCk7CiAgICByZXR1cm4gYzsKICB9Owp9CgpmdW5jdGlvbiBkYXRlKGEsIGIpIHsKICB2YXIgZCA9IG5ldyBEYXRlOwogIHJldHVybiBhID0gK2EsIGIgLT0gYSwgZnVuY3Rpb24odCkgewogICAgcmV0dXJuIGQuc2V0VGltZShhICsgYiAqIHQpLCBkOwogIH07Cn0KCmZ1bmN0aW9uIHJlaW50ZXJwb2xhdGUoYSwgYikgewogIHJldHVybiBhID0gK2EsIGIgLT0gYSwgZnVuY3Rpb24odCkgewogICAgcmV0dXJuIGEgKyBiICogdDsKICB9Owp9CgpmdW5jdGlvbiBvYmplY3QoYSwgYikgewogIHZhciBpID0ge30sCiAgICAgIGMgPSB7fSwKICAgICAgazsKCiAgaWYgKGEgPT09IG51bGwgfHwgdHlwZW9mIGEgIT09ICJvYmplY3QiKSBhID0ge307CiAgaWYgKGIgPT09IG51bGwgfHwgdHlwZW9mIGIgIT09ICJvYmplY3QiKSBiID0ge307CgogIGZvciAoayBpbiBiKSB7CiAgICBpZiAoayBpbiBhKSB7CiAgICAgIGlba10gPSBpbnRlcnBvbGF0ZVZhbHVlKGFba10sIGJba10pOwogICAgfSBlbHNlIHsKICAgICAgY1trXSA9IGJba107CiAgICB9CiAgfQoKICByZXR1cm4gZnVuY3Rpb24odCkgewogICAgZm9yIChrIGluIGkpIGNba10gPSBpW2tdKHQpOwogICAgcmV0dXJuIGM7CiAgfTsKfQoKdmFyIHJlQSA9IC9bLStdPyg/OlxkK1wuP1xkKnxcLj9cZCspK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WF0aC5leHAocmhvICogdCAqIFMpCiAgICAgIF07CiAgICB9OwogIH0KCiAgLy8gR2VuZXJhbCBjYXNlLgogIGVsc2UgewogICAgdmFyIGQxID0gTWF0aC5zcXJ0KGQyKSwKICAgICAgICBiMCA9ICh3MSAqIHcxIC0gdzAgKiB3MCArIHJobzQgKiBkMikgLyAoMiAqIHcwICogcmhvMiAqIGQxKSwKICAgICAgICBiMSA9ICh3MSAqIHcxIC0gdzAgKiB3MCAtIHJobzQgKiBkMikgLyAoMiAqIHcxICogcmhvMiAqIGQxKSwKICAgICAgICByMCA9IE1hdGgubG9nKE1hdGguc3FydChiMCAqIGIwICsgMSkgLSBiMCksCiAgICAgICAgcjEgPSBNYXRoLmxvZyhNYXRoLnNxcnQoYjEgKiBiMSArIDEpIC0gYjEpOwogICAgUyA9IChyMSAtIHIwKSAvIHJobzsKICAgIGkgPSBmdW5jdGlvbih0KSB7CiAgICAgIHZhciBzID0gdCAqIFMsCiAgICAgICAgICBjb3NocjAgPSBjb3NoKHIwKSwKICAgICAgICAgIHUgPSB3MCAvIChyaG8yICogZDEpICogKGNvc2hyMCAqIHRhbmgocmhvICogcyArIHIwKSAtIHNpbmgocjApKTsKICAgICAgcmV0dXJuIFsKICAgICAgICB1eDAgKyB1ICogZHgsCiAgICAgICAgdXkwICsgdSAqIGR5LAogICAgICAgIHcwICogY29zaHIwIC8gY29zaChyaG8gKiBzICsgcjApCiAgICAgIF07CiAgICB9OwogIH0KCiAgaS5kdXJhdGlvbiA9IFMgKiAxMDAwOwoKICByZXR1cm4gaTsKfQoKZnVuY3Rpb24gaHNsJDEoaHVlJCQxKSB7CiAgcmV0dXJuIGZ1bmN0aW9uKHN0YXJ0LCBlbmQpIHsKICAgIHZhciBoID0gaHVlJCQxKChzdGFydCA9IGhzbChzdGFydCkpLmgsIChlbmQgPSBoc2woZW5kKSkuaCksCiAgICAgICAgcyA9IG5vZ2FtbWEoc3RhcnQucywgZW5kLnMpLAogICAgICAgIGwgPSBub2dh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md1bWVudHMpLmVuZCgpOyB9KQogICAgICAgICAgLnR3ZWVuKCJicnVzaCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICB2YXIgdGhhdCA9IHRoaXMsCiAgICAgICAgICAgICAgICBzdGF0ZSA9IHRoYXQuX19icnVzaCwKICAgICAgICAgICAgICAgIGVtaXQgPSBlbWl0dGVyKHRoYXQsIGFyZ3VtZW50cyksCiAgICAgICAgICAgICAgICBzZWxlY3Rpb24wID0gc3RhdGUuc2VsZWN0aW9uLAogICAgICAgICAgICAgICAgc2VsZWN0aW9uMSA9IGRpbS5pbnB1dCh0eXBlb2Ygc2VsZWN0aW9uJCQxID09PSAiZnVuY3Rpb24iID8gc2VsZWN0aW9uJCQxLmFwcGx5KHRoaXMsIGFyZ3VtZW50cykgOiBzZWxlY3Rpb24kJDEsIHN0YXRlLmV4dGVudCksCiAgICAgICAgICAgICAgICBpID0gaW50ZXJwb2xhdGVWYWx1ZShzZWxlY3Rpb24wLCBzZWxlY3Rpb24xKTsKCiAgICAgICAgICAgIGZ1bmN0aW9uIHR3ZWVuKHQpIHsKICAgICAgICAgICAgICBzdGF0ZS5zZWxlY3Rpb24gPSB0ID09PSAxICYmIGVtcHR5JDEoc2VsZWN0aW9uMSkgPyBudWxsIDogaSh0KTsKICAgICAgICAgICAgICByZWRyYXcuY2FsbCh0aGF0KTsKICAgICAgICAgICAgICBlbWl0LmJydXNoKCk7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIHJldHVybiBzZWxlY3Rpb24wICYmIHNlbGVjdGlvbjEgPyB0d2VlbiA6IHR3ZWVuKDEpOwogICAgICAgICAgfSk7CiAgICB9IGVsc2UgewogICAgICBncm91cAogICAgICAgICAgLmVhY2goZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHZhciB0aGF0ID0gdGhpcywKICAgICAgICAgICAgICAgIGFyZ3MgPSBhcmd1bWVudHMsCiAgICAgICAgICAgICAgICBzdGF0ZSA9IHRoYXQuX19icnVzaCwKICAg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AgICB9CiAgICAgIHBvaW50JCQxID0gcG9pbnQxOwogICAgICBtb3ZpbmcgPSB0cnVlOwogICAgICBub2V2ZW50JDEoKTsKICAgICAgbW92ZSgpOwogICAgfQoKICAgIGZ1bmN0aW9uIG1vdmUoKSB7CiAgICAgIHZhciB0OwoKICAgICAgZHggPSBwb2ludCQkMVswXSAtIHBvaW50MFswXTsKICAgICAgZHkgPSBwb2ludCQkMVsxXSAtIHBvaW50MFsxXTsKCiAgICAgIHN3aXRjaCAobW9kZSkgewogICAgICAgIGNhc2UgTU9ERV9TUEFDRToKICAgICAgICBjYXNlIE1PREVfRFJBRzogewogICAgICAgICAgaWYgKHNpZ25YKSBkeCA9IE1hdGgubWF4KFcgLSB3MCwgTWF0aC5taW4oRSAtIGUwLCBkeCkpLCB3MSA9IHcwICsgZHgsIGUxID0gZTAgKyBkeDsKICAgICAgICAgIGlmIChzaWduWSkgZHkgPSBNYXRoLm1heChOIC0gbjAsIE1hdGgubWluKFMgLSBzMCwgZHkpKSwgbjEgPSBuMCArIGR5LCBzMSA9IHMwICsgZHk7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgY2FzZSBNT0RFX0hBTkRMRTogewogICAgICAgICAgaWYgKHNpZ25YIDwgMCkgZHggPSBNYXRoLm1heChXIC0gdzAsIE1hdGgubWluKEUgLSB3MCwgZHgpKSwgdzEgPSB3MCArIGR4LCBlMSA9IGUwOwogICAgICAgICAgZWxzZSBpZiAoc2lnblggPiAwKSBkeCA9IE1hdGgubWF4KFcgLSBlMCwgTWF0aC5taW4oRSAtIGUwLCBkeCkpLCB3MSA9IHcwLCBlMSA9IGUwICsgZHg7CiAgICAgICAgICBpZiAoc2lnblkgPCAwKSBkeSA9IE1hdGgubWF4KE4gLSBuMCwgTWF0aC5taW4oUyAtIG4wLCBkeSkpLCBuMSA9IG4wICsgZHksIHMxID0gczA7CiAgICAgICAgICBlbHNlIGlmIChzaWduWSA+IDApIGR5ID0gTWF0aC5tYXgoTiAt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gICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIGNhc2UgMzI6IHsgLy8gU1BBQ0U7IHRha2VzIHByaW9yaXR5IG92ZXIgQUxUCiAgICAgICAgICBpZiAobW9kZSA9PT0gTU9ERV9IQU5ETEUgfHwgbW9kZSA9PT0gTU9ERV9DRU5URVIpIHsKICAgICAgICAgICAgaWYgKHNpZ25YIDwgMCkgZTAgPSBlMSAtIGR4OyBlbHNlIGlmIChzaWduWCA+IDApIHcwID0gdzEgLSBkeDsKICAgICAgICAgICAgaWYgKHNpZ25ZIDwgMCkgczAgPSBzMSAtIGR5OyBlbHNlIGlmIChzaWduWSA+IDApIG4wID0gbjEgLSBkeTsKICAgICAgICAgICAgbW9kZSA9IE1PREVfU1BBQ0U7CiAgICAgICAgICAgIG92ZXJsYXkuYXR0cigiY3Vyc29yIiwgY3Vyc29ycy5zZWxlY3Rpb24pOwogICAgICAgICAgICBtb3ZlKCk7CiAgICAgICAgICB9CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZGVmYXVsdDogcmV0dXJuOwogICAgICB9CiAgICAgIG5vZXZlbnQkMSgpOwogICAgfQoKICAgIGZ1bmN0aW9uIGtleXVwcGVkKCkgewogICAgICBzd2l0Y2ggKGV4cG9ydHMuZXZlbnQua2V5Q29kZSkgewogICAgICAgIGNhc2UgMTY6IHsgLy8gU0hJRlQKICAgICAgICAgIGlmIChzaGlmdGluZykgewogICAgICAgICAgICBsb2NrWCA9IGxvY2tZID0gc2hpZnRpbmcgPSBmYWxzZTsKICAgICAgICAgICAgbW92ZSgpOwogICAgICAgICAgfQogICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIGNhc2UgMTg6IHsgLy8gQUxUCiAgICAgICAgICBpZiAobW9kZSA9PT0gTU9ERV9DRU5URVIpIHsKICAgICAgICAgICAgaWYgKHNpZ25YIDwgMCkgZTAgPSBlMTsgZWxzZSBpZiAoc2lnblggPiAwKSB3MCA9IHcxOwogICAgICAgICAgICBpZiAoc2lnblkgPCAwKSBzMCA9IHMxOyBlbHNlIGlmIChzaWduWSA+IDApIG4wID0gbjE7CiAgICAgICAgICAgIG1vZGUgPSBNT0RFX0hBTkRMRTsKICAgICAgICAgICAgbW92ZSgpOwogICAgICAgICAgfQogICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIGNhc2UgMzI6IHsgLy8gU1BBQ0UKICAgICAgICAgIGlmIChtb2RlID09PSBNT0RFX1NQQUNFKSB7CiAgICAgICAgICAgIGlmIChleHBvcnRzLmV2ZW50LmFsdEtleSkgewogICAgICAgICAgICAgIGlmIChzaWduWCkgZTAgPSBlMSAtIGR4ICogc2lnblgsIHcwID0gdzEgKyBkeCAqIHNpZ25YOwogICAgICAgICAgICAgIGlmIChzaWduWSkgczAgPSBzMSAtIGR5ICogc2lnblksIG4wID0gbjEgKyBkeSAqIHNpZ25ZOwogICAgICAgICAgICAgIG1vZGUgPSBNT0RFX0NFTlRFUjsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBpZiAoc2lnblggPCAwKSBlMCA9IGUxOyBlbHNlIGlmIChzaWduWCA+IDApIHcwID0gdzE7CiAgICAgICAgICAgICAgaWYgKHNpZ25ZIDwgMCkgczAgPSBzMTsgZWxzZSBpZiAoc2lnblkgPiAwKSBuMCA9IG4xOwogICAgICAgICAgICAgIG1vZGUgPSBNT0RFX0hBTkRMRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBvdmVybGF5LmF0dHIoImN1cnNvciIsIGN1cnNvcnNbdHlwZV0pOwogICAgICAgICAgICBtb3ZlKCk7CiAgICAgICAgICB9CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZGVmYXVsdDogcmV0dXJuOwogICAgICB9CiAgICAgIG5vZXZlbnQkMSgpOwogICAgfQogIH0KCiAgZnVuY3Rpb24gaW5pdGlhbGl6ZSgpIHsKICAgIHZhciBzdGF0ZSA9IHRoaXMuX19icnVzaCB8fCB7c2VsZWN0a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mN0aW9uIGNvbXBhcmVWYWx1ZShjb21wYXJlKSB7CiAgcmV0dXJuIGZ1bmN0aW9uKGEsIGIpIHsKICAgIHJldHVybiBjb21wYXJlKAogICAgICBhLnNvdXJjZS52YWx1ZSArIGEudGFyZ2V0LnZhbHVlLAogICAgICBiLnNvdXJjZS52YWx1ZSArIGIudGFyZ2V0LnZhbHVlCiAgICApOwogIH07Cn0KCmZ1bmN0aW9uIGNob3JkKCkgewogIHZhciBwYWRBbmdsZSA9IDAsCiAgICAgIHNvcnRHcm91cHMgPSBudWxsLAogICAgICBzb3J0U3ViZ3JvdXBzID0gbnVsbCwKICAgICAgc29ydENob3JkcyA9IG51bGw7CgogIGZ1bmN0aW9uIGNob3JkKG1hdHJpeCkgewogICAgdmFyIG4gPSBtYXRyaXgubGVuZ3RoLAogICAgICAgIGdyb3VwU3VtcyA9IFtdLAogICAgICAgIGdyb3VwSW5kZXggPSBzZXF1ZW5jZShuKSwKICAgICAgICBzdWJncm91cEluZGV4ID0gW10sCiAgICAgICAgY2hvcmRzID0gW10sCiAgICAgICAgZ3JvdXBzID0gY2hvcmRzLmdyb3VwcyA9IG5ldyBBcnJheShuKSwKICAgICAgICBzdWJncm91cHMgPSBuZXcgQXJyYXkobiAqIG4pLAogICAgICAgIGssCiAgICAgICAgeCwKICAgICAgICB4MCwKICAgICAgICBkeCwKICAgICAgICBpLAogICAgICAgIGo7CgogICAgLy8gQ29tcHV0ZSB0aGUgc3VtLgogICAgayA9IDAsIGkgPSAtMTsgd2hpbGUgKCsraSA8IG4pIHsKICAgICAgeCA9IDAsIGogPSAtMTsgd2hpbGUgKCsraiA8IG4pIHsKICAgICAgICB4ICs9IG1hdHJpeFtpXVtqXTsKICAgICAgfQogICAgICBncm91cFN1bXMucHVzaCh4KTsKICAgICAgc3ViZ3JvdXBJbmRleC5wdXNoKHNlcXVlbmNlKG4pKTsKICAgICAgayArPSB4OwogICAgfQoKICAgIC8vIFNvcnQgZ3JvdXBz4oCmCiAgICBpZi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RpXVtqXSwKICAgICAgICAgICAgdiA9IG1hdHJpeFtkaV1bZGpdLAogICAgICAgICAgICBhMCA9IHgsCiAgICAgICAgICAgIGExID0geCArPSB2ICogazsKICAgICAgICBzdWJncm91cHNbZGogKiBuICsgZGldID0gewogICAgICAgICAgaW5kZXg6IGRpLAogICAgICAgICAgc3ViaW5kZXg6IGRqLAogICAgICAgICAgc3RhcnRBbmdsZTogYTAsCiAgICAgICAgICBlbmRBbmdsZTogYTEsCiAgICAgICAgICB2YWx1ZTogdgogICAgICAgIH07CiAgICAgIH0KICAgICAgZ3JvdXBzW2RpXSA9IHsKICAgICAgICBpbmRleDogZGksCiAgICAgICAgc3RhcnRBbmdsZTogeDAsCiAgICAgICAgZW5kQW5nbGU6IHgsCiAgICAgICAgdmFsdWU6IGdyb3VwU3Vtc1tkaV0KICAgICAgfTsKICAgICAgeCArPSBkeDsKICAgIH0KCiAgICAvLyBHZW5lcmF0ZSBjaG9yZHMgZm9yIGVhY2ggKG5vbi1lbXB0eSkgc3ViZ3JvdXAtc3ViZ3JvdXAgbGluay4KICAgIGkgPSAtMTsgd2hpbGUgKCsraSA8IG4pIHsKICAgICAgaiA9IGkgLSAxOyB3aGlsZSAoKytqIDwgbikgewogICAgICAgIHZhciBzb3VyY2UgPSBzdWJncm91cHNbaiAqIG4gKyBpXSwKICAgICAgICAgICAgdGFyZ2V0ID0gc3ViZ3JvdXBzW2kgKiBuICsgal07CiAgICAgICAgaWYgKHNvdXJjZS52YWx1ZSB8fCB0YXJnZXQudmFsdWUpIHsKICAgICAgICAgIGNob3Jkcy5wdXNoKHNvdXJjZS52YWx1ZSA8IHRhcmdldC52YWx1ZQogICAgICAgICAgICAgID8ge3NvdXJjZTogdGFyZ2V0LCB0YXJnZXQ6IHNvdXJjZX0KICAgICAgICAgICAgICA6IHtzb3VyY2U6IHNvdXJjZSwgdGFyZ2V0OiB0YXJnZXR9KTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gc29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gpICsgIiwiICsgKHRoaXMuX3kxID0gK3kpOwogIH0sCiAgYXJjVG86IGZ1bmN0aW9uKHgxLCB5MSwgeDIsIHkyLCByKSB7CiAgICB4MSA9ICt4MSwgeTEgPSAreTEsIHgyID0gK3gyLCB5MiA9ICt5MiwgciA9ICtyOwogICAgdmFyIHgwID0gdGhpcy5feDEsCiAgICAgICAgeTAgPSB0aGlzLl95MSwKICAgICAgICB4MjEgPSB4MiAtIHgxLAogICAgICAgIHkyMSA9IHkyIC0geTEsCiAgICAgICAgeDAxID0geDAgLSB4MSwKICAgICAgICB5MDEgPSB5MCAtIHkxLAogICAgICAgIGwwMV8yID0geDAxICogeDAxICsgeTAxICogeTAxOwoKICAgIC8vIElzIHRoZSByYWRpdXMgbmVnYXRpdmU/IEVycm9yLgogICAgaWYgKHIgPCAwKSB0aHJvdyBuZXcgRXJyb3IoIm5lZ2F0aXZlIHJhZGl1czogIiArIHIpOwoKICAgIC8vIElzIHRoaXMgcGF0aCBlbXB0eT8gTW92ZSB0byAoeDEseTEpLgogICAgaWYgKHRoaXMuX3gxID09PSBudWxsKSB7CiAgICAgIHRoaXMuXyArPSAiTSIgKyAodGhpcy5feDEgPSB4MSkgKyAiLCIgKyAodGhpcy5feTEgPSB5MSk7CiAgICB9CgogICAgLy8gT3IsIGlzICh4MSx5MSkgY29pbmNpZGVudCB3aXRoICh4MCx5MCk/IERvIG5vdGhpbmcuCiAgICBlbHNlIGlmICghKGwwMV8yID4gZXBzaWxvbiQxKSkge30KCiAgICAvLyBPciwgYXJlICh4MCx5MCksICh4MSx5MSkgYW5kICh4Mix5MikgY29sbGluZWFyPwogICAgLy8gRXF1aXZhbGVudGx5LCBpcyAoeDEseTEpIGNvaW5jaWRlbnQgd2l0aCAoeDIseTIpPwogICAgLy8gT3IsIGlzIHRoZSByYWRpdXMgemVybz8gTGluZSB0byAoeDEseTEpLgogICAgZWxzZSBpZiAoIShNYXRoLmFicyh5MDEgKiB4MjEgLSB5MjEgKiB4MDEpID4gZXBzaWxvbiQxKSB8fCAhcikgewogICAgICB0aGlzLl8gKz0gIkwiICsgKHRoaXMuX3gxID0geDEpICsgIiwiICsgKHRoaXMuX3kxID0geTEpOwogICAgfQoKICAgIC8vIE90aGVyd2lzZSwgZHJhdyBhbiBhcmMhCiAgICBlbHNlIHsKICAgICAgdmFyIHgyMCA9IHgyIC0geDAsCiAgICAgICAgICB5MjAgPSB5MiAtIHkwLAogICAgICAgICAgbDIxXzIgPSB4MjEgKiB4MjEgKyB5MjEgKiB5MjEsCiAgICAgICAgICBsMjBfMiA9IHgyMCAqIHgyMCArIHkyMCAqIHkyMCwKICAgICAgICAgIGwyMSA9IE1hdGguc3FydChsMjFfMiksCiAgICAgICAgICBsMDEgPSBNYXRoLnNxcnQobDAxXzIpLAogICAgICAgICAgbCA9IHIgKiBNYXRoLnRhbigocGkkMiAtIE1hdGguYWNvcygobDIxXzIgKyBsMDFfMiAtIGwyMF8yKSAvICgyICogbDIxICogbDAxKSkpIC8gMiksCiAgICAgICAgICB0MDEgPSBsIC8gbDAxLAogICAgICAgICAgdDIxID0gbCAvIGwyMTsKCiAgICAgIC8vIElmIHRoZSBzdGFydCB0YW5nZW50IGlzIG5vdCBjb2luY2lkZW50IHdpdGggKHgwLHkwKSwgbGluZSB0by4KICAgICAgaWYgKE1hdGguYWJzKHQwMSAtIDEpID4gZXBzaWxvbiQxKSB7CiAgICAgICAgdGhpcy5fICs9ICJMIiArICh4MSArIHQwMSAqIHgwMSkgKyAiLCIgKyAoeTEgKyB0MDEgKiB5MDEpOwogICAgICB9CgogICAgICB0aGlzLl8gKz0gIkEiICsgciArICIsIiArIHIgKyAiLDAsMCwiICsgKCsoeTAxICogeDIwID4geDAxICogeTIwKSkgKyAiLCIgKyAodGhpcy5feDEgPSB4MSArIHQyMSAqIHgyMSkgKyAiLCIgKyAodGhpcy5feTEgPSB5MSArIHQyMSAqIHkyMSk7CiAgICB9CiAgfSwKICBhcmM6IGZ1bmN0aW9uKHgsIHksIHIs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ndGggLSAxXSA9IHF1YWRzW3F1YWRzLmxlbmd0aCAtIDEgLSBpXTsKICAgICAgICBxdWFkc1txdWFkcy5sZW5ndGggLSAxIC0gaV0gPSBxOwogICAgICB9CiAgICB9CgogICAgLy8gVmlzaXQgdGhpcyBwb2ludC4gKFZpc2l0aW5nIGNvaW5jaWRlbnQgcG9pbnRzIGlzbuKAmXQgbmVjZXNzYXJ5ISkKICAgIGVsc2UgewogICAgICB2YXIgZHggPSB4IC0gK3RoaXMuX3guY2FsbChudWxsLCBub2RlLmRhdGEpLAogICAgICAgICAgZHkgPSB5IC0gK3RoaXMuX3kuY2FsbChudWxsLCBub2RlLmRhdGEpLAogICAgICAgICAgZDIgPSBkeCAqIGR4ICsgZHkgKiBkeTsKICAgICAgaWYgKGQyIDwgcmFkaXVzKSB7CiAgICAgICAgdmFyIGQgPSBNYXRoLnNxcnQocmFkaXVzID0gZDIpOwogICAgICAgIHgwID0geCAtIGQsIHkwID0geSAtIGQ7CiAgICAgICAgeDMgPSB4ICsgZCwgeTMgPSB5ICsgZDsKICAgICAgICBkYXRhID0gbm9kZS5kYXRhOwogICAgICB9CiAgICB9CiAgfQoKICByZXR1cm4gZGF0YTsKfQoKZnVuY3Rpb24gdHJlZV9yZW1vdmUoZCkgewogIGlmIChpc05hTih4ID0gK3RoaXMuX3guY2FsbChudWxsLCBkKSkgfHwgaXNOYU4oeSA9ICt0aGlzLl95LmNhbGwobnVsbCwgZCkpKSByZXR1cm4gdGhpczsgLy8gaWdub3JlIGludmFsaWQgcG9pbnRzCgogIHZhciBwYXJlbnQsCiAgICAgIG5vZGUgPSB0aGlzLl9yb290LAogICAgICByZXRhaW5lciwKICAgICAgcHJldmlvdXMsCiAgICAgIG5leHQsCiAgICAgIHgwID0gdGhpcy5feDAsCiAgICAgIHkwID0gdGhpcy5feTAsCiAgICAgIHgxID0gdGhpcy5feDEsCiAgICAgIHkxID0gdGhpcy5feTEsCiAgICAgIHgsCiAgICAgIHksCiAgICAgIHhtLAog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RyZWVQcm90by52aXNpdEFmdGVyID0gdHJlZV92aXNpdEFmdGVyOwp0cmVlUHJvdG8ueCA9IHRyZWVfeDsKdHJlZVByb3RvLnkgPSB0cmVlX3k7CgpmdW5jdGlvbiB4KGQpIHsKICByZXR1cm4gZC54ICsgZC52eDsKfQoKZnVuY3Rpb24geShkKSB7CiAgcmV0dXJuIGQueSArIGQudnk7Cn0KCmZ1bmN0aW9uIGNvbGxpZGUocmFkaXVzKSB7CiAgdmFyIG5vZGVzLAogICAgICByYWRpaSwKICAgICAgc3RyZW5ndGggPSAxLAogICAgICBpdGVyYXRpb25zID0gMTsKCiAgaWYgKHR5cGVvZiByYWRpdXMgIT09ICJmdW5jdGlvbiIpIHJhZGl1cyA9IGNvbnN0YW50JDcocmFkaXVzID09IG51bGwgPyAxIDogK3JhZGl1cyk7CgogIGZ1bmN0aW9uIGZvcmNlKCkgewogICAgdmFyIGksIG4gPSBub2Rlcy5sZW5ndGgsCiAgICAgICAgdHJlZSwKICAgICAgICBub2RlLAogICAgICAgIHhpLAogICAgICAgIHlpLAogICAgICAgIHJpLAogICAgICAgIHJpMjsKCiAgICBmb3IgKHZhciBrID0gMDsgayA8IGl0ZXJhdGlvbnM7ICsraykgewogICAgICB0cmVlID0gcXVhZHRyZWUobm9kZXMsIHgsIHkpLnZpc2l0QWZ0ZXIocHJlcGFyZSk7CiAgICAgIGZvciAoaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICBub2RlID0gbm9kZXNbaV07CiAgICAgICAgcmkgPSByYWRpaVtub2RlLmluZGV4XSwgcmkyID0gcmkgKiByaTsKICAgICAgICB4aSA9IG5vZGUueCArIG5vZGUudng7CiAgICAgICAgeWkgPSBub2RlLnkgKyBub2RlLnZ5OwogICAgICAgIHRyZWUudmlzaXQoYXBwbHkpOwogICAgICB9CiAgICB9CgogICAgZnVuY3Rpb24gYXBwbHkocXVhZCwgeDAsIHkwLCB4MSwgeTEpIHsKICAgICAgdmFyIGRhdGEgPSBxdWFkLmRhdGEsIHJqID0gcXVhZC5yLCByID0gcmkgKyByajsKICAgICAgaWYgKGRhdGEpIHsKICAgICAgICBpZiAoZGF0YS5pbmRleCA+IG5vZGUuaW5kZXgpIHsKICAgICAgICAgIHZhciB4ID0geGkgLSBkYXRhLnggLSBkYXRhLnZ4LAogICAgICAgICAgICAgIHkgPSB5aSAtIGRhdGEueSAtIGRhdGEudnksCiAgICAgICAgICAgICAgbCA9IHggKiB4ICsgeSAqIHk7CiAgICAgICAgICBpZiAobCA8IHIgKiByKSB7CiAgICAgICAgICAgIGlmICh4ID09PSAwKSB4ID0gamlnZ2xlKCksIGwgKz0geCAqIHg7CiAgICAgICAgICAgIGlmICh5ID09PSAwKSB5ID0gamlnZ2xlKCksIGwgKz0geSAqIHk7CiAgICAgICAgICAgIGwgPSAociAtIChsID0gTWF0aC5zcXJ0KGwpKSkgLyBsICogc3RyZW5ndGg7CiAgICAgICAgICAgIG5vZGUudnggKz0gKHggKj0gbCkgKiAociA9IChyaiAqPSByaikgLyAocmkyICsgcmopKTsKICAgICAgICAgICAgbm9kZS52eSArPSAoeSAqPSBsKSAqIHI7CiAgICAgICAgICAgIGRhdGEudnggLT0geCAqIChyID0gMSAtIHIpOwogICAgICAgICAgICBkYXRhLnZ5IC09IHkgKiByOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm47CiAgICAgIH0KICAgICAgcmV0dXJuIHgwID4geGkgKyByIHx8IHgxIDwgeGkgLSByIHx8IHkwID4geWkgKyByIHx8IHkxIDwgeWkgLSByOwogICAgfQogIH0KCiAgZnVuY3Rpb24gcHJlcGFyZShxdWFkKSB7CiAgICBpZiAocXVhZC5kYXRhKSByZXR1cm4gcXVhZC5yID0gcmFkaWlbcXVhZC5kYXRhLmluZGV4XTsKICAgIGZvciAodmFyIGkgPSBxdWFkLnIgPSAwOyBpIDwgNDsgKytpKSB7CiAgICAgIGlmIChxdWFkW2ldICYmIHF1YWRbaV0uciA+IHF1YWQucikgewogICAgICA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wgPSAobCAtIGRpc3RhbmNlc1tpXSkgLyBsICogYWxwaGEgKiBzdHJlbmd0aHNbaV07CiAgICAgICAgeCAqPSBsLCB5ICo9IGw7CiAgICAgICAgdGFyZ2V0LnZ4IC09IHggKiAoYiA9IGJpYXNbaV0pOwogICAgICAgIHRhcmdldC52eSAtPSB5ICogYjsKICAgICAgICBzb3VyY2UudnggKz0geCAqIChiID0gMSAtIGIpOwogICAgICAgIHNvdXJjZS52eSArPSB5ICogYjsKICAgICAgfQogICAgfQogIH0KCiAgZnVuY3Rpb24gaW5pdGlhbGl6ZSgpIHsKICAgIGlmICghbm9kZXMpIHJldHVybjsKCiAgICB2YXIgaSwKICAgICAgICBuID0gbm9kZXMubGVuZ3RoLAogICAgICAgIG0gPSBsaW5rcy5sZW5ndGgsCiAgICAgICAgbm9kZUJ5SWQgPSBtYXAkMShub2RlcywgaWQpLAogICAgICAgIGxpbms7CgogICAgZm9yIChpID0gMCwgY291bnQgPSBuZXcgQXJyYXkobik7IGkgPCBtOyArK2kpIHsKICAgICAgbGluayA9IGxpbmtzW2ldLCBsaW5rLmluZGV4ID0gaTsKICAgICAgaWYgKHR5cGVvZiBsaW5rLnNvdXJjZSAhPT0gIm9iamVjdCIpIGxpbmsuc291cmNlID0gZmluZChub2RlQnlJZCwgbGluay5zb3VyY2UpOwogICAgICBpZiAodHlwZW9mIGxpbmsudGFyZ2V0ICE9PSAib2JqZWN0IikgbGluay50YXJnZXQgPSBmaW5kKG5vZGVCeUlkLCBsaW5rLnRhcmdldCk7CiAgICAgIGNvdW50W2xpbmsuc291cmNlLmluZGV4XSA9IChjb3VudFtsaW5rLnNvdXJjZS5pbmRleF0gfHwgMCkgKyAxOwogICAgICBjb3VudFtsaW5rLnRhcmdldC5pbmRleF0gPSAoY291bnRbbGluay50YXJnZXQuaW5kZXhdIHx8IDApICsgMTsKICAgIH0KCiAgICBmb3IgKGkgPSAwLCBiaWFzID0gbmV3IEFycmF5KG0pOyBpIDwgbTsgKytpKSB7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2F5ID0gMC42LAogICAgICBmb3JjZXMgPSBtYXAkMSgpLAogICAgICBzdGVwcGVyID0gdGltZXIoc3RlcCksCiAgICAgIGV2ZW50ID0gZGlzcGF0Y2goInRpY2siLCAiZW5kIik7CgogIGlmIChub2RlcyA9PSBudWxsKSBub2RlcyA9IFtdOwoKICBmdW5jdGlvbiBzdGVwKCkgewogICAgdGljaygpOwogICAgZXZlbnQuY2FsbCgidGljayIsIHNpbXVsYXRpb24pOwogICAgaWYgKGFscGhhIDwgYWxwaGFNaW4pIHsKICAgICAgc3RlcHBlci5zdG9wKCk7CiAgICAgIGV2ZW50LmNhbGwoImVuZCIsIHNpbXVsYXRpb24pOwogICAgfQogIH0KCiAgZnVuY3Rpb24gdGljaygpIHsKICAgIHZhciBpLCBuID0gbm9kZXMubGVuZ3RoLCBub2RlOwoKICAgIGFscGhhICs9IChhbHBoYVRhcmdldCAtIGFscGhhKSAqIGFscGhhRGVjYXk7CgogICAgZm9yY2VzLmVhY2goZnVuY3Rpb24oZm9yY2UpIHsKICAgICAgZm9yY2UoYWxwaGEpOwogICAgfSk7CgogICAgZm9yIChpID0gMDsgaSA8IG47ICsraSkgewogICAgICBub2RlID0gbm9kZXNbaV07CiAgICAgIGlmIChub2RlLmZ4ID09IG51bGwpIG5vZGUueCArPSBub2RlLnZ4ICo9IHZlbG9jaXR5RGVjYXk7CiAgICAgIGVsc2Ugbm9kZS54ID0gbm9kZS5meCwgbm9kZS52eCA9IDA7CiAgICAgIGlmIChub2RlLmZ5ID09IG51bGwpIG5vZGUueSArPSBub2RlLnZ5ICo9IHZlbG9jaXR5RGVjYXk7CiAgICAgIGVsc2Ugbm9kZS55ID0gbm9kZS5meSwgbm9kZS52eSA9IDA7CiAgICB9CiAgfQoKICBmdW5jdGlvbiBpbml0aWFsaXplTm9kZXMoKSB7CiAgICBmb3IgKHZhciBpID0gMCwgbiA9IG5vZGVzLmxlbmd0aCwgbm9kZTsgaSA8IG47ICsraSkgewogICAgICBub2RlID0gbm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gIHN0cmVhbS5saW5lU3RhcnQoKTsKICAgIGRvIHsKICAgICAgY3VycmVudC52ID0gY3VycmVudC5vLnYgPSB0cnVlOwogICAgICBpZiAoY3VycmVudC5lKSB7CiAgICAgICAgaWYgKGlzU3ViamVjdCkgewogICAgICAgICAgZm9yIChpID0gMCwgbiA9IHBvaW50cy5sZW5ndGg7IGkgPCBuOyArK2kpIHN0cmVhbS5wb2ludCgocG9pbnQgPSBwb2ludHNbaV0pWzBdLCBwb2ludFsxXSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGludGVycG9sYXRlKGN1cnJlbnQueCwgY3VycmVudC5uLngsIDEsIHN0cmVhbSk7CiAgICAgICAgfQogICAgICAgIGN1cnJlbnQgPSBjdXJyZW50Lm47CiAgICAgIH0gZWxzZSB7CiAgICAgICAgaWYgKGlzU3ViamVjdCkgewogICAgICAgICAgcG9pbnRzID0gY3VycmVudC5wLno7CiAgICAgICAgICBmb3IgKGkgPSBwb2ludHMubGVuZ3RoIC0gMTsgaSA+PSAwOyAtLWkpIHN0cmVhbS5wb2ludCgocG9pbnQgPSBwb2ludHNbaV0pWzBdLCBwb2ludFsxXSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGludGVycG9sYXRlKGN1cnJlbnQueCwgY3VycmVudC5wLngsIC0xLCBzdHJlYW0pOwogICAgICAgIH0KICAgICAgICBjdXJyZW50ID0gY3VycmVudC5wOwogICAgICB9CiAgICAgIGN1cnJlbnQgPSBjdXJyZW50Lm87CiAgICAgIHBvaW50cyA9IGN1cnJlbnQuejsKICAgICAgaXNTdWJqZWN0ID0gIWlzU3ViamVjdDsKICAgIH0gd2hpbGUgKCFjdXJyZW50LnYpOwogICAgc3RyZWFtLmxpbmVFbmQoKTsKICB9Cn0KCmZ1bmN0aW9uIGxpbmskMShhcnJheSkgewogIGlmICghKG4gPSBhcnJheS5sZW5ndGgpKSByZXR1cm47CiAgdmFyIG4sCiAgICAgIGkgPSAwLAogICAgICBhID0gYX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nRJbnNpZGUgPSBwb2x5Z29uQ29udGFpbnMocG9seWdvbiwgc3RhcnQpOwogICAgICAgIGlmIChzZWdtZW50cy5sZW5ndGgpIHsKICAgICAgICAgIGlmICghcG9seWdvblN0YXJ0ZWQpIHNpbmsucG9seWdvblN0YXJ0KCksIHBvbHlnb25TdGFydGVkID0gdHJ1ZTsKICAgICAgICAgIGNsaXBSZWpvaW4oc2VnbWVudHMsIGNvbXBhcmVJbnRlcnNlY3Rpb24sIHN0YXJ0SW5zaWRlLCBpbnRlcnBvbGF0ZSwgc2luayk7CiAgICAgICAgfSBlbHNlIGlmIChzdGFydEluc2lkZSkgewogICAgICAgICAgaWYgKCFwb2x5Z29uU3RhcnRlZCkgc2luay5wb2x5Z29uU3RhcnQoKSwgcG9seWdvblN0YXJ0ZWQgPSB0cnVlOwogICAgICAgICAgc2luay5saW5lU3RhcnQoKTsKICAgICAgICAgIGludGVycG9sYXRlKG51bGwsIG51bGwsIDEsIHNpbmspOwogICAgICAgICAgc2luay5saW5lRW5kKCk7CiAgICAgICAgfQogICAgICAgIGlmIChwb2x5Z29uU3RhcnRlZCkgc2luay5wb2x5Z29uRW5kKCksIHBvbHlnb25TdGFydGVkID0gZmFsc2U7CiAgICAgICAgc2VnbWVudHMgPSBwb2x5Z29uID0gbnVsbDsKICAgICAgfSwKICAgICAgc3BoZXJlOiBmdW5jdGlvbigpIHsKICAgICAgICBzaW5rLnBvbHlnb25TdGFydCgpOwogICAgICAgIHNpbmsubGluZVN0YXJ0KCk7CiAgICAgICAgaW50ZXJwb2xhdGUobnVsbCwgbnVsbCwgMSwgc2luayk7CiAgICAgICAgc2luay5saW5lRW5kKCk7CiAgICAgICAgc2luay5wb2x5Z29uRW5kKCk7CiAgICAgIH0KICAgIH07CgogICAgZnVuY3Rpb24gcG9pbnQobGFtYmRhLCBwaGkpIHsKICAgICAgaWYgKHBvaW50VmlzaWJsZShsYW1iZGEsIHBoaSkpIHNpbmsucG9pbnQobGFtYmRhLCBwaGkpOwogICAgfQoKICAgIGZ1bmN0aW9uIHBvaW50TGluZShsYW1iZGEsIHBoaSkgewogICAgICBsaW5lLnBvaW50KGxhbWJkYSwgcGhpKTsKICAgIH0KCiAgICBmdW5jdGlvbiBsaW5lU3RhcnQoKSB7CiAgICAgIGNsaXAucG9pbnQgPSBwb2ludExpbmU7CiAgICAgIGxpbmUubGluZVN0YXJ0KCk7CiAgICB9CgogICAgZnVuY3Rpb24gbGluZUVuZCgpIHsKICAgICAgY2xpcC5wb2ludCA9IHBvaW50OwogICAgICBsaW5lLmxpbmVFbmQoKTsKICAgIH0KCiAgICBmdW5jdGlvbiBwb2ludFJpbmcobGFtYmRhLCBwaGkpIHsKICAgICAgcmluZy5wdXNoKFtsYW1iZGEsIHBoaV0pOwogICAgICByaW5nU2luay5wb2ludChsYW1iZGEsIHBoaSk7CiAgICB9CgogICAgZnVuY3Rpb24gcmluZ1N0YXJ0KCkgewogICAgICByaW5nU2luay5saW5lU3RhcnQoKTsKICAgICAgcmluZyA9IFtdOwogICAgfQoKICAgIGZ1bmN0aW9uIHJpbmdFbmQoKSB7CiAgICAgIHBvaW50UmluZyhyaW5nWzBdWzBdLCByaW5nWzBdWzFdKTsKICAgICAgcmluZ1NpbmsubGluZUVuZCgpOwoKICAgICAgdmFyIGNsZWFuID0gcmluZ1NpbmsuY2xlYW4oKSwKICAgICAgICAgIHJpbmdTZWdtZW50cyA9IHJpbmdCdWZmZXIucmVzdWx0KCksCiAgICAgICAgICBpLCBuID0gcmluZ1NlZ21lbnRzLmxlbmd0aCwgbSwKICAgICAgICAgIHNlZ21lbnQsCiAgICAgICAgICBwb2ludDsKCiAgICAgIHJpbmcucG9wKCk7CiAgICAgIHBvbHlnb24ucHVzaChyaW5nKTsKICAgICAgcmluZyA9IG51bGw7CgogICAgICBpZiAoIW4pIHJldHVybjsKCiAgICAgIC8vIE5vIGludGVyc2VjdGlvbnMuCiAgICAgIGlmIChjbGVhbiAmIDEpIHsKICAgICAgICBzZWdtZW50ID0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aSksCiAgICAgICAgICAgIGMgPSBzbWFsbFJhZGl1cwogICAgICAgICAgICAgID8gdiA/IDAgOiBjb2RlKGxhbWJkYSwgcGhpKQogICAgICAgICAgICAgIDogdiA/IGNvZGUobGFtYmRhICsgKGxhbWJkYSA8IDAgPyBwaSQzIDogLXBpJDMpLCBwaGkpIDogMDsKICAgICAgICBpZiAoIXBvaW50MCAmJiAodjAwID0gdjAgPSB2KSkgc3RyZWFtLmxpbmVTdGFydCgpOwogICAgICAgIC8vIEhhbmRsZSBkZWdlbmVyYWNpZXMuCiAgICAgICAgLy8gVE9ETyBpZ25vcmUgaWYgbm90IGNsaXBwaW5nIHBvbHlnb25zLgogICAgICAgIGlmICh2ICE9PSB2MCkgewogICAgICAgICAgcG9pbnQyID0gaW50ZXJzZWN0KHBvaW50MCwgcG9pbnQxKTsKICAgICAgICAgIGlmICghcG9pbnQyIHx8IHBvaW50RXF1YWwocG9pbnQwLCBwb2ludDIpIHx8IHBvaW50RXF1YWwocG9pbnQxLCBwb2ludDIpKSB7CiAgICAgICAgICAgIHBvaW50MVswXSArPSBlcHNpbG9uJDI7CiAgICAgICAgICAgIHBvaW50MVsxXSArPSBlcHNpbG9uJDI7CiAgICAgICAgICAgIHYgPSB2aXNpYmxlKHBvaW50MVswXSwgcG9pbnQxWzFdKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHYgIT09IHYwKSB7CiAgICAgICAgICBjbGVhbiA9IDA7CiAgICAgICAgICBpZiAodikgewogICAgICAgICAgICAvLyBvdXRzaWRlIGdvaW5nIGluCiAgICAgICAgICAgIHN0cmVhbS5saW5lU3RhcnQoKTsKICAgICAgICAgICAgcG9pbnQyID0gaW50ZXJzZWN0KHBvaW50MSwgcG9pbnQwKTsKICAgICAgICAgICAgc3RyZWFtLnBvaW50KHBvaW50MlswXSwgcG9pbnQyWzFdKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIC8vIGluc2lkZSBnb2luZyBvdXQKICAgICAgICAgICAgcG9pbnQyID0gaW50ZXJzZWN0KHBvaW50MCwgcG9pbnQxKTsKICAgICAgICAgICAgc3RyZWFtLnBvaW50KHBvaW50MlswXSwgcG9pbnQyWzFdKTsKICAgICAgICAgICAgc3RyZWFtLmxpbmVFbmQoKTsKICAgICAgICAgIH0KICAgICAgICAgIHBvaW50MCA9IHBvaW50MjsKICAgICAgICB9IGVsc2UgaWYgKG5vdEhlbWlzcGhlcmUgJiYgcG9pbnQwICYmIHNtYWxsUmFkaXVzIF4gdikgewogICAgICAgICAgdmFyIHQ7CiAgICAgICAgICAvLyBJZiB0aGUgY29kZXMgZm9yIHR3byBwb2ludHMgYXJlIGRpZmZlcmVudCwgb3IgYXJlIGJvdGggemVybywKICAgICAgICAgIC8vIGFuZCB0aGVyZSB0aGlzIHNlZ21lbnQgaW50ZXJzZWN0cyB3aXRoIHRoZSBzbWFsbCBjaXJjbGUuCiAgICAgICAgICBpZiAoIShjICYgYzApICYmICh0ID0gaW50ZXJzZWN0KHBvaW50MSwgcG9pbnQwLCB0cnVlKSkpIHsKICAgICAgICAgICAgY2xlYW4gPSAwOwogICAgICAgICAgICBpZiAoc21hbGxSYWRpdXMpIHsKICAgICAgICAgICAgICBzdHJlYW0ubGluZVN0YXJ0KCk7CiAgICAgICAgICAgICAgc3RyZWFtLnBvaW50KHRbMF1bMF0sIHRbMF1bMV0pOwogICAgICAgICAgICAgIHN0cmVhbS5wb2ludCh0WzFdWzBdLCB0WzFdWzFdKTsKICAgICAgICAgICAgICBzdHJlYW0ubGluZUVuZCgpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHN0cmVhbS5wb2ludCh0WzFdWzBdLCB0WzFdWzFdKTsKICAgICAgICAgICAgICBzdHJlYW0ubGluZUVuZCgpOwogICAgICAgICAgICAgIHN0cmVhbS5saW5lU3RhcnQoKTsKICAgICAgICAgICAgICBzdHJlYW0ucG9pbnQodFswXVswXSwgdFswXVsxXSk7CiAgICAgICAgICAgIH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AgICAgeDIgPSBiLngsIHkyID0gYi55LCByMiA9IGIuciwKICAgICAgeDIxID0geDIgLSB4MSwgeTIxID0geTIgLSB5MSwgcjIxID0gcjIgLSByMSwKICAgICAgbCA9IE1hdGguc3FydCh4MjEgKiB4MjEgKyB5MjEgKiB5MjEpOwogIHJldHVybiB7CiAgICB4OiAoeDEgKyB4MiArIHgyMSAvIGwgKiByMjEpIC8gMiwKICAgIHk6ICh5MSArIHkyICsgeTIxIC8gbCAqIHIyMSkgLyAyLAogICAgcjogKGwgKyByMSArIHIyKSAvIDIKICB9Owp9CgpmdW5jdGlvbiBlbmNsb3NlQmFzaXMzKGEsIGIsIGMpIHsKICB2YXIgeDEgPSBhLngsIHkxID0gYS55LCByMSA9IGEuciwKICAgICAgeDIgPSBiLngsIHkyID0gYi55LCByMiA9IGIuciwKICAgICAgeDMgPSBjLngsIHkzID0gYy55LCByMyA9IGMuciwKICAgICAgYTIgPSB4MSAtIHgyLAogICAgICBhMyA9IHgxIC0geDMsCiAgICAgIGIyID0geTEgLSB5MiwKICAgICAgYjMgPSB5MSAtIHkzLAogICAgICBjMiA9IHIyIC0gcjEsCiAgICAgIGMzID0gcjMgLSByMSwKICAgICAgZDEgPSB4MSAqIHgxICsgeTEgKiB5MSAtIHIxICogcjEsCiAgICAgIGQyID0gZDEgLSB4MiAqIHgyIC0geTIgKiB5MiArIHIyICogcjIsCiAgICAgIGQzID0gZDEgLSB4MyAqIHgzIC0geTMgKiB5MyArIHIzICogcjMsCiAgICAgIGFiID0gYTMgKiBiMiAtIGEyICogYjMsCiAgICAgIHhhID0gKGIyICogZDMgLSBiMyAqIGQyKSAvIChhYiAqIDIpIC0geDEsCiAgICAgIHhiID0gKGIzICogYzIgLSBiMiAqIGMzKSAvIGFiLAogICAgICB5YSA9IChhMyAqIGQyIC0gYTIgKiBkMykgLyAoYWIgKiAyKSAtIHkxLAogICAgICB5YiA9IChhMiAqIGMzIC0gYTMgKiBjMikgLyBhYiwKICAgICAgQSA9IHhiICogeGIgKyB5YiAqIHliIC0gMSwKICAgICAgQiA9IDIgKiAocjEgKyB4YSAqIHhiICsgeWEgKiB5YiksCiAgICAgIEMgPSB4YSAqIHhhICsgeWEgKiB5YSAtIHIxICogcjEsCiAgICAgIHIgPSAtKEEgPyAoQiArIE1hdGguc3FydChCICogQiAtIDQgKiBBICogQykpIC8gKDIgKiBBKSA6IEMgLyBCKTsKICByZXR1cm4gewogICAgeDogeDEgKyB4YSArIHhiICogciwKICAgIHk6IHkxICsgeWEgKyB5YiAqIHIsCiAgICByOiByCiAgfTsKfQoKZnVuY3Rpb24gcGxhY2UoYiwgYSwgYykgewogIHZhciBkeCA9IGIueCAtIGEueCwgeCwgYTIsCiAgICAgIGR5ID0gYi55IC0gYS55LCB5LCBiMiwKICAgICAgZDIgPSBkeCAqIGR4ICsgZHkgKiBkeTsKICBpZiAoZDIpIHsKICAgIGEyID0gYS5yICsgYy5yLCBhMiAqPSBhMjsKICAgIGIyID0gYi5yICsgYy5yLCBiMiAqPSBiMjsKICAgIGlmIChhMiA+IGIyKSB7CiAgICAgIHggPSAoZDIgKyBiMiAtIGEyKSAvICgyICogZDIpOwogICAgICB5ID0gTWF0aC5zcXJ0KE1hdGgubWF4KDAsIGIyIC8gZDIgLSB4ICogeCkpOwogICAgICBjLnggPSBiLnggLSB4ICogZHggLSB5ICogZHk7CiAgICAgIGMueSA9IGIueSAtIHggKiBkeSArIHkgKiBkeDsKICAgIH0gZWxzZSB7CiAgICAgIHggPSAoZDIgKyBhMiAtIGIyKSAvICgyICogZDIpOwogICAgICB5ID0gTWF0aC5zcXJ0KE1hdGgubWF4KDAsIGEyIC8gZDIgLSB4ICogeCkpOwogICAgICBjLnggPSBhLnggKyB4ICogZHggLSB5ICogZHk7CiAgICAgIGMueSA9IGEueSArIHggKiBkeSArIHkgKiBkeDsKICAgIH0KICB9IGVsc2UgewogICAgYy54ID0gYS54ICsgYy5yOwogICAgYy55ID0gYS55OwogIH0KfQoKZnVuY3Rpb24gaW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gICAgIGlmIChpbnRlcnNlY3RzKGsuXywgYy5fKSkgewogICAgICAgICAgYSA9IGssIGEubmV4dCA9IGIsIGIucHJldmlvdXMgPSBhLCAtLWk7CiAgICAgICAgICBjb250aW51ZSBwYWNrOwogICAgICAgIH0KICAgICAgICBzayArPSBrLl8uciwgayA9IGsucHJldmlvdXM7CiAgICAgIH0KICAgIH0gd2hpbGUgKGogIT09IGsubmV4dCk7CgogICAgLy8gU3VjY2VzcyEgSW5zZXJ0IHRoZSBuZXcgY2lyY2xlIGMgYmV0d2VlbiBhIGFuZCBiLgogICAgYy5wcmV2aW91cyA9IGEsIGMubmV4dCA9IGIsIGEubmV4dCA9IGIucHJldmlvdXMgPSBiID0gYzsKCiAgICAvLyBDb21wdXRlIHRoZSBuZXcgY2xvc2VzdCBjaXJjbGUgcGFpciB0byB0aGUgY2VudHJvaWQuCiAgICBhYSA9IHNjb3JlKGEpOwogICAgd2hpbGUgKChjID0gYy5uZXh0KSAhPT0gYikgewogICAgICBpZiAoKGNhID0gc2NvcmUoYykpIDwgYWEpIHsKICAgICAgICBhID0gYywgYWEgPSBjYTsKICAgICAgfQogICAgfQogICAgYiA9IGEubmV4dDsKICB9CgogIC8vIENvbXB1dGUgdGhlIGVuY2xvc2luZyBjaXJjbGUgb2YgdGhlIGZyb250IGNoYWluLgogIGEgPSBbYi5fXSwgYyA9IGI7IHdoaWxlICgoYyA9IGMubmV4dCkgIT09IGIpIGEucHVzaChjLl8pOyBjID0gZW5jbG9zZShhKTsKCiAgLy8gVHJhbnNsYXRlIHRoZSBjaXJjbGVzIHRvIHB1dCB0aGUgZW5jbG9zaW5nIGNpcmNsZSBhcm91bmQgdGhlIG9yaWdpbi4KICBmb3IgKGkgPSAwOyBpIDwgbjsgKytpKSBhID0gY2lyY2xlc1tpXSwgYS54IC09IGMueCwgYS55IC09IGMueTsKCiAgcmV0dXJuIGMucjsKfQoKZnVuY3Rpb24gc2libGluZ3MoY2lyY2xlcykgewogIHBhY2tFbmNsb3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CiAgICAgICAgbm9kZUlkLAogICAgICAgIG5vZGVLZXksCiAgICAgICAgbm9kZUJ5S2V5ID0ge307CgogICAgZm9yIChpID0gMDsgaSA8IG47ICsraSkgewogICAgICBkID0gZGF0YVtpXSwgbm9kZSA9IG5vZGVzW2ldID0gbmV3IE5vZGUoZCk7CiAgICAgIGlmICgobm9kZUlkID0gaWQoZCwgaSwgZGF0YSkpICE9IG51bGwgJiYgKG5vZGVJZCArPSAiIikpIHsKICAgICAgICBub2RlS2V5ID0ga2V5UHJlZml4JDEgKyAobm9kZS5pZCA9IG5vZGVJZCk7CiAgICAgICAgbm9kZUJ5S2V5W25vZGVLZXldID0gbm9kZUtleSBpbiBub2RlQnlLZXkgPyBhbWJpZ3VvdXMgOiBub2RlOwogICAgICB9CiAgICB9CgogICAgZm9yIChpID0gMDsgaSA8IG47ICsraSkgewogICAgICBub2RlID0gbm9kZXNbaV0sIG5vZGVJZCA9IHBhcmVudElkKGRhdGFbaV0sIGksIGRhdGEpOwogICAgICBpZiAobm9kZUlkID09IG51bGwgfHwgIShub2RlSWQgKz0gIiIpKSB7CiAgICAgICAgaWYgKHJvb3QpIHRocm93IG5ldyBFcnJvcigibXVsdGlwbGUgcm9vdHMiKTsKICAgICAgICByb290ID0gbm9kZTsKICAgICAgfSBlbHNlIHsKICAgICAgICBwYXJlbnQgPSBub2RlQnlLZXlba2V5UHJlZml4JDEgKyBub2RlSWRdOwogICAgICAgIGlmICghcGFyZW50KSB0aHJvdyBuZXcgRXJyb3IoIm1pc3Npbmc6ICIgKyBub2RlSWQpOwogICAgICAgIGlmIChwYXJlbnQgPT09IGFtYmlndW91cykgdGhyb3cgbmV3IEVycm9yKCJhbWJpZ3VvdXM6ICIgKyBub2RlSWQpOwogICAgICAgIGlmIChwYXJlbnQuY2hpbGRyZW4pIHBhcmVudC5jaGlsZHJlbi5wdXNoKG5vZGUpOwogICAgICAgIGVsc2UgcGFyZW50LmNoaWxkcmVuID0gW25vZGVdOwogICAgICAgIG5v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bSAtIHZpcC56IC0gc2lwICsgc2VwYXJhdGlvbih2aW0uXywgdmlwLl8pOwogICAgICAgIGlmIChzaGlmdCA+IDApIHsKICAgICAgICAgIG1vdmVTdWJ0cmVlKG5leHRBbmNlc3Rvcih2aW0sIHYsIGFuY2VzdG9yKSwgdiwgc2hpZnQpOwogICAgICAgICAgc2lwICs9IHNoaWZ0OwogICAgICAgICAgc29wICs9IHNoaWZ0OwogICAgICAgIH0KICAgICAgICBzaW0gKz0gdmltLm07CiAgICAgICAgc2lwICs9IHZpcC5tOwogICAgICAgIHNvbSArPSB2b20ubTsKICAgICAgICBzb3AgKz0gdm9wLm07CiAgICAgIH0KICAgICAgaWYgKHZpbSAmJiAhbmV4dFJpZ2h0KHZvcCkpIHsKICAgICAgICB2b3AudCA9IHZpbTsKICAgICAgICB2b3AubSArPSBzaW0gLSBzb3A7CiAgICAgIH0KICAgICAgaWYgKHZpcCAmJiAhbmV4dExlZnQodm9tKSkgewogICAgICAgIHZvbS50ID0gdmlwOwogICAgICAgIHZvbS5tICs9IHNpcCAtIHNvbTsKICAgICAgICBhbmNlc3RvciA9IHY7CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBhbmNlc3RvcjsKICB9CgogIGZ1bmN0aW9uIHNpemVOb2RlKG5vZGUpIHsKICAgIG5vZGUueCAqPSBkeDsKICAgIG5vZGUueSA9IG5vZGUuZGVwdGggKiBkeTsKICB9CgogIHRyZWUuc2VwYXJhdGlvbiA9IGZ1bmN0aW9uKHgpIHsKICAgIHJldHVybiBhcmd1bWVudHMubGVuZ3RoID8gKHNlcGFyYXRpb24gPSB4LCB0cmVlKSA6IHNlcGFyYXRpb247CiAgfTsKCiAgdHJlZS5zaXplID0gZnVuY3Rpb24oeCkgewogICAgcmV0dXJuIGFyZ3VtZW50cy5sZW5ndGggPyAobm9kZVNpemUgPSBmYWxzZSwgZHggPSAreFswXSwgZHkgPSAreFsxXSwgdHJlZSkgOiAobm9kZVNpemUgPyBudWxsIDogW2R4LCB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PSBjb25zdGFudFplcm8sCiAgICAgIHBhZGRpbmdCb3R0b20gPSBjb25zdGFudFplcm8sCiAgICAgIHBhZGRpbmdMZWZ0ID0gY29uc3RhbnRaZXJvOwoKICBmdW5jdGlvbiB0cmVlbWFwKHJvb3QpIHsKICAgIHJvb3QueDAgPQogICAgcm9vdC55MCA9IDA7CiAgICByb290LngxID0gZHg7CiAgICByb290LnkxID0gZHk7CiAgICByb290LmVhY2hCZWZvcmUocG9zaXRpb25Ob2RlKTsKICAgIHBhZGRpbmdTdGFjayA9IFswXTsKICAgIGlmIChyb3VuZCkgcm9vdC5lYWNoQmVmb3JlKHJvdW5kTm9kZSk7CiAgICByZXR1cm4gcm9vdDsKICB9CgogIGZ1bmN0aW9uIHBvc2l0aW9uTm9kZShub2RlKSB7CiAgICB2YXIgcCA9IHBhZGRpbmdTdGFja1tub2RlLmRlcHRoXSwKICAgICAgICB4MCA9IG5vZGUueDAgKyBwLAogICAgICAgIHkwID0gbm9kZS55MCArIHAsCiAgICAgICAgeDEgPSBub2RlLngxIC0gcCwKICAgICAgICB5MSA9IG5vZGUueTEgLSBwOwogICAgaWYgKHgxIDwgeDApIHgwID0geDEgPSAoeDAgKyB4MSkgLyAyOwogICAgaWYgKHkxIDwgeTApIHkwID0geTEgPSAoeTAgKyB5MSkgLyAyOwogICAgbm9kZS54MCA9IHgwOwogICAgbm9kZS55MCA9IHkwOwogICAgbm9kZS54MSA9IHgxOwogICAgbm9kZS55MSA9IHkxOwogICAgaWYgKG5vZGUuY2hpbGRyZW4pIHsKICAgICAgcCA9IHBhZGRpbmdTdGFja1tub2RlLmRlcHRoICsgMV0gPSBwYWRkaW5nSW5uZXIobm9kZSkgLyAyOwogICAgICB4MCArPSBwYWRkaW5nTGVmdChub2RlKSAtIHA7CiAgICAgIHkwICs9IHBhZGRpbmdUb3Aobm9kZSkgLSBwOwogICAgICB4MSAtPSBwYWRkaW5nUmlnaHQobm9kZSkgLSBwOwogICAgICB5MSAtPSBwYWRkaW5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gPyAxMCA6ICtjb3VudCwKICAgICAgICB6ID0gW107CgogICAgaWYgKCEoYmFzZSAlIDEpICYmIGogLSBpIDwgbikgewogICAgICBpID0gTWF0aC5yb3VuZChpKSAtIDEsIGogPSBNYXRoLnJvdW5kKGopICsgMTsKICAgICAgaWYgKHUgPiAwKSBmb3IgKDsgaSA8IGo7ICsraSkgewogICAgICAgIGZvciAoayA9IDEsIHAgPSBwb3dzKGkpOyBrIDwgYmFzZTsgKytrKSB7CiAgICAgICAgICB0ID0gcCAqIGs7CiAgICAgICAgICBpZiAodCA8IHUpIGNvbnRpbnVlOwogICAgICAgICAgaWYgKHQgPiB2KSBicmVhazsKICAgICAgICAgIHoucHVzaCh0KTsKICAgICAgICB9CiAgICAgIH0gZWxzZSBmb3IgKDsgaSA8IGo7ICsraSkgewogICAgICAgIGZvciAoayA9IGJhc2UgLSAxLCBwID0gcG93cyhpKTsgayA+PSAxOyAtLWspIHsKICAgICAgICAgIHQgPSBwICogazsKICAgICAgICAgIGlmICh0IDwgdSkgY29udGludWU7CiAgICAgICAgICBpZiAodCA+IHYpIGJyZWFrOwogICAgICAgICAgei5wdXNoKHQpOwogICAgICAgIH0KICAgICAgfQogICAgfSBlbHNlIHsKICAgICAgeiA9IHRpY2tzKGksIGosIE1hdGgubWluKGogLSBpLCBuKSkubWFwKHBvd3MpOwogICAgfQoKICAgIHJldHVybiByID8gei5yZXZlcnNlKCkgOiB6OwogIH07CgogIHNjYWxlLnRpY2tGb3JtYXQgPSBmdW5jdGlvbihjb3VudCwgc3BlY2lmaWVyKSB7CiAgICBpZiAoc3BlY2lmaWVyID09IG51bGwpIHNwZWNpZmllciA9IGJhc2UgPT09IDEwID8gIi4wZSIgOiAiLCI7CiAgICBpZiAodHlwZW9mIHNwZWNpZmllciAhPT0gImZ1bmN0aW9uIikgc3BlY2lmaWVyID0gZXhwb3J0cy5mb3JtYXQoc3BlY2lmaWVyKTsKICAgIGlmIChjb3VudCA9PT0gSW5maW5pdHkpIHJldHV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KiB4MTAsIHkwICsgdCAqIHkxMF07Cn0KCi8vIENvbXB1dGUgcGVycGVuZGljdWxhciBvZmZzZXQgbGluZSBvZiBsZW5ndGggcmMuCi8vIGh0dHA6Ly9tYXRod29ybGQud29sZnJhbS5jb20vQ2lyY2xlLUxpbmVJbnRlcnNlY3Rpb24uaHRtbApmdW5jdGlvbiBjb3JuZXJUYW5nZW50cyh4MCwgeTAsIHgxLCB5MSwgcjEsIHJjLCBjdykgewogIHZhciB4MDEgPSB4MCAtIHgxLAogICAgICB5MDEgPSB5MCAtIHkxLAogICAgICBsbyA9IChjdyA/IHJjIDogLXJjKSAvIHNxcnQkMih4MDEgKiB4MDEgKyB5MDEgKiB5MDEpLAogICAgICBveCA9IGxvICogeTAxLAogICAgICBveSA9IC1sbyAqIHgwMSwKICAgICAgeDExID0geDAgKyBveCwKICAgICAgeTExID0geTAgKyBveSwKICAgICAgeDEwID0geDEgKyBveCwKICAgICAgeTEwID0geTEgKyBveSwKICAgICAgeDAwID0gKHgxMSArIHgxMCkgLyAyLAogICAgICB5MDAgPSAoeTExICsgeTEwKSAvIDIsCiAgICAgIGR4ID0geDEwIC0geDExLAogICAgICBkeSA9IHkxMCAtIHkxMSwKICAgICAgZDIgPSBkeCAqIGR4ICsgZHkgKiBkeSwKICAgICAgciA9IHIxIC0gcmMsCiAgICAgIEQgPSB4MTEgKiB5MTAgLSB4MTAgKiB5MTEsCiAgICAgIGQgPSAoZHkgPCAwID8gLTEgOiAxKSAqIHNxcnQkMihtYXgkMigwLCByICogciAqIGQyIC0gRCAqIEQpKSwKICAgICAgY3gwID0gKEQgKiBkeSAtIGR4ICogZCkgLyBkMiwKICAgICAgY3kwID0gKC1EICogZHggLSBkeSAqIGQpIC8gZDIsCiAgICAgIGN4MSA9IChEICogZHkgKyBkeCAqIGQpIC8gZDIsCiAgICAgIGN5MSA9ICgtRCAqIGR4ICsgZHkgKiBkKSAvIGQyLAogICAgICBkeDAgPSBjeDAgLSB4MDAsCiAgICAgIG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GRhMCA9IGRhLAogICAgICAgICAgZGExID0gZGEsCiAgICAgICAgICBhcCA9IHBhZEFuZ2xlLmFwcGx5KHRoaXMsIGFyZ3VtZW50cykgLyAyLAogICAgICAgICAgcnAgPSAoYXAgPiBlcHNpbG9uJDMpICYmIChwYWRSYWRpdXMgPyArcGFkUmFkaXVzLmFwcGx5KHRoaXMsIGFyZ3VtZW50cykgOiBzcXJ0JDIocjAgKiByMCArIHIxICogcjEpKSwKICAgICAgICAgIHJjID0gbWluJDEoYWJzJDEocjEgLSByMCkgLyAyLCArY29ybmVyUmFkaXVzLmFwcGx5KHRoaXMsIGFyZ3VtZW50cykpLAogICAgICAgICAgcmMwID0gcmMsCiAgICAgICAgICByYzEgPSByYywKICAgICAgICAgIHQwLAogICAgICAgICAgdDE7CgogICAgICAvLyBBcHBseSBwYWRkaW5nPyBOb3RlIHRoYXQgc2luY2UgcjEg4omlIHIwLCBkYTEg4omlIGRhMC4KICAgICAgaWYgKHJwID4gZXBzaWxvbiQzKSB7CiAgICAgICAgdmFyIHAwID0gYXNpbiQxKHJwIC8gcjAgKiBzaW4kMihhcCkpLAogICAgICAgICAgICBwMSA9IGFzaW4kMShycCAvIHIxICogc2luJDIoYXApKTsKICAgICAgICBpZiAoKGRhMCAtPSBwMCAqIDIpID4gZXBzaWxvbiQzKSBwMCAqPSAoY3cgPyAxIDogLTEpLCBhMDAgKz0gcDAsIGExMCAtPSBwMDsKICAgICAgICBlbHNlIGRhMCA9IDAsIGEwMCA9IGExMCA9IChhMCArIGExKSAvIDI7CiAgICAgICAgaWYgKChkYTEgLT0gcDEgKiAyKSA+IGVwc2lsb24kMykgcDEgKj0gKGN3ID8gMSA6IC0xKSwgYTAxICs9IHAxLCBhMTEgLT0gcDE7CiAgICAgICAgZWxzZSBkYTEgPSAwLCBhMDEgPSBhMTEgPSAoYTAgKyBhMSkgLyAyOwogICAgICB9CgogICAgICB2YXIgeDAxID0gcjEgKiBjb3MkMihhMDEpLAogICAgICAgICAgeTAxID0gcjEgKiBzaW4kMihhMDEpLAogICAgICAgICAgeDEwID0gcjAgKiBjb3MkMihhMTApLAogICAgICAgICAgeTEwID0gcjAgKiBzaW4kMihhMTApOwoKICAgICAgLy8gQXBwbHkgcm91bmRlZCBjb3JuZXJzPwogICAgICBpZiAocmMgPiBlcHNpbG9uJDMpIHsKICAgICAgICB2YXIgeDExID0gcjEgKiBjb3MkMihhMTEpLAogICAgICAgICAgICB5MTEgPSByMSAqIHNpbiQyKGExMSksCiAgICAgICAgICAgIHgwMCA9IHIwICogY29zJDIoYTAwKSwKICAgICAgICAgICAgeTAwID0gcjAgKiBzaW4kMihhMDApOwoKICAgICAgICAvLyBSZXN0cmljdCB0aGUgY29ybmVyIHJhZGl1cyBhY2NvcmRpbmcgdG8gdGhlIHNlY3RvciBhbmdsZS4KICAgICAgICBpZiAoZGEgPCBwaSQ0KSB7CiAgICAgICAgICB2YXIgb2MgPSBkYTAgPiBlcHNpbG9uJDMgPyBpbnRlcnNlY3QoeDAxLCB5MDEsIHgwMCwgeTAwLCB4MTEsIHkxMSwgeDEwLCB5MTApIDogW3gxMCwgeTEwXSwKICAgICAgICAgICAgICBheCA9IHgwMSAtIG9jWzBdLAogICAgICAgICAgICAgIGF5ID0geTAxIC0gb2NbMV0sCiAgICAgICAgICAgICAgYnggPSB4MTEgLSBvY1swXSwKICAgICAgICAgICAgICBieSA9IHkxMSAtIG9jWzFdLAogICAgICAgICAgICAgIGtjID0gMSAvIHNpbiQyKGFjb3MkMSgoYXggKiBieCArIGF5ICogYnkpIC8gKHNxcnQkMihheCAqIGF4ICsgYXkgKiBheSkgKiBzcXJ0JDIoYnggKiBieCArIGJ5ICogYnkpKSkgLyAyKSwKICAgICAgICAgICAgICBsYyA9IHNxcnQkMihvY1swXSAqIG9jWzBdICsgb2NbMV0gKiBvY1sxXSk7CiAgICAgICAgICByYzAgPSBtaW4kMShyYywgKHIwIC0gbGMpIC8gKGtjIC0gMSkpOwogICAgICAgICAgcmMxID0gbWluJD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oY29udGV4dCkpLCBsaW5lKSA6IGN1cnZlOwogIH07CgogIGxpbmUuY29udGV4dCA9IGZ1bmN0aW9uKF8pIHsKICAgIHJldHVybiBhcmd1bWVudHMubGVuZ3RoID8gKF8gPT0gbnVsbCA/IGNvbnRleHQgPSBvdXRwdXQgPSBudWxsIDogb3V0cHV0ID0gY3VydmUoY29udGV4dCA9IF8pLCBsaW5lKSA6IGNvbnRleHQ7CiAgfTsKCiAgcmV0dXJuIGxpbmU7Cn0KCmZ1bmN0aW9uIGFyZWEkMygpIHsKICB2YXIgeDAgPSB4JDMsCiAgICAgIHgxID0gbnVsbCwKICAgICAgeTAgPSBjb25zdGFudCQxMSgwKSwKICAgICAgeTEgPSB5JDMsCiAgICAgIGRlZmluZWQgPSBjb25zdGFudCQxMSh0cnVlKSwKICAgICAgY29udGV4dCA9IG51bGwsCiAgICAgIGN1cnZlID0gY3VydmVMaW5lYXIsCiAgICAgIG91dHB1dCA9IG51bGw7CgogIGZ1bmN0aW9uIGFyZWEoZGF0YSkgewogICAgdmFyIGksCiAgICAgICAgaiwKICAgICAgICBrLAogICAgICAgIG4gPSBkYXRhLmxlbmd0aCwKICAgICAgICBkLAogICAgICAgIGRlZmluZWQwID0gZmFsc2UsCiAgICAgICAgYnVmZmVyLAogICAgICAgIHgweiA9IG5ldyBBcnJheShuKSwKICAgICAgICB5MHogPSBuZXcgQXJyYXkobik7CgogICAgaWYgKGNvbnRleHQgPT0gbnVsbCkgb3V0cHV0ID0gY3VydmUoYnVmZmVyID0gcGF0aCgpKTsKCiAgICBmb3IgKGkgPSAwOyBpIDw9IG47ICsraSkgewogICAgICBpZiAoIShpIDwgbiAmJiBkZWZpbmVkKGQgPSBkYXRhW2ldLCBpLCBkYXRhKSkgPT09IGRlZmluZWQwKSB7CiAgICAgICAgaWYgKGRlZmluZWQwID0gIWRlZmluZWQwKSB7CiAgICAgICAgICBqID0gaTsKICAgICAgICAgIG91dHB1dC5hcmVhU3RhcnQoKTsKICAgICAgICAgIG91dHB1dC5saW5lU3RhcnQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgb3V0cHV0LmxpbmVFbmQoKTsKICAgICAgICAgIG91dHB1dC5saW5lU3RhcnQoKTsKICAgICAgICAgIGZvciAoayA9IGkgLSAxOyBrID49IGo7IC0taykgewogICAgICAgICAgICBvdXRwdXQucG9pbnQoeDB6W2tdLCB5MHpba10pOwogICAgICAgICAgfQogICAgICAgICAgb3V0cHV0LmxpbmVFbmQoKTsKICAgICAgICAgIG91dHB1dC5hcmVhRW5kKCk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGlmIChkZWZpbmVkMCkgewogICAgICAgIHgweltpXSA9ICt4MChkLCBpLCBkYXRhKSwgeTB6W2ldID0gK3kwKGQsIGksIGRhdGEpOwogICAgICAgIG91dHB1dC5wb2ludCh4MSA/ICt4MShkLCBpLCBkYXRhKSA6IHgweltpXSwgeTEgPyAreTEoZCwgaSwgZGF0YSkgOiB5MHpbaV0pOwogICAgICB9CiAgICB9CgogICAgaWYgKGJ1ZmZlcikgcmV0dXJuIG91dHB1dCA9IG51bGwsIGJ1ZmZlciArICIiIHx8IG51bGw7CiAgfQoKICBmdW5jdGlvbiBhcmVhbGluZSgpIHsKICAgIHJldHVybiBsaW5lKCkuZGVmaW5lZChkZWZpbmVkKS5jdXJ2ZShjdXJ2ZSkuY29udGV4dChjb250ZXh0KTsKICB9CgogIGFyZWEueCA9IGZ1bmN0aW9uKF8pIHsKICAgIHJldHVybiBhcmd1bWVudHMubGVuZ3RoID8gKHgwID0gdHlwZW9mIF8gPT09ICJmdW5jdGlvbiIgPyBfIDogY29uc3RhbnQkMTEoK18pLCB4MSA9IG51bGwsIGFyZWEpIDogeDA7CiAgfTsKCiAgYXJlYS54MCA9IGZ1bmN0aW9uKF8pIHsKICAgIHJldHVybiBhcmd1bWVudHMubGVuZ3RoID8gKHgwID0gdHlwZW9mIF8gPT09ICJmdW5jdGlvbiIgPyBfIDogY29uc3RhbnQkMTEoK18pLC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sKICBsLmFuZ2xlID0gbC54LCBkZWxldGUgbC54OwogIGwucmFkaXVzID0gbC55LCBkZWxldGUgbC55OwogIHJldHVybiBsOwp9Cgp2YXIgY2lyY2xlJDIgPSB7CiAgZHJhdzogZnVuY3Rpb24oY29udGV4dCwgc2l6ZSkgewogICAgdmFyIHIgPSBNYXRoLnNxcnQoc2l6ZSAvIHBpJDQpOwogICAgY29udGV4dC5tb3ZlVG8ociwgMCk7CiAgICBjb250ZXh0LmFyYygwLCAwLCByLCAwLCB0YXUkNCk7CiAgfQp9OwoKdmFyIGNyb3NzJDIgPSB7CiAgZHJhdzogZnVuY3Rpb24oY29udGV4dCwgc2l6ZSkgewogICAgdmFyIHIgPSBNYXRoLnNxcnQoc2l6ZSAvIDUpIC8gMjsKICAgIGNvbnRleHQubW92ZVRvKC0zICogciwgLXIpOwogICAgY29udGV4dC5saW5lVG8oLXIsIC1yKTsKICAgIGNvbnRleHQubGluZVRvKC1yLCAtMyAqIHIpOwogICAgY29udGV4dC5saW5lVG8ociwgLTMgKiByKTsKICAgIGNvbnRleHQubGluZVRvKHIsIC1yKTsKICAgIGNvbnRleHQubGluZVRvKDMgKiByLCAtcik7CiAgICBjb250ZXh0LmxpbmVUbygzICogciwgcik7CiAgICBjb250ZXh0LmxpbmVUbyhyLCByKTsKICAgIGNvbnRleHQubGluZVRvKHIsIDMgKiByKTsKICAgIGNvbnRleHQubGluZVRvKC1yLCAzICogcik7CiAgICBjb250ZXh0LmxpbmVUbygtciwgcik7CiAgICBjb250ZXh0LmxpbmVUbygtMyAqIHIsIHIpOwogICAgY29udGV4dC5jbG9zZVBhdGgoKTsKICB9Cn07Cgp2YXIgdGFuMzAgPSBNYXRoLnNxcnQoMSAvIDMpLAogICAgdGFuMzBfMiA9IHRhbjMwICogMjsKCnZhciBkaWFtb25kID0gewogIGRyYXc6IGZ1bmN0aW9uKGNvbnRleHQsIHNpemUpIHsKICAgIHZhciB5ID0gTWF0aC5zcXJ0KHNpemUgLyB0YW4zMF8yKSwKICAgICAgICB4ID0geSAqIHRhbjMwOwogICAgY29udGV4dC5tb3ZlVG8oMCwgLXkpOwogICAgY29udGV4dC5saW5lVG8oeCwgMCk7CiAgICBjb250ZXh0LmxpbmVUbygwLCB5KTsKICAgIGNvbnRleHQubGluZVRvKC14LCAwKTsKICAgIGNvbnRleHQuY2xvc2VQYXRoKCk7CiAgfQp9OwoKdmFyIGthID0gMC44OTA4MTMwOTE1MjkyODUyMjgxMCwKICAgIGtyID0gTWF0aC5zaW4ocGkkNCAvIDEwKSAvIE1hdGguc2luKDcgKiBwaSQ0IC8gMTApLAogICAga3ggPSBNYXRoLnNpbih0YXUkNCAvIDEwKSAqIGtyLAogICAga3kgPSAtTWF0aC5jb3ModGF1JDQgLyAxMCkgKiBrcjsKCnZhciBzdGFyID0gewogIGRyYXc6IGZ1bmN0aW9uKGNvbnRleHQsIHNpemUpIHsKICAgIHZhciByID0gTWF0aC5zcXJ0KHNpemUgKiBrYSksCiAgICAgICAgeCA9IGt4ICogciwKICAgICAgICB5ID0ga3kgKiByOwogICAgY29udGV4dC5tb3ZlVG8oMCwgLXIpOwogICAgY29udGV4dC5saW5lVG8oeCwgeSk7CiAgICBmb3IgKHZhciBpID0gMTsgaSA8IDU7ICsraSkgewogICAgICB2YXIgYSA9IHRhdSQ0ICogaSAvIDUsCiAgICAgICAgICBjID0gTWF0aC5jb3MoYSksCiAgICAgICAgICBzID0gTWF0aC5zaW4oYSk7CiAgICAgIGNvbnRleHQubGluZVRvKHMgKiByLCAtYyAqIHIpOwogICAgICBjb250ZXh0LmxpbmVUbyhjICogeCAtIHMgKiB5LCBzICogeCArIGMgKiB5KTsKICAgIH0KICAgIGNvbnRleHQuY2xvc2VQYXRoKCk7CiAgfQp9OwoKdmFyIHNxdWFyZSA9IHsKICBkcmF3OiBmdW5jdGlvbihjb250ZXh0LCBzaXplKSB7CiAgICB2YXIgdyA9IE1hdGguc3FydChzaXplKSwKICAgICAgICB4ID0gLXcgLyAyOwogICAgY29udGV4dC5yZWN0KHgsIHgsIHcsIHcpOwogIH0KfTsKCnZhciBzcXJ0MyA9IE1hdGguc3FydCgzKTsKCnZhciB0cmlhbmdsZSA9IHsKICBkcmF3OiBmdW5jdGlvbihjb250ZXh0LCBzaXplKSB7CiAgICB2YXIgeSA9IC1NYXRoLnNxcnQoc2l6ZSAvIChzcXJ0MyAqIDMpKTsKICAgIGNvbnRleHQubW92ZVRvKDAsIHkgKiAyKTsKICAgIGNvbnRleHQubGluZVRvKC1zcXJ0MyAqIHksIC15KTsKICAgIGNvbnRleHQubGluZVRvKHNxcnQzICogeSwgLXkpOwogICAgY29udGV4dC5jbG9zZVBhdGgoKTsKICB9Cn07Cgp2YXIgYyA9IC0wLjUsCiAgICBzID0gTWF0aC5zcXJ0KDMpIC8gMiwKICAgIGsgPSAxIC8gTWF0aC5zcXJ0KDEyKSwKICAgIGEgPSAoayAvIDIgKyAxKSAqIDM7Cgp2YXIgd3llID0gewogIGRyYXc6IGZ1bmN0aW9uKGNvbnRleHQsIHNpemUpIHsKICAgIHZhciByID0gTWF0aC5zcXJ0KHNpemUgLyBhKSwKICAgICAgICB4MCA9IHIgLyAyLAogICAgICAgIHkwID0gciAqIGssCiAgICAgICAgeDEgPSB4MCwKICAgICAgICB5MSA9IHIgKiBrICsgciwKICAgICAgICB4MiA9IC14MSwKICAgICAgICB5MiA9IHkxOwogICAgY29udGV4dC5tb3ZlVG8oeDAsIHkwKTsKICAgIGNvbnRleHQubGluZVRvKHgxLCB5MSk7CiAgICBjb250ZXh0LmxpbmVUbyh4MiwgeTIpOwogICAgY29udGV4dC5saW5lVG8oYyAqIHgwIC0gcyAqIHkwLCBzICogeDAgKyBjICogeTApOwogICAgY29udGV4dC5saW5lVG8oYyAqIHgxIC0gcyAqIHkxLCBzICogeDEgKyBjICogeTEpOwogICAgY29udGV4dC5saW5lVG8oYyAqIHgyIC0gcyAqIHkyLCBzICogeDIgKyBjICogeTIpOwogICAgY29udGV4dC5saW5lVG8oYyAq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lzLl9jb250ZXh0ID0gY29udGV4dDsKfQoKQmFzaXNDbG9zZWQucHJvdG90eXBlID0gewogIGFyZWFTdGFydDogbm9vcCQzLAogIGFyZWFFbmQ6IG5vb3AkMywKICBsaW5lU3RhcnQ6IGZ1bmN0aW9uKCkgewogICAgdGhpcy5feDAgPSB0aGlzLl94MSA9IHRoaXMuX3gyID0gdGhpcy5feDMgPSB0aGlzLl94NCA9CiAgICB0aGlzLl95MCA9IHRoaXMuX3kxID0gdGhpcy5feTIgPSB0aGlzLl95MyA9IHRoaXMuX3k0ID0gTmFOOwogICAgdGhpcy5fcG9pbnQgPSAwOwogIH0sCiAgbGluZUVuZDogZnVuY3Rpb24oKSB7CiAgICBzd2l0Y2ggKHRoaXMuX3BvaW50KSB7CiAgICAgIGNhc2UgMTogewogICAgICAgIHRoaXMuX2NvbnRleHQubW92ZVRvKHRoaXMuX3gyLCB0aGlzLl95Mik7CiAgICAgICAgdGhpcy5fY29udGV4dC5jbG9zZVBhdGgoKTsKICAgICAgICBicmVhazsKICAgICAgfQogICAgICBjYXNlIDI6IHsKICAgICAgICB0aGlzLl9jb250ZXh0Lm1vdmVUbygodGhpcy5feDIgKyAyICogdGhpcy5feDMpIC8gMywgKHRoaXMuX3kyICsgMiAqIHRoaXMuX3kzKSAvIDMpOwogICAgICAgIHRoaXMuX2NvbnRleHQubGluZVRvKCh0aGlzLl94MyArIDIgKiB0aGlzLl94MikgLyAzLCAodGhpcy5feTMgKyAyICogdGhpcy5feTIpIC8gMyk7CiAgICAgICAgdGhpcy5fY29udGV4dC5jbG9zZVBhdGgoKTsKICAgICAgICBicmVhazsKICAgICAgfQogICAgICBjYXNlIDM6IHsKICAgICAgICB0aGlzLnBvaW50KHRoaXMuX3gyLCB0aGlzLl95Mik7CiAgICAgICAgdGhpcy5wb2ludCh0aGlzLl94MywgdGhpcy5feTMpOwogICAgICAgIHRoaXMucG9pbnQodGhpcy5feDQsIHRoaXMuX3k0KTsKICAgICAgICBicmVhazsKICAgIC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1ZShkLCBrZXkpIHsKICByZXR1cm4gZFtrZXldOwp9CgpmdW5jdGlvbiBzdGFjaygpIHsKICB2YXIga2V5cyA9IGNvbnN0YW50JDExKFtdKSwKICAgICAgb3JkZXIgPSBub25lJDIsCiAgICAgIG9mZnNldCA9IG5vbmUkMSwKICAgICAgdmFsdWUgPSBzdGFja1ZhbHVlOwoKICBmdW5jdGlvbiBzdGFjayhkYXRhKSB7CiAgICB2YXIga3ogPSBrZXlzLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyksCiAgICAgICAgaSwKICAgICAgICBtID0gZGF0YS5sZW5ndGgsCiAgICAgICAgbiA9IGt6Lmxlbmd0aCwKICAgICAgICBzeiA9IG5ldyBBcnJheShuKSwKICAgICAgICBvejsKCiAgICBmb3IgKGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgIGZvciAodmFyIGtpID0ga3pbaV0sIHNpID0gc3pbaV0gPSBuZXcgQXJyYXkobSksIGogPSAwLCBzaWo7IGogPCBtOyArK2opIHsKICAgICAgICBzaVtqXSA9IHNpaiA9IFswLCArdmFsdWUoZGF0YVtqXSwga2ksIGosIGRhdGEpXTsKICAgICAgICBzaWouZGF0YSA9IGRhdGFbal07CiAgICAgIH0KICAgICAgc2kua2V5ID0ga2k7CiAgICB9CgogICAgZm9yIChpID0gMCwgb3ogPSBvcmRlcihzeik7IGkgPCBuOyArK2kpIHsKICAgICAgc3pbb3pbaV1dLmluZGV4ID0gaTsKICAgIH0KCiAgICBvZmZzZXQoc3osIG96KTsKICAgIHJldHVybiBzejsKICB9CgogIHN0YWNrLmtleXMgPSBmdW5jdGlvbihfKSB7CiAgICByZXR1cm4gYXJndW1lbnRzLmxlbmd0aCA/IChrZXlzID0gdHlwZW9mIF8gPT09ICJmdW5jdGlvbiIgPyBfIDogY29uc3RhbnQkMTEoc2xpY2UkNi5jYWxsKF8pKSwgc3RhY2spIDoga2V5czsKICB9OwoKICBzdGFjay52YWx1ZSA9IGZ1bmN0aW9uKF8pIH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udDsKICAgIG5vZGUuQyA9IHRydWU7CgogICAgYWZ0ZXIgPSBub2RlOwogICAgd2hpbGUgKHBhcmVudCAmJiBwYXJlbnQuQykgewogICAgICBncmFuZHBhID0gcGFyZW50LlU7CiAgICAgIGlmIChwYXJlbnQgPT09IGdyYW5kcGEuTCkgewogICAgICAgIHVuY2xlID0gZ3JhbmRwYS5SOwogICAgICAgIGlmICh1bmNsZSAmJiB1bmNsZS5DKSB7CiAgICAgICAgICBwYXJlbnQuQyA9IHVuY2xlLkMgPSBmYWxzZTsKICAgICAgICAgIGdyYW5kcGEuQyA9IHRydWU7CiAgICAgICAgICBhZnRlciA9IGdyYW5kcGE7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmIChhZnRlciA9PT0gcGFyZW50LlIpIHsKICAgICAgICAgICAgUmVkQmxhY2tSb3RhdGVMZWZ0KHRoaXMsIHBhcmVudCk7CiAgICAgICAgICAgIGFmdGVyID0gcGFyZW50OwogICAgICAgICAgICBwYXJlbnQgPSBhZnRlci5VOwogICAgICAgICAgfQogICAgICAgICAgcGFyZW50LkMgPSBmYWxzZTsKICAgICAgICAgIGdyYW5kcGEuQyA9IHRydWU7CiAgICAgICAgICBSZWRCbGFja1JvdGF0ZVJpZ2h0KHRoaXMsIGdyYW5kcGEpOwogICAgICAgIH0KICAgICAgfSBlbHNlIHsKICAgICAgICB1bmNsZSA9IGdyYW5kcGEuTDsKICAgICAgICBpZiAodW5jbGUgJiYgdW5jbGUuQykgewogICAgICAgICAgcGFyZW50LkMgPSB1bmNsZS5DID0gZmFsc2U7CiAgICAgICAgICBncmFuZHBhLkMgPSB0cnVlOwogICAgICAgICAgYWZ0ZXIgPSBncmFuZHBhOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoYWZ0ZXIgPT09IHBhcmVudC5MKSB7CiAgICAgICAgICAgIFJlZEJsYWNrUm90YXRlUmlnaHQodGhpcywgcGFyZW50KTsKICAgICAgICAgICAgYWZ0ZXIgPSBw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WdodCkgewogICAgICAgIHBhcmVudCA9IG5leHQuVTsKICAgICAgICBuZXh0LlUgPSBub2RlLlU7CiAgICAgICAgbm9kZSA9IG5leHQuUjsKICAgICAgICBwYXJlbnQuTCA9IG5vZGU7CiAgICAgICAgbmV4dC5SID0gcmlnaHQ7CiAgICAgICAgcmlnaHQuVSA9IG5leHQ7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgbmV4dC5VID0gcGFyZW50OwogICAgICAgIHBhcmVudCA9IG5leHQ7CiAgICAgICAgbm9kZSA9IG5leHQuUjsKICAgICAgfQogICAgfSBlbHNlIHsKICAgICAgcmVkID0gbm9kZS5DOwogICAgICBub2RlID0gbmV4dDsKICAgIH0KCiAgICBpZiAobm9kZSkgbm9kZS5VID0gcGFyZW50OwogICAgaWYgKHJlZCkgcmV0dXJuOwogICAgaWYgKG5vZGUgJiYgbm9kZS5DKSB7IG5vZGUuQyA9IGZhbHNlOyByZXR1cm47IH0KCiAgICBkbyB7CiAgICAgIGlmIChub2RlID09PSB0aGlzLl8pIGJyZWFrOwogICAgICBpZiAobm9kZSA9PT0gcGFyZW50LkwpIHsKICAgICAgICBzaWJsaW5nID0gcGFyZW50LlI7CiAgICAgICAgaWYgKHNpYmxpbmcuQykgewogICAgICAgICAgc2libGluZy5DID0gZmFsc2U7CiAgICAgICAgICBwYXJlbnQuQyA9IHRydWU7CiAgICAgICAgICBSZWRCbGFja1JvdGF0ZUxlZnQodGhpcywgcGFyZW50KTsKICAgICAgICAgIHNpYmxpbmcgPSBwYXJlbnQuUjsKICAgICAgICB9CiAgICAgICAgaWYgKChzaWJsaW5nLkwgJiYgc2libGluZy5MLkMpCiAgICAgICAgICAgIHx8IChzaWJsaW5nLlIgJiYgc2libGluZy5SLkMpKSB7CiAgICAgICAgICBpZiAoIXNpYmxpbmcuUiB8fCAhc2libGluZy5SLkMpIHsKICAgICAgICAgICAgc2libGluZy5MLkMgPSBmYWxzZTsKICAgICAgICAgICAgc2libGluZy5DID0gdHJ1ZTsKICAgICAgICAgICAgUmVkQmxhY2tSb3RhdGVSaWdodCh0aGlzLCBzaWJsaW5nKTsKICAgICAgICAgICAgc2libGluZyA9IHBhcmVudC5SOwogICAgICAgICAgfQogICAgICAgICAgc2libGluZy5DID0gcGFyZW50LkM7CiAgICAgICAgICBwYXJlbnQuQyA9IHNpYmxpbmcuUi5DID0gZmFsc2U7CiAgICAgICAgICBSZWRCbGFja1JvdGF0ZUxlZnQodGhpcywgcGFyZW50KTsKICAgICAgICAgIG5vZGUgPSB0aGlzLl87CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgc2libGluZyA9IHBhcmVudC5MOwogICAgICAgIGlmIChzaWJsaW5nLkMpIHsKICAgICAgICAgIHNpYmxpbmcuQyA9IGZhbHNlOwogICAgICAgICAgcGFyZW50LkMgPSB0cnVlOwogICAgICAgICAgUmVkQmxhY2tSb3RhdGVSaWdodCh0aGlzLCBwYXJlbnQpOwogICAgICAgICAgc2libGluZyA9IHBhcmVudC5MOwogICAgICAgIH0KICAgICAgICBpZiAoKHNpYmxpbmcuTCAmJiBzaWJsaW5nLkwuQykKICAgICAgICAgIHx8IChzaWJsaW5nLlIgJiYgc2libGluZy5SLkMpKSB7CiAgICAgICAgICBpZiAoIXNpYmxpbmcuTCB8fCAhc2libGluZy5MLkMpIHsKICAgICAgICAgICAgc2libGluZy5SLkMgPSBmYWxzZTsKICAgICAgICAgICAgc2libGluZy5DID0gdHJ1ZTsKICAgICAgICAgICAgUmVkQmxhY2tSb3RhdGVMZWZ0KHRoaXMsIHNpYmxpbmcpOwogICAgICAgICAgICBzaWJsaW5nID0gcGFyZW50Lkw7CiAgICAgICAgICB9CiAgICAgICAgICBzaWJsaW5nLkMgPSBwYXJlbnQuQzsKICAgICAgICAgIHBhcmVudC5DID0gc2libGluZy5MLkMgPSBmYWxzZTsKICAgICAgICAgIFJlZEJsYWNrUm90YXRlUmlnaHQodGhpcywgcGFyZW50KTsKICAgIC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2VbMV0sCiAgICAgIGF4ID0gYVswXSwKICAgICAgYXkgPSBhWzFdLAogICAgICBieCA9IGJbMF0sCiAgICAgIGJ5ID0gYlsxXSwKICAgICAgdDAgPSAwLAogICAgICB0MSA9IDEsCiAgICAgIGR4ID0gYnggLSBheCwKICAgICAgZHkgPSBieSAtIGF5LAogICAgICByOwoKICByID0geDAgLSBheDsKICBpZiAoIWR4ICYmIHIgPiAwKSByZXR1cm47CiAgciAvPSBkeDsKICBpZiAoZHggPCAwKSB7CiAgICBpZiAociA8IHQwKSByZXR1cm47CiAgICBpZiAociA8IHQxKSB0MSA9IHI7CiAgfSBlbHNlIGlmIChkeCA+IDApIHsKICAgIGlmIChyID4gdDEpIHJldHVybjsKICAgIGlmIChyID4gdDApIHQwID0gcjsKICB9CgogIHIgPSB4MSAtIGF4OwogIGlmICghZHggJiYgciA8IDApIHJldHVybjsKICByIC89IGR4OwogIGlmIChkeCA8IDApIHsKICAgIGlmIChyID4gdDEpIHJldHVybjsKICAgIGlmIChyID4gdDApIHQwID0gcjsKICB9IGVsc2UgaWYgKGR4ID4gMCkgewogICAgaWYgKHIgPCB0MCkgcmV0dXJuOwogICAgaWYgKHIgPCB0MSkgdDEgPSByOwogIH0KCiAgciA9IHkwIC0gYXk7CiAgaWYgKCFkeSAmJiByID4gMCkgcmV0dXJuOwogIHIgLz0gZHk7CiAgaWYgKGR5IDwgMCkgewogICAgaWYgKHIgPCB0MCkgcmV0dXJuOwogICAgaWYgKHIgPCB0MSkgdDEgPSByOwogIH0gZWxzZSBpZiAoZHkgPiAwKSB7CiAgICBpZiAociA+IHQxKSByZXR1cm47CiAgICBpZiAociA+IHQwKSB0MCA9IHI7CiAgfQoKICByID0geTEgLSBheTsKICBpZiAoIWR5ICYmIHIgPCAwKSByZXR1cm47CiAgciAvPSBkeTsKICBpZiAoZHkgPCAwKSB7CiAgICBpZiAociA+IHQxKSByZXR1cm47CiAgICBpZiAociA+IHQwKSB0MCA9IHI7CiAgfSBlbHNlIGlmIChkeSA+IDApIHsKICAgIGlmIChyIDwgdDApIHJldHVybjsKICAgIGlmIChyIDwgdDEpIHQxID0gcjsKICB9CgogIGlmICghKHQwID4gMCkgJiYgISh0MSA8IDEpKSByZXR1cm4gdHJ1ZTsgLy8gVE9ETyBCZXR0ZXIgY2hlY2s/CgogIGlmICh0MCA+IDApIGVkZ2VbMF0gPSBbYXggKyB0MCAqIGR4LCBheSArIHQwICogZHldOwogIGlmICh0MSA8IDEpIGVkZ2VbMV0gPSBbYXggKyB0MSAqIGR4LCBheSArIHQxICogZHldOwogIHJldHVybiB0cnVlOwp9CgpmdW5jdGlvbiBjb25uZWN0RWRnZShlZGdlLCB4MCwgeTAsIHgxLCB5MSkgewogIHZhciB2MSA9IGVkZ2VbMV07CiAgaWYgKHYxKSByZXR1cm4gdHJ1ZTsKCiAgdmFyIHYwID0gZWRnZVswXSwKICAgICAgbGVmdCA9IGVkZ2UubGVmdCwKICAgICAgcmlnaHQgPSBlZGdlLnJpZ2h0LAogICAgICBseCA9IGxlZnRbMF0sCiAgICAgIGx5ID0gbGVmdFsxXSwKICAgICAgcnggPSByaWdodFswXSwKICAgICAgcnkgPSByaWdodFsxXSwKICAgICAgZnggPSAobHggKyByeCkgLyAyLAogICAgICBmeSA9IChseSArIHJ5KSAvIDIsCiAgICAgIGZtLAogICAgICBmYjsKCiAgaWYgKHJ5ID09PSBseSkgewogICAgaWYgKGZ4IDwgeDAgfHwgZnggPj0geDEpIHJldHVybjsKICAgIGlmIChseCA+IHJ4KSB7CiAgICAgIGlmICghdjApIHYwID0gW2Z4LCB5MF07CiAgICAgIGVsc2UgaWYgKHYwWzFdID49IHkxKSByZXR1cm47CiAgICAgIHYxID0gW2Z4LCB5MV07CiAgICB9IGVsc2UgewogICAgICBpZiAoIXYwKSB2MCA9IFtmeCwgeTFdOwogICAgICBlbHNlIGlmICh2MFsxXSA8IHkwKSByZXR1cm47CiAgICAgIHYxID0gW2Z4LCB5MF07CiAgICB9CiAgfSBlbHNlIHsKICAgIGZtID0gKGx4IC0gcngpIC8gKHJ5IC0gbHkpOwogICAgZmIgPSBmeSAtIGZtICogZng7CiAgICBpZiAoZm0gPCAtMSB8fCBmbSA+IDEpIHsKICAgICAgaWYgKGx4ID4gcngpIHsKICAgICAgICBpZiAoIXYwKSB2MCA9IFsoeTAgLSBmYikgLyBmbSwgeTBdOwogICAgICAgIGVsc2UgaWYgKHYwWzFdID49IHkxKSByZXR1cm47CiAgICAgICAgdjEgPSBbKHkxIC0gZmIpIC8gZm0sIHkxXTsKICAgICAgfSBlbHNlIHsKICAgICAgICBpZiAoIXYwKSB2MCA9IFsoeTEgLSBmYikgLyBmbSwgeTFdOwogICAgICAgIGVsc2UgaWYgKHYwWzFdIDwgeTApIHJldHVybjsKICAgICAgICB2MSA9IFsoeTAgLSBmYikgLyBmbSwgeTBdOwogICAgICB9CiAgICB9IGVsc2UgewogICAgICBpZiAobHkgPCByeSkgewogICAgICAgIGlmICghdjApIHYwID0gW3gwLCBmbSAqIHgwICsgZmJdOwogICAgICAgIGVsc2UgaWYgKHYwWzBdID49IHgxKSByZXR1cm47CiAgICAgICAgdjEgPSBbeDEsIGZtICogeDEgKyBmYl07CiAgICAgIH0gZWxzZSB7CiAgICAgICAgaWYgKCF2MCkgdjAgPSBbeDEsIGZtICogeDEgKyBmYl07CiAgICAgICAgZWxzZSBpZiAodjBbMF0gPCB4MCkgcmV0dXJuOwogICAgICAgIHYxID0gW3gwLCBmbSAqIHgwICsgZmJdOwogICAgICB9CiAgICB9CiAgfQoKICBlZGdlWzBdID0gdjA7CiAgZWRnZVsxXSA9IHYxOwogIHJldHVybiB0cnVlOwp9CgpmdW5jdGlvbiBjbGlwRWRnZXMoeDAsIHkwLCB4MSwgeTEpIHsKICB2YXIgaSA9IGVkZ2VzLmxlbmd0aCwKICAgICAgZWRnZTsKCiAgd2hpbGUgKGktLSkgewogICAgaWYgKCFjb25uZWN0RWRnZShlZGdlID0gZWRnZXNbaV0sIHgwLCB5MCwgeD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ICAgICBkaXJlY3RyaXggPSBzaXRlWzFdLAogICAgICBsQXJjLAogICAgICByQXJjLAogICAgICBkeGwsCiAgICAgIGR4ciwKICAgICAgbm9kZSA9IGJlYWNoZXMuXzsKCiAgd2hpbGUgKG5vZGUpIHsKICAgIGR4bCA9IGxlZnRCcmVha1BvaW50KG5vZGUsIGRpcmVjdHJpeCkgLSB4OwogICAgaWYgKGR4bCA+IGVwc2lsb24kNCkgbm9kZSA9IG5vZGUuTDsgZWxzZSB7CiAgICAgIGR4ciA9IHggLSByaWdodEJyZWFrUG9pbnQobm9kZSwgZGlyZWN0cml4KTsKICAgICAgaWYgKGR4ciA+IGVwc2lsb24kNCkgewogICAgICAgIGlmICghbm9kZS5SKSB7CiAgICAgICAgICBsQXJjID0gbm9kZTsKICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBub2RlID0gbm9kZS5SOwogICAgICB9IGVsc2UgewogICAgICAgIGlmIChkeGwgPiAtZXBzaWxvbiQ0KSB7CiAgICAgICAgICBsQXJjID0gbm9kZS5QOwogICAgICAgICAgckFyYyA9IG5vZGU7CiAgICAgICAgfSBlbHNlIGlmIChkeHIgPiAtZXBzaWxvbiQ0KSB7CiAgICAgICAgICBsQXJjID0gbm9kZTsKICAgICAgICAgIHJBcmMgPSBub2RlLk47CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGxBcmMgPSByQXJjID0gbm9kZTsKICAgICAgICB9CiAgICAgICAgYnJlYWs7CiAgICAgIH0KICAgIH0KICB9CgogIGNyZWF0ZUNlbGwoc2l0ZSk7CiAgdmFyIG5ld0FyYyA9IGNyZWF0ZUJlYWNoKHNpdGUpOwogIGJlYWNoZXMuaW5zZXJ0KGxBcmMsIG5ld0FyYyk7CgogIGlmICghbEFyYyAmJiAhckFyYykgcmV0dXJuOwoKICBpZiAobEFyYyA9PT0gckFyYykgewogICAgZGV0YWNoQ2lyY2xlKGxBcmMpOwogICAgckFyYyA9IGNyZWF0ZUJlYWNoKGxBc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gICB2YXIgc2NhbGUgPSBkMy5zY2FsZUxpbmVhcigpDQogICAgICAgICAgICAgICAgICAuZG9tYWluKGNoX2RvbWFpbikubmljZSgpDQogICAgICAgICAgICAgICAgICAucmFuZ2UoWzAsIHhfc2NhbGVfd2lkdGhdKTsNCg0KICAgIC8vIEFkZCBzY2FsZXMgdG8gYXhpcw0KICAgIHZhciB4X2F4aXMgPSBkMy5heGlzQm90dG9tKCkNCiAgICAgICAgICAgICAgICAgLnNjYWxlKHNjYWxlKQ0KICAgICAgICAgICAgICAgICAudGlja3MoNSkNCiAgICAgICAgICAgICAgICAgLnRpY2tGb3JtYXQoZnVuY3Rpb24oZCl7DQogICAgICAgICAgICAgICAgICAgaWYoZD49MTAwMDAwMDAwMCl7IHJldHVybiAoZC8xMDAwMDAwMDAwKSsiR2IiDQogICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmKGQ+PTEwMDAwMDApew0KDQogICAgICAgICAgICAgICAgICAgcmV0dXJuIChkLzEwMDAwMDApKyJNYiI7DQogICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoZD49MTAwMCkgew0KICAgICAgICAgICAgICAgICAgIHJldHVybiAoZC8xMDAwKSsia2IiOw0KICAgICAgICAgICAgICAgICB9IGVsc2UgeyByZXR1cm4gZCsiYnAiO319KTsNCg0KICAgIC8vQXBwZW5kIGdyb3VwIGFuZCBpbnNlcnQgYXhpcw0KICAgIHN2Zy5hcHBlbmQoImciKQ0KICAgIC5hdHRyKCJ0cmFuc2Zvcm0iLCAidHJhbnNsYXRlKCIrKGxlZnRfbWFyZ2luIC0gYXJjX3JhZGl1cykrIiwiICsgeF9zY2FsZV9wb3MgKyAiKSIpDQogICAgLmNhbGwoeF9heGlzKTsNCg0KDQogICAgLyogYXhpcyB0aXRsZSAqLw0KICAgIHN2Zy5hcHBlbmQoInRleHQiKQ0KICAgIC5hdHRyKCJ4Iix4X3NjYWxlX3dpZHRoLzIpDQogICAgLmF0dHIoInkiLHhfc2NhbGVfcG9z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oImZpbGwiLCBjaHJfY29sb3IpDQogICAgICAuYXR0cigiY2xhc3MiLCJjaExvYyIpDQogICAgICAuYXR0cigiaWQiLGZ1bmN0aW9uKGQsail7IHJldHVybiBuTG9jaVtpXS5uYW1lKyItIisoaisxKSsiLSIrcGxvaWR5O30pOw0KDQoNCg0KICAgICAgLy9sYWJlbGxpbmdzDQogICAgICBzdmcuc2VsZWN0QWxsKCIudGV4dHMiKQ0KICAgICAgLmRhdGEoYWxsRGF0YVtpXSkNCiAgICAgIC5lbnRlcigpDQogICAgICAuYXBwZW5kKCJ0ZXh0IikNCiAgICAgIC5hdHRyKCJjbGFzcyIsImxhYmVscyIpDQogICAgICAuYXR0cigieSIsICh5X3ZhbCArIGkqY2hyX3NwYWNpbmcgKyAocGxvaWR5IC0gMSkqKGNoX3dpZHRoICsxICkpLTIpDQogICAgICAuYXR0cigieCIsIGZ1bmN0aW9uKGQsaSl7cmV0dXJuIGxlZnRfbWFyZ2luICsgaSpsb2NpX3dpZHRoO30pDQogICAgICAuYXR0cigiaWQiLGZ1bmN0aW9uKGQsail7cmV0dXJuICJMIituTG9jaVtpXS5uYW1lKyItIisoaisxKSsiLSIrcGxvaWR5O30pLnRleHQoIiIpDQogICAgICAuYXR0cigiZm9udC1mYW1pbHkiLCAic2Fucy1zZXJpZiIpDQogICAgICAuYXR0cigiZm9udC1zaXplIiwgIjlweCIpDQogICAgICAuc3R5bGUoInRleHQtYW5jaG9yIiwgIm1pZGRsZSIpDQogICAgICAgIC5hdHRyKCJmaWxsIiwgImJsYWNrIik7DQoNCg0KDQoNCg0KDQoNCg0KDQogICAgIC8qICAgZmluYWwgY2FwICovDQoNCg0KICAgICAgcG9zeD1sZWZ0X21hcmdpbisobkxvY2lbaV0ubikqbG9jaV93aWR0aA0KICAgICAgcG9zeT15X3ZhbCArIGkqY2hyX3NwYWNpbmcrICsgYXJjX3JhZGl1cyArIChwbG9pZHkgLSAxKSooY2hfd2lkdGggKzEgKQ0KICAgICBzdmcuYXB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Nmb3JtIiwgInRyYW5zbGF0ZSgiKygod2lkdGgtMzUtKHRpbWVzKjUwKSktbGdfeCkrIiwiICsgKChoZWlnaHQtMTAwKS1sZ195ICkrICIpIikNCiAgICAuY2FsbChsZWdlbmQyKTsNCg0KfSAgKi8NCiAgICBjaExpbkdyYWRWW3RpbWVzXSA9IHN2Zy5hcHBlbmQoImRlZnMiKS5hcHBlbmQoImxpbmVhckdyYWRpZW50IikNCiAgICAgICAgICAgICAgICAgICAgICAgICAuYXR0cigiaWQiLCBmdW5jdGlvbihkKXsgcmV0dXJuICJsaW5lYXItZ3JhZGllbnQtY2hyb21ILSIrdGltZXM7fSkNCiAgICAgICAgICAgICAgICAgICAgICAgICAuYXR0cigieDEiLCAiMCUiKQ0KICAgICAgICAgICAgICAgICAgICAgICAgIC5hdHRyKCJ5MSIsICIwJSIpDQogICAgICAgICAgICAgICAgICAgICAgICAgLmF0dHIoIngyIiwgIjAlIikNCiAgICAgICAgICAgICAgICAgICAgICAgICAuYXR0cigieTIiLCAiMTAwJSIpDQogICAgICAgICAgICAgICAgICAgICAgICAgLnNlbGVjdEFsbCgic3RvcCIpDQogICAgICAgIC5kYXRhKCBjb2xvcnNbdGltZXNdLnJhbmdlKCkgKQ0KICAgICAgICAuZW50ZXIoKS5hcHBlbmQoInN0b3AiKQ0KICAgICAgICAuYXR0cigib2Zmc2V0IiwgZnVuY3Rpb24oZCxpKSB7IHJldHVybiBpLyhjb2xvcnNbdGltZXNdLnJhbmdlKCkubGVuZ3RoLTEpOyB9KQ0KICAgICAgICAuYXR0cigic3RvcC1jb2xvciIsIGZ1bmN0aW9uKGQpIHsgcmV0dXJuIGQ7IH0pOw0KDQoNCmlmKGxlZ2VuZCl7DQogICAgICBzdmcuYXBwZW5kKCdyZWN0JykNCiAgICAgIC5hdHRyKCJoZWlnaHQiLDEwMCkuYXR0cigid2lkdGgiLDEwKS5hdHRyKCJ5IiwoKGhlaWdodC05OSktbGdfeSkpLmF0dHIoIngiLCgod2lkdG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ICAgICAgIGFsbERhdGFxW2ldPWQzLnJhbmdlKG5Mb2NpW2ldLnEpOw0KDQogICAgfQ0KDQogICAgZm9yKGk9MDtpPCBuTG9jaS5sZW5ndGg7aSsrKXsNCg0KICAgICAgICAvKiAgZmlyc3QgY2FwICovDQogICAgICAgIHBvc3g9bGVmdF9tYXJnaW47DQogICAgICAgIHBvc3k9eV92YWwgKyBpKmNocl9zcGFjaW5nKyArIGFyY19yYWRpdXMgKyAocGxvaWR5IC0gMSkqKGNoX3dpZHRoICsxICkNCiAgICAgICAgc3ZnLmFwcGVuZCgiZyIpDQogICAgICAgICAgICAuYXR0cigidHJhbnNmb3JtIiwgInRyYW5zbGF0ZSgiK3Bvc3krIiwiK3Bvc3grIikiKQ0KICAgICAgICAgICAgIC5hcHBlbmQoInBhdGgiKQ0KICAgICAgICAgICAgIC5zdHlsZSgiZmlsbCIsIGNocl9jb2xvcikNCiAgICAgICAgICAgICAuYXR0cigiZCIsIGFyY1RvcCk7DQoNCiAgICAgICAgLyogIHAgYXJtICovDQogICAgICAgIHN2Zy5zZWxlY3RBbGwoIi5yZWN0cyIpDQogICAgICAgICAgLmRhdGEoYWxsRGF0YXBbaV0pDQogICAgICAgICAgLmVudGVyKCkNCiAgICAgICAgICAuYXBwZW5kKCJyZWN0IikNCiAgICAgICAgICAuYXR0cigieCIsIHlfdmFsICsgaSpjaHJfc3BhY2luZyArIChwbG9pZHkgLSAxKSooY2hfd2lkdGggKzEgKSkNCiAgICAgICAgICAuYXR0cigiaGVpZ2h0Iixsb2NpX3dpZHRoICkNCiAgICAgICAgICAuYXR0cigieSIsIGZ1bmN0aW9uKGQsaSl7cmV0dXJuIGxlZnRfbWFyZ2luICsgaSpsb2NpX3dpZHRoO30pDQogICAgICAgICAgLmF0dHIoIndpZHRoIixjaF93aWR0aCApDQogICAgICAgICAgLmF0dHIoImZpbGwiLCBjaHJfY29sb3IpDQogICAgICAgICAgLmF0dHIoImNsYXNzIiwiY2hMb2MiKQ0KICAgICAg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1lcyo1MCkpLWxnX3gpKyIsIiArICgoaGVpZ2h0LTEwMCktbGdfeSApKyAiKSIpDQogICAgLmNhbGwobGVnZW5kMik7DQp9ICAqLw0KDQogICAgY2hMaW5HcmFkVlt0aW1lc10gPSBzdmcuYXBwZW5kKCJkZWZzIikuYXBwZW5kKCJsaW5lYXJHcmFkaWVudCIpDQogICAgICAgICAgICAgICAgICAgICAgICAgLmF0dHIoImlkIiwgZnVuY3Rpb24oZCl7IHJldHVybiAibGluZWFyLWdyYWRpZW50LWNocm9tSC0iK3RpbWVzO30pDQogICAgICAgICAgICAgICAgICAgICAgICAgLmF0dHIoIngxIiwgIjAlIikNCiAgICAgICAgICAgICAgICAgICAgICAgICAuYXR0cigieTEiLCAiMCUiKQ0KICAgICAgICAgICAgICAgICAgICAgICAgIC5hdHRyKCJ4MiIsICIwJSIpDQogICAgICAgICAgICAgICAgICAgICAgICAgLmF0dHIoInkyIiwgIjEwMCUiKQ0KICAgICAgICAgICAgICAgICAgICAgICAgIC5zZWxlY3RBbGwoInN0b3AiKQ0KICAgICAgICAuZGF0YSggY29sb3JzW3RpbWVzXS5yYW5nZSgpICkNCiAgICAgICAgLmVudGVyKCkuYXBwZW5kKCJzdG9wIikNCiAgICAgICAgLmF0dHIoIm9mZnNldCIsIGZ1bmN0aW9uKGQsaSkgeyByZXR1cm4gaS8oY29sb3JzW3RpbWVzXS5yYW5nZSgpLmxlbmd0aC0xKTsgfSkNCiAgICAgICAgLmF0dHIoInN0b3AtY29sb3IiLCBmdW5jdGlvbihkKSB7IHJldHVybiBkOyB9KTsNCg0KaWYobGVnZW5kKXsNCiAgICAgIHN2Zy5hcHBlbmQoJ3JlY3QnKQ0KICAgICAgLmF0dHIoImhlaWdodCIsMTAwKS5hdHRyKCJ3aWR0aCIsMTApLmF0dHIoInkiLCgoaGVpZ2h0LTk5KS1sZ195KSkuYXR0cigieCIsKCh3aWR0aC00NS0odGltZXMqNTApKS1sZ194KSkNCiAgICAgIC5zdHlsZSgiZ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hEYXRhLmxlbmd0aDtpKyspew0KDQogICAgICAgICAgYVtpXT1IVE1MV2lkZ2V0cy5kYXRhZnJhbWVUb0QzKHguY2hEYXRhW2ldKTsNCiAgICAgICAgfQ0KICAgICAgICBmb3IoaT0wO2k8eC5uTG9jaS5sZW5ndGg7aSsrKXsNCg0KICAgICAgICAgIGJbaV09SFRNTFdpZGdldHMuZGF0YWZyYW1lVG9EMyh4Lm5Mb2NpW2ldKTsNCiAgICAgICAgfQ0KDQogICAgICAgIGNocm9tb01hcChhLA0KICAgICAgICAgIGIsDQogICAgICAgICAgeC5wbG9pZHlfbiwNCiAgICAgICAgICB4LnRpdGxlLA0KICAgICAgICAgIHguY250LA0KICAgICAgICAgIHguY2hfZ2FwLA0KICAgICAgICAgIHgudG9wX21hcmdpbiwNCiAgICAgICAgICB4LmxlZnRfbWFyZ2luLA0KICAgICAgICAgIHguY2hyX3dpZHRoLA0KICAgICAgICAgIHguY2hyX2xlbmd0aCwNCiAgICAgICAgICB4LmNocl9jb2wsDQogICAgICAgICAgeC5oZWF0bWFwLA0KICAgICAgICAgIHgudl9hbGlnbiwNCiAgICAgICAgICB4LmNoX2RvbWFpbiwNCiAgICAgICAgICB4LmxnX3gsDQogICAgICAgICAgeC5sZ195LA0KICAgICAgICAgIHguaGVhdF9zY2FsZSwNCiAgICAgICAgICB4LmxhYmVscywNCiAgICAgICAgICB4LmRpdl9pZCwNCiAgICAgICAgICB4LncsDQogICAgICAgICAgeC5oLHgucm5nLHguaGVhdF9jb2wseC5hbl9jb2wseC5jaF90ZXh0LHgubGVnZW5kLHguYWdncmVnYXRlX2Z1bmMNCg0KKTsNCg0KDQoNCiAgICAgIH0sDQoNCiAgICAgIHJlc2l6ZTogZnVuY3Rpb24od2lkdGgsaGVpZ2gpIHsNCg0KICAgICAgICAvLyBhbHJlYWR5IGhhbmRsZWQgYnkgbWFpbiBmdW5jdGlvbiB0aGF0IHJlbmRlciBwbG90DQoNCiAgICAgIH0NCg0KICAgIH07DQogIH0NCn0pOw0K"></script>
</head>
<body style="background-color: white;">
<div id="htmlwidget_container">
<div id="htmlwidget-c1a27c1ebf3ff410447f" class="chromoMap html-widget" style="width:960px;height:500px;">
</div>
</div>
<script type="application/json" data-for="htmlwidget-c1a27c1ebf3ff410447f">{"x":{"chData":[{"name":["putative_transposase_[n=1]_2","putative_Sir2-like_protein_[n=16]_37","DNA_methylase_[n=7]_41","capsid_and_scaffold_protein_[n=1]_44","capsid_and_scaffold_protein_[n=1]_44","integrase_[n=57]_47","putative_DNA_N6-adenine_methyltransferase_[n=6]_49","putative_DNA_N6-adenine_methyltransferase_[n=6]_49","putative_DNA_helicase_[n=124]_51","putative_DNA_helicase_[n=124]_51","glutaredoxin_[n=198]_54","putative_dTDP-4-dehydrorhamnose_3,5-epimerase_[n=2]_56","putative_dTDP-4-dehydrorhamnose_3,5-epimerase_[n=2]_56","putative_phage-related_hydrogenase_[n=3]_58","putative_phage-related_hydrogenase_[n=3]_58","aerobic_NDP_reductase_small_subunit_[n=2]_61","aerobic_NDP_reductase_small_subunit_[n=2]_61","thymidylate_synthase_[n=118]_66","thymidine_kinase_[n=87]_68","No_annotation_provided_[n=3]_73","DNA_ligase_[n=230]_78","terminase_small_subunit_[n=6]_79","RNA_ligase_[n=41]_83","transposase-like_protein_[n=5]_88","nicotinamide_phosphoribosyltransferase_[n=40]_91","nicotinamide_phosphoribosyltransferase_[n=40]_91","DNA_methylase_[n=1]_98","DNA_methylase_[n=1]_98","portal_protein_[n=269]_99","portal_protein_[n=269]_99","major_capsid_protein_[n=27]_103","putative_tape_measure_protein_[n=3]_113","putative_tape_measure_protein_[n=3]_113","160_kDa_protein_[n=3]_121","160_kDa_protein_[n=3]_121","160_kDa_protein_[n=3]_132","160_kDa_protein_[n=3]_132","putative_methyltransferase_[n=6]_133","p53_[n=1]_136","putative_DNA_primase_[n=11]_139","putative_glycosyltransferase_[n=5]_142","peptidase_domain-containing_protein_[n=2]_145","peptidase_domain-containing_protein_[n=2]_145","putative_phosphoribosyltransferase-like_domain_protein_[n=1]_153","putative_phosphoribosyltransferase-like_domain_protein_[n=1]_153","putative_dehalogenase_hydrolase-like_protein_[n=1]_154","AAA_ATPase_[n=5]_155","AAA_ATPase_[n=5]_155","anaerobic_NTP_reductase_small_subunit_[n=31]_156","anaerobic_NTP_reductase_large_subunit_[n=23]_158","internal_virion_protein_C_[n=36]_162","internal_virion_protein_C_[n=36]_162","putative_glucose-1-phosphate_thymidylyltransferase_[n=2]_175","topoisomerase_II_large_subunit_[n=5]_177","terminase_large_subunit_[n=695]_182","putative_ATPase_[n=2]_192","major_capsid_protein_[n=27]_194","major_capsid_protein_[n=27]_194","glycosyl_transferase_group_I_[n=2]_196","gp23_[n=4]_197","tapemeasure_[n=2]_199","tapemeasure_[n=2]_199","tail_protein_[n=5]_200","tail_protein_[n=5]_200","minor_structural_protein_[n=15]_201","No_annotation_provided_[n=3]_203","No_annotation_provided_[n=3]_203","O-methyltransferase_[n=3]_207","HNH_endonuclease_[n=1]_217","scaffolding_protein_[n=11]_231","major_capsid_protein_[n=27]_233","major_capsid_protein_[n=27]_233","glycosyl_transferase_group_I_[n=2]_235","glycosyl_transferase_group_I_[n=2]_235","gp23_[n=4]_236","tapemeasure_[n=2]_237","tapemeasure_[n=2]_237","tail_protein_[n=5]_238","tail_protein_[n=5]_238","minor_structural_protein_[n=15]_239","No_annotation_provided_[n=3]_242","O-methyltransferase_[n=3]_246","BcepNY3gp56_[n=1]_256","gp85_[n=1]_262","peptidase_domain-containing_protein_[n=2]_265","structural_protein_[n=4]_266","PfWMP3_27_[n=1]_268","PfWMP3_27_[n=1]_268","portal_protein_[n=269]_272","portal_protein_[n=269]_272","major_capsid_protein_[n=37]_277","major_capsid_protein_[n=37]_277","gp56_[n=2]_278","cell_adhesion_domain-containing_protein_[n=3]_279","unknown_[n=3]_280","unknown_[n=3]_280","unknown_[n=3]_280","minor_tail_protein_[n=118]_283","minor_tail_protein_[n=118]_283","tail_protein_[n=2]_284","holin_[n=8]_286","holin_[n=8]_286","DNA_helicase_[n=102]_306","DNA_helicase_[n=102]_306","DNA_helicase_[n=102]_306","HNH_endonuclease_domain_protein_[n=1]_315","carboxylesterase_[n=19]_317","carboxylesterase_[n=19]_317","thymidylate_synthase_[n=3]_319","exonuclease_[n=48]_326","terminase_large_subunit_[n=2]_330","head_fiber_protein_[n=4]_335","tail_sheath_protein_[n=101]_341","tail_sheath_protein_[n=101]_341","hinge_connector_of_long_tail_fiber_distal_connector_[n=16]_349","hinge_connector_of_long_tail_fiber_distal_connector_[n=16]_349","gp28_[n=2]_351","major_capsid_&_capsid_maturation_protease_[n=4]_353","baseplate_J_[n=7]_355","baseplate_J_[n=7]_355","head-tail_connector_[n=1]_356","exonuclease_[n=32]_357","exonuclease_[n=32]_357","RecT_[n=14]_358","RNA_polymerase_sigma_factor_[n=33]_360","No_annotation_provided_[n=4]_365","gp139_[n=1]_372","acetyltransferase_[n=4]_375","DNA_polymerase_subunit_III_[n=1]_376","DNA_polymerase_subunit_III_[n=1]_376","terminase_large_subunit_[n=4]_379","No_annotation_provided_[n=1]_382","No_annotation_provided_[n=1]_382","major_tail_protein_[n=29]_391","holin_[n=3]_393","tail_protein_[n=1]_395","tail_protein_[n=1]_395","carboxypeptidase_A_[n=4]_397","carboxypeptidase_A_[n=4]_397","pore-forming_tail_tip_protein_[n=5]_402","pore-forming_tail_tip_protein_[n=5]_402","tail_protein_[n=6]_407","putative_transcriptional_regulator_[n=2]_413","putative_transcriptional_regulator_[n=2]_413","No_annotation_provided_[n=6]_417","No_annotation_provided_[n=7]_418","No_annotation_provided_[n=7]_418","5-phosphoribosylformylglycinamide_amidotransferase_[n=30]_420","deoxyuridine_5-triphosphate_nucleotidohydrolase_[n=40]_437","deoxyuridine_5-triphosphate_nucleotidohydrolase_[n=40]_437","transcriptional_activator_RinB_[n=17]_439","DNA_primase_[n=259]_443","PE/PPE-like_protein_[n=5]_446","putative_tail_fiber_[n=2]_458","tail_tubular_protein_B_[n=69]_462","tail_tubular_protein_B_[n=69]_462","tail_tubular_protein_A_[n=77]_463","major_capsid_protein_[n=107]_464","head-tail_connector_protein_[n=33]_466","DNA_ligase_[n=230]_471","No_annotation_provided_[n=3]_475","No_annotation_provided_[n=3]_475","DNA_polymerase_[n=254]_478","DNA_polymerase_[n=254]_478","DNA_polymerase_[n=254]_478","putative_DNA_helicase_[n=124]_479","putative_tail_fiber_[n=2]_480","tail_tubular_protein_B_[n=69]_484","tail_tubular_protein_B_[n=69]_484","tail_tubular_protein_A_[n=77]_485","major_capsid_protein_[n=107]_487","major_capsid_protein_[n=107]_487","head-tail_connector_protein_[n=33]_489","head-tail_connector_protein_[n=33]_489","DNA_ligase_[n=230]_495","DNA_polymerase_[n=3]_502","DNA_polymerase_[n=3]_502","DNA_primase_[n=259]_505","DNA_primase_[n=259]_505","putative_major_tail_protein_[n=14]_523","Ren_protein_[n=4]_524","Ren_protein_[n=4]_524","metallophosphoesterase_[n=6]_526","DNA_methylase_[n=102]_534","DNA_methylase_[n=102]_534","helicase_[n=252]_537","helicase_[n=252]_537","Ner-like_protein_[n=7]_545","RecA-like_recombinase_[n=1]_546","RecA-like_recombinase_[n=1]_546","terminase_small_subunit_[n=20]_563","terminase_small_subunit_[n=20]_563","gpF-like_protein_[n=2]_566","gpF-like_protein_[n=2]_566","putative_tail_protein_[n=10]_567","scaffolding_protein_[n=107]_569","scaffolding_protein_[n=107]_569","major_capsid_protein_[n=19]_570","head_fiber_protein_[n=4]_571","putative_tail_protein_[n=10]_572","putative_tail_protein_[n=10]_572","serine/threonine_protein_phosphatase_[n=22]_578","No_annotation_provided_[n=2]_582","No_annotation_provided_[n=2]_582","thymidylate_synthase_[n=118]_583","ribonucleoside_triphosphate_reductase,_alpha_chain_[n=7]_591","ribonucleoside_triphosphate_reductase,_alpha_chain_[n=7]_591","putative_terminase_large_subunit_[n=5]_592","putative_terminase_large_subunit_[n=5]_592","portal_vertex_protein_[n=79]_593","ribonucleoside_triphosphate_reductase,_alpha_chain_[n=7]_595","ribonucleoside_triphosphate_reductase,_alpha_chain_[n=7]_595","aerobic_NDP_reductase_small_subunit_[n=2]_596","major_capsid_protein_[n=99]_600","peptidase_[n=55]_601","neck_protein_[n=153]_602","neck_protein_[n=153]_602","gp25_[n=2]_604","tail_sheath_stabilizer_and_completion_protein_[n=74]_606","baseplate_hub_subunit_[n=112]_609","baseplate_hub_subunit_[n=112]_609","baseplate_hub_subunit_and_tail_lysozyme_[n=50]_612","baseplate_hub_subunit_and_tail_lysozyme_[n=50]_612","putative_tail_protein_[n=6]_618","putative_tail_protein_[n=6]_618","No_annotation_provided_[n=2]_623","late_promoter_transcription_accessory_protein_[n=68]_624","late_promoter_transcription_accessory_protein_[n=68]_624","topoisomerase_II_large_subunit_[n=5]_628","ATP-dependent_helicase_[n=9]_631","ATP-dependent_helicase_[n=9]_631","putative_DNA_helicase_[n=124]_632","DNA_primase_[n=259]_634","recombinase_[n=3]_636","bacterial_surface_protein_[n=2]_637","putative_DNA_polymerase_I_[n=6]_639","putative_tail_sheath_protein_[n=7]_640","DNA_polymerase_[n=254]_646","gp65_[n=3]_654","gp65_[n=3]_654","recombination_endonuclease_subunit_[n=63]_660","recombination_endonuclease_subunit_[n=63]_660","recombination_endonuclease_subunit_[n=74]_661","NAD-dependent_DNA_ligase_subunit_B_[n=7]_664","putative_UDP-glucose_dehydrogenase_[n=1]_666","alpha-glucosyl-transferase_[n=16]_670","glutaredoxin_[n=198]_672","helicase_[n=252]_674","helicase_[n=252]_674","internal_virion_protein_[n=2]_676","internal_virion_protein_[n=2]_676","putative_DNA_helicase_[n=7]_693","ORF031_[n=2]_702","ORF031_[n=2]_702","deaminase_[n=1]_706","DNA_methylase_[n=2]_717","DNA_methylase_[n=2]_717","tail_protein_[n=1]_719","No_annotation_provided_[n=2]_723","No_annotation_provided_[n=2]_723","structural_protein_[n=1]_735","DNA_primase_[n=259]_739","DNA_primase_[n=259]_739","excisionase_[n=4]_742","tail_completion_and_sheath_stabilizer_protein_[n=67]_744"],"data":["Other","Other","Other","Capsid","Capsid","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Capsid","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Capsid","Capsid","Other","Other","Other","Other","Tail","Tail","Other","Other","Other","Other","Other","Other","Capsid","Capsid","Other","Other","Other","Other","Other","Tail","Tail","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Capsid","Capsid","Other","Other","Other","Other","Other","Tail","Tail","Tail","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Tail","Tail","Tail","Tail","Other","Capsid","Baseplate","Baseplate","Tail","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Tail","Other","Tail","Tail","Other","Other","Tail","Tail","Tail","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Tail","Tail","Tail","Tail","Capsid","Tail","Other","Other","Other","Other","Other","Other","Other","Tail","Tail","Tail","Tail","Capsid","Capsid","Tail","Tail","Other","Other","Other","Other","Other","Tail","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Tail","Other","Other","Capsid","Other","Tail","Tail","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Capsid","Other","Other","Other","Other","Tail","Baseplate","Baseplate","Baseplate","Baseplate","Tail","Tail","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Tail","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Other","Tail","Other","Other","Other","Other","Other","Other","Tail"],"loci":["pos_phage_0-1-1","pos_phage_0-11-1","pos_phage_0-12-1","pos_phage_0-12-1","pos_phage_0-13-1","pos_phage_0-14-1","pos_phage_0-14-1","pos_phage_0-15-1","pos_phage_0-15-1","pos_phage_0-16-1","pos_phage_0-16-1","pos_phage_0-16-1","pos_phage_0-17-1","pos_phage_0-17-1","pos_phage_0-18-1","pos_phage_0-18-1","pos_phage_0-19-1","pos_phage_0-20-1","pos_phage_0-21-1","pos_phage_0-22-1","pos_phage_0-24-1","pos_phage_0-24-1","pos_phage_0-25-1","pos_phage_0-26-1","pos_phage_0-27-1","pos_phage_0-28-1","pos_phage_0-30-1","pos_phage_0-31-1","pos_phage_0-31-1","pos_phage_0-32-1","pos_phage_0-33-1","pos_phage_0-36-1","pos_phage_0-37-1","pos_phage_0-40-1","pos_phage_0-41-1","pos_phage_0-46-1","pos_phage_0-47-1","pos_phage_0-47-1","pos_phage_0-48-1","pos_phage_0-50-1","pos_phage_0-52-1","pos_phage_0-52-1","pos_phage_0-53-1","pos_phage_0-56-1","pos_phage_0-57-1","pos_phage_0-57-1","pos_phage_0-57-1","pos_phage_0-58-1","pos_phage_0-58-1","pos_phage_0-59-1","pos_phage_0-60-1","pos_phage_0-61-1","pos_phage_0-64-1","pos_phage_0-64-1","pos_phage_0-65-1","pos_phage_1-6-1","pos_phage_1-6-1","pos_phage_1-7-1","pos_phage_1-8-1","pos_phage_1-8-1","pos_phage_1-9-1","pos_phage_1-10-1","pos_phage_1-10-1","pos_phage_1-11-1","pos_phage_1-14-1","pos_phage_1-15-1","pos_phage_1-16-1","pos_phage_1-17-1","pos_phage_1-22-1","pos_phage_2-6-1","pos_phage_2-6-1","pos_phage_2-7-1","pos_phage_2-7-1","pos_phage_2-8-1","pos_phage_2-8-1","pos_phage_2-9-1","pos_phage_2-10-1","pos_phage_2-10-1","pos_phage_2-11-1","pos_phage_2-14-1","pos_phage_2-15-1","pos_phage_2-16-1","pos_phage_2-22-1","pos_phage_2-24-1","pos_phage_2-26-1","pos_phage_3-1-1","pos_phage_3-1-1","pos_phage_3-2-1","pos_phage_3-3-1","pos_phage_3-4-1","pos_phage_3-5-1","pos_phage_3-6-1","pos_phage_3-6-1","pos_phage_3-6-1","pos_phage_3-7-1","pos_phage_3-8-1","pos_phage_3-9-1","pos_phage_3-11-1","pos_phage_3-12-1","pos_phage_3-12-1","pos_phage_3-12-1","pos_phage_3-13-1","pos_phage_3-18-1","pos_phage_3-19-1","pos_phage_3-20-1","pos_phage_3-23-1","pos_phage_3-23-1","pos_phage_3-24-1","pos_phage_3-24-1","pos_phage_3-26-1","pos_phage_4-1-1","pos_phage_4-4-1","pos_phage_4-5-1","pos_phage_4-6-1","pos_phage_4-10-1","pos_phage_4-11-1","pos_phage_4-11-1","pos_phage_4-12-1","pos_phage_4-12-1","pos_phage_4-13-1","pos_phage_4-13-1","pos_phage_4-13-1","pos_phage_4-14-1","pos_phage_4-14-1","pos_phage_4-15-1","pos_phage_4-17-1","pos_phage_4-20-1","pos_phage_4-21-1","pos_phage_4-21-1","pos_phage_4-22-1","pos_phage_5-1-1","pos_phage_5-2-1","pos_phage_5-3-1","pos_phage_5-4-1","pos_phage_5-5-1","pos_phage_5-6-1","pos_phage_5-7-1","pos_phage_5-8-1","pos_phage_5-9-1","pos_phage_5-10-1","pos_phage_5-11-1","pos_phage_5-12-1","pos_phage_5-14-1","pos_phage_5-15-1","pos_phage_5-15-1","pos_phage_5-15-1","pos_phage_5-16-1","pos_phage_5-16-1","pos_phage_5-19-1","pos_phage_5-20-1","pos_phage_5-20-1","pos_phage_6-1-1","pos_phage_6-2-1","pos_phage_6-7-1","pos_phage_6-11-1","pos_phage_6-12-1","pos_phage_6-12-1","pos_phage_6-13-1","pos_phage_6-14-1","pos_phage_6-16-1","pos_phage_6-17-1","pos_phage_6-18-1","pos_phage_6-18-1","pos_phage_6-19-1","pos_phage_6-20-1","pos_phage_6-20-1","pos_phage_7-1-1","pos_phage_7-5-1","pos_phage_7-6-1","pos_phage_7-6-1","pos_phage_7-6-1","pos_phage_7-7-1","pos_phage_7-7-1","pos_phage_7-8-1","pos_phage_7-10-1","pos_phage_7-12-1","pos_phage_7-13-1","pos_phage_7-14-1","pos_phage_7-15-1","pos_phage_8-1-1","pos_phage_8-1-1","pos_phage_8-2-1","pos_phage_8-2-1","pos_phage_8-6-1","pos_phage_8-7-1","pos_phage_8-7-1","pos_phage_8-8-1","pos_phage_8-11-1","pos_phage_8-11-1","pos_phage_8-12-1","pos_phage_8-14-1","pos_phage_8-15-1","pos_phage_8-16-1","pos_phage_8-17-1","pos_phage_8-17-1","pos_phage_8-17-1","pos_phage_8-18-1","pos_phage_8-18-1","pos_phage_8-18-1","pos_phage_8-18-1","pos_phage_8-19-1","pos_phage_9-1-1","pos_phage_9-2-1","pos_phage_9-3-1","pos_phage_9-3-1","pos_phage_9-7-1","pos_phage_9-8-1","pos_phage_9-8-1","pos_phage_9-9-1","pos_phage_9-9-1","pos_phage_9-10-1","pos_phage_9-11-1","pos_phage_9-11-1","pos_phage_9-13-1","pos_phage_9-13-1","pos_phage_9-13-1","pos_phage_9-14-1","pos_phage_9-14-1","pos_phage_9-15-1","pos_phage_9-16-1","pos_phage_9-17-1","pos_phage_9-19-1","pos_phage_9-20-1","pos_phage_9-24-1","pos_phage_9-25-1","pos_phage_9-33-1","pos_phage_9-33-1","pos_phage_9-34-1","pos_phage_9-36-1","pos_phage_9-39-1","pos_phage_9-40-1","pos_phage_9-40-1","pos_phage_9-41-1","pos_phage_9-42-1","pos_phage_9-43-1","pos_phage_9-44-1","pos_phage_9-44-1","pos_phage_9-49-1","pos_phage_9-52-1","pos_phage_9-53-1","pos_phage_9-55-1","pos_phage_9-56-1","pos_phage_9-56-1","pos_phage_9-58-1","pos_phage_9-59-1","pos_phage_9-62-1","pos_phage_9-63-1","pos_phage_9-64-1","pos_phage_9-65-1","pos_phage_9-65-1","pos_phage_9-66-1","pos_phage_9-72-1","pos_phage_9-75-1","pos_phage_9-76-1","pos_phage_9-78-1","pos_phage_9-84-1","pos_phage_9-85-1","pos_phage_9-85-1","pos_phage_9-85-1","pos_phage_9-86-1","pos_phage_9-93-1","pos_phage_9-94-1","pos_phage_9-95-1","pos_phage_9-97-1","pos_phage_9-98-1"],"loci_start":[1,22221,24443,24443,26665,28887,28887,31109,31109,33331,33331,33331,35553,35553,37775,37775,39997,42219,44441,46663,51107,51107,53329,55551,57773,59995,64439,66661,66661,68883,71105,77771,79993,86659,88881,99991,102213,102213,104435,108879,113323,113323,115545,122211,124433,124433,124433,126655,126655,128877,131099,133321,139987,139987,142209,10901,10901,13081,15261,15261,17441,19621,19621,21801,28341,30521,32701,34881,45781,11261,11261,13513,13513,15765,15765,18017,20269,20269,22521,29277,31529,33781,47293,51797,56301,1,1,2203,4405,6607,8809,11011,11011,11011,13213,15415,17617,22021,24223,24223,24223,26425,37435,39637,41839,48445,48445,50647,50647,55051,1,6691,8921,11151,20071,22301,22301,24531,24531,26761,26761,26761,28991,28991,31221,35681,42371,44601,44601,46831,1,2166,4331,6496,8661,10826,12991,15156,17321,19486,21651,23816,28146,30311,30311,30311,32476,32476,38971,41136,41136,1,2194,13159,21931,24124,24124,26317,28510,32896,35089,37282,37282,39475,41668,41668,1,8853,11066,11066,11066,13279,13279,15492,19918,24344,26557,28770,30983,1,1,2204,2204,11016,13219,13219,15422,22031,22031,24234,28640,30843,33046,35249,35249,35249,37452,37452,37452,37452,39655,1,2220,4439,4439,13315,15534,15534,17753,17753,19972,22191,22191,26629,26629,26629,28848,28848,31067,33286,35505,39943,42162,51038,53257,71009,71009,73228,77666,84323,86542,86542,88761,90980,93199,95418,95418,106513,113170,115389,119827,122046,122046,126484,128703,135360,137579,139798,142017,142017,144236,157550,164207,166426,170864,184178,186397,186397,186397,188616,204149,206368,208587,213025,215244],"loci_end":[2222,24442,26664,26664,28886,31108,31108,33330,33330,35552,35552,35552,37774,37774,39996,39996,42218,44440,46662,48884,53328,53328,55550,57772,59994,62216,66660,68882,68882,71104,73326,79992,82214,88880,91102,102212,104434,104434,106656,111100,115544,115544,117766,124432,126654,126654,126654,128876,128876,131098,133320,135542,142208,142208,144430,13080,13080,15260,17440,17440,19620,21800,21800,23980,30520,32700,34880,37060,47960,13512,13512,15764,15764,18016,18016,20268,22520,22520,24772,31528,33780,36032,49544,54048,58560,2202,2202,4404,6606,8808,11010,13212,13212,13212,15414,17616,19818,24222,26424,26424,26424,28626,39636,41838,44040,50646,50646,52848,52848,57252,2230,8920,11150,13380,22300,24530,24530,26760,26760,28990,28990,28990,31220,31220,33450,37910,44600,46830,46830,49060,2165,4330,6495,8660,10825,12990,15155,17320,19485,21650,23815,25980,30310,32475,32475,32475,34640,34640,41135,43293,43293,2193,4386,15351,24123,26316,26316,28509,30702,35088,37281,39474,39474,41667,43851,43851,2213,11065,13278,13278,13278,15491,15491,17704,22130,26556,28769,30982,33195,2203,2203,4406,4406,13218,15421,15421,17624,24233,24233,26436,30842,33045,35248,37451,37451,37451,39654,39654,39654,39654,41865,2219,4438,6657,6657,15533,17752,17752,19971,19971,22190,24409,24409,28847,28847,28847,31066,31066,33285,35504,37723,42161,44380,53256,55475,73227,73227,75446,79884,86541,88760,88760,90979,93198,95417,97636,97636,108731,115388,117607,122045,124264,124264,128702,130921,137578,139797,142016,144235,144235,146454,159768,166425,168644,173082,186396,188615,188615,188615,190834,206367,208586,210805,215243,217462],"hlink":["1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1"],"label":["Lpos_phage_0-1-1","Lpos_phage_0-11-1","Lpos_phage_0-12-1","Lpos_phage_0-12-1","Lpos_phage_0-12-1","Lpos_phage_0-14-1","Lpos_phage_0-14-1","Lpos_phage_0-14-1","Lpos_phage_0-15-1","Lpos_phage_0-15-1","Lpos_phage_0-16-1","Lpos_phage_0-16-1","Lpos_phage_0-16-1","Lpos_phage_0-17-1","Lpos_phage_0-17-1","Lpos_phage_0-18-1","Lpos_phage_0-18-1","Lpos_phage_0-20-1","Lpos_phage_0-21-1","Lpos_phage_0-22-1","Lpos_phage_0-24-1","Lpos_phage_0-24-1","Lpos_phage_0-25-1","Lpos_phage_0-26-1","Lpos_phage_0-27-1","Lpos_phage_0-27-1","Lpos_phage_0-30-1","Lpos_phage_0-30-1","Lpos_phage_0-31-1","Lpos_phage_0-31-1","Lpos_phage_0-33-1","Lpos_phage_0-36-1","Lpos_phage_0-36-1","Lpos_phage_0-40-1","Lpos_phage_0-40-1","Lpos_phage_0-46-1","Lpos_phage_0-46-1","Lpos_phage_0-47-1","Lpos_phage_0-48-1","Lpos_phage_0-50-1","Lpos_phage_0-52-1","Lpos_phage_0-52-1","Lpos_phage_0-52-1","Lpos_phage_0-56-1","Lpos_phage_0-56-1","Lpos_phage_0-57-1","Lpos_phage_0-57-1","Lpos_phage_0-57-1","Lpos_phage_0-58-1","Lpos_phage_0-59-1","Lpos_phage_0-60-1","Lpos_phage_0-60-1","Lpos_phage_0-64-1","Lpos_phage_0-64-1","Lpos_phage_0-65-1","Lpos_phage_1-6-1","Lpos_phage_1-6-1","Lpos_phage_1-6-1","Lpos_phage_1-8-1","Lpos_phage_1-8-1","Lpos_phage_1-9-1","Lpos_phage_1-9-1","Lpos_phage_1-10-1","Lpos_phage_1-10-1","Lpos_phage_1-14-1","Lpos_phage_1-15-1","Lpos_phage_1-15-1","Lpos_phage_1-17-1","Lpos_phage_1-22-1","Lpos_phage_2-6-1","Lpos_phage_2-6-1","Lpos_phage_2-6-1","Lpos_phage_2-7-1","Lpos_phage_2-7-1","Lpos_phage_2-8-1","Lpos_phage_2-9-1","Lpos_phage_2-9-1","Lpos_phage_2-10-1","Lpos_phage_2-10-1","Lpos_phage_2-14-1","Lpos_phage_2-15-1","Lpos_phage_2-16-1","Lpos_phage_2-22-1","Lpos_phage_2-24-1","Lpos_phage_2-26-1","Lpos_phage_3-1-1","Lpos_phage_3-1-1","Lpos_phage_3-1-1","Lpos_phage_3-3-1","Lpos_phage_3-3-1","Lpos_phage_3-5-1","Lpos_phage_3-5-1","Lpos_phage_3-6-1","Lpos_phage_3-6-1","Lpos_phage_3-8-1","Lpos_phage_3-8-1","Lpos_phage_3-8-1","Lpos_phage_3-11-1","Lpos_phage_3-11-1","Lpos_phage_3-12-1","Lpos_phage_3-12-1","Lpos_phage_3-12-1","Lpos_phage_3-19-1","Lpos_phage_3-19-1","Lpos_phage_3-19-1","Lpos_phage_3-23-1","Lpos_phage_3-23-1","Lpos_phage_3-23-1","Lpos_phage_3-24-1","Lpos_phage_3-26-1","Lpos_phage_4-1-1","Lpos_phage_4-4-1","Lpos_phage_4-5-1","Lpos_phage_4-5-1","Lpos_phage_4-10-1","Lpos_phage_4-10-1","Lpos_phage_4-11-1","Lpos_phage_4-12-1","Lpos_phage_4-12-1","Lpos_phage_4-12-1","Lpos_phage_4-13-1","Lpos_phage_4-13-1","Lpos_phage_4-13-1","Lpos_phage_4-14-1","Lpos_phage_4-15-1","Lpos_phage_4-17-1","Lpos_phage_4-20-1","Lpos_phage_4-21-1","Lpos_phage_4-21-1","Lpos_phage_4-21-1","Lpos_phage_5-1-1","Lpos_phage_5-2-1","Lpos_phage_5-2-1","Lpos_phage_5-4-1","Lpos_phage_5-5-1","Lpos_phage_5-6-1","Lpos_phage_5-6-1","Lpos_phage_5-8-1","Lpos_phage_5-8-1","Lpos_phage_5-10-1","Lpos_phage_5-10-1","Lpos_phage_5-12-1","Lpos_phage_5-14-1","Lpos_phage_5-14-1","Lpos_phage_5-15-1","Lpos_phage_5-15-1","Lpos_phage_5-15-1","Lpos_phage_5-16-1","Lpos_phage_5-19-1","Lpos_phage_5-19-1","Lpos_phage_5-20-1","Lpos_phage_6-1-1","Lpos_phage_6-2-1","Lpos_phage_6-7-1","Lpos_phage_6-11-1","Lpos_phage_6-11-1","Lpos_phage_6-12-1","Lpos_phage_6-13-1","Lpos_phage_6-14-1","Lpos_phage_6-16-1","Lpos_phage_6-17-1","Lpos_phage_6-17-1","Lpos_phage_6-19-1","Lpos_phage_6-19-1","Lpos_phage_6-19-1","Lpos_phage_6-20-1","Lpos_phage_7-1-1","Lpos_phage_7-5-1","Lpos_phage_7-5-1","Lpos_phage_7-6-1","Lpos_phage_7-6-1","Lpos_phage_7-6-1","Lpos_phage_7-7-1","Lpos_phage_7-7-1","Lpos_phage_7-10-1","Lpos_phage_7-12-1","Lpos_phage_7-12-1","Lpos_phage_7-14-1","Lpos_phage_7-14-1","Lpos_phage_8-1-1","Lpos_phage_8-1-1","Lpos_phage_8-1-1","Lpos_phage_8-2-1","Lpos_phage_8-6-1","Lpos_phage_8-6-1","Lpos_phage_8-7-1","Lpos_phage_8-7-1","Lpos_phage_8-11-1","Lpos_phage_8-11-1","Lpos_phage_8-11-1","Lpos_phage_8-14-1","Lpos_phage_8-14-1","Lpos_phage_8-16-1","Lpos_phage_8-16-1","Lpos_phage_8-17-1","Lpos_phage_8-17-1","Lpos_phage_8-17-1","Lpos_phage_8-18-1","Lpos_phage_8-18-1","Lpos_phage_8-18-1","Lpos_phage_8-18-1","Lpos_phage_9-1-1","Lpos_phage_9-2-1","Lpos_phage_9-2-1","Lpos_phage_9-3-1","Lpos_phage_9-7-1","Lpos_phage_9-7-1","Lpos_phage_9-8-1","Lpos_phage_9-8-1","Lpos_phage_9-9-1","Lpos_phage_9-10-1","Lpos_phage_9-10-1","Lpos_phage_9-11-1","Lpos_phage_9-13-1","Lpos_phage_9-13-1","Lpos_phage_9-13-1","Lpos_phage_9-13-1","Lpos_phage_9-14-1","Lpos_phage_9-15-1","Lpos_phage_9-16-1","Lpos_phage_9-16-1","Lpos_phage_9-19-1","Lpos_phage_9-19-1","Lpos_phage_9-24-1","Lpos_phage_9-24-1","Lpos_phage_9-33-1","Lpos_phage_9-33-1","Lpos_phage_9-33-1","Lpos_phage_9-36-1","Lpos_phage_9-39-1","Lpos_phage_9-39-1","Lpos_phage_9-40-1","Lpos_phage_9-41-1","Lpos_phage_9-42-1","Lpos_phage_9-43-1","Lpos_phage_9-44-1","Lpos_phage_9-44-1","Lpos_phage_9-49-1","Lpos_phage_9-52-1","Lpos_phage_9-52-1","Lpos_phage_9-55-1","Lpos_phage_9-55-1","Lpos_phage_9-56-1","Lpos_phage_9-58-1","Lpos_phage_9-59-1","Lpos_phage_9-62-1","Lpos_phage_9-63-1","Lpos_phage_9-64-1","Lpos_phage_9-64-1","Lpos_phage_9-65-1","Lpos_phage_9-65-1","Lpos_phage_9-72-1","Lpos_phage_9-75-1","Lpos_phage_9-75-1","Lpos_phage_9-78-1","Lpos_phage_9-84-1","Lpos_phage_9-84-1","Lpos_phage_9-85-1","Lpos_phage_9-85-1","Lpos_phage_9-85-1","Lpos_phage_9-93-1","Lpos_phage_9-94-1","Lpos_phage_9-94-1","Lpos_phage_9-97-1","Lpos_phage_9-98-1"]}],"nLoci":[{"name":["pos_phage_0","pos_phage_1","pos_phage_2","pos_phage_3","pos_phage_4","pos_phage_5","pos_phage_6","pos_phage_7","pos_phage_8","pos_phage_9"],"start":[1,1,1,1,1,1,1,1,1,1],"end":[146647,58871,58560,59443,51290,43293,43851,44262,41865,221908],"ch_average":[0.660848914184771,0.265295822123682,0.263894334112939,0.267873478529294,0.231132861964697,0.19509524260163,0.197609809514797,0.19946193675729,0.188660114372237,1.00000450639232],"n":[66,27,26,27,23,20,20,20,19,100],"seq_len":[146647,58871,58560,59443,51290,43293,43851,44262,41865,221908]}],"ploidy_n":1,"title":null,"cnt":false,"ch_gap":6,"top_margin":25,"left_margin":340,"chr_width":6,"chr_length":12,"chr_col":["black",""],"heatmap":true,"v_align":false,"ch_domain":["1","221908"],"lg_x":300,"lg_y":0,"heat_scale":"ordinal","labels":false,"div_id":"chromap","w":1500,"h":800,"rng":[["Other","Capsid","Tail","Baseplate"]],"heat_col":[["red","lightblue","orange","green"]],"an_col":["yellow",""],"ch_text":[true,true],"legend":[true,true],"aggregate_func":["avg",""]},"evals":[],"jsHooks":[]}</script>
<script type="application/htmlwidget-sizing" data-for="htmlwidget-c1a27c1ebf3ff410447f">{"viewer":{"width":450,"height":350,"padding":10,"fill":true},"browser":{"width":960,"height":500,"padding":10,"fill":true}}</script>
</body>
</html>