Skip to content

Instantly share code, notes, and snippets.

@justlebeau
Last active Apr 4, 2016
Embed
What would you like to do?
Language Bubbles
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="data:application/x-javascript;base64,KGZ1bmN0aW9uKCkgewogIC8vIElmIHdpbmRvdy5IVE1MV2lkZ2V0cyBpcyBhbHJlYWR5IGRlZmluZWQsIHRoZW4gdXNlIGl0OyBvdGhlcndpc2UgY3JlYXRlIGEKICAvLyBuZXcgb2JqZWN0LiBUaGlzIGFsbG93cyBwcmVjZWRpbmcgY29kZSB0byBzZXQgb3B0aW9ucyB0aGF0IGFmZmVjdCB0aGUKICAvLyBpbml0aWFsaXphdGlvbiBwcm9jZXNzICh0aG91Z2ggbm9uZSBjdXJyZW50bHkgZXhpc3QpLgogIHdpbmRvdy5IVE1MV2lkZ2V0cyA9IHdpbmRvdy5IVE1MV2lkZ2V0cyB8fCB7fTsKCiAgLy8gU2VlIGlmIHdlJ3JlIHJ1bm5pbmcgaW4gYSB2aWV3ZXIgcGFuZS4gSWYgbm90LCB3ZSdyZSBpbiBhIHdlYiBicm93c2VyLgogIHZhciB2aWV3ZXJNb2RlID0gd2luZG93LkhUTUxXaWRnZXRzLnZpZXdlck1vZGUgPQogICAgICAvXGJ2aWV3ZXJfcGFuZT0xXGIvLnRlc3Qod2luZG93LmxvY2F0aW9uKTsKCiAgLy8gU2VlIGlmIHdlJ3JlIHJ1bm5pbmcgaW4gU2hpbnkgbW9kZS4gSWYgbm90LCBpdCdzIGEgc3RhdGljIGRvY3VtZW50LgogIC8vIE5vdGUgdGhhdCBzdGF0aWMgd2lkZ2V0cyBjYW4gYXBwZWFyIGluIGJvdGggU2hpbnkgYW5kIHN0YXRpYyBtb2RlcywgYnV0CiAgLy8gb2J2aW91c2x5LCBTaGlueSB3aWRnZXRzIGNhbiBvbmx5IGFwcGVhciBpbiBTaGlueSBhcHBzL2RvY3VtZW50cy4KICB2YXIgc2hpbnlNb2RlID0gd2luZG93LkhUTUxXaWR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R1bmF0ZWx5IGlzbid0CiAgICAgIC8vIHN1cHBvcnRlZCBuYXRpdmVseSBieSBTaGlueSBhdCB0aGUgdGltZSBvZiB0aGlzIHdyaXRpbmcuCgogICAgICBzaGlueUJpbmRpbmcucmVuZGVyVmFsdWUgPSBmdW5jdGlvbihlbCwgZGF0YSkgewogICAgICAgIC8vIFJlc29sdmUgc3RyaW5ncyBtYXJrZWQgYXMgamF2YXNjcmlwdCBsaXRlcmFscyB0byBvYmplY3RzCiAgICAgICAgaWYgKCEoZGF0YS5ldmFscyBpbnN0YW5jZW9mIEFycmF5KSkgZGF0YS5ldmFscyA9IFtkYXRhLmV2YWxzXTsKICAgICAgICBmb3IgKHZhciBpID0gMDsgZGF0YS5ldmFscyAmJiBpIDwgZGF0YS5ldmFscy5sZW5ndGg7IGkrKykgewogICAgICAgICAgd2luZG93LkhUTUxXaWRnZXRzLmV2YWx1YXRlU3RyaW5nTWVtYmVyKGRhdGEueCwgZGF0YS5ldmFsc1tpXSk7CiAgICAgICAgfQogICAgICAgIGlmICghYmluZGluZ0RlZi5yZW5kZXJPbk51bGxWYWx1ZSkgewogICAgICAgICAgaWYgKGRhdGEueCA9PT0gbnVsbCkgewogICAgICAgICAgICBlbC5zdHlsZS52aXNpYmlsaXR5ID0gImhpZGRlbiI7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGVsLnN0eWxlLnZpc2liaWxpdHkgPSAiaW5oZXJpdCI7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICghZWxlbWVudERhdGEoZWwsICJpbml0aWFsaXplZCIpKSB7CiAgICAgICAgICBpbml0U2l6aW5nKGVsKTsKCiAgICAgICAgICBlbGVtZW50RGF0YShlbCwgImluaXRpYWxpemVkIiwgdHJ1ZSk7CiAgICAgICAgICBpZiAoYmluZGluZ0RlZi5pbml0aWFsaXplKSB7CiAgICAgICAgICAgIHZhciByZXN1bHQgPSBiaW5kaW5nRGVmL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gICBlbC5jbGFzc05hbWUgPSBlbC5jbGFzc05hbWUgKyAiIGh0bWwtd2lkZ2V0LXN0YXRpYy1ib3VuZCI7CgogICAgICAgIHZhciBpbml0UmVzdWx0OwogICAgICAgIGlmIChiaW5kaW5nLmluaXRpYWxpemUpIHsKICAgICAgICAgIGluaXRSZXN1bHQgPSBiaW5kaW5nLmluaXRpYWxpemUoZWwsCiAgICAgICAgICAgIHNpemVPYmogPyBzaXplT2JqLmdldFdpZHRoKCkgOiBlbC5vZmZzZXRXaWR0aCwKICAgICAgICAgICAgc2l6ZU9iaiA/IHNpemVPYmouZ2V0SGVpZ2h0KCkgOiBlbC5vZmZzZXRIZWlnaHQKICAgICAgICAgICk7CiAgICAgICAgICBlbGVtZW50RGF0YShlbCwgImluaXRfcmVzdWx0IiwgaW5pdFJlc3VsdCk7CiAgICAgICAgfQoKICAgICAgICBpZiAoYmluZGluZy5yZXNpemUpIHsKICAgICAgICAgIHZhciBsYXN0U2l6ZSA9IHt9OwogICAgICAgICAgdmFyIHJlc2l6ZUhhbmRsZXIgPSBmdW5jdGlvbihlKSB7CiAgICAgICAgICAgIHZhciBzaXplID0gewogICAgICAgICAgICAgIHc6IHNpemVPYmogPyBzaXplT2JqLmdldFdpZHRoKCkgOiBlbC5vZmZzZXRXaWR0aCwKICAgICAgICAgICAgICBoOiBzaXplT2JqID8gc2l6ZU9iai5nZXRIZWlnaHQoKSA6IGVsLm9mZnNldEhlaWdodAogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc2l6ZS53ID09PSAwICYmIHNpemUuaCA9PT0gMCkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIGlmIChzaXplLncgPT09IGxhc3RTaXplLncgJiYgc2l6ZS5oID09PSBsYXN0U2l6ZS5oKQogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgbGFzdFNpemUgPSBzaXplOwogICAgICAgICAgICBiaW5kaW5nLnJlc2l6ZShlbCwgc2l6ZS53LCBzaXplLmg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21vZGF0ZSBib3RoCiAgLy8gdHlwZXMgb2YgZGVmaW5pdGlvbnMuCiAgZnVuY3Rpb24gY3JlYXRlTGVnYWN5RGVmaW5pdGlvbkFkYXB0ZXIoZGVmbikgewogICAgdmFyIHJlc3VsdCA9IHsKICAgICAgbmFtZTogZGVmbi5uYW1lLAogICAgICB0eXBlOiBkZWZuLnR5cGUsCiAgICAgIGluaXRpYWxpemU6IGZ1bmN0aW9uKGVsLCB3aWR0aCwgaGVpZ2h0KSB7CiAgICAgICAgcmV0dXJuIGRlZm4uZmFjdG9yeShlbCwgd2lkdGgsIGhlaWdodCk7CiAgICAgIH0sCiAgICAgIHJlbmRlclZhbHVlOiBmdW5jdGlvbihlbCwgeCwgaW5zdGFuY2UpIHsKICAgICAgICByZXR1cm4gaW5zdGFuY2UucmVuZGVyVmFsdWUoeCk7CiAgICAgIH0sCiAgICAgIHJlc2l6ZTogZnVuY3Rpb24oZWwsIHdpZHRoLCBoZWlnaHQsIGluc3RhbmNlKSB7CiAgICAgICAgcmV0dXJuIGluc3RhbmNlLnJlc2l6ZSh3aWR0aCwgaGVpZ2h0KTsKICAgICAgfQogICAgfTsKCiAgICBpZiAoZGVmbi5maW5kKQogICAgICByZXN1bHQuZmluZCA9IGRlZm4uZmluZDsKICAgIGlmIChkZWZuLnJlbmRlckVycm9yKQogICAgICByZXN1bHQucmVuZGVyRXJyb3IgPSBkZWZuLnJlbmRlckVycm9yOwogICAgaWYgKGRlZm4uY2xlYXJFcnJvcikKICAgICAgcmVzdWx0LmNsZWFyRXJyb3IgPSBkZWZuLmNsZWFyRXJyb3I7CgogICAgcmV0dXJuIHJlc3VsdDsKICB9Cn0pKCk7Cgo="></script>
<script src="data:application/x-javascript;base64,IWZ1bmN0aW9uKCkgewogIHZhciBkMyA9IHsKICAgIHZlcnNpb246ICIzLjUuMyIKICB9OwogIGlmICghRGF0ZS5ub3cpIERhdGUubm93ID0gZnVuY3Rpb24oKSB7CiAgICByZXR1cm4gK25ldyBEYXR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9IGFycmF5W2ldKSAhPSBudWxsICYmIGIgPj0gYikgewogICAgICAgIGEgPSBiOwogICAgICAgIGJyZWFrOwogICAgICB9CiAgICAgIHdoaWxlICgrK2kgPCBuKSBpZiAoKGIgPSBhcnJheVtpXSkgIT0gbnVsbCAmJiBhID4gYikgYSA9IGI7CiAgICB9IGVsc2UgewogICAgICB3aGlsZSAoKytpIDwgbikgaWYgKChiID0gZi5jYWxsKGFycmF5LCBhcnJheVtpXSwgaSkpICE9IG51bGwgJiYgYiA+PSBiKSB7CiAgICAgICAgYSA9IGI7CiAgICAgICAgYnJlYWs7CiAgICAgIH0KICAgICAgd2hpbGUgKCsraSA8IG4pIGlmICgoYiA9IGYuY2FsbChhcnJheSwgYXJyYXlbaV0sIGkpKSAhPSBudWxsICYmIGEgPiBiKSBhID0gYjsKICAgIH0KICAgIHJldHVybiBhOwogIH07CiAgZDMubWF4ID0gZnVuY3Rpb24oYXJyYXksIGYpIHsKICAgIHZhciBpID0gLTEsIG4gPSBhcnJheS5sZW5ndGgsIGEsIGI7CiAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA9PT0gMSkgewogICAgICB3aGlsZSAoKytpIDwgbikgaWYgKChiID0gYXJyYXlbaV0pICE9IG51bGwgJiYgYiA+PSBiKSB7CiAgICAgICAgYSA9IGI7CiAgICAgICAgYnJlYWs7CiAgICAgIH0KICAgICAgd2hpbGUgKCsraSA8IG4pIGlmICgoYiA9IGFycmF5W2ldKSAhPSBudWxsICYmIGIgPiBhKSBhID0gYjsKICAgIH0gZWxzZSB7CiAgICAgIHdoaWxlICgrK2kgPCBuKSBpZiAoKGIgPSBmLmNhbGwoYXJyYXksIGFycmF5W2ldLCBpKSkgIT0gbnVsbCAmJiBiID49IGIpIHsKICAgICAgICBhID0gYjsKICAgICAgICBicmVhazsKICAgICAgfQogICAgICB3aGlsZSAoKytpIDwgbikgaWYgKChiID0gZi5jYWxsKGFycmF5LCBhcnJheVtpXSwgaSkpICE9IG51bGwgJiYgYiA+IGEpIGEgPSBiOwogICAgfQogICAgcmV0dXJuIGE7CiAgfTsKICBkMy5leHRlbnQgPSBmdW5jdGlvbihhcnJheSwgZikgewogICAgdmFyIGkgPSAtMSwgbiA9IGFycmF5Lmxlbmd0aCwgYSwgYiwgYzsKICAgIGlmIChhcmd1bWVudHMubGVuZ3RoID09PSAxKSB7CiAgICAgIHdoaWxlICgrK2kgPCBuKSBpZiAoKGIgPSBhcnJheVtpXSkgIT0gbnVsbCAmJiBiID49IGIpIHsKICAgICAgICBhID0gYyA9IGI7CiAgICAgICAgYnJlYWs7CiAgICAgIH0KICAgICAgd2hpbGUgKCsraSA8IG4pIGlmICgoYiA9IGFycmF5W2ldKSAhPSBudWxsKSB7CiAgICAgICAgaWYgKGEgPiBiKSBhID0gYjsKICAgICAgICBpZiAoYyA8IGIpIGMgPSBiOwogICAgICB9CiAgICB9IGVsc2UgewogICAgICB3aGlsZSAoKytpIDwgbikgaWYgKChiID0gZi5jYWxsKGFycmF5LCBhcnJheVtpXSwgaSkpICE9IG51bGwgJiYgYiA+PSBiKSB7CiAgICAgICAgYSA9IGMgPSBiOwogICAgICAgIGJyZWFrOwogICAgICB9CiAgICAgIHdoaWxlICgrK2kgPCBuKSBpZiAoKGIgPSBmLmNhbGwoYXJyYXksIGFycmF5W2ldLCBpKSkgIT0gbnVsbCkgewogICAgICAgIGlmIChhID4gYikgYSA9IGI7CiAgICAgICAgaWYgKGMgPCBiKSBjID0gYjsKICAgICAgfQogICAgfQogICAgcmV0dXJuIFsgYSwgYyBdOwogIH07CiAgZnVuY3Rpb24gZDNfbnVtYmVyKHgpIHsKICAgIHJldHVybiB4ID09PSBudWxsID8gTmFOIDogK3g7CiAgfQogIGZ1bmN0aW9uIGQzX251bWVyaWMoeCkgewogICAgcmV0dXJuICFpc05hTih4KTsKICB9CiAgZDMuc3VtID0gZnVuY3Rpb24oYXJyYXksIGYpIHsKICAgIHZhciBzID0gMCwgbiA9IGFycmF5Lmxlbmd0aCwgYSwgaSA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udHMubGVuZ3RoID09PSAxKSB7CiAgICAgIHdoaWxlICgrK2kgPCBuKSBpZiAoZDNfbnVtZXJpYyhhID0gZDNfbnVtYmVyKGFycmF5W2ldKSkpIG51bWJlcnMucHVzaChhKTsKICAgIH0gZWxzZSB7CiAgICAgIHdoaWxlICgrK2kgPCBuKSBpZiAoZDNfbnVtZXJpYyhhID0gZDNfbnVtYmVyKGYuY2FsbChhcnJheSwgYXJyYXlbaV0sIGkpKSkpIG51bWJlcnMucHVzaChhKTsKICAgIH0KICAgIGlmIChudW1iZXJzLmxlbmd0aCkgcmV0dXJuIGQzLnF1YW50aWxlKG51bWJlcnMuc29ydChkM19hc2NlbmRpbmcpLCAuNSk7CiAgfTsKICBkMy52YXJpYW5jZSA9IGZ1bmN0aW9uKGFycmF5LCBmKSB7CiAgICB2YXIgbiA9IGFycmF5Lmxlbmd0aCwgbSA9IDAsIGEsIGQsIHMgPSAwLCBpID0gLTEsIGogPSAwOwogICAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPT09IDEpIHsKICAgICAgd2hpbGUgKCsraSA8IG4pIHsKICAgICAgICBpZiAoZDNfbnVtZXJpYyhhID0gZDNfbnVtYmVyKGFycmF5W2ldKSkpIHsKICAgICAgICAgIGQgPSBhIC0gbTsKICAgICAgICAgIG0gKz0gZCAvICsrajsKICAgICAgICAgIHMgKz0gZCAqIChhIC0gbSk7CiAgICAgICAgfQogICAgICB9CiAgICB9IGVsc2UgewogICAgICB3aGlsZSAoKytpIDwgbikgewogICAgICAgIGlmIChkM19udW1lcmljKGEgPSBkM19udW1iZXIoZi5jYWxsKGFycmF5LCBhcnJheVtpXSwgaSkpKSkgewogICAgICAgICAgZCA9IGEgLSBtOwogICAgICAgICAgbSArPSBkIC8gKytqOwogICAgICAgICAgcyArPSBkICogKGEgLSBtKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIGlmIChqID4gMSkgcmV0dXJuIHMgLyAoaiAtIDEpOwogIH07CiAgZDMuZGV2aWF0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wID0gcDEsIHAxID0gYXJyYXlbKytpXSBdOwogICAgcmV0dXJuIHBhaXJzOwogIH07CiAgZDMuemlwID0gZnVuY3Rpb24oKSB7CiAgICBpZiAoIShuID0gYXJndW1lbnRzLmxlbmd0aCkpIHJldHVybiBbXTsKICAgIGZvciAodmFyIGkgPSAtMSwgbSA9IGQzLm1pbihhcmd1bWVudHMsIGQzX3ppcExlbmd0aCksIHppcHMgPSBuZXcgQXJyYXkobSk7ICsraSA8IG07ICkgewogICAgICBmb3IgKHZhciBqID0gLTEsIG4sIHppcCA9IHppcHNbaV0gPSBuZXcgQXJyYXkobik7ICsraiA8IG47ICkgewogICAgICAgIHppcFtqXSA9IGFyZ3VtZW50c1tqXVtpXTsKICAgICAgfQogICAgfQogICAgcmV0dXJuIHppcHM7CiAgfTsKICBmdW5jdGlvbiBkM196aXBMZW5ndGgoZCkgewogICAgcmV0dXJuIGQubGVuZ3RoOwogIH0KICBkMy50cmFuc3Bvc2UgPSBmdW5jdGlvbihtYXRyaXgpIHsKICAgIHJldHVybiBkMy56aXAuYXBwbHkoZDMsIG1hdHJpeCk7CiAgfTsKICBkMy5rZXlzID0gZnVuY3Rpb24obWFwKSB7CiAgICB2YXIga2V5cyA9IFtdOwogICAgZm9yICh2YXIga2V5IGluIG1hcCkga2V5cy5wdXNoKGtleSk7CiAgICByZXR1cm4ga2V5czsKICB9OwogIGQzLnZhbHVlcyA9IGZ1bmN0aW9uKG1hcCkgewogICAgdmFyIHZhbHVlcyA9IFtdOwogICAgZm9yICh2YXIga2V5IGluIG1hcCkgdmFsdWVzLnB1c2gobWFwW2tleV0pOwogICAgcmV0dXJuIHZhbHVlczsKICB9OwogIGQzLmVudHJpZXMgPSBmdW5jdGlvbihtYXApIHsKICAgIHZhciBlbnRyaWVzID0gW107CiAgICBmb3IgKHZhciBrZXkgaW4gbWFwKSBlbnRyaWVzLnB1c2goewogICAgICBrZXk6IGtleSwKICAgICAgdmFsdWU6IG1hcFtrZXldCiAgICB9KTsKIC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vYmplY3Rba2V5XSk7CiAgICB9CiAgICByZXR1cm4gbWFwOwogIH07CiAgZnVuY3Rpb24gZDNfTWFwKCkgewogICAgdGhpcy5fID0gT2JqZWN0LmNyZWF0ZShudWxsKTsKICB9CiAgdmFyIGQzX21hcF9wcm90byA9ICJfX3Byb3RvX18iLCBkM19tYXBfemVybyA9ICJceDAwIjsKICBkM19jbGFzcyhkM19NYXAsIHsKICAgIGhhczogZDNfbWFwX2hhcywKICAgIGdldDogZnVuY3Rpb24oa2V5KSB7CiAgICAgIHJldHVybiB0aGlzLl9bZDNfbWFwX2VzY2FwZShrZXkpXTsKICAgIH0sCiAgICBzZXQ6IGZ1bmN0aW9uKGtleSwgdmFsdWUpIHsKICAgICAgcmV0dXJuIHRoaXMuX1tkM19tYXBfZXNjYXBlKGtleSldID0gdmFsdWU7CiAgICB9LAogICAgcmVtb3ZlOiBkM19tYXBfcmVtb3ZlLAogICAga2V5czogZDNfbWFwX2tleXMsCiAgICB2YWx1ZXM6IGZ1bmN0aW9uKCkgewogICAgICB2YXIgdmFsdWVzID0gW107CiAgICAgIGZvciAodmFyIGtleSBpbiB0aGlzLl8pIHZhbHVlcy5wdXNoKHRoaXMuX1trZXldKTsKICAgICAgcmV0dXJuIHZhbHVlczsKICAgIH0sCiAgICBlbnRyaWVzOiBmdW5jdGlvbigpIHsKICAgICAgdmFyIGVudHJpZXMgPSBbXTsKICAgICAgZm9yICh2YXIga2V5IGluIHRoaXMuXykgZW50cmllcy5wdXNoKHsKICAgICAgICBrZXk6IGQzX21hcF91bmVzY2FwZShrZXkpLAogICAgICAgIHZhbHVlOiB0aGlzLl9ba2V5XQogICAgICB9KTsKICAgICAgcmV0dXJuIGVudHJpZXM7CiAgICB9LAogICAgc2l6ZTogZDNfbWFwX3NpemUsCiAgICBlbXB0eTogZDNfbWFwX2VtcHR5LAogICAgZm9yRWFjaDogZnVuY3Rpb24oZikgewogICAgICBmb3IgKHZhciBrZXkgaW4gdGhpcy5fKSBmLmNhbGw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UgIT09IHRydWUpIHsKICAgICAgICAgICAgdXBkYXRlTm9kZXNbaV0gPSBub2RlOwogICAgICAgICAgICBub2RlLl9fZGF0YV9fID0gbm9kZURhdGE7CiAgICAgICAgICB9CiAgICAgICAgICBub2RlQnlLZXlWYWx1ZS5zZXQoa2V5VmFsdWUsIHRydWUpOwogICAgICAgIH0KICAgICAgICBmb3IgKGkgPSAtMTsgKytpIDwgbjsgKSB7CiAgICAgICAgICBpZiAobm9kZUJ5S2V5VmFsdWUuZ2V0KGtleVZhbHVlc1tpXSkgIT09IHRydWUpIHsKICAgICAgICAgICAgZXhpdE5vZGVzW2ldID0gZ3JvdXBbaV07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9IGVsc2UgewogICAgICAgIGZvciAoaSA9IC0xOyArK2kgPCBuMDsgKSB7CiAgICAgICAgICBub2RlID0gZ3JvdXBbaV07CiAgICAgICAgICBub2RlRGF0YSA9IGdyb3VwRGF0YVtpXTsKICAgICAgICAgIGlmIChub2RlKSB7CiAgICAgICAgICAgIG5vZGUuX19kYXRhX18gPSBub2RlRGF0YTsKICAgICAgICAgICAgdXBkYXRlTm9kZXNbaV0gPSBub2RlOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZW50ZXJOb2Rlc1tpXSA9IGQzX3NlbGVjdGlvbl9kYXRhTm9kZShub2RlRGF0YSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoO2kgPCBtOyArK2kpIHsKICAgICAgICAgIGVudGVyTm9kZXNbaV0gPSBkM19zZWxlY3Rpb25fZGF0YU5vZGUoZ3JvdXBEYXRhW2ldKTsKICAgICAgICB9CiAgICAgICAgZm9yICg7aSA8IG47ICsraSkgewogICAgICAgICAgZXhpdE5vZGVzW2ldID0gZ3JvdXBbaV07CiAgICAgICAgfQogICAgICB9CiAgICAgIGVudGVyTm9kZXMudXBkYXRlID0gdXBkYXRlTm9kZXM7CiAgICAgIGVudGVyTm9kZXMucGFyZW50Tm9kZ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bmRvdykub24oInRvdWNobW92ZSIgKyBuYW1lLCBkM19ldmVudFByZXZlbnREZWZhdWx0KS5vbigiZHJhZ3N0YXJ0IiArIG5hbWUsIGQzX2V2ZW50UHJldmVudERlZmF1bHQpLm9uKCJzZWxlY3RzdGFydCIgKyBuYW1lLCBkM19ldmVudFByZXZlbnREZWZhdWx0KTsKICAgIGlmIChkM19ldmVudF9kcmFnU2VsZWN0KSB7CiAgICAgIHZhciBzdHlsZSA9IGQzX2RvY3VtZW50RWxlbWVudC5zdHlsZSwgc2VsZWN0ID0gc3R5bGVbZDNfZXZlbnRfZHJhZ1NlbGVjdF07CiAgICAgIHN0eWxlW2QzX2V2ZW50X2RyYWdTZWxlY3RdID0gIm5vbmUiOwogICAgfQogICAgcmV0dXJuIGZ1bmN0aW9uKHN1cHByZXNzQ2xpY2spIHsKICAgICAgdy5vbihuYW1lLCBudWxsKTsKICAgICAgaWYgKGQzX2V2ZW50X2RyYWdTZWxlY3QpIHN0eWxlW2QzX2V2ZW50X2RyYWdTZWxlY3RdID0gc2VsZWN0OwogICAgICBpZiAoc3VwcHJlc3NDbGljaykgewogICAgICAgIHZhciBvZmYgPSBmdW5jdGlvbigpIHsKICAgICAgICAgIHcub24oY2xpY2ssIG51bGwpOwogICAgICAgIH07CiAgICAgICAgdy5vbihjbGljaywgZnVuY3Rpb24oKSB7CiAgICAgICAgICBkM19ldmVudFByZXZlbnREZWZhdWx0KCk7CiAgICAgICAgICBvZmYoKTsKICAgICAgICB9LCB0cnVlKTsKICAgICAgICBzZXRUaW1lb3V0KG9mZiwgMCk7CiAgICAgIH0KICAgIH07CiAgfQogIGQzLm1vdXNlID0gZnVuY3Rpb24oY29udGFpbmVyKSB7CiAgICByZXR1cm4gZDNfbW91c2VQb2ludChjb250YWluZXIsIGQzX2V2ZW50U291cmNlKCkpOwogIH07CiAgdmFyIGQzX21vdXNlX2J1ZzQ0MDgzID0gL1dlYktpdC8udGVzdChkM193aW5kb3cubmF2aWdhdG9yLnVzZ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AgICB9IGVsc2UgewogICAgICAgICAgZHJhZ09mZnNldCA9IFsgMCwgMCBdOwogICAgICAgIH0KICAgICAgICBkaXNwYXRjaCh7CiAgICAgICAgICB0eXBlOiAiZHJhZ3N0YXJ0IgogICAgICAgIH0pOwogICAgICAgIGZ1bmN0aW9uIG1vdmVkKCkgewogICAgICAgICAgdmFyIHBvc2l0aW9uMSA9IHBvc2l0aW9uKHBhcmVudCwgZHJhZ0lkKSwgZHgsIGR5OwogICAgICAgICAgaWYgKCFwb3NpdGlvbjEpIHJldHVybjsKICAgICAgICAgIGR4ID0gcG9zaXRpb24xWzBdIC0gcG9zaXRpb24wWzBdOwogICAgICAgICAgZHkgPSBwb3NpdGlvbjFbMV0gLSBwb3NpdGlvbjBbMV07CiAgICAgICAgICBkcmFnZ2VkIHw9IGR4IHwgZHk7CiAgICAgICAgICBwb3NpdGlvbjAgPSBwb3NpdGlvbjE7CiAgICAgICAgICBkaXNwYXRjaCh7CiAgICAgICAgICAgIHR5cGU6ICJkcmFnIiwKICAgICAgICAgICAgeDogcG9zaXRpb24xWzBdICsgZHJhZ09mZnNldFswXSwKICAgICAgICAgICAgeTogcG9zaXRpb24xWzFdICsgZHJhZ09mZnNldFsxXSwKICAgICAgICAgICAgZHg6IGR4LAogICAgICAgICAgICBkeTogZHkKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBlbmRlZCgpIHsKICAgICAgICAgIGlmICghcG9zaXRpb24ocGFyZW50LCBkcmFnSWQpKSByZXR1cm47CiAgICAgICAgICBkcmFnU3ViamVjdC5vbihtb3ZlICsgZHJhZ05hbWUsIG51bGwpLm9uKGVuZCArIGRyYWdOYW1lLCBudWxsKTsKICAgICAgICAgIGRyYWdSZXN0b3JlKGRyYWdnZWQgJiYgZDMuZXZlbnQudGFyZ2V0ID09PSB0YXJnZXQpOwogICAgICAgICAgZGlzcGF0Y2goewogICAgICAgICAgICB0eXBlOiAiZHJhZ2VuZCIKICAgICAgICAgIH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ewogICAgICAgICAgICAgIHg6IDAsCiAgICAgICAgICAgICAgeTogMCwKICAgICAgICAgICAgICBrOiAxCiAgICAgICAgICAgIH07CiAgICAgICAgICAgIHpvb21zdGFydGVkKGRpc3BhdGNoKTsKICAgICAgICAgIH0pLnR3ZWVuKCJ6b29tOnpvb20iLCBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGR4ID0gc2l6ZVswXSwgZHkgPSBzaXplWzFdLCBjeCA9IGNlbnRlcjAgPyBjZW50ZXIwWzBdIDogZHggLyAyLCBjeSA9IGNlbnRlcjAgPyBjZW50ZXIwWzFdIDogZHkgLyAyLCBpID0gZDMuaW50ZXJwb2xhdGVab29tKFsgKGN4IC0gdmlldy54KSAvIHZpZXcuaywgKGN5IC0gdmlldy55KSAvIHZpZXcuaywgZHggLyB2aWV3LmsgXSwgWyAoY3ggLSB2aWV3MS54KSAvIHZpZXcxLmssIChjeSAtIHZpZXcxLnkpIC8gdmlldzEuaywgZHggLyB2aWV3MS5rIF0pOwogICAgICAgICAgICByZXR1cm4gZnVuY3Rpb24odCkgewogICAgICAgICAgICAgIHZhciBsID0gaSh0KSwgayA9IGR4IC8gbFsyXTsKICAgICAgICAgICAgICB0aGlzLl9fY2hhcnRfXyA9IHZpZXcgPSB7CiAgICAgICAgICAgICAgICB4OiBjeCAtIGxbMF0gKiBrLAogICAgICAgICAgICAgICAgeTogY3kgLSBsWzFdICogaywKICAgICAgICAgICAgICAgIGs6IGsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgIHpvb21lZChkaXNwYXRjaCk7CiAgICAgICAgICAgIH07CiAgICAgICAgICB9KS5lYWNoKCJpbnRlcnJ1cHQuem9vbSIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICB6b29tZW5kZWQoZGlzcGF0Y2gpOwogICAgICAgICAgfSkuZWFjaCgiZW5kLnpvb20iLCBmdW5jdGlvbigpIHsKICAgICAgICAgICAgem9vbWVuZGVkKGRpc3BhdGNoKTsKICAgICAgICAgIH0pOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB0aGlzLl9fY2hhcnRfXyA9IHZpZXc7CiAgICAgICAgICB6b29tc3RhcnRlZChkaXNwYXRjaCk7CiAgICAgICAgICB6b29tZWQoZGlzcGF0Y2gpOwogICAgICAgICAgem9vbWVuZGVkKGRpc3BhdGNoKTsKICAgICAgICB9CiAgICAgIH0pOwogICAgfTsKICAgIHpvb20udHJhbnNsYXRlID0gZnVuY3Rpb24oXykgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBbIHZpZXcueCwgdmlldy55IF07CiAgICAgIHZpZXcgPSB7CiAgICAgICAgeDogK19bMF0sCiAgICAgICAgeTogK19bMV0sCiAgICAgICAgazogdmlldy5rCiAgICAgIH07CiAgICAgIHJlc2NhbGUoKTsKICAgICAgcmV0dXJuIHpvb207CiAgICB9OwogICAgem9vbS5zY2FsZSA9IGZ1bmN0aW9uKF8pIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4gdmlldy5rOwogICAgICB2aWV3ID0gewogICAgICAgIHg6IHZpZXcueCwKICAgICAgICB5OiB2aWV3LnksCiAgICAgICAgazogK18KICAgICAgfTsKICAgICAgcmVzY2FsZSgpOwogICAgICByZXR1cm4gem9vbTsKICAgIH07CiAgICB6b29tLnNjYWxlRXh0ZW50ID0gZnVuY3Rpb24oXykgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBzY2FsZUV4dGVudDsKICAgICAgc2NhbGVFeHRlbnQgPSBfID09IG51bGwgPyBkM19iZWhhdmlvcl96b29tSW5maW5pdHkgOiBbICtfWzBdLCArX1sxXSBdOwogICAgICByZXR1cm4gem9vbTsKICAgIH07CiAgICB6b29tLmNlbnRlciA9IGZ1bmN0aW9uKF8pIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4gY2VudGVyOwogICAgICBjZW50ZXIgPSBfICYmIFsgK19bMF0sICtfWzFdIF07CiAgICAgIHJldHVybiB6b29tOwogICAgfTsKICAgIHpvb20uc2l6ZSA9IGZ1bmN0aW9uKF8pIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4gc2l6ZTsKICAgICAgc2l6ZSA9IF8gJiYgWyArX1swXSwgK19bMV0gXTsKICAgICAgcmV0dXJuIHpvb207CiAgICB9OwogICAgem9vbS5kdXJhdGlvbiA9IGZ1bmN0aW9uKF8pIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4gZHVyYXRpb247CiAgICAgIGR1cmF0aW9uID0gK187CiAgICAgIHJldHVybiB6b29tOwogICAgfTsKICAgIHpvb20ueCA9IGZ1bmN0aW9uKHopIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4geDE7CiAgICAgIHgxID0gejsKICAgICAgeDAgPSB6LmNvcHkoKTsKICAgICAgdmlldyA9IHsKICAgICAgICB4OiAwLAogICAgICAgIHk6IDAsCiAgICAgICAgazogMQogICAgICB9OwogICAgICByZXR1cm4gem9vbTsKICAgIH07CiAgICB6b29tLnkgPSBmdW5jdGlvbih6KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIHkxOwogICAgICB5MSA9IHo7CiAgICAgIHkwID0gei5jb3B5KCk7CiAgICAgIHZpZXcgPSB7CiAgICAgICAgeDogMCwKICAgICAgICB5OiAwLAogICAgICAgIGs6IDEKICAgICAgfTsKICAgICAgcmV0dXJuIHpvb207CiAgICB9OwogICAgZnVuY3Rpb24gbG9jYXRpb24ocCkgewogICAgICByZXR1cm4gWyAocFswXSAtIHZpZXcueCkgLyB2aWV3LmssIChwWzFdIC0gdmlldy55KSAvIHZpZXcuayBdOwogICAgfQogICAgZnVuY3Rpb24gcG9pbnQobCkgewogICAgICByZXR1cm4gWyBsWzBdICogdmlldy5rICsgdmlldy54LCBsWzFdICogdmlldy5rICsgdmlldy55IF07CiAgICB9CiAgICBmdW5jdGlvbiBzY2FsZVRvKHMpIHsKICAgICAgdmlldy5rID0gTWF0aC5tYXgoc2NhbGVFeHRlbnRbMF0sIE1hdGgubWluKHNjYWxlRXh0ZW50WzFdLCBzKSk7CiAgICB9CiAgICBmdW5jdGlvbiB0cmFuc2xhdGVUbyhwLCBsKSB7CiAgICAgIGwgPSBwb2ludChsKTsKICAgICAgdmlldy54ICs9IHBbMF0gLSBsWzBdOwogICAgICB2aWV3LnkgKz0gcFsxXSAtIGxbMV07CiAgICB9CiAgICBmdW5jdGlvbiB6b29tVG8odGhhdCwgcCwgbCwgaykgewogICAgICB0aGF0Ll9fY2hhcnRfXyA9IHsKICAgICAgICB4OiB2aWV3LngsCiAgICAgICAgeTogdmlldy55LAogICAgICAgIGs6IHZpZXcuawogICAgICB9OwogICAgICBzY2FsZVRvKE1hdGgucG93KDIsIGspKTsKICAgICAgdHJhbnNsYXRlVG8oY2VudGVyMCA9IHAsIGwpOwogICAgICB0aGF0ID0gZDMuc2VsZWN0KHRoYXQpOwogICAgICBpZiAoZHVyYXRpb24gPiAwKSB0aGF0ID0gdGhhdC50cmFuc2l0aW9uKCkuZHVyYXRpb24oZHVyYXRpb24pOwogICAgICB0aGF0LmNhbGwoem9vbS5ldmVudCk7CiAgICB9CiAgICBmdW5jdGlvbiByZXNjYWxlKCkgewogICAgICBpZiAoeDEpIHgxLmRvbWFpbih4MC5yYW5nZSgpLm1hcChmdW5jdGlvbih4KSB7CiAgICAgICAgcmV0dXJuICh4IC0gdmlldy54KSAvIHZpZXcuazsKICAgICAgfSkubWFwKHgwLmludmVydCkpOwogICAgICBpZiAoeTEpIHkxLmRvbWFpbih5MC5yYW5nZSgpLm1hcChmdW5jdGlvbih5KSB7CiAgICAgICAgcmV0dXJuICh5IC0gdmlldy55KSAvIHZpZXcuazsKICAgICAgfSkubWFwKHkwLmludmVydCkpOwogICAgfQogICAgZnVuY3Rpb24gem9vbXN0YXJ0ZWQoZGlzcGF0Y2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MwW3QuaWRlbnRpZmllcl0gPSBsb2NhdGlvbih0KTsKICAgICAgICB9KTsKICAgICAgICByZXR1cm4gdG91Y2hlczsKICAgICAgfQogICAgICBmdW5jdGlvbiBzdGFydGVkKCkgewogICAgICAgIHZhciB0YXJnZXQgPSBkMy5ldmVudC50YXJnZXQ7CiAgICAgICAgZDMuc2VsZWN0KHRhcmdldCkub24odG91Y2htb3ZlLCBtb3ZlZCkub24odG91Y2hlbmQsIGVuZGVkKTsKICAgICAgICB0YXJnZXRzLnB1c2godGFyZ2V0KTsKICAgICAgICB2YXIgY2hhbmdlZCA9IGQzLmV2ZW50LmNoYW5nZWRUb3VjaGVzOwogICAgICAgIGZvciAodmFyIGkgPSAwLCBuID0gY2hhbmdlZC5sZW5ndGg7IGkgPCBuOyArK2kpIHsKICAgICAgICAgIGxvY2F0aW9uczBbY2hhbmdlZFtpXS5pZGVudGlmaWVyXSA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHZhciB0b3VjaGVzID0gcmVsb2NhdGUoKSwgbm93ID0gRGF0ZS5ub3coKTsKICAgICAgICBpZiAodG91Y2hlcy5sZW5ndGggPT09IDEpIHsKICAgICAgICAgIGlmIChub3cgLSB0b3VjaHRpbWUgPCA1MDApIHsKICAgICAgICAgICAgdmFyIHAgPSB0b3VjaGVzWzBdOwogICAgICAgICAgICB6b29tVG8odGhhdCwgcCwgbG9jYXRpb25zMFtwLmlkZW50aWZpZXJdLCBNYXRoLmZsb29yKE1hdGgubG9nKHZpZXcuaykgLyBNYXRoLkxOMikgKyAxKTsKICAgICAgICAgICAgZDNfZXZlbnRQcmV2ZW50RGVmYXVsdCgpOwogICAgICAgICAgfQogICAgICAgICAgdG91Y2h0aW1lID0gbm93OwogICAgICAgIH0gZWxzZSBpZiAodG91Y2hlcy5sZW5ndGggPiAxKSB7CiAgICAgICAgICB2YXIgcCA9IHRvdWNoZXNbMF0sIHEgPSB0b3VjaGVzWzFdLCBkeCA9IHBbMF0gLSBxWzBdLCBkeSA9IHBbMV0gLSBxWzFdOwogICAgICAgICAgZGlzdGFuY2UwID0gZHggKiBkeCArIGR5ICogZHk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIG1vdmVkKCkgewogICAgICAgIHZhciB0b3VjaGVzID0gZDMudG91Y2hlcyh0aGF0KSwgcDAsIGwwLCBwMSwgbDE7CiAgICAgICAgZDNfc2VsZWN0aW9uX2ludGVycnVwdC5jYWxsKHRoYXQpOwogICAgICAgIGZvciAodmFyIGkgPSAwLCBuID0gdG91Y2hlcy5sZW5ndGg7IGkgPCBuOyArK2ksIGwxID0gbnVsbCkgewogICAgICAgICAgcDEgPSB0b3VjaGVzW2ldOwogICAgICAgICAgaWYgKGwxID0gbG9jYXRpb25zMFtwMS5pZGVudGlmaWVyXSkgewogICAgICAgICAgICBpZiAobDApIGJyZWFrOwogICAgICAgICAgICBwMCA9IHAxLCBsMCA9IGwxOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobDEpIHsKICAgICAgICAgIHZhciBkaXN0YW5jZTEgPSAoZGlzdGFuY2UxID0gcDFbMF0gLSBwMFswXSkgKiBkaXN0YW5jZTEgKyAoZGlzdGFuY2UxID0gcDFbMV0gLSBwMFsxXSkgKiBkaXN0YW5jZTEsIHNjYWxlMSA9IGRpc3RhbmNlMCAmJiBNYXRoLnNxcnQoZGlzdGFuY2UxIC8gZGlzdGFuY2UwKTsKICAgICAgICAgIHAwID0gWyAocDBbMF0gKyBwMVswXSkgLyAyLCAocDBbMV0gKyBwMVsxXSkgLyAyIF07CiAgICAgICAgICBsMCA9IFsgKGwwWzBdICsgbDFbMF0pIC8gMiwgKGwwWzFdICsgbDFbMV0pIC8gMiBdOwogICAgICAgICAgc2NhbGVUbyhzY2FsZTEgKiBzY2FsZTApOwogICAgICAgIH0KICAgICAgICB0b3VjaHRpbWUgPSBudWxsOwogICAgICAgIHRyYW5zbGF0ZVRvKHAwLCBsMCk7CiAgICAgICAgem9vbWVkKGRpc3Bh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tYXQpOwogICAgaWYgKG0xKSB7CiAgICAgIG0yID0gbTFbMl0uc3BsaXQoIiwiKTsKICAgICAgc3dpdGNoIChtMVsxXSkgewogICAgICAgY2FzZSAiaHNsIjoKICAgICAgICB7CiAgICAgICAgICByZXR1cm4gaHNsKHBhcnNlRmxvYXQobTJbMF0pLCBwYXJzZUZsb2F0KG0yWzFdKSAvIDEwMCwgcGFyc2VGbG9hdChtMlsyXSkgLyAxMDApOwogICAgICAgIH0KCiAgICAgICBjYXNlICJyZ2IiOgogICAgICAgIHsKICAgICAgICAgIHJldHVybiByZ2IoZDNfcmdiX3BhcnNlTnVtYmVyKG0yWzBdKSwgZDNfcmdiX3BhcnNlTnVtYmVyKG0yWzFdKSwgZDNfcmdiX3BhcnNlTnVtYmVyKG0yWzJdKSk7CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICBpZiAoY29sb3IgPSBkM19yZ2JfbmFtZXMuZ2V0KGZvcm1hdCkpIHJldHVybiByZ2IoY29sb3IuciwgY29sb3IuZywgY29sb3IuYik7CiAgICBpZiAoZm9ybWF0ICE9IG51bGwgJiYgZm9ybWF0LmNoYXJBdCgwKSA9PT0gIiMiICYmICFpc05hTihjb2xvciA9IHBhcnNlSW50KGZvcm1hdC5zbGljZSgxKSwgMTYpKSkgewogICAgICBpZiAoZm9ybWF0Lmxlbmd0aCA9PT0gNCkgewogICAgICAgIHIgPSAoY29sb3IgJiAzODQwKSA+PiA0OwogICAgICAgIHIgPSByID4+IDQgfCByOwogICAgICAgIGcgPSBjb2xvciAmIDI0MDsKICAgICAgICBnID0gZyA+PiA0IHwgZzsKICAgICAgICBiID0gY29sb3IgJiAxNTsKICAgICAgICBiID0gYiA8PCA0IHwgYjsKICAgICAgfSBlbHNlIGlmIChmb3JtYXQubGVuZ3RoID09PSA3KSB7CiAgICAgICAgciA9IChjb2xvciAmIDE2NzExNjgwKSA+PiAxNjsKICAgICAgICBnID0gKGNvbG9yICYgNjUyODApID4+IDg7CiAgICAgICAgYi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sc2UsIEVPTDsKICAgICAgICB2YXIgaiA9IEk7CiAgICAgICAgaWYgKHRleHQuY2hhckNvZGVBdChqKSA9PT0gMzQpIHsKICAgICAgICAgIHZhciBpID0gajsKICAgICAgICAgIHdoaWxlIChpKysgPCBOKSB7CiAgICAgICAgICAgIGlmICh0ZXh0LmNoYXJDb2RlQXQoaSkgPT09IDM0KSB7CiAgICAgICAgICAgICAgaWYgKHRleHQuY2hhckNvZGVBdChpICsgMSkgIT09IDM0KSBicmVhazsKICAgICAgICAgICAgICArK2k7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIEkgPSBpICsgMjsKICAgICAgICAgIHZhciBjID0gdGV4dC5jaGFyQ29kZUF0KGkgKyAxKTsKICAgICAgICAgIGlmIChjID09PSAxMykgewogICAgICAgICAgICBlb2wgPSB0cnVlOwogICAgICAgICAgICBpZiAodGV4dC5jaGFyQ29kZUF0KGkgKyAyKSA9PT0gMTApICsrSTsKICAgICAgICAgIH0gZWxzZSBpZiAoYyA9PT0gMTApIHsKICAgICAgICAgICAgZW9sID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0ZXh0LnNsaWNlKGogKyAxLCBpKS5yZXBsYWNlKC8iIi9nLCAnIicpOwogICAgICAgIH0KICAgICAgICB3aGlsZSAoSSA8IE4pIHsKICAgICAgICAgIHZhciBjID0gdGV4dC5jaGFyQ29kZUF0KEkrKyksIGsgPSAxOwogICAgICAgICAgaWYgKGMgPT09IDEwKSBlb2wgPSB0cnVlOyBlbHNlIGlmIChjID09PSAxMykgewogICAgICAgICAgICBlb2wgPSB0cnVlOwogICAgICAgICAgICBpZiAodGV4dC5jaGFyQ29kZUF0KEkpID09PSAxMCkgKytJLCArK2s7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgIT09IGRlbGltaXRlckNvZGUpIGNvbnRpbnVlOwogICAgICAgICAgcmV0dXJuIHRleHQuc2xpY2UoaiwgSSAtIGspOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGV4dC5zbGljZShqKTsKICAgICAgfQogICAgICB3aGlsZSAoKHQgPSB0b2tlbigpKSAhPT0gRU9GKSB7CiAgICAgICAgdmFyIGEgPSBbXTsKICAgICAgICB3aGlsZSAodCAhPT0gRU9MICYmIHQgIT09IEVPRikgewogICAgICAgICAgYS5wdXNoKHQpOwogICAgICAgICAgdCA9IHRva2VuKCk7CiAgICAgICAgfQogICAgICAgIGlmIChmICYmIChhID0gZihhLCBuKyspKSA9PSBudWxsKSBjb250aW51ZTsKICAgICAgICByb3dzLnB1c2goYSk7CiAgICAgIH0KICAgICAgcmV0dXJuIHJvd3M7CiAgICB9OwogICAgZHN2LmZvcm1hdCA9IGZ1bmN0aW9uKHJvd3MpIHsKICAgICAgaWYgKEFycmF5LmlzQXJyYXkocm93c1swXSkpIHJldHVybiBkc3YuZm9ybWF0Um93cyhyb3dzKTsKICAgICAgdmFyIGZpZWxkU2V0ID0gbmV3IGQzX1NldCgpLCBmaWVsZHMgPSBbXTsKICAgICAgcm93cy5mb3JFYWNoKGZ1bmN0aW9uKHJvdykgewogICAgICAgIGZvciAodmFyIGZpZWxkIGluIHJvdykgewogICAgICAgICAgaWYgKCFmaWVsZFNldC5oYXMoZmllbGQpKSB7CiAgICAgICAgICAgIGZpZWxkcy5wdXNoKGZpZWxkU2V0LmFkZChmaWVsZCkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfSk7CiAgICAgIHJldHVybiBbIGZpZWxkcy5tYXAoZm9ybWF0VmFsdWUpLmpvaW4oZGVsaW1pdGVyKSBdLmNvbmNhdChyb3dzLm1hcChmdW5jdGlvbihyb3cpIHsKICAgICAgICByZXR1cm4gZmllbGRzLm1hcChmdW5jdGlvbihmaWVsZCkgewogICAgICAgICAgcmV0dXJuIGZvcm1hdFZhbHVlKHJvd1tmaWVsZF0pOwogICAgICAgIH0pLmpvaW4oZGVsaW1pdGVyKTsKICAgICAgfSkpLmpvaW4oIlxuIik7CiAgICB9OwogICAg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YWxsYmFjaywKICAgICAgdDogdGltZSwKICAgICAgZjogZmFsc2UsCiAgICAgIG46IG51bGwKICAgIH07CiAgICBpZiAoZDNfdGltZXJfcXVldWVUYWlsKSBkM190aW1lcl9xdWV1ZVRhaWwubiA9IHRpbWVyOyBlbHNlIGQzX3RpbWVyX3F1ZXVlSGVhZCA9IHRpbWVyOwogICAgZDNfdGltZXJfcXVldWVUYWlsID0gdGltZXI7CiAgICBpZiAoIWQzX3RpbWVyX2ludGVydmFsKSB7CiAgICAgIGQzX3RpbWVyX3RpbWVvdXQgPSBjbGVhclRpbWVvdXQoZDNfdGltZXJfdGltZW91dCk7CiAgICAgIGQzX3RpbWVyX2ludGVydmFsID0gMTsKICAgICAgZDNfdGltZXJfZnJhbWUoZDNfdGltZXJfc3RlcCk7CiAgICB9CiAgfTsKICBmdW5jdGlvbiBkM190aW1lcl9zdGVwKCkgewogICAgdmFyIG5vdyA9IGQzX3RpbWVyX21hcmsoKSwgZGVsYXkgPSBkM190aW1lcl9zd2VlcCgpIC0gbm93OwogICAgaWYgKGRlbGF5ID4gMjQpIHsKICAgICAgaWYgKGlzRmluaXRlKGRlbGF5KSkgewogICAgICAgIGNsZWFyVGltZW91dChkM190aW1lcl90aW1lb3V0KTsKICAgICAgICBkM190aW1lcl90aW1lb3V0ID0gc2V0VGltZW91dChkM190aW1lcl9zdGVwLCBkZWxheSk7CiAgICAgIH0KICAgICAgZDNfdGltZXJfaW50ZXJ2YWwgPSAwOwogICAgfSBlbHNlIHsKICAgICAgZDNfdGltZXJfaW50ZXJ2YWwgPSAxOwogICAgICBkM190aW1lcl9mcmFtZShkM190aW1lcl9zdGVwKTsKICAgIH0KICB9CiAgZDMudGltZXIuZmx1c2ggPSBmdW5jdGlvbigpIHsKICAgIGQzX3RpbWVyX21hcmsoKTsKICAgIGQzX3RpbWVyX3N3ZWVwKCk7CiAgfTsKICBmdW5jdGlvbiBkM190aW1lcl9tYXJrKCkgewogICAgdmFyIG5vdyA9IERhdGUubm93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OF0sIHR5cGUgPSBtYXRjaFs5XSwgc2NhbGUgPSAxLCBwcmVmaXggPSAiIiwgc3VmZml4ID0gIiIsIGludGVnZXIgPSBmYWxzZSwgZXhwb25lbnQgPSB0cnVlOwogICAgICBpZiAocHJlY2lzaW9uKSBwcmVjaXNpb24gPSArcHJlY2lzaW9uLnN1YnN0cmluZygxKTsKICAgICAgaWYgKHpmaWxsIHx8IGZpbGwgPT09ICIwIiAmJiBhbGlnbiA9PT0gIj0iKSB7CiAgICAgICAgemZpbGwgPSBmaWxsID0gIjAiOwogICAgICAgIGFsaWduID0gIj0iOwogICAgICB9CiAgICAgIHN3aXRjaCAodHlwZSkgewogICAgICAgY2FzZSAibiI6CiAgICAgICAgY29tbWEgPSB0cnVlOwogICAgICAgIHR5cGUgPSAiZyI7CiAgICAgICAgYnJlYWs7CgogICAgICAgY2FzZSAiJSI6CiAgICAgICAgc2NhbGUgPSAxMDA7CiAgICAgICAgc3VmZml4ID0gIiUiOwogICAgICAgIHR5cGUgPSAiZiI7CiAgICAgICAgYnJlYWs7CgogICAgICAgY2FzZSAicCI6CiAgICAgICAgc2NhbGUgPSAxMDA7CiAgICAgICAgc3VmZml4ID0gIiUiOwogICAgICAgIHR5cGUgPSAiciI7CiAgICAgICAgYnJlYWs7CgogICAgICAgY2FzZSAiYiI6CiAgICAgICBjYXNlICJvIjoKICAgICAgIGNhc2UgIngiOgogICAgICAgY2FzZSAiWCI6CiAgICAgICAgaWYgKHN5bWJvbCA9PT0gIiMiKSBwcmVmaXggPSAiMCIgKyB0eXBlLnRvTG93ZXJDYXNlKCk7CgogICAgICAgY2FzZSAiYyI6CiAgICAgICAgZXhwb25lbnQgPSBmYWxzZTsKCiAgICAgICBjYXNlICJkIjoKICAgICAgICBpbnRlZ2VyID0gdHJ1ZTsKICAgICAgICBwcmVjaXNpb24gPSAwOwogICAgICAgIGJyZWFrOwoKICAgICAgIGNhc2UgInMiOgogICAgICAgIHNjYWxlID0gLTE7CiAgICAgICAgdHlw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ZC5tLCBkLmQpOwogICAgICAgIGRhdGUuc2V0SG91cnMoZC5IICsgKGQuWiAvIDEwMCB8IDApLCBkLk0gKyBkLlogJSAxMDAsIGQuUywgZC5MKTsKICAgICAgICByZXR1cm4gbG9jYWxaID8gZGF0ZS5fIDogZGF0ZTsKICAgICAgfTsKICAgICAgZm9ybWF0LnRvU3RyaW5nID0gZnVuY3Rpb24oKSB7CiAgICAgICAgcmV0dXJuIHRlbXBsYXRlOwogICAgICB9OwogICAgICByZXR1cm4gZm9ybWF0OwogICAgfQogICAgZnVuY3Rpb24gZDNfdGltZV9wYXJzZShkYXRlLCB0ZW1wbGF0ZSwgc3RyaW5nLCBqKSB7CiAgICAgIHZhciBjLCBwLCB0LCBpID0gMCwgbiA9IHRlbXBsYXRlLmxlbmd0aCwgbSA9IHN0cmluZy5sZW5ndGg7CiAgICAgIHdoaWxlIChpIDwgbikgewogICAgICAgIGlmIChqID49IG0pIHJldHVybiAtMTsKICAgICAgICBjID0gdGVtcGxhdGUuY2hhckNvZGVBdChpKyspOwogICAgICAgIGlmIChjID09PSAzNykgewogICAgICAgICAgdCA9IHRlbXBsYXRlLmNoYXJBdChpKyspOwogICAgICAgICAgcCA9IGQzX3RpbWVfcGFyc2Vyc1t0IGluIGQzX3RpbWVfZm9ybWF0UGFkcyA/IHRlbXBsYXRlLmNoYXJBdChpKyspIDogdF07CiAgICAgICAgICBpZiAoIXAgfHwgKGogPSBwKGRhdGUsIHN0cmluZywgaikpIDwgMCkgcmV0dXJuIC0xOwogICAgICAgIH0gZWxzZSBpZiAoYyAhPSBzdHJpbmcuY2hhckNvZGVBdChqKyspKSB7CiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiBqOwogICAgfQogICAgZDNfdGltZV9mb3JtYXQudXRjID0gZnVuY3Rpb24odGVtcGxhdGUpIHsKICAgICAgdmFyIGxvY2FsID0gZDNfdGltZV9mb3JtYXQodGVtcGxhdGUpOwogICAgICBm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XAobG9jYWxlX3Nob3J0RGF5cyksIGQzX3RpbWVfbW9udGhSZSA9IGQzX3RpbWVfZm9ybWF0UmUobG9jYWxlX21vbnRocyksIGQzX3RpbWVfbW9udGhMb29rdXAgPSBkM190aW1lX2Zvcm1hdExvb2t1cChsb2NhbGVfbW9udGhzKSwgZDNfdGltZV9tb250aEFiYnJldlJlID0gZDNfdGltZV9mb3JtYXRSZShsb2NhbGVfc2hvcnRNb250aHMpLCBkM190aW1lX21vbnRoQWJicmV2TG9va3VwID0gZDNfdGltZV9mb3JtYXRMb29rdXAobG9jYWxlX3Nob3J0TW9udGhzKTsKICAgIGxvY2FsZV9wZXJpb2RzLmZvckVhY2goZnVuY3Rpb24ocCwgaSkgewogICAgICBkM190aW1lX3BlcmlvZExvb2t1cC5zZXQocC50b0xvd2VyQ2FzZSgpLCBpKTsKICAgIH0pOwogICAgdmFyIGQzX3RpbWVfZm9ybWF0cyA9IHsKICAgICAgYTogZnVuY3Rpb24oZCkgewogICAgICAgIHJldHVybiBsb2NhbGVfc2hvcnREYXlzW2QuZ2V0RGF5KCldOwogICAgICB9LAogICAgICBBOiBmdW5jdGlvbihkKSB7CiAgICAgICAgcmV0dXJuIGxvY2FsZV9kYXlzW2QuZ2V0RGF5KCldOwogICAgICB9LAogICAgICBiOiBmdW5jdGlvbihkKSB7CiAgICAgICAgcmV0dXJuIGxvY2FsZV9zaG9ydE1vbnRoc1tkLmdldE1vbnRoKCldOwogICAgICB9LAogICAgICBCOiBmdW5jdGlvbihkKSB7CiAgICAgICAgcmV0dXJuIGxvY2FsZV9tb250aHNbZC5nZXRNb250aCgpXTsKICAgICAgfSwKICAgICAgYzogZDNfdGltZV9mb3JtYXQobG9jYWxlX2RhdGVUaW1lKSwKICAgICAgZDogZnVuY3Rpb24oZCwgcCkgewogICAgICAgIHJldHVybiBkM190aW1lX2Zvcm1hdFBhZChkLmdldERhdGUoKSwgcCwgMik7CiAgICAgIH0sCiAgICAgIGU6IGZ1bmN0aW9uKGQs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AgICAgcmV0dXJuIGQzX3RpbWVfZm9ybWF0UGFkKGQzX3RpbWUuc3VuZGF5T2ZZZWFyKGQpLCBwLCAyKTsKICAgICAgfSwKICAgICAgdzogZnVuY3Rpb24oZCkgewogICAgICAgIHJldHVybiBkLmdldERheSgpOwogICAgICB9LAogICAgICBXOiBmdW5jdGlvbihkLCBwKSB7CiAgICAgICAgcmV0dXJuIGQzX3RpbWVfZm9ybWF0UGFkKGQzX3RpbWUubW9uZGF5T2ZZZWFyKGQpLCBwLCAyKTsKICAgICAgfSwKICAgICAgeDogZDNfdGltZV9mb3JtYXQobG9jYWxlX2RhdGUpLAogICAgICBYOiBkM190aW1lX2Zvcm1hdChsb2NhbGVfdGltZSksCiAgICAgIHk6IGZ1bmN0aW9uKGQsIHApIHsKICAgICAgICByZXR1cm4gZDNfdGltZV9mb3JtYXRQYWQoZC5nZXRGdWxsWWVhcigpICUgMTAwLCBwLCAyKTsKICAgICAgfSwKICAgICAgWTogZnVuY3Rpb24oZCwgcCkgewogICAgICAgIHJldHVybiBkM190aW1lX2Zvcm1hdFBhZChkLmdldEZ1bGxZZWFyKCkgJSAxZTQsIHAsIDQpOwogICAgICB9LAogICAgICBaOiBkM190aW1lX3pvbmUsCiAgICAgICIlIjogZnVuY3Rpb24oKSB7CiAgICAgICAgcmV0dXJuICIlIjsKICAgICAgfQogICAgfTsKICAgIHZhciBkM190aW1lX3BhcnNlcnMgPSB7CiAgICAgIGE6IGQzX3RpbWVfcGFyc2VXZWVrZGF5QWJicmV2LAogICAgICBBOiBkM190aW1lX3BhcnNlV2Vla2RheSwKICAgICAgYjogZDNfdGltZV9wYXJzZU1vbnRoQWJicmV2LAogICAgICBCOiBkM190aW1lX3BhcnNlTW9udGgsCiAgICAgIGM6IGQzX3RpbWVfcGFyc2VMb2NhbGVGdWxsLAogICAgICBkOiBkM190aW1lX3BhcnNlRGF5LAogICAgICBlOiBkM190aW1lX3BhcnNlRGF5LAogICAgICBIOiBkM190aW1lX3BhcnNlS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iAgICAgICAgdmFyIGTOuyA9IM67IC0gzrtfLCBzID0gZM67ID4gMCA/IDEgOiAtMSwgzrtpID0gaW5mbGVjdGlvblswXSAqIGQzX2RlZ3JlZXMgKiBzLCBhbnRpbWVyaWRpYW4gPSBhYnMoZM67KSA+IDE4MDsKICAgICAgICBpZiAoYW50aW1lcmlkaWFuIF4gKHMgKiDOu18gPCDOu2kgJiYgzrtpIDwgcyAqIM67KSkgewogICAgICAgICAgdmFyIM+GaSA9IGluZmxlY3Rpb25bMV0gKiBkM19kZWdyZWVzOwogICAgICAgICAgaWYgKM+GaSA+IM+GMSkgz4YxID0gz4ZpOwogICAgICAgIH0gZWxzZSBpZiAozrtpID0gKM67aSArIDM2MCkgJSAzNjAgLSAxODAsIGFudGltZXJpZGlhbiBeIChzICogzrtfIDwgzrtpICYmIM67aSA8IHMgKiDOuykpIHsKICAgICAgICAgIHZhciDPhmkgPSAtaW5mbGVjdGlvblsxXSAqIGQzX2RlZ3JlZXM7CiAgICAgICAgICBpZiAoz4ZpIDwgz4YwKSDPhjAgPSDPhmk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICjPhiA8IM+GMCkgz4YwID0gz4Y7CiAgICAgICAgICBpZiAoz4YgPiDPhjEpIM+GMSA9IM+GOwogICAgICAgIH0KICAgICAgICBpZiAoYW50aW1lcmlkaWFuKSB7CiAgICAgICAgICBpZiAozrsgPCDOu18pIHsKICAgICAgICAgICAgaWYgKGFuZ2xlKM67MCwgzrspID4gYW5nbGUozrswLCDOuzEpKSDOuzEgPSDOuzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGlmIChhbmdsZSjOuywgzrsxKSA+IGFuZ2xlKM67MCwgzrsxKSkgzrswID0gzrs7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICjOuzEgPj0gzrswKSB7CiAgICAgICAgICAgIGlmICjOuyA8IM67MCkgzrswID0gzrs7CiAgICAgICAgICAgIGlmICjOuyA+IM67MSkgzrsxID0gzrs7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBpZiAozrsgPiDOu18pIHsKICAgICAgICAgICAgICBpZiAoYW5nbGUozrswLCDOuykgPiBhbmdsZSjOuzAsIM67MSkpIM67MSA9IM67OwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGlmIChhbmdsZSjOuywgzrsxKSA+IGFuZ2xlKM67MCwgzrsxKSkgzrswID0gzrs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgcG9pbnQozrssIM+GKTsKICAgICAgfQogICAgICBwMCA9IHAsIM67XyA9IM67OwogICAgfQogICAgZnVuY3Rpb24gbGluZVN0YXJ0KCkgewogICAgICBib3VuZC5wb2ludCA9IGxpbmVQb2ludDsKICAgIH0KICAgIGZ1bmN0aW9uIGxpbmVFbmQoKSB7CiAgICAgIHJhbmdlWzBdID0gzrswLCByYW5nZVsxXSA9IM67MTsKICAgICAgYm91bmQucG9pbnQgPSBwb2ludDsKICAgICAgcDAgPSBudWxsOwogICAgfQogICAgZnVuY3Rpb24gcmluZ1BvaW50KM67LCDPhikgewogICAgICBpZiAocDApIHsKICAgICAgICB2YXIgZM67ID0gzrsgLSDOu187CiAgICAgICAgZM67U3VtICs9IGFicyhkzrspID4gMTgwID8gZM67ICsgKGTOuyA+IDAgPyAzNjAgOiAtMzYwKSA6IGTOuzsKICAgICAgfSBlbHNlIM67X18gPSDOuywgz4ZfXyA9IM+GOwogICAgICBkM19nZW9fYXJlYS5wb2ludCjOuywgz4YpOwogICAgICBsaW5lUG9pbnQozrssIM+GKTsKICAgIH0KICAgIGZ1bmN0aW9uIHJpbmdTdGFydCgpIHsKICAgICAgZDNfZ2VvX2FyZWEubGluZVN0YXJ0KCk7CiAgICB9CiAgICBmdW5jdGlvbiByaW5nRW5kKCkgewogICAgICByaW5nUG9pbnQozrtfXywgz4ZfXyk7CiAgICAgIGQzX2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eTAsIHowOwogICAgZDNfZ2VvX2NlbnRyb2lkLnBvaW50ID0gZnVuY3Rpb24ozrssIM+GKSB7CiAgICAgIM67ICo9IGQzX3JhZGlhbnM7CiAgICAgIHZhciBjb3PPhiA9IE1hdGguY29zKM+GICo9IGQzX3JhZGlhbnMpOwogICAgICB4MCA9IGNvc8+GICogTWF0aC5jb3MozrspOwogICAgICB5MCA9IGNvc8+GICogTWF0aC5zaW4ozrspOwogICAgICB6MCA9IE1hdGguc2luKM+GKTsKICAgICAgZDNfZ2VvX2NlbnRyb2lkLnBvaW50ID0gbmV4dFBvaW50OwogICAgICBkM19nZW9fY2VudHJvaWRQb2ludFhZWih4MCwgeTAsIHowKTsKICAgIH07CiAgICBmdW5jdGlvbiBuZXh0UG9pbnQozrssIM+GKSB7CiAgICAgIM67ICo9IGQzX3JhZGlhbnM7CiAgICAgIHZhciBjb3PPhiA9IE1hdGguY29zKM+GICo9IGQzX3JhZGlhbnMpLCB4ID0gY29zz4YgKiBNYXRoLmNvcyjOuyksIHkgPSBjb3PPhiAqIE1hdGguc2luKM67KSwgeiA9IE1hdGguc2luKM+GKSwgdyA9IE1hdGguYXRhbjIoTWF0aC5zcXJ0KCh3ID0geTAgKiB6IC0gejAgKiB5KSAqIHcgKyAodyA9IHowICogeCAtIHgwICogeikgKiB3ICsgKHcgPSB4MCAqIHkgLSB5MCAqIHgpICogdyksIHgwICogeCArIHkwICogeSArIHowICogeik7CiAgICAgIGQzX2dlb19jZW50cm9pZFcxICs9IHc7CiAgICAgIGQzX2dlb19jZW50cm9pZFgxICs9IHcgKiAoeDAgKyAoeDAgPSB4KSk7CiAgICAgIGQzX2dlb19jZW50cm9pZFkxICs9IHcgKiAoeTAgKyAoeTAgPSB5KSk7CiAgICAgIGQzX2dlb19jZW50cm9pZFoxICs9IHcgKiAoejAgKyAoejAgPSB6KSk7CiAgICAgIGQzX2dlb19jZW50cm9pZFBvaW50WFlaKHgwLCB5MCwgejApOwogICAgfQogIH0KICBmdW5jd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A9IGN1cnJlbnQubjsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGlzU3ViamVjdCkgewogICAgICAgICAgICBwb2ludHMgPSBjdXJyZW50LnAuejsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IHBvaW50cy5sZW5ndGggLSAxOyBpID49IDA7IC0taSkgbGlzdGVuZXIucG9pbnQoKHBvaW50ID0gcG9pbnRzW2ldKVswXSwgcG9pbnRbMV0pOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaW50ZXJwb2xhdGUoY3VycmVudC54LCBjdXJyZW50LnAueCwgLTEsIGxpc3RlbmVyKTsKICAgICAgICAgIH0KICAgICAgICAgIGN1cnJlbnQgPSBjdXJyZW50LnA7CiAgICAgICAgfQogICAgICAgIGN1cnJlbnQgPSBjdXJyZW50Lm87CiAgICAgICAgcG9pbnRzID0gY3VycmVudC56OwogICAgICAgIGlzU3ViamVjdCA9ICFpc1N1YmplY3Q7CiAgICAgIH0gd2hpbGUgKCFjdXJyZW50LnYpOwogICAgICBsaXN0ZW5lci5saW5lRW5kKCk7CiAgICB9CiAgfQogIGZ1bmN0aW9uIGQzX2dlb19jbGlwUG9seWdvbkxpbmtDaXJjdWxhcihhcnJheSkgewogICAgaWYgKCEobiA9IGFycmF5Lmxlbmd0aCkpIHJldHVybjsKICAgIHZhciBuLCBpID0gMCwgYSA9IGFycmF5WzBdLCBiOwogICAgd2hpbGUgKCsraSA8IG4pIHsKICAgICAgYS5uID0gYiA9IGFycmF5W2ldOwogICAgICBiLnAgPSBhOwogICAgICBhID0gYjsKICAgIH0KICAgIGEubiA9IGIgPSBhcnJheVswXTsKICAgIGIucCA9IGE7CiAgfQogIGZ1bmN0aW9uIGQzX2dlb19jbGlwUG9seWdvbkludGVyc2VjdGlvbihwb2ludCwgcG9pbnRzLCBvdGhlciwgZW50cnkpIHsKICAgIHRoaXMueCA9IHBvaW50OwogICAgdGhpcy56ID0gcG9pbnRzOwogICAgdGhpcy5vID0gb3RoZ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cG9seWdvbik7CiAgICAgICAgICBpZiAoc2VnbWVudHMubGVuZ3RoKSB7CiAgICAgICAgICAgIGlmICghcG9seWdvblN0YXJ0ZWQpIGxpc3RlbmVyLnBvbHlnb25TdGFydCgpLCBwb2x5Z29uU3RhcnRlZCA9IHRydWU7CiAgICAgICAgICAgIGQzX2dlb19jbGlwUG9seWdvbihzZWdtZW50cywgZDNfZ2VvX2NsaXBTb3J0LCBjbGlwU3RhcnRJbnNpZGUsIGludGVycG9sYXRlLCBsaXN0ZW5lcik7CiAgICAgICAgICB9IGVsc2UgaWYgKGNsaXBTdGFydEluc2lkZSkgewogICAgICAgICAgICBpZiAoIXBvbHlnb25TdGFydGVkKSBsaXN0ZW5lci5wb2x5Z29uU3RhcnQoKSwgcG9seWdvblN0YXJ0ZWQgPSB0cnVlOwogICAgICAgICAgICBsaXN0ZW5lci5saW5lU3RhcnQoKTsKICAgICAgICAgICAgaW50ZXJwb2xhdGUobnVsbCwgbnVsbCwgMSwgbGlzdGVuZXIpOwogICAgICAgICAgICBsaXN0ZW5lci5saW5lRW5kKCk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocG9seWdvblN0YXJ0ZWQpIGxpc3RlbmVyLnBvbHlnb25FbmQoKSwgcG9seWdvblN0YXJ0ZWQgPSBmYWxzZTsKICAgICAgICAgIHNlZ21lbnRzID0gcG9seWdvbiA9IG51bGw7CiAgICAgICAgfSwKICAgICAgICBzcGhlcmU6IGZ1bmN0aW9uKCkgewogICAgICAgICAgbGlzdGVuZXIucG9seWdvblN0YXJ0KCk7CiAgICAgICAgICBsaXN0ZW5lci5saW5lU3RhcnQoKTsKICAgICAgICAgIGludGVycG9sYXRlKG51bGwsIG51bGwsIDEsIGxpc3RlbmVyKTsKICAgICAgICAgIGxpc3RlbmVyLmxpbmVFbmQoKTsKICAgICAgICAgIGxpc3RlbmVyLnBvbHlnb25FbmQoKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIHBvaW50KM67LCDPhikgewogICAgICAgIHZhciBwb2ludCA9IHJvdGF0ZSjOuywgz4YpOwogICAgICAgIGlmIChwb2ludFZpc2libGUozrsgPSBwb2ludFswXSwgz4YgPSBwb2ludFsxXSkpIGxpc3RlbmVyLnBvaW50KM67LCDPhik7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcG9pbnRMaW5lKM67LCDPhikgewogICAgICAgIHZhciBwb2ludCA9IHJvdGF0ZSjOuywgz4YpOwogICAgICAgIGxpbmUucG9pbnQocG9pbnRbMF0sIHBvaW50WzFdKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBsaW5lU3RhcnQoKSB7CiAgICAgICAgY2xpcC5wb2ludCA9IHBvaW50TGluZTsKICAgICAgICBsaW5lLmxpbmVTdGFydCgpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGxpbmVFbmQoKSB7CiAgICAgICAgY2xpcC5wb2ludCA9IHBvaW50OwogICAgICAgIGxpbmUubGluZUVuZCgpOwogICAgICB9CiAgICAgIHZhciBzZWdtZW50czsKICAgICAgdmFyIGJ1ZmZlciA9IGQzX2dlb19jbGlwQnVmZmVyTGlzdGVuZXIoKSwgcmluZ0xpc3RlbmVyID0gY2xpcExpbmUoYnVmZmVyKSwgcG9seWdvblN0YXJ0ZWQgPSBmYWxzZSwgcG9seWdvbiwgcmluZzsKICAgICAgZnVuY3Rpb24gcG9pbnRSaW5nKM67LCDPhikgewogICAgICAgIHJpbmcucHVzaChbIM67LCDPhiBdKTsKICAgICAgICB2YXIgcG9pbnQgPSByb3RhdGUozrssIM+GKTsKICAgICAgICByaW5nTGlzdGVuZXIucG9pbnQocG9pbnRbMF0sIHBvaW50WzFdKTsKICAgICAgfQogICAgICBmdW5jdGlvbiByaW5nU3RhcnQoKSB7CiAgICAgICAgcmluZ0xpc3RlbmVyLmxpbmVTdGFydCgpOwogICAgICAgIHJpbmcgPSBbXTsKICAgICAgfQogICAgICBmdW5jdGlvbiByaW5nRW5kKCkgewogICAgICAgIHBvaW50UmluZyhyaW5nWzBdWzBdLCByaW5nWzBdWzFdKTsKICAgICAgICByaW5nTGlzdGVuZXIubGluZUVuZCgpOwogICAgICAgIHZhciBjbGVhbiA9IHJpbmdMaXN0ZW5lci5jbGVhbigpLCByaW5nU2VnbWVudHMgPSBidWZmZXIuYnVmZmVyKCksIHNlZ21lbnQsIG4gPSByaW5nU2VnbWVudHMubGVuZ3RoOwogICAgICAgIHJpbmcucG9wKCk7CiAgICAgICAgcG9seWdvbi5wdXNoKHJpbmcpOwogICAgICAgIHJpbmcgPSBudWxsOwogICAgICAgIGlmICghbikgcmV0dXJuOwogICAgICAgIGlmIChjbGVhbiAmIDEpIHsKICAgICAgICAgIHNlZ21lbnQgPSByaW5nU2VnbWVudHNbMF07CiAgICAgICAgICB2YXIgbiA9IHNlZ21lbnQubGVuZ3RoIC0gMSwgaSA9IC0xLCBwb2ludDsKICAgICAgICAgIGlmIChuID4gMCkgewogICAgICAgICAgICBpZiAoIXBvbHlnb25TdGFydGVkKSBsaXN0ZW5lci5wb2x5Z29uU3RhcnQoKSwgcG9seWdvblN0YXJ0ZWQgPSB0cnVlOwogICAgICAgICAgICBsaXN0ZW5lci5saW5lU3RhcnQoKTsKICAgICAgICAgICAgd2hpbGUgKCsraSA8IG4pIGxpc3RlbmVyLnBvaW50KChwb2ludCA9IHNlZ21lbnRbaV0pWzBdLCBwb2ludFsxXSk7CiAgICAgICAgICAgIGxpc3RlbmVyLmxpbmVFbmQoKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgaWYgKG4gPiAxICYmIGNsZWFuICYgMikgcmluZ1NlZ21lbnRzLnB1c2gocmluZ1NlZ21lbnRzLnBvcCgpLmNvbmNhdChyaW5nU2VnbWVudHMuc2hpZnQoKSkpOwogICAgICAgIHNlZ21lbnRzLnB1c2gocmluZ1NlZ21lbnRzLmZpbHRlcihkM19nZW9fY2xpcFNlZ21lbnRMZW5ndGgxKSk7CiAgICAgIH0KICAgIC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BbnRpbWVyaWRpYW5MaW5lLCBkM19nZW9fY2xpcEFudGltZXJpZGlhbkludGVycG9sYXRlLCBbIC3PgCwgLc+AIC8gMiBdKTsKICBmdW5jdGlvbiBkM19nZW9fY2xpcEFudGltZXJpZGlhbkxpbmUobGlzdGVuZXIpIHsKICAgIHZhciDOuzAgPSBOYU4sIM+GMCA9IE5hTiwgc867MCA9IE5hTiwgY2xlYW47CiAgICByZXR1cm4gewogICAgICBsaW5lU3RhcnQ6IGZ1bmN0aW9uKCkgewogICAgICAgIGxpc3RlbmVyLmxpbmVTdGFydCgpOwogICAgICAgIGNsZWFuID0gMTsKICAgICAgfSwKICAgICAgcG9pbnQ6IGZ1bmN0aW9uKM67MSwgz4YxKSB7CiAgICAgICAgdmFyIHPOuzEgPSDOuzEgPiAwID8gz4AgOiAtz4AsIGTOuyA9IGFicyjOuzEgLSDOuzApOwogICAgICAgIGlmIChhYnMoZM67IC0gz4ApIDwgzrUpIHsKICAgICAgICAgIGxpc3RlbmVyLnBvaW50KM67MCwgz4YwID0gKM+GMCArIM+GMSkgLyAyID4gMCA/IGhhbGbPgCA6IC1oYWxmz4ApOwogICAgICAgICAgbGlzdGVuZXIucG9pbnQoc867MCwgz4YwKTsKICAgICAgICAgIGxpc3RlbmVyLmxpbmVFbmQoKTsKICAgICAgICAgIGxpc3RlbmVyLmxpbmVTdGFydCgpOwogICAgICAgICAgbGlzdGVuZXIucG9pbnQoc867MSwgz4YwKTsKICAgICAgICAgIGxpc3RlbmVyLnBvaW50KM67MSwgz4YwKTsKICAgICAgICAgIGNsZWFuID0gMDsKICAgICAgICB9IGVsc2UgaWYgKHPOuzAgIT09IHPOuzEgJiYgZM67ID49IM+AKSB7CiAgICAgICAgICBpZiAoYWJzKM67MCAtIHPOuzApIDwgzrUpIM67MCAtPSBzzrswICogzrU7CiAgICAgICAgICBpZiAoYWJzKM67MSAtIHPOuzEpIDwgzrUpIM67MSAtPSBzzrsxICogzrU7CiAgICAgICAgICDPhjAgPSBk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W50ZXJwb2xhdGUocmFkaXVzLCA2ICogZDNfcmFkaWFucyk7CiAgICByZXR1cm4gZDNfZ2VvX2NsaXAodmlzaWJsZSwgY2xpcExpbmUsIGludGVycG9sYXRlLCBzbWFsbFJhZGl1cyA/IFsgMCwgLXJhZGl1cyBdIDogWyAtz4AsIHJhZGl1cyAtIM+AIF0pOwogICAgZnVuY3Rpb24gdmlzaWJsZSjOuywgz4YpIHsKICAgICAgcmV0dXJuIE1hdGguY29zKM67KSAqIE1hdGguY29zKM+GKSA+IGNyOwogICAgfQogICAgZnVuY3Rpb24gY2xpcExpbmUobGlzdGVuZXIpIHsKICAgICAgdmFyIHBvaW50MCwgYzAsIHYwLCB2MDAsIGNsZWFuOwogICAgICByZXR1cm4gewogICAgICAgIGxpbmVTdGFydDogZnVuY3Rpb24oKSB7CiAgICAgICAgICB2MDAgPSB2MCA9IGZhbHNlOwogICAgICAgICAgY2xlYW4gPSAxOwogICAgICAgIH0sCiAgICAgICAgcG9pbnQ6IGZ1bmN0aW9uKM67LCDPhikgewogICAgICAgICAgdmFyIHBvaW50MSA9IFsgzrssIM+GIF0sIHBvaW50MiwgdiA9IHZpc2libGUozrssIM+GKSwgYyA9IHNtYWxsUmFkaXVzID8gdiA/IDAgOiBjb2RlKM67LCDPhikgOiB2ID8gY29kZSjOuyArICjOuyA8IDAgPyDPgCA6IC3PgCksIM+GKSA6IDA7CiAgICAgICAgICBpZiAoIXBvaW50MCAmJiAodjAwID0gdjAgPSB2KSkgbGlzdGVuZXIubGluZVN0YXJ0KCk7CiAgICAgICAgICBpZiAodiAhPT0gdjApIHsKICAgICAgICAgICAgcG9pbnQyID0gaW50ZXJzZWN0KHBvaW50MCwgcG9pbnQxKTsKICAgICAgICAgICAgaWYgKGQzX2dlb19zcGhlcmljYWxFcXVhbChwb2ludDAsIHBvaW50MikgfHwgZDNfZ2VvX3NwaGVyaWNhbEVxdWFsKHBvaW50MSwgcG9pbnQyKSkgewogICAgICAgICAgICAgIHBvaW50MVswXSArPSDOtTsKICAgICAgICAgICAgICBwb2ludDFbMV0gKz0gzrU7CiAgICAgICAgICAgICAgdiA9IHZpc2libGUocG9pbnQxWzBdLCBwb2ludDFbMV0pOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodiAhPT0gdjApIHsKICAgICAgICAgICAgY2xlYW4gPSAwOwogICAgICAgICAgICBpZiAodikgewogICAgICAgICAgICAgIGxpc3RlbmVyLmxpbmVTdGFydCgpOwogICAgICAgICAgICAgIHBvaW50MiA9IGludGVyc2VjdChwb2ludDEsIHBvaW50MCk7CiAgICAgICAgICAgICAgbGlzdGVuZXIucG9pbnQocG9pbnQyWzBdLCBwb2ludDJbMV0pOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBvaW50MiA9IGludGVyc2VjdChwb2ludDAsIHBvaW50MSk7CiAgICAgICAgICAgICAgbGlzdGVuZXIucG9pbnQocG9pbnQyWzBdLCBwb2ludDJbMV0pOwogICAgICAgICAgICAgIGxpc3RlbmVyLmxpbmVFbmQoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBwb2ludDAgPSBwb2ludDI7CiAgICAgICAgICB9IGVsc2UgaWYgKG5vdEhlbWlzcGhlcmUgJiYgcG9pbnQwICYmIHNtYWxsUmFkaXVzIF4gdikgewogICAgICAgICAgICB2YXIgdDsKICAgICAgICAgICAgaWYgKCEoYyAmIGMwKSAmJiAodCA9IGludGVyc2VjdChwb2ludDEsIHBvaW50MCwgdHJ1ZSkpKSB7CiAgICAgICAgICAgICAgY2xlYW4gPSAwOwogICAgICAgICAgICAgIGlmIChzbWFsbFJhZGl1cykgewogICAgICAgICAgICAgICAgbGlzdGVuZXIubGluZVN0YXJ0KCk7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5wb2ludCh0WzBdWzBdLCB0WzBdWzFdKTsKICAgICAgICAgICAgICAgIGxpc3RlbmVyLnBvaW50KHRbMV1bMF0sIHRbMV1bMV0pOwogICAgICAgICAgICAgICAgbGlzdGVuZXIubGluZUVuZCgpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5wb2ludCh0WzFdWzBdLCB0WzFdWzFdKTsKICAgICAgICAgICAgICAgIGxpc3RlbmVyLmxpbmVFbmQoKTsKICAgICAgICAgICAgICAgIGxpc3RlbmVyLmxpbmVTdGFydCgpOwogICAgICAgICAgICAgICAgbGlzdGVuZXIucG9pbnQodFswXVswXSwgdFswXVsxXSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodiAmJiAoIXBvaW50MCB8fCAhZDNfZ2VvX3NwaGVyaWNhbEVxdWFsKHBvaW50MCwgcG9pbnQxKSkpIHsKICAgICAgICAgICAgbGlzdGVuZXIucG9pbnQocG9pbnQxWzBdLCBwb2ludDFbMV0pOwogICAgICAgICAgfQogICAgICAgICAgcG9pbnQwID0gcG9pbnQxLCB2MCA9IHYsIGMwID0gYzsKICAgICAgICB9LAogICAgICAgIGxpbmVFbmQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgaWYgKHYwKSBsaXN0ZW5lci5saW5lRW5kKCk7CiAgICAgICAgICBwb2ludDAgPSBudWxsOwogICAgICAgIH0sCiAgICAgICAgY2xlYW46IGZ1bmN0aW9uKCkgewogICAgICAgICAgcmV0dXJuIGNsZWFuIHwgKHYwMCAmJiB2MCkgPDwgMTsKICAgICAgICB9CiAgICAgIH07CiAgICB9CiAgICBmdW5jdGlvbiBpbnRlcnNlY3QoYSwgYiwgdHdvKSB7CiAgICAgIHZhciBwYSA9IGQzX2dlb19jYXJ0ZXNpYW4oYSksIHBiID0gZDNfZ2VvX2NhcnRlc2lhbihiKTsKICAgICAgdmFyIG4xID0gWyAxLCAwLCAwIF0sIG4yID0gZDNfZ2VvX2NhcnRlc2lhbkNyb3NzKHBhLCBwYiksIG4ybjIgPSBkM19nZW9fY2FydGVzaWFuRG90KG4yLCBuMiksIG4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ICAgICBpZiAoIWR4ICYmIHIgPiAwKSByZXR1cm47CiAgICAgIHIgLz0gZHg7CiAgICAgIGlmIChkeCA8IDApIHsKICAgICAgICBpZiAociA8IHQwKSByZXR1cm47CiAgICAgICAgaWYgKHIgPCB0MSkgdDEgPSByOwogICAgICB9IGVsc2UgaWYgKGR4ID4gMCkgewogICAgICAgIGlmIChyID4gdDEpIHJldHVybjsKICAgICAgICBpZiAociA+IHQwKSB0MCA9IHI7CiAgICAgIH0KICAgICAgciA9IHgxIC0gYXg7CiAgICAgIGlmICghZHggJiYgciA8IDApIHJldHVybjsKICAgICAgciAvPSBkeDsKICAgICAgaWYgKGR4IDwgMCkgewogICAgICAgIGlmIChyID4gdDEpIHJldHVybjsKICAgICAgICBpZiAociA+IHQwKSB0MCA9IHI7CiAgICAgIH0gZWxzZSBpZiAoZHggPiAwKSB7CiAgICAgICAgaWYgKHIgPCB0MCkgcmV0dXJuOwogICAgICAgIGlmIChyIDwgdDEpIHQxID0gcjsKICAgICAgfQogICAgICByID0geTAgLSBheTsKICAgICAgaWYgKCFkeSAmJiByID4gMCkgcmV0dXJuOwogICAgICByIC89IGR5OwogICAgICBpZiAoZHkgPCAwKSB7CiAgICAgICAgaWYgKHIgPCB0MCkgcmV0dXJuOwogICAgICAgIGlmIChyIDwgdDEpIHQxID0gcjsKICAgICAgfSBlbHNlIGlmIChkeSA+IDApIHsKICAgICAgICBpZiAociA+IHQxKSByZXR1cm47CiAgICAgICAgaWYgKHIgPiB0MCkgdDAgPSByOwogICAgICB9CiAgICAgIHIgPSB5MSAtIGF5OwogICAgICBpZiAoIWR5ICYmIHIgPCAwKSByZXR1cm47CiAgICAgIHIgLz0gZHk7CiAgICAgIGlmIChkeSA8IDApIHsKICAgICAgICBpZiAociA+IHQxKSByZXR1cm47CiAgICAgICAgaWYgKHIgPiB0MCkgdDAgPSByOwogICAgICB9IGVsc2UgaWYgKGR5ID4gMCkgewogICAgICAgIGlmIChyIDwgdDApIHJldHVybjsKICAgICAgICBpZiAociA8IHQxKSB0MSA9IHI7CiAgICAgIH0KICAgICAgaWYgKHQwID4gMCkgbGluZS5hID0gewogICAgICAgIHg6IGF4ICsgdDAgKiBkeCwKICAgICAgICB5OiBheSArIHQwICogZHkKICAgICAgfTsKICAgICAgaWYgKHQxIDwgMSkgbGluZS5iID0gewogICAgICAgIHg6IGF4ICsgdDEgKiBkeCwKICAgICAgICB5OiBheSArIHQxICogZHkKICAgICAgfTsKICAgICAgcmV0dXJuIGxpbmU7CiAgICB9OwogIH0KICB2YXIgZDNfZ2VvX2NsaXBFeHRlbnRNQVggPSAxZTk7CiAgZDMuZ2VvLmNsaXBFeHRlbnQgPSBmdW5jdGlvbigpIHsKICAgIHZhciB4MCwgeTAsIHgxLCB5MSwgc3RyZWFtLCBjbGlwLCBjbGlwRXh0ZW50ID0gewogICAgICBzdHJlYW06IGZ1bmN0aW9uKG91dHB1dCkgewogICAgICAgIGlmIChzdHJlYW0pIHN0cmVhbS52YWxpZCA9IGZhbHNlOwogICAgICAgIHN0cmVhbSA9IGNsaXAob3V0cHV0KTsKICAgICAgICBzdHJlYW0udmFsaWQgPSB0cnVlOwogICAgICAgIHJldHVybiBzdHJlYW07CiAgICAgIH0sCiAgICAgIGV4dGVudDogZnVuY3Rpb24oXykgewogICAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIFsgWyB4MCwgeTAgXSwgWyB4MSwgeTEgXSBdOwogICAgICAgIGNsaXAgPSBkM19nZW9fY2xpcEV4dGVudCh4MCA9ICtfWzBdWzBdLCB5MCA9ICtfWzBdWzFdLCB4MSA9ICtfWzFdWzBdLCB5MSA9ICtfWzFdWzFdKTsKICAgICAgICBpZiAoc3RyZWFtKSBzdHJlYW0udmFsaWQgPSBmYWxzZSwgc3RyZWFtID0gbnVsbDsKICAgICAgICByZXR1cm4gY2xpcEV4dGVudDsKICAgICAgfQogICAgfTsKICAgIHJldHVybiBjbGlwRXh0ZW50LmV4dGVudChbIFsgMCwgMC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ICAgICAgICAgICAgbGlzdGVuZXIubGluZVN0YXJ0KCk7CiAgICAgICAgICAgICAgaW50ZXJwb2xhdGUobnVsbCwgbnVsbCwgMSwgbGlzdGVuZXIpOwogICAgICAgICAgICAgIGxpc3RlbmVyLmxpbmVFbmQoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmlzaWJsZSkgewogICAgICAgICAgICAgIGQzX2dlb19jbGlwUG9seWdvbihzZWdtZW50cywgY29tcGFyZSwgY2xpcFN0YXJ0SW5zaWRlLCBpbnRlcnBvbGF0ZSwgbGlzdGVuZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxpc3RlbmVyLnBvbHlnb25FbmQoKTsKICAgICAgICAgIH0KICAgICAgICAgIHNlZ21lbnRzID0gcG9seWdvbiA9IHJpbmcgPSBudWxsOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZnVuY3Rpb24gaW5zaWRlUG9seWdvbihwKSB7CiAgICAgICAgdmFyIHduID0gMCwgbiA9IHBvbHlnb24ubGVuZ3RoLCB5ID0gcFsxXTsKICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgICAgZm9yICh2YXIgaiA9IDEsIHYgPSBwb2x5Z29uW2ldLCBtID0gdi5sZW5ndGgsIGEgPSB2WzBdLCBiOyBqIDwgbTsgKytqKSB7CiAgICAgICAgICAgIGIgPSB2W2pdOwogICAgICAgICAgICBpZiAoYVsxXSA8PSB5KSB7CiAgICAgICAgICAgICAgaWYgKGJbMV0gPiB5ICYmIGQzX2Nyb3NzMmQoYSwgYiwgcCkgPiAwKSArK3duOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGlmIChiWzFdIDw9IHkgJiYgZDNfY3Jvc3MyZChhLCBiLCBwKSA8IDApIC0td247CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYSA9IGI7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB3biAhPT0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbnRlcnBvbGF0ZShmcm9tLCB0bywgZGlyZWN0aW9uLCBsaXN0ZW5lcikgewogICAgICAgIHZhciBhID0gMCwgYTEgPSAwOwogICAgICAgIGlmIChmcm9tID09IG51bGwgfHwgKGEgPSBjb3JuZXIoZnJvbSwgZGlyZWN0aW9uKSkgIT09IChhMSA9IGNvcm5lcih0bywgZGlyZWN0aW9uKSkgfHwgY29tcGFyZVBvaW50cyhmcm9tLCB0bykgPCAwIF4gZGlyZWN0aW9uID4gMCkgewogICAgICAgICAgZG8gewogICAgICAgICAgICBsaXN0ZW5lci5wb2ludChhID09PSAwIHx8IGEgPT09IDMgPyB4MCA6IHgxLCBhID4gMSA/IHkxIDogeTApOwogICAgICAgICAgfSB3aGlsZSAoKGEgPSAoYSArIGRpcmVjdGlvbiArIDQpICUgNCkgIT09IGExKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbGlzdGVuZXIucG9pbnQodG9bMF0sIHRvWzFdKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcG9pbnRWaXNpYmxlKHgsIHkpIHsKICAgICAgICByZXR1cm4geDAgPD0geCAmJiB4IDw9IHgxICYmIHkwIDw9IHkgJiYgeSA8PSB5MTsKICAgICAgfQogICAgICBmdW5jdGlvbiBwb2ludCh4LCB5KSB7CiAgICAgICAgaWYgKHBvaW50VmlzaWJsZSh4LCB5KSkgbGlzdGVuZXIucG9pbnQoeCwgeSk7CiAgICAgIH0KICAgICAgdmFyIHhfXywgeV9fLCB2X18sIHhfLCB5Xywgdl8sIGZpcnN0LCBjbGVhbjsKICAgICAgZnVuY3Rpb24gbGluZVN0YXJ0KCkgewogICAgICAgIGNsaXAucG9pbnQgPSBsaW5lUG9pbnQ7CiAgICAgICAgaWYgKHBvbHlnb24pIHBvbHlnb24ucHVzaChyaW5nID0gW10pOwogICAgICAgIGZpcnN0ID0gdHJ1ZTsKICAgICAgICB2XyA9IGZhbHNlOwogICAgICAgIHhfID0geV8gPSBOYU47CiAgICAgIH0KICAgICAgZnVuY3Rpb24gbGluZUVuZCgpIHsKICAgICAgICBpZiAoc2VnbWVudHMpIHsKICAgICAgICAgIGxpbmVQb2ludCh4X18sIHlfXyk7CiAgICAgICAgICBpZiAodl9fICYmIHZfKSBidWZmZXJMaXN0ZW5lci5yZWpvaW4oKTsKICAgICAgICAgIHNlZ21lbnRzLnB1c2goYnVmZmVyTGlzdGVuZXIuYnVmZmVyKCkpOwogICAgICAgIH0KICAgICAgICBjbGlwLnBvaW50ID0gcG9pbnQ7CiAgICAgICAgaWYgKHZfKSBsaXN0ZW5lci5saW5lRW5kKCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gbGluZVBvaW50KHgsIHkpIHsKICAgICAgICB4ID0gTWF0aC5tYXgoLWQzX2dlb19jbGlwRXh0ZW50TUFYLCBNYXRoLm1pbihkM19nZW9fY2xpcEV4dGVudE1BWCwgeCkpOwogICAgICAgIHkgPSBNYXRoLm1heCgtZDNfZ2VvX2NsaXBFeHRlbnRNQVgsIE1hdGgubWluKGQzX2dlb19jbGlwRXh0ZW50TUFYLCB5KSk7CiAgICAgICAgdmFyIHYgPSBwb2ludFZpc2libGUoeCwgeSk7CiAgICAgICAgaWYgKHBvbHlnb24pIHJpbmcucHVzaChbIHgsIHkgXSk7CiAgICAgICAgaWYgKGZpcnN0KSB7CiAgICAgICAgICB4X18gPSB4LCB5X18gPSB5LCB2X18gPSB2OwogICAgICAgICAgZmlyc3QgPSBmYWxzZTsKICAgICAgICAgIGlmICh2KSB7CiAgICAgICAgICAgIGxpc3RlbmVyLmxpbmVTdGFydCgpOwogICAgICAgICAgICBsaXN0ZW5lci5wb2ludCh4LCB5KTsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHYgJiYgdl8pIGxpc3RlbmVyLnBvaW50KHgsIHkpOyBlbHNlIHsKICAgICAgICAgICAgdmFyIGwgPSB7CiAgICAgICAgICAgICAgYTogewogICAgICAgICAgICAgICAgeDogeF8sCiAgICAgICAgICAgICAgICB5OiB5XwogICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgYjogewogICAgICAgICAgICAgICAgeDogeCwKICAgICAgICAgICAgICAgIHk6IHkKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGlmIChjbGlwTGluZShsKSkgewogICAgICAgICAgICAgIGlmICghdl8pIHsKICAgICAgICAgICAgICAgIGxpc3RlbmVyLmxpbmVTdGFydCgpOwogICAgICAgICAgICAgICAgbGlzdGVuZXIucG9pbnQobC5hLngsIGwuYS55KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgbGlzdGVuZXIucG9pbnQobC5iLngsIGwuYi55KTsKICAgICAgICAgICAgICBpZiAoIXYpIGxpc3RlbmVyLmxpbmVFbmQoKTsKICAgICAgICAgICAgICBjbGVhbiA9IGZhbHNlOwogICAgICAgICAgICB9IGVsc2UgaWYgKHYpIHsKICAgICAgICAgICAgICBsaXN0ZW5lci5saW5lU3RhcnQoKTsKICAgICAgICAgICAgICBsaXN0ZW5lci5wb2ludCh4LCB5KTsKICAgICAgICAgICAgICBjbGVhbiA9IGZhbHNlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHhfID0geCwgeV8gPSB5LCB2XyA9IHY7CiAgICAgIH0KICAgICAgcmV0dXJuIGNsaXA7CiAgICB9OwogICAgZnVuY3Rpb24gY29ybmVyKHAsIGRpcmVjdGlvbikgewogICAgICByZXR1cm4gYWJzKHBbMF0gLSB4MCkgPCDOtSA/IGRpcmVjdGlvbiA+IDAgPyAwIDogMyA6IGFicyhwWzBdIC0geDEpIDwgzrUgPyBkaXJlY3Rpb24gPiAwID8gMiA6IDEgOiBhYnMocFsxXSAtIHkwKSA8IM61ID8gZGlyZWN0aW9uID4gMCA/IDEgOiAwIDogZGlyZWN0aW9uID4gMCA/IDMgOiAyOwogICAgfQogICAgZnVuY3Rpb24gY29tc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AgICAgICAgcG9pbnQ6IHBvaW50LAogICAgICAgIGxpbmVTdGFydDogbGluZVN0YXJ0LAogICAgICAgIGxpbmVFbmQ6IGxpbmVFbmQsCiAgICAgICAgcG9seWdvblN0YXJ0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIHN0cmVhbS5wb2x5Z29uU3RhcnQoKTsKICAgICAgICAgIHJlc2FtcGxlLmxpbmVTdGFydCA9IHJpbmdTdGFydDsKICAgICAgICB9LAogICAgICAgIHBvbHlnb25FbmQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgc3RyZWFtLnBvbHlnb25FbmQoKTsKICAgICAgICAgIHJlc2FtcGxlLmxpbmVTdGFydCA9IGxpbmVTdGFydDsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIHBvaW50KHgsIHkpIHsKICAgICAgICB4ID0gcHJvamVjdCh4LCB5KTsKICAgICAgICBzdHJlYW0ucG9pbnQoeFswXSwgeFsxXSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gbGluZVN0YXJ0KCkgewogICAgICAgIHgwID0gTmFOOwogICAgICAgIHJlc2FtcGxlLnBvaW50ID0gbGluZVBvaW50OwogICAgICAgIHN0cmVhbS5saW5lU3RhcnQoKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBsaW5lUG9pbnQozrssIM+GKSB7CiAgICAgICAgdmFyIGMgPSBkM19nZW9fY2FydGVzaWFuKFsgzrssIM+GIF0pLCBwID0gcHJvamVjdCjOuywgz4YpOwogICAgICAgIHJlc2FtcGxlTGluZVRvKHgwLCB5MCwgzrswLCBhMCwgYjAsIGMwLCB4MCA9IHBbMF0sIHkwID0gcFsxXSwgzrswID0gzrssIGEwID0gY1swXSwgYjAgPSBjWzFdLCBjMCA9IGNbMl0sIG1heERlcHRoLCBzdHJlYW0pOwogICAgICAgIHN0cmVhbS5wb2ludCh4MCwgeTApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGxpbmVFbmQoKSB7CiAgICAgICAgc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bi5jZW50ZXIgPSBmdW5jdGlvbihfKSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIFsgzrsgKiBkM19kZWdyZWVzLCDPhiAqIGQzX2RlZ3JlZXMgXTsKICAgICAgzrsgPSBfWzBdICUgMzYwICogZDNfcmFkaWFuczsKICAgICAgz4YgPSBfWzFdICUgMzYwICogZDNfcmFkaWFuczsKICAgICAgcmV0dXJuIHJlc2V0KCk7CiAgICB9OwogICAgcHJvamVjdGlvbi5yb3RhdGUgPSBmdW5jdGlvbihfKSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIFsgzrTOuyAqIGQzX2RlZ3JlZXMsIM60z4YgKiBkM19kZWdyZWVzLCDOtM6zICogZDNfZGVncmVlcyBdOwogICAgICDOtM67ID0gX1swXSAlIDM2MCAqIGQzX3JhZGlhbnM7CiAgICAgIM60z4YgPSBfWzFdICUgMzYwICogZDNfcmFkaWFuczsKICAgICAgzrTOsyA9IF8ubGVuZ3RoID4gMiA/IF9bMl0gJSAzNjAgKiBkM19yYWRpYW5zIDogMDsKICAgICAgcmV0dXJuIHJlc2V0KCk7CiAgICB9OwogICAgZDMucmViaW5kKHByb2plY3Rpb24sIHByb2plY3RSZXNhbXBsZSwgInByZWNpc2lvbiIpOwogICAgZnVuY3Rpb24gcmVzZXQoKSB7CiAgICAgIHByb2plY3RSb3RhdGUgPSBkM19nZW9fY29tcG9zZShyb3RhdGUgPSBkM19nZW9fcm90YXRpb24ozrTOuywgzrTPhiwgzrTOsyksIHByb2plY3QpOwogICAgICB2YXIgY2VudGVyID0gcHJvamVjdCjOuywgz4YpOwogICAgICDOtHggPSB4IC0gY2VudGVyWzBdICogazsKICAgICAgzrR5ID0geSArIGNlbnRlclsxXSAqIGs7CiAgICAgIHJldHVybiBpbnZhbGlkYXRlKCk7CiAgICB9CiAgICBmdW5jdGlvbiBpbnZhbGlkYXRlKCkgewogICAgICBpZiAoc3RyZWFtKSBz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4dGVudFsxXVsxXSwgbFNpdGUgPSBlZGdlLmwsIHJTaXRlID0gZWRnZS5yLCBseCA9IGxTaXRlLngsIGx5ID0gbFNpdGUueSwgcnggPSByU2l0ZS54LCByeSA9IHJTaXRlLnksIGZ4ID0gKGx4ICsgcngpIC8gMiwgZnkgPSAobHkgKyByeSkgLyAyLCBmbSwgZmI7CiAgICBpZiAocnkgPT09IGx5KSB7CiAgICAgIGlmIChmeCA8IHgwIHx8IGZ4ID49IHgxKSByZXR1cm47CiAgICAgIGlmIChseCA+IHJ4KSB7CiAgICAgICAgaWYgKCF2YSkgdmEgPSB7CiAgICAgICAgICB4OiBmeCwKICAgICAgICAgIHk6IHkwCiAgICAgICAgfTsgZWxzZSBpZiAodmEueSA+PSB5MSkgcmV0dXJuOwogICAgICAgIHZiID0gewogICAgICAgICAgeDogZngsCiAgICAgICAgICB5OiB5MQogICAgICAgIH07CiAgICAgIH0gZWxzZSB7CiAgICAgICAgaWYgKCF2YSkgdmEgPSB7CiAgICAgICAgICB4OiBmeCwKICAgICAgICAgIHk6IHkxCiAgICAgICAgfTsgZWxzZSBpZiAodmEueSA8IHkwKSByZXR1cm47CiAgICAgICAgdmIgPSB7CiAgICAgICAgICB4OiBmeCwKICAgICAgICAgIHk6IHkwCiAgICAgICAgfTsKICAgICAgfQogICAgfSBlbHNlIHsKICAgICAgZm0gPSAobHggLSByeCkgLyAocnkgLSBseSk7CiAgICAgIGZiID0gZnkgLSBmbSAqIGZ4OwogICAgICBpZiAoZm0gPCAtMSB8fCBmbSA+IDEpIHsKICAgICAgICBpZiAobHggPiByeCkgewogICAgICAgICAgaWYgKCF2YSkgdmEgPSB7CiAgICAgICAgICAgIHg6ICh5MCAtIGZiKSAvIGZtLAogICAgICAgICAgICB5OiB5MAogICAgICAgICAgfTsgZWxzZSBpZiAodmEueSA+PSB5MSkgcmV0dXJuOwogICAgICAgICAgdmIgPSB7CiAgICAgICAgICAgIHg6ICh5MSAtIGZiKSAvIGZtLAogICAgICAgICAgICB5OiB5MQogICAgICAgICAgfTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKCF2YSkgdmEgPSB7CiAgICAgICAgICAgIHg6ICh5MSAtIGZiKSAvIGZtLAogICAgICAgICAgICB5OiB5MQogICAgICAgICAgfTsgZWxzZSBpZiAodmEueSA8IHkwKSByZXR1cm47CiAgICAgICAgICB2YiA9IHsKICAgICAgICAgICAgeDogKHkwIC0gZmIpIC8gZm0sCiAgICAgICAgICAgIHk6IHkwCiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgfSBlbHNlIHsKICAgICAgICBpZiAobHkgPCByeSkgewogICAgICAgICAgaWYgKCF2YSkgdmEgPSB7CiAgICAgICAgICAgIHg6IHgwLAogICAgICAgICAgICB5OiBmbSAqIHgwICsgZmIKICAgICAgICAgIH07IGVsc2UgaWYgKHZhLnggPj0geDEpIHJldHVybjsKICAgICAgICAgIHZiID0gewogICAgICAgICAgICB4OiB4MSwKICAgICAgICAgICAgeTogZm0gKiB4MSArIGZiCiAgICAgICAgICB9OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIXZhKSB2YSA9IHsKICAgICAgICAgICAgeDogeDEsCiAgICAgICAgICAgIHk6IGZtICogeDEgKyBmYgogICAgICAgICAgfTsgZWxzZSBpZiAodmEueCA8IHgwKSByZXR1cm47CiAgICAgICAgICB2YiA9IHsKICAgICAgICAgICAgeDogeDAsCiAgICAgICAgICAgIHk6IGZtICogeDAgKyBmYgogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIGVkZ2UuYSA9IHZhOwogICAgZWRnZS5iID0gdmI7CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZnVuY3Rpb24gZDNfZ2VvbV92b3Jvbm9pRWRnZShsU2l0ZSwgclNpdGUpIHsKICAgIHRoaXMubCA9IGxTaXRlOwogICAgdGhpcy5yID0gclNpdGU7CiAgICB0aGlzLmEgPSB0aGlzLmIgPSBudWxsOwogIH0KICB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S5MID0gbm9kZS5SID0gbnVsbDsKICAgICAgbm9kZS5VID0gcGFyZW50OwogICAgICBub2RlLkMgPSB0cnVlOwogICAgICBhZnRlciA9IG5vZGU7CiAgICAgIHdoaWxlIChwYXJlbnQgJiYgcGFyZW50LkMpIHsKICAgICAgICBncmFuZHBhID0gcGFyZW50LlU7CiAgICAgICAgaWYgKHBhcmVudCA9PT0gZ3JhbmRwYS5MKSB7CiAgICAgICAgICB1bmNsZSA9IGdyYW5kcGEuUjsKICAgICAgICAgIGlmICh1bmNsZSAmJiB1bmNsZS5DKSB7CiAgICAgICAgICAgIHBhcmVudC5DID0gdW5jbGUuQyA9IGZhbHNlOwogICAgICAgICAgICBncmFuZHBhLkMgPSB0cnVlOwogICAgICAgICAgICBhZnRlciA9IGdyYW5kcGE7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBpZiAoYWZ0ZXIgPT09IHBhcmVudC5SKSB7CiAgICAgICAgICAgICAgZDNfZ2VvbV92b3Jvbm9pUmVkQmxhY2tSb3RhdGVMZWZ0KHRoaXMsIHBhcmVudCk7CiAgICAgICAgICAgICAgYWZ0ZXIgPSBwYXJlbnQ7CiAgICAgICAgICAgICAgcGFyZW50ID0gYWZ0ZXIuVTsKICAgICAgICAgICAgfQogICAgICAgICAgICBwYXJlbnQuQyA9IGZhbHNlOwogICAgICAgICAgICBncmFuZHBhLkMgPSB0cnVlOwogICAgICAgICAgICBkM19nZW9tX3Zvcm9ub2lSZWRCbGFja1JvdGF0ZVJpZ2h0KHRoaXMsIGdyYW5kcGEpOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB1bmNsZSA9IGdyYW5kcGEuTDsKICAgICAgICAgIGlmICh1bmNsZSAmJiB1bmNsZS5DKSB7CiAgICAgICAgICAgIHBhcmVudC5DID0gdW5jbGUuQyA9IGZhbHNlOwogICAgICAgICAgICBncmFuZHBhLkMgPSB0cnVlOwogICAgICAgICAgICBhZnRlciA9IGdyYW5kcGE7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MuXyA9IG5leHQ7CiAgICAgIH0KICAgICAgaWYgKGxlZnQgJiYgcmlnaHQpIHsKICAgICAgICByZWQgPSBuZXh0LkM7CiAgICAgICAgbmV4dC5DID0gbm9kZS5DOwogICAgICAgIG5leHQuTCA9IGxlZnQ7CiAgICAgICAgbGVmdC5VID0gbmV4dDsKICAgICAgICBpZiAobmV4dCAhPT0gcmlnaHQpIHsKICAgICAgICAgIHBhcmVudCA9IG5leHQuVTsKICAgICAgICAgIG5leHQuVSA9IG5vZGUuVTsKICAgICAgICAgIG5vZGUgPSBuZXh0LlI7CiAgICAgICAgICBwYXJlbnQuTCA9IG5vZGU7CiAgICAgICAgICBuZXh0LlIgPSByaWdodDsKICAgICAgICAgIHJpZ2h0LlUgPSBuZXh0OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBuZXh0LlUgPSBwYXJlbnQ7CiAgICAgICAgICBwYXJlbnQgPSBuZXh0OwogICAgICAgICAgbm9kZSA9IG5leHQuUjsKICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgcmVkID0gbm9kZS5DOwogICAgICAgIG5vZGUgPSBuZXh0OwogICAgICB9CiAgICAgIGlmIChub2RlKSBub2RlLlUgPSBwYXJlbnQ7CiAgICAgIGlmIChyZWQpIHJldHVybjsKICAgICAgaWYgKG5vZGUgJiYgbm9kZS5DKSB7CiAgICAgICAgbm9kZS5DID0gZmFsc2U7CiAgICAgICAgcmV0dXJuOwogICAgICB9CiAgICAgIGRvIHsKICAgICAgICBpZiAobm9kZSA9PT0gdGhpcy5fKSBicmVhazsKICAgICAgICBpZiAobm9kZSA9PT0gcGFyZW50LkwpIHsKICAgICAgICAgIHNpYmxpbmcgPSBwYXJlbnQuUjsKICAgICAgICAgIGlmIChzaWJsaW5nLkMpIHsKICAgICAgICAgICAgc2libGluZy5DID0gZmFsc2U7CiAgICAgICAgICAgIHBhcmVudC5DID0gdHJ1ZTsKICAgICAgICAgICAgZDNfZ2VvbV92b3Jvbm9pUmVkQmxhY2tSb3RhdGVMZWZ0KHRoaXMsIHBhcmVudCk7CiAgICAgICAgICAgIHNpYmxpbmcgPSBwYXJlbnQuUjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzaWJsaW5nLkwgJiYgc2libGluZy5MLkMgfHwgc2libGluZy5SICYmIHNpYmxpbmcuUi5DKSB7CiAgICAgICAgICAgIGlmICghc2libGluZy5SIHx8ICFzaWJsaW5nLlIuQykgewogICAgICAgICAgICAgIHNpYmxpbmcuTC5DID0gZmFsc2U7CiAgICAgICAgICAgICAgc2libGluZy5DID0gdHJ1ZTsKICAgICAgICAgICAgICBkM19nZW9tX3Zvcm9ub2lSZWRCbGFja1JvdGF0ZVJpZ2h0KHRoaXMsIHNpYmxpbmcpOwogICAgICAgICAgICAgIHNpYmxpbmcgPSBwYXJlbnQuUjsKICAgICAgICAgICAgfQogICAgICAgICAgICBzaWJsaW5nLkMgPSBwYXJlbnQuQzsKICAgICAgICAgICAgcGFyZW50LkMgPSBzaWJsaW5nLlIuQyA9IGZhbHNlOwogICAgICAgICAgICBkM19nZW9tX3Zvcm9ub2lSZWRCbGFja1JvdGF0ZUxlZnQodGhpcywgcGFyZW50KTsKICAgICAgICAgICAgbm9kZSA9IHRoaXMuXzsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHNpYmxpbmcgPSBwYXJlbnQuTDsKICAgICAgICAgIGlmIChzaWJsaW5nLkMpIHsKICAgICAgICAgICAgc2libGluZy5DID0gZmFsc2U7CiAgICAgICAgICAgIHBhcmVudC5DID0gdHJ1ZTsKICAgICAgICAgICAgZDNfZ2VvbV92b3Jvbm9pUmVkQmxhY2tSb3RhdGVSaWdodCh0aGlzLCBwYXJlbnQpOwogICAgICAgICAgICBzaWJsaW5nID0gcGFyZW50Lkw7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc2libGluZy5MICYmIHNpYmxpbmcuTC5DIHx8IHNpYmxpbmcuU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zsKICAgICAgICAgIHhzLnB1c2goeF8pOwogICAgICAgICAgeXMucHVzaCh5Xyk7CiAgICAgICAgfQogICAgICB9CiAgICAgIHZhciBkeCA9IHgyXyAtIHgxXywgZHkgPSB5Ml8gLSB5MV87CiAgICAgIGlmIChkeCA+IGR5KSB5Ml8gPSB5MV8gKyBkeDsgZWxzZSB4Ml8gPSB4MV8gKyBkeTsKICAgICAgZnVuY3Rpb24gaW5zZXJ0KG4sIGQsIHgsIHksIHgxLCB5MSwgeDIsIHkyKSB7CiAgICAgICAgaWYgKGlzTmFOKHgpIHx8IGlzTmFOKHkpKSByZXR1cm47CiAgICAgICAgaWYgKG4ubGVhZikgewogICAgICAgICAgdmFyIG54ID0gbi54LCBueSA9IG4ueTsKICAgICAgICAgIGlmIChueCAhPSBudWxsKSB7CiAgICAgICAgICAgIGlmIChhYnMobnggLSB4KSArIGFicyhueSAtIHkpIDwgLjAxKSB7CiAgICAgICAgICAgICAgaW5zZXJ0Q2hpbGQobiwgZCwgeCwgeSwgeDEsIHkxLCB4MiwgeTIpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHZhciBuUG9pbnQgPSBuLnBvaW50OwogICAgICAgICAgICAgIG4ueCA9IG4ueSA9IG4ucG9pbnQgPSBudWxsOwogICAgICAgICAgICAgIGluc2VydENoaWxkKG4sIG5Qb2ludCwgbngsIG55LCB4MSwgeTEsIHgyLCB5Mik7CiAgICAgICAgICAgICAgaW5zZXJ0Q2hpbGQobiwgZCwgeCwgeSwgeDEsIHkxLCB4MiwgeTIpOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBuLnggPSB4LCBuLnkgPSB5LCBuLnBvaW50ID0gZDsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgaW5zZXJ0Q2hpbGQobiwgZCwgeCwgeSwgeDEsIHkxLCB4MiwgeTIpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBpbnNlcnRDaGlsZChuLCBkLCB4LCB5LCB4MSwgeTEsIHgyLCB5MikgewogICAgICAgIHZhciB4bSA9ICh4MSArIHgyKSAqIC41LCB5bSA9ICh5MSArIHkyKSAqIC41LCByaWdodCA9IHggPj0geG0sIGJlbG93ID0geSA+PSB5bSwgaSA9IGJlbG93IDw8IDEgfCByaWdodDsKICAgICAgICBuLmxlYWYgPSBmYWxzZTsKICAgICAgICBuID0gbi5ub2Rlc1tpXSB8fCAobi5ub2Rlc1tpXSA9IGQzX2dlb21fcXVhZHRyZWVOb2RlKCkpOwogICAgICAgIGlmIChyaWdodCkgeDEgPSB4bTsgZWxzZSB4MiA9IHhtOwogICAgICAgIGlmIChiZWxvdykgeTEgPSB5bTsgZWxzZSB5MiA9IHltOwogICAgICAgIGluc2VydChuLCBkLCB4LCB5LCB4MSwgeTEsIHgyLCB5Mik7CiAgICAgIH0KICAgICAgdmFyIHJvb3QgPSBkM19nZW9tX3F1YWR0cmVlTm9kZSgpOwogICAgICByb290LmFkZCA9IGZ1bmN0aW9uKGQpIHsKICAgICAgICBpbnNlcnQocm9vdCwgZCwgK2Z4KGQsICsraSksICtmeShkLCBpKSwgeDFfLCB5MV8sIHgyXywgeTJfKTsKICAgICAgfTsKICAgICAgcm9vdC52aXNpdCA9IGZ1bmN0aW9uKGYpIHsKICAgICAgICBkM19nZW9tX3F1YWR0cmVlVmlzaXQoZiwgcm9vdCwgeDFfLCB5MV8sIHgyXywgeTJfKTsKICAgICAgfTsKICAgICAgcm9vdC5maW5kID0gZnVuY3Rpb24ocG9pbnQpIHsKICAgICAgICByZXR1cm4gZDNfZ2VvbV9xdWFkdHJlZUZpbmQocm9vdCwgcG9pbnRbMF0sIHBvaW50WzFdLCB4MV8sIHkxXywgeDJfLCB5Ml8pOwogICAgICB9OwogICAgICBpID0gLTE7CiAgICAgIGlmICh4MSA9PSBudWxsKSB7CiAgICAgICAgd2hpbGUgKCsraSA8IG4pIHsKICAgICAgICAgIGluc2VydChyb290LCBkY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B4MCwgeTAsIHgzLCB5MykgewogICAgdmFyIG1pbkRpc3RhbmNlMiA9IEluZmluaXR5LCBjbG9zZXN0UG9pbnQ7CiAgICAoZnVuY3Rpb24gZmluZChub2RlLCB4MSwgeTEsIHgyLCB5MikgewogICAgICBpZiAoeDEgPiB4MyB8fCB5MSA+IHkzIHx8IHgyIDwgeDAgfHwgeTIgPCB5MCkgcmV0dXJuOwogICAgICBpZiAocG9pbnQgPSBub2RlLnBvaW50KSB7CiAgICAgICAgdmFyIHBvaW50LCBkeCA9IHggLSBwb2ludFswXSwgZHkgPSB5IC0gcG9pbnRbMV0sIGRpc3RhbmNlMiA9IGR4ICogZHggKyBkeSAqIGR5OwogICAgICAgIGlmIChkaXN0YW5jZTIgPCBtaW5EaXN0YW5jZTIpIHsKICAgICAgICAgIHZhciBkaXN0YW5jZSA9IE1hdGguc3FydChtaW5EaXN0YW5jZTIgPSBkaXN0YW5jZTIpOwogICAgICAgICAgeDAgPSB4IC0gZGlzdGFuY2UsIHkwID0geSAtIGRpc3RhbmNlOwogICAgICAgICAgeDMgPSB4ICsgZGlzdGFuY2UsIHkzID0geSArIGRpc3RhbmNlOwogICAgICAgICAgY2xvc2VzdFBvaW50ID0gcG9pbnQ7CiAgICAgICAgfQogICAgICB9CiAgICAgIHZhciBjaGlsZHJlbiA9IG5vZGUubm9kZXMsIHhtID0gKHgxICsgeDIpICogLjUsIHltID0gKHkxICsgeTIpICogLjUsIHJpZ2h0ID0geCA+PSB4bSwgYmVsb3cgPSB5ID49IHltOwogICAgICBmb3IgKHZhciBpID0gYmVsb3cgPDwgMSB8IHJpZ2h0LCBqID0gaSArIDQ7IGkgPCBqOyArK2kpIHsKICAgICAgICBpZiAobm9kZSA9IGNoaWxkcmVuW2kgJiAzXSkgc3dpdGNoIChpICYgMykgewogICAgICAgICBjYXNlIDA6CiAgICAgICAgICBmaW5kKG5vZGUsIHgxLCB5MSwgeG0sIHltKTsKICAgICAgICAgIGJyZWFrOwoKICAgICAgICAgY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2tdKTsKICAgICAgfSBlbHNlIHsKICAgICAgICBjW2tdID0gYVtrXTsKICAgICAgfQogICAgfQogICAgZm9yIChrIGluIGIpIHsKICAgICAgaWYgKCEoayBpbiBhKSkgewogICAgICAgIGNba10gPSBiW2tdOwogICAgICB9CiAgICB9CiAgICByZXR1cm4gZnVuY3Rpb24odCkgewogICAgICBmb3IgKGsgaW4gaSkgY1trXSA9IGlba10odCk7CiAgICAgIHJldHVybiBjOwogICAgfTsKICB9CiAgZDMuaW50ZXJwb2xhdGVOdW1iZXIgPSBkM19pbnRlcnBvbGF0ZU51bWJlcjsKICBmdW5jdGlvbiBkM19pbnRlcnBvbGF0ZU51bWJlcihhLCBiKSB7CiAgICBhID0gK2EsIGIgPSArYjsKICAgIHJldHVybiBmdW5jdGlvbih0KSB7CiAgICAgIHJldHVybiBhICogKDEgLSB0KSArIGIgKiB0OwogICAgfTsKICB9CiAgZDMuaW50ZXJwb2xhdGVTdHJpbmcgPSBkM19pbnRlcnBvbGF0ZVN0cmluZzsKICBmdW5jdGlvbiBkM19pbnRlcnBvbGF0ZVN0cmluZyhhLCBiKSB7CiAgICB2YXIgYmkgPSBkM19pbnRlcnBvbGF0ZV9udW1iZXJBLmxhc3RJbmRleCA9IGQzX2ludGVycG9sYXRlX251bWJlckIubGFzdEluZGV4ID0gMCwgYW0sIGJtLCBicywgaSA9IC0xLCBzID0gW10sIHEgPSBbXTsKICAgIGEgPSBhICsgIiIsIGIgPSBiICsgIiI7CiAgICB3aGlsZSAoKGFtID0gZDNfaW50ZXJwb2xhdGVfbnVtYmVyQS5leGVjKGEpKSAmJiAoYm0gPSBkM19pbnRlcnBvbGF0ZV9udW1iZXJCLmV4ZWMoYikpKSB7CiAgICAgIGlmICgoYnMgPSBibS5pbmRleCkgPiBiaSkgewogICAgICAgIGJzID0gYi5zbGljZShiaSwgYnMpOwogICAgICAgIGlmIChzW2ldKSBzW2ldICs9IGJzOyBlbHNlIHNbKytpXSA9IGJzOwogICAgICB9CiAgIC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uc2xhdGUsIHRiID0gQi50cmFuc2xhdGUsIHJhID0gQS5yb3RhdGUsIHJiID0gQi5yb3RhdGUsIHdhID0gQS5za2V3LCB3YiA9IEIuc2tldywga2EgPSBBLnNjYWxlLCBrYiA9IEIuc2NhbGU7CiAgICBpZiAodGFbMF0gIT0gdGJbMF0gfHwgdGFbMV0gIT0gdGJbMV0pIHsKICAgICAgcy5wdXNoKCJ0cmFuc2xhdGUoIiwgbnVsbCwgIiwiLCBudWxsLCAiKSIpOwogICAgICBxLnB1c2goewogICAgICAgIGk6IDEsCiAgICAgICAgeDogZDNfaW50ZXJwb2xhdGVOdW1iZXIodGFbMF0sIHRiWzBdKQogICAgICB9LCB7CiAgICAgICAgaTogMywKICAgICAgICB4OiBkM19pbnRlcnBvbGF0ZU51bWJlcih0YVsxXSwgdGJbMV0pCiAgICAgIH0pOwogICAgfSBlbHNlIGlmICh0YlswXSB8fCB0YlsxXSkgewogICAgICBzLnB1c2goInRyYW5zbGF0ZSgiICsgdGIgKyAiKSIpOwogICAgfSBlbHNlIHsKICAgICAgcy5wdXNoKCIiKTsKICAgIH0KICAgIGlmIChyYSAhPSByYikgewogICAgICBpZiAocmEgLSByYiA+IDE4MCkgcmIgKz0gMzYwOyBlbHNlIGlmIChyYiAtIHJhID4gMTgwKSByYSArPSAzNjA7CiAgICAgIHEucHVzaCh7CiAgICAgICAgaTogcy5wdXNoKHMucG9wKCkgKyAicm90YXRlKCIsIG51bGwsICIpIikgLSAyLAogICAgICAgIHg6IGQzX2ludGVycG9sYXRlTnVtYmVyKHJhLCByYikKICAgICAgfSk7CiAgICB9IGVsc2UgaWYgKHJiKSB7CiAgICAgIHMucHVzaChzLnBvcCgpICsgInJvdGF0ZSgiICsgcmIgKyAiKSIpOwogICAgfQogICAgaWYgKHdhICE9IHdiKSB7CiAgICAgIHEucHVzaCh7CiAgICAgICAgaTogcy5wdXNoKHMucG9wKCkgKyAic2tld1goIiwgbnVsbCwgIikiKSAtIDIsCiAgICAgICAgeDogZDNfaW50ZXJwb2xhdGVOdW1iZXIod2EsIHdiKQogICAgICB9KTsKICAgIH0gZWxzZSBpZiAod2IpIHsKICAgICAgcy5wdXNoKHMucG9wKCkgKyAic2tld1goIiArIHdiICsgIikiKTsKICAgIH0KICAgIGlmIChrYVswXSAhPSBrYlswXSB8fCBrYVsxXSAhPSBrYlsxXSkgewogICAgICBuID0gcy5wdXNoKHMucG9wKCkgKyAic2NhbGUoIiwgbnVsbCwgIiwiLCBudWxsLCAiKSIpOwogICAgICBxLnB1c2goewogICAgICAgIGk6IG4gLSA0LAogICAgICAgIHg6IGQzX2ludGVycG9sYXRlTnVtYmVyKGthWzBdLCBrYlswXSkKICAgICAgfSwgewogICAgICAgIGk6IG4gLSAyLAogICAgICAgIHg6IGQzX2ludGVycG9sYXRlTnVtYmVyKGthWzFdLCBrYlsxXSkKICAgICAgfSk7CiAgICB9IGVsc2UgaWYgKGtiWzBdICE9IDEgfHwga2JbMV0gIT0gMSkgewogICAgICBzLnB1c2gocy5wb3AoKSArICJzY2FsZSgiICsga2IgKyAiKSIpOwogICAgfQogICAgbiA9IHEubGVuZ3RoOwogICAgcmV0dXJuIGZ1bmN0aW9uKHQpIHsKICAgICAgdmFyIGkgPSAtMSwgbzsKICAgICAgd2hpbGUgKCsraSA8IG4pIHNbKG8gPSBxW2ldKS5pXSA9IG8ueCh0KTsKICAgICAgcmV0dXJuIHMuam9pbigiIik7CiAgICB9OwogIH0KICBmdW5jdGlvbiBkM191bmludGVycG9sYXRlTnVtYmVyKGEsIGIpIHsKICAgIGIgPSAoYiAtPSBhID0gK2EpIHx8IDEgLyBiOwogICAgcmV0dXJuIGZ1bmN0aW9uKHgpIHsKICAgICAgcmV0dXJuICh4IC0gYSkgLyBiOwogICAgfTsKICB9CiAgZnVuY3Rpb24gZDNfdW5pbnRlcnBvbGF0ZUNsYW1wKGEsIGIpIHsKICAgIGIgPSAoYiAtPSBhID0gK2EpIHx8IDEgLyBiOwogICAgcmV0dXJuIGZ1b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CBuKSB7CiAgICAgICAgeCA9IDAsIGogPSAtMTsKICAgICAgICB3aGlsZSAoKytqIDwgbikgewogICAgICAgICAgeCArPSBtYXRyaXhbaV1bal07CiAgICAgICAgfQogICAgICAgIGdyb3VwU3Vtcy5wdXNoKHgpOwogICAgICAgIHN1Ymdyb3VwSW5kZXgucHVzaChkMy5yYW5nZShuKSk7CiAgICAgICAgayArPSB4OwogICAgICB9CiAgICAgIGlmIChzb3J0R3JvdXBzKSB7CiAgICAgICAgZ3JvdXBJbmRleC5zb3J0KGZ1bmN0aW9uKGEsIGIpIHsKICAgICAgICAgIHJldHVybiBzb3J0R3JvdXBzKGdyb3VwU3Vtc1thXSwgZ3JvdXBTdW1zW2JdKTsKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoc29ydFN1Ymdyb3VwcykgewogICAgICAgIHN1Ymdyb3VwSW5kZXguZm9yRWFjaChmdW5jdGlvbihkLCBpKSB7CiAgICAgICAgICBkLnNvcnQoZnVuY3Rpb24oYSwgYikgewogICAgICAgICAgICByZXR1cm4gc29ydFN1Ymdyb3VwcyhtYXRyaXhbaV1bYV0sIG1hdHJpeFtpXVtiXSk7CiAgICAgICAgICB9KTsKICAgICAgICB9KTsKICAgICAgfQogICAgICBrID0gKM+EIC0gcGFkZGluZyAqIG4pIC8gazsKICAgICAgeCA9IDAsIGkgPSAtMTsKICAgICAgd2hpbGUgKCsraSA8IG4pIHsKICAgICAgICB4MCA9IHgsIGogPSAtMTsKICAgICAgICB3aGlsZSAoKytqIDwgbikgewogICAgICAgICAgdmFyIGRpID0gZ3JvdXBJbmRleFtpXSwgZGogPSBzdWJncm91cEluZGV4W2RpXVtqXSwgdiA9IG1hdHJpeFtkaV1bZGpdLCBhMCA9IHgsIGExID0geCArPSB2ICogazsKICAgICAgICAgIHN1Ymdyb3Vwc1tkaSArICItIiArIGRqXSA9IHsKICAgICAgICAgICAgaW5kZXg6IGRpLAogICAgICAgICAgICBzdWJpbmRleDogZGosCiAgICAgICAgICAgIHN0YXJ0QW5nbGU6IGEwLAogICAgICAgICAgICBlbmRBbmdsZTogYTEsCiAgICAgICAgICAgIHZhbHVlOiB2CiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgICBncm91cHNbZGldID0gewogICAgICAgICAgaW5kZXg6IGRpLAogICAgICAgICAgc3RhcnRBbmdsZTogeDAsCiAgICAgICAgICBlbmRBbmdsZTogeCwKICAgICAgICAgIHZhbHVlOiAoeCAtIHgwKSAvIGsKICAgICAgICB9OwogICAgICAgIHggKz0gcGFkZGluZzsKICAgICAgfQogICAgICBpID0gLTE7CiAgICAgIHdoaWxlICgrK2kgPCBuKSB7CiAgICAgICAgaiA9IGkgLSAxOwogICAgICAgIHdoaWxlICgrK2ogPCBuKSB7CiAgICAgICAgICB2YXIgc291cmNlID0gc3ViZ3JvdXBzW2kgKyAiLSIgKyBqXSwgdGFyZ2V0ID0gc3ViZ3JvdXBzW2ogKyAiLSIgKyBpXTsKICAgICAgICAgIGlmIChzb3VyY2UudmFsdWUgfHwgdGFyZ2V0LnZhbHVlKSB7CiAgICAgICAgICAgIGNob3Jkcy5wdXNoKHNvdXJjZS52YWx1ZSA8IHRhcmdldC52YWx1ZSA/IHsKICAgICAgICAgICAgICBzb3VyY2U6IHRhcmdldCwKICAgICAgICAgICAgICB0YXJnZXQ6IHNvdXJjZQogICAgICAgICAgICB9IDogewogICAgICAgICAgICAgIHNvdXJjZTogc291cmNlLAogICAgICAgICAgICAgIHRhcmdldDogdGFyZ2V0CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBpZiAoc29ydENob3JkcykgcmVzb3J0KCk7CiAgICB9CiAgICBmdW5jdGlvbiByZXNvcnQoKSB7CiAgICAgIGNob3Jkcy5zb3J0KGZ1bmN0aW9uKGEsIGIpIHsKICAgICAgICByZXR1cm4gc29ydENob3JkcygoYS5zb3VyY2UudmFsdWUgKyBhLnRhcmdldC52YWx1ZSkgLyAyLCAoYi5zb3VyY2UudmFsdWUgKyBiLnRhcmdldC52YWx1ZSkgLyAyKTsKICAgICAgfSk7CiAgICB9CiAgICBjaG9yZC5tYXRyaXggPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIG1hdHJpeDsKICAgICAgbiA9IChtYXRyaXggPSB4KSAmJiBtYXRyaXgubGVuZ3RoOwogICAgICBjaG9yZHMgPSBncm91cHMgPSBudWxsOwogICAgICByZXR1cm4gY2hvcmQ7CiAgICB9OwogICAgY2hvcmQucGFkZGluZyA9IGZ1bmN0aW9uKHgpIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4gcGFkZGluZzsKICAgICAgcGFkZGluZyA9IHg7CiAgICAgIGNob3JkcyA9IGdyb3VwcyA9IG51bGw7CiAgICAgIHJldHVybiBjaG9yZDsKICAgIH07CiAgICBjaG9yZC5zb3J0R3JvdXBzID0gZnVuY3Rpb24oeCkgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBzb3J0R3JvdXBzOwogICAgICBzb3J0R3JvdXBzID0geDsKICAgICAgY2hvcmRzID0gZ3JvdXBzID0gbnVsbDsKICAgICAgcmV0dXJuIGNob3JkOwogICAgfTsKICAgIGNob3JkLnNvcnRTdWJncm91cHMgPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIHNvcnRTdWJncm91cHM7CiAgICAgIHNvcnRTdWJncm91cHMgPSB4OwogICAgICBjaG9yZHMgPSBudWxsOwogICAgICByZXR1cm4gY2hvcmQ7CiAgICB9OwogICAgY2hvcmQuc29ydENob3JkcyA9IGZ1bmN0aW9uKHgpIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4gc29ydENob3JkczsKICAgICAgc29ydENob3JkcyA9IHg7CiAgICAgIGlmIChjaG9yZHMpIHJlc29ydCgpOwogICAgICByZXR1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ogZHcgLyB0aGV0YTIgPCBkbikgewogICAgICAgICAgICBpZiAoZG4gPCBjaGFyZ2VEaXN0YW5jZTIpIHsKICAgICAgICAgICAgICB2YXIgayA9IHF1YWQuY2hhcmdlIC8gZG47CiAgICAgICAgICAgICAgbm9kZS5weCAtPSBkeCAqIGs7CiAgICAgICAgICAgICAgbm9kZS5weSAtPSBkeSAqIGs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocXVhZC5wb2ludCAmJiBkbiAmJiBkbiA8IGNoYXJnZURpc3RhbmNlMikgewogICAgICAgICAgICB2YXIgayA9IHF1YWQucG9pbnRDaGFyZ2UgLyBkbjsKICAgICAgICAgICAgbm9kZS5weCAtPSBkeCAqIGs7CiAgICAgICAgICAgIG5vZGUucHkgLT0gZHkgKiBrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gIXF1YWQuY2hhcmdlOwogICAgICB9OwogICAgfQogICAgZm9yY2UudGljayA9IGZ1bmN0aW9uKCkgewogICAgICBpZiAoKGFscGhhICo9IC45OSkgPCAuMDA1KSB7CiAgICAgICAgZXZlbnQuZW5kKHsKICAgICAgICAgIHR5cGU6ICJlbmQiLAogICAgICAgICAgYWxwaGE6IGFscGhhID0gMAogICAgICAgIH0pOwogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9CiAgICAgIHZhciBuID0gbm9kZXMubGVuZ3RoLCBtID0gbGlua3MubGVuZ3RoLCBxLCBpLCBvLCBzLCB0LCBsLCBrLCB4LCB5OwogICAgICBmb3IgKGkgPSAwOyBpIDwgbTsgKytpKSB7CiAgICAgICAgbyA9IGxpbmtzW2ldOwogICAgICAgIHMgPSBvLnNvdXJjZTsKICAgICAgICB0ID0gby50YXJnZXQ7CiAgICAgICAgeCA9IHQueCAtIHMueDsKICAgICAgICB5ID0gdC55IC0gcy55OwogICAgICAgIGlmIChsID0geCAqIHggKyB5ICogeSkgewogICAgICAgICAgbCA9IGFscGhhICogc3RyZW5ndGhzW2ldICogKChsID0gTWF0aC5zcXJ0KGwpKSAtIGRpc3RhbmNlc1tpXSkgLyBsOwogICAgICAgICAgeCAqPSBsOwogICAgICAgICAgeSAqPSBsOwogICAgICAgICAgdC54IC09IHggKiAoayA9IHMud2VpZ2h0IC8gKHQud2VpZ2h0ICsgcy53ZWlnaHQpKTsKICAgICAgICAgIHQueSAtPSB5ICogazsKICAgICAgICAgIHMueCArPSB4ICogKGsgPSAxIC0gayk7CiAgICAgICAgICBzLnkgKz0geSAqIGs7CiAgICAgICAgfQogICAgICB9CiAgICAgIGlmIChrID0gYWxwaGEgKiBncmF2aXR5KSB7CiAgICAgICAgeCA9IHNpemVbMF0gLyAyOwogICAgICAgIHkgPSBzaXplWzFdIC8gMjsKICAgICAgICBpID0gLTE7CiAgICAgICAgaWYgKGspIHdoaWxlICgrK2kgPCBuKSB7CiAgICAgICAgICBvID0gbm9kZXNbaV07CiAgICAgICAgICBvLnggKz0gKHggLSBvLngpICogazsKICAgICAgICAgIG8ueSArPSAoeSAtIG8ueSkgKiBrOwogICAgICAgIH0KICAgICAgfQogICAgICBpZiAoY2hhcmdlKSB7CiAgICAgICAgZDNfbGF5b3V0X2ZvcmNlQWNjdW11bGF0ZShxID0gZDMuZ2VvbS5xdWFkdHJlZShub2RlcyksIGFscGhhLCBjaGFyZ2VzKTsKICAgICAgICBpID0gLTE7CiAgICAgICAgd2hpbGUgKCsraSA8IG4pIHsKICAgICAgICAgIGlmICghKG8gPSBub2Rlc1tpXSkuZml4ZWQpIHsKICAgICAgICAgICAgcS52aXNpdChyZXB1bHNlKG8pKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaSA9IC0xOwogICAgICB3aGlsZSAoKytpIDwgbikgewogICAgICAgIG8gPSBub2Rlc1tpXTsKICAgICAgICBpZiAoby5maXhlZCkgewogICAgICAgICAgby54ID0gby5weDsKICAgICAgICAgIG8ueSA9IG8ucHk7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SBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIGFscGhhOwogICAgICB4ID0gK3g7CiAgICAgIGlmIChhbHBoYSkgewogICAgICAgIGlmICh4ID4gMCkgYWxwaGEgPSB4OyBlbHNlIGFscGhhID0gMDsKICAgICAgfSBlbHNlIGlmICh4ID4gMCkgewogICAgICAgIGV2ZW50LnN0YXJ0KHsKICAgICAgICAgIHR5cGU6ICJzdGFydCIsCiAgICAgICAgICBhbHBoYTogYWxwaGEgPSB4CiAgICAgICAgfSk7CiAgICAgICAgZDMudGltZXIoZm9yY2UudGljayk7CiAgICAgIH0KICAgICAgcmV0dXJuIGZvcmNlOwogICAgfTsKICAgIGZvcmNlLnN0YXJ0ID0gZnVuY3Rpb24oKSB7CiAgICAgIHZhciBpLCBuID0gbm9kZXMubGVuZ3RoLCBtID0gbGlua3MubGVuZ3RoLCB3ID0gc2l6ZVswXSwgaCA9IHNpemVbMV0sIG5laWdoYm9ycywgbzsKICAgICAgZm9yIChpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIChvID0gbm9kZXNbaV0pLmluZGV4ID0gaTsKICAgICAgICBvLndlaWdodCA9IDA7CiAgICAgIH0KICAgICAgZm9yIChpID0gMDsgaSA8IG07ICsraSkgewogICAgICAgIG8gPSBsaW5rc1tpXTsKICAgICAgICBpZiAodHlwZW9mIG8uc291cmNlID09ICJudW1iZXIiKSBvLnNvdXJjZSA9IG5vZGVzW28uc291cmNlXTsKICAgICAgICBpZiAodHlwZW9mIG8udGFyZ2V0ID09ICJudW1iZXIiKSBvLnRhcmdldCA9IG5vZGVzW28udGFyZ2V0XTsKICAgICAgICArK28uc291cmNlLndlaWdodDsKICAgICAgICArK28udGFyZ2V0LndlaWdodDsKICAgICAgfQogICAgICBmb3IgKGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgbyA9IG5vZGVzW2ldOwogICAgICAgIGlmIChpc05hTihvLngpKSBvLnggPSBw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YWx1ZSA9IGQzX2xheW91dF9oaWVyYXJjaHlWYWx1ZTsKICAgIGZ1bmN0aW9uIGhpZXJhcmNoeShyb290KSB7CiAgICAgIHZhciBzdGFjayA9IFsgcm9vdCBdLCBub2RlcyA9IFtdLCBub2RlOwogICAgICByb290LmRlcHRoID0gMDsKICAgICAgd2hpbGUgKChub2RlID0gc3RhY2sucG9wKCkpICE9IG51bGwpIHsKICAgICAgICBub2Rlcy5wdXNoKG5vZGUpOwogICAgICAgIGlmICgoY2hpbGRzID0gY2hpbGRyZW4uY2FsbChoaWVyYXJjaHksIG5vZGUsIG5vZGUuZGVwdGgpKSAmJiAobiA9IGNoaWxkcy5sZW5ndGgpKSB7CiAgICAgICAgICB2YXIgbiwgY2hpbGRzLCBjaGlsZDsKICAgICAgICAgIHdoaWxlICgtLW4gPj0gMCkgewogICAgICAgICAgICBzdGFjay5wdXNoKGNoaWxkID0gY2hpbGRzW25dKTsKICAgICAgICAgICAgY2hpbGQucGFyZW50ID0gbm9kZTsKICAgICAgICAgICAgY2hpbGQuZGVwdGggPSBub2RlLmRlcHRoICsgMTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWx1ZSkgbm9kZS52YWx1ZSA9IDA7CiAgICAgICAgICBub2RlLmNoaWxkcmVuID0gY2hpbGRzOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAodmFsdWUpIG5vZGUudmFsdWUgPSArdmFsdWUuY2FsbChoaWVyYXJjaHksIG5vZGUsIG5vZGUuZGVwdGgpIHx8IDA7CiAgICAgICAgICBkZWxldGUgbm9kZS5jaGlsZHJlbjsKICAgICAgICB9CiAgICAgIH0KICAgICAgZDNfbGF5b3V0X2hpZXJhcmNoeVZpc2l0QWZ0ZXIocm9vdCwgZnVuY3Rpb24obm9kZSkgewogICAgICAgIHZhciBjaGlsZHMsIHBhcmVudDsKICAgICAgICBpZiAoc29ydCAmJiAoY2hpbGRzID0gbm9kZS5jaGlsZHJlbikpIGNoaWxkcy5zb3J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ZGUuZGVwdGgpIHx8IDA7CiAgICAgICAgICBpZiAocGFyZW50ID0gbm9kZS5wYXJlbnQpIHBhcmVudC52YWx1ZSArPSBub2RlLnZhbHVlOwogICAgICAgIH0pOwogICAgICB9CiAgICAgIHJldHVybiByb290OwogICAgfTsKICAgIHJldHVybiBoaWVyYXJjaHk7CiAgfTsKICBmdW5jdGlvbiBkM19sYXlvdXRfaGllcmFyY2h5UmViaW5kKG9iamVjdCwgaGllcmFyY2h5KSB7CiAgICBkMy5yZWJpbmQob2JqZWN0LCBoaWVyYXJjaHksICJzb3J0IiwgImNoaWxkcmVuIiwgInZhbHVlIik7CiAgICBvYmplY3Qubm9kZXMgPSBvYmplY3Q7CiAgICBvYmplY3QubGlua3MgPSBkM19sYXlvdXRfaGllcmFyY2h5TGlua3M7CiAgICByZXR1cm4gb2JqZWN0OwogIH0KICBmdW5jdGlvbiBkM19sYXlvdXRfaGllcmFyY2h5VmlzaXRCZWZvcmUobm9kZSwgY2FsbGJhY2spIHsKICAgIHZhciBub2RlcyA9IFsgbm9kZSBdOwogICAgd2hpbGUgKChub2RlID0gbm9kZXMucG9wKCkpICE9IG51bGwpIHsKICAgICAgY2FsbGJhY2sobm9kZSk7CiAgICAgIGlmICgoY2hpbGRyZW4gPSBub2RlLmNoaWxkcmVuKSAmJiAobiA9IGNoaWxkcmVuLmxlbmd0aCkpIHsKICAgICAgICB2YXIgbiwgY2hpbGRyZW47CiAgICAgICAgd2hpbGUgKC0tbiA+PSAwKSBub2Rlcy5wdXNoKGNoaWxkcmVuW25dKTsKICAgICAgfQogICAgfQogIH0KICBmdW5jdGlvbiBkM19sYXlvdXRfaGllcmFyY2h5VmlzaXRBZnRlcihub2RlLCBjYWxsYmFjaykgewogICAgdmFyIG5vZGVzID0gWyBub2RlIF0sIG5vZGVzMiA9IFtdOwogICAgd2hpbGUgKChub2RlID0gbm9kZXMucG9wKCkpICE9IG51bGwpIHsKICAgICAgbm9kZXMyLnB1c2gobm9kZSk7CiAgICAg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kZXguc29ydChzb3J0ID09PSBkM19sYXlvdXRfcGllU29ydEJ5VmFsdWUgPyBmdW5jdGlvbihpLCBqKSB7CiAgICAgICAgcmV0dXJuIHZhbHVlc1tqXSAtIHZhbHVlc1tpXTsKICAgICAgfSA6IGZ1bmN0aW9uKGksIGopIHsKICAgICAgICByZXR1cm4gc29ydChkYXRhW2ldLCBkYXRhW2pdKTsKICAgICAgfSk7CiAgICAgIGluZGV4LmZvckVhY2goZnVuY3Rpb24oaSkgewogICAgICAgIGFyY3NbaV0gPSB7CiAgICAgICAgICBkYXRhOiBkYXRhW2ldLAogICAgICAgICAgdmFsdWU6IHYgPSB2YWx1ZXNbaV0sCiAgICAgICAgICBzdGFydEFuZ2xlOiBhLAogICAgICAgICAgZW5kQW5nbGU6IGEgKz0gdiAqIGsgKyBwYSwKICAgICAgICAgIHBhZEFuZ2xlOiBwCiAgICAgICAgfTsKICAgICAgfSk7CiAgICAgIHJldHVybiBhcmNzOwogICAgfQogICAgcGllLnZhbHVlID0gZnVuY3Rpb24oXykgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiB2YWx1ZTsKICAgICAgdmFsdWUgPSBfOwogICAgICByZXR1cm4gcGllOwogICAgfTsKICAgIHBpZS5zb3J0ID0gZnVuY3Rpb24oXykgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBzb3J0OwogICAgICBzb3J0ID0gXzsKICAgICAgcmV0dXJuIHBpZTsKICAgIH07CiAgICBwaWUuc3RhcnRBbmdsZSA9IGZ1bmN0aW9uKF8pIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4gc3RhcnRBbmdsZTsKICAgICAgc3RhcnRBbmdsZSA9IF87CiAgICAgIHJldHVybiBwaWU7CiAgICB9OwogICAgcGllLmVuZEFuZ2xlID0gZnVuY3Rpb24oXykgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBlbmRBbm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ID0gbzsKICAgICAgICBzdW1zLnB1c2gobyk7CiAgICAgIH0KICAgICAgZm9yIChqID0gMDsgaiA8IG07ICsraikgewogICAgICAgIHkwW2pdID0gKG1heCAtIHN1bXNbal0pIC8gMjsKICAgICAgfQogICAgICByZXR1cm4geTA7CiAgICB9LAogICAgd2lnZ2xlOiBmdW5jdGlvbihkYXRhKSB7CiAgICAgIHZhciBuID0gZGF0YS5sZW5ndGgsIHggPSBkYXRhWzBdLCBtID0geC5sZW5ndGgsIGksIGosIGssIHMxLCBzMiwgczMsIGR4LCBvLCBvMCwgeTAgPSBbXTsKICAgICAgeTBbMF0gPSBvID0gbzAgPSAwOwogICAgICBmb3IgKGogPSAxOyBqIDwgbTsgKytqKSB7CiAgICAgICAgZm9yIChpID0gMCwgczEgPSAwOyBpIDwgbjsgKytpKSBzMSArPSBkYXRhW2ldW2pdWzFdOwogICAgICAgIGZvciAoaSA9IDAsIHMyID0gMCwgZHggPSB4W2pdWzBdIC0geFtqIC0gMV1bMF07IGkgPCBuOyArK2kpIHsKICAgICAgICAgIGZvciAoayA9IDAsIHMzID0gKGRhdGFbaV1bal1bMV0gLSBkYXRhW2ldW2ogLSAxXVsxXSkgLyAoMiAqIGR4KTsgayA8IGk7ICsraykgewogICAgICAgICAgICBzMyArPSAoZGF0YVtrXVtqXVsxXSAtIGRhdGFba11baiAtIDFdWzFdKSAvIGR4OwogICAgICAgICAgfQogICAgICAgICAgczIgKz0gczMgKiBkYXRhW2ldW2pdWzFdOwogICAgICAgIH0KICAgICAgICB5MFtqXSA9IG8gLT0gczEgPyBzMiAvIHMxICogZHggOiAwOwogICAgICAgIGlmIChvIDwgbzApIG8wID0gbzsKICAgICAgfQogICAgICBmb3IgKGogPSAwOyBqIDwgbTsgKytqKSB5MFtqXSAtPSBvMDsKICAgICAgcmV0dXJuIHkwOwogICAgfSwKICAgIGV4cGFuZDogZnVuY3Rpb24oZGF0YSkgewogICAgICB2YXIgbiA9IGRhdGEubGVuZ3RoLCBtID0g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wogICAgICByb290LnggPSByb290LnkgPSAwOwogICAgICBkM19sYXlvdXRfaGllcmFyY2h5VmlzaXRBZnRlcihyb290LCBmdW5jdGlvbihkKSB7CiAgICAgICAgZC5yID0gK3IoZC52YWx1ZSk7CiAgICAgIH0pOwogICAgICBkM19sYXlvdXRfaGllcmFyY2h5VmlzaXRBZnRlcihyb290LCBkM19sYXlvdXRfcGFja1NpYmxpbmdzKTsKICAgICAgaWYgKHBhZGRpbmcpIHsKICAgICAgICB2YXIgZHIgPSBwYWRkaW5nICogKHJhZGl1cyA/IDEgOiBNYXRoLm1heCgyICogcm9vdC5yIC8gdywgMiAqIHJvb3QuciAvIGgpKSAvIDI7CiAgICAgICAgZDNfbGF5b3V0X2hpZXJhcmNoeVZpc2l0QWZ0ZXIocm9vdCwgZnVuY3Rpb24oZCkgewogICAgICAgICAgZC5yICs9IGRyOwogICAgICAgIH0pOwogICAgICAgIGQzX2xheW91dF9oaWVyYXJjaHlWaXNpdEFmdGVyKHJvb3QsIGQzX2xheW91dF9wYWNrU2libGluZ3MpOwogICAgICAgIGQzX2xheW91dF9oaWVyYXJjaHlWaXNpdEFmdGVyKHJvb3QsIGZ1bmN0aW9uKGQpIHsKICAgICAgICAgIGQuciAtPSBkcjsKICAgICAgICB9KTsKICAgICAgfQogICAgICBkM19sYXlvdXRfcGFja1RyYW5zZm9ybShyb290LCB3IC8gMiwgaCAvIDIsIHJhZGl1cyA/IDEgOiAxIC8gTWF0aC5tYXgoMiAqIHJvb3QuciAvIHcsIDIgKiByb290LnIgLyBoKSk7CiAgICAgIHJldHVybiBub2RlczsKICAgIH0KICAgIHBhY2suc2l6ZSA9IGZ1bmN0aW9uKF8pIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4gc2l6ZTsKICAgICAgc2l6ZSA9IF87CiAgICAgIHJldHVybiBwYWNrOwogICAgfTsKICAgIHBhY2sucmFkaXVzID0gZnVuY3Rpb24oXykgewogICAgICBpZiAoIWFyZ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ZGUuY2hpbGRyZW4pIHx8ICEobiA9IG5vZGVzLmxlbmd0aCkpIHJldHVybjsKICAgIHZhciBub2RlcywgeE1pbiA9IEluZmluaXR5LCB4TWF4ID0gLUluZmluaXR5LCB5TWluID0gSW5maW5pdHksIHlNYXggPSAtSW5maW5pdHksIGEsIGIsIGMsIGksIGosIGssIG47CiAgICBmdW5jdGlvbiBib3VuZChub2RlKSB7CiAgICAgIHhNaW4gPSBNYXRoLm1pbihub2RlLnggLSBub2RlLnIsIHhNaW4pOwogICAgICB4TWF4ID0gTWF0aC5tYXgobm9kZS54ICsgbm9kZS5yLCB4TWF4KTsKICAgICAgeU1pbiA9IE1hdGgubWluKG5vZGUueSAtIG5vZGUuciwgeU1pbik7CiAgICAgIHlNYXggPSBNYXRoLm1heChub2RlLnkgKyBub2RlLnIsIHlNYXgpOwogICAgfQogICAgbm9kZXMuZm9yRWFjaChkM19sYXlvdXRfcGFja0xpbmspOwogICAgYSA9IG5vZGVzWzBdOwogICAgYS54ID0gLWEucjsKICAgIGEueSA9IDA7CiAgICBib3VuZChhKTsKICAgIGlmIChuID4gMSkgewogICAgICBiID0gbm9kZXNbMV07CiAgICAgIGIueCA9IGIucjsKICAgICAgYi55ID0gMDsKICAgICAgYm91bmQoYik7CiAgICAgIGlmIChuID4gMikgewogICAgICAgIGMgPSBub2Rlc1syXTsKICAgICAgICBkM19sYXlvdXRfcGFja1BsYWNlKGEsIGIsIGMpOwogICAgICAgIGJvdW5kKGMpOwogICAgICAgIGQzX2xheW91dF9wYWNrSW5zZXJ0KGEsIGMpOwogICAgICAgIGEuX3BhY2tfcHJldiA9IGM7CiAgICAgICAgZDNfbGF5b3V0X3BhY2tJbnNlcnQoYywgYik7CiAgICAgICAgYiA9IGEuX3BhY2tfbmV4dDsKICAgICAgICBmb3IgKGkgPSAzOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICBkM19sYXlvdXRfcGFja1BsYWNlKGEsIGIsIGMgPSBub2Rlc1tpXSk7CiAgICAgICAgICB2YXIgaXNlY3QgPSAwLCBzMSA9IDEsIHMyID0gMTsKICAgICAgICAgIGZvciAoaiA9IGIuX3BhY2tfbmV4dDsgaiAhPT0gYjsgaiA9IGouX3BhY2tfbmV4dCwgczErKykgewogICAgICAgICAgICBpZiAoZDNfbGF5b3V0X3BhY2tJbnRlcnNlY3RzKGosIGMpKSB7CiAgICAgICAgICAgICAgaXNlY3QgPSAxOwogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaXNlY3QgPT0gMSkgewogICAgICAgICAgICBmb3IgKGsgPSBhLl9wYWNrX3ByZXY7IGsgIT09IGouX3BhY2tfcHJldjsgayA9IGsuX3BhY2tfcHJldiwgczIrKykgewogICAgICAgICAgICAgIGlmIChkM19sYXlvdXRfcGFja0ludGVyc2VjdHMoaywgYykpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGlzZWN0KSB7CiAgICAgICAgICAgIGlmIChzMSA8IHMyIHx8IHMxID09IHMyICYmIGIuciA8IGEucikgZDNfbGF5b3V0X3BhY2tTcGxpY2UoYSwgYiA9IGopOyBlbHNlIGQzX2xheW91dF9wYWNrU3BsaWNlKGEgPSBrLCBiKTsKICAgICAgICAgICAgaS0tOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZDNfbGF5b3V0X3BhY2tJbnNlcnQoYSwgYyk7CiAgICAgICAgICAgIGIgPSBjOwogICAgICAgICAgICBib3VuZChjKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHZhciBjeCA9ICh4TWluICsgeE1heCkgLyAyLCBjeSA9ICh5TWluICsgeU1heCkgLyAyLCBjciA9IDA7CiAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgIGMgPSBub2Rlc1tpXTsKICAgICAgYy54IC09IGN4OwogICAgICBjLnkgLT0gY3k7CiAgICAgIGNyID0gTWF0aC5tYXgoY3IsIGMuciArIE1hdGguc3FydChjLnggKiBjLnggKyBjLnkgKiBjLnkpKTsKICAgIH0KICAgIG5vZGUuciA9IGNyOwogICAgbm9kZXMuZm9yRWFjaChkM19sYXlvdXRfcGFja1VubGluayk7CiAgfQogIGZ1bmN0aW9uIGQzX2xheW91dF9wYWNrTGluayhub2RlKSB7CiAgICBub2RlLl9wYWNrX25leHQgPSBub2RlLl9wYWNrX3ByZXYgPSBub2RlOwogIH0KICBmdW5jdGlvbiBkM19sYXlvdXRfcGFja1VubGluayhub2RlKSB7CiAgICBkZWxldGUgbm9kZS5fcGFja19uZXh0OwogICAgZGVsZXRlIG5vZGUuX3BhY2tfcHJldjsKICB9CiAgZnVuY3Rpb24gZDNfbGF5b3V0X3BhY2tUcmFuc2Zvcm0obm9kZSwgeCwgeSwgaykgewogICAgdmFyIGNoaWxkcmVuID0gbm9kZS5jaGlsZHJlbjsKICAgIG5vZGUueCA9IHggKz0gayAqIG5vZGUueDsKICAgIG5vZGUueSA9IHkgKz0gayAqIG5vZGUueTsKICAgIG5vZGUuciAqPSBrOwogICAgaWYgKGNoaWxkcmVuKSB7CiAgICAgIHZhciBpID0gLTEsIG4gPSBjaGlsZHJlbi5sZW5ndGg7CiAgICAgIHdoaWxlICgrK2kgPCBuKSBkM19sYXlvdXRfcGFja1RyYW5zZm9ybShjaGlsZHJlbltpXSwgeCwgeSwgayk7CiAgICB9CiAgfQogIGZ1bmN0aW9uIGQzX2xheW91dF9wYWNrUGxhY2UoYSwgYiwgYykgewogICAgdmFyIGRiID0gYS5yICsgYy5yLCBkeCA9IGIueCAtIGEueCwgZHkgPSBiLnkgLSBhLnk7CiAgICBpZiAoZGIgJiYgKGR4IHx8IGR5KSkgewogICAgICB2YXIgZGEgPSBiLnIgKyBjLnIsIGRjID0gZHggKiBkeCArIGR5ICogZHk7CiAgICAgIGRhICo9IGRhOwogICAgICBkYiAqP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heW91dF9oaWVyYXJjaHlWaXNpdEJlZm9yZShyb290MCwgZnVuY3Rpb24obm9kZSkgewogICAgICAgICAgaWYgKG5vZGUueCA8IGxlZnQueCkgbGVmdCA9IG5vZGU7CiAgICAgICAgICBpZiAobm9kZS54ID4gcmlnaHQueCkgcmlnaHQgPSBub2RlOwogICAgICAgICAgaWYgKG5vZGUuZGVwdGggPiBib3R0b20uZGVwdGgpIGJvdHRvbSA9IG5vZGU7CiAgICAgICAgfSk7CiAgICAgICAgdmFyIHR4ID0gc2VwYXJhdGlvbihsZWZ0LCByaWdodCkgLyAyIC0gbGVmdC54LCBreCA9IHNpemVbMF0gLyAocmlnaHQueCArIHNlcGFyYXRpb24ocmlnaHQsIGxlZnQpIC8gMiArIHR4KSwga3kgPSBzaXplWzFdIC8gKGJvdHRvbS5kZXB0aCB8fCAxKTsKICAgICAgICBkM19sYXlvdXRfaGllcmFyY2h5VmlzaXRCZWZvcmUocm9vdDAsIGZ1bmN0aW9uKG5vZGUpIHsKICAgICAgICAgIG5vZGUueCA9IChub2RlLnggKyB0eCkgKiBreDsKICAgICAgICAgIG5vZGUueSA9IG5vZGUuZGVwdGggKiBreTsKICAgICAgICB9KTsKICAgICAgfQogICAgICByZXR1cm4gbm9kZXM7CiAgICB9CiAgICBmdW5jdGlvbiB3cmFwVHJlZShyb290MCkgewogICAgICB2YXIgcm9vdDEgPSB7CiAgICAgICAgQTogbnVsbCwKICAgICAgICBjaGlsZHJlbjogWyByb290MCBdCiAgICAgIH0sIHF1ZXVlID0gWyByb290MSBdLCBub2RlMTsKICAgICAgd2hpbGUgKChub2RlMSA9IHF1ZXVlLnBvcCgpKSAhPSBudWxsKSB7CiAgICAgICAgZm9yICh2YXIgY2hpbGRyZW4gPSBub2RlMS5jaGlsZHJlbiwgY2hpbGQsIGkgPSAwLCBuID0gY2hpbGRyZW4ubGVuZ3RoOyBpIDwgbjsgKytpKSB7CiAgICAgICAgICBxdWV1ZS5wdXNoKChjaGlsZHJlbltpXSA9IGNoaWxkID0gewogICAgICAgICAgICBfOiBjaGlsZHJlbltpXSwKICAgICAgICAgICAgcGFyZW50OiBub2RlMSwKICAgICAgICAgICAgY2hpbGRyZW46IChjaGlsZCA9IGNoaWxkcmVuW2ldLmNoaWxkcmVuKSAmJiBjaGlsZC5zbGljZSgpIHx8IFtdLAogICAgICAgICAgICBBOiBudWxsLAogICAgICAgICAgICBhOiBudWxsLAogICAgICAgICAgICB6OiAwLAogICAgICAgICAgICBtOiAwLAogICAgICAgICAgICBjOiAwLAogICAgICAgICAgICBzOiAwLAogICAgICAgICAgICB0OiBudWxsLAogICAgICAgICAgICBpOiBpCiAgICAgICAgICB9KS5hID0gY2hpbGQpOwogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gcm9vdDEuY2hpbGRyZW5bMF07CiAgICB9CiAgICBmdW5jdGlvbiBmaXJzdFdhbGsodikgewogICAgICB2YXIgY2hpbGRyZW4gPSB2LmNoaWxkcmVuLCBzaWJsaW5ncyA9IHYucGFyZW50LmNoaWxkcmVuLCB3ID0gdi5pID8gc2libGluZ3Nbdi5pIC0gMV0gOiBudWxsOwogICAgICBpZiAoY2hpbGRyZW4ubGVuZ3RoKSB7CiAgICAgICAgZDNfbGF5b3V0X3RyZWVTaGlmdCh2KTsKICAgICAgICB2YXIgbWlkcG9pbnQgPSAoY2hpbGRyZW5bMF0ueiArIGNoaWxkcmVuW2NoaWxkcmVuLmxlbmd0aCAtIDFdLnopIC8gMjsKICAgICAgICBpZiAodykgewogICAgICAgICAgdi56ID0gdy56ICsgc2VwYXJhdGlvbih2Ll8sIHcuXyk7CiAgICAgICAgICB2Lm0gPSB2LnogLSBtaWRwb2ludDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdi56ID0gbWlkcG9pbnQ7CiAgICAgICAgfQogICAgICB9IGVsc2UgaWYgKHcpIHsKICAgICAgICB2LnogPSB3LnogKyBzZXBhcmF0aW9uKHYuXywgdy5fKTsKICAgICAgfQogICAgICB2LnBhcmVudC5BID0gYXBwb3J0aW9uKHYsIHcsIHYucGFyZW50LkEgfHwgc2libGluZ3NbMF0pOwogICAgfQogICAgZnVuY3Rpb24gc2Vjb25kV2Fsayh2KSB7CiAgICAgIHYuXy54ID0gdi56ICsgdi5wYXJlbnQubTsKICAgICAgdi5tICs9IHYucGFyZW50Lm07CiAgICB9CiAgICBmdW5jdGlvbiBhcHBvcnRpb24odiwgdywgYW5jZXN0b3IpIHsKICAgICAgaWYgKHcpIHsKICAgICAgICB2YXIgdmlwID0gdiwgdm9wID0gdiwgdmltID0gdywgdm9tID0gdmlwLnBhcmVudC5jaGlsZHJlblswXSwgc2lwID0gdmlwLm0sIHNvcCA9IHZvcC5tLCBzaW0gPSB2aW0ubSwgc29tID0gdm9tLm0sIHNoaWZ0OwogICAgICAgIHdoaWxlICh2aW0gPSBkM19sYXlvdXRfdHJlZVJpZ2h0KHZpbSksIHZpcCA9IGQzX2xheW91dF90cmVlTGVmdCh2aXApLCB2aW0gJiYgdmlwKSB7CiAgICAgICAgICB2b20gPSBkM19sYXlvdXRfdHJlZUxlZnQodm9tKTsKICAgICAgICAgIHZvcCA9IGQzX2xheW91dF90cmVlUmlnaHQodm9wKTsKICAgICAgICAgIHZvcC5hID0gdjsKICAgICAgICAgIHNoaWZ0ID0gdmltLnogKyBzaW0gLSB2aXAueiAtIHNpcCArIHNlcGFyYXRpb24odmltLl8sIHZpcC5fKTsKICAgICAgICAgIGlmIChzaGlmdCA+IDApIHsKICAgICAgICAgICAgZDNfbGF5b3V0X3RyZWVNb3ZlKGQzX2xheW91dF90cmVlQW5jZXN0b3IodmltLCB2LCBhbmNlc3RvciksIHYsIHNoaWZ0KTsKICAgICAgICAgICAgc2lwICs9IHNoaWZ0OwogICAgICAgICAgICBzb3AgKz0gc2hpZnQ7CiAgICAgICAgICB9CiAgICAgICAgICBzaW0gKz0gdmltLm07CiAgICAgICAgICBzaXAgKz0gdmlwLm07CiAgICAgICAgICBzb20gKz0gdm9tLm07CiAgICAgICAgICBzb3AgKz0gdm9wLm07CiAgICAgICAgfQogICAgICAgIGlmICh2aW0gJiYgIWQzX2xheW91dF90cmVlUmlnaHQodm9wKSkgewogICAgICAgICAgdm9wLnQgPSB2aW07CiAgICAgICAgICB2b3AubSArPSBzaW0gLSBzb3A7CiAgICAgICAgfQogICAgICAgIGlmICh2aXAgJiYgIWQzX2xheW91dF90cmVlTGVmdCh2b20pKSB7CiAgICAgICAgICB2b20udCA9IHZpcDsKICAgICAgICAgIHZvbS5tICs9IHNpcCAtIHNvbTsKICAgICAgICAgIGFuY2VzdG9yID0gdjsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIGFuY2VzdG9yOwogICAgfQogICAgZnVuY3Rpb24gc2l6ZU5vZGUobm9kZSkgewogICAgICBub2RlLnggKj0gc2l6ZVswXTsKICAgICAgbm9kZS55ID0gbm9kZS5kZXB0aCAqIHNpemVbMV07CiAgICB9CiAgICB0cmVlLnNlcGFyYXRpb24gPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIHNlcGFyYXRpb247CiAgICAgIHNlcGFyYXRpb24gPSB4OwogICAgICByZXR1cm4gdHJlZTsKICAgIH07CiAgICB0cmVlLnNpemUgPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIG5vZGVTaXplID8gbnVsbCA6IHNpemU7CiAgICAgIG5vZGVTaXplID0gKHNpemUgPSB4KSA9PSBudWxsID8gc2l6ZU5vZGUgOiBudWxsOwogICAgICByZXR1cm4gdHJlZTsKICAgIH07CiAgICB0cmVlLm5vZGVTaXplID0gZnVuY3Rpb24oeCkgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBub2RlU2l6ZSA/IHNpemUgOiBudWxsOwogICAgICBub2RlU2l6ZSA9IChzaXplID0geCkgPT0gbnVsbCA/IG51bGwgOiBzaXplTm9kZTsKICAgICAg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gICB9CiAgICAgIH0pOwogICAgICB2YXIgbGVmdCA9IGQzX2xheW91dF9jbHVzdGVyTGVmdChyb290KSwgcmlnaHQgPSBkM19sYXlvdXRfY2x1c3RlclJpZ2h0KHJvb3QpLCB4MCA9IGxlZnQueCAtIHNlcGFyYXRpb24obGVmdCwgcmlnaHQpIC8gMiwgeDEgPSByaWdodC54ICsgc2VwYXJhdGlvbihyaWdodCwgbGVmdCkgLyAyOwogICAgICBkM19sYXlvdXRfaGllcmFyY2h5VmlzaXRBZnRlcihyb290LCBub2RlU2l6ZSA/IGZ1bmN0aW9uKG5vZGUpIHsKICAgICAgICBub2RlLnggPSAobm9kZS54IC0gcm9vdC54KSAqIHNpemVbMF07CiAgICAgICAgbm9kZS55ID0gKHJvb3QueSAtIG5vZGUueSkgKiBzaXplWzFdOwogICAgICB9IDogZnVuY3Rpb24obm9kZSkgewogICAgICAgIG5vZGUueCA9IChub2RlLnggLSB4MCkgLyAoeDEgLSB4MCkgKiBzaXplWzBdOwogICAgICAgIG5vZGUueSA9ICgxIC0gKHJvb3QueSA/IG5vZGUueSAvIHJvb3QueSA6IDEpKSAqIHNpemVbMV07CiAgICAgIH0pOwogICAgICByZXR1cm4gbm9kZXM7CiAgICB9CiAgICBjbHVzdGVyLnNlcGFyYXRpb24gPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIHNlcGFyYXRpb247CiAgICAgIHNlcGFyYXRpb24gPSB4OwogICAgICByZXR1cm4gY2x1c3RlcjsKICAgIH07CiAgICBjbHVzdGVyLnNpemUgPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIG5vZGVTaXplID8gbnVsbCA6IHNpemU7CiAgICAgIG5vZGVTaXplID0gKHNpemUgPSB4KSA9PSBudWxsOwogICAgICByZXR1cm4gY2x1c3RlcjsKICAgIH07CiAgICBjbHVzdGVyLm5vZGVTaXplID0gZnV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0LmR5KSwgbjsKICAgICAgICBzY2FsZShyZW1haW5pbmcsIHJlY3QuZHggKiByZWN0LmR5IC8gbm9kZS52YWx1ZSk7CiAgICAgICAgcm93LmFyZWEgPSAwOwogICAgICAgIHdoaWxlICgobiA9IHJlbWFpbmluZy5sZW5ndGgpID4gMCkgewogICAgICAgICAgcm93LnB1c2goY2hpbGQgPSByZW1haW5pbmdbbiAtIDFdKTsKICAgICAgICAgIHJvdy5hcmVhICs9IGNoaWxkLmFyZWE7CiAgICAgICAgICBpZiAobW9kZSAhPT0gInNxdWFyaWZ5IiB8fCAoc2NvcmUgPSB3b3JzdChyb3csIHUpKSA8PSBiZXN0KSB7CiAgICAgICAgICAgIHJlbWFpbmluZy5wb3AoKTsKICAgICAgICAgICAgYmVzdCA9IHNjb3JlOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcm93LmFyZWEgLT0gcm93LnBvcCgpLmFyZWE7CiAgICAgICAgICAgIHBvc2l0aW9uKHJvdywgdSwgcmVjdCwgZmFsc2UpOwogICAgICAgICAgICB1ID0gTWF0aC5taW4ocmVjdC5keCwgcmVjdC5keSk7CiAgICAgICAgICAgIHJvdy5sZW5ndGggPSByb3cuYXJlYSA9IDA7CiAgICAgICAgICAgIGJlc3QgPSBJbmZpbml0eTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHJvdy5sZW5ndGgpIHsKICAgICAgICAgIHBvc2l0aW9uKHJvdywgdSwgcmVjdCwgdHJ1ZSk7CiAgICAgICAgICByb3cubGVuZ3RoID0gcm93LmFyZWEgPSAwOwogICAgICAgIH0KICAgICAgICBjaGlsZHJlbi5mb3JFYWNoKHNxdWFyaWZ5KTsKICAgICAgfQogICAgfQogICAgZnVuY3Rpb24gc3RpY2tpZnkobm9kZSkgewogICAgICB2YXIgY2hpbGRyZW4gPSBub2RlLmNoaWxkcmVuOwogICAgICBpZiAoY2hpbGRyZW4gJiYgY2hpbGRyZW4ubGVuZ3RoKSB7CiAgICAgICAgdmFyIHJlY3QgPSBwYWQobm9kZSksIHJlbWFpbmluZyA9IGNoaWxkcmVuLnNsaWNlKCksIGNoaWxkLCByb3cgPSBbXTsKICAgICAgICBzY2FsZShyZW1haW5pbmcsIHJlY3QuZHggKiByZWN0LmR5IC8gbm9kZS52YWx1ZSk7CiAgICAgICAgcm93LmFyZWEgPSAwOwogICAgICAgIHdoaWxlIChjaGlsZCA9IHJlbWFpbmluZy5wb3AoKSkgewogICAgICAgICAgcm93LnB1c2goY2hpbGQpOwogICAgICAgICAgcm93LmFyZWEgKz0gY2hpbGQuYXJlYTsKICAgICAgICAgIGlmIChjaGlsZC56ICE9IG51bGwpIHsKICAgICAgICAgICAgcG9zaXRpb24ocm93LCBjaGlsZC56ID8gcmVjdC5keCA6IHJlY3QuZHksIHJlY3QsICFyZW1haW5pbmcubGVuZ3RoKTsKICAgICAgICAgICAgcm93Lmxlbmd0aCA9IHJvdy5hcmVhID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY2hpbGRyZW4uZm9yRWFjaChzdGlja2lmeSk7CiAgICAgIH0KICAgIH0KICAgIGZ1bmN0aW9uIHdvcnN0KHJvdywgdSkgewogICAgICB2YXIgcyA9IHJvdy5hcmVhLCByLCBybWF4ID0gMCwgcm1pbiA9IEluZmluaXR5LCBpID0gLTEsIG4gPSByb3cubGVuZ3RoOwogICAgICB3aGlsZSAoKytpIDwgbikgewogICAgICAgIGlmICghKHIgPSByb3dbaV0uYXJlYSkpIGNvbnRpbnVlOwogICAgICAgIGlmIChyIDwgcm1pbikgcm1pbiA9IHI7CiAgICAgICAgaWYgKHIgPiBybWF4KSBybWF4ID0gcjsKICAgICAgfQogICAgICBzICo9IHM7CiAgICAgIHUgKj0gdTsKICAgICAgcmV0dXJuIHMgPyBNYXRoLm1heCh1ICogcm1heCAqIHJhdGlvIC8gcywgcyAvICh1ICogcm1pbiAqIHJhdGlvKSkgOiBJbmZpbml0eTsKICAgIH0KICAgIGZ1bmN0aW9uIHBvc2l0aW9uKHJvdywgdSwgcmVjdCwgZmx1c2gpIHsKICAgICAgdmFyIGkgPSAtMSwgbiA9IHJvdy5sZW5ndGgsIHggPSByZWN0LngsIHkgPSByZWN0LnksIHYgPSB1ID8gcm91bmQocm93LmFyZWEgLyB1KSA6IDAsIG87CiAgICAgIGlmICh1ID09IHJlY3QuZHgpIHsKICAgICAgICBpZiAoZmx1c2ggfHwgdiA+IHJlY3QuZHkpIHYgPSByZWN0LmR5OwogICAgICAgIHdoaWxlICgrK2kgPCBuKSB7CiAgICAgICAgICBvID0gcm93W2ldOwogICAgICAgICAgby54ID0geDsKICAgICAgICAgIG8ueSA9IHk7CiAgICAgICAgICBvLmR5ID0gdjsKICAgICAgICAgIHggKz0gby5keCA9IE1hdGgubWluKHJlY3QueCArIHJlY3QuZHggLSB4LCB2ID8gcm91bmQoby5hcmVhIC8gdikgOiAwKTsKICAgICAgICB9CiAgICAgICAgby56ID0gdHJ1ZTsKICAgICAgICBvLmR4ICs9IHJlY3QueCArIHJlY3QuZHggLSB4OwogICAgICAgIHJlY3QueSArPSB2OwogICAgICAgIHJlY3QuZHkgLT0gdjsKICAgICAgfSBlbHNlIHsKICAgICAgICBpZiAoZmx1c2ggfHwgdiA+IHJlY3QuZHgpIHYgPSByZWN0LmR4OwogICAgICAgIHdoaWxlICgrK2kgPCBuKSB7CiAgICAgICAgICBvID0gcm93W2ldOwogICAgICAgICAgby54ID0geDsKICAgICAgICAgIG8ueSA9IHk7CiAgICAgICAgICBvLmR4ID0gdjsKICAgICAgICAgIHkgKz0gby5keSA9IE1hdGgubWluKHJlY3QueSArIHJlY3QuZHkgLSB5LCB2ID8gcm91bmQoby5hcmVhIC8gdikgOiAwKTsKICAgICAgICB9CiAgICAgICAgby56ID0gZmFsc2U7CiAgICAgICAgby5keSArPSByZWN0LnkgKyByZWN0LmR5IC0geTsKICAgICAgICByZWN0LnggKz0gdjsKICAgICAgICByZWN0LmR4IC09IHY7CiAgICAgIH0KICAgIH0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9OwogICAgcmV0dXJuIGQzX2xheW91dF9oaWVyYXJjaHlSZWJpbmQodHJlZW1hcCwgaGllcmFyY2h5KTsKICB9OwogIGZ1bmN0aW9uIGQzX2xheW91dF90cmVlbWFwUGFkTnVsbChub2RlKSB7CiAgICByZXR1cm4gewogICAgICB4OiBub2RlLngsCiAgICAgIHk6IG5vZGUueSwKICAgICAgZHg6IG5vZGUuZHgsCiAgICAgIGR5OiBub2RlLmR5CiAgICB9OwogIH0KICBmdW5jdGlvbiBkM19sYXlvdXRfdHJlZW1hcFBhZChub2RlLCBwYWRkaW5nKSB7CiAgICB2YXIgeCA9IG5vZGUueCArIHBhZGRpbmdbM10sIHkgPSBub2RlLnkgKyBwYWRkaW5nWzBdLCBkeCA9IG5vZGUuZHggLSBwYWRkaW5nWzFdIC0gcGFkZGluZ1szXSwgZHkgPSBub2RlLmR5IC0gcGFkZGluZ1swXSAtIHBhZGRpbmdbMl07CiAgICBpZiAoZHggPCAwKSB7CiAgICAgIHggKz0gZHggLyAyOwogICAgICBkeCA9IDA7CiAgICB9CiAgICBpZiAoZHkgPCAwKSB7CiAgICAgIHkgKz0gZHkgLyAyOwogICAgICBkeSA9IDA7CiAgICB9CiAgICByZXR1cm4gewogICAgICB4OiB4LAogICAgICB5OiB5LAogICAgICBkeDogZHgsCiAgICAgIGR5OiBkeQogICAgfTsKICB9CiAgZDMucmFuZG9tID0gewogICAgbm9ybWFsOiBmdW5jdGlvbijCtSwgz4MpIHsKICAgICAgdmFyIG4gPSBhcmd1bWVudHMubGVuZ3RoOwogICAgICBpZiAobiA8IDIpIM+DID0gMTsKICAgICAgaWYgKG4gPCAxKSDCtSA9IDA7CiAgICAgIHJldHVybiBmdW5jdGlvbigpIHsKICAgICAgICB2YXIgeCwgeSwgcjsKICAgICAgICBkbyB7CiAgICAgICAgICB4ID0gTWF0aC5yYW5kb20oKSAqIDIgLSAxOwogICAgICAgICAgeSA9IE1hdGgucmFuZG9tKCkgKiAyIC0gMTsKICAgICAgICA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mludmVydCh4KSk7CiAgICB9OwogICAgc2NhbGUuZG9tYWluID0gZnVuY3Rpb24oeCkgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBkb21haW47CiAgICAgIHBvc2l0aXZlID0geFswXSA+PSAwOwogICAgICBsaW5lYXIuZG9tYWluKChkb21haW4gPSB4Lm1hcChOdW1iZXIpKS5tYXAobG9nKSk7CiAgICAgIHJldHVybiBzY2FsZTsKICAgIH07CiAgICBzY2FsZS5iYXNlID0gZnVuY3Rpb24oXykgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBiYXNlOwogICAgICBiYXNlID0gK187CiAgICAgIGxpbmVhci5kb21haW4oZG9tYWluLm1hcChsb2cpKTsKICAgICAgcmV0dXJuIHNjYWxlOwogICAgfTsKICAgIHNjYWxlLm5pY2UgPSBmdW5jdGlvbigpIHsKICAgICAgdmFyIG5pY2VkID0gZDNfc2NhbGVfbmljZShkb21haW4ubWFwKGxvZyksIHBvc2l0aXZlID8gTWF0aCA6IGQzX3NjYWxlX2xvZ05pY2VOZWdhdGl2ZSk7CiAgICAgIGxpbmVhci5kb21haW4obmljZWQpOwogICAgICBkb21haW4gPSBuaWNlZC5tYXAocG93KTsKICAgICAgcmV0dXJuIHNjYWxlOwogICAgfTsKICAgIHNjYWxlLnRpY2tzID0gZnVuY3Rpb24oKSB7CiAgICAgIHZhciBleHRlbnQgPSBkM19zY2FsZUV4dGVudChkb21haW4pLCB0aWNrcyA9IFtdLCB1ID0gZXh0ZW50WzBdLCB2ID0gZXh0ZW50WzFdLCBpID0gTWF0aC5mbG9vcihsb2codSkpLCBqID0gTWF0aC5jZWlsKGxvZyh2KSksIG4gPSBiYXNlICUgMSA/IDIgOiBiYXNlOwogICAgICBpZiAoaXNGaW5pdGUoaiAtIGkpKSB7CiAgICAgICAgaWYgKHBvc2l0aXZlKSB7CiAgICAgICAgICBmb3IgKDtpIDwgajsgaSsrKSBmb3IgKHZhciBrID0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tYmVyKSkubWFwKHBvd3ApKTsKICAgICAgcmV0dXJuIHNjYWxlOwogICAgfTsKICAgIHNjYWxlLnRpY2tzID0gZnVuY3Rpb24obSkgewogICAgICByZXR1cm4gZDNfc2NhbGVfbGluZWFyVGlja3MoZG9tYWluLCBtKTsKICAgIH07CiAgICBzY2FsZS50aWNrRm9ybWF0ID0gZnVuY3Rpb24obSwgZm9ybWF0KSB7CiAgICAgIHJldHVybiBkM19zY2FsZV9saW5lYXJUaWNrRm9ybWF0KGRvbWFpbiwgbSwgZm9ybWF0KTsKICAgIH07CiAgICBzY2FsZS5uaWNlID0gZnVuY3Rpb24obSkgewogICAgICByZXR1cm4gc2NhbGUuZG9tYWluKGQzX3NjYWxlX2xpbmVhck5pY2UoZG9tYWluLCBtKSk7CiAgICB9OwogICAgc2NhbGUuZXhwb25lbnQgPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIGV4cG9uZW50OwogICAgICBwb3dwID0gZDNfc2NhbGVfcG93UG93KGV4cG9uZW50ID0geCk7CiAgICAgIHBvd2IgPSBkM19zY2FsZV9wb3dQb3coMSAvIGV4cG9uZW50KTsKICAgICAgbGluZWFyLmRvbWFpbihkb21haW4ubWFwKHBvd3ApKTsKICAgICAgcmV0dXJuIHNjYWxlOwogICAgfTsKICAgIHNjYWxlLmNvcHkgPSBmdW5jdGlvbigpIHsKICAgICAgcmV0dXJuIGQzX3NjYWxlX3BvdyhsaW5lYXIuY29weSgpLCBleHBvbmVudCwgZG9tYWluKTsKICAgIH07CiAgICByZXR1cm4gZDNfc2NhbGVfbGluZWFyUmViaW5kKHNjYWxlLCBsaW5lYXIpOwogIH0KICBmdW5jdGlvbiBkM19zY2FsZV9wb3dQb3coZSkgewogICAgcmV0dXJuIGZ1bmN0aW9uKHgpIHsKICAgICAgcmV0dXJuIHggPCAwID8gLU1hdGgucG93KC14LCBlKSA6IE1hdGgucG93KHgsIGUpOwogICAgfTsKICB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pIHAxICo9IC0xOwogICAgICAgIGlmIChyMSkgcDEgPSBkM19hc2luKHJwIC8gcjEgKiBNYXRoLnNpbihhcCkpOwogICAgICAgIGlmIChyMCkgcDAgPSBkM19hc2luKHJwIC8gcjAgKiBNYXRoLnNpbihhcCkpOwogICAgICB9CiAgICAgIGlmIChyMSkgewogICAgICAgIHgwID0gcjEgKiBNYXRoLmNvcyhhMCArIHAxKTsKICAgICAgICB5MCA9IHIxICogTWF0aC5zaW4oYTAgKyBwMSk7CiAgICAgICAgeDEgPSByMSAqIE1hdGguY29zKGExIC0gcDEpOwogICAgICAgIHkxID0gcjEgKiBNYXRoLnNpbihhMSAtIHAxKTsKICAgICAgICB2YXIgbDEgPSBNYXRoLmFicyhhMSAtIGEwIC0gMiAqIHAxKSA8PSDPgCA/IDAgOiAxOwogICAgICAgIGlmIChwMSAmJiBkM19zdmdfYXJjU3dlZXAoeDAsIHkwLCB4MSwgeTEpID09PSBjdyBeIGwxKSB7CiAgICAgICAgICB2YXIgaDEgPSAoYTAgKyBhMSkgLyAyOwogICAgICAgICAgeDAgPSByMSAqIE1hdGguY29zKGgxKTsKICAgICAgICAgIHkwID0gcjEgKiBNYXRoLnNpbihoMSk7CiAgICAgICAgICB4MSA9IHkxID0gbnVsbDsKICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgeDAgPSB5MCA9IDA7CiAgICAgIH0KICAgICAgaWYgKHIwKSB7CiAgICAgICAgeDIgPSByMCAqIE1hdGguY29zKGExIC0gcDApOwogICAgICAgIHkyID0gcjAgKiBNYXRoLnNpbihhMSAtIHAwKTsKICAgICAgICB4MyA9IHIwICogTWF0aC5jb3MoYTAgKyBwMCk7CiAgICAgICAgeTMgPSByMCAqIE1hdGguc2luKGEwICsgcDApOwogICAgICAgIHZhciBsMCA9IE1hdGguYWJzKGEwIC0gYTEgKyAyICogcDApIDw9IM+AID8gMCA6IDE7CiAgICAgICAgaWYgKHAwICYmIGQzX3N2Z19hcmNTd2VlcCh4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gewogICAgaWYgKHRhbmdlbnRzLmxlbmd0aCA8IDEgfHwgcG9pbnRzLmxlbmd0aCAhPSB0YW5nZW50cy5sZW5ndGggJiYgcG9pbnRzLmxlbmd0aCAhPSB0YW5nZW50cy5sZW5ndGggKyAyKSB7CiAgICAgIHJldHVybiBkM19zdmdfbGluZUxpbmVhcihwb2ludHMpOwogICAgfQogICAgdmFyIHF1YWQgPSBwb2ludHMubGVuZ3RoICE9IHRhbmdlbnRzLmxlbmd0aCwgcGF0aCA9ICIiLCBwMCA9IHBvaW50c1swXSwgcCA9IHBvaW50c1sxXSwgdDAgPSB0YW5nZW50c1swXSwgdCA9IHQwLCBwaSA9IDE7CiAgICBpZiAocXVhZCkgewogICAgICBwYXRoICs9ICJRIiArIChwWzBdIC0gdDBbMF0gKiAyIC8gMykgKyAiLCIgKyAocFsxXSAtIHQwWzFdICogMiAvIDMpICsgIiwiICsgcFswXSArICIsIiArIHBbMV07CiAgICAgIHAwID0gcG9pbnRzWzFdOwogICAgICBwaSA9IDI7CiAgICB9CiAgICBpZiAodGFuZ2VudHMubGVuZ3RoID4gMSkgewogICAgICB0ID0gdGFuZ2VudHNbMV07CiAgICAgIHAgPSBwb2ludHNbcGldOwogICAgICBwaSsrOwogICAgICBwYXRoICs9ICJDIiArIChwMFswXSArIHQwWzBdKSArICIsIiArIChwMFsxXSArIHQwWzFdKSArICIsIiArIChwWzBdIC0gdFswXSkgKyAiLCIgKyAocFsxXSAtIHRbMV0pICsgIiwiICsgcFswXSArICIsIiArIHBbMV07CiAgICAgIGZvciAodmFyIGkgPSAyOyBpIDwgdGFuZ2VudHMubGVuZ3RoOyBpKyssIHBpKyspIHsKICAgICAgICBwID0gcG9pbnRzW3BpXTsKICAgICAgICB0ID0gdGFuZ2VudHNbaV07CiAgICAgICAgcGF0aCArPSAiUyIgKyAocFswXSAtIHRbMF0pICsgIiwiICsgKHBbMV0gLSB0WzFdKSArICIsIiArIHBbMF0gKyAiLCIgKyBwWzFdOwogICAgICB9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ICAgICAgICAgIHMgPSBkICogMyAvIE1hdGguc3FydChzKTsKICAgICAgICAgIG1baV0gPSBzICogYTsKICAgICAgICAgIG1baSArIDFdID0gcyAqIGI7CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICBpID0gLTE7CiAgICB3aGlsZSAoKytpIDw9IGopIHsKICAgICAgcyA9IChwb2ludHNbTWF0aC5taW4oaiwgaSArIDEpXVswXSAtIHBvaW50c1tNYXRoLm1heCgwLCBpIC0gMSldWzBdKSAvICg2ICogKDEgKyBtW2ldICogbVtpXSkpOwogICAgICB0YW5nZW50cy5wdXNoKFsgcyB8fCAwLCBtW2ldICogcyB8fCAwIF0pOwogICAgfQogICAgcmV0dXJuIHRhbmdlbnRzOwogIH0KICBmdW5jdGlvbiBkM19zdmdfbGluZU1vbm90b25lKHBvaW50cykgewogICAgcmV0dXJuIHBvaW50cy5sZW5ndGggPCAzID8gZDNfc3ZnX2xpbmVMaW5lYXIocG9pbnRzKSA6IHBvaW50c1swXSArIGQzX3N2Z19saW5lSGVybWl0ZShwb2ludHMsIGQzX3N2Z19saW5lTW9ub3RvbmVUYW5nZW50cyhwb2ludHMpKTsKICB9CiAgZDMuc3ZnLmxpbmUucmFkaWFsID0gZnVuY3Rpb24oKSB7CiAgICB2YXIgbGluZSA9IGQzX3N2Z19saW5lKGQzX3N2Z19saW5lUmFkaWFsKTsKICAgIGxpbmUucmFkaXVzID0gbGluZS54LCBkZWxldGUgbGluZS54OwogICAgbGluZS5hbmdsZSA9IGxpbmUueSwgZGVsZXRlIGxpbmUueTsKICAgIHJldHVybiBsaW5lOwogIH07CiAgZnVuY3Rpb24gZDNfc3ZnX2xpbmVSYWRpYWwocG9pbnRzKSB7CiAgICB2YXIgcG9pbnQsIGkgPSAtMSwgbiA9IHBvaW50cy5sZW5ndGgsIHIsIGE7CiAgICB3aGlsZSAoKytpIDwgbikgewogICAgICBwb2ludCA9IHBvaW50c1tpXTsKICAgICAgciA9IHBvaW50WzBdOwogICAgICBhID0gc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HRlbnNpb24pLCAiWiIpOwogICAgICB9CiAgICAgIHdoaWxlICgrK2kgPCBuKSB7CiAgICAgICAgaWYgKGRlZmluZWQuY2FsbCh0aGlzLCBkID0gZGF0YVtpXSwgaSkpIHsKICAgICAgICAgIHBvaW50czAucHVzaChbIHggPSArZngwLmNhbGwodGhpcywgZCwgaSksIHkgPSArZnkwLmNhbGwodGhpcywgZCwgaSkgXSk7CiAgICAgICAgICBwb2ludHMxLnB1c2goWyArZngxLmNhbGwodGhpcywgZCwgaSksICtmeTEuY2FsbCh0aGlzLCBkLCBpKSBdKTsKICAgICAgICB9IGVsc2UgaWYgKHBvaW50czAubGVuZ3RoKSB7CiAgICAgICAgICBzZWdtZW50KCk7CiAgICAgICAgICBwb2ludHMwID0gW107CiAgICAgICAgICBwb2ludHMxID0gW107CiAgICAgICAgfQogICAgICB9CiAgICAgIGlmIChwb2ludHMwLmxlbmd0aCkgc2VnbWVudCgpOwogICAgICByZXR1cm4gc2VnbWVudHMubGVuZ3RoID8gc2VnbWVudHMuam9pbigiIikgOiBudWxsOwogICAgfQogICAgYXJlYS54ID0gZnVuY3Rpb24oXykgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiB4MTsKICAgICAgeDAgPSB4MSA9IF87CiAgICAgIHJldHVybiBhcmVhOwogICAgfTsKICAgIGFyZWEueDAgPSBmdW5jdGlvbihfKSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIHgwOwogICAgICB4MCA9IF87CiAgICAgIHJldHVybiBhcmVhOwogICAgfTsKICAgIGFyZWEueDEgPSBmdW5jdGlvbihfKSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIHgxOwogICAgICB4MSA9IF87CiAgICAgIHJldHVybiBhcmVhOwogICAgfTsKICAgIGFyZWEueSA9IGZ1bmN0aW9uKF8pIHsKICAgICAgaWYgKCFhcmd1bWVudHMubGVuZ3RoKSByZXR1cm4geTE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ncm91cCA9IHRoaXNbal0sIGkgPSAwLCBuID0gZ3JvdXAubGVuZ3RoOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgaWYgKG5vZGUgPSBncm91cFtpXSkgewogICAgICAgICAgdHJhbnNpdGlvbiA9IG5vZGVbbnNdW2lkMF07CiAgICAgICAgICBkM190cmFuc2l0aW9uTm9kZShub2RlLCBpLCBucywgaWQxLCB7CiAgICAgICAgICAgIHRpbWU6IHRyYW5zaXRpb24udGltZSwKICAgICAgICAgICAgZWFzZTogdHJhbnNpdGlvbi5lYXNlLAogICAgICAgICAgICBkZWxheTogdHJhbnNpdGlvbi5kZWxheSArIHRyYW5zaXRpb24uZHVyYXRpb24sCiAgICAgICAgICAgIGR1cmF0aW9uOiB0cmFuc2l0aW9uLmR1cmF0aW9uCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgc3ViZ3JvdXAucHVzaChub2RlKTsKICAgICAgfQogICAgfQogICAgcmV0dXJuIGQzX3RyYW5zaXRpb24oc3ViZ3JvdXBzLCBucywgaWQxKTsKICB9OwogIGZ1bmN0aW9uIGQzX3RyYW5zaXRpb25OYW1lc3BhY2UobmFtZSkgewogICAgcmV0dXJuIG5hbWUgPT0gbnVsbCA/ICJfX3RyYW5zaXRpb25fXyIgOiAiX190cmFuc2l0aW9uXyIgKyBuYW1lICsgIl9fIjsKICB9CiAgZnVuY3Rpb24gZDNfdHJhbnNpdGlvbk5vZGUobm9kZSwgaSwgbnMsIGlkLCBpbmhlcml0KSB7CiAgICB2YXIgbG9jayA9IG5vZGVbbnNdIHx8IChub2RlW25zXSA9IHsKICAgICAgYWN0aXZlOiAwLAogICAgICBjb3VudDogMAogICAgfSksIHRyYW5zaXRpb24gPSBsb2NrW2lkXTsKICAgIGlmICghdHJhbnNpdGlvbikgewogICAgICB2YXIgdGltZSA9IGluaGVyaXQudGltZTsKICAgICAgdHJhbnNpdGlvbiA9IGxvY2tbaWRdID0gewogICAgICAgIHR3ZWVuOiBuZXcgZDNfTWFwKCksCiAgICAgICAgdGltZTogdGltZSwKICAgICAgICBkZWxheTogaW5oZXJpdC5kZWxheSwKICAgICAgICBkdXJhdGlvbjogaW5oZXJpdC5kdXJhdGlvbiwKICAgICAgICBlYXNlOiBpbmhlcml0LmVhc2UsCiAgICAgICAgaW5kZXg6IGkKICAgICAgfTsKICAgICAgaW5oZXJpdCA9IG51bGw7CiAgICAgICsrbG9jay5jb3VudDsKICAgICAgZDMudGltZXIoZnVuY3Rpb24oZWxhcHNlZCkgewogICAgICAgIHZhciBkZWxheSA9IHRyYW5zaXRpb24uZGVsYXksIGR1cmF0aW9uLCBlYXNlLCB0aW1lciA9IGQzX3RpbWVyX2FjdGl2ZSwgdHdlZW5lZCA9IFtdOwogICAgICAgIHRpbWVyLnQgPSBkZWxheSArIHRpbWU7CiAgICAgICAgaWYgKGRlbGF5IDw9IGVsYXBzZWQpIHJldHVybiBzdGFydChlbGFwc2VkIC0gZGVsYXkpOwogICAgICAgIHRpbWVyLmMgPSBzdGFydDsKICAgICAgICBmdW5jdGlvbiBzdGFydChlbGFwc2VkKSB7CiAgICAgICAgICBpZiAobG9jay5hY3RpdmUgPiBpZCkgcmV0dXJuIHN0b3AoKTsKICAgICAgICAgIHZhciBhY3RpdmUgPSBsb2NrW2xvY2suYWN0aXZlXTsKICAgICAgICAgIGlmIChhY3RpdmUpIHsKICAgICAgICAgICAgLS1sb2NrLmNvdW50OwogICAgICAgICAgICBkZWxldGUgbG9ja1tsb2NrLmFjdGl2ZV07CiAgICAgICAgICAgIGFjdGl2ZS5ldmVudCAmJiBhY3RpdmUuZXZlbnQuaW50ZXJydXB0LmNhbGwobm9kZSwgbm9kZS5fX2RhdGFfXywgYWN0aXZlLmluZGV4KTsKICAgICAgICAgIH0KICAgICAgICAgIGxvY2suYWN0aXZlID0gaWQ7CiAgICAgICAgICB0cmFuc2l0aW9uLmV2ZW50ICYmIHRyYW5zaXRpb24uZXZlbnQuc3RhcnQuY2FsbChub2RlLCBub2RlLl9fZGF0YV9fLCBpKTsKICAgICAgICAgIHRyYW5zaXRpb24udHdlZW4uZm9yRWFjaChmdW5jdGlvbihrZXksIHZhbHVlKSB7CiAgICAgICAgICAgIGlmICh2YWx1ZSA9IHZhbHVlLmNhbGwobm9kZSwgbm9kZS5fX2RhdGFfXywgaSkpIHsKICAgICAgICAgICAgICB0d2VlbmVkLnB1c2godmFsdWUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9KTsKICAgICAgICAgIGVhc2UgPSB0cmFuc2l0aW9uLmVhc2U7CiAgICAgICAgICBkdXJhdGlvbiA9IHRyYW5zaXRpb24uZHVyYXRpb247CiAgICAgICAgICBkMy50aW1lcihmdW5jdGlvbigpIHsKICAgICAgICAgICAgdGltZXIuYyA9IHRpY2soZWxhcHNlZCB8fCAxKSA/IGQzX3RydWUgOiB0aWNrOwogICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICAgIH0sIDAsIHRpbWUpOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiB0aWNrKGVsYXBzZWQpIHsKICAgICAgICAgIGlmIChsb2NrLmFjdGl2ZSAhPT0gaWQpIHJldHVybiAxOwogICAgICAgICAgdmFyIHQgPSBlbGFwc2VkIC8gZHVyYXRpb24sIGUgPSBlYXNlKHQpLCBuID0gdHdlZW5lZC5sZW5ndGg7CiAgICAgICAgICB3aGlsZSAobiA+IDApIHsKICAgICAgICAgICAgdHdlZW5lZFstLW5dLmNhbGwobm9kZSwgZSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodCA+PSAxKSB7CiAgICAgICAgICAgIHRyYW5zaXRpb24uZXZlbnQgJiYgdHJhbnNpdGlvbi5ldmVudC5lbmQuY2FsbChub2RlLCBub2RlLl9fZGF0YV9fLCBpKTsKICAgICAgICAgICAgcmV0dXJuIHN0b3AoKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gc3RvcCgpIHsKICAgICAgICAgIGlmICgtLWxvY2suY291bnQpIGRlbGV0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gKiB0aWNrU3BhY2luZyk7CiAgICAgICAgaWYgKHNjYWxlMS5yYW5nZUJhbmQpIHsKICAgICAgICAgIHZhciB4ID0gc2NhbGUxLCBkeCA9IHgucmFuZ2VCYW5kKCkgLyAyOwogICAgICAgICAgc2NhbGUwID0gc2NhbGUxID0gZnVuY3Rpb24oZCkgewogICAgICAgICAgICByZXR1cm4geChkKSArIGR4OwogICAgICAgICAgfTsKICAgICAgICB9IGVsc2UgaWYgKHNjYWxlMC5yYW5nZUJhbmQpIHsKICAgICAgICAgIHNjYWxlMCA9IHNjYWxlMTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGlja0V4aXQuY2FsbCh0aWNrVHJhbnNmb3JtLCBzY2FsZTEsIHNjYWxlMCk7CiAgICAgICAgfQogICAgICAgIHRpY2tFbnRlci5jYWxsKHRpY2tUcmFuc2Zvcm0sIHNjYWxlMCwgc2NhbGUxKTsKICAgICAgICB0aWNrVXBkYXRlLmNhbGwodGlja1RyYW5zZm9ybSwgc2NhbGUxLCBzY2FsZTEpOwogICAgICB9KTsKICAgIH0KICAgIGF4aXMuc2NhbGUgPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIHNjYWxlOwogICAgICBzY2FsZSA9IHg7CiAgICAgIHJldHVybiBheGlzOwogICAgfTsKICAgIGF4aXMub3JpZW50ID0gZnVuY3Rpb24oeCkgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBvcmllbnQ7CiAgICAgIG9yaWVudCA9IHggaW4gZDNfc3ZnX2F4aXNPcmllbnRzID8geCArICIiIDogZDNfc3ZnX2F4aXNEZWZhdWx0T3JpZW50OwogICAgICByZXR1cm4gYXhpczsKICAgIH07CiAgICBheGlzLnRpY2tzID0gZnVuY3Rpb24oKSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIHRpY2tBcmd1bWVudHNfOwogICAgICB0aWNrQXJndW1lbnRzXyA9IGFyZ3VtZW50czsKICAgICAgcmV0dXJuIGF4aXM7CiAgICB9OwogICAgYXhpcy50aWNrVmFsdWVzID0gZnVuY3Rpb24oeCkgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiB0aWNrVmFsdWVzOwogICAgICB0aWNrVmFsdWVzID0geDsKICAgICAgcmV0dXJuIGF4aXM7CiAgICB9OwogICAgYXhpcy50aWNrRm9ybWF0ID0gZnVuY3Rpb24oeCkgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiB0aWNrRm9ybWF0XzsKICAgICAgdGlja0Zvcm1hdF8gPSB4OwogICAgICByZXR1cm4gYXhpczsKICAgIH07CiAgICBheGlzLnRpY2tTaXplID0gZnVuY3Rpb24oeCkgewogICAgICB2YXIgbiA9IGFyZ3VtZW50cy5sZW5ndGg7CiAgICAgIGlmICghbikgcmV0dXJuIGlubmVyVGlja1NpemU7CiAgICAgIGlubmVyVGlja1NpemUgPSAreDsKICAgICAgb3V0ZXJUaWNrU2l6ZSA9ICthcmd1bWVudHNbbiAtIDFdOwogICAgICByZXR1cm4gYXhpczsKICAgIH07CiAgICBheGlzLmlubmVyVGlja1NpemUgPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgcmV0dXJuIGlubmVyVGlja1NpemU7CiAgICAgIGlubmVyVGlja1NpemUgPSAreDsKICAgICAgcmV0dXJuIGF4aXM7CiAgICB9OwogICAgYXhpcy5vdXRlclRpY2tTaXplID0gZnVuY3Rpb24oeCkgewogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHJldHVybiBvdXRlclRpY2tTaXplOwogICAgICBvdXRlclRpY2tTaXplID0gK3g7CiAgICAgIHJldHVybiBheGlzOwogICAgfTsKICAgIGF4aXMudGlja1BhZGRpbmcgPSBmdW5jdGlvbih4KSB7CiAgICAgIGlmICghYXJndW1lbnRzLmxlbmd0aCkgc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cmFuZ2VbMF0pOwogICAgICAgICAgcmVkcmF3WShnVXBkYXRlKTsKICAgICAgICB9CiAgICAgICAgcmVkcmF3KGdVcGRhdGUpOwogICAgICB9KTsKICAgIH0KICAgIGJydXNoLmV2ZW50ID0gZnVuY3Rpb24oZykgewogICAgICBnLmVhY2goZnVuY3Rpb24oKSB7CiAgICAgICAgdmFyIGV2ZW50XyA9IGV2ZW50Lm9mKHRoaXMsIGFyZ3VtZW50cyksIGV4dGVudDEgPSB7CiAgICAgICAgICB4OiB4RXh0ZW50LAogICAgICAgICAgeTogeUV4dGVudCwKICAgICAgICAgIGk6IHhFeHRlbnREb21haW4sCiAgICAgICAgICBqOiB5RXh0ZW50RG9tYWluCiAgICAgICAgfSwgZXh0ZW50MCA9IHRoaXMuX19jaGFydF9fIHx8IGV4dGVudDE7CiAgICAgICAgdGhpcy5fX2NoYXJ0X18gPSBleHRlbnQxOwogICAgICAgIGlmIChkM190cmFuc2l0aW9uSW5oZXJpdElkKSB7CiAgICAgICAgICBkMy5zZWxlY3QodGhpcykudHJhbnNpdGlvbigpLmVhY2goInN0YXJ0LmJydXNoIiwgZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHhFeHRlbnREb21haW4gPSBleHRlbnQwLmk7CiAgICAgICAgICAgIHlFeHRlbnREb21haW4gPSBleHRlbnQwLmo7CiAgICAgICAgICAgIHhFeHRlbnQgPSBleHRlbnQwLng7CiAgICAgICAgICAgIHlFeHRlbnQgPSBleHRlbnQwLnk7CiAgICAgICAgICAgIGV2ZW50Xyh7CiAgICAgICAgICAgICAgdHlwZTogImJydXNoc3RhcnQiCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfSkudHdlZW4oImJydXNoOmJydXNoIiwgZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHZhciB4aSA9IGQzX2ludGVycG9sYXRlQXJyYXkoeEV4dGVudCwgZXh0ZW50MS54KSwgeWkgPSBkM19pbnRlcnBvbGF0ZUFycmF5KHlFeHRlbnQsIGV4dGVudDEueSk7CiAgICAgICAgICAgIHhFeHRlbnREb21haW4gPSB5RXh0ZW50RG9tYWluID0gbnVsbDsKICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKHQpIHsKICAgICAgICAgICAgICB4RXh0ZW50ID0gZXh0ZW50MS54ID0geGkodCk7CiAgICAgICAgICAgICAgeUV4dGVudCA9IGV4dGVudDEueSA9IHlpKHQpOwogICAgICAgICAgICAgIGV2ZW50Xyh7CiAgICAgICAgICAgICAgICB0eXBlOiAiYnJ1c2giLAogICAgICAgICAgICAgICAgbW9kZTogInJlc2l6ZSIKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfTsKICAgICAgICAgIH0pLmVhY2goImVuZC5icnVzaCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICB4RXh0ZW50RG9tYWluID0gZXh0ZW50MS5pOwogICAgICAgICAgICB5RXh0ZW50RG9tYWluID0gZXh0ZW50MS5qOwogICAgICAgICAgICBldmVudF8oewogICAgICAgICAgICAgIHR5cGU6ICJicnVzaCIsCiAgICAgICAgICAgICAgbW9kZTogInJlc2l6ZSIKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGV2ZW50Xyh7CiAgICAgICAgICAgICAgdHlwZTogImJydXNoZW5kIgogICAgICAgICAgICB9KTsKICAgICAgICAgIH0pOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBldmVudF8oewogICAgICAgICAgICB0eXBlOiAiYnJ1c2hzdGFydCIKICAgICAgICAgIH0pOwogICAgICAgICAgZXZlbnRfKHsKICAgICAgICAgICAgdHlwZTogImJydXNoIiwKICAgICAgICAgICAgbW9kZTogInJlc2l6ZSIKICAgICAgICAgIH0pOwogICAgICAgICAgZXZlbnRfKHsKICAgICAgICAgICAgdHlwZTogImJydXNoZW5kIgogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICB9KTsKICAgIH07CiAgICBmdW5jdGlvbiByZWRyYXcoZykgewogICAgICBnLnNlbGVjdEFsbCgiLnJlc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G9pbnRlci1ldmVudHMiLCAibm9uZSIpLnNlbGVjdEFsbCgiLnJlc2l6ZSIpLnN0eWxlKCJkaXNwbGF5IiwgbnVsbCk7CiAgICAgIGQzLnNlbGVjdCgiYm9keSIpLnN0eWxlKCJjdXJzb3IiLCBldmVudFRhcmdldC5zdHlsZSgiY3Vyc29yIikpOwogICAgICBldmVudF8oewogICAgICAgIHR5cGU6ICJicnVzaHN0YXJ0IgogICAgICB9KTsKICAgICAgYnJ1c2htb3ZlKCk7CiAgICAgIGZ1bmN0aW9uIGtleWRvd24oKSB7CiAgICAgICAgaWYgKGQzLmV2ZW50LmtleUNvZGUgPT0gMzIpIHsKICAgICAgICAgIGlmICghZHJhZ2dpbmcpIHsKICAgICAgICAgICAgY2VudGVyID0gbnVsbDsKICAgICAgICAgICAgb3JpZ2luWzBdIC09IHhFeHRlbnRbMV07CiAgICAgICAgICAgIG9yaWdpblsxXSAtPSB5RXh0ZW50WzFdOwogICAgICAgICAgICBkcmFnZ2luZyA9IDI7CiAgICAgICAgICB9CiAgICAgICAgICBkM19ldmVudFByZXZlbnREZWZhdWx0KCk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGtleXVwKCkgewogICAgICAgIGlmIChkMy5ldmVudC5rZXlDb2RlID09IDMyICYmIGRyYWdnaW5nID09IDIpIHsKICAgICAgICAgIG9yaWdpblswXSArPSB4RXh0ZW50WzFdOwogICAgICAgICAgb3JpZ2luWzFdICs9IHlFeHRlbnRbMV07CiAgICAgICAgICBkcmFnZ2luZyA9IDA7CiAgICAgICAgICBkM19ldmVudFByZXZlbnREZWZhdWx0KCk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJydXNobW92ZSgpIHsKICAgICAgICB2YXIgcG9pbnQgPSBkMy5tb3VzZSh0YXJnZXQpLCBtb3ZlZCA9IGZhbHNlOwogICAgICAgIGlmIChvZmZzZXQpIHsKICAgICAgICAgIHBvaW50WzBdICs9IG9mZnNldFswXTsKICAgICAgICAgIHBvaW50WzFdICs9IG9mZnNldFsxXTsKICAgICAgICB9CiAgICAgICAgaWYgKCFkcmFnZ2luZykgewogICAgICAgICAgaWYgKGQzLmV2ZW50LmFsdEtleSkgewogICAgICAgICAgICBpZiAoIWNlbnRlcikgY2VudGVyID0gWyAoeEV4dGVudFswXSArIHhFeHRlbnRbMV0pIC8gMiwgKHlFeHRlbnRbMF0gKyB5RXh0ZW50WzFdKSAvIDIgXTsKICAgICAgICAgICAgb3JpZ2luWzBdID0geEV4dGVudFsrKHBvaW50WzBdIDwgY2VudGVyWzBdKV07CiAgICAgICAgICAgIG9yaWdpblsxXSA9IHlFeHRlbnRbKyhwb2ludFsxXSA8IGNlbnRlclsxXSldOwogICAgICAgICAgfSBlbHNlIGNlbnRlciA9IG51bGw7CiAgICAgICAgfQogICAgICAgIGlmIChyZXNpemluZ1ggJiYgbW92ZTEocG9pbnQsIHgsIDApKSB7CiAgICAgICAgICByZWRyYXdYKGcpOwogICAgICAgICAgbW92ZWQgPSB0cnVlOwogICAgICAgIH0KICAgICAgICBpZiAocmVzaXppbmdZICYmIG1vdmUxKHBvaW50LCB5LCAxKSkgewogICAgICAgICAgcmVkcmF3WShnKTsKICAgICAgICAgIG1vdmVkID0gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgaWYgKG1vdmVkKSB7CiAgICAgICAgICByZWRyYXcoZyk7CiAgICAgICAgICBldmVudF8oewogICAgICAgICAgICB0eXBlOiAiYnJ1c2giLAogICAgICAgICAgICBtb2RlOiBkcmFnZ2luZyA/ICJtb3ZlIiA6ICJyZXNpemUiCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gbW92ZTEocG9pbnQsIHNjYWxlLCBpKSB7CiAgICAgICAgdmFyIHJhbmdlID0gZDNfc2NhbGVSYW5nZShzY2FsZSksIHIwID0gcmFuZ2VbMF0sIHIxID0gcmFuZ2VbMV0sIHBvc2l0aW9uID0gb3JpZ2luW2ldLCBleHRlbnQgPSBpID8geUV4dGVudCA6IHhFeHRlbnQsIHNpemUgPSBleHRlbnRbMV0gLSBleHRlbnRbMF0sIG1pbiwgbWF4OwogICAgICAgIGlmIChkcmFnZ2luZykgewogICAgICAgICAgcjAgLT0gcG9zaXRpb247CiAgICAgICAgICByMSAtPSBzaXplICsgcG9zaXRpb247CiAgICAgICAgfQogICAgICAgIG1pbiA9IChpID8geUNsYW1wIDogeENsYW1wKSA/IE1hdGgubWF4KHIwLCBNYXRoLm1pbihyMSwgcG9pbnRbaV0pKSA6IHBvaW50W2ldOwogICAgICAgIGlmIChkcmFnZ2luZykgewogICAgICAgICAgbWF4ID0gKG1pbiArPSBwb3NpdGlvbikgKyBzaXplOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoY2VudGVyKSBwb3NpdGlvbiA9IE1hdGgubWF4KHIwLCBNYXRoLm1pbihyMSwgMiAqIGNlbnRlcltpXSAtIG1pbikpOwogICAgICAgICAgaWYgKHBvc2l0aW9uIDwgbWluKSB7CiAgICAgICAgICAgIG1heCA9IG1pbjsKICAgICAgICAgICAgbWluID0gcG9zaXRpb247CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXggPSBwb3NpdGlvbjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGV4dGVudFswXSAhPSBtaW4gfHwgZXh0ZW50WzFdICE9IG1heCkgewogICAgICAgICAgaWYgKGkpIHlFeHRlbnREb21haW4gPSBudWxsOyBlbHNlIHhFeHRlbnREb21haW4gPSBudWxsOwogICAgICAgICAgZXh0ZW50WzBdID0gbWluOwogICAgICAgICAgZXh0ZW50WzFdID0gbWF4OwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJydXNoZW5kKCkgewogICAgICAgIGJydXNobW92ZSgpOwogICAgICAgIGcuc3R5bGUoInBvaW50ZXItZXZlbnRzIiwgImFsbCIpLnNlbGVj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HhDbGFtcCA9ICEhelswXSwgeUNsYW1wID0gISF6WzFdOyBlbHNlIGlmICh4KSB4Q2xhbXAgPSAhIXo7IGVsc2UgaWYgKHkpIHlDbGFtcCA9ICEhejsKICAgICAgcmV0dXJuIGJydXNoOwogICAgfTsKICAgIGJydXNoLmV4dGVudCA9IGZ1bmN0aW9uKHopIHsKICAgICAgdmFyIHgwLCB4MSwgeTAsIHkxLCB0OwogICAgICBpZiAoIWFyZ3VtZW50cy5sZW5ndGgpIHsKICAgICAgICBpZiAoeCkgewogICAgICAgICAgaWYgKHhFeHRlbnREb21haW4pIHsKICAgICAgICAgICAgeDAgPSB4RXh0ZW50RG9tYWluWzBdLCB4MSA9IHhFeHRlbnREb21haW5bMV07CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB4MCA9IHhFeHRlbnRbMF0sIHgxID0geEV4dGVudFsxXTsKICAgICAgICAgICAgaWYgKHguaW52ZXJ0KSB4MCA9IHguaW52ZXJ0KHgwKSwgeDEgPSB4LmludmVydCh4MSk7CiAgICAgICAgICAgIGlmICh4MSA8IHgwKSB0ID0geDAsIHgwID0geDEsIHgxID0gdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHkpIHsKICAgICAgICAgIGlmICh5RXh0ZW50RG9tYWluKSB7CiAgICAgICAgICAgIHkwID0geUV4dGVudERvbWFpblswXSwgeTEgPSB5RXh0ZW50RG9tYWluWzFdOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgeTAgPSB5RXh0ZW50WzBdLCB5MSA9IHlFeHRlbnRbMV07CiAgICAgICAgICAgIGlmICh5LmludmVydCkgeTAgPSB5LmludmVydCh5MCksIHkxID0geS5pbnZlcnQoeTEpOwogICAgICAgICAgICBpZiAoeTEgPCB5MCkgdCA9IHkwLCB5MCA9IHkxLCB5MSA9IHQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB4ICYmIHkgPyBbIFsgeDAsIHkwIF0sIFsgeDEsIHkxIF0gXSA6IHggPyBbIHgwLCB4MSBdIDogeSAmJiBbIHkwLCB5MSBdOwogICAgICB9CiAgICAgIGlmICh4KSB7CiAgICAgICAgeDAgPSB6WzBdLCB4MSA9IHpbMV07CiAgICAgICAgaWYgKHkpIHgwID0geDBbMF0sIHgxID0geDFbMF07CiAgICAgICAgeEV4dGVudERvbWFpbiA9IFsgeDAsIHgxIF07CiAgICAgICAgaWYgKHguaW52ZXJ0KSB4MCA9IHgoeDApLCB4MSA9IHgoeDEpOwogICAgICAgIGlmICh4MSA8IHgwKSB0ID0geDAsIHgwID0geDEsIHgxID0gdDsKICAgICAgICBpZiAoeDAgIT0geEV4dGVudFswXSB8fCB4MSAhPSB4RXh0ZW50WzFdKSB4RXh0ZW50ID0gWyB4MCwgeDEgXTsKICAgICAgfQogICAgICBpZiAoeSkgewogICAgICAgIHkwID0gelswXSwgeTEgPSB6WzFdOwogICAgICAgIGlmICh4KSB5MCA9IHkwWzFdLCB5MSA9IHkxWzFdOwogICAgICAgIHlFeHRlbnREb21haW4gPSBbIHkwLCB5MSBdOwogICAgICAgIGlmICh5LmludmVydCkgeTAgPSB5KHkwKSwgeTEgPSB5KHkxKTsKICAgICAgICBpZiAoeTEgPCB5MCkgdCA9IHkwLCB5MCA9IHkxLCB5MSA9IHQ7CiAgICAgICAgaWYgKHkwICE9IHlFeHRlbnRbMF0gfHwgeTEgIT0geUV4dGVudFsxXSkgeUV4dGVudCA9IFsgeTAsIHkxIF07CiAgICAgIH0KICAgICAgcmV0dXJuIGJydXNoOwogICAgfTsKICAgIGJydXNoLmNsZWFyID0gZnVuY3Rpb24oKSB7CiAgICAgIGlmICghYnJ1c2guZW1wdHkoKSkgewogICAgICAgIHhFeHRlbnQgPSBbIDAsIDAgXSwgeUV4dGVudCA9IFsgMCwgMCBdOwogICAgICAgIHhFeHRlbnREb21haW4gPSB5RXh0ZW50RG9tYWluID0gbnVsbDsKICAgICAgfQogICAgICByZXR1cm4gYnJ1c2g7CiAg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19qc29uKHJlcXVlc3QpIHsKICAgIHJldHVybiBKU09OLnBhcnNlKHJlcXVlc3QucmVzcG9uc2VUZXh0KTsKICB9CiAgZDMuaHRtbCA9IGZ1bmN0aW9uKHVybCwgY2FsbGJhY2spIHsKICAgIHJldHVybiBkM194aHIodXJsLCAidGV4dC9odG1sIiwgZDNfaHRtbCwgY2FsbGJhY2spOwogIH07CiAgZnVuY3Rpb24gZDNfaHRtbChyZXF1ZXN0KSB7CiAgICB2YXIgcmFuZ2UgPSBkM19kb2N1bWVudC5jcmVhdGVSYW5nZSgpOwogICAgcmFuZ2Uuc2VsZWN0Tm9kZShkM19kb2N1bWVudC5ib2R5KTsKICAgIHJldHVybiByYW5nZS5jcmVhdGVDb250ZXh0dWFsRnJhZ21lbnQocmVxdWVzdC5yZXNwb25zZVRleHQpOwogIH0KICBkMy54bWwgPSBkM194aHJUeXBlKGZ1bmN0aW9uKHJlcXVlc3QpIHsKICAgIHJldHVybiByZXF1ZXN0LnJlc3BvbnNlWE1MOwogIH0pOwogIGlmICh0eXBlb2YgZGVmaW5lID09PSAiZnVuY3Rpb24iICYmIGRlZmluZS5hbWQpIGRlZmluZShkMyk7IGVsc2UgaWYgKHR5cGVvZiBtb2R1bGUgPT09ICJvYmplY3QiICYmIG1vZHVsZS5leHBvcnRzKSBtb2R1bGUuZXhwb3J0cyA9IGQzOwogIHRoaXMuZDMgPSBkMzsKfSgpOw=="></script>
<script src="data:application/x-javascript;base64,SFRNTFdpZGdldHMud2lkZ2V0KHsKCiAgbmFtZTogJ2J1YmJsZXMnLAoKICB0eXBlOiAnb3V0cHV0JywKICAKICByZW5kZXJPbk51bGxWYWx1ZTogdHJ1ZSwKCiAgaW5pdGlhbGl6ZTogZnVuY3Rpb24oZWwsIHdpZHRoLCBoZWlnaHQpIHsKCiAgICB2YXIgYnViYmxlID0gZDMubGF5b3V0LnBhY2soKQogICAgICAgIC5zb3J0KG51bGwpCiAgICAgICAgLnBhZGRpbmcoMS41KTsKICAgIAog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vdmUoKQogICAgICAgIC5zdHlsZSgib3BhY2l0eSIsIDApOwoKICAgIC8vIFVwZGF0ZSBhbGwgbmV3IGFuZCByZW1haW5pbmcgbm9kZXMKCiAgICBub2RlLnRyYW5zaXRpb24oKQogICAgICAgIC5zdHlsZSgib3BhY2l0eSIsIDEpCiAgICAgICAgLmF0dHIoInRyYW5zZm9ybSIsIGZ1bmN0aW9uKGQpIHsKICAgICAgICAgIHJldHVybiAidHJhbnNsYXRlKCIgKyBkLnggKyAiLCIgKyBkLnkgKyAiKSI7CiAgICAgICAgfSk7CgogICAgbm9kZS5zZWxlY3QoInRpdGxlIikKICAgICAgICAudGV4dChmdW5jdGlvbihkKSB7IHJldHVybiBkLnRvb2x0aXA7IH0pOwoKICAgIG5vZGUuc2VsZWN0KCJjaXJjbGUiKS50cmFuc2l0aW9uKCkKICAgICAgICAuYXR0cigiciIsIGZ1bmN0aW9uKGQpIHsgcmV0dXJuIGQucjsgfSkKICAgICAgICAuc3R5bGUoImZpbGwiLCBmdW5jdGlvbihkKSB7IHJldHVybiBkLmNvbG9yOyB9KTsKCiAgICBub2RlLnNlbGVjdCgidGV4dCIpCiAgICAgICAgLnRleHQoZnVuY3Rpb24oZCkgeyByZXR1cm4gZC5sYWJlbDsgfSkKICAgICAgICAuc3R5bGUoImZpbGwiLCBmdW5jdGlvbihkKSB7IHJldHVybiBkLnRleHRDb2xvcjsgfSk7CiAgfSwKCiAgcmVzaXplOiBmdW5jdGlvbihlbCwgd2lkdGgsIGhlaWdodCwgaW5zdGFuY2UpIHsKICAgIC8vIFJlLXJlbmRlciB0aGUgcHJldmlvdXMgdmFsdWUsIGlmIGFueQogICAgaWYgKGluc3RhbmNlLmxhc3RWYWx1ZSkgewogICAgICB0aGlzLnJlbmRlclZhbHVlKGVsLCBpbnN0YW5jZS5sYXN0VmFsdWUsIGluc3RhbmNlKTsKICAgIH0KICB9Cgp9KTsK"></script>
</head>
<body style="background-color:white;">
<div id="htmlwidget_container">
<div id="htmlwidget-9665" class="bubbles html-widget" style="width:1200px;height:800px;">
</div>
</div>
<script type="application/json" data-for="htmlwidget-9665">{"x":{"value":["1","1","1","1","1","1","1","1","1","1","1","1","2","2","2","2","2","2","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","3","4","4","4","4","4","4","4"],"label":["Afrikaans","Catalan","Danish","Dutch","French","Galician","Italian","Norwegian","Portuguese","Romanian","Spanish","Swedish","German","Indonesian","Javanese","Jumieka","Malay","Swahili","Albanian","Amharic","Armenian","Azerbaijani","Belarusian","Bengali","Bosnian","Bulgarian","Burmese","Cebuano","Croatian","Czech","Dzongkha","Estonian","Finnish","Georgian","Greek","Gujarati","Hebrew","Hindi","Hungarian","Icelandic","Ilocano","Irish","Kannada","Kazakh","Kurdish","Kyrgyz","Khmer","Lao","Latvian","Lithuanian","Macedonian","Marathi","Mongolian","Nepali","Pashto","Persian(Dari-Farsi-Tajik)","Polish","Punjabi","Russian","Serbian","Sinhalese","Slovak","Slovenian","Somali","Tagalog","Tamil","Tanchangya","Telugu","Tetum","Thai","Turkish","Turkmen","Ukrainian","Urdu","Uzbek","Vietnamese","Xhosa","Zulu","Arabic","Cantonese","Japanese","Korean","Mandarin","Taiwanese","Wu"],"tooltip":["575-600 hours","575-600 hours","575-600 hours","575-600 hours","575-600 hours","575-600 hours","575-600 hours","575-600 hours","575-600 hours","575-600 hours","575-600 hours","575-600 hours","750-900 hours","750-900 hours","750-900 hours","750-900 hours","750-900 hours","750-900 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","1100 hours","2200 hours+","2200 hours+","2200 hours+","2200 hours+","2200 hours+","2200 hours+","2200 hours+"],"color":["red","red","red","red","red","red","red","red","red","red","red","red","#80FF00","#80FF00","#80FF00","#80FF00","#80FF00","#80FF00","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","cyan","#8000FF","#8000FF","#8000FF","#8000FF","#8000FF","#8000FF","#8000FF"],"textColor":["#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333","#33333"]},"evals":[],"jsHooks":[]}</script>
<script type="application/htmlwidget-sizing" data-for="htmlwidget-9665">{"viewer":{"width":1200,"height":800,"padding":15,"fill":false},"browser":{"width":1200,"height":800,"padding":40,"fill":false}}</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment