-
Notifications
You must be signed in to change notification settings - Fork 114
/
index.html
58 lines (57 loc) · 214 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<html>
<head>
</head>
<body>
<div class="bonito-fragment" id="dd71e922-4763-457a-9553-9c711838578d" data-jscall-id="root">
<div>
<script src="http://localhost:9385/assets/2501eda11ea02b31664bfd5ec85286c4d168c355-Bonito.bundled.js" type="module"></script>
<style></style>
<div></div>
</div>
<div>
<script type="module"> Bonito.lock_loading(() => {
return Bonito.fetch_binary('http://localhost:9385/assets/d5ecb22b270d6708b5ad92a04f49eec8c05d0e43-11200659735366302283.bin').then(msgs=> Bonito.init_session('dd71e922-4763-457a-9553-9c711838578d', msgs, 'root'));
})
</script>
<script type="module"> import('http://localhost:9385/assets/fa24f420cac57c8018c442b33aff9b91b5e432cf-Websocket.bundled.js').then(WS => {
WS.setup_connection({proxy_url: 'http://localhost:9385', session_id: 'dd71e922-4763-457a-9553-9c711838578d', compression_enabled: false})
})
</script>
<div style="width: 100%; height: 100%" data-jscall-id="1">
<canvas style="display: block" data-jscall-id="2" tabindex="0"></canvas>
</div>
</div>
</div><div class="bonito-fragment" id="05267e6a-1d5f-413b-a7a0-b72a68577846" data-jscall-id="root">
<div>
<script src="http://localhost:9385/assets/2501eda11ea02b31664bfd5ec85286c4d168c355-Bonito.bundled.js" type="module"></script>
<style></style>
<div></div>
</div>
<div>
<script type="module"> Bonito.lock_loading(() => {
return Bonito.fetch_binary('http://localhost:9385/assets/56580d1d963b36009a564223ea751f0f36ecc7fa-12401213583129004171.bin').then(msgs=> Bonito.init_session('05267e6a-1d5f-413b-a7a0-b72a68577846', msgs, 'root'));
})
</script>
<script type="module"> import('http://localhost:9385/assets/fa24f420cac57c8018c442b33aff9b91b5e432cf-Websocket.bundled.js').then(WS => {
WS.setup_connection({proxy_url: 'http://localhost:9385', session_id: '05267e6a-1d5f-413b-a7a0-b72a68577846', compression_enabled: false})
})
</script>
<div style="width: 100%; height: 100%" data-jscall-id="1">
<canvas style="display: block" data-jscall-id="2" tabindex="0"></canvas>
</div>
</div>
</div><div>
<div id="38ddff6c-5548-4b0a-9e3a-4e4ec3d3c27b" data-jscall-id="root">
<div>
<script src="data:application/javascript;base64,Ly8gZGVuby1mbXQtaWdub3JlLWZpbGUKLy8gZGVuby1saW50LWlnbm9yZS1maWxlCi8vIFRoaXMgY29kZSB3YXMgYnVuZGxlZCB1c2luZyBgZGVubyBidW5kbGVgIGFuZCBpdCdzIG5vdCByZWNvbW1lbmRlZCB0byBlZGl0IGl0IG1hbnVhbGx5CgpmdW5jdGlvbiB1dGY4Q291bnQoc3RyKSB7CiAgICB2YXIgc3RyTGVuZ3RoID0gc3RyLmxlbmd0aDsKICAgIHZhciBieXRlTGVuZ3RoID0gMDsKICAgIHZhciBwb3MgPSAwOwogICAgd2hpbGUocG9zIDwgc3RyTGVuZ3RoKXsKICAgICAgICB2YXIgdmFsdWUgPSBzdHIuY2hhckNvZGVBdChwb3MrKyk7CiAgICAgICAgaWYgKCh2YWx1ZSAmIDB4ZmZmZmZmODApID09PSAwKSB7CiAgICAgICAgICAgIGJ5dGVMZW5ndGgrKzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfSBlbHNlIGlmICgodmFsdWUgJiAweGZmZmZmODAwKSA9PT0gMCkgewogICAgICAgICAgICBieXRlTGVuZ3RoICs9IDI7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaWYgKHZhbHVlID49IDB4ZDgwMCAmJiB2YWx1ZSA8PSAweGRiZmYpIHsKICAgICAgICAgICAgICAgIGlmIChwb3MgPCBzdHJMZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICB2YXIgZXh0cmEgPSBzdHIuY2hhckNvZGVBdChwb3MpOwogICAgICAgICAgICAgICAgICAgIGlmICgoZXh0cmEgJiAweGZjMDApID09PSAweGRjMDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgKytwb3M7CiAgICAgICAgICAgICAgICAgICAgICAgIHZhbHVlID0gKCh2YWx1ZSAmIDB4M2ZmKSA8PCAxMCkgKyAoZXh0cmEgJiAweDNmZikgKyAweDEwMDAwOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoKHZhbHVlICYgMHhmZmZmMDAwMCkgPT09IDApIHsKICAgICAgICAgICAgICAgIGJ5dGVMZW5ndGggKz0gMzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGJ5dGVMZW5ndGggKz0gNDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBieXRlTGVuZ3RoOwp9CmZ1bmN0aW9uIHV0ZjhFbmNvZGVKcyhzdHIsIG91dHB1dCwgb3V0cHV0T2Zmc2V0KSB7CiAgICB2YXIgc3RyTGVuZ3RoID0gc3RyLmxlbmd0aDsKICAgIHZhciBvZmZzZXQgPSBvdXRwdXRPZmZzZXQ7CiAgICB2YXIgcG9zID0gMDsKICAgIHdoaWxlKHBvcyA8IHN0ckxlbmd0aCl7CiAgICAgICAgdmFyIHZhbHVlID0gc3RyLmNoYXJDb2RlQXQocG9zKyspOwogICAgICAgIGlmICgodmFsdWUgJiAweGZmZmZmZjgwKSA9PT0gMCkgewogICAgICAgICAgICBvdXRwdXRbb2Zmc2V0KytdID0gdmFsdWU7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0gZWxzZSBpZiAoKHZhbHVlICYgMHhmZmZmZjgwMCkgPT09IDApIHsKICAgICAgICAgICAgb3V0cHV0W29mZnNldCsrXSA9IHZhbHVlID4+IDYgJiAweDFmIHwgMHhjMDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBpZiAodmFsdWUgPj0gMHhkODAwICYmIHZhbHVlIDw9IDB4ZGJmZikgewogICAgICAgICAgICAgICAgaWYgKHBvcyA8IHN0ckxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIHZhciBleHRyYSA9IHN0ci5jaGFyQ29kZUF0KHBvcyk7CiAgICAgICAgICAgICAgICAgICAgaWYgKChleHRyYSAmIDB4ZmMwMCkgPT09IDB4ZGMwMCkgewogICAgICAgICAgICAgICAgICAgICAgICArK3BvczsKICAgICAgICAgICAgICAgICAgICAgICAgdmFsdWUgPSAoKHZhbHVlICYgMHgzZmYpIDw8IDEwKSArIChleHRyYSAmIDB4M2ZmKSArIDB4MTAwMDA7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICgodmFsdWUgJiAweGZmZmYwMDAwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgb3V0cHV0W29mZnNldCsrXSA9IHZhbHVlID4+IDEyICYgMHgwZiB8IDB4ZTA7CiAgICAgICAgICAgICAgICBvdXRwdXRbb2Zmc2V0KytdID0gdmFsdWUgPj4gNiAmIDB4M2YgfCAweDgwOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgb3V0cHV0W29mZnNldCsrXSA9IHZhbHVlID4+IDE4ICYgMHgwNyB8IDB4ZjA7CiAgICAgICAgICAgICAgICBvdXRwdXRbb2Zmc2V0KytdID0gdmFsdWUgPj4gMTIgJiAweDNmIHwgMHg4MDsKICAgICAgICAgICAgICAgIG91dHB1dFtvZmZzZXQrK10gPSB2YWx1ZSA+PiA2ICYgMHgzZiB8IDB4ODA7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgb3V0cHV0W29mZnNldCsrXSA9IHZhbHVlICYgMHgzZiB8IDB4ODA7CiAgICB9Cn0KdmFyIHNoYXJlZFRleHRFbmNvZGVyID0gbmV3IFRleHRFbmNvZGVyKCk7CnZhciBURVhUX0VOQ09ERVJfVEhSRVNIT0xEID0gNTA7CmZ1bmN0aW9uIHV0ZjhFbmNvZGVURShzd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T09IDB4ZTApIHsKICAgICAgICAgICAgdmFyIGJ5dGUyID0gYnl0ZXNbb2Zmc2V0KytdICYgMHgzZjsKICAgICAgICAgICAgdmFyIGJ5dGUzID0gYnl0ZXNbb2Zmc2V0KytdICYgMHgzZjsKICAgICAgICAgICAgdW5pdHMucHVzaCgoYnl0ZTEgJiAweDFmKSA8PCAxMiB8IGJ5dGUyIDw8IDYgfCBieXRlMyk7CiAgICAgICAgfSBlbHNlIGlmICgoYnl0ZTEgJiAweGY4KSA9PT0gMHhmMCkgewogICAgICAgICAgICB2YXIgYnl0ZTIgPSBieXRlc1tvZmZzZXQrK10gJiAweDNmOwogICAgICAgICAgICB2YXIgYnl0ZTMgPSBieXRlc1tvZmZzZXQrK10gJiAweDNmOwogICAgICAgICAgICB2YXIgYnl0ZTQgPSBieXRlc1tvZmZzZXQrK10gJiAweDNmOwogICAgICAgICAgICB2YXIgdW5pdCA9IChieXRlMSAmIDB4MDcpIDw8IDB4MTIgfCBieXRlMiA8PCAweDBjIHwgYnl0ZTMgPDwgMHgwNiB8IGJ5dGU0OwogICAgICAgICAgICBpZiAodW5pdCA+IDB4ZmZmZikgewogICAgICAgICAgICAgICAgdW5pdCAtPSAweDEwMDAwOwogICAgICAgICAgICAgICAgdW5pdHMucHVzaCh1bml0ID4+PiAxMCAmIDB4M2ZmIHwgMHhkODAwKTsKICAgICAgICAgICAgICAgIHVuaXQgPSAweGRjMDAgfCB1bml0ICYgMHgzZmY7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdW5pdHMucHVzaCh1bml0KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB1bml0cy5wdXNoKGJ5dGUxKTsKICAgICAgICB9CiAgICAgICAgaWYgKHVuaXRzLmxlbmd0aCA+PSBDSFVOS19TSVpFKSB7CiAgICAgICAgICAgIHJlc3VsdCArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgdW5pdHMpOwogICAgICAgICAgICB1bml0cy5sZW5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Y29kZVRpbWVTcGVjVG9UaW1lc3RhbXAodGltZVNwZWMpOwogICAgfSBlbHNlIHsKICAgICAgICByZXR1cm4gbnVsbDsKICAgIH0KfQpmdW5jdGlvbiBkZWNvZGVUaW1lc3RhbXBUb1RpbWVTcGVjKGRhdGEpIHsKICAgIHZhciB2aWV3ID0gbmV3IERhdGFWaWV3KGRhdGEuYnVmZmVyLCBkYXRhLmJ5dGVPZmZzZXQsIGRhdGEuYnl0ZUxlbmd0aCk7CiAgICBzd2l0Y2goZGF0YS5ieXRlTGVuZ3RoKXsKICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHZhciBzZWMgPSB2aWV3LmdldFVpbnQzMigwKTsKICAgICAgICAgICAgICAgIHZhciBuc2VjID0gMDsKICAgICAgICAgICAgICAgIHJldHVybiB7CiAgICAgICAgICAgICAgICAgICAgc2VjOiBzZWMsCiAgICAgICAgICAgICAgICAgICAgbnNlYzogbnNlYwogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgIGNhc2UgODoKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdmFyIG5zZWMzMEFuZFNlY0hpZ2gyID0gdmlldy5nZXRVaW50MzIoMCk7CiAgICAgICAgICAgICAgICB2YXIgc2VjTG93MzIgPSB2aWV3LmdldFVpbnQzMig0KTsKICAgICAgICAgICAgICAgIHZhciBzZWMgPSAobnNlYzMwQW5kU2VjSGlnaDIgJiAweDMpICogMHgxMDAwMDAwMDAgKyBzZWNMb3czMjsKICAgICAgICAgICAgICAgIHZhciBuc2VjID0gbnNlYzMwQW5kU2VjSGlnaDIgPj4+IDI7CiAgICAgICAgICAgICAgICByZXR1cm4gewogICAgICAgICAgICAgICAgICAgIHNlYzogc2VjLAogICAgICAgICAgICAgICAgICAgIG5zZWM6IG5zZWMKICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgIH0KICAgICAgICBjYXNlIDEyOgogICAgICAgICAgICB7CiAgICAgICAgIC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lzdGVyKHRpbWVzdGFtcEV4dGVuc2lvbik7CiAgICB9CiAgICBFeHRlbnNpb25Db2RlYy5wcm90b3R5cGUucmVnaXN0ZXIgPSBmdW5jdGlvbihfYSkgewogICAgICAgIHZhciB0eXBlID0gX2EudHlwZSwgZW5jb2RlID0gX2EuZW5jb2RlLCBkZWNvZGUgPSBfYS5kZWNvZGU7CiAgICAgICAgaWYgKHR5cGUgPj0gMCkgewogICAgICAgICAgICB0aGlzLmVuY29kZXJzW3R5cGVdID0gZW5jb2RlOwogICAgICAgICAgICB0aGlzLmRlY29kZXJzW3R5cGVdID0gZGVjb2RlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHZhciBpbmRleCA9IDEgKyB0eXBlOwogICAgICAgICAgICB0aGlzLmJ1aWx0SW5FbmNvZGVyc1tpbmRleF0gPSBlbmNvZGU7CiAgICAgICAgICAgIHRoaXMuYnVpbHRJbkRlY29kZXJzW2luZGV4XSA9IGRlY29kZTsKICAgICAgICB9CiAgICB9OwogICAgRXh0ZW5zaW9uQ29kZWMucHJvdG90eXBlLnRyeVRvRW5jb2RlID0gZnVuY3Rpb24ob2JqZWN0LCBjb250ZXh0KSB7CiAgICAgICAgZm9yKHZhciBpID0gMDsgaSA8IHRoaXMuYnVpbHRJbkVuY29kZXJzLmxlbmd0aDsgaSsrKXsKICAgICAgICAgICAgdmFyIGVuY29kZUV4dCA9IHRoaXMuYnVpbHRJbkVuY29kZXJzW2ldOwogICAgICAgICAgICBpZiAoZW5jb2RlRXh0ICE9IG51bGwpIHsKICAgICAgICAgICAgICAgIHZhciBkYXRhID0gZW5jb2RlRXh0KG9iamVjdCwgY29udGV4dCk7CiAgICAgICAgICAgICAgICBpZiAoZGF0YSAhPSBudWxsKSB7CiAgICAgICAgICAgICAgICAgICAgdmFyIHR5cGUgPSAtMSAtIGk7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG5ldyBFeHREYXRhKHR5cGUsIGRhdGEpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvcih2YXIgaSA9IDA7IGkgPCB0aGlzLmVuY29kZXJzLmxlbmd0aDsgaSsrKXsKICAgICAgICAgICAgdmFyIGVuY29kZUV4dCA9IHRoaXMuZW5jb2RlcnNbaV07CiAgICAgICAgICAgIGlmIChlbmNvZGVFeHQgIT0gbnVsbCkgewogICAgICAgICAgICAgICAgdmFyIGRhdGEgPSBlbmNvZGVFeHQob2JqZWN0LCBjb250ZXh0KTsKICAgICAgICAgICAgICAgIGlmIChkYXRhICE9IG51bGwpIHsKICAgICAgICAgICAgICAgICAgICB2YXIgdHlwZSA9IGk7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG5ldyBFeHREYXRhKHR5cGUsIGRhdGEpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvYmplY3QgaW5zdGFuY2VvZiBFeHREYXRhKSB7CiAgICAgICAgICAgIHJldHVybiBvYmplY3Q7CiAgICAgICAgfQogICAgICAgIHJldHVybiBudWxsOwogICAgfTsKICAgIEV4dGVuc2lvbkNvZGVjLnByb3RvdHlwZS5kZWNvZGUgPSBmdW5jdGlvbihkYXRhLCB0eXBlLCBjb250ZXh0KSB7CiAgICAgICAgdmFyIGRlY29kZUV4dCA9IHR5cGUgPCAwID8gdGhpcy5idWlsdEluRGVjb2RlcnNbLTEgLSB0eXBlXSA6IHRoaXMuZGVjb2RlcnNbdHlwZV07CiAgICAgICAgaWYgKGRlY29kZUV4dCkgewogICAgICAgICAgICByZXR1cm4gZGVjb2RlRXh0KGRhdGEsIHR5cGUsIGNvbnRleHQpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgRXh0RGF0YSh0eXBlLCBkYXRhKTsKICAgICAgICB9CiAgICB9OwogICAgRXh0ZW5zaW9uQ29kZWMuZGVmYXVsdENvZGVjID0gbmV3IEV4dGVuc2lvbkNvZGVjKCk7C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SBmdW5jdGlvbihvYmplY3QpIHsKICAgICAgICB0aGlzLnJlaW5pdGlhbGl6ZVN0YXRlKCk7CiAgICAgICAgdGhpcy5kb0VuY29kZShvYmplY3QsIDEpOwogICAgICAgIHJldHVybiB0aGlzLmJ5dGVzLnN1YmFycmF5KDAsIHRoaXMucG9zKTsKICAgIH07CiAgICBFbmNvZGVyLnByb3RvdHlwZS5lbmNvZGUgPSBmdW5jdGlvbihvYmplY3QpIHsKICAgICAgICB0aGlzLnJlaW5pdGlhbGl6ZVN0YXRlKCk7CiAgICAgICAgdGhpcy5kb0VuY29kZShvYmplY3QsIDEpOwogICAgICAgIHJldHVybiB0aGlzLmJ5dGVzLnNsaWNlKDAsIHRoaXMucG9zKTsKICAgIH07CiAgICBFbmNvZGVyLnByb3RvdHlwZS5kb0VuY29kZSA9IGZ1bmN0aW9uKG9iamVjdCwgZGVwdGgpIHsKICAgICAgICBpZiAoZGVwdGggPiB0aGlzLm1heERlcHRoKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiVG9vIGRlZXAgb2JqZWN0cyBpbiBkZXB0aCAiLmNvbmNhdChkZXB0aCkpOwogICAgICAgIH0KICAgICAgICBpZiAob2JqZWN0ID09IG51bGwpIHsKICAgICAgICAgICAgdGhpcy5lbmNvZGVOaWwoKTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBvYmplY3QgPT09ICJib29sZWFuIikgewogICAgICAgICAgICB0aGlzLmVuY29kZUJvb2xlYW4ob2JqZWN0KTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBvYmplY3QgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICAgIGlmICghdGhpcy5mb3JjZUludGVnZXJUb0Zsb2F0KSB7CiAgICAgICAgICAgICAgICB0aGlzLmVuY29kZU51bWJlcihvYmplY3QpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdGhpcy5lbmNvZGVOdW1iZXJBc0Zsb2F0KG9iamVjdCk7C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AgICBFbmNvZGVyLnByb3RvdHlwZS5lbmNvZGVOaWwgPSBmdW5jdGlvbigpIHsKICAgICAgICB0aGlzLndyaXRlVTgoMHhjMCk7CiAgICB9OwogICAgRW5jb2Rlci5wcm90b3R5cGUuZW5jb2RlQm9vbGVhbiA9IGZ1bmN0aW9uKG9iamVjdCkgewogICAgICAgIGlmIChvYmplY3QgPT09IGZhbHNlKSB7CiAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGMyKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhjMyk7CiAgICAgICAgfQogICAgfTsKICAgIEVuY29kZXIucHJvdG90eXBlLmVuY29kZU51bWJlciA9IGZ1bmN0aW9uKG9iamVjdCkgewogICAgICAgIGlmICghdGhpcy5mb3JjZUludGVnZXJUb0Zsb2F0ICYmIE51bWJlci5pc1NhZmVJbnRlZ2VyKG9iamVjdCkpIHsKICAgICAgICAgICAgaWYgKG9iamVjdCA+PSAwKSB7CiAgICAgICAgICAgICAgICBpZiAob2JqZWN0IDwgMHg4MCkgewogICAgICAgICAgICAgICAgICAgIHRoaXMud3JpdGVVOChvYmplY3QpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvYmplY3QgPCAweDEwMCkgewogICAgICAgICAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGNjKTsKICAgICAgICAgICAgICAgICAgICB0aGlzLndyaXRlVTgob2JqZWN0KTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob2JqZWN0IDwgMHgxMDAwMCkgewogICAgICAgICAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGNkKTsKICAgICAgICAgICAgICAgICAgICB0aGlzLndyaXRlVTE2KG9iamVjdCk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9iamVjdCA8IDB4MTAwMDAwMDAwKSB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy53cml0ZVU4KDB4Y2UpOwogICAgICAgICAgICAgICAgICAgIHRoaXMud3JpdGVVMzIob2JqZWN0KTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoIXRoaXMudXNlQmlnSW50NjQpIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhjZik7CiAgICAgICAgICAgICAgICAgICAgdGhpcy53cml0ZVU2NChvYmplY3QpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLmVuY29kZU51bWJlckFzRmxvYXQob2JqZWN0KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGlmIChvYmplY3QgPj0gLTB4MjApIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhlMCB8IG9iamVjdCArIDB4MjApOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvYmplY3QgPj0gLTB4ODApIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhkMCk7CiAgICAgICAgICAgICAgICAgICAgdGhpcy53cml0ZUk4KG9iamVjdCk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9iamVjdCA+PSAtMHg4MDAwKSB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy53cml0ZVU4KDB4ZDEpOwogICAgICAgICAgICAgICAgICAgIHRoaXMud3JpdGVJMTYob2JqZWN0KTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob2JqZWN0ID49IC0weDgwMDAwMDAwKSB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy53cml0ZVU4KDB4ZDIpOwogICAgICAgICAgICAgICAgICAgIHRoaXMud3JpdGVJMzIob2JqZWN0KTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoIXRoaXMudXNlQmlnSW50NjQpIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhkMyk7CiAgICAgICAgICAgICAgICAgICAgdGhpcy53cml0ZUk2NChvYmplY3QpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLmVuY29kZU51bWJlckFzRmxvYXQob2JqZWN0KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMuZW5jb2RlTnVtYmVyQXNGbG9hdChvYmplY3QpOwogICAgICAgIH0KICAgIH07CiAgICBFbmNvZGVyLnByb3RvdHlwZS5lbmNvZGVOdW1iZXJBc0Zsb2F0ID0gZnVuY3Rpb24ob2JqZWN0KSB7CiAgICAgICAgaWYgKHRoaXMuZm9yY2VGbG9hdDMyKSB7CiAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGNhKTsKICAgICAgICAgICAgdGhpcy53cml0ZUYzMihvYmplY3QpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGNiKTsKICAgICAgICAgICAgdGhpcy53cml0ZUY2NChvYmplY3QpOwogICAgICAgIH0KICAgIH07CiAgICBFbmNvZGVyLnByb3RvdHlwZS5lbmNvZGVCaWdJbnQ2NCA9IGZ1bmN0aW9uKG9iamVjdCkgewogICAgICAgIGlmIChvYmplY3QgPj0gQmlnSW50KDApKSB7CiAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGNmKTsKICAgICAgICAgICAgdGhpcy53cml0ZUJpZ1VpbnQ2NChvYmplY3QpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGQzKTsKICAgICAgICAgICAgdGhpcy53cml0ZUJpZ0ludDY0KG9iamVjdCk7CiAgICAgICAgfQogICAgfTsKICAgIEVuY29kZXIucHJvdG90eXBlLndyaXRlU3RyaW5nSGVhZGVyID0gZnVuY3Rpb24oYnl0ZUxlbmd0aCkgewogICAgICAgIGlmIChieXRlTGVuZ3RoIDwgMzIpIHsKICAgICAgICAgICAgdGhpcy53cml0ZVU4KDB4YTAgKyBieXRlTGVuZ3Ro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ndyaXRlVTE2KHNpemUpOwogICAgICAgIH0gZWxzZSBpZiAoc2l6ZSA8IDB4MTAwMDAwMDAwKSB7CiAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGM2KTsKICAgICAgICAgICAgdGhpcy53cml0ZVUzMihzaXplKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIlRvbyBsYXJnZSBiaW5hcnk6ICIuY29uY2F0KHNpemUpKTsKICAgICAgICB9CiAgICAgICAgdmFyIGJ5dGVzID0gZW5zdXJlVWludDhBcnJheShvYmplY3QpOwogICAgICAgIHRoaXMud3JpdGVVOGEoYnl0ZXMpOwogICAgfTsKICAgIEVuY29kZXIucHJvdG90eXBlLmVuY29kZUFycmF5ID0gZnVuY3Rpb24ob2JqZWN0LCBkZXB0aCkgewogICAgICAgIHZhciBzaXplID0gb2JqZWN0Lmxlbmd0aDsKICAgICAgICBpZiAoc2l6ZSA8IDE2KSB7CiAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweDkwICsgc2l6ZSk7CiAgICAgICAgfSBlbHNlIGlmIChzaXplIDwgMHgxMDAwMCkgewogICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhkYyk7CiAgICAgICAgICAgIHRoaXMud3JpdGVVMTYoc2l6ZSk7CiAgICAgICAgfSBlbHNlIGlmIChzaXplIDwgMHgxMDAwMDAwMDApIHsKICAgICAgICAgICAgdGhpcy53cml0ZVU4KDB4ZGQpOwogICAgICAgICAgICB0aGlzLndyaXRlVTMyKHNpemUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiVG9vIGxhcmdlIGFycmF5OiAiLmNvbmNhdChzaXplKSk7CiAgICAgICAgfQogICAgICAgIGZvcih2YXIgX2kgPSAwLCBvYmplY3RfMSA9IG9iamVjdDsgX2kgPCBvYmplY3RfMS5sZW5ndGg7IF9pKyspewogICAgICAgICAgICB2YXIgaXRlbSA9IG9iamVjdF8xW19pXTsKICAgICAgICAgICAgdGhpcy5kb0VuY29kZShpdGVtLCBkZXB0aCArIDEpOwogICAgICAgIH0KICAgIH07CiAgICBFbmNvZGVyLnByb3RvdHlwZS5jb3VudFdpdGhvdXRVbmRlZmluZWQgPSBmdW5jdGlvbihvYmplY3QsIGtleXMpIHsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIGZvcih2YXIgX2kgPSAwLCBrZXlzXzEgPSBrZXlzOyBfaSA8IGtleXNfMS5sZW5ndGg7IF9pKyspewogICAgICAgICAgICB2YXIga2V5ID0ga2V5c18xW19pXTsKICAgICAgICAgICAgaWYgKG9iamVjdFtrZXldICE9PSB1bmRlZmluZWQpIHsKICAgICAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGNvdW50OwogICAgfTsKICAgIEVuY29kZXIucHJvdG90eXBlLmVuY29kZU1hcCA9IGZ1bmN0aW9uKG9iamVjdCwgZGVwdGgpIHsKICAgICAgICB2YXIga2V5cyA9IE9iamVjdC5rZXlzKG9iamVjdCk7CiAgICAgICAgaWYgKHRoaXMuc29ydEtleXMpIHsKICAgICAgICAgICAga2V5cy5zb3J0KCk7CiAgICAgICAgfQogICAgICAgIHZhciBzaXplID0gdGhpcy5pZ25vcmVVbmRlZmluZWQgPyB0aGlzLmNvdW50V2l0aG91dFVuZGVmaW5lZChvYmplY3QsIGtleXMpIDoga2V5cy5sZW5ndGg7CiAgICAgICAgaWYgKHNpemUgPCAxNikgewogICAgICAgICAgICB0aGlzLndyaXRlVTgoMHg4MCArIHNpemUpOwogICAgICAgIH0gZWxzZSBpZiAoc2l6ZSA8IDB4MTAwMDApIHsKICAgICAgICAgICAgdGhpcy53cml0ZVU4KDB4ZGUpOwogICAgICAgICAgICB0aGlzLndyaXRlVTE2KHNpemUpOwogICAgICAgIH0gZWxzZSBpZiAoc2l6ZSA8IDB4MTAwMDAwMDAwKSB7CiAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGRmKTsKICAgICAgICAgICAgdGhpcy53cml0ZVUzMihzaXplKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIlRvbyBsYXJnZSBtYXAgb2JqZWN0OiAiLmNvbmNhdChzaXplKSk7CiAgICAgICAgfQogICAgICAgIGZvcih2YXIgX2kgPSAwLCBrZXlzXzIgPSBrZXlzOyBfaSA8IGtleXNfMi5sZW5ndGg7IF9pKyspewogICAgICAgICAgICB2YXIga2V5ID0ga2V5c18yW19pXTsKICAgICAgICAgICAgdmFyIHZhbHVlID0gb2JqZWN0W2tleV07CiAgICAgICAgICAgIGlmICghKHRoaXMuaWdub3JlVW5kZWZpbmVkICYmIHZhbHVlID09PSB1bmRlZmluZWQpKSB7CiAgICAgICAgICAgICAgICB0aGlzLmVuY29kZVN0cmluZyhrZXkpOwogICAgICAgICAgICAgICAgdGhpcy5kb0VuY29kZSh2YWx1ZSwgZGVwdGggKyAxKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH07CiAgICBFbmNvZGVyLnByb3RvdHlwZS5lbmNvZGVFeHRlbnNpb24gPSBmdW5jdGlvbihleHQpIHsKICAgICAgICB2YXIgc2l6ZSA9IGV4dC5kYXRhLmxlbmd0aDsKICAgICAgICBpZiAoc2l6ZSA9PT0gMSkgewogICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhkNCk7CiAgICAgICAgfSBlbHNlIGlmIChzaXplID09PSAyKSB7CiAgICAgICAgICAgIHRoaXMud3JpdGVVOCgweGQ1KTsKICAgICAgICB9IGVsc2UgaWYgKHNpemUgPT09IDQpIHsKICAgICAgICAgICAgdGhpcy53cml0ZVU4KDB4ZDYpOwogICAgICAgIH0gZWxzZSBpZiAoc2l6ZSA9PT0gOCkgewogICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhkNyk7CiAgICAgICAgfSBlbHNlIGlmIChzaXplID09PSAxNikgewogICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhkOCk7CiAgICAgICAgfSBlbHNlIGlmIChzaXplIDwgMHgxMDApIHsKICAgICAgICAgICAgdGhpcy53cml0ZVU4KDB4YzcpOwogICAgICAgICAgICB0aGlzLndyaXRlVTgoc2l6ZSk7CiAgICAgICAgfSBlbHNlIGlmIChzaXplIDwgMHgxMDAwMCkgewogICAgICAgICAgICB0aGlzLndyaXRlVTgoMHhjOCk7CiAgICAgICAgICAgIHRoaXMud3JpdGVVMTYoc2l6ZSk7CiAgICAgICAgfSBlbHNlIGlmIChzaXplIDwgMHgxMDAwMDAwMDApIHsKICAgICAgICAgICAgdGhpcy53cml0ZVU4KDB4YzkpOwogICAgICAgICAgICB0aGlzLndyaXRlVTMyKHNpemUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiVG9vIGxhcmdlIGV4dGVuc2lvbiBvYmplY3Q6ICIuY29uY2F0KHNpemUpKTsKICAgICAgICB9CiAgICAgICAgdGhpcy53cml0ZUk4KGV4dC50eXBlKTsKICAgICAgICB0aGlzLndyaXRlVThhKGV4dC5kYXRhKTsKICAgIH07CiAgICBFbmNvZGVyLnByb3RvdHlwZS53cml0ZVU4ID0gZnVuY3Rpb24odmFsdWUpIHsKICAgICAgICB0aGlzLmVuc3VyZUJ1ZmZlclNpemVUb1dyaXRlKDEpOwogICAgICAgIHRoaXMudmlldy5zZXRVaW50OCh0aGlzLnBvcywgdmFsdWUpOwogICAgICAgIHRoaXMucG9zKys7CiAgICB9OwogICAgRW5jb2Rlci5wcm90b3R5cGUud3JpdGVVOGEgPSBmdW5jdGlvbih2YWx1ZXMpIHsKICAgICAgICB2YXIgc2l6ZSA9IHZhbHVlcy5sZW5ndGg7CiAgICAgICAgdGhpcy5lbnN1cmVCdWZmZXJTaXplVG9Xcml0ZShzaXplKTsKICAgICAgICB0aGlzLmJ5dGVzLnNldCh2YWx1ZXMsIHRoaXMucG9zKTsKICAgICAgICB0aGlzLnBvcyArPSBzaXplOwogICAgfTsKICAgIEVuY29kZXIucHJvdG90eXBlLndyaXRlSTggPSBmdW5jdGlvbih2YWx1ZSkgewogICAgICAgIHRoaXMuZW5zdXJlQnVmZmVyU2l6ZVRvV3JpdGUoMSk7CiAgICAgICAgdGhpcy52aWV3LnNldEludDgodGhpcy5wb3MsIHZhbHVlKTsKICAgICAgICB0aGlzLnBvcysrOwogICAgfTsKICAgIEVuY29kZXIucHJvdG90eXBlLndyaXRlVTE2ID0gZnVuY3Rpb24odmFsdWUpIHsKICAgICAgICB0aGlzLmVuc3VyZUJ1ZmZlclNpemVUb1dyaXRlKDIpOwogICAgICAgIHRoaXMudmlldy5zZXRVaW50MTYodGhpcy5wb3MsIHZhbHVlKTsKICAgICAgICB0aGlzLnBvcyArPSAyOwogICAgfTsKICAgIEVuY29kZXIucHJvdG90eXBlLndyaXRlSTE2ID0gZnVuY3Rpb24odmFsdWUpIHsKICAgICAgICB0aGlzLmVuc3VyZUJ1ZmZlclNpemVUb1dyaXRlKDIpOwogICAgICAgIHRoaXMudmlldy5zZXRJbnQxNih0aGlzLnBvcywgdmFsdWUpOwogICAgICAgIHRoaXMucG9zICs9IDI7CiAgICB9OwogICAgRW5jb2Rlci5wcm90b3R5cGUud3JpdGVVMzIgPSBmdW5jdGlvbih2YWx1ZSkgewogICAgICAgIHRoaXMuZW5zdXJlQnVmZmVyU2l6ZVRvV3JpdGUoNCk7CiAgICAgICAgdGhpcy52aWV3LnNldFVpbnQzMih0aGlzLnBvcywgdmFsdWUpOwogICAgICAgIHRoaXMucG9zICs9IDQ7CiAgICB9OwogICAgRW5jb2Rlci5wcm90b3R5cGUud3JpdGVJMzIgPSBmdW5jdGlvbih2YWx1ZSkgewogICAgICAgIHRoaXMuZW5zdXJlQnVmZmVyU2l6ZVRvV3JpdGUoNCk7CiAgICAgICAgdGhpcy52aWV3LnNldEludDMyKHRoaXMucG9zLCB2YWx1ZSk7CiAgICAgICAgdGhpcy5wb3MgKz0gNDsKICAgIH07CiAgICBFb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W5wdXRPZmZzZXQgKyBqXSkgewogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIEZJTkRfQ0hVTks7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHJlY29yZC5zdHI7CiAgICAgICAgfQogICAgICAgIHJldHVybiBudWxsOwogICAgfTsKICAgIENhY2hlZEtleURlY29kZXIucHJvdG90eXBlLnN0b3JlID0gZnVuY3Rpb24oYnl0ZXMsIHZhbHVlKSB7CiAgICAgICAgdmFyIHJlY29yZHMgPSB0aGlzLmNhY2hlc1tieXRlcy5sZW5ndGggLSAxXTsKICAgICAgICB2YXIgcmVjb3JkID0gewogICAgICAgICAgICBieXRlczogYnl0ZXMsCiAgICAgICAgICAgIHN0cjogdmFsdWUKICAgICAgICB9OwogICAgICAgIGlmIChyZWNvcmRzLmxlbmd0aCA+PSB0aGlzLm1heExlbmd0aFBlcktleSkgewogICAgICAgICAgICByZWNvcmRzW01hdGgucmFuZG9tKCkgKiByZWNvcmRzLmxlbmd0aCB8IDBdID0gcmVjb3JkOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJlY29yZHMucHVzaChyZWNvcmQpOwogICAgICAgIH0KICAgIH07CiAgICBDYWNoZWRLZXlEZWNvZGVyLnByb3RvdHlwZS5kZWNvZGUgPSBmdW5jdGlvbihieXRlcywgaW5wdXRPZmZzZXQsIGJ5dGVMZW5ndGgpIHsKICAgICAgICB2YXIgY2FjaGVkVmFsdWUgPSB0aGlzLmZpbmQoYnl0ZXMsIGlucHV0T2Zmc2V0LCBieXRlTGVuZ3RoKTsKICAgICAgICBpZiAoY2FjaGVkVmFsdWUgIT0gbnVsbCkgewogICAgICAgICAgICB0aGlzLmhpdCsrOwogICAgICAgICAgICByZXR1cm4gY2FjaGVkVmFsdWU7CiAgICAgICAgfQogICAgICAgIHRoaXMubWlzcysrOwogICAgICAgIHZhciBzdHIgPSB1dGY4RGVjb2RlSnMoYnl0ZXMsIGl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2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgewogICAgICAgICAgICByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsKICAgICAgICB9CiAgICAgICAgc3RlcCgoZ2VuZXJhdG9yID0gZ2VuZXJhdG9yLmFwcGx5KHRoaXNBcmcsIF9hcmd1bWVudHMgfHwgW10pKS5uZXh0KCkpOwogICAgfSk7Cn07CnZhciBfX2dlbmVyYXRvciA9IHRoaXMgJiYgdGhpcy5fX2dlbmVyYXRvciB8fCBmdW5jdGlvbih0aGlzQXJnLCBib2R5KSB7CiAgICB2YXIgXyA9IHsKICAgICAgICBsYWJlbDogMCwKICAgICAgICBzZW50OiBmdW5jdGlvbigpIHsKICAgICAgICAgICAgaWYgKHRbMF0gJiAxKSB0aHJvdyB0WzFdOwogICAgICAgICAgICByZXR1cm4gdFsxXTsKICAgICAgICB9LAogICAgICAgIHRyeXM6IFtdLAogICAgICAgIG9wczogW10KICAgIH0sIGYsIHksIHQsIGc7CiAgICByZXR1cm4gZyA9IHsKICAgICAgICBuZXh0OiB2ZXJiKDApLAogICAgICAgICJ0aHJvdyI6IHZlcmIoMSksCiAgICAgICAgInJldHVybiI6IHZlcmIoMikKICAgIH0sIHR5cGVvZiBTeW1ib2wgPT09ICJmdW5jdGlvbiIgJiYgKGdbU3ltYm9sLml0ZXJhdG9yXSA9IGZ1bmN0aW9uKCkgewogICAgICAgIHJldHVybiB0aGlzOwogICAgfSksIGc7CiAgICBmdW5jdGlvbiB2ZXJiKG4pIHsKICAgICAgICByZXR1cm4gZnVuY3Rpb24odikgewogICAgICAgICAgICByZXR1cm4gc3RlcChbCiAgICAgICAgICAgICAgICBuLAogICAgICAgICAgICAgICAgdgogICAgICAgICAgICBdKTsKICAgICAgICB9OwogICAgfQogICAgZnVuY3Rpb24gc3RlcChvcCkgewogICAgICAgIGlmIChmKSB0aHJvdyBuZXcgVHlwZUVycm9yKCJHZW5lcmF0b3IgaXMgYWxyZWFkeSBleGVjdXRpbmcuIik7CiAgICAgICAgd2hpbGUoZyAmJiAoZyA9IDAsIG9wWzBdICYmIChfID0gMCkpLCBfKXRyeSB7CiAgICAgICAgICAgIGlmIChmID0gMSwgeSAmJiAodCA9IG9wWzBdICYgMiA/IHlbInJldHVybiJdIDogb3BbMF0gPyB5WyJ0aHJvdyJdIHx8ICgodCA9IHlbInJldHVybiJdKSAmJiB0LmNhbGwoeSksIDApIDogeS5uZXh0KSAmJiAhKHQgPSB0LmNhbGwoeSwgb3BbMV0pKS5kb25lKSByZXR1cm4gdDsKICAgICAgICAgICAgaWYgKHkgPSAwLCB0KSBvcCA9IFsKICAgICAgICAgICAgICAgIG9wWzBdICYgMiwKICAgICAgICAgICAgICAgIHQudmFsdWUKICAgICAgICAgICAgXTsKICAgICAgICAgICAgc3dpdGNoKG9wWzBdKXsKICAgICAgICAgICAgICAgIGNhc2UgMDoKICAgICAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgICAgICB0ID0gb3A7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgICAgICAgICAgXy5sYWJlbCsrOwogICAgICAgICAgICAgICAgICAgIHJldHVybiB7CiAgICAgICAgICAgICAgICAgICAgICAgIHZhbHVlOiBvcFsxXSwKICAgICAgICAgICAgICAgICAgICAgICAgZG9uZTogZmFsc2UKICAgICAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgY2FzZSA1OgogICAgICAgICAgICAgICAgICAgIF8ubGFiZWwrKzsKICAgICAgICAgICAgICAgICAgICB5ID0gb3BbMV07CiAgICAgICAgICAgICAgICAgICAgb3AgPSBbCiAgICAgICAgICAgICAgICAgICAgICAgIDAKICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgY2FzZSA3OgogICAgICAgICAgICAgICAgICAgIG9wID0gXy5vcHMucG9wKCk7CiAgICAgICAgICAgICAgICAgICAgXy50cnlzLnBvcCgpOwogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgICAgICBpZiAoISh0ID0gXy50cnlzLCB0ID0gdC5sZW5ndGggPiAwICYmIHRbdC5sZW5ndGggLSAxXSkgJiYgKG9wWzBdID09PSA2IHx8IG9wWzBdID09PSAyKSkgewogICAgICAgICAgICAgICAgICAgICAgICBfID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChvcFswXSA9PT0gMyAmJiAoIXQgfHwgb3BbMV0gPiB0WzBdICYmIG9wWzFdIDwgdFszXSkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgXy5sYWJlbCA9IG9wWzFdOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKG9wWzBdID09PSA2ICYmIF8ubGFiZWwgPCB0WzFdKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIF8ubGFiZWwgPSB0WzFdOwogICAgICAgICAgICAgICAgICAgICAgICB0ID0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAodCAmJiBfLmxhYmVsIDwgdFsyXSkgewogICAgICAgICAgICAgICAgICAgICAgICBfLmxhYmVsID0gdFsyXTsKICAgICAgICAgICAgICAgICAgICAgICAgXy5vcHMucHVzaChvcCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAodFsyXSkgXy5vcHMucG9wKCk7CiAgICAgICAgICAgICAgICAgICAgXy50cnlzLnBvcCgpOwogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG9wID0gYm9keS5jYWxsKHRoaXNBcmcsIF8pOwogICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgb3AgPSBbCiAgICAgICAgICAgICAgICA2LAogICAgICAgICAgICAgICAgZQogICAgICAgICAgICBdOwogICAgICAgICAgICB5ID0gMDsKICAgICAgICB9IGZpbmFsbHl7CiAgICAgICAgICAgIGYgPSB0ID0gMDsKICAgICAgICB9CiAgICAgICAgaWYgKG9wWzBdICYgNSkgdGhyb3cgb3BbMV07CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgdmFsdWU6IG9wWzBdID8gb3BbMV0gOiB2b2lkIDAsCiAgICAgICAgICAgIGRvbmU6IHRydWUKICAgICAgICB9OwogICAgfQp9Owp2YXIgX19hc3luY1ZhbHVlcyA9IHRoaXMgJiYgdGhpcy5fX2FzeW5jVmFsdWVzIHx8IGZ1bmN0aW9uKG8pIHsKICAgIGlmICghU3ltYm9sLmFzeW5jSXRlcmF0b3IpIHRocm93IG5ldyBUeXBlRXJyb3IoIlN5bWJvbC5hc3luY0l0ZXJhdG9yIGlzIG5vdCBkZWZpbmVkLiIpOwogICAgdmFyIG0gPSBvW1N5bWJvbC5hc3luY0l0ZXJhdG9yXSwgaTsKICAgIHJldHVybiBtID8gbS5jYWxsKG8pIDogKG8gPSB0eXBlb2YgX192YWx1ZXMgPT09ICJmdW5jdGlvbiIgPyBfX3ZhbHVlcyhvKSA6IG9bU3ltYm9sLml0ZXJhdG9yXSgpLCBpID0ge30sIHZlcmIoIm5leHQiKSwgdmVyYigidGhyb3ciKSwgdmVyYigicmV0dXJuIiksIGlbU3ltYm9sLmFzeW5jSXRlcmF0b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fYXJndW1lbnRzIHx8IFtdKSwgaSwgcSA9IFtdOwogICAgcmV0dXJuIGkgPSB7fSwgdmVyYigibmV4dCIpLCB2ZXJiKCJ0aHJvdyIpLCB2ZXJiKCJyZXR1cm4iKSwgaVtTeW1ib2wuYXN5bmNJdGVyYXRvcl0gPSBmdW5jdGlvbigpIHsKICAgICAgICByZXR1cm4gdGhpczsKICAgIH0sIGk7CiAgICBmdW5jdGlvbiB2ZXJiKG4pIHsKICAgICAgICBpZiAoZ1tuXSkgaVtuXSA9IGZ1bmN0aW9uKHYpIHsKICAgICAgICAgICAgcmV0dXJuIG5ldyBQcm9taXNlKGZ1bmN0aW9uKGEsIGIpIHsKICAgICAgICAgICAgICAgIHEucHVzaChbCiAgICAgICAgICAgICAgICAgICAgbiwKICAgICAgICAgICAgICAgICAgICB2LAogICAgICAgICAgICAgICAgICAgIGEsCiAgICAgICAgICAgICAgICAgICAgYgogICAgICAgICAgICAgICAgXSkgPiAxIHx8IHJlc3VtZShuLCB2KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfTsKICAgIH0KICAgIGZ1bmN0aW9uIHJlc3VtZShuLCB2KSB7CiAgICAgICAgdHJ5IHsKICAgICAgICAgICAgc3RlcChnW25dKHYpKTsKICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgIHNldHRsZShxWzBdWzNdLCBlKTsKICAgICAgICB9CiAgICB9CiAgICBmdW5jdGlvbiBzdGVwKHIpIHsKICAgICAgICByLnZhbHVlIGluc3RhbmNlb2YgX19hd2FpdCA/IFByb21pc2UucmVzb2x2ZShyLnZhbHVlLnYpLnRoZW4oZnVsZmlsbCwgcmVqZWN0KSA6IHNldHRsZShxWzBdWzJdLCByKTsKICAgIH0KICAgIGZ1bmN0aW9uIGZ1bGZpbGwodmFsdWUpIHsKICAgICAgICByZXN1bWUoIm5leHQiLCB2YWx1ZSk7CiAgICB9CiAgICBmdW5jdGlvbiByZWplY3QodmFsdWUpIHsKICAgICAgICByZXN1bWUo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LmtleURlY29kZXIgOiBzaGFyZWRDYWNoZWRLZXlEZWNvZGVyOwogICAgfQogICAgRGVjb2Rlci5wcm90b3R5cGUucmVpbml0aWFsaXplU3RhdGUgPSBmdW5jdGlvbigpIHsKICAgICAgICB0aGlzLnRvdGFsUG9zID0gMDsKICAgICAgICB0aGlzLmhlYWRCeXRlID0gSEVBRF9CWVRFX1JFUVVJUkVEOwogICAgICAgIHRoaXMuc3RhY2subGVuZ3RoID0gMDsKICAgIH07CiAgICBEZWNvZGVyLnByb3RvdHlwZS5zZXRCdWZmZXIgPSBmdW5jdGlvbihidWZmZXIpIHsKICAgICAgICB0aGlzLmJ5dGVzID0gZW5zdXJlVWludDhBcnJheShidWZmZXIpOwogICAgICAgIHRoaXMudmlldyA9IGNyZWF0ZURhdGFWaWV3KHRoaXMuYnl0ZXMpOwogICAgICAgIHRoaXMucG9zID0gMDsKICAgIH07CiAgICBEZWNvZGVyLnByb3RvdHlwZS5hcHBlbmRCdWZmZXIgPSBmdW5jdGlvbihidWZmZXIpIHsKICAgICAgICBpZiAodGhpcy5oZWFkQnl0ZSA9PT0gSEVBRF9CWVRFX1JFUVVJUkVEICYmICF0aGlzLmhhc1JlbWFpbmluZygxKSkgewogICAgICAgICAgICB0aGlzLnNldEJ1ZmZlcihidWZmZXIpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHZhciByZW1haW5pbmdEYXRhID0gdGhpcy5ieXRlcy5zdWJhcnJheSh0aGlzLnBvcyk7CiAgICAgICAgICAgIHZhciBuZXdEYXRhID0gZW5zdXJlVWludDhBcnJheShidWZmZXIpOwogICAgICAgICAgICB2YXIgbmV3QnVmZmVyID0gbmV3IFVpbnQ4QXJyYXkocmVtYWluaW5nRGF0YS5sZW5ndGggKyBuZXdEYXRhLmxlbmd0aCk7CiAgICAgICAgICAgIG5ld0J1ZmZlci5zZXQocmVtYWluaW5nRGF0YSk7CiAgICAgICAgICAgIG5ld0J1ZmZlci5zZXQobmV3RGF0YSwgcm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gICAgICByZXR1cm4gX19nZW5lcmF0b3IodGhpcywgZnVuY3Rpb24oX2EpIHsKICAgICAgICAgICAgc3dpdGNoKF9hLmxhYmVsKXsKICAgICAgICAgICAgICAgIGNhc2UgMDoKICAgICAgICAgICAgICAgICAgICB0aGlzLnJlaW5pdGlhbGl6ZVN0YXRlKCk7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5zZXRCdWZmZXIoYnVmZmVyKTsKICAgICAgICAgICAgICAgICAgICBfYS5sYWJlbCA9IDE7CiAgICAgICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgICAgICAgICAgaWYgKCF0aGlzLmhhc1JlbWFpbmluZygxKSkgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgMywKICAgICAgICAgICAgICAgICAgICAgICAgMwogICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgNCwKICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5kb0RlY29kZVN5bmMoKQogICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICAgICAgX2Euc2VudCgpOwogICAgICAgICAgICAgICAgICAgIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgIDMsCiAgICAgICAgICAgICAgICAgICAgICAgIDEKICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgIDIKICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICB9OwogICAgRGVjb2Rlci5wcm90b3R5cGUuZGVjb2RlQXN5bmMgPSBmdW5jdGlvbihzdHJlYW0pIHsKICAgICAgICB2YXIgX2EsIHN0cmVhbV8xLCBzdHJlYW1fMV8xOwogICAgICAgIHZhciBfYiwgZV8xLCBfYywgX2Q7CiAgICAgICAgcmV0dXJuIF9fYXdhaXRlcih0aGlzLCB2b2lkIDAsIHZvaWQgMCwgZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHZhciBkZWNvZGVkLCBvYmplY3QsIGJ1ZmZlciwgZV8xXzEsIF9lLCBoZWFkQnl0ZSwgcG9zLCB0b3RhbFBvczsKICAgICAgICAgICAgcmV0dXJuIF9fZ2VuZXJhdG9yKHRoaXMsIGZ1bmN0aW9uKF9mKSB7CiAgICAgICAgICAgICAgICBzd2l0Y2goX2YubGFiZWwpewogICAgICAgICAgICAgICAgICAgIGNhc2UgMDoKICAgICAgICAgICAgICAgICAgICAgICAgZGVjb2RlZCA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICBfZi5sYWJlbCA9IDE7CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgICAgICBfZi50cnlzLnB1c2goWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDYsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICA3LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgMTIKICAgICAgICAgICAgICAgICAgICAgICAgXSk7CiAgICAgICAgICAgICAgICAgICAgICAgIF9hID0gdHJ1ZSwgc3RyZWFtXzEgPSBfX2FzeW5jVmFsdWVzKHN0cmVhbSk7CiAgICAgICAgICAgICAgICAgICAgICAgIF9mLmxhYmVsID0gMjsKICAgICAgICAgICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICA0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RyZWFtXzEubmV4dCgpCiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgICAgICBpZiAoIShzdHJlYW1fMV8xID0gX2Yuc2VudCgpLCBfYiA9IHN0cmVhbV8xXzEuZG9uZSwgIV9iKSkgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICA1CiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgICAgIF9kID0gc3RyZWFtXzFfMS52YWx1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgX2EgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJ1ZmZlciA9IF9kOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRlY29kZWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aHJvdyB0aGlzLmNyZWF0ZUV4dHJhQnl0ZUVycm9yKHRoaXMudG90YWxQb3MpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5hcHBlbmRCdWZmZXIoYnVmZmVyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2JqZWN0ID0gdGhpcy5kb0RlY29kZVN5bmMoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWNvZGVkID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoIShlIGluc3RhbmNlb2YgRGF0YVZpZXdJbmRleE91dE9mQm91bmRzRXJyb3IpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRocm93IGU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy50b3RhbFBvcyArPSB0aGlzLnBvczsKICAgICAgICAgICAgICAgICAgICAgICAgfSBmaW5hbGx5ewogICAgICAgICAgICAgICAgICAgICAgICAgICAgX2EgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIF9mLmxhYmVsID0gNDsKICAgICAgICAgICAgICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgMgogICAgICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICAgICAgICAgIGNhc2UgNToKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAxMgogICAgICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICAgICAgICAgIGNhc2UgNjoKICAgICAgICAgICAgICAgICAgICAgICAgZV8xXzEgPSBfZi5zZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGVfMSA9IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVycm9yOiBlXzFfMQogICAgICAgICAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMywKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEyCiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSA3OgogICAgICAgICAgICAgICAgICAgICAgICBfZi50cnlzLnB1c2goWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgNywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEwLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgMTEKICAgICAgICAgICAgICAgICAgICAgICAgXSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghKCFfYSAmJiAhX2IgJiYgKF9jID0gc3RyZWFtXzEucmV0dXJuKSkpIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgOQogICAgICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgNCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9jLmNhbGwoc3RyZWFtXzEpCiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSA4OgogICAgICAgICAgICAgICAgICAgICAgICBfZi5zZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICAgIF9mLmxhYmVsID0gOTsKICAgICAgICAgICAgICAgICAgICBjYXNlIDk6CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgMTEKICAgICAgICAgICAgICAgICAgICAgICAgXTsKICAgICAgICAgICAgICAgICAgICBjYXNlIDEwOgogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZV8xKSB0aHJvdyBlXzEuZXJyb3I7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICA3CiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxMToKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDcKICAgICAgICAgICAgICAgICAgICAgICAgXTsKICAgICAgICAgICAgICAgICAgICBjYXNlIDEyOgogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGVjb2RlZCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuaGFzUmVtYWluaW5nKDEpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhyb3cgdGhpcy5jcmVhdGVFeHRyYUJ5dGVFcnJvcih0aGlzLnRvdGFsUG9zKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvYmplY3QKICAgICAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgX2UgPSB0aGlzLCBoZWFkQnl0ZSA9IF9lLmhlYWRCeXRlLCBwb3MgPSBfZS5wb3MsIHRvdGFsUG9zID0gX2UudG90YWxQb3M7CiAgICAgICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJJbnN1ZmZpY2llbnQgZGF0YSBpbiBwYXJzaW5nICIuY29uY2F0KHByZXR0eUJ5dGUoaGVhZEJ5dGUpLCAiIGF0ICIpLmNvbmNhdCh0b3RhbFBvcywgIiAoIikuY29uY2F0KHBvcywgIiBpbiB0aGUgY3VycmVudCBidWZmZXIpIikpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9KTsKICAgICAgICB9KTsKICAgIH07CiAgICBEZWNvZGVyLnByb3RvdHlwZS5kZWNvZGVBcnJheVN0cmVhbSA9IGZ1bmN0aW9uKHN0cmVhbSkgewogICAgICAgIHJldHVybiB0aGlzLmRlY29kZU11bHRpQXN5bmMoc3RyZWFtLCB0cnVlKTsKICAgIH07CiAgICBEZWNvZGVyLnByb3RvdHlwZS5kZWNvZGVTdHJlYW0gPSBmdW5jdGlvbihzdHJlYW0pIHsKICAgICAgICByZXR1cm4gdGhpcy5kZWNvZGVNdWx0aUFzeW5jKHN0cmVhbSwgZmFsc2UpOwogICAgfTsKICAgIERlY29kZXIucHJvdG90eXBlLmRlY29kZU11bHRpQXN5bmMgPSBmdW5jdGlvbihzdHJlYW0sIGlzQXJyYXkpIHsKICAgICAgICByZXR1cm4gX19hc3luY0dlbmVyYXRvcih0aGlzLCBhcmd1bWVudHMsIGZ1bmN0aW9uIGRlY29kZU11bHRpQXN5bmNfMSgpIHsKICAgICAgICAgICAgdmFyIGlzQXJyYXlIZWFkZXJSZXF1aXJlZCwgYXJyYXlJdGVtc0xlZnQsIF9hLCBzdHJlYW1fMiwgc3RyZWFtXzJfMSwgYnVmZmVyLCBlXzIsIGVfM18xOwogICAgICAgICAgICB2YXIgX2IsIGVfMywgX2MsIF9kOwogICAgICAgICAgICByZXR1cm4gX19nZW5lcmF0b3IodGhpcywgZnVuY3Rpb24oX2UpIHsKICAgICAgICAgICAgICAgIHN3aXRjaChfZS5sYWJlbCl7CiAgICAgICAgICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgICAgICAgICBpc0FycmF5SGVhZGVyUmVxdWlyZWQgPSBpc0FycmF5OwogICAgICAgICAgICAgICAgICAgICAgICBhcnJheUl0ZW1zTGVmdCA9IC0xOwogICAgICAgICAgICAgICAgICAgICAgICBfZS5sYWJlbCA9IDE7CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgICAgICBfZS50cnlzLnB1c2goWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDE1LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgMTYsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAyMQogICAgICAgICAgICAgICAgICAgICAgICBdKTsKICAgICAgICAgICAgICAgICAgICAgICAgX2EgPSB0cnVlLCBzdHJlYW1fMiA9IF9fYXN5bmNWYWx1ZXMoc3RyZWFtKTsKICAgICAgICAgICAgICAgICAgICAgICAgX2UubGFiZWwgPSAyOwogICAgICAgICAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2F3YWl0KHN0cmVhbV8yLm5leHQoKSkKICAgICAgICAgICAgICAgICAgICAgICAgXTsKICAgICAgICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghKHN0cmVhbV8yXzEgPSBfZS5zZW50KCksIF9iID0gc3RyZWFtXzJfMS5kb25lLCAhX2IpKSByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMywKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDE0CiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgICAgIF9kID0gc3RyZWFtXzJfMS52YWx1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgX2EgPSBmYWxzZTsKICAgICAgICAgICAgICAgICAgICAgICAgX2UubGFiZWwgPSA0OwogICAgICAgICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgICAgICAgICAgX2UudHJ5cy5wdXNoKFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAxMiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEzCiAgICAgICAgICAgICAgICAgICAgICAgIF0pOwogICAgICAgICAgICAgICAgICAgICAgICBidWZmZXIgPSBfZDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzQXJyYXkgJiYgYXJyYXlJdGVtc0xlZnQgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRocm93IHRoaXMuY3JlYXRlRXh0cmFCeXRlRXJyb3IodGhpcy50b3RhbFBvcyk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5hcHBlbmRCdWZmZXIoYnVmZmVyKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlzQXJyYXlIZWFkZXJSZXF1aXJlZCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgYXJyYXlJdGVtc0xlZnQgPSB0aGlzLnJlYWRBcnJheVNpemUoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzQXJyYXlIZWFkZXJSZXF1aXJlZCA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5jb21wbGV0ZSgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIF9lLmxhYmVsID0gNTsKICAgICAgICAgICAgICAgICAgICBjYXNlIDU6CiAgICAgICAgICAgICAgICAgICAgICAgIF9lLnRyeXMucHVzaChbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICA1LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgMTAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAxMQogICAgICAgICAgICAgICAgICAgICAgICBdKTsKICAgICAgICAgICAgICAgICAgICAgICAgX2UubGFiZWwgPSA2OwogICAgICAgICAgICAgICAgICAgIGNhc2UgNjoKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCF0cnVlKSByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMywKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDkKICAgICAgICAgICAgICAgICAgICAgICAgXTsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2F3YWl0KHRoaXMuZG9EZWNvZGVTeW5jKCkpCiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSA3OgogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgNCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9lLnNlbnQoKQogICAgICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICAgICAgICAgIGNhc2UgODoKICAgICAgICAgICAgICAgICAgICAgICAgX2Uuc2VudCgpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoLS1hcnJheUl0ZW1zTGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICA2CiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSA5OgogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMywKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDExCiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxMDoKICAgICAgICAgICAgICAgICAgICAgICAgZV8yID0gX2Uuc2VudCgpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoIShlXzIgaW5zdGFuY2VvZiBEYXRhVmlld0luZGV4T3V0T2ZCb3VuZHNFcnJvcikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRocm93IGVfMjsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMywKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDExCiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxMToKICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy50b3RhbFBvcyArPSB0aGlzLnBvczsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAxMwogICAgICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICAgICAgICAgIGNhc2UgMTI6CiAgICAgICAgICAgICAgICAgICAgICAgIF9hID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDcKICAgICAgICAgICAgICAgICAgICAgICAgXTsKICAgICAgICAgICAgICAgICAgICBjYXNlIDEzOgogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMywKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDIKICAgICAgICAgICAgICAgICAgICAgICAgXTsKICAgICAgICAgICAgICAgICAgICBjYXNlIDE0OgogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMywKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDIxCiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxNToKICAgICAgICAgICAgICAgICAgICAgICAgZV8zXzEgPSBfZS5zZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGVfMyA9IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVycm9yOiBlXzNfMQogICAgICAgICAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMywKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDIxCiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxNjoKICAgICAgICAgICAgICAgICAgICAgICAgX2UudHJ5cy5wdXNoKFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDE2LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgMTksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAyMAogICAgICAgICAgICAgICAgICAgICAgICBdKTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCEoIV9hICYmICFfYiAmJiAoX2MgPSBzdHJlYW1fMi5yZXR1cm4pKSkgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAxOAogICAgICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgNCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYXdhaXQoX2MuY2FsbChzdHJlYW1fMikpCiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxNzoKICAgICAgICAgICAgICAgICAgICAgICAgX2Uuc2VudCgpOwogICAgICAgICAgICAgICAgICAgICAgICBfZS5sYWJlbCA9IDE4OwogICAgICAgICAgICAgICAgICAgIGNhc2UgMTg6CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgMjAKICAgICAgICAgICAgICAgICAgICAgICAgXTsKICAgICAgICAgICAgICAgICAgICBjYXNlIDE5OgogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZV8zKSB0aHJvdyBlXzMuZXJyb3I7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICA3CiAgICAgICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY2FzZSAyMDoKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIDcKICAgICAgICAgICAgICAgICAgICAgICAgXTsKICAgICAgICAgICAgICAgICAgICBjYXNlIDIxOgogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gWwogICAgICAgICAgICAgICAgICAgICAgICAgICAgMgogICAgICAgICAgICAgICAgICAgICAgICBdOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9KTsKICAgICAgICB9KTsKICAgIH07CiAgICBEZWNvZGVyLnByb3RvdHlwZS5kb0RlY29kZVN5bmMgPSBmdW5jdGlvbigpIHsKICAgICAgICBERUNPREU6IHdoaWxlKHRydWUpewogICAgICAgICAgICB2YXIgaGVhZEJ5dGUgPSB0aGlzLnJlYWRIZWFkQnl0ZSgpOwogICAgICAgICAgICB2YXIgb2JqZWN0ID0gdm9pZCAwOwogICAgICAgICAgICBpZiAoaGVhZEJ5dGUgPj0gMHhlMCkgewogICAgICAgICAgICAgICAgb2JqZWN0ID0gaGVhZEJ5dGUgLSAweDEwMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA8IDB4YzApIHsKICAgICAgICAgICAgICAgIGlmIChoZWFkQnl0ZSA8IDB4ODApIHsKICAgICAgICAgICAgICAgICAgICBvYmplY3QgPSBoZWFkQnl0ZTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPCAweDkwKSB7CiAgICAgICAgICAgICAgICAgICAgdmFyIHNpemUgPSBoZWFkQnl0ZSAtIDB4ODA7CiAgICAgICAgICAgICAgICAgICAgaWYgKHNpemUgIT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5wdXNoTWFwU3RhdGUoc2l6ZSk7CiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuY29tcGxldGUoKTsKICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWUgREVDT0RFOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG9iamVjdCA9IHt9OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPCAweGEwKSB7CiAgICAgICAgICAgICAgICAgICAgdmFyIHNpemUgPSBoZWFkQnl0ZSAtIDB4OTA7CiAgICAgICAgICAgICAgICAgICAgaWYgKHNpemUgIT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5wdXNoQXJyYXlTdGF0ZShzaXplKTsKICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5jb21wbGV0ZSgpOwogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZSBERUNPREU7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgb2JqZWN0ID0gW107CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICB2YXIgYnl0ZUxlbmd0aCA9IGhlYWRCeXRlIC0gMHhhMDsKICAgICAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLmRlY29kZVV0ZjhTdHJpbmcoYnl0ZUxlbmd0aCwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4YzApIHsKICAgICAgICAgICAgICAgIG9iamVjdCA9IG51bGw7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4YzIpIHsKICAgICAgICAgICAgICAgIG9iamVjdCA9IGZhbHNlOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGMzKSB7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0cnVlOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGNhKSB7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLnJlYWRGMzIoKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA9PT0gMHhjYikgewogICAgICAgICAgICAgICAgb2JqZWN0ID0gdGhpcy5yZWFkRjY0KCk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4Y2MpIHsKICAgICAgICAgICAgICAgIG9iamVjdCA9IHRoaXMucmVhZFU4KCk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4Y2QpIHsKICAgICAgICAgICAgICAgIG9iamVjdCA9IHRoaXMucmVhZFUxNigpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGNlKSB7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLnJlYWRVMzIoKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA9PT0gMHhjZikgewogICAgICAgICAgICAgICAgaWYgKHRoaXMudXNlQmlnSW50NjQpIHsKICAgICAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLnJlYWRVNjRBc0JpZ0ludCgpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLnJlYWRVNjQoKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA9PT0gMHhkMCkgewogICAgICAgICAgICAgICAgb2JqZWN0ID0gdGhpcy5yZWFkSTgoKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA9PT0gMHhkMSkgewogICAgICAgICAgICAgICAgb2JqZWN0ID0gdGhpcy5yZWFkSTE2KCk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4ZDIpIHsKICAgICAgICAgICAgICAgIG9iamVjdCA9IHRoaXMucmVhZEkzMigpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGQzKSB7CiAgICAgICAgICAgICAgICBpZiAodGhpcy51c2VCaWdJbnQ2NCkgewogICAgICAgICAgICAgICAgICAgIG9iamVjdCA9IHRoaXMucmVhZEk2NEFzQmlnSW50KCk7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIG9iamVjdCA9IHRoaXMucmVhZEk2NCgpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGQ5KSB7CiAgICAgICAgICAgICAgICB2YXIgYnl0ZUxlbmd0aCA9IHRoaXMubG9va1U4KCk7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLmRlY29kZVV0ZjhTdHJpbmcoYnl0ZUxlbmd0aCwgMSk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4ZGEpIHsKICAgICAgICAgICAgICAgIHZhciBieXRlTGVuZ3RoID0gdGhpcy5sb29rVTE2KCk7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLmRlY29kZVV0ZjhTdHJpbmcoYnl0ZUxlbmd0aCwgMik7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4ZGIpIHsKICAgICAgICAgICAgICAgIHZhciBieXRlTGVuZ3RoID0gdGhpcy5sb29rVTMyKCk7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLmRlY29kZVV0ZjhTdHJpbmcoYnl0ZUxlbmd0aCwgNCk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4ZGMpIHsKICAgICAgICAgICAgICAgIHZhciBzaXplID0gdGhpcy5yZWFkVTE2KCk7CiAgICAgICAgICAgICAgICBpZiAoc2l6ZSAhPT0gMCkgewogICAgICAgICAgICAgICAgICAgIHRoaXMucHVzaEFycmF5U3RhdGUoc2l6ZSk7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb21wbGV0ZSgpOwogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIERFQ09ERTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgb2JqZWN0ID0gW107CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4ZGQpIHsKICAgICAgICAgICAgICAgIHZhciBzaXplID0gdGhpcy5yZWFkVTMyKCk7CiAgICAgICAgICAgICAgICBpZiAoc2l6ZSAhPT0gMCkgewogICAgICAgICAgICAgICAgICAgIHRoaXMucHVzaEFycmF5U3RhdGUoc2l6ZSk7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb21wbGV0ZSgpOwogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIERFQ09ERTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgb2JqZWN0ID0gW107CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4ZGUpIHsKICAgICAgICAgICAgICAgIHZhciBzaXplID0gdGhpcy5yZWFkVTE2KCk7CiAgICAgICAgICAgICAgICBpZiAoc2l6ZSAhPT0gMCkgewogICAgICAgICAgICAgICAgICAgIHRoaXMucHVzaE1hcFN0YXRlKHNpemUpOwogICAgICAgICAgICAgICAgICAgIHRoaXMuY29tcGxldGUoKTsKICAgICAgICAgICAgICAgICAgICBjb250aW51ZSBERUNPREU7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIG9iamVjdCA9IHt9OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGRmKSB7CiAgICAgICAgICAgICAgICB2YXIgc2l6ZSA9IHRoaXMucmVhZFUzMigpOwogICAgICAgICAgICAgICAgaWYgKHNpemUgIT09IDApIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLnB1c2hNYXBTdGF0ZShzaXplKTsKICAgICAgICAgICAgICAgICAgICB0aGlzLmNvbXBsZXRlKCk7CiAgICAgICAgICAgICAgICAgICAgY29udGludWUgREVDT0RFOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBvYmplY3QgPSB7fTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA9PT0gMHhjNCkgewogICAgICAgICAgICAgICAgdmFyIHNpemUgPSB0aGlzLmxvb2tVOCgpOwogICAgICAgICAgICAgICAgb2JqZWN0ID0gdGhpcy5kZWNvZGVCaW5hcnkoc2l6ZSwgMSk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4YzUpIHsKICAgICAgICAgICAgICAgIHZhciBzaXplID0gdGhpcy5sb29rVTE2KCk7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLmRlY29kZUJpbmFyeShzaXplLCAyKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA9PT0gMHhjNikgewogICAgICAgICAgICAgICAgdmFyIHNpemUgPSB0aGlzLmxvb2tVMzIoKTsKICAgICAgICAgICAgICAgIG9iamVjdCA9IHRoaXMuZGVjb2RlQmluYXJ5KHNpemUsIDQpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGQ0KSB7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLmRlY29kZUV4dGVuc2lvbigxLCAwKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA9PT0gMHhkNSkgewogICAgICAgICAgICAgICAgb2JqZWN0ID0gdGhpcy5kZWNvZGVFeHRlbnNpb24oMiwgMCk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVhZEJ5dGUgPT09IDB4ZDYpIHsKICAgICAgICAgICAgICAgIG9iamVjdCA9IHRoaXMuZGVjb2RlRXh0ZW5zaW9uKDQsIDApOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGQ3KSB7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLmRlY29kZUV4dGVuc2lvbig4LCAwKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA9PT0gMHhkOCkgewogICAgICAgICAgICAgICAgb2JqZWN0ID0gdGhpcy5kZWNvZGVFeHRlbnNpb24oMTYsIDApOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGM3KSB7CiAgICAgICAgICAgICAgICB2YXIgc2l6ZSA9IHRoaXMubG9va1U4KCk7CiAgICAgICAgICAgICAgICBvYmplY3QgPSB0aGlzLmRlY29kZUV4dGVuc2lvbihzaXplLCAxKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChoZWFkQnl0ZSA9PT0gMHhjOCkgewogICAgICAgICAgICAgICAgdmFyIHNpemUgPSB0aGlzLmxvb2tVMTYoKTsKICAgICAgICAgICAgICAgIG9iamVjdCA9IHRoaXMuZGVjb2RlRXh0ZW5zaW9uKHNpemUsIDIpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRCeXRlID09PSAweGM5KSB7CiAgICAgICAgICAgICAgICB2YXIgc2l6ZSA9IHRoaXMubG9va1UzMigpOwogICAgICAgICAgICAgICAgb2JqZWN0ID0gdGhpcy5kZWNvZGVFeHRlbnNpb24oc2l6ZSwgNCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRGVjb2RlRXJyb3IoIlVucmVjb2duaXplZCB0eXBlIGJ5dGU6ICIuY29uY2F0KHByZXR0eUJ5dGUoaGVhZEJ5dGUpKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5jb21wbGV0ZSgpOwogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLnN0YWNrOwogICAgICAgICAgICB3aGlsZShzdGFjay5sZW5ndGggPiAwKXsKICAgICAgICAgICAgICAgIHZhciBzdGF0ZSA9IHN0YWNrW3N0YWNrLmxlbmd0aCAtIDFdOwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLnR5cGUgPT09IFNUQVRFX0FSUkFZKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuYXJyYXlbc3RhdGUucG9zaXRpb25dID0gb2JqZWN0OwogICAgICAgICAgICAgICAgICAgIHN0YXRlLnBvc2l0aW9uKys7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLnBvc2l0aW9uID09PSBzdGF0ZS5zaXplKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YWNrLnBvcCgpOwogICAgICAgICAgICAgICAgICAgICAgICBvYmplY3QgPSBzdGF0ZS5hcnJheTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZSBERUNPREU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS50eXBlID09PSBTVEFURV9NQVBfS0VZKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFpc1ZhbGlkTWFwS2V5VHlwZShvYmplY3QpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBEZWNvZGVFcnJvcigiVGhlIHR5cGUgb2Yga2V5IG11c3QgYmUgc3RyaW5nIG9yIG51bWJlciBidXQgIiArIHR5cGVvZiBvYmplY3QpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAob2JqZWN0ID09PSAiX19wcm90b19fIikgewogICAgICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRGVjb2RlRXJyb3IoIlRoZSBrZXkgX19wcm90b19fIGlzIG5vdCBhbGxvd2VkIik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHN0YXRlLmtleSA9IG9iamVjdDsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS50eXBlID0gU1RBVEVfTUFQX1ZBTFVFOwogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIERFQ09ERTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubWFwW3N0YXRlLmtleV0gPSBvYmplY3Q7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUucmVhZENvdW50Kys7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLnJlYWRDb3VudCA9PT0gc3RhdGUuc2l6ZSkgewogICAgICAgICAgICAgICAgICAgICAgICBzdGFjay5wb3AoKTsKICAgICAgICAgICAgICAgICAgICAgICAgb2JqZWN0ID0gc3RhdGUubWFwOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmtleSA9IG51bGw7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLnR5cGUgPSBTVEFURV9NQVBfS0VZOwogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZSBERUNPREU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBvYmplY3Q7CiAgICAgICAgfQogICAgfTsKICAgIERlY29kZXIucHJvdG90eXBlLnJlYWRIZWFkQnl0ZSA9IGZ1bmN0aW9uKCkgewogICAgICAgIGlmICh0aGlzLmhlYWRCeXRlID09PSBIRUFEX0JZVEVfUkVRVUlSRUQpIHsKICAgICAgICAgICAgdGhpcy5oZWFkQnl0ZSA9IHRoaXMucmVhZFU4KCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzLmhlYWRCeXRlOwogICAgfTsKICAgIERlY29kZXIucHJvdG90eXBlLmNvbXBsZXRlID0gZnVuY3Rpb24oKSB7CiAgICAgICAgdGhpcy5oZWFkQnl0ZSA9IEhFQURfQllURV9SRVFVSVJFRDsKICAgIH07CiAgICBEZWNvZGVyLnByb3RvdHlwZS5yZWFkQXJyYXlTaXplID0gZnVuY3Rpb24oKSB7CiAgICAgICAgdmFyIGhlYWRCeXRlID0gdGhpcy5yZWFkSGVhZEJ5dGUoKTsKICAgICAgICBzd2l0Y2goaGVhZEJ5dGUpewogICAgICAgICAgICBjYXNlIDB4ZGM6CiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5yZWFkVTE2KCk7CiAgICAgICAgICAgIGNhc2UgMHhkZDoKICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnJlYWRVMzIoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGVhZEJ5dGUgPCAweGEwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBoZWFkQnl0ZSAtIDB4OTA7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IERlY29kZUVycm9yKCJVbnJlY29nbml6ZWQgYXJyYXkgdHlwZSBieXRlOiAiLmNvbmNhdChwcmV0dHlCeXRlKGhlYWRCeXRlKSkpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9OwogICAgRGVjb2Rlci5wcm90b3R5cGUucHVzaE1hcFN0YXRlID0gZnVuY3Rpb24oc2l6ZSkgewogICAgICAgIGlmIChzaXplID4gdGhpcy5tYXhNYXBMZW5ndGgpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IERlY29kZUVycm9yKCJNYXggbGVuZ3RoIGV4Y2VlZGVkOiBtYXAgbGVuZ3RoICgiLmNvbmNhdChzaXplLCAiKSA+IG1heE1hcExlbmd0aExlbmd0aCAoIikuY29uY2F0KHRoaXMubWF4TWFwTGVuZ3RoLCAiKSIpKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5zdGFjay5wdXNoKHsKICAgICAgICAgICA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s9IDI7CiAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgfTsKICAgIERlY29kZXIucHJvdG90eXBlLnJlYWRJMTYgPSBmdW5jdGlvbigpIHsKICAgICAgICB2YXIgdmFsdWUgPSB0aGlzLnZpZXcuZ2V0SW50MTYodGhpcy5wb3MpOwogICAgICAgIHRoaXMucG9zICs9IDI7CiAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgfTsKICAgIERlY29kZXIucHJvdG90eXBlLnJlYWRVMzIgPSBmdW5jdGlvbigpIHsKICAgICAgICB2YXIgdmFsdWUgPSB0aGlzLnZpZXcuZ2V0VWludDMyKHRoaXMucG9zKTsKICAgICAgICB0aGlzLnBvcyArPSA0OwogICAgICAgIHJldHVybiB2YWx1ZTsKICAgIH07CiAgICBEZWNvZGVyLnByb3RvdHlwZS5yZWFkSTMyID0gZnVuY3Rpb24oKSB7CiAgICAgICAgdmFyIHZhbHVlID0gdGhpcy52aWV3LmdldEludDMyKHRoaXMucG9zKTsKICAgICAgICB0aGlzLnBvcyArPSA0OwogICAgICAgIHJldHVybiB2YWx1ZTsKICAgIH07CiAgICBEZWNvZGVyLnByb3RvdHlwZS5yZWFkVTY0ID0gZnVuY3Rpb24oKSB7CiAgICAgICAgdmFyIHZhbHVlID0gZ2V0VWludDY0KHRoaXMudmlldywgdGhpcy5wb3MpOwogICAgICAgIHRoaXMucG9zICs9IDg7CiAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgfTsKICAgIERlY29kZXIucHJvdG90eXBlLnJlYWRJNjQgPSBmdW5jdGlvbigpIHsKICAgICAgICB2YXIgdmFsdWUgPSBnZXRJbnQ2NCh0aGlzLnZpZXcsIHRoaXMucG9zKTsKICAgICAgICB0aGlzLnBvcyArPSA4OwogICAgICAgIHJldHVybiB2YWx1ZTsKICAgIH07CiAgICBEZWNvZGVyLnByb3RvdHlwZS5yZWFkVTY0QXNCaWdJbnQgPSBmdW5jdGlvbigpIHsKICAgICAgICB2YXIgdmFsdWUgPSB0aG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gICAgIHJldHVybiB0WzFdOwogICAgICAgIH0sCiAgICAgICAgdHJ5czogW10sCiAgICAgICAgb3BzOiBbXQogICAgfSwgZiwgeSwgdCwgZzsKICAgIHJldHVybiBnID0gewogICAgICAgIG5leHQ6IHZlcmIoMCksCiAgICAgICAgInRocm93IjogdmVyYigxKSwKICAgICAgICAicmV0dXJuIjogdmVyYigyKQogICAgfSwgdHlwZW9mIFN5bWJvbCA9PT0gImZ1bmN0aW9uIiAmJiAoZ1tTeW1ib2wuaXRlcmF0b3JdID0gZnVuY3Rpb24oKSB7CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICB9KSwgZzsKICAgIGZ1bmN0aW9uIHZlcmIobikgewogICAgICAgIHJldHVybiBmdW5jdGlvbih2KSB7CiAgICAgICAgICAgIHJldHVybiBzdGVwKFsKICAgICAgICAgICAgICAgIG4sCiAgICAgICAgICAgICAgICB2CiAgICAgICAgICAgIF0pOwogICAgICAgIH07CiAgICB9CiAgICBmdW5jdGlvbiBzdGVwKG9wKSB7CiAgICAgICAgaWYgKGYpIHRocm93IG5ldyBUeXBlRXJyb3IoIkdlbmVyYXRvciBpcyBhbHJlYWR5IGV4ZWN1dGluZy4iKTsKICAgICAgICB3aGlsZShnICYmIChnID0gMCwgb3BbMF0gJiYgKF8gPSAwKSksIF8pdHJ5IHsKICAgICAgICAgICAgaWYgKGYgPSAxLCB5ICYmICh0ID0gb3BbMF0gJiAyID8geVsicmV0dXJuIl0gOiBvcFswXSA/IHlbInRocm93Il0gfHwgKCh0ID0geVsicmV0dXJuIl0pICYmIHQuY2FsbCh5KSwgMCkgOiB5Lm5leHQpICYmICEodCA9IHQuY2FsbCh5LCBvcFsxXSkpLmRvbmUpIHJldHVybiB0OwogICAgICAgICAgICBpZiAoeSA9IDAsIHQpIG9wID0gWwogICAgICAgICAgICAgICAgb3BbMF0gJiAyLAogICAgICAgICAgICAgICAgdC52YWx1ZQogICAgICAgICAgICBdOwogICAgICAgICAgICBzd2l0Y2gob3BbMF0pewogICAgICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIHQgPSBvcDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgICAgICBfLmxhYmVsKys7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgICAgICAgICAgICAgdmFsdWU6IG9wWzFdLAogICAgICAgICAgICAgICAgICAgICAgICBkb25lOiBmYWxzZQogICAgICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICBjYXNlIDU6CiAgICAgICAgICAgICAgICAgICAgXy5sYWJlbCsrOwogICAgICAgICAgICAgICAgICAgIHkgPSBvcFsxXTsKICAgICAgICAgICAgICAgICAgICBvcCA9IFsKICAgICAgICAgICAgICAgICAgICAgICAgMAogICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICBjYXNlIDc6CiAgICAgICAgICAgICAgICAgICAgb3AgPSBfLm9wcy5wb3AoKTsKICAgICAgICAgICAgICAgICAgICBfLnRyeXMucG9wKCk7CiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgICAgIGlmICghKHQgPSBfLnRyeXMsIHQgPSB0Lmxlbmd0aCA+IDAgJiYgdFt0Lmxlbmd0aCAtIDFdKSAmJiAob3BbMF0gPT09IDYgfHwgb3BbMF0gPT09IDIpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIF8gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKG9wWzBdID09PSAzICYmICghdCB8fCBvcFsxXSA+IHRbMF0gJiYgb3BbMV0gPCB0WzNdKSkgewogICAgICAgICAgICAgICAgICAgICAgICBfLmxhYmVsID0gb3BbMV07CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAob3BbMF0gPT09IDYgJiYgXy5sYWJlbCA8IHRbMV0pIHsKICAgICAgICAgICAgICAgICAgICAgICAgXy5sYWJlbCA9IHRbMV07CiAgICAgICAgICAgICAgICAgICAgICAgIHQgPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmICh0ICYmIF8ubGFiZWwgPCB0WzJdKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIF8ubGFiZWwgPSB0WzJdOwogICAgICAgICAgICAgICAgICAgICAgICBfLm9wcy5wdXNoKG9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmICh0WzJdKSBfLm9wcy5wb3AoKTsKICAgICAgICAgICAgICAgICAgICBfLnRyeXMucG9wKCk7CiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgb3AgPSBib2R5LmNhbGwodGhpc0FyZywgXyk7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICBvcCA9IFsKICAgICAgICAgICAgICAgIDYsCiAgICAgICAgICAgICAgICBlCiAgICAgICAgICAgIF07CiAgICAgICAgICAgIHkgPSAwOwogICAgICAgIH0gZmluYWxseXsKICAgICAgICAgICAgZiA9IHQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAob3BbMF0gJiA1KSB0aHJvdyBvcFsxXTsKICAgICAgICByZXR1cm4gewogICAgICAgICAgICB2YWx1ZTogb3BbMF0gPyBvcFsxXSA6IHZvaWQgMCwKICAgICAgICAgICAgZG9uZTogdHJ1ZQogICAgICAgIH07CiAgICB9Cn07CnZhciBfX2F3YWl0M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YXRvci5uZXh0KHZhbHVlKSk7CiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiByZWplY3RlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgc3RlcChnZW5lcmF0b3JbInRocm93Il0odmFsdWUpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHN0ZXAocmVzdWx0KSB7CiAgICAgICAgICAgIHJlc3VsdC5kb25lID8gcmVzb2x2ZShyZXN1bHQudmFsdWUpIDogYWRvcHQocmVzdWx0LnZhbHVlKS50aGVuKGZ1bGZpbGxlZCwgcmVqZWN0ZWQpOwogICAgICAgIH0KICAgICAgICBzdGVwKChnZW5lcmF0b3IgPSBnZW5lcmF0b3IuYXBwbHkodGhpc0FyZywgX2FyZ3VtZW50cyB8fCBbXSkpLm5leHQoKSk7CiAgICB9KTsKfTsKdGhpcyAmJiB0aGlzLl9fZ2VuZXJhdG9yIHx8IGZ1bmN0aW9uKHRoaXNBcmcsIGJvZHkpIHsKICAgIHZhciBfID0gewogICAgICAgIGxhYmVsOiAwLAogICAgICAgIHNlbnQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgICBpZiAodFswXSAmIDEpIHRocm93IHRbMV07CiAgICAgICAgICAgIHJldHVybiB0WzFdOwogICAgICAgIH0sCiAgICAgICAgdHJ5czogW10sCiAgICAgICAgb3BzOiBbXQogICAgfSwgZiwgeSwgdCwgZzsKICAgIHJldHVybiBnID0gewogICAgICAgIG5leHQ6IHZlcmIoMCksCiAgICAgICAgInRocm93IjogdmVyYigxKSwKICAgICAgICAicmV0dXJuIjogdmVyYigyKQogICAgfSwgdHlwZW9mIFN5bWJvbCA9PT0gImZ1bmN0aW9uIiAmJiAoZ1tTeW1ib2wuaXRlcmF0b3JdID0gZnVuY3Rpb24oKSB7CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICB9KSwgZzsKICAgIGZ1bmN0aW9uIHZlcmIobikgewogICAgICAgIHJldHVybiBmdW5jdGlvbih2KSB7CiAgICAgICAgICAgIHJldHVybiBzdGVwKFsKICAgICAgICAgICAgICAgIG4sCiAgICAgICAgICAgICAgICB2CiAgICAgICAgICAgIF0pOwogICAgICAgIH07CiAgICB9CiAgICBmdW5jdGlvbiBzdGVwKG9wKSB7CiAgICAgICAgaWYgKGYpIHRocm93IG5ldyBUeXBlRXJyb3IoIkdlbmVyYXRvciBpcyBhbHJlYWR5IGV4ZWN1dGluZy4iKTsKICAgICAgICB3aGlsZShnICYmIChnID0gMCwgb3BbMF0gJiYgKF8gPSAwKSksIF8pdHJ5IHsKICAgICAgICAgICAgaWYgKGYgPSAxLCB5ICYmICh0ID0gb3BbMF0gJiAyID8geVsicmV0dXJuIl0gOiBvcFswXSA/IHlbInRocm93Il0gfHwgKCh0ID0geVsicmV0dXJuIl0pICYmIHQuY2FsbCh5KSwgMCkgOiB5Lm5leHQpICYmICEodCA9IHQuY2FsbCh5LCBvcFsxXSkpLmRvbmUpIHJldHVybiB0OwogICAgICAgICAgICBpZiAoeSA9IDAsIHQpIG9wID0gWwogICAgICAgICAgICAgICAgb3BbMF0gJiAyLAogICAgICAgICAgICAgICAgdC52YWx1ZQogICAgICAgICAgICBdOwogICAgICAgICAgICBzd2l0Y2gob3BbMF0pewogICAgICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIHQgPSBvcDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgICAgICBfLmxhYmVsKys7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgICAgICAgICAgICAgdmFsdWU6IG9wWzFdLAogICAgICAgICAgICAgICAgICAgICAgICBkb25lOiBmYWxzZQogICAgICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICBjYXNlIDU6CiAgICAgICAgICAgICAgICAgICAgXy5sYWJlbCsrOwogICAgICAgICAgICAgICAgICAgIHkgPSBvcFsxXTsKICAgICAgICAgICAgICAgICAgICBvcCA9IFsKICAgICAgICAgICAgICAgICAgICAgICAgMAogICAgICAgICAgICAgICAgICAgIF07CiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICBjYXNlIDc6CiAgICAgICAgICAgICAgICAgICAgb3AgPSBfLm9wcy5wb3AoKTsKICAgICAgICAgICAgICAgICAgICBfLnRyeXMucG9wKCk7CiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgICAgIGlmICghKHQgPSBfLnRyeXMsIHQgPSB0Lmxlbmd0aCA+IDAgJiYgdFt0Lmxlbmd0aCAtIDFdKSAmJiAob3BbMF0gPT09IDYgfHwgb3BbMF0gPT09IDIpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIF8gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKG9wWzBdID09PSAzICYmICghdCB8fCBvcFsxXSA+IHRbMF0gJiYgb3BbMV0gPCB0WzNdKSkgewogICAgICAgICAgICAgICAgICAgICAgICBfLmxhYmVsID0gb3BbMV07CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAob3BbMF0gPT09IDYgJiYgXy5sYWJlbCA8IHRbMV0pIHsKICAgICAgICAgICAgICAgICAgICAgICAgXy5sYWJlbCA9IHRbMV07CiAgICAgICAgICAgICAgICAgICAgICAgIHQgPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmICh0ICYmIF8ubGFiZWwgPCB0WzJdKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIF8ubGFiZWwgPSB0WzJdOwogICAgICAgICAgICAgICAgICAgICAgICBfLm9wcy5wdXNoKG9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmICh0WzJdKSBfLm9wcy5wb3AoKTsKICAgICAgICAgICAgICAgICAgICBfLnRyeXMucG9wKCk7CiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgb3AgPSBib2R5LmNhbGwodGhpc0FyZywgXyk7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICBvcCA9IFsKICAgICAgICAgICAgICAgIDYsCiAgICAgICAgICAgICAgICBlCiAgICAgICAgICAgIF07CiAgICAgICAgICAgIHkgPSAwOwogICAgICAgIH0gZmluYWxseXsKICAgICAgICAgICAgZiA9IHQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAob3BbMF0gJiA1KSB0aHJvdyBvcFsxXTsKICAgICAgICByZXR1cm4gewogICAgICAgICAgICB2YWx1ZTogb3BbMF0gPyBvcFsxXSA6IHZvaWQgMCwKICAgICAgICAgICAgZG9uZTogdHJ1ZQogICAgICAgIH07CiAgICB9Cn07CmZ1bmN0aW9uIF9lKGUpIHsKICAgIGxldCBpID0gZS5sZW5ndGg7CiAgICBmb3IoOyAtLWkgPj0gMDspZVtpXSA9IDA7Cn0KdmFyICRpID0gMCwgYWkgPSAxLCBDaSA9IDIsIEZpID0gMywgTWkgPSAyNTgsIGR0ID0gMjksIEFlID0gMjU2LCBnZSA9IEFlICsgMSArIGR0LCBvZSA9IDMwLCBzdCA9IDE5LCBuaSA9IDIgKiBnZSArIDEsIFEgPSAxNSwgR2UgPSAxNiwgSGkgPSA3LCBjdCA9IDI1NiwgbGkgPSAxNiwgcmkgPSAxNywgZmkgPSAxOCwgZnQgPSBuZXcgVWludDhBcnJheShbCiAgICAwLAogICAgMCwKICAgIDAsCiAgICAwLAogICAgMCwKICAgIDAsCiAgICAwLAogICAgMCwKICAgIDEsCiAgICAxLAogICAgMSwKICAgIDEsCiAgICAyLAogICAgMiwKICAgIDIsCiAgICAyLAogICAgMywKICAgIDMsCiAgICAzLAogICAgMywKICAgIDQsCiAgICA0LAogICAgNCwKICAgIDQsCiAgICA1LAogICAgNSwKICAgIDUsCiAgICA1LAogICAgMApdKSwgJGUgPSBuZXcgVWludDhBcnJheShbCiAgICAwLAogICAgMCwKICAgIDAsCiAgICAwLAogICAgMSwKICAgIDEsCiAgICAyLAogICAgMiwKICAgIDMsCiAgICAzLAogICAgNCwKICAgIDQsCiAgICA1LAogICAgNSwKICAgIDYsCiAgICA2LAogICAgNywKICAgIDcsCiAgICA4LAogICAgOCwKICAgIDksCiAgICA5LAogICAgMTAsCiAgICAxMCwKICAgIDExLAogICAgMTEsCiAgICAxMiwKICAgIDEyLAogICAgMTMsCiAgICAxMwpdKSwgQmkgPSBuZXcgVWludDhBcnJheShbCiAgICAwLAogICAgMCwKICAgIDAsCiAgICAwLAogICAgMCwKICAgIDAsCiAgICAwLAogICAgMCwKICAgIDAsCiAgICAwLAogICAgMCwKICAgIDAsCiAgICAwLAogICAgMCwKICAgIDAsCiAgICAwLAogICAgMiwKICAgIDMsCiAgICA3Cl0pLCBvaSA9IG5ldyBVaW50OEFycmF5KFsKICAgIDE2LAogICAgMTcsCiAgICAxOCwKICAgIDAsCiAgICA4LAogICAgNywKICAgIDksCiAgICA2LAogICAgMTAsCiAgICA1LAogICAgMTEsCiAgICA0LAogICAgMTIsCiAgICAzLAogICAgMTMsCiAgICAyLAogICAgMTQsCiAgICAxLAogICAgMTUKXSksIEtpID0gNTEyLCBCID0gbmV3IEFycmF5KChnZSArIDIpICogMik7Cl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pICYmIChlLmJsX2NvdW50W3NdKyssIGggPSAwLCBfID49IGYgJiYgKGggPSBvW18gLSBmXSksIHUgPSB0W18gKiAyXSwgZS5vcHRfbGVuICs9IHUgKiAocyArIGgpLCBsICYmIChlLnN0YXRpY19sZW4gKz0gdSAqIChhW18gKiAyICsgMV0gKyBoKSkpOwogICAgaWYgKG0gIT09IDApIHsKICAgICAgICBkbyB7CiAgICAgICAgICAgIGZvcihzID0gYyAtIDE7IGUuYmxfY291bnRbc10gPT09IDA7KXMtLTsKICAgICAgICAgICAgZS5ibF9jb3VudFtzXS0tLCBlLmJsX2NvdW50W3MgKyAxXSArPSAyLCBlLmJsX2NvdW50W2NdLS0sIG0gLT0gMjsKICAgICAgICB9d2hpbGUgKG0gPiAwKQogICAgICAgIGZvcihzID0gYzsgcyAhPT0gMDsgcy0tKWZvcihfID0gZS5ibF9jb3VudFtzXTsgXyAhPT0gMDspRSA9IGUuaGVhcFstLXJdLCAhKEUgPiBuKSAmJiAodFtFICogMiArIDFdICE9PSBzICYmIChlLm9wdF9sZW4gKz0gKHMgLSB0W0UgKiAyICsgMV0pICogdFtFICogMl0sIHRbRSAqIDIgKyAxXSA9IHMpLCBfLS0pOwogICAgfQp9LCB1aSA9IChlLCBpLCB0KT0+ewogICAgbGV0IG4gPSBuZXcgQXJyYXkoUSArIDEpLCBhID0gMCwgbCwgbzsKICAgIGZvcihsID0gMTsgbCA8PSBROyBsKyspbltsXSA9IGEgPSBhICsgdFtsIC0gMV0gPDwgMTsKICAgIGZvcihvID0gMDsgbyA8PSBpOyBvKyspewogICAgICAgIGxldCBmID0gZVtvICogMiArIDFdOwogICAgICAgIGYgIT09IDAgJiYgKGVbbyAqIDJdID0gY2kobltmXSsrLCBmKSk7CiAgICB9Cn0sIFlpID0gKCk9PnsKICAgIGxldCBlLCBpLCB0LCBuLCBhLCBsID0gbmV3IEFycmF5KFEgKyAxKTsKICAgIGZvcih0ID0gMCwgbiA9IDA7IG4gPCBkdCAtIDE7IG4rK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rYV0gJiYgclsrK25dID09PSByWysrYV0gJiYgclsrK25dID09PSByWysrYV0gJiYgclsrK25dID09PSByWysrYV0gJiYgclsrK25dID09PSByWysrYV0gJiYgclsrK25dID09PSByWysrYV0gJiYgclsrK25dID09PSByWysrYV0gJiYgclsrK25dID09PSByWysrYV0gJiYgbiA8IHMpCiAgICAgICAgaWYgKGwgPSBZIC0gKHMgLSBuKSwgbiA9IHMgLSBZLCBsID4gbykgewogICAgICAgICAgICBpZiAoZS5tYXRjaF9zdGFydCA9IGksIG8gPSBsLCBsID49IGYpIGJyZWFrOwogICAgICAgICAgICBoID0gcltuICsgbyAtIDFdLCB1ID0gcltuICsgb107CiAgICAgICAgfQogICAgfQogICAgd2hpbGUgKChpID0gRVtpICYgX10pID4gYyAmJiAtLXQgIT09IDApCiAgICByZXR1cm4gbyA8PSBlLmxvb2thaGVhZCA/IG8gOiBlLmxvb2thaGVhZDsKfSwgaWUgPSAoZSk9PnsKICAgIGxldCBpID0gZS53X3NpemUsIHQsIG4sIGEsIGwsIG87CiAgICBkbyB7CiAgICAgICAgaWYgKGwgPSBlLndpbmRvd19zaXplIC0gZS5sb29rYWhlYWQgLSBlLnN0cnN0YXJ0LCBlLnN0cnN0YXJ0ID49IGkgKyAoaSAtICQpKSB7CiAgICAgICAgICAgIGUud2luZG93LnNldChlLndpbmRvdy5zdWJhcnJheShpLCBpICsgaSksIDApLCBlLm1hdGNoX3N0YXJ0IC09IGksIGUuc3Ryc3RhcnQgLT0gaSwgZS5ibG9ja19zdGFydCAtPSBpLCBuID0gZS5oYXNoX3NpemUsIHQgPSBuOwogICAgICAgICAgICBkbyBhID0gZS5oZWFkWy0tdF0sIGUuaGVhZFt0XSA9IGEgPj0gaSA/IGEgLSBpIDogMDsKICAgICAgICAgICAgd2hpbGUgKC0tbikKICAgICAgICAgICAgbiA9IGksIHQgPSBuOwogICAgICAgICAgICBkbyBhID0gZS5wcmV2Wy0tdF0sIGUucHJldlt0XSA9IGEgPj0gaSA/IGEgLSBpIDogMDsKICAgICAgICAgICAgd2hpbGUgKC0tbikKICAgICAgICAgICAgbCArPSBpOwogICAgICAgIH0KICAgICAgICBpZiAoZS5zdHJtLmF2YWlsX2luID09PSAwKSBicmVhazsKICAgICAgICBpZiAobiA9IFVhKGUuc3RybSwgZS53aW5kb3csIGUuc3Ryc3RhcnQgKyBlLmxvb2thaGVhZCwgbCksIGUubG9va2FoZWFkICs9IG4sIGUubG9va2FoZWFkICsgZS5pbnNlcnQgPj0gaykgZm9yKG8gPSBlLnN0cnN0YXJ0IC0gZS5pbnNlcnQsIGUuaW5zX2ggPSBlLndpbmRvd1tvXSwgZS5pbnNfaCA9IFYoZSwgZS5pbnNfaCwgZS53aW5kb3dbbyArIDFdKTsgZS5pbnNlcnQgJiYgKGUuaW5zX2ggPSBWKGUsIGUuaW5zX2gsIGUud2luZG93W28gKyBrIC0gMV0pLCBlLnByZXZbbyAmIGUud19tYXNrXSA9IGUuaGVhZFtlLmluc19oXSwgZS5oZWFkW2UuaW5zX2hdID0gbywgbysrLCBlLmluc2VydC0tLCAhKGUubG9va2FoZWFkICsgZS5pbnNlcnQgPCBrKSk7KTsKICAgIH13aGlsZSAoZS5sb29rYWhlYWQgPCAkICYmIGUuc3RybS5hdmFpbF9pbiAhPT0gMCkKfSwgJGEgPSAoZSwgaSk9PnsKICAgIGxldCB0ID0gNjU1MzU7CiAgICBmb3IodCA+IGUucGVuZGluZ19idWZfc2l6ZSAtIDUgJiYgKHQgPSBlLnBlbmRpbmdfYnVmX3NpemUgLSA1KTs7KXsKICAgICAgICBpZiAoZS5sb29rYWhlYWQgPD0gMSkgewogICAgICAgICAgICBpZiAoaWUoZSksIGUubG9va2FoZWFkID09PSAwICYmIGkgPT09IGxlKSByZXR1cm4gRDsKICAgICAgICAgICAgaWYgKGUubG9va2FoZWFkID09PSAwKSBicmVhazsKICAgICAgICB9CiAgICAgICAgZS5zdHJzdGFydCArPSBlLmxvb2thaGVhZCwgZS5sb29rYWhlYWQgPSAw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07CiAgICB9CiAgICByZXR1cm4gZS5tYXRjaF9hdmFpbGFibGUgJiYgKG4gPSBqKGUsIDAsIGUud2luZG93W2Uuc3Ryc3RhcnQgLSAxXSksIGUubWF0Y2hfYXZhaWxhYmxlID0gMCksIGUuaW5zZXJ0ID0gZS5zdHJzdGFydCA8IGsgLSAxID8gZS5zdHJzdGFydCA6IGsgLSAxLCBpID09PSBXID8gKE8oZSwgITApLCBlLnN0cm0uYXZhaWxfb3V0ID09PSAwID8gdGUgOiBoZSkgOiBlLmxhc3RfbGl0ICYmIChPKGUsICExKSwgZS5zdHJtLmF2YWlsX291dCA9PT0gMCkgPyBEIDogUmU7Cn0sIENhID0gKGUsIGkpPT57CiAgICBsZXQgdCwgbiwgYSwgbCwgbyA9IGUud2luZG93OwogICAgZm9yKDs7KXsKICAgICAgICBpZiAoZS5sb29rYWhlYWQgPD0gWSkgewogICAgICAgICAgICBpZiAoaWUoZSksIGUubG9va2FoZWFkIDw9IFkgJiYgaSA9PT0gbGUpIHJldHVybiBEOwogICAgICAgICAgICBpZiAoZS5sb29rYWhlYWQgPT09IDApIGJyZWFrOwogICAgICAgIH0KICAgICAgICBpZiAoZS5tYXRjaF9sZW5ndGggPSAwLCBlLmxvb2thaGVhZCA+PSBrICYmIGUuc3Ryc3RhcnQgPiAwICYmIChhID0gZS5zdHJzdGFydCAtIDEsIG4gPSBvW2FdLCBuID09PSBvWysrYV0gJiYgbiA9PT0gb1srK2FdICYmIG4gPT09IG9bKythXSkpIHsKICAgICAgICAgICAgbCA9IGUuc3Ryc3RhcnQgKyBZOwogICAgICAgICAgICBkbyA7CiAgICAgICAgICAgIHdoaWxlIChuID09PSBvWysrYV0gJiYgbiA9PT0gb1srK2FdICYmIG4gPT09IG9bKythXSAmJiBuID09PSBvWysrYV0gJiYgbiA9PT0gb1srK2FdICYmIG4gPT09IG9bKythXSAmJiBuID09PSBvWysrYV0gJiYgbiA9PT0gb1srK2FdICYmIGEgPCBsKQogICAgICAgICAgICBlLm1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UZXh0RGVjb2Rlci5wcm90b3R5cGUuZGVjb2RlKSByZXR1cm4gbmV3IFRleHREZWNvZGVyKCkuZGVjb2RlKGUuc3ViYXJyYXkoMCwgaSkpOwogICAgbGV0IG4sIGEsIGwgPSBuZXcgQXJyYXkodCAqIDIpOwogICAgZm9yKGEgPSAwLCBuID0gMDsgbiA8IHQ7KXsKICAgICAgICBsZXQgbyA9IGVbbisrXTsKICAgICAgICBpZiAobyA8IDEyOCkgewogICAgICAgICAgICBsW2ErK10gPSBvOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgbGV0IGYgPSBFZVtvXTsKICAgICAgICBpZiAoZiA+IDQpIHsKICAgICAgICAgICAgbFthKytdID0gNjU1MzMsIG4gKz0gZiAtIDE7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBmb3IobyAmPSBmID09PSAyID8gMzEgOiBmID09PSAzID8gMTUgOiA3OyBmID4gMSAmJiBuIDwgdDspbyA9IG8gPDwgNiB8IGVbbisrXSAmIDYzLCBmLS07CiAgICAgICAgaWYgKGYgPiAxKSB7CiAgICAgICAgICAgIGxbYSsrXSA9IDY1NTMzOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgbyA8IDY1NTM2ID8gbFthKytdID0gbyA6IChvIC09IDY1NTM2LCBsW2ErK10gPSA1NTI5NiB8IG8gPj4gMTAgJiAxMDIzLCBsW2ErK10gPSA1NjMyMCB8IG8gJiAxMDIzKTsKICAgIH0KICAgIHJldHVybiBmbihsLCBhKTsKfSwgX24gPSAoZSwgaSk9PnsKICAgIGkgPSBpIHx8IGUubGVuZ3RoLCBpID4gZS5sZW5ndGggJiYgKGkgPSBlLmxlbmd0aCk7CiAgICBsZXQgdCA9IGkgLSAxOwogICAgZm9yKDsgdCA+PSAwICYmIChlW3RdICYgMTkyKSA9PT0gMTI4Oyl0LS07CiAgICByZXR1cm4gdCA8IDAgfHwgdCA9PT0gMCA/IG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wgdSA8IDE1ICYmIChoICs9IFJbbisrXSA8PCB1LCB1ICs9IDgsIGggKz0gUltuKytdIDw8IHUsIHUgKz0gOCksIHggPSB2W2ggJiBBXTsKICAgICAgICAgICAgICAgIGk6IGZvcig7Oyl7CiAgICAgICAgICAgICAgICAgICAgaWYgKGQgPSB4ID4+PiAyNCwgaCA+Pj49IGQsIHUgLT0gZCwgZCA9IHggPj4+IDE2ICYgMjU1LCBkICYgMTYpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKFogPSB4ICYgNjU1MzUsIGQgJj0gMTUsIHUgPCBkICYmIChoICs9IFJbbisrXSA8PCB1LCB1ICs9IDgsIHUgPCBkICYmIChoICs9IFJbbisrXSA8PCB1LCB1ICs9IDgpKSwgWiArPSBoICYgKDEgPDwgZCkgLSAxLCBaID4gYykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siLCBwLm1vZGUgPSBPZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGU7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGggPj4+PSBkLCB1IC09IGQsIGQgPSBsIC0gbywgWiA+IGQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkID0gWiAtIGQsIGQgPiBfICYmIHAuc2FuZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGkubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIiwgcC5tb2RlID0gT2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiID0gMCwgeiA9IHMsIEUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYiArPSByIC0gZCwgZCA8IFMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUyAtPSBkOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyBnW2wrK10gPSBzW2IrK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlICgtLWQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGIgPSBsIC0gWiwgeiA9IGc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChFIDwgZCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiICs9IHIgKyBFIC0gZCwgZCAtPSBFLCBkIDwgUykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBTIC09IGQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIGdbbCsrXSA9IHNbYisrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKC0tZCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGIgPSAwLCBFIDwgUykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZCA9IEUsIFMgLT0gZDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIGdbbCsrXSA9IHNbYisrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlICgtLWQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBiID0gbCAtIFosIHogPSBnOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChiICs9IEUgLSBkLCBkIDwgUykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFMgLT0gZDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyBnW2wrK10gPSBzW2IrK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKC0tZCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBiID0gbCAtIFosIHogPSBnOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yKDsgUyA+IDI7KWdbbCsrXSA9IHpbYisrXSwgZ1tsKytdID0geltiKytdLCBnW2wrK10gPSB6W2IrK10sIFMgLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIFMgJiYgKGdbbCsrXSA9IHpbYisrXSwgUyA+IDEgJiYgKGdbbCsrXSA9IHpbYisrXSkpOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgYiA9IGwgLSBaOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gZ1tsKytdID0gZ1tiKytdLCBnW2wrK10gPSBnW2IrK10sIGdbbCsrXSA9IGdbYisrXSwgUyAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKFMgPiAyKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgUyAmJiAoZ1tsKytdID0gZ1tiKytdLCBTID4gMSAmJiAoZ1tsKytdID0gZ1tiKytdKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGQgJiA2NCkgewogICAgICAgICAgICAgICAgICAgICAgICBpLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiLCBwLm1vZGUgPSBPZTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgZTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICB4ID0gdlsoeCAmIDY1NTM1KSArIChoICYgKDEgPDwgZCkgLSAxKV07CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgaWYgKGQgJiA2NCkgaWYgKGQgJiAzMikgewogICAgICAgICAgICAgICAgcC5tb2RlID0gem47CiAgICAgICAgICAgICAgICBicmVhayBlOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgaS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIiwgcC5tb2RlID0gT2U7CiAgICAgICAgICAgICAgICBicmVhayBlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgeCA9IG1bKHggJiA2NTUzNSkgKyAoaCAmICgxIDw8IGQpIC0gMSldOwogICAgICAgICAgICAgICAgY29udGludWUgdDsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9d2hpbGUgKG4gPCBhICYmIGwgPCBmKQogICAgUyA9IHUgPj4gMywgbiAtPSBTLCB1IC09IFMgPDwgMywgaCAmPSAoMSA8PCB1KSAtIDEsIGkubmV4dF9pbiA9IG4sIGkubmV4dF9vdXQgPSBsLCBpLmF2YWlsX2luID0gbiA8IGEgPyA1ICsgKGEgLSBuKSA6IDUgLSAobiAtIGEpLCBpLmF2YWlsX291dCA9IGwgPCBmID8gMjU3ICsgKGYgLSBsKSA6IDI1NyAtIChsIC0gZiksIHAuaG9sZCA9IGgsIHAuYml0cyA9IHU7Cn0sIGZlID0gMTUsIHp0ID0gODUyLCBUdCA9IDU5MiwgbXQgPSAwLCBxZSA9IDEsIER0ID0gMiwgbW4gPSBuZXcgVWludDE2QXJyYXkoWwogICAgMywKICAgIDQsCiAgICA1LAogICAgNiwKICAgIDcsCiAgICA4LAogICAgOSwKICAgIDEwLAogICAgMTEsCiAgICAxMywKICAgIDE1LAogICAgMTcsCiAgICAxOSwKICAgIDIzLAogICAgMjcsCiAgICAzMSwKICAgIDM1LAogICAgNDMsCiAgICA1MSwKICAgIDU5LAogICAgNjcsCiAgICA4MywKICAgIDk5LAogICAgMTE1LAogICAgMTMxLAogICAgMTYzLAogICAgMTk1LAogICAgMjI3LAogICAgMjU4LAogICAgMCwKICAgIDAKXSksIERuID0gbmV3IFVpbnQ4QXJyYXkoWwogICAgMTYsCiAgICAxNiwKICAgIDE2LAogICAgMTYsCiAgICAxNiwKICAgIDE2LAogICAgMTYsCiAgICAxNiwKICAgIDE3LAogICAgMTcsCiAgICAxNywKICAgIDE3LAogICAgMTgsCiAgICAxOCwKICAgIDE4LAogICAgMTgsCiAgICAxOSwKICAgIDE5LAogICAgMTksCiAgICAxOSwKICAgIDIwLAogICAgMjAsCiAgICAyMCwKICAgIDIwLAogICAgMjEsCiAgICAyMSwKICAgIDIxLAogICAgMjEsCiAgICAxNiwKICAgIDcyLAogICAgNzgKXSksIFpuID0gbmV3IFVpbnQxNkFycmF5KFsKICAgIDEsCiAgICAyLAogICAgMywKICAgIDQsCiAgICA1LAogICAgNywKICAgIDksCiAgICAxMywKICAgIDE3LAogICAgMjUsCiAgICAzMywKICAgIDQ5LAogICAgNjUsCiAgICA5NywKICAgIDEyOSwKICAgIDE5MywKICAgIDI1NywKICAgIDM4NSwKICAgIDUxMywKICAgIDc2OSwKICAgIDEwMjUsCiAgICAxNTM3LAogICAgMjA0OSwKICAgIDMwNzMsCiAgICA0MDk3LAogICAgNjE0NSwKICAgIDgxOTMsCiAgICAxMjI4OSwKICAgIDE2Mzg1LAogICAgMjQ1NzcsCiAgICAwLAogICAgMApdKSwgSW4gPSBuZXcgVWludDhBcnJheShbCiAgICAxNiwKICAgIDE2LAogICAgMTYsCiAgICAxNiwKICAgIDE3LAogICAgMTcsCiAgICAxOCwKICAgIDE4LAogICAgMTksCiAgICAxOSwKICAgIDIwLAogICAgMjAsCiAgICAyMSwKICAgIDIxLAogICAg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bGwpLCBuLndyYXAgPSB0LCBuLndiaXRzID0gaSwgSWkoZSkpOwp9LCBOaSA9IChlLCBpKT0+ewogICAgaWYgKCFlKSByZXR1cm4gVTsKICAgIGxldCB0ID0gbmV3IFBuOwogICAgZS5zdGF0ZSA9IHQsIHQud2luZG93ID0gbnVsbDsKICAgIGxldCBuID0gT2koZSwgaSk7CiAgICByZXR1cm4gbiAhPT0gYWUgJiYgKGUuc3RhdGUgPSBudWxsKSwgbjsKfSwgWG4gPSAoZSk9Pk5pKGUsIEtuKSwgdGkgPSAhMCwgYXQsIG50LCBZbiA9IChlKT0+ewogICAgaWYgKHRpKSB7CiAgICAgICAgYXQgPSBuZXcgSW50MzJBcnJheSg1MTIpLCBudCA9IG5ldyBJbnQzMkFycmF5KDMyKTsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgZm9yKDsgaSA8IDE0NDspZS5sZW5zW2krK10gPSA4OwogICAgICAgIGZvcig7IGkgPCAyNTY7KWUubGVuc1tpKytdID0gOTsKICAgICAgICBmb3IoOyBpIDwgMjgwOyllLmxlbnNbaSsrXSA9IDc7CiAgICAgICAgZm9yKDsgaSA8IDI4ODspZS5sZW5zW2krK10gPSA4OwogICAgICAgIGZvcih3ZShBaSwgZS5sZW5zLCAwLCAyODgsIGF0LCAwLCBlLndvcmssIHsKICAgICAgICAgICAgYml0czogOQogICAgICAgIH0pLCBpID0gMDsgaSA8IDMyOyllLmxlbnNbaSsrXSA9IDU7CiAgICAgICAgd2UoUmksIGUubGVucywgMCwgMzIsIG50LCAwLCBlLndvcmssIHsKICAgICAgICAgICAgYml0czogNQogICAgICAgIH0pLCB0aSA9ICExOwogICAgfQogICAgZS5sZW5jb2RlID0gYXQsIGUubGVuYml0cyA9IDksIGUuZGlzdGNvZGUgPSBudCwgZS5kaXN0Yml0cyA9IDU7Cn0sIExpID0gKGUsIGksIHQsIG4pPT57CiAgICBsZXQgYSwgbCA9IGUuc3RhdGU7CiAgICByZXR1cm4gbC53aW5kb3cgPT09IG51bGwgJiYgKGwud3NpemUgPSAxIDw8IGwud2JpdHMsIGwud25leHQgPSAwLCBsLndoYXZlID0gMCwgbC53aW5kb3cgPSBuZXcgVWludDhBcnJheShsLndzaXplKSksIG4gPj0gbC53c2l6ZSA/IChsLndpbmRvdy5zZXQoaS5zdWJhcnJheSh0IC0gbC53c2l6ZSwgdCksIDApLCBsLnduZXh0ID0gMCwgbC53aGF2ZSA9IGwud3NpemUpIDogKGEgPSBsLndzaXplIC0gbC53bmV4dCwgYSA+IG4gJiYgKGEgPSBuKSwgbC53aW5kb3cuc2V0KGkuc3ViYXJyYXkodCAtIG4sIHQgLSBuICsgYSksIGwud25leHQpLCBuIC09IGEsIG4gPyAobC53aW5kb3cuc2V0KGkuc3ViYXJyYXkodCAtIG4sIHQpLCAwKSwgbC53bmV4dCA9IG4sIGwud2hhdmUgPSBsLndzaXplKSA6IChsLnduZXh0ICs9IGEsIGwud25leHQgPT09IGwud3NpemUgJiYgKGwud25leHQgPSAwKSwgbC53aGF2ZSA8IGwud3NpemUgJiYgKGwud2hhdmUgKz0gYSkpKSwgMDsKfSwgR24gPSAoZSwgaSk9PnsKICAgIGxldCB0LCBuLCBhLCBsLCBvLCBmLCBjLCByLCBfLCBFLCBzLCBoLCB1LCBtLCB2ID0gMCwgdywgQSwgeCwgZCwgUywgWiwgYiwgeiwgUiA9IG5ldyBVaW50OEFycmF5KDQpLCBnLCBwLCBKID0gbmV3IFVpbnQ4QXJyYXkoWwogICAgICAgIDE2LAogICAgICAgIDE3LAogICAgICAgIDE4LAogICAgICAgIDAsCiAgICAgICAgOCwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgNiwKICAgICAgICAxMCwKICAgICAgICA1LAogICAgICAgIDExLAogICAgICAgIDQsCiAgICAgICAgMTIsCiAgICAgICAgMywKICAgICAgICAxMywKICAgICAgICAyLAogICAgICAgIDE0LAogICAgICAgIDEsCiAgICAgICAgMTUKICAgIF0pOwogICAgaWYgKCFlIHx8ICFlLnN0YXRlIHx8ICFlLm91dHB1dCB8fCAhZS5pbnB1dCAmJiBlLmF2YWlsX2luICE9PSAwKSByZXR1cm4gVTsKICAgIHQgPSBlLnN0YXRlLCB0Lm1vZGUgPT09IEggJiYgKHQubW9kZSA9IGV0KSwgbyA9IGUubmV4dF9vdXQsIGEgPSBlLm91dHB1dCwgYyA9IGUuYXZhaWxfb3V0LCBsID0gZS5uZXh0X2luLCBuID0gZS5pbnB1dCwgZiA9IGUuYXZhaWxfaW4sIHIgPSB0LmhvbGQsIF8gPSB0LmJpdHMsIEUgPSBmLCBzID0gYywgeiA9IGFlOwogICAgZTogZm9yKDs7KXN3aXRjaCh0Lm1vZGUpewogICAgICAgIGNhc2UgbWk6CiAgICAgICAgICAgIGlmICh0LndyYXAgPT09IDApIHsKICAgICAgICAgICAgICAgIHQubW9kZSA9IGV0OwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yKDsgXyA8IDE2Oyl7CiAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgIGYtLSwgciArPSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0LndyYXAgJiAyICYmIHIgPT09IDM1NjE1KSB7CiAgICAgICAgICAgICAgICB0LmNoZWNrID0gMCwgUlswXSA9IHIgJiAyNTUsIFJbMV0gPSByID4+PiA4ICYgMjU1LCB0LmNoZWNrID0gSSh0LmNoZWNrLCBSLCAyLCAwKSwgciA9IDAsIF8gPSAwLCB0Lm1vZGUgPSBPdDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0LmZsYWdzID0gMCwgdC5oZWFkICYmICh0LmhlYWQuZG9uZSA9ICExKSwgISh0LndyYXAgJiAxKSB8fCAoKChyICYgMjU1KSA8PCA4KSArIChyID4+IDgpKSAlIDMxKSB7CiAgICAgICAgICAgICAgICBlLm1zZyA9ICJpbmNvcnJlY3QgaGVhZGVyIGNoZWNrIiwgdC5tb2RlID0gVDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICgociAmIDE1KSAhPT0gSXQpIHsKICAgICAgICAgICAgICAgIGUubXNnID0gInVua25vd24gY29tcHJlc3Npb24gbWV0aG9kIiwgdC5tb2RlID0gVDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChyID4+Pj0gNCwgXyAtPSA0LCBiID0gKHIgJiAxNSkgKyA4LCB0LndiaXRzID09PSAwKSB0LndiaXRzID0gYjsKICAgICAgICAgICAgZWxzZSBpZiAoYiA+IHQud2JpdHMpIHsKICAgICAgICAgICAgICAgIGUubXNnID0gImludmFsaWQgd2luZG93IHNpemUiLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdC5kbWF4ID0gMSA8PCB0LndiaXRzLCBlLmFkbGVyID0gdC5jaGVjayA9IDEsIHQubW9kZSA9IHIgJiA1MTIgPyBIdCA6IEgsIHIgPSAwLCBfID0gMDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBPdDoKICAgICAgICAgICAgZm9yKDsgXyA8IDE2Oyl7CiAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgIGYtLSwgciArPSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0LmZsYWdzID0gciwgKHQuZmxhZ3MgJiAyNTUpICE9PSBJdCkgewogICAgICAgICAgICAgICAgZS5tc2cgPSAidW5rbm93biBjb21wcmVzc2lvbiBtZXRob2QiLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHQuZmxhZ3MgJiA1NzM0NCkgewogICAgICAgICAgICAgICAgZS5tc2cgPSAidW5rbm93biBoZWFkZXIgZmxhZ3Mgc2V0IiwgdC5tb2RlID0gVDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHQuaGVhZCAmJiAodC5oZWFkLnRleHQgPSByID4+IDggJiAxKSwgdC5mbGFncyAmIDUxMiAmJiAoUlswXSA9IHIgJiAyNTUsIFJbMV0gPSByID4+PiA4ICYgMjU1LCB0LmNoZWNrID0gSSh0LmNoZWNrLCBSLCAyLCAwKSksIHIgPSAwLCBfID0gMCwgdC5tb2RlID0gTnQ7CiAgICAgICAgY2FzZSBOdDoKICAgICAgICAgICAgZm9yKDsgXyA8IDMyOyl7CiAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgIGYtLSwgciArPSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIHQuaGVhZCAmJiAodC5oZWFkLnRpbWUgPSByKSwgdC5mbGFncyAmIDUxMiAmJiAoUlswXSA9IHIgJiAyNTUsIFJbMV0gPSByID4+PiA4ICYgMjU1LCBSWzJdID0gciA+Pj4gMTYgJiAyNTUsIFJbM10gPSByID4+PiAyNCAmIDI1NSwgdC5jaGVjayA9IEkodC5jaGVjaywgUiwgNCwgMCkpLCByID0gMCwgXyA9IDAsIHQubW9kZSA9IEx0OwogICAgICAgIGNhc2UgTHQ6CiAgICAgICAgICAgIGZvcig7IF8gPCAxNjspewogICAgICAgICAgICAgICAgaWYgKGYgPT09IDApIGJyZWFrIGU7CiAgICAgICAgICAgICAgICBmLS0sIHIgKz0gbltsKytdIDw8IF8sIF8gKz0gODsKICAgICAgICAgICAgfQogICAgICAgICAgICB0LmhlYWQgJiYgKHQuaGVhZC54ZmxhZ3MgPSByICYgMjU1LCB0LmhlYWQub3MgPSByID4+IDgpLCB0LmZsYWdzICYgNTEyICYm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ICs9IGgsIHQubGVuZ3RoIC09IGgpLCB0Lmxlbmd0aCkpIGJyZWFrIGU7CiAgICAgICAgICAgIHQubGVuZ3RoID0gMCwgdC5tb2RlID0gQ3Q7CiAgICAgICAgY2FzZSBDdDoKICAgICAgICAgICAgaWYgKHQuZmxhZ3MgJiAyMDQ4KSB7CiAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgIGggPSAwOwogICAgICAgICAgICAgICAgZG8gYiA9IG5bbCArIGgrK10sIHQuaGVhZCAmJiBiICYmIHQubGVuZ3RoIDwgNjU1MzYgJiYgKHQuaGVhZC5uYW1lICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYikpOwogICAgICAgICAgICAgICAgd2hpbGUgKGIgJiYgaCA8IGYpCiAgICAgICAgICAgICAgICBpZiAodC5mbGFncyAmIDUxMiAmJiAodC5jaGVjayA9IEkodC5jaGVjaywgbiwgaCwgbCkpLCBmIC09IGgsIGwgKz0gaCwgYikgYnJlYWsgZTsKICAgICAgICAgICAgfSBlbHNlIHQuaGVhZCAmJiAodC5oZWFkLm5hbWUgPSBudWxsKTsKICAgICAgICAgICAgdC5sZW5ndGggPSAwLCB0Lm1vZGUgPSBGdDsKICAgICAgICBjYXNlIEZ0OgogICAgICAgICAgICBpZiAodC5mbGFncyAmIDQwOTYpIHsKICAgICAgICAgICAgICAgIGlmIChmID09PSAwKSBicmVhayBlOwogICAgICAgICAgICAgICAgaCA9IDA7CiAgICAgICAgICAgICAgICBkbyBiID0gbltsICsgaCsrXSwgdC5oZWFkICYmIGIgJiYgdC5sZW5ndGggPCA2NTUzNiAmJiAodC5oZWFkLmNvbW1lbnQgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShiKSk7CiAgICAgICAgICAgICAgICB3aGlsZSAoYiAmJiBoIDwgZikKICAgICAgICAgICAgICAgIGlmICh0LmZsYWdzICYgNTEyICYmICh0LmNoZWNrID0gSSh0LmNoZWNrLCBuLCBoLCBsKSksIGYgLT0gaCwgbCArPSBoLCBiKSBicmVhayBlOwogICAgICAgICAgICB9IGVsc2UgdC5oZWFkICYmICh0LmhlYWQuY29tbWVudCA9IG51bGwpOwogICAgICAgICAgICB0Lm1vZGUgPSBNdDsKICAgICAgICBjYXNlIE10OgogICAgICAgICAgICBpZiAodC5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgZm9yKDsgXyA8IDE2Oyl7CiAgICAgICAgICAgICAgICAgICAgaWYgKGYgPT09IDApIGJyZWFrIGU7CiAgICAgICAgICAgICAgICAgICAgZi0tLCByICs9IG5bbCsrXSA8PCBfLCBfICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAociAhPT0gKHQuY2hlY2sgJiA2NTUzNSkpIHsKICAgICAgICAgICAgICAgICAgICBlLm1zZyA9ICJoZWFkZXIgY3JjIG1pc21hdGNoIiwgdC5tb2RlID0gVDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHIgPSAwLCBfID0gMDsKICAgICAgICAgICAgfQogICAgICAgICAgICB0LmhlYWQgJiYgKHQuaGVhZC5oY3JjID0gdC5mbGFncyA+PiA5ICYgMSwgdC5oZWFkLmRvbmUgPSAhMCksIGUuYWRsZXIgPSB0LmNoZWNrID0gMCwgdC5tb2RlID0gSDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBIdDoKICAgICAgICAgICAgZm9yKDsgXyA8IDMyOyl7CiAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgIGYtLSwgciArPSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGUuYWRsZXIgPSB0LmNoZWNrID0gZWkociksIHIgPSAwLCBfID0gMCwgdC5tb2RlID0gS2U7CiAgICAgICAgY2FzZSBLZToKICAgICAgICAgICAgaWYgKHQuaGF2ZWRpY3QgPT09IDApIHJldHVybiBlLm5leHRfb3V0ID0gbywgZS5hdmFpbF9vdXQgPSBjLCBlLm5leHRfaW4gPSBsLCBlLmF2YWlsX2luID0gZiwgdC5ob2xkID0gciwgdC5iaXRzID0gXywgJG47CiAgICAgICAgICAgIGUuYWRsZXIgPSB0LmNoZWNrID0gMSwgdC5tb2RlID0gSDsKICAgICAgICBjYXNlIEg6CiAgICAgICAgICAgIGlmIChpID09PSBMbiB8fCBpID09PSBOZSkgYnJlYWsgZTsKICAgICAgICBjYXNlIGV0OgogICAgICAgICAgICBpZiAodC5sYXN0KSB7CiAgICAgICAgICAgICAgICByID4+Pj0gXyAmIDcsIF8gLT0gXyAmIDcsIHQubW9kZSA9IGl0OwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yKDsgXyA8IDM7KXsKICAgICAgICAgICAgICAgIGlmIChmID09PSAwKSBicmVhayBlOwogICAgICAgICAgICAgICAgZi0tLCByICs9IG5bbCsrXSA8PCBfLCBfICs9IDg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc3dpdGNoKHQubGFzdCA9IHIgJiAxLCByID4+Pj0gMSwgXyAtPSAxLCByICYgMyl7CiAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgdC5tb2RlID0gQnQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgICAgICAgICAgaWYgKFluKHQpLCB0Lm1vZGUgPSBMZSwgaSA9PT0gTmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgciA+Pj49IDIsIF8gLT0gMjsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICAgICAgdC5tb2RlID0gUHQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICAgICAgZS5tc2cgPSAiaW52YWxpZCBibG9jayB0eXBlIiwgdC5tb2RlID0gVDsKICAgICAgICAgICAgfQogICAgICAgICAgICByID4+Pj0gMiwgXyAtPSAyOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIEJ0OgogICAgICAgICAgICBmb3IociA+Pj49IF8gJiA3LCBfIC09IF8gJiA3OyBfIDwgMzI7KXsKICAgICAgICAgICAgICAgIGlmIChmID09PSAwKSBicmVhayBlOwogICAgICAgICAgICAgICAgZi0tLCByICs9IG5bbCsrXSA8PCBfLCBfICs9IDg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKChyICYgNjU1MzUpICE9PSAociA+Pj4gMTYgXiA2NTUzNSkpIHsKICAgICAgICAgICAgICAgIGUubXNnID0gImludmFsaWQgc3RvcmVkIGJsb2NrIGxlbmd0aHMiLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHQubGVuZ3RoID0gciAmIDY1NTM1LCByID0gMCwgXyA9IDAsIHQubW9kZSA9IHR0LCBpID09PSBOZSkgYnJlYWsgZTsKICAgICAgICBjYXNlIHR0OgogICAgICAgICAgICB0Lm1vZGUgPSBLdDsKICAgICAgICBjYXNlIEt0OgogICAgICAgICAgICBpZiAoaCA9IHQubGVuZ3RoLCBoKSB7CiAgICAgICAgICAgICAgICBpZiAoaCA+IGYgJiYgKGggPSBmKSwgaCA+IGMgJiYgKGggPSBjKSwgaCA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgIGEuc2V0KG4uc3ViYXJyYXkobCwgbCArIGgpLCBvKSwgZiAtPSBoLCBsICs9IGgsIGMgLT0gaCwgbyArPSBoLCB0Lmxlbmd0aCAtPSBoOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdC5tb2RlID0gSDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBQdDoKICAgICAgICAgICAgZm9yKDsgXyA8IDE0Oyl7CiAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgIGYtLSwgciArPSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0Lm5sZW4gPSAociAmIDMxKSArIDI1NywgciA+Pj49IDUsIF8gLT0gNSwgdC5uZGlzdCA9IChyICYgMzEpICsgMSwgciA+Pj49IDUsIF8gLT0gNSwgdC5uY29kZSA9IChyICYgMTUpICsgNCwgciA+Pj49IDQsIF8gLT0gNCwgdC5ubGVuID4gMjg2IHx8IHQubmRpc3QgPiAzMCkgewogICAgICAgICAgICAgICAgZS5tc2cgPSAidG9vIG1hbnkgbGVuZ3RoIG9yIGRpc3RhbmNlIHN5bWJvbHMiLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdC5oYXZlID0gMCwgdC5tb2RlID0gWHQ7CiAgICAgICAgY2FzZSBYdDoKICAgICAgICAgICAgZm9yKDsgdC5oYXZlIDwgdC5uY29kZTspewogICAgICAgICAgICAgICAgZm9yKDsgXyA8IDM7KXsKICAgICAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgICAgICBmLS0sIHIgKz0gbltsKytdIDw8IF8sIF8gKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHQubGVuc1tKW3QuaGF2ZSsrXV0gPSByICYgNywgciA+Pj49IDMsIF8gLT0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IoOyB0LmhhdmUgPCAxOTspdC5sZW5zW0pbdC5oYXZlKytdXSA9IDA7CiAgICAgICAgICAgIGlmICh0LmxlbmNvZGUgPSB0LmxlbmR5biwgdC5sZW5iaXRzID0gNywgZyA9IHsKICAgICAgICAgICAgICAgIGJpdHM6IHQubGVuYml0cwogICAgICAgICAgICB9LCB6ID0gd2UoTm4sIHQubGVucywgMCwgMTksIHQubGVuY29kZSwgMCwgdC53b3JrLCBnKSwgdC5sZW5iaXRzID0gZy5iaXRzLCB6KSB7CiAgICAgICAgICAgICAgICBlLm1zZyA9ICJpbnZhbGlkIGNvZGUgbGVuZ3RocyBzZXQiLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdC5oYXZlID0gMCwgdC5tb2RlID0gWXQ7CiAgICAgICAgY2FzZSBZdDoKICAgICAgICAgICAgZm9yKDsgdC5oYXZlIDwgdC5ubGVuICsgdC5uZGlzdDspewogICAgICAgICAgICAgICAgZm9yKDsgdiA9IHQubGVuY29kZVtyICYgKDEgPDwgdC5sZW5iaXRzKSAtIDFdLCB3ID0gdiA+Pj4gMjQsIEEgPSB2ID4+PiAxNiAmIDI1NSwgeCA9IHYgJiA2NTUzNSwgISh3IDw9IF8pOyl7CiAgICAgICAgICAgICAgICAgICAgaWYgKGYgPT09IDApIGJyZWFrIGU7CiAgICAgICAgICAgICAgICAgICAgZi0tLCByICs9IG5bbCsrXSA8PCBfLCBfICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoeCA8IDE2KSByID4+Pj0gdywgXyAtPSB3LCB0LmxlbnNbdC5oYXZlKytdID0geDsKICAgICAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmICh4ID09PSAxNikgewogICAgICAgICAgICAgICAgICAgICAgICBmb3IocCA9IHcgKyAyOyBfIDwgcDspewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGYgPT09IDApIGJyZWFrIGU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmLS0sIHIgKz0gbltsKytdIDw8IF8sIF8gKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpZiAociA+Pj49IHcsIF8gLT0gdywgdC5oYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlLm1zZyA9ICJpbnZhbGlkIGJpdCBsZW5ndGggcmVwZWF0IiwgdC5tb2RlID0gVDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGIgPSB0LmxlbnNbdC5oYXZlIC0gMV0sIGggPSAzICsgKHIgJiAzKSwgciA+Pj49IDIsIF8gLT0gMjsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHggPT09IDE3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvcihwID0gdyArIDM7IF8gPCBwOyl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGYtLSwgciArPSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIHIgPj4+PSB3LCBfIC09IHcsIGIgPSAwLCBoID0gMyArIChyICYgNyksIHIgPj4+PSAzLCBfIC09IDM7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yKHAgPSB3ICsgNzsgXyA8IHA7KXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChmID09PSAwKSBicmVhayBlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgZi0tLCByICs9IG5bbCsrXSA8PCBfLCBfICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgciA+Pj49IHcsIF8gLT0gdywgYiA9IDAsIGggPSAxMSArIChyICYgMTI3KSwgciA+Pj49IDcsIF8gLT0gNzsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKHQuaGF2ZSArIGggPiB0Lm5sZW4gKyB0Lm5kaXN0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGUubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgZm9yKDsgaC0tOyl0LmxlbnNbdC5oYXZlKytdID0gYjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodC5tb2RlID09PSBUKSBicmVhazsKICAgICAgICAgICAgaWYgKHQubGVuc1syNTZdID09PSAwKSB7CiAgICAgICAgICAgICAgICBlLm1zZyA9ICJpbnZhbGlkIGNvZGUgLS0gbWlzc2luZyBlbmQtb2YtYmxvY2siLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHQubGVuYml0cyA9IDksIGcgPSB7CiAgICAgICAgICAgICAgICBiaXRzOiB0LmxlbmJpdHMKICAgICAgICAgICAgfSwgeiA9IHdlKEFpLCB0LmxlbnMsIDAsIHQubmxlbiwgdC5sZW5jb2RlLCAwLCB0LndvcmssIGcpLCB0LmxlbmJpdHMgPSBnLmJpdHMsIHopIHsKICAgICAgICAgICAgICAgIGUubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGhzIHNldCIsIHQubW9kZSA9IFQ7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodC5kaXN0Yml0cyA9IDYsIHQuZGlzdGNvZGUgPSB0LmRpc3RkeW4sIGcgPSB7CiAgICAgICAgICAgICAgICBiaXRzOiB0LmRpc3RiaXRzCiAgICAgICAgICAgIH0sIHogPSB3ZShSaSwgdC5sZW5zLCB0Lm5sZW4sIHQubmRpc3QsIHQuZGlzdGNvZGUsIDAsIHQud29yaywgZyksIHQuZGlzdGJpdHMgPSBnLmJpdHMsIHopIHsKICAgICAgICAgICAgICAgIGUubXNnID0gImludmFsaWQgZGlzdGFuY2VzIHNldCIsIHQubW9kZSA9IFQ7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodC5tb2RlID0gTGUsIGkgPT09IE5lKSBicmVhayBlOwogICAgICAgIGNhc2UgTGU6CiAgICAgICAgICAgIHQubW9kZSA9IFVlOwogICAgICAgIGNhc2UgVWU6CiAgICAgICAgICAgIGlmIChmID49IDYgJiYgYyA+PSAyNTgpIHsKICAgICAgICAgICAgICAgIGUubmV4dF9vdXQgPSBvLCBlLmF2YWlsX291dCA9IGMsIGUubmV4dF9pbiA9IGwsIGUuYXZhaWxfaW4gPSBmLCB0LmhvbGQgPSByLCB0LmJpdHMgPSBfLCBUbihlLCBzKSwgbyA9IGUubmV4dF9vdXQsIGEgPSBlLm91dHB1dCwgYyA9IGUuYXZhaWxfb3V0LCBsID0gZS5uZXh0X2luLCBuID0gZS5pbnB1dCwgZiA9IGUuYXZhaWxfaW4sIHIgPSB0LmhvbGQsIF8gPSB0LmJpdHMsIHQubW9kZSA9PT0gSCAmJiAodC5iYWNrID0gLTEpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yKHQuYmFjayA9IDA7IHYgPSB0LmxlbmNvZGVbciAmICgxIDw8IHQubGVuYml0cykgLSAxXSwgdyA9IHYgPj4+IDI0LCBBID0gdiA+Pj4gMTYgJiAyNTUsIHggPSB2ICYgNjU1MzUsICEodyA8PSBfKTspewogICAgICAgICAgICAgICAgaWYgKGYgPT09IDApIGJyZWFrIGU7CiAgICAgICAgICAgICAgICBmLS0sIHIgKz0gbltsKytdIDw8IF8sIF8gKz0gODsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQSAmJiAhKEEgJiAyNDApKSB7CiAgICAgICAgICAgICAgICBmb3IoZCA9IHcsIFMgPSBBLCBaID0geDsgdiA9IHQubGVuY29kZVtaICsgKChyICYgKDEgPDwgZCArIFMpIC0gMSkgPj4gZCldLCB3ID0gdiA+Pj4gMjQsIEEgPSB2ID4+PiAxNiAmIDI1NSwgeCA9IHYgJiA2NTUzNSwgIShkICsgdyA8PSBfKTspewogICAgICAgICAgICAgICAgICAgIGlmIChmID09PSAwKSBicmVhayBlOwogICAgICAgICAgICAgICAgICAgIGYtLSwgciArPSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgciA+Pj49IGQsIF8gLT0gZCwgdC5iYWNrICs9IGQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHIgPj4+PSB3LCBfIC09IHcsIHQuYmFjayArPSB3LCB0Lmxlbmd0aCA9IHgsIEEgPT09IDApIHsKICAgICAgICAgICAgICAgIHQubW9kZSA9IEp0OwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEEgJiAzMikgewogICAgICAgICAgICAgICAgdC5iYWNrID0gLTEsIHQubW9kZSA9IEg7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQSAmIDY0KSB7CiAgICAgICAgICAgICAgICBlLm1zZyA9ICJpbnZhbGlkIGxpdGVyYWwvbGVuZ3RoIGNvZGUiLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdC5leHRyYSA9IEEgJiAxNSwgdC5tb2RlID0gR3Q7CiAgICAgICAgY2FzZSBHdDoKICAgICAgICAgICAgaWYgKHQuZXh0cmEpIHsKICAgICAgICAgICAgICAgIGZvcihwID0gdC5leHRyYTsgXyA8IHA7KXsKICAgICAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgICAgICBmLS0sIHIgKz0gbltsKytdIDw8IF8sIF8gKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHQubGVuZ3RoICs9IHIgJiAoMSA8PCB0LmV4dHJhKSAtIDEsIHIgPj4+PSB0LmV4dHJhLCBfIC09IHQuZXh0cmEsIHQuYmFjayArPSB0LmV4dHJhOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHQud2FzID0gdC5sZW5ndGgsIHQubW9kZSA9IGp0OwogICAgICAgIGNhc2UganQ6CiAgICAgICAgICAgIGZvcig7IHYgPSB0LmRpc3Rjb2RlW3IgJiAoMSA8PCB0LmRpc3RiaXRzKSAtIDFdLCB3ID0gdiA+Pj4gMjQsIEEgPSB2ID4+PiAxNiAmIDI1NSwgeCA9IHYgJiA2NTUzNSwgISh3IDw9IF8pOyl7CiAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgIGYtLSwgciArPSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghKEEgJiAyNDApKSB7CiAgICAgICAgICAgICAgICBmb3IoZCA9IHcsIFMgPSBBLCBaID0geDsgdiA9IHQuZGlzdGNvZGVbWiArICgociAmICgxIDw8IGQgKyBTKSAtIDEpID4+IGQpXSwgdyA9IHYgPj4+IDI0LCBBID0gdiA+Pj4gMTYgJiAyNTUsIHggPSB2ICYgNjU1MzUsICEoZCArIHcgPD0gXyk7KXsKICAgICAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgICAgICBmLS0sIHIgKz0gbltsKytdIDw8IF8sIF8gKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHIgPj4+PSBkLCBfIC09IGQsIHQuYmFjayArPSBkOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChyID4+Pj0gdywgXyAtPSB3LCB0LmJhY2sgKz0gdywgQSAmIDY0KSB7CiAgICAgICAgICAgICAgICBlLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdC5vZmZzZXQgPSB4LCB0LmV4dHJhID0gQSAmIDE1LCB0Lm1vZGUgPSBXdDsKICAgICAgICBjYXNlIFd0OgogICAgICAgICAgICBpZiAodC5leHRyYSkgewogICAgICAgICAgICAgICAgZm9yKHAgPSB0LmV4dHJhOyBfIDwgcDspewogICAgICAgICAgICAgICAgICAgIGlmIChmID09PSAwKSBicmVhayBlOwogICAgICAgICAgICAgICAgICAgIGYtLSwgciArPSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdC5vZmZzZXQgKz0gciAmICgxIDw8IHQuZXh0cmEpIC0gMSwgciA+Pj49IHQuZXh0cmEsIF8gLT0gdC5leHRyYSwgdC5iYWNrICs9IHQuZXh0cmE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHQub2Zmc2V0ID4gdC5kbWF4KSB7CiAgICAgICAgICAgICAgICBlLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayIsIHQubW9kZSA9IFQ7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICB0Lm1vZGUgPSBWdDsKICAgICAgICBjYXNlIFZ0OgogICAgICAgICAgICBpZiAoYyA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgaWYgKGggPSBzIC0gYywgdC5vZmZzZXQgPiBoKSB7CiAgICAgICAgICAgICAgICBpZiAoaCA9IHQub2Zmc2V0IC0gaCwgaCA+IHQud2hhdmUgJiYgdC5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgZS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siLCB0Lm1vZGUgPSBUOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaCA+IHQud25leHQgPyAoaCAtPSB0LnduZXh0LCB1ID0gdC53c2l6ZSAtIGgpIDogdSA9IHQud25leHQgLSBoLCBoID4gdC5sZW5ndGggJiYgKGggPSB0Lmxlbmd0aCksIG0gPSB0LndpbmRvdzsKICAgICAgICAgICAgfSBlbHNlIG0gPSBhLCB1ID0gbyAtIHQub2Zmc2V0LCBoID0gdC5sZW5ndGg7CiAgICAgICAgICAgIGggPiBjICYmIChoID0gYyksIGMgLT0gaCwgdC5sZW5ndGggLT0gaDsKICAgICAgICAgICAgZG8gYVtvKytdID0gbVt1KytdOwogICAgICAgICAgICB3aGlsZSAoLS1oKQogICAgICAgICAgICB0Lmxlbmd0aCA9PT0gMCAmJiAodC5tb2RlID0gVWUpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIEp0OgogICAgICAgICAgICBpZiAoYyA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgYVtvKytdID0gdC5sZW5ndGgsIGMtLSwgdC5tb2RlID0gVWU7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgaXQ6CiAgICAgICAgICAgIGlmICh0LndyYXApIHsKICAgICAgICAgICAgICAgIGZvcig7IF8gPCAzMjspewogICAgICAgICAgICAgICAgICAgIGlmIChmID09PSAwKSBicmVhayBlOwogICAgICAgICAgICAgICAgICAgIGYtLSwgciB8PSBuW2wrK10gPDwgXywgXyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHMgLT0gYywgZS50b3RhbF9vdXQgKz0gcywgdC50b3RhbCArPSBzLCBzICYmIChlLmFkbGVyID0gdC5jaGVjayA9IHQuZmxhZ3MgPyBJKHQuY2hlY2ssIGEsIHMsIG8gLSBzKSA6IHZlKHQuY2hlY2ssIGEsIHMsIG8gLSBzKSksIHMgPSBjLCAodC5mbGFncyA/IHIgOiBlaShyKSkgIT09IHQuY2hlY2spIHsKICAgICAgICAgICAgICAgICAgICBlLm1zZyA9ICJpbmNvcnJlY3QgZGF0YSBjaGVjayIsIHQubW9kZSA9IFQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICByID0gMCwgXyA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdC5tb2RlID0gUXQ7CiAgICAgICAgY2FzZSBRdDoKICAgICAgICAgICAgaWYgKHQud3JhcCAmJiB0LmZsYWdzKSB7CiAgICAgICAgICAgICAgICBmb3IoOyBfIDwgMzI7KXsKICAgICAgICAgICAgICAgICAgICBpZiAoZiA9PT0gMCkgYnJlYWsgZTsKICAgICAgICAgICAgICAgICAgICBmLS0sIHIgKz0gbltsKytdIDw8IF8sIF8gKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChyICE9PSAodC50b3RhbCAmIDQyOTQ5NjcyOTUpKSB7CiAgICAgICAgICAgICAgICAgICAgZS5tc2cgPSAiaW5jb3JyZWN0IGxlbmd0aCBjaGVjayIsIHQubW9kZSA9IFQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICByID0gMCwgXyA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdC5tb2RlID0gcXQ7CiAgICAgICAgY2FzZSBxdDoKICAgICAgICAgICAgeiA9IFVuOwogICAgICAgICAgICBicmVhayBlOwogICAgICAgIGNhc2UgVDoKICAgICAgICAgICAgeiA9IHppOwogICAgICAgICAgICBicmVhayBlOwogICAgICAgIGNhc2UgRGk6CiAgICAgICAgICAgIHJldHVybiBUaTsKICAgICAgICBjYXNlIEZuOgogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHJldHVybiBVOwogICAgfQ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FpbF9vdXQgPT09IDAgJiYgKHQub3V0cHV0ID0gbmV3IFVpbnQ4QXJyYXkobiksIHQubmV4dF9vdXQgPSAwLCB0LmF2YWlsX291dCA9IG4pLCBsID0gSy5pbmZsYXRlKHQsIG8pLCBsID09PSBydCAmJiBhICYmIChsID0gSy5pbmZsYXRlU2V0RGljdGlvbmFyeSh0LCBhKSwgbCA9PT0gU2UgPyBsID0gSy5pbmZsYXRlKHQsIG8pIDogbCA9PT0gaWkgJiYgKGwgPSBydCkpOyB0LmF2YWlsX2luID4gMCAmJiBsID09PSBsdCAmJiB0LnN0YXRlLndyYXAgPiAwICYmIGVbdC5uZXh0X2luXSAhPT0gMDspSy5pbmZsYXRlUmVzZXQodCksIGwgPSBLLmluZmxhdGUodCwgbyk7CiAgICAgICAgc3dpdGNoKGwpewogICAgICAgICAgICBjYXNlIGRsOgogICAgICAgICAgICBjYXNlIGlpOgogICAgICAgICAgICBjYXNlIHJ0OgogICAgICAgICAgICBjYXNlIHNsOgogICAgICAgICAgICAgICAgcmV0dXJuIHRoaXMub25FbmQobCksIHRoaXMuZW5kZWQgPSAhMCwgITE7CiAgICAgICAgfQogICAgICAgIGlmIChmID0gdC5hdmFpbF9vdXQsIHQubmV4dF9vdXQgJiYgKHQuYXZhaWxfb3V0ID09PSAwIHx8IGwgPT09IGx0KSkgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgbGV0IGMgPSB5ZS51dGY4Ym9yZGVyKHQub3V0cHV0LCB0Lm5leHRfb3V0KSwgciA9IHQubmV4dF9vdXQgLSBjLCBfID0geWUuYnVmMnN0cmluZyh0Lm91dHB1dCwgYyk7CiAgICAgICAgICAgIHQubmV4dF9vdXQgPSByLCB0LmF2YWlsX291dCA9IG4gLSByLCByICYmIHQub3V0cHV0LnNldCh0Lm91dHB1dC5zdWJhcnJheShjLCBjICsgciksIDApLCB0aGlzLm9uRGF0YShfKTsKICAgICAgICB9IGVsc2UgdGhpcy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pbGUgY29ubmVjdGlvbiBpcyBvZmZsaW5lIik7CiAgICB9Cn0KY2xhc3MgT2JzZXJ2YWJsZSB7CiAgICAjY2FsbGJhY2tzID0gW107CiAgICBjb25zdHJ1Y3RvcihpZCwgdmFsdWUpewogICAgICAgIHRoaXMuaWQgPSBpZDsKICAgICAgICB0aGlzLnZhbHVlID0gdmFsdWU7CiAgICB9CiAgICBub3RpZnkodmFsdWUsIGRvbnRfbm90aWZ5X2p1bGlhKSB7CiAgICAgICAgaWYgKHZhbHVlKSB7CiAgICAgICAgICAgIHRoaXMudmFsdWUgPSB2YWx1ZTsKICAgICAgICB9CiAgICAgICAgdGhpcy4jY2FsbGJhY2tzLmZvckVhY2goKGNhbGxiYWNrKT0+ewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgY29uc3QgZGVyZWdpc3RlciA9IGNhbGxiYWNrKHZhbHVlKTsKICAgICAgICAgICAgICAgIGlmIChkZXJlZ2lzdGVyID09IGZhbHNlKSB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy4jY2FsbGJhY2tzLnNwbGljZSh0aGlzLiNjYWxsYmFja3MuaW5kZXhPZihjYWxsYmFjayksIDEpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGNhdGNoIChleGNlcHRpb24pIHsKICAgICAgICAgICAgICAgIHNlbmRfZXJyb3IoIkVycm9yIGR1cmluZyBydW5uaW5nIG9uanMgY2FsbGJhY2tcbiIgKyAiQ2FsbGJhY2s6XG4iICsgY2FsbGJhY2sudG9TdHJpbmcoKSwgZXhjZXB0aW9uKTsKICAgICAgICAgICAgfQogICAgICAgIH0pOwogICAgICAgIGlmICghZG9udF9ub3RpZnlfanVsaWEpIHsKICAgICAgICAgICAgc2VuZF90b19qdWxpYSh7CiAgICAgICAgICAgICAgICBtc2dfdHlwZTogVXBkYXRlT2JzZXJ2YWJsZSwKICAgICAgICAgICAgICAgIGlkOiB0aGlzLmlkLAogICAgICAgICAgICAgICAgcGF5bG9hZDogdmFsdWUKICAgICAgICAgICAgfSk7CiAgICAgICAgfQogICAgfQogICAgb24oY2FsbGJhY2spIHsKICAgICAgICB0aGlzLiNjYWxsYmFja3MucHVzaChjYWxsYmFjayk7CiAgICB9Cn0KcmVnaXN0ZXJfZXh0KDEwMSwgKHVpbnRfOF9hcnJheSk9PnsKICAgIGNvbnN0IFtpZCwgdmFsdWVdID0gdW5wYWNrKHVpbnRfOF9hcnJheSk7CiAgICByZXR1cm4gbmV3IE9ic2VydmFibGUoaWQsIHZhbHVlKTsKfSk7CnJlZ2lzdGVyX2V4dCgxMDIsICh1aW50XzhfYXJyYXkpPT57CiAgICBjb25zdCBbaW50ZXJwb2xhdGVkX29iamVjdHMsIHNvdXJjZSwganVsaWFfZmlsZV0gPSB1bnBhY2sodWludF84X2FycmF5KTsKICAgIGNvbnN0IGxvb2t1cF9pbnRlcnBvbGF0ZWQgPSAoaWQpPT5pbnRlcnBvbGF0ZWRfb2JqZWN0c1tpZF07CiAgICB0cnkgewogICAgICAgIGNvbnN0IGV2YWxfZnVuYyA9IG5ldyBGdW5jdGlvbigiX19sb29rdXBfaW50ZXJwb2xhdGVkIiwgIkpTU2VydmUiLCBzb3VyY2UpOwogICAgICAgIHJldHVybiAoKT0+ewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgcmV0dXJuIGV2YWxfZnVuYyhsb29rdXBfaW50ZXJwb2xhdGVkLCB3aW5kb3cuSlNTZXJ2ZSk7CiAgICAgICAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coYGVycm9yIGluIGNsb3N1cmUgZnJvbTogJHtqdWxpYV9maWxlfWApOwogICAgICAgICAgICAgICAgY29uc29sZS5sb2coYFNvdXJjZTpgKTsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHNvdXJjZSk7CiAgICAgICAgICAgICAgICB0aHJvdyBlcnI7CiAgICAgICAgICAgIH0KICAgICAgICB9OwogICAgfSBjYXRjaCAoZXJyK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AgICAgIHN1YnNlc3Npb24KICAgIH0pOwp9CmNsYXNzIExvY2sgewogICAgY29uc3RydWN0b3IoKXsKICAgICAgICB0aGlzLmxvY2tlZCA9IGZhbHNlOwogICAgICAgIHRoaXMucXVldWUgPSBbXTsKICAgICAgICB0aGlzLmxvY2tpbmdfdGFza3MgPSBuZXcgU2V0KCk7CiAgICB9CiAgICB1bmxvY2soKSB7CiAgICAgICAgdGhpcy5sb2NrZWQgPSBmYWxzZTsKICAgICAgICBpZiAodGhpcy5xdWV1ZS5sZW5ndGggPiAwKSB7CiAgICAgICAgICAgIGNvbnN0IGpvYiA9IHRoaXMucXVldWUucG9wKCk7CiAgICAgICAgICAgIHRoaXMubG9jayhqb2IpOwogICAgICAgIH0KICAgIH0KICAgIHRhc2tfbG9jayh0YXNrX2lkKSB7CiAgICAgICAgdGhpcy5sb2NrZWQgPSB0cnVlOwogICAgICAgIHRoaXMubG9ja2luZ190YXNrcy5hZGQodGFza19pZCk7CiAgICB9CiAgICB0YXNrX3VubG9jayh0YXNrX2lkKSB7CiAgICAgICAgdGhpcy5sb2NraW5nX3Rhc2tzLmRlbGV0ZSh0YXNrX2lkKTsKICAgICAgICBpZiAodGhpcy5sb2NraW5nX3Rhc2tzLnNpemUgPT0gMCkgewogICAgICAgICAgICB0aGlzLnVubG9jaygpOwogICAgICAgIH0KICAgIH0KICAgIGxvY2soZnVuYykgewogICAgICAgIHJldHVybiBuZXcgUHJvbWlzZSgocmVzb2x2ZSk9PnsKICAgICAgICAgICAgaWYgKHRoaXMubG9ja2VkKSB7CiAgICAgICAgICAgICAgICBjb25zdCBmdW5jX3JlcyA9ICgpPT5Qcm9taXNlLnJlc29sdmUoZnVuYygpKS50aGVuKHJlc29sdmUpOwogICAgICAgICAgICAgICAgdGhpcy5xdWV1ZS5wdXNoKGZ1bmNfcmVzKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHRoaXMubG9ja2VkID0gdHJ1ZTsKICAgICAgICAgICAgICAgIFByb21pc2UucmVzb2x2ZShmdW5jKCkpLnRoZW4oKHgpPT57CiAgICAgICAgICAgICAgICAgICAgdGhpcy51bmxvY2soKTsKICAgICAgICAgICAgICAgICAgICByZXNvbHZlKHgpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0KICAgICAgICB9KTsKICAgIH0KfQpmdW5jdGlvbiBwcm9jZXNzX21lc3NhZ2UoZGF0YSkgewogICAgdHJ5IHsKICAgICAgICBzd2l0Y2goZGF0YS5tc2dfdHlwZSl7CiAgICAgICAgICAgIGNhc2UgVXBkYXRlT2JzZXJ2YWJsZToKICAgICAgICAgICAgICAgIGxvb2t1cF9nbG9iYWxfb2JqZWN0KGRhdGEuaWQpLm5vdGlmeShkYXRhLnBheWxvYWQsIHRydWUpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgT25qc0NhbGxiYWNrOgogICAgICAgICAgICAgICAgZGF0YS5vYnMub24oZGF0YS5wYXlsb2FkKCkpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgRXZhbEphdmFzY3JpcHQ6CiAgICAgICAgICAgICAgICBkYXRhLnBheWxvYWQoKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIEZ1c2VkTWVzc2FnZToKICAgICAgICAgICAgICAgIGRhdGEucGF5bG9hZC5mb3JFYWNoKHByb2Nlc3NfbWVzc2FnZSk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSBQaW5nUG9uZzoKICAgICAgICAgICAgICAgIGNvbnNvbGUuZGVidWcoInBpbmciKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIFVwZGF0ZVNlc3Npb246CiAgICAgICAgICAgICAgICB1cGRhdGVfc2Vzc2lvbl9kb20oZGF0YSk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICA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ogICAgICAgIGlmIChkYXRhIGluc3RhbmNlb2YgUHJvbWlzZSkgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGlmIChkYXRhIGluc3RhbmNlb2YgUmV0YWluKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgaWYgKCFpc19zdGlsbF9yZWZlcmVuY2VkKGlkKSkgewogICAgICAgICAgICBkZWxldGUgR0xPQkFMX09CSkVDVF9DQUNIRVtpZF07CiAgICAgICAgfQogICAgICAgIHJldHVybjsKICAgIH0gZWxzZSB7CiAgICAgICAgY29uc29sZS53YXJuKGBUcnlpbmcgdG8gZGVsZXRlIG9iamVjdCAke2lkfSwgd2hpY2ggaXMgbm90IGluIGdsb2JhbCBzZXNzaW9uIGNhY2hlLmApOwogICAgfQogICAgcmV0dXJuOwp9CmxldCBERUxFVEVfT0JTRVJWRVIgPSB1bmRlZmluZWQ7CmZ1bmN0aW9uIHRyYWNrX2RlbGV0ZWRfc2Vzc2lvbnMoKSB7CiAgICBpZiAoIURFTEVURV9PQlNFUlZFUikgewogICAgICAgIGNvbnN0IG9ic2VydmVyID0gbmV3IE11dGF0aW9uT2JzZXJ2ZXIoZnVuY3Rpb24obXV0YXRpb25zKSB7CiAgICAgICAgICAgIGxldCByZW1vdmFsX29jY3VyZWQgPSBmYWxzZTsKICAgICAgICAgICAgY29uc3QgdG9fZGVsZXRlID0gbmV3IFNldCgpOwogICAgICAgICAgICBtdXRhdGlvbnMuZm9yRWFjaCgobXV0YXRpb24pPT57CiAgICAgICAgICAgICAgICBtdXRhdGlvbi5yZW1vdmVkTm9kZXMuZm9yRWFjaCgoeCk9PnsKICAgICAgICAgICAgICAgICAgICBpZiAoeC5pZCBpbiBTRVNTSU9OUykgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzdGF0dXMgPSBTRVNTSU9OU1t4LmlkXVsxXTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXR1cyA9PT0gImRlbGV0ZSIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRvX2RlbGV0ZS5hZGQoeC5pZCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICByZW1vdmFsX29jY3VyZWQgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgaWYgKHJlbW92YWxfb2NjdXJlZCkgewogICAgICAgICAgICAgICAgT2JqZWN0LmtleXMoU0VTU0lPTlMpLmZvckVhY2goKGlkKT0+ewogICAgICAgICAgICAgICAgICAgIGNvbnN0IHN0YXR1cyA9IFNFU1NJT05TW2lkXVsxXTsKICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdHVzID09PSAiZGVsZXRlIikgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmdldEVsZW1lbnRCeUlkKGlkKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5kZWJ1ZyhgYWRkaW5nIHNlc3Npb24gdG8gZGVsZXRlIGNhbmRpZGF0ZXM6ICR7aWR9YCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0b19kZWxldGUuYWRkKGlkKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRvX2RlbGV0ZS5mb3JFYWNoKChpZCk9PnsKICAgICAgICAgICAgICAgIGNsb3NlX3Nlc3Npb24oaWQpOwogICAgICAgICAgICB9KTsKICAgICAgICB9KTsKICAgICAgICBvYnNlcnZlci5vYnNlcnZlKGRvY3VtZW50LCB7CiAgICAgICAgICAgIGF0dHJpYnV0ZXM6IGZhbHNlLAogICAgICAgICAgICBjaGlsZExpc3Q6IHRydWUsCiAgICAgICAgICAgIGNoYXJ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lsYWJsZShub2RlX2lkLCB0aW1lb3V0KSB7CiAgICByZXR1cm4gbmV3IFByb21pc2UoKHJlc29sdmUpPT57CiAgICAgICAgZnVuY3Rpb24gdGVzdF9ub2RlKHRpbWVvdXQpIHsKICAgICAgICAgICAgY29uc3Qgbm9kZSA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoYFtkYXRhLWpzY2FsbC1pZD0nJHtub2RlX2lkfSddYCk7CiAgICAgICAgICAgIGlmIChub2RlKSB7CiAgICAgICAgICAgICAgICByZXNvbHZlKG5vZGUpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgY29uc3QgbmV3X3RpbWVvdXQgPSAyICogdGltZW91dDsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKG5ld190aW1lb3V0KTsKICAgICAgICAgICAgICAgIHNldFRpbWVvdXQodGVzdF9ub2RlLCBuZXdfdGltZW91dCwgbmV3X3RpbWVvdXQpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRlc3Rfbm9kZSh0aW1lb3V0KTsKICAgIH0pOwp9CmZ1bmN0aW9uIHVwZGF0ZV9vcl9yZXBsYWNlKG5vZGUsIG5ld19odG1sLCByZXBsYWNlKSB7CiAgICBpZiAocmVwbGFjZSkgewogICAgICAgIG5vZGUucGFyZW50Tm9kZS5yZXBsYWNlQ2hpbGQobmV3X2h0bWwsIG5vZGUpOwogICAgfSBlbHNlIHsKICAgICAgICB3aGlsZShub2RlLmNoaWxkRWxlbWVudENvdW50ID4gMCl7CiAgICAgICAgICAgIG5vZGUucmVtb3ZlQ2hpbGQobm9kZS5maXJzdENoaWxkKTsKICAgICAgICB9CiAgICAgICAgbm9kZS5hcHBlbmQobmV3X2h0bWwpOwogICAgfQp9CmZ1bmN0aW9uIHVwZGF0ZV9zZXNzaW9uX2RvbShtZXNzYWdlKSB7CiAgICBjb25zdCB7IHNlc3Npb25faWQgLCBtZXNzYWdlcyAsIGh0bWwgLCBkb21fbm9kZV9zZWxlY3RvciAsIHJlcGxhY2UgIH0gPSBtZXNzYWdlOwogICAgb25fbm9kZV9hdmFpbGFibGUoZG9tX25vZGVfc2VsZWN0b3IsIDEpLnRoZW4oKGRvbSk9PnsKICAgICAgICB0cnkgewogICAgICAgICAgICB1cGRhdGVfb3JfcmVwbGFjZShkb20sIGh0bWwsIHJlcGxhY2UpOwogICAgICAgICAgICBwcm9jZXNzX21lc3NhZ2UobWVzc2FnZXMpOwogICAgICAgICAgICBkb25lX2luaXRpYWxpemluZ19zZXNzaW9uKHNlc3Npb25faWQpOwogICAgICAgIH0gY2F0Y2ggKGVycm9yKSB7CiAgICAgICAgICAgIHNlbmRfZG9uZV9sb2FkaW5nKHNlc3Npb25faWQsIGVycm9yKTsKICAgICAgICAgICAgY29uc29sZS5lcnJvcihlcnJvci5zdGFjayk7CiAgICAgICAgICAgIHRocm93IGVycm9yOwogICAgICAgIH0gZmluYWxseXsKICAgICAgICAgICAgT0JKRUNUX0ZSRUVJTkdfTE9DSy50YXNrX3VubG9jayhzZXNzaW9uX2lkKTsKICAgICAgICB9CiAgICB9KTsKICAgIHJldHVybjsKfQpmdW5jdGlvbiB1cGRhdGVfc2Vzc2lvbl9jYWNoZShzZXNzaW9uX2lkLCBuZXdfamxfb2JqZWN0cywgc2Vzc2lvbl9zdGF0dXMpIHsKICAgIGZ1bmN0aW9uIHVwZGF0ZV9jYWNoZSh0cmFja2VkX29iamVjdHMpIHsKICAgICAgICBmb3IoY29uc3Qga2V5IGluIG5ld19qbF9vYmplY3RzKXsKICAgICAgICAgICAgdHJhY2tlZF9vYmplY3RzLmFkZChrZXkpOwogICAgICAgICAgICBjb25zdCBuZXdfb2JqZWN0ID0gbmV3X2psX29iamVjdHNba2V5XTsKICAgICAgICAgICAgaWYgKG5ld19vYmplY3QgPT0gInRyYWNraW5nLW9ubHkiKSB7CiAgICAgICAgICAgICAgICBpZiAoIShrZXkgaW4gR0xPQkFMX09CSkVDVF9DQUNIRSkpIHsKICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYEtleSAke2tleX0gb25seSBzZW5kIGZvciB0cmFja2luZywgYnV0IG5vdCBhbHJlYWR5IHRyYWNrZWQhISFgKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGlmIChrZXkgaW4gR0xPQkFMX09CSkVDVF9DQUNIRSkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybihgJHtrZXl9IGluIHNlc3Npb24gY2FjaGUgYW5kIHNlbmQgYWdhaW4hISAke25ld19vYmplY3R9YCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBHTE9CQUxfT0JKRUNUX0NBQ0hFW2tleV0gPSBuZXdfb2JqZWN0OwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgY29uc3Qgc2Vzc2lvbiA9IFNFU1NJT05TW3Nlc3Npb25faWRdOwogICAgaWYgKHNlc3Npb24pIHsKICAgICAgICB1cGRhdGVfY2FjaGUoc2Vzc2lvblswXSk7CiAgICB9IGVsc2UgewogICAgICAgIE9CSkVDVF9GUkVFSU5HX0xPQ0sudGFza19sb2NrKHNlc3Npb25faWQpOwogICAgICAgIGNvbnN0IHRyYWNrZWRfaXRlbXMgPSBuZXcgU2V0KCk7CiAgICAgICAgU0VTU0lPTlNbc2Vzc2lvbl9pZF0gPSBbCiAgICAgICAgICAgIHRyYWNrZWRfaXRlbXMsCiAgICAgICAgICAgIHNlc3Npb25fc3RhdHVzCiAgICAgICAgXTsKICAgICAgICB1cGRhdGVfY2FjaGUodHJhY2tlZF9pdGVtcyk7CiAgICB9Cn0KY29uc3QgbW9kMSA9IHsKICAgIFNFU1NJT05TOiBTRVNTSU9OUywKICAgIEdMT0JBTF9PQkpFQ1RfQ0FDSEU6IEdMT0JBTF9PQkpFQ1RfQ0FDSEUsCiAgICBPQkpFQ1RfRlJFRUlOR19MT0NLOiBPQkpFQ1RfRlJFRUlOR19M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24oJzM4ZGRmZjZjLTU1NDgtNGIwYS05ZTNhLTRlNGVjM2QzYzI3YicsIG51bGwsICdyb290Jykp" type="module"></script>
</span>
</div>
<div id="ec4d85cd-0789-4142-a728-1429d7887bd2" data-jscall-id="subsession-application-dom">
<div>
<div></div>
</div>
<input step="1" max="3" min="1" data-jscall-id="1" value="1" oninput="" type="range"