Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 海阔视界规则分享,当前分享的是:网页插件¥js_url¥global@base64://Ly89PT09PT09PT09dmlhLXBsdWdpbjoyNT09PT09PT09PT0KLy89PT09PT09PT09Ti1saWI9PT09PT09PT09CmAKQG5hbWUgTi1saWIKQHZlcnNpb24gMC4wLjMKYAoucmVwbGFjZSgiIiwgKF8sIF9fLCBjb25maWdfdGV4dCkgPT4gewogICAgY29uc3QgcGFyc2UgPSBjb25maWdfdGV4dCA9PiB7CiAgICAgICAgY29uc3QgY29uZmlnX2l0ZW1fcmVnZXggPSBuZXcgUmVnRXhwKGBAKFxcUyspXFxiXFxzKyhbXkBcXHNdKyhbXlxcclxcblxcU10rW15AXFxzXSspKilgLCAnZ20nKTsKICAgICAgICByZXR1cm4gT2JqZWN0LmFzc2lnbih7IGluY2x1ZGU6IFsnLionXSwgZXhjbHVkZTogW10sIG1hdGNoOiBbXSB9LAogICAgICAgICAgICAoY29uZmlnX3RleHQubWF0Y2goY29uZmlnX2l0ZW1fcmVnZXgpIHx8IFtdKQogICAgICAgICAgICAubWFwKGNvbmZpZ19pdGVtID0+IGNvbmZpZ19pdGVtLnJlcGxhY2UoL15ccypALywgJycpLnNwbGl0KC9ccysvKSkKICAgICAgICAgICAgLnJlZHVjZSgoY29uZmlnLCBpdGVtKSA9PiB7CiAgICAgICAgICAgICAgICAoY29uZmlnW2l0ZW1bMF1dID0gY29uZmlnW2l0ZW1bMF1dIHx8IFtdKS5wdXNoKGl0ZW1bMV0pOwogICAgICAgICAgICAgICAgcmV0dXJuIGNvbmZpZzsKICAgICAgICAgICAgfSwge30pKTsKICAgIH07CgogICAgY29uc3Qgb25jZSA9IChjb25maWcgPSBwYXJzZShgYCkpID0+IGZuID0+IHsKICAgICAgICBjb25zdCBpbmNsdWRlX3B0biA9IG5ldyBSZWdFeHAoJ14oJyArIGNvbmZpZy5pbmNsdWRlLmNvbmNhdChjb25maWcubWF0Y2gpLmpvaW4oJ3wnKSArICcpJCcpOwogICAgICAgIGNvbnN0IGV4Y2x1ZGVfcHRuID0gbmV3IFJlZ0V4cCgnXignICsgY29uZmlnLmV4Y2x1ZGUuam9pbignfCcpICsgJykkJyk7CiAgICAgICAgaWYgKCF3aW5kb3cubG9jYXRpb24uaHJlZi5tYXRjaChpbmNsdWRlX3B0bikgfHwKICAgICAgICAgICAgd2luZG93LmxvY2F0aW9uLmhyZWYubWF0Y2goZXhjbHVkZV9wdG4pKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CgogICAgICAgIGNvbnN0IGhhc2hfY29kZSA9IHN0ciA9PiBBcnJheS5mcm9tKHN0cikKICAgICAgICAgICAgLnJlZHVjZSgoaGFzaCwgY2gpID0+IChoYXNoIDw8IDUpIC0gaGFzaCArIGNoLmNoYXJDb2RlQXQoKSwgMCk7CiAgICAgICAgd2luZG93Ll9fbG9hZGVkX3NjcmlwdHNfXyA9IHdpbmRvdy5fX2xvYWRlZF9zY3JpcHRzX18gfHwge307CiAgICAgICAgY29uc3Qga2V5ID0gY29uZmlnLm5hbWUgfHwgaGFzaF9jb2RlKGZuLnRvU3RyaW5nKCkpOwogICAgICAgIGlmICghKGtleSBpbiB3aW5kb3cuX19sb2FkZWRfc2NyaXB0c19fKSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgZm4uY2FsbChjb25maWcpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICB3aW5kb3cuX19sb2FkZWRfc2NyaXB0c19fW2tleV0gPSBlOwogICAgICAgICAgICAgICAgY29uc29sZS5sb2coYHNjcmlwdCAiJHtrZXl9IiBsb2FkIGZhaWxlZCFgKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB3aW5kb3cuX19sb2FkZWRfc2NyaXB0c19fW2tleV0gPSBjb25maWc7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKGBzY3JpcHQgIiR7a2V5fSIgbG9hZCBzdWNjZXNzZnVsIWApOwogICAgICA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mN0aW9uIHRocm90dGxlKGZuLCB3YWl0KSB7CiAgICBsZXQgaW5UaHJvdHRsZSwgbGFzdEZuLCBsYXN0VGltZTsKICAgIHJldHVybiBmdW5jdGlvbiguLi5hcmdzKSB7CiAgICAgICAgaWYgKCFpblRocm90dGxlKSB7CiAgICAgICAgICAgIGZuLmFwcGx5KHRoaXMsIGFyZ3MpOwogICAgICAgICAgICBsYXN0VGltZSA9IERhdGUubm93KCk7CiAgICAgICAgICAgIGluVGhyb3R0bGUgPSB0cnVlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNsZWFyVGltZW91dChsYXN0Rm4pOwogICAgICAgICAgICBsYXN0Rm4gPSBzZXRUaW1lb3V0KGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgaWYgKERhdGUubm93KCkgLSBsYXN0VGltZSA+PSB3YWl0KSB7CiAgICAgICAgICAgICAgICAgICAgZm4uYXBwbHkodGhpcywgYXJncyk7CiAgICAgICAgICAgICAgICAgICAgbGFzdFRpbWUgPSBEYXRlLm5vdygpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9LCBNYXRoLm1heCh3YWl0IC0gKERhdGUubm93KCkgLSBsYXN0VGltZSksIDApKTsKICAgICAgICB9CiAgICB9Owp9OwoKZnVuY3Rpb24gaXNfc2FtZV9zaXplX3Bvc2l0aW9uKGVsZTEsIGVsZTIpIHsKICAgIHRyeSB7CiAgICAgICAgcmV0dXJuIGVsZTEuY2xpZW50V2lkdGggPT0gZWxlMi5jbGllbnRXaWR0aCAmJgogICAgICAgICAgICBlbGUxLmNsaWVudEhlaWdodCA9PSBlbGUyLmNsaWVudEhlaWdodCAmJgogICAgICAgICAgICBlbGUxLnNjcm9sbEhlaWdodCA9PSBlbGUyLnNjcm9sbEhlaWdodDsKICAgIH0gY2F0Y2ggewogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KfQoKZnVuY3Rpb24gZmluZF90b3Bfd3JhcF9lbGUoZWxlKSB7CiAgICBs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c3QgcGl4ZWwgPSBkaXYuY2xpZW50V2lkdGg7CiAgICBkaXYucmVtb3ZlKCk7CiAgICBnZXRfMWNtX3BpeGVsX251bSA9ICgpID0+IHBpeGVsOwogICAgcmV0dXJuIHBpeGVsOwp9CgpmdW5jdGlvbiBweDJjbShweCkgewogICAgcmV0dXJuIHB4IC8gZ2V0XzFjbV9waXhlbF9udW0oKTsKfQoKLyogbGliIGVuZCAqLwoKLyogYWRkIGN1c3RvbSBldmVudCBiZWdpbiAqLwoKZnVuY3Rpb24gY29weShvYmopIHsKICAgIGNvbnN0IG5ld19vYmogPSB7fTsKICAgIGZvciAobGV0IGkgaW4gb2JqKSB7CiAgICAgICAgbmV3X29ialtpXSA9IG9ialtpXTsKICAgIH0KICAgIHJldHVybiBuZXdfb2JqOwp9CgpmdW5jdGlvbiBUYXBFdmVudCh0b3VjaF9ldmVudCkgewogICAgcmV0dXJuIG5ldyBUb3VjaEV2ZW50KCd0YXAnLAogICAgICAgICAgICAgICAgICAgICAgICAgIE9iamVjdC5hc3NpZ24oY29weSh0b3VjaF9ldmVudCksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7IGJ1YmJsZXM6IHRydWUsIGNhbmNlbGFibGU6IHRydWUsIGNvbXBvc2VkOiB0cnVlIH0pKTsKfQoKZnVuY3Rpb24gRG91YmxlVGFwRXZlbnQodG91Y2hfZXZlbnQpIHsKICAgIHJldHVybiBuZXcgVG91Y2hFdmVudCgnZG91YmxldGFwJywKICAgICAgICAgICAgICAgICAgICAgICAgICBPYmplY3QuYXNzaWduKGNvcHkodG91Y2hfZXZlbnQpLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgeyBidWJibGVzOiB0cnVlLCBjYW5jZWxhYmxlOiB0cnVlLCBjb21wb3NlZDogdHJ1ZSB9KSk7Cn0KCmZ1bmN0aW9uIFRvdWNoRXZlbnQyTW91c2VFdmVudChldmVudF90eXBlLCBldmVudCkgewogICAgY29uc3QgdG91Y2ggPSBldmVudC50YXJnZXRUb3VjaGVzICYmIGV2ZW50LnRhcmdldFRvdWNoZXNbMF0gfHwge307CiAgICByZXR1cm4gbmV3IE1vdXNlRXZlbnQoZXZlbnRfdHlwZSwKICAgICAgICAgICAgICAgICAgICAgICAgICBPYmplY3QuYXNzaWduKHt9LCBjb3B5KGV2ZW50KSwgY29weSh0b3VjaCksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7IGJ1YmJsZXM6IHRydWUsIGNhbmNlbGFibGU6IHRydWUsIGNvbXBvc2VkOiB0cnVlIH0pKTsKfQoKZnVuY3Rpb24gYWRkX3RhcF9ldmVudF9ob29rKGVsZW1lbnQpIHsKICAgIGxldCBzdGFydF90b3VjaCwgZW5kX3RvdWNoLCBlbmRfZXZlbnQgPSB7fTsKICAgIGNvbnN0IHN0YXJ0ID0gZSA9PiB7CiAgICAgICAgc3RhcnRfdG91Y2ggPSBlbmRfdG91Y2ggPSBjb3B5KGUudG91Y2hlc1swXSk7CiAgICAgICAgZW5kX2V2ZW50ID0gY29weShlKTsKICAgIH07CiAgICBjb25zdCBtb3ZlID0gZSA9PiB7CiAgICAgICAgZW5kX3RvdWNoID0gY29weShlLnRvdWNoZXNbMF0pOwogICAgICAgIGVuZF9ldmVudCA9IGNvcHkoZSk7CiAgICB9OwogICAgY29uc3QgZW5kID0gZSA9PiB7CiAgICAgICAgaWYgKE1hdGguYWJzKHN0YXJ0X3RvdWNoLmNsaWVudFggLSBlbmRfdG91Y2guY2xpZW50WCkgPD0gMTAgJiYKICAgICAgICAgICAgTWF0aC5hYnMoc3RhcnRfdG91Y2guY2xpZW50WSAtIGVuZF90b3VjaC5jbGllbnRZKSA8PSAxMCkgewogICAgICAgICAgICBlLnRhcmdldC5kaXNwYXRjaEV2ZW50KG5ldyBUYXBFdmVudChlbmRfZXZlbnQpKTsKICAgICAgICAgICAgZS5wcmV2ZW50RGVmYXVsdCgpOwogICAgICAgICAgICBlLnRhcmdld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ICAgIGNvbG9yOiB3aGl0ZTsKICAgIGJveC1zaXppbmc6IGJvcmRlci1ib3g7CiAgICBkaXNwbGF5OiBub25lOwogICAganVzdGlmeS1jb250ZW50OiBjZW50ZXI7CiAgICBhbGlnbi1pdGVtczogY2VudGVyOwogICAgZm9udC1zaXplOiAxY207CiAgICBwb2ludGVyLWV2ZW50czogYXV0bzsKICAgIGA7CgogICAgcmV0dXJuIHsKICAgICAgICBkaXNwbGF5KCkgewogICAgICAgICAgICBkaXYuc3R5bGUuZGlzcGxheSA9ICdmbGV4JzsKICAgICAgICB9LAogICAgICAgIGhpZGRlbigpIHsKICAgICAgICAgICAgZGl2LnN0eWxlLmRpc3BsYXkgPSAnbm9uZSc7CiAgICAgICAgfSwKICAgICAgICB0b2dnbGUoKSB7CiAgICAgICAgICAgIGlmIChkaXYuc3R5bGUuZGlzcGxheSA9PT0gJ2ZsZXgnKSB7CiAgICAgICAgICAgICAgICB0aGlzLmhpZGRlbigpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdGhpcy5kaXNwbGF5KCk7CiAgICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGRpdiwKICAgICAgICBjb250ZW50X2RpdnMsCiAgICB9Owp9Cgpjb25zdCBnZXRfdmlkZW9fdG91Y2hfaG9vayA9ICh2aWRlbywgZSkgPT4gewogICAgbGV0IHRvcF93cmFwID0gZmluZF90b3Bfd3JhcF9lbGUodmlkZW8pOwogICAgaWYgKHRvcF93cmFwID09PSB2aWRlbykgewogICAgICAgIHRvcF93cmFwID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgnZGl2Jyk7CiAgICAgICAgdmlkZW8ucGFyZW50RWxlbWVudC5pbnNlcnRCZWZvcmUodG9wX3dyYXAsIHZpZGVvKTsKICAgICAgICB0b3Bfd3JhcC5hcHBlbmQodmlkZW8pOwogICAgfQoKICAgIGNvbnN0IGV2ZW50X2NsZWFyZXIgPSBbYWRkX3RhcF9ldmVudF9ob29rLC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ocGxheWluZykgewogICAgICAgICAgICB2aWRlby5wbGF5KCk7CiAgICAgICAgICAgIHBsYXlpbmcgPSBmYWxzZTsKICAgICAgICB9CiAgICB9LCAxMDApOwoKICAgIGhvb2tfZm4ubW92ZS5wdXNoKChlLCBzdGFydF90aW1lLCB4X2Rpc3RhbmNlX3B4LCB0aW1lX2xlbmd0aCkgPT4gewogICAgICAgIHBhdXNlKCk7CiAgICAgICAgdmlkZW8uY3VycmVudFRpbWUgPSBNYXRoLm1heChNYXRoLm1pbihzdGFydF90aW1lICsgdGltZV9sZW5ndGgsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2aWRlby5kdXJhdGlvbiksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAwKTsKICAgICAgICBwbGF5KCk7CiAgICB9KTsKfTsKCmNvbnN0IGhvb2tfdmlkZW9fdGltZV9jaGFuZ2UgPSBob29rID0+IHsKICAgIGNvbnN0IHt2aWRlbywgaG9va19mbiwgZXZlbnRfY2xlYXJlcn0gPSBob29rOwogICAgY29uc3QgdG9wX3dyYXAgPSBmaW5kX3RvcF93cmFwX2VsZSh2aWRlbyk7CiAgICBjb25zdCB2aWRlb19wcm9tcHQgPSBjcmVhdGVfcHJvbXB0X3BhbmVsKCk7CiAgICB0b3Bfd3JhcC5hcHBlbmQodmlkZW9fcHJvbXB0LmRpdik7CgogICAgZXZlbnRfY2xlYXJlci5wdXNoKCgpID0+IHZpZGVvX3Byb21wdC5kaXYucmVtb3ZlKCkpOwoKICAgIGhvb2tfZm4uc3RhcnQucHVzaCgoKSA9PiB7CiAgICAgICAgdmlkZW9fcHJvbXB0LnJpZ2h0X3RpbWUuaW5uZXJUZXh0ID0gc2VjMkhITU1TUyh2aWRlby5kdXJhdGlvbik7CiAgICB9KTsKCiAgICBob29rX2ZuLm1vdmUucHVzaCgoZSwgc3RhcnRfdGltZSwgeF9kaXN0YW5jZV9weCwgdGltZV9sZW5ndGgpID0+IH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SBbXTsKICAgICAgICByZXR1cm4gZm4gPT4gewogICAgICAgICAgICBiaW5kX2ZuLmZvckVhY2goKFtkaXYsIGZuXSkgPT4gZGl2LnJlbW92ZUV2ZW50TGlzdGVuZXIoJ3RhcCcsIGZuKSk7CiAgICAgICAgICAgIGJpbmRfZm4gPSBbXTsKICAgICAgICAgICAgY29udHJvbC5jb250ZW50X2RpdnMuZm9yRWFjaChkaXYgPT4gewogICAgICAgICAgICAgICAgYmluZF9mbi5wdXNoKFtkaXYsIGZuXSk7CiAgICAgICAgICAgICAgICBkaXYuYWRkRXZlbnRMaXN0ZW5lcigndGFwJywgZm4pOwogICAgICAgICAgICB9KTsKICAgICAgICB9OwogICAgfSkoKTsKCiAgICBsZXQgc3RhdGUgPSBbXTsKICAgIGZ1bmN0aW9uIHNldF9zdGF0ZSgpIHsKICAgICAgICBjb250cm9sLmNvbnRlbnRfZGl2cy5mb3JFYWNoKChkaXYsIGkpID0+IHN0YXRlW2ldID0gZGl2LmlubmVyVGV4dCk7CiAgICB9CgogICAgbGV0IHN0YXJ0X3ksIG1vZGlmaWVyOwogICAgY29uc3Qgc3RhcnQgPSBlID0+IHsKICAgICAgICBzdGFydF95ID0gZS50b3VjaGVzWzBdLnNjcmVlblk7CiAgICAgICAgc2V0X3N0YXRlKCk7CiAgICB9OwogICAgY29uc3QgbW92ZSA9IGUgPT4gewogICAgICAgIGNvbnN0IGVuZF95ID0gZS50b3VjaGVzWzBdLnNjcmVlblk7CiAgICAgICAgY29uc3QgeV9kaXN0YW5jZV9weCA9IHN0YXJ0X3kgLSBlbmRfeTsKICAgICAgICBjb25zdCBpbmNyZWFzZSA9IE1hdGguZmxvb3IocHgyY20oeV9kaXN0YW5jZV9weCkgKiAodGhpcy5pbmNyZWFzZV8xY20gfHwgMSkpOwogICAgICAgIGNvbnN0IGlkeCA9IEFycmF5LmZyb20oZS50YXJnZXQucGFyZW50RWxlbWVudC5jaGlsZHJlbikuaW5kZXhPZihlLnRhcmdldCk7CiAgICAgICAgaWYgKG1vZGlmaWVyW2lkeF0pIHsKICAgICAgICAgICAgbW9kaWZpZXJbaWR4XShpbmNyZWFzZSk7CiAgICAgICAgfQogICAgfTsKCiAgICBjb25zdCBpbmNyZWFzZV9oZWxwZXIgPSAoc3RhdGVfaWR4LCBpbmNyZWFzZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsaW1pdCwgcHJlX2VsZV9tb2RpZmllciwgd3JhcCA9IHggPT4geCkgPT4gewogICAgICAgICBjb25zdCB2ID0gcGFyc2VGbG9hdChzdGF0ZVtzdGF0ZV9pZHhdKSArIGluY3JlYXNlOwogICAgICAgICBpZiAobGltaXQgIT09IHVuZGVmaW5lZCkgewogICAgICAgICAgICAgaWYgKHByZV9lbGVfbW9kaWZpZXIpIHsKICAgICAgICAgICAgICAgICBpZiAodiA+PSBsaW1pdCkgewogICAgICAgICAgICAgICAgICAgICBwcmVfZWxlX21vZGlmaWVyKE1hdGguZmxvb3IodiAvIGxpbWl0KSk7CiAgICAgICAgICAgICAgICAgICAgIGNvbnRyb2wuY29udGVudF9kaXZzW3N0YXRlX2lkeF0uaW5uZXJUZXh0ID0gd3JhcCh2ICUgbGltaXQpOwogICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodiA8IDApIHsKICAgICAgICAgICAgICAgICAgICAgcHJlX2VsZV9tb2RpZmllcigtMSk7CiAgICAgICAgICAgICAgICAgICAgIGNvbnRyb2wuY29udGVudF9kaXZzW3N0YXRlX2lkeF0uaW5uZXJUZXh0ID0gd3JhcChsaW1pdCArIHYpOwogICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgIGNvbnRyb2wuY29udGVudF9kaXZzW3N0YXRlX2lkeF0uaW5uZXJUZXh0ID0gd3JhcCh2KTsKICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgIGNvbnRyb2wuY29udGVudF9kaXZzW3N0YXRlX2lkeF0uaW5u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2hvb2tfdmlkZW9fXy5maW5kKHYgPT4gdi52aWRlbyA9PT0gdmlkZW8pOwogICAgcmV0dXJuIGV4aXN0X3ZpZGVvOwp9CgpmdW5jdGlvbiByZWdpc3Rlcl9ob29rKGhvb2spIHsKICAgIGlmICghZmluZF9ob29rKGhvb2sudmlkZW8pKSB7CiAgICAgICAgd2luZG93Ll9faG9va192aWRlb19fLnB1c2goaG9vayk7CiAgICAgICAgcmV0dXJuIGhvb2s7CiAgICB9Cn0KCmNvbnN0IGhvb2tfdmlkZW8gPSAodmlkZW8pID0+IHsKICAgIGNvbnN0IGV4aXN0X3ZpZGVvID0gZmluZF9ob29rKHZpZGVvKTsKICAgIGlmICh2aWRlby5jbGllbnRXaWR0aCAmJiB2aWRlby5jbGllbnRIZWlnaHQgJiYKICAgICAgICAoIWV4aXN0X3ZpZGVvIHx8IGlzX3BhcmVudChleGlzdF92aWRlby53cmFwLCBmaW5kX3RvcF93cmFwX2VsZSh2aWRlbykpKSkgewogICAgICAgIGNvbnN0IGhvb2sgPSBnZXRfdmlkZW9fdG91Y2hfaG9vayh2aWRlbyk7CiAgICAgICAgaG9va192aWRlb19tb3ZlKGhvb2spOwogICAgICAgIGhvb2tfdmlkZW9fdGltZV9jaGFuZ2UoaG9vayk7CiAgICAgICAgaG9va192aWRlb19jb250cm9sKGhvb2spOwoKICAgICAgICBpZiAoZXhpc3RfdmlkZW8pIHsKICAgICAgICAgICAgZXhpc3RfdmlkZW8uZXZlbnRfY2xlYXJlci5mb3JFYWNoKHggPT4geCgpKTsKICAgICAgICAgICAgT2JqZWN0LmFzc2lnbihleGlzdF92aWRlbywgaG9vayk7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCd2aWRlby1pbXByb3ZlOiByZWxvYWRlZCBmb3IgJywgdmlkZW8sICcsIHdyYXBwZWQgYnkgJywgZmluZF90b3Bfd3JhcF9lbGUodmlkZW8pKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZWdpc3Rlcl9ob29rK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FbaHJlZl06bm90KFtocmVmXj0iamF2YSJdKSwgW29uY2xpY2tdLCBbZGF0YS1ocmVmXScpKSk7Cn0KCmZ1bmN0aW9uIGxpbmtfdG9fZXh0ZXJuYWwoZWwpIHsKICAgIGNvbnN0IGxpbmtfZWxzID0gY2xpY2thYmxlcyhlbCk7CiAgICByZXR1cm4gbGlua19lbHMuc29tZShsaW5rX2VsID0+IHsKICAgICAgICBjb25zdCBsaW5rID0gbGlua19lbC5ocmVmIHx8IGxpbmtfZWwuZGF0YXNldC5ocmVmOwogICAgICAgIHJldHVybiBsaW5rICYmICFpc19zYW1lX3NlY29uZGVfbGV2ZWxfZG9tYWluKGxpbmssIHRvcC5sb2NhdGlvbi5ocmVmKSB8fAogICAgICAgICAgICBsaW5rX2VsLm9uY2xpY2sgJiYgbGlua19lbC5vbmNsaWNrLnRvU3RyaW5nKCkubWF0Y2goL3tccyouK1xzKn0vKSAmJgogICAgICAgICAgICAhaXNfc2FtZV9zZWNvbmRlX2xldmVsX2RvbWFpbihnZXRfdXJsKGxpbmtfZWwub25jbGljay50b1N0cmluZygpKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdG9wLmxvY2F0aW9uLmhyZWYpICYmCiAgICAgICAgICAgICFsaW5rX2VsLm9uY2xpY2sudG9TdHJpbmcoKS5pbmNsdWRlcygncGFyZW50JykgJiYKICAgICAgICAgICAgIWxpbmtfZWwub25jbGljay50b1N0cmluZygpLmluY2x1ZGVzKCduZXh0Jyk7CiAgICB9KTsKfQoKZnVuY3Rpb24gaW1hZ2VfbGlua190b19leHRlcm5hbChlbCkgewogICAgY29uc3QgbGlua19lbHMgPSBjbGlja2FibGVzKGVsKTsKICAgIHJldHVybiBsaW5rX2Vscy5zb21lKGxpbmtfZWwgPT4gewogICAgICAgIHJldHVybiBleGlzdF9pbWFnZShsaW5rX2VsKSAmJiBsaW5rX3RvX2V4dGVybmFsKGxpbmtfZWwpOwogICAgfSk7Cn0KCmZ1bmN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kKCk7Cgp9XSk7cmV0dXJuIF87fSksMDsKCi8vPT09PT09PT09PXZpYS1wbHVnaW46MzM9PT09PT09PT09Ci8vPT09PT09PT09PXZpYS1wbHVnaW46NjI9PT09PT09PT09Ci8vPT09PT09PT09PUg16KeG6aKR6LCD6YCf5ZmoPT09PT09PT09PQovLyA9PVVzZXJTY3JpcHQ9PQovLyBAbmFtZSAgICAgICAgIFtWaWFdSDXop4bpopHosIPpgJ/lmagKLy8gQG5hbWVzcGFjZSAgICBodHRwOi8vdGFtcGVybW9ua2V5Lm5ldC8KLy8gQHZlcnNpb24gICAgICAwLjEuNAovLyBAZGVzY3JpcHRpb24gIOS4gOS4qumSiOWvueaJi+acuua1j+iniOWZqOeahEg16KeG6aKR6LCD6YCf5ZmoCi8vIEBhdXRob3IgICAgICAgTXIuTnVsbE51bGwKLy8gQG1hdGNoICAgICAgICAqOi8vKi8qCi8vIEBncmFudCAgICAgICAgbm9uZQovLyA9PS9Vc2VyU2NyaXB0PT0KIAovKkg16KeG6aKR6LCD6YCf5Zmo77yM5L2c6ICF77yaTXIuTnVsbE51bGwqLwooZnVuY3Rpb24gKCkgewogICAgJ3VzZSBzdHJpY3QnOwogCiAgICB2YXIgSW50UGJyID0gMTsKIAogICAgY29uc3QgSW50UGJyTWF4ID0gMTY7CiAgICBjb25zdCBJbnRQYnJNaW4gPSAwLjE7CiAgICBjb25zdCBJbnRQYnJTdGVwID0gMC4yNTsKIAogICAgZnVuY3Rpb24gTWFpbigpIHsKICAgICAgICBpZiAoZG9jdW1lbnQucXVlcnlTZWxlY3RvcigibXlQYnJNYWluIikpIHJldHVybjsKIAogICAgICAgIHZhciBteUNzcyA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInN0eWxlIik7CiAgICAgICAgbXlDc3MuaW5uZXJIVE1MID0gYAogICAgICAgICAgICBkaXYjbXlQYnJNYWluIHsKICAgICAgICAgICAgICAgIHBhZGRpbmc6IDA7CiAgICAgICAgICAgICAgICBtYXJnaW46IDA7CiAgICAgICAgICAgICAgICB3aWR0aDogMXB4OwogICAgICAgICAgICAgICAgcG9zaXRpb246IGZpeGVkOwogICAgICAgICAgICAgICAgYm90dG9tOiAyOHZ3OwogICAgICAgICAgICAgICAgcmlnaHQ6IDV2dzsKICAgICAgICAgICAgICAgIHotaW5kZXg6IDIxNDc0ODM2NDc7CiAgICAgICAgICAgIH0KIAogICAgICAgICAgICBkaXYjbXlQYnJNYWluPiogewogICAgICAgICAgICAgICAgZmxvYXQ6IHJpZ2h0OwogICAgICAgICAgICB9CiAKICAgICAgICAgICAgZGl2I215UGJyTWFpbj5kaXYubXlQYnJCdG5zIHsKICAgICAgICAgICAgICAgIHdpZHRoOiAxcHg7CiAgICAgICAgICAgICAgICBtYXJnaW4tYm90dG9tOiAyLjJ2dzsKICAgICAgICAgICAgfQogCiAgICAgICAgICAgIGRpdi5teVBickJ0bnMgewogICAgICAgICAgICAgICAgb3BhY2l0eTogMDsKICAgICAgICAgICAgfQogCiAgICAgICAgICAgIGRpdi5teVBickJ0biB7CiAgICAgICAgICAgICAgICBmb250OiA0dncvMSAn5b6u6L2v6ZuF6buRJzsKICAgICAgICAgICAgICAgIGZsb2F0OiByaWdodDsKICAgICAgICAgICAgICAgIGhlaWdodDogNHZ3OwogICAgICAgICAgICAgICAgcGFkZGluZzogMnZ3OwogICAgICAgICAgICAgICAgbWFyZ2luLWJvdHRvbTogMC44dnc7CiAgICAgICAgICAgICAgICBib3JkZXItcmFkaXVzOiAyMHZ3OwogICAgICAgICAgICAgICAgY29sb3I6ICNlZWU7CiAgICAgICAgICAgICAgICBiYWNrZ3JvdW5kLWNvbG9yOiByZ2JhKDAsIDAsIDAsIDAuNjUpOwogICAgICAgICAgICB9CiAKICAgICAgICAgICAgZGl2I215UGJyTWFpbj5kaXYubXlQYnJCdG4gewogICAgICAgICAgICAgICAgd2lkdGg6IGF1dG87CiAgICAgICAgICAgIH0KIAogICAgICAgICAgICBkaXYjbXlQYnJNYWluICogewogICAgICAgICAgICAgICAgYm94LXNpemluZzogY29udGVudC1ib3g7CiAgICAgICAgICAgICAgICB3b3JkLWJyZWFrOiBub3JtYWw7CiAgICAgICAgICAgIH0KIAogICAgICAgICAgICBkaXYuc2hvdyB7CiAgICAgICAgICAgICAgICBhbmltYXRpb246IHNob3dlciAwLjNzOwogICAgICAgICAgICAgICAgb3BhY2l0eTogMTsKICAgICAgICAgICAgICAgIGRpc3BsYXk6IGJsb2NrOwogICAgICAgICAgICB9CiAKICAgICAgICAgICAgZGl2LmhpZGRlbiB7CiAgICAgICAgICAgICAgICBhbmltYXRpb246IGhpZGRlbmVyIDAuM3M7CiAgICAgICAgICAgICAgICBvcGFjaXR5OiAwOwogICAgICAgICAgICAgICAgZGlzcGxheTogbm9uZTsKICAgICAgICAgICAgfQoKCiAgICAgICAgICAgIEBrZXlmcmFtZXMgc2hvd2VyIHsKICAgICAgICAgICAgICAgIGZyb20gewogICAgICAgICAgICAgICAgICAgIG9wYWNpdHk6IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0byB7CiAgICAgICAgICAgICAgICAgICAgb3BhY2l0eTogMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogCiAgICAgICAgICAgIEBrZXlmcmFtZXMgaGlkZGVuZXIgewogICAgICAgICAgICAgICAgZnJvbSB7CiAgICAgICAgICAgICAgICAgICAgb3BhY2l0eTogMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRvIHsKICAgICAgICAgICAgICAgICAgICBvcGFjaXR5OiAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgYDsKICAgICAgICBkb2N1bWVudC5oZWFkLmFwcGVuZENoaWxkKG15Q3NzKTsKIAogICAgICAgIHZhciBtYWluRGl2VG9wID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiZGl2Iik7CiAgICAgICAgbWFpbkRpdlRvcC5pZCA9ICJteVBick1haW4iOwogICAgICAgIG1haW5EaXZ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iAgICAgICAgZG9jdW1lbnQuYm9keS5hcHBlbmRDaGlsZChtYWluRGl2VG9wKTsKIAogICAgICAgIHZhciBtYWluQnRuID0gbWFpbkRpdlRvcC5xdWVyeVNlbGVjdG9yKCIjbXlQYnJCdG5fTWFpbiIpOwogICAgICAgIHZhciBtYWluRGl2ID0gbWFpbkRpdlRvcC5xdWVyeVNlbGVjdG9yKCIubXlQYnJCdG5zIik7CiAKIAogICAgICAgIHNldE1haW5CdG5UeHQoKTsKIAogCiAgICAgICAgbWFpbkJ0bi5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBpZiAobWFpbkRpdi5jbGFzc05hbWUgPT0gIm15UGJyQnRucyBoaWRkZW4iKSB7CiAgICAgICAgICAgICAgICBzZXRNYWluRGl2U2hvdygpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgc2V0TWFpbkRpdk5vbmUoKTsKICAgICAgICAgICAgfQogICAgICAgIH07CiAKICAgICAgICBtYWluRGl2LnF1ZXJ5U2VsZWN0b3IoIiNteVBickJ0bl84MDAiKS5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBJbnRQYnIgPSA4OwogICAgICAgICAgICBzZXRWaWRlb1BCUigpOwogICAgICAgICAgICBzZXRNYWluQnRuVHh0KCk7CiAgICAgICAgICAgIHNldE1haW5EaXZOb25lKCk7CiAgICAgICAgfTsKICAgICAgICBtYWluRGl2LnF1ZXJ5U2VsZWN0b3IoIiNteVBickJ0bl8zMDAiKS5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBJbnRQYnIgPSAzOwogICAgICAgICAgICBzZXRWaWRlb1BCUigpOwogICAgICAgICAgICBzZXRNYWluQnRuVHh0KCk7CiAgICAgICAgICAgIHNldE1haW5EaXZOb25lKCk7CiAgICAgICAgfTsKICAgICAgICBtYWluRGl2LnF1ZXJ5U2VsZWN0b3IoIiNteVBickJ0bl8yMDAiKS5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBJbnRQYnIgPSAyLjAwOwogICAgICAgICAgICBzZXRWaWRlb1BCUigpOwogICAgICAgICAgICBzZXRNYWluQnRuVHh0KCk7CiAgICAgICAgICAgIHNldE1haW5EaXZOb25lKCk7CiAgICAgICAgfTsKICAgICAgICBtYWluRGl2LnF1ZXJ5U2VsZWN0b3IoIiNteVBickJ0bl8xNTAiKS5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBJbnRQYnIgPSAxLjUwOwogICAgICAgICAgICBzZXRWaWRlb1BCUigpOwogICAgICAgICAgICBzZXRNYWluQnRuVHh0KCk7CiAgICAgICAgICAgIHNldE1haW5EaXZOb25lKCk7CiAgICAgICAgfTsKICAgICAgICBtYWluRGl2LnF1ZXJ5U2VsZWN0b3IoIiNteVBickJ0bl8xMjUiKS5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBJbnRQYnIgPSAxLjI1OwogICAgICAgICAgICBzZXRWaWRlb1BCUigpOwogICAgICAgICAgICBzZXRNYWluQnRuVHh0KCk7CiAgICAgICAgICAgIHNldE1haW5EaXZOb25lKCk7CiAgICAgICAgfTsKICAgICAgICBtYWluRGl2LnF1ZXJ5U2VsZWN0b3IoIiNteVBickJ0bl8xMDAiKS5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBJbnRQYnIgPSAxLjAwOwogICAgICAgICAgICBzZXRWaWRlb1BCUigpOwogICAgICAgICAgICBzZXRNYWluQnRuVHh0KCk7CiAgICAgICAgICAgIHNldE1haW5EaXZOb25lKCk7CiAgICAgICAgfTsKICAgICAgICBtYWluRGl2LnF1ZXJ5U2VsZWN0b3IoIiNteVBickJ0bl8wNzUiKS5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBJbnRQYnIgPSAwLjc1OwogICAgICAgICAgICBzZXRWaWRlb1BCUigpOwogICAgICAgICAgICBzZXRNYWluQnRuVHh0KCk7CiAgICAgICAgICAgIHNldE1haW5EaXZOb25lKCk7CiAgICAgICAgfTsKICAgICAgICBtYWluRGl2LnF1ZXJ5U2VsZWN0b3IoIiNteVBickJ0bl8wNTAiKS5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBJbnRQYnIgPSAwLjUwOwogICAgICAgICAgICBzZXRWaWRlb1BCUigpOwogICAgICAgICAgICBzZXRNYWluQnRuVHh0KCk7CiAgICAgICAgICAgIHNldE1haW5EaXZOb25lKCk7CiAgICAgICAgfTsKIAogICAgICAgIG1haW5EaXYucXVlcnlTZWxlY3RvcigiI215UGJyQnRuX0FkZCIpLm9uY2xpY2sgPSBmdW5jdGlvbiAoKSB7CiAgICAgICAgICAgIEludFBiciArPSBJbnRQYnJTdGVwOwogICAgICAgICAgICBzZXRWaWRlb1BCUigpOwogICAgICAgICAgICBzZXRNYWluQnRuVHh0KCk7CiAgICAgICAgfTsKICAgICAgICBtYWluRGl2LnF1ZXJ5U2VsZWN0b3IoIiNteVBickJ0bl9DdXQiKS5vbmNsaWNrID0gZnVuY3Rpb24gKCkgewogICAgICAgICAgICBJbnRQYnIgLT0gSW50UGJyU3RlcDsKICAgICAgICAgICAgc2V0VmlkZW9QQlIoKTsKICAgICAgICAgICAgc2V0TWFpbkJ0blR4dCgpOwogICAgICAgIH07CiAKIAogICAgICAgIGZ1bmN0aW9uIHNldFZpZGVvUEJSKCkgewogICAgICAgICAgICBpZiAoSW50UGJyID4gSW50UGJyTWF4KSB7CiAgICAgICAgICAgICAgICBJbnRQYnIgPSBJbnRQYnJNYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEludFBiciA8IEludFBick1pbikgewogICAgICAgICAgICAgICAgSW50UGJyID0gSW50UGJyTWluOwogICAgICAgICAgICB9CiAKICAgICAgICAgICAgdmFyIHRtcHMgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yQWxsKCJ2aWRlbyIpOwogICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHRtcHMubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgICAgIGNvbnN0IGVsZW1lbnQgPSB0bXBzW2ldOwogICAgICAgICAgICAgICAgZWxlbWVudC5wbGF5YmFja1JhdGUgPSBJbnRQYnI7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY29uc29sZS5sb2coIlBCUiA9ICIgKyBJbnRQYnIpOwogICAgICAgIH0KIAogICAgICAgIGZ1bmN0aW9uIHNldE1haW5CdG5UeHQoKSB7CgkJCW1haW5CdG4uaW5uZXJIVE1MID0gIngiICsgSW50UGJyLnRvRml4ZWQoMik7CiAgICAgICAgfQogCiAgICAgICAgZnVuY3Rpb24gc2V0TWFpbkRpdlNob3coKSB7CiAgICAgICAgICAgIG1haW5EaXYuY2xhc3NOYW1lID0gIm15UGJyQnRucyBzaG93IjsKICAgICAgICB9CiAKICAgICAgICBmdW5jdGlvbiBzZXRNYWluRGl2Tm9uZSgpIHsKICAgICAgICAgICAgbWFpbkRpdi5jbGFzc05hbWUgPSAibXlQYnJCdG5zIGhpZGRlbiI7CiAgICAgICAgfQogICAgfTsKIAogICAgZnVuY3Rpb24gUGFkZGluZyhudW0sIGxlbmd0aCkgewogICAgICAgIHJldHVybiAoQXJyYXkobGVuZ3RoKS5qb2luKCIwIikgKyBudW0pLnNsaWNlKC1sZW5ndGgpOwogICAgfQogCiAKICAgIHZhciBzbGkgPSBzZXRJbnRlcnZhbCgoKSA9PiB7CiAgICAgICAgaWYgKGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoInZpZGVvIikpIHsKICAgICAgICAgICAgTWFpbigpOwogICAgICAgICAgICBjbGVhckludGVydmFsKHNsaSk7CiAgICAgICAgfQogICAgfSwgMTAwMCk7CiAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICBjbGVhckludGVydmFsKHNsaSk7CiAgICB9LCAxMDAwMCk7Cn0pKCk7Ci8vPT09PT09PT09PXZpYS1wbHVnaW46NjI9PT09PT09PT09Cg==
Add Comment
Please, Sign In to add comment